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." ) );
119 if(
path == paths.end() )
120 THROW_IO_ERROR(
_(
"Connectivity contains an unknown sheet instance." ) );
145 itemNets.emplace( item->m_Uuid, connection->Name() );
155 for(
const auto& [key, subgraphs] :
m_schematic->ConnectionGraph()->GetNetMap() )
161 result.hasNoConnect |= subgraph->GetNoConnect()
165 for(
SCH_ITEM* item : subgraph->GetItems() )
184 const auto found = sheet->second.find( aItem.
m_Uuid );
185 return found == sheet->second.end() ? std::nullopt : std::optional( found->second );
198 const wxString& aFinalFile,
const wxString& aProjectPath )
206 wxString ret = aFormatString;
207 wxFileName in = aNetlistFile;
208 wxFileName out = aFinalFile;
209 wxString str_out = out.GetFullPath();
211 ret.Replace(
"%P", aProjectPath,
true );
212 ret.Replace(
"%B", out.GetName(),
true );
213 ret.Replace(
"%I", in.GetFullPath(),
true );
221 if( !str_out.StartsWith(
"\\\\" ) )
222 str_out.Replace(
"\\",
"/" );
225 ret.Replace(
"%O", str_out,
true );
233 wxCHECK( aItem,
nullptr );
245 ref = symbol->
GetRef( &aSheetPath );
247 if( ref[0] == wxChar(
'#' ) )
252 wxCHECK( screen,
nullptr );
278 std::vector<PIN_INFO> pins;
283 wxString ref( aSymbol->
GetRef( &aSheetPath ) );
287 if( ( ref[0] == wxChar(
'#' ) ) || aSymbol->
IsPower() )
310 if(
const std::optional<wxString> netName =
itemNetName( *
pin, aSheetPath ) )
316 std::sort( pins.begin(), pins.end(),
319 return StrNumCmp( lhs.num, rhs.num, true ) < 0;
343 if( !fpText.IsEmpty() && fpId.
Parse( fpText,
true ) < 0 )
352 if( state == SCH_PIN::PAD_RESOLUTION::UNMAPPED )
374 if(
m_kiway && !aFootprintId.IsEmpty() )
378 typedef void ( *PAD_NUMBERS_FN_PTR )(
const wxString&,
PROJECT*, std::set<wxString>& );
381 fetch( aFootprintId, &
m_schematic->Project(), pads );
396 wxString pinName = baseName.IsEmpty() ? padNum : baseName + wxT(
"_" ) + padNum;
397 aPins.emplace_back( padNum, aNetName, pinName, aPin->
GetNumber() );
404 for(
unsigned ii = 0; ii < aPins.size(); ii++ )
406 if( aPins[ii].num.empty() )
415 unsigned idxBest = ii;
417 for(
unsigned jj = ii + 1; jj < aPins.size(); jj++ )
419 if( aPins[jj].num.empty() )
422 if( aPins[idxBest].num != aPins[jj].num )
429 if( aPins[idxBest].netName != aPins[jj].netName
430 && !aPins[idxBest].srcPin.IsEmpty()
431 && !aPins[jj].srcPin.IsEmpty()
432 && aPins[idxBest].srcPin != aPins[jj].srcPin )
442 if( bestIsAuto && !jjIsAuto )
445 aPins[idxBest].num.clear();
450 aPins[jj].num.clear();
458 std::vector<PIN_INFO>& aPins )
460 const wxString ref = aSchSymbol->
GetRef( &aSheetPath );
468 if( symbol->
GetRef( &sheet ).CmpNoCase( ref ) != 0 )
473 if(
const std::optional<wxString> netName =
itemNetName( *
pin, 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)
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.
wxString m_exportVariant
The schematic we're generating a netlist for.
KIWAY * m_kiway
The variant of the schematic to export.
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).
std::vector< SCH_ITEM * > Items() const
KIID_PATH Instance() const
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.