KiCad PCB EDA Suite
NETLIST_EXPORTER_GENERIC Class Reference

Generate a generic XML based netlist file. More...

#include <netlist_exporter_generic.h>

Inheritance diagram for NETLIST_EXPORTER_GENERIC:
NETLIST_EXPORTER NETLIST_EXPORTER_KICAD

Public Member Functions

 NETLIST_EXPORTER_GENERIC (SCHEMATIC *aSchematic)
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions) override
 Write generic netlist to aOutFileName. More...
 

Static Public Member Functions

static wxString MakeCommandLine (const wxString &aFormatString, const wxString &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
 Function MakeCommandLine builds up a string that describes a command line for executing a child process. More...
 

Protected Member Functions

XNODEnode (const wxString &aName, const wxString &aTextualContent=wxEmptyString)
 A convenience function that creates a new XNODE with an optional textual child. More...
 
XNODEmakeRoot (int aCtl=GNL_ALL)
 Build the entire document tree for the generic export. More...
 
XNODEmakeComponents (unsigned aCtl)
 
XNODEmakeDesignHeader ()
 Fills out a project "design" header into an XML node. More...
 
XNODEmakeLibParts ()
 Fill out an XML node with the unique library parts and returns it. More...
 
XNODEmakeListOfNets ()
 Fill out an XML node with a list of nets and returns it. More...
 
XNODEmakeLibraries ()
 Fill out an XML node with a list of used libraries and returns it. More...
 
void addComponentFields (XNODE *xcomp, SCH_COMPONENT *comp, SCH_SHEET_PATH *aSheet)
 
void CreatePinList (SCH_COMPONENT *aItem, SCH_SHEET_PATH *aSheetPath)
 Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin list in m_SortedComponentPinList. More...
 
SCH_COMPONENTfindNextComponent (EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
 Checks if the given component should be processed for netlisting. More...
 
void eraseDuplicatePins ()
 Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i.e. More...
 
void findAllUnitsOfComponent (SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
 Function findAllUnitsOfComponent is used for "multiple parts per package" components. More...
 

Protected Attributes

std::vector< PIN_INFOm_SortedComponentPinList
 Used to temporarily store and filter the list of pins of a schematic component when generating schematic component data in netlist (comp section). More...
 
UNIQUE_STRINGS m_ReferencesAlreadyFound
 Used for "multi parts per package" components, avoids processing a lib component more than once. More...
 
std::set< LIB_PART *, LIB_PART_LESS_THANm_LibParts
 unique library parts used. More...
 
SCHEMATICm_schematic
 The schematic we're generating a netlist for. More...
 

Private Attributes

std::set< wxString > m_libraries
 Set of library nicknames. More...
 

Detailed Description

Generate a generic XML based netlist file.

This allows using XSLT or other methods to transform the XML to other netlist formats outside of the C++ codebase.

Definition at line 62 of file netlist_exporter_generic.h.

Constructor & Destructor Documentation

◆ NETLIST_EXPORTER_GENERIC()

NETLIST_EXPORTER_GENERIC::NETLIST_EXPORTER_GENERIC ( SCHEMATIC aSchematic)
inline

Definition at line 68 of file netlist_exporter_generic.h.

68  :
69  NETLIST_EXPORTER( aSchematic )
70  {}
NETLIST_EXPORTER(SCHEMATIC *aSchematic)
Constructor.

Member Function Documentation

◆ addComponentFields()

void NETLIST_EXPORTER_GENERIC::addComponentFields ( XNODE xcomp,
SCH_COMPONENT comp,
SCH_SHEET_PATH aSheet 
)
protected

Definition at line 89 of file netlist_exporter_generic.cpp.

91 {
92  COMP_FIELDS fields;
93 
94  if( comp->GetUnitCount() > 1 )
95  {
96  // Sadly, each unit of a component can have its own unique fields. This
97  // block finds the unit with the lowest number having a non blank field
98  // value and records it. Therefore user is best off setting fields
99  // into only the first unit. But this scavenger algorithm will find
100  // any non blank fields in all units and use the first non-blank field
101  // for each unique field name.
102 
103  wxString ref = comp->GetRef( aSheet );
104 
105  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
106  int minUnit = comp->GetUnit();
107 
108  for( unsigned i = 0; i < sheetList.size(); i++ )
109  {
110  for( auto item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
111  {
112  SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
113 
114  wxString ref2 = comp2->GetRef( &sheetList[i] );
115 
116  if( ref2.CmpNoCase( ref ) != 0 )
117  continue;
118 
119  int unit = comp2->GetUnit();
120 
121  // The lowest unit number wins. User should only set fields in any one unit.
122  // remark: IsVoid() returns true for empty strings or the "~" string (empty
123  // field value)
124  if( !comp2->GetField( VALUE )->IsVoid()
125  && ( unit < minUnit || fields.value.IsEmpty() ) )
126  fields.value = comp2->GetField( VALUE )->GetText();
127 
128  if( !comp2->GetField( FOOTPRINT )->IsVoid()
129  && ( unit < minUnit || fields.footprint.IsEmpty() ) )
130  fields.footprint = comp2->GetField( FOOTPRINT )->GetText();
131 
132  if( !comp2->GetField( DATASHEET )->IsVoid()
133  && ( unit < minUnit || fields.datasheet.IsEmpty() ) )
134  fields.datasheet = comp2->GetField( DATASHEET )->GetText();
135 
136  for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp2->GetFieldCount(); ++fldNdx )
137  {
138  SCH_FIELD* f = comp2->GetField( fldNdx );
139 
140  if( f->GetText().size()
141  && ( unit < minUnit || fields.f.count( f->GetName() ) == 0 ) )
142  {
143  fields.f[ f->GetName() ] = f->GetText();
144  }
145  }
146 
147  minUnit = std::min( unit, minUnit );
148  }
149  }
150 
151  }
152  else
153  {
154  fields.value = comp->GetField( VALUE )->GetText();
155  fields.footprint = comp->GetField( FOOTPRINT )->GetText();
156  fields.datasheet = comp->GetField( DATASHEET )->GetText();
157 
158  for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
159  {
160  SCH_FIELD* f = comp->GetField( fldNdx );
161 
162  if( f->GetText().size() )
163  fields.f[ f->GetName() ] = f->GetText();
164  }
165  }
166 
167  // Do not output field values blank in netlist:
168  if( fields.value.size() )
169  xcomp->AddChild( node( "value", fields.value ) );
170  else // value field always written in netlist
171  xcomp->AddChild( node( "value", "~" ) );
172 
173  if( fields.footprint.size() )
174  xcomp->AddChild( node( "footprint", fields.footprint ) );
175 
176  if( fields.datasheet.size() )
177  xcomp->AddChild( node( "datasheet", fields.datasheet ) );
178 
179  if( fields.f.size() )
180  {
181  XNODE* xfields;
182  xcomp->AddChild( xfields = node( "fields" ) );
183 
184  // non MANDATORY fields are output alphabetically
185  for( std::map< wxString, wxString >::const_iterator it = fields.f.begin();
186  it != fields.f.end(); ++it )
187  {
188  XNODE* xfield;
189  xfields->AddChild( xfield = node( "field", it->second ) );
190  xfield->AddAttribute( "name", it->first );
191  }
192  }
193 }
SCH_SHEET_LIST.
SCH_FIELD instances are attached to a component and provide a place for the component's value,...
Definition: sch_field.h:52
name of datasheet
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors.
int GetUnitCount() const
Return the number of units per package of the symbol.
Field Name Module PCB, i.e. "16DIP300".
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:311
int GetUnit() const
Holder for multi-unit component fields.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
int GetFieldCount() const
Return the number of fields in this symbol.
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
SCH_FIELD * GetField(int aFieldNdx)
Returns a field in this symbol.
Field Value of part, i.e. "3.3K".
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:438
Schematic symbol object.
Definition: sch_component.h:88
std::map< wxString, wxString > f
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:127

References DATASHEET, COMP_FIELDS::datasheet, COMP_FIELDS::f, FOOTPRINT, COMP_FIELDS::footprint, SCH_COMPONENT::GetField(), SCH_COMPONENT::GetFieldCount(), SCH_FIELD::GetName(), SCH_COMPONENT::GetRef(), SCHEMATIC::GetSheets(), EDA_TEXT::GetText(), SCH_COMPONENT::GetUnit(), SCH_COMPONENT::GetUnitCount(), SCH_FIELD::IsVoid(), NETLIST_EXPORTER::m_schematic, MANDATORY_FIELDS, node(), SCH_COMPONENT_T, VALUE, and COMP_FIELDS::value.

Referenced by makeComponents().

◆ CreatePinList()

void NETLIST_EXPORTER::CreatePinList ( SCH_COMPONENT aItem,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin list in m_SortedComponentPinList.

This list is sorted by pin num. the component is the next actual component after aItem (power symbols and virtual components that have their reference starting by '#'are skipped).

Definition at line 124 of file netlist_exporter.cpp.

125 {
126  wxString ref( comp->GetRef( aSheetPath ) );
127 
128  // Power symbols and other components which have the reference starting
129  // with "#" are not included in netlist (pseudo or virtual components)
130 
131  if( ref[0] == wxChar( '#' ) )
132  return;
133 
134  // if( Component->m_FlagControlMulti == 1 )
135  // continue; /* yes */
136  // removed because with multiple instances of one schematic
137  // (several sheets pointing to 1 screen), this will be erroneously be
138  // toggled.
139 
140  if( !comp->GetPartRef() )
141  return;
142 
143  m_SortedComponentPinList.clear();
144 
145  // If component is a "multi parts per package" type
146  if( comp->GetPartRef()->GetUnitCount() > 1 )
147  {
148  // Collect all pins for this reference designator by searching
149  // the entire design for other parts with the same reference designator.
150  // This is only done once, it would be too expensive otherwise.
151  findAllUnitsOfComponent( comp, comp->GetPartRef().get(), aSheetPath );
152  }
153 
154  else // entry->GetUnitCount() <= 1 means one part per package
155  {
156  for( const auto& pin : comp->GetSchPins( aSheetPath ) )
157  {
158  if( auto conn = pin->Connection( *aSheetPath ) )
159  {
160  const wxString& netName = conn->Name();
161 
162  // Skip unconnected pins
163  CONNECTION_SUBGRAPH* sg =
164  m_schematic->ConnectionGraph()->FindSubgraphByName( netName, *aSheetPath );
165 
166  if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
167  continue;
168 
169  m_SortedComponentPinList.emplace_back( pin->GetNumber(), netName );
170  }
171  }
172  }
173 
174  // Sort pins in m_SortedComponentPinList by pin number
176 
177  // Remove duplicate Pins in m_SortedComponentPinList
179 
180  // record the usage of this library component entry.
181  m_LibParts.insert( comp->GetPartRef().get() ); // rejects non-unique pointers
182 }
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Returns the subgraph for a given net name on a given sheet.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:132
void findAllUnitsOfComponent(SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
Function findAllUnitsOfComponent is used for "multiple parts per package" components.
A subgraph is a set of items that are electrically connected on a single sheet.
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used.
std::vector< SCH_ITEM * > m_items
std::vector< PIN_INFO > m_SortedComponentPinList
Used to temporarily store and filter the list of pins of a schematic component when generating schema...
static bool sortPinsByNum(PIN_INFO &aPin1, PIN_INFO &aPin2)
Comparison routine for sorting by pin numbers.
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
void eraseDuplicatePins()
Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i....

References SCHEMATIC::ConnectionGraph(), NETLIST_EXPORTER::eraseDuplicatePins(), NETLIST_EXPORTER::findAllUnitsOfComponent(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetRef(), SCH_COMPONENT::GetSchPins(), CONNECTION_SUBGRAPH::m_items, NETLIST_EXPORTER::m_LibParts, CONNECTION_SUBGRAPH::m_no_connect, NETLIST_EXPORTER::m_schematic, NETLIST_EXPORTER::m_SortedComponentPinList, and sortPinsByNum().

Referenced by NETLIST_EXPORTER_PSPICE::ProcessNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ eraseDuplicatePins()

void NETLIST_EXPORTER::eraseDuplicatePins ( )
protectedinherited

Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i.e.

set pointer in this list to NULL). (This is a list of pins found in the whole schematic, for a single component.) These duplicate pins were put in list because some pins (powers... ) are found more than one time when we have a multiple parts per package component. For instance, a 74ls00 has 4 parts, and therefore the VCC pin and GND pin appears 4 times in the list. Note: this list MUST be sorted by pin number (.m_PinNum member value) Also set the m_Flag member of "removed" NETLIST_OBJECT pin item to 1

Definition at line 185 of file netlist_exporter.cpp.

186 {
187  for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
188  {
189  if( m_SortedComponentPinList[ii].num.empty() ) /* already deleted */
190  continue;
191 
192  /* Search for duplicated pins
193  * If found, remove duplicates. The priority is to keep connected pins
194  * and remove unconnected
195  * - So this allows (for instance when using multi op amps per package
196  * - to connect only one op amp to power
197  * Because the pin list is sorted by m_PinNum value, duplicated pins
198  * are necessary successive in list
199  */
200  int idxref = ii;
201 
202  for( unsigned jj = ii + 1; jj < m_SortedComponentPinList.size(); jj++ )
203  {
204  if( m_SortedComponentPinList[jj].num.empty() ) // Already removed
205  continue;
206 
207  // if other pin num, stop search,
208  // because all pins having the same number are consecutive in list.
209  if( m_SortedComponentPinList[idxref].num != m_SortedComponentPinList[jj].num )
210  break;
211 
212  m_SortedComponentPinList[jj].num.clear();
213  }
214  }
215 }
std::vector< PIN_INFO > m_SortedComponentPinList
Used to temporarily store and filter the list of pins of a schematic component when generating schema...

References NETLIST_EXPORTER::m_SortedComponentPinList.

Referenced by NETLIST_EXPORTER::CreatePinList().

◆ findAllUnitsOfComponent()

void NETLIST_EXPORTER::findAllUnitsOfComponent ( SCH_COMPONENT aComponent,
LIB_PART aEntry,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Function findAllUnitsOfComponent is used for "multiple parts per package" components.

Search the entire design for all units of aComponent based on matching reference designator, and for each unit, add all its pins to the temporary sorted pin list, m_SortedComponentPinList.

Definition at line 218 of file netlist_exporter.cpp.

220 {
221  wxString ref = aComponent->GetRef( aSheetPath );
222  wxString ref2;
223 
224  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
225 
226  for( unsigned i = 0; i < sheetList.size(); i++ )
227  {
228  for( auto item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
229  {
230  SCH_COMPONENT* comp2 = static_cast<SCH_COMPONENT*>( item );
231 
232  ref2 = comp2->GetRef( &sheetList[i] );
233 
234  if( ref2.CmpNoCase( ref ) != 0 )
235  continue;
236 
237  for( const auto& pin : comp2->GetSchPins( aSheetPath ) )
238  {
239  if( auto conn = pin->Connection( *aSheetPath ) )
240  {
241  const wxString& netName = conn->Name();
242 
243  // Skip unconnected pins
245  netName, *aSheetPath );
246 
247  if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
248  continue;
249 
250  m_SortedComponentPinList.emplace_back( pin->GetNumber(), netName );
251  }
252  }
253  }
254  }
255 }
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Returns the subgraph for a given net name on a given sheet.
SCH_SHEET_LIST.
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:132
A subgraph is a set of items that are electrically connected on a single sheet.
std::vector< SCH_ITEM * > m_items
std::vector< PIN_INFO > m_SortedComponentPinList
Used to temporarily store and filter the list of pins of a schematic component when generating schema...
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
Schematic symbol object.
Definition: sch_component.h:88
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
SCH_PIN_PTRS GetSchPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieves a list of the SCH_PINs for the given sheet path.

References SCHEMATIC::ConnectionGraph(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_COMPONENT::GetRef(), SCH_COMPONENT::GetSchPins(), SCHEMATIC::GetSheets(), CONNECTION_SUBGRAPH::m_items, CONNECTION_SUBGRAPH::m_no_connect, NETLIST_EXPORTER::m_schematic, NETLIST_EXPORTER::m_SortedComponentPinList, and SCH_COMPONENT_T.

Referenced by NETLIST_EXPORTER::CreatePinList().

◆ findNextComponent()

SCH_COMPONENT * NETLIST_EXPORTER::findNextComponent ( EDA_ITEM aItem,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Checks if the given component should be processed for netlisting.

Prevents processing multi-unit components more than once, etc.

Parameters
aItemis a component to check
aSheetPathis the sheet to check the component for
Returns
the component if it should be processed, or nullptr

Definition at line 75 of file netlist_exporter.cpp.

76 {
77  wxString ref;
78 
79  if( aItem->Type() != SCH_COMPONENT_T )
80  return nullptr;
81 
82  // found next component
83  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
84 
85  // Power symbols and other components which have the reference starting
86  // with "#" are not included in netlist (pseudo or virtual components)
87  ref = comp->GetRef( aSheetPath );
88 
89  if( ref[0] == wxChar( '#' ) )
90  return nullptr;
91 
92  // if( Component->m_FlagControlMulti == 1 )
93  // continue; /* yes */
94  // removed because with multiple instances of one schematic
95  // (several sheets pointing to 1 screen), this will be erroneously be
96  // toggled.
97 
98  if( !comp->GetPartRef() )
99  return nullptr;
100 
101  // If component is a "multi parts per package" type
102  if( comp->GetPartRef()->GetUnitCount() > 1 )
103  {
104  // test if this reference has already been processed, and if so skip
105  if( m_ReferencesAlreadyFound.Lookup( ref ) )
106  return nullptr;
107  }
108 
109  // record the usage of this library component entry.
110  m_LibParts.insert( comp->GetPartRef().get() ); // rejects non-unique pointers
111 
112  return comp;
113 }
bool Lookup(const wxString &aString)
Function Lookup returns true if aString already exists in the set, otherwise returns false and adds a...
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once.
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used.
std::unique_ptr< LIB_PART > & GetPartRef()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
Schematic symbol object.
Definition: sch_component.h:88
KICAD_T Type() const
Function Type()
Definition: base_struct.h:193

References SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetRef(), UNIQUE_STRINGS::Lookup(), NETLIST_EXPORTER::m_LibParts, NETLIST_EXPORTER::m_ReferencesAlreadyFound, SCH_COMPONENT_T, and EDA_ITEM::Type().

Referenced by makeComponents(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

◆ MakeCommandLine()

wxString NETLIST_EXPORTER::MakeCommandLine ( const wxString &  aFormatString,
const wxString &  aNetlistFile,
const wxString &  aFinalFile,
const wxString &  aProjectDirectory 
)
staticinherited

Function MakeCommandLine builds up a string that describes a command line for executing a child process.

The input and output file names along with any options to the executable are all possibly in the returned string.

Parameters
aFormatStringholds:
  • the name of the external program
  • any options needed by that program
  • formatting sequences, see below.
aNetlistFileis the name of the input file for the external program, that is a intermediate netlist file in xml format.
aFinalFileis the name of the output file that the user expects.
aProjectDirectoryis used for P replacement, it should omit the trailing '/'.

Supported formatting sequences and their meaning:

  • B => base filename of selected output file, minus path and extension.
  • I => complete filename and path of the temporary input file.
  • O => complete filename and path of the user chosen output file.
  • P => project directory, without name and without trailing '/'

Definition at line 41 of file netlist_exporter.cpp.

43 {
44  // Expand format symbols in the command line:
45  // %B => base filename of selected output file, minus path and extension.
46  // %P => project directory name, without trailing '/' or '\'.
47  // %I => full filename of the input file (the intermediate net file).
48  // %O => complete filename and path (but without extension) of the user chosen output file.
49 
50  wxString ret = aFormatString;
51  wxFileName in = aNetlistFile;
52  wxFileName out = aFinalFile;
53  wxString str_out = out.GetFullPath();
54 
55  ret.Replace( "%P", aProjectPath, true );
56  ret.Replace( "%B", out.GetName(), true );
57  ret.Replace( "%I", in.GetFullPath(), true );
58 
59 #ifdef __WINDOWS__
60  // A ugly hack to run xsltproc that has a serious bug on Window since a long time:
61  // the filename given after -o option (output filename) cannot use '\' in filename
62  // so replace if by '/' if possible (I mean if the filename does not start by "\\"
63  // that is a filename on a Windows server)
64 
65  if( !str_out.StartsWith( "\\\\" ) )
66  str_out.Replace( "\\", "/" );
67 #endif
68 
69  ret.Replace( "%O", str_out, true );
70 
71  return ret;
72 }

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

◆ makeComponents()

XNODE * NETLIST_EXPORTER_GENERIC::makeComponents ( unsigned  aCtl)
protected
Returns
XNODE* - returns a sub-tree holding all the schematic components.

Definition at line 196 of file netlist_exporter_generic.cpp.

197 {
198  XNODE* xcomps = node( "components" );
199 
201  m_LibParts.clear();
202 
203  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
204 
205  // Output is xml, so there is no reason to remove spaces from the field values.
206  // And XML element names need not be translated to various languages.
207 
208  for( unsigned i = 0; i < sheetList.size(); i++ )
209  {
210  SCH_SHEET_PATH sheet = sheetList[i];
211 
212  auto cmp =
213  [sheet]( SCH_COMPONENT* a, SCH_COMPONENT* b )
214  {
215  return ( UTIL::RefDesStringCompare( a->GetRef( &sheet ),
216  b->GetRef( &sheet ) ) < 0 );
217  };
218 
219  std::set<SCH_COMPONENT*, decltype( cmp )> ordered_components( cmp );
220 
221  for( auto item : sheetList[i].LastScreen()->Items().OfType( SCH_COMPONENT_T ) )
222  {
223  auto comp = static_cast<SCH_COMPONENT*>( item );
224  auto test = ordered_components.insert( comp );
225 
226  if( !test.second )
227  {
228  if( ( *( test.first ) )->GetUnit() > comp->GetUnit() )
229  {
230  ordered_components.erase( test.first );
231  ordered_components.insert( comp );
232  }
233  }
234  }
235 
236  for( auto item : ordered_components )
237  {
238  SCH_COMPONENT* comp = findNextComponent( item, &sheet );
239 
240  if( !comp
241  || ( ( aCtl & GNL_OPT_BOM ) && !comp->GetIncludeInBom() )
242  || ( ( aCtl & GNL_OPT_KICAD ) && !comp->GetIncludeOnBoard() ) )
243  continue;
244 
245  XNODE* xcomp; // current component being constructed
246 
247  // Output the component's elements in order of expected access frequency.
248  // This may not always look best, but it will allow faster execution
249  // under XSL processing systems which do sequential searching within
250  // an element.
251 
252  xcomps->AddChild( xcomp = node( "comp" ) );
253  xcomp->AddAttribute( "ref", comp->GetRef( &sheet ) );
254 
255  addComponentFields( xcomp, comp, &sheetList[i] );
256 
257  XNODE* xlibsource;
258  xcomp->AddChild( xlibsource = node( "libsource" ) );
259 
260  // "logical" library name, which is in anticipation of a better search
261  // algorithm for parts based on "logical_lib.part" and where logical_lib
262  // is merely the library name minus path and extension.
263  if( comp->GetPartRef() )
264  xlibsource->AddAttribute( "lib", comp->GetPartRef()->GetLibId().GetLibNickname() );
265 
266  // We only want the symbol name, not the full LIB_ID.
267  xlibsource->AddAttribute( "part", comp->GetLibId().GetLibItemName() );
268 
269  xlibsource->AddAttribute( "description", comp->GetDescription() );
270 
271  XNODE* xsheetpath;
272 
273  xcomp->AddChild( xsheetpath = node( "sheetpath" ) );
274  xsheetpath->AddAttribute( "names", sheet.PathHumanReadable() );
275  xsheetpath->AddAttribute( "tstamps", sheet.PathAsString() );
276  xcomp->AddChild( node( "tstamp", comp->m_Uuid.AsString() ) );
277  }
278  }
279 
280  return xcomps;
281 }
SCH_SHEET_LIST.
const UTF8 & GetLibItemName() const
Definition: lib_id.h:114
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once.
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
bool GetIncludeOnBoard() const
wxString AsString() const
Definition: common.cpp:165
wxString PathAsString() const
Function PathAsString the path uses the time stamps which do not changes even when editing sheet para...
wxString GetDescription() const
Return information about the aliased parts.
void Clear()
Function Clear erases the record.
SCH_COMPONENT * findNextComponent(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Checks if the given component should be processed for netlisting.
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::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used.
void addComponentFields(XNODE *xcomp, SCH_COMPONENT *comp, SCH_SHEET_PATH *aSheet)
SCH_SHEET_PATH.
std::unique_ptr< LIB_PART > & GetPartRef()
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
bool GetIncludeInBom() const
const KIID m_Uuid
Definition: base_struct.h:162
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
Schematic symbol object.
Definition: sch_component.h:88
wxString PathHumanReadable() const
Function PathHumanReadable returns the sheet path in a human readable form, i.e.
const LIB_ID & GetLibId() const

References addComponentFields(), KIID::AsString(), UNIQUE_STRINGS::Clear(), NETLIST_EXPORTER::findNextComponent(), SCH_COMPONENT::GetDescription(), SCH_COMPONENT::GetIncludeInBom(), SCH_COMPONENT::GetIncludeOnBoard(), SCH_COMPONENT::GetLibId(), LIB_ID::GetLibItemName(), SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetRef(), SCHEMATIC::GetSheets(), GNL_OPT_BOM, GNL_OPT_KICAD, NETLIST_EXPORTER::m_LibParts, NETLIST_EXPORTER::m_ReferencesAlreadyFound, NETLIST_EXPORTER::m_schematic, EDA_ITEM::m_Uuid, node(), SCH_SHEET_PATH::PathAsString(), SCH_SHEET_PATH::PathHumanReadable(), UTIL::RefDesStringCompare(), and SCH_COMPONENT_T.

Referenced by makeRoot().

◆ makeDesignHeader()

XNODE * NETLIST_EXPORTER_GENERIC::makeDesignHeader ( )
protected

Fills out a project "design" header into an XML node.

Returns
XNODE* - the design header

Definition at line 284 of file netlist_exporter_generic.cpp.

285 {
286  SCH_SCREEN* screen;
287  XNODE* xdesign = node( "design" );
288  XNODE* xtitleBlock;
289  XNODE* xsheet;
290  XNODE* xcomment;
291  wxString sheetTxt;
292  wxFileName sourceFileName;
293 
294  // the root sheet is a special sheet, call it source
295  xdesign->AddChild( node( "source", m_schematic->GetFileName() ) );
296 
297  xdesign->AddChild( node( "date", DateAndTime() ) );
298 
299  // which Eeschema tool
300  xdesign->AddChild( node( "tool", wxString( "Eeschema " ) + GetBuildVersion() ) );
301 
302  /*
303  Export the sheets information
304  */
305  SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
306 
307  for( unsigned i = 0; i < sheetList.size(); i++ )
308  {
309  screen = sheetList[i].LastScreen();
310 
311  xdesign->AddChild( xsheet = node( "sheet" ) );
312 
313  // get the string representation of the sheet index number.
314  // Note that sheet->GetIndex() is zero index base and we need to increment the
315  // number by one to make it human readable
316  sheetTxt.Printf( "%u", i + 1 );
317  xsheet->AddAttribute( "number", sheetTxt );
318  xsheet->AddAttribute( "name", sheetList[i].PathHumanReadable() );
319  xsheet->AddAttribute( "tstamps", sheetList[i].PathAsString() );
320 
321 
322  TITLE_BLOCK tb = screen->GetTitleBlock();
323 
324  xsheet->AddChild( xtitleBlock = node( "title_block" ) );
325 
326  xtitleBlock->AddChild( node( "title", tb.GetTitle() ) );
327  xtitleBlock->AddChild( node( "company", tb.GetCompany() ) );
328  xtitleBlock->AddChild( node( "rev", tb.GetRevision() ) );
329  xtitleBlock->AddChild( node( "date", tb.GetDate() ) );
330 
331  // We are going to remove the fileName directories.
332  sourceFileName = wxFileName( screen->GetFileName() );
333  xtitleBlock->AddChild( node( "source", sourceFileName.GetFullName() ) );
334 
335  xtitleBlock->AddChild( xcomment = node( "comment" ) );
336  xcomment->AddAttribute( "number", "1" );
337  xcomment->AddAttribute( "value", tb.GetComment( 0 ) );
338 
339  xtitleBlock->AddChild( xcomment = node( "comment" ) );
340  xcomment->AddAttribute( "number", "2" );
341  xcomment->AddAttribute( "value", tb.GetComment( 1 ) );
342 
343  xtitleBlock->AddChild( xcomment = node( "comment" ) );
344  xcomment->AddAttribute( "number", "3" );
345  xcomment->AddAttribute( "value", tb.GetComment( 2 ) );
346 
347  xtitleBlock->AddChild( xcomment = node( "comment" ) );
348  xcomment->AddAttribute( "number", "4" );
349  xcomment->AddAttribute( "value", tb.GetComment( 3 ) );
350 
351  xtitleBlock->AddChild( xcomment = node( "comment" ) );
352  xcomment->AddAttribute( "number", "5" );
353  xcomment->AddAttribute( "value", tb.GetComment( 4 ) );
354 
355  xtitleBlock->AddChild( xcomment = node( "comment" ) );
356  xcomment->AddAttribute( "number", "6" );
357  xcomment->AddAttribute( "value", tb.GetComment( 5 ) );
358 
359  xtitleBlock->AddChild( xcomment = node( "comment" ) );
360  xcomment->AddAttribute( "number", "7" );
361  xcomment->AddAttribute( "value", tb.GetComment( 6 ) );
362 
363  xtitleBlock->AddChild( xcomment = node( "comment" ) );
364  xcomment->AddAttribute( "number", "8" );
365  xcomment->AddAttribute( "value", tb.GetComment( 7 ) );
366 
367  xtitleBlock->AddChild( xcomment = node( "comment" ) );
368  xcomment->AddAttribute( "number", "9" );
369  xcomment->AddAttribute( "value", tb.GetComment( 8 ) );
370  }
371 
372  return xdesign;
373 }
SCH_SHEET_LIST.
const wxString & GetFileName() const
Definition: sch_screen.h:185
SCH_SHEET_LIST GetSheets() const
Builds and returns an updated schematic hierarchy TODO: can this be cached?
Definition: schematic.h:92
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
const wxString & GetComment(int aIdx) const
Definition: title_block.h:110
const TITLE_BLOCK & GetTitleBlock() const
Definition: sch_screen.h:190
wxString GetFileName() const
Helper to retrieve the filename from the root sheet screen.
Definition: schematic.cpp:132
TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout,...
Definition: title_block.h:40
wxString GetBuildVersion()
Get the full KiCad version string.
const wxString & GetRevision() const
Definition: title_block.h:89
const wxString & GetCompany() const
Definition: title_block.h:99
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
const wxString & GetDate() const
Definition: title_block.h:79
const wxString & GetTitle() const
Definition: title_block.h:65
wxString DateAndTime()
Definition: string.cpp:373

References DateAndTime(), GetBuildVersion(), TITLE_BLOCK::GetComment(), TITLE_BLOCK::GetCompany(), TITLE_BLOCK::GetDate(), SCHEMATIC::GetFileName(), SCH_SCREEN::GetFileName(), TITLE_BLOCK::GetRevision(), SCHEMATIC::GetSheets(), TITLE_BLOCK::GetTitle(), SCH_SCREEN::GetTitleBlock(), NETLIST_EXPORTER::m_schematic, and node().

Referenced by makeRoot().

◆ makeLibParts()

XNODE * NETLIST_EXPORTER_GENERIC::makeLibParts ( )
protected

Fill out an XML node with the unique library parts and returns it.

Returns
XNODE* - the library parts nodes

Definition at line 400 of file netlist_exporter_generic.cpp.

401 {
402  XNODE* xlibparts = node( "libparts" ); // auto_ptr
403 
404  LIB_PINS pinList;
405  LIB_FIELDS fieldList;
406 
407  m_libraries.clear();
408 
409  for( auto lcomp : m_LibParts )
410  {
411  wxString libNickname = lcomp->GetLibId().GetLibNickname();;
412 
413  // The library nickname will be empty if the cache library is used.
414  if( !libNickname.IsEmpty() )
415  m_libraries.insert( libNickname ); // inserts component's library if unique
416 
417  XNODE* xlibpart;
418  xlibparts->AddChild( xlibpart = node( "libpart" ) );
419  xlibpart->AddAttribute( "lib", libNickname );
420  xlibpart->AddAttribute( "part", lcomp->GetName() );
421 
422  //----- show the important properties -------------------------
423  if( !lcomp->GetDescription().IsEmpty() )
424  xlibpart->AddChild( node( "description", lcomp->GetDescription() ) );
425 
426  if( !lcomp->GetDatasheetField().GetText().IsEmpty() )
427  xlibpart->AddChild( node( "docs", lcomp->GetDatasheetField().GetText() ) );
428 
429  // Write the footprint list
430  if( lcomp->GetFootprints().GetCount() )
431  {
432  XNODE* xfootprints;
433  xlibpart->AddChild( xfootprints = node( "footprints" ) );
434 
435  for( unsigned i=0; i<lcomp->GetFootprints().GetCount(); ++i )
436  {
437  xfootprints->AddChild( node( "fp", lcomp->GetFootprints()[i] ) );
438  }
439  }
440 
441  //----- show the fields here ----------------------------------
442  fieldList.clear();
443  lcomp->GetFields( fieldList );
444 
445  XNODE* xfields;
446  xlibpart->AddChild( xfields = node( "fields" ) );
447 
448  for( unsigned i=0; i<fieldList.size(); ++i )
449  {
450  if( !fieldList[i].GetText().IsEmpty() )
451  {
452  XNODE* xfield;
453  xfields->AddChild( xfield = node( "field", fieldList[i].GetText() ) );
454  xfield->AddAttribute( "name", fieldList[i].GetCanonicalName() );
455  }
456  }
457 
458  //----- show the pins here ------------------------------------
459  pinList.clear();
460  lcomp->GetPins( pinList, 0, 0 );
461 
462  /* we must erase redundant Pins references in pinList
463  * These redundant pins exist because some pins
464  * are found more than one time when a component has
465  * multiple parts per package or has 2 representations (DeMorgan conversion)
466  * For instance, a 74ls00 has DeMorgan conversion, with different pin shapes,
467  * and therefore each pin appears 2 times in the list.
468  * Common pins (VCC, GND) can also be found more than once.
469  */
470  sort( pinList.begin(), pinList.end(), sortPinsByNumber );
471  for( int ii = 0; ii < (int)pinList.size()-1; ii++ )
472  {
473  if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
474  { // 2 pins have the same number, remove the redundant pin at index i+1
475  pinList.erase(pinList.begin() + ii + 1);
476  ii--;
477  }
478  }
479 
480  if( pinList.size() )
481  {
482  XNODE* pins;
483 
484  xlibpart->AddChild( pins = node( "pins" ) );
485  for( unsigned i=0; i<pinList.size(); ++i )
486  {
487  XNODE* pin;
488 
489  pins->AddChild( pin = node( "pin" ) );
490  pin->AddAttribute( "num", pinList[i]->GetNumber() );
491  pin->AddAttribute( "name", pinList[i]->GetName() );
492  pin->AddAttribute( "type", pinList[i]->GetCanonicalElectricalTypeName() );
493 
494  // caution: construction work site here, drive slowly
495  }
496  }
497  }
498 
499  return xlibparts;
500 }
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used.
std::set< wxString > m_libraries
Set of library nicknames.
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:218
static bool sortPinsByNumber(LIB_PIN *aPin1, LIB_PIN *aPin2)

References NETLIST_EXPORTER::m_LibParts, m_libraries, node(), and sortPinsByNumber().

Referenced by makeRoot().

◆ makeLibraries()

XNODE * NETLIST_EXPORTER_GENERIC::makeLibraries ( )
protected

Fill out an XML node with a list of used libraries and returns it.

Must have called makeGenericLibParts() before this function.

Returns
XNODE* - the library nodes

Definition at line 376 of file netlist_exporter_generic.cpp.

377 {
378  XNODE* xlibs = node( "libraries" ); // auto_ptr
379 
380  for( std::set<wxString>::iterator it = m_libraries.begin(); it!=m_libraries.end(); ++it )
381  {
382  wxString libNickname = *it;
383  XNODE* xlibrary;
384 
385  if( m_schematic->Prj().SchSymbolLibTable()->HasLibrary( libNickname ) )
386  {
387  xlibs->AddChild( xlibrary = node( "library" ) );
388  xlibrary->AddAttribute( "logical", libNickname );
389  xlibrary->AddChild( node(
390  "uri", m_schematic->Prj().SchSymbolLibTable()->GetFullURI( libNickname ) ) );
391  }
392 
393  // @todo: add more fun stuff here
394  }
395 
396  return xlibs;
397 }
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
std::set< wxString > m_libraries
Set of library nicknames.
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
PROJECT & Prj() const
Return a reference to the project this schematic is part of.
Definition: schematic.h:77

References m_libraries, NETLIST_EXPORTER::m_schematic, node(), and SCHEMATIC::Prj().

Referenced by makeRoot().

◆ makeListOfNets()

XNODE * NETLIST_EXPORTER_GENERIC::makeListOfNets ( )
protected

Fill out an XML node with a list of nets and returns it.

Returns
XNODE* - the list of nets nodes

Definition at line 503 of file netlist_exporter_generic.cpp.

504 {
505  XNODE* xnets = node( "nets" ); // auto_ptr if exceptions ever get used.
506  wxString netCodeTxt;
507  wxString netName;
508  wxString ref;
509 
510  XNODE* xnet = 0;
511 
512  /* output:
513  <net code="123" name="/cfcard.sch/WAIT#">
514  <node ref="R23" pin="1"/>
515  <node ref="U18" pin="12"/>
516  </net>
517  */
518 
519  int code = 0;
520 
521  for( const auto& it : m_schematic->ConnectionGraph()->GetNetMap() )
522  {
523  bool added = false;
524  wxString net_name = it.first.first;
525  auto subgraphs = it.second;
526 
527  // Code starts at 1
528  code++;
529 
530  XNODE* xnode;
531  std::vector<std::pair<SCH_PIN*, SCH_SHEET_PATH>> sorted_items;
532 
533  for( auto subgraph : subgraphs )
534  {
535  auto sheet = subgraph->m_sheet;
536 
537  for( auto item : subgraph->m_items )
538  if( item->Type() == SCH_PIN_T )
539  sorted_items.emplace_back(
540  std::make_pair( static_cast<SCH_PIN*>( item ), sheet ) );
541  }
542 
543  // Netlist ordering: Net name, then ref des, then pin name
544  std::sort( sorted_items.begin(), sorted_items.end(), [] ( auto a, auto b ) {
545  auto ref_a = a.first->GetParentComponent()->GetRef( &a.second );
546  auto ref_b = b.first->GetParentComponent()->GetRef( &b.second );
547 
548  if( ref_a == ref_b )
549  return a.first->GetNumber() < b.first->GetNumber();
550 
551  return ref_a < ref_b;
552  } );
553 
554  // Some duplicates can exist, for example on multi-unit parts with duplicated
555  // pins across units. If the user connects the pins on each unit, they will
556  // appear on separate subgraphs. Remove those here:
557  sorted_items.erase( std::unique( sorted_items.begin(), sorted_items.end(),
558  [] ( auto a, auto b ) {
559  auto ref_a = a.first->GetParentComponent()->GetRef( &a.second );
560  auto ref_b = b.first->GetParentComponent()->GetRef( &b.second );
561 
562  return ref_a == ref_b && a.first->GetNumber() == b.first->GetNumber();
563  } ), sorted_items.end() );
564 
565  for( const auto& pair : sorted_items )
566  {
567  SCH_PIN* pin = pair.first;
568  SCH_SHEET_PATH sheet = pair.second;
569 
570  auto refText = pin->GetParentComponent()->GetRef( &sheet );
571  const auto& pinText = pin->GetNumber();
572 
573  // Skip power symbols and virtual components
574  if( refText[0] == wxChar( '#' ) )
575  continue;
576 
577  if( !added )
578  {
579  xnets->AddChild( xnet = node( "net" ) );
580  netCodeTxt.Printf( "%d", code );
581  xnet->AddAttribute( "code", netCodeTxt );
582  xnet->AddAttribute( "name", net_name );
583 
584  added = true;
585  }
586 
587  xnet->AddChild( xnode = node( "node" ) );
588  xnode->AddAttribute( "ref", refText );
589  xnode->AddAttribute( "pin", pinText );
590 
591  wxString pinName;
592 
593  if( pin->GetName() != "~" ) // ~ is a char used to code empty strings in libs.
594  pinName = pin->GetName();
595 
596  if( !pinName.IsEmpty() )
597  xnode->AddAttribute( "pinfunction", pinName );
598  }
599  }
600 
601  return xnets;
602 }
const wxString & GetName() const
Definition: sch_pin.h:104
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
SCHEMATIC * m_schematic
The schematic we're generating a netlist for.
CONNECTION_GRAPH * ConnectionGraph() const
Definition: schematic.h:132
const wxString & GetNumber() const
Definition: sch_pin.h:106
const NET_MAP & GetNetMap() const
SCH_SHEET_PATH.
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false)
Return the reference for the given sheet path.
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
SCH_COMPONENT * GetParentComponent() const
Definition: sch_pin.cpp:81

References SCHEMATIC::ConnectionGraph(), SCH_PIN::GetName(), CONNECTION_GRAPH::GetNetMap(), SCH_PIN::GetNumber(), SCH_PIN::GetParentComponent(), SCH_COMPONENT::GetRef(), NETLIST_EXPORTER::m_schematic, node(), and SCH_PIN_T.

Referenced by makeRoot().

◆ makeRoot()

XNODE * NETLIST_EXPORTER_GENERIC::makeRoot ( int  aCtl = GNL_ALL)
protected

Build the entire document tree for the generic export.

This is factored out here so we can write the tree in either S-expression file format or in XML if we put the tree built here into a wxXmlDocument.

Parameters
aCtl- a bitset or-ed together from GNL_ENUM values
Returns
XNODE* - the root nodes

Definition at line 51 of file netlist_exporter_generic.cpp.

52 {
53  XNODE* xroot = node( "export" );
54 
55  xroot->AddAttribute( "version", "D" );
56 
57  if( aCtl & GNL_HEADER )
58  // add the "design" header
59  xroot->AddChild( makeDesignHeader() );
60 
61  if( aCtl & GNL_COMPONENTS )
62  xroot->AddChild( makeComponents( aCtl ) );
63 
64  if( aCtl & GNL_PARTS )
65  xroot->AddChild( makeLibParts() );
66 
67  if( aCtl & GNL_LIBRARIES )
68  // must follow makeGenericLibParts()
69  xroot->AddChild( makeLibraries() );
70 
71  if( aCtl & GNL_NETS )
72  xroot->AddChild( makeListOfNets() );
73 
74  return xroot;
75 }
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
A convenience function that creates a new XNODE with an optional textual child.
XNODE * makeDesignHeader()
Fills out a project "design" header into an XML node.
XNODE * makeComponents(unsigned aCtl)
XNODE holds an XML or S-expression element.
Definition: xnode.h:43
XNODE * makeLibraries()
Fill out an XML node with a list of used libraries and returns it.
XNODE * makeListOfNets()
Fill out an XML node with a list of nets and returns it.
XNODE * makeLibParts()
Fill out an XML node with the unique library parts and returns it.

References GNL_COMPONENTS, GNL_HEADER, GNL_LIBRARIES, GNL_NETS, GNL_PARTS, makeComponents(), makeDesignHeader(), makeLibParts(), makeLibraries(), makeListOfNets(), and node().

Referenced by NETLIST_EXPORTER_KICAD::Format(), and WriteNetlist().

◆ node()

XNODE * NETLIST_EXPORTER_GENERIC::node ( const wxString &  aName,
const wxString &  aTextualContent = wxEmptyString 
)
protected

A convenience function that creates a new XNODE with an optional textual child.

It also provides some insulation from a possible change in XML library.

Parameters
aNameis the name to associate with a new node of type wxXML_ELEMENT_NODE.
aTextualContentis optional, and if given is the text to include in a child of the returned node, and has type wxXML_TEXT_NODE.

Definition at line 605 of file netlist_exporter_generic.cpp.

607 {
608  XNODE* n = new XNODE( wxXML_ELEMENT_NODE, aName );
609 
610  if( aTextualContent.Len() > 0 ) // excludes wxEmptyString, the parameter's default value
611  n->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
612 
613  return n;
614 }
XNODE holds an XML or S-expression element.
Definition: xnode.h:43

Referenced by addComponentFields(), makeComponents(), makeDesignHeader(), makeLibParts(), makeLibraries(), makeListOfNets(), and makeRoot().

◆ WriteNetlist()

bool NETLIST_EXPORTER_GENERIC::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions 
)
overridevirtual

Write generic netlist to aOutFileName.

Parameters
aOutFileNameis the file name to write.
aNetlistOptionsare the options used to control the netlist output.
Returns
true if the netlist was written successfully.

Reimplemented from NETLIST_EXPORTER.

Reimplemented in NETLIST_EXPORTER_KICAD.

Definition at line 39 of file netlist_exporter_generic.cpp.

41 {
42  // output the XML format netlist.
43  wxXmlDocument xdoc;
44 
45  xdoc.SetRoot( makeRoot( GNL_ALL ) );
46 
47  return xdoc.Save( aOutFileName, 2 /* indent bug, today was ignored by wxXml lib */ );
48 }
XNODE * makeRoot(int aCtl=GNL_ALL)
Build the entire document tree for the generic export.
#define GNL_ALL

References GNL_ALL, and makeRoot().

Member Data Documentation

◆ m_LibParts

std::set<LIB_PART*, LIB_PART_LESS_THAN> NETLIST_EXPORTER::m_LibParts
protectedinherited

unique library parts used.

LIB_PART items are s orted by names

Definition at line 114 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER::CreatePinList(), NETLIST_EXPORTER::findNextComponent(), makeComponents(), makeLibParts(), and NETLIST_EXPORTER_PSPICE::ProcessNetlist().

◆ m_libraries

std::set< wxString > NETLIST_EXPORTER_GENERIC::m_libraries
private

Set of library nicknames.

Definition at line 65 of file netlist_exporter_generic.h.

Referenced by makeLibParts(), and makeLibraries().

◆ m_ReferencesAlreadyFound

UNIQUE_STRINGS NETLIST_EXPORTER::m_ReferencesAlreadyFound
protectedinherited

Used for "multi parts per package" components, avoids processing a lib component more than once.

Definition at line 110 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER::findNextComponent(), makeComponents(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

◆ m_schematic

◆ m_SortedComponentPinList

std::vector<PIN_INFO> NETLIST_EXPORTER::m_SortedComponentPinList
protectedinherited

Used to temporarily store and filter the list of pins of a schematic component when generating schematic component data in netlist (comp section).

No ownership of members. TODO(snh): Descope this object

Definition at line 106 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER::CreatePinList(), NETLIST_EXPORTER::eraseDuplicatePins(), NETLIST_EXPORTER::findAllUnitsOfComponent(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().


The documentation for this class was generated from the following files: