KiCad PCB EDA Suite
Loading...
Searching...
No Matches
simulator_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-2023 CERN
5 * Copyright The 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, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef SIMULATOR_FRAME_H
25#define SIMULATOR_FRAME_H
26
27
29#include <sim/sim_types.h>
30
31#include <kiway_player.h>
33
34#include <wx/event.h>
35
36#include <list>
37#include <memory>
38#include <map>
39
40class SCH_EDIT_FRAME;
41class SCH_SYMBOL;
44class ACTION_TOOLBAR;
45class SPICE_SIMULATOR;
46
47
52class SIMULATOR_INIT_ERR : public std::runtime_error
53{
54public:
55 explicit SIMULATOR_INIT_ERR(const std::string& what_arg)
56 : std::runtime_error(what_arg) {}
57};
58
59
77
78
80{
81public:
82 SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
84
89 bool LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
90
94 void ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
95
96 void StartSimulation();
97
103 SIM_TAB* NewSimTab( const wxString& aSimCommand );
104
109 bool EditAnalysis();
110
114 const std::vector<wxString> SimPlotVectors();
115
119 const std::vector<wxString> Signals();
120
121 const std::map<int, wxString>& UserDefinedSignals();
122
123 void SetUserDefinedSignals( const std::map<int, wxString>& aSignals );
124
130 void AddVoltageTrace( const wxString& aNetName );
131
138 void AddCurrentTrace( const wxString& aDeviceName );
139
143 void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
144
148 SIM_TAB* GetCurrentSimTab() const;
149
150 void ToggleSimConsole();
151
152 void ToggleSimSidePanel();
153
157 void ToggleDarkModePlots();
158
159 void ShowChangedLanguage() override;
160
164 bool LoadWorkbook( const wxString& aPath );
165
169 bool SaveWorkbook( const wxString& aPath );
170
171 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
172
173 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
174
175 void CommonSettingsChanged( int aFlags ) override;
176
178
180
181 std::shared_ptr<SPICE_CIRCUIT_MODEL> GetCircuitModel() const { return m_circuitModel; }
182
183 std::shared_ptr<SPICE_SIMULATOR> GetSimulator() const { return m_simulator; }
184
185 wxString GetCurrentSimCommand() const;
187 int GetCurrentOptions() const;
188
189 bool SimFinished() const { return m_simFinished; }
190
191 // Simulator doesn't host a canvas
192 wxWindow* GetToolCanvas() const override { return nullptr; }
193
197 void UpdateTitle();
198
199 void OnModify() override;
200
201 DECLARE_EVENT_TABLE()
202
203private:
204 void setupTools();
205 void doReCreateMenuBar() override;
206
207 void setupUIConditions() override;
208
209 void showNetlistErrors( const WX_STRING_REPORTER& aReporter );
210
211 bool canCloseWindow( wxCloseEvent& aEvent ) override;
212 void doCloseWindow() override;
213
214 void onUpdateSim( wxCommandEvent& aEvent );
215 void onSimReport( wxCommandEvent& aEvent );
216 void onSimStarted( wxCommandEvent& aEvent );
217 void onSimFinished( wxCommandEvent& aEvent );
218
219 void onExit( wxCommandEvent& event );
220
221private:
225
229
232};
233
234// Commands
235wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
236wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
237
238// Notifications
239wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
240wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
241
242#endif // SIMULATOR_FRAME_H
Define the structure of a toolbar with buttons that invoke ACTIONs.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
Schematic editor (Eeschema) main window.
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
Schematic symbol object.
Definition sch_symbol.h:69
The SIMULATOR_FRAME_UI holds the main user-interface for running simulations.
SIMULATOR_FRAME(KIWAY *aKiway, wxWindow *aParent)
SIM_TAB * GetCurrentSimTab() const
Return the current tab (or NULL if there is none).
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
bool canCloseWindow(wxCloseEvent &aEvent) override
void onSimFinished(wxCommandEvent &aEvent)
bool LoadSimulator(const wxString &aSimCommand, unsigned aSimOptions)
Check and load the current netlist into the simulator.
void onSimReport(wxCommandEvent &aEvent)
wxString GetCurrentSimCommand() const
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
std::shared_ptr< SPICE_CIRCUIT_MODEL > GetCircuitModel() const
void showNetlistErrors(const WX_STRING_REPORTER &aReporter)
void onExit(wxCommandEvent &event)
std::shared_ptr< SPICE_SIMULATOR > m_simulator
SIM_TYPE GetCurrentSimType() const
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
ACTION_TOOLBAR * m_toolBar
void AddCurrentTrace(const wxString &aDeviceName)
Add a current trace for a given device to the current plot.
void OnModify() override
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
bool SaveWorkbook(const wxString &aPath)
Save plot, signal, cursor, measurement, etc.
void doReCreateMenuBar() override
SCH_EDIT_FRAME * GetSchematicFrame() const
const std::vector< wxString > Signals()
void doCloseWindow() override
bool SimFinished() const
const std::vector< wxString > SimPlotVectors()
void AddVoltageTrace(const wxString &aNetName)
Add a voltage trace for a given net to the current plot.
void ToggleDarkModePlots()
Toggle dark-mode of the plot tabs.
SIM_THREAD_REPORTER * m_reporter
void AddTuner(const SCH_SHEET_PATH &aSheetPath, SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
void onSimStarted(wxCommandEvent &aEvent)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
std::shared_ptr< SPICE_CIRCUIT_MODEL > m_circuitModel
SIM_TAB * NewSimTab(const wxString &aSimCommand)
Create a new plot tab for a given simulation type.
bool EditAnalysis()
Shows a dialog for editing the current tab's simulation command, or creating a new tab with a differe...
int GetCurrentOptions() const
bool LoadWorkbook(const wxString &aPath)
Load plot, signal, cursor, measurement, etc.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void onUpdateSim(wxCommandEvent &aEvent)
void UpdateTitle()
Set the main window title bar text.
const std::map< int, wxString > & UserDefinedSignals()
std::shared_ptr< SPICE_SIMULATOR > GetSimulator() const
void SetUserDefinedSignals(const std::map< int, wxString > &aSignals)
wxWindow * GetToolCanvas() const override
Canvas access.
void ReloadSimulator(const wxString &aSimCommand, unsigned aSimOptions)
Re-send the current command and settings to the simulator.
SCH_EDIT_FRAME * m_schematicFrame
SIMULATOR_FRAME_UI * m_ui
SIMULATOR_INIT_ERR(const std::string &what_arg)
Special netlist exporter flavor that allows one to override simulation commands.
A wrapper for reporting to a wxString object.
Definition reporter.h:189
STL namespace.
wxDECLARE_EVENT(wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent)
SIM_TYPE
< Possible simulation types
Definition sim_types.h:28
Store the common settings that are saved and loaded for each window / frame.