38 if( ( f = wxFopen( aOutFileName, wxT(
"wt" ) ) ) ==
nullptr )
40 wxString msg = wxString::Format(
_(
"Failed to create file '%s'." ), aOutFileName );
51 fmt::print( f,
"*PADS-PCB*\n" );
52 fmt::print( f,
"*PART*\n" );
62 std::vector<EDA_ITEM*> sheetItems;
65 sheetItems.push_back( item );
70 return item1->
m_Uuid < item2->m_Uuid;
73 std::sort( sheetItems.begin(), sheetItems.end(), pred );
87 footprint = footprint.Trim(
true );
88 footprint = footprint.Trim(
false );
89 footprint.Replace( wxT(
" " ), wxT(
"_" ) );
91 if( footprint.IsEmpty() )
95 footprint.Replace( wxT(
" " ), wxT(
"_" ) );
96 footprint = footprint.Trim(
true );
97 footprint = footprint.Trim(
false );
100 msg = symbol->
GetRef( &sheet );
101 fmt::print( f,
"{:<16} {}\n",
TO_UTF8( msg ),
TO_UTF8( footprint ) );
105 fmt::print( f,
"\n" );
113 catch(
const std::system_error& e )
118 catch(
const fmt::format_error& e )
120 aReporter.
Report( wxString::Format(
_(
"Formatting error writing netlist: %s" ), e.what() ),
135 fmt::print( f,
"*NET*\n" );
138 std::vector<std::pair<wxString, std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>>>> allNets;
141 allNets.emplace_back( net.name, net.pins );
143 for(
auto& [netName, sortedItems] : allNets )
146 std::sort( sortedItems.begin(), sortedItems.end(),
147 [](
const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a,
const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
149 wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
150 wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
153 return a.first->GetShownNumber() < b.first->GetShownNumber();
155 return ref_a < ref_b;
159 sortedItems.erase( std::unique( sortedItems.begin(), sortedItems.end(),
160 [](
const std::pair<SCH_PIN*, SCH_SHEET_PATH>& a,
const std::pair<SCH_PIN*, SCH_SHEET_PATH>& b )
162 wxString ref_a = a.first->GetParentSymbol()->GetRef( &a.second );
163 wxString ref_b = b.first->GetParentSymbol()->GetRef( &b.second );
165 return ref_a == ref_b && a.first->GetShownNumber() == b.first->GetShownNumber();
172 std::sort( allNets.begin(), allNets.end(),
173 [](
const auto& a,
const auto& b )
175 return a.first < b.first;
178 for(
const auto& [sortedNetName, sorted_items] : allNets )
180 std::vector<wxString> netConns;
182 for(
const std::pair<SCH_PIN*, SCH_SHEET_PATH>& pair : sorted_items )
187 wxString refText =
pin->GetParentSymbol()->GetRef( &sheet );
188 wxString pinText =
pin->GetShownNumber();
191 if( refText[0] == wxChar(
'#' ) )
194 netConns.push_back( wxString::Format(
"%s.%s", refText, pinText ) );
199 if( netConns .size() > 1 )
201 fmt::print( f,
"*SIGNAL* {}\n",
TO_UTF8(sortedNetName) );
204 for( wxString& netConn : netConns )
206 fmt::print( f,
"{}",
TO_UTF8( netConn ) );
208 if( cnt != 0 && cnt % 6 == 0 )
209 fmt::print( f,
"\n" );
211 fmt::print( f,
" " );
216 fmt::print( f,
"\n" );
220 fmt::print( f,
"*END*\n" );
222 return ferror( f ) == 0;
224 catch(
const std::system_error& )
228 catch(
const fmt::format_error& )