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 
162  const NETLIST_EXPORTER_PSPICE_SIM* GetExporter() const;
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  {
302  TRACE_MAP m_traces;
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  {
336  HIDE_CURSOR
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__
wxString m_simCommand
Spice directive used to execute the simulation
wxToolBarToolBase * m_toolProbe
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 ...
int m_splitterPlotAndConsoleSashPosition
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
Trace descriptor class
Schematic editor (Eeschema) main window.
SIM_THREAD_REPORTER * m_reporter
std::shared_ptr< SPICE_SIMULATOR > m_simulator
SCH_EDIT_FRAME * m_schematicFrame
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
SIM_TYPE
Possible simulation types
Definition: sim_types.h:29
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)
wxToolBarToolBase * m_toolSimulate
Implementing SIM_PLOT_FRAME_BASE.
static wxString m_savedWorkbooksPath
A string to store the path of saved workbooks during a session
DIALOG_SIM_SETTINGS * m_settingsDlg
std::unique_ptr< NETLIST_EXPORTER_PSPICE_SIM > m_exporter
void menuExit(wxCommandEvent &event) override
wxString m_param
Name of the signal parameter
TRACE_MAP m_traces
Map of the traces displayed on the plot
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
std::map< wxString, TRACE_DESC > TRACE_MAP
int m_splitterLeftRightSashPosition
Custom widget to handle quick component values modification and simulation on the fly...
Definition: tuner_slider.h:40
SIM_PLOT_TYPE
Possible plot types
Definition: sim_types.h:35
wxToolBarToolBase * m_toolTune
Special netlist exporter flavor that allows one to override simulation commands.
wxToolBarToolBase * m_toolSettings
wxString m_name
Name of the measured net/device