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-2021 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_SYMBOL;
51 
52 class SPICE_SIMULATOR;
55 
56 #include "sim_plot_panel.h"
57 #include "sim_panel_base.h"
58 #include "sim_workbook.h"
59 
61 class TUNER_SLIDER;
62 
67 {
68 public:
69  SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
71 
72  void StartSimulation( const wxString& aSimCommand = wxEmptyString );
73  void StopSimulation();
74 
81  SIM_PANEL_BASE* NewPlotPanel( wxString aSimCommand );
82 
88  void AddVoltagePlot( const wxString& aNetName );
89 
96  void AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam );
97 
101  void AddTuner( SCH_SYMBOL* aSymbol );
102 
110  void RemoveTuner( TUNER_SLIDER* aTuner, bool aErase = true );
111 
116 
121 
126  bool GetPlotBgOpt() const { return m_plotUseWhiteBg; }
127 
128  void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
129 
130  void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
131 
133 
134  // Simulator doesn't host a tool framework
135  wxWindow* GetToolCanvas() const override { return nullptr; }
136 
137  std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& GetSimulatorSettings();
138 
139 private:
144  void initWorkbook();
145 
149  void updateTitle();
150 
154  void setIconsForMenuItems();
155 
163  void addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam );
164 
170  void removePlot( const wxString& aPlotName );
171 
175  void updateNetlistExporter();
176 
187  bool updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam,
188  SIM_PLOT_PANEL* aPlotPanel );
189 
193  void updateSignalList();
194 
200  void updateTuners();
201 
205  void applyTuners();
206 
213  bool loadWorkbook( const wxString& aPath );
214 
221  bool saveWorkbook( const wxString& aPath );
222 
226  wxString getDefaultFilename();
227 
231  wxString getDefaultPath();
232 
237  {
238  return dynamic_cast<SIM_PANEL_BASE*>( m_workbook->GetCurrentPage() );
239  }
240 
244  wxString getCurrentSimCommand() const
245  {
246  if( getCurrentPlotWindow() == nullptr )
247  return m_exporter->GetSheetSimCommand();
248  else
250  }
251 
255  SIM_PLOT_TYPE getXAxisType( SIM_TYPE aType ) const;
256 
257  // Menu handlers
258  void menuNewPlot( wxCommandEvent& aEvent ) override;
259  void menuOpenWorkbook( wxCommandEvent& event ) override;
260  void menuSaveWorkbook( wxCommandEvent& event ) override;
261  void menuSaveWorkbookAs( wxCommandEvent& event ) override;
262 
263  void menuExit( wxCommandEvent& event ) override
264  {
265  Close();
266  }
267 
268  void menuSaveImage( wxCommandEvent& event ) override;
269  void menuSaveCsv( wxCommandEvent& event ) override;
270  void menuZoomIn( wxCommandEvent& event ) override;
271  void menuZoomOut( wxCommandEvent& event ) override;
272  void menuZoomFit( wxCommandEvent& event ) override;
273  void menuShowGrid( wxCommandEvent& event ) override;
274  void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
275  void menuShowLegend( wxCommandEvent& event ) override;
276  void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
277  void menuShowDotted( wxCommandEvent& event ) override;
278  void menuShowDottedUpdate( wxUpdateUIEvent& event ) override;
279  void menuWhiteBackground( wxCommandEvent& event ) override;
280  void menuShowWhiteBackgroundUpdate( wxUpdateUIEvent& event ) override
281  {
282  event.Check( m_plotUseWhiteBg );
283  }
284 
285  void menuSimulateUpdate( wxUpdateUIEvent& event ) override;
286  void menuAddSignalsUpdate( wxUpdateUIEvent& event ) override;
287  void menuProbeUpdate( wxUpdateUIEvent& event ) override;
288  void menuTuneUpdate( wxUpdateUIEvent& event ) override;
289 
290  // Event handlers
291  void onPlotClose( wxAuiNotebookEvent& event ) override;
292  void onPlotClosed( wxAuiNotebookEvent& event ) override;
293  void onPlotChanged( wxAuiNotebookEvent& event ) override;
294  void onPlotDragged( wxAuiNotebookEvent& event ) override;
295 
296  void onSignalDblClick( wxMouseEvent& event ) override;
297  void onSignalRClick( wxListEvent& event ) override;
298 
299  void onWorkbookModified( wxCommandEvent& event );
300  void onWorkbookClrModified( wxCommandEvent& event );
301 
302  void onSimulate( wxCommandEvent& event );
303  void onSettings( wxCommandEvent& event );
304  void onAddSignal( wxCommandEvent& event );
305  void onProbe( wxCommandEvent& event );
306  void onTune( wxCommandEvent& event );
307  void onShowNetlist( wxCommandEvent& event );
308 
309  bool canCloseWindow( wxCloseEvent& aEvent ) override;
310  void doCloseWindow() override;
311 
312  void onCursorUpdate( wxCommandEvent& aEvent );
313  void onSimUpdate( wxCommandEvent& aEvent );
314  void onSimReport( wxCommandEvent& aEvent );
315  void onSimStarted( wxCommandEvent& aEvent );
316  void onSimFinished( wxCommandEvent& aEvent );
317 
318  // adjust the sash dimension of splitter windows after reading
319  // the config settings
320  // must be called after the config settings are read, and once the
321  // frame is initialized (end of the Ctor)
322  void setSubWindowsSashSize();
323 
324  // Toolbar buttons
325  wxToolBarToolBase* m_toolSimulate;
326  wxToolBarToolBase* m_toolAddSignals;
327  wxToolBarToolBase* m_toolProbe;
328  wxToolBarToolBase* m_toolTune;
329  wxToolBarToolBase* m_toolSettings;
330 
332  std::unique_ptr<NETLIST_EXPORTER_PSPICE_SIM> m_exporter;
333  std::shared_ptr<SPICE_SIMULATOR> m_simulator;
335 
337  std::list<TUNER_SLIDER*> m_tuners;
338 
339  // Trick to preserve settings between runs:
340  // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
341  // Once created it will be not shown (shown only on request) during a session
342  // and will be destroyed only when closing the simulator frame.
344 
345  // Right click context menu for signals in the listbox
346  class SIGNAL_CONTEXT_MENU : public wxMenu
347  {
348  public:
349  SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
350 
351  private:
352  void onMenuEvent( wxMenuEvent& aEvent );
353 
354  const wxString& m_signal;
356 
358  {
362  };
363  };
364 
367 
371 
372  // Variables for temporary storage:
378  unsigned int m_plotNumber;
380 };
381 
382 // Commands
383 wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
384 wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
385 
386 // Notifications
387 wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
388 wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
389 
390 #endif // __sim_plot_frame__
void onAddSignal(wxCommandEvent &event)
bool saveWorkbook(const wxString &aPath)
Save plot settings to a file.
wxToolBarToolBase * m_toolProbe
void setIconsForMenuItems()
Give icons to menuitems of the main menubar.
void onSimStarted(wxCommandEvent &aEvent)
void RemoveTuner(TUNER_SLIDER *aTuner, bool aErase=true)
Remove an existing tuner.
bool GetPlotBgOpt() const
wxImageList * m_signalsIconColorList
void onPlotChanged(wxAuiNotebookEvent &event) override
void onPlotDragged(wxAuiNotebookEvent &event) override
void menuWhiteBackground(wxCommandEvent &event) override
void onSignalDblClick(wxMouseEvent &event) override
void onPlotClosed(wxAuiNotebookEvent &event) override
SIM_PANEL_BASE * NewPlotPanel(wxString aSimCommand)
Create a new plot panel for a given simulation type and adds it to the main notebook.
int m_splitterPlotAndConsoleSashPosition
void menuZoomFit(wxCommandEvent &event) override
void initWorkbook()
Load the currently active workbook stored in the project settings.
bool canCloseWindow(wxCloseEvent &aEvent) override
std::list< TUNER_SLIDER * > m_tuners
void doCloseWindow() override
Class SIM_PLOT_FRAME_BASE.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void menuNewPlot(wxCommandEvent &aEvent) override
void applyTuners()
Apply component values specified using tuner sliders to the current netlist.
SIM_PLOT_PANEL * GetCurrentPlot() const
Return the currently opened plot panel (or NULL if there is none).
wxString getDefaultPath()
Return the default path to be used in file browser dialog.
void AddVoltagePlot(const wxString &aNetName)
Add a voltage plot for a given net name.
void AddCurrentPlot(const wxString &aDeviceName, const wxString &aParam)
Add a current plot for a particular device.
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & GetSimulatorSettings()
Schematic editor (Eeschema) main window.
wxString getDefaultFilename()
Return the default filename (with extension) to be used in file browser dialog.
void onWorkbookModified(wxCommandEvent &event)
void onSimUpdate(wxCommandEvent &aEvent)
bool updatePlot(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam, SIM_PLOT_PANEL *aPlotPanel)
Update plot in a particular SIM_PLOT_PANEL.
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
List of currently displayed tuners.
std::shared_ptr< SPICE_SIMULATOR > m_simulator
void menuProbeUpdate(wxUpdateUIEvent &event) override
void AddTuner(SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
void menuSaveCsv(wxCommandEvent &event) override
void onPlotClose(wxAuiNotebookEvent &event) override
void StartSimulation(const wxString &aSimCommand=wxEmptyString)
SCH_EDIT_FRAME * m_schematicFrame
void setSubWindowsSashSize()
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:81
SIM_PLOT_PANEL * m_lastSimPlot
imagelists used to add a small colored icon to signal names and cursors name, the same color as the c...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:99
void removePlot(const wxString &aPlotName)
Remove a plot with a specific title.
wxString getCurrentSimCommand() const
void onSimReport(wxCommandEvent &aEvent)
SIM_TYPE
< Possible simulation types
Definition: sim_types.h:31
void menuTuneUpdate(wxUpdateUIEvent &event) override
void onSimFinished(wxCommandEvent &aEvent)
void menuShowWhiteBackgroundUpdate(wxUpdateUIEvent &event) override
void onShowNetlist(wxCommandEvent &event)
void menuShowLegendUpdate(wxUpdateUIEvent &event) override
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:260
void menuSaveWorkbookAs(wxCommandEvent &event) override
wxToolBarToolBase * m_toolAddSignals
SIM_PANEL_BASE * getCurrentPlotWindow() const
Return the currently opened plot panel (or NULL if there is none).
int m_splitterTuneValuesSashPosition
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
void onSignalRClick(wxListEvent &event) override
void onWorkbookClrModified(wxCommandEvent &event)
void menuAddSignalsUpdate(wxUpdateUIEvent &event) override
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)
Load plot settings from a file.
void onCursorUpdate(wxCommandEvent &aEvent)
const wxString & GetSimCommand(const SIM_PANEL_BASE *aPlotPanel)
Definition: sim_workbook.h:62
wxWindow * GetToolCanvas() const override
Canvas access.
DIALOG_SIM_SETTINGS * m_settingsDlg
std::unique_ptr< NETLIST_EXPORTER_PSPICE_SIM > m_exporter
void updateNetlistExporter()
Reload the current schematic for the netlist exporter.
void menuExit(wxCommandEvent &event) override
Schematic symbol object.
Definition: sch_symbol.h:78
void onSimulate(wxCommandEvent &event)
SIGNAL_CONTEXT_MENU(const wxString &aSignal, SIM_PLOT_FRAME *aPlotFrame)
void onProbe(wxCommandEvent &event)
void menuSimulateUpdate(wxUpdateUIEvent &event) override
void updateSignalList()
Update the list of currently plotted signals.
SIM_WORKBOOK * m_workbook
wxDECLARE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
SIM_PLOT_TYPE getXAxisType(SIM_TYPE aType) const
Return X axis for a given simulation type.
unsigned int m_plotNumber
int m_splitterSignalsSashPosition
void updateTitle()
Set the main window title bar text.
void menuShowDotted(wxCommandEvent &event) override
int m_splitterLeftRightSashPosition
void menuShowDottedUpdate(wxUpdateUIEvent &event) override
const NETLIST_EXPORTER_PSPICE_SIM * GetExporter() const
Return the netlist exporter object used for simulations.
Custom widget to handle quick component values modification and simulation on the fly.
Definition: tuner_slider.h:42
void menuShowGridUpdate(wxUpdateUIEvent &event) override
void menuSaveWorkbook(wxCommandEvent &event) override
SIM_PLOT_TYPE
Definition: sim_types.h:46
Panel that was used as the most recent one for simulations.
void addPlot(const wxString &aName, SIM_PLOT_TYPE aType, const wxString &aParam)
Add a new plot to the current panel.
void onSettings(wxCommandEvent &event)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
wxToolBarToolBase * m_toolTune
void onMenuEvent(wxMenuEvent &aEvent)
Storage for simulator specific settings.
Special netlist exporter flavor that allows one to override simulation commands.
void updateTuners()
Filter out tuners for components that do not exist anymore.
wxToolBarToolBase * m_toolSettings
SIM_PLOT_FRAME(KIWAY *aKiway, wxWindow *aParent)