KiCad PCB EDA Suite
Loading...
Searching...
No Matches
simulator_frame.cpp
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) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 * @author Tomasz Wlostowski <[email protected]>
7 * @author Maciej Suminski <[email protected]>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version 3
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, you may find one here:
21 * https://www.gnu.org/licenses/gpl-3.0.html
22 * or you may search the http://www.gnu.org website for the version 3 license,
23 * or you may write to the Free Software Foundation, Inc.,
24 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
25 */
26
27#include <wx/debug.h>
28
29// For some obscure reason, needed on msys2 with some wxWidgets versions (3.0) to avoid
30// undefined symbol at link stage (due to use of #include <pegtl.hpp>)
31// Should not create issues on other platforms
32#include <wx/menu.h>
33
35#include <sch_edit_frame.h>
36#include <kiway.h>
37#include <confirm.h>
38#include <bitmaps.h>
42#include <widgets/wx_grid.h>
43#include <tool/tool_manager.h>
45#include <tool/action_manager.h>
46#include <tool/action_toolbar.h>
47#include <tool/common_control.h>
49#include <tools/ee_actions.h>
50#include <string_utils.h>
51#include <pgm_base.h>
52#include "ngspice.h"
53#include <sim/simulator_frame.h>
55#include <sim/sim_plot_tab.h>
56#include <sim/spice_simulator.h>
58#include <eeschema_settings.h>
59#include <advanced_config.h>
60
61#include <memory>
62
63
65{
66public:
68 m_parent( aParent )
69 {
70 }
71
72 REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
73 {
74 wxCommandEvent* event = new wxCommandEvent( EVT_SIM_REPORT );
75 event->SetString( aText );
76 wxQueueEvent( m_parent, event );
77 return *this;
78 }
79
80 bool HasMessage() const override
81 {
82 return false; // Technically "indeterminate" rather than false.
83 }
84
85 void OnSimStateChange( SIMULATOR* aObject, SIM_STATE aNewState ) override
86 {
87 wxCommandEvent* event = nullptr;
88
89 switch( aNewState )
90 {
91 case SIM_IDLE: event = new wxCommandEvent( EVT_SIM_FINISHED ); break;
92 case SIM_RUNNING: event = new wxCommandEvent( EVT_SIM_STARTED ); break;
93 default: wxFAIL; return;
94 }
95
96 wxQueueEvent( m_parent, event );
97 }
98
99private:
101};
102
103
104BEGIN_EVENT_TABLE( SIMULATOR_FRAME, KIWAY_PLAYER )
105 EVT_MENU( wxID_EXIT, SIMULATOR_FRAME::onExit )
106 EVT_MENU( wxID_CLOSE, SIMULATOR_FRAME::onExit )
107END_EVENT_TABLE()
108
109
110SIMULATOR_FRAME::SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
111 KIWAY_PLAYER( aKiway, aParent, FRAME_SIMULATOR, _( "Simulator" ), wxDefaultPosition,
112 wxDefaultSize, wxDEFAULT_FRAME_STYLE, wxT( "simulator" ), unityScale ),
113 m_schematicFrame( nullptr ),
114 m_toolBar( nullptr ),
115 m_ui( nullptr ),
116 m_simFinished( false ),
117 m_workbookModified( false )
118{
119 m_schematicFrame = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
120 wxASSERT( m_schematicFrame );
121
122 // Give an icon
123 wxIcon icon;
124 icon.CopyFromBitmap( KiBitmap( BITMAPS::simulator ) );
125 SetIcon( icon );
126
127 wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
128 SetSizer( mainSizer );
129
130 m_infoBar = new WX_INFOBAR( this );
131 mainSizer->Add( m_infoBar, 0, wxEXPAND, 0 );
132
133 m_toolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
134 wxAUI_TB_DEFAULT_STYLE|wxAUI_TB_HORZ_LAYOUT|wxAUI_TB_PLAIN_BACKGROUND );
135 m_toolBar->Realize();
136 mainSizer->Add( m_toolBar, 0, wxEXPAND, 5 );
137
138 m_ui = new SIMULATOR_FRAME_UI( this, m_schematicFrame );
139 mainSizer->Add( m_ui, 1, wxEXPAND, 5 );
140
141 m_simulator = SIMULATOR::CreateInstance( "ngspice" );
142 wxASSERT( m_simulator );
143
144 LoadSettings( config() );
145
146 NGSPICE_SETTINGS* settings = dynamic_cast<NGSPICE_SETTINGS*>( m_simulator->Settings().get() );
147
148 wxCHECK2( settings, /* do nothing in release builds*/ );
149
150 if( settings && settings->GetWorkbookFilename().IsEmpty() )
152
153 m_simulator->Init();
154
155 m_reporter = new SIM_THREAD_REPORTER( this );
156 m_simulator->SetReporter( m_reporter );
157
158 m_circuitModel = std::make_shared<SPICE_CIRCUIT_MODEL>( &m_schematicFrame->Schematic(), this );
159
160 setupTools();
161 setupUIConditions();
162
163 ReCreateHToolbar();
164 ReCreateMenuBar();
165
166 Bind( wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIMULATOR_FRAME::onExit ), this,
167 wxID_EXIT );
168
169 Bind( EVT_SIM_UPDATE, &SIMULATOR_FRAME::onUpdateSim, this );
170 Bind( EVT_SIM_REPORT, &SIMULATOR_FRAME::onSimReport, this );
171 Bind( EVT_SIM_STARTED, &SIMULATOR_FRAME::onSimStarted, this );
172 Bind( EVT_SIM_FINISHED, &SIMULATOR_FRAME::onSimFinished, this );
173
174 // Ensure new items are taken in account by sizers:
175 Layout();
176
177 // resize the subwindows size. At least on Windows, calling wxSafeYield before
178 // resizing the subwindows forces the wxSplitWindows size events automatically generated
179 // by wxWidgets to be executed before our resize code.
180 // Otherwise, the changes made by setSubWindowsSashSize are overwritten by one these
181 // events
182 wxSafeYield();
183 m_ui->SetSubWindowsSashSize();
184
185 // Ensure the window is on top
186 Raise();
187
188 m_ui->InitWorkbook();
189 UpdateTitle();
190}
191
192
194{
195 NULL_REPORTER devnull;
196
197 m_simulator->Attach( nullptr, wxEmptyString, 0, devnull );
198 m_simulator->SetReporter( nullptr );
199 delete m_reporter;
200}
201
202
204{
205 // Create the manager
207 m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this );
208
210
211 // Attach the events to the tool dispatcher
213 Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
214
215 // Register tools
219}
220
221
223{
225
226 UpdateTitle();
227
229}
230
231
233{
234 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
235 wxASSERT( cfg );
236
237 if( cfg )
238 {
240 m_ui->LoadSettings( cfg );
241 }
242
244
245 NGSPICE* currentSim = dynamic_cast<NGSPICE*>( m_simulator.get() );
246
247 if( currentSim )
248 m_simulator->Settings() = project.m_SchematicSettings->m_NgspiceSettings;
249}
250
251
253{
254 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
255 wxASSERT( cfg );
256
257 if( cfg )
258 {
260 m_ui->SaveSettings( cfg );
261 }
262
264
265 if( project.m_SchematicSettings )
266 {
267 bool modified = project.m_SchematicSettings->m_NgspiceSettings->SaveToFile();
268
269 if( m_schematicFrame && modified )
271 }
272}
273
274
276{
277 EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
278 wxASSERT( cfg );
279
280 return cfg ? &cfg->m_Simulator.window : nullptr;
281}
282
283
285{
286 if( m_ui->GetCurrentSimTab() )
288 else
289 return m_circuitModel->GetSchTextSimCommand();
290}
291
292
294{
296}
297
298
300{
301 if( SIM_TAB* simTab = m_ui->GetCurrentSimTab() )
302 return simTab->GetSimOptions();
303 else
305}
306
307
309{
310 bool unsaved = true;
311 bool readOnly = false;
312 wxString title;
313 wxFileName filename = Prj().AbsolutePath( m_simulator->Settings()->GetWorkbookFilename() );
314
315 if( filename.IsOk() && filename.FileExists() )
316 {
317 unsaved = false;
318 readOnly = !filename.IsFileWritable();
319 }
320
322 title = wxT( "*" ) + filename.GetName();
323 else
324 title = filename.GetName();
325
326 if( readOnly )
327 title += wxS( " " ) + _( "[Read Only]" );
328
329 if( unsaved )
330 title += wxS( " " ) + _( "[Unsaved]" );
331
332 title += wxT( " \u2014 " ) + _( "Spice Simulator" );
333
334 SetTitle( title );
335}
336
337
338
339bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions )
340{
341 wxString errors;
342 WX_STRING_REPORTER reporter( &errors );
343
344 if( !m_schematicFrame->ReadyToNetlist( _( "Simulator requires a fully annotated schematic." ) ) )
345 return false;
346
347 // If we are using the new connectivity, make sure that we do a full-rebuild
348 if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
350
351 if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, reporter ) )
352 {
353 DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) + errors );
354 return false;
355 }
356
357 return true;
358}
359
360
362{
363 SIM_TAB* simTab = m_ui->GetCurrentSimTab();
364
365 if( !simTab )
366 return;
367
368 if( simTab->GetSimCommand().Upper().StartsWith( wxT( "FFT" ) ) )
369 {
370 wxString tranSpicePlot;
371
372 if( SIM_TAB* tranPlotTab = m_ui->GetSimTab( ST_TRAN ) )
373 tranSpicePlot = tranPlotTab->GetSpicePlotName();
374
375 if( tranSpicePlot.IsEmpty() )
376 {
377 DisplayErrorMessage( this, _( "You must run a TRAN simulation first; its results"
378 "will be used for the fast Fourier transform." ) );
379 }
380 else
381 {
382 m_simulator->Command( "setplot " + tranSpicePlot.ToStdString() );
383
384 wxArrayString commands = wxSplit( simTab->GetSimCommand(), '\n' );
385
386 for( const wxString& command : commands )
387 {
388 wxBusyCursor wait;
389 m_simulator->Command( command.ToStdString() );
390 }
391
392 simTab->SetSpicePlotName( m_simulator->CurrentPlotName() );
393 m_ui->OnSimRefresh( true );
394
395#if 0
396 m_simulator->Command( "setplot" ); // Print available plots to console
397 m_simulator->Command( "display" ); // Print vectors in current plot to console
398#endif
399 }
400
401 return;
402 }
403 else
404 {
405 if( m_ui->GetSimTabIndex( simTab ) == 0
406 && m_circuitModel->GetSchTextSimCommand() != simTab->GetLastSchTextSimCommand() )
407 {
408 if( simTab->GetLastSchTextSimCommand().IsEmpty()
409 || IsOK( this, _( "Schematic sheet simulation command directive has changed. "
410 "Do you wish to update the Simulation Command?" ) ) )
411 {
412 simTab->SetSimCommand( m_circuitModel->GetSchTextSimCommand() );
413 simTab->SetLastSchTextSimCommand( simTab->GetSimCommand() );
414 OnModify();
415 }
416 }
417 }
418
419 if( !LoadSimulator( simTab->GetSimCommand(), simTab->GetSimOptions() ) )
420 return;
421
422 std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
423
424 if( simulatorLock.owns_lock() )
425 {
426 m_ui->OnSimUpdate();
427 m_simulator->Run();
428 }
429 else
430 {
431 DisplayErrorMessage( this, _( "Another simulation is already running." ) );
432 }
433}
434
435
436SIM_TAB* SIMULATOR_FRAME::NewSimTab( const wxString& aSimCommand )
437{
438 return m_ui->NewSimTab( aSimCommand );
439}
440
441
442const std::vector<wxString> SIMULATOR_FRAME::SimPlotVectors()
443{
444 return m_ui->SimPlotVectors();
445}
446
447
448const std::vector<wxString> SIMULATOR_FRAME::Signals()
449{
450 return m_ui->Signals();
451}
452
453
454const std::map<int, wxString>& SIMULATOR_FRAME::UserDefinedSignals()
455{
456 return m_ui->UserDefinedSignals();
457}
458
459
460void SIMULATOR_FRAME::SetUserDefinedSignals( const std::map<int, wxString>& aSignals )
461{
462 m_ui->SetUserDefinedSignals( aSignals );
463}
464
465
466void SIMULATOR_FRAME::AddVoltageTrace( const wxString& aNetName )
467{
468 m_ui->AddTrace( aNetName, SPT_VOLTAGE );
469}
470
471
472void SIMULATOR_FRAME::AddCurrentTrace( const wxString& aDeviceName )
473{
474 m_ui->AddTrace( aDeviceName, SPT_CURRENT );
475}
476
477
478void SIMULATOR_FRAME::AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol )
479{
480 m_ui->AddTuner( aSheetPath, aSymbol );
481}
482
483
485{
486 return m_ui->GetCurrentSimTab();
487}
488
489
490bool SIMULATOR_FRAME::LoadWorkbook( const wxString& aPath )
491{
492 if( m_ui->LoadWorkbook( aPath ) )
493 {
494 UpdateTitle();
495
496 // Successfully loading a workbook does not count as modifying it. Clear the modified
497 // flag after all the EVT_WORKBOOK_MODIFIED events have been processed.
498 CallAfter( [=]()
499 {
500 m_workbookModified = false;
501 } );
502
503 return true;
504 }
505
506 return false;
507}
508
509
510bool SIMULATOR_FRAME::SaveWorkbook( const wxString& aPath )
511{
512 if( m_ui->SaveWorkbook( aPath ) )
513 {
514 m_workbookModified = false;
515 UpdateTitle();
516
517 return true;
518 }
519
520 return false;
521}
522
523
525{
527}
528
529
531{
532 SIM_TAB* simTab = m_ui->GetCurrentSimTab();
533 DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() );
534 wxString errors;
535 WX_STRING_REPORTER reporter( &errors );
536
537 if( !simTab )
538 return false;
539
540 if( !m_circuitModel->ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS,
541 reporter ) )
542 {
543 DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" )
544 + errors );
545 }
546
547 dlg.SetSimCommand( simTab->GetSimCommand() );
548 dlg.SetSimOptions( simTab->GetSimOptions() );
549 dlg.SetPlotSettings( simTab );
550
551 if( dlg.ShowModal() == wxID_OK )
552 {
553 simTab->SetSimCommand( dlg.GetSimCommand() );
554 dlg.ApplySettings( simTab );
556 OnModify();
557 return true;
558 }
559
560 return false;
561}
562
563
564bool SIMULATOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
565{
567 {
568 wxFileName filename = m_simulator->Settings()->GetWorkbookFilename();
569
570 if( filename.GetName().IsEmpty() )
571 {
572 if( Prj().GetProjectName().IsEmpty() )
573 filename.SetFullName( wxT( "noname.wbk" ) );
574 else
575 filename.SetFullName( Prj().GetProjectName() + wxT( ".wbk" ) );
576 }
577
578 return HandleUnsavedChanges( this, _( "Save changes to workbook?" ),
579 [&]() -> bool
580 {
581 return SaveWorkbook( Prj().AbsolutePath( filename.GetFullName() ) );
582 } );
583 }
584
585 return true;
586}
587
588
590{
591 if( m_simulator->IsRunning() )
592 m_simulator->Stop();
593
594 // Prevent memory leak on exit by deleting all simulation vectors
595 m_simulator->Clean();
596
597 // Cancel a running simProbe or simTune tool
599
600 SaveSettings( config() );
601
602 m_simulator->Settings() = nullptr;
603
604 Destroy();
605}
606
607
609{
611
613 wxASSERT( mgr );
614
615 auto showGridCondition =
616 [this]( const SELECTION& aSel )
617 {
618 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
619 return plotTab && plotTab->IsGridShown();
620 };
621
622 auto showLegendCondition =
623 [this]( const SELECTION& aSel )
624 {
625 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
626 return plotTab && plotTab->IsLegendShown();
627 };
628
629 auto showDottedCondition =
630 [this]( const SELECTION& aSel )
631 {
632 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
633 return plotTab && plotTab->GetDottedSecondary();
634 };
635
636 auto darkModePlotCondition =
637 [this]( const SELECTION& aSel )
638 {
639 return m_ui->DarkModePlots();
640 };
641
642 auto simRunning =
643 [this]( const SELECTION& aSel )
644 {
645 return m_simulator && m_simulator->IsRunning();
646 };
647
648 auto simFinished =
649 [this]( const SELECTION& aSel )
650 {
651 return m_simFinished;
652 };
653
654 auto haveSim =
655 [this]( const SELECTION& aSel )
656 {
657 return GetCurrentSimTab() != nullptr;
658 };
659
660 auto havePlot =
661 [this]( const SELECTION& aSel )
662 {
663 return dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) != nullptr;
664 };
665
666#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
667#define CHECK( x ) ACTION_CONDITIONS().Check( x )
668
672
675
676 mgr->SetConditions( EE_ACTIONS::toggleGrid, CHECK( showGridCondition ) );
677 mgr->SetConditions( EE_ACTIONS::toggleLegend, CHECK( showLegendCondition ) );
678 mgr->SetConditions( EE_ACTIONS::toggleDottedSecondary, CHECK( showDottedCondition ) );
679 mgr->SetConditions( EE_ACTIONS::toggleDarkModePlots, CHECK( darkModePlotCondition ) );
680
683 mgr->SetConditions( EE_ACTIONS::runSimulation, ENABLE( !simRunning ) );
684 mgr->SetConditions( EE_ACTIONS::stopSimulation, ENABLE( simRunning ) );
685 mgr->SetConditions( EE_ACTIONS::simProbe, ENABLE( simFinished ) );
686 mgr->SetConditions( EE_ACTIONS::simTune, ENABLE( simFinished ) );
688
689#undef CHECK
690#undef ENABLE
691}
692
693
694void SIMULATOR_FRAME::onSimStarted( wxCommandEvent& aEvent )
695{
696 SetCursor( wxCURSOR_ARROWWAIT );
697}
698
699
700void SIMULATOR_FRAME::onSimFinished( wxCommandEvent& aEvent )
701{
702 // Sometimes (for instance with a directive like wrdata my_file.csv "my_signal")
703 // the simulator is in idle state (simulation is finished), but still running, during
704 // the time the file is written. So gives a slice of time to fully finish the work:
705 if( m_simulator->IsRunning() )
706 {
707 int max_time = 40; // For a max timeout = 2s
708
709 do
710 {
711 wxMilliSleep( 50 );
712 wxYield();
713
714 if( max_time )
715 max_time--;
716
717 } while( max_time && m_simulator->IsRunning() );
718 }
719
720 // ensure the shown cursor is the default cursor, not the wxCURSOR_ARROWWAIT set when
721 // staring the simulator in onSimStarted:
722 SetCursor( wxNullCursor );
723
724 // Is a warning message useful if the simulatior is still running?
725 SCHEMATIC& schematic = m_schematicFrame->Schematic();
726 schematic.ClearOperatingPoints();
727
728 m_simFinished = true;
729
730 m_ui->OnSimRefresh( true );
731
734}
735
736
737void SIMULATOR_FRAME::onUpdateSim( wxCommandEvent& aEvent )
738{
739 static bool updateInProgress = false;
740
741 // skip update when events are triggered too often and previous call didn't end yet
742 if( updateInProgress )
743 return;
744
745 updateInProgress = true;
746
747 if( m_simulator->IsRunning() )
748 m_simulator->Stop();
749
750 std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
751
752 if( simulatorLock.owns_lock() )
753 {
754 m_ui->OnSimUpdate();
755 m_simulator->Run();
756 }
757 else
758 {
759 DisplayErrorMessage( this, _( "Another simulation is already running." ) );
760 }
761
762 updateInProgress = false;
763}
764
765
766void SIMULATOR_FRAME::onSimReport( wxCommandEvent& aEvent )
767{
768 m_ui->OnSimReport( aEvent.GetString() );
769}
770
771
772void SIMULATOR_FRAME::onExit( wxCommandEvent& aEvent )
773{
774 if( aEvent.GetId() == wxID_EXIT )
775 Kiway().OnKiCadExit();
776
777 if( aEvent.GetId() == wxID_CLOSE )
778 Close( false );
779}
780
781
783{
785 m_workbookModified = true;
786 UpdateTitle();
787}
788
789
790wxDEFINE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
791wxDEFINE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
792
793wxDEFINE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
794wxDEFINE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
constexpr EDA_IU_SCALE unityScale
Definition: base_units.h:112
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:106
static TOOL_ACTION toggleGrid
Definition: actions.h:146
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
Manage TOOL_ACTION objects.
void SetConditions(const TOOL_ACTION &aAction, const ACTION_CONDITIONS &aConditions)
Set the conditions the UI elements for activating a specific tool action should use for determining t...
Define the structure of a toolbar with buttons that invoke ACTIONs.
static const ADVANCED_CFG & GetCfg()
Get the singleton instance's config, which is shared by all consumers.
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
Definition: app_settings.h:92
Handle actions that are shared between different applications.
void SetPlotSettings(const SIM_TAB *aSimTab)
void SetSimCommand(const wxString &aCommand)
void ApplySettings(SIM_TAB *aTab)
void SetSimOptions(int aOptions)
const wxString & GetSimCommand() const
virtual APP_SETTINGS_BASE * config() const
Returns the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
virtual void setupUIConditions()
Setup the UI conditions for the various actions and their controls in this frame.
virtual void OnModify()
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
virtual void LoadSettings(APP_SETTINGS_BASE *aCfg)
Load common frame parameters from a configuration file.
virtual void SaveSettings(APP_SETTINGS_BASE *aCfg)
Save common frame parameters to a configuration data file.
virtual void Refresh(bool aEraseBackground=true, const wxRect *aRect=nullptr) override
static TOOL_ACTION simAnalysisProperties
Definition: ee_actions.h:275
static TOOL_ACTION openWorkbook
Definition: ee_actions.h:264
static TOOL_ACTION stopSimulation
Definition: ee_actions.h:277
static TOOL_ACTION toggleLegend
Definition: ee_actions.h:272
static TOOL_ACTION saveWorkbook
Definition: ee_actions.h:265
static TOOL_ACTION saveWorkbookAs
Definition: ee_actions.h:266
static TOOL_ACTION exportPlotAsCSV
Definition: ee_actions.h:268
static TOOL_ACTION simTune
Definition: ee_actions.h:271
static TOOL_ACTION toggleDarkModePlots
Definition: ee_actions.h:274
static TOOL_ACTION exportPlotAsPNG
Definition: ee_actions.h:267
static TOOL_ACTION showNetlist
Definition: ee_actions.h:279
static TOOL_ACTION simProbe
Definition: ee_actions.h:270
static TOOL_ACTION toggleDottedSecondary
Definition: ee_actions.h:273
static TOOL_ACTION runSimulation
Definition: ee_actions.h:276
static TOOL_ACTION newAnalysisTab
Definition: ee_actions.h:263
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
void OnKiCadExit()
Definition: kiway.cpp:737
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:432
Container for Ngspice simulator settings.
void SetCompatibilityMode(NGSPICE_COMPATIBILITY_MODE aMode)
A singleton reporter that reports to nowhere.
Definition: reporter.h:223
The backing store for a PROJECT, in JSON format.
Definition: project_file.h:69
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:158
virtual const wxString AbsolutePath(const wxString &aFileName) const
Fix up aFileName if it is relative to the project's directory to be an absolute path and filename.
Definition: project.cpp:322
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:71
Holds all the data relating to one schematic.
Definition: schematic.h:75
void ClearOperatingPoints()
Clear operating points from a .op simulation.
Definition: schematic.h:224
SCH_DRAW_PANEL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
Schematic editor (Eeschema) main window.
void RefreshOperatingPointDisplay()
Refresh the display of any operaintg points.
void OnModify() override
Must be called after a schematic change in order to set the "modify" flag and update other data struc...
bool ReadyToNetlist(const wxString &aAnnotateMessage)
Check if we are ready to write a netlist file for the current schematic.
SCHEMATIC & Schematic() const
void RecalculateConnections(SCH_COMMIT *aCommit, SCH_CLEANUP_FLAGS aCleanupFlags)
Generate the connection data for the entire schematic hierarchy.
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
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
Handle actions for the various symbol editor and viewers.
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 OnSimRefresh(bool aFinal)
SIM_TAB * GetSimTab(SIM_TYPE aType) const
std::vector< wxString > SimPlotVectors() const
std::vector< wxString > Signals() const
bool SaveWorkbook(const wxString &aPath)
Save plot, signal, cursor, measurement, etc.
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.
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 SaveSettings(EESCHEMA_SETTINGS *aCfg)
int GetSimTabIndex(SIM_TAB *aPlot) const
void OnSimReport(const wxString &aMsg)
void AddTuner(const SCH_SHEET_PATH &aSheetPath, SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
void LoadSettings(EESCHEMA_SETTINGS *aCfg)
The SIMULATOR_FRAME holds the main user-interface for running simulations.
SIM_TAB * GetCurrentSimTab() const
Return the current tab (or NULL if there is none).
void ShowChangedLanguage() override
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 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.
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.
const std::vector< wxString > Signals()
void doCloseWindow() override
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()
void SetUserDefinedSignals(const std::map< int, wxString > &aSignals)
SCH_EDIT_FRAME * m_schematicFrame
SIMULATOR_FRAME_UI * m_ui
Interface to receive simulation updates from SPICE_SIMULATOR class.
static std::shared_ptr< SPICE_SIMULATOR > CreateInstance(const std::string &aName)
bool IsGridShown() const
Definition: sim_plot_tab.h:280
bool GetDottedSecondary() const
Toggle cursor for a particular trace.
Definition: sim_plot_tab.h:324
bool IsLegendShown() const
Definition: sim_plot_tab.h:294
int GetSimOptions() const
Definition: sim_tab.h:52
const wxString & GetSpicePlotName() const
Definition: sim_tab.h:58
void SetLastSchTextSimCommand(const wxString &aCmd)
Definition: sim_tab.h:56
void SetSimCommand(const wxString &aSimCommand)
Definition: sim_tab.h:50
const wxString & GetSimCommand() const
Definition: sim_tab.h:49
wxString GetLastSchTextSimCommand() const
Definition: sim_tab.h:55
void SetSpicePlotName(const wxString &aPlotName)
Definition: sim_tab.h:59
SIMULATOR_FRAME * m_parent
SIM_THREAD_REPORTER(SIMULATOR_FRAME *aParent)
REPORTER & Report(const wxString &aText, SEVERITY aSeverity=RPT_SEVERITY_UNDEFINED) override
Report a string with a given severity.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
void OnSimStateChange(SIMULATOR *aObject, SIM_STATE aNewState) override
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Return simulation type basing on a simulation command directive.
wxString GetWorkbookFilename() const
TOOL_MANAGER * m_toolManager
Definition: tools_holder.h:165
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:167
TOOL_MANAGER * GetToolManager() const
Return the MVC controller.
Definition: tools_holder.h:55
virtual void DispatchWxEvent(wxEvent &aEvent)
Process wxEvents (mostly UI events), translate them to TOOL_EVENTs, and make tools handle those.
Master controller class:
Definition: tool_manager.h:57
ACTION_MANAGER * GetActionManager() const
Definition: tool_manager.h:289
bool PostAction(const std::string &aActionName, T aParam)
Run the specified action after the current action (coroutine) ends.
Definition: tool_manager.h:230
void RegisterTool(TOOL_BASE *aTool)
Add a tool to the manager set and sets it up.
void SetEnvironment(EDA_ITEM *aModel, KIGFX::VIEW *aView, KIGFX::VIEW_CONTROLS *aViewControls, APP_SETTINGS_BASE *aSettings, TOOLS_HOLDER *aFrame)
Set the work environment (model, view, view controls and the parent window).
void InitTools()
Initializes all registered tools.
A modified version of the wxInfoBar class that allows us to:
Definition: wx_infobar.h:75
A wrapper for reporting to a wxString object.
Definition: reporter.h:164
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:362
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
Definition: confirm.cpp:242
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:307
This file is part of the common library.
#define CHECK(x)
#define ENABLE(x)
#define _(s)
@ FRAME_SCH
Definition: frame_type.h:34
@ FRAME_SIMULATOR
Definition: frame_type.h:38
KIWAY Kiway
see class PGM_BASE
SEVERITY
@ RPT_SEVERITY_UNDEFINED
@ GLOBAL_CLEANUP
@ SPT_VOLTAGE
Definition: sim_types.h:52
@ SPT_CURRENT
Definition: sim_types.h:53
SIM_TYPE
< Possible simulation types
Definition: sim_types.h:32
@ ST_TRAN
Definition: sim_types.h:42
wxDEFINE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
@ SIM_IDLE
@ SIM_RUNNING
Stores the common settings that are saved and loaded for each window / frame.
Definition: app_settings.h:74
Definition of file extensions used in Kicad.