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() )
204 m_ui->SetSubWindowsSashSize();
209 m_ui->InitWorkbook();
210 m_ui->FlushSimConsole();
219 m_simulator->Attach(
nullptr, wxEmptyString, 0, wxEmptyString, devnull );
252 m_ui->ShowChangedLanguage();
261 m_ui->LoadSettings( cfg );
274 m_ui->SaveSettings( cfg );
289 m_ui->ApplyPreferences( cfg->m_Simulator.preferences );
296 return &cfg->m_Simulator.window;
298 wxFAIL_MSG( wxT(
"SIMULATOR not running with EESCHEMA_SETTINGS" ) );
305 if(
m_ui->GetCurrentSimTab() )
306 return m_ui->GetCurrentSimTab()->GetSimCommand();
321 return simTab->GetSimOptions();
330 bool readOnly =
false;
333 wxFileName filename =
Prj().
AbsolutePath( cfg->GetWorkbookFilename() );
335 if( filename.IsOk() && filename.FileExists() )
338 readOnly = !filename.IsFileWritable();
342 title = wxT(
"*" ) + filename.GetName();
344 title = filename.GetName();
347 title += wxS(
" " ) +
_(
"[Read Only]" );
350 title += wxS(
" " ) +
_(
"[Unsaved]" );
352 title += wxT(
" \u2014 " ) +
_(
"SPICE Simulator" );
359#define MAX_MESSAGES 20
366 wxArrayString lines = wxSplit( aReporter.
GetMessages(),
'\n' );
371 lines.Add( wxS(
"..." ) );
377 wxJoin( lines,
'\n' ) );
382 wxJoin( lines,
'\n' ) );
391 if( !
m_schematicFrame->ReadyToNetlist(
_(
"Simulator requires a fully annotated schematic." ) ) )
422 if( oldPlotName.IsEmpty() )
428 if(
m_ui->IsPlotOwnedByOtherTab( aSimTab, oldPlotName ) )
436 long noiseNumber = 0;
438 if( oldPlotName.StartsWith( wxS(
"noise" ) ) && oldPlotName.Mid( 5 ).ToLong( &noiseNumber ) )
440 long spectral = ( noiseNumber % 2 == 0 ) ? noiseNumber - 1 : noiseNumber;
444 wxString::Format( wxT(
"destroy noise%ld" ), spectral + 1 ).
ToStdString() );
448 m_simulator->Command(
"destroy " + oldPlotName.ToStdString() );
462 if( simTab->
GetSimCommand().Upper().StartsWith( wxT(
"FFT" ) )
463 || simTab->
GetSimCommand().Upper().Contains( wxT(
"\nFFT" ) ) )
465 wxString tranSpicePlot;
468 tranSpicePlot = tranPlotTab->GetSpicePlotName();
470 if( tranSpicePlot.IsEmpty() )
473 "will be used for the fast Fourier transform." ) );
481 m_simulator->Command(
"setplot " + tranSpicePlot.ToStdString() );
483 wxArrayString commands = wxSplit( simTab->
GetSimCommand(),
'\n' );
485 for(
const wxString& command : commands )
492 m_ui->OnSimRefresh(
true );
504 if(
m_ui->GetSimTabIndex( simTab ) == 0
508 ||
IsOK(
this,
_(
"Schematic sheet simulation command directive has changed. "
509 "Do you wish to update the Simulation Command?" ) ) )
521 std::unique_lock<std::mutex> simulatorLock(
m_simulator->GetMutex(), std::try_to_lock );
523 if( simulatorLock.owns_lock() )
537 m_ui->OnPlotSettingsChanged();
548 return m_ui->NewSimTab( aSimCommand );
554 return m_ui->SimPlotVectors();
560 return m_ui->Signals();
566 return m_ui->UserDefinedSignals();
572 m_ui->SetUserDefinedSignals( aSignals );
590 m_ui->AddTuner( aSheetPath, aSymbol );
596 return m_ui->GetCurrentSimTab();
602 if(
m_ui->LoadWorkbook( aPath ) )
623 if(
m_ui->SaveWorkbook( aPath ) )
637 m_ui->ToggleSimConsole();
643 m_ui->ToggleSimSidePanel();
649 m_ui->ToggleSmithChart();
655 m_ui->ToggleDarkModePlots();
682 m_ui->OnPlotSettingsChanged();
695 wxFileName filename =
m_simulator->Settings()->GetWorkbookFilename();
697 if( filename.GetName().IsEmpty() )
699 if(
Prj().GetProjectName().IsEmpty() )
700 filename.SetFullName( wxT(
"noname.wbk" ) );
702 filename.SetFullName(
Prj().GetProjectName() + wxT(
".wbk" ) );
742 auto showGridCondition =
749 auto showLegendCondition =
756 auto showDottedCondition =
763 auto darkModePlotCondition =
766 return m_ui->DarkModePlots();
769 auto smithChartCondition =
822 auto isSimConsoleShown =
828 return m_ui->IsSimConsoleShown();
833 auto isSimSidePanelShown =
839 return m_ui->IsSimSidePanelShown();
845#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
846#define CHECK( x ) ACTION_CONDITIONS().Check( x )
884 SetCursor( wxCURSOR_ARROWWAIT );
916 SetCursor( wxNullCursor );
920 schematic.ClearOperatingPoints();
924 m_ui->OnSimRefresh(
true );
933 static bool updateInProgress =
false;
936 if( updateInProgress )
939 updateInProgress =
true;
944 std::unique_lock<std::mutex> simulatorLock(
m_simulator->GetMutex(), std::try_to_lock );
946 if( simulatorLock.owns_lock() )
962 updateInProgress =
false;
968 if( aEvent.GetId() == wxID_EXIT )
971 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...
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.
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.
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)
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
bool GetDottedSecondary() const
bool IsLegendShown() const
bool IsSmithMode() const
Refresh the grid z0 from the shown Smith traces.
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.