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 
170  void setIconsForMenuItems();
171 
178  void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
179 
185  void removePlot( const wxString& aPlotName, bool aErase = true );
186 
190  void updateNetlistExporter();
191 
199  bool updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel );
200 
204  void updateSignalList();
205 
209  void updateCursors();
210 
215  void updateTuners();
216 
220  void applyTuners();
221 
227  bool loadWorkbook( const wxString& aPath );
228 
234  bool saveWorkbook( const wxString& aPath );
235 
239  SIM_PLOT_TYPE GetXAxisType( SIM_TYPE aType ) const;
240 
241  // Menu handlers
242  void menuNewPlot( wxCommandEvent& aEvent ) override;
243  void menuOpenWorkbook( wxCommandEvent& event ) override;
244  void menuSaveWorkbook( wxCommandEvent& event ) override;
245 
246  void menuExit( wxCommandEvent& event ) override
247  {
248  Close();
249  }
250 
251  void menuSaveImage( wxCommandEvent& event ) override;
252  void menuSaveCsv( wxCommandEvent& event ) override;
253  void menuZoomIn( wxCommandEvent& event ) override;
254  void menuZoomOut( wxCommandEvent& event ) override;
255  void menuZoomFit( wxCommandEvent& event ) override;
256  void menuShowGrid( wxCommandEvent& event ) override;
257  void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
258  void menuShowLegend( wxCommandEvent& event ) override;
259  void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
260 
261  // Event handlers
262  void onPlotChanged( wxAuiNotebookEvent& event ) override;
263  void onPlotClose( wxAuiNotebookEvent& event ) override;
264 
265  void onSignalDblClick( wxMouseEvent& event ) override;
266  void onSignalRClick( wxListEvent& event ) override;
267 
268  void onSimulate( wxCommandEvent& event );
269  void onSettings( wxCommandEvent& event );
270  void onAddSignal( wxCommandEvent& event );
271  void onProbe( wxCommandEvent& event );
272  void onTune( wxCommandEvent& event );
273  void onShowNetlist( wxCommandEvent& event );
274 
275  void onClose( wxCloseEvent& aEvent );
276 
277  void onCursorUpdate( wxCommandEvent& aEvent );
278  void onSimUpdate( wxCommandEvent& aEvent );
279  void onSimReport( wxCommandEvent& aEvent );
280  void onSimStarted( wxCommandEvent& aEvent );
281  void onSimFinished( wxCommandEvent& aEvent );
282 
283  // adjust the sash dimension of splitter windows after reading
284  // the config settings
285  // must be called after the config settings are read, and once the
286  // frame is initialized (end of the Ctor)
287  void setSubWindowsSashSize();
288 
289  // Toolbar buttons
290  wxToolBarToolBase* m_toolSimulate;
291  wxToolBarToolBase* m_toolAddSignals;
292  wxToolBarToolBase* m_toolProbe;
293  wxToolBarToolBase* m_toolTune;
294  wxToolBarToolBase* m_toolSettings;
295 
297  std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
298  std::shared_ptr<SPICE_SIMULATOR> m_simulator;
300 
301  typedef std::map<wxString, TRACE_DESC> TRACE_MAP;
302 
303  struct PLOT_INFO
304  {
307 
309  wxString m_simCommand;
310  };
311 
313  std::map<SIM_PLOT_PANEL*, PLOT_INFO> m_plots;
314 
316  std::list<TUNER_SLIDER*> m_tuners;
317 
318  // Trick to preserve settings between runs:
319  // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
320  // Once created it will be not shown (shown only on request) during a session
321  // and will be destroyed only when closing the simulator frame.
323 
324  // Right click context menu for signals in the listbox
325  class SIGNAL_CONTEXT_MENU : public wxMenu
326  {
327  public:
328  SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
329 
330  private:
331  void onMenuEvent( wxMenuEvent& aEvent );
332 
333  const wxString& m_signal;
335 
337  {
341  };
342  };
343 
346 
350 
352  static wxString m_savedWorkbooksPath;
353 
354  // Variables for temporary storage:
359 };
360 
361 // Commands
362 wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
363 wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
364 
365 // Notifications
366 wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
367 wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
368 
369 #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
Load common frame parameters from a configuration file.
void setIconsForMenuItems()
Give icons to menuitems of the main menubar.
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:73
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
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.