KiCad PCB EDA Suite
NETLIST_EXPORTER_PSPICE Class Reference

Class NETLIST_EXPORTER_PSPICE generates a PSPICE compatible netlist. More...

#include <netlist_exporter_pspice.h>

Inheritance diagram for NETLIST_EXPORTER_PSPICE:
NETLIST_EXPORTER NETLIST_EXPORTER_PSPICE_SIM

Public Types

typedef std::list< SPICE_ITEMSPICE_ITEM_LIST
 
typedef std::map< wxString, int > NET_INDEX_MAP
 

Net name to circuit node number mapping

More...
 

Public Member Functions

 NETLIST_EXPORTER_PSPICE (NETLIST_OBJECT_LIST *aMasterList, PROJECT *aProject=NULL)
 
virtual ~NETLIST_EXPORTER_PSPICE ()
 
const SPICE_ITEM_LISTGetSpiceItems () const
 Returns list of items representing schematic components in the Spice world. More...
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions) override
 Function WriteNetlist writes to specified output file. More...
 
bool Format (OUTPUTFORMATTER *aFormatter, unsigned aCtl)
 > More...
 
bool ProcessNetlist (unsigned aCtl)
 Processes the netlist to create net mapping and a list of SPICE_ITEMs. More...
 
const NET_INDEX_MAPGetNetIndexMap () const
 Returns a map of circuit nodes to net names. More...
 
void UpdateDirectives (unsigned aCtl)
 Updates the vector of Spice directives placed in the schematics. More...
 
const std::vector< wxString > GetDirectives () const
 Returnss a vector of Spice directives found in the schematics. More...
 

Static Public Member Functions

static void ReplaceForbiddenChars (wxString &aNetName)
 some chars are not accepted in netnames in spice netlists. More...
 
static const std::vector< wxString > & GetSpiceFields ()
 Returns a vector of component field names related to Spice simulation. More...
 
static const wxString & GetSpiceFieldName (SPICE_FIELD aField)
 Returns a string used for a particular component field related to Spice simulation. More...
 
static wxString GetSpiceField (SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
 Retrieves either the requested field value or the default value. More...
 
static wxString GetSpiceFieldDefVal (SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
 Retrieves the default value for a given field. More...
 
static bool StringToBool (const wxString &aStr)
 Convertes typical boolean string values (no/yes, true/false, 1/0) to a boolean value. More...
 
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

virtual void writeDirectives (OUTPUTFORMATTER *aFormatter, unsigned aCtl) const
 Saves the Spice directives. More...
 
SCH_COMPONENTfindNextComponentAndCreatePinList (EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
 Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin list in m_SortedComponentPinList. More...
 
SCH_COMPONENTfindNextComponent (EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
 
void eraseDuplicatePins ()
 Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i.e. More...
 
bool addPinToComponentPinList (SCH_COMPONENT *Component, SCH_SHEET_PATH *sheet, LIB_PIN *PinEntry)
 Function addPinToComponentPinList adds a new pin description to the pin list m_SortedComponentPinList. More...
 
void 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 Attributes

wxString m_title
 

Spice simulation title found in the processed schematic sheet

More...
 
std::vector< wxString > m_directives
 

Spice directives found in the processed schematic sheet

More...
 
std::set< wxString > m_libraries
 

Libraries used by the simulated circuit

More...
 
NET_INDEX_MAP m_netMap
 

Maps circuit nodes to net names

More...
 
SPICE_ITEM_LIST m_spiceItems
 

List of items representing schematic components in the Spice world

More...
 
PROJECTm_project
 

Project object to fetch its settings (e.g. paths)

More...
 

Static Private Attributes

static const std::vector< wxString > m_spiceFields
 

Detailed Description

Class NETLIST_EXPORTER_PSPICE generates a PSPICE compatible netlist.

Definition at line 99 of file netlist_exporter_pspice.h.

Member Typedef Documentation

typedef std::map<wxString, int> NETLIST_EXPORTER_PSPICE::NET_INDEX_MAP

Net name to circuit node number mapping

Definition at line 115 of file netlist_exporter_pspice.h.

Definition at line 112 of file netlist_exporter_pspice.h.

Constructor & Destructor Documentation

NETLIST_EXPORTER_PSPICE::NETLIST_EXPORTER_PSPICE ( NETLIST_OBJECT_LIST aMasterList,
PROJECT aProject = NULL 
)
inline

Definition at line 102 of file netlist_exporter_pspice.h.

102  :
103  NETLIST_EXPORTER( aMasterList ),
104  m_project( aProject )
105  {
106  }
NETLIST_EXPORTER(NETLIST_OBJECT_LIST *aMasterList)
Constructor.
PROJECT * m_project
Project object to fetch its settings (e.g. paths)
virtual NETLIST_EXPORTER_PSPICE::~NETLIST_EXPORTER_PSPICE ( )
inlinevirtual

Definition at line 108 of file netlist_exporter_pspice.h.

109  {
110  }

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:74
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(), 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:235
int GetConvert() const
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
const wxString GetRef(const SCH_SHEET_PATH *aSheet)
Return the reference for the given sheet path.
LIB_PIN * GetNextPin(LIB_PIN *aItem=NULL)
Return the next pin object from the draw list.
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:180
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:227
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:235
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(), 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 ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::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:227
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:235
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:60
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:69
bool addPinToComponentPinList(SCH_COMPONENT *Component, SCH_SHEET_PATH *sheet, LIB_PIN *PinEntry)
Function addPinToComponentPinList adds a new pin description to the pin list m_SortedComponentPinList...
void eraseDuplicatePins()
Function eraseDuplicatePins erase duplicate Pins from m_SortedComponentPinList (i.e.
bool NETLIST_EXPORTER_PSPICE::Format ( OUTPUTFORMATTER aFormatter,
unsigned  aCtl 
)

>

Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.

Definition at line 60 of file netlist_exporter_pspice.cpp.

References DisplayError(), Format(), NETLIST_OBJECT::GetNetName(), m_libraries, m_netMap, m_project, m_spiceItems, m_title, NET_ADJUST_INCLUDE_PATHS, Pgm(), OUTPUTFORMATTER::Print(), ProcessNetlist(), ReplaceForbiddenChars(), ResolveFile(), NETLIST_EXPORTER::sprintPinNetName(), TO_UTF8, and writeDirectives().

Referenced by WriteNetlist().

61 {
62  // Netlist options
63  const bool useNetcodeAsNetName = false;//aCtl & NET_USE_NETCODES_AS_NETNAMES;
64 
65  // default title
66  m_title = "KiCad schematic";
67 
68  if( !ProcessNetlist( aCtl ) )
69  return false;
70 
71  aFormatter->Print( 0, ".title %s\n", (const char*) m_title.c_str() );
72 
73  // Write .include directives
74  for( const auto& lib : m_libraries )
75  {
76  wxString full_path;
77 
78  if( ( aCtl & NET_ADJUST_INCLUDE_PATHS ) )
79  {
80  // Look for the library in known search locations
81  full_path = ResolveFile( lib, &Pgm().GetLocalEnvVariables(), m_project );
82 
83  if( full_path.IsEmpty() )
84  {
85  DisplayError( NULL, wxString::Format( _( "Could not find library file %s" ), lib ) );
86  full_path = lib;
87  }
88  }
89  else
90  full_path = lib; // just use the unaltered path
91 
92  aFormatter->Print( 0, ".include \"%s\"\n", (const char*) full_path.c_str() );
93  }
94 
95  for( const auto& item : m_spiceItems )
96  {
97  if( !item.m_enabled )
98  continue;
99 
100  // Save the node order
101  aFormatter->Print( 0, "%c%s ", item.m_primitive, (const char*) item.m_refName.c_str() );
102 
103  size_t pspiceNodes = item.m_pinSequence.empty() ? item.m_pins.size() : item.m_pinSequence.size();
104 
105  for( size_t ii = 0; ii < pspiceNodes; ii++ )
106  {
107  // Use the custom order if defined, otherwise use the standard pin order as defined in the compon
108  size_t activePinIndex = item.m_pinSequence.empty() ? ii : item.m_pinSequence[ii];
109  // Valid used Node Indexes are in the set
110  // {0,1,2,...m_item.m_pin.size()-1}
111  if( activePinIndex >= item.m_pins.size() )
112  {
113  wxASSERT_MSG( false, "Used an invalid pin number in node sequence" );
114  continue;
115  }
116 
117  NETLIST_OBJECT* pin = item.m_pins[activePinIndex];
118  assert( pin );
119  wxString netName = pin->GetNetName();
120 
121  if( useNetcodeAsNetName )
122  {
123  assert( m_netMap.count( netName ) );
124  aFormatter->Print( 0, "%d ", m_netMap[netName] );
125  }
126  else
127  {
128  sprintPinNetName( netName , wxT( "N-%.6d" ), pin, useNetcodeAsNetName );
129 
130  // Replace parenthesis with underscore to prevent parse issues with simulators
131  ReplaceForbiddenChars( netName );
132 
133  if( netName.IsEmpty() )
134  netName = wxT( "?" );
135 
136  aFormatter->Print( 0, "%s ", TO_UTF8( netName ) );
137  }
138  }
139 
140  aFormatter->Print( 0, "%s\n", (const char*) item.m_model.c_str() );
141  }
142 
143  // Print out all directives found in the text fields on the schematics
144  writeDirectives( aFormatter, aCtl );
145 
146  aFormatter->Print( 0, ".end\n" );
147 
148  return true;
149 }
wxString ResolveFile(const wxString &aFileName, const ENV_VAR_MAP *aEnvVars, const PROJECT *aProject)
Searches the default paths trying to find one with the requested file.
Definition: env_paths.cpp:129
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
std::set< wxString > m_libraries
Libraries used by the simulated circuit
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...
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: kicad.cpp:65
SPICE_ITEM_LIST m_spiceItems
List of items representing schematic components in the Spice world
#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
wxString m_title
Spice simulation title found in the processed schematic sheet
NET_INDEX_MAP m_netMap
Maps circuit nodes to net names
bool ProcessNetlist(unsigned aCtl)
Processes the netlist to create net mapping and a list of SPICE_ITEMs.
static void ReplaceForbiddenChars(wxString &aNetName)
some chars are not accepted in netnames in spice netlists.
PROJECT * m_project
Project object to fetch its settings (e.g. paths)
virtual void writeDirectives(OUTPUTFORMATTER *aFormatter, unsigned aCtl) const
Saves the Spice directives.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:74
const std::vector<wxString> NETLIST_EXPORTER_PSPICE::GetDirectives ( ) const
inline

Returnss a vector of Spice directives found in the schematics.

Definition at line 193 of file netlist_exporter_pspice.h.

Referenced by NETLIST_EXPORTER_PSPICE_SIM::GetSheetSimCommand(), and NETLIST_EXPORTER_PSPICE_SIM::writeDirectives().

194  {
195  return m_directives;
196  }
std::vector< wxString > m_directives
Spice directives found in the processed schematic sheet
const NET_INDEX_MAP& NETLIST_EXPORTER_PSPICE::GetNetIndexMap ( ) const
inline

Returns a map of circuit nodes to net names.

Definition at line 154 of file netlist_exporter_pspice.h.

Referenced by DIALOG_SIM_SETTINGS::ShowModal(), DIALOG_SIM_SETTINGS::TransferDataFromWindow(), DIALOG_SIGNAL_LIST::TransferDataToWindow(), and NETLIST_EXPORTER_PSPICE_SIM::writeDirectives().

155  {
156  return m_netMap;
157  }
NET_INDEX_MAP m_netMap
Maps circuit nodes to net names
wxString NETLIST_EXPORTER_PSPICE::GetSpiceField ( SPICE_FIELD  aField,
SCH_COMPONENT aComponent,
unsigned  aCtl 
)
static

Retrieves either the requested field value or the default value.

Definition at line 152 of file netlist_exporter_pspice.cpp.

References SCH_COMPONENT::FindField(), GetSpiceFieldDefVal(), GetSpiceFieldName(), and EDA_TEXT::GetText().

Referenced by SIM_PLOT_FRAME::AddTuner(), ProcessNetlist(), and TUNER_SLIDER::TUNER_SLIDER().

154 {
155  SCH_FIELD* field = aComponent->FindField( GetSpiceFieldName( aField ) );
156  return field ? field->GetText() : GetSpiceFieldDefVal( aField, aComponent, aCtl );
157 }
Class SCH_FIELD instances are attached to a component and provide a place for the component&#39;s value...
Definition: sch_field.h:56
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
static const wxString & GetSpiceFieldName(SPICE_FIELD aField)
Returns a string used for a particular component field related to Spice simulation.
static wxString GetSpiceFieldDefVal(SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
Retrieves the default value for a given field.
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
wxString NETLIST_EXPORTER_PSPICE::GetSpiceFieldDefVal ( SPICE_FIELD  aField,
SCH_COMPONENT aComponent,
unsigned  aCtl 
)
static

Retrieves the default value for a given field.

Definition at line 160 of file netlist_exporter_pspice.cpp.

References SCH_COMPONENT::GetField(), SCH_COMPONENT::GetPins(), EDA_TEXT::GetText(), NET_ADJUST_PASSIVE_VALS, REFERENCE, SF_ENABLED, SF_LIB_FILE, SF_MODEL, SF_NODE_SEQUENCE, SF_PRIMITIVE, and VALUE.

Referenced by GetSpiceField(), and DIALOG_SPICE_MODEL::TransferDataToWindow().

162 {
163  switch( aField )
164  {
165  case SF_PRIMITIVE:
166  {
167  const wxString& refName = aComponent->GetField( REFERENCE )->GetText();
168  return refName.GetChar( 0 );
169  break;
170  }
171 
172  case SF_MODEL:
173  {
174  wxChar prim = aComponent->GetField( REFERENCE )->GetText().GetChar( 0 );
175  wxString value = aComponent->GetField( VALUE )->GetText();
176 
177  // Is it a passive component?
178  if( aCtl & NET_ADJUST_PASSIVE_VALS && ( prim == 'C' || prim == 'L' || prim == 'R' ) )
179  {
180  // Regular expression to match common formats used for passive parts description
181  // (e.g. 100k, 2k3, 1 uF)
182  wxRegEx passiveVal( "^([0-9\\. ]+)([fFpPnNuUmMkKgGtT]|M(e|E)(g|G))?([fFhH]|ohm)?([-1-9 ]*)$" );
183 
184  if( passiveVal.Matches( value ) )
185  {
186  wxString prefix( passiveVal.GetMatch( value, 1 ) );
187  wxString unit( passiveVal.GetMatch( value, 2 ) );
188  wxString suffix( passiveVal.GetMatch( value, 6 ) );
189 
190  prefix.Trim(); prefix.Trim( false );
191  unit.Trim(); unit.Trim( false );
192  suffix.Trim(); suffix.Trim( false );
193 
194  // Make 'mega' units comply with the Spice expectations
195  if( unit == "M" )
196  unit = "Meg";
197 
198  value = prefix + unit + suffix;
199  }
200  }
201 
202  return value;
203  break;
204  }
205 
206  case SF_ENABLED:
207  return wxString( "Y" );
208  break;
209 
210  case SF_NODE_SEQUENCE:
211  {
212  wxString nodeSeq;
213  std::vector<LIB_PIN*> pins;
214 
215  aComponent->GetPins( pins );
216 
217  for( auto pin : pins )
218  nodeSeq += pin->GetNumber() + " ";
219 
220  nodeSeq.Trim();
221 
222  return nodeSeq;
223  break;
224  }
225 
226  case SF_LIB_FILE:
227  // There is no default Spice library
228  return wxEmptyString;
229  break;
230 
231  default:
232  wxASSERT_MSG( false, "Missing default value definition for a Spice field" );
233  break;
234  }
235 
236 
237  return wxString( "<unknown>" );
238 }
Field Reference of part, i.e. "IC21".
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:128
void GetPins(std::vector< LIB_PIN * > &aPinsList)
Populate a vector with all the pins.
#define VALUE
static const wxString& NETLIST_EXPORTER_PSPICE::GetSpiceFieldName ( SPICE_FIELD  aField)
inlinestatic

Returns a string used for a particular component field related to Spice simulation.

Definition at line 170 of file netlist_exporter_pspice.h.

Referenced by DIALOG_SPICE_MODEL::getField(), GetSpiceField(), ProcessNetlist(), and DIALOG_SPICE_MODEL::TransferDataFromWindow().

171  {
172  return m_spiceFields[(int) aField];
173  }
static const std::vector< wxString > m_spiceFields
static const std::vector<wxString>& NETLIST_EXPORTER_PSPICE::GetSpiceFields ( )
inlinestatic

Returns a vector of component field names related to Spice simulation.

Definition at line 162 of file netlist_exporter_pspice.h.

Referenced by DIALOG_SPICE_MODEL::TransferDataToWindow().

163  {
164  return m_spiceFields;
165  }
static const std::vector< wxString > m_spiceFields
const SPICE_ITEM_LIST& NETLIST_EXPORTER_PSPICE::GetSpiceItems ( ) const
inline

Returns list of items representing schematic components in the Spice world.

Definition at line 120 of file netlist_exporter_pspice.h.

References Format().

Referenced by NETLIST_EXPORTER_PSPICE_SIM::GetSpiceDevice(), DIALOG_SIM_SETTINGS::ShowModal(), DIALOG_SIGNAL_LIST::TransferDataToWindow(), and NETLIST_EXPORTER_PSPICE_SIM::writeDirectives().

121  {
122  return m_spiceItems;
123  }
SPICE_ITEM_LIST m_spiceItems
List of items representing schematic components in the Spice world
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 along 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 }
bool NETLIST_EXPORTER_PSPICE::ProcessNetlist ( unsigned  aCtl)

Processes the netlist to create net mapping and a list of SPICE_ITEMs.

It is automatically called by WriteNetlist(), but might be used separately, if only net mapping and the list of SPICE_ITEMs are required.

Returns
True if successful.

Definition at line 241 of file netlist_exporter_pspice.cpp.

References UNIQUE_STRINGS::Clear(), DisplayError(), SCH_COMPONENT::FindField(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), g_RootSheet, NETLIST_OBJECT_LIST::GetItem(), NETLIST_OBJECT::GetNetName(), NETLIST_OBJECT::GetPinNumText(), SCH_COMPONENT::GetRef(), GetSpiceField(), GetSpiceFieldName(), EDA_TEXT::GetText(), SPICE_ITEM::m_enabled, NETLIST_OBJECT::m_Flag, m_libraries, NETLIST_EXPORTER::m_masterList, SPICE_ITEM::m_model, m_netMap, SPICE_ITEM::m_parent, SPICE_ITEM::m_pins, SPICE_ITEM::m_pinSequence, SPICE_ITEM::m_primitive, NETLIST_EXPORTER::m_ReferencesAlreadyFound, SPICE_ITEM::m_refName, NETLIST_EXPORTER::m_SortedComponentPinList, m_spiceItems, SF_ENABLED, SF_LIB_FILE, SF_MODEL, SF_NODE_SEQUENCE, SF_PRIMITIVE, StringToBool(), and UpdateDirectives().

Referenced by Format().

242 {
243  const wxString delimiters( "{:,; }" );
244  SCH_SHEET_LIST sheetList( g_RootSheet );
245  // Set of reference names, to check for duplications
246  std::set<wxString> refNames;
247 
248  // Prepare list of nets generation (not used here, but...
249  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
250  m_masterList->GetItem( ii )->m_Flag = 0;
251 
252  m_netMap.clear();
253  m_netMap["GND"] = 0; // 0 is reserved for "GND"
254  int netIdx = 1;
255 
256  m_libraries.clear();
258 
259  UpdateDirectives( aCtl );
260 
261  for( unsigned sheet_idx = 0; sheet_idx < sheetList.size(); sheet_idx++ )
262  {
263  // Process component attributes to find Spice directives
264  for( EDA_ITEM* item = sheetList[sheet_idx].LastDrawList(); item; item = item->Next() )
265  {
266  SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[sheet_idx] );
267 
268  if( !comp )
269  break;
270 
271  item = comp;
272 
273  SPICE_ITEM spiceItem;
274  spiceItem.m_parent = comp;
275 
276  // Obtain Spice fields
277  SCH_FIELD* fieldLibFile = comp->FindField( GetSpiceFieldName( SF_LIB_FILE ) );
278  SCH_FIELD* fieldSeq = comp->FindField( GetSpiceFieldName( SF_NODE_SEQUENCE ) );
279 
280  spiceItem.m_primitive = GetSpiceField( SF_PRIMITIVE, comp, aCtl )[0];
281  spiceItem.m_model = GetSpiceField( SF_MODEL, comp, aCtl );
282  spiceItem.m_refName = comp->GetRef( &sheetList[sheet_idx] );
283 
284  // Duplicate references will result in simulation errors
285  if( refNames.count( spiceItem.m_refName ) )
286  {
287  DisplayError( NULL, wxT( "There are duplicate components. "
288  "You need to annotate schematics first." ) );
289  return false;
290  }
291 
292  refNames.insert( spiceItem.m_refName );
293 
294  // Check to see if component should be removed from Spice netlist
295  spiceItem.m_enabled = StringToBool( GetSpiceField( SF_ENABLED, comp, aCtl ) );
296 
297  if( fieldLibFile && !fieldLibFile->GetText().IsEmpty() )
298  m_libraries.insert( fieldLibFile->GetText() );
299 
300  wxArrayString pinNames;
301 
302  // Store pin information
303  for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
304  {
306 
307  // NETLIST_EXPORTER marks removed pins by setting them to NULL
308  if( !pin )
309  continue;
310 
311  spiceItem.m_pins.push_back( pin );
312  pinNames.Add( pin->GetPinNumText() );
313 
314  // Create net mapping
315  const wxString& netName = pin->GetNetName();
316  if( m_netMap.count( netName ) == 0 )
317  m_netMap[netName] = netIdx++;
318  }
319 
320  // Check if an alternative pin sequence is available:
321  if( fieldSeq )
322  {
323  // Get the string containing the sequence of nodes:
324  const wxString& nodeSeqIndexLineStr = fieldSeq->GetText();
325 
326  // Verify field exists and is not empty:
327  if( !nodeSeqIndexLineStr.IsEmpty() )
328  {
329  // Get Alt Pin Name Array From User:
330  wxStringTokenizer tkz( nodeSeqIndexLineStr, delimiters );
331 
332  while( tkz.HasMoreTokens() )
333  {
334  wxString pinIndex = tkz.GetNextToken();
335  int seq;
336 
337  // Find PinName In Standard List assign Standard List Index to Name:
338  seq = pinNames.Index( pinIndex );
339 
340  if( seq != wxNOT_FOUND )
341  spiceItem.m_pinSequence.push_back( seq );
342  }
343  }
344  }
345 
346  m_spiceItems.push_back( spiceItem );
347  }
348  }
349 
350  return true;
351 }
Class SCH_SHEET_LIST.
Class SCH_FIELD instances are attached to a component and provide a place for the component&#39;s value...
Definition: sch_field.h:56
std::vector< NETLIST_OBJECT * > m_pins
Array containing Standard Pin Name
SCH_FIELD * FindField(const wxString &aFieldName, bool aIncludeDefaultFields=true)
Search for a SCH_FIELD with aFieldName.
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
const wxString & GetPinNumText() const
Function GetPinNum returns a pin number in wxString form.
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.
std::set< wxString > m_libraries
Libraries used by the simulated circuit
SCH_COMPONENT * m_parent
Schematic component represented by this SPICE_ITEM.
Structure to represent a schematic component in the Spice simulation.
static const wxString & GetSpiceFieldName(SPICE_FIELD aField)
Returns a string used for a particular component field related to Spice simulation.
bool m_enabled
Flag to indicate whether the component should be used in simulation.
EDA_ITEM * Next() const
Definition: base_struct.h:235
void Clear()
Function Clear erases the record.
static bool StringToBool(const wxString &aStr)
Convertes typical boolean string values (no/yes, true/false, 1/0) to a boolean value.
wxString m_model
Library model (for semiconductors and subcircuits), component value (for passive components) or volta...
NETLIST_OBJECT_LIST * m_masterList
SPICE_ITEM_LIST m_spiceItems
List of items representing schematic components in the Spice world
NET_INDEX_MAP m_netMap
Maps circuit nodes to net names
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:128
void UpdateDirectives(unsigned aCtl)
Updates the vector of Spice directives placed in the schematics.
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 wxString GetSpiceField(SPICE_FIELD aField, SCH_COMPONENT *aComponent, unsigned aCtl)
Retrieves either the requested field value or the default value.
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:180
wxChar m_primitive
Spice primitive type (
std::vector< int > m_pinSequence
Numeric indices into m_SortedComponentPinList
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:74
void NETLIST_EXPORTER_PSPICE::ReplaceForbiddenChars ( wxString &  aNetName)
static

some chars are not accepted in netnames in spice netlists.

for instance '(' and ')' ReplaceForbiddenChars replace these chars by an underscore.

Parameters
aNetName= the netname to modify.

Definition at line 49 of file netlist_exporter_pspice.cpp.

Referenced by Format(), and NETLIST_EXPORTER_PSPICE_SIM::GetSpiceVector().

50 {
51  // some chars are not accepted in netnames in spice netlists, because they are separators
52  // they are replaced an underscore or some other allowed char.
53  // Note: this is a static function
54 
55  aNetName.Replace( "(", "_" );
56  aNetName.Replace( ")", "_" );
57 }
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 Format(), and NETLIST_EXPORTER_ORCADPCB2::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
static bool NETLIST_EXPORTER_PSPICE::StringToBool ( const wxString &  aStr)
inlinestatic

Convertes typical boolean string values (no/yes, true/false, 1/0) to a boolean value.

Definition at line 201 of file netlist_exporter_pspice.h.

Referenced by ProcessNetlist(), and DIALOG_SPICE_MODEL::TransferDataToWindow().

202  {
203  if( aStr.IsEmpty() )
204  return false;
205 
206  char c = tolower( aStr[0] );
207 
208  // Different ways of saying false (no/false/0)
209  return !( c == 'n' || c == 'f' || c == '0' );
210  }
void NETLIST_EXPORTER_PSPICE::UpdateDirectives ( unsigned  aCtl)

Updates the vector of Spice directives placed in the schematics.

Definition at line 354 of file netlist_exporter_pspice.cpp.

References g_RootSheet, GetText(), m_directives, m_libraries, m_title, and SCH_TEXT_T.

Referenced by NETLIST_EXPORTER_PSPICE_SIM::GetSheetSimCommand(), and ProcessNetlist().

355 {
356  const SCH_SHEET_LIST& sheetList = g_RootSheet;
357 
358  m_directives.clear();
359 
360  for( unsigned i = 0; i < sheetList.size(); i++ )
361  {
362  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
363  {
364  if( item->Type() != SCH_TEXT_T )
365  continue;
366 
367  wxString text = static_cast<SCH_TEXT*>( item )->GetText();
368 
369  if( text.IsEmpty() )
370  continue;
371 
372  if( text.GetChar( 0 ) == '.' )
373  {
374  wxStringTokenizer tokenizer( text, "\r\n" );
375 
376  while( tokenizer.HasMoreTokens() )
377  {
378  wxString directive( tokenizer.GetNextToken() );
379 
380  if( directive.StartsWith( ".inc" ) )
381  {
382  wxString lib = directive.AfterFirst( ' ' );
383 
384  if( !lib.IsEmpty() )
385  m_libraries.insert( lib );
386  }
387  else if( directive.StartsWith( ".title " ) )
388  {
389  m_title = directive.AfterFirst( ' ' );
390  }
391  else
392  {
393  m_directives.push_back( directive );
394  }
395  }
396  }
397  }
398  }
399 }
Class SCH_SHEET_LIST.
std::set< wxString > m_libraries
Libraries used by the simulated circuit
std::vector< wxString > m_directives
Spice directives found in the processed schematic sheet
wxString m_title
Spice simulation title found in the processed schematic sheet
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:55
wxString GetText(GRAPHIC_PINSHAPE shape)
Definition: pin_shape.cpp:33
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:180
void NETLIST_EXPORTER_PSPICE::writeDirectives ( OUTPUTFORMATTER aFormatter,
unsigned  aCtl 
) const
protectedvirtual

Saves the Spice directives.

Reimplemented in NETLIST_EXPORTER_PSPICE_SIM.

Definition at line 402 of file netlist_exporter_pspice.cpp.

References m_directives, m_spiceFields, and OUTPUTFORMATTER::Print().

Referenced by Format(), and NETLIST_EXPORTER_PSPICE_SIM::writeDirectives().

403 {
404  for( auto& dir : m_directives )
405  {
406  aFormatter->Print( 0, "%s\n", (const char*) dir.c_str() );
407  }
408 }
std::vector< wxString > m_directives
Spice directives found in the processed schematic sheet
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:404
bool NETLIST_EXPORTER_PSPICE::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions 
)
overridevirtual

Function WriteNetlist writes to specified output file.

Reimplemented from NETLIST_EXPORTER.

Definition at line 42 of file netlist_exporter_pspice.cpp.

References Format().

43 {
44  FILE_OUTPUTFORMATTER outputFile( aOutFileName, wxT( "wt" ), '\'' );
45 
46  return Format( &outputFile, aNetlistOptions );
47 }
bool Format(OUTPUTFORMATTER *aFormatter, unsigned aCtl)
>
Class FILE_OUTPUTFORMATTER may be used for text file output.
Definition: richio.h:492

Member Data Documentation

std::vector<wxString> NETLIST_EXPORTER_PSPICE::m_directives
private

Spice directives found in the processed schematic sheet

Definition at line 223 of file netlist_exporter_pspice.h.

Referenced by UpdateDirectives(), and writeDirectives().

std::set<LIB_PART*, LIB_PART_LESS_THAN> NETLIST_EXPORTER::m_LibParts
protectedinherited
std::set<wxString> NETLIST_EXPORTER_PSPICE::m_libraries
private

Libraries used by the simulated circuit

Definition at line 226 of file netlist_exporter_pspice.h.

Referenced by Format(), ProcessNetlist(), and UpdateDirectives().

NET_INDEX_MAP NETLIST_EXPORTER_PSPICE::m_netMap
private

Maps circuit nodes to net names

Definition at line 229 of file netlist_exporter_pspice.h.

Referenced by Format(), and ProcessNetlist().

PROJECT* NETLIST_EXPORTER_PSPICE::m_project
private

Project object to fetch its settings (e.g. paths)

Definition at line 235 of file netlist_exporter_pspice.h.

Referenced by Format().

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(), ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().

const std::vector< wxString > NETLIST_EXPORTER_PSPICE::m_spiceFields
staticprivate
Initial value:
= {
"Spice_Primitive",
"Spice_Model",
"Spice_Netlist_Enabled",
"Spice_Node_Sequence",
"Spice_Lib_File"
}

Definition at line 238 of file netlist_exporter_pspice.h.

Referenced by writeDirectives().

SPICE_ITEM_LIST NETLIST_EXPORTER_PSPICE::m_spiceItems
private

List of items representing schematic components in the Spice world

Definition at line 232 of file netlist_exporter_pspice.h.

Referenced by Format(), and ProcessNetlist().

wxString NETLIST_EXPORTER_PSPICE::m_title
private

Spice simulation title found in the processed schematic sheet

Definition at line 220 of file netlist_exporter_pspice.h.

Referenced by Format(), and UpdateDirectives().


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