62 SIM_MODEL::TYPE* aType,
bool aFirstPass )
64 *aType = SIM_MODEL::TYPE::NONE;
66 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
67 std::unique_ptr<tao::pegtl::parse_tree::node> root;
77 catch(
const tao::pegtl::parse_error& e )
83 for(
const auto& node : root->children )
92 std::string
modelName = node->children.at( 0 )->string();
93 std::string akoName = node->children.at( 1 )->string();
98 THROW_IO_ERROR( wxString::Format(
_(
"Could not find parent model '%s' for \"A Kind Of\" model '%s'" ),
103 *aType = sourceModel->
GetType();
110 *aType = SIM_MODEL::TYPE::RAWSPICE;
115 std::string paramName;
116 std::string typeString;
120 for(
const auto& subnode : node->children )
128 typeString = subnode->string();
131 if( type != SIM_MODEL::TYPE::RAWSPICE )
139 paramName = subnode->string();
143 wxASSERT( paramName !=
"" );
145 if( paramName ==
"level" )
146 level = subnode->string();
147 else if( paramName ==
"version" )
148 version = subnode->string();
152 wxFAIL_MSG(
"Unhandled parse tree subnode" );
171 *aType = SIM_MODEL::TYPE::SUBCKT;
176 wxFAIL_MSG(
"Unhandled parse tree node" );
181 wxFAIL_MSG(
"Could not derive type from SPICE code" );
187 const std::string& aSpiceCode )
192 tao::pegtl::string_input<> in( aSpiceCode,
"Spice_Code" );
193 std::unique_ptr<tao::pegtl::parse_tree::node> root;
203 catch( tao::pegtl::parse_error& e )
208 for(
const auto& node : root->children )
212 std::string
modelName = node->children.at( 0 )->string();
213 std::string akoName = node->children.at( 1 )->string();
219 THROW_IO_ERROR( wxString::Format(
_(
"Could not find parent model '%s' for \"A Kind Of\" model '%s'" ),
224 for(
int i = 0; i < static_cast<int>( sourceModel->
GetParamCount() ); ++i )
227 std::string paramName;
229 for(
const auto& subnode : node->children )
241 paramName = subnode->string();
245 wxASSERT( paramName !=
"" );
247 m_model.SetParamFromSpiceCode( paramName, subnode->string() );
251 wxFAIL_MSG(
"Unhandled parse tree subnode" );
258 std::string paramName;
260 for(
const auto& subnode : node->children )
272 paramName = subnode->string();
276 wxASSERT( paramName !=
"" );
278 m_model.SetParamFromSpiceCode( paramName, subnode->string() );
282 wxFAIL_MSG(
"Unhandled parse tree subnode" );
288 wxFAIL_MSG(
"Unhandled parse tree node" );
292 m_model.m_spiceCode = aSpiceCode;
297 const std::string& aLevel,
298 const std::string& aVersion,
299 bool aSkipDefaultLevel )
301 wxString input_level = wxString( aLevel ).BeforeFirst(
'.' );
302 wxString input_type( aTypeString );
306 input_type.UpperCase();
308 if( input_type.StartsWith( wxS(
"VDMOS" ) ) )
311 pchan = input_type.Contains( wxS(
"PCHAN" ) );
314 for( SIM_MODEL::TYPE candidate : SIM_MODEL::TYPE_ITERATOR() )
318 if( candidate_type.IsEmpty() )
321 if( candidate_type.StartsWith( wxS(
"VDMOS" ) ) && vdmos )
323 if( vdmos && pchan && candidate_type.EndsWith( wxS(
"PCHAN" ) ) )
325 else if( vdmos && !pchan && candidate_type.EndsWith( wxS(
"NCHAN" ) ) )
328 else if( input_type.StartsWith( candidate_type ) )
336 if( aSkipDefaultLevel )
346 return SIM_MODEL::TYPE::RAWSPICE;