25#include <wx/tokenzr.h>
32 wxString& aSignal )
const
34 static wxString BRANCH( wxS(
"#branch" ) );
35 static wxString
POWER( wxS(
":power" ) );
38 static wxRegEx internalDevParameter( wxS(
"^@(\\w*[\\.\\w+]*)\\[(\\w*)\\]$" ), wxRE_ADVANCED );
40 wxString vector( aVector );
42 if( !internalDevParameter.Matches( vector ) )
44 if( vector.EndsWith( BRANCH ) )
46 aSignal = wxT(
"I(" ) + vector.Left( vector.Length() - BRANCH.Length() ) + wxT(
")" );
49 else if( vector.EndsWith(
POWER ) )
51 aSignal = wxT(
"P(" ) + vector.Left( vector.Length() -
POWER.Length() ) + wxT(
")" );
56 aSignal = wxT(
"V(" ) + vector + wxT(
")" );
62 wxString paramType = internalDevParameter.GetMatch( vector, 2 );
64 if( paramType.Lower()[0] ==
'i' )
68 aSignal = paramType + wxT(
"(" );
69 aSignal += internalDevParameter.GetMatch( vector, 1 ).Upper() + wxT(
")" );
89 simCmd += wxString::Format( wxT(
"%s\r\n" ), directive );
98 wxString cmd = aCmd.Lower().Trim();
100 if( cmd == wxT(
".op" ) )
return ST_OP;
101 else if( cmd.StartsWith( wxT(
".ac" ) ) )
return ST_AC;
102 else if( cmd.StartsWith( wxT(
".dc" ) ) )
return ST_DC;
103 else if( cmd.StartsWith( wxT(
".tran" ) ) )
return ST_TRAN;
104 else if( cmd.StartsWith( wxT(
".disto" ) ) )
return ST_DISTO;
105 else if( cmd.StartsWith( wxT(
".noise" ) ) )
return ST_NOISE;
106 else if( cmd.StartsWith( wxT(
".pz" ) ) )
return ST_PZ;
107 else if( cmd.StartsWith( wxT(
".sens" ) ) )
return ST_SENS;
108 else if( cmd.StartsWith( wxT(
".sp" ) ) )
return ST_SP;
109 else if( cmd.StartsWith( wxT(
".tf" ) ) )
return ST_TF;
111 else if( cmd.StartsWith( wxT(
"fft" ) ) || cmd.Contains( wxT(
"\nfft" ) ) )
121 if( !aCmd.Lower().StartsWith(
".dc" ) )
124 wxString cmd = aCmd.Mid( 3 );
125 wxStringTokenizer tokens( cmd,
" \t", wxTOKEN_STRTOK );
127 aSource1->
m_source = tokens.GetNextToken();
132 if( tokens.HasMoreTokens() )
134 aSource2->
m_source = tokens.GetNextToken();
145 wxString* input, wxString* inputRef, wxString*
output,
148 if( !aCmd.Lower().StartsWith( wxS(
".pz" ) ) )
151 *transferFunction =
"vol";
155 wxStringTokenizer tokens( aCmd.Mid( 3 ),
" \t", wxTOKEN_STRTOK );
157 if( tokens.HasMoreTokens() )
158 *input = tokens.GetNextToken();
160 if( tokens.HasMoreTokens() )
161 *inputRef = tokens.GetNextToken();
163 if( tokens.HasMoreTokens() )
164 *
output = tokens.GetNextToken();
166 if( tokens.HasMoreTokens() )
167 *outputRef = tokens.GetNextToken();
169 if( tokens.HasMoreTokens() )
170 *transferFunction = tokens.GetNextToken();
172 if( tokens.HasMoreTokens() )
174 wxString token = tokens.GetNextToken().Lower();
176 if( token == wxS(
"pol" ) )
178 else if( token == wxS(
"zer" ) )
186 wxString* aRef, wxString* aSource, wxString* aScale,
190 if( !aCmd.Lower().StartsWith( wxS(
".noise" ) ) )
193 wxString cmd = aCmd.Mid( 6 );
197 if( !cmd.Lower().StartsWith( wxS(
"v(" ) ) )
202 wxString function = cmd.Before(
')' );
203 wxString params = cmd.After(
')' );
205 wxStringTokenizer func_tokens( function,
" ,\t", wxTOKEN_STRTOK );
207 *aOutput = func_tokens.GetNextToken();
208 *aRef = func_tokens.GetNextToken();
210 wxStringTokenizer tokens( params,
" \t", wxTOKEN_STRTOK );
211 wxString token = tokens.GetNextToken();
213 if( !token.IsEmpty() )
216 token = tokens.GetNextToken();
219 if( token.Lower() ==
"dec" || token.Lower() ==
"oct" || token.Lower() ==
"lin" )
222 token = tokens.GetNextToken();
225 if( !token.IsEmpty() )
228 token = tokens.GetNextToken();
231 if( !token.IsEmpty() )
234 token = tokens.GetNextToken();
237 if( !token.IsEmpty() )
240 token = tokens.GetNextToken();
243 if( !token.IsEmpty() )
253 if( aSimCommand.IsEmpty() )
258 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.