75 if(
board->Footprints().empty() )
77 m_frame->ShowInfoBarError(
_(
"Cannot export BOM: there are no footprints on the PCB." ) );
82 fn =
board->GetFileName();
85 wxString pro_dir = wxPathOnly(
m_frame->Prj().GetProjectFullName() );
87 wxFileDialog dlg(
m_frame,
_(
"Save Bill of Materials" ), pro_dir, fn.GetFullName(),
92 if( dlg.ShowModal() == wxID_CANCEL )
97 fp_bom = wxFopen( fn.GetFullPath(), wxT(
"wt" ) );
99 if( fp_bom ==
nullptr )
101 DisplayError(
m_frame, wxString::Format(
_(
"Failed to create file '%s'." ), fn.GetFullPath() ) );
106 wxString msg = wxT(
"\"" );
107 msg <<
_(
"Id" ) << wxT(
"\";\"" );
108 msg <<
_(
"Designator" ) << wxT(
"\";\"" );
109 msg <<
_(
"Footprint" ) << wxT(
"\";\"" );
110 msg <<
_(
"Quantity" ) << wxT(
"\";\"" );
111 msg <<
_(
"Designation" ) << wxT(
"\";\"" );
112 msg <<
_(
"Supplier and ref" ) << wxT(
"\";\n" );
113 fprintf( fp_bom,
"%s",
TO_UTF8( msg ) );
116 std::vector<BOM_ENTRY> list;
123 bool valExist =
false;
128 if( curEntry.m_Val ==
footprint->GetValue() && curEntry.m_FPID ==
footprint->GetFPID() )
130 curEntry.m_Refs.emplace_back(
footprint->Reference().GetShownText(
false ) );
144 newEntry.
m_Refs.emplace_back(
footprint->Reference().GetShownText(
false ) );
152 std::sort( curEntry.m_Refs.begin(), curEntry.m_Refs.end(),
153 [](
const wxString& lhs,
const wxString& rhs )
155 return StrNumCmp( lhs, rhs, true ) < 0;
159 std::sort( list.begin(), list.end(),
162 return StrNumCmp( lhs.m_Refs[0], rhs.m_Refs[0], true ) < 0;
172 msg <<
id++ << wxT(
";\"" );
174 msg << curEntry.m_Refs[0];
176 for(
int ii = 1; ii < (int) curEntry.m_Refs.size(); ++ii )
177 msg << wxT(
", " ) << curEntry.m_Refs[ii];
179 msg << wxT(
"\";\"" );
181 msg <<
From_UTF8( curEntry.m_FPID.GetLibItemName().c_str() ) << wxT(
"\";" );
182 msg << curEntry.m_Count << wxT(
";\"" );
183 msg << curEntry.m_Val << wxT(
"\";;;\n" );
184 fprintf( fp_bom,
"%s",
TO_UTF8( msg ) );
std::vector< wxString > m_Refs