2016-08-11 12:41:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2023-01-01 23:37:24 +00:00
|
|
|
* Copyright (C) 2016-2023 CERN
|
2024-01-23 01:02:50 +00:00
|
|
|
* Copyright (C) 2017-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
2017-06-13 23:47:05 +00:00
|
|
|
*
|
2016-08-11 12:41:07 +00:00
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:07 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:07 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
#ifndef SIMULATOR_FRAME_H
|
|
|
|
#define SIMULATOR_FRAME_H
|
2016-08-11 12:41:01 +00:00
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
#include <sim/simulator_frame_ui_base.h>
|
2023-01-01 23:37:24 +00:00
|
|
|
#include <sim/sim_types.h>
|
2016-08-11 12:41:41 +00:00
|
|
|
|
|
|
|
#include <kiway_player.h>
|
2022-12-11 15:49:29 +00:00
|
|
|
#include <dialogs/dialog_sim_command.h>
|
2016-08-11 12:41:19 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
#include <wx/event.h>
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
#include <list>
|
2016-08-11 12:41:41 +00:00
|
|
|
#include <memory>
|
2016-08-11 12:41:45 +00:00
|
|
|
#include <map>
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:41 +00:00
|
|
|
class SCH_EDIT_FRAME;
|
2021-06-10 14:10:55 +00:00
|
|
|
class SCH_SYMBOL;
|
2023-07-14 09:21:58 +00:00
|
|
|
class SIMULATOR_FRAME_UI;
|
2016-08-19 13:51:19 +00:00
|
|
|
class SIM_THREAD_REPORTER;
|
2023-06-15 12:39:04 +00:00
|
|
|
class ACTION_TOOLBAR;
|
2023-08-08 17:19:40 +00:00
|
|
|
class SPICE_SIMULATOR;
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* The SIMULATOR_FRAME holds the main user-interface for running simulations.
|
|
|
|
*
|
2023-07-09 22:00:25 +00:00
|
|
|
* It contains a workbook with multiple tabs, each tab holding a SIM_PLOT_TAB, a specific
|
2023-03-03 22:36:07 +00:00
|
|
|
* simulation command (.TRAN, .AC, etc.), and simulation settings (save all currents, etc.).
|
|
|
|
*
|
|
|
|
* Each plot can have multiple TRACEs. While internally each TRACE can have multiple cursors,
|
|
|
|
* the GUI supports only two cursors (and a differential cursor) for each plot.
|
|
|
|
*
|
|
|
|
* TRACEs are identified by a signal (V(OUT), I(R2), etc.) and a type (SPT_VOLTAGE, SPT_AC_PHASE,
|
|
|
|
* etc.).
|
|
|
|
*
|
|
|
|
* The simulator outputs simple signals in a vector of the same name. Complex signals (such as
|
|
|
|
* V(OUT) / V(IN)) are stored in vectors of the format "user%d".
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
class SIMULATOR_FRAME : public KIWAY_PLAYER
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2016-08-11 12:42:17 +00:00
|
|
|
public:
|
2023-03-03 22:36:07 +00:00
|
|
|
SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent );
|
|
|
|
~SIMULATOR_FRAME();
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2023-02-12 14:55:00 +00:00
|
|
|
/**
|
|
|
|
* Check and load the current netlist into the simulator.
|
|
|
|
* @return true if document is fully annotated and netlist was loaded successfully.
|
|
|
|
*/
|
2023-07-05 17:25:52 +00:00
|
|
|
bool LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
|
2024-02-13 14:38:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Re-send the current command and settings to the simulator. Use the existing netlist.
|
|
|
|
*/
|
|
|
|
void ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions );
|
2023-02-12 14:55:00 +00:00
|
|
|
|
2023-02-11 23:25:32 +00:00
|
|
|
void StartSimulation();
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-03 22:36:07 +00:00
|
|
|
* Create a new plot tab for a given simulation type.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2023-01-14 00:17:33 +00:00
|
|
|
* @param aSimCommand is requested simulation command.
|
2016-08-11 12:42:17 +00:00
|
|
|
*/
|
2023-07-19 15:25:57 +00:00
|
|
|
SIM_TAB* NewSimTab( const wxString& aSimCommand );
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
/**
|
|
|
|
* Shows a dialog for editing the current tab's simulation command, or creating a new tab
|
|
|
|
* with a different simulation command type.
|
|
|
|
*/
|
2023-07-19 15:25:57 +00:00
|
|
|
bool EditAnalysis();
|
2023-01-01 23:37:24 +00:00
|
|
|
|
2023-07-04 10:04:20 +00:00
|
|
|
/**
|
2023-07-05 17:25:52 +00:00
|
|
|
* @return the list of vectors (signals) in the current simulation results.
|
|
|
|
*/
|
|
|
|
const std::vector<wxString> SimPlotVectors();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return the list of schematic signals + any user defined signals.
|
2023-07-04 10:04:20 +00:00
|
|
|
*/
|
|
|
|
const std::vector<wxString> Signals();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
const std::map<int, wxString>& UserDefinedSignals();
|
2023-02-21 09:06:02 +00:00
|
|
|
|
2023-02-27 21:08:05 +00:00
|
|
|
void SetUserDefinedSignals( const std::map<int, wxString>& aSignals );
|
2023-02-21 09:06:02 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
/**
|
2023-03-03 22:36:07 +00:00
|
|
|
* Add a voltage trace for a given net to the current plot.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2016-08-11 12:42:17 +00:00
|
|
|
* @param aNetName is the net name for which a voltage plot should be created.
|
|
|
|
*/
|
2023-03-03 22:36:07 +00:00
|
|
|
void AddVoltageTrace( const wxString& aNetName );
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-03 22:36:07 +00:00
|
|
|
* Add a current trace for a given device to the current plot.
|
2021-01-26 15:23:37 +00:00
|
|
|
*
|
2016-08-11 12:42:17 +00:00
|
|
|
* @param aDeviceName is the device name (e.g. R1, C1).
|
|
|
|
* @param aParam is the current type (e.g. I, Ic, Id).
|
|
|
|
*/
|
2023-03-03 22:36:07 +00:00
|
|
|
void AddCurrentTrace( const wxString& aDeviceName );
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
/**
|
2021-06-10 14:10:55 +00:00
|
|
|
* Add a tuner for a symbol.
|
2016-08-11 12:42:17 +00:00
|
|
|
*/
|
2022-12-23 22:02:59 +00:00
|
|
|
void AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol );
|
2016-08-11 12:42:17 +00:00
|
|
|
|
|
|
|
/**
|
2023-03-03 22:36:07 +00:00
|
|
|
* Return the current tab (or NULL if there is none).
|
2016-08-11 12:42:17 +00:00
|
|
|
*/
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* GetCurrentSimTab() const;
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2020-02-01 12:05:44 +00:00
|
|
|
/**
|
2023-03-03 22:36:07 +00:00
|
|
|
* Toggle dark-mode of the plot tabs.
|
2023-01-01 23:37:24 +00:00
|
|
|
*/
|
|
|
|
void ToggleDarkModePlots();
|
|
|
|
|
2023-01-04 18:06:04 +00:00
|
|
|
void ShowChangedLanguage() override;
|
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
void ReCreateHToolbar();
|
|
|
|
|
|
|
|
/**
|
2023-03-03 22:36:07 +00:00
|
|
|
* Load plot, signal, cursor, measurement, etc. settings from a file.
|
2020-02-01 12:05:44 +00:00
|
|
|
*/
|
2023-01-01 23:37:24 +00:00
|
|
|
bool LoadWorkbook( const wxString& aPath );
|
|
|
|
|
|
|
|
/**
|
2023-03-03 22:36:07 +00:00
|
|
|
* Save plot, signal, cursor, measurement, etc. settings to a file.
|
2023-01-01 23:37:24 +00:00
|
|
|
*/
|
|
|
|
bool SaveWorkbook( const wxString& aPath );
|
2020-02-01 12:05:44 +00:00
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void LoadSettings( APP_SETTINGS_BASE* aCfg ) override;
|
|
|
|
|
|
|
|
void SaveSettings( APP_SETTINGS_BASE* aCfg ) override;
|
|
|
|
|
2024-01-23 01:02:50 +00:00
|
|
|
void CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged ) override;
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
WINDOW_SETTINGS* GetWindowSettings( APP_SETTINGS_BASE* aCfg ) override;
|
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
SCH_EDIT_FRAME* GetSchematicFrame() const { return m_schematicFrame; }
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
std::shared_ptr<SPICE_CIRCUIT_MODEL> GetCircuitModel() const { return m_circuitModel; }
|
2023-01-01 23:37:24 +00:00
|
|
|
|
|
|
|
std::shared_ptr<SPICE_SIMULATOR> GetSimulator() const { return m_simulator; }
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
wxString GetCurrentSimCommand() const;
|
|
|
|
SIM_TYPE GetCurrentSimType() const;
|
|
|
|
int GetCurrentOptions() const;
|
|
|
|
|
|
|
|
bool SimFinished() const { return m_simFinished; }
|
2023-01-01 23:37:24 +00:00
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
// Simulator doesn't host a canvas
|
2020-03-24 01:01:23 +00:00
|
|
|
wxWindow* GetToolCanvas() const override { return nullptr; }
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
/**
|
|
|
|
* Set the main window title bar text.
|
|
|
|
*/
|
|
|
|
void UpdateTitle();
|
|
|
|
|
2023-02-26 11:57:02 +00:00
|
|
|
void OnModify() override;
|
|
|
|
|
2023-04-16 22:44:43 +00:00
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
private:
|
2023-01-01 23:37:24 +00:00
|
|
|
void setupTools();
|
|
|
|
void doReCreateMenuBar() override;
|
|
|
|
|
|
|
|
void setupUIConditions() override;
|
|
|
|
|
2021-05-09 23:32:49 +00:00
|
|
|
bool canCloseWindow( wxCloseEvent& aEvent ) override;
|
2020-08-24 02:01:14 +00:00
|
|
|
void doCloseWindow() override;
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
void onUpdateSim( wxCommandEvent& aEvent );
|
2016-08-11 12:42:17 +00:00
|
|
|
void onSimReport( wxCommandEvent& aEvent );
|
|
|
|
void onSimStarted( wxCommandEvent& aEvent );
|
|
|
|
void onSimFinished( wxCommandEvent& aEvent );
|
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
void onExit( wxCommandEvent& event );
|
|
|
|
|
|
|
|
private:
|
2023-07-14 09:21:58 +00:00
|
|
|
SCH_EDIT_FRAME* m_schematicFrame;
|
|
|
|
ACTION_TOOLBAR* m_toolBar;
|
|
|
|
SIMULATOR_FRAME_UI* m_ui;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
std::shared_ptr<SPICE_SIMULATOR> m_simulator;
|
|
|
|
SIM_THREAD_REPORTER* m_reporter;
|
|
|
|
std::shared_ptr<SPICE_CIRCUIT_MODEL> m_circuitModel;
|
2023-01-01 23:37:24 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
bool m_simFinished;
|
|
|
|
bool m_workbookModified;
|
2016-08-11 12:41:01 +00:00
|
|
|
};
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
// Commands
|
|
|
|
wxDECLARE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDECLARE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
// Notifications
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDECLARE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
|
|
|
|
wxDECLARE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
#endif // SIMULATOR_FRAME_H
|