Clear model name when switching to internal model.

Also fixes a bug to ensure that a modelLine gets written when using
an internal model.

Fixes https://gitlab.com/kicad/code/kicad/issues/14083

(cherry picked from commit 2e5bf0210a)
This commit is contained in:
Jeff Young 2023-02-25 15:21:08 +00:00
parent e82c21e944
commit d32e13daee
9 changed files with 14 additions and 13 deletions

View File

@ -1051,7 +1051,7 @@ void SIM_MODEL::doWriteFields( std::vector<T>& aFields ) const
}
bool SIM_MODEL::requiresSpiceModelLine() const
bool SIM_MODEL::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
{
for( const PARAM& param : GetParams() )
{

View File

@ -40,6 +40,7 @@
#include <enum_vector.h>
class SIM_LIBRARY;
class SPICE_ITEM;
class SPICE_GENERATOR;
class SIM_MODEL_SERIALIZER;
class PROJECT;
@ -524,7 +525,7 @@ private:
template <typename T>
void doWriteFields( std::vector<T>& aFields ) const;
virtual bool requiresSpiceModelLine() const;
virtual bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const;
protected:
std::vector<PARAM> m_params;

View File

@ -89,7 +89,7 @@ public:
bool m_enableDiff;
private:
bool requiresSpiceModelLine() const override { return true; }
bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override { return true; }
static std::vector<PARAM::INFO> makeParamInfos( TYPE aType );
static std::vector<PARAM::INFO> makeDcWaveformParamInfos();

View File

@ -215,8 +215,12 @@ bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName )
}
bool SIM_MODEL_NGSPICE::requiresSpiceModelLine() const
bool SIM_MODEL_NGSPICE::requiresSpiceModelLine( const SPICE_ITEM& aItem ) const
{
// Model must be written if there's no base model or the base model is an internal model
if( !m_baseModel || aItem.baseModelName == "" )
return true;
for( int ii = 0; ii < GetParamCount(); ++ii )
{
const PARAM& param = m_params[ii];
@ -229,10 +233,6 @@ bool SIM_MODEL_NGSPICE::requiresSpiceModelLine() const
if ( param.value == "" )
continue;
// Any non-empty parameter must be written if there's no base model
if( !m_baseModel )
return true;
const SIM_MODEL_NGSPICE* baseModel = dynamic_cast<const SIM_MODEL_NGSPICE*>( m_baseModel );
std::string baseValue = baseModel->m_params[ii].value;

View File

@ -109,7 +109,7 @@ protected:
int doFindParam( const std::string& aParamName ) const override;
private:
bool requiresSpiceModelLine() const override;
bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override;
bool canSilentlyIgnoreParam( const std::string& aParamName );

View File

@ -79,7 +79,7 @@ public:
private:
static std::vector<PARAM::INFO> makeParamInfos();
bool requiresSpiceModelLine() const override { return false; }
bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override { return false; }
private:
std::string m_spiceCode;

View File

@ -60,7 +60,7 @@ public:
std::string GetSpiceCode() const;
private:
bool requiresSpiceModelLine() const override { return true; }
bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override { return true; }
std::vector<std::unique_ptr<PARAM::INFO>> m_paramInfos;
};

View File

@ -51,7 +51,7 @@ public:
}
private:
bool requiresSpiceModelLine() const override { return true; }
bool requiresSpiceModelLine( const SPICE_ITEM& aItem ) const override { return true; }
static const std::vector<PARAM::INFO> makeSwVParamInfos();
static const std::vector<PARAM::INFO> makeSwIParamInfos();

View File

@ -44,7 +44,7 @@ std::string SPICE_GENERATOR::ModelName( const SPICE_ITEM& aItem ) const
std::string SPICE_GENERATOR::ModelLine( const SPICE_ITEM& aItem ) const
{
if( !m_model.requiresSpiceModelLine() )
if( !m_model.requiresSpiceModelLine( aItem ) )
return "";
std::string result;