From 91358dfcacc170cac9f98398e2551142e52d5ef8 Mon Sep 17 00:00:00 2001 From: Mikolaj Wielgus Date: Sun, 11 Sep 2022 15:22:45 +0200 Subject: [PATCH] Sim Model Editor: Fix Enable/Disable of parameters Only SIM_STRING_PROPERTY-based parameters were updated. --- eeschema/dialogs/dialog_sim_model.cpp | 18 ++++++------ eeschema/sim/sim_property.cpp | 24 +++++++++------- eeschema/sim/sim_property.h | 41 +++++++++++++-------------- 3 files changed, 42 insertions(+), 41 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_model.cpp b/eeschema/dialogs/dialog_sim_model.cpp index 50a10ed9e6..305ee53e7e 100644 --- a/eeschema/dialogs/dialog_sim_model.cpp +++ b/eeschema/dialogs/dialog_sim_model.cpp @@ -151,6 +151,8 @@ bool DIALOG_SIM_MODEL::TransferDataToWindow() m_curModelType = type; } + m_overrideCheckbox->SetValue( curModel().HasNonInstanceOverrides() ); + updateWidgets(); return DIALOG_SIM_MODEL_BASE::TransferDataToWindow(); @@ -288,9 +290,9 @@ void DIALOG_SIM_MODEL::updateModelParamsTab() // Set all properties to default colors. for( wxPropertyGridIterator it = m_paramGrid->GetIterator(); !it.AtEnd(); ++it ) { - SIM_STRING_PROPERTY* prop = dynamic_cast( *it ); - - if( !prop ) // Not all properties are SIM_PROPERTY yet. TODO. + SIM_PROPERTY* prop = dynamic_cast( *it ); + + if( !prop ) continue; wxColour bgCol = m_paramGrid->GetGrid()->GetPropertyDefaultCell().GetBgCol(); @@ -298,20 +300,18 @@ void DIALOG_SIM_MODEL::updateModelParamsTab() for( int col = 0; col < m_paramGridMgr->GetColumnCount(); ++col ) { - prop->GetCell( col ).SetBgCol( bgCol ); - prop->GetCell( col ).SetFgCol( fgCol ); + ( *it )->GetCell( col ).SetBgCol( bgCol ); + ( *it )->GetCell( col ).SetFgCol( fgCol ); } // 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 // models that don't have it for performance reasons. if( curModel().HasAutofill() ) - prop->SetValueFromString( prop->GetParam().value->ToString() ); - - m_overrideCheckbox->SetValue( curModel().HasNonInstanceOverrides() ); + ( *it )->SetValueFromString( prop->GetParam().value->ToString() ); // 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.category == SIM_MODEL::PARAM::CATEGORY::PRINCIPAL ) || m_overrideCheckbox->GetValue() ); diff --git a/eeschema/sim/sim_property.cpp b/eeschema/sim/sim_property.cpp index f25ac484a4..40dfd9f62e 100644 --- a/eeschema/sim/sim_property.cpp +++ b/eeschema/sim/sim_property.cpp @@ -306,14 +306,22 @@ void SIM_STRING_VALIDATOR::onMouse( wxMouseEvent& aEvent ) } +SIM_PROPERTY::SIM_PROPERTY( std::shared_ptr aLibrary, + std::shared_ptr 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, std::shared_ptr aLibrary, std::shared_ptr aModel, int aParamIndex ) : wxBoolProperty( aLabel, aName ), - m_library( aLibrary ), - m_model( aModel ), - m_paramIndex( aParamIndex ) + SIM_PROPERTY( aLibrary, aModel, aParamIndex ) { auto simValue = dynamic_cast*>( 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_GRAMMAR::NOTATION aNotation ) : wxStringProperty( aLabel, aName ), + SIM_PROPERTY( aLibrary, aModel, aParamIndex ), m_valueType( aValueType ), - m_notation( aNotation ), - m_library( aLibrary ), - m_model( aModel ), - m_paramIndex( aParamIndex ) + m_notation( aNotation ) { SetValueFromString( GetParam().value->ToString() ); } @@ -402,9 +408,7 @@ SIM_ENUM_PROPERTY::SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aN : wxEnumProperty( aLabel, aName, wxArrayString( aModel->GetParam( aParamIndex ).info.enumValues.size(), &aModel->GetParam( aParamIndex ).info.enumValues[0] ) ), - m_library( aLibrary ), - m_model( aModel ), - m_paramIndex( aParamIndex ) + SIM_PROPERTY( aLibrary, aModel, aParamIndex ) { auto it = std::find( GetParam().info.enumValues.begin(), GetParam().info.enumValues.end(), GetParam().value->ToString() ); diff --git a/eeschema/sim/sim_property.h b/eeschema/sim/sim_property.h index 37aa36ac13..b7b62d9f9b 100644 --- a/eeschema/sim/sim_property.h +++ b/eeschema/sim/sim_property.h @@ -87,7 +87,23 @@ private: }; -class SIM_BOOL_PROPERTY : public wxBoolProperty +class SIM_PROPERTY +{ +public: + SIM_PROPERTY( std::shared_ptr aLibrary, std::shared_ptr aModel, + int aParamIndex ); + + const SIM_MODEL::PARAM& GetParam() const { return m_model->GetParam( m_paramIndex ); } + +protected: + std::shared_ptr m_library; // We hold a shared_ptr to SIM_LIBRARY to prevent its + // deallocation during this object's lifetime. + std::shared_ptr m_model; + int m_paramIndex; +}; + + +class SIM_BOOL_PROPERTY : public wxBoolProperty, public SIM_PROPERTY { public: SIM_BOOL_PROPERTY( const wxString& aLabel, const wxString& aName, @@ -98,17 +114,10 @@ public: wxValidator* DoGetValidator() const override; void OnSetValue() override; - - const SIM_MODEL::PARAM& GetParam() const { return m_model->GetParam( m_paramIndex ); } - -protected: - std::shared_ptr m_library; - std::shared_ptr m_model; - int m_paramIndex; }; -class SIM_STRING_PROPERTY : public wxStringProperty +class SIM_STRING_PROPERTY : public wxStringProperty, public SIM_PROPERTY { public: // 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 ) const override; - const SIM_MODEL::PARAM& GetParam() const { return m_model->GetParam( m_paramIndex ); } - protected: SIM_VALUE::TYPE m_valueType; SIM_VALUE_GRAMMAR::NOTATION m_notation; - std::shared_ptr m_library; - std::shared_ptr m_model; - int m_paramIndex; }; -class SIM_ENUM_PROPERTY : public wxEnumProperty +class SIM_ENUM_PROPERTY : public wxEnumProperty, public SIM_PROPERTY { public: SIM_ENUM_PROPERTY( const wxString& aLabel, const wxString& aName, @@ -147,13 +151,6 @@ public: SIM_VALUE_GRAMMAR::NOTATION aNotation = SIM_VALUE_GRAMMAR::NOTATION::SI ); 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 m_library; - std::shared_ptr m_model; - int m_paramIndex; }; #endif // SIM_PROPERTY_H