ReadDataFields must be a separate step from Create.

Create() is done without execption processing, while ReadDataFields
should have exception processing.

(This also fixes a case where exception processing on ReadDataFields
was missing.)

Also fixes a bug where the pinSelect menu wasn't checked for -1 before
fetching.

Fixes https://gitlab.com/kicad/code/kicad/issues/13856
This commit is contained in:
Jeff Young 2023-02-13 11:52:30 +00:00
parent 534000b49d
commit 53a4ed6b24
3 changed files with 22 additions and 35 deletions

View File

@ -337,17 +337,19 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
if( ibismodel )
{
SIM_MODEL::SetFieldValue(
m_fields, SIM_LIBRARY_KIBIS::PIN_FIELD,
ibismodel->GetIbisPins().at( m_ibisPinCombobox->GetSelection() ).first );
std::string pins;
std::string modelName = std::string( m_ibisModelCombobox->GetValue().c_str() );
std::string differential;
SIM_MODEL::SetFieldValue(
m_fields, SIM_LIBRARY_KIBIS::MODEL_FIELD,
std::string( m_ibisModelCombobox->GetValue().c_str() ) );
if( m_ibisPinCombobox->GetSelection() >= 0 )
pins = ibismodel->GetIbisPins().at( m_ibisPinCombobox->GetSelection() ).first;
SIM_MODEL::SetFieldValue(
m_fields, SIM_LIBRARY_KIBIS::DIFF_FIELD,
ibismodel->CanDifferential() && m_differentialCheckbox->GetValue() ? "1" : "" );
if( ibismodel->CanDifferential() && m_differentialCheckbox->GetValue() )
differential = "1";
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY_KIBIS::PIN_FIELD, pins );
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY_KIBIS::MODEL_FIELD, modelName );
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY_KIBIS::DIFF_FIELD, differential );
}
}
@ -1219,10 +1221,18 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onTypeChoice( wxCommandEvent& aEvent )
{
int idx = m_modelNameChoice->GetSelection();
auto& kibisModel = static_cast<SIM_MODEL_KIBIS&>( m_libraryModelsMgr.GetModels().at( idx ).get() );
auto& baseModel = static_cast<SIM_MODEL_KIBIS&>( m_libraryModelsMgr.GetModels().at( idx ).get() );
m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_KIBIS>( type, kibisModel,
m_fields, sourcePins ) );
m_libraryModelsMgr.SetModel( idx, std::make_unique<SIM_MODEL_KIBIS>( type, baseModel ) );
try
{
m_libraryModelsMgr.GetModels().at( idx ).get().ReadDataFields( &m_fields, sourcePins );
}
catch( IO_ERROR& err )
{
DisplayErrorMessage( this, err.What() );
}
}
m_curModelType = type;

View File

@ -278,24 +278,6 @@ SIM_MODEL_KIBIS::SIM_MODEL_KIBIS( TYPE aType, const SIM_MODEL_KIBIS& aSource ) :
}
SIM_MODEL_KIBIS::SIM_MODEL_KIBIS( TYPE aType, SIM_MODEL_KIBIS& aSource,
const std::vector<LIB_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins ) :
SIM_MODEL_KIBIS( aType, aSource )
{
ReadDataFields( &aFields, aPins );
}
SIM_MODEL_KIBIS::SIM_MODEL_KIBIS( TYPE aType, SIM_MODEL_KIBIS& aSource,
const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins ) :
SIM_MODEL_KIBIS( aType, aSource )
{
ReadDataFields( &aFields, aPins );
}
bool SIM_MODEL_KIBIS::ChangePin( const SIM_LIBRARY_KIBIS& aLib, std::string aPinNumber )
{
KIBIS_COMPONENT* kcomp = aLib.m_kibis.GetComponent( std::string( GetComponentName() ) );

View File

@ -59,11 +59,6 @@ public:
// creates a a model with aType, but tries to match parameters from aSource.
SIM_MODEL_KIBIS( TYPE aType, const SIM_MODEL_KIBIS& aSource );
SIM_MODEL_KIBIS( TYPE aType, SIM_MODEL_KIBIS& aSource, const std::vector<LIB_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins );
SIM_MODEL_KIBIS( TYPE aType, SIM_MODEL_KIBIS& aSource, const std::vector<SCH_FIELD>& aFields,
const std::vector<LIB_PIN*>& aPins );
std::vector<std::pair<std::string, std::string>> GetIbisPins() const
{
return m_sourceModel ? m_sourceModel->GetIbisPins() : m_ibisPins;