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 <[email protected]>
8 * @author Maciej Suminski <[email protected]>
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
49class SCH_EDIT_FRAME;
50class SCH_SYMBOL;
51
52class SPICE_SIMULATOR;
55
56#include "sim_plot_panel.h"
57#include "sim_panel_base.h"
58#include "sim_workbook.h"
59
61class TUNER_SLIDER;
62
67{
68public:
69 SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent );
71
72 void StartSimulation( const wxString& aSimCommand = wxEmptyString );
73
80 SIM_PANEL_BASE* NewPlotPanel( wxString aSimCommand );
81
87 void AddVoltagePlot( const wxString& aNetName );
88
95 void AddCurrentPlot( const wxString& aDeviceName );
96
100 void AddTuner( SCH_SYMBOL* aSymbol );
101
109 void RemoveTuner( TUNER_SLIDER* aTuner, bool aErase = true );
110
119 void UpdateTunerValue( SCH_SYMBOL* aSymbol, int aId, const wxString& aValue );
120
125
129 const NGSPICE_CIRCUIT_MODEL* GetExporter() const;
130
135 bool GetPlotBgOpt() const { return m_plotUseWhiteBg; }
136
137 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
138
139 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
140
142
143 // Simulator doesn't host a tool framework
144 wxWindow* GetToolCanvas() const override { return nullptr; }
145
146 std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& GetSimulatorSettings();
147
148private:
153 void initWorkbook();
154
158 void updateTitle();
159
164
172 void addPlot( const wxString& aName, SIM_PLOT_TYPE aType );
173
179 void removePlot( const wxString& aPlotName );
180
191 bool updatePlot( const wxString& aName, SIM_PLOT_TYPE aType, SIM_PLOT_PANEL* aPlotPanel );
192
196 void updateSignalList();
197
203 void updateTuners();
204
208 void applyTuners();
209
216 bool loadWorkbook( const wxString& aPath );
217
224 bool saveWorkbook( const wxString& aPath );
225
229 wxString getDefaultFilename();
230
234 wxString getDefaultPath();
235
240 {
241 return dynamic_cast<SIM_PANEL_BASE*>( m_workbook->GetCurrentPage() );
242 }
243
247 wxString getCurrentSimCommand() const
248 {
249 if( getCurrentPlotWindow() == nullptr )
250 return m_circuitModel->GetSheetSimCommand();
251 else
253 }
254
258 SIM_PLOT_TYPE getXAxisType( SIM_TYPE aType ) const;
259
260 // Menu handlers
261 void menuNewPlot( wxCommandEvent& aEvent ) override;
262 void menuOpenWorkbook( wxCommandEvent& event ) override;
263 void menuSaveWorkbook( wxCommandEvent& event ) override;
264 void menuSaveWorkbookAs( wxCommandEvent& event ) override;
265
266 void menuExit( wxCommandEvent& event ) override
267 {
268 Close();
269 }
270
271 void menuSaveImage( wxCommandEvent& event ) override;
272 void menuSaveCsv( wxCommandEvent& event ) override;
273 void menuZoomIn( wxCommandEvent& event ) override;
274 void menuZoomOut( wxCommandEvent& event ) override;
275 void menuZoomFit( wxCommandEvent& event ) override;
276 void menuShowGrid( wxCommandEvent& event ) override;
277 void menuShowGridUpdate( wxUpdateUIEvent& event ) override;
278 void menuShowLegend( wxCommandEvent& event ) override;
279 void menuShowLegendUpdate( wxUpdateUIEvent& event ) override;
280 void menuShowDotted( wxCommandEvent& event ) override;
281 void menuShowDottedUpdate( wxUpdateUIEvent& event ) override;
282 void menuWhiteBackground( wxCommandEvent& event ) override;
283 void menuShowWhiteBackgroundUpdate( wxUpdateUIEvent& event ) override
284 {
285 event.Check( m_plotUseWhiteBg );
286 }
287
288 void menuSimulateUpdate( wxUpdateUIEvent& event ) override;
289 void menuAddSignalsUpdate( wxUpdateUIEvent& event ) override;
290 void menuProbeUpdate( wxUpdateUIEvent& event ) override;
291 void menuTuneUpdate( wxUpdateUIEvent& event ) override;
292
293 // Event handlers
294 void onPlotClose( wxAuiNotebookEvent& event ) override;
295 void onPlotClosed( wxAuiNotebookEvent& event ) override;
296 void onPlotChanged( wxAuiNotebookEvent& event ) override;
297 void onPlotDragged( wxAuiNotebookEvent& event ) override;
298
299 void onSignalDblClick( wxMouseEvent& event ) override;
300 void onSignalRClick( wxListEvent& event ) override;
301
302 void onWorkbookModified( wxCommandEvent& event );
303 void onWorkbookClrModified( wxCommandEvent& event );
304
305 void onSimulate( wxCommandEvent& event );
306 void onSettings( wxCommandEvent& event );
307 void onAddSignal( wxCommandEvent& event );
308 void onProbe( wxCommandEvent& event );
309 void onTune( wxCommandEvent& event );
310 void onShowNetlist( wxCommandEvent& event );
311
312 bool canCloseWindow( wxCloseEvent& aEvent ) override;
313 void doCloseWindow() override;
314
315 void onCursorUpdate( wxCommandEvent& aEvent );
316 void onSimUpdate( wxCommandEvent& aEvent );
317 void onSimReport( wxCommandEvent& aEvent );
318 void onSimStarted( wxCommandEvent& aEvent );
319 void onSimFinished( wxCommandEvent& aEvent );
320
321 // adjust the sash dimension of splitter windows after reading
322 // the config settings
323 // must be called after the config settings are read, and once the
324 // frame is initialized (end of the Ctor)
326
327 // Toolbar buttons
328 wxToolBarToolBase* m_toolSimulate;
329 wxToolBarToolBase* m_toolAddSignals;
330 wxToolBarToolBase* m_toolProbe;
331 wxToolBarToolBase* m_toolTune;
332 wxToolBarToolBase* m_toolSettings;
333
335 std::shared_ptr<NGSPICE_CIRCUIT_MODEL> m_circuitModel;
336 std::shared_ptr<SPICE_SIMULATOR> m_simulator;
338
340 std::list<TUNER_SLIDER*> m_tuners;
341
342 // Trick to preserve settings between runs:
343 // the DIALOG_SIM_SETTINGS is not destroyed after closing the dialog.
344 // Once created it will be not shown (shown only on request) during a session
345 // and will be destroyed only when closing the simulator frame.
347
348 // Right click context menu for signals in the listbox
349 class SIGNAL_CONTEXT_MENU : public wxMenu
350 {
351 public:
352 SIGNAL_CONTEXT_MENU( const wxString& aSignal, SIM_PLOT_FRAME* aPlotFrame );
353
354 private:
355 void onMenuEvent( wxMenuEvent& aEvent );
356
357 const wxString& m_signal;
359
361 {
365 };
366 };
367
370
374
375 // Variables for temporary storage:
381 unsigned int m_plotNumber;
383};
384
385// Commands
386wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
387wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
388
389// Notifications
390wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
391wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
392
393#endif // __sim_plot_frame__
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:101
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:267
Special netlist exporter flavor that allows one to override simulation commands.
Schematic editor (Eeschema) main window.
Schematic symbol object.
Definition: sch_symbol.h:79
Panel that was used as the most recent one for simulations.
SIGNAL_CONTEXT_MENU(const wxString &aSignal, SIM_PLOT_FRAME *aPlotFrame)
void onMenuEvent(wxMenuEvent &aEvent)
Class SIM_PLOT_FRAME_BASE.
SIM_WORKBOOK * m_workbook
Implementing SIM_PLOT_FRAME_BASE.
void setSubWindowsSashSize()
int m_splitterSignalsSashPosition
void menuShowWhiteBackgroundUpdate(wxUpdateUIEvent &event) override
void onShowNetlist(wxCommandEvent &event)
void setIconsForMenuItems()
Give icons to menuitems of the main menubar.
void onProbe(wxCommandEvent &event)
void AddVoltagePlot(const wxString &aNetName)
Add a voltage plot for a given net name.
void menuShowLegendUpdate(wxUpdateUIEvent &event) override
const NGSPICE_CIRCUIT_MODEL * GetExporter() const
Return the netlist exporter object used for simulations.
void onCursorUpdate(wxCommandEvent &aEvent)
void onAddSignal(wxCommandEvent &event)
void onPlotDragged(wxAuiNotebookEvent &event) override
wxString getDefaultPath()
Return the default path to be used in file browser dialog.
void onSignalRClick(wxListEvent &event) override
void RemoveTuner(TUNER_SLIDER *aTuner, bool aErase=true)
Remove an existing tuner.
void onSimReport(wxCommandEvent &aEvent)
void menuZoomIn(wxCommandEvent &event) override
void updateSignalList()
Update the list of currently plotted signals.
void menuWhiteBackground(wxCommandEvent &event) override
wxWindow * GetToolCanvas() const override
Canvas access.
void menuSaveWorkbook(wxCommandEvent &event) override
void onSimStarted(wxCommandEvent &aEvent)
wxToolBarToolBase * m_toolTune
void menuShowDotted(wxCommandEvent &event) override
wxToolBarToolBase * m_toolAddSignals
SIM_THREAD_REPORTER * m_reporter
List of currently displayed tuners.
DIALOG_SIM_SETTINGS * m_settingsDlg
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
wxToolBarToolBase * m_toolSimulate
void AddTuner(SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
void menuSimulateUpdate(wxUpdateUIEvent &event) override
void menuAddSignalsUpdate(wxUpdateUIEvent &event) override
bool loadWorkbook(const wxString &aPath)
Load plot settings from a file.
void onSimUpdate(wxCommandEvent &aEvent)
bool saveWorkbook(const wxString &aPath)
Save plot settings to a file.
void menuExit(wxCommandEvent &event) override
void onWorkbookClrModified(wxCommandEvent &event)
wxToolBarToolBase * m_toolProbe
void onPlotChanged(wxAuiNotebookEvent &event) override
void AddCurrentPlot(const wxString &aDeviceName)
Add a current plot for a particular device.
void updateTitle()
Set the main window title bar text.
void menuSaveCsv(wxCommandEvent &event) override
void updateTuners()
Filter out tuners for components that do not exist anymore.
SIM_PLOT_FRAME(KIWAY *aKiway, wxWindow *aParent)
void onWorkbookModified(wxCommandEvent &event)
void onSignalDblClick(wxMouseEvent &event) override
void StartSimulation(const wxString &aSimCommand=wxEmptyString)
void menuShowLegend(wxCommandEvent &event) override
int m_splitterTuneValuesSashPosition
bool GetPlotBgOpt() const
SIM_PANEL_BASE * m_lastSimPlot
imagelists used to add a small colored icon to signal names and cursors name, the same color as the c...
void onPlotClosed(wxAuiNotebookEvent &event) override
void onSimulate(wxCommandEvent &event)
void menuShowGridUpdate(wxUpdateUIEvent &event) override
wxString getDefaultFilename()
Return the default filename (with extension) to be used in file browser dialog.
void menuShowDottedUpdate(wxUpdateUIEvent &event) override
wxToolBarToolBase * m_toolSettings
void menuSaveWorkbookAs(wxCommandEvent &event) override
void onPlotClose(wxAuiNotebookEvent &event) override
bool updatePlot(const wxString &aName, SIM_PLOT_TYPE aType, SIM_PLOT_PANEL *aPlotPanel)
Update plot in a particular SIM_PLOT_PANEL.
bool canCloseWindow(wxCloseEvent &aEvent) override
SIM_PLOT_PANEL * GetCurrentPlot() const
Return the currently opened plot panel (or NULL if there is none).
void doCloseWindow() override
wxString getCurrentSimCommand() const
void menuTuneUpdate(wxUpdateUIEvent &event) override
void initWorkbook()
Load the currently active workbook stored in the project settings.
std::list< TUNER_SLIDER * > m_tuners
SIM_PANEL_BASE * getCurrentPlotWindow() const
Return the currently opened plot panel (or NULL if there is none).
void addPlot(const wxString &aName, SIM_PLOT_TYPE aType)
Add a new plot to the current panel.
void applyTuners()
Apply component values specified using tuner sliders to the current netlist.
void removePlot(const wxString &aPlotName)
Remove a plot with a specific title.
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
std::shared_ptr< SPICE_SIMULATOR_SETTINGS > & GetSimulatorSettings()
void menuShowGrid(wxCommandEvent &event) override
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void onSimFinished(wxCommandEvent &aEvent)
void onSettings(wxCommandEvent &event)
void menuSaveImage(wxCommandEvent &event) override
void UpdateTunerValue(SCH_SYMBOL *aSymbol, int aId, const wxString &aValue)
Safely update a field of the associated symbol without dereferencing the symbol.
SIM_PANEL_BASE * NewPlotPanel(wxString aSimCommand)
Create a new plot panel for a given simulation type and adds it to the main notebook.
void onTune(wxCommandEvent &event)
int m_splitterLeftRightSashPosition
SCH_EDIT_FRAME * m_schematicFrame
void menuNewPlot(wxCommandEvent &aEvent) override
void menuOpenWorkbook(wxCommandEvent &event) override
void menuZoomOut(wxCommandEvent &event) override
wxImageList * m_signalsIconColorList
std::shared_ptr< NGSPICE_CIRCUIT_MODEL > m_circuitModel
std::shared_ptr< SPICE_SIMULATOR > m_simulator
SIM_PLOT_TYPE getXAxisType(SIM_TYPE aType) const
Return X axis for a given simulation type.
int m_splitterPlotAndConsoleSashPosition
void menuProbeUpdate(wxUpdateUIEvent &event) override
unsigned int m_plotNumber
void menuZoomFit(wxCommandEvent &event) override
const wxString & GetSimCommand(const SIM_PANEL_BASE *aPlotPanel)
Definition: sim_workbook.h:61
Storage for simulator specific settings.
Custom widget to handle quick component values modification and simulation on the fly.
Definition: tuner_slider.h:43
wxDECLARE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
SIM_PLOT_TYPE
Definition: sim_types.h:47
SIM_TYPE
< Possible simulation types
Definition: sim_types.h:32
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:83