29#include <wx/tokenzr.h>
34 wxString& aSignal )
const
36 static wxString BRANCH( wxS(
"#branch" ) );
37 static wxString
POWER( wxS(
":power" ) );
40 static wxRegEx internalDevParameter( wxS(
"^@(\\w*[\\.\\w+]*)\\[(\\w*)\\]$" ), wxRE_ADVANCED );
42 wxString vector( aVector );
44 if( !internalDevParameter.Matches( vector ) )
46 if( vector.EndsWith( BRANCH ) )
48 aSignal = wxT(
"I(" ) + vector.Left( vector.Length() - BRANCH.Length() ) + wxT(
")" );
51 else if( vector.EndsWith(
POWER ) )
53 aSignal = wxT(
"P(" ) + vector.Left( vector.Length() -
POWER.Length() ) + wxT(
")" );
58 aSignal = wxT(
"V(" ) + vector + wxT(
")" );
64 wxString paramType = internalDevParameter.GetMatch( vector, 2 );
66 if( paramType.Lower()[0] ==
'i' )
70 aSignal = paramType + wxT(
"(" );
71 aSignal += internalDevParameter.GetMatch( vector, 1 ).Upper() + wxT(
")" );
91 simCmd += wxString::Format( wxT(
"%s\r\n" ), directive );
100 wxString cmd = aCmd.Lower().Trim();
102 if( cmd == wxT(
".op" ) )
return ST_OP;
103 else if( cmd.StartsWith( wxT(
".ac" ) ) )
return ST_AC;
104 else if( cmd.StartsWith( wxT(
".dc" ) ) )
return ST_DC;
105 else if( cmd.StartsWith( wxT(
".tran" ) ) )
return ST_TRAN;
106 else if( cmd.StartsWith( wxT(
".disto" ) ) )
return ST_DISTO;
107 else if( cmd.StartsWith( wxT(
".noise" ) ) )
return ST_NOISE;
108 else if( cmd.StartsWith( wxT(
".pz" ) ) )
return ST_PZ;
109 else if( cmd.StartsWith( wxT(
".sens" ) ) )
return ST_SENS;
110 else if( cmd.StartsWith( wxT(
".sp" ) ) )
return ST_SP;
111 else if( cmd.StartsWith( wxT(
".tf" ) ) )
return ST_TF;
113 else if( cmd.StartsWith( wxT(
"fft" ) ) || cmd.Contains( wxT(
"\nfft" ) ) )
123 if( !aCmd.Lower().StartsWith(
".dc" ) )
126 wxString cmd = aCmd.Mid( 3 );
127 wxStringTokenizer tokens( cmd, wxS(
" \t" ), wxTOKEN_STRTOK );
129 aSource1->
m_source = tokens.GetNextToken();
134 aSource2->
m_source = tokens.GetNextToken();
144 wxString* input, wxString* inputRef, wxString* output,
147 if( !aCmd.Lower().StartsWith( wxS(
".pz" ) ) )
150 *transferFunction =
"vol";
154 wxStringTokenizer tokens( aCmd.Mid( 3 ), wxS(
" \t" ), wxTOKEN_STRTOK );
156 if( tokens.HasMoreTokens() )
157 *input = tokens.GetNextToken();
159 if( tokens.HasMoreTokens() )
160 *inputRef = tokens.GetNextToken();
162 if( tokens.HasMoreTokens() )
163 *output = tokens.GetNextToken();
165 if( tokens.HasMoreTokens() )
166 *outputRef = tokens.GetNextToken();
168 if( tokens.HasMoreTokens() )
169 *transferFunction = tokens.GetNextToken();
171 if( tokens.HasMoreTokens() )
173 wxString token = tokens.GetNextToken().Lower();
175 if( token == wxS(
"pol" ) )
177 else if( token == wxS(
"zer" ) )
185 wxString* aRef, wxString* aSource, wxString* aScale,
189 if( !aCmd.Lower().StartsWith( wxS(
".noise" ) ) )
192 wxString cmd = aCmd.Mid( 6 );
196 if( !cmd.Lower().StartsWith( wxS(
"v(" ) ) )
201 wxString function = cmd.Before(
')' );
202 wxString params = cmd.After(
')' );
204 wxStringTokenizer func_tokens( function, wxS(
" ,\t" ), wxTOKEN_STRTOK );
206 *aOutput = func_tokens.GetNextToken();
207 *aRef = func_tokens.GetNextToken();
209 wxStringTokenizer tokens( params, wxS(
" \t" ), wxTOKEN_STRTOK );
210 wxString token = tokens.GetNextToken();
212 if( !token.IsEmpty() )
215 token = tokens.GetNextToken();
218 if( token.Lower() ==
"dec" || token.Lower() ==
"oct" || token.Lower() ==
"lin" )
221 token = tokens.GetNextToken();
224 if( !token.IsEmpty() )
227 token = tokens.GetNextToken();
230 if( !token.IsEmpty() )
233 token = tokens.GetNextToken();
236 if( !token.IsEmpty() )
239 token = tokens.GetNextToken();
242 if( !token.IsEmpty() )
252 if( aSimCommand.IsEmpty() )
257 if( !aSimCommand.IsEmpty() )
void ReadDirectives(unsigned aNetlistOptions)
const std::vector< wxString > & GetDirectives()
virtual void WriteDirectives(const wxString &aSimCommand, unsigned aSimOptions, OUTPUTFORMATTER &candidate) const
bool ParsePZCommand(const wxString &aCmd, wxString *transferFunction, wxString *input, wxString *inputRef, wxString *output, wxString *outputRef, SPICE_PZ_ANALYSES *analyses)
static bool IsSimCommand(const wxString &aCmd)
Determine if a directive is a simulation command.
bool ParseDCCommand(const wxString &aCmd, SPICE_DC_PARAMS *aSource1, SPICE_DC_PARAMS *aSource2)
Parse a two-source .dc command directive into its symbols.
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Return simulation type basing on a simulation command directive.
bool ParseNoiseCommand(const wxString &aCmd, wxString *aOutput, wxString *aRef, wxString *aSource, wxString *aScale, SPICE_VALUE *aPts, SPICE_VALUE *aFStart, SPICE_VALUE *aFStop, bool *aSaveAll)
void WriteDirectives(const wxString &aSimCommand, unsigned aSimOptions, OUTPUTFORMATTER &aFormatter) const override
wxString GetSchTextSimCommand()
Return simulation command directives placed in schematic sheets (if any).
SIM_TRACE_TYPE VectorToSignal(const std::string &aVector, wxString &aSignal) const
Return name of Spice dataset for a specific trace.
Helper class to recognize Spice formatted values.
SIM_TYPE
< Possible simulation types
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.