KiCad PCB EDA Suite
NETLIST_EXPORTER_SPICE_MODEL Class Reference

#include <netlist_exporter_spice_model.h>

Inheritance diagram for NETLIST_EXPORTER_SPICE_MODEL:
NETLIST_EXPORTER_SPICE NETLIST_EXPORTER_BASE

Classes

struct  PORT_INFO
 

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

 NETLIST_EXPORTER_SPICE_MODEL (SCHEMATIC_IFACE *aSchematic)
 
void WriteHead (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions) override
 Write the netlist head (title and so on). More...
 
void WriteTail (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions) override
 Write the tail (.end). More...
 
bool ReadSchematicAndLibraries (unsigned aNetlistOptions, REPORTER &aReporter) override
 Process the schematic and Spice libraries to create net mapping and a list of SPICE_ITEMs. 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...
 
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 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

std::string GenerateItemPinNetName (const std::string &aNetName, int &aNcCounter) const override
 
void ReadDirectives (unsigned aNetlistOptions)
 
virtual void WriteDirectives (OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions) 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 readPorts (unsigned aNetlistOptions)
 
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

std::map< std::string, PORT_INFOm_ports
 
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

Definition at line 30 of file netlist_exporter_spice_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

◆ NETLIST_EXPORTER_SPICE_MODEL()

NETLIST_EXPORTER_SPICE_MODEL::NETLIST_EXPORTER_SPICE_MODEL ( SCHEMATIC_IFACE aSchematic)
inline

Definition at line 33 of file netlist_exporter_spice_model.h.

34 : NETLIST_EXPORTER_SPICE( aSchematic )
35 {
36 }
NETLIST_EXPORTER_SPICE(SCHEMATIC_IFACE *aSchematic, wxWindow *aDialogParent=nullptr)

Member Function Documentation

◆ 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 NGSPICE_CIRCUIT_MODEL::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:478
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_MODEL::GenerateItemPinNetName ( const std::string &  aNetName,
int &  aNcCounter 
) const
overrideprotectedvirtual

Reimplemented from NETLIST_EXPORTER_SPICE.

Definition at line 77 of file netlist_exporter_spice_model.cpp.

79{
80 std::string netName = aNetName;
81
82 if( m_ports.count( netName ) )
83 netName = m_ports.at( netName ).name;
84
85 return NETLIST_EXPORTER_SPICE::GenerateItemPinNetName( netName, aNcCounter );
86}
std::map< std::string, PORT_INFO > m_ports
virtual std::string GenerateItemPinNetName(const std::string &aNetName, int &aNcCounter) const

References NETLIST_EXPORTER_SPICE::GenerateItemPinNetName(), and m_ports.

◆ 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 NGSPICE_CIRCUIT_MODEL::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().

◆ 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(), readPorts(), and NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

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

◆ 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 NGSPICE_CIRCUIT_MODEL::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)
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
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}
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().

◆ readPorts()

void NETLIST_EXPORTER_SPICE_MODEL::readPorts ( unsigned  aNetlistOptions)
private

Definition at line 89 of file netlist_exporter_spice_model.cpp.

90{
91 for( const SCH_SHEET_PATH& sheet : GetSheets( aNetlistOptions ) )
92 {
93 for( SCH_ITEM* item : sheet.LastScreen()->Items().OfType( SCH_HIER_LABEL_T ) )
94 {
95 SCH_LABEL_BASE* label = static_cast<SCH_LABEL_BASE*>( item );
96
97 if( SCH_CONNECTION* conn = label->Connection( &sheet ) )
98 {
99 m_ports.insert( { std::string( conn->Name().ToUTF8() ),
100 PORT_INFO{ std::string( label->GetText().ToUTF8() ),
101 label->GetShape()
102 }
103 } );
104 }
105 }
106 }
107}
virtual const wxString & GetText() const
Return the string associated with the text object.
Definition: eda_text.h:87
SCH_CONNECTION * Connection(const SCH_SHEET_PATH *aSheet=nullptr) const
Retrieve the connection associated with this object in the given sheet.
Definition: sch_item.cpp:146
LABEL_FLAG_SHAPE GetShape() const override
Definition: sch_label.h:73
@ SCH_HIER_LABEL_T
Definition: typeinfo.h:153

References SCH_ITEM::Connection(), SCH_LABEL_BASE::GetShape(), NETLIST_EXPORTER_SPICE::GetSheets(), EDA_TEXT::GetText(), m_ports, and SCH_HIER_LABEL_T.

Referenced by 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_MODEL::ReadSchematicAndLibraries ( unsigned  aNetlistOptions,
REPORTER aReporter 
)
overridevirtual

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 from NETLIST_EXPORTER_SPICE.

Definition at line 68 of file netlist_exporter_spice_model.cpp.

70{
71 readPorts( aNetlistOptions );
72
73 return NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries( aNetlistOptions, aReporter );
74}
void readPorts(unsigned aNetlistOptions)

References readPorts(), and NETLIST_EXPORTER_SPICE::ReadSchematicAndLibraries().

◆ WriteDirectives()

void NETLIST_EXPORTER_SPICE::WriteDirectives ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions 
) const
protectedvirtualinherited

Reimplemented in NGSPICE_CIRCUIT_MODEL.

Definition at line 626 of file netlist_exporter_spice.cpp.

628{
629 if( aNetlistOptions & OPTION_SAVE_ALL_VOLTAGES )
630 aFormatter.Print( 0, ".save all\n" );
631
632 if( aNetlistOptions & OPTION_SAVE_ALL_CURRENTS )
633 aFormatter.Print( 0, ".probe alli\n" );
634
635 for( const wxString& directive : m_directives )
636 {
637 bool simCommand = false;
638
639 if( directive.StartsWith( "." ) )
640 {
641 wxString candidate = directive.Upper();
642
643 simCommand = ( candidate.StartsWith( wxT( ".AC" ) )
644 || candidate.StartsWith( wxT( ".DC" ) )
645 || candidate.StartsWith( wxT( ".TRAN" ) )
646 || candidate.StartsWith( wxT( ".OP" ) )
647 || candidate.StartsWith( wxT( ".DISTO" ) )
648 || candidate.StartsWith( wxT( ".NOISE" ) )
649 || candidate.StartsWith( wxT( ".PZ" ) )
650 || candidate.StartsWith( wxT( ".SENS" ) )
651 || candidate.StartsWith( wxT( ".TF" ) ) );
652 }
653
654 if( !simCommand || ( aNetlistOptions & OPTION_SIM_COMMAND ) )
655 aFormatter.Print( 0, "%s\n", UTF8( directive ).c_str() );
656 }
657}
int PRINTF_FUNC Print(int nestLevel, const char *fmt,...)
Format and write text to the output stream.
Definition: richio.cpp:433
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:71
const char * c_str() const
Definition: utf8.h:102

References UTF8::c_str(), NETLIST_EXPORTER_SPICE::m_directives, NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS, NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES, NETLIST_EXPORTER_SPICE::OPTION_SIM_COMMAND, and OUTPUTFORMATTER::Print().

Referenced by NETLIST_EXPORTER_SPICE::DoWriteNetlist(), and NGSPICE_CIRCUIT_MODEL::WriteDirectives().

◆ WriteHead()

void NETLIST_EXPORTER_SPICE_MODEL::WriteHead ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions 
)
overridevirtual

Write the netlist head (title and so on).

Reimplemented from NETLIST_EXPORTER_SPICE.

Definition at line 30 of file netlist_exporter_spice_model.cpp.

32{
33 aFormatter.Print( 0, "*\n" );
34 aFormatter.Print( 0, "\n" );
35 aFormatter.Print( 0, ".subckt %s\n", TO_UTF8( m_schematic->Prj().GetProjectName() ) );
36
37 for( auto const& [key, port] : m_ports )
38 {
39 std::string portDir;
40
41 switch( port.dir )
42 {
43 case L_INPUT: portDir = "input"; break;
44 case L_OUTPUT: portDir = "output"; break;
45 case L_BIDI: portDir = "inout"; break;
46 case L_TRISTATE: portDir = "tristate"; break;
47 case L_UNSPECIFIED: portDir = "passive"; break;
48
49 default:
50 wxFAIL_MSG( "Invalid port direction" );
51 break;
52 }
53
54 aFormatter.Print( 0, "+ %s ; %s\n", port.name.c_str(), portDir.c_str() );
55 }
56
57 aFormatter.Print( 0, "\n\n" );
58}
virtual const wxString GetProjectName() const
Return the short name of the project.
Definition: project.cpp:132
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
@ L_BIDI
Definition: sch_text.h:99
@ L_TRISTATE
Definition: sch_text.h:100
@ L_UNSPECIFIED
Definition: sch_text.h:101
@ L_OUTPUT
Definition: sch_text.h:98
@ L_INPUT
Definition: sch_text.h:97

References PROJECT::GetProjectName(), L_BIDI, L_INPUT, L_OUTPUT, L_TRISTATE, L_UNSPECIFIED, m_ports, NETLIST_EXPORTER_BASE::m_schematic, OUTPUTFORMATTER::Print(), SCHEMATIC_IFACE::Prj(), and TO_UTF8.

◆ 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
bool DoWriteNetlist(OUTPUTFORMATTER &aFormatter, unsigned aNetlistOptions, REPORTER &aReporter)
Write the netlist in aFormatter.
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_MODEL::WriteTail ( OUTPUTFORMATTER aFormatter,
unsigned  aNetlistOptions 
)
overridevirtual

Write the tail (.end).

Reimplemented from NETLIST_EXPORTER_SPICE.

Definition at line 61 of file netlist_exporter_spice_model.cpp.

63{
64 aFormatter.Print( 0, "\n.ends\n" );
65}

References OUTPUTFORMATTER::Print().

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_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_ports

std::map<std::string, PORT_INFO> NETLIST_EXPORTER_SPICE_MODEL::m_ports
private

Definition at line 54 of file netlist_exporter_spice_model.h.

Referenced by GenerateItemPinNetName(), readPorts(), and WriteHead().

◆ 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_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: