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)
 
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 &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
 Function MakeCommandLine builds up a string that describes a command line for executing a child process. More...
 

Protected Member Functions

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
 
NETLIST_OBJECTS m_SortedComponentPinList
 yes ownership, connected items flat list 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...
 

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 36 of file netlist_exporter_cadstar.h.

Constructor & Destructor Documentation

◆ NETLIST_EXPORTER_CADSTAR()

NETLIST_EXPORTER_CADSTAR::NETLIST_EXPORTER_CADSTAR ( NETLIST_OBJECT_LIST aMasterList)
inline

Definition at line 51 of file netlist_exporter_cadstar.h.

51  :
52  NETLIST_EXPORTER( aMasterList )
53  {
54  }
NETLIST_EXPORTER(NETLIST_OBJECT_LIST *aMasterList)
Constructor.

Member Function Documentation

◆ addPinToComponentPinList()

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 238 of file netlist_exporter.cpp.

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

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

◆ eraseDuplicatePins()

void NETLIST_EXPORTER::eraseDuplicatePins ( )
protectedinherited

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

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

Definition at line 274 of file netlist_exporter.cpp.

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

References NETLIST_EXPORTER::m_SortedComponentPinList, and PAD_CONNECT.

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

◆ findAllUnitsOfComponent()

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

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

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

Definition at line 325 of file netlist_exporter.cpp.

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:218
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
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.
size_t i
Definition: json11.cpp:597
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
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...
int GetConvert() const

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

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

◆ findNextComponent()

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

Definition at line 101 of file netlist_exporter.cpp.

102 {
103  wxString ref;
104 
105  // continue searching from the middle of a linked list (the draw list)
106  for( ; aItem; aItem = aItem->Next() )
107  {
108  if( aItem->Type() != SCH_COMPONENT_T )
109  continue;
110 
111  // found next component
112  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
113 
114  // Power symbols and other components which have the reference starting
115  // with "#" are not included in netlist (pseudo or virtual components)
116  ref = comp->GetRef( aSheetPath );
117 
118  if( ref[0] == wxChar( '#' ) )
119  continue;
120 
121  // if( Component->m_FlagControlMulti == 1 )
122  // continue; /* yes */
123  // removed because with multiple instances of one schematic
124  // (several sheets pointing to 1 screen), this will be erroneously be
125  // toggled.
126 
127  LIB_PART* part = comp->GetPartRef().lock().get();
128 
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 }
int GetUnitCount() const
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:218
std::set< LIB_PART *, LIB_PART_LESS_THAN > m_LibParts
unique library parts used. LIB_PART items are sorted by names
Define a library symbol object.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210

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

◆ findNextComponentAndCreatePinList()

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.

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 = comp->GetPartRef().lock().get();
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  findAllUnitsOfComponent( 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 }
int GetUnitCount() const
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.
std::vector< LIB_PIN * > LIB_PINS
Helper for defining a list of pin object pointers.
Definition: lib_item.h:55
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
void findAllUnitsOfComponent(SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
Function findAllUnitsOfComponent is used for "multiple parts per package" components.
EDA_ITEM * Next() const
Definition: base_struct.h:218
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
Define a library symbol object.
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
NETLIST_OBJECTS m_SortedComponentPinList
yes ownership, connected items flat list
size_t i
Definition: json11.cpp:597
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
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...
int GetConvert() const
KICAD_T Type() const
Function Type()
Definition: base_struct.h:210
void eraseDuplicatePins()
Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i....

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

◆ MakeCommandLine()

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

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

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

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

Supported formatting sequences and their meaning:

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

Definition at line 39 of file netlist_exporter.cpp.

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

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

◆ sprintPinNetName()

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 73 of file netlist_exporter.cpp.

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

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

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

◆ writeListOfNets()

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 117 of file netlist_exporter_cadstar.cpp.

118 {
119  int ret = 0;
120  wxString InitNetDesc = StartLine + wxT( "ADD_TER" );
121  wxString StartNetDesc = StartLine + wxT( "TER" );
122  wxString netcodeName, InitNetDescLine;
123  unsigned ii;
124  int print_ter = 0;
125  int NetCode, lastNetCode = -1;
126  SCH_COMPONENT* Cmp;
127  wxString netName;
128 
129  for( ii = 0; ii < m_masterList->size(); ii++ )
130  {
131  NETLIST_OBJECT* nitem = m_masterList->GetItem( ii );
132 
133  // Get the NetName of the current net :
134  if( ( NetCode = nitem->GetNet() ) != lastNetCode )
135  {
136  netName = nitem->GetNetName();
137  netcodeName = wxT( "\"" );
138 
139  if( !netName.IsEmpty() )
140  netcodeName << netName;
141  else // this net has no name: create a default name $<net number>
142  netcodeName << wxT( "$" ) << NetCode;
143 
144  netcodeName += wxT( "\"" );
145  lastNetCode = NetCode;
146  print_ter = 0;
147  }
148 
149 
150  if( nitem->m_Type != NET_PIN )
151  continue;
152 
153  if( nitem->m_Flag != 0 )
154  continue;
155 
156  Cmp = nitem->GetComponentParent();
157  wxString refstr = Cmp->GetRef( &nitem->m_SheetPath );
158  if( refstr[0] == '#' )
159  continue; // Power supply symbols.
160 
161  switch( print_ter )
162  {
163  case 0:
164  {
165  InitNetDescLine.Printf( wxT( "\n%s %s %.4s %s" ),
166  GetChars( InitNetDesc ),
167  GetChars( refstr ),
168  GetChars( nitem->m_PinNum ),
169  GetChars( netcodeName ) );
170  }
171  print_ter++;
172  break;
173 
174  case 1:
175  ret |= fprintf( f, "%s\n", TO_UTF8( InitNetDescLine ) );
176  ret |= fprintf( f, "%s %s %.4s\n",
177  TO_UTF8( StartNetDesc ),
178  TO_UTF8( refstr ),
179  TO_UTF8( nitem->m_PinNum ) );
180  print_ter++;
181  break;
182 
183  default:
184  ret |= fprintf( f, " %s %.4s\n",
185  TO_UTF8( refstr ),
186  TO_UTF8( nitem->m_PinNum ) );
187  break;
188  }
189 
190  nitem->m_Flag = 1;
191  }
192 
193  return ret >= 0;
194 }
SCH_COMPONENT * GetComponentParent() const
For Pins (NET_PINS):
int GetNet() const
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:48
static wxString StartLine(wxT("."))
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
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:101
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73

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

◆ WriteNetlist()

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 38 of file netlist_exporter_cadstar.cpp.

39 {
40  (void)aNetlistOptions; //unused
41  int ret = 0;
42  FILE* f = NULL;
43 
44  if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
45  {
46  wxString msg;
47  msg.Printf( _( "Failed to create file \"%s\"" ),
48  GetChars( aOutFileName ) );
49  DisplayError( NULL, msg );
50  return false;
51  }
52 
53  wxString StartCmpDesc = StartLine + wxT( "ADD_COM" );
54  wxString msg;
55  wxString footprint;
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, ".TYP FULL\n\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  if( !component->GetField( FOOTPRINT )->IsVoid() )
86  footprint = component->GetField( FOOTPRINT )->GetText();
87  else
88  footprint = "$noname";
89 
90  msg = component->GetRef( &sheetList[i] );
91  ret |= fprintf( f, "%s ", TO_UTF8( StartCmpDesc ) );
92  ret |= fprintf( f, "%s", TO_UTF8( msg ) );
93 
94  msg = component->GetField( VALUE )->GetText();
95  msg.Replace( wxT( " " ), wxT( "_" ) );
96  ret |= fprintf( f, " \"%s\"", TO_UTF8( msg ) );
97  ret |= fprintf( f, " \"%s\"", TO_UTF8( footprint ) );
98  ret |= fprintf( f, "\n" );
99  }
100  }
101 
102  ret |= fprintf( f, "\n" );
103 
104  m_SortedComponentPinList.clear();
105 
106  if( ! writeListOfNets( f ) )
107  ret = -1; // set error
108 
109  ret |= fprintf( f, "\n%sEND\n", TO_UTF8( StartLine ) );
110 
111  fclose( f );
112 
113  return ret >= 0;
114 }
Class SCH_SHEET_LIST.
UNIQUE_STRINGS m_ReferencesAlreadyFound
Used for "multi parts per package" components, avoids processing a lib component more than once.
void Clear()
Function Clear erases the record.
NETLIST_OBJECT_LIST * m_masterList
Field Name Module PCB, i.e. "16DIP300".
bool IsVoid() const
Function IsVoid returns true if the field is either empty or holds "~".
Definition: sch_field.cpp:257
EDA_ITEM * Next() const
Definition: base_struct.h:218
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
#define VALUE
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:47
wxString GetBuildVersion()
Function GetBuildVersion Return the build version string.
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.
#define _(s)
bool writeListOfNets(FILE *f)
Function writeListOfNetsCADSTAR writes a net list (ranked by Netcode), and pins connected to it.
NETLIST_OBJECTS m_SortedComponentPinList
yes ownership, connected items flat list
NETLIST_OBJECT * GetItem(unsigned aIdx) const
Acces to an item in list.
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:101
size_t i
Definition: json11.cpp:597
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:73
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:163
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:243
virtual const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:124
wxString DateAndTime()
Definition: string.cpp:333

References _, UNIQUE_STRINGS::Clear(), DateAndTime(), DisplayError(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), FOOTPRINT, g_RootSheet, GetBuildVersion(), GetChars(), SCH_COMPONENT::GetField(), NETLIST_OBJECT_LIST::GetItem(), SCH_COMPONENT::GetRef(), EDA_TEXT::GetText(), i, SCH_FIELD::IsVoid(), 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().

Member Data Documentation

◆ m_LibParts

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

◆ m_masterList

◆ m_ReferencesAlreadyFound

UNIQUE_STRINGS NETLIST_EXPORTER::m_ReferencesAlreadyFound
protectedinherited

◆ m_SortedComponentPinList

NETLIST_OBJECTS NETLIST_EXPORTER::m_SortedComponentPinList
protectedinherited

yes ownership, connected items flat list

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 95 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: