74 if(
board->Footprints().empty() )
76 m_frame->ShowInfoBarError(
_(
"Cannot export BOM: there are no footprints on the PCB." ) );
81 fn =
board->GetFileName();
84 wxString pro_dir = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
86 wxFileDialog dlg(
m_frame,
_(
"Save Bill of Materials" ), pro_dir, fn.GetFullName(),
89 if( dlg.ShowModal() == wxID_CANCEL )
94 fp_bom = wxFopen( fn.GetFullPath(), wxT(
"wt" ) );
96 if( fp_bom ==
nullptr )
98 DisplayError(
m_frame, wxString::Format(
_(
"Failed to create file '%s'." ), fn.GetFullPath() ) );
103 wxString msg = wxT(
"\"" );
104 msg <<
_(
"Id" ) << wxT(
"\";\"" );
105 msg <<
_(
"Designator" ) << wxT(
"\";\"" );
106 msg <<
_(
"Footprint" ) << wxT(
"\";\"" );
107 msg <<
_(
"Quantity" ) << wxT(
"\";\"" );
108 msg <<
_(
"Designation" ) << wxT(
"\";\"" );
109 msg <<
_(
"Supplier and ref" ) << wxT(
"\";\n" );
110 fprintf( fp_bom,
"%s",
TO_UTF8( msg ) );
113 std::vector<BOM_ENTRY> list;
120 bool valExist =
false;
125 if( curEntry.m_Val ==
footprint->GetValue() && curEntry.m_FPID ==
footprint->GetFPID() )
127 curEntry.m_Refs.emplace_back(
footprint->Reference().GetShownText(
false ) );
141 newEntry.
m_Refs.emplace_back(
footprint->Reference().GetShownText(
false ) );
149 std::sort( curEntry.m_Refs.begin(), curEntry.m_Refs.end(),
150 [](
const wxString& lhs,
const wxString& rhs )
152 return StrNumCmp( lhs, rhs, true ) < 0;
156 std::sort( list.begin(), list.end(),
159 return StrNumCmp( lhs.m_Refs[0], rhs.m_Refs[0], true ) < 0;
169 msg <<
id++ << wxT(
";\"" );
171 msg << curEntry.m_Refs[0];
173 for(
int ii = 1; ii < (int) curEntry.m_Refs.size(); ++ii )
174 msg << wxT(
", " ) << curEntry.m_Refs[ii];
176 msg << wxT(
"\";\"" );
178 msg <<
From_UTF8( curEntry.m_FPID.GetLibItemName().c_str() ) << wxT(
"\";" );
179 msg << curEntry.m_Count << wxT(
";\"" );
180 msg << curEntry.m_Val << wxT(
"\";;;\n" );
181 fprintf( fp_bom,
"%s",
TO_UTF8( msg ) );
std::vector< wxString > m_Refs