Sim Model Editor: Fix Enable/Disable of parameters

Only SIM_STRING_PROPERTY-based parameters were updated.
This commit is contained in:
Mikolaj Wielgus 2022-09-11 15:22:45 +02:00
parent a0d859c324
commit 91358dfcac
3 changed files with 42 additions and 41 deletions

View File

@ -151,6 +151,8 @@ bool DIALOG_SIM_MODEL<T>::TransferDataToWindow()
m_curModelType = type; m_curModelType = type;
} }
m_overrideCheckbox->SetValue( curModel().HasNonInstanceOverrides() );
updateWidgets(); updateWidgets();
return DIALOG_SIM_MODEL_BASE::TransferDataToWindow(); return DIALOG_SIM_MODEL_BASE::TransferDataToWindow();
@ -288,9 +290,9 @@ void DIALOG_SIM_MODEL<T>::updateModelParamsTab()
// Set all properties to default colors. // Set all properties to default colors.
for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it ) for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it )
{ {
SIM_STRING_PROPERTY* prop = dynamic_cast<SIM_STRING_PROPERTY*>( *it ); SIM_PROPERTY* prop = dynamic_cast<SIM_PROPERTY*>( *it );
if( !prop ) // Not all properties are SIM_PROPERTY yet. TODO. if( !prop )
continue; continue;
wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol(); wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol();
@ -298,20 +300,18 @@ void DIALOG_SIM_MODEL<T>::updateModelParamsTab()
for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col ) for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col )
{ {
prop->GetCell( col ).SetBgCol( bgCol ); ( *it )->GetCell( col ).SetBgCol( bgCol );
prop->GetCell( col ).SetFgCol( fgCol ); ( *it )->GetCell( col ).SetFgCol( fgCol );
} }
// Model values other than the currently edited value may have changed. Update them. // Model values other than the currently edited value may have changed. Update them.
// This feature is called "autofill" and present only in certain models. Don't do it for // This feature is called "autofill" and present only in certain models. Don't do it for
// models that don't have it for performance reasons. // models that don't have it for performance reasons.
if( curModel().HasAutofill() ) if( curModel().HasAutofill() )
prop->SetValueFromString( prop->GetParam().value->ToString() ); ( *it )->SetValueFromString( prop->GetParam().value->ToString() );
m_overrideCheckbox->SetValue( curModel().HasNonInstanceOverrides() );
// Most of the values are disabled when the override checkbox is unchecked. // Most of the values are disabled when the override checkbox is unchecked.
prop->Enable( m_useInstanceModelRadioButton->GetValue() ( *it )->Enable( m_useInstanceModelRadioButton->GetValue()
|| ( prop->GetParam().info.isInstanceParam || ( prop->GetParam().info.isInstanceParam
&& prop->GetParam().info.category == SIM_MODEL::PARAM::CATEGORY::PRINCIPAL ) && prop->GetParam().info.category == SIM_MODEL::PARAM::CATEGORY::PRINCIPAL )
|| m_overrideCheckbox->GetValue() ); || m_overrideCheckbox->GetValue() );

View File

@ -306,14 +306,22 @@ void SIM_STRING_VALIDATOR::onMouse( wxMouseEvent& aEvent )
} }
SIM_PROPERTY::SIM_PROPERTY( std::shared_ptr<SIM_LIBRARY> aLibrary,
std::shared_ptr<SIM_MODEL> aModel,
int aParamIndex )
: m_library( std::move( aLibrary ) ),
m_model( std::move( aModel ) ),
m_paramIndex( aParamIndex )
{
}
SIM_BOOL_PROPERTY::SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_BOOL_PROPERTY::SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName,
std::shared_ptr<SIM_LIBRARY> aLibrary, std::shared_ptr<SIM_LIBRARY> aLibrary,
std::shared_ptr<SIM_MODEL> aModel, std::shared_ptr<SIM_MODEL> aModel,
int aParamIndex ) int aParamIndex )
: wxBoolProperty( aLabel, aName ), : wxBoolProperty( aLabel, aName ),
m_library( aLibrary ), SIM_PROPERTY( aLibrary, aModel, aParamIndex )
m_model( aModel ),
m_paramIndex( aParamIndex )
{ {
auto simValue = dynamic_cast<SIM_VALUE_INST<bool>*>( auto simValue = dynamic_cast<SIM_VALUE_INST<bool>*>(
m_model->GetParam( m_paramIndex ).value.get() ); m_model->GetParam( m_paramIndex ).value.get() );
@ -353,11 +361,9 @@ SIM_STRING_PROPERTY::SIM_STRING_PROPERTY( const wxString& aLabel, const wxString
SIM_VALUE::TYPE aValueType, SIM_VALUE::TYPE aValueType,
SIM_VALUE_GRAMMAR::NOTATION aNotation ) SIM_VALUE_GRAMMAR::NOTATION aNotation )
: wxStringProperty( aLabel, aName ), : wxStringProperty( aLabel, aName ),
SIM_PROPERTY( aLibrary, aModel, aParamIndex ),
m_valueType( aValueType ), m_valueType( aValueType ),
m_notation( aNotation ), m_notation( aNotation )
m_library( aLibrary ),
m_model( aModel ),
m_paramIndex( aParamIndex )
{ {
SetValueFromString( GetParam().value->ToString() ); SetValueFromString( GetParam().value->ToString() );
} }
@ -402,9 +408,7 @@ SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aN
: wxEnumProperty( aLabel, aName, : wxEnumProperty( aLabel, aName,
wxArrayString( aModel->GetParam( aParamIndex ).info.enumValues.size(), wxArrayString( aModel->GetParam( aParamIndex ).info.enumValues.size(),
&aModel->GetParam( aParamIndex ).info.enumValues[0] ) ), &aModel->GetParam( aParamIndex ).info.enumValues[0] ) ),
m_library( aLibrary ), SIM_PROPERTY( aLibrary, aModel, aParamIndex )
m_model( aModel ),
m_paramIndex( aParamIndex )
{ {
auto it = std::find( GetParam().info.enumValues.begin(), GetParam().info.enumValues.end(), auto it = std::find( GetParam().info.enumValues.begin(), GetParam().info.enumValues.end(),
GetParam().value->ToString() ); GetParam().value->ToString() );

View File

@ -87,7 +87,23 @@ private:
}; };
class SIM_BOOL_PROPERTY : public wxBoolProperty class SIM_PROPERTY
{
public:
SIM_PROPERTY( std::shared_ptr<SIM_LIBRARY> aLibrary, std::shared_ptr<SIM_MODEL> aModel,
int aParamIndex );
const SIM_MODEL::PARAM& GetParam() const { return m_model->GetParam( m_paramIndex ); }
protected:
std::shared_ptr<SIM_LIBRARY> m_library; // We hold a shared_ptr to SIM_LIBRARY to prevent its
// deallocation during this object's lifetime.
std::shared_ptr<SIM_MODEL> m_model;
int m_paramIndex;
};
class SIM_BOOL_PROPERTY : public wxBoolProperty, public SIM_PROPERTY
{ {
public: public:
SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName,
@ -98,17 +114,10 @@ public:
wxValidator* DoGetValidator() const override; wxValidator* DoGetValidator() const override;
void OnSetValue() override; void OnSetValue() override;
const SIM_MODEL::PARAM& GetParam() const { return m_model->GetParam( m_paramIndex ); }
protected:
std::shared_ptr<SIM_LIBRARY> m_library;
std::shared_ptr<SIM_MODEL> m_model;
int m_paramIndex;
}; };
class SIM_STRING_PROPERTY : public wxStringProperty class SIM_STRING_PROPERTY : public wxStringProperty, public SIM_PROPERTY
{ {
public: public:
// We pass shared_ptrs because we need to make sure they are destroyed only after the last time // We pass shared_ptrs because we need to make sure they are destroyed only after the last time
@ -125,18 +134,13 @@ public:
bool StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 ) bool StringToValue( wxVariant& aVariant, const wxString& aText, int aArgFlags = 0 )
const override; const override;
const SIM_MODEL::PARAM& GetParam() const { return m_model->GetParam( m_paramIndex ); }
protected: protected:
SIM_VALUE::TYPE m_valueType; SIM_VALUE::TYPE m_valueType;
SIM_VALUE_GRAMMAR::NOTATION m_notation; SIM_VALUE_GRAMMAR::NOTATION m_notation;
std::shared_ptr<SIM_LIBRARY> m_library;
std::shared_ptr<SIM_MODEL> m_model;
int m_paramIndex;
}; };
class SIM_ENUM_PROPERTY : public wxEnumProperty class SIM_ENUM_PROPERTY : public wxEnumProperty, public SIM_PROPERTY
{ {
public: public:
SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName, SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName,
@ -147,13 +151,6 @@ public:
SIM_VALUE_GRAMMAR::NOTATION aNotation = SIM_VALUE_GRAMMAR::NOTATION::SI ); SIM_VALUE_GRAMMAR::NOTATION aNotation = SIM_VALUE_GRAMMAR::NOTATION::SI );
bool IntToValue( wxVariant& aVariant, int aNumber, int aArgFlags = 0 ) const override; bool IntToValue( wxVariant& aVariant, int aNumber, int aArgFlags = 0 ) const override;
const SIM_MODEL::PARAM& GetParam() const { return m_model->GetParam( m_paramIndex ); }
protected:
std::shared_ptr<SIM_LIBRARY> m_library;
std::shared_ptr<SIM_MODEL> m_model;
int m_paramIndex;
}; };
#endif // SIM_PROPERTY_H #endif // SIM_PROPERTY_H