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 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 class SIM_PLOT_PANEL;
56 class TUNER_SLIDER;
57 
60 {
61 public:
62  TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
63  SIM_PLOT_TYPE aType, const wxString& aParam );
64 
67  const TRACE_DESC& aDescription, SIM_PLOT_TYPE aNewType )
68  : TRACE_DESC( aExporter, aDescription.GetName(), aNewType, aDescription.GetParam() )
69  {
70  }
71 
72  const wxString& GetTitle() const
73  {
74  return m_title;
75  }
76 
77  const wxString& GetName() const
78  {
79  return m_name;
80  }
81 
82  const wxString& GetParam() const
83  {
84  return m_param;
85  }
86 
88  {
89  return m_type;
90  }
91 
92 private:
93  // Three basic parameters
95  wxString m_name;
96 
99 
101  wxString m_param;
102 
103  // Generated data
105  wxString m_title;
106 };
107 
110 {
111 public:
113  SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
114  ~SIM_PLOT_FRAME();
115 
116  void StartSimulation();
117  void StopSimulation();
118  bool IsSimulationRunning();
119 
126  SIM_PLOT_PANEL* NewPlotPanel( SIM_TYPE aSimType );
127 
132  void AddVoltagePlot( const wxString& aNetName );
133 
139  void AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam );
140 
144  void AddTuner( SCH_COMPONENT* aComponent );
145 
152  void RemoveTuner( TUNER_SLIDER* aTuner, bool aErase = true );
153 
157  SIM_PLOT_PANEL* CurrentPlot() const;
158 
159 private:
160  void LoadSettings( wxConfigBase* aCfg ) override;
161  void SaveSettings( wxConfigBase* aCfg ) override;
162 
169  void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
170 
176  void removePlot( const wxString& aPlotName, bool aErase = true );
177 
181  void updateNetlistExporter();
182 
190  bool updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel );
191 
195  void updateSignalList();
196 
200  void updateCursors();
201 
206  void updateTuners();
207 
211  void applyTuners();
212 
218  bool loadWorkbook( const wxString& aPath );
219 
225  bool saveWorkbook( const wxString& aPath );
226 
230  SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
231 
232  // Menu handlers
233  void menuNewPlot( wxCommandEvent& aEvent ) override;
234  void menuOpenWorkbook( wxCommandEvent& event ) override;
235  void menuSaveWorkbook( wxCommandEvent& event ) override;
236 
237  void menuExit( wxCommandEvent& event ) override
238  {
239  Close();
240  }
241 
242  void menuSaveImage( wxCommandEvent& event ) override;
243  void menuSaveCsv( wxCommandEvent& event ) override;
244  void menuZoomIn( wxCommandEvent& event ) override;
245  void menuZoomOut( wxCommandEvent& event ) override;
246  void menuZoomFit( wxCommandEvent& event ) override;
247  void menuShowGrid( wxCommandEvent& event ) override;
248  void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
249  void menuShowLegend( wxCommandEvent& event ) override;
250  void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
251 
252  // Event handlers
253  void onPlotChanged( wxAuiNotebookEvent& event ) override;
254  void onPlotClose( wxAuiNotebookEvent& event ) override;
255 
256  void onSignalDblClick( wxMouseEvent& event ) override;
257  void onSignalRClick( wxListEvent& event ) override;
258 
259  void onSimulate( wxCommandEvent& event );
260  void onSettings( wxCommandEvent& event );
261  void onAddSignal( wxCommandEvent& event );
262  void onProbe( wxCommandEvent& event );
263  void onTune( wxCommandEvent& event );
264 
265  void onClose( wxCloseEvent& aEvent );
266 
267  void onCursorUpdate( wxCommandEvent& aEvent );
268  void onSimUpdate( wxCommandEvent& aEvent );
269  void onSimReport( wxCommandEvent& aEvent );
270  void onSimStarted( wxCommandEvent& aEvent );
271  void onSimFinished( wxCommandEvent& aEvent );
272 
273  // adjust the sash dimension of splitter windows after reading
274  // the config settings
275  // must be called after the config settings are read, and once the
276  // frame is initialized (end of the Ctor)
277  void setSubWindowsSashSize();
278 
279  // Toolbar buttons
280  wxToolBarToolBase* m_toolSimulate;
281  wxToolBarToolBase* m_toolAddSignals;
282  wxToolBarToolBase* m_toolProbe;
283  wxToolBarToolBase* m_toolTune;
284  wxToolBarToolBase* m_toolSettings;
285 
287  std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
290 
291  typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
292 
293  struct PLOT_INFO
294  {
296  TRACE_MAP m_traces;
297 
299  wxString m_simCommand;
300  };
301 
303  std::map<SIM_PLOT_PANEL*, PLOT_INFO> m_plots;
304 
306  std::list<TUNER_SLIDER*> m_tuners;
307 
308  // Trick to preserve settings between runs:
309  // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
310  // Once created it will be not shown (shown only on request) during a session
311  // and will be destroyed only when closing the simulator frame.
313 
314  // Right click context menu for signals in the listbox
315  class SIGNAL_CONTEXT_MENU : public wxMenu
316  {
317  public:
318  SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
319 
320  private:
321  void onMenuEvent( wxMenuEvent& aEvent );
322 
323  const wxString& m_signal;
325 
327  {
331  };
332  };
333 
336 
340 
342  static wxString m_savedWorkbooksPath;
343 
344  // Variables for temporary storage:
349 };
350 
351 // Commands
352 wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
353 wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
354 
355 // Notifications
356 wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
357 wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
358 
359 #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:118
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:69
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.