78 wxCommandEvent*
event =
new wxCommandEvent( EVT_SIM_REPORT );
79 event->SetString( aText );
91 wxCommandEvent*
event =
nullptr;
95 case SIM_IDLE:
event =
new wxCommandEvent( EVT_SIM_FINISHED );
break;
96 case SIM_RUNNING:
event =
new wxCommandEvent( EVT_SIM_STARTED );
break;
97 default: wxFAIL;
return;
117 m_schematicFrame(
nullptr ),
118 m_toolBar(
nullptr ),
120 m_simFinished( false ),
121 m_workbookModified( false )
124 wxASSERT( m_schematicFrame );
131 wxBoxSizer* mainSizer =
new wxBoxSizer( wxVERTICAL );
132 SetSizer( mainSizer );
135 mainSizer->Add( m_infoBar, 0, wxEXPAND, 0 );
137 m_toolBar =
new ACTION_TOOLBAR(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
138 wxAUI_TB_DEFAULT_STYLE|wxAUI_TB_HORZ_LAYOUT|wxAUI_TB_PLAIN_BACKGROUND );
139 m_toolBar->Realize();
140 mainSizer->Add( m_toolBar, 0, wxEXPAND, 5 );
143 mainSizer->Add( m_ui, 1, wxEXPAND, 5 );
146 wxASSERT( m_simulator );
152 wxCHECK2( settings, );
160 m_simulator->SetReporter( m_reporter );
162 m_circuitModel = std::make_shared<SPICE_CIRCUIT_MODEL>( &m_schematicFrame->Schematic() );
187 m_ui->SetSubWindowsSashSize();
192 m_ui->InitWorkbook();
201 m_simulator->Attach(
nullptr, wxEmptyString, 0, wxEmptyString, devnull );
269 if(
project.m_SchematicSettings )
271 bool modified =
project.m_SchematicSettings->m_NgspiceSettings->SaveToFile();
284 wxASSERT( cfg !=
nullptr );
316 return simTab->GetSimOptions();
325 bool readOnly =
false;
329 if( filename.IsOk() && filename.FileExists() )
332 readOnly = !filename.IsFileWritable();
336 title = wxT(
"*" ) + filename.GetName();
338 title = filename.GetName();
341 title += wxS(
" " ) +
_(
"[Read Only]" );
344 title += wxS(
" " ) +
_(
"[Unsaved]" );
346 title += wxT(
" \u2014 " ) +
_(
"SPICE Simulator" );
353#define MAX_MESSAGES 20
360 wxArrayString lines = wxSplit( aReporter.
GetMessages(),
'\n' );
365 lines.Add( wxS(
"..." ) );
371 wxJoin( lines,
'\n' ) );
376 wxJoin( lines,
'\n' ) );
419 if( simTab->
GetSimCommand().Upper().StartsWith( wxT(
"FFT" ) )
420 || simTab->
GetSimCommand().Upper().Contains( wxT(
"\nFFT" ) ) )
422 wxString tranSpicePlot;
427 if( tranSpicePlot.IsEmpty() )
430 "will be used for the fast Fourier transform." ) );
434 m_simulator->Command(
"setplot " + tranSpicePlot.ToStdString() );
436 wxArrayString commands = wxSplit( simTab->
GetSimCommand(),
'\n' );
438 for(
const wxString& command : commands )
461 ||
IsOK(
this,
_(
"Schematic sheet simulation command directive has changed. "
462 "Do you wish to update the Simulation Command?" ) ) )
474 std::unique_lock<std::mutex> simulatorLock(
m_simulator->GetMutex(), std::try_to_lock );
476 if( simulatorLock.owns_lock() )
625 wxFileName filename =
m_simulator->Settings()->GetWorkbookFilename();
627 if( filename.GetName().IsEmpty() )
629 if(
Prj().GetProjectName().IsEmpty() )
630 filename.SetFullName( wxT(
"noname.wbk" ) );
632 filename.SetFullName(
Prj().GetProjectName() + wxT(
".wbk" ) );
672 auto showGridCondition =
679 auto showLegendCondition =
686 auto showDottedCondition =
693 auto darkModePlotCondition =
737#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
738#define CHECK( x ) ACTION_CONDITIONS().Check( x )
771 SetCursor( wxCURSOR_ARROWWAIT );
797 SetCursor( wxNullCursor );
814 static bool updateInProgress =
false;
817 if( updateInProgress )
820 updateInProgress =
true;
825 std::unique_lock<std::mutex> simulatorLock(
m_simulator->GetMutex(), std::try_to_lock );
827 if( simulatorLock.owns_lock() )
837 updateInProgress =
false;
849 if( aEvent.GetId() == wxID_EXIT )
852 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
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.
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
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
static TOOL_ACTION openWorkbook
static TOOL_ACTION stopSimulation
static TOOL_ACTION toggleLegend
static TOOL_ACTION saveWorkbook
static TOOL_ACTION saveWorkbookAs
static TOOL_ACTION exportPlotAsCSV
static TOOL_ACTION simTune
static TOOL_ACTION toggleDarkModePlots
static TOOL_ACTION exportPlotAsPNG
static TOOL_ACTION showNetlist
static TOOL_ACTION simProbe
static TOOL_ACTION toggleDottedSecondary
static TOOL_ACTION exportPlotToSchematic
static TOOL_ACTION runSimulation
static TOOL_ACTION newAnalysisTab
static TOOL_ACTION exportPlotToClipboard
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.
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...
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Container for Ngspice simulator settings.
void SetCompatibilityMode(NGSPICE_COMPATIBILITY_MODE aMode)
A singleton reporter that reports to nowhere.
The backing store for a PROJECT, in JSON format.
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.
A pure virtual class used to derive REPORTER objects from.
Holds all the data relating to one schematic.
void ClearOperatingPoints()
Clear operating points from a .op simulation.
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...
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 ToggleDarkModePlots()
void OnPlotSettingsChanged()
void OnSimReport(const wxString &aMsg)
void ApplyPreferences(const SIM_PREFERENCES &aPrefs)
Called when settings are changed via the common Preferences dialog.
void ShowChangedLanguage()
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)
void CommonSettingsChanged(bool aEnvVarsChanged, bool aTextVarsChanged) override
Notification event that some of the common (suite-wide) settings have changed.
bool LoadSimulator(const wxString &aSimCommand, unsigned aSimOptions)
Check and load the current netlist into the simulator.
void onSimReport(wxCommandEvent &aEvent)
wxString GetCurrentSimCommand() const
void showNetlistErrors(const WX_STRING_REPORTER &aReporter)
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
bool GetDottedSecondary() const
Toggle cursor for a particular trace.
bool IsLegendShown() const
int GetSimOptions() const
const wxString & GetSpicePlotName() const
void SetLastSchTextSimCommand(const wxString &aCmd)
void SetSimCommand(const wxString &aSimCommand)
const wxString & GetSimCommand() const
wxString GetLastSchTextSimCommand() const
void SetSpicePlotName(const wxString &aPlotName)
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
A modified version of the wxInfoBar class that allows us to:
A wrapper for reporting to a wxString object.
bool HasMessage() const override
Returns true if the reporter client is non-empty.
bool HasMessageOfSeverity(int aSeverityMask) const override
Returns true if the reporter has one or more messages matching the specified severity mask.
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.
SIM_TYPE
< Possible simulation types
wxDEFINE_EVENT(EVT_SIM_UPDATE, wxCommandEvent)
static WX_STRING_REPORTER s_reporter
KIWAY Kiway(KFCTL_STANDALONE)
Stores the common settings that are saved and loaded for each window / frame.
Definition of file extensions used in Kicad.