31 #include <wx/tokenzr.h> 34 const wxString& aName,
SIM_PLOT_TYPE aType,
const wxString& aParam )
const 58 wxString param = aParam.Lower();
60 if( device.length() > 0 && device[0] ==
'x' )
62 return wxT(
"current probe of .subckt not yet implemented" );
68 param.IsEmpty() ? wxT(
"i" ) : param );
77 const std::string& aVector, wxString& aSignal )
const 82 wxRegEx internalDevParameter(
"^@(\\w*[\\.\\w+]*)\\[(\\w*)\\]$", wxRE_ADVANCED );
83 wxString vector( aVector );
85 if( !internalDevParameter.Matches( vector ) )
88 aSignal = wxT(
"V(" ) + aVector + wxT(
")" );
93 wxString paramType = internalDevParameter.GetMatch( vector, 2 );
95 if( paramType.Lower()[0] ==
'i' )
99 aSignal = paramType + wxT(
"(" );
100 aSignal += internalDevParameter.GetMatch( vector, 1 ).Upper() + wxT(
")" );
113 static const std::vector<wxString> passive = { wxT(
"I" ) };
114 static const std::vector<wxString> diode = { wxT(
"Id" ) };
115 static const std::vector<wxString> bjt = { wxT(
"Ib" ), wxT(
"Ic" ), wxT(
"Ie" ) };
116 static const std::vector<wxString> mos = { wxT(
"Ig" ), wxT(
"Id" ), wxT(
"Is" ) };
117 static const std::vector<wxString>
empty;
172 const std::vector<std::pair<wxString, SIM_TYPE>> simCmds = {
173 { wxT(
"^.ac\\M.*" ),
ST_AC },
174 { wxT(
"^.dc\\M.*" ),
ST_DC },
176 { wxT(
"^.op\\M.*" ),
ST_OP },
178 { wxT(
"^.noise\\M.*" ),
ST_NOISE },
184 for(
const auto& c : simCmds )
186 simCmd.Compile( c.first, wxRE_ADVANCED | wxRE_NOSUB | wxRE_ICASE );
188 if( simCmd.Matches( aCmd ) )
199 if( !aCmd.Lower().StartsWith( wxT(
".dc" ) ) )
202 wxString cmd = aCmd.Mid( 3 ).Trim().Trim(
false );
204 wxStringTokenizer tokens( cmd );
206 size_t num = tokens.CountTokens();
208 if( num != 4 && num != 8 )
211 aSource1->
m_source = tokens.GetNextToken();
218 aSource2->
m_source = tokens.GetNextToken();
235 for(
const auto& current :
238 if( !item.m_enabled )
242 aFormatter->
Print( 0,
".save %s\n",
254 if( netname == wxT(
"V(0)" ) || netname == wxT(
"V(GND)" ) )
257 aFormatter->
Print( 0,
".save %s\n",
TO_UTF8( netname ) );
wxString m_simCommand
< Custom simulation command (has priority over the schematic sheet simulation commands)
wxString ComponentToVector(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam=wxEmptyString) const
Return name of Spice dataset for a specific plot.
wxString GetUsedSimCommand()
Return the command directive that is in use (either from the sheet or from m_simCommand.
const std::vector< wxString > GetDirectives() const
Return a vector of Spice directives found in the schematics.
SIM_PLOT_TYPE VectorToSignal(const std::string &aVector, wxString &aSignal) const
Return name of Spice dataset for a specific plot.
static bool IsSimCommand(const wxString &aCmd)
Determine if a directive is a simulation command.
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Return simulation type basing on a simulation command directive.
This file contains miscellaneous commonly used macros and functions.
const std::map< wxString, int > & GetNetIndexMap() const
Return a map of circuit nodes to net names.
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
void writeDirectives(OUTPUTFORMATTER *aFormatter, unsigned aCtl) const override
Save the Spice directives.
static const std::vector< wxString > & GetCurrents(SPICE_PRIMITIVE aPrimitive)
Return a list of currents that can be probed in a Spice primitive.
wxString GetSheetSimCommand()
Return simulation command directives placed in schematic sheets (if any).
< Helper class to handle Spice way of expressing values (e.g. 10.5 Meg) Helper class to recognize Spi...
const std::list< SPICE_ITEM > & GetSpiceItems() const
Return list of items representing schematic components in the Spice world.
SIM_TYPE
< Possible simulation types
virtual void writeDirectives(OUTPUTFORMATTER *aFormatter, unsigned aCtl) const
Save the Spice directives.
void UpdateDirectives(unsigned aCtl)
Update the vector of Spice directives placed in the schematics.
wxString GetSpiceDevice(const wxString &aSymbol) const
Return name of Spice device corresponding to a schematic symbol.
static void ReplaceForbiddenChars(wxString &aNetName)
Replace illegal spice net name characters with an underscore.
wxString UnescapeString(const wxString &aSource)
bool ParseDCCommand(const wxString &aCmd, SPICE_DC_PARAMS *aSource1, SPICE_DC_PARAMS *aSource2)
Parse a two-source .dc command directive into its symbols.
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
static bool empty(const wxTextEntryBase *aCtrl)
SIM_TYPE GetSimType()
Return simulation type basing on the simulation command directives.