KiCad PCB EDA Suite
NGSPICE_CIRCUIT_MODEL Class Reference

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

#include <ngspice_circuit_model.h>

Inheritance diagram for NGSPICE_CIRCUIT_MODEL:
NETLIST_EXPORTER_SPICE SIMULATION_MODEL NETLIST_EXPORTER_BASE

Public Types

enum  OPTIONS {
  OPTION_ADJUST_INCLUDE_PATHS = 0x0010 , OPTION_ADJUST_PASSIVE_VALS = 0x0020 , OPTION_SAVE_ALL_VOLTAGES = 0x0040 , OPTION_SAVE_ALL_CURRENTS = 0x0080 ,
  OPTION_CUR_SHEET_AS_ROOT = 0x0100 , OPTION_SIM_COMMAND = 0x0200 , OPTION_DEFAULT_FLAGS
}
 

Public Member Functions

 NGSPICE_CIRCUIT_MODEL (SCHEMATIC_IFACE *aSchematic, wxWindow *aDialogParent=nullptr)
 
virtual ~NGSPICE_CIRCUIT_MODEL ()
 
SIM_PLOT_TYPE VectorToSignal (const std::string &aVector, wxString &aSignal) const
 Return name of Spice dataset for a specific plot. More...
 
void SetSimOptions (int aOptions)
 
int GetSimOptions () const
 
bool GetNetlist (OUTPUTFORMATTER *aFormatter, REPORTER &aReporter)
 
void SetSimCommandOverride (const wxString &aCmd)
 Override the simulation command directive. More...
 
wxString GetSimCommand ()
 Return the command directive that is in use (either from the sheet or from m_simCommand) More...
 
wxString GetSimCommandOverride () const
 Return the simulation command directive if stored separately (not as a sheet directive). More...
 
SIM_TYPE GetSimType ()
 Return simulation type basing on the simulation command directives. More...
 
wxString GetSheetSimCommand ()
 Return simulation command directives placed in schematic sheets (if any). More...
 
wxString GetLastSheetSimCommand () const
 Return the sim command present as a sheet directive when the sim command override was last updated. More...
 
bool ParseDCCommand (const wxString &aCmd, SPICE_DC_PARAMS *aSource1, SPICE_DC_PARAMS *aSource2)
 Parse a two-source .dc command directive into its symbols. More...
 
bool WriteNetlist (const wxString &aOutFileName, unsigned aNetlistOptions, REPORTER &aReporter) override
 Write to specified output file. More...
 
bool DoWriteNetlist (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, REPORTER &aReporter)
 Write the netlist in aFormatter. More...
 
virtual void WriteHead (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
 Write the netlist head (title and so on). More...
 
virtual void WriteTail (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
 Write the tail (.end). More...
 
virtual bool ReadSchematicAndLibraries (unsigned aNetlistOptions, REPORTER &aReporter)
 Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs. More...
 
std::set< std::string > GetNets () const
 Return the list of nets. More...
 
std::string GetItemName (const std::string &aRefName) const
 Return name of Spice device corresponding to a schematic symbol. More...
 
const std::list< SPICE_ITEM > & GetItems () const
 Return the list of items representing schematic symbols in the Spice world. More...
 
const SPICE_ITEMFindItem (const std::string &aRefName) const
 Find and return the item corresponding to aRefName. More...
 
const std::vector< wxString > & GetDirectives ()
 

Static Public Member Functions

static bool IsSimCommand (const wxString &aCmd)
 Determine if a directive is a simulation command. More...
 
static SIM_TYPE CommandToSimType (const wxString &aCmd)
 Return simulation type basing on a simulation command directive. More...
 
static void ConvertToSpiceMarkup (std::string &aNetName)
 Remove formatting wrappers and replace illegal spice net name characters with underscores. More...
 
static wxString MakeCommandLine (const wxString &aFormatString, const wxString &aNetlistFile, const wxString &aFinalFile, const wxString &aProjectDirectory)
 Build up a string that describes a command line for executing a child process. More...
 

Protected Member Functions

void WriteDirectives (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions) const override
 
void ReadDirectives (unsigned aNetlistOptions)
 
virtual std::string GenerateItemPinNetName (const std::string &aNetName, int &aNcCounter) const
 
SCH_SHEET_LIST GetSheets (unsigned aNetlistOptions=0) const
 Return the paths of exported sheets (either all or the current one). More...
 
void CreatePinList (SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
 Find a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList. More...
 
SCH_SYMBOLfindNextSymbol (EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
 Check if the given symbol should be processed for netlisting. More...
 
void eraseDuplicatePins ()
 Erase duplicate pins from m_sortedSymbolPinList (i.e. More...
 
void findAllUnitsOfSymbol (SCH_SYMBOL *aSchSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
 Find all units for symbols with multiple symbols per package. More...
 

Protected Attributes

std::vector< PIN_INFOm_sortedSymbolPinList
 Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic symbol data in netlist (comp section). More...
 
UNIQUE_STRINGS m_referencesAlreadyFound
 Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once. More...
 
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THANm_libParts
 unique library symbols used. LIB_SYMBOL items are sorted by names More...
 
SCHEMATIC_IFACEm_schematic
 The schematic we're generating a netlist for. More...
 

Private Member Functions

void readRefName (SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, std::set< std::string > &aRefNames)
 
void readModel (SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem)
 
void readPinNumbers (SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem)
 
void readPinNetNames (SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, int &aNcCounter)
 
void writeInclude (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, const wxString &aPath)
 
void writeIncludes (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
 
void writeModels (OUTPUTFORMATTER &aFormatter)
 
void writeItems (OUTPUTFORMATTER &aFormatter)
 

Private Attributes

wxString m_simCommand
 < Custom simulation command (has priority over the schematic sheet simulation commands) More...
 
wxString m_lastSheetSimCommand
 
int m_options
 
SIM_LIB_MGR m_libMgr
 Holds libraries and models. More...
 
NAME_GENERATOR m_modelNameGenerator
 Generates unique model names. More...
 
NAME_GENERATOR m_netNameGenerator
 
std::vector< wxString > m_directives
 Spice directives found in the schematic sheet. More...
 
std::set< wxString > m_rawIncludes
 include directives found in symbols More...
 
std::set< std::string > m_nets
 Items representing schematic symbols in Spice world. More...
 
std::list< SPICE_ITEMm_items
 
wxWindow * m_dialogParent
 

Detailed Description

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

Definition at line 47 of file ngspice_circuit_model.h.

Member Enumeration Documentation

◆ OPTIONS

Enumerator
OPTION_ADJUST_INCLUDE_PATHS 
OPTION_ADJUST_PASSIVE_VALS 
OPTION_SAVE_ALL_VOLTAGES 
OPTION_SAVE_ALL_CURRENTS 
OPTION_CUR_SHEET_AS_ROOT 
OPTION_SIM_COMMAND 
OPTION_DEFAULT_FLAGS 

Definition at line 52 of file netlist_exporter_spice.h.

Constructor & Destructor Documentation

◆ NGSPICE_CIRCUIT_MODEL()

NGSPICE_CIRCUIT_MODEL::NGSPICE_CIRCUIT_MODEL ( SCHEMATIC_IFACE aSchematic,
wxWindow *  aDialogParent = nullptr 
)
inline

Definition at line 50 of file ngspice_circuit_model.h.

50 :
51 NETLIST_EXPORTER_SPICE( aSchematic, aDialogParent ),
53 {}
NETLIST_EXPORTER_SPICE(SCHEMATIC_IFACE *aSchematic, wxWindow *aDialogParent=nullptr)

◆ ~NGSPICE_CIRCUIT_MODEL()

virtual NGSPICE_CIRCUIT_MODEL::~NGSPICE_CIRCUIT_MODEL ( )
inlinevirtual

Definition at line 55 of file ngspice_circuit_model.h.

55{}

Member Function Documentation

◆ CommandToSimType()

SIM_TYPE NGSPICE_CIRCUIT_MODEL::CommandToSimType ( const wxString &  aCmd)
static

Return simulation type basing on a simulation command directive.

Definition at line 90 of file ngspice_circuit_model.cpp.

91{
92 const std::vector<std::pair<wxString, SIM_TYPE>> simCmds = {
93 { wxT( "^.ac\\M.*" ), ST_AC },
94 { wxT( "^.dc\\M.*" ), ST_DC },
95 { wxT( "^.tran\\M.*" ), ST_TRANSIENT },
96 { wxT( "^.op\\M.*" ), ST_OP },
97 { wxT( "^.disto\\M.*" ), ST_DISTORTION },
98 { wxT( "^.noise\\M.*" ), ST_NOISE },
99 { wxT( "^.pz\\M.*" ), ST_POLE_ZERO },
100 { wxT( "^.sens\\M.*" ), ST_SENSITIVITY },
101 { wxT( "^.tf\\M.*" ), ST_TRANS_FUNC } };
102 wxRegEx simCmd;
103
104 for( const std::pair<wxString, SIM_TYPE>& c : simCmds )
105 {
106 simCmd.Compile( c.first, wxRE_ADVANCED | wxRE_NOSUB | wxRE_ICASE );
107
108 if( simCmd.Matches( aCmd ) )
109 return c.second;
110 }
111
112 return ST_UNKNOWN;
113}
@ ST_TRANS_FUNC
Definition: sim_types.h:41
@ ST_TRANSIENT
Definition: sim_types.h:42
@ ST_DISTORTION
Definition: sim_types.h:36
@ ST_UNKNOWN
Definition: sim_types.h:33
@ ST_NOISE
Definition: sim_types.h:37
@ ST_AC
Definition: sim_types.h:34
@ ST_POLE_ZERO
Definition: sim_types.h:39
@ ST_DC
Definition: sim_types.h:35
@ ST_OP
Definition: sim_types.h:38
@ ST_SENSITIVITY
Definition: sim_types.h:40

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 BOOST_AUTO_TEST_CASE(), GetSimType(), SIM_PANEL_BASE::GetType(), IsSimCommand(), SIM_PLOT_FRAME::NewPlotPanel(), SIM_PLOT_FRAME::onSettings(), SIM_PANEL_BASE::setSimCommand(), and SIM_PLOT_FRAME::StartSimulation().

◆ ConvertToSpiceMarkup()

void NETLIST_EXPORTER_SPICE::ConvertToSpiceMarkup ( std::string &  aNetName)
staticinherited

Remove formatting wrappers and replace illegal spice net name characters with underscores.

Definition at line 291 of file netlist_exporter_spice.cpp.

292{
293 MARKUP::MARKUP_PARSER markupParser( aNetName );
294 std::unique_ptr<MARKUP::NODE> root = markupParser.Parse();
295 std::string converted;
296
297 std::function<void( const std::unique_ptr<MARKUP::NODE>&)> convertMarkup =
298 [&]( const std::unique_ptr<MARKUP::NODE>& aNode )
299 {
300 if( aNode )
301 {
302 if( !aNode->is_root() )
303 {
304 if( aNode->isOverbar() )
305 {
306 // ~{CLK} is a different signal than CLK
307 converted += '~';
308 }
309 else if( aNode->isSubscript() || aNode->isSuperscript() )
310 {
311 // V_{OUT} is just a pretty-printed version of VOUT
312 }
313
314 if( aNode->has_content() )
315 converted += aNode->string();
316 }
317
318 for( const std::unique_ptr<MARKUP::NODE>& child : aNode->children )
319 convertMarkup( child );
320 }
321 };
322
323 convertMarkup( root );
324
325 // Remove ngspice-disallowed chars
326 std::replace( converted.begin(), converted.end(), '%', '_' );
327 std::replace( converted.begin(), converted.end(), '(', '_' );
328 std::replace( converted.begin(), converted.end(), ')', '_' );
329 std::replace( converted.begin(), converted.end(), ',', '_' );
330 std::replace( converted.begin(), converted.end(), '[', '_' );
331 std::replace( converted.begin(), converted.end(), ']', '_' );
332 std::replace( converted.begin(), converted.end(), '<', '_' );
333 std::replace( converted.begin(), converted.end(), '>', '_' );
334 std::replace( converted.begin(), converted.end(), '~', '_' );
335
336 aNetName = converted;
337}

References MARKUP::MARKUP_PARSER::Parse().

Referenced by NETLIST_EXPORTER_SPICE::GenerateItemPinNetName().

◆ CreatePinList()

void NETLIST_EXPORTER_BASE::CreatePinList ( SCH_SYMBOL aSymbol,
SCH_SHEET_PATH aSheetPath,
bool  aKeepUnconnectedPins 
)
protectedinherited

Find a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList.

This list is sorted by pin number. The symbol is the next actual symbol after aSymbol. Power symbols and virtual symbols that have their reference designators starting with '#' are skipped. if aKeepUnconnectedPins = false, unconnected pins will be removed from list but usually we need all pins in netlists.

Definition at line 116 of file netlist_exporter_base.cpp.

118{
119 wxString ref( aSymbol->GetRef( aSheetPath ) );
120
121 // Power symbols and other symbols which have the reference starting with "#" are not
122 // included in netlist (pseudo or virtual symbols)
123
124 if( ref[0] == wxChar( '#' ) )
125 return;
126
127 // if( aSymbol->m_FlagControlMulti == 1 )
128 // continue; /* yes */
129 // removed because with multiple instances of one schematic (several sheets pointing to
130 // 1 screen), this will be erroneously be toggled.
131
132 if( !aSymbol->GetLibSymbolRef() )
133 return;
134
135 m_sortedSymbolPinList.clear();
136
137 // If symbol is a "multi parts per package" type
138 if( aSymbol->GetLibSymbolRef()->GetUnitCount() > 1 )
139 {
140 // Collect all pins for this reference designator by searching the entire design for
141 // other parts with the same reference designator.
142 // This is only done once, it would be too expensive otherwise.
143 findAllUnitsOfSymbol( aSymbol, aSheetPath, aKeepUnconnectedPins );
144 }
145
146 else // GetUnitCount() <= 1 means one part per package
147 {
149
150 for( const SCH_PIN* pin : aSymbol->GetPins( aSheetPath ) )
151 {
152 if( SCH_CONNECTION* conn = pin->Connection( aSheetPath ) )
153 {
154 const wxString& netName = conn->Name();
155
156 if( !aKeepUnconnectedPins ) // Skip unconnected pins if requested
157 {
158 CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, *aSheetPath );
159
160 if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
161 continue;
162 }
163
164 m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
165 }
166 }
167 }
168
169 // Sort pins in m_SortedSymbolPinList by pin number
170 std::sort( m_sortedSymbolPinList.begin(), m_sortedSymbolPinList.end(),
171 []( const PIN_INFO& lhs, const PIN_INFO& rhs )
172 {
173 return StrNumCmp( lhs.num, rhs.num, true ) < 0;
174 } );
175
176 // Remove duplicate Pins in m_SortedSymbolPinList
178
179 // record the usage of this library symbol
180 m_libParts.insert( aSymbol->GetLibSymbolRef().get() ); // rejects non-unique pointers
181}
Calculates the connectivity of a schematic and generates netlists.
CONNECTION_SUBGRAPH * FindSubgraphByName(const wxString &aNetName, const SCH_SHEET_PATH &aPath)
Returns the subgraph for a given net name on a given sheet.
A subgraph is a set of items that are electrically connected on a single sheet.
std::vector< SCH_ITEM * > m_items
SCH_ITEM * m_no_connect
No-connect item in graph, if any.
void eraseDuplicatePins()
Erase duplicate pins from m_sortedSymbolPinList (i.e.
std::set< LIB_SYMBOL *, LIB_SYMBOL_LESS_THAN > m_libParts
unique library symbols used. LIB_SYMBOL items are sorted by names
void findAllUnitsOfSymbol(SCH_SYMBOL *aSchSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
Find all units for symbols with multiple symbols per package.
SCHEMATIC_IFACE * m_schematic
The schematic we're generating a netlist for.
std::vector< PIN_INFO > m_sortedSymbolPinList
Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic...
virtual CONNECTION_GRAPH * ConnectionGraph() const =0
Each graphical item can have a SCH_CONNECTION describing its logical connection (to a bus or net).
const wxString GetRef(const SCH_SHEET_PATH *aSheet, bool aIncludeUnit=false) const
Return the reference for the given sheet path.
Definition: sch_symbol.cpp:652
std::vector< SCH_PIN * > GetPins(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve a list of the SCH_PINs for the given sheet path.
std::unique_ptr< LIB_SYMBOL > & GetLibSymbolRef()
Definition: sch_symbol.h:192

References SCHEMATIC_IFACE::ConnectionGraph(), NETLIST_EXPORTER_BASE::eraseDuplicatePins(), NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_SYMBOL::GetLibSymbolRef(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), CONNECTION_SUBGRAPH::m_items, NETLIST_EXPORTER_BASE::m_libParts, CONNECTION_SUBGRAPH::m_no_connect, NETLIST_EXPORTER_BASE::m_schematic, NETLIST_EXPORTER_BASE::m_sortedSymbolPinList, and pin.

Referenced by NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ DoWriteNetlist()

bool NETLIST_EXPORTER_SPICE::DoWriteNetlist ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions,
REPORTER aReporter 
)
inherited

Write the netlist in aFormatter.

Definition at line 121 of file netlist_exporter_spice.cpp.

123{
125
126 // Cleanup list to avoid duplicate if the netlist exporter is run more than once.
127 m_rawIncludes.clear();
128
129 if( !ReadSchematicAndLibraries( aNetlistOptions, aReporter ) )
130 return false;
131
132 WriteHead( aFormatter, aNetlistOptions );
133
134 writeIncludes( aFormatter, aNetlistOptions );
135 writeModels( aFormatter );
136
137 // Skip this if there is no netlist to avoid an ngspice segfault
138 if( !m_items.empty() )
139 WriteDirectives( aFormatter, aNetlistOptions );
140
141 writeItems( aFormatter );
142
143 WriteTail( aFormatter, aNetlistOptions );
144
145 return true;
146}
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:41
void writeModels(OUTPUTFORMATTER &aFormatter)
void writeIncludes(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
std::list< SPICE_ITEM > m_items
virtual void WriteDirectives(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions) const
void writeItems(OUTPUTFORMATTER &aFormatter)
virtual void WriteHead(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
Write the netlist head (title and so on).
virtual bool ReadSchematicAndLibraries(unsigned aNetlistOptions, REPORTER &aReporter)
Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs.
std::set< wxString > m_rawIncludes
include directives found in symbols
virtual void WriteTail(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions)
Write the tail (.end).
std::vector< FAB_LAYER_COLOR > dummy

References dummy, NETLIST_EXPORTER_SPICE::m_items, NETLIST_EXPORTER_SPICE::m_rawIncludes, NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries(), NETLIST_EXPORTER_SPICE::WriteDirectives(), NETLIST_EXPORTER_SPICE::WriteHead(), NETLIST_EXPORTER_SPICE::writeIncludes(), NETLIST_EXPORTER_SPICE::writeItems(), NETLIST_EXPORTER_SPICE::writeModels(), and NETLIST_EXPORTER_SPICE::WriteTail().

Referenced by GetNetlist(), and NETLIST_EXPORTER_SPICE::WriteNetlist().

◆ eraseDuplicatePins()

void NETLIST_EXPORTER_BASE::eraseDuplicatePins ( )
protectedinherited

Erase duplicate pins from m_sortedSymbolPinList (i.e.

set pointer in this list to NULL).

(This is a list of pins found in the whole schematic, for a single symbol.) These duplicate pins were put in list because some pins (power pins...) are found more than once when in "multiple symbols per package" symbols. For instance, a 74ls00 has 4 symbols, 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 184 of file netlist_exporter_base.cpp.

185{
186 for( unsigned ii = 0; ii < m_sortedSymbolPinList.size(); ii++ )
187 {
188 if( m_sortedSymbolPinList[ii].num.empty() ) /* already deleted */
189 continue;
190
191 /* Search for duplicated pins
192 * If found, remove duplicates. The priority is to keep connected pins
193 * and remove unconnected
194 * - So this allows (for instance when using multi op amps per package
195 * - to connect only one op amp to power
196 * Because the pin list is sorted by m_PinNum value, duplicated pins
197 * are necessary successive in list
198 */
199 int idxref = ii;
200
201 for( unsigned jj = ii + 1; jj < m_sortedSymbolPinList.size(); jj++ )
202 {
203 if( m_sortedSymbolPinList[jj].num.empty() ) // Already removed
204 continue;
205
206 // if other pin num, stop search,
207 // because all pins having the same number are consecutive in list.
208 if( m_sortedSymbolPinList[idxref].num != m_sortedSymbolPinList[jj].num )
209 break;
210
211 m_sortedSymbolPinList[jj].num.clear();
212 }
213 }
214}

References NETLIST_EXPORTER_BASE::m_sortedSymbolPinList.

Referenced by NETLIST_EXPORTER_BASE::CreatePinList().

◆ findAllUnitsOfSymbol()

void NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol ( SCH_SYMBOL aSchSymbol,
SCH_SHEET_PATH aSheetPath,
bool  aKeepUnconnectedPins 
)
protectedinherited

Find all units for symbols with multiple symbols per package.

Search the entire design for all units of aSymbol based on matching reference designator, and for each unit, add all its pins to the temporary sorted pin list, m_sortedSymbolPinList. if aKeepUnconnectedPins = false, unconnected pins will be removed from list but usually we need all pins in netlists.

Definition at line 217 of file netlist_exporter_base.cpp.

220{
221 wxString ref = aSchSymbol->GetRef( aSheetPath );
222 wxString ref2;
223
224 SCH_SHEET_LIST sheetList = m_schematic->GetSheets();
226
227 for( unsigned i = 0; i < sheetList.size(); i++ )
228 {
229 SCH_SHEET_PATH& sheet = sheetList[i];
230
231 for( SCH_ITEM* item : sheetList[i].LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
232 {
233 SCH_SYMBOL* comp2 = static_cast<SCH_SYMBOL*>( item );
234
235 ref2 = comp2->GetRef( &sheet );
236
237 if( ref2.CmpNoCase( ref ) != 0 )
238 continue;
239
240 for( const SCH_PIN* pin : comp2->GetPins( &sheet ) )
241 {
242 if( SCH_CONNECTION* conn = pin->Connection( &sheet ) )
243 {
244 const wxString& netName = conn->Name();
245
246 if( !aKeepUnconnectedPins ) // Skip unconnected pins if requested
247 {
248 CONNECTION_SUBGRAPH* sg = graph->FindSubgraphByName( netName, sheet );
249
250 if( !sg || sg->m_no_connect || sg->m_items.size() < 2 )
251 continue;
252 }
253
254 m_sortedSymbolPinList.emplace_back( pin->GetShownNumber(), netName );
255 }
256 }
257 }
258 }
259}
virtual SCH_SHEET_LIST GetSheets() const =0
Base class for any item which can be embedded within the SCHEMATIC container class,...
Definition: sch_item.h:147
A container for handling SCH_SHEET_PATH objects in a flattened hierarchy.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition: sch_symbol.h:81
@ SCH_SYMBOL_T
Definition: typeinfo.h:156

References SCHEMATIC_IFACE::ConnectionGraph(), CONNECTION_GRAPH::FindSubgraphByName(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), SCHEMATIC_IFACE::GetSheets(), CONNECTION_SUBGRAPH::m_items, CONNECTION_SUBGRAPH::m_no_connect, NETLIST_EXPORTER_BASE::m_schematic, NETLIST_EXPORTER_BASE::m_sortedSymbolPinList, pin, and SCH_SYMBOL_T.

Referenced by NETLIST_EXPORTER_BASE::CreatePinList().

◆ FindItem()

const SPICE_ITEM * NETLIST_EXPORTER_SPICE::FindItem ( const std::string &  aRefName) const
inherited

Find and return the item corresponding to aRefName.

Definition at line 351 of file netlist_exporter_spice.cpp.

352{
353 const std::list<SPICE_ITEM>& spiceItems = GetItems();
354
355 auto it = std::find_if( spiceItems.begin(), spiceItems.end(),
356 [aRefName]( const SPICE_ITEM& item )
357 {
358 return item.refName == aRefName;
359 } );
360
361 if( it != spiceItems.end() )
362 return &*it;
363
364 return nullptr;
365}
const std::list< SPICE_ITEM > & GetItems() const
Return the list of items representing schematic symbols in the Spice world.

References NETLIST_EXPORTER_SPICE::GetItems().

Referenced by SIM_PLOT_FRAME::AddTuner(), SIM_PLOT_FRAME::applyTuners(), NETLIST_EXPORTER_SPICE::GetItemName(), and TUNER_SLIDER::TUNER_SLIDER().

◆ findNextSymbol()

SCH_SYMBOL * NETLIST_EXPORTER_BASE::findNextSymbol ( EDA_ITEM aItem,
SCH_SHEET_PATH aSheetPath 
)
protectedinherited

Check if the given symbol should be processed for netlisting.

Prevent processing multi-unit symbols more than once, etc.

Parameters
aItemis a symbol to check
aSheetPathis the sheet to check the symbol for
Returns
the symbol if it should be processed, or nullptr

Definition at line 73 of file netlist_exporter_base.cpp.

74{
75 wxCHECK( aItem, nullptr );
76 wxCHECK( aSheetPath, nullptr );
77
78 wxString ref;
79
80 if( aItem->Type() != SCH_SYMBOL_T )
81 return nullptr;
82
83 // found next symbol
84 SCH_SYMBOL* symbol = (SCH_SYMBOL*) aItem;
85
86 // Power symbols and other symbols which have the reference starting with "#" are not
87 // included in netlist (pseudo or virtual symbols)
88 ref = symbol->GetRef( aSheetPath );
89
90 if( ref[0] == wxChar( '#' ) )
91 return nullptr;
92
93 SCH_SCREEN* screen = aSheetPath->LastScreen();
94
95 wxCHECK( screen, nullptr );
96
97 LIB_SYMBOL* libSymbol = screen->GetLibSymbols()[ symbol->GetSchSymbolLibraryName() ];
98
99 wxCHECK( libSymbol, nullptr );
100
101 // If symbol is a "multi parts per package" type
102 if( libSymbol->GetUnitCount() > 1 )
103 {
104 // test if this reference has already been processed, and if so skip
106 return nullptr;
107 }
108
109 // record the usage of this library symbol entry.
110 m_libParts.insert( libSymbol ); // rejects non-unique pointers
111
112 return symbol;
113}
KICAD_T Type() const
Returns the type of object.
Definition: eda_item.h:97
Define a library symbol object.
Definition: lib_symbol.h:99
int GetUnitCount() const override
For items with units, return the number of units.
UNIQUE_STRINGS m_referencesAlreadyFound
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
std::map< wxString, LIB_SYMBOL * > & GetLibSymbols()
Fetch a list of unique LIB_SYMBOL object pointers required to properly render each SCH_SYMBOL in this...
Definition: sch_screen.h:481
SCH_SCREEN * LastScreen()
wxString GetSchSymbolLibraryName() const
Definition: sch_symbol.cpp:290
bool Lookup(const wxString &aString)

References SCH_SCREEN::GetLibSymbols(), SCH_SYMBOL::GetRef(), SCH_SYMBOL::GetSchSymbolLibraryName(), LIB_SYMBOL::GetUnitCount(), SCH_SHEET_PATH::LastScreen(), UNIQUE_STRINGS::Lookup(), NETLIST_EXPORTER_BASE::m_libParts, NETLIST_EXPORTER_BASE::m_referencesAlreadyFound, SCH_SYMBOL_T, and EDA_ITEM::Type().

Referenced by NETLIST_EXPORTER_XML::makeSymbols(), NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ GenerateItemPinNetName()

std::string NETLIST_EXPORTER_SPICE::GenerateItemPinNetName ( const std::string &  aNetName,
int &  aNcCounter 
) const
protectedvirtualinherited

Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.

Definition at line 660 of file netlist_exporter_spice.cpp.

662{
663 std::string netName = aNetName;
664
665 ConvertToSpiceMarkup( netName );
666 netName = std::string( UnescapeString( netName ).ToUTF8() );
667
668 if( netName == "" )
669 netName = fmt::format( "NC-{}", aNcCounter++ );
670
671 return netName;
672}
static void ConvertToSpiceMarkup(std::string &aNetName)
Remove formatting wrappers and replace illegal spice net name characters with underscores.
wxString UnescapeString(const wxString &aSource)

References NETLIST_EXPORTER_SPICE::ConvertToSpiceMarkup(), and UnescapeString().

Referenced by NETLIST_EXPORTER_SPICE_MODEL::GenerateItemPinNetName(), and NETLIST_EXPORTER_SPICE::readPinNetNames().

◆ GetDirectives()

const std::vector< wxString > & NETLIST_EXPORTER_SPICE::GetDirectives ( )
inlineinherited

Definition at line 129 of file netlist_exporter_spice.h.

129{ return m_directives; }
std::vector< wxString > m_directives
Spice directives found in the schematic sheet.

References NETLIST_EXPORTER_SPICE::m_directives.

Referenced by GetSheetSimCommand().

◆ GetItemName()

std::string NETLIST_EXPORTER_SPICE::GetItemName ( const std::string &  aRefName) const
inherited

Return name of Spice device corresponding to a schematic symbol.

Parameters
aRefNameis the component reference.
Returns
Spice device name or empty string if there is no such symbol in the netlist. Normally the name is either a plain reference if the first character of reference corresponds to the assigned device model type or a reference prefixed with a character defining the device model type.

Definition at line 340 of file netlist_exporter_spice.cpp.

341{
342 const SPICE_ITEM* item = FindItem( aRefName );
343
344 if( !item )
345 return "";
346
347 return item->model->SpiceGenerator().ItemName( *item );
348}
const SPICE_ITEM * FindItem(const std::string &aRefName) const
Find and return the item corresponding to aRefName.
const SPICE_GENERATOR & SpiceGenerator() const
Definition: sim_model.h:430
virtual std::string ItemName(const SPICE_ITEM &aItem) const
const SIM_MODEL * model

References NETLIST_EXPORTER_SPICE::FindItem(), SPICE_GENERATOR::ItemName(), SPICE_ITEM::model, and SIM_MODEL::SpiceGenerator().

◆ GetItems()

const std::list< SPICE_ITEM > & NETLIST_EXPORTER_SPICE::GetItems ( ) const
inlineinherited

Return the list of items representing schematic symbols in the Spice world.

Definition at line 122 of file netlist_exporter_spice.h.

122{ return m_items; }

References NETLIST_EXPORTER_SPICE::m_items.

Referenced by NETLIST_EXPORTER_SPICE::FindItem(), and DIALOG_SIGNAL_LIST::TransferDataToWindow().

◆ GetLastSheetSimCommand()

wxString NGSPICE_CIRCUIT_MODEL::GetLastSheetSimCommand ( ) const
inline

Return the sim command present as a sheet directive when the sim command override was last updated.

Returns

Definition at line 119 of file ngspice_circuit_model.h.

References m_lastSheetSimCommand.

◆ GetNetlist()

bool NGSPICE_CIRCUIT_MODEL::GetNetlist ( OUTPUTFORMATTER aFormatter,
REPORTER aReporter 
)
inline

Definition at line 70 of file ngspice_circuit_model.h.

71 {
72 return NGSPICE_CIRCUIT_MODEL::DoWriteNetlist( *aFormatter, m_options, aReporter );
73 }
bool DoWriteNetlist(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, REPORTER &aReporter)
Write the netlist in aFormatter.

References NETLIST_EXPORTER_SPICE::DoWriteNetlist(), and m_options.

Referenced by NGSPICE::Attach().

◆ GetNets()

std::set< std::string > NETLIST_EXPORTER_SPICE::GetNets ( ) const
inlineinherited

Return the list of nets.

Definition at line 106 of file netlist_exporter_spice.h.

106{ return m_nets; }
std::set< std::string > m_nets
Items representing schematic symbols in Spice world.

References NETLIST_EXPORTER_SPICE::m_nets.

Referenced by DIALOG_SIGNAL_LIST::TransferDataToWindow().

◆ GetSheets()

SCH_SHEET_LIST NETLIST_EXPORTER_SPICE::GetSheets ( unsigned  aNetlistOptions = 0) const
protectedinherited

Return the paths of exported sheets (either all or the current one).

Definition at line 675 of file netlist_exporter_spice.cpp.

676{
677 if( aNetlistOptions & OPTION_CUR_SHEET_AS_ROOT )
679 else
680 return m_schematic->GetSheets();
681}
virtual SCH_SHEET_PATH & CurrentSheet() const =0
SCH_SHEET * Last() const
Return a pointer to the last SCH_SHEET of the list.

References SCHEMATIC_IFACE::CurrentSheet(), SCHEMATIC_IFACE::GetSheets(), SCH_SHEET_PATH::Last(), NETLIST_EXPORTER_BASE::m_schematic, and NETLIST_EXPORTER_SPICE::OPTION_CUR_SHEET_AS_ROOT.

Referenced by NETLIST_EXPORTER_SPICE::ReadDirectives(), NETLIST_EXPORTER_SPICE_MODEL::readPorts(), and NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ GetSheetSimCommand()

wxString NGSPICE_CIRCUIT_MODEL::GetSheetSimCommand ( )

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

Definition at line 68 of file ngspice_circuit_model.cpp.

69{
70 wxString simCmd;
71
72 ReadDirectives( 0 );
73
74 for( const wxString& directive : GetDirectives() )
75 {
76 if( IsSimCommand( directive ) )
77 simCmd += wxString::Format( wxT( "%s\r\n" ), directive );
78 }
79
80 return simCmd;
81}
void ReadDirectives(unsigned aNetlistOptions)
const std::vector< wxString > & GetDirectives()
static bool IsSimCommand(const wxString &aCmd)
Determine if a directive is a simulation command.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References Format(), NETLIST_EXPORTER_SPICE::GetDirectives(), IsSimCommand(), and NETLIST_EXPORTER_SPICE::ReadDirectives().

Referenced by GetSimCommand(), and SetSimCommandOverride().

◆ GetSimCommand()

wxString NGSPICE_CIRCUIT_MODEL::GetSimCommand ( )
inline

Return the command directive that is in use (either from the sheet or from m_simCommand)

Returns

Definition at line 91 of file ngspice_circuit_model.h.

92 {
93 return m_simCommand.IsEmpty() ? GetSheetSimCommand() : m_simCommand;
94 }
wxString GetSheetSimCommand()
Return simulation command directives placed in schematic sheets (if any).
wxString m_simCommand
< Custom simulation command (has priority over the schematic sheet simulation commands)

References GetSheetSimCommand(), and m_simCommand.

Referenced by GetSimType().

◆ GetSimCommandOverride()

wxString NGSPICE_CIRCUIT_MODEL::GetSimCommandOverride ( ) const
inline

Return the simulation command directive if stored separately (not as a sheet directive).

Definition at line 99 of file ngspice_circuit_model.h.

99{ return m_simCommand; }

References m_simCommand.

Referenced by WriteDirectives().

◆ GetSimOptions()

int NGSPICE_CIRCUIT_MODEL::GetSimOptions ( ) const
inline

Definition at line 68 of file ngspice_circuit_model.h.

68{ return m_options; }

References m_options.

◆ GetSimType()

SIM_TYPE NGSPICE_CIRCUIT_MODEL::GetSimType ( )

Return simulation type basing on the simulation command directives.

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

Definition at line 84 of file ngspice_circuit_model.cpp.

85{
87}
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Return simulation type basing on a simulation command directive.
wxString GetSimCommand()
Return the command directive that is in use (either from the sheet or from m_simCommand)

References CommandToSimType(), and GetSimCommand().

Referenced by DIALOG_SIGNAL_LIST::TransferDataToWindow().

◆ IsSimCommand()

static bool NGSPICE_CIRCUIT_MODEL::IsSimCommand ( const wxString &  aCmd)
inlinestatic

Determine if a directive is a simulation command.

Definition at line 133 of file ngspice_circuit_model.h.

134 {
135 return CommandToSimType( aCmd ) != ST_UNKNOWN;
136 }

References CommandToSimType(), and ST_UNKNOWN.

Referenced by GetSheetSimCommand().

◆ MakeCommandLine()

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

Build 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 37 of file netlist_exporter_base.cpp.

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

Referenced by SCH_EDIT_FRAME::WriteNetListFile().

◆ ParseDCCommand()

bool NGSPICE_CIRCUIT_MODEL::ParseDCCommand ( const wxString &  aCmd,
SPICE_DC_PARAMS aSource1,
SPICE_DC_PARAMS aSource2 
)

Parse a two-source .dc command directive into its symbols.

Parameters
aCmdis the input command string
Returns
true if the command was parsed successfully

Definition at line 116 of file ngspice_circuit_model.cpp.

118{
119 if( !aCmd.Lower().StartsWith( ".dc" ) )
120 return false;
121
122 wxString cmd = aCmd.Mid( 3 ).Trim().Trim( false );
123
124 wxStringTokenizer tokens( cmd );
125
126 size_t num = tokens.CountTokens();
127
128 if( num != 4 && num != 8 )
129 return false;
130
131 aSource1->m_source = tokens.GetNextToken();
132 aSource1->m_vstart = SPICE_VALUE( tokens.GetNextToken() );
133 aSource1->m_vend = SPICE_VALUE( tokens.GetNextToken() );
134 aSource1->m_vincrement = SPICE_VALUE( tokens.GetNextToken() );
135
136 if( num == 8 )
137 {
138 aSource2->m_source = tokens.GetNextToken();
139 aSource2->m_vstart = SPICE_VALUE( tokens.GetNextToken() );
140 aSource2->m_vend = SPICE_VALUE( tokens.GetNextToken() );
141 aSource2->m_vincrement = SPICE_VALUE( tokens.GetNextToken() );
142 }
143
144 return true;
145}
< Helper class to handle Spice way of expressing values (e.g. 10.5 Meg) Helper class to recognize Spi...
Definition: spice_value.h:35

References SPICE_DC_PARAMS::m_source, SPICE_DC_PARAMS::m_vend, SPICE_DC_PARAMS::m_vincrement, and SPICE_DC_PARAMS::m_vstart.

◆ ReadDirectives()

void NETLIST_EXPORTER_SPICE::ReadDirectives ( unsigned  aNetlistOptions)
protectedinherited

Definition at line 368 of file netlist_exporter_spice.cpp.

369{
370 wxString msg;
371 wxString text;
372
373 m_directives.clear();
374
375 for( const SCH_SHEET_PATH& sheet : GetSheets( aNetlistOptions ) )
376 {
377 for( SCH_ITEM* item : sheet.LastScreen()->Items() )
378 {
379 if( item->Type() == SCH_TEXT_T )
380 text = static_cast<SCH_TEXT*>( item )->GetShownText();
381 else if( item->Type() == SCH_TEXTBOX_T )
382 text = static_cast<SCH_TEXTBOX*>( item )->GetShownText();
383 else
384 continue;
385
386 // Send anything that contains directives to SPICE
387 wxStringTokenizer tokenizer( text, wxT( "\r\n" ), wxTOKEN_STRTOK );
388 bool foundDirective = false;
389
390 while( tokenizer.HasMoreTokens() )
391 {
392 wxString line = tokenizer.GetNextToken().Upper();
393
394 if( line.StartsWith( wxT( "." ) ) )
395 {
396 if( line.StartsWith( wxT( ".AC" ) )
397 || line.StartsWith( wxT( ".CONTROL" ) )
398 || line.StartsWith( wxT( ".CSPARAM" ) )
399 || line.StartsWith( wxT( ".DISTO" ) )
400 || line.StartsWith( wxT( ".ELSE" ) )
401 || line.StartsWith( wxT( ".ELSEIF" ) )
402 || line.StartsWith( wxT( ".END" ) )
403 || line.StartsWith( wxT( ".ENDC" ) )
404 || line.StartsWith( wxT( ".ENDIF" ) )
405 || line.StartsWith( wxT( ".ENDS" ) )
406 || line.StartsWith( wxT( ".FOUR" ) )
407 || line.StartsWith( wxT( ".FUNC" ) )
408 || line.StartsWith( wxT( ".GLOBAL" ) )
409 || line.StartsWith( wxT( ".IC" ) )
410 || line.StartsWith( wxT( ".IF" ) )
411 || line.StartsWith( wxT( ".INCLUDE" ) )
412 || line.StartsWith( wxT( ".LIB" ) )
413 || line.StartsWith( wxT( ".MEAS" ) )
414 || line.StartsWith( wxT( ".MODEL" ) )
415 || line.StartsWith( wxT( ".NODESET" ) )
416 || line.StartsWith( wxT( ".NOISE" ) )
417 || line.StartsWith( wxT( ".OP" ) )
418 || line.StartsWith( wxT( ".OPTIONS" ) )
419 || line.StartsWith( wxT( ".PARAM" ) )
420 || line.StartsWith( wxT( ".PLOT" ) )
421 || line.StartsWith( wxT( ".PRINT" ) )
422 || line.StartsWith( wxT( ".PROBE" ) )
423 || line.StartsWith( wxT( ".PZ" ) )
424 || line.StartsWith( wxT( ".SAVE" ) )
425 || line.StartsWith( wxT( ".SENS" ) )
426 || line.StartsWith( wxT( ".SP" ) )
427 || line.StartsWith( wxT( ".SUBCKT" ) )
428 || line.StartsWith( wxT( ".TEMP" ) )
429 || line.StartsWith( wxT( ".TF" ) )
430 || line.StartsWith( wxT( ".TITLE" ) )
431 || line.StartsWith( wxT( ".TRAN" ) )
432 || line.StartsWith( wxT( ".WIDTH" ) ) )
433 {
434 foundDirective = true;
435 break;
436 }
437 }
438 else if( line.StartsWith( wxT( "K" ) ) )
439 {
440 // Check for mutual inductor declaration
441 wxStringTokenizer line_t( line, wxT( " \t" ), wxTOKEN_STRTOK );
442
443 // Coupling ID
444 if( !line_t.HasMoreTokens() || !line_t.GetNextToken().StartsWith( wxT( "K" ) ) )
445 continue;
446
447 // Inductor 1 ID
448 if( !line_t.HasMoreTokens() || !line_t.GetNextToken().StartsWith( wxT( "L" ) ) )
449 continue;
450
451 // Inductor 2 ID
452 if( !line_t.HasMoreTokens() || !line_t.GetNextToken().StartsWith( wxT( "L" ) ) )
453 continue;
454
455 // That's probably distinctive enough not to bother trying to parse the
456 // coupling value. If there's anything else, assume it's the value.
457 if( line_t.HasMoreTokens() )
458 {
459 foundDirective = true;
460 break;
461 }
462 }
463 }
464
465 if( foundDirective )
466 m_directives.emplace_back( text );
467 }
468 }
469}
SCH_SHEET_LIST GetSheets(unsigned aNetlistOptions=0) const
Return the paths of exported sheets (either all or the current one).
wxString GetShownText(int aDepth=0, bool aAllowExtraText=true) const override
Return the string actually shown after processing of the base text.
@ SCH_TEXT_T
Definition: typeinfo.h:150
@ SCH_TEXTBOX_T
Definition: typeinfo.h:149

References NETLIST_EXPORTER_SPICE::GetSheets(), SCH_TEXTBOX::GetShownText(), NETLIST_EXPORTER_SPICE::m_directives, SCH_TEXT_T, SCH_TEXTBOX_T, and text.

Referenced by GetSheetSimCommand(), and NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ readModel()

void NETLIST_EXPORTER_SPICE::readModel ( SCH_SHEET_PATH aSheet,
SCH_SYMBOL aSymbol,
SPICE_ITEM aItem 
)
privateinherited

Definition at line 482 of file netlist_exporter_spice.cpp.

484{
485 SIM_LIBRARY::MODEL libModel = m_libMgr.CreateModel( &aSheet, aSymbol );
486
487 aItem.baseModelName = libModel.name;
488 aItem.model = &libModel.model;
489
490 std::string modelName = aItem.model->SpiceGenerator().ModelName( aItem );
491 // Resolve model name collisions.
492 aItem.modelName = m_modelNameGenerator.Generate( modelName );
493
494 // FIXME: Don't have special cases for raw Spice models and KIBIS.
495 if( auto rawSpiceModel = dynamic_cast<const SIM_MODEL_RAW_SPICE*>( aItem.model ) )
496 {
497 int libParamIndex = static_cast<int>( SIM_MODEL_RAW_SPICE::SPICE_PARAM::LIB );
498 wxString path = rawSpiceModel->GetParam( libParamIndex ).value->ToString();
499
500 if( !path.IsEmpty() )
501 m_rawIncludes.insert( path );
502 }
503 else if( auto kibisModel = dynamic_cast<const SIM_MODEL_KIBIS*>( aItem.model ) )
504 {
505 wxFileName cacheFn;
506 cacheFn.AssignDir( PATHS::GetUserCachePath() );
507 cacheFn.AppendDir( wxT( "ibis" ) );
508 cacheFn.SetFullName( aSymbol.GetRef( &aSheet ) + wxT( ".cache" ) );
509
510 wxFile cacheFile( cacheFn.GetFullPath(), wxFile::write );
511
512 if( !cacheFile.IsOpened() )
513 {
515 wxString::Format( _( "Could not open file '%s' to write "
516 "IBIS model" ),
517 cacheFn.GetFullPath() ) );
518 }
519
520 auto spiceGenerator = static_cast<const SPICE_GENERATOR_KIBIS&>( kibisModel->SpiceGenerator() );
521 std::string modelData = spiceGenerator.IbisDevice( aItem, m_schematic->Prj(),
522 cacheFn.GetPath( wxPATH_GET_SEPARATOR ) );
523
524 cacheFile.Write( wxString( modelData ) );
525 m_rawIncludes.insert( cacheFn.GetFullPath() );
526 }
527}
std::string Generate(const std::string &aProposedName)
SIM_LIB_MGR m_libMgr
Holds libraries and models.
NAME_GENERATOR m_modelNameGenerator
Generates unique model names.
static wxString GetUserCachePath()
Gets the stock (install) 3d viewer plugins path.
Definition: paths.cpp:321
virtual PROJECT & Prj() const =0
SIM_MODEL & CreateModel(SIM_MODEL::TYPE aType, const std::vector< LIB_PIN * > &aPins)
std::string IbisDevice(const SPICE_ITEM &aItem, const PROJECT &aProject, const wxString &aCacheDir) const
virtual std::string ModelName(const SPICE_ITEM &aItem) const
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:325
#define _(s)
SIM_MODEL & model
Definition: sim_library.h:41
std::string name
Definition: sim_library.h:40
std::string modelName
std::string baseModelName

References _, SPICE_ITEM::baseModelName, SIM_LIB_MGR::CreateModel(), DisplayErrorMessage(), Format(), NAME_GENERATOR::Generate(), SCH_SYMBOL::GetRef(), PATHS::GetUserCachePath(), SPICE_GENERATOR_KIBIS::IbisDevice(), NETLIST_EXPORTER_SPICE::m_dialogParent, NETLIST_EXPORTER_SPICE::m_libMgr, NETLIST_EXPORTER_SPICE::m_modelNameGenerator, NETLIST_EXPORTER_SPICE::m_rawIncludes, NETLIST_EXPORTER_BASE::m_schematic, SIM_LIBRARY::MODEL::model, SPICE_ITEM::model, SPICE_ITEM::modelName, SPICE_GENERATOR::ModelName(), SIM_LIBRARY::MODEL::name, path, SCHEMATIC_IFACE::Prj(), and SIM_MODEL::SpiceGenerator().

Referenced by NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ readPinNetNames()

void NETLIST_EXPORTER_SPICE::readPinNetNames ( SCH_SYMBOL aSymbol,
SPICE_ITEM aItem,
int &  aNcCounter 
)
privateinherited

Definition at line 537 of file netlist_exporter_spice.cpp.

539{
540 for( const PIN_INFO& pinInfo : m_sortedSymbolPinList )
541 {
542 std::string netName = GenerateItemPinNetName( std::string( pinInfo.netName.ToUTF8() ),
543 aNcCounter );
544
545 aItem.pinNetNames.push_back( netName );
546 m_nets.insert( netName );
547 }
548}
virtual std::string GenerateItemPinNetName(const std::string &aNetName, int &aNcCounter) const
std::vector< std::string > pinNetNames

References NETLIST_EXPORTER_SPICE::GenerateItemPinNetName(), NETLIST_EXPORTER_SPICE::m_nets, NETLIST_EXPORTER_BASE::m_sortedSymbolPinList, and SPICE_ITEM::pinNetNames.

Referenced by NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ readPinNumbers()

void NETLIST_EXPORTER_SPICE::readPinNumbers ( SCH_SYMBOL aSymbol,
SPICE_ITEM aItem 
)
privateinherited

Definition at line 530 of file netlist_exporter_spice.cpp.

531{
532 for( const PIN_INFO& pin : m_sortedSymbolPinList )
533 aItem.pinNumbers.emplace_back( std::string( pin.num.ToUTF8() ) );
534}
std::vector< std::string > pinNumbers

References NETLIST_EXPORTER_BASE::m_sortedSymbolPinList, pin, and SPICE_ITEM::pinNumbers.

Referenced by NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ readRefName()

void NETLIST_EXPORTER_SPICE::readRefName ( SCH_SHEET_PATH aSheet,
SCH_SYMBOL aSymbol,
SPICE_ITEM aItem,
std::set< std::string > &  aRefNames 
)
privateinherited

Definition at line 472 of file netlist_exporter_spice.cpp.

474{
475 aItem.refName = aSymbol.GetRef( &aSheet );
476
477 if( !aRefNames.insert( aItem.refName ).second )
478 wxASSERT( wxT( "Duplicate refdes encountered; what happened to ReadyToNetlist()?" ) );
479}
std::string refName

References SCH_SYMBOL::GetRef(), and SPICE_ITEM::refName.

Referenced by NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ ReadSchematicAndLibraries()

bool NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries ( unsigned  aNetlistOptions,
REPORTER aReporter 
)
virtualinherited

Process the schematic and Spice libraries 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.

Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.

Definition at line 161 of file netlist_exporter_spice.cpp.

163{
164 wxString msg;
165 std::set<std::string> refNames; // Set of reference names to check for duplication.
166 int ncCounter = 1;
167
168 ReadDirectives( aNetlistOptions );
169
170 m_nets.clear();
171 m_items.clear();
173 m_libParts.clear();
174
175 wxFileName cacheDir;
176 cacheDir.AssignDir( PATHS::GetUserCachePath() );
177 cacheDir.AppendDir( wxT( "ibis" ) );
178
179 if( !cacheDir.DirExists() )
180 {
181 cacheDir.Mkdir( wxS_DIR_DEFAULT, wxPATH_MKDIR_FULL );
182
183 if( !cacheDir.DirExists() )
184 {
185 wxLogTrace( wxT( "IBIS_CACHE:" ),
186 wxT( "%s:%s:%d\n * failed to create ibis cache directory '%s'" ),
187 __FILE__, __FUNCTION__, __LINE__, cacheDir.GetPath() );
188
189 return false;
190 }
191 }
192
193 wxDir dir;
194 wxString dirName = cacheDir.GetFullPath();
195
196 if( !dir.Open( dirName ) )
197 return false;
198
199 wxFileName thisFile;
200 wxArrayString fileList;
201 wxString fileSpec = wxT( "*.cache" );
202
203 thisFile.SetPath( dirName ); // Set the base path to the cache folder
204
205 size_t numFilesFound = wxDir::GetAllFiles( dirName, &fileList, fileSpec );
206
207 for( size_t ii = 0; ii < numFilesFound; ii++ )
208 {
209 // Completes path to specific file so we can get its "last access" date
210 thisFile.SetFullName( fileList[ii] );
211 wxRemoveFile( thisFile.GetFullPath() );
212 }
213
214 for( SCH_SHEET_PATH& sheet : GetSheets( aNetlistOptions ) )
215 {
216 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_SYMBOL_T ) )
217 {
218 SCH_SYMBOL* symbol = findNextSymbol( item, &sheet );
219
220 if( !symbol || symbol->GetFieldText( SIM_ENABLE_FIELD ) == wxT( "0" ) )
221 continue;
222
223 CreatePinList( symbol, &sheet, true );
224
225 SPICE_ITEM spiceItem;
226
227 for( int i = 0; i < symbol->GetFieldCount(); ++i )
228 {
229 spiceItem.fields.emplace_back( VECTOR2I(), i, symbol,
230 symbol->GetFields()[ i ].GetName() );
231
232 if( i == REFERENCE_FIELD )
233 spiceItem.fields.back().SetText( symbol->GetRef( &sheet ) );
234 else
235 spiceItem.fields.back().SetText( symbol->GetFields()[i].GetShownText( 0, false ) );
236 }
237
238 wxString deviceType;
239 wxString modelType;
240 wxString modelParams;
241 wxString pinMap;
242
243 // JEY TODO: readModel() below will also do the inference, so I don't think this
244 // accomplishes anything....
245 // Infer RLC and VI models if they aren't specified
246 if( SIM_MODEL::InferSimModel( *symbol, &spiceItem.fields, true,
248 &modelType, &modelParams, &pinMap ) )
249 {
250 spiceItem.fields.emplace_back( symbol, -1, SIM_DEVICE_TYPE_FIELD );
251 spiceItem.fields.back().SetText( deviceType );
252
253 if( !modelType.IsEmpty() )
254 {
255 spiceItem.fields.emplace_back( symbol, -1, SIM_TYPE_FIELD );
256 spiceItem.fields.back().SetText( modelType );
257 }
258
259 spiceItem.fields.emplace_back( symbol, -1, SIM_PARAMS_FIELD );
260 spiceItem.fields.back().SetText( modelParams );
261
262 spiceItem.fields.emplace_back( symbol, -1, SIM_PINS_FIELD );
263 spiceItem.fields.back().SetText( pinMap );
264 }
265
266 try
267 {
268 readRefName( sheet, *symbol, spiceItem, refNames );
269 readModel( sheet, *symbol, spiceItem );
270 readPinNumbers( *symbol, spiceItem );
271 readPinNetNames( *symbol, spiceItem, ncCounter );
272
273 // TODO: transmission line handling?
274
275 m_items.push_back( std::move( spiceItem ) );
276 }
277 catch( const IO_ERROR& e )
278 {
279 msg.Printf( _( "Error reading simulation model from symbol '%s':\n%s" ),
280 symbol->GetRef( &sheet ),
281 e.Problem() );
282 aReporter.Report( msg, RPT_SEVERITY_ERROR );
283 }
284 }
285 }
286
287 return !aReporter.HasMessage();
288}
Hold an error message and may be used when throwing exceptions containing meaningful error messages.
Definition: ki_exception.h:76
virtual const wxString Problem() const
what was the problem?
Definition: exceptions.cpp:46
void CreatePinList(SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins)
Find a symbol from the DrawList and builds its pin list in m_sortedSymbolPinList.
SCH_SYMBOL * findNextSymbol(EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath)
Check if the given symbol should be processed for netlisting.
void readRefName(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, std::set< std::string > &aRefNames)
void readPinNumbers(SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem)
void readPinNetNames(SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, int &aNcCounter)
void readModel(SCH_SHEET_PATH &aSheet, SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem)
virtual bool HasMessage() const =0
Returns true if the reporter client is non-empty.
virtual REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED)=0
Report a string with a given severity.
int GetFieldCount() const
Return the number of fields in this symbol.
Definition: sch_symbol.h:486
void GetFields(std::vector< SCH_FIELD * > &aVector, bool aVisibleOnly)
Populate a std::vector with SCH_FIELDs.
Definition: sch_symbol.cpp:879
wxString GetFieldText(const wxString &aFieldName) const
Search for a field named aFieldName and returns text associated with this field.
Definition: sch_symbol.cpp:867
static bool InferSimModel(T_symbol &aSymbol, std::vector< T_field > *aFields, bool aResolve, SIM_VALUE_GRAMMAR::NOTATION aNotation, wxString *aDeviceType, wxString *aModelType, wxString *aModelParams, wxString *aPinMap)
Definition: sim_model.cpp:1098
void Clear()
Erase the record.
@ RPT_SEVERITY_ERROR
#define SIM_ENABLE_FIELD
Definition: sim_model.h:55
#define SIM_PINS_FIELD
Definition: sim_model.h:53
#define SIM_DEVICE_TYPE_FIELD
Definition: sim_model.h:51
#define SIM_TYPE_FIELD
Definition: sim_model.h:52
#define SIM_PARAMS_FIELD
Definition: sim_model.h:54
std::vector< SCH_FIELD > fields
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".
VECTOR2< int > VECTOR2I
Definition: vector2d.h:618

References _, UNIQUE_STRINGS::Clear(), NETLIST_EXPORTER_BASE::CreatePinList(), SPICE_ITEM::fields, NETLIST_EXPORTER_BASE::findNextSymbol(), SCH_SYMBOL::GetFieldCount(), SCH_SYMBOL::GetFields(), SCH_SYMBOL::GetFieldText(), SCH_SYMBOL::GetRef(), NETLIST_EXPORTER_SPICE::GetSheets(), PATHS::GetUserCachePath(), REPORTER::HasMessage(), SIM_MODEL::InferSimModel(), NETLIST_EXPORTER_SPICE::m_items, NETLIST_EXPORTER_BASE::m_libParts, NETLIST_EXPORTER_SPICE::m_nets, NETLIST_EXPORTER_BASE::m_referencesAlreadyFound, IO_ERROR::Problem(), NETLIST_EXPORTER_SPICE::ReadDirectives(), NETLIST_EXPORTER_SPICE::readModel(), NETLIST_EXPORTER_SPICE::readPinNetNames(), NETLIST_EXPORTER_SPICE::readPinNumbers(), NETLIST_EXPORTER_SPICE::readRefName(), REFERENCE_FIELD, REPORTER::Report(), RPT_SEVERITY_ERROR, SCH_SYMBOL_T, SIM_DEVICE_TYPE_FIELD, SIM_ENABLE_FIELD, SIM_PARAMS_FIELD, SIM_PINS_FIELD, SIM_TYPE_FIELD, and SIM_VALUE_GRAMMAR::SPICE.

Referenced by NETLIST_EXPORTER_SPICE::DoWriteNetlist(), and NETLIST_EXPORTER_SPICE_MODEL::ReadSchematicAndLibraries().

◆ SetSimCommandOverride()

void NGSPICE_CIRCUIT_MODEL::SetSimCommandOverride ( const wxString &  aCmd)
inline

Override the simulation command directive.

Definition at line 78 of file ngspice_circuit_model.h.

79 {
80 if( aCmd != m_simCommand )
81 {
83 m_simCommand = aCmd;
84 }
85 }

References GetSheetSimCommand(), m_lastSheetSimCommand, and m_simCommand.

◆ SetSimOptions()

void NGSPICE_CIRCUIT_MODEL::SetSimOptions ( int  aOptions)
inline

Definition at line 67 of file ngspice_circuit_model.h.

67{ m_options = aOptions; }

References m_options.

◆ VectorToSignal()

SIM_PLOT_TYPE NGSPICE_CIRCUIT_MODEL::VectorToSignal ( const std::string &  aVector,
wxString &  aSignal 
) const

Return name of Spice dataset for a specific plot.

Parameters
aVectoris name of the vector produced by ngspice
[out]aSignalis output in form: V(R1), Ib(Q2), I(L8)
Returns
[SPT_VOLTAGE, SPT_CURRENT]. Otherwise SPT_UNKNOWN if vector is of different, unsupported type.

Definition at line 33 of file ngspice_circuit_model.cpp.

35{
36 using namespace std;
37
38 // See ngspice manual chapt. 31.1 "Accessing internal device parameters"
39 wxRegEx internalDevParameter( "^@(\\w*[\\.\\w+]*)\\[(\\w*)\\]$", wxRE_ADVANCED );
40 wxString vector( aVector );
41
42 if( !internalDevParameter.Matches( vector ) )
43 {
44 // any text is a node name, which returns voltage
45 aSignal = wxT( "V(" ) + aVector + wxT( ")" );
46 return SPT_VOLTAGE;
47 }
48 else
49 {
50 wxString paramType = internalDevParameter.GetMatch( vector, 2 );
51
52 if( paramType.Lower()[0] == 'i' )
53 {
54 // this is a branch current
55 paramType[0] = 'I';
56 aSignal = paramType + wxT( "(" );
57 aSignal += internalDevParameter.GetMatch( vector, 1 ).Upper() + wxT( ")" );
58 return SPT_CURRENT;
59 }
60 else
61 {
62 return SPT_UNKNOWN;
63 }
64 }
65}
Definition: bitmap.cpp:64
@ SPT_UNKNOWN
Definition: sim_types.h:60
@ SPT_VOLTAGE
Definition: sim_types.h:49
@ SPT_CURRENT
Definition: sim_types.h:50

References SPT_CURRENT, SPT_UNKNOWN, and SPT_VOLTAGE.

◆ WriteDirectives()

void NGSPICE_CIRCUIT_MODEL::WriteDirectives ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions 
) const
overrideprotectedvirtual

Reimplemented from NETLIST_EXPORTER_SPICE.

Definition at line 148 of file ngspice_circuit_model.cpp.

150{
151 if( GetSimCommandOverride().IsEmpty() )
152 aNetlistOptions |= OPTION_SIM_COMMAND;
153
154 NETLIST_EXPORTER_SPICE::WriteDirectives( aFormatter, aNetlistOptions );
155
156 if( !GetSimCommandOverride().IsEmpty() )
157 aFormatter.Print( 0, "%s\n", TO_UTF8( GetSimCommandOverride() ) );
158}
wxString GetSimCommandOverride() const
Return the simulation command directive if stored separately (not as a sheet directive).
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:433
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96

References GetSimCommandOverride(), NETLIST_EXPORTER_SPICE::OPTION_SIM_COMMAND, OUTPUTFORMATTER::Print(), TO_UTF8, and NETLIST_EXPORTER_SPICE::WriteDirectives().

◆ WriteHead()

void NETLIST_EXPORTER_SPICE::WriteHead ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions 
)
virtualinherited

Write the netlist head (title and so on).

Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.

Definition at line 149 of file netlist_exporter_spice.cpp.

150{
151 aFormatter.Print( 0, "KiCad schematic\n" );
152}

References OUTPUTFORMATTER::Print().

Referenced by NETLIST_EXPORTER_SPICE::DoWriteNetlist().

◆ writeInclude()

void NETLIST_EXPORTER_SPICE::writeInclude ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions,
const wxString &  aPath 
)
privateinherited

Definition at line 551 of file netlist_exporter_spice.cpp.

553{
554 // First, expand env vars, if any.
555 wxString expandedPath = ExpandEnvVarSubstitutions( aPath, &m_schematic->Prj() );
556
557 // Path may have been authored by someone on a Windows box; convert it to UNIX format
558 expandedPath.Replace( '\\', '/' );
559
560 wxString fullPath;
561
562 if( aNetlistOptions & OPTION_ADJUST_INCLUDE_PATHS )
563 {
564 // Look for the library in known search locations.
565 fullPath = ResolveFile( expandedPath, &Pgm().GetLocalEnvVariables(), &m_schematic->Prj() );
566
567 if( fullPath.IsEmpty() )
568 {
570 wxString::Format( _( "Could not find library file '%s'" ),
571 expandedPath ) );
572 fullPath = expandedPath;
573 }
574 else if( wxFileName::GetPathSeparator() == '\\' )
575 {
576 // Convert it to UNIX format (again) if ResolveFile() returned a Windows style path
577 fullPath.Replace( '\\', '/' );
578 }
579 }
580 else
581 {
582 fullPath = expandedPath;
583 }
584
585 aFormatter.Print( 0, ".include \"%s\"\n", TO_UTF8( fullPath ) );
586}
const wxString ExpandEnvVarSubstitutions(const wxString &aString, const PROJECT *aProject)
Replace any environment variable & text variable references with their values.
Definition: common.cpp:299
wxString ResolveFile(const wxString &aFileName, const ENV_VAR_MAP *aEnvVars, const PROJECT *aProject)
Search the default paths trying to find one with the requested file.
Definition: env_paths.cpp:164
KIWAY Kiway & Pgm(), KFCTL_STANDALONE
The global Program "get" accessor.
Definition: single_top.cpp:111

References _, DisplayErrorMessage(), ExpandEnvVarSubstitutions(), Format(), NETLIST_EXPORTER_SPICE::m_dialogParent, NETLIST_EXPORTER_BASE::m_schematic, NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS, Pgm(), OUTPUTFORMATTER::Print(), SCHEMATIC_IFACE::Prj(), ResolveFile(), and TO_UTF8.

Referenced by NETLIST_EXPORTER_SPICE::writeIncludes().

◆ writeIncludes()

void NETLIST_EXPORTER_SPICE::writeIncludes ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions 
)
privateinherited

Definition at line 589 of file netlist_exporter_spice.cpp.

590{
591 for( auto& [path, library] : m_libMgr.GetLibraries() )
592 {
593 if( dynamic_cast<const SIM_LIBRARY_SPICE*>( &library.get() ) )
594 writeInclude( aFormatter, aNetlistOptions, path );
595 }
596
597 for( const wxString& path : m_rawIncludes )
598 writeInclude( aFormatter, aNetlistOptions, path );
599}
void writeInclude(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, const wxString &aPath)
std::map< wxString, std::reference_wrapper< const SIM_LIBRARY > > GetLibraries() const

References SIM_LIB_MGR::GetLibraries(), library, NETLIST_EXPORTER_SPICE::m_libMgr, NETLIST_EXPORTER_SPICE::m_rawIncludes, path, and NETLIST_EXPORTER_SPICE::writeInclude().

Referenced by NETLIST_EXPORTER_SPICE::DoWriteNetlist().

◆ writeItems()

void NETLIST_EXPORTER_SPICE::writeItems ( OUTPUTFORMATTER aFormatter)
privateinherited

Definition at line 614 of file netlist_exporter_spice.cpp.

615{
616 for( const SPICE_ITEM& item : m_items )
617 {
618 if( !item.model->IsEnabled() )
619 continue;
620
621 aFormatter.Print( 0, "%s", item.model->SpiceGenerator().ItemLine( item ).c_str() );
622 }
623}

References NETLIST_EXPORTER_SPICE::m_items, and OUTPUTFORMATTER::Print().

Referenced by NETLIST_EXPORTER_SPICE::DoWriteNetlist().

◆ writeModels()

void NETLIST_EXPORTER_SPICE::writeModels ( OUTPUTFORMATTER aFormatter)
privateinherited

Definition at line 602 of file netlist_exporter_spice.cpp.

603{
604 for( const SPICE_ITEM& item : m_items )
605 {
606 if( !item.model->IsEnabled() )
607 continue;
608
609 aFormatter.Print( 0, "%s", item.model->SpiceGenerator().ModelLine( item ).c_str() );
610 }
611}

References NETLIST_EXPORTER_SPICE::m_items, and OUTPUTFORMATTER::Print().

Referenced by NETLIST_EXPORTER_SPICE::DoWriteNetlist().

◆ WriteNetlist()

bool NETLIST_EXPORTER_SPICE::WriteNetlist ( const wxString &  aOutFileName,
unsigned  aNetlistOptions,
REPORTER aReporter 
)
overridevirtualinherited

Write to specified output file.

Reimplemented from NETLIST_EXPORTER_BASE.

Definition at line 112 of file netlist_exporter_spice.cpp.

114{
115 m_libMgr.SetReporter( &aReporter );
116 FILE_OUTPUTFORMATTER formatter( aOutFileName, wxT( "wt" ), '\'' );
117 return DoWriteNetlist( formatter, aNetlistOptions, aReporter );
118}
Used for text file output.
Definition: richio.h:457
void SetReporter(REPORTER *aReporter)
Definition: sim_lib_mgr.h:46

References NETLIST_EXPORTER_SPICE::DoWriteNetlist(), NETLIST_EXPORTER_SPICE::m_libMgr, and SIM_LIB_MGR::SetReporter().

◆ WriteTail()

void NETLIST_EXPORTER_SPICE::WriteTail ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions 
)
virtualinherited

Write the tail (.end).

Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.

Definition at line 155 of file netlist_exporter_spice.cpp.

156{
157 aFormatter.Print( 0, ".end\n" );
158}

References OUTPUTFORMATTER::Print().

Referenced by NETLIST_EXPORTER_SPICE::DoWriteNetlist().

Member Data Documentation

◆ m_dialogParent

wxWindow* NETLIST_EXPORTER_SPICE::m_dialogParent
privateinherited

◆ m_directives

std::vector<wxString> NETLIST_EXPORTER_SPICE::m_directives
privateinherited

Spice directives found in the schematic sheet.

Definition at line 162 of file netlist_exporter_spice.h.

Referenced by NETLIST_EXPORTER_SPICE::GetDirectives(), NETLIST_EXPORTER_SPICE::ReadDirectives(), and NETLIST_EXPORTER_SPICE::WriteDirectives().

◆ m_items

◆ m_lastSheetSimCommand

wxString NGSPICE_CIRCUIT_MODEL::m_lastSheetSimCommand
private

Definition at line 151 of file ngspice_circuit_model.h.

Referenced by GetLastSheetSimCommand(), and SetSimCommandOverride().

◆ m_libMgr

SIM_LIB_MGR NETLIST_EXPORTER_SPICE::m_libMgr
privateinherited

◆ m_libParts

std::set<LIB_SYMBOL*, LIB_SYMBOL_LESS_THAN> NETLIST_EXPORTER_BASE::m_libParts
protectedinherited

◆ m_modelNameGenerator

NAME_GENERATOR NETLIST_EXPORTER_SPICE::m_modelNameGenerator
privateinherited

Generates unique model names.

Generates unique net names (only unique for NC nets for now)

Definition at line 158 of file netlist_exporter_spice.h.

Referenced by NETLIST_EXPORTER_SPICE::readModel().

◆ m_netNameGenerator

NAME_GENERATOR NETLIST_EXPORTER_SPICE::m_netNameGenerator
privateinherited

Definition at line 161 of file netlist_exporter_spice.h.

◆ m_nets

std::set<std::string> NETLIST_EXPORTER_SPICE::m_nets
privateinherited

Items representing schematic symbols in Spice world.

Definition at line 164 of file netlist_exporter_spice.h.

Referenced by NETLIST_EXPORTER_SPICE::GetNets(), NETLIST_EXPORTER_SPICE::readPinNetNames(), and NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ m_options

int NGSPICE_CIRCUIT_MODEL::m_options
private

Definition at line 153 of file ngspice_circuit_model.h.

Referenced by GetNetlist(), GetSimOptions(), and SetSimOptions().

◆ m_rawIncludes

std::set<wxString> NETLIST_EXPORTER_SPICE::m_rawIncludes
privateinherited

◆ m_referencesAlreadyFound

UNIQUE_STRINGS NETLIST_EXPORTER_BASE::m_referencesAlreadyFound
protectedinherited

Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.

Definition at line 203 of file netlist_exporter_base.h.

Referenced by NETLIST_EXPORTER_BASE::findNextSymbol(), NETLIST_EXPORTER_XML::makeSymbols(), NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().

◆ m_schematic

◆ m_simCommand

wxString NGSPICE_CIRCUIT_MODEL::m_simCommand
private

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

Value of schematic sheet simulation command when override was last updated

Definition at line 148 of file ngspice_circuit_model.h.

Referenced by GetSimCommand(), GetSimCommandOverride(), and SetSimCommandOverride().

◆ m_sortedSymbolPinList

std::vector<PIN_INFO> NETLIST_EXPORTER_BASE::m_sortedSymbolPinList
protectedinherited

Used to temporarily store and filter the list of pins of a schematic symbol when generating schematic symbol data in netlist (comp section).

No ownership of members. TODO(snh): Descope this object

Definition at line 199 of file netlist_exporter_base.h.

Referenced by NETLIST_EXPORTER_BASE::CreatePinList(), NETLIST_EXPORTER_BASE::eraseDuplicatePins(), NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol(), NETLIST_EXPORTER_SPICE::readPinNetNames(), NETLIST_EXPORTER_SPICE::readPinNumbers(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().


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