62 return writeNetlist( aOutFileName, aNetlistOptions, aReporter );
69 catch(
const std::exception& error )
71 aReporter.
Report( wxString::Format(
_(
"Failed to export schematic: %s" ), error.
what() ),
87 std::map<KIID_PATH, const SCH_SHEET_PATH*> paths;
92 for(
const auto& [key, row] : facade.Published().Rows() )
94 const auto&
path = facade.Keys().Instance( key.inst );
95 const auto view = facade.Connection( key.item,
path );
98 THROW_IO_ERROR(
_(
"Connectivity changed while preparing the netlist." ) );
100 const auto sheet = paths.find(
path );
102 if( sheet == paths.end() )
103 THROW_IO_ERROR(
_(
"Connectivity contains an unknown sheet instance." ) );
108 for(
const auto&
group : facade.GetNetMap() )
112 for(
const auto& net :
group.instances )
117 const auto path = paths.find( net.Instance() );
119 if(
path == paths.end() )
120 THROW_IO_ERROR(
_(
"Connectivity contains an unknown sheet instance." ) );
140 auto collect = [&](
SCH_ITEM* item )
143 itemNets.emplace( item->m_Uuid, connection->Name() );
153 for(
const auto& [key, subgraphs] :
m_schematic->ConnectionGraph()->GetNetMap() )
159 result.hasNoConnect |= subgraph->GetNoConnect()
163 for(
SCH_ITEM* item : subgraph->GetItems() )
182 const auto found = sheet->second.find( aItem.
m_Uuid );
183 return found == sheet->second.end() ? std::nullopt : std::optional( found->second );
197 const wxString& aNetlistFile,
198 const wxString& aFinalFile,
199 const wxString& aProjectPath )
207 wxString ret = aFormatString;
208 wxFileName in = aNetlistFile;
209 wxFileName out = aFinalFile;
210 wxString str_out = out.GetFullPath();
212 ret.Replace(
"%P", aProjectPath,
true );
213 ret.Replace(
"%B", out.GetName(),
true );
214 ret.Replace(
"%I", in.GetFullPath(),
true );
222 if( !str_out.StartsWith(
"\\\\" ) )
223 str_out.Replace(
"\\",
"/" );
226 ret.Replace(
"%O", str_out,
true );
235 wxCHECK( aItem,
nullptr );
247 ref = symbol->
GetRef( &aSheetPath );
249 if( ref[0] == wxChar(
'#' ) )
254 wxCHECK( screen,
nullptr );
281 std::vector<PIN_INFO> pins;
286 wxString ref( aSymbol->
GetRef( &aSheetPath ) );
290 if( ( ref[0] == wxChar(
'#' ) ) || aSymbol->
IsPower() )
319 std::sort( pins.begin(), pins.end(),
322 return StrNumCmp( lhs.num, rhs.num, true ) < 0;
345 wxString fpText = symbol->GetFootprintFieldText( &aSheetPath,
RESOLVED, variantName );
348 if( !fpText.IsEmpty() && fpId.
Parse( fpText,
true ) < 0 )
357 if( state == SCH_PIN::PAD_RESOLUTION::UNMAPPED )
379 if(
m_kiway && !aFootprintId.IsEmpty() )
383 typedef void ( *PAD_NUMBERS_FN_PTR )(
const wxString&,
PROJECT*, std::set<wxString>& );
386 fetch( aFootprintId, &
m_schematic->Project(), pads );
401 wxString pinName = baseName.IsEmpty() ? padNum : baseName + wxT(
"_" ) + padNum;
402 aPins.emplace_back( padNum, aNetName, pinName, aPin->
GetNumber() );
409 for(
unsigned ii = 0; ii < aPins.size(); ii++ )
411 if( aPins[ii].num.empty() )
420 unsigned idxBest = ii;
422 for(
unsigned jj = ii + 1; jj < aPins.size(); jj++ )
424 if( aPins[jj].num.empty() )
427 if( aPins[idxBest].num != aPins[jj].num )
434 if( aPins[idxBest].netName != aPins[jj].netName && !aPins[idxBest].srcPin.IsEmpty()
435 && !aPins[jj].srcPin.IsEmpty() && aPins[idxBest].srcPin != aPins[jj].srcPin )
445 if( bestIsAuto && !jjIsAuto )
448 aPins[idxBest].num.clear();
453 aPins[jj].num.clear();
462 std::vector<PIN_INFO>& aPins )
464 const wxString ref = aSchSymbol->
GetRef( &aSheetPath );
470 auto* symbol =
static_cast<SCH_SYMBOL*
>( item );
472 if( symbol->GetRef( &sheet ).CmpNoCase( ref ) != 0 )
475 for(
const SCH_PIN*
pin : symbol->GetPins( &sheet ) )
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
A subgraph is a set of items that are electrically connected on a single sheet.
A base class for most all the KiCad significant classes used in schematics and boards.
KICAD_T Type() const
Returns the type of object.
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
virtual const wxString What() const
A composite of Problem() and Where()
virtual const char * what() const override
std::exception interface, returned as UTF-8
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
wxString GetUniStringLibId() const
Define a library symbol object.
const LIB_ID & GetLibId() const override
int GetUnitCount() const override
CONNECTIVITY_SCOPE(NETLIST_EXPORTER_BASE &aExporter)
NETLIST_EXPORTER_BASE & m_exporter
NETLIST_EXPORTER_BASE(SCHEMATIC *aSchematic, KIWAY *aKiway)
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
virtual bool writeNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter)
std::optional< wxString > itemNetName(const SCH_ITEM &aItem, const SCH_SHEET_PATH &aPath) const
const std::set< wxString > & footprintPads(const wxString &aFootprintId) const
void findAllUnitsOfSymbol(SCH_SYMBOL *aSchSymbol, const SCH_SHEET_PATH &aSheetPath, std::vector< PIN_INFO > &aPins)
Find all units for symbols with multiple symbols per package.
void rebuildConnectivity()
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, const SCH_SHEET_PATH &aSheetPath)
Check if the given symbol should be processed for netlisting.
std::map< wxString, std::set< wxString > > m_footprintPadCache
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
void eraseDuplicatePins(std::vector< PIN_INFO > &pins)
Erase duplicate pins.
std::vector< wxString > resolvePadNumbers(const SCH_PIN *aPin, const SCH_SHEET_PATH &aSheetPath) const
Resolve aPin to its effective pad number(s) for every netlist path (issue #2282).
std::map< SCH_SHEET_PATH, std::unordered_map< KIID, wxString > > m_exportItemNets
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
SCH_SHEET_LIST m_exportSheets
std::vector< EXPORT_NET > m_exportNets
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter)
Write to specified output file.
static wxString MakeCommandLine(const wxString &aFormatString, const wxString &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
Build up a string that describes a command line for executing a child process.
void appendResolvedPins(std::vector< PIN_INFO > &aPins, const SCH_PIN *aPin, const SCH_SHEET_PATH &aSheetPath, const wxString &aNetName)
Resolve aPin to its pad number(s) and append a PIN_INFO for each (issue #2282).
std::vector< PIN_INFO > CreatePinList(SCH_SYMBOL *aSymbol, const SCH_SHEET_PATH &aSheetPath)
Find a symbol from the DrawList and builds its pin list.
Container for project specific data.
A pure virtual class used to derive REPORTER objects from.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)
Report a string with a given severity.
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
Base class for any item which can be embedded within the SCHEMATIC container class,...
const SYMBOL * GetParentSymbol() const
PAD_RESOLUTION
Outcome of pin-to-pad resolution (issue #2282).
const wxString & GetShownName() const
wxString GetEffectivePadNumber(const SCH_SHEET_PATH &aSheet, const wxString &aVariantName, const LIB_ID &aFootprintLibId, const std::set< wxString > *aFootprintPadNumbers, PAD_RESOLUTION *aState=nullptr) const
Resolve the footprint pad number this symbol pin lands on (issue #2282).
const wxString & GetNumber() const
const std::map< wxString, LIB_SYMBOL * > & GetLibSymbols() const
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
SCH_SCREEN * LastScreen()
wxString GetSchSymbolLibraryName() const
std::vector< const SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet) const
Retrieve a list of the SCH_PINs for the given sheet path.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const override
bool IsPower() const override
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
@ KIFACE_FOOTPRINT_PAD_NUMBERS
Function pointer type: void (*)( const wxString& aFootprint, PROJECT* aProject, std::set<wxString>& a...
std::vector< wxString > ExpandStackedPinNotation(const wxString &aPinName, bool *aValid)
Expand stacked pin notation like [1,2,3], [1-4], [A1-A4], or [AA1-AA3,AB4,CD12-CD14] into individual ...
bool IsAutoGeneratedNetName(const wxString &aNetName)
Recognize the reserved prefixes used for generated pin-net names.
Implement a participant in the KIWAY alchemy.
bool operator()(LIB_SYMBOL *const &libsymbol1, LIB_SYMBOL *const &libsymbol2) const
wxString result
Test unit parsing edge cases and error handling.
wxLogTrace helper definitions.