From 419fe236ada0a1813e5f49122cbb86162f7fcdbd Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 11 Dec 2022 21:28:04 +0000 Subject: [PATCH] Fix logic error in parsing sim command, and DC source types in dialog. Fixes https://gitlab.com/kicad/code/kicad/issues/9064 --- eeschema/dialogs/dialog_sim_command.cpp | 20 +++++++++++--------- eeschema/dialogs/dialog_sim_command.h | 2 +- eeschema/dialogs/dialog_sim_command_base.cpp | 4 ++++ eeschema/dialogs/dialog_sim_command_base.fbp | 4 ++-- eeschema/sim/sim_plot_frame.cpp | 4 ++-- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/eeschema/dialogs/dialog_sim_command.cpp b/eeschema/dialogs/dialog_sim_command.cpp index 3bdd57bbf3..ef6cb5e4a2 100644 --- a/eeschema/dialogs/dialog_sim_command.cpp +++ b/eeschema/dialogs/dialog_sim_command.cpp @@ -105,9 +105,12 @@ DIALOG_SIM_COMMAND::DIALOG_SIM_COMMAND( wxWindow* aParent, wxString DIALOG_SIM_COMMAND::evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart, wxTextCtrl* aDcStop, wxTextCtrl* aDcIncr ) { - wxString dcSource = aDcSource->GetString( aDcSource->GetSelection() ); + wxString dcSource; wxWindow* ctrlWithError = nullptr; + if( aDcSource->GetSelection() >= 0 ) + dcSource = aDcSource->GetString( aDcSource->GetSelection() ); + if( dcSource.IsEmpty() ) { DisplayError( this, _( "You need to select DC source" ) ); @@ -393,13 +396,12 @@ void DIALOG_SIM_COMMAND::updateDCSources( wxChar aType, wxChoice* aSource ) if( aType != 'T' ) { - for( const auto& item : m_circuitModel->GetItems() ) + for( const SPICE_ITEM& item : m_circuitModel->GetItems() ) { if( ( aType == 'R' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::R ) - || ( aType == 'C' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::C ) - || ( aType == 'L' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::L ) ) + || ( aType == 'V' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V ) + || ( aType == 'I' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::I ) ) { - // TODO: VSOURCE, ISOURCE. sourcesList.insert( item.refName ); } } @@ -444,9 +446,9 @@ bool DIALOG_SIM_COMMAND::parseCommand( const wxString& aCommand ) if( tkn == "dec" ) m_acScale->SetSelection( 0 ); - if( tkn == "oct" ) + else if( tkn == "oct" ) m_acScale->SetSelection( 1 ); - if( tkn == "lin" ) + else if( tkn == "lin" ) m_acScale->SetSelection( 2 ); else return false; @@ -458,14 +460,14 @@ bool DIALOG_SIM_COMMAND::parseCommand( const wxString& aCommand ) } else if( tkn == ".dc" ) { + m_simPages->SetSelection( m_simPages->FindPage( m_pgDC ) ); + SPICE_DC_PARAMS src1, src2; src2.m_vincrement = SPICE_VALUE( -1 ); if( !m_circuitModel->ParseDCCommand( aCommand, &src1, &src2 ) ) return false; - m_simPages->SetSelection( m_simPages->FindPage( m_pgDC ) ); - if( src1.m_source.IsSameAs( wxT( "TEMP" ), false ) ) setStringSelection( m_dcSourceType1, wxT( "TEMP" ) ); else diff --git a/eeschema/dialogs/dialog_sim_command.h b/eeschema/dialogs/dialog_sim_command.h index f9e9db1c17..c6cc11eb7f 100644 --- a/eeschema/dialogs/dialog_sim_command.h +++ b/eeschema/dialogs/dialog_sim_command.h @@ -40,7 +40,7 @@ class DIALOG_SIM_COMMAND : public DIALOG_SIM_COMMAND_BASE { public: DIALOG_SIM_COMMAND( wxWindow* aParent, std::shared_ptr aCircuitModel, - std::shared_ptr& aSettings ); + std::shared_ptr& aSettings ); const wxString& GetSimCommand() const { diff --git a/eeschema/dialogs/dialog_sim_command_base.cpp b/eeschema/dialogs/dialog_sim_command_base.cpp index 3f3e077afe..d066117159 100644 --- a/eeschema/dialogs/dialog_sim_command_base.cpp +++ b/eeschema/dialogs/dialog_sim_command_base.cpp @@ -134,6 +134,8 @@ DIALOG_SIM_COMMAND_BASE::DIALOG_SIM_COMMAND_BASE( wxWindow* parent, wxWindowID i gbSizer1->Add( m_staticText5, wxGBPosition( 3, 0 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT, 5 ); m_dcStart1 = new wxTextCtrl( m_pgDC, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_dcStart1->SetMinSize( wxSize( 100,-1 ) ); + gbSizer1->Add( m_dcStart1, wxGBPosition( 3, 1 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_src1DCStartValUnit = new wxStaticText( m_pgDC, wxID_ANY, _("Volts"), wxDefaultPosition, wxDefaultSize, 0 ); @@ -143,6 +145,8 @@ DIALOG_SIM_COMMAND_BASE::DIALOG_SIM_COMMAND_BASE( wxWindow* parent, wxWindowID i gbSizer1->Add( m_src1DCStartValUnit, wxGBPosition( 3, 2 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxRIGHT, 5 ); m_dcStart2 = new wxTextCtrl( m_pgDC, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_dcStart2->SetMinSize( wxSize( 100,-1 ) ); + gbSizer1->Add( m_dcStart2, wxGBPosition( 3, 3 ), wxGBSpan( 1, 1 ), wxALIGN_CENTER_VERTICAL|wxRIGHT|wxLEFT|wxEXPAND, 5 ); m_src2DCStartValUnit = new wxStaticText( m_pgDC, wxID_ANY, _("Volts"), wxDefaultPosition, wxDefaultSize, 0 ); diff --git a/eeschema/dialogs/dialog_sim_command_base.fbp b/eeschema/dialogs/dialog_sim_command_base.fbp index a3a0efca20..9999341033 100644 --- a/eeschema/dialogs/dialog_sim_command_base.fbp +++ b/eeschema/dialogs/dialog_sim_command_base.fbp @@ -1493,7 +1493,7 @@ 0 - + 100,-1 1 m_dcStart1 1 @@ -1624,7 +1624,7 @@ 0 - + 100,-1 1 m_dcStart2 1 diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 4929171c2a..a94a27a9c1 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -1508,8 +1508,8 @@ void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event ) else oldCommand = wxString(); - wxString newCommand = dlg.GetSimCommand(); - SIM_TYPE newSimType = NGSPICE_CIRCUIT_MODEL::CommandToSimType( newCommand ); + const wxString& newCommand = dlg.GetSimCommand(); + SIM_TYPE newSimType = NGSPICE_CIRCUIT_MODEL::CommandToSimType( newCommand ); // If it is a new simulation type, open a new plot // For the DC sim, check if sweep source type has changed (char 4 will contain 'v',