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  * @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
6  * @author Maciej Suminski <maciej.suminski@cern.ch>
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * https://www.gnu.org/licenses/gpl-3.0.html
21  * or you may search the http://www.gnu.org website for the version 3 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 #ifndef __sim_plot_frame__
27 #define __sim_plot_frame__
28 
33 #include "sim_plot_frame_base.h"
34 #include "sim_types.h"
35 
36 #include <kiway_player.h>
38 
39 #include <wx/event.h>
40 
41 #include <list>
42 #include <memory>
43 #include <map>
44 
45 class SCH_EDIT_FRAME;
46 class SCH_COMPONENT;
47 
48 class SPICE_SIMULATOR;
50 class SIM_PLOT_PANEL;
52 class TUNER_SLIDER;
53 
56 {
57 public:
58  TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
59  SIM_PLOT_TYPE aType, const wxString& aParam );
60 
63  const TRACE_DESC& aDescription, SIM_PLOT_TYPE aNewType )
64  : TRACE_DESC( aExporter, aDescription.GetName(), aNewType, aDescription.GetParam() )
65  {
66  }
67 
68  const wxString& GetTitle() const
69  {
70  return m_title;
71  }
72 
73  const wxString& GetName() const
74  {
75  return m_name;
76  }
77 
78  const wxString& GetParam() const
79  {
80  return m_param;
81  }
82 
84  {
85  return m_type;
86  }
87 
88 private:
89  // Three basic parameters
91  wxString m_name;
92 
95 
97  wxString m_param;
98 
99  // Generated data
101  wxString m_title;
102 };
103 
106 {
107 public:
109  SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
110  ~SIM_PLOT_FRAME();
111 
112  void StartSimulation();
113  void StopSimulation();
114  bool IsSimulationRunning();
115 
122  SIM_PLOT_PANEL* NewPlotPanel( SIM_TYPE aSimType );
123 
128  void AddVoltagePlot( const wxString& aNetName );
129 
135  void AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam );
136 
140  void AddTuner( SCH_COMPONENT* aComponent );
141 
148  void RemoveTuner( TUNER_SLIDER* aTuner, bool aErase = true );
149 
153  SIM_PLOT_PANEL* CurrentPlot() const;
154 
155 private:
156  void LoadSettings( wxConfigBase* aCfg ) override;
157  void SaveSettings( wxConfigBase* aCfg ) override;
158 
165  void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
166 
172  void removePlot( const wxString& aPlotName, bool aErase = true );
173 
177  void updateNetlistExporter();
178 
186  bool updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel );
187 
191  void updateSignalList();
192 
196  void updateCursors();
197 
202  void updateTuners();
203 
207  void applyTuners();
208 
214  bool loadWorkbook( const wxString& aPath );
215 
221  bool saveWorkbook( const wxString& aPath );
222 
226  SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
227 
228  // Menu handlers
229  void menuNewPlot( wxCommandEvent& aEvent ) override;
230  void menuOpenWorkbook( wxCommandEvent& event ) override;
231  void menuSaveWorkbook( wxCommandEvent& event ) override;
232 
233  void menuExit( wxCommandEvent& event ) override
234  {
235  Close();
236  }
237 
238  void menuSaveImage( wxCommandEvent& event ) override;
239  void menuSaveCsv( wxCommandEvent& event ) override;
240  void menuZoomIn( wxCommandEvent& event ) override;
241  void menuZoomOut( wxCommandEvent& event ) override;
242  void menuZoomFit( wxCommandEvent& event ) override;
243  void menuShowGrid( wxCommandEvent& event ) override;
244  void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
245  void menuShowLegend( wxCommandEvent& event ) override;
246  void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
247 
248  // Event handlers
249  void onPlotChanged( wxAuiNotebookEvent& event ) override;
250  void onPlotClose( wxAuiNotebookEvent& event ) override;
251 
252  void onSignalDblClick( wxMouseEvent& event ) override;
253  void onSignalRClick( wxListEvent& event ) override;
254 
255  void onSimulate( wxCommandEvent& event );
256  void onSettings( wxCommandEvent& event );
257  void onAddSignal( wxCommandEvent& event );
258  void onProbe( wxCommandEvent& event );
259  void onTune( wxCommandEvent& event );
260 
261  void onClose( wxCloseEvent& aEvent );
262 
263  void onCursorUpdate( wxCommandEvent& aEvent );
264  void onSimUpdate( wxCommandEvent& aEvent );
265  void onSimReport( wxCommandEvent& aEvent );
266  void onSimStarted( wxCommandEvent& aEvent );
267  void onSimFinished( wxCommandEvent& aEvent );
268 
269  // adjust the sash dimension of splitter windows after reading
270  // the config settings
271  // must be called after the config settings are read, and once the
272  // frame is initialized (end of the Ctor)
273  void setSubWindowsSashSize();
274 
275  // Toolbar buttons
276  wxToolBarToolBase* m_toolSimulate;
277  wxToolBarToolBase* m_toolAddSignals;
278  wxToolBarToolBase* m_toolProbe;
279  wxToolBarToolBase* m_toolTune;
280  wxToolBarToolBase* m_toolSettings;
281 
283  std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
286 
287  typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
288 
289  struct PLOT_INFO
290  {
292  TRACE_MAP m_traces;
293 
295  wxString m_simCommand;
296  };
297 
299  std::map<SIM_PLOT_PANEL*, PLOT_INFO> m_plots;
300 
302  std::list<TUNER_SLIDER*> m_tuners;
303 
304  // Trick to preserve settings between runs:
305  // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
306  // Once created it will be not shown (shown only on request) during a session
307  // and will be destroyed only when closing the simulator frame.
309 
310  // Right click context menu for signals in the listbox
311  class SIGNAL_CONTEXT_MENU : public wxMenu
312  {
313  public:
314  SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
315 
316  private:
317  void onMenuEvent( wxMenuEvent& aEvent );
318 
319  const wxString& m_signal;
321 
323  {
327  };
328  };
329 
332 
336 
338  static wxString m_savedWorkbooksPath;
339 
340  // Variables for temporary storage:
345 };
346 
347 // Commands
348 wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
349 wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
350 
351 // Notifications
352 wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
353 wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
354 
355 #endif // __sim_plot_frame__
void onAddSignal(wxCommandEvent &event)
wxString m_simCommand
Spice directive used to execute the simulation
bool saveWorkbook(const wxString &aPath)
Saves plot settings to a file.
wxToolBarToolBase * m_toolProbe
void LoadSettings(wxConfigBase *aCfg) override
Function LoadSettings loads common frame parameters from a configuration file.
void onSimStarted(wxCommandEvent &aEvent)
void RemoveTuner(TUNER_SLIDER *aTuner, bool aErase=true)
Removes an existing tuner.
const wxString & GetName() const
wxImageList * m_signalsIconColorList
imagelists uset to add a small coloured icon to signal names and cursors name, the same color as the ...
void onPlotChanged(wxAuiNotebookEvent &event) override
void onSignalDblClick(wxMouseEvent &event) override
SIM_PLOT_TYPE GetXAxisType(SIM_TYPE aType) const
Returns X axis for a given simulation type.
int m_splitterPlotAndConsoleSashPosition
void menuZoomFit(wxCommandEvent &event) override
SIM_PLOT_TYPE GetType() const
TRACE_DESC(const NETLIST_EXPORTER_PSPICE_SIM &aExporter, const TRACE_DESC &aDescription, SIM_PLOT_TYPE aNewType)
Modifies an existing TRACE_DESC simulation type
std::list< TUNER_SLIDER * > m_tuners
List of currently displayed tuners
wxString m_title
Title displayed in the signal list/plot legend
Class SIM_PLOT_FRAME_BASE.
const wxString & GetParam() const
void menuNewPlot(wxCommandEvent &aEvent) override
void applyTuners()
Applies component values specified using tunder sliders to the current netlist.
void AddVoltagePlot(const wxString &aNetName)
Adds a voltage plot for a given net name.
void AddCurrentPlot(const wxString &aDeviceName, const wxString &aParam)
Adds a current plot for a particular device.
Trace descriptor class
Schematic editor (Eeschema) main window.
Definition: schframe.h:117
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
bool updatePlot(const TRACE_DESC &aDescriptor, SIM_PLOT_PANEL *aPanel)
Updates plot in a particular SIM_PLOT_PANEL.
void updateCursors()
Updates the cursor values list.
void menuSaveCsv(wxCommandEvent &event) override
void onPlotClose(wxAuiNotebookEvent &event) override
SCH_EDIT_FRAME * m_schematicFrame
void setSubWindowsSashSize()
std::map< SIM_PLOT_PANEL *, PLOT_INFO > m_plots
Map of plot panels and associated data
SIM_PLOT_PANEL * m_lastSimPlot
Panel that was used as the most recent one for simulations
void onSimReport(wxCommandEvent &aEvent)
SIM_TYPE
Possible simulation types
Definition: sim_types.h:29
void onSimFinished(wxCommandEvent &aEvent)
void menuShowLegendUpdate(wxUpdateUIEvent &event) override
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:257
wxToolBarToolBase * m_toolAddSignals
int m_splitterTuneValuesSashPosition
TRACE_DESC(const NETLIST_EXPORTER_PSPICE_SIM &aExporter, const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
void onSignalRClick(wxListEvent &event) override
bool IsSimulationRunning()
SPICE_SIMULATOR * m_simulator
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)
Loads plot settings from a file.
static wxString m_savedWorkbooksPath
A string to store the path of saved workbooks during a session
void onCursorUpdate(wxCommandEvent &aEvent)
DIALOG_SIM_SETTINGS * m_settingsDlg
std::unique_ptr< NETLIST_EXPORTER_PSPICE_SIM > m_exporter
void updateNetlistExporter()
Reloads the current schematic for the netlist exporter.
void menuExit(wxCommandEvent &event) override
void onSimulate(wxCommandEvent &event)
wxString m_param
Name of the signal parameter
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()
Updates the list of currently plotted signals.
wxDECLARE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
const wxString & GetTitle() const
SIM_PLOT_TYPE m_type
Type of the signal
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:68
int m_splitterSignalsSashPosition
SIM_PLOT_PANEL * CurrentPlot() const
Returns the currently opened plot panel (or NULL if there is none).
std::map< wxString, TRACE_DESC > TRACE_MAP
int m_splitterLeftRightSashPosition
void removePlot(const wxString &aPlotName, bool aErase=true)
Removes a plot with a specific title.
void SaveSettings(wxConfigBase *aCfg) override
Function SaveSettings saves common frame parameters to a configuration data file. ...
Custom widget to handle quick component values modification and simulation on the fly...
Definition: tuner_slider.h:40
void AddTuner(SCH_COMPONENT *aComponent)
Adds a tuner for a component.
void menuShowGridUpdate(wxUpdateUIEvent &event) override
void menuSaveWorkbook(wxCommandEvent &event) override
SIM_PLOT_TYPE
Possible plot types
Definition: sim_types.h:35
void addPlot(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
Adds a new plot to the current panel.
void onSettings(wxCommandEvent &event)
void onClose(wxCloseEvent &aEvent)
wxToolBarToolBase * m_toolTune
void onMenuEvent(wxMenuEvent &aEvent)
SIM_PLOT_PANEL * NewPlotPanel(SIM_TYPE aSimType)
Creates a new plot panel for a given simulation type and adds it to the main notebook.
Special netlist exporter flavor that allows to override simulation commands.
void updateTuners()
Filters 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.