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
361void SIMULATOR_FRAME::ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions )
362{
363 wxString errors;
364 WX_STRING_REPORTER reporter( &errors );
365
366 if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, reporter ) )
367 {
368 DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" ) + errors );
369 }
370}
371
372
374{
375 SIM_TAB* simTab = m_ui->GetCurrentSimTab();
376
377 if( !simTab )
378 return;
379
380 if( simTab->GetSimCommand().Upper().StartsWith( wxT( "FFT" ) )
381 || simTab->GetSimCommand().Upper().Contains( wxT( "\nFFT" ) ) )
382 {
383 wxString tranSpicePlot;
384
385 if( SIM_TAB* tranPlotTab = m_ui->GetSimTab( ST_TRAN ) )
386 tranSpicePlot = tranPlotTab->GetSpicePlotName();
387
388 if( tranSpicePlot.IsEmpty() )
389 {
390 DisplayErrorMessage( this, _( "You must run a TRAN simulation first; its results"
391 "will be used for the fast Fourier transform." ) );
392 }
393 else
394 {
395 m_simulator->Command( "setplot " + tranSpicePlot.ToStdString() );
396
397 wxArrayString commands = wxSplit( simTab->GetSimCommand(), '\n' );
398
399 for( const wxString& command : commands )
400 {
401 wxBusyCursor wait;
402 m_simulator->Command( command.ToStdString() );
403 }
404
405 simTab->SetSpicePlotName( m_simulator->CurrentPlotName() );
406 m_ui->OnSimRefresh( true );
407
408#if 0
409 m_simulator->Command( "setplot" ); // Print available plots to console
410 m_simulator->Command( "display" ); // Print vectors in current plot to console
411#endif
412 }
413
414 return;
415 }
416 else
417 {
418 if( m_ui->GetSimTabIndex( simTab ) == 0
419 && m_circuitModel->GetSchTextSimCommand() != simTab->GetLastSchTextSimCommand() )
420 {
421 if( simTab->GetLastSchTextSimCommand().IsEmpty()
422 || IsOK( this, _( "Schematic sheet simulation command directive has changed. "
423 "Do you wish to update the Simulation Command?" ) ) )
424 {
425 simTab->SetSimCommand( m_circuitModel->GetSchTextSimCommand() );
426 simTab->SetLastSchTextSimCommand( simTab->GetSimCommand() );
427 OnModify();
428 }
429 }
430 }
431
432 if( !LoadSimulator( simTab->GetSimCommand(), simTab->GetSimOptions() ) )
433 return;
434
435 std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
436
437 if( simulatorLock.owns_lock() )
438 {
439 m_ui->OnSimUpdate();
440 m_simulator->Run();
441 }
442 else
443 {
444 DisplayErrorMessage( this, _( "Another simulation is already running." ) );
445 }
446}
447
448
449SIM_TAB* SIMULATOR_FRAME::NewSimTab( const wxString& aSimCommand )
450{
451 return m_ui->NewSimTab( aSimCommand );
452}
453
454
455const std::vector<wxString> SIMULATOR_FRAME::SimPlotVectors()
456{
457 return m_ui->SimPlotVectors();
458}
459
460
461const std::vector<wxString> SIMULATOR_FRAME::Signals()
462{
463 return m_ui->Signals();
464}
465
466
467const std::map<int, wxString>& SIMULATOR_FRAME::UserDefinedSignals()
468{
469 return m_ui->UserDefinedSignals();
470}
471
472
473void SIMULATOR_FRAME::SetUserDefinedSignals( const std::map<int, wxString>& aSignals )
474{
475 m_ui->SetUserDefinedSignals( aSignals );
476}
477
478
479void SIMULATOR_FRAME::AddVoltageTrace( const wxString& aNetName )
480{
481 m_ui->AddTrace( aNetName, SPT_VOLTAGE );
482}
483
484
485void SIMULATOR_FRAME::AddCurrentTrace( const wxString& aDeviceName )
486{
487 m_ui->AddTrace( aDeviceName, SPT_CURRENT );
488}
489
490
491void SIMULATOR_FRAME::AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol )
492{
493 m_ui->AddTuner( aSheetPath, aSymbol );
494}
495
496
498{
499 return m_ui->GetCurrentSimTab();
500}
501
502
503bool SIMULATOR_FRAME::LoadWorkbook( const wxString& aPath )
504{
505 if( m_ui->LoadWorkbook( aPath ) )
506 {
507 UpdateTitle();
508
509 // Successfully loading a workbook does not count as modifying it. Clear the modified
510 // flag after all the EVT_WORKBOOK_MODIFIED events have been processed.
511 CallAfter( [=]()
512 {
513 m_workbookModified = false;
514 } );
515
516 return true;
517 }
518
519 return false;
520}
521
522
523bool SIMULATOR_FRAME::SaveWorkbook( const wxString& aPath )
524{
525 if( m_ui->SaveWorkbook( aPath ) )
526 {
527 m_workbookModified = false;
528 UpdateTitle();
529
530 return true;
531 }
532
533 return false;
534}
535
536
538{
540}
541
542
544{
545 SIM_TAB* simTab = m_ui->GetCurrentSimTab();
546 DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() );
547 wxString errors;
548 WX_STRING_REPORTER reporter( &errors );
549
550 if( !simTab )
551 return false;
552
553 if( !m_circuitModel->ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS,
554 reporter ) )
555 {
556 DisplayErrorMessage( this, _( "Errors during netlist generation.\n\n" )
557 + errors );
558 }
559
560 dlg.SetSimCommand( simTab->GetSimCommand() );
561 dlg.SetSimOptions( simTab->GetSimOptions() );
562 dlg.SetPlotSettings( simTab );
563
564 if( dlg.ShowModal() == wxID_OK )
565 {
566 simTab->SetSimCommand( dlg.GetSimCommand() );
567 dlg.ApplySettings( simTab );
569 OnModify();
570 return true;
571 }
572
573 return false;
574}
575
576
577bool SIMULATOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
578{
580 {
581 wxFileName filename = m_simulator->Settings()->GetWorkbookFilename();
582
583 if( filename.GetName().IsEmpty() )
584 {
585 if( Prj().GetProjectName().IsEmpty() )
586 filename.SetFullName( wxT( "noname.wbk" ) );
587 else
588 filename.SetFullName( Prj().GetProjectName() + wxT( ".wbk" ) );
589 }
590
591 return HandleUnsavedChanges( this, _( "Save changes to workbook?" ),
592 [&]() -> bool
593 {
594 return SaveWorkbook( Prj().AbsolutePath( filename.GetFullName() ) );
595 } );
596 }
597
598 return true;
599}
600
601
603{
604 if( m_simulator->IsRunning() )
605 m_simulator->Stop();
606
607 // Prevent memory leak on exit by deleting all simulation vectors
608 m_simulator->Clean();
609
610 // Cancel a running simProbe or simTune tool
612
613 SaveSettings( config() );
614
615 m_simulator->Settings() = nullptr;
616
617 Destroy();
618}
619
620
622{
624
626 wxASSERT( mgr );
627
628 auto showGridCondition =
629 [this]( const SELECTION& aSel )
630 {
631 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
632 return plotTab && plotTab->IsGridShown();
633 };
634
635 auto showLegendCondition =
636 [this]( const SELECTION& aSel )
637 {
638 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
639 return plotTab && plotTab->IsLegendShown();
640 };
641
642 auto showDottedCondition =
643 [this]( const SELECTION& aSel )
644 {
645 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
646 return plotTab && plotTab->GetDottedSecondary();
647 };
648
649 auto darkModePlotCondition =
650 [this]( const SELECTION& aSel )
651 {
652 return m_ui->DarkModePlots();
653 };
654
655 auto simRunning =
656 [this]( const SELECTION& aSel )
657 {
658 return m_simulator && m_simulator->IsRunning();
659 };
660
661 auto simFinished =
662 [this]( const SELECTION& aSel )
663 {
664 return m_simFinished;
665 };
666
667 auto haveSim =
668 [this]( const SELECTION& aSel )
669 {
670 return GetCurrentSimTab() != nullptr;
671 };
672
673 auto havePlot =
674 [this]( const SELECTION& aSel )
675 {
676 return dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) != nullptr;
677 };
678
679 auto haveZoomUndo =
680 [this]( const SELECTION& aSel )
681 {
682 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
683 return plotTab && plotTab->GetPlotWin()->UndoZoomStackSize() > 0;
684 };
685
686 auto haveZoomRedo =
687 [this]( const SELECTION& aSel )
688 {
689 SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
690 return plotTab && plotTab->GetPlotWin()->RedoZoomStackSize() > 0;
691 };
692
693#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
694#define CHECK( x ) ACTION_CONDITIONS().Check( x )
695
699
702
703 mgr->SetConditions( ACTIONS::zoomUndo, ENABLE( haveZoomUndo ) );
704 mgr->SetConditions( ACTIONS::zoomRedo, ENABLE( haveZoomRedo ) );
705 mgr->SetConditions( EE_ACTIONS::toggleGrid, CHECK( showGridCondition ) );
706 mgr->SetConditions( EE_ACTIONS::toggleLegend, CHECK( showLegendCondition ) );
707 mgr->SetConditions( EE_ACTIONS::toggleDottedSecondary, CHECK( showDottedCondition ) );
708 mgr->SetConditions( EE_ACTIONS::toggleDarkModePlots, CHECK( darkModePlotCondition ) );
709
712 mgr->SetConditions( EE_ACTIONS::runSimulation, ENABLE( !simRunning ) );
713 mgr->SetConditions( EE_ACTIONS::stopSimulation, ENABLE( simRunning ) );
714 mgr->SetConditions( EE_ACTIONS::simProbe, ENABLE( simFinished ) );
715 mgr->SetConditions( EE_ACTIONS::simTune, ENABLE( simFinished ) );
717
718#undef CHECK
719#undef ENABLE
720}
721
722
723void SIMULATOR_FRAME::onSimStarted( wxCommandEvent& aEvent )
724{
725 SetCursor( wxCURSOR_ARROWWAIT );
726}
727
728
729void SIMULATOR_FRAME::onSimFinished( wxCommandEvent& aEvent )
730{
731 // Sometimes (for instance with a directive like wrdata my_file.csv "my_signal")
732 // the simulator is in idle state (simulation is finished), but still running, during
733 // the time the file is written. So gives a slice of time to fully finish the work:
734 if( m_simulator->IsRunning() )
735 {
736 int max_time = 40; // For a max timeout = 2s
737
738 do
739 {
740 wxMilliSleep( 50 );
741 wxYield();
742
743 if( max_time )
744 max_time--;
745
746 } while( max_time && m_simulator->IsRunning() );
747 }
748
749 // ensure the shown cursor is the default cursor, not the wxCURSOR_ARROWWAIT set when
750 // staring the simulator in onSimStarted:
751 SetCursor( wxNullCursor );
752
753 // Is a warning message useful if the simulatior is still running?
754 SCHEMATIC& schematic = m_schematicFrame->Schematic();
755 schematic.ClearOperatingPoints();
756
757 m_simFinished = true;
758
759 m_ui->OnSimRefresh( true );
760
763}
764
765
766void SIMULATOR_FRAME::onUpdateSim( wxCommandEvent& aEvent )
767{
768 static bool updateInProgress = false;
769
770 // skip update when events are triggered too often and previous call didn't end yet
771 if( updateInProgress )
772 return;
773
774 updateInProgress = true;
775
776 if( m_simulator->IsRunning() )
777 m_simulator->Stop();
778
779 std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
780
781 if( simulatorLock.owns_lock() )
782 {
783 m_ui->OnSimUpdate();
784 m_simulator->Run();
785 }
786 else
787 {
788 DisplayErrorMessage( this, _( "Another simulation is already running." ) );
789 }
790
791 updateInProgress = false;
792}
793
794
795void SIMULATOR_FRAME::onSimReport( wxCommandEvent& aEvent )
796{
797 m_ui->OnSimReport( aEvent.GetString() );
798}
799
800
801void SIMULATOR_FRAME::onExit( wxCommandEvent& aEvent )
802{
803 if( aEvent.GetId() == wxID_EXIT )
804 Kiway().OnKiCadExit();
805
806 if( aEvent.GetId() == wxID_CLOSE )
807 Close( false );
808}
809
810
812{
814 m_workbookModified = true;
815 UpdateTitle();
816}
817
818
819wxDEFINE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
820wxDEFINE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
821
822wxDEFINE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
823wxDEFINE_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:104
static TOOL_ACTION toggleGrid
Definition: actions.h:168
static TOOL_ACTION cancelInteractive
Definition: actions.h:63
static TOOL_ACTION zoomRedo
Definition: actions.h:125
static TOOL_ACTION zoomUndo
Definition: actions.h:124
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:280
static TOOL_ACTION openWorkbook
Definition: ee_actions.h:269
static TOOL_ACTION stopSimulation
Definition: ee_actions.h:282
static TOOL_ACTION toggleLegend
Definition: ee_actions.h:277
static TOOL_ACTION saveWorkbook
Definition: ee_actions.h:270
static TOOL_ACTION saveWorkbookAs
Definition: ee_actions.h:271
static TOOL_ACTION exportPlotAsCSV
Definition: ee_actions.h:273
static TOOL_ACTION simTune
Definition: ee_actions.h:276
static TOOL_ACTION toggleDarkModePlots
Definition: ee_actions.h:279
static TOOL_ACTION exportPlotAsPNG
Definition: ee_actions.h:272
static TOOL_ACTION showNetlist
Definition: ee_actions.h:284
static TOOL_ACTION simProbe
Definition: ee_actions.h:275
static TOOL_ACTION toggleDottedSecondary
Definition: ee_actions.h:278
static TOOL_ACTION runSimulation
Definition: ee_actions.h:281
static TOOL_ACTION newAnalysisTab
Definition: ee_actions.h:268
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:67
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:743
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:70
virtual PROJECT_FILE & GetProjectFile() const
Definition: project.h:166
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:320
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:109
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)
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
Interface to receive simulation updates from SPICE_SIMULATOR class.
static std::shared_ptr< SPICE_SIMULATOR > CreateInstance(const std::string &aName)
mpWindow * GetPlotWin() const
Definition: sim_plot_tab.h:345
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:167
TOOL_DISPATCHER * m_toolDispatcher
Definition: tools_holder.h:169
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
int RedoZoomStackSize() const
Definition: mathplot.h:1234
int UndoZoomStackSize() const
Definition: mathplot.h:1233
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
Definition: confirm.cpp:360
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:240
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
Definition: confirm.cpp:305
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.