KiCad PCB EDA Suite
NETLIST_EXPORTER_PSPICE_SIM Class Reference

Special netlist exporter flavor that allows to override simulation commands. More...

#include <netlist_exporter_pspice_sim.h>

Inheritance diagram for NETLIST_EXPORTER_PSPICE_SIM:
NETLIST_EXPORTER_PSPICE NETLIST_EXPORTER

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_SIM (NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs, SEARCH_STACK *aPaths=NULL)
 
wxString GetSpiceVector (const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam=wxEmptyString) const
 Returns name of Spice dataset for a specific plot. More...
 
wxString GetSpiceDevice (const wxString &aComponent) const
 Returns name of Spice device corresponding to a schematic component. More...
 
void SetSimCommand (const wxString &aCmd)
 Overrides the simulation command directive. More...
 
const wxString & GetSimCommand () const
 Returns the simulation command directive. More...
 
void ClearSimCommand ()
 Clears the simulation command directive. More...
 
SIM_TYPE GetSimType ()
 Returns simulation type basing on the simulation command directives. More...
 
wxString GetSheetSimCommand ()
 Returns simulation command directives placed in schematic sheets (if any). More...
 
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 const std::vector< wxString > & GetCurrents (SPICE_PRIMITIVE aPrimitive)
 Returns a list of currents that can be probed in a Spice primitive. More...
 
static bool IsSimCommand (const wxString &aCmd)
 Determines if a directive is a simulation command. More...
 
static SIM_TYPE CommandToSimType (const wxString &aCmd)
 Returns simulation type basing on a simulation command directive. More...
 
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 &aTempfile, const wxString &aFinalFile, const wxString &aProjectDirectory)
 Function MakeCommandLine builds up a string that describes a command line for executing a child process. More...
 

Protected Member Functions

void writeDirectives (OUTPUTFORMATTER *aFormatter, unsigned aCtl) const override
 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 findAllInstancesOfComponent (SCH_COMPONENT *aComponent, LIB_PART *aEntry, SCH_SHEET_PATH *aSheetPath)
 Function findAllInstancesOfComponent is used for "multiple parts per package" components. More...
 

Static Protected Member Functions

static void sprintPinNetName (wxString &aResult, const wxString &aNetNameFormat, NETLIST_OBJECT *aPin, bool aUseNetcodeAsNetName=false)
 Function sprintPinNetName formats the net name for aPin using aNetNameFormat into aResult. More...
 

Protected Attributes

NETLIST_OBJECT_LISTm_masterList
 
PART_LIBSm_libs
 yes ownership, connected items flat list More...
 
NETLIST_OBJECTS m_SortedComponentPinList
 no ownership More...
 
UNIQUE_STRINGS m_ReferencesAlreadyFound
 Used for "multi parts per package" components, avoids processing a lib component more than once. More...
 
std::set< LIB_PART *, LIB_PART_LESS_THANm_LibParts
 unique library parts used. LIB_PART items are sorted by names More...
 
std::set< void * > m_Libraries
 unique libraries used More...
 

Private Attributes

wxString m_simCommand
 

Custom simulation command (has priority over the schematic sheet simulation commands)

More...
 

Detailed Description

Special netlist exporter flavor that allows to override simulation commands.

Definition at line 34 of file netlist_exporter_pspice_sim.h.

Member Typedef Documentation

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

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_SIM::NETLIST_EXPORTER_PSPICE_SIM ( NETLIST_OBJECT_LIST aMasterList,
PART_LIBS aLibs,
SEARCH_STACK aPaths = NULL 
)
inline

Definition at line 37 of file netlist_exporter_pspice_sim.h.

38  :
39  NETLIST_EXPORTER_PSPICE( aMasterList, aLibs, aPaths )
40  {
41  }
NETLIST_EXPORTER_PSPICE(NETLIST_OBJECT_LIST *aMasterList, PART_LIBS *aLibs, SEARCH_STACK *aPaths=NULL)

Member Function Documentation

bool NETLIST_EXPORTER::addPinToComponentPinList ( SCH_COMPONENT Component,
SCH_SHEET_PATH sheet,
LIB_PIN PinEntry 
)
protectedinherited

Function addPinToComponentPinList adds a new pin description to the pin list m_SortedComponentPinList.

A pin description is a pointer to the corresponding structure created by BuildNetList() in the table g_NetObjectslist.

Definition at line 237 of file netlist_exporter.cpp.

References DisplayError(), NETLIST_OBJECT_LIST::GetItem(), LIB_PIN::GetNumber(), NETLIST_OBJECT::m_Link, NETLIST_EXPORTER::m_masterList, NETLIST_OBJECT::m_PinNum, NETLIST_OBJECT::m_SheetPath, NETLIST_EXPORTER::m_SortedComponentPinList, NETLIST_OBJECT::m_Type, MAXPIN, and NET_PIN.

Referenced by NETLIST_EXPORTER::findAllInstancesOfComponent(), and NETLIST_EXPORTER::findNextComponentAndCreatePinList().

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

Clears the simulation command directive.

Definition at line 86 of file netlist_exporter_pspice_sim.h.

References m_simCommand.

87  {
88  m_simCommand.Clear();
89  }
wxString m_simCommand
Custom simulation command (has priority over the schematic sheet simulation commands) ...
SIM_TYPE NETLIST_EXPORTER_PSPICE_SIM::CommandToSimType ( const wxString &  aCmd)
static

Returns simulation type basing on a simulation command directive.

Definition at line 125 of file netlist_exporter_pspice_sim.cpp.

References ST_AC, ST_DC, ST_DISTORTION, ST_NOISE, ST_OP, ST_POLE_ZERO, ST_SENSITIVITY, ST_TRANS_FUNC, ST_TRANSIENT, and ST_UNKNOWN.

Referenced by GetSimType(), IsSimCommand(), and SIM_PLOT_FRAME::onSettings().

126 {
127  const std::map<wxString, SIM_TYPE> simCmds = {
128  { ".ac", ST_AC }, { ".dc", ST_DC }, { ".disto", ST_DISTORTION }, { ".noise", ST_NOISE },
129  { ".op", ST_OP }, { ".pz", ST_POLE_ZERO }, { ".sens", ST_SENSITIVITY }, { ".tf", ST_TRANS_FUNC },
130  { ".tran", ST_TRANSIENT }
131  };
132  wxString lcaseCmd = aCmd.Lower();
133 
134  for( const auto& c : simCmds )
135  {
136  if( lcaseCmd.StartsWith( c.first ) )
137  return c.second;
138  }
139 
140  return ST_UNKNOWN;
141 }
void NETLIST_EXPORTER::eraseDuplicatePins ( )
protectedinherited

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

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

Definition at line 273 of file netlist_exporter.cpp.

References NETLIST_EXPORTER::m_SortedComponentPinList, and PAD_CONNECT.

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

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

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

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

Definition at line 324 of file netlist_exporter.cpp.

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

Referenced by NETLIST_EXPORTER::findNextComponentAndCreatePinList().

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

Definition at line 103 of file netlist_exporter.cpp.

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

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

Function findNextComponentAndCreatePinList finds a component from the DrawList and builds its pin list in m_SortedComponentPinList.

This list is sorted by pin num. the component is the next actual component after aItem (power symbols and virtual components that have their reference starting by '#'are skipped).

Definition at line 158 of file netlist_exporter.cpp.

References NETLIST_EXPORTER::addPinToComponentPinList(), NETLIST_EXPORTER::eraseDuplicatePins(), NETLIST_EXPORTER::findAllInstancesOfComponent(), PART_LIBS::FindLibPart(), SCH_COMPONENT::GetConvert(), SCH_COMPONENT::GetLibId(), LIB_PART::GetPins(), SCH_COMPONENT::GetRef(), LIB_PART::GetUnitCount(), SCH_COMPONENT::GetUnitSelection(), LIB_PIN_T, UNIQUE_STRINGS::Lookup(), NETLIST_EXPORTER::m_LibParts, NETLIST_EXPORTER::m_libs, NETLIST_EXPORTER::m_ReferencesAlreadyFound, NETLIST_EXPORTER::m_SortedComponentPinList, EDA_ITEM::Next(), SCH_COMPONENT_T, sortPinsByNum(), and EDA_ITEM::Type().

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

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

>

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(), SEARCH_STACK::FindValidPath(), Format(), NETLIST_OBJECT::GetNetName(), NETLIST_EXPORTER_PSPICE::m_libraries, NETLIST_EXPORTER_PSPICE::m_netMap, NETLIST_EXPORTER_PSPICE::m_paths, NETLIST_EXPORTER_PSPICE::m_spiceItems, NET_ADJUST_INCLUDE_PATHS, OUTPUTFORMATTER::Print(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_PSPICE::ReplaceForbiddenChars(), NETLIST_EXPORTER::sprintPinNetName(), TO_UTF8, and NETLIST_EXPORTER_PSPICE::writeDirectives().

Referenced by NETLIST_EXPORTER_PSPICE::WriteNetlist().

61 {
62  // Netlist options
63  const bool useNetcodeAsNetName = false;//aCtl & NET_USE_NETCODES_AS_NETNAMES;
64 
65  if( !ProcessNetlist( aCtl ) )
66  return false;
67 
68  aFormatter->Print( 0, ".title KiCad schematic\n" );
69 
70  // Write .include directives
71  for( auto lib : m_libraries )
72  {
73  wxString full_path;
74 
75  if( ( aCtl & NET_ADJUST_INCLUDE_PATHS ) && m_paths )
76  {
77  // Look for the library in known search locations
78  full_path = m_paths->FindValidPath( lib );
79 
80  if( full_path.IsEmpty() )
81  {
82  DisplayError( NULL, wxString::Format( _( "Could not find library file %s" ), lib ) );
83  full_path = lib;
84  }
85  }
86  else
87  full_path = lib; // just use the unaltered path
88 
89  aFormatter->Print( 0, ".include \"%s\"\n", (const char*) full_path.c_str() );
90  }
91 
92  for( const auto& item : m_spiceItems )
93  {
94  if( !item.m_enabled )
95  continue;
96 
97  // Save the node order
98  aFormatter->Print( 0, "%c%s ", item.m_primitive, (const char*) item.m_refName.c_str() );
99 
100  size_t pspiceNodes = item.m_pinSequence.empty() ? item.m_pins.size() : item.m_pinSequence.size();
101 
102  for( size_t ii = 0; ii < pspiceNodes; ii++ )
103  {
104  // Use the custom order if defined, otherwise use the standard pin order as defined in the compon
105  size_t activePinIndex = item.m_pinSequence.empty() ? ii : item.m_pinSequence[ii];
106  // Valid used Node Indexes are in the set
107  // {0,1,2,...m_item.m_pin.size()-1}
108  if( activePinIndex >= item.m_pins.size() )
109  {
110  wxASSERT_MSG( false, "Used an invalid pin number in node sequence" );
111  continue;
112  }
113 
114  NETLIST_OBJECT* pin = item.m_pins[activePinIndex];
115  assert( pin );
116  wxString netName = pin->GetNetName();
117 
118  if( useNetcodeAsNetName )
119  {
120  assert( m_netMap.count( netName ) );
121  aFormatter->Print( 0, "%d ", m_netMap[netName] );
122  }
123  else
124  {
125  sprintPinNetName( netName , wxT( "N-%.6d" ), pin, useNetcodeAsNetName );
126 
127  // Replace parenthesis with underscore to prevent parse issues with simulators
128  ReplaceForbiddenChars( netName );
129 
130  if( netName.IsEmpty() )
131  netName = wxT( "?" );
132 
133  aFormatter->Print( 0, "%s ", TO_UTF8( netName ) );
134  }
135  }
136 
137  aFormatter->Print( 0, "%s\n", (const char*) item.m_model.c_str() );
138  }
139 
140  // Print out all directives found in the text fields on the schematics
141  writeDirectives( aFormatter, aCtl );
142 
143  aFormatter->Print( 0, ".end\n" );
144 
145  return true;
146 }
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...
SEARCH_STACK * m_paths
Paths to be searched for included Spice libraries
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
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.
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
wxString FindValidPath(const wxString &aFileName) const
Definition: search_stack.h:71
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Function DisplayError displays an error or warning message box with aMessage.
Definition: confirm.cpp:69
const std::vector< wxString > & NETLIST_EXPORTER_PSPICE_SIM::GetCurrents ( SPICE_PRIMITIVE  aPrimitive)
static

Returns a list of currents that can be probed in a Spice primitive.

Definition at line 57 of file netlist_exporter_pspice_sim.cpp.

References empty(), SP_BJT, SP_CAPACITOR, SP_DIODE, SP_INDUCTOR, SP_MOSFET, SP_RESISTOR, and SP_VSOURCE.

Referenced by DIALOG_SIGNAL_LIST::TransferDataToWindow(), and writeDirectives().

58 {
59  static const std::vector<wxString> passive = { "I" };
60  static const std::vector<wxString> diode = { "Id" };
61  static const std::vector<wxString> bjt = { "Ib", "Ic", "Ie" };
62  static const std::vector<wxString> mos = { "Ig", "Id", "Is" };
63  static const std::vector<wxString> empty;
64 
65  switch( aPrimitive )
66  {
67  case SP_RESISTOR:
68  case SP_CAPACITOR:
69  case SP_INDUCTOR:
70  case SP_VSOURCE:
71  return passive;
72 
73  case SP_DIODE:
74  return diode;
75 
76  case SP_BJT:
77  return bjt;
78 
79  case SP_MOSFET:
80  return mos;
81 
82  default:
83  return empty;
84  }
85 }
static bool empty(const wxTextEntryBase *aCtrl)
const std::vector<wxString> NETLIST_EXPORTER_PSPICE::GetDirectives ( ) const
inlineinherited

Returnss a vector of Spice directives found in the schematics.

Definition at line 193 of file netlist_exporter_pspice.h.

References NETLIST_EXPORTER_PSPICE::m_directives.

Referenced by GetSheetSimCommand(), and 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
inlineinherited

Returns a map of circuit nodes to net names.

Definition at line 154 of file netlist_exporter_pspice.h.

References NETLIST_EXPORTER_PSPICE::m_netMap.

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

155  {
156  return m_netMap;
157  }
NET_INDEX_MAP m_netMap
Maps circuit nodes to net names
wxString NETLIST_EXPORTER_PSPICE_SIM::GetSheetSimCommand ( )

Returns simulation command directives placed in schematic sheets (if any).

Definition at line 103 of file netlist_exporter_pspice_sim.cpp.

References Format(), NETLIST_EXPORTER_PSPICE::GetDirectives(), IsSimCommand(), NET_ALL_FLAGS, and NETLIST_EXPORTER_PSPICE::UpdateDirectives().

Referenced by GetSimType(), and DIALOG_SIM_SETTINGS::loadDirectives().

104 {
105  wxString simCmd;
106 
108 
109  for( const auto& dir : GetDirectives() )
110  {
111  if( IsSimCommand( dir ) )
112  simCmd += wxString::Format( "%s\r\n", dir );
113  }
114 
115  return simCmd;
116 }
const std::vector< wxString > GetDirectives() const
Returnss a vector of Spice directives found in the schematics.
static bool IsSimCommand(const wxString &aCmd)
Determines if a directive is a simulation command.
void UpdateDirectives(unsigned aCtl)
Updates the vector of Spice directives placed in the schematics.
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
const wxString& NETLIST_EXPORTER_PSPICE_SIM::GetSimCommand ( ) const
inline

Returns the simulation command directive.

Definition at line 78 of file netlist_exporter_pspice_sim.h.

References m_simCommand.

79  {
80  return m_simCommand;
81  }
wxString m_simCommand
Custom simulation command (has priority over the schematic sheet simulation commands) ...
SIM_TYPE NETLIST_EXPORTER_PSPICE_SIM::GetSimType ( )

Returns simulation type basing on the simulation command directives.

Simulation directives set using SetSimCommand() have priority over the ones placed in schematic sheets.

Definition at line 119 of file netlist_exporter_pspice_sim.cpp.

References CommandToSimType(), GetSheetSimCommand(), and m_simCommand.

Referenced by DIALOG_SIGNAL_LIST::TransferDataToWindow().

120 {
122 }
wxString m_simCommand
Custom simulation command (has priority over the schematic sheet simulation commands) ...
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Returns simulation type basing on a simulation command directive.
wxString GetSheetSimCommand()
Returns simulation command directives placed in schematic sheets (if any).
wxString NETLIST_EXPORTER_PSPICE_SIM::GetSpiceDevice ( const wxString &  aComponent) const

Returns name of Spice device corresponding to a schematic component.

Parameters
aComponentis the component reference.
Returns
Spice device name or empty string if there is no such component in the netlist.

Definition at line 88 of file netlist_exporter_pspice_sim.cpp.

References NETLIST_EXPORTER_PSPICE::GetSpiceItems().

Referenced by GetSpiceVector().

89 {
90  const auto& spiceItems = GetSpiceItems();
91 
92  auto it = std::find_if( spiceItems.begin(), spiceItems.end(), [&]( const SPICE_ITEM& item ) {
93  return item.m_refName == aComponent;
94  } );
95 
96  if( it == spiceItems.end() )
97  return wxEmptyString;
98 
99  return wxString( it->m_primitive + it->m_refName );
100 }
Structure to represent a schematic component in the Spice simulation.
const SPICE_ITEM_LIST & GetSpiceItems() const
Returns list of items representing schematic components in the Spice world.
wxString NETLIST_EXPORTER_PSPICE::GetSpiceField ( SPICE_FIELD  aField,
SCH_COMPONENT aComponent,
unsigned  aCtl 
)
staticinherited

Retrieves either the requested field value or the default value.

Definition at line 149 of file netlist_exporter_pspice.cpp.

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

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

151 {
152  SCH_FIELD* field = aComponent->FindField( GetSpiceFieldName( aField ) );
153  return field ? field->GetText() : GetSpiceFieldDefVal( aField, aComponent, aCtl );
154 }
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
static const wxString & GetSpiceFieldName(SPICE_FIELD aField)
Returns a string used for a particular component field related to Spice simulation.
SCH_FIELD * FindField(const wxString &aFieldName)
Function FindField searches for SCH_FIELD with aFieldName and returns it if found, else NULL.
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:130
wxString NETLIST_EXPORTER_PSPICE::GetSpiceFieldDefVal ( SPICE_FIELD  aField,
SCH_COMPONENT aComponent,
unsigned  aCtl 
)
staticinherited

Retrieves the default value for a given field.

Definition at line 157 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 NETLIST_EXPORTER_PSPICE::GetSpiceField(), and DIALOG_SPICE_MODEL::TransferDataToWindow().

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

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

Definition at line 170 of file netlist_exporter_pspice.h.

References NETLIST_EXPORTER_PSPICE::m_spiceFields.

Referenced by DIALOG_SPICE_MODEL::getField(), NETLIST_EXPORTER_PSPICE::GetSpiceField(), NETLIST_EXPORTER_PSPICE::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 ( )
inlinestaticinherited

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

Definition at line 162 of file netlist_exporter_pspice.h.

References NETLIST_EXPORTER_PSPICE::m_spiceFields.

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
inlineinherited

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

Definition at line 120 of file netlist_exporter_pspice.h.

References NETLIST_EXPORTER_PSPICE::m_spiceItems.

Referenced by GetSpiceDevice(), DIALOG_SIM_SETTINGS::ShowModal(), DIALOG_SIGNAL_LIST::TransferDataToWindow(), and 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_PSPICE_SIM::GetSpiceVector ( const wxString &  aName,
SIM_PLOT_TYPE  aType,
const wxString &  aParam = wxEmptyString 
) const

Returns name of Spice dataset for a specific plot.

Parameters
aNameis name of the measured net or device
aTypedescribes the type of expected plot
aParamis an optional parameter for devices, if absent it will return current (only for passive devices).
Returns
Empty string if query is invalid, otherwise a plot name that can be requested from the simulator.

Definition at line 27 of file netlist_exporter_pspice_sim.cpp.

References Format(), GetSpiceDevice(), NETLIST_EXPORTER_PSPICE::ReplaceForbiddenChars(), SPT_AC_MAG, SPT_AC_PHASE, SPT_CURRENT, and SPT_VOLTAGE.

Referenced by writeDirectives().

29 {
30  wxString res;
31 
32  // Some of the flags should exclude mutually
33  assert( ( ( aType & SPT_VOLTAGE ) == 0 ) != ( ( aType & SPT_CURRENT ) == 0 ) );
34  assert( ( ( aType & SPT_AC_PHASE ) == 0 ) || ( ( aType & SPT_AC_MAG ) == 0 ) );
35 
36  if( aType & SPT_VOLTAGE )
37  {
38  // Spice netlist netnames does not accept some chars, whicyh are replaced
39  // by eeschema netlist generator.
40  // Replace these forbidden chars to find the actual spice net name
41  wxString spicenet = aName;
43 
44  return wxString::Format( "V(%s)", spicenet.GetData() );
45  }
46 
47  else if( aType & SPT_CURRENT )
48  {
49  return wxString::Format( "@%s[%s]", GetSpiceDevice( aName ).Lower(),
50  aParam.IsEmpty() ? "i" : aParam.Lower() );
51  }
52 
53  return res;
54 }
wxString GetSpiceDevice(const wxString &aComponent) const
Returns name of Spice device corresponding to a schematic component.
static void ReplaceForbiddenChars(wxString &aNetName)
some chars are not accepted in netnames in spice netlists.
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
static bool NETLIST_EXPORTER_PSPICE_SIM::IsSimCommand ( const wxString &  aCmd)
inlinestatic

Determines if a directive is a simulation command.

Definition at line 106 of file netlist_exporter_pspice_sim.h.

References CommandToSimType(), and ST_UNKNOWN.

Referenced by GetSheetSimCommand(), and writeDirectives().

107  {
108  return CommandToSimType( aCmd ) != ST_UNKNOWN;
109  }
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Returns simulation type basing on a simulation command directive.
wxString NETLIST_EXPORTER::MakeCommandLine ( const wxString &  aFormatString,
const wxString &  aTempfile,
const wxString &  aFinalFile,
const wxString &  aProjectDirectory 
)
staticinherited

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

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

Parameters
aFormatStringholds:
  • the name of the external program
  • any options needed by that program
  • formatting sequences, see below.
aTempfileis the name of an input file to the external program.
aFinalFileis the name of an output file that the user expects.
aProjectDirectoryis used for P replacement, it should omit the trailing '/'.

Supported formatting sequences and their meaning:

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

Definition at line 50 of file netlist_exporter.cpp.

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

52 {
53  // Expand format symbols in the command line:
54  // %B => base filename of selected output file, minus path and extension.
55  // %P => project directory name, without trailing '/' or '\'.
56  // %I => full filename of the input file (the intermediate net file).
57  // %O => complete filename and path (but without extension) of the user chosen output file.
58 
59  wxString ret = aFormatString;
60  wxFileName in = aTempfile;
61  wxFileName out = aFinalFile;
62 
63  ret.Replace( wxT( "%P" ), aProjectPath.GetData(), true );
64  ret.Replace( wxT( "%B" ), out.GetName().GetData(), true );
65  ret.Replace( wxT( "%I" ), in.GetFullPath().GetData(), true );
66  ret.Replace( wxT( "%O" ), out.GetFullPath().GetData(), true );
67 
68  // Use Unix like notation, which always works
69  ret.Replace( wxT( "\\" ), "/", true );
70 
71  return ret;
72 }
bool NETLIST_EXPORTER_PSPICE::ProcessNetlist ( unsigned  aCtl)
inherited

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 238 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(), NETLIST_EXPORTER_PSPICE::GetSpiceField(), NETLIST_EXPORTER_PSPICE::GetSpiceFieldName(), EDA_TEXT::GetText(), SPICE_ITEM::m_enabled, NETLIST_OBJECT::m_Flag, NETLIST_EXPORTER_PSPICE::m_libraries, NETLIST_EXPORTER::m_masterList, SPICE_ITEM::m_model, NETLIST_EXPORTER_PSPICE::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, NETLIST_EXPORTER_PSPICE::m_spiceItems, SF_ENABLED, SF_LIB_FILE, SF_MODEL, SF_NODE_SEQUENCE, SF_PRIMITIVE, NETLIST_EXPORTER_PSPICE::StringToBool(), and NETLIST_EXPORTER_PSPICE::UpdateDirectives().

Referenced by NETLIST_EXPORTER_PSPICE::Format().

239 {
240  const wxString delimiters( "{:,; }" );
241  SCH_SHEET_LIST sheetList( g_RootSheet );
242  // Set of reference names, to check for duplications
243  std::set<wxString> refNames;
244 
245  // Prepare list of nets generation (not used here, but...
246  for( unsigned ii = 0; ii < m_masterList->size(); ii++ )
247  m_masterList->GetItem( ii )->m_Flag = 0;
248 
249  m_netMap.clear();
250  m_netMap["GND"] = 0; // 0 is reserved for "GND"
251  int netIdx = 1;
252 
253  m_libraries.clear();
255 
256  UpdateDirectives( aCtl );
257 
258  for( unsigned sheet_idx = 0; sheet_idx < sheetList.size(); sheet_idx++ )
259  {
260  // Process component attributes to find Spice directives
261  for( EDA_ITEM* item = sheetList[sheet_idx].LastDrawList(); item; item = item->Next() )
262  {
263  SCH_COMPONENT* comp = findNextComponentAndCreatePinList( item, &sheetList[sheet_idx] );
264 
265  if( !comp )
266  break;
267 
268  item = comp;
269 
270  SPICE_ITEM spiceItem;
271  spiceItem.m_parent = comp;
272 
273  // Obtain Spice fields
274  SCH_FIELD* fieldLibFile = comp->FindField( GetSpiceFieldName( SF_LIB_FILE ) );
275  SCH_FIELD* fieldSeq = comp->FindField( GetSpiceFieldName( SF_NODE_SEQUENCE ) );
276 
277  spiceItem.m_primitive = GetSpiceField( SF_PRIMITIVE, comp, aCtl )[0];
278  spiceItem.m_model = GetSpiceField( SF_MODEL, comp, aCtl );
279  spiceItem.m_refName = comp->GetRef( &sheetList[sheet_idx] );
280 
281  // Duplicate references will result in simulation errors
282  if( refNames.count( spiceItem.m_refName ) )
283  {
284  DisplayError( NULL, wxT( "There are duplicate components. "
285  "You need to annotate schematics first." ) );
286  return false;
287  }
288 
289  refNames.insert( spiceItem.m_refName );
290 
291  // Check to see if component should be removed from Spice netlist
292  spiceItem.m_enabled = StringToBool( GetSpiceField( SF_ENABLED, comp, aCtl ) );
293 
294  if( fieldLibFile && !fieldLibFile->GetText().IsEmpty() )
295  m_libraries.insert( fieldLibFile->GetText() );
296 
297  wxArrayString pinNames;
298 
299  // Store pin information
300  for( unsigned ii = 0; ii < m_SortedComponentPinList.size(); ii++ )
301  {
303 
304  // NETLIST_EXPORTER marks removed pins by setting them to NULL
305  if( !pin )
306  continue;
307 
308  spiceItem.m_pins.push_back( pin );
309  pinNames.Add( pin->GetPinNumText() );
310 
311  // Create net mapping
312  const wxString& netName = pin->GetNetName();
313  if( m_netMap.count( netName ) == 0 )
314  m_netMap[netName] = netIdx++;
315  }
316 
317  // Check if an alternative pin sequence is available:
318  if( fieldSeq )
319  {
320  // Get the string containing the sequence of nodes:
321  wxString nodeSeqIndexLineStr = fieldSeq->GetText();
322 
323  // Verify field exists and is not empty:
324  if( !nodeSeqIndexLineStr.IsEmpty() )
325  {
326  // Get Alt Pin Name Array From User:
327  wxStringTokenizer tkz( nodeSeqIndexLineStr, delimiters );
328 
329  while( tkz.HasMoreTokens() )
330  {
331  wxString pinIndex = tkz.GetNextToken();
332  int seq;
333 
334  // Find PinName In Standard List assign Standard List Index to Name:
335  seq = pinNames.Index( pinIndex );
336 
337  if( seq != wxNOT_FOUND )
338  spiceItem.m_pinSequence.push_back( seq );
339  }
340  }
341  }
342 
343  m_spiceItems.push_back( spiceItem );
344  }
345  }
346 
347  return true;
348 }
Class SCH_SHEET_LIST.
Class SCH_FIELD instances are attached to a component and provide a place for the component's value...
Definition: sch_field.h:56
std::vector< NETLIST_OBJECT * > m_pins
Array containing Standard Pin Name
wxString GetNetName(bool adoptTimestamp=false) const
Function GetNetName.
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.
SCH_FIELD * FindField(const wxString &aFieldName)
Function FindField searches for SCH_FIELD with aFieldName and returns it if found, else NULL.
bool m_enabled
Flag to indicate whether the component should be used in simulation.
EDA_ITEM * Next() const
Definition: base_struct.h:206
void Clear()
Function Clear erases the record.
wxString GetPinNumText()
Function GetPinNum returns a pin number in wxString form.
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:54
const wxString & GetText() const
Function GetText returns the string associated with the text object.
Definition: eda_text.h:130
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...
NETLIST_OBJECTS m_SortedComponentPinList
no ownership
const wxString GetRef(const SCH_SHEET_PATH *sheet)
Function GetRef returns the reference, for the given sheet path.
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:68
Class EDA_ITEM is a base class for most all the KiCad significant classes, used in schematics and boa...
Definition: base_struct.h:151
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:69
void NETLIST_EXPORTER_PSPICE::ReplaceForbiddenChars ( wxString &  aNetName)
staticinherited

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 NETLIST_EXPORTER_PSPICE::Format(), and 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_PSPICE_SIM::SetSimCommand ( const wxString &  aCmd)
inline

Overrides the simulation command directive.

Definition at line 70 of file netlist_exporter_pspice_sim.h.

References m_simCommand.

71  {
72  m_simCommand = aCmd;
73  }
wxString m_simCommand
Custom simulation command (has priority over the schematic sheet simulation commands) ...
void NETLIST_EXPORTER::sprintPinNetName ( wxString &  aResult,
const wxString &  aNetNameFormat,
NETLIST_OBJECT aPin,
bool  aUseNetcodeAsNetName = false 
)
staticprotectedinherited

Function sprintPinNetName formats the net name for aPin using aNetNameFormat into aResult.

Net name is:

  • "?" if pin not connected
  • "netname" for global net (like gnd, vcc ..
  • "/path/netname" for the usual nets

if aUseNetcodeAsNetName is true, the net name is just the net code (SPICE only)

Definition at line 75 of file netlist_exporter.cpp.

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

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

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

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 NETLIST_EXPORTER_PSPICE::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)
inherited

Updates the vector of Spice directives placed in the schematics.

Definition at line 351 of file netlist_exporter_pspice.cpp.

References g_RootSheet, GetText(), NETLIST_EXPORTER_PSPICE::m_directives, NETLIST_EXPORTER_PSPICE::m_libraries, and SCH_TEXT_T.

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

352 {
353  const SCH_SHEET_LIST& sheetList = g_RootSheet;
354 
355  m_directives.clear();
356 
357  for( unsigned i = 0; i < sheetList.size(); i++ )
358  {
359  for( EDA_ITEM* item = sheetList[i].LastDrawList(); item; item = item->Next() )
360  {
361  if( item->Type() != SCH_TEXT_T )
362  continue;
363 
364  wxString text = static_cast<SCH_TEXT*>( item )->GetText();
365 
366  if( text.IsEmpty() )
367  continue;
368 
369  if( text.GetChar( 0 ) == '.' )
370  {
371  wxStringTokenizer tokenizer( text, "\r\n" );
372 
373  while( tokenizer.HasMoreTokens() )
374  {
375  wxString directive( tokenizer.GetNextToken() );
376 
377  if( directive.StartsWith( ".inc" ) )
378  {
379  wxString lib = directive.AfterFirst( ' ' );
380 
381  if( !lib.IsEmpty() )
382  m_libraries.insert( lib );
383  }
384  else
385  {
386  m_directives.push_back( directive );
387  }
388  }
389  }
390  }
391  }
392 }
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
SCH_SHEET * g_RootSheet
Definition: eeschema.cpp:54
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:151
void NETLIST_EXPORTER_PSPICE_SIM::writeDirectives ( OUTPUTFORMATTER aFormatter,
unsigned  aCtl 
) const
overrideprotectedvirtual

Saves the Spice directives.

Todo:
is it required to switch to lowercase

Reimplemented from NETLIST_EXPORTER_PSPICE.

Definition at line 144 of file netlist_exporter_pspice_sim.cpp.

References GetCurrents(), NETLIST_EXPORTER_PSPICE::GetDirectives(), NETLIST_EXPORTER_PSPICE::GetNetIndexMap(), NETLIST_EXPORTER_PSPICE::GetSpiceItems(), GetSpiceVector(), IsSimCommand(), m_simCommand, OUTPUTFORMATTER::Print(), SPT_CURRENT, SPT_VOLTAGE, and NETLIST_EXPORTER_PSPICE::writeDirectives().

145 {
146  // Add a directive to obtain currents
147  //aFormatter->Print( 0, ".options savecurrents\n" ); // does not work :(
148 
149  for( const auto& item : GetSpiceItems() )
150  {
151  for( const auto& current :
153  {
154  if( !item.m_enabled )
155  continue;
156 
158  aFormatter->Print( 0, ".save %s\n",
159  (const char*) GetSpiceVector( item.m_refName, SPT_CURRENT, current ).c_str() );
160  }
161  }
162 
163  // If we print out .save directives for currents, then it needs to be done for voltages as well
164  for( const auto& netMap : GetNetIndexMap() )
165  {
166  aFormatter->Print( 0, ".save %s\n",
167  (const char*) GetSpiceVector( netMap.first, SPT_VOLTAGE ).c_str() );
168  }
169 
170  if( m_simCommand.IsEmpty() )
171  {
172  // Fallback to the default behavior and just write all directives
173  NETLIST_EXPORTER_PSPICE::writeDirectives( aFormatter, aCtl );
174  }
175  else
176  {
177  // Dump all directives but simulation commands
178  for( const auto& dir : GetDirectives() )
179  {
180  if( !IsSimCommand( dir ) )
181  aFormatter->Print( 0, "%s\n", (const char*) dir.c_str() );
182  }
183 
184  // Finish with our custom simulation command
185  aFormatter->Print( 0, "%s\n", (const char*) m_simCommand.c_str() );
186  }
187 }
const std::vector< wxString > GetDirectives() const
Returnss a vector of Spice directives found in the schematics.
wxString m_simCommand
Custom simulation command (has priority over the schematic sheet simulation commands) ...
const NET_INDEX_MAP & GetNetIndexMap() const
Returns a map of circuit nodes to net names.
wxString GetSpiceVector(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam=wxEmptyString) const
Returns name of Spice dataset for a specific plot.
static bool IsSimCommand(const wxString &aCmd)
Determines if a directive is a simulation command.
static const std::vector< wxString > & GetCurrents(SPICE_PRIMITIVE aPrimitive)
Returns a list of currents that can be probed in a Spice primitive.
const SPICE_ITEM_LIST & GetSpiceItems() const
Returns list of items representing schematic components in the Spice world.
virtual void writeDirectives(OUTPUTFORMATTER *aFormatter, unsigned aCtl) const
Saves the Spice directives.
SPICE_PRIMITIVE
Basic Spice component primitives
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Function Print formats and writes text to the output stream.
Definition: richio.cpp:408
bool NETLIST_EXPORTER_PSPICE::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions 
)
overridevirtualinherited

Function WriteNetlist writes to specified output file.

Reimplemented from NETLIST_EXPORTER.

Definition at line 42 of file netlist_exporter_pspice.cpp.

References NETLIST_EXPORTER_PSPICE::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::set<LIB_PART*, LIB_PART_LESS_THAN> NETLIST_EXPORTER::m_LibParts
protectedinherited
std::set<void*> NETLIST_EXPORTER::m_Libraries
protectedinherited

unique libraries used

Definition at line 107 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER_GENERIC::makeLibParts(), and NETLIST_EXPORTER_GENERIC::makeLibraries().

PART_LIBS* NETLIST_EXPORTER::m_libs
protectedinherited
UNIQUE_STRINGS NETLIST_EXPORTER::m_ReferencesAlreadyFound
protectedinherited
wxString NETLIST_EXPORTER_PSPICE_SIM::m_simCommand
private

Custom simulation command (has priority over the schematic sheet simulation commands)

Definition at line 122 of file netlist_exporter_pspice_sim.h.

Referenced by ClearSimCommand(), GetSimCommand(), GetSimType(), SetSimCommand(), and writeDirectives().

NETLIST_OBJECTS NETLIST_EXPORTER::m_SortedComponentPinList
protectedinherited

no ownership

Used to temporary store and filter the list of pins of a schematic component when generating schematic component data in netlist (comp section). No ownership of members.

Definition at line 97 of file netlist_exporter.h.

Referenced by NETLIST_EXPORTER::addPinToComponentPinList(), NETLIST_EXPORTER::eraseDuplicatePins(), NETLIST_EXPORTER::findNextComponentAndCreatePinList(), NETLIST_EXPORTER_PSPICE::ProcessNetlist(), NETLIST_EXPORTER_ORCADPCB2::WriteNetlist(), and NETLIST_EXPORTER_CADSTAR::WriteNetlist().


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