A fall-back model for FOO should supply FOO's pin names.

Fixes https://gitlab.com/kicad/code/kicad/issues/13589
This commit is contained in:
Jeff Young 2023-01-19 12:14:29 +00:00
parent 47ae8bdb86
commit 959e20f52c
12 changed files with 35 additions and 26 deletions

View File

@ -1003,12 +1003,12 @@ void SIM_MODEL::createPins( const std::vector<LIB_PIN*>& aSymbolPins )
{
// Default pin sequence: model pins are the same as symbol pins.
// Excess model pins are set as Not Connected.
// Note that intentionally nothing is added if `getPinNames()` returns an empty vector.
// Note that intentionally nothing is added if `GetPinNames()` returns an empty vector.
// SIM_MODEL pins must be ordered by symbol pin numbers -- this is assumed by the code that
// accesses them.
std::vector<std::string> pinNames = getPinNames();
std::vector<std::string> pinNames = GetPinNames();
for( unsigned modelPinIndex = 0; modelPinIndex < pinNames.size(); ++modelPinIndex )
{

View File

@ -475,6 +475,8 @@ public:
m_baseModel = &aBaseModel;
}
virtual std::vector<std::string> GetPinNames() const { return {}; }
int GetPinCount() const { return static_cast<int>( m_pins.size() ); }
const PIN& GetPin( unsigned aIndex ) const { return m_pins.at( aIndex ); }
@ -553,8 +555,6 @@ private:
virtual bool requiresSpiceModelLine() const;
virtual std::vector<std::string> getPinNames() const { return {}; }
protected:
std::vector<PARAM> m_params;
std::vector<PIN> m_pins;

View File

@ -45,9 +45,10 @@ class SIM_MODEL_BEHAVIORAL : public SIM_MODEL
public:
SIM_MODEL_BEHAVIORAL( TYPE aType );
std::vector<std::string> GetPinNames() const override { return { "+", "-" }; }
private:
bool parseValueField( const std::string& aValueField );
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
static PARAM::INFO makeParams( std::string aName, std::string aDescription, std::string aUnit );
};

View File

@ -49,9 +49,9 @@ public:
const PARAM* GetTunerParam() const override { return &GetParam( 0 ); }
bool HasPrimaryValue() const override { return true; }
private:
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
std::vector<std::string> GetPinNames() const override { return { "+", "-" }; }
private:
static PARAM::INFO makeParamInfo( std::string aName, std::string aDescription, std::string aUnit );
};

View File

@ -217,7 +217,7 @@ bool SIM_MODEL_NGSPICE::canSilentlyIgnoreParam( const std::string& aParamName )
}
std::vector<std::string> SIM_MODEL_NGSPICE::getPinNames() const
std::vector<std::string> SIM_MODEL_NGSPICE::GetPinNames() const
{
return ModelInfo( getModelType() ).pinNames;
}

View File

@ -49,6 +49,8 @@ public:
void SetParamFromSpiceCode( const std::string& aParamName, const std::string& aValue,
SIM_VALUE_GRAMMAR::NOTATION aNotation ) override;
std::vector<std::string> GetPinNames() const override;
// Protected because it's accessed by QA tests.
protected:
DEFINE_ENUM_CLASS_WITH_ITERATOR( MODEL_TYPE,
@ -111,8 +113,6 @@ private:
bool canSilentlyIgnoreParam( const std::string& aParamName );
std::vector<std::string> getPinNames() const override;
MODEL_TYPE getModelType() const;
bool getIsOtherVariant();
};

View File

@ -48,9 +48,9 @@ public:
const PARAM* GetTunerParam() const override { return FindParam( "pos" ); }
bool HasPrimaryValue() const override { return true; }
private:
std::vector<std::string> getPinNames() const override { return { "+", "wiper", "-" }; }
std::vector<std::string> GetPinNames() const override { return { "+", "wiper", "-" }; }
private:
static const std::vector<PARAM::INFO> makeParamInfos();
};

View File

@ -76,9 +76,9 @@ public:
bool HasAutofill() const override { return true; }
bool HasPrimaryValue() const override { return GetType() == TYPE::V || GetType() == TYPE::I; }
private:
std::vector<std::string> getPinNames() const override { return { "+", "-" }; }
std::vector<std::string> GetPinNames() const override { return { "+", "-" }; }
private:
static const std::vector<PARAM::INFO>& makeParamInfos( TYPE aType );
static std::vector<PARAM::INFO> makeDcParamInfos( std::string aPrefix, std::string aUnit );

View File

@ -35,16 +35,22 @@ SIM_MODEL_SPICE_FALLBACK::SIM_MODEL_SPICE_FALLBACK( TYPE aType, const std::strin
void SIM_MODEL_SPICE_FALLBACK::SetPinSymbolPinNumber( const std::string& aPinName,
const std::string& aSymbolPinNumber )
{
for( PIN& pin : m_pins )
try
{
if( pin.name == aPinName )
{
pin.symbolPinNumber = aSymbolPinNumber;
return;
}
SIM_MODEL::SetPinSymbolPinNumber( aPinName, aSymbolPinNumber );
}
catch( IO_ERROR& )
{
// This is a fall-back, so we won't necessarily know the pin names. If we didn't find
// it, then just create a new pin.
m_pins.push_back( { aPinName, aSymbolPinNumber } );
}
m_pins.push_back( { aPinName, aSymbolPinNumber } );
}
std::vector<std::string> SIM_MODEL_SPICE_FALLBACK::GetPinNames() const
{
// If we're a fall-back for a paticular model type, then return its pin names
std::unique_ptr<SIM_MODEL> model = SIM_MODEL::Create( GetType() );
return model->GetPinNames();
}

View File

@ -34,6 +34,8 @@ public:
void SetPinSymbolPinNumber( const std::string& aPinName,
const std::string& aSymbolPinNumber ) override;
std::vector<std::string> GetPinNames() const override;
};
#endif // SIM_MODEL_SPICE_FALLBACK_H

View File

@ -45,12 +45,12 @@ class SIM_MODEL_SWITCH : public SIM_MODEL
public:
SIM_MODEL_SWITCH( TYPE aType );
private:
std::vector<std::string> getPinNames() const override
std::vector<std::string> GetPinNames() const override
{
return { "ctrl+", "ctrl-", "no+", "no-" };
}
private:
bool requiresSpiceModelLine() const override { return true; }
static const std::vector<PARAM::INFO> makeSwVParamInfos();

View File

@ -43,9 +43,9 @@ class SIM_MODEL_TLINE : public SIM_MODEL
public:
SIM_MODEL_TLINE( TYPE aType );
private:
std::vector<std::string> getPinNames() const override { return { "1+", "1-", "2+", "2-" }; }
std::vector<std::string> GetPinNames() const override { return { "1+", "1-", "2+", "2-" }; }
private:
static std::vector<PARAM::INFO> makeZ0ParamInfos();
static std::vector<PARAM::INFO> makeRlgcParamInfos();
};