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 
163 
164 private:
165  void LoadSettings( wxConfigBase* aCfg ) override;
166  void SaveSettings( wxConfigBase* aCfg ) override;
167 
174  void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
175 
181  void removePlot( const wxString& aPlotName, bool aErase = true );
182 
186  void updateNetlistExporter();
187 
195  bool updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel );
196 
200  void updateSignalList();
201 
205  void updateCursors();
206 
211  void updateTuners();
212 
216  void applyTuners();
217 
223  bool loadWorkbook( const wxString& aPath );
224 
230  bool saveWorkbook( const wxString& aPath );
231 
235  SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
236 
237  // Menu handlers
238  void menuNewPlot( wxCommandEvent& aEvent ) override;
239  void menuOpenWorkbook( wxCommandEvent& event ) override;
240  void menuSaveWorkbook( wxCommandEvent& event ) override;
241 
242  void menuExit( wxCommandEvent& event ) override
243  {
244  Close();
245  }
246 
247  void menuSaveImage( wxCommandEvent& event ) override;
248  void menuSaveCsv( wxCommandEvent& event ) override;
249  void menuZoomIn( wxCommandEvent& event ) override;
250  void menuZoomOut( wxCommandEvent& event ) override;
251  void menuZoomFit( wxCommandEvent& event ) override;
252  void menuShowGrid( wxCommandEvent& event ) override;
253  void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
254  void menuShowLegend( wxCommandEvent& event ) override;
255  void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
256 
257  // Event handlers
258  void onPlotChanged( wxAuiNotebookEvent& event ) override;
259  void onPlotClose( wxAuiNotebookEvent& event ) override;
260 
261  void onSignalDblClick( wxMouseEvent& event ) override;
262  void onSignalRClick( wxListEvent& event ) override;
263 
264  void onSimulate( wxCommandEvent& event );
265  void onSettings( wxCommandEvent& event );
266  void onAddSignal( wxCommandEvent& event );
267  void onProbe( wxCommandEvent& event );
268  void onTune( wxCommandEvent& event );
269  void onShowNetlist( wxCommandEvent& event );
270 
271  void onClose( wxCloseEvent& aEvent );
272 
273  void onCursorUpdate( wxCommandEvent& aEvent );
274  void onSimUpdate( wxCommandEvent& aEvent );
275  void onSimReport( wxCommandEvent& aEvent );
276  void onSimStarted( wxCommandEvent& aEvent );
277  void onSimFinished( wxCommandEvent& aEvent );
278 
279  // adjust the sash dimension of splitter windows after reading
280  // the config settings
281  // must be called after the config settings are read, and once the
282  // frame is initialized (end of the Ctor)
283  void setSubWindowsSashSize();
284 
285  // Toolbar buttons
286  wxToolBarToolBase* m_toolSimulate;
287  wxToolBarToolBase* m_toolAddSignals;
288  wxToolBarToolBase* m_toolProbe;
289  wxToolBarToolBase* m_toolTune;
290  wxToolBarToolBase* m_toolSettings;
291 
293  std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
294  std::shared_ptr<SPICE_SIMULATOR> m_simulator;
296 
297  typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
298 
299  struct PLOT_INFO
300  {
303 
305  wxString m_simCommand;
306  };
307 
309  std::map<SIM_PLOT_PANEL*, PLOT_INFO> m_plots;
310 
312  std::list<TUNER_SLIDER*> m_tuners;
313 
314  // Trick to preserve settings between runs:
315  // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
316  // Once created it will be not shown (shown only on request) during a session
317  // and will be destroyed only when closing the simulator frame.
319 
320  // Right click context menu for signals in the listbox
321  class SIGNAL_CONTEXT_MENU : public wxMenu
322  {
323  public:
324  SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
325 
326  private:
327  void onMenuEvent( wxMenuEvent& aEvent );
328 
329  const wxString& m_signal;
331 
333  {
337  };
338  };
339 
342 
346 
348  static wxString m_savedWorkbooksPath;
349 
350  // Variables for temporary storage:
355 };
356 
357 // Commands
358 wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
359 wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
360 
361 // Notifications
362 wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
363 wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
364 
365 #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.
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
const wxString & GetTitle() const
int m_splitterPlotAndConsoleSashPosition
void menuZoomFit(wxCommandEvent &event) override
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
SIM_PLOT_TYPE GetType() const
wxString m_title
Title displayed in the signal list/plot legend
Class SIM_PLOT_FRAME_BASE.
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.
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
std::shared_ptr< SPICE_SIMULATOR > m_simulator
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.
SIM_PLOT_TYPE GetXAxisType(SIM_TYPE aType) const
Returns X axis for a given simulation type.
void menuSaveCsv(wxCommandEvent &event) override
void onPlotClose(wxAuiNotebookEvent &event) override
const wxString & GetParam() const
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 onShowNetlist(wxCommandEvent &event)
void menuShowLegendUpdate(wxUpdateUIEvent &event) override
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
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()
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
const wxString & GetName() const
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)
SIM_PLOT_TYPE m_type
Type of the signal
Class SCH_COMPONENT describes a real schematic component.
Definition: sch_component.h:70
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
const NETLIST_EXPORTER_PSPICE_SIM * GetExporter() const
Returns the netlist exporter object used for simulations.
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 one 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.