61 SIM_MODEL::TYPE* aType,
bool aFirstPass )
63 *aType = SIM_MODEL::TYPE::NONE;
65 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
66 std::unique_ptr<tao::pegtl::parse_tree::node> root;
76 catch(
const tao::pegtl::parse_error& e )
82 for(
const auto& node : root->children )
91 std::string
modelName = node->children.at( 0 )->string();
92 std::string akoName = node->children.at( 1 )->string();
97 THROW_IO_ERROR( wxString::Format(
_(
"Could not find parent model '%s' for \"A Kind Of\" model '%s'" ),
102 *aType = sourceModel->
GetType();
107 std::string paramName;
108 std::string typeString;
112 for(
const auto& subnode : node->children )
120 typeString = subnode->string();
123 if( type != SIM_MODEL::TYPE::RAWSPICE )
131 paramName = subnode->string();
135 wxASSERT( paramName !=
"" );
137 if( paramName ==
"level" )
138 level = subnode->string();
139 else if( paramName ==
"version" )
140 version = subnode->string();
144 wxFAIL_MSG(
"Unhandled parse tree subnode" );
163 *aType = SIM_MODEL::TYPE::SUBCKT;
168 wxFAIL_MSG(
"Unhandled parse tree node" );
173 wxFAIL_MSG(
"Could not derive type from SPICE code" );
179 const std::string& aSpiceCode )
184 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
185 std::unique_ptr<tao::pegtl::parse_tree::node> root;
195 catch( tao::pegtl::parse_error& e )
200 for(
const auto& node : root->children )
204 std::string
modelName = node->children.at( 0 )->string();
205 std::string akoName = node->children.at( 1 )->string();
211 THROW_IO_ERROR( wxString::Format(
_(
"Could not find parent model '%s' for \"A Kind Of\" model '%s'" ),
216 for(
int i = 0; i < static_cast<int>( sourceModel->
GetParamCount() ); ++i )
219 std::string paramName;
221 for(
const auto& subnode : node->children )
233 paramName = subnode->string();
237 wxASSERT( paramName !=
"" );
239 m_model.SetParamFromSpiceCode( paramName, subnode->string() );
243 wxFAIL_MSG(
"Unhandled parse tree subnode" );
250 std::string paramName;
252 for(
const auto& subnode : node->children )
264 paramName = subnode->string();
268 wxASSERT( paramName !=
"" );
270 m_model.SetParamFromSpiceCode( paramName, subnode->string() );
274 wxFAIL_MSG(
"Unhandled parse tree subnode" );
280 wxFAIL_MSG(
"Unhandled parse tree node" );
284 m_model.m_spiceCode = aSpiceCode;
289 const std::string& aLevel,
290 const std::string& aVersion,
291 bool aSkipDefaultLevel )
293 wxString input_level = wxString( aLevel ).BeforeFirst(
'.' );
294 wxString input_type( aTypeString );
298 input_type.UpperCase();
300 if( input_type.StartsWith( wxS(
"VDMOS" ) ) )
303 pchan = input_type.Contains( wxS(
"PCHAN" ) );
306 for( SIM_MODEL::TYPE candidate : SIM_MODEL::TYPE_ITERATOR() )
310 if( candidate_type.IsEmpty() )
313 if( candidate_type.StartsWith( wxS(
"VDMOS" ) ) && vdmos )
315 if( vdmos && pchan && candidate_type.EndsWith( wxS(
"PCHAN" ) ) )
317 else if( vdmos && !pchan && candidate_type.EndsWith( wxS(
"NCHAN" ) ) )
320 else if( input_type.StartsWith( candidate_type ) )
328 if( aSkipDefaultLevel )
338 return SIM_MODEL::TYPE::RAWSPICE;