77 std::lock_guard lock(
m_mutex );
79 wxString messages =
m_strRep.GetMessages();
100 wxCommandEvent*
event =
nullptr;
104 case SIM_IDLE:
event =
new wxCommandEvent( EVT_SIM_FINISHED );
break;
105 case SIM_RUNNING:
event =
new wxCommandEvent( EVT_SIM_STARTED );
break;
106 default: wxFAIL;
return;
125 wxDefaultSize, wxDEFAULT_FRAME_STYLE, wxT(
"simulator" ),
unityScale ),
142 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
143 SetSizer( mainSizer );
146 mainSizer->Add(
m_infoBar, 0, wxEXPAND, 0 );
149 wxAUI_TB_DEFAULT_STYLE|wxAUI_TB_HORZ_LAYOUT|wxAUI_TB_PLAIN_BACKGROUND );
154 mainSizer->Add(
m_ui, 1, wxEXPAND, 5 );
165 if( cfg->GetWorkbookFilename().IsEmpty() )
205 m_ui->SetSubWindowsSashSize();
210 m_ui->InitWorkbook();
211 m_ui->FlushSimConsole();
220 m_simulator->Attach(
nullptr, wxEmptyString, 0, wxEmptyString, devnull );
253 m_ui->ShowChangedLanguage();
262 m_ui->LoadSettings( cfg );
275 m_ui->SaveSettings( cfg );
290 m_ui->ApplyPreferences( cfg->m_Simulator.preferences );
297 return &cfg->m_Simulator.window;
299 wxFAIL_MSG( wxT(
"SIMULATOR not running with EESCHEMA_SETTINGS" ) );
306 if(
m_ui->GetCurrentSimTab() )
307 return m_ui->GetCurrentSimTab()->GetSimCommand();
322 return simTab->GetSimOptions();
331 bool readOnly =
false;
334 wxFileName filename =
Prj().
AbsolutePath( cfg->GetWorkbookFilename() );
336 if( filename.IsOk() && filename.FileExists() )
339 readOnly = !filename.IsFileWritable();
343 title = wxT(
"*" ) + filename.GetName();
345 title = filename.GetName();
348 title += wxS(
" " ) +
_(
"[Read Only]" );
351 title += wxS(
" " ) +
_(
"[Unsaved]" );
353 title += wxT(
" \u2014 " ) +
_(
"SPICE Simulator" );
360#define MAX_MESSAGES 20
367 wxArrayString lines = wxSplit( aReporter.
GetMessages(),
'\n' );
372 lines.Add( wxS(
"..." ) );
378 wxJoin( lines,
'\n' ) );
383 wxJoin( lines,
'\n' ) );
392 if( !
m_schematicFrame->ReadyToNetlist(
_(
"Simulator requires a fully annotated schematic." ) ) )
423 if( oldPlotName.IsEmpty() )
429 if(
m_ui->IsPlotOwnedByOtherTab( aSimTab, oldPlotName ) )
437 long noiseNumber = 0;
439 if( oldPlotName.StartsWith( wxS(
"noise" ) ) && oldPlotName.Mid( 5 ).ToLong( &noiseNumber ) )
441 long spectral = ( noiseNumber % 2 == 0 ) ? noiseNumber - 1 : noiseNumber;
445 wxString::Format( wxT(
"destroy noise%ld" ), spectral + 1 ).
ToStdString() );
449 m_simulator->Command(
"destroy " + oldPlotName.ToStdString() );
463 if( simTab->
GetSimCommand().Upper().StartsWith( wxT(
"FFT" ) )
464 || simTab->
GetSimCommand().Upper().Contains( wxT(
"\nFFT" ) ) )
466 wxString tranSpicePlot;
469 tranSpicePlot = tranPlotTab->GetSpicePlotName();
471 if( tranSpicePlot.IsEmpty() )
474 "will be used for the fast Fourier transform." ) );
482 m_simulator->Command(
"setplot " + tranSpicePlot.ToStdString() );
484 wxArrayString commands = wxSplit( simTab->
GetSimCommand(),
'\n' );
486 for(
const wxString& command : commands )
493 m_ui->OnSimRefresh(
true );
505 if(
m_ui->GetSimTabIndex( simTab ) == 0
509 ||
IsOK(
this,
_(
"Schematic sheet simulation command directive has changed. "
510 "Do you wish to update the Simulation Command?" ) ) )
522 std::unique_lock<std::mutex> simulatorLock(
m_simulator->GetMutex(), std::try_to_lock );
524 if( simulatorLock.owns_lock() )
538 m_ui->OnPlotSettingsChanged();
549 return m_ui->NewSimTab( aSimCommand );
555 return m_ui->SimPlotVectors();
561 return m_ui->Signals();
567 return m_ui->UserDefinedSignals();
573 m_ui->SetUserDefinedSignals( aSignals );
591 m_ui->AddTuner( aSheetPath, aSymbol );
597 return m_ui->GetCurrentSimTab();
603 if(
m_ui->LoadWorkbook( aPath ) )
624 if(
m_ui->SaveWorkbook( aPath ) )
638 m_ui->ToggleSimConsole();
644 m_ui->ToggleSimSidePanel();
650 m_ui->ToggleSmithChart();
656 m_ui->ToggleDarkModePlots();
683 m_ui->OnPlotSettingsChanged();
696 wxFileName filename =
m_simulator->Settings()->GetWorkbookFilename();
698 if( filename.GetName().IsEmpty() )
700 if(
Prj().GetProjectName().IsEmpty() )
701 filename.SetFullName( wxT(
"noname.wbk" ) );
703 filename.SetFullName(
Prj().GetProjectName() + wxT(
".wbk" ) );
743 auto showGridCondition =
750 auto showLegendCondition =
757 auto showDottedCondition =
764 auto darkModePlotCondition =
767 return m_ui->DarkModePlots();
770 auto smithChartCondition =
823 auto isSimConsoleShown =
829 return m_ui->IsSimConsoleShown();
834 auto isSimSidePanelShown =
840 return m_ui->IsSimSidePanelShown();
846#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
847#define CHECK( x ) ACTION_CONDITIONS().Check( x )
885 SetCursor( wxCURSOR_ARROWWAIT );
920 SetCursor( wxNullCursor );
928 m_ui->OnSimRefresh(
true );
937 static bool updateInProgress =
false;
940 if( updateInProgress )
943 updateInProgress =
true;
948 std::unique_lock<std::mutex> simulatorLock(
m_simulator->GetMutex(), std::try_to_lock );
950 if( simulatorLock.owns_lock() )
966 updateInProgress =
false;
972 if( aEvent.GetId() == wxID_EXIT )
975 if( aEvent.GetId() == wxID_CLOSE )
constexpr EDA_IU_SCALE unityScale
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
static TOOL_ACTION toggleGrid
static TOOL_ACTION cancelInteractive
static TOOL_ACTION zoomRedo
static TOOL_ACTION zoomUndo
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...
APP_SETTINGS_BASE is a settings class that should be derived for each standalone KiCad application.
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
Return the settings object used in SaveSettings(), and is overloaded in KICAD_MANAGER_FRAME.
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
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...
TOOLBAR_SETTINGS * m_toolbarSettings
virtual void configureToolbars()
virtual void RecreateToolbars()
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.
ACTION_TOOLBAR * m_tbTopMain
void ReCreateMenuBar()
Recreate the menu bar.
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.
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
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...
bool SaveToFile(const wxString &aDirectory="", bool aForce=false) override
Calls Store() and then saves the JSON document contents into the parent JSON_SETTINGS.
A singleton reporter that reports to nowhere.
SCHEMATIC_SETTINGS * m_SchematicSettings
virtual PROJECT_FILE & GetProjectFile() const
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.
virtual bool HasMessageOfSeverity(int aSeverityMask) const
Returns true if the reporter has one or more messages matching the specified severity mask.
virtual bool HasMessage() const
Returns true if any messages were reported.
std::shared_ptr< NGSPICE_SETTINGS > m_NgspiceSettings
Ngspice simulator settings.
Holds all the data relating to one schematic.
void ClearOperatingPoints()
Clear operating points from a .op simulation.
static TOOL_ACTION toggleSimConsole
static TOOL_ACTION exportPlotToClipboard
static TOOL_ACTION saveWorkbookAs
static TOOL_ACTION toggleSimSidePanel
static TOOL_ACTION exportPlotAsCSV
static TOOL_ACTION simAnalysisProperties
static TOOL_ACTION toggleSmithChart
static TOOL_ACTION toggleDottedSecondary
static TOOL_ACTION simTune
static TOOL_ACTION toggleDarkModePlots
static TOOL_ACTION exportPlotAsPNG
static TOOL_ACTION exportPlotToSchematic
static TOOL_ACTION runSimulation
static TOOL_ACTION newAnalysisTab
static TOOL_ACTION simProbe
static TOOL_ACTION showNetlist
static TOOL_ACTION openWorkbook
static TOOL_ACTION saveWorkbook
static TOOL_ACTION toggleLegend
static TOOL_ACTION stopSimulation
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...
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.
The SIMULATOR_FRAME holds the main user-interface for running simulations.
SIMULATOR_FRAME(KIWAY *aKiway, wxWindow *aParent)
SIM_TAB * GetCurrentSimTab() const
Return the current tab (or NULL if there is none).
void ShowChangedLanguage() override
Redraw the menus and what not in current language.
bool canCloseWindow(wxCloseEvent &aEvent) override
void onSimFinished(wxCommandEvent &aEvent)
bool LoadSimulator(const wxString &aSimCommand, unsigned aSimOptions)
Check and load the current netlist into the simulator.
wxString GetCurrentSimCommand() const
void CommonSettingsChanged(int aFlags) override
Notification event that some of the common (suite-wide) settings have changed.
void showNetlistErrors(const WX_STRING_REPORTER &aReporter)
void onExit(wxCommandEvent &event)
void destroyTabPlot(SIM_TAB *aSimTab)
Free a tab's previous ngspice plot (and its noise companion) so reruns don't leak.
std::shared_ptr< SPICE_SIMULATOR > m_simulator
SIM_TYPE GetCurrentSimType() const
void setupUIConditions() override
Setup the UI conditions for the various actions and their controls in this frame.
void SaveSettings(APP_SETTINGS_BASE *aCfg) override
Save common frame parameters to a configuration data file.
ACTION_TOOLBAR * m_toolBar
wxString TakeSimReportMessages()
void AddCurrentTrace(const wxString &aDeviceName)
Add a current trace for a given device to the current plot.
void OnModify() override
Must be called after a model change in order to set the "modify" flag and do other frame-specific pro...
bool SaveWorkbook(const wxString &aPath)
Save plot, signal, cursor, measurement, etc.
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.
void AddTuner(const SCH_SHEET_PATH &aSheetPath, SCH_SYMBOL *aSymbol)
Add a tuner for a symbol.
void onSimStarted(wxCommandEvent &aEvent)
void LoadSettings(APP_SETTINGS_BASE *aCfg) override
Load common frame parameters from a configuration file.
std::shared_ptr< SPICE_CIRCUIT_MODEL > m_circuitModel
SIM_TAB * NewSimTab(const wxString &aSimCommand)
Create a new plot tab for a given simulation type.
bool EditAnalysis()
Shows a dialog for editing the current tab's simulation command, or creating a new tab with a differe...
int GetCurrentOptions() const
bool LoadWorkbook(const wxString &aPath)
Load plot, signal, cursor, measurement, etc.
WINDOW_SETTINGS * GetWindowSettings(APP_SETTINGS_BASE *aCfg) override
Return a pointer to the window settings for this frame.
void onUpdateSim(wxCommandEvent &aEvent)
void UpdateTitle()
Set the main window title bar text.
const std::map< int, wxString > & UserDefinedSignals()
SIM_FRAME_STATE_LISTENER * m_stateListener
void ToggleSmithChart()
Toggle the current S-parameter tab between Smith chart and amplitude/phase views.
void SetUserDefinedSignals(const std::map< int, wxString > &aSignals)
void ToggleSimSidePanel()
void ReloadSimulator(const wxString &aSimCommand, unsigned aSimOptions)
Re-send the current command and settings to the simulator.
SIM_CONSOLE_REPORTER * m_consoleReporter
SCH_EDIT_FRAME * m_schematicFrame
SIMULATOR_FRAME_UI * m_ui
Simple error container for failure to init the simulation engine and ultimately abort the frame const...
static std::shared_ptr< SPICE_SIMULATOR > CreateInstance(const std::string &aName)
Create a simulator instance of particular type (currently only ngspice is handled)
wxString TakePendingMessages()
WX_STRING_REPORTER m_strRep
SIM_FRAME_STATE_LISTENER(SIMULATOR_FRAME *aParent)
void OnSimStateChange(SIMULATOR *aObject, SIM_STATE aNewState) override
SIMULATOR_FRAME * m_parent
mpWindow * GetPlotWin() const
Getter for the default view's math plot window (back-compat for zoom undo/redo, export).
bool GetDottedSecondary() const
bool IsLegendShown() const
Interface to receive simulation state transitions from SPICE_SIMULATOR.
int GetSimOptions() const
const wxString & GetSpicePlotName() const
void SetLastSchTextSimCommand(const wxString &aCmd)
SIM_TYPE GetSimType() const
void SetSimCommand(const wxString &aSimCommand)
const wxString & GetSimCommand() const
wxString GetLastSchTextSimCommand() const
void SetSpicePlotName(const wxString &aPlotName)
static SIM_TYPE CommandToSimType(const wxString &aCmd)
Return simulation type basing on a simulation command directive.
SYNC_REPORTER(REPORTER &aReporter)
A modified version of the wxInfoBar class that allows us to:
A wrapper for reporting to a wxString object.
const wxString & GetMessages() const
int RedoZoomStackSize() const
int UndoZoomStackSize() const
bool IsOK(wxWindow *aParent, const wxString &aMessage)
Display a yes/no dialog with aMessage and returns the user response.
void DisplayInfoMessage(wxWindow *aParent, const wxString &aMessage, const wxString &aExtraInfo)
Display an informational message box with aMessage.
bool HandleUnsavedChanges(wxWindow *aParent, const wxString &aMessage, const std::function< bool()> &aSaveFunction)
Display a dialog with Save, Cancel and Discard Changes buttons.
void DisplayErrorMessage(wxWindow *aParent, const wxString &aText, const wxString &aExtraInfo)
Display an error message with aMessage.
This file is part of the common library.
static std::string ToStdString(const wxString &aStr)
EVT_MENU(ID_COMPARE_PROJECT_BRANCHES, KICAD_MANAGER_FRAME::OnCompareProjectBranches) KICAD_MANAGER_FRAME
T * GetToolbarSettings(const wxString &aFilename)
T * GetAppSettings(const char *aFilename)
SIM_TYPE
Possible simulation types.
wxDEFINE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
static WX_STRING_REPORTER s_reporter
KIWAY Kiway(KFCTL_STANDALONE)
Functors that can be used to figure out how the action controls should be displayed in the UI and if ...
Store the common settings that are saved and loaded for each window / frame.
Definition of file extensions used in Kicad.