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_COMPONENT;
51 
52 class SPICE_SIMULATOR;
54 
55 #include "sim_plot_panel.h"
56 #include "sim_panel_base.h"
57 
59 class TUNER_SLIDER;
60 
61 
64 {
65 public:
66  TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
67  SIM_PLOT_TYPE aType, const wxString& aParam );
68 
71  const TRACE_DESC& aDescription, SIM_PLOT_TYPE aNewType )
72  : TRACE_DESC( aExporter, aDescription.GetName(), aNewType, aDescription.GetParam() )
73  {
74  }
75 
76  const wxString& GetTitle() const
77  {
78  return m_title;
79  }
80 
81  const wxString& GetName() const
82  {
83  return m_name;
84  }
85 
86  const wxString& GetParam() const
87  {
88  return m_param;
89  }
90 
92  {
93  return m_type;
94  }
95 
96 private:
97  // Three basic parameters
99  wxString m_name;
100 
103 
105  wxString m_param;
106 
107  // Generated data
109  wxString m_title;
110 };
111 
112 
115 {
116 public:
118  SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
119  ~SIM_PLOT_FRAME();
120 
121  void StartSimulation( const wxString& aSimCommand = wxEmptyString );
122  void StopSimulation();
123  bool IsSimulationRunning();
124 
131  SIM_PANEL_BASE* NewPlotPanel( wxString aSimCommand );
132 
138  void AddVoltagePlot( const wxString& aNetName );
139 
146  void AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam );
147 
152  void AddTuner( SCH_COMPONENT* aComponent );
153 
161  void RemoveTuner( TUNER_SLIDER* aTuner, bool aErase = true );
162 
166  SIM_PLOT_PANEL* CurrentPlot() const;
167 
172 
177  bool GetPlotBgOpt() const { return m_plotUseWhiteBg; }
178 
179  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
180 
181  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
182 
184 
185  // Simulator doesn't host a tool framework
186  wxWindow* GetToolCanvas() const override { return nullptr; }
187 
188 private:
192  void setIconsForMenuItems();
193 
198  {
199  return dynamic_cast<SIM_PANEL_BASE*>( m_plotNotebook->GetCurrentPage() );
200  }
201 
209  void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
210 
217  void removePlot( const wxString& aPlotName, bool aErase = true );
218 
222  void updateNetlistExporter();
223 
232  bool updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel );
233 
237  void updateSignalList();
238 
243  void updateTuners();
244 
248  void applyTuners();
249 
256  bool loadWorkbook( const wxString& aPath );
257 
264  bool saveWorkbook( const wxString& aPath );
265 
269  SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
270 
271  // Menu handlers
272  void menuNewPlot( wxCommandEvent& aEvent ) override;
273  void menuOpenWorkbook( wxCommandEvent& event ) override;
274  void menuSaveWorkbook( wxCommandEvent& event ) override;
275 
276  void menuExit( wxCommandEvent& event ) override
277  {
278  Close();
279  }
280 
281  void menuSaveImage( wxCommandEvent& event ) override;
282  void menuSaveCsv( wxCommandEvent& event ) override;
283  void menuZoomIn( wxCommandEvent& event ) override;
284  void menuZoomOut( wxCommandEvent& event ) override;
285  void menuZoomFit( wxCommandEvent& event ) override;
286  void menuShowGrid( wxCommandEvent& event ) override;
287  void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
288  void menuShowLegend( wxCommandEvent& event ) override;
289  void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
290  void menuShowDotted( wxCommandEvent& event ) override;
291  void menuShowDottedUpdate( wxUpdateUIEvent& event ) override;
292  void menuWhiteBackground( wxCommandEvent& event ) override;
293  void menuShowWhiteBackgroundUpdate( wxUpdateUIEvent& event ) override
294  {
295  event.Check( m_plotUseWhiteBg );
296  }
297 
298  // Event handlers
299  void onPlotChanged( wxAuiNotebookEvent& event ) override;
300  void onPlotClose( wxAuiNotebookEvent& event ) override;
301 
302  void onSignalDblClick( wxMouseEvent& event ) override;
303  void onSignalRClick( wxListEvent& event ) override;
304 
305  void onSimulate( wxCommandEvent& event );
306  void onSettings( wxCommandEvent& event );
307  void onAddSignal( wxCommandEvent& event );
308  void onProbe( wxCommandEvent& event );
309  void onTune( wxCommandEvent& event );
310  void onShowNetlist( wxCommandEvent& event );
311 
312  void doCloseWindow() override;
313 
314  void onCursorUpdate( wxCommandEvent& aEvent );
315  void onSimUpdate( wxCommandEvent& aEvent );
316  void onSimReport( wxCommandEvent& aEvent );
317  void onSimStarted( wxCommandEvent& aEvent );
318  void onSimFinished( wxCommandEvent& aEvent );
319 
320  // adjust the sash dimension of splitter windows after reading
321  // the config settings
322  // must be called after the config settings are read, and once the
323  // frame is initialized (end of the Ctor)
324  void setSubWindowsSashSize();
325 
326  // Toolbar buttons
327  wxToolBarToolBase* m_toolSimulate;
328  wxToolBarToolBase* m_toolAddSignals;
329  wxToolBarToolBase* m_toolProbe;
330  wxToolBarToolBase* m_toolTune;
331  wxToolBarToolBase* m_toolSettings;
332 
334  std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
335  std::shared_ptr<SPICE_SIMULATOR> m_simulator;
337 
338  typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
339 
340  struct PLOT_INFO
341  {
344 
346  wxString m_simCommand;
347  };
348 
350  std::map<SIM_PANEL_BASE*, PLOT_INFO> m_plots;
351 
353  std::list<TUNER_SLIDER*> m_tuners;
354 
355  // Trick to preserve settings between runs:
356  // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
357  // Once created it will be not shown (shown only on request) during a session
358  // and will be destroyed only when closing the simulator frame.
360 
361  // Right click context menu for signals in the listbox
362  class SIGNAL_CONTEXT_MENU : public wxMenu
363  {
364  public:
365  SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
366 
367  private:
368  void onMenuEvent( wxMenuEvent& aEvent );
369 
370  const wxString& m_signal;
372 
374  {
378  };
379  };
380 
383 
387 
389  static wxString m_savedWorkbooksPath;
390 
393 
394  // Variables for temporary storage:
400  unsigned int m_plotNumber;
401 };
402 
403 // Commands
404 wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
405 wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
406 
407 // Notifications
408 wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
409 wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
410 
411 #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 menuWhiteBackground(wxCommandEvent &event) override
void onSignalDblClick(wxMouseEvent &event) override
const wxString & GetTitle() const
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
Map of plot panels and associated data.
TRACE_DESC(const NETLIST_EXPORTER_PSPICE_SIM &aExporter, const TRACE_DESC &aDescription, SIM_PLOT_TYPE aNewType)
std::list< TUNER_SLIDER * > m_tuners
void doCloseWindow() override
SIM_PLOT_TYPE GetType() const
wxString m_title
< Title displayed in the signal list/plot legend
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.
Trace descriptor class
Schematic editor (Eeschema) main window.
void onSimUpdate(wxCommandEvent &aEvent)
void menuOpenWorkbook(wxCommandEvent &event) override
void menuShowGrid(wxCommandEvent &event) override
void menuZoomIn(wxCommandEvent &event) override
std::map< SIM_PANEL_BASE *, PLOT_INFO > m_plots
List of currently displayed tuners.
void menuZoomOut(wxCommandEvent &event) override
SIM_THREAD_REPORTER * m_reporter
std::shared_ptr< SPICE_SIMULATOR > m_simulator
bool updatePlot(const TRACE_DESC &aDescriptor, SIM_PLOT_PANEL *aPanel)
Update plot in a particular SIM_PLOT_PANEL.
SIM_PANEL_BASE * m_welcomePanel
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)
const wxString & GetParam() const
wxAuiNotebook * m_plotNotebook
SCH_EDIT_FRAME * m_schematicFrame
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:260
wxToolBarToolBase * m_toolAddSignals
int m_splitterTuneValuesSashPosition
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
TRACE_DESC(const NETLIST_EXPORTER_PSPICE_SIM &aExporter, const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
Modifies an existing TRACE_DESC simulation type.
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
Info panel.
void onCursorUpdate(wxCommandEvent &aEvent)
wxWindow * GetToolCanvas() const override
Canvas access.
DIALOG_SIM_SETTINGS * m_settingsDlg
const wxString & GetName() const
std::unique_ptr< NETLIST_EXPORTER_PSPICE_SIM > m_exporter
void updateNetlistExporter()
Reload the current schematic for the netlist exporter.
void menuExit(wxCommandEvent &event) override
void onSimulate(wxCommandEvent &event)
wxString m_param
TRACE_MAP m_traces
< Map of the traces displayed on the plot
SIGNAL_CONTEXT_MENU(const wxString &aSignal, SIM_PLOT_FRAME *aPlotFrame)
void onProbe(wxCommandEvent &event)
void updateSignalList()
Update the list of currently plotted signals.
wxDECLARE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
SIM_PLOT_TYPE m_type
Name of the signal parameter.
unsigned int m_plotNumber
Schematic symbol object.
Definition: sch_symbol.h:79
int m_splitterSignalsSashPosition
SIM_PLOT_PANEL * CurrentPlot() const
Return the currently opened plot panel (or NULL if there is none).
std::map< wxString, TRACE_DESC > TRACE_MAP
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 AddTuner(SCH_COMPONENT *aComponent)
Add a tuner for a component.
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)
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
wxString m_name
< Name of the measured net/device
SIM_PLOT_FRAME(KIWAY *aKiway, wxWindow *aParent)
Constructor.