KiCad PCB EDA Suite
Loading...
Searching...
No Matches
simulator_frame_ui.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 (C) 2017-2023 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 SIMULATOR_FRAME_UI_H
29#define SIMULATOR_FRAME_UI_H
30
31
33#include <sim/sim_types.h>
34#include <sim/sim_plot_tab.h>
35
36#include <wx/event.h>
37
38class SCH_EDIT_FRAME;
39class SCH_SYMBOL;
40
41class SPICE_SIMULATOR;
42class SPICE_SETTINGS;
45
47class TUNER_SLIDER;
48
49
70{
71public:
72 SIMULATOR_FRAME_UI( SIMULATOR_FRAME* aSimulatorFrame, SCH_EDIT_FRAME* aSchematicFrame );
74
80 SIM_TAB* NewSimTab( const wxString& aSimCommand );
81
82 std::vector<wxString> SimPlotVectors() const;
83
84 std::vector<wxString> Signals() const;
85
86 const std::map<int, wxString>& UserDefinedSignals() { return m_userDefinedSignals; }
87 void SetUserDefinedSignals( const std::map<int, wxString>& aSignals );
88
95 void AddTrace( const wxString& aName, SIM_TRACE_TYPE aType );
96
101 SPICE_VALUE_FORMAT GetCursorFormat( int aCursorId, int aValueCol ) const
102 {
103 return m_cursorFormats[ aCursorId ][ aValueCol ];
104 }
105
106 void SetCursorFormat( int aCursorId, int aValueCol, const SPICE_VALUE_FORMAT& aFormat )
107 {
108 m_cursorFormats[ aCursorId ][ aValueCol ] = aFormat;
109
110 wxCommandEvent dummy;
112 }
113
117 void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
118
122 void RemoveTuner( TUNER_SLIDER* aTuner );
123
132 void UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, const KIID& aSymbol,
133 const wxString& aRef, const wxString& aValue );
134
138 void AddMeasurement( const wxString& aCmd );
139
143 void DeleteMeasurement( int aRow );
144
148 SPICE_VALUE_FORMAT GetMeasureFormat( int aRow ) const;
149 void SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat );
150
154 void UpdateMeasurement( int aRow );
155
156 void DoFourier( const wxString& aSignal, const wxString& aFundamental );
157
161 const SPICE_CIRCUIT_MODEL* GetExporter() const;
162
163 bool DarkModePlots() const { return m_darkMode; }
164 void ToggleDarkModePlots();
165
166 void ShowChangedLanguage();
167
172 void InitWorkbook();
173
177 bool LoadWorkbook( const wxString& aPath );
178
182 bool SaveWorkbook( const wxString& aPath );
183
184 void LoadSettings( EESCHEMA_SETTINGS* aCfg );
185
186 void SaveSettings( EESCHEMA_SETTINGS* aCfg );
187
188 // adjust the sash dimension of splitter windows after reading
189 // the config settings
190 // must be called after the config settings are read, and once the
191 // frame is initialized (end of the Ctor)
193
198 {
199 return dynamic_cast<SIM_TAB*>( m_plotNotebook->GetCurrentPage() );
200 }
201
202 SIM_TAB* GetSimTab( SIM_TYPE aType ) const
203 {
204 for( int ii = 0; ii < (int) m_plotNotebook->GetPageCount(); ++ii )
205 {
206 SIM_TAB* candidate = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( ii ) );
207
208 if( candidate && candidate->GetSimType() == aType )
209 return candidate;
210 }
211
212 return nullptr;
213 }
214
215 int GetSimTabIndex( SIM_TAB* aPlot ) const
216 {
217 return m_plotNotebook->GetPageIndex( aPlot );
218 }
219
221
222 void OnSimUpdate();
223 void OnSimReport( const wxString& aMsg );
224 void OnSimRefresh( bool aFinal );
225
226 void OnModify();
227
228private:
232 wxString vectorNameFromSignalName( SIM_PLOT_TAB* aPlotTab, const wxString& aSignalName,
233 int* aTraceType );
234
243 void updateTrace( const wxString& aVectorName, int aTraceType, SIM_PLOT_TAB* aPlotTab,
244 std::vector<double>* aDataX = nullptr, bool aClearData = false );
245
251 void rebuildSignalsList();
252
256 void rebuildSignalsGrid( wxString aFilter );
257
261 void updateSignalsGrid();
262
266 void updatePlotCursors();
267
272
277
279
283 void applyTuners();
284
288 SIM_TRACE_TYPE getXAxisType( SIM_TYPE aType ) const;
289
290 wxString getNoiseSource() const;
291
292 void parseTraceParams( SIM_PLOT_TAB* aPlotTab, TRACE* aTrace, const wxString& aSignalName,
293 const wxString& aParams );
294
295 std::shared_ptr<SPICE_SIMULATOR> simulator() const;
296 std::shared_ptr<SPICE_CIRCUIT_MODEL> circuitModel() const;
297
298 // Event handlers
299 void onPlotClose( wxAuiNotebookEvent& event ) override;
300 void onPlotClosed( wxAuiNotebookEvent& event ) override;
301 void onPlotChanging( wxAuiNotebookEvent& event ) override;
302 void onPlotChanged( wxAuiNotebookEvent& event ) override;
303 void onPlotDragged( wxAuiNotebookEvent& event ) override;
304
305 void OnFilterText( wxCommandEvent& aEvent ) override;
306 void OnFilterMouseMoved( wxMouseEvent& aEvent ) override;
307
308 void onSignalsGridCellChanged( wxGridEvent& aEvent ) override;
309 void onCursorsGridCellChanged( wxGridEvent& aEvent ) override;
310 void onMeasurementsGridCellChanged( wxGridEvent& aEvent ) override;
311
312 void OnUpdateUI( wxUpdateUIEvent& event ) override;
313
314 bool loadLegacyWorkbook( const wxString & aPath );
315 bool loadJsonWorkbook( const wxString & aPath );
316
317 void onPlotCursorUpdate( wxCommandEvent& aEvent );
318
319public:
321
322private:
325
326 std::vector<wxString> m_signals;
327 std::map<int, wxString> m_userDefinedSignals;
328 std::list<TUNER_SLIDER*> m_tuners;
329
332 std::map<wxString, wxString> m_quotedNetnames;
333
335
336 // Variables for temporary storage:
343 unsigned int m_plotNumber;
345};
346
347#endif // SIMULATOR_FRAME_UI_H
Definition: kiid.h:49
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:81
Class SIMULATOR_FRAME_UI_BASE.
The SIMULATOR_FRAME_UI holds the main user-interface for running simulations.
SIM_TAB * NewSimTab(const wxString &aSimCommand)
Create a new simulation tab for a given simulation type.
void SetUserDefinedSignals(const std::map< int, wxString > &aSignals)
void updatePlotCursors()
Update the cursor values (in the grid) and graphics (in the plot window).
void OnSimRefresh(bool aFinal)
void onPlotClose(wxAuiNotebookEvent &event) override
void onPlotChanged(wxAuiNotebookEvent &event) override
void rebuildSignalsGrid(wxString aFilter)
Rebuild the filtered list of signals in the signals grid.
SIM_TAB * GetSimTab(SIM_TYPE aType) const
void DoFourier(const wxString &aSignal, const wxString &aFundamental)
void rebuildMeasurementsGrid()
Rebuild the measurements grid for the current plot.
std::list< TUNER_SLIDER * > m_tuners
SPICE expressions need quoted versions of the netnames since KiCad allows '-' and '/' in netnames.
void rebuildSignalsList()
Rebuild the list of signals available from the netlist.
bool loadLegacyWorkbook(const wxString &aPath)
void UpdateMeasurement(int aRow)
Update a measurement in the measurements grid.
wxString getNoiseSource() const
std::vector< wxString > SimPlotVectors() const
void applyUserDefinedSignals()
Apply user-defined signals to the SPICE session.
std::map< wxString, wxString > m_quotedNetnames
void DeleteMeasurement(int aRow)
Delete a row from the measurements grid.
SCH_EDIT_FRAME * m_schematicFrame
wxString vectorNameFromSignalName(SIM_PLOT_TAB *aPlotTab, const wxString &aSignalName, int *aTraceType)
Get the simulator output vector name for a given signal name and type.
void updateSignalsGrid()
Update the values in the signals grid.
void onCursorsGridCellChanged(wxGridEvent &aEvent) override
void onPlotDragged(wxAuiNotebookEvent &event) override
std::vector< wxString > Signals() const
bool SaveWorkbook(const wxString &aPath)
Save plot, signal, cursor, measurement, etc.
std::vector< wxString > m_signals
SIM_TAB * GetCurrentSimTab() const
Return the currently opened plot panel (or NULL if there is none).
bool LoadWorkbook(const wxString &aPath)
Load plot, signal, cursor, measurement, etc.
SPICE_VALUE_FORMAT GetMeasureFormat(int aRow) const
Get/Set the format of a value in the measurements grid.
std::map< int, wxString > m_userDefinedSignals
void UpdateTunerValue(const SCH_SHEET_PATH &aSheetPath, const KIID &aSymbol, const wxString &aRef, const wxString &aValue)
Safely update a field of the associated symbol without dereferencing the symbol.
bool DarkModePlots() const
const std::map< int, wxString > & UserDefinedSignals()
void AddTrace(const wxString &aName, SIM_TRACE_TYPE aType)
Add a new trace to the current plot.
void onPlotClosed(wxAuiNotebookEvent &event) override
void RemoveTuner(TUNER_SLIDER *aTuner)
Remove an existing tuner.
void SaveSettings(EESCHEMA_SETTINGS *aCfg)
std::shared_ptr< SPICE_CIRCUIT_MODEL > circuitModel() const
void OnFilterText(wxCommandEvent &aEvent) override
void onMeasurementsGridCellChanged(wxGridEvent &aEvent) override
void applyTuners()
Apply component values specified using tuner sliders to the current netlist.
bool loadJsonWorkbook(const wxString &aPath)
void OnFilterMouseMoved(wxMouseEvent &aEvent) override
void AddMeasurement(const wxString &aCmd)
Add a measurement to the measurements grid.
void onPlotChanging(wxAuiNotebookEvent &event) override
std::shared_ptr< SPICE_SIMULATOR > simulator() const
int GetSimTabIndex(SIM_TAB *aPlot) const
void onPlotCursorUpdate(wxCommandEvent &aEvent)
void onSignalsGridCellChanged(wxGridEvent &aEvent) override
void SetCursorFormat(int aCursorId, int aValueCol, const SPICE_VALUE_FORMAT &aFormat)
void InitWorkbook()
Load the currently active workbook stored in the project settings.
SIM_TRACE_TYPE getXAxisType(SIM_TYPE aType) const
Return X axis for a given simulation type.
void SetMeasureFormat(int aRow, const SPICE_VALUE_FORMAT &aFormat)
void OnSimReport(const wxString &aMsg)
const SPICE_CIRCUIT_MODEL * GetExporter() const
Return the netlist exporter object used for simulations.
SIMULATOR_FRAME * m_simulatorFrame
void AddTuner(const SCH_SHEET_PATH &aSheetPath, SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
void parseTraceParams(SIM_PLOT_TAB *aPlotTab, TRACE *aTrace, const wxString &aSignalName, const wxString &aParams)
SPICE_VALUE_FORMAT GetCursorFormat(int aCursorId, int aValueCol) const
Get/Set the number of significant digits and the range for formatting a cursor value.
void OnUpdateUI(wxUpdateUIEvent &event) override
void updateTrace(const wxString &aVectorName, int aTraceType, SIM_PLOT_TAB *aPlotTab, std::vector< double > *aDataX=nullptr, bool aClearData=false)
Update a trace in a particular SIM_PLOT_TAB.
SPICE_VALUE_FORMAT m_cursorFormats[3][2]
void LoadSettings(EESCHEMA_SETTINGS *aCfg)
The SIMULATOR_FRAME holds the main user-interface for running simulations.
SIM_TYPE GetSimType() const
Definition: sim_tab.cpp:71
Special netlist exporter flavor that allows one to override simulation commands.
Storage for simulator specific settings.
Custom widget to handle quick component values modification and simulation on the fly.
Definition: tuner_slider.h:44
SIM_TRACE_TYPE
Definition: sim_types.h:50
SIM_TYPE
< Possible simulation types
Definition: sim_types.h:32
std::vector< FAB_LAYER_COLOR > dummy
A SPICE_VALUE_FORMAT holds precision and range info for formatting values.Helper class to handle Spic...
Definition: spice_value.h:43