Simplify library model name from combobox to choice.

Fixes https://gitlab.com/kicad/code/kicad/issues/13168
This commit is contained in:
Jeff Young 2022-12-15 12:12:36 +00:00
parent ba585e9b3a
commit 00a5fddda4
5 changed files with 43 additions and 101 deletions

View File

@ -61,7 +61,6 @@ DIALOG_SIM_MODEL<T_symbol, T_field>::DIALOG_SIM_MODEL( wxWindow* aParent, T_symb
m_lastParamGridWidth( 0 ),
m_inKillFocus( false )
{
m_modelNameCombobox->SetValidator( m_modelNameValidator );
m_browseButton->SetBitmap( KiBitmap( BITMAPS::small_folder ) );
// Note that to get ALL pins, not only of the current part, you need to use
@ -176,21 +175,21 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataToWindow()
loadLibrary( libraryFilename );
// Must be set before curModel() is used since the latter checks the combobox value.
m_modelNameCombobox->SetStringSelection(
SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD ) );
std::string modelName = SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY::NAME_FIELD );
m_modelNameChoice->SetStringSelection( modelName );
if( isIbisLoaded() && ( m_modelNameCombobox->GetSelection() >= 0 ) )
if( isIbisLoaded() && ( m_modelNameChoice->GetSelection() >= 0 ) )
{
SIM_MODEL_KIBIS* kibismodel = dynamic_cast<SIM_MODEL_KIBIS*>(
&m_libraryModelsMgr.GetModels().at( m_modelNameCombobox->GetSelection() ).get() );
&m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get() );
if( kibismodel )
{
onModelNameCombobox( dummyEvent ); // refresh list of pins
onModelNameChoice( dummyEvent ); // refresh list of pins
int i = 0;
for( std::pair<std::string, std::string> strs : kibismodel->GetIbisPins() )
for( const std::pair<std::string, std::string>& strs : kibismodel->GetIbisPins() )
{
if( strs.first
== SIM_MODEL::GetFieldValue( &m_fields, SIM_LIBRARY_KIBIS::PIN_FIELD ) )
@ -275,9 +274,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
if( !DIALOG_SIM_MODEL_BASE::TransferDataFromWindow() )
return false;
std::string modelName;
modelName = m_modelNameCombobox->GetValue();
std::string modelName = m_modelNameChoice->GetStringSelection().ToStdString();
SIM_MODEL::SetFieldValue( m_fields, SIM_LIBRARY::NAME_FIELD, modelName );
@ -297,7 +294,7 @@ bool DIALOG_SIM_MODEL<T_symbol, T_field>::TransferDataFromWindow()
if( isIbisLoaded() )
{
SIM_MODEL_KIBIS* kibismodel = dynamic_cast<SIM_MODEL_KIBIS*>(
&m_libraryModelsMgr.GetModels().at( m_modelNameCombobox->GetSelection() ).get() );
&m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get() );
if( kibismodel )
{
@ -527,7 +524,7 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::updateModelCodeTab()
{
wxString text;
SPICE_ITEM item;
item.modelName = m_modelNameCombobox->GetStringSelection();
item.modelName = m_modelNameChoice->GetStringSelection();
if( m_useInstanceModelRadioButton->GetValue() || item.modelName == "" )
item.modelName = m_fields.at( REFERENCE_FIELD ).GetText();
@ -667,19 +664,16 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::loadLibrary( const wxString& aLibraryP
DisplayErrorMessage( this, e.What() );
}
m_useLibraryModelRadioButton->SetValue( true );
m_libraryPathText->ChangeValue( aLibraryPath );
wxArrayString modelNames;
for( auto& [modelName, model] : library()->GetModels() )
modelNames.Add( modelName );
auto validator = dynamic_cast<MODEL_NAME_VALIDATOR*>( m_modelNameCombobox->GetValidator() );
if( validator )
validator->SetIncludes( modelNames );
m_libraryPathText->ChangeValue( aLibraryPath );
m_modelNameCombobox->Set( modelNames );
m_useLibraryModelRadioButton->SetValue( true );
m_modelNameChoice->Clear();
m_modelNameChoice->Append( modelNames );
if( isIbisLoaded() )
{
@ -873,9 +867,9 @@ template <typename T_symbol, typename T_field>
SIM_MODEL& DIALOG_SIM_MODEL<T_symbol, T_field>::curModel() const
{
if( m_useLibraryModelRadioButton->GetValue()
&& m_modelNameCombobox->GetSelection() != wxNOT_FOUND )
&& m_modelNameChoice->GetSelection() != wxNOT_FOUND )
{
return m_libraryModelsMgr.GetModels().at( m_modelNameCombobox->GetSelection() ).get();
return m_libraryModelsMgr.GetModels().at( m_modelNameChoice->GetSelection() ).get();
}
else
{
@ -957,7 +951,7 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onRadioButton( wxCommandEvent& aEvent
m_libraryPathText->Enable( fromLibrary );
m_browseButton->Enable( fromLibrary );
m_modelNameLabel->Enable( fromLibrary );
m_modelNameCombobox->Enable( fromLibrary );
m_modelNameChoice->Enable( fromLibrary );
m_ibisPinLabel->Enable( fromLibrary );
m_ibisPinCombobox->Enable( fromLibrary );
m_differentialCheckbox->Enable( fromLibrary );
@ -1030,7 +1024,7 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onBrowseButtonClick( wxCommandEvent& a
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onModelNameCombobox( wxCommandEvent& aEvent )
void DIALOG_SIM_MODEL<T_symbol, T_field>::onModelNameChoice( wxCommandEvent& aEvent )
{
if( isIbisLoaded() )
{
@ -1052,24 +1046,6 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onModelNameCombobox( wxCommandEvent& a
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onModelNameComboboxKillFocus( wxFocusEvent& aEvent )
{
m_modelNameCombobox->SetSelection(
m_modelNameCombobox->FindString( m_modelNameCombobox->GetValue() ) );
updateWidgets();
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onModelNameComboboxTextEnter( wxCommandEvent& aEvent )
{
m_modelNameCombobox->SetSelection(
m_modelNameCombobox->FindString( m_modelNameCombobox->GetValue() ) );
onModelNameCombobox( aEvent );
}
template <typename T_symbol, typename T_field>
void DIALOG_SIM_MODEL<T_symbol, T_field>::onIbisPinCombobox( wxCommandEvent& aEvent )
{
@ -1172,12 +1148,11 @@ void DIALOG_SIM_MODEL<T_symbol, T_field>::onTypeChoice( wxCommandEvent& aEvent )
|| type == SIM_MODEL::TYPE::KIBIS_DRIVER_RECT
|| type == SIM_MODEL::TYPE::KIBIS_DRIVER_PRBS ) )
{
SIM_MODEL_KIBIS& kibisModel = static_cast<SIM_MODEL_KIBIS&>(
m_libraryModelsMgr.GetModels().at( m_modelNameCombobox->GetSelection() ).get() );
int idx = m_modelNameChoice->GetSelection();
m_libraryModelsMgr.SetModel( m_modelNameCombobox->GetSelection(),
std::make_unique<SIM_MODEL_KIBIS>( type, kibisModel,
m_fields ) );
auto& kibisModel = 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 ) );
}
m_curModelType = type;

View File

@ -45,27 +45,6 @@ template <typename T_symbol, typename T_field>
class DIALOG_SIM_MODEL : public DIALOG_SIM_MODEL_BASE
{
public:
class MODEL_NAME_VALIDATOR : public wxTextValidator
{
public:
MODEL_NAME_VALIDATOR() : wxTextValidator( wxFILTER_INCLUDE_LIST )
{
}
wxObject* Clone() const override
{
return new MODEL_NAME_VALIDATOR( *this );
}
wxString IsValid( const wxString& aStr ) const override
{
if( m_includes.Index( aStr ) == wxNOT_FOUND )
return wxString::Format( _( "No model named '%s' in library." ), aStr );
return wxString();
}
};
enum PARAM_COLUMN
{
DESCRIPTION = 0,
@ -117,9 +96,7 @@ private:
void onLibraryPathTextEnter( wxCommandEvent& aEvent ) override;
void onLibraryPathTextKillFocus( wxFocusEvent& aEvent ) override;
void onBrowseButtonClick( wxCommandEvent& aEvent ) override;
void onModelNameCombobox( wxCommandEvent& aEvent ) override;
void onModelNameComboboxKillFocus( wxFocusEvent& event ) override;
void onModelNameComboboxTextEnter( wxCommandEvent& event ) override;
void onModelNameChoice( wxCommandEvent& aEvent ) override;
void onIbisPinCombobox( wxCommandEvent& event ) override;
void onIbisPinComboboxTextEnter( wxCommandEvent& event ) override;
void onIbisModelCombobox( wxCommandEvent& event ) override;
@ -153,7 +130,6 @@ private:
std::map<SIM_MODEL::DEVICE_T, SIM_MODEL::TYPE> m_curModelTypeOfDeviceType;
SIM_MODEL::TYPE m_curModelType;
MODEL_NAME_VALIDATOR m_modelNameValidator;
SCINTILLA_TRICKS* m_scintillaTricks;
wxPGProperty* m_firstCategory; // Used to add principal parameters to root.

View File

@ -55,8 +55,10 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
m_modelNameLabel->Wrap( -1 );
gbSizer1->Add( m_modelNameLabel, wxGBPosition( 1, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL, 5 );
m_modelNameCombobox = new wxComboBox( m_modelPanel, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0, NULL, wxTE_PROCESS_ENTER );
gbSizer1->Add( m_modelNameCombobox, wxGBPosition( 1, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
wxArrayString m_modelNameChoiceChoices;
m_modelNameChoice = new wxChoice( m_modelPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, m_modelNameChoiceChoices, 0 );
m_modelNameChoice->SetSelection( 0 );
gbSizer1->Add( m_modelNameChoice, wxGBPosition( 1, 1 ), wxGBSpan( 1, 2 ), wxEXPAND|wxRIGHT, 5 );
gbSizer1->Add( 0, 0, wxGBPosition( 1, 3 ), wxGBSpan( 1, 1 ), wxEXPAND, 5 );
@ -94,7 +96,7 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
bSizerMargins->Add( gbSizer1, 0, wxEXPAND|wxLEFT, 28 );
bSizerMargins->Add( 0, 20, 0, wxEXPAND, 5 );
bSizerMargins->Add( 0, 25, 0, wxEXPAND, 5 );
m_useInstanceModelRadioButton = new wxRadioButton( m_modelPanel, wxID_ANY, _("Built-in SPICE model"), wxDefaultPosition, wxDefaultSize, 0 );
bSizerMargins->Add( m_useInstanceModelRadioButton, 0, wxBOTTOM|wxLEFT, 5 );
@ -291,10 +293,7 @@ DIALOG_SIM_MODEL_BASE::DIALOG_SIM_MODEL_BASE( wxWindow* parent, wxWindowID id, c
m_browseButton->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonClick ), NULL, this );
m_browseButton->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonUpdate ), NULL, this );
m_modelNameLabel->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameLabelUpdate ), NULL, this );
m_modelNameCombobox->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameCombobox ), NULL, this );
m_modelNameCombobox->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxKillFocus ), NULL, this );
m_modelNameCombobox->Connect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxTextEnter ), NULL, this );
m_modelNameCombobox->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxUpdate ), NULL, this );
m_modelNameChoice->Connect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameChoice ), NULL, this );
m_ibisPinLabel->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onIbisPinLabelUpdate ), NULL, this );
m_ibisPinCombobox->Connect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onIbisPinCombobox ), NULL, this );
m_ibisPinCombobox->Connect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxKillFocus ), NULL, this );
@ -331,10 +330,7 @@ DIALOG_SIM_MODEL_BASE::~DIALOG_SIM_MODEL_BASE()
m_browseButton->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonClick ), NULL, this );
m_browseButton->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onBrowseButtonUpdate ), NULL, this );
m_modelNameLabel->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameLabelUpdate ), NULL, this );
m_modelNameCombobox->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameCombobox ), NULL, this );
m_modelNameCombobox->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxKillFocus ), NULL, this );
m_modelNameCombobox->Disconnect( wxEVT_COMMAND_TEXT_ENTER, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxTextEnter ), NULL, this );
m_modelNameCombobox->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxUpdate ), NULL, this );
m_modelNameChoice->Disconnect( wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameChoice ), NULL, this );
m_ibisPinLabel->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( DIALOG_SIM_MODEL_BASE::onIbisPinLabelUpdate ), NULL, this );
m_ibisPinCombobox->Disconnect( wxEVT_COMMAND_COMBOBOX_SELECTED, wxCommandEventHandler( DIALOG_SIM_MODEL_BASE::onIbisPinCombobox ), NULL, this );
m_ibisPinCombobox->Disconnect( wxEVT_KILL_FOCUS, wxFocusEventHandler( DIALOG_SIM_MODEL_BASE::onModelNameComboboxKillFocus ), NULL, this );

View File

@ -554,12 +554,12 @@
</object>
<object class="gbsizeritem" expanded="1">
<property name="border">5</property>
<property name="colspan">1</property>
<property name="colspan">2</property>
<property name="column">1</property>
<property name="flag">wxALIGN_CENTER_VERTICAL|wxEXPAND</property>
<property name="flag">wxEXPAND|wxRIGHT</property>
<property name="row">1</property>
<property name="rowspan">1</property>
<object class="wxComboBox" expanded="1">
<object class="wxChoice" expanded="1">
<property name="BottomDockable">1</property>
<property name="LeftDockable">1</property>
<property name="RightDockable">1</property>
@ -595,7 +595,7 @@
<property name="minimize_button">0</property>
<property name="minimum_size"></property>
<property name="moveable">1</property>
<property name="name">m_modelNameCombobox</property>
<property name="name">m_modelNameChoice</property>
<property name="pane_border">1</property>
<property name="pane_position"></property>
<property name="pane_size"></property>
@ -603,10 +603,10 @@
<property name="pin_button">1</property>
<property name="pos"></property>
<property name="resize">Resizable</property>
<property name="selection">-1</property>
<property name="selection">0</property>
<property name="show">1</property>
<property name="size"></property>
<property name="style">wxTE_PROCESS_ENTER</property>
<property name="style"></property>
<property name="subclass">; ; forward_declare</property>
<property name="toolbar_pane">0</property>
<property name="tooltip"></property>
@ -614,14 +614,10 @@
<property name="validator_style">wxFILTER_NONE</property>
<property name="validator_type">wxDefaultValidator</property>
<property name="validator_variable"></property>
<property name="value"></property>
<property name="window_extra_style"></property>
<property name="window_name"></property>
<property name="window_style"></property>
<event name="OnCombobox">onModelNameCombobox</event>
<event name="OnKillFocus">onModelNameComboboxKillFocus</event>
<event name="OnTextEnter">onModelNameComboboxTextEnter</event>
<event name="OnUpdateUI">onModelNameComboboxUpdate</event>
<event name="OnChoice">onModelNameChoice</event>
</object>
</object>
<object class="gbsizeritem" expanded="1">
@ -987,7 +983,7 @@
<property name="flag">wxEXPAND</property>
<property name="proportion">0</property>
<object class="spacer" expanded="1">
<property name="height">20</property>
<property name="height">25</property>
<property name="permission">protected</property>
<property name="width">0</property>
</object>

View File

@ -28,10 +28,10 @@ class WX_GRID;
#include <wx/icon.h>
#include <wx/button.h>
#include <wx/sizer.h>
#include <wx/choice.h>
#include <wx/combobox.h>
#include <wx/checkbox.h>
#include <wx/gbsizer.h>
#include <wx/choice.h>
#include <wx/propgrid/propgrid.h>
#include <wx/propgrid/manager.h>
#include <wx/propgrid/advprops.h>
@ -59,7 +59,7 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM
wxTextCtrl* m_libraryPathText;
STD_BITMAP_BUTTON* m_browseButton;
wxStaticText* m_modelNameLabel;
wxComboBox* m_modelNameCombobox;
wxChoice* m_modelNameChoice;
wxStaticText* m_ibisPinLabel;
wxComboBox* m_ibisPinCombobox;
wxCheckBox* m_differentialCheckbox;
@ -92,13 +92,12 @@ class DIALOG_SIM_MODEL_BASE : public DIALOG_SHIM
virtual void onBrowseButtonClick( wxCommandEvent& event ) { event.Skip(); }
virtual void onBrowseButtonUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onModelNameLabelUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onModelNameCombobox( wxCommandEvent& event ) { event.Skip(); }
virtual void onModelNameComboboxKillFocus( wxFocusEvent& event ) { event.Skip(); }
virtual void onModelNameComboboxTextEnter( wxCommandEvent& event ) { event.Skip(); }
virtual void onModelNameComboboxUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onModelNameChoice( wxCommandEvent& event ) { event.Skip(); }
virtual void onIbisPinLabelUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onIbisPinCombobox( wxCommandEvent& event ) { event.Skip(); }
virtual void onModelNameComboboxKillFocus( wxFocusEvent& event ) { event.Skip(); }
virtual void onIbisPinComboboxTextEnter( wxCommandEvent& event ) { event.Skip(); }
virtual void onModelNameComboboxUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onDifferentialCheckbox( wxCommandEvent& event ) { event.Skip(); }
virtual void onOverrideCheckboxUpdate( wxUpdateUIEvent& event ) { event.Skip(); }
virtual void onIbisModelLabelUpdate( wxUpdateUIEvent& event ) { event.Skip(); }