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 if( tokens.HasMoreTokens() )
136 aSource2->
m_source = tokens.GetNextToken();
147 wxString* input, wxString* inputRef, wxString* output,
150 if( !aCmd.Lower().StartsWith( wxS(
".pz" ) ) )
153 *transferFunction =
"vol";
157 wxStringTokenizer tokens( aCmd.Mid( 3 ), wxS(
" \t" ), wxTOKEN_STRTOK );
159 if( tokens.HasMoreTokens() )
160 *input = tokens.GetNextToken();
162 if( tokens.HasMoreTokens() )
163 *inputRef = tokens.GetNextToken();
165 if( tokens.HasMoreTokens() )
166 *output = tokens.GetNextToken();
168 if( tokens.HasMoreTokens() )
169 *outputRef = tokens.GetNextToken();
171 if( tokens.HasMoreTokens() )
172 *transferFunction = tokens.GetNextToken();
174 if( tokens.HasMoreTokens() )
176 wxString token = tokens.GetNextToken().Lower();
178 if( token == wxS(
"pol" ) )
180 else if( token == wxS(
"zer" ) )
188 wxString* aRef, wxString* aSource, wxString* aScale,
192 if( !aCmd.Lower().StartsWith( wxS(
".noise" ) ) )
195 wxString cmd = aCmd.Mid( 6 );
199 if( !cmd.Lower().StartsWith( wxS(
"v(" ) ) )
204 wxString function = cmd.Before(
')' );
205 wxString params = cmd.After(
')' );
207 wxStringTokenizer func_tokens( function, wxS(
" ,\t" ), wxTOKEN_STRTOK );
209 *aOutput = func_tokens.GetNextToken();
210 *aRef = func_tokens.GetNextToken();
212 wxStringTokenizer tokens( params, wxS(
" \t" ), wxTOKEN_STRTOK );
213 wxString token = tokens.GetNextToken();
215 if( !token.IsEmpty() )
218 token = tokens.GetNextToken();
221 if( token.Lower() ==
"dec" || token.Lower() ==
"oct" || token.Lower() ==
"lin" )
224 token = tokens.GetNextToken();
227 if( !token.IsEmpty() )
230 token = tokens.GetNextToken();
233 if( !token.IsEmpty() )
236 token = tokens.GetNextToken();
239 if( !token.IsEmpty() )
242 token = tokens.GetNextToken();
245 if( !token.IsEmpty() )
255 if( aSimCommand.IsEmpty() )
260 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.