KiCad PCB EDA Suite
NETLIST_EXPORTER_KICAD Class Reference

Class NETLIST_EXPORTER_KICAD generates the kicad netlist format supported by pcbnew. More...

#include <netlist_exporter_kicad.h>

Inheritance diagram for NETLIST_EXPORTER_KICAD:
NETLIST_EXPORTER_GENERIC NETLIST_EXPORTER

Public Member Functions

 NETLIST_EXPORTER_KICAD (NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs)
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions) override
 Function WriteNetlist writes to specified output file. More...
 
void Format (OUTPUTFORMATTER *aOutputFormatter, int aCtl)
 Function Format outputs this s-expression netlist into aOutputFormatter. More...
 

Static Public Member Functions

static wxString MakeCommandLine (const wxString &aFormatString, const wxString &aTempfile, 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)
 Function node is a convenience function that creates a new XNODE with an optional textual child. More...
 
XNODEmakeRoot (int aCtl=GNL_ALL)
 Function makeGenericRoot builds the entire document tree for the generic export. More...
 
XNODEmakeComponents ()
 Function makeComponents. More...
 
XNODEmakeDesignHeader ()
 Function makeDesignHeader fills out a project "design" header into an XML node. More...
 
XNODEmakeLibParts ()
 Function makeLibParts fills out an XML node with the unique library parts and returns it. More...
 
XNODEmakeListOfNets ()
 Function makeListOfNets fills out an XML node with a list of nets and returns it. More...
 
XNODEmakeLibraries ()
 Function makeLibraries fills 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)
 
SCH_COMPONENTfindNextComponentAndCreatePinList (EDA_ITEM *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)
 
void eraseDuplicatePins ()
 Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i.e. More...
 
bool addPinToComponentPinList (SCH_COMPONENT *Component, SCH_SHEET_PATH *sheet, LIB_PIN *PinEntry)
 Function addPinToComponentPinList adds a new pin description to the pin list m_SortedComponentPinList. More...
 
void findAllUnitsOfComponent (SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
 Function findAllUnitsOfComponent is used for "multiple parts per package" components. More...
 

Static Protected Member Functions

static void sprintPinNetName (wxString &aResult, const wxString &aNetNameFormat, NETLIST_OBJECT *aPin, bool aUseNetcodeAsNetName=false)
 Function sprintPinNetName formats the net name for aPin using aNetNameFormat into aResult. More...
 

Protected Attributes

NETLIST_OBJECT_LISTm_masterList
 
PART_LIBSm_libs
 yes ownership, connected items flat list More...
 
NETLIST_OBJECTS m_SortedComponentPinList
 no ownership 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. LIB_PART items are sorted by names More...
 
std::set< void * > m_Libraries
 unique libraries used More...
 

Detailed Description

Class NETLIST_EXPORTER_KICAD generates the kicad netlist format supported by pcbnew.

It is basically the generic netlist format just formatted slightly different.

Definition at line 38 of file netlist_exporter_kicad.h.

Constructor & Destructor Documentation

NETLIST_EXPORTER_KICAD::NETLIST_EXPORTER_KICAD ( NETLIST_OBJECT_LIST aMasterList,
PART_LIBS aLibs 
)
inline

Definition at line 41 of file netlist_exporter_kicad.h.

41  :
42  NETLIST_EXPORTER_GENERIC( aMasterList, aLibs )
43  {
44  }
NETLIST_EXPORTER_GENERIC(NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs)

Member Function Documentation

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

Definition at line 88 of file netlist_exporter_generic.cpp.

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

Referenced by NETLIST_EXPORTER_GENERIC::makeComponents().

89 {
90  if( comp->GetUnitCount() > 1 )
91  {
92  // Sadly, each unit of a component can have its own unique fields. This block
93  // finds the last non blank field and records it. Last guy wins and the order
94  // of units occuring in a schematic hierarchy is variable. Therefore user
95  // is best off setting fields into only one unit. But this scavenger algorithm
96  // will find any non blank fields in all units and use the last non-blank field
97  // for each unique field name.
98 
99  COMP_FIELDS fields;
100  wxString ref = comp->GetRef( aSheet );
101 
102  SCH_SHEET_LIST sheetList( g_RootSheet );
103 
104  for( unsigned i = 0; i < sheetList.size(); i++ )
105  {
106  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
107  {
108  if( item->Type() != SCH_COMPONENT_T )
109  continue;
110 
111  SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
112 
113  wxString ref2 = comp2->GetRef( &sheetList[i] );
114 
115  if( ref2.CmpNoCase( ref ) != 0 )
116  continue;
117 
118  // The last guy wins. User should only set fields in any one unit.
119 
120  if( !comp2->GetField( VALUE )->IsVoid() )
121  fields.value = comp2->GetField( VALUE )->GetText();
122 
123  if( !comp2->GetField( FOOTPRINT )->IsVoid() )
124  fields.footprint = comp2->GetField( FOOTPRINT )->GetText();
125 
126  if( !comp2->GetField( DATASHEET )->IsVoid() )
127  fields.datasheet = comp2->GetField( DATASHEET )->GetText();
128 
129  for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp2->GetFieldCount(); ++fldNdx )
130  {
131  SCH_FIELD* f = comp2->GetField( fldNdx );
132 
133  if( f->GetText().size() )
134  {
135  fields.f[ f->GetName() ] = f->GetText();
136  }
137  }
138  }
139  }
140 
141  xcomp->AddChild( node( "value", fields.value ) );
142 
143  if( fields.footprint.size() )
144  xcomp->AddChild( node( "footprint", fields.footprint ) );
145 
146  if( fields.datasheet.size() )
147  xcomp->AddChild( node( "datasheet", fields.datasheet ) );
148 
149  if( fields.f.size() )
150  {
151  XNODE* xfields;
152  xcomp->AddChild( xfields = node( "fields" ) );
153 
154  // non MANDATORY fields are output alphabetically
155  for( std::map< wxString, wxString >::const_iterator it = fields.f.begin();
156  it != fields.f.end(); ++it )
157  {
158  XNODE* xfield;
159  xfields->AddChild( xfield = node( "field", it->second ) );
160  xfield->AddAttribute( "name", it->first );
161  }
162  }
163  }
164  else
165  {
166  xcomp->AddChild( node( "value", comp->GetField( VALUE )->GetText() ) );
167 
168  if( !comp->GetField( FOOTPRINT )->IsVoid() )
169  xcomp->AddChild( node( "footprint", comp->GetField( FOOTPRINT )->GetText() ) );
170 
171  if( !comp->GetField( DATASHEET )->IsVoid() )
172  xcomp->AddChild( node( "datasheet", comp->GetField( DATASHEET )->GetText() ) );
173 
174  // Export all user defined fields within the component,
175  // which start at field index MANDATORY_FIELDS. Only output the <fields>
176  // container element if there are any <field>s.
177  if( comp->GetFieldCount() > MANDATORY_FIELDS )
178  {
179  XNODE* xfields;
180  xcomp->AddChild( xfields = node( "fields" ) );
181 
182  for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
183  {
184  SCH_FIELD* f = comp->GetField( fldNdx );
185 
186  // only output a field if non empty and not just "~"
187  if( !f->IsVoid() )
188  {
189  XNODE* xfield;
190  xfields->AddChild( xfield = node( "field", f->GetText() ) );
191  xfield->AddAttribute( "name", f->GetName() );
192  }
193  }
194  }
195  }
196 }
Class SCH_SHEET_LIST.
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
wxString GetName(bool aUseDefaultName=true) const
Function GetName returns the field name.
Definition: sch_field.cpp:473
name of datasheet
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
Function node is a convenience function that creates a new XNODE with an optional textual child...
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.h:116
int GetUnitCount() const
Return the number of units per package of the symbol.
EDA_ITEM * Next() const
Definition: base_struct.h:220
Field Name Module PCB, i.e. "16DIP300".
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
Holder for multi-unit component fields.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
Field Value of part, i.e. "3.3K".
int GetFieldCount() const
Return the number of fields in this symbol.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
std::map< wxString, wxString > f
bool NETLIST_EXPORTER::addPinToComponentPinList ( SCH_COMPONENT Component,
SCH_SHEET_PATH sheet,
LIB_PIN PinEntry 
)
protectedinherited

Function addPinToComponentPinList adds a new pin description to the pin list m_SortedComponentPinList.

A pin description is a pointer to the corresponding structure created by BuildNetList() in the table g_NetObjectslist.

Definition at line 237 of file netlist_exporter.cpp.

References DisplayError(), NETLIST_OBJECT_LIST::GetItem(), LIB_PIN::GetNumber(), NETLIST_OBJECT::m_Link, NETLIST_EXPORTER::m_masterList, NETLIST_OBJECT::m_PinNum, NETLIST_OBJECT::m_SheetPath, NETLIST_EXPORTER::m_SortedComponentPinList, NETLIST_OBJECT::m_Type, MAXPIN, and NET_PIN.

Referenced by NETLIST_EXPORTER::findAllUnitsOfComponent(), and NETLIST_EXPORTER::findNextComponentAndCreatePinList().

239 {
240  // Search the PIN description for Pin in g_NetObjectslist
241  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
242  {
243  NETLIST_OBJECT* pin = m_masterList->GetItem( ii );
244 
245  if( pin->m_Type != NET_PIN )
246  continue;
247 
248  if( pin->m_Link != aComponent )
249  continue;
250 
251  if( pin->m_PinNum != aPin->GetNumber() )
252  continue;
253 
254  // most expensive test at the end.
255  if( pin->m_SheetPath != *aSheetPath )
256  continue;
257 
258  m_SortedComponentPinList.push_back( pin );
259 
260  if( m_SortedComponentPinList.size() >= MAXPIN )
261  {
262  // Log message for Internal error
263  DisplayError( NULL, wxT( "addPinToComponentPinList err: MAXPIN reached" ) );
264  }
265 
266  return true; // we're done, we appended.
267  }
268 
269  return false;
270 }
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
#define MAXPIN
Definition: netlist.h:53
SCH_SHEET_PATH m_SheetPath
NETLIST_ITEM_T m_Type
NETLIST_OBJECT_LIST * m_masterList
NETLIST_OBJECTS m_SortedComponentPinList
no ownership
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
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 273 of file netlist_exporter.cpp.

References NETLIST_EXPORTER::m_SortedComponentPinList, and PAD_CONNECT.

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

274 {
275  for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
276  {
277  if( m_SortedComponentPinList[ii] == NULL ) /* already deleted */
278  continue;
279 
280  /* Search for duplicated pins
281  * If found, remove duplicates. The priority is to keep connected pins
282  * and remove unconnected
283  * - So this allows (for instance when using multi op amps per package
284  * - to connect only one op amp to power
285  * Because the pin list is sorted by m_PinNum value, duplicated pins
286  * are necessary successive in list
287  */
288  int idxref = ii;
289  for( unsigned jj = ii + 1; jj < m_SortedComponentPinList.size(); jj++ )
290  {
291  if( m_SortedComponentPinList[jj] == NULL ) // Already removed
292  continue;
293 
294  // if other pin num, stop search,
295  // because all pins having the same number are consecutive in list.
296  if( m_SortedComponentPinList[idxref]->m_PinNum != m_SortedComponentPinList[jj]->m_PinNum )
297  break;
298 
299  if( m_SortedComponentPinList[idxref]->GetConnectionType() == PAD_CONNECT )
300  {
301  m_SortedComponentPinList[jj]->m_Flag = 1;
302  m_SortedComponentPinList[jj] = NULL;
303  }
304  else /* the reference pin is not connected: remove this pin if the
305  * other pin is connected */
306  {
307  if( m_SortedComponentPinList[jj]->GetConnectionType() == PAD_CONNECT )
308  {
309  m_SortedComponentPinList[idxref]->m_Flag = 1;
310  m_SortedComponentPinList[idxref] = NULL;
311  idxref = jj;
312  }
313  else // the 2 pins are not connected: remove the tested pin,
314  { // and continue ...
315  m_SortedComponentPinList[jj]->m_Flag = 1;
316  m_SortedComponentPinList[jj] = NULL;
317  }
318  }
319  }
320  }
321 }
NETLIST_OBJECTS m_SortedComponentPinList
no ownership
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 324 of file netlist_exporter.cpp.

References NETLIST_EXPORTER::addPinToComponentPinList(), g_RootSheet, SCH_COMPONENT::GetConvert(), LIB_PART::GetNextPin(), SCH_COMPONENT::GetRef(), SCH_COMPONENT::GetUnitSelection(), LIB_PIN_T, and SCH_COMPONENT_T.

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

326 {
327  wxString ref = aComponent->GetRef( aSheetPath );
328  wxString ref2;
329 
330  SCH_SHEET_LIST sheetList( g_RootSheet );
331 
332  for( unsigned i = 0; i < sheetList.size(); i++ )
333  {
334  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
335  {
336  if( item->Type() != SCH_COMPONENT_T )
337  continue;
338 
339  SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
340 
341  ref2 = comp2->GetRef( &sheetList[i] );
342 
343  if( ref2.CmpNoCase( ref ) != 0 )
344  continue;
345 
346  int unit2 = comp2->GetUnitSelection( &sheetList[i] ); // slow
347 
348  for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) )
349  {
350  wxASSERT( pin->Type() == LIB_PIN_T );
351 
352  if( pin->GetUnit() && pin->GetUnit() != unit2 )
353  continue;
354 
355  if( pin->GetConvert() && pin->GetConvert() != comp2->GetConvert() )
356  continue;
357 
358  // A suitable pin is found: add it to the current list
359  addPinToComponentPinList( comp2, &sheetList[i], pin );
360  }
361  }
362  }
363 }
Class SCH_SHEET_LIST.
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
EDA_ITEM * Next() const
Definition: base_struct.h:220
int GetConvert() const
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
bool addPinToComponentPinList(SCH_COMPONENT *Component, SCH_SHEET_PATH *sheet, LIB_PIN *PinEntry)
Function addPinToComponentPinList adds a new pin description to the pin list m_SortedComponentPinList...
SCH_COMPONENT * NETLIST_EXPORTER::findNextComponent ( EDA_ITEM aItem,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Definition at line 100 of file netlist_exporter.cpp.

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

Referenced by NETLIST_EXPORTER_GENERIC::makeComponents().

101 {
102  wxString ref;
103 
104  // continue searching from the middle of a linked list (the draw list)
105  for( ; aItem; aItem = aItem->Next() )
106  {
107  if( aItem->Type() != SCH_COMPONENT_T )
108  continue;
109 
110  // found next component
111  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
112 
113  // Power symbols and other components which have the reference starting
114  // with "#" are not included in netlist (pseudo or virtual components)
115  ref = comp->GetRef( aSheetPath );
116 
117  if( ref[0] == wxChar( '#' ) )
118  continue;
119 
120  // if( Component->m_FlagControlMulti == 1 )
121  // continue; /* yes */
122  // removed because with multiple instances of one schematic
123  // (several sheets pointing to 1 screen), this will be erroneously be
124  // toggled.
125 
126  LIB_PART* part = comp->GetPartRef().lock().get();
127 
128  if( !part )
129  continue;
130 
131  // If component is a "multi parts per package" type
132  if( part->GetUnitCount() > 1 )
133  {
134  // test if this reference has already been processed, and if so skip
135  if( m_ReferencesAlreadyFound.Lookup( ref ) )
136  continue;
137  }
138 
139  // record the usage of this library component entry.
140  m_LibParts.insert( part ); // rejects non-unique pointers
141 
142  return comp;
143  }
144 
145  return NULL;
146 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool Lookup(const wxString &aString)
Function Lookup returns true if aString already exists in the set, otherwise returns false and adds a...
PART_REF & GetPartRef()
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once...
EDA_ITEM * Next() const
Definition: base_struct.h:220
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used. LIB_PART items are sorted by names
Class LIB_PART defines a library part object.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
int GetUnitCount() const
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
SCH_COMPONENT * NETLIST_EXPORTER::findNextComponentAndCreatePinList ( EDA_ITEM 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 157 of file netlist_exporter.cpp.

References NETLIST_EXPORTER::addPinToComponentPinList(), NETLIST_EXPORTER::eraseDuplicatePins(), NETLIST_EXPORTER::findAllUnitsOfComponent(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetPartRef(), LIB_PART::GetPins(), SCH_COMPONENT::GetRef(), LIB_PART::GetUnitCount(), SCH_COMPONENT::GetUnitSelection(), LIB_PIN_T, UNIQUE_STRINGS::Lookup(), NETLIST_EXPORTER::m_LibParts, NETLIST_EXPORTER::m_ReferencesAlreadyFound, NETLIST_EXPORTER::m_SortedComponentPinList, EDA_ITEM::Next(), SCH_COMPONENT_T, MULTIVECTOR< T, FIRST_TYPE_VAL, LAST_TYPE_VAL >::sort(), sortPinsByNum(), and EDA_ITEM::Type().

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

159 {
160  wxString ref;
161 
162  m_SortedComponentPinList.clear();
163 
164  // continue searching from the middle of a linked list (the draw list)
165  for( ; aItem; aItem = aItem->Next() )
166  {
167  if( aItem->Type() != SCH_COMPONENT_T )
168  continue;
169 
170  // found next component
171  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
172 
173  // Power symbols and other components which have the reference starting
174  // with "#" are not included in netlist (pseudo or virtual components)
175  ref = comp->GetRef( aSheetPath );
176 
177  if( ref[0] == wxChar( '#' ) )
178  continue;
179 
180  // if( Component->m_FlagControlMulti == 1 )
181  // continue; /* yes */
182  // removed because with multiple instances of one schematic
183  // (several sheets pointing to 1 screen), this will be erroneously be
184  // toggled.
185 
186  LIB_PART* part = comp->GetPartRef().lock().get();
187 
188  if( !part )
189  continue;
190 
191  // If component is a "multi parts per package" type
192  if( part->GetUnitCount() > 1 )
193  {
194  // test if this reference has already been processed, and if so skip
195  if( m_ReferencesAlreadyFound.Lookup( ref ) )
196  continue;
197 
198  // Collect all pins for this reference designator by searching
199  // the entire design for other parts with the same reference designator.
200  // This is only done once, it would be too expensive otherwise.
201  findAllUnitsOfComponent( comp, part, aSheetPath );
202  }
203 
204  else // entry->GetUnitCount() <= 1 means one part per package
205  {
206  LIB_PINS pins; // constructed once here
207 
208  part->GetPins( pins, comp->GetUnitSelection( aSheetPath ), comp->GetConvert() );
209 
210  for( size_t i = 0; i < pins.size(); i++ )
211  {
212  LIB_PIN* pin = pins[i];
213 
214  wxASSERT( pin->Type() == LIB_PIN_T );
215 
216  addPinToComponentPinList( comp, aSheetPath, pin );
217  }
218  }
219 
220  // Sort pins in m_SortedComponentPinList by pin number
221  sort( m_SortedComponentPinList.begin(),
223 
224  // Remove duplicate Pins in m_SortedComponentPinList
226 
227  // record the usage of this library component entry.
228  m_LibParts.insert( part ); // rejects non-unique pointers
229 
230  return comp;
231  }
232 
233  return NULL;
234 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:212
bool Lookup(const wxString &aString)
Function Lookup returns true if aString already exists in the set, otherwise returns false and adds a...
PART_REF & GetPartRef()
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once...
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
EDA_ITEM * Next() const
Definition: base_struct.h:220
void findAllUnitsOfComponent(SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
Function findAllUnitsOfComponent is used for "multiple parts per package" components.
static bool sortPinsByNum(NETLIST_OBJECT *aPin1, NETLIST_OBJECT *aPin2)
Comparison routine for sorting by pin numbers.
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used. LIB_PART items are sorted by names
int GetConvert() const
Class LIB_PART defines a library part object.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
int GetUnitCount() const
NETLIST_OBJECTS m_SortedComponentPinList
no ownership
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:60
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
bool addPinToComponentPinList(SCH_COMPONENT *Component, SCH_SHEET_PATH *sheet, LIB_PIN *PinEntry)
Function addPinToComponentPinList adds a new pin description to the pin list m_SortedComponentPinList...
void eraseDuplicatePins()
Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i.e.
void NETLIST_EXPORTER_KICAD::Format ( OUTPUTFORMATTER aOutputFormatter,
int  aCtl 
)

Function Format outputs this s-expression netlist into aOutputFormatter.

Parameters
aOutputFormatteris the destination of the serialization to text.
aCtlis bit set composed by OR-ing together enum GNL bits, it allows ouputting a subset of the full document model.
Exceptions
IO_ERRORif any problems.

Definition at line 52 of file netlist_exporter_kicad.cpp.

References NETLIST_OBJECT_LIST::GetItem(), NETLIST_OBJECT::m_Flag, NETLIST_EXPORTER::m_masterList, and NETLIST_EXPORTER_GENERIC::makeRoot().

Referenced by SCH_EDIT_FRAME::OnUpdatePCB(), SCH_EDIT_FRAME::sendNetlist(), and WriteNetlist().

53 {
54  // Prepare list of nets generation
55  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
56  m_masterList->GetItem( ii )->m_Flag = 0;
57 
58  std::unique_ptr<XNODE> xroot( makeRoot( aCtl ) );
59 
60  xroot->Format( aOut, 0 );
61 }
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
NETLIST_OBJECT_LIST * m_masterList
XNODE * makeRoot(int aCtl=GNL_ALL)
Function makeGenericRoot builds the entire document tree for the generic export.
wxString NETLIST_EXPORTER::MakeCommandLine ( const wxString &  aFormatString,
const wxString &  aTempfile,
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.
aTempfileis the name of an input file to the external program.
aFinalFileis the name of an 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 50 of file netlist_exporter.cpp.

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

52 {
53  // Expand format symbols in the command line:
54  // %B => base filename of selected output file, minus path and extension.
55  // %P => project directory name, without trailing '/' or '\'.
56  // %I => full filename of the input file (the intermediate net file).
57  // %O => complete filename and path (but without extension) of the user chosen output file.
58 
59  wxString ret = aFormatString;
60  wxFileName in = aTempfile;
61  wxFileName out = aFinalFile;
62 
63  ret.Replace( wxT( "%P" ), aProjectPath.GetData(), true );
64  ret.Replace( wxT( "%B" ), out.GetName().GetData(), true );
65  ret.Replace( wxT( "%I" ), in.GetFullPath().GetData(), true );
66  ret.Replace( wxT( "%O" ), out.GetFullPath().GetData(), true );
67 
68  return ret;
69 }
XNODE * NETLIST_EXPORTER_GENERIC::makeComponents ( )
protectedinherited

Function makeComponents.

Returns
XNODE* - returns a sub-tree holding all the schematic components.

Definition at line 199 of file netlist_exporter_generic.cpp.

References NETLIST_EXPORTER_GENERIC::addComponentFields(), UNIQUE_STRINGS::Clear(), PART_LIBS::FindLibPart(), NETLIST_EXPORTER::findNextComponent(), g_RootSheet, LIB_PART::GetLib(), SCH_COMPONENT::GetLibId(), LIB_ID::GetLibItemName(), PART_LIB::GetLogicalName(), SCH_COMPONENT::GetRef(), EDA_ITEM::GetTimeStamp(), NETLIST_EXPORTER::m_libs, NETLIST_EXPORTER::m_ReferencesAlreadyFound, NETLIST_EXPORTER_GENERIC::node(), and timeStamp().

Referenced by NETLIST_EXPORTER_GENERIC::makeRoot().

200 {
201  XNODE* xcomps = node( "components" );
202 
203  wxString timeStamp;
204 
206 
207  SCH_SHEET_LIST sheetList( g_RootSheet );
208 
209  // Output is xml, so there is no reason to remove spaces from the field values.
210  // And XML element names need not be translated to various languages.
211 
212  for( unsigned i = 0; i < sheetList.size(); i++ )
213  {
214  for( EDA_ITEM* schItem = sheetList[i].LastDrawList(); schItem; schItem = schItem->Next() )
215  {
216  SCH_COMPONENT* comp = findNextComponent( schItem, &sheetList[i] );
217  if( !comp )
218  break; // No component left
219 
220  schItem = comp;
221 
222  XNODE* xcomp; // current component being constructed
223 
224  // Output the component's elements in order of expected access frequency.
225  // This may not always look best, but it will allow faster execution
226  // under XSL processing systems which do sequential searching within
227  // an element.
228 
229  xcomps->AddChild( xcomp = node( "comp" ) );
230  xcomp->AddAttribute( "ref", comp->GetRef( &sheetList[i] ) );
231 
232  addComponentFields( xcomp, comp, &sheetList[i] );
233 
234  XNODE* xlibsource;
235  xcomp->AddChild( xlibsource = node( "libsource" ) );
236 
237  // "logical" library name, which is in anticipation of a better search
238  // algorithm for parts based on "logical_lib.part" and where logical_lib
239  // is merely the library name minus path and extension.
240  LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() );
241  if( part )
242  xlibsource->AddAttribute( "lib", part->GetLib()->GetLogicalName() );
243 
244  // We only want the symbol name, not the full LIB_ID.
245  xlibsource->AddAttribute( "part", comp->GetLibId().GetLibItemName() );
246 
247  XNODE* xsheetpath;
248 
249  xcomp->AddChild( xsheetpath = node( "sheetpath" ) );
250  xsheetpath->AddAttribute( "names", sheetList[i].PathHumanReadable() );
251  xsheetpath->AddAttribute( "tstamps", sheetList[i].Path() );
252 
253  timeStamp.Printf( "%8.8lX", (unsigned long)comp->GetTimeStamp() );
254  xcomp->AddChild( node( "tstamp", timeStamp ) );
255  }
256  }
257 
258  return xcomps;
259 }
PART_LIB * GetLib()
Class SCH_SHEET_LIST.
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)
Function node is a convenience function that creates a new XNODE with an optional textual child...
unsigned long timeStamp(wxXmlNode *aTree)
Make a unique time stamp.
const wxString GetLogicalName()
Function GetLogicalName returns the logical name of the library.
EDA_ITEM * Next() const
Definition: base_struct.h:220
void Clear()
Function Clear erases the record.
SCH_COMPONENT * findNextComponent(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
void addComponentFields(XNODE *xcomp, SCH_COMPONENT *comp, SCH_SHEET_PATH *aSheet)
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
Class LIB_PART defines a library part object.
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
time_t GetTimeStamp() const
Definition: base_struct.h:218
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
const LIB_ID & GetLibId() const
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:165
PART_LIBS * m_libs
yes ownership, connected items flat list
XNODE * NETLIST_EXPORTER_GENERIC::makeDesignHeader ( )
protectedinherited

Function makeDesignHeader fills out a project "design" header into an XML node.

Returns
XNODE* - the design header

Definition at line 262 of file netlist_exporter_generic.cpp.

References DateAndTime(), g_RootSheet, GetBuildVersion(), TITLE_BLOCK::GetComment1(), TITLE_BLOCK::GetComment2(), TITLE_BLOCK::GetComment3(), TITLE_BLOCK::GetComment4(), TITLE_BLOCK::GetCompany(), TITLE_BLOCK::GetDate(), SCH_SCREEN::GetFileName(), TITLE_BLOCK::GetRevision(), SCH_SHEET::GetScreen(), TITLE_BLOCK::GetTitle(), SCH_SCREEN::GetTitleBlock(), and NETLIST_EXPORTER_GENERIC::node().

Referenced by NETLIST_EXPORTER_GENERIC::makeRoot().

263 {
264  SCH_SCREEN* screen;
265  XNODE* xdesign = node( "design" );
266  XNODE* xtitleBlock;
267  XNODE* xsheet;
268  XNODE* xcomment;
269  wxString sheetTxt;
270  wxFileName sourceFileName;
271 
272  // the root sheet is a special sheet, call it source
273  xdesign->AddChild( node( "source", g_RootSheet->GetScreen()->GetFileName() ) );
274 
275  xdesign->AddChild( node( "date", DateAndTime() ) );
276 
277  // which Eeschema tool
278  xdesign->AddChild( node( "tool", wxString( "Eeschema " ) + GetBuildVersion() ) );
279 
280  /*
281  Export the sheets information
282  */
283  SCH_SHEET_LIST sheetList( g_RootSheet );
284 
285  for( unsigned i = 0; i < sheetList.size(); i++ )
286  {
287  screen = sheetList[i].LastScreen();
288 
289  xdesign->AddChild( xsheet = node( "sheet" ) );
290 
291  // get the string representation of the sheet index number.
292  // Note that sheet->GetIndex() is zero index base and we need to increment the
293  // number by one to make it human readable
294  sheetTxt.Printf( "%u", i + 1 );
295  xsheet->AddAttribute( "number", sheetTxt );
296  xsheet->AddAttribute( "name", sheetList[i].PathHumanReadable() );
297  xsheet->AddAttribute( "tstamps", sheetList[i].Path() );
298 
299 
300  TITLE_BLOCK tb = screen->GetTitleBlock();
301 
302  xsheet->AddChild( xtitleBlock = node( "title_block" ) );
303 
304  xtitleBlock->AddChild( node( "title", tb.GetTitle() ) );
305  xtitleBlock->AddChild( node( "company", tb.GetCompany() ) );
306  xtitleBlock->AddChild( node( "rev", tb.GetRevision() ) );
307  xtitleBlock->AddChild( node( "date", tb.GetDate() ) );
308 
309  // We are going to remove the fileName directories.
310  sourceFileName = wxFileName( screen->GetFileName() );
311  xtitleBlock->AddChild( node( "source", sourceFileName.GetFullName() ) );
312 
313  xtitleBlock->AddChild( xcomment = node( "comment" ) );
314  xcomment->AddAttribute( "number", "1" );
315  xcomment->AddAttribute( "value", tb.GetComment1() );
316 
317  xtitleBlock->AddChild( xcomment = node( "comment" ) );
318  xcomment->AddAttribute( "number", "2" );
319  xcomment->AddAttribute( "value", tb.GetComment2() );
320 
321  xtitleBlock->AddChild( xcomment = node( "comment" ) );
322  xcomment->AddAttribute( "number", "3" );
323  xcomment->AddAttribute( "value", tb.GetComment3() );
324 
325  xtitleBlock->AddChild( xcomment = node( "comment" ) );
326  xcomment->AddAttribute( "number", "4" );
327  xcomment->AddAttribute( "value", tb.GetComment4() );
328  }
329 
330  return xdesign;
331 }
Class SCH_SHEET_LIST.
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
Function node is a convenience function that creates a new XNODE with an optional textual child...
const wxString & GetCompany() const
const wxString & GetFileName() const
const wxString & GetComment4() const
const wxString & GetDate() const
SCH_SCREEN * GetScreen()
Definition: sch_sheet.h:286
Class TITLE_BLOCK holds the information shown in the lower right corner of a plot, printout, or editing view.
const wxString & GetTitle() const
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString & GetRevision() const
const wxString & GetComment3() const
const TITLE_BLOCK & GetTitleBlock() const
const wxString & GetComment2() const
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
const wxString & GetComment1() const
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:229
XNODE * NETLIST_EXPORTER_GENERIC::makeLibParts ( )
protectedinherited

Function makeLibParts fills out an XML node with the unique library parts and returns it.

Returns
XNODE* - the library parts nodes

Definition at line 354 of file netlist_exporter_generic.cpp.

References LIB_PART::GetAlias(), LIB_PART::GetAliasCount(), LIB_PART::GetAliasNames(), LIB_ALIAS::GetDescription(), LIB_ALIAS::GetDocFileName(), LIB_PART::GetFields(), LIB_PART::GetFootPrints(), LIB_PART::GetLib(), PART_LIB::GetLogicalName(), LIB_PART::GetName(), LIB_PART::GetPins(), GetText(), NETLIST_EXPORTER::m_LibParts, NETLIST_EXPORTER::m_Libraries, NETLIST_EXPORTER_GENERIC::node(), and sortPinsByNumber().

Referenced by NETLIST_EXPORTER_GENERIC::makeRoot().

355 {
356  XNODE* xlibparts = node( "libparts" ); // auto_ptr
357 
358  LIB_PINS pinList;
359  LIB_FIELDS fieldList;
360 
361  m_Libraries.clear();
362 
363  for( std::set<LIB_PART*>::iterator it = m_LibParts.begin(); it!=m_LibParts.end(); ++it )
364  {
365  LIB_PART* lcomp = *it;
366  PART_LIB* library = lcomp->GetLib();
367 
368  m_Libraries.insert( library ); // inserts component's library if unique
369 
370  XNODE* xlibpart;
371  xlibparts->AddChild( xlibpart = node( "libpart" ) );
372  xlibpart->AddAttribute( "lib", library->GetLogicalName() );
373  xlibpart->AddAttribute( "part", lcomp->GetName() );
374 
375  if( lcomp->GetAliasCount() )
376  {
377  wxArrayString aliases = lcomp->GetAliasNames( false );
378  if( aliases.GetCount() )
379  {
380  XNODE* xaliases = node( "aliases" );
381  xlibpart->AddChild( xaliases );
382  for( unsigned i=0; i<aliases.GetCount(); ++i )
383  {
384  xaliases->AddChild( node( "alias", aliases[i] ) );
385  }
386  }
387  }
388 
389  //----- show the important properties -------------------------
390  if( !lcomp->GetAlias( 0 )->GetDescription().IsEmpty() )
391  xlibpart->AddChild( node( "description", lcomp->GetAlias( 0 )->GetDescription() ) );
392 
393  if( !lcomp->GetAlias( 0 )->GetDocFileName().IsEmpty() )
394  xlibpart->AddChild( node( "docs", lcomp->GetAlias( 0 )->GetDocFileName() ) );
395 
396  // Write the footprint list
397  if( lcomp->GetFootPrints().GetCount() )
398  {
399  XNODE* xfootprints;
400  xlibpart->AddChild( xfootprints = node( "footprints" ) );
401 
402  for( unsigned i=0; i<lcomp->GetFootPrints().GetCount(); ++i )
403  {
404  xfootprints->AddChild( node( "fp", lcomp->GetFootPrints()[i] ) );
405  }
406  }
407 
408  //----- show the fields here ----------------------------------
409  fieldList.clear();
410  lcomp->GetFields( fieldList );
411 
412  XNODE* xfields;
413  xlibpart->AddChild( xfields = node( "fields" ) );
414 
415  for( unsigned i=0; i<fieldList.size(); ++i )
416  {
417  if( !fieldList[i].GetText().IsEmpty() )
418  {
419  XNODE* xfield;
420  xfields->AddChild( xfield = node( "field", fieldList[i].GetText() ) );
421  xfield->AddAttribute( "name", fieldList[i].GetName(false) );
422  }
423  }
424 
425  //----- show the pins here ------------------------------------
426  pinList.clear();
427  lcomp->GetPins( pinList, 0, 0 );
428 
429  /* we must erase redundant Pins references in pinList
430  * These redundant pins exist because some pins
431  * are found more than one time when a component has
432  * multiple parts per package or has 2 representations (DeMorgan conversion)
433  * For instance, a 74ls00 has DeMorgan conversion, with different pin shapes,
434  * and therefore each pin appears 2 times in the list.
435  * Common pins (VCC, GND) can also be found more than once.
436  */
437  sort( pinList.begin(), pinList.end(), sortPinsByNumber );
438  for( int ii = 0; ii < (int)pinList.size()-1; ii++ )
439  {
440  if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
441  { // 2 pins have the same number, remove the redundant pin at index i+1
442  pinList.erase(pinList.begin() + ii + 1);
443  ii--;
444  }
445  }
446 
447  if( pinList.size() )
448  {
449  XNODE* pins;
450 
451  xlibpart->AddChild( pins = node( "pins" ) );
452  for( unsigned i=0; i<pinList.size(); ++i )
453  {
454  XNODE* pin;
455 
456  pins->AddChild( pin = node( "pin" ) );
457  pin->AddAttribute( "num", pinList[i]->GetNumber() );
458  pin->AddAttribute( "name", pinList[i]->GetName() );
459  pin->AddAttribute( "type", pinList[i]->GetCanonicalElectricalTypeName() );
460 
461  // caution: construction work site here, drive slowly
462  }
463  }
464  }
465 
466  return xlibparts;
467 }
PART_LIB * GetLib()
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
Function node is a convenience function that creates a new XNODE with an optional textual child...
LIB_ALIAS * GetAlias(size_t aIndex)
const wxString GetLogicalName()
Function GetLogicalName returns the logical name of the library.
size_t GetAliasCount() const
void GetPins(LIB_PINS &aList, int aUnit=0, int aConvert=0)
Return a list of pin object pointers from the draw item list.
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used. LIB_PART items are sorted by names
const wxString & GetName() const
wxString GetDescription() const
Class LIB_PART defines a library part object.
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
std::set< void * > m_Libraries
unique libraries used
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
wxString GetDocFileName() const
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:60
std::vector< LIB_FIELD > LIB_FIELDS
Definition: lib_field.h:261
wxArrayString GetAliasNames(bool aIncludeRoot=true) const
wxArrayString & GetFootPrints()
static bool sortPinsByNumber(LIB_PIN *aPin1, LIB_PIN *aPin2)
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
void GetFields(LIB_FIELDS &aList)
Function GetFields returns a list of fields withing this part.
XNODE * NETLIST_EXPORTER_GENERIC::makeLibraries ( )
protectedinherited

Function makeLibraries fills 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 334 of file netlist_exporter_generic.cpp.

References PART_LIB::GetFullFileName(), PART_LIB::GetLogicalName(), NETLIST_EXPORTER::m_Libraries, and NETLIST_EXPORTER_GENERIC::node().

Referenced by NETLIST_EXPORTER_GENERIC::makeRoot().

335 {
336  XNODE* xlibs = node( "libraries" ); // auto_ptr
337 
338  for( std::set<void*>::iterator it = m_Libraries.begin(); it!=m_Libraries.end(); ++it )
339  {
340  PART_LIB* lib = (PART_LIB*) *it;
341  XNODE* xlibrary;
342 
343  xlibs->AddChild( xlibrary = node( "library" ) );
344  xlibrary->AddAttribute( "logical", lib->GetLogicalName() );
345  xlibrary->AddChild( node( "uri", lib->GetFullFileName() ) );
346 
347  // @todo: add more fun stuff here
348  }
349 
350  return xlibs;
351 }
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
Function node is a convenience function that creates a new XNODE with an optional textual child...
wxString GetFullFileName()
Function GetFullFileName returns the full file library name with path and extension.
const wxString GetLogicalName()
Function GetLogicalName returns the logical name of the library.
std::set< void * > m_Libraries
unique libraries used
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
Class PART_LIB is used to load, save, search, and otherwise manipulate part library files...
XNODE * NETLIST_EXPORTER_GENERIC::makeListOfNets ( )
protectedinherited

Function makeListOfNets fills out an XML node with a list of nets and returns it.

Returns
XNODE* - the list of nets nodes

Definition at line 470 of file netlist_exporter_generic.cpp.

References NETLIST_OBJECT::GetComponentParent(), NETLIST_OBJECT_LIST::GetItem(), NETLIST_OBJECT::GetNet(), NETLIST_OBJECT::GetNetName(), NETLIST_OBJECT::GetPinNumText(), SCH_COMPONENT::GetRef(), NETLIST_OBJECT::m_Flag, NETLIST_EXPORTER::m_LibParts, NETLIST_EXPORTER::m_masterList, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Type, NET_PIN, and NETLIST_EXPORTER_GENERIC::node().

Referenced by NETLIST_EXPORTER_GENERIC::makeRoot().

471 {
472  XNODE* xnets = node( "nets" ); // auto_ptr if exceptions ever get used.
473  wxString netCodeTxt;
474  wxString netName;
475  wxString ref;
476 
477  XNODE* xnet = 0;
478  int netCode;
479  int lastNetCode = -1;
480  int sameNetcodeCount = 0;
481 
482 
483  /* output:
484  <net code="123" name="/cfcard.sch/WAIT#">
485  <node ref="R23" pin="1"/>
486  <node ref="U18" pin="12"/>
487  </net>
488  */
489 
490  m_LibParts.clear(); // must call this function before using m_LibParts.
491 
492  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
493  {
494  NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
495  SCH_COMPONENT* comp;
496 
497  // New net found, write net id;
498  if( ( netCode = nitem->GetNet() ) != lastNetCode )
499  {
500  sameNetcodeCount = 0; // item count for this net
501  netName = nitem->GetNetName();
502  lastNetCode = netCode;
503  }
504 
505  if( nitem->m_Type != NET_PIN )
506  continue;
507 
508  if( nitem->m_Flag != 0 ) // Redundant pin, skip it
509  continue;
510 
511  comp = nitem->GetComponentParent();
512 
513  // Get the reference for the net name and the main parent component
514  ref = comp->GetRef( &nitem->m_SheetPath );
515  if( ref[0] == wxChar( '#' ) )
516  continue;
517 
518  if( ++sameNetcodeCount == 1 )
519  {
520  xnets->AddChild( xnet = node( "net" ) );
521  netCodeTxt.Printf( "%d", netCode );
522  xnet->AddAttribute( "code", netCodeTxt );
523  xnet->AddAttribute( "name", netName );
524  }
525 
526  XNODE* xnode;
527  xnet->AddChild( xnode = node( "node" ) );
528  xnode->AddAttribute( "ref", ref );
529  xnode->AddAttribute( "pin", nitem->GetPinNumText() );
530  }
531 
532  return xnets;
533 }
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
const wxString & GetPinNumText() const
Function GetPinNum returns a pin number in wxString form.
XNODE * node(const wxString &aName, const wxString &aTextualContent=wxEmptyString)
Function node is a convenience function that creates a new XNODE with an optional textual child...
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
SCH_SHEET_PATH m_SheetPath
NETLIST_ITEM_T m_Type
NETLIST_OBJECT_LIST * m_masterList
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used. LIB_PART items are sorted by names
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
XNODE * NETLIST_EXPORTER_GENERIC::makeRoot ( int  aCtl = GNL_ALL)
protectedinherited

Function makeGenericRoot builds 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 50 of file netlist_exporter_generic.cpp.

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

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

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

Function node is 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 536 of file netlist_exporter_generic.cpp.

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

537 {
538  XNODE* n = new XNODE( wxXML_ELEMENT_NODE, aName );
539 
540  if( aTextualContent.Len() > 0 ) // excludes wxEmptyString, the parameter's default value
541  n->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
542 
543  return n;
544 }
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
void NETLIST_EXPORTER::sprintPinNetName ( wxString &  aResult,
const wxString &  aNetNameFormat,
NETLIST_OBJECT aPin,
bool  aUseNetcodeAsNetName = false 
)
staticprotectedinherited

Function sprintPinNetName formats the net name for aPin using aNetNameFormat into aResult.

Net name is:

  • "?" if pin not connected
  • "netname" for global net (like gnd, vcc ..
  • "/path/netname" for the usual nets

if aUseNetcodeAsNetName is true, the net name is just the net code (SPICE only)

Definition at line 72 of file netlist_exporter.cpp.

References NETLIST_OBJECT::GetConnectionType(), NETLIST_OBJECT::GetNet(), NETLIST_OBJECT::GetNetName(), and PAD_CONNECT.

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

75 {
76  int netcode = aPin->GetNet();
77 
78  // Not wxString::Clear(), which would free memory. We want the worst
79  // case wxString memory to grow to avoid reallocation from within the
80  // caller's loop.
81  aResult.Empty();
82 
83  if( netcode != 0 && aPin->GetConnectionType() == PAD_CONNECT )
84  {
85  if( aUseNetcodeAsNetName )
86  {
87  aResult.Printf( wxT("%d"), netcode );
88  }
89  else
90  {
91  aResult = aPin->GetNetName();
92 
93  if( aResult.IsEmpty() ) // No net name: give a name from net code
94  aResult.Printf( aNetNameFormat.GetData(), netcode );
95  }
96  }
97 }
NET_CONNECTION_T GetConnectionType() const
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
bool NETLIST_EXPORTER_KICAD::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions 
)
overridevirtual

Function WriteNetlist writes to specified output file.

Reimplemented from NETLIST_EXPORTER_GENERIC.

Definition at line 34 of file netlist_exporter_kicad.cpp.

References DisplayError(), Format(), GNL_ALL, and IO_ERROR::What().

35 {
36  try
37  {
38  FILE_OUTPUTFORMATTER formatter( aOutFileName );
39  Format( &formatter, GNL_ALL );
40  }
41 
42  catch( const IO_ERROR& ioe )
43  {
44  DisplayError( NULL, ioe.What() );
45  return false;
46  }
47 
48  return true;
49 }
void Format(OUTPUTFORMATTER *aOutputFormatter, int aCtl)
Function Format outputs this s-expression netlist into aOutputFormatter.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
#define GNL_ALL
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
Struct IO_ERROR is a class used to hold an error message and may be used when throwing exceptions con...
Definition: ki_exception.h:47

Member Data Documentation

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

unique libraries used

Definition at line 107 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER_GENERIC::makeLibParts(), and NETLIST_EXPORTER_GENERIC::makeLibraries().

PART_LIBS* NETLIST_EXPORTER::m_libs
protectedinherited

yes ownership, connected items flat list

Definition at line 92 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER_GENERIC::makeComponents(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

UNIQUE_STRINGS NETLIST_EXPORTER::m_ReferencesAlreadyFound
protectedinherited
NETLIST_OBJECTS NETLIST_EXPORTER::m_SortedComponentPinList
protectedinherited

no ownership

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.

Definition at line 97 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER::addPinToComponentPinList(), NETLIST_EXPORTER::eraseDuplicatePins(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().


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