From 69448afb47b7fe2aad46575a5d5be6ed413a778f Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 7 Dec 2022 00:23:18 +0000 Subject: [PATCH] Don't run simulation twice when the sim command is overridden. Fixes https://gitlab.com/kicad/code/kicad/issues/12731 --- eeschema/CMakeLists.txt | 2 +- eeschema/dialogs/dialog_signal_list.cpp | 2 +- eeschema/dialogs/dialog_sim_settings.cpp | 2 +- .../netlist_exporter_spice.cpp | 13 +++- .../netlist_exporter_spice.h | 11 +-- eeschema/sim/ngspice.cpp | 2 +- ..._helpers.cpp => ngspice_circuit_model.cpp} | 7 +- ...pice_helpers.h => ngspice_circuit_model.h} | 6 +- eeschema/sim/sim_panel_base.cpp | 2 +- eeschema/sim/sim_panel_base.h | 2 +- eeschema/sim/sim_workbook.cpp | 72 +++++++++++++------ eeschema/sim/sim_workbook.h | 2 +- eeschema/widgets/tuner_slider.cpp | 2 +- .../eeschema/sim/test_ngspice_helpers.cpp | 2 +- 14 files changed, 85 insertions(+), 42 deletions(-) rename eeschema/sim/{ngspice_helpers.cpp => ngspice_circuit_model.cpp} (96%) rename eeschema/sim/{ngspice_helpers.h => ngspice_circuit_model.h} (97%) diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index d51f55b99c..1227223e90 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -349,7 +349,7 @@ if( KICAD_SPICE ) dialogs/dialog_sim_settings_base.cpp dialogs/dialog_sim_model.cpp dialogs/dialog_sim_model_base.cpp - sim/ngspice_helpers.cpp + sim/ngspice_circuit_model.cpp sim/ngspice.cpp sim/sim_panel_base.cpp sim/sim_plot_colors.cpp diff --git a/eeschema/dialogs/dialog_signal_list.cpp b/eeschema/dialogs/dialog_signal_list.cpp index f78750d774..da2893c378 100644 --- a/eeschema/dialogs/dialog_signal_list.cpp +++ b/eeschema/dialogs/dialog_signal_list.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include diff --git a/eeschema/dialogs/dialog_sim_settings.cpp b/eeschema/dialogs/dialog_sim_settings.cpp index b4d68a548f..5510867e63 100644 --- a/eeschema/dialogs/dialog_sim_settings.cpp +++ b/eeschema/dialogs/dialog_sim_settings.cpp @@ -24,7 +24,7 @@ */ #include "dialog_sim_settings.h" -#include +#include #include #include diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.cpp b/eeschema/netlist_exporters/netlist_exporter_spice.cpp index 8c4b013297..69645a1019 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.cpp +++ b/eeschema/netlist_exporters/netlist_exporter_spice.cpp @@ -25,6 +25,7 @@ #include #include "netlist_exporter_spice.h" +#include "sim/ngspice_circuit_model.h" #include #include #include @@ -539,7 +540,17 @@ void NETLIST_EXPORTER_SPICE::WriteDirectives( OUTPUTFORMATTER& aFormatter, aFormatter.Print( 0, ".probe alli\n" ); for( const std::string& directive : m_directives ) - aFormatter.Print( 0, "%s\n", directive.c_str() ); + { + if( NGSPICE_CIRCUIT_MODEL::IsSimCommand( directive ) ) + { + if( aNetlistOptions & OPTION_SIM_COMMAND ) + aFormatter.Print( 0, "%s\n", directive.c_str() ); + } + else + { + aFormatter.Print( 0, "%s\n", directive.c_str() ); + } + } } diff --git a/eeschema/netlist_exporters/netlist_exporter_spice.h b/eeschema/netlist_exporters/netlist_exporter_spice.h index 23904f37ae..10ae7fff8d 100644 --- a/eeschema/netlist_exporters/netlist_exporter_spice.h +++ b/eeschema/netlist_exporters/netlist_exporter_spice.h @@ -48,11 +48,12 @@ class NETLIST_EXPORTER_SPICE : public NETLIST_EXPORTER_BASE public: enum OPTIONS { - OPTION_ADJUST_INCLUDE_PATHS = 0x10, - OPTION_ADJUST_PASSIVE_VALS = 0x20, - OPTION_SAVE_ALL_VOLTAGES = 0x40, - OPTION_SAVE_ALL_CURRENTS = 0x80, - OPTION_CUR_SHEET_AS_ROOT = 0x0100, + OPTION_ADJUST_INCLUDE_PATHS = 0x0010, + OPTION_ADJUST_PASSIVE_VALS = 0x0020, + OPTION_SAVE_ALL_VOLTAGES = 0x0040, + OPTION_SAVE_ALL_CURRENTS = 0x0080, + OPTION_CUR_SHEET_AS_ROOT = 0x0100, + OPTION_SIM_COMMAND = 0x0200, OPTION_DEFAULT_FLAGS = OPTION_ADJUST_INCLUDE_PATHS | OPTION_ADJUST_PASSIVE_VALS | OPTION_SAVE_ALL_VOLTAGES diff --git a/eeschema/sim/ngspice.cpp b/eeschema/sim/ngspice.cpp index 39a75d3068..ae102ef68a 100644 --- a/eeschema/sim/ngspice.cpp +++ b/eeschema/sim/ngspice.cpp @@ -28,7 +28,7 @@ #include // Needed for MSW compilation #include -#include "ngspice_helpers.h" +#include "ngspice_circuit_model.h" #include "ngspice.h" #include "spice_reporter.h" #include "spice_settings.h" diff --git a/eeschema/sim/ngspice_helpers.cpp b/eeschema/sim/ngspice_circuit_model.cpp similarity index 96% rename from eeschema/sim/ngspice_helpers.cpp rename to eeschema/sim/ngspice_circuit_model.cpp index 30dc92c0bd..9a00df6e9a 100644 --- a/eeschema/sim/ngspice_helpers.cpp +++ b/eeschema/sim/ngspice_circuit_model.cpp @@ -23,7 +23,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include "ngspice_helpers.h" +#include "ngspice_circuit_model.h" #include // for TO_UTF8 def #include #include @@ -149,8 +149,11 @@ bool NGSPICE_CIRCUIT_MODEL::ParseDCCommand( const wxString& aCmd, SPICE_DC_PARAM void NGSPICE_CIRCUIT_MODEL::WriteDirectives( OUTPUTFORMATTER& aFormatter, unsigned aNetlistOptions ) const { + if( GetSimCommandOverride().IsEmpty() ) + aNetlistOptions |= OPTION_SIM_COMMAND; + NETLIST_EXPORTER_SPICE::WriteDirectives( aFormatter, aNetlistOptions ); - if( GetSimCommandOverride() != "" ) + if( !GetSimCommandOverride().IsEmpty() ) aFormatter.Print( 0, "%s\n", TO_UTF8( GetSimCommandOverride() ) ); } diff --git a/eeschema/sim/ngspice_helpers.h b/eeschema/sim/ngspice_circuit_model.h similarity index 97% rename from eeschema/sim/ngspice_helpers.h rename to eeschema/sim/ngspice_circuit_model.h index 270b2f26ba..5479ab8efc 100644 --- a/eeschema/sim/ngspice_helpers.h +++ b/eeschema/sim/ngspice_circuit_model.h @@ -24,8 +24,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#ifndef NETLIST_EXPORTER_PSPICE_SIM_H -#define NETLIST_EXPORTER_PSPICE_SIM_H +#ifndef NGSPICE_CIRCUIT_MODEL_H +#define NGSPICE_CIRCUIT_MODEL_H #include #include @@ -155,4 +155,4 @@ private: int m_options; }; -#endif /* NETLIST_EXPORTER_PSPICE_SIM_H */ +#endif /* NGSPICE_CIRCUIT_MODEL_H */ diff --git a/eeschema/sim/sim_panel_base.cpp b/eeschema/sim/sim_panel_base.cpp index fec66e390d..a025a1ba31 100644 --- a/eeschema/sim/sim_panel_base.cpp +++ b/eeschema/sim/sim_panel_base.cpp @@ -27,7 +27,7 @@ #include "sim_panel_base.h" #include "sim_plot_frame.h" -#include "ngspice_helpers.h" +#include "ngspice_circuit_model.h" SIM_PANEL_BASE::SIM_PANEL_BASE() : m_simCommand( wxEmptyString ) diff --git a/eeschema/sim/sim_panel_base.h b/eeschema/sim/sim_panel_base.h index 5764c4001e..99645a45bc 100644 --- a/eeschema/sim/sim_panel_base.h +++ b/eeschema/sim/sim_panel_base.h @@ -27,7 +27,7 @@ #define __SIM_PLOT_PANEL_BASE_H #include "sim_types.h" -#include "ngspice_helpers.h" +#include "ngspice_circuit_model.h" #include #include #include diff --git a/eeschema/sim/sim_workbook.cpp b/eeschema/sim/sim_workbook.cpp index f9b9edd933..49c78b9dc5 100644 --- a/eeschema/sim/sim_workbook.cpp +++ b/eeschema/sim/sim_workbook.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2021 MikoĊ‚aj Wielgus - * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors. + * Copyright (C) 2021-2022 KiCad Developers, see AUTHORS.txt for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -32,7 +32,8 @@ SIM_WORKBOOK::SIM_WORKBOOK() : wxAuiNotebook() SIM_WORKBOOK::SIM_WORKBOOK( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, const wxSize& - aSize, long aStyle ) : wxAuiNotebook( aParent, aId, aPos, aSize, aStyle ) + aSize, long aStyle ) : + wxAuiNotebook( aParent, aId, aPos, aSize, aStyle ) { m_modified = false; } @@ -40,33 +41,49 @@ SIM_WORKBOOK::SIM_WORKBOOK( wxWindow* aParent, wxWindowID aId, const wxPoint& aP bool SIM_WORKBOOK::AddPage( wxWindow* page, const wxString& caption, bool select, const wxBitmap& bitmap ) { - bool res = wxAuiNotebook::AddPage( page, caption, select, bitmap ); - setModified( res ); - return res; + if( wxAuiNotebook::AddPage( page, caption, select, bitmap ) ) + { + setModified(); + return true; + } + + return false; } bool SIM_WORKBOOK::AddPage( wxWindow* page, const wxString& text, bool select, int imageId ) { - bool res = wxAuiNotebook::AddPage( page, text, select, imageId ); - setModified( res ); - return res; + if( wxAuiNotebook::AddPage( page, text, select, imageId ) ) + { + setModified(); + return true; + } + + return false; } bool SIM_WORKBOOK::DeleteAllPages() { - bool res = wxAuiNotebook::DeleteAllPages(); - setModified( res ); - return res; + if( wxAuiNotebook::DeleteAllPages() ) + { + setModified(); + return true; + } + + return false; } bool SIM_WORKBOOK::DeletePage( size_t page ) { - bool res = wxAuiNotebook::DeletePage( page ); - setModified( res ); - return res; + if( wxAuiNotebook::DeletePage( page ) ) + { + setModified(); + return true; + } + + return false; } @@ -74,30 +91,41 @@ bool SIM_WORKBOOK::AddTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aTitle, const wxString& aName, int aPoints, const double* aX, const double* aY, SIM_PLOT_TYPE aType ) { - bool res = aPlotPanel->addTrace( aTitle, aName, aPoints, aX, aY, aType ); - setModified( res ); - return res; + if( aPlotPanel->addTrace( aTitle, aName, aPoints, aX, aY, aType ) ) + { + setModified(); + return true; + } + + return false; } bool SIM_WORKBOOK::DeleteTrace( SIM_PLOT_PANEL* aPlotPanel, const wxString& aName ) { - bool res = aPlotPanel->deleteTrace( aName ); - setModified( res ); - return res; + if( aPlotPanel->deleteTrace( aName ) ) + { + setModified(); + return true; + } + + return false; } + void SIM_WORKBOOK::ClrModified() { m_modified = false; wxPostEvent( GetParent(), wxCommandEvent( EVT_WORKBOOK_CLR_MODIFIED ) ); } -void SIM_WORKBOOK::setModified( bool value ) + +void SIM_WORKBOOK::setModified() { - m_modified = value; + m_modified = true; wxPostEvent( GetParent(), wxCommandEvent( EVT_WORKBOOK_MODIFIED ) ); } + wxDEFINE_EVENT( EVT_WORKBOOK_MODIFIED, wxCommandEvent ); wxDEFINE_EVENT( EVT_WORKBOOK_CLR_MODIFIED, wxCommandEvent ); diff --git a/eeschema/sim/sim_workbook.h b/eeschema/sim/sim_workbook.h index 6ed0437484..6149949487 100644 --- a/eeschema/sim/sim_workbook.h +++ b/eeschema/sim/sim_workbook.h @@ -67,7 +67,7 @@ public: bool IsModified() const { return m_modified; } private: - void setModified( bool value = true ); + void setModified(); ///< Dirty bit, indicates something in the workbook has changed bool m_modified; diff --git a/eeschema/widgets/tuner_slider.cpp b/eeschema/widgets/tuner_slider.cpp index cccab8e6cf..078294aa79 100644 --- a/eeschema/widgets/tuner_slider.cpp +++ b/eeschema/widgets/tuner_slider.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include // log log1p expm1 #include // norm diff --git a/qa/unittests/eeschema/sim/test_ngspice_helpers.cpp b/qa/unittests/eeschema/sim/test_ngspice_helpers.cpp index 4508389611..c11b218051 100644 --- a/qa/unittests/eeschema/sim/test_ngspice_helpers.cpp +++ b/qa/unittests/eeschema/sim/test_ngspice_helpers.cpp @@ -36,7 +36,7 @@ #include #include #include -#include +#include class TEST_NGSPICE_HELPERS {