KiCad PCB EDA Suite
NETLIST_EXPORTER_CADSTAR Class Reference

Class NETLIST_EXPORTER_CADSTAR generates a netlist compatible with CADSTAR. More...

#include <netlist_exporter_cadstar.h>

Inheritance diagram for NETLIST_EXPORTER_CADSTAR:
NETLIST_EXPORTER

Public Member Functions

 NETLIST_EXPORTER_CADSTAR (NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs)
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions) override
 Function WriteList 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

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

Private Member Functions

bool writeListOfNets (FILE *f)
 Function writeListOfNetsCADSTAR writes a net list (ranked by Netcode), and pins connected to it. More...
 

Detailed Description

Class NETLIST_EXPORTER_CADSTAR generates a netlist compatible with CADSTAR.

Definition at line 35 of file netlist_exporter_cadstar.h.

Constructor & Destructor Documentation

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

Definition at line 50 of file netlist_exporter_cadstar.h.

50  :
51  NETLIST_EXPORTER( aMasterList, aLibs )
52  {
53  }
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 240 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().

242 {
243  // Search the PIN description for Pin in g_NetObjectslist
244  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
245  {
246  NETLIST_OBJECT* pin = m_masterList->GetItem( ii );
247 
248  if( pin->m_Type != NET_PIN )
249  continue;
250 
251  if( pin->m_Link != aComponent )
252  continue;
253 
254  if( pin->m_PinNum != aPin->GetNumber() )
255  continue;
256 
257  // most expensive test at the end.
258  if( pin->m_SheetPath != *aSheetPath )
259  continue;
260 
261  m_SortedComponentPinList.push_back( pin );
262 
263  if( m_SortedComponentPinList.size() >= MAXPIN )
264  {
265  // Log message for Internal error
266  DisplayError( NULL, wxT( "addPinToComponentPinList err: MAXPIN reached" ) );
267  }
268 
269  return true; // we're done, we appended.
270  }
271 
272  return false;
273 }
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 276 of file netlist_exporter.cpp.

References NETLIST_EXPORTER::m_SortedComponentPinList, and PAD_CONNECT.

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

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

329 {
330  wxString ref = aComponent->GetRef( aSheetPath );
331  wxString ref2;
332 
333  SCH_SHEET_LIST sheetList( g_RootSheet );
334 
335  for( unsigned i = 0; i < sheetList.size(); i++ )
336  {
337  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
338  {
339  if( item->Type() != SCH_COMPONENT_T )
340  continue;
341 
342  SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
343 
344  ref2 = comp2->GetRef( &sheetList[i] );
345 
346  if( ref2.CmpNoCase( ref ) != 0 )
347  continue;
348 
349  int unit2 = comp2->GetUnitSelection( &sheetList[i] ); // slow
350 
351  for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) )
352  {
353  wxASSERT( pin->Type() == LIB_PIN_T );
354 
355  if( pin->GetUnit() && pin->GetUnit() != unit2 )
356  continue;
357 
358  if( pin->GetConvert() && pin->GetConvert() != comp2->GetConvert() )
359  continue;
360 
361  // A suitable pin is found: add it to the current list
362  addPinToComponentPinList( comp2, &sheetList[i], pin );
363  }
364  }
365  }
366 }
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
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: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 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().

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 
120  if( ref[0] == wxChar( '#' ) )
121  continue;
122 
123  // if( Component->m_FlagControlMulti == 1 )
124  // continue; /* yes */
125  // removed because with multiple instances of one schematic
126  // (several sheets pointing to 1 screen), this will be erroneously be
127  // toggled.
128 
129  LIB_PART* part = comp->GetPartRef().lock().get();
130 
131  if( !part )
132  continue;
133 
134  // If component is a "multi parts per package" type
135  if( part->GetUnitCount() > 1 )
136  {
137  // test if this reference has already been processed, and if so skip
138  if( m_ReferencesAlreadyFound.Lookup( ref ) )
139  continue;
140  }
141 
142  // record the usage of this library component entry.
143  m_LibParts.insert( part ); // rejects non-unique pointers
144 
145  return comp;
146  }
147 
148  return NULL;
149 }
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...
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: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.
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 160 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, sortPinsByNum(), and EDA_ITEM::Type().

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

162 {
163  wxString ref;
164 
165  m_SortedComponentPinList.clear();
166 
167  // continue searching from the middle of a linked list (the draw list)
168  for( ; aItem; aItem = aItem->Next() )
169  {
170  if( aItem->Type() != SCH_COMPONENT_T )
171  continue;
172 
173  // found next component
174  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
175 
176  // Power symbols and other components which have the reference starting
177  // with "#" are not included in netlist (pseudo or virtual components)
178  ref = comp->GetRef( aSheetPath );
179 
180  if( ref[0] == wxChar( '#' ) )
181  continue;
182 
183  // if( Component->m_FlagControlMulti == 1 )
184  // continue; /* yes */
185  // removed because with multiple instances of one schematic
186  // (several sheets pointing to 1 screen), this will be erroneously be
187  // toggled.
188 
189  LIB_PART* part = comp->GetPartRef().lock().get();
190 
191  if( !part )
192  continue;
193 
194  // If component is a "multi parts per package" type
195  if( part->GetUnitCount() > 1 )
196  {
197  // test if this reference has already been processed, and if so skip
198  if( m_ReferencesAlreadyFound.Lookup( ref ) )
199  continue;
200 
201  // Collect all pins for this reference designator by searching
202  // the entire design for other parts with the same reference designator.
203  // This is only done once, it would be too expensive otherwise.
204  findAllUnitsOfComponent( comp, part, aSheetPath );
205  }
206 
207  else // entry->GetUnitCount() <= 1 means one part per package
208  {
209  LIB_PINS pins; // constructed once here
210 
211  part->GetPins( pins, comp->GetUnitSelection( aSheetPath ), comp->GetConvert() );
212 
213  for( size_t i = 0; i < pins.size(); i++ )
214  {
215  LIB_PIN* pin = pins[i];
216 
217  wxASSERT( pin->Type() == LIB_PIN_T );
218 
219  addPinToComponentPinList( comp, aSheetPath, pin );
220  }
221  }
222 
223  // Sort pins in m_SortedComponentPinList by pin number
224  sort( m_SortedComponentPinList.begin(),
226 
227  // Remove duplicate Pins in m_SortedComponentPinList
229 
230  // record the usage of this library component entry.
231  m_LibParts.insert( part ); // rejects non-unique pointers
232 
233  return comp;
234  }
235 
236  return NULL;
237 }
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...
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:206
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:70
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.
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 }
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_CADSTAR::writeListOfNets ( FILE *  f)
private

Function writeListOfNetsCADSTAR writes a net list (ranked by Netcode), and pins connected to it.

Format:

  • ADD_TER RR2 6 "$42"
  • B U1 100
  • 6 CA

Definition at line 121 of file netlist_exporter_cadstar.cpp.

References FROM_UTF8(), GetChars(), NETLIST_OBJECT::GetComponentParent(), NETLIST_OBJECT_LIST::GetItem(), NETLIST_OBJECT::GetNet(), NETLIST_OBJECT::GetNetName(), SCH_COMPONENT::GetRef(), NETLIST_OBJECT::m_Flag, NETLIST_EXPORTER::m_masterList, NETLIST_OBJECT::m_PinNum, NETLIST_OBJECT::m_SheetPath, NETLIST_OBJECT::m_Type, NET_PIN, StartLine(), and TO_UTF8.

Referenced by WriteNetlist().

122 {
123  int ret = 0;
124  wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
125  wxString StartNetDesc = StartLine + wxT( "TER" );
126  wxString netcodeName, InitNetDescLine;
127  unsigned ii;
128  int print_ter = 0;
129  int NetCode, lastNetCode = -1;
130  SCH_COMPONENT* Cmp;
131  wxString netName;
132 
133  for( ii = 0; ii < m_masterList->size(); ii++ )
134  {
135  NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
136 
137  // Get the NetName of the current net :
138  if( ( NetCode = nitem->GetNet() ) != lastNetCode )
139  {
140  netName = nitem->GetNetName();
141  netcodeName = wxT( "\"" );
142 
143  if( !netName.IsEmpty() )
144  netcodeName << netName;
145  else // this net has no name: create a default name $<net number>
146  netcodeName << wxT( "$" ) << NetCode;
147 
148  netcodeName += wxT( "\"" );
149  lastNetCode = NetCode;
150  print_ter = 0;
151  }
152 
153 
154  if( nitem->m_Type != NET_PIN )
155  continue;
156 
157  if( nitem->m_Flag != 0 )
158  continue;
159 
160  Cmp = nitem->GetComponentParent();
161  wxString refstr = Cmp->GetRef( &nitem->m_SheetPath );
162  if( refstr[0] == '#' )
163  continue; // Power supply symbols.
164 
165  switch( print_ter )
166  {
167  case 0:
168  {
169  char buf[5];
170  wxString str_pinnum;
171  strncpy( buf, (char*) &nitem->m_PinNum, 4 );
172  buf[4] = 0;
173  str_pinnum = FROM_UTF8( buf );
174  InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
175  GetChars( InitNetDesc ),
176  GetChars( refstr ),
177  GetChars( str_pinnum ),
178  GetChars( netcodeName ) );
179  }
180  print_ter++;
181  break;
182 
183  case 1:
184  ret |= fprintf( f, "%s\n", TO_UTF8( InitNetDescLine ) );
185  ret |= fprintf( f, "%s %s %.4s\n",
186  TO_UTF8( StartNetDesc ),
187  TO_UTF8( refstr ),
188  (char*) &nitem->m_PinNum );
189  print_ter++;
190  break;
191 
192  default:
193  ret |= fprintf( f, " %s %.4s\n",
194  TO_UTF8( refstr ),
195  (char*) &nitem->m_PinNum );
196  break;
197  }
198 
199  nitem->m_Flag = 1;
200  }
201 
202  return ret >= 0;
203 }
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
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
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
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
static wxString StartLine(wxT("."))
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
bool NETLIST_EXPORTER_CADSTAR::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions 
)
overridevirtual

Function WriteList writes to specified output file.

Reimplemented from NETLIST_EXPORTER.

Definition at line 39 of file netlist_exporter_cadstar.cpp.

References UNIQUE_STRINGS::Clear(), DateAndTime(), DisplayError(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), g_RootSheet, GetBuildVersion(), GetChars(), SCH_COMPONENT::GetField(), NETLIST_OBJECT_LIST::GetItem(), SCH_COMPONENT::GetRef(), EDA_TEXT::GetText(), NETLIST_OBJECT::m_Flag, NETLIST_EXPORTER::m_masterList, NETLIST_EXPORTER::m_ReferencesAlreadyFound, NETLIST_EXPORTER::m_SortedComponentPinList, EDA_ITEM::Next(), StartLine(), TO_UTF8, VALUE, and writeListOfNets().

40 {
41  (void)aNetlistOptions; //unused
42  int ret = 0;
43  FILE* f = NULL;
44 
45  if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
46  {
47  wxString msg;
48  msg.Printf( _( "Failed to create file '%s'" ),
49  GetChars( aOutFileName ) );
50  DisplayError( NULL, msg );
51  return false;
52  }
53 
54  wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
55  wxString msg;
56  EDA_ITEM* DrawList;
57  SCH_COMPONENT* component;
58  wxString title = wxT( "Eeschema " ) + GetBuildVersion();
59 
60  ret |= fprintf( f, "%sHEA\n", TO_UTF8( StartLine ) );
61  ret |= fprintf( f, "%sTIM %s\n", TO_UTF8( StartLine ), TO_UTF8( DateAndTime() ) );
62  ret |= fprintf( f, "%sAPP ", TO_UTF8( StartLine ) );
63  ret |= fprintf( f, "\"%s\"\n", TO_UTF8( title ) );
64  ret |= fprintf( f, "\n" );
65 
66  // Prepare list of nets generation
67  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
68  m_masterList->GetItem( ii )->m_Flag = 0;
69 
70  // Create netlist module section
72 
73  SCH_SHEET_LIST sheetList( g_RootSheet );
74 
75  for( unsigned i = 0; i < sheetList.size(); i++ )
76  {
77  for( DrawList = sheetList[i].LastDrawList(); DrawList != NULL; DrawList = DrawList->Next() )
78  {
79  DrawList = component = findNextComponentAndCreatePinList( DrawList, &sheetList[i] );
80 
81  if( component == NULL )
82  break;
83 
84  /*
85  doing nothing with footprint
86  if( !component->GetField( FOOTPRINT )->IsVoid() )
87  {
88  footprint = component->GetField( FOOTPRINT )->m_Text;
89  footprint.Replace( wxT( " " ), wxT( "_" ) );
90  }
91  else
92  footprint = wxT( "$noname" );
93  */
94 
95  msg = component->GetRef( &sheetList[i] );
96  ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
97  ret |= fprintf( f, "%s", TO_UTF8( msg ) );
98 
99  msg = component->GetField( VALUE )->GetText();
100  msg.Replace( wxT( " " ), wxT( "_" ) );
101  ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
102  ret |= fprintf( f, "\n" );
103  }
104  }
105 
106  ret |= fprintf( f, "\n" );
107 
108  m_SortedComponentPinList.clear();
109 
110  if( ! writeListOfNets( f ) )
111  ret = -1; // set error
112 
113  ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) );
114 
115  fclose( f );
116 
117  return ret >= 0;
118 }
Class SCH_SHEET_LIST.
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once...
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
EDA_ITEM * Next() const
Definition: base_struct.h:206
void Clear()
Function Clear erases the record.
NETLIST_OBJECT_LIST * m_masterList
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes...
Definition: macros.h:47
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
SCH_COMPONENT * findNextComponentAndCreatePinList(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin lis...
static wxString StartLine(wxT("."))
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
Field Value of part, i.e. "3.3K".
bool writeListOfNets(FILE *f)
Function writeListOfNetsCADSTAR writes a net list (ranked by Netcode), and pins connected to it...
NETLIST_OBJECTS m_SortedComponentPinList
no ownership
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
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:151
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:71
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:229

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


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