71 if(
board->Footprints().empty() )
73 m_frame->ShowInfoBarError(
_(
"Cannot export BOM: there are no footprints on the PCB." ) );
78 fn =
board->GetFileName();
81 wxString pro_dir = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
83 wxFileDialog dlg(
m_frame,
_(
"Save Bill of Materials" ), pro_dir, fn.GetFullName(),
88 if( dlg.ShowModal() == wxID_CANCEL )
93 fp_bom = wxFopen( fn.GetFullPath(), wxT(
"wt" ) );
95 if( fp_bom ==
nullptr )
97 DisplayError(
m_frame, wxString::Format(
_(
"Failed to create file '%s'." ), fn.GetFullPath() ) );
102 wxString msg = wxT(
"\"" );
103 msg <<
_(
"Id" ) << wxT(
"\";\"" );
104 msg <<
_(
"Designator" ) << wxT(
"\";\"" );
105 msg <<
_(
"Footprint" ) << wxT(
"\";\"" );
106 msg <<
_(
"Quantity" ) << wxT(
"\";\"" );
107 msg <<
_(
"Designation" ) << wxT(
"\";\"" );
108 msg <<
_(
"Supplier and ref" ) << wxT(
"\";\n" );
109 fprintf( fp_bom,
"%s",
TO_UTF8( msg ) );
112 std::vector<BOM_ENTRY> list;
119 bool valExist =
false;
124 if( curEntry.m_Val ==
footprint->GetValue() && curEntry.m_FPID ==
footprint->GetFPID() )
126 curEntry.m_Refs.emplace_back(
footprint->Reference().GetShownText(
false ) );
140 newEntry.
m_Refs.emplace_back(
footprint->Reference().GetShownText(
false ) );
148 std::sort( curEntry.m_Refs.begin(), curEntry.m_Refs.end(),
149 [](
const wxString& lhs,
const wxString& rhs )
151 return StrNumCmp( lhs, rhs, true ) < 0;
155 std::sort( list.begin(), list.end(),
158 return StrNumCmp( lhs.m_Refs[0], rhs.m_Refs[0], true ) < 0;
168 msg <<
id++ << wxT(
";\"" );
170 msg << curEntry.m_Refs[0];
172 for(
int ii = 1; ii < (int) curEntry.m_Refs.size(); ++ii )
173 msg << wxT(
", " ) << curEntry.m_Refs[ii];
175 msg << wxT(
"\";\"" );
177 msg <<
From_UTF8( curEntry.m_FPID.GetLibItemName().c_str() ) << wxT(
"\";" );
178 msg << curEntry.m_Count << wxT(
";\"" );
179 msg << curEntry.m_Val << wxT(
"\";;;\n" );
180 fprintf( fp_bom,
"%s",
TO_UTF8( msg ) );
std::vector< wxString > m_Refs