KiCad PCB EDA Suite
sim_plot_frame.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2016 CERN
5  * Copyright (C) 2017-2021 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
8  * @author Maciej Suminski <maciej.suminski@cern.ch>
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 3
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, you may find one here:
22  * https://www.gnu.org/licenses/gpl-3.0.html
23  * or you may search the http://www.gnu.org website for the version 3 license,
24  * or you may write to the Free Software Foundation, Inc.,
25  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
26  */
27 
28 #ifndef __SIM_PLOT_FRAME__
29 #define __SIM_PLOT_FRAME__
30 
37 #include "sim_plot_frame_base.h"
38 #include "sim_types.h"
39 
40 #include <kiway_player.h>
42 
43 #include <wx/event.h>
44 
45 #include <list>
46 #include <memory>
47 #include <map>
48 
49 class SCH_EDIT_FRAME;
50 class SCH_SYMBOL;
51 
52 class SPICE_SIMULATOR;
55 
56 #include "sim_plot_panel.h"
57 #include "sim_panel_base.h"
58 #include "sim_workbook.h"
59 
61 class TUNER_SLIDER;
62 
67 {
68 public:
69  SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
71 
72  void StartSimulation( const wxString& aSimCommand = wxEmptyString );
73  void StopSimulation();
74  bool IsSimulationRunning();
75 
82  SIM_PANEL_BASE* NewPlotPanel( wxString aSimCommand );
83 
89  void AddVoltagePlot( const wxString& aNetName );
90 
97  void AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam );
98 
102  void AddTuner( SCH_SYMBOL* aSymbol );
103 
111  void RemoveTuner( TUNER_SLIDER* aTuner, bool aErase = true );
112 
116  SIM_PLOT_PANEL* CurrentPlot() const;
117 
122 
127  bool GetPlotBgOpt() const { return m_plotUseWhiteBg; }
128 
129  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
130 
131  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
132 
134 
135  // Simulator doesn't host a tool framework
136  wxWindow* GetToolCanvas() const override { return nullptr; }
137 
138  std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& GetSimulatorSettings();
139 
140 private:
145  void initWorkbook();
146 
150  void updateTitle();
151 
155  void updateWorkbook();
156 
161  void updateFrame();
162 
166  void setIconsForMenuItems();
167 
172  {
173  return dynamic_cast<SIM_PANEL_BASE*>( m_plotNotebook->GetCurrentPage() );
174  }
175 
183  void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
184 
191  void removePlot( const wxString& aPlotName, bool aErase = true );
192 
196  void updateNetlistExporter();
197 
206  bool updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam,
207  SIM_PLOT_PANEL* aPanel );
208 
212  void updateSignalList();
213 
219  void updateTuners();
220 
224  void applyTuners();
225 
232  bool loadWorkbook( const wxString& aPath );
233 
240  bool saveWorkbook( const wxString& aPath );
241 
245  SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
246 
247  // Menu handlers
248  void menuNewPlot( wxCommandEvent& aEvent ) override;
249  void menuOpenWorkbook( wxCommandEvent& event ) override;
250  void menuSaveWorkbook( wxCommandEvent& event ) override;
251  void menuSaveWorkbookAs( wxCommandEvent& event ) override;
252 
253  void menuExit( wxCommandEvent& event ) override
254  {
255  Close();
256  }
257 
258  void menuSaveImage( wxCommandEvent& event ) override;
259  void menuSaveCsv( wxCommandEvent& event ) override;
260  void menuZoomIn( wxCommandEvent& event ) override;
261  void menuZoomOut( wxCommandEvent& event ) override;
262  void menuZoomFit( wxCommandEvent& event ) override;
263  void menuShowGrid( wxCommandEvent& event ) override;
264  void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
265  void menuShowLegend( wxCommandEvent& event ) override;
266  void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
267  void menuShowDotted( wxCommandEvent& event ) override;
268  void menuShowDottedUpdate( wxUpdateUIEvent& event ) override;
269  void menuWhiteBackground( wxCommandEvent& event ) override;
270  void menuShowWhiteBackgroundUpdate( wxUpdateUIEvent& event ) override
271  {
272  event.Check( m_plotUseWhiteBg );
273  }
274 
275  // Event handlers
276  void onPlotClose( wxAuiNotebookEvent& event ) override;
277  void onPlotClosed( wxAuiNotebookEvent& event ) override;
278  void onPlotChanged( wxAuiNotebookEvent& event ) override;
279  void onPlotDragged( wxAuiNotebookEvent& event ) override;
280 
281  void onSignalDblClick( wxMouseEvent& event ) override;
282  void onSignalRClick( wxListEvent& event ) override;
283 
284  void onSimulate( wxCommandEvent& event );
285  void onSettings( wxCommandEvent& event );
286  void onAddSignal( wxCommandEvent& event );
287  void onProbe( wxCommandEvent& event );
288  void onTune( wxCommandEvent& event );
289  void onShowNetlist( wxCommandEvent& event );
290 
291  bool canCloseWindow( wxCloseEvent& aEvent ) override;
292  void doCloseWindow() override;
293 
294  void onCursorUpdate( wxCommandEvent& aEvent );
295  void onSimUpdate( wxCommandEvent& aEvent );
296  void onSimReport( wxCommandEvent& aEvent );
297  void onSimStarted( wxCommandEvent& aEvent );
298  void onSimFinished( wxCommandEvent& aEvent );
299 
300  // adjust the sash dimension of splitter windows after reading
301  // the config settings
302  // must be called after the config settings are read, and once the
303  // frame is initialized (end of the Ctor)
304  void setSubWindowsSashSize();
305 
306  // Toolbar buttons
307  wxToolBarToolBase* m_toolSimulate;
308  wxToolBarToolBase* m_toolAddSignals;
309  wxToolBarToolBase* m_toolProbe;
310  wxToolBarToolBase* m_toolTune;
311  wxToolBarToolBase* m_toolSettings;
312 
314  std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
315  std::shared_ptr<SPICE_SIMULATOR> m_simulator;
317 
319  std::unique_ptr<SIM_WORKBOOK> m_workbook;
320 
322  std::list<TUNER_SLIDER*> m_tuners;
323 
324  // Trick to preserve settings between runs:
325  // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
326  // Once created it will be not shown (shown only on request) during a session
327  // and will be destroyed only when closing the simulator frame.
329 
330  // Right click context menu for signals in the listbox
331  class SIGNAL_CONTEXT_MENU : public wxMenu
332  {
333  public:
334  SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
335 
336  private:
337  void onMenuEvent( wxMenuEvent& aEvent );
338 
339  const wxString& m_signal;
341 
343  {
347  };
348  };
349 
352 
356 
358  static wxString m_savedWorkbooksPath;
359 
360  // Variables for temporary storage:
366  unsigned int m_plotNumber;
367 };
368 
369 // Commands
370 wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
371 wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
372 
373 // Notifications
374 wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
375 wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
376 
377 #endif // __sim_plot_frame__
void onAddSignal(wxCommandEvent &event)
bool saveWorkbook(const wxString &aPath)
Save plot settings to a file.
wxToolBarToolBase * m_toolProbe
void setIconsForMenuItems()
Give icons to menuitems of the main menubar.
void onSimStarted(wxCommandEvent &aEvent)
void RemoveTuner(TUNER_SLIDER *aTuner, bool aErase=true)
Remove an existing tuner.
bool GetPlotBgOpt() const
wxImageList * m_signalsIconColorList
A string to store the path of saved workbooks during a session.
void onPlotChanged(wxAuiNotebookEvent &event) override
void onPlotDragged(wxAuiNotebookEvent &event) override
void menuWhiteBackground(wxCommandEvent &event) override
void onSignalDblClick(wxMouseEvent &event) override
void onPlotClosed(wxAuiNotebookEvent &event) override
SIM_PANEL_BASE * NewPlotPanel(wxString aSimCommand)
Create a new plot panel for a given simulation type and adds it to the main notebook.
int m_splitterPlotAndConsoleSashPosition
void menuZoomFit(wxCommandEvent &event) override
void initWorkbook()
Load the currently active workbook stored in the project settings.
void updateFrame()
Update the frame to match the changes to the workbook.
bool canCloseWindow(wxCloseEvent &aEvent) override
std::list< TUNER_SLIDER * > m_tuners
void doCloseWindow() override
Class SIM_PLOT_FRAME_BASE.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void menuNewPlot(wxCommandEvent &aEvent) override
void applyTuners()
Apply component values specified using tuner sliders to the current netlist.
void AddVoltagePlot(const wxString &aNetName)
Add a voltage plot for a given net name.
void AddCurrentPlot(const wxString &aDeviceName, const wxString &aParam)
Add a current plot for a particular device.
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & GetSimulatorSettings()
Schematic editor (Eeschema) main window.
std::unique_ptr< SIM_WORKBOOK > m_workbook
List of currently displayed tuners.
void onSimUpdate(wxCommandEvent &aEvent)
void menuOpenWorkbook(wxCommandEvent &event) override
void menuShowGrid(wxCommandEvent &event) override
void menuZoomIn(wxCommandEvent &event) override
void menuZoomOut(wxCommandEvent &event) override
SIM_THREAD_REPORTER * m_reporter
Stores the data that can be preserved across simulator sessions.
std::shared_ptr< SPICE_SIMULATOR > m_simulator
void AddTuner(SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
SIM_PLOT_TYPE GetXAxisType(SIM_TYPE aType) const
Return X axis for a given simulation type.
void menuSaveCsv(wxCommandEvent &event) override
void onPlotClose(wxAuiNotebookEvent &event) override
void StartSimulation(const wxString &aSimCommand=wxEmptyString)
wxAuiNotebook * m_plotNotebook
SCH_EDIT_FRAME * m_schematicFrame
void updateWorkbook()
Update the workbook to match the changes in the frame.
void setSubWindowsSashSize()
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
SIM_PLOT_PANEL * m_lastSimPlot
imagelists used to add a small colored icon to signal names and cursors name, the same color as the c...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
void onSimReport(wxCommandEvent &aEvent)
SIM_TYPE
< Possible simulation types
Definition: sim_types.h:31
void onSimFinished(wxCommandEvent &aEvent)
void menuShowWhiteBackgroundUpdate(wxUpdateUIEvent &event) override
void onShowNetlist(wxCommandEvent &event)
void menuShowLegendUpdate(wxUpdateUIEvent &event) override
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:258
void menuSaveWorkbookAs(wxCommandEvent &event) override
wxToolBarToolBase * m_toolAddSignals
int m_splitterTuneValuesSashPosition
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
SIM_PANEL_BASE * currentPlotWindow() const
Return the currently opened plot panel (or NULL if there is none).
void onSignalRClick(wxListEvent &event) override
bool IsSimulationRunning()
void menuShowLegend(wxCommandEvent &event) override
void onTune(wxCommandEvent &event)
wxToolBarToolBase * m_toolSimulate
void menuSaveImage(wxCommandEvent &event) override
Implementing SIM_PLOT_FRAME_BASE.
bool loadWorkbook(const wxString &aPath)
Load plot settings from a file.
static wxString m_savedWorkbooksPath
void onCursorUpdate(wxCommandEvent &aEvent)
wxWindow * GetToolCanvas() const override
Canvas access.
DIALOG_SIM_SETTINGS * m_settingsDlg
std::unique_ptr< NETLIST_EXPORTER_PSPICE_SIM > m_exporter
void updateNetlistExporter()
Reload the current schematic for the netlist exporter.
void menuExit(wxCommandEvent &event) override
Schematic symbol object.
Definition: sch_symbol.h:78
void onSimulate(wxCommandEvent &event)
SIGNAL_CONTEXT_MENU(const wxString &aSignal, SIM_PLOT_FRAME *aPlotFrame)
void onProbe(wxCommandEvent &event)
bool updatePlot(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam, SIM_PLOT_PANEL *aPanel)
Update plot in a particular SIM_PLOT_PANEL.
void updateSignalList()
Update the list of currently plotted signals.
wxDECLARE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
unsigned int m_plotNumber
int m_splitterSignalsSashPosition
void updateTitle()
Set the main window title bar text.
SIM_PLOT_PANEL * CurrentPlot() const
Return the currently opened plot panel (or NULL if there is none).
void menuShowDotted(wxCommandEvent &event) override
int m_splitterLeftRightSashPosition
void menuShowDottedUpdate(wxUpdateUIEvent &event) override
const NETLIST_EXPORTER_PSPICE_SIM * GetExporter() const
Return the netlist exporter object used for simulations.
void removePlot(const wxString &aPlotName, bool aErase=true)
Remove a plot with a specific title.
Custom widget to handle quick component values modification and simulation on the fly.
Definition: tuner_slider.h:42
void menuShowGridUpdate(wxUpdateUIEvent &event) override
void menuSaveWorkbook(wxCommandEvent &event) override
SIM_PLOT_TYPE
Definition: sim_types.h:46
Panel that was used as the most recent one for simulations.
void addPlot(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
Add a new plot to the current panel.
void onSettings(wxCommandEvent &event)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
wxToolBarToolBase * m_toolTune
void onMenuEvent(wxMenuEvent &aEvent)
Storage for simulator specific settings.
Special netlist exporter flavor that allows one to override simulation commands.
void updateTuners()
Filter out tuners for components that do not exist anymore.
wxToolBarToolBase * m_toolSettings
SIM_PLOT_FRAME(KIWAY *aKiway, wxWindow *aParent)