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 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, 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#include <sim/sim_preferences.h>
36
37#include <wx/event.h>
38
39class SCH_EDIT_FRAME;
40class SCH_SYMBOL;
41
42class SPICE_SIMULATOR;
43class SPICE_SETTINGS;
46
48class TUNER_SLIDER;
49
50
68
69
71{
72public:
73 SIMULATOR_FRAME_UI( SIMULATOR_FRAME* aSimulatorFrame, SCH_EDIT_FRAME* aSchematicFrame );
75
81 SIM_TAB* NewSimTab( const wxString& aSimCommand );
82
83 std::vector<wxString> SimPlotVectors() const;
84
85 std::vector<wxString> Signals() const;
86
87 const std::map<int, wxString>& UserDefinedSignals() { return m_userDefinedSignals; }
88 void SetUserDefinedSignals( const std::map<int, wxString>& aSignals );
89
96 void CreateNewCursor();
97
103 void DeleteCursor();
104
111 void AddTrace( const wxString& aName, SIM_TRACE_TYPE aType );
112
117 SPICE_VALUE_FORMAT GetCursorFormat( int aCursorId, int aValueCol ) const
118 {
119 return m_cursorFormatsDyn[aCursorId][aValueCol];
120 }
121
122 void SetCursorFormat( int aCursorId, int aValueCol, const SPICE_VALUE_FORMAT& aFormat )
123 {
124 m_cursorFormatsDyn[ aCursorId ][ aValueCol ] = aFormat;
125
126 wxCommandEvent dummy;
128 }
129
133 void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
134
138 void RemoveTuner( TUNER_SLIDER* aTuner );
139
148 void UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, const KIID& aSymbol,
149 const wxString& aRef, const wxString& aValue );
150
154 void AddMeasurement( const wxString& aCmd );
155
159 void DeleteMeasurement( int aRow );
160
164 SPICE_VALUE_FORMAT GetMeasureFormat( int aRow ) const;
165 void SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat );
166
170 void UpdateMeasurement( int aRow );
171
172 void DoFourier( const wxString& aSignal, const wxString& aFundamental );
173
177 const SPICE_CIRCUIT_MODEL* GetExporter() const;
178
179 bool IsSimConsoleShown();
180 void ToggleSimConsole();
181 bool IsSimSidePanelShown();
182 void ToggleSimSidePanel();
183
184 bool DarkModePlots() const { return m_darkMode; }
185 void ToggleDarkModePlots();
186
187 void ShowChangedLanguage();
188
193 void InitWorkbook();
194
198 bool LoadWorkbook( const wxString& aPath );
199
203 bool SaveWorkbook( const wxString& aPath );
204
205 void LoadSettings( EESCHEMA_SETTINGS* aCfg );
206
207 void SaveSettings( EESCHEMA_SETTINGS* aCfg );
208
212 void ApplyPreferences( const SIM_PREFERENCES& aPrefs );
213
221
226 {
227 return dynamic_cast<SIM_TAB*>( m_plotNotebook->GetCurrentPage() );
228 }
229
230 SIM_TAB* GetSimTab( SIM_TYPE aType ) const
231 {
232 for( int ii = 0; ii < (int) m_plotNotebook->GetPageCount(); ++ii )
233 {
234 SIM_TAB* candidate = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( ii ) );
235
236 if( candidate && candidate->GetSimType() == aType )
237 return candidate;
238 }
239
240 return nullptr;
241 }
242
243 int GetSimTabIndex( SIM_TAB* aPlot ) const
244 {
245 return m_plotNotebook->GetPageIndex( aPlot );
246 }
247
249
250 void OnSimUpdate();
251 void OnSimReport( const wxString& aMsg );
252 void OnSimRefresh( bool aFinal );
253
254 void OnModify();
255
256private:
260 wxString vectorNameFromSignalName( SIM_PLOT_TAB* aPlotTab, const wxString& aSignalName,
261 int* aTraceType );
262
271 void updateTrace( const wxString& aVectorName, int aTraceType, SIM_PLOT_TAB* aPlotTab,
272 std::vector<double>* aDataX = nullptr, bool aClearData = false );
273
277 void TogglePanel( wxPanel* aPanel, wxSplitterWindow* aSplitterWindow, int& aSashPosition );
278
284 void CustomCursorsInit();
285
291 void rebuildSignalsList();
292
296 void rebuildSignalsGrid( wxString aFilter );
297
301 void updateSignalsGrid();
302
306 void updatePlotCursors();
307
315 template <typename T, typename U, typename R>
316 void signalsGridCursorUpdate( T t, U u, R r );
317
322
327
329
333 void applyTuners();
334
338 SIM_TRACE_TYPE getXAxisType( SIM_TYPE aType ) const;
339
340 struct MULTI_RUN_STEP;
341
342 void clearMultiRunState( bool aClearTraces );
344 std::vector<MULTI_RUN_STEP> calculateMultiRunSteps( const std::vector<TUNER_SLIDER*>& aTuners ) const;
345 std::string multiRunTraceKey( const wxString& aVectorName, int aTraceType ) const;
346 void recordMultiRunData( const wxString& aVectorName, int aTraceType,
347 const std::vector<double>& aX, const std::vector<double>& aY );
348 bool hasMultiRunTrace( const wxString& aVectorName, int aTraceType ) const;
349
350 wxString getNoiseSource() const;
351
352 void parseTraceParams( SIM_PLOT_TAB* aPlotTab, TRACE* aTrace, const wxString& aSignalName,
353 const wxString& aParams );
354
355 std::shared_ptr<SPICE_SIMULATOR> simulator() const;
356 std::shared_ptr<SPICE_CIRCUIT_MODEL> circuitModel() const;
357
358 // Event handlers
359 void onPlotClose( wxAuiNotebookEvent& event ) override;
360 void onPlotClosed( wxAuiNotebookEvent& event ) override;
361 void onPlotChanging( wxAuiNotebookEvent& event ) override;
362 void onPlotChanged( wxAuiNotebookEvent& event ) override;
363 void onPlotDragged( wxAuiNotebookEvent& event ) override;
364
365 void OnFilterText( wxCommandEvent& aEvent ) override;
366 void OnFilterMouseMoved( wxMouseEvent& aEvent ) override;
367
368 void onSignalsGridCellChanged( wxGridEvent& aEvent ) override;
369 void onCursorsGridCellChanged( wxGridEvent& aEvent ) override;
370 void onMeasurementsGridCellChanged( wxGridEvent& aEvent ) override;
371
372 void OnUpdateUI( wxUpdateUIEvent& event ) override;
373
374 bool loadLegacyWorkbook( const wxString & aPath );
375 bool loadJsonWorkbook( const wxString & aPath );
376
377 void SaveCursorToWorkbook( nlohmann::json& aTraceJs, TRACE* aTrace, int aCursorId );
378
379 void onPlotCursorUpdate( wxCommandEvent& aEvent );
380
381public:
383
384private:
387
388 std::vector<wxString> m_signals;
389 std::map<int, wxString> m_userDefinedSignals;
390 std::list<TUNER_SLIDER*> m_tuners;
391 std::map<const TUNER_SLIDER*, double> m_tunerOverrides;
392
394 {
396 std::vector<double> xValues;
397 std::vector<std::vector<double>> yValues;
398 };
399
401 {
402 std::map<const TUNER_SLIDER*, double> overrides;
403 };
404
406 {
407 bool active = false;
408 std::vector<TUNER_SLIDER*> tuners;
409 std::vector<MULTI_RUN_STEP> steps;
410 size_t currentStep = 0;
411 size_t storedSteps = 0;
412 bool storePending = false;
413 std::map<std::string, MULTI_RUN_TRACE> traces;
414 };
415
417
420 std::vector<wxString> m_netnames;
421
423
424 // Holds cursor formating for m_cursorsGrid, includes m_cursorFormats[3][2], TODO: merge.
425 std::vector<std::vector<SPICE_VALUE_FORMAT>> m_cursorFormatsDyn;
426
427 // Variables for temporary storage:
434 unsigned int m_plotNumber;
437
438 // Count all available cursors in m_signalsGrid
439 int m_customCursorsCnt; // Defaults to 2 + 1
440};
441
442#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:75
SIMULATOR_FRAME_UI_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(-1,-1), long style=wxTAB_TRAVERSAL, const wxString &name=wxEmptyString)
SIM_TAB * NewSimTab(const wxString &aSimCommand)
Create a new simulation tab for a given simulation type.
std::string multiRunTraceKey(const wxString &aVectorName, int aTraceType) const
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 CustomCursorsInit()
Init handler for custom cursors.
void recordMultiRunData(const wxString &aVectorName, int aTraceType, const std::vector< double > &aX, const std::vector< double > &aY)
std::vector< MULTI_RUN_STEP > calculateMultiRunSteps(const std::vector< TUNER_SLIDER * > &aTuners) const
void TogglePanel(wxPanel *aPanel, wxSplitterWindow *aSplitterWindow, int &aSashPosition)
A common toggler for the two main wxSplitterWindow s.
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
std::vector< std::vector< SPICE_VALUE_FORMAT > > m_cursorFormatsDyn
void DoFourier(const wxString &aSignal, const wxString &aFundamental)
void rebuildMeasurementsGrid()
Rebuild the measurements grid for the current plot.
std::list< TUNER_SLIDER * > m_tuners
void rebuildSignalsList()
Rebuild the list of signals available from the netlist.
bool loadLegacyWorkbook(const wxString &aPath)
MULTI_RUN_STATE m_multiRunState
SPICE expressions need quoted versions of the netnames since KiCad allows '-' and '/' in netnames.
void UpdateMeasurement(int aRow)
Update a measurement in the measurements grid.
wxString getNoiseSource() const
std::vector< wxString > SimPlotVectors() const
void SetSubWindowsSashSize()
Adjust the sash dimension of splitter windows after reading the config settings must be called after ...
void applyUserDefinedSignals()
Apply user-defined signals to the SPICE session.
SIM_PREFERENCES m_preferences
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.
bool hasMultiRunTrace(const wxString &aVectorName, int aTraceType) const
std::vector< wxString > m_signals
SIM_TAB * GetCurrentSimTab() const
Return the currently opened plot panel (or NULL if there is none).
void SaveCursorToWorkbook(nlohmann::json &aTraceJs, TRACE *aTrace, int aCursorId)
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.
const std::map< int, wxString > & UserDefinedSignals()
std::vector< wxString > m_netnames
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 DeleteCursor()
Deletes last m_signalsGrid "Cursor n" column, removes vector's m_cursorFormatsDyn last entry,...
void CreateNewCursor()
Creates a column at the end of m_signalsGrid named "Cursor n" ( n = m_customCursorsCnt ),...
void applyTuners()
Apply component values specified using tuner sliders to the current netlist.
bool loadJsonWorkbook(const wxString &aPath)
void clearMultiRunState(bool aClearTraces)
void OnFilterMouseMoved(wxMouseEvent &aEvent) override
void AddMeasurement(const wxString &aCmd)
Add a measurement to the measurements grid.
void onPlotChanging(wxAuiNotebookEvent &event) override
std::map< const TUNER_SLIDER *, double > m_tunerOverrides
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 signalsGridCursorUpdate(T t, U u, R r)
Updates m_signalsGrid cursor widget, column rendering and attributes.
void SetMeasureFormat(int aRow, const SPICE_VALUE_FORMAT &aFormat)
void OnSimReport(const wxString &aMsg)
void ApplyPreferences(const SIM_PREFERENCES &aPrefs)
Called when settings are changed via the common Preferences dialog.
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.
SIMULATOR_FRAME_UI(SIMULATOR_FRAME *aSimulatorFrame, SCH_EDIT_FRAME *aSchematicFrame)
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:75
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.
Contains preferences pertaining to the simulator.
SIM_TRACE_TYPE
Definition sim_types.h:50
@ SPT_UNKNOWN
Definition sim_types.h:67
SIM_TYPE
< Possible simulation types
Definition sim_types.h:32
std::vector< FAB_LAYER_COLOR > dummy
std::vector< TUNER_SLIDER * > tuners
std::map< std::string, MULTI_RUN_TRACE > traces
std::vector< MULTI_RUN_STEP > steps
std::map< const TUNER_SLIDER *, double > overrides
std::vector< std::vector< double > > yValues
Contains preferences pertaining to the simulator.
A SPICE_VALUE_FORMAT holds precision and range info for formatting values.Helper class to handle Spic...
Definition spice_value.h:43