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;
45class ACTION_TOOLBAR;
46class SPICE_SIMULATOR;
47
48
53class SIMULATOR_INIT_ERR : public std::runtime_error
54{
55public:
56 explicit SIMULATOR_INIT_ERR(const std::string& what_arg)
57 : std::runtime_error(what_arg) {}
58};
59
60
78
79
81{
82public:
83 SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
85
90 bool LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
91
95 void ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
96
97 void StartSimulation();
98
104 SIM_TAB* NewSimTab( const wxString& aSimCommand );
105
110 bool EditAnalysis();
111
115 const std::vector<wxString> SimPlotVectors();
116
120 const std::vector<wxString> Signals();
121
122 const std::map<int, wxString>& UserDefinedSignals();
123
124 void SetUserDefinedSignals( const std::map<int, wxString>& aSignals );
125
131 void AddVoltageTrace( const wxString& aNetName );
132
139 void AddCurrentTrace( const wxString& aDeviceName );
140
144 void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
145
149 SIM_TAB* GetCurrentSimTab() const;
150
151 void ToggleSimConsole();
152
153 void ToggleSimSidePanel();
154
158 void ToggleDarkModePlots();
159
163 void ToggleSmithChart();
164
165 void ShowChangedLanguage() override;
166
170 bool LoadWorkbook( const wxString& aPath );
171
175 bool SaveWorkbook( const wxString& aPath );
176
177 void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
178
179 void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
180
181 void CommonSettingsChanged( int aFlags ) override;
182
184
186
187 std::shared_ptr<SPICE_CIRCUIT_MODEL> GetCircuitModel() const { return m_circuitModel; }
188
189 std::shared_ptr<SPICE_SIMULATOR> GetSimulator() const { return m_simulator; }
190
191 wxString GetCurrentSimCommand() const;
193 int GetCurrentOptions() const;
194
195 bool SimFinished() const { return m_simFinished; }
196
197 wxString TakeSimReportMessages();
198
199 // Simulator doesn't host a canvas
200 wxWindow* GetToolCanvas() const override { return nullptr; }
201
205 void UpdateTitle();
206
207 void OnModify() override;
208
209 DECLARE_EVENT_TABLE()
210
211private:
212 void setupTools();
213 void doReCreateMenuBar() override;
214
215 void setupUIConditions() override;
216
217 void showNetlistErrors( const WX_STRING_REPORTER& aReporter );
218
220 void destroyTabPlot( SIM_TAB* aSimTab );
221
222 bool canCloseWindow( wxCloseEvent& aEvent ) override;
223 void doCloseWindow() override;
224
225 void onUpdateSim( wxCommandEvent& aEvent );
226 void onSimStarted( wxCommandEvent& aEvent );
227 void onSimFinished( wxCommandEvent& aEvent );
228
229 void onExit( wxCommandEvent& event );
230
231private:
235
240
243};
244
245// Commands
246wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
247
248// Notifications
249wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
250wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
251
252#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.
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)
void destroyTabPlot(SIM_TAB *aSimTab)
Free a tab's previous ngspice plot (and its noise companion) so reruns don't leak.
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
wxString TakeSimReportMessages()
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.
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()
SIM_FRAME_STATE_LISTENER * m_stateListener
std::shared_ptr< SPICE_SIMULATOR > GetSimulator() const
void ToggleSmithChart()
Toggle the current S-parameter tab between Smith chart and amplitude/phase views.
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.
SIM_CONSOLE_REPORTER * m_consoleReporter
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:225
STL namespace.
wxDECLARE_EVENT(wxCUSTOM_PANEL_SHOWN_EVENT, wxCommandEvent)
SIM_TYPE
< Possible simulation types
Definition sim_types.h:31
Store the common settings that are saved and loaded for each window / frame.