48 return xdoc.Save( aOutFileName, 2 );
56 xroot->AddAttribute(
"version",
"E" );
86 std::map< wxString, wxString >
f;
104 wxString ref = aSymbol->
GetRef( aSheet );
107 int minUnit = aSymbol->
GetUnit();
109 for(
unsigned i = 0; i < sheetList.size(); i++ )
111 for(
auto item : sheetList[i].LastScreen()->Items().OfType(
SCH_COMPONENT_T ) )
115 wxString ref2 = comp2->
GetRef( &sheetList[i] );
117 if( ref2.CmpNoCase( ref ) != 0 )
126 && ( unit < minUnit || fields.
value.IsEmpty() ) )
132 && ( unit < minUnit || fields.
footprint.IsEmpty() ) )
138 && ( unit < minUnit || fields.
datasheet.IsEmpty() ) )
151 && ( unit < minUnit || fields.
f.count( f.
GetName() ) == 0 ) )
160 minUnit = std::min( unit, minUnit );
189 if( fields.
value.size() )
190 aNode->AddChild(
node(
"value", fields.
value ) );
192 aNode->AddChild(
node(
"value",
"~" ) );
200 if( fields.
f.size() )
203 aNode->AddChild( xfields =
node(
"fields" ) );
206 for( std::map< wxString, wxString >::const_iterator it = fields.
f.begin();
207 it != fields.
f.end(); ++it )
210 xfields->AddChild( xfield =
node(
"field", it->second ) );
211 xfield->AddAttribute(
"name", it->first );
229 for(
unsigned ii = 0; ii < sheetList.size(); ii++ )
237 b->GetRef( &sheet ) ) < 0 );
240 std::set<
SCH_COMPONENT*, decltype( cmp )> ordered_symbols( cmp );
241 std::multiset<
SCH_COMPONENT*, decltype( cmp )> extra_units( cmp );
246 auto test = ordered_symbols.insert( symbol );
250 if( ( *(
test.first ) )->m_Uuid > symbol->
m_Uuid )
252 extra_units.insert( *(
test.first ) );
253 ordered_symbols.erase(
test.first );
254 ordered_symbols.insert( symbol );
258 extra_units.insert( symbol );
263 for(
EDA_ITEM* item : ordered_symbols )
279 xcomps->AddChild( xcomp =
node(
"comp" ) );
281 xcomp->AddAttribute(
"ref", symbol->
GetRef( &sheet ) );
285 xcomp->AddChild( xlibsource =
node(
"libsource" ) );
291 xlibsource->AddAttribute(
"lib", symbol->
GetPartRef()->GetLibId().GetLibNickname() );
296 xlibsource->AddAttribute(
"description", symbol->
GetDescription() );
300 std::vector<SCH_FIELD>& fields = symbol->
GetFields();
304 xcomp->AddChild( xproperty =
node(
"property" ) );
305 xproperty->AddAttribute(
"name", fields[jj].GetCanonicalName() );
306 xproperty->AddAttribute(
"value", fields[jj].GetText() );
311 xcomp->AddChild( xproperty =
node(
"property" ) );
312 xproperty->AddAttribute(
"name", sheetField.GetCanonicalName() );
313 xproperty->AddAttribute(
"value", sheetField.GetText() );
318 xcomp->AddChild( xproperty =
node(
"property" ) );
319 xproperty->AddAttribute(
"name",
"exclude_from_bom" );
324 xcomp->AddChild( xproperty =
node(
"property" ) );
325 xproperty->AddAttribute(
"name",
"exclude_from_board" );
329 xcomp->AddChild( xsheetpath =
node(
"sheetpath" ) );
332 xsheetpath->AddAttribute(
"tstamps", sheet.
PathAsString() );
335 xcomp->AddChild( xunits =
node(
"tstamps" ) );
337 auto range = extra_units.equal_range( symbol );
340 for(
auto it = range.first; it != range.second; ++it )
342 new XNODE( wxXML_TEXT_NODE, wxEmptyString, ( *it )->m_Uuid.AsString() ) );
363 wxFileName sourceFileName;
375 for(
const std::pair<const wxString, wxString>& prop : properties )
377 xdesign->AddChild( xtextvar =
node(
"textvar", prop.second ) );
378 xtextvar->AddAttribute(
"name", prop.first );
386 for(
unsigned i = 0; i < sheetList.size(); i++ )
388 screen = sheetList[i].LastScreen();
390 xdesign->AddChild( xsheet =
node(
"sheet" ) );
395 sheetTxt.Printf(
"%u", i + 1 );
396 xsheet->AddAttribute(
"number", sheetTxt );
397 xsheet->AddAttribute(
"name", sheetList[i].PathHumanReadable() );
398 xsheet->AddAttribute(
"tstamps", sheetList[i].PathAsString() );
403 xsheet->AddChild( xtitleBlock =
node(
"title_block" ) );
411 sourceFileName = wxFileName( screen->
GetFileName() );
412 xtitleBlock->AddChild(
node(
"source", sourceFileName.GetFullName() ) );
414 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
415 xcomment->AddAttribute(
"number",
"1" );
418 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
419 xcomment->AddAttribute(
"number",
"2" );
422 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
423 xcomment->AddAttribute(
"number",
"3" );
426 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
427 xcomment->AddAttribute(
"number",
"4" );
430 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
431 xcomment->AddAttribute(
"number",
"5" );
434 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
435 xcomment->AddAttribute(
"number",
"6" );
438 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
439 xcomment->AddAttribute(
"number",
"7" );
442 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
443 xcomment->AddAttribute(
"number",
"8" );
446 xtitleBlock->AddChild( xcomment =
node(
"comment" ) );
447 xcomment->AddAttribute(
"number",
"9" );
462 wxString libNickname = *it;
465 if( symbolLibTable->
HasLibrary( libNickname ) )
467 xlibs->AddChild( xlibrary =
node(
"library" ) );
468 xlibrary->AddAttribute(
"logical", libNickname );
469 xlibrary->AddChild(
node(
"uri", symbolLibTable->
GetFullURI( libNickname ) ) );
484 std::vector<LIB_FIELD*> fieldList;
490 wxString libNickname = lcomp->GetLibId().GetLibNickname();;
493 if( !libNickname.IsEmpty() )
497 xlibparts->AddChild( xlibpart =
node(
"libpart" ) );
498 xlibpart->AddAttribute(
"lib", libNickname );
499 xlibpart->AddAttribute(
"part", lcomp->GetName() );
502 if( !lcomp->GetDescription().IsEmpty() )
503 xlibpart->AddChild(
node(
"description", lcomp->GetDescription() ) );
505 if( !lcomp->GetDatasheetField().GetText().IsEmpty() )
506 xlibpart->AddChild(
node(
"docs", lcomp->GetDatasheetField().GetText() ) );
509 if( lcomp->GetFPFilters().GetCount() )
512 xlibpart->AddChild( xfootprints =
node(
"footprints" ) );
514 for(
unsigned i = 0; i < lcomp->GetFPFilters().GetCount(); ++i )
515 xfootprints->AddChild(
node(
"fp", lcomp->GetFPFilters()[i] ) );
520 lcomp->GetFields( fieldList );
523 xlibpart->AddChild( xfields =
node(
"fields" ) );
525 for(
const LIB_FIELD* field : fieldList )
527 if( !field->GetText().IsEmpty() )
530 xfields->AddChild( xfield =
node(
"field", field->GetText() ) );
531 xfield->AddAttribute(
"name", field->GetCanonicalName() );
537 lcomp->GetPins( pinList, 0, 0 );
548 for(
int ii = 0; ii < (int)pinList.size()-1; ii++ )
550 if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
552 pinList.erase(pinList.begin() + ii + 1);
561 xlibpart->AddChild( pins =
node(
"pins" ) );
562 for(
unsigned i=0; i<pinList.size(); ++i )
566 pins->AddChild( pin =
node(
"pin" ) );
567 pin->AddAttribute(
"num", pinList[i]->GetNumber() );
568 pin->AddAttribute(
"name", pinList[i]->GetName() );
569 pin->AddAttribute(
"type", pinList[i]->GetCanonicalElectricalTypeName() );
587 XNODE* xnet =
nullptr;
601 m_NoConnect( aNoConnect )
611 NET_RECORD(
const wxString& aName ) :
616 std::vector<NET_NODE> m_Nodes;
619 std::vector<NET_RECORD*> nets;
623 wxString net_name = it.first.first;
624 auto subgraphs = it.second;
625 NET_RECORD* net_record;
627 if( subgraphs.empty() )
630 nets.emplace_back(
new NET_RECORD( net_name ) );
631 net_record = nets.back();
635 bool nc = subgraph->m_no_connect && subgraph->m_no_connect->Type() ==
SCH_NO_CONNECT_T;
638 for(
SCH_ITEM* item : subgraph->m_items )
642 SCH_PIN* pin = static_cast<SCH_PIN*>( item );
652 net_record->m_Nodes.emplace_back( pin, sheet, nc );
659 std::sort( nets.begin(), nets.end(),
660 [](
const NET_RECORD* a,
const NET_RECORD*b )
662 return StrNumCmp( a->m_Name, b->m_Name ) < 0;
665 for(
int i = 0; i < (int) nets.size(); ++i )
667 NET_RECORD* net_record = nets[i];
672 std::sort( net_record->m_Nodes.begin(), net_record->m_Nodes.end(),
673 [](
const NET_NODE& a,
const NET_NODE& b )
675 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
676 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
679 return a.m_Pin->GetNumber() < b.m_Pin->GetNumber();
687 net_record->m_Nodes.erase(
688 std::unique( net_record->m_Nodes.begin(), net_record->m_Nodes.end(),
689 [](
const NET_NODE& a,
const NET_NODE& b )
691 wxString refA = a.m_Pin->GetParentSymbol()->GetRef( &a.m_Sheet );
692 wxString refB = b.m_Pin->GetParentSymbol()->GetRef( &b.m_Sheet );
694 return refA == refB && a.m_Pin->GetNumber() == b.m_Pin->GetNumber();
696 net_record->m_Nodes.end() );
698 for(
const NET_NODE& netNode : net_record->m_Nodes )
700 wxString refText = netNode.m_Pin->GetParentSymbol()->GetRef( &netNode.m_Sheet );
701 wxString pinText = netNode.m_Pin->GetNumber();
704 if( refText[0] == wxChar(
'#' ) )
709 netCodeTxt.Printf(
"%d", i + 1 );
711 xnets->AddChild( xnet =
node(
"net" ) );
712 xnet->AddAttribute(
"code", netCodeTxt );
713 xnet->AddAttribute(
"name", net_record->m_Name );
718 xnet->AddChild( xnode =
node(
"node" ) );
719 xnode->AddAttribute(
"ref", refText );
720 xnode->AddAttribute(
"pin", pinText );
722 wxString pinName = netNode.m_Pin->GetName();
723 wxString pinType = netNode.m_Pin->GetCanonicalElectricalTypeName();
726 if( pinName !=
"~" && !pinName.IsEmpty() )
727 xnode->AddAttribute(
"pinfunction", pinName );
729 if( netNode.m_NoConnect )
730 pinType +=
"+no_connect";
732 xnode->AddAttribute(
"pintype", pinType );
736 for( NET_RECORD* record : nets )
744 const wxString& aTextualContent )
746 XNODE* n =
new XNODE( wxXML_ELEMENT_NODE, aName );
748 if( aTextualContent.Len() > 0 )
749 n->AddChild(
new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
EE_TYPE OfType(KICAD_T aType) const
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
virtual std::map< wxString, wxString > & GetTextVars() const
const wxString & GetFileName() const
const UTF8 & GetLibItemName() const
virtual wxString GetFileName() const =0
bool HasLibrary(const wxString &aNickname, bool aCheckEnabled=false) const
Test for the existence of aNickname in the library table.
int StrNumCmp(const wxString &aString1, const wxString &aString2, bool aIgnoreCase)
Compare two strings with alphanumerical content.
Container for project specific data.
SCH_FIELD * GetField(MANDATORY_FIELD_T aFieldType)
Returns a mandatory field in this symbol.
wxString ExpandTextVars(const wxString &aSource, const PROJECT *aProject)
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.
bool GetIncludeOnBoard() const
const wxString & GetComment(int aIdx) const
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
SCH_COMPONENT * GetParentSymbol() const
wxString PathHumanReadable(bool aUseShortRootName=true) const
Return the sheet path in a human readable form made from the sheet names.
Field object used in symbol libraries.
XNODE * makeRoot(unsigned aCtl=GNL_ALL)
Build the entire document tree for the generic export.
int GetUnitCount() const
Return the number of units per package of the symbol.
Collection of utility functions for component reference designators (refdes)
XNODE * makeLibParts()
Fill out an XML node with the unique library parts and returns it.
wxString AsString() const
const TITLE_BLOCK & GetTitleBlock() const
wxString PathAsString() const
Return the path of time stamps which do not changes even when editing sheet parameters.
wxString GetDescription() const
Return information about the aliased parts.
virtual CONNECTION_GRAPH * ConnectionGraph() const =0
void Clear()
Function Clear erases the record.
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_libParts
unique library parts used. LIB_PART items are sorted by names
Hold the information shown in the lower right corner of a plot, printout, or editing view.
A subgraph is a set of items that are electrically connected on a single sheet.
wxString GetShownText(int aDepth=0) const override
Return the string actually shown after processing of the base text.
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populates a std::vector with SCH_FIELDs.
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
virtual PROJECT & Prj() const =0
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple parts per package" symbols to avoid processing a lib part more than once.
const wxString GetFootprint(const SCH_SHEET_PATH *sheet, bool aResolve) const
int RefDesStringCompare(const wxString &aFirst, const wxString &aSecond)
Acts just like the strcmp function but treats numbers within the string text correctly for sorting.
std::vector< SCH_FIELD > & GetFields()
XNODE * makeListOfNets(unsigned aCtl)
Fill out an XML node with a list of nets and returns it.
const wxString GetValue(const SCH_SHEET_PATH *sheet, bool aResolve) const
wxString GetBuildVersion()
Get the full KiCad version string.
const wxString & GetRevision() const
static bool sortPinsByNumber(LIB_PIN *aPin1, LIB_PIN *aPin2)
wxString GetFullURI(const wxString &aLibNickname, bool aExpandEnvVars=true) const
Return the full URI of the library mapped to aLibNickname.
const wxString & GetCompany() const
SCH_COMPONENT * findNextSymbol(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Checks if the given symbol should be processed for netlisting.
const NET_MAP & GetNetMap() const
Holder for multi-unit component fields.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
std::unique_ptr< LIB_PART > & GetPartRef()
bool GetIncludeInBom() const
int GetFieldCount() const
Return the number of fields in this symbol.
virtual void SetCurrentSheet(const SCH_SHEET_PATH &aPath)=0
Hold an XML or S-expression element.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
std::set< wxString > m_libraries
const wxString & GetDate() const
const wxString & GetNumber() const
XNODE * makeSymbols(unsigned aCtl)
SCH_SCREEN * LastScreen()
void addSymbolFields(XNODE *aNode, SCH_COMPONENT *aSymbol, SCH_SHEET_PATH *aSheet)
bool WriteNetlist(const wxString &aOutFileName, unsigned aNetlistOptions) override
Write generic netlist to aOutFileName.
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
A base class for most all the KiCad significant classes used in schematics and boards.
std::map< wxString, wxString > f
const wxString & GetTitle() const
Definition for part library class.
const LIB_ID & GetLibId() const
virtual SCH_SHEET_LIST GetSheets() const =0
Base class for any item which can be embedded within the SCHEMATIC container class,...
virtual const wxString & GetText() const
Return the string associated with the text object.
XNODE * makeLibraries()
Fill out an XML node with a list of used libraries and returns it.
KICAD_T Type() const
Returns the type of object.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
XNODE * makeDesignHeader()
Fills out a project "design" header into an XML node.