KiCad PCB EDA Suite
NETLIST_EXPORTER_ORCADPCB2 Class Reference

Class NETLIST_EXPORTER_ORCADPCB2 generates a netlist compatible with OrCAD. More...

#include <netlist_exporter_orcadpcb2.h>

Inheritance diagram for NETLIST_EXPORTER_ORCADPCB2:
NETLIST_EXPORTER

Public Member Functions

 NETLIST_EXPORTER_ORCADPCB2 (NETLIST_OBJECT_LIST *aMasterList)
 
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 &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...
 

Detailed Description

Class NETLIST_EXPORTER_ORCADPCB2 generates a netlist compatible with OrCAD.

Definition at line 35 of file netlist_exporter_orcadpcb2.h.

Constructor & Destructor Documentation

NETLIST_EXPORTER_ORCADPCB2::NETLIST_EXPORTER_ORCADPCB2 ( NETLIST_OBJECT_LIST aMasterList)
inline

Definition at line 38 of file netlist_exporter_orcadpcb2.h.

References WriteNetlist().

38  :
39  NETLIST_EXPORTER( aMasterList )
40  {
41  }
NETLIST_EXPORTER(NETLIST_OBJECT_LIST *aMasterList)
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 244 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().

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

References NETLIST_EXPORTER::m_SortedComponentPinList, and PAD_CONNECT.

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

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

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

333 {
334  wxString ref = aComponent->GetRef( aSheetPath );
335  wxString ref2;
336 
337  SCH_SHEET_LIST sheetList( g_RootSheet );
338 
339  for( unsigned i = 0; i < sheetList.size(); i++ )
340  {
341  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
342  {
343  if( item->Type() != SCH_COMPONENT_T )
344  continue;
345 
346  SCH_COMPONENT* comp2 = (SCH_COMPONENT*) item;
347 
348  ref2 = comp2->GetRef( &sheetList[i] );
349 
350  if( ref2.CmpNoCase( ref ) != 0 )
351  continue;
352 
353  int unit2 = comp2->GetUnitSelection( &sheetList[i] ); // slow
354 
355  for( LIB_PIN* pin = aEntry->GetNextPin(); pin; pin = aEntry->GetNextPin( pin ) )
356  {
357  wxASSERT( pin->Type() == LIB_PIN_T );
358 
359  if( pin->GetUnit() && pin->GetUnit() != unit2 )
360  continue;
361 
362  if( pin->GetConvert() && pin->GetConvert() != comp2->GetConvert() )
363  continue;
364 
365  // A suitable pin is found: add it to the current list
366  addPinToComponentPinList( comp2, &sheetList[i], pin );
367  }
368  }
369  }
370 }
Class SCH_SHEET_LIST.
int GetUnitSelection(SCH_SHEET_PATH *aSheet)
EDA_ITEM * Next() const
Definition: base_struct.h:209
int GetConvert() const
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:56
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:69
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:154
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 107 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().

108 {
109  wxString ref;
110 
111  // continue searching from the middle of a linked list (the draw list)
112  for( ; aItem; aItem = aItem->Next() )
113  {
114  if( aItem->Type() != SCH_COMPONENT_T )
115  continue;
116 
117  // found next component
118  SCH_COMPONENT* comp = (SCH_COMPONENT*) aItem;
119 
120  // Power symbols and other components which have the reference starting
121  // with "#" are not included in netlist (pseudo or virtual components)
122  ref = comp->GetRef( aSheetPath );
123 
124  if( ref[0] == wxChar( '#' ) )
125  continue;
126 
127  // if( Component->m_FlagControlMulti == 1 )
128  // continue; /* yes */
129  // removed because with multiple instances of one schematic
130  // (several sheets pointing to 1 screen), this will be erroneously be
131  // toggled.
132 
133  LIB_PART* part = comp->GetPartRef().lock().get();
134 
135  if( !part )
136  continue;
137 
138  // If component is a "multi parts per package" type
139  if( part->GetUnitCount() > 1 )
140  {
141  // test if this reference has already been processed, and if so skip
142  if( m_ReferencesAlreadyFound.Lookup( ref ) )
143  continue;
144  }
145 
146  // record the usage of this library component entry.
147  m_LibParts.insert( part ); // rejects non-unique pointers
148 
149  return comp;
150  }
151 
152  return NULL;
153 }
KICAD_T Type() const
Function Type()
Definition: base_struct.h:201
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:209
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.
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 164 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(), 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(), WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

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

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

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

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

Function WriteNetlist writes to specified output file.

Reimplemented from NETLIST_EXPORTER.

Definition at line 39 of file netlist_exporter_orcadpcb2.cpp.

References UNIQUE_STRINGS::Clear(), DateAndTime(), DisplayError(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), FOOTPRINT, g_RootSheet, GetChars(), SCH_COMPONENT::GetField(), NETLIST_OBJECT_LIST::GetItem(), SCH_COMPONENT::GetPartRef(), SCH_COMPONENT::GetPath(), SCH_COMPONENT::GetRef(), EDA_TEXT::GetText(), i, SCH_FIELD::IsVoid(), NETLIST_OBJECT::m_Flag, NETLIST_EXPORTER::m_masterList, NETLIST_OBJECT::m_PinNum, NETLIST_EXPORTER::m_ReferencesAlreadyFound, NETLIST_EXPORTER::m_SortedComponentPinList, NETLIST_HEAD_STRING, NETLIST_EXPORTER::sprintPinNetName(), TO_UTF8, and VALUE.

Referenced by NETLIST_EXPORTER_ORCADPCB2().

41 {
42  (void)aNetlistOptions; //unused
43  FILE* f = NULL;
44  wxString field;
45  wxString footprint;
46  int ret = 0; // zero now, OR in the sign bit on error
47  wxString netName;
48 
49 
50  if( ( f = wxFopen( aOutFileName, wxT( "wt" ) ) ) == NULL )
51  {
52  wxString msg;
53  msg.Printf( _( "Failed to create file \"%s\"" ),
54  GetChars( aOutFileName ) );
55  DisplayError( NULL, msg );
56  return false;
57  }
58 
59  std::vector< SCH_REFERENCE > cmpList;
60 
61  ret |= fprintf( f, "( { %s created %s }\n",
63 
64  // Prepare list of nets generation
65  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
66  m_masterList->GetItem( ii )->m_Flag = 0;
67 
68  // Create netlist module section
70 
71  SCH_SHEET_LIST sheetList( g_RootSheet );
72 
73  for( unsigned i = 0; i < sheetList.size(); i++ )
74  {
75  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
76  {
77  SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[i] );
78 
79  if( !comp )
80  break;
81 
82  item = comp;
83 
84  PART_SPTR part = comp->GetPartRef().lock();
85 
86  if( part )
87  {
88  if( part->GetFootprints().GetCount() != 0 ) // Put in list
89  {
90  cmpList.push_back( SCH_REFERENCE( comp, part.get(), sheetList[i] ) );
91  }
92  }
93 
94  if( !comp->GetField( FOOTPRINT )->IsVoid() )
95  {
96  footprint = comp->GetField( FOOTPRINT )->GetText();
97  footprint.Replace( wxT( " " ), wxT( "_" ) );
98  }
99  else
100  footprint = wxT( "$noname" );
101 
102  field = comp->GetRef( &sheetList[i] );
103 
104  ret |= fprintf( f, " ( %s %s",
105  TO_UTF8( comp->GetPath( &sheetList[i] ) ),
106  TO_UTF8( footprint ) );
107 
108  ret |= fprintf( f, " %s", TO_UTF8( field ) );
109 
110  field = comp->GetField( VALUE )->GetText();
111  field.Replace( wxT( " " ), wxT( "_" ) );
112  ret |= fprintf( f, " %s", TO_UTF8( field ) );
113 
114  ret |= fprintf( f, "\n" );
115 
116  // Write pin list:
117  for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
118  {
120 
121  if( !pin )
122  continue;
123 
124  sprintPinNetName( netName, wxT( "N-%.6d" ), pin );
125 
126  if( netName.IsEmpty() )
127  netName = wxT( "?" );
128 
129  netName.Replace( wxT( " " ), wxT( "_" ) );
130 
131  ret |= fprintf( f, " ( %4.4s %s )\n", TO_UTF8( pin->m_PinNum ),
132  TO_UTF8( netName ) );
133  }
134 
135  ret |= fprintf( f, " )\n" );
136  }
137  }
138 
139  ret |= fprintf( f, ")\n*\n" );
140 
141  fclose( f );
142 
143  m_SortedComponentPinList.clear();
144  return ret >= 0;
145 }
Class SCH_SHEET_LIST.
#define NETLIST_HEAD_STRING
Definition: netlist.h:50
PART_REF & GetPartRef()
wxString GetPath(const SCH_SHEET_PATH *sheet) const
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.
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...
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:209
void Clear()
Function Clear erases the record.
NETLIST_OBJECT_LIST * m_masterList
Field Name Module PCB, i.e. "16DIP300".
#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:56
SCH_FIELD * GetField(int aFieldNdx) const
Returns a field in this symbol.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:143
std::shared_ptr< LIB_PART > PART_SPTR
shared pointer to LIB_PART
SCH_COMPONENT * findNextComponentAndCreatePinList(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin lis...
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
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
size_t i
Definition: json11.cpp:597
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:154
#define VALUE
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:245
Class SCH_REFERENCE is used as a helper to define a component&#39;s reference designator in a schematic...
wxString DateAndTime()
Function DateAndTime.
Definition: string.cpp:306

Member Data Documentation

std::set<LIB_PART*, LIB_PART_LESS_THAN> NETLIST_EXPORTER::m_LibParts
protectedinherited
UNIQUE_STRINGS NETLIST_EXPORTER::m_ReferencesAlreadyFound
protectedinherited
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(), WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().


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