KiCad PCB EDA Suite
NETLIST_EXPORTER_GENERIC Class Reference

Class NETLIST_EXPORTER_GENERIC generates 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 (NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs)
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions) override
 Function WriteNetlist writes to specified output file. 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...
 
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 findAllInstancesOfComponent (SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
 Function findAllInstancesOfComponent 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_GENERIC generates 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 54 of file netlist_exporter_generic.h.

Constructor & Destructor Documentation

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

Definition at line 57 of file netlist_exporter_generic.h.

57  :
58  NETLIST_EXPORTER( aMasterList, aLibs )
59  {
60  }
NETLIST_EXPORTER(NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs)
Constructor.

Member Function Documentation

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::findAllInstancesOfComponent(), 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:69
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::findAllInstancesOfComponent ( SCH_COMPONENT aComponent,
LIB_PART aEntry,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

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

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

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().

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

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

104 {
105  wxString ref;
106 
107  // continue searching from the middle of a linked list (the draw list)
108  for( ; aItem; aItem = aItem->Next() )
109  {
110  if( aItem->Type() != SCH_COMPONENT_T )
111  continue;
112 
113  // found next component
114  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
115 
116  // Power symbols and other components which have the reference starting
117  // with "#" are not included in netlist (pseudo or virtual components)
118  ref = comp->GetRef( aSheetPath );
119  if( ref[0] == wxChar( '#' ) )
120  continue;
121 
122  // if( Component->m_FlagControlMulti == 1 )
123  // continue; /* yes */
124  // removed because with multiple instances of one schematic
125  // (several sheets pointing to 1 screen), this will be erroneously be
126  // toggled.
127 
128  LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() );
129  if( !part )
130  continue;
131 
132  // If component is a "multi parts per package" type
133  if( part->GetUnitCount() > 1 )
134  {
135  // test if this reference has already been processed, and if so skip
136  if( m_ReferencesAlreadyFound.Lookup( ref ) )
137  continue;
138  }
139 
140  // record the usage of this library component entry.
141  m_LibParts.insert( part ); // rejects non-unique pointers
142 
143  return comp;
144  }
145 
146  return NULL;
147 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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...
EDA_ITEM * Next() const
Definition: base_struct.h:206
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.
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
int GetUnitCount() const
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
const LIB_ID & GetLibId() const
PART_LIBS * m_libs
yes ownership, connected items flat list
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 158 of file netlist_exporter.cpp.

References NETLIST_EXPORTER::addPinToComponentPinList(), NETLIST_EXPORTER::eraseDuplicatePins(), NETLIST_EXPORTER::findAllInstancesOfComponent(), PART_LIBS::FindLibPart(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetLibId(), 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_libs, NETLIST_EXPORTER::m_ReferencesAlreadyFound, NETLIST_EXPORTER::m_SortedComponentPinList, EDA_ITEM::Next(), SCH_COMPONENT_T, sortPinsByNum(), and EDA_ITEM::Type().

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

160 {
161  wxString ref;
162 
163  m_SortedComponentPinList.clear();
164 
165  // continue searching from the middle of a linked list (the draw list)
166  for( ; aItem; aItem = aItem->Next() )
167  {
168  if( aItem->Type() != SCH_COMPONENT_T )
169  continue;
170 
171  // found next component
172  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
173 
174  // Power symbols and other components which have the reference starting
175  // with "#" are not included in netlist (pseudo or virtual components)
176  ref = comp->GetRef( aSheetPath );
177 
178  if( ref[0] == wxChar( '#' ) )
179  continue;
180 
181  // if( Component->m_FlagControlMulti == 1 )
182  // continue; /* yes */
183  // removed because with multiple instances of one schematic
184  // (several sheets pointing to 1 screen), this will be erroneously be
185  // toggled.
186 
187  LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() );
188 
189  if( !part )
190  continue;
191 
192  // If component is a "multi parts per package" type
193  if( part->GetUnitCount() > 1 )
194  {
195  // test if this reference has already been processed, and if so skip
196  if( m_ReferencesAlreadyFound.Lookup( ref ) )
197  continue;
198 
199  // Collect all pins for this reference designator by searching
200  // the entire design for other parts with the same reference designator.
201  // This is only done once, it would be too expensive otherwise.
202  findAllInstancesOfComponent( comp, part, aSheetPath );
203  }
204 
205  else // entry->GetUnitCount() <= 1 means one part per package
206  {
207  LIB_PINS pins; // constructed once here
208 
209  part->GetPins( pins, comp->GetUnitSelection( aSheetPath ), comp->GetConvert() );
210 
211  for( size_t i = 0; i < pins.size(); i++ )
212  {
213  LIB_PIN* pin = pins[i];
214 
215  wxASSERT( pin->Type() == LIB_PIN_T );
216 
217  addPinToComponentPinList( comp, aSheetPath, pin );
218  }
219  }
220 
221  // Sort pins in m_SortedComponentPinList by pin number
222  sort( m_SortedComponentPinList.begin(),
224 
225  // Remove duplicate Pins in m_SortedComponentPinList
227 
228  // record the usage of this library component entry.
229  m_LibParts.insert( part ); // rejects non-unique pointers
230 
231  return comp;
232  }
233 
234  return NULL;
235 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:198
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...
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
EDA_ITEM * Next() const
Definition: base_struct.h:206
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.
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
int GetUnitCount() const
NETLIST_OBJECTS m_SortedComponentPinList
no ownership
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_draw_item.h:70
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
const LIB_ID & GetLibId() const
PART_LIBS * m_libs
yes ownership, connected items flat list
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 findAllInstancesOfComponent(SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
Function findAllInstancesOfComponent is used for "multiple parts per package" components.
void eraseDuplicatePins()
Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i.e.
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  // Use Unix like notation, which always works
69  ret.Replace( wxT( "\\" ), "/", true );
70 
71  return ret;
72 }
XNODE * NETLIST_EXPORTER_GENERIC::makeComponents ( )
protected

Function makeComponents.

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

Definition at line 77 of file netlist_exporter_generic.cpp.

References UNIQUE_STRINGS::Clear(), DATASHEET, PART_LIBS::FindLibPart(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), FOOTPRINT, FROM_UTF8(), g_RootSheet, SCH_COMPONENT::GetField(), SCH_COMPONENT::GetFieldCount(), LIB_PART::GetLib(), SCH_COMPONENT::GetLibId(), LIB_ID::GetLibItemName(), PART_LIB::GetLogicalName(), SCH_FIELD::GetName(), SCH_COMPONENT::GetRef(), EDA_TEXT::GetText(), EDA_ITEM::GetTimeStamp(), SCH_FIELD::IsVoid(), NETLIST_EXPORTER::m_libs, NETLIST_EXPORTER::m_ReferencesAlreadyFound, MANDATORY_FIELDS, node(), timeStamp(), and VALUE.

Referenced by makeRoot().

78 {
79  XNODE* xcomps = node( wxT( "components" ) );
80 
81  wxString timeStamp;
82 
83  // some strings we need many times, but don't want to construct more
84  // than once for performance. These are used within loops so the
85  // enclosing wxString constructor would fire on each loop iteration if
86  // they were in a nested scope.
87 
88  // these are actually constructor invocations, not assignments as it appears:
89  wxString sFields = wxT( "fields" );
90  wxString sField = wxT( "field" );
91  wxString sComponent = wxT( "comp" ); // use "part" ?
92  wxString sName = wxT( "name" );
93  wxString sRef = wxT( "ref" );
94  wxString sPins = wxT( "pins" );
95  wxString sPin = wxT( "pin" );
96  wxString sValue = wxT( "value" );
97  wxString sSheetPath = wxT( "sheetpath" );
98  wxString sFootprint = wxT( "footprint" );
99  wxString sDatasheet = wxT( "datasheet" );
100  wxString sTStamp = wxT( "tstamp" );
101  wxString sTStamps = wxT( "tstamps" );
102  wxString sTSFmt = wxT( "%8.8lX" ); // comp->m_TimeStamp
103  wxString sLibSource = wxT( "libsource" );
104  wxString sLibPart = wxT( "libpart" );
105  wxString sLib = wxT( "lib" );
106  wxString sPart = wxT( "part" );
107  wxString sNames = wxT( "names" );
108 
110 
111  SCH_SHEET_LIST sheetList( g_RootSheet );
112 
113  // Output is xml, so there is no reason to remove spaces from the field values.
114  // And XML element names need not be translated to various languages.
115 
116  for( unsigned i = 0; i < sheetList.size(); i++ )
117  {
118  for( EDA_ITEM* schItem = sheetList[i].LastDrawList(); schItem; schItem = schItem->Next() )
119  {
120  SCH_COMPONENT* comp = findNextComponentAndCreatePinList( schItem, &sheetList[i] );
121  if( !comp )
122  break; // No component left
123 
124  schItem = comp;
125 
126  XNODE* xcomp; // current component being constructed
127 
128  // Output the component's elements in order of expected access frequency.
129  // This may not always look best, but it will allow faster execution
130  // under XSL processing systems which do sequential searching within
131  // an element.
132 
133  xcomps->AddChild( xcomp = node( sComponent ) );
134  xcomp->AddAttribute( sRef, comp->GetRef( &sheetList[i] ) );
135 
136  xcomp->AddChild( node( sValue, comp->GetField( VALUE )->GetText() ) );
137 
138  if( !comp->GetField( FOOTPRINT )->IsVoid() )
139  xcomp->AddChild( node( sFootprint, comp->GetField( FOOTPRINT )->GetText() ) );
140 
141  if( !comp->GetField( DATASHEET )->IsVoid() )
142  xcomp->AddChild( node( sDatasheet, comp->GetField( DATASHEET )->GetText() ) );
143 
144  // Export all user defined fields within the component,
145  // which start at field index MANDATORY_FIELDS. Only output the <fields>
146  // container element if there are any <field>s.
147  if( comp->GetFieldCount() > MANDATORY_FIELDS )
148  {
149  XNODE* xfields;
150  xcomp->AddChild( xfields = node( sFields ) );
151 
152  for( int fldNdx = MANDATORY_FIELDS; fldNdx < comp->GetFieldCount(); ++fldNdx )
153  {
154  SCH_FIELD* f = comp->GetField( fldNdx );
155 
156  // only output a field if non empty and not just "~"
157  if( !f->IsVoid() )
158  {
159  XNODE* xfield;
160  xfields->AddChild( xfield = node( sField, f->GetText() ) );
161  xfield->AddAttribute( sName, f->GetName() );
162  }
163  }
164  }
165 
166  XNODE* xlibsource;
167  xcomp->AddChild( xlibsource = node( sLibSource ) );
168 
169  // "logical" library name, which is in anticipation of a better search
170  // algorithm for parts based on "logical_lib.part" and where logical_lib
171  // is merely the library name minus path and extension.
172  LIB_PART* part = m_libs->FindLibPart( comp->GetLibId() );
173  if( part )
174  xlibsource->AddAttribute( sLib, part->GetLib()->GetLogicalName() );
175 
176  // We only want the symbol name, not the full LIB_ID.
177  xlibsource->AddAttribute( sPart, FROM_UTF8( comp->GetLibId().GetLibItemName() ) );
178 
179  XNODE* xsheetpath;
180 
181  xcomp->AddChild( xsheetpath = node( sSheetPath ) );
182  xsheetpath->AddAttribute( sNames, sheetList[i].PathHumanReadable() );
183  xsheetpath->AddAttribute( sTStamps, sheetList[i].Path() );
184 
185  timeStamp.Printf( sTSFmt, (unsigned long)comp->GetTimeStamp() );
186  xcomp->AddChild( node( sTStamp, timeStamp ) );
187  }
188  }
189 
190  return xcomps;
191 }
PART_LIB * GetLib()
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
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
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...
The first 4 are mandatory, and must be instantiated in SCH_COMPONENT and LIB_PART constructors...
const wxString GetLogicalName()
Function GetLogicalName returns the logical name of the library.
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.h:116
EDA_ITEM * Next() const
Definition: base_struct.h:206
void Clear()
Function Clear erases the record.
Field Name Module PCB, i.e. "16DIP300".
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
SCH_FIELD * GetField(int aFieldNdx) const
Function GetField returns a field.
const UTF8 & GetLibItemName() const
Function GetLibItemName.
Definition: lib_id.h:129
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
Class LIB_PART defines a library part object.
SCH_COMPONENT * findNextComponentAndCreatePinList(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin lis...
LIB_PART * FindLibPart(const LIB_ID &aLibId, const wxString &aLibraryName=wxEmptyString)
Function FindLibPart searches all libraries in the list for a part.
time_t GetTimeStamp() const
Definition: base_struct.h:204
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
Field Value of part, i.e. "3.3K".
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
int GetFieldCount() const
Function GetFieldCount returns the number of fields in this component.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
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:151
PART_LIBS * m_libs
yes ownership, connected items flat list
static unsigned long timeStamp(CPTREE &aTree)
Make a unique time stamp.
XNODE * NETLIST_EXPORTER_GENERIC::makeDesignHeader ( )
protected

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

Returns
XNODE* - the design header

Definition at line 194 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 node().

Referenced by makeRoot().

195 {
196  SCH_SCREEN* screen;
197  XNODE* xdesign = node( wxT( "design" ) );
198  XNODE* xtitleBlock;
199  XNODE* xsheet;
200  XNODE* xcomment;
201  wxString sheetTxt;
202  wxFileName sourceFileName;
203 
204  // the root sheet is a special sheet, call it source
205  xdesign->AddChild( node( wxT( "source" ), g_RootSheet->GetScreen()->GetFileName() ) );
206 
207  xdesign->AddChild( node( wxT( "date" ), DateAndTime() ) );
208 
209  // which Eeschema tool
210  xdesign->AddChild( node( wxT( "tool" ), wxT( "Eeschema " ) + GetBuildVersion() ) );
211 
212  /*
213  Export the sheets information
214  */
215  SCH_SHEET_LIST sheetList( g_RootSheet );
216 
217  for( unsigned i = 0; i < sheetList.size(); i++ )
218  {
219  screen = sheetList[i].LastScreen();
220 
221  xdesign->AddChild( xsheet = node( wxT( "sheet" ) ) );
222 
223  // get the string representation of the sheet index number.
224  // Note that sheet->GetIndex() is zero index base and we need to increment the
225  // number by one to make it human readable
226  sheetTxt.Printf( wxT( "%u" ), i + 1 );
227  xsheet->AddAttribute( wxT( "number" ), sheetTxt );
228  xsheet->AddAttribute( wxT( "name" ), sheetList[i].PathHumanReadable() );
229  xsheet->AddAttribute( wxT( "tstamps" ), sheetList[i].Path() );
230 
231 
232  TITLE_BLOCK tb = screen->GetTitleBlock();
233 
234  xsheet->AddChild( xtitleBlock = node( wxT( "title_block" ) ) );
235 
236  xtitleBlock->AddChild( node( wxT( "title" ), tb.GetTitle() ) );
237  xtitleBlock->AddChild( node( wxT( "company" ), tb.GetCompany() ) );
238  xtitleBlock->AddChild( node( wxT( "rev" ), tb.GetRevision() ) );
239  xtitleBlock->AddChild( node( wxT( "date" ), tb.GetDate() ) );
240 
241  // We are going to remove the fileName directories.
242  sourceFileName = wxFileName( screen->GetFileName() );
243  xtitleBlock->AddChild( node( wxT( "source" ), sourceFileName.GetFullName() ) );
244 
245  xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
246  xcomment->AddAttribute( wxT("number"), wxT("1") );
247  xcomment->AddAttribute( wxT( "value" ), tb.GetComment1() );
248 
249  xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
250  xcomment->AddAttribute( wxT("number"), wxT("2") );
251  xcomment->AddAttribute( wxT( "value" ), tb.GetComment2() );
252 
253  xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
254  xcomment->AddAttribute( wxT("number"), wxT("3") );
255  xcomment->AddAttribute( wxT( "value" ), tb.GetComment3() );
256 
257  xtitleBlock->AddChild( xcomment = node( wxT( "comment" ) ) );
258  xcomment->AddAttribute( wxT("number"), wxT("4") );
259  xcomment->AddAttribute( wxT( "value" ), tb.GetComment4() );
260  }
261 
262  return xdesign;
263 }
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:54
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 ( )
protected

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

Returns
XNODE* - the library parts nodes

Definition at line 286 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, node(), and sortPinsByNumber().

Referenced by makeRoot().

287 {
288  XNODE* xlibparts = node( wxT( "libparts" ) ); // auto_ptr
289  wxString sLibpart = wxT( "libpart" );
290  wxString sLib = wxT( "lib" );
291  wxString sPart = wxT( "part" );
292  wxString sAliases = wxT( "aliases" );
293  wxString sAlias = wxT( "alias" );
294  wxString sPins = wxT( "pins" ); // key for library component pins list
295  wxString sPin = wxT( "pin" ); // key for one library component pin descr
296  wxString sPinNum = wxT( "num" ); // key for one library component pin num
297  wxString sPinName = wxT( "name" ); // key for one library component pin name
298  wxString sPinType = wxT( "type" ); // key for one library component pin electrical type
299  wxString sName = wxT( "name" );
300  wxString sField = wxT( "field" );
301  wxString sFields = wxT( "fields" );
302  wxString sDescr = wxT( "description" );
303  wxString sDocs = wxT( "docs" );
304  wxString sFprints = wxT( "footprints" );
305  wxString sFp = wxT( "fp" );
306 
307  LIB_PINS pinList;
308  LIB_FIELDS fieldList;
309 
310  m_Libraries.clear();
311 
312  for( std::set<LIB_PART*>::iterator it = m_LibParts.begin(); it!=m_LibParts.end(); ++it )
313  {
314  LIB_PART* lcomp = *it;
315  PART_LIB* library = lcomp->GetLib();
316 
317  m_Libraries.insert( library ); // inserts component's library if unique
318 
319  XNODE* xlibpart;
320  xlibparts->AddChild( xlibpart = node( sLibpart ) );
321  xlibpart->AddAttribute( sLib, library->GetLogicalName() );
322  xlibpart->AddAttribute( sPart, lcomp->GetName() );
323 
324  if( lcomp->GetAliasCount() )
325  {
326  wxArrayString aliases = lcomp->GetAliasNames( false );
327  if( aliases.GetCount() )
328  {
329  XNODE* xaliases = node( sAliases );
330  xlibpart->AddChild( xaliases );
331  for( unsigned i=0; i<aliases.GetCount(); ++i )
332  {
333  xaliases->AddChild( node( sAlias, aliases[i] ) );
334  }
335  }
336  }
337 
338  //----- show the important properties -------------------------
339  if( !lcomp->GetAlias( 0 )->GetDescription().IsEmpty() )
340  xlibpart->AddChild( node( sDescr, lcomp->GetAlias( 0 )->GetDescription() ) );
341 
342  if( !lcomp->GetAlias( 0 )->GetDocFileName().IsEmpty() )
343  xlibpart->AddChild( node( sDocs, lcomp->GetAlias( 0 )->GetDocFileName() ) );
344 
345  // Write the footprint list
346  if( lcomp->GetFootPrints().GetCount() )
347  {
348  XNODE* xfootprints;
349  xlibpart->AddChild( xfootprints = node( sFprints ) );
350 
351  for( unsigned i=0; i<lcomp->GetFootPrints().GetCount(); ++i )
352  {
353  xfootprints->AddChild( node( sFp, lcomp->GetFootPrints()[i] ) );
354  }
355  }
356 
357  //----- show the fields here ----------------------------------
358  fieldList.clear();
359  lcomp->GetFields( fieldList );
360 
361  XNODE* xfields;
362  xlibpart->AddChild( xfields = node( sFields ) );
363 
364  for( unsigned i=0; i<fieldList.size(); ++i )
365  {
366  if( !fieldList[i].GetText().IsEmpty() )
367  {
368  XNODE* xfield;
369  xfields->AddChild( xfield = node( sField, fieldList[i].GetText() ) );
370  xfield->AddAttribute( sName, fieldList[i].GetName(false) );
371  }
372  }
373 
374  //----- show the pins here ------------------------------------
375  pinList.clear();
376  lcomp->GetPins( pinList, 0, 0 );
377 
378  /* we must erase redundant Pins references in pinList
379  * These redundant pins exist because some pins
380  * are found more than one time when a component has
381  * multiple parts per package or has 2 representations (DeMorgan conversion)
382  * For instance, a 74ls00 has DeMorgan conversion, with different pin shapes,
383  * and therefore each pin appears 2 times in the list.
384  * Common pins (VCC, GND) can also be found more than once.
385  */
386  sort( pinList.begin(), pinList.end(), sortPinsByNumber );
387  for( int ii = 0; ii < (int)pinList.size()-1; ii++ )
388  {
389  if( pinList[ii]->GetNumber() == pinList[ii+1]->GetNumber() )
390  { // 2 pins have the same number, remove the redundant pin at index i+1
391  pinList.erase(pinList.begin() + ii + 1);
392  ii--;
393  }
394  }
395 
396  if( pinList.size() )
397  {
398  XNODE* pins;
399 
400  xlibpart->AddChild( pins = node( sPins ) );
401  for( unsigned i=0; i<pinList.size(); ++i )
402  {
403  XNODE* pin;
404 
405  pins->AddChild( pin = node( sPin ) );
406  pin->AddAttribute( sPinNum, pinList[i]->GetNumberString() );
407  pin->AddAttribute( sPinName, pinList[i]->GetName() );
408  pin->AddAttribute( sPinType, pinList[i]->GetCanonicalElectricalTypeName() );
409 
410  // caution: construction work site here, drive slowly
411  }
412  }
413  }
414 
415  return xlibparts;
416 }
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:70
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 ( )
protected

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 266 of file netlist_exporter_generic.cpp.

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

Referenced by makeRoot().

267 {
268  XNODE* xlibs = node( wxT( "libraries" ) ); // auto_ptr
269 
270  for( std::set<void*>::iterator it = m_Libraries.begin(); it!=m_Libraries.end(); ++it )
271  {
272  PART_LIB* lib = (PART_LIB*) *it;
273  XNODE* xlibrary;
274 
275  xlibs->AddChild( xlibrary = node( wxT( "library" ) ) );
276  xlibrary->AddAttribute( wxT( "logical" ), lib->GetLogicalName() );
277  xlibrary->AddChild( node( wxT( "uri" ), lib->GetFullFileName() ) );
278 
279  // @todo: add more fun stuff here
280  }
281 
282  return xlibs;
283 }
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 ( )
protected

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 419 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 node().

Referenced by makeRoot().

420 {
421  XNODE* xnets = node( wxT( "nets" ) ); // auto_ptr if exceptions ever get used.
422  wxString netCodeTxt;
423  wxString netName;
424  wxString ref;
425 
426  wxString sNet = wxT( "net" );
427  wxString sName = wxT( "name" );
428  wxString sCode = wxT( "code" );
429  wxString sRef = wxT( "ref" );
430  wxString sPin = wxT( "pin" );
431  wxString sNode = wxT( "node" );
432  wxString sFmtd = wxT( "%d" );
433 
434  XNODE* xnet = 0;
435  int netCode;
436  int lastNetCode = -1;
437  int sameNetcodeCount = 0;
438 
439 
440  /* output:
441  <net code="123" name="/cfcard.sch/WAIT#">
442  <node ref="R23" pin="1"/>
443  <node ref="U18" pin="12"/>
444  </net>
445  */
446 
447  m_LibParts.clear(); // must call this function before using m_LibParts.
448 
449  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
450  {
451  NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
452  SCH_COMPONENT* comp;
453 
454  // New net found, write net id;
455  if( ( netCode = nitem->GetNet() ) != lastNetCode )
456  {
457  sameNetcodeCount = 0; // item count for this net
458  netName = nitem->GetNetName();
459  lastNetCode = netCode;
460  }
461 
462  if( nitem->m_Type != NET_PIN )
463  continue;
464 
465  if( nitem->m_Flag != 0 ) // Redundant pin, skip it
466  continue;
467 
468  comp = nitem->GetComponentParent();
469 
470  // Get the reference for the net name and the main parent component
471  ref = comp->GetRef( &nitem->m_SheetPath );
472  if( ref[0] == wxChar( '#' ) )
473  continue;
474 
475  if( ++sameNetcodeCount == 1 )
476  {
477  xnets->AddChild( xnet = node( sNet ) );
478  netCodeTxt.Printf( sFmtd, netCode );
479  xnet->AddAttribute( sCode, netCodeTxt );
480  xnet->AddAttribute( sName, netName );
481  }
482 
483  XNODE* xnode;
484  xnet->AddChild( xnode = node( sNode ) );
485  xnode->AddAttribute( sRef, ref );
486  xnode->AddAttribute( sPin, nitem->GetPinNumText() );
487  }
488 
489  return xnets;
490 }
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
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
wxString GetPinNumText()
Function GetPinNum returns a pin number in wxString form.
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
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
Class XNODE holds an XML or S-expression element.
Definition: xnode.h:43
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
XNODE * NETLIST_EXPORTER_GENERIC::makeRoot ( int  aCtl = GNL_ALL)
protected

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, makeComponents(), makeDesignHeader(), makeLibParts(), makeLibraries(), makeListOfNets(), and node().

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

51 {
52  XNODE* xroot = node( wxT( "export" ) );
53 
54  xroot->AddAttribute( wxT( "version" ), wxT( "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 
)
protected

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 493 of file netlist_exporter_generic.cpp.

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

494 {
495  XNODE* n = new XNODE( wxXML_ELEMENT_NODE, aName );
496 
497  if( aTextualContent.Len() > 0 ) // excludes wxEmptyString, the parameter's default value
498  n->AddChild( new XNODE( wxXML_TEXT_NODE, wxEmptyString, aTextualContent ) );
499 
500  return n;
501 }
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 75 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().

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

Function WriteNetlist writes to specified output file.

Reimplemented from NETLIST_EXPORTER.

Reimplemented in NETLIST_EXPORTER_KICAD.

Definition at line 35 of file netlist_exporter_generic.cpp.

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

36 {
37  // Prepare list of nets generation
38  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
39  m_masterList->GetItem( ii )->m_Flag = 0;
40 
41  // output the XML format netlist.
42  wxXmlDocument xdoc;
43 
44  xdoc.SetRoot( makeRoot( GNL_ALL ) );
45 
46  return xdoc.Save( aOutFileName, 2 /* indent bug, today was ignored by wxXml lib */ );
47 }
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.
#define GNL_ALL

Member Data Documentation

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

unique library parts used. LIB_PART items are sorted by names

Definition at line 104 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER::findNextComponent(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), makeLibParts(), and makeListOfNets().

std::set<void*> NETLIST_EXPORTER::m_Libraries
protectedinherited

unique libraries used

Definition at line 107 of file netlist_exporter.h.

Referenced by makeLibParts(), and makeLibraries().

PART_LIBS* NETLIST_EXPORTER::m_libs
protectedinherited
UNIQUE_STRINGS NETLIST_EXPORTER::m_ReferencesAlreadyFound
protectedinherited
NETLIST_OBJECTS NETLIST_EXPORTER::m_SortedComponentPinList
protectedinherited

no ownership

Used to temporary 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: