KiCad PCB EDA Suite
|
#include <netlist_exporter_spice.h>
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_SAVE_ALL_DISSIPATIONS = 0x0100 , OPTION_CUR_SHEET_AS_ROOT = 0x0200 , OPTION_SIM_COMMAND = 0x0400 , OPTION_DEFAULT_FLAGS } |
Public Member Functions | |
NETLIST_EXPORTER_SPICE (SCHEMATIC_IFACE *aSchematic, wxWindow *aDialogParent=nullptr) | |
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_ITEM * | FindItem (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 | |
void | ReadDirectives (unsigned aNetlistOptions) |
virtual void | WriteDirectives (OUTPUTFORMATTER &candidate, unsigned aNetlistOptions) const |
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... | |
std::vector< PIN_INFO > | CreatePinList (SCH_SYMBOL *aSymbol, SCH_SHEET_PATH *aSheetPath, bool aKeepUnconnectedPins) |
Find a symbol from the DrawList and builds its pin list. More... | |
SCH_SYMBOL * | findNextSymbol (EDA_ITEM *aItem, SCH_SHEET_PATH *aSheetPath) |
Check if the given symbol should be processed for netlisting. More... | |
void | eraseDuplicatePins (std::vector< PIN_INFO > &pins) |
Erase duplicate pins. More... | |
void | findAllUnitsOfSymbol (SCH_SYMBOL *aSchSymbol, SCH_SHEET_PATH *aSheetPath, std::vector< PIN_INFO > &aPins, bool aKeepUnconnectedPins) |
Find all units for symbols with multiple symbols per package. More... | |
Protected Attributes | |
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_THAN > | m_libParts |
unique library symbols used. LIB_SYMBOL items are sorted by names More... | |
SCHEMATIC_IFACE * | m_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, const std::vector< PIN_INFO > &aPins) |
void | readPinNetNames (SCH_SYMBOL &aSymbol, SPICE_ITEM &aItem, const std::vector< PIN_INFO > &aPins, 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 | |
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_ITEM > | m_items |
wxWindow * | m_dialogParent |
Definition at line 49 of file netlist_exporter_spice.h.
Definition at line 52 of file netlist_exporter_spice.h.
NETLIST_EXPORTER_SPICE::NETLIST_EXPORTER_SPICE | ( | SCHEMATIC_IFACE * | aSchematic, |
wxWindow * | aDialogParent = nullptr |
||
) |
Definition at line 95 of file netlist_exporter_spice.cpp.
|
static |
Remove formatting wrappers and replace illegal spice net name characters with underscores.
Definition at line 246 of file netlist_exporter_spice.cpp.
References MARKUP::MARKUP_PARSER::Parse().
Referenced by GenerateItemPinNetName(), SCHEMATIC::GetOperatingPoint(), and SCH_EDITOR_CONTROL::SimProbe().
|
protectedinherited |
Find a symbol from the DrawList and builds its pin list.
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.
References SCHEMATIC_IFACE::ConnectionGraph(), NETLIST_EXPORTER_BASE::eraseDuplicatePins(), NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol(), CONNECTION_GRAPH::FindSubgraphByName(), CONNECTION_SUBGRAPH::GetItems(), SCH_SYMBOL::GetLibSymbolRef(), CONNECTION_SUBGRAPH::GetNoConnect(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), SCH_SYMBOL::IsPower(), NETLIST_EXPORTER_BASE::m_libParts, NETLIST_EXPORTER_BASE::m_schematic, and pin.
Referenced by ReadSchematicAndLibraries(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().
bool NETLIST_EXPORTER_SPICE::DoWriteNetlist | ( | OUTPUTFORMATTER & | aFormatter, |
unsigned | aNetlistOptions, | ||
REPORTER & | aReporter | ||
) |
Write the netlist in aFormatter.
Definition at line 113 of file netlist_exporter_spice.cpp.
References dummy, m_items, m_rawIncludes, ReadSchematicAndLibraries(), WriteDirectives(), WriteHead(), writeIncludes(), writeItems(), writeModels(), and WriteTail().
Referenced by NGSPICE_CIRCUIT_MODEL::GetNetlist(), and WriteNetlist().
|
protectedinherited |
Erase duplicate pins.
(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 188 of file netlist_exporter_base.cpp.
Referenced by NETLIST_EXPORTER_BASE::CreatePinList().
|
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 sorted pin list. if aKeepUnconnectedPins = false, unconnected pins will be removed from list but usually we need all pins in netlists.
Definition at line 221 of file netlist_exporter_base.cpp.
References SCHEMATIC_IFACE::ConnectionGraph(), CONNECTION_GRAPH::FindSubgraphByName(), CONNECTION_SUBGRAPH::GetItems(), CONNECTION_SUBGRAPH::GetNoConnect(), SCH_SYMBOL::GetPins(), SCH_SYMBOL::GetRef(), SCHEMATIC_IFACE::GetSheets(), NETLIST_EXPORTER_BASE::m_schematic, pin, and SCH_SYMBOL_T.
Referenced by NETLIST_EXPORTER_BASE::CreatePinList().
const SPICE_ITEM * NETLIST_EXPORTER_SPICE::FindItem | ( | const std::string & | aRefName | ) | const |
Find and return the item corresponding to aRefName.
Definition at line 307 of file netlist_exporter_spice.cpp.
References GetItems().
Referenced by SIMULATOR_FRAME::AddTuner(), SIMULATOR_FRAME::applyTuners(), GetItemName(), and TUNER_SLIDER::TUNER_SLIDER().
|
protectedinherited |
Check if the given symbol should be processed for netlisting.
Prevent processing multi-unit symbols more than once, etc.
aItem | is a symbol to check |
aSheetPath | is the sheet to check the symbol for |
Definition at line 73 of file netlist_exporter_base.cpp.
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(), ReadSchematicAndLibraries(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().
|
protectedvirtual |
Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.
Definition at line 647 of file netlist_exporter_spice.cpp.
References ConvertToSpiceMarkup(), and UnescapeString().
Referenced by NETLIST_EXPORTER_SPICE_MODEL::GenerateItemPinNetName(), and readPinNetNames().
|
inline |
Definition at line 131 of file netlist_exporter_spice.h.
References m_directives.
Referenced by NGSPICE_CIRCUIT_MODEL::GetSchTextSimCommand().
std::string NETLIST_EXPORTER_SPICE::GetItemName | ( | const std::string & | aRefName | ) | const |
Return name of Spice device corresponding to a schematic symbol.
aRefName | is the component reference. |
Definition at line 296 of file netlist_exporter_spice.cpp.
References FindItem(), SPICE_GENERATOR::ItemName(), SPICE_ITEM::model, and SIM_MODEL::SpiceGenerator().
|
inline |
Return the list of items representing schematic symbols in the Spice world.
Definition at line 124 of file netlist_exporter_spice.h.
References m_items.
Referenced by FindItem().
|
inline |
Return the list of nets.
Definition at line 108 of file netlist_exporter_spice.h.
References m_nets.
|
protected |
Return the paths of exported sheets (either all or the current one).
Definition at line 662 of file netlist_exporter_spice.cpp.
References SCHEMATIC_IFACE::CurrentSheet(), SCHEMATIC_IFACE::GetSheets(), SCH_SHEET_PATH::Last(), NETLIST_EXPORTER_BASE::m_schematic, and OPTION_CUR_SHEET_AS_ROOT.
Referenced by ReadDirectives(), NETLIST_EXPORTER_SPICE_MODEL::readPorts(), and ReadSchematicAndLibraries().
|
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.
aFormatString | holds:
|
aNetlistFile | is the name of the input file for the external program, that is a intermediate netlist file in xml format. |
aFinalFile | is the name of the output file that the user expects. |
aProjectDirectory | is used for P replacement, it should omit the trailing '/'. |
Supported formatting sequences and their meaning:
Definition at line 37 of file netlist_exporter_base.cpp.
Referenced by SCH_EDIT_FRAME::WriteNetListFile().
|
protected |
Definition at line 324 of file netlist_exporter_spice.cpp.
References GetSheets(), SCH_TEXTBOX::GetShownText(), m_directives, SCH_TEXT_T, SCH_TEXTBOX_T, and text.
Referenced by NGSPICE_CIRCUIT_MODEL::GetSchTextSimCommand(), and ReadSchematicAndLibraries().
|
private |
Definition at line 448 of file netlist_exporter_spice.cpp.
References _, SPICE_ITEM::baseModelName, SIM_LIB_MGR::CreateModel(), DisplayErrorMessage(), NAME_GENERATOR::Generate(), SCH_SYMBOL::GetRef(), PATHS::GetUserCachePath(), SPICE_GENERATOR_KIBIS::IbisDevice(), m_dialogParent, m_libMgr, m_modelNameGenerator, 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 ReadSchematicAndLibraries().
|
private |
Definition at line 503 of file netlist_exporter_spice.cpp.
References GenerateItemPinNetName(), m_nets, and SPICE_ITEM::pinNetNames.
Referenced by ReadSchematicAndLibraries().
|
private |
Definition at line 495 of file netlist_exporter_spice.cpp.
References pin, and SPICE_ITEM::pinNumbers.
Referenced by ReadSchematicAndLibraries().
|
private |
Definition at line 438 of file netlist_exporter_spice.cpp.
References SCH_SYMBOL::GetRef(), and SPICE_ITEM::refName.
Referenced by ReadSchematicAndLibraries().
|
virtual |
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.
Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.
Definition at line 152 of file netlist_exporter_spice.cpp.
References UNIQUE_STRINGS::Clear(), NETLIST_EXPORTER_BASE::CreatePinList(), SPICE_ITEM::fields, NETLIST_EXPORTER_BASE::findNextSymbol(), SCH_SYMBOL::GetExcludeFromSim(), SCH_SYMBOL::GetFields(), SCH_SYMBOL::GetRef(), GetSheets(), PATHS::GetUserCachePath(), REPORTER::HasMessage(), m_items, m_libMgr, NETLIST_EXPORTER_BASE::m_libParts, m_nets, NETLIST_EXPORTER_BASE::m_referencesAlreadyFound, ReadDirectives(), readModel(), readPinNetNames(), readPinNumbers(), readRefName(), REFERENCE_FIELD, SCH_SYMBOL_T, and SIM_LIB_MGR::SetReporter().
Referenced by DoWriteNetlist(), and NETLIST_EXPORTER_SPICE_MODEL::ReadSchematicAndLibraries().
|
protectedvirtual |
Reimplemented in NGSPICE_CIRCUIT_MODEL.
Definition at line 591 of file netlist_exporter_spice.cpp.
References UTF8::c_str(), m_directives, m_items, OPTION_SAVE_ALL_CURRENTS, OPTION_SAVE_ALL_DISSIPATIONS, OPTION_SAVE_ALL_VOLTAGES, OPTION_SIM_COMMAND, and OUTPUTFORMATTER::Print().
Referenced by DoWriteNetlist(), and NGSPICE_CIRCUIT_MODEL::WriteDirectives().
|
virtual |
Write the netlist head (title and so on).
Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.
Definition at line 140 of file netlist_exporter_spice.cpp.
References OUTPUTFORMATTER::Print().
Referenced by DoWriteNetlist().
|
private |
Definition at line 516 of file netlist_exporter_spice.cpp.
References _, DisplayErrorMessage(), ExpandEnvVarSubstitutions(), m_dialogParent, NETLIST_EXPORTER_BASE::m_schematic, OPTION_ADJUST_INCLUDE_PATHS, Pgm(), OUTPUTFORMATTER::Print(), SCHEMATIC_IFACE::Prj(), ResolveFile(), and TO_UTF8.
Referenced by writeIncludes().
|
private |
Definition at line 554 of file netlist_exporter_spice.cpp.
References SIM_LIB_MGR::GetLibraries(), library, m_libMgr, m_rawIncludes, path, and writeInclude().
Referenced by DoWriteNetlist().
|
private |
Definition at line 579 of file netlist_exporter_spice.cpp.
References m_items, and OUTPUTFORMATTER::Print().
Referenced by DoWriteNetlist().
|
private |
Definition at line 567 of file netlist_exporter_spice.cpp.
References m_items, and OUTPUTFORMATTER::Print().
Referenced by DoWriteNetlist().
|
overridevirtual |
Write to specified output file.
Reimplemented from NETLIST_EXPORTER_BASE.
Definition at line 104 of file netlist_exporter_spice.cpp.
References DoWriteNetlist(), m_libMgr, and SIM_LIB_MGR::SetReporter().
|
virtual |
Write the tail (.end).
Reimplemented in NETLIST_EXPORTER_SPICE_MODEL.
Definition at line 146 of file netlist_exporter_spice.cpp.
References OUTPUTFORMATTER::Print().
Referenced by DoWriteNetlist().
|
private |
Definition at line 173 of file netlist_exporter_spice.h.
Referenced by readModel(), and writeInclude().
|
private |
Spice directives found in the schematic sheet.
Definition at line 166 of file netlist_exporter_spice.h.
Referenced by GetDirectives(), ReadDirectives(), and WriteDirectives().
|
private |
Definition at line 171 of file netlist_exporter_spice.h.
Referenced by DoWriteNetlist(), GetItems(), ReadSchematicAndLibraries(), WriteDirectives(), writeItems(), and writeModels().
|
private |
Holds libraries and models.
Definition at line 161 of file netlist_exporter_spice.h.
Referenced by readModel(), ReadSchematicAndLibraries(), writeIncludes(), and WriteNetlist().
|
protectedinherited |
unique library symbols used. LIB_SYMBOL items are sorted by names
Definition at line 200 of file netlist_exporter_base.h.
Referenced by NETLIST_EXPORTER_BASE::CreatePinList(), NETLIST_EXPORTER_BASE::findNextSymbol(), NETLIST_EXPORTER_XML::makeLibParts(), NETLIST_EXPORTER_XML::makeSymbols(), and ReadSchematicAndLibraries().
|
private |
Generates unique model names.
Generates unique net names (only unique for NC nets for now)
Definition at line 162 of file netlist_exporter_spice.h.
Referenced by readModel().
|
private |
Definition at line 165 of file netlist_exporter_spice.h.
|
private |
Items representing schematic symbols in Spice world.
Definition at line 168 of file netlist_exporter_spice.h.
Referenced by GetNets(), readPinNetNames(), and ReadSchematicAndLibraries().
|
private |
include directives found in symbols
Definition at line 167 of file netlist_exporter_spice.h.
Referenced by DoWriteNetlist(), readModel(), and writeIncludes().
|
protectedinherited |
Used for "multiple symbols per package" symbols to avoid processing a lib symbol more than once.
Definition at line 197 of file netlist_exporter_base.h.
Referenced by NETLIST_EXPORTER_BASE::findNextSymbol(), NETLIST_EXPORTER_XML::makeSymbols(), ReadSchematicAndLibraries(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().
|
protectedinherited |
The schematic we're generating a netlist for.
Definition at line 203 of file netlist_exporter_base.h.
Referenced by NETLIST_EXPORTER_XML::addSymbolFields(), NETLIST_EXPORTER_BASE::CreatePinList(), NETLIST_EXPORTER_BASE::findAllUnitsOfSymbol(), GetSheets(), NETLIST_EXPORTER_XML::makeDesignHeader(), NETLIST_EXPORTER_XML::makeLibraries(), NETLIST_EXPORTER_XML::makeListOfNets(), NETLIST_EXPORTER_XML::makeSymbols(), readModel(), NETLIST_EXPORTER_SPICE_MODEL::WriteHead(), writeInclude(), NETLIST_EXPORTER_CADSTAR::writeListOfNets(), NETLIST_EXPORTER_CADSTAR::WriteNetlist(), and NETLIST_EXPORTER_ORCADPCB2::WriteNetlist().