diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index cf007e07ee..f32d6fa8ea 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -484,20 +484,25 @@ std::unique_ptr SIM_MODEL::Create( const SIM_MODEL* aBaseModel, const std::vector& aPins, REPORTER* aReporter ) { - TYPE type = aBaseModel ? aBaseModel->GetType() : TYPE::NONE; std::unique_ptr model; - // A null base model means the model wasn't found in the library, so create a fallback - - if( !aBaseModel || dynamic_cast( aBaseModel ) ) - model = std::make_unique( type ); - else if( dynamic_cast< const SIM_MODEL_RAW_SPICE*>( aBaseModel ) ) - model = std::make_unique(); - else - model = Create( type ); - if( aBaseModel ) + { + TYPE type = aBaseModel->GetType(); + + if( dynamic_cast( aBaseModel ) ) + model = std::make_unique( type ); + else if( dynamic_cast< const SIM_MODEL_RAW_SPICE*>( aBaseModel ) ) + model = std::make_unique(); + else + model = Create( type ); + model->SetBaseModel( *aBaseModel ); + } + else // No base model means the model wasn't found in the library, so create a fallback + { + model = std::make_unique( TYPE::NONE ); + } try { @@ -518,25 +523,30 @@ std::unique_ptr SIM_MODEL::Create( const SIM_MODEL* aBaseModel, const std::vector& aFields, REPORTER* aReporter ) { - TYPE type = ReadTypeFromFields( aFields, aReporter ); - - // If the model has a specified type, it takes priority over the type of its base class. - if( type == TYPE::NONE && aBaseModel ) - type = aBaseModel->GetType(); - std::unique_ptr model; - // A null base model means the model wasn't found in the library, so create a fallback - - if( !aBaseModel || dynamic_cast( aBaseModel ) ) - model = std::make_unique( type ); - else if( dynamic_cast< const SIM_MODEL_RAW_SPICE*>( aBaseModel ) ) - model = std::make_unique(); - else - model = Create( type ); - if( aBaseModel ) + { + TYPE type = aBaseModel->GetType(); + + // No REPORTER here; we're just checking to see if we have an override + if( ReadTypeFromFields( aFields, nullptr ) != TYPE::NONE ) + type = ReadTypeFromFields( aFields, nullptr ); + + if( dynamic_cast( aBaseModel ) ) + model = std::make_unique( type ); + else if( dynamic_cast< const SIM_MODEL_RAW_SPICE*>( aBaseModel ) ) + model = std::make_unique(); + else + model = Create( type ); + model->SetBaseModel( *aBaseModel ); + } + else // No base model means the model wasn't found in the library, so create a fallback + { + TYPE type = ReadTypeFromFields( aFields, aReporter ); + model = std::make_unique( type ); + } try {