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-05-08 20:39:23 +00:00
|
|
|
* Copyright (C) 2016-2024 KiCad Developers, see AUTHORS.txt for contributors.
|
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
|
|
|
|
*/
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
#include <wx/debug.h>
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2022-11-16 09:09:54 +00:00
|
|
|
// For some obscure reason, needed on msys2 with some wxWidgets versions (3.0) to avoid
|
|
|
|
// undefined symbol at link stage (due to use of #include <pegtl.hpp>)
|
|
|
|
// Should not create issues on other platforms
|
|
|
|
#include <wx/menu.h>
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
#include <project/project_file.h>
|
2018-01-30 10:49:51 +00:00
|
|
|
#include <sch_edit_frame.h>
|
2016-08-11 12:41:01 +00:00
|
|
|
#include <kiway.h>
|
2016-08-11 12:41:45 +00:00
|
|
|
#include <confirm.h>
|
2016-08-11 12:42:00 +00:00
|
|
|
#include <bitmaps.h>
|
2017-11-12 00:31:38 +00:00
|
|
|
#include <wildcards_and_files_ext.h>
|
2016-08-11 12:41:45 +00:00
|
|
|
#include <widgets/tuner_slider.h>
|
2023-01-29 16:01:03 +00:00
|
|
|
#include <widgets/grid_color_swatch_helpers.h>
|
|
|
|
#include <widgets/wx_grid.h>
|
2023-01-01 23:37:24 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tool/tool_dispatcher.h>
|
|
|
|
#include <tool/action_manager.h>
|
|
|
|
#include <tool/action_toolbar.h>
|
|
|
|
#include <tool/common_control.h>
|
|
|
|
#include <tools/simulator_control.h>
|
|
|
|
#include <tools/ee_actions.h>
|
|
|
|
#include <string_utils.h>
|
2016-09-17 07:34:16 +00:00
|
|
|
#include <pgm_base.h>
|
2022-11-12 19:45:56 +00:00
|
|
|
#include "ngspice.h"
|
2023-06-15 12:39:04 +00:00
|
|
|
#include <sim/simulator_frame.h>
|
2023-07-14 09:21:58 +00:00
|
|
|
#include <sim/simulator_frame_ui.h>
|
2023-07-09 22:00:25 +00:00
|
|
|
#include <sim/sim_plot_tab.h>
|
2023-06-15 12:39:04 +00:00
|
|
|
#include <sim/spice_simulator.h>
|
2023-07-14 09:21:58 +00:00
|
|
|
#include <sim/simulator_reporter.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <eeschema_settings.h>
|
2023-05-03 16:57:22 +00:00
|
|
|
#include <advanced_config.h>
|
2023-01-01 23:37:24 +00:00
|
|
|
|
|
|
|
#include <memory>
|
2016-08-29 09:39:54 +00:00
|
|
|
|
2021-07-09 20:20:23 +00:00
|
|
|
|
2024-05-18 22:44:12 +00:00
|
|
|
// Reporter is stored by pointer in KIBIS, so keep this here to avoid crashes
|
|
|
|
static wxString s_errors;
|
|
|
|
static WX_STRING_REPORTER s_reporter( &s_errors );
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
class SIM_THREAD_REPORTER : public SIMULATOR_REPORTER
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-03-03 22:36:07 +00:00
|
|
|
SIM_THREAD_REPORTER( SIMULATOR_FRAME* aParent ) :
|
2021-03-18 19:31:02 +00:00
|
|
|
m_parent( aParent )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2020-03-04 09:48:18 +00:00
|
|
|
REPORTER& Report( const wxString& aText, SEVERITY aSeverity = RPT_SEVERITY_UNDEFINED ) override
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
wxCommandEvent* event = new wxCommandEvent( EVT_SIM_REPORT );
|
2016-08-11 12:41:19 +00:00
|
|
|
event->SetString( aText );
|
2016-08-11 12:41:07 +00:00
|
|
|
wxQueueEvent( m_parent, event );
|
|
|
|
return *this;
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
2018-02-18 20:22:16 +00:00
|
|
|
bool HasMessage() const override
|
2018-02-17 11:43:56 +00:00
|
|
|
{
|
|
|
|
return false; // Technically "indeterminate" rather than false.
|
|
|
|
}
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void OnSimStateChange( SIMULATOR* aObject, SIM_STATE aNewState ) override
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
wxCommandEvent* event = nullptr;
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
switch( aNewState )
|
|
|
|
{
|
2022-12-23 22:02:59 +00:00
|
|
|
case SIM_IDLE: event = new wxCommandEvent( EVT_SIM_FINISHED ); break;
|
|
|
|
case SIM_RUNNING: event = new wxCommandEvent( EVT_SIM_STARTED ); break;
|
|
|
|
default: wxFAIL; return;
|
2016-08-11 12:41:19 +00:00
|
|
|
}
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
wxQueueEvent( m_parent, event );
|
2016-08-11 12:41:07 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
private:
|
2023-03-03 22:36:07 +00:00
|
|
|
SIMULATOR_FRAME* m_parent;
|
2016-08-11 12:41:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
BEGIN_EVENT_TABLE( SIMULATOR_FRAME, KIWAY_PLAYER )
|
2023-04-16 22:44:43 +00:00
|
|
|
EVT_MENU( wxID_EXIT, SIMULATOR_FRAME::onExit )
|
|
|
|
EVT_MENU( wxID_CLOSE, SIMULATOR_FRAME::onExit )
|
|
|
|
END_EVENT_TABLE()
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
SIMULATOR_FRAME::SIMULATOR_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
2023-06-15 12:39:04 +00:00
|
|
|
KIWAY_PLAYER( aKiway, aParent, FRAME_SIMULATOR, _( "Simulator" ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxDEFAULT_FRAME_STYLE, wxT( "simulator" ), unityScale ),
|
2023-06-15 16:38:43 +00:00
|
|
|
m_schematicFrame( nullptr ),
|
|
|
|
m_toolBar( nullptr ),
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui( nullptr ),
|
2023-02-11 20:39:50 +00:00
|
|
|
m_simFinished( false ),
|
2023-02-12 14:55:00 +00:00
|
|
|
m_workbookModified( false )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2016-08-11 12:41:41 +00:00
|
|
|
m_schematicFrame = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
|
2023-01-01 23:37:24 +00:00
|
|
|
wxASSERT( m_schematicFrame );
|
2016-08-11 12:41:41 +00:00
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
// Give an icon
|
|
|
|
wxIcon icon;
|
2021-03-08 02:59:07 +00:00
|
|
|
icon.CopyFromBitmap( KiBitmap( BITMAPS::simulator ) );
|
2016-08-29 09:39:54 +00:00
|
|
|
SetIcon( icon );
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
wxBoxSizer* mainSizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
SetSizer( mainSizer );
|
2023-01-29 16:01:03 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
m_infoBar = new WX_INFOBAR( this );
|
|
|
|
mainSizer->Add( m_infoBar, 0, wxEXPAND, 0 );
|
2023-01-29 16:01:03 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
m_toolBar = new ACTION_TOOLBAR( this, wxID_ANY, wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxAUI_TB_DEFAULT_STYLE|wxAUI_TB_HORZ_LAYOUT|wxAUI_TB_PLAIN_BACKGROUND );
|
|
|
|
m_toolBar->Realize();
|
|
|
|
mainSizer->Add( m_toolBar, 0, wxEXPAND, 5 );
|
2023-01-29 16:01:03 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui = new SIMULATOR_FRAME_UI( this, m_schematicFrame );
|
|
|
|
mainSizer->Add( m_ui, 1, wxEXPAND, 5 );
|
2023-01-29 16:01:03 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
m_simulator = SIMULATOR::CreateInstance( "ngspice" );
|
|
|
|
wxASSERT( m_simulator );
|
2023-02-11 20:39:50 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
LoadSettings( config() );
|
2019-04-14 13:31:32 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
NGSPICE_SETTINGS* settings = dynamic_cast<NGSPICE_SETTINGS*>( m_simulator->Settings().get() );
|
2023-04-22 20:23:42 +00:00
|
|
|
|
2023-06-03 11:28:03 +00:00
|
|
|
wxCHECK2( settings, /* do nothing in release builds*/ );
|
|
|
|
|
|
|
|
if( settings && settings->GetWorkbookFilename().IsEmpty() )
|
2023-07-14 09:21:58 +00:00
|
|
|
settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LT_PSPICE );
|
2023-04-22 20:23:42 +00:00
|
|
|
|
2016-08-19 13:51:19 +00:00
|
|
|
m_simulator->Init();
|
|
|
|
|
|
|
|
m_reporter = new SIM_THREAD_REPORTER( this );
|
|
|
|
m_simulator->SetReporter( m_reporter );
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
m_circuitModel = std::make_shared<SPICE_CIRCUIT_MODEL>( &m_schematicFrame->Schematic(), this );
|
2023-01-01 23:37:24 +00:00
|
|
|
|
|
|
|
setupTools();
|
|
|
|
setupUIConditions();
|
2016-08-11 12:41:41 +00:00
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
ReCreateHToolbar();
|
|
|
|
ReCreateMenuBar();
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIMULATOR_FRAME::onExit ), this,
|
2023-01-19 12:59:18 +00:00
|
|
|
wxID_EXIT );
|
2023-01-13 13:38:23 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
Bind( EVT_SIM_UPDATE, &SIMULATOR_FRAME::onUpdateSim, this );
|
2023-03-03 22:36:07 +00:00
|
|
|
Bind( EVT_SIM_REPORT, &SIMULATOR_FRAME::onSimReport, this );
|
|
|
|
Bind( EVT_SIM_STARTED, &SIMULATOR_FRAME::onSimStarted, this );
|
|
|
|
Bind( EVT_SIM_FINISHED, &SIMULATOR_FRAME::onSimFinished, this );
|
2021-04-23 02:24:20 +00:00
|
|
|
|
2021-03-08 12:49:45 +00:00
|
|
|
// Ensure new items are taken in account by sizers:
|
|
|
|
Layout();
|
|
|
|
|
2016-12-02 14:34:23 +00:00
|
|
|
// resize the subwindows size. At least on Windows, calling wxSafeYield before
|
|
|
|
// resizing the subwindows forces the wxSplitWindows size events automatically generated
|
|
|
|
// by wxWidgets to be executed before our resize code.
|
|
|
|
// Otherwise, the changes made by setSubWindowsSashSize are overwritten by one these
|
|
|
|
// events
|
|
|
|
wxSafeYield();
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->SetSubWindowsSashSize();
|
2020-04-17 23:32:29 +00:00
|
|
|
|
|
|
|
// Ensure the window is on top
|
|
|
|
Raise();
|
2021-05-04 22:35:04 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->InitWorkbook();
|
2023-06-15 12:39:04 +00:00
|
|
|
UpdateTitle();
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
SIMULATOR_FRAME::~SIMULATOR_FRAME()
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2022-11-18 15:27:53 +00:00
|
|
|
NULL_REPORTER devnull;
|
|
|
|
|
2024-05-08 20:39:23 +00:00
|
|
|
m_simulator->Attach( nullptr, wxEmptyString, 0, wxEmptyString, devnull );
|
2016-08-19 14:39:46 +00:00
|
|
|
m_simulator->SetReporter( nullptr );
|
2016-08-19 13:51:19 +00:00
|
|
|
delete m_reporter;
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 14:34:23 +00:00
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::setupTools()
|
2023-01-01 23:37:24 +00:00
|
|
|
{
|
|
|
|
// Create the manager
|
|
|
|
m_toolManager = new TOOL_MANAGER;
|
|
|
|
m_toolManager->SetEnvironment( nullptr, nullptr, nullptr, config(), this );
|
|
|
|
|
|
|
|
m_toolDispatcher = new TOOL_DISPATCHER( m_toolManager );
|
|
|
|
|
|
|
|
// Attach the events to the tool dispatcher
|
|
|
|
Bind( wxEVT_CHAR, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
|
|
|
|
Bind( wxEVT_CHAR_HOOK, &TOOL_DISPATCHER::DispatchWxEvent, m_toolDispatcher );
|
|
|
|
|
|
|
|
// Register tools
|
|
|
|
m_toolManager->RegisterTool( new COMMON_CONTROL );
|
|
|
|
m_toolManager->RegisterTool( new SIMULATOR_CONTROL );
|
|
|
|
m_toolManager->InitTools();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::ShowChangedLanguage()
|
2023-01-04 18:06:04 +00:00
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::ShowChangedLanguage();
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
UpdateTitle();
|
2023-01-04 18:06:04 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->ShowChangedLanguage();
|
2023-01-04 18:06:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
|
|
|
wxASSERT( cfg );
|
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::LoadSettings( cfg );
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->LoadSettings( cfg );
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
|
|
|
|
|
|
|
NGSPICE* currentSim = dynamic_cast<NGSPICE*>( m_simulator.get() );
|
|
|
|
|
|
|
|
if( currentSim )
|
2023-07-14 09:21:58 +00:00
|
|
|
m_simulator->Settings() = project.m_SchematicSettings->m_NgspiceSettings;
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
|
2016-12-02 14:34:23 +00:00
|
|
|
{
|
2021-02-16 15:17:02 +00:00
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
2020-01-13 01:44:19 +00:00
|
|
|
wxASSERT( cfg );
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( cfg )
|
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::SaveSettings( cfg );
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->SaveSettings( cfg );
|
2023-02-26 17:09:56 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
2023-03-10 21:32:16 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( project.m_SchematicSettings )
|
2023-03-10 21:32:16 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
bool modified = project.m_SchematicSettings->m_NgspiceSettings->SaveToFile();
|
2023-03-10 21:32:16 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( m_schematicFrame && modified )
|
|
|
|
m_schematicFrame->OnModify();
|
2023-03-10 21:32:16 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-03-10 21:32:16 +00:00
|
|
|
|
2023-02-12 00:54:54 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
WINDOW_SETTINGS* SIMULATOR_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
|
|
|
wxASSERT( cfg );
|
2021-05-09 23:32:49 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
return cfg ? &cfg->m_Simulator.window : nullptr;
|
|
|
|
}
|
2021-08-14 15:54:20 +00:00
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
wxString SIMULATOR_FRAME::GetCurrentSimCommand() const
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
if( m_ui->GetCurrentSimTab() )
|
|
|
|
return m_ui->GetCurrentSimTab()->GetSimCommand();
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
|
|
|
return m_circuitModel->GetSchTextSimCommand();
|
|
|
|
}
|
2023-02-12 14:55:00 +00:00
|
|
|
|
2023-02-14 00:03:30 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
SIM_TYPE SIMULATOR_FRAME::GetCurrentSimType() const
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
return SPICE_CIRCUIT_MODEL::CommandToSimType( GetCurrentSimCommand() );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
int SIMULATOR_FRAME::GetCurrentOptions() const
|
2016-08-11 12:42:12 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
if( SIM_TAB* simTab = m_ui->GetCurrentSimTab() )
|
2023-07-09 22:00:25 +00:00
|
|
|
return simTab->GetSimOptions();
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
2023-07-05 17:25:52 +00:00
|
|
|
return NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS;
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2018-01-30 10:49:51 +00:00
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
void SIMULATOR_FRAME::UpdateTitle()
|
|
|
|
{
|
|
|
|
bool unsaved = true;
|
|
|
|
bool readOnly = false;
|
|
|
|
wxString title;
|
|
|
|
wxFileName filename = Prj().AbsolutePath( m_simulator->Settings()->GetWorkbookFilename() );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( filename.IsOk() && filename.FileExists() )
|
2016-08-11 12:42:12 +00:00
|
|
|
{
|
2023-06-15 12:39:04 +00:00
|
|
|
unsaved = false;
|
|
|
|
readOnly = !filename.IsFileWritable();
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( m_workbookModified )
|
|
|
|
title = wxT( "*" ) + filename.GetName();
|
|
|
|
else
|
|
|
|
title = filename.GetName();
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( readOnly )
|
|
|
|
title += wxS( " " ) + _( "[Read Only]" );
|
2021-06-30 00:13:10 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( unsaved )
|
|
|
|
title += wxS( " " ) + _( "[Unsaved]" );
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
title += wxT( " \u2014 " ) + _( "Spice Simulator" );
|
2023-01-14 00:17:33 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
SetTitle( title );
|
|
|
|
}
|
2023-01-14 00:17:33 +00:00
|
|
|
|
|
|
|
|
2024-06-24 21:47:42 +00:00
|
|
|
// Don't let the dialog grow too tall: you may not be able to get to the OK button
|
|
|
|
#define MAX_MESSAGES 20
|
|
|
|
|
|
|
|
void SIMULATOR_FRAME::showNetlistErrors( const wxString& aErrors )
|
|
|
|
{
|
|
|
|
wxArrayString lines = wxSplit( aErrors, '\n' );
|
|
|
|
|
|
|
|
if( lines.size() > MAX_MESSAGES )
|
|
|
|
{
|
|
|
|
lines.RemoveAt( MAX_MESSAGES, lines.size() - MAX_MESSAGES );
|
|
|
|
lines.Add( wxS( "..." ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
DisplayErrorMessage( this, _( "Errors during netlist generation." ), wxJoin( lines, '\n' ) );
|
|
|
|
}
|
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
bool SIMULATOR_FRAME::LoadSimulator( const wxString& aSimCommand, unsigned aSimOptions )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2024-05-18 22:44:12 +00:00
|
|
|
s_errors.clear();
|
2023-01-14 00:17:33 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( !m_schematicFrame->ReadyToNetlist( _( "Simulator requires a fully annotated schematic." ) ) )
|
|
|
|
return false;
|
2023-02-10 20:52:52 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
// If we are using the new connectivity, make sure that we do a full-rebuild
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
|
|
|
|
m_schematicFrame->RecalculateConnections( nullptr, GLOBAL_CLEANUP );
|
2021-05-04 22:35:04 +00:00
|
|
|
|
2024-05-08 20:39:23 +00:00
|
|
|
if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, Prj().GetProjectPath(),
|
2024-05-18 22:44:12 +00:00
|
|
|
s_reporter ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2024-06-24 21:47:42 +00:00
|
|
|
showNetlistErrors( s_errors );
|
2023-06-15 12:39:04 +00:00
|
|
|
return false;
|
|
|
|
}
|
2021-05-26 18:15:16 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
return true;
|
|
|
|
}
|
2021-05-24 20:17:29 +00:00
|
|
|
|
2023-03-20 09:43:16 +00:00
|
|
|
|
2024-02-13 14:38:02 +00:00
|
|
|
void SIMULATOR_FRAME::ReloadSimulator( const wxString& aSimCommand, unsigned aSimOptions )
|
|
|
|
{
|
2024-06-24 21:47:42 +00:00
|
|
|
s_errors.clear();
|
|
|
|
|
2024-05-08 20:39:23 +00:00
|
|
|
if( !m_simulator->Attach( m_circuitModel, aSimCommand, aSimOptions, Prj().GetProjectPath(),
|
2024-05-18 22:44:12 +00:00
|
|
|
s_reporter ) )
|
2024-02-13 14:38:02 +00:00
|
|
|
{
|
2024-06-24 21:47:42 +00:00
|
|
|
showNetlistErrors( s_errors );
|
2024-02-13 14:38:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
void SIMULATOR_FRAME::StartSimulation()
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
SIM_TAB* simTab = m_ui->GetCurrentSimTab();
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !simTab )
|
2023-07-05 17:25:52 +00:00
|
|
|
return;
|
|
|
|
|
2023-11-04 15:19:05 +00:00
|
|
|
if( simTab->GetSimCommand().Upper().StartsWith( wxT( "FFT" ) )
|
|
|
|
|| simTab->GetSimCommand().Upper().Contains( wxT( "\nFFT" ) ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
wxString tranSpicePlot;
|
2023-03-20 09:43:16 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
if( SIM_TAB* tranPlotTab = m_ui->GetSimTab( ST_TRAN ) )
|
2023-07-09 22:00:25 +00:00
|
|
|
tranSpicePlot = tranPlotTab->GetSpicePlotName();
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
if( tranSpicePlot.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "You must run a TRAN simulation first; its results"
|
|
|
|
"will be used for the fast Fourier transform." ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_simulator->Command( "setplot " + tranSpicePlot.ToStdString() );
|
2023-02-27 21:08:05 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxArrayString commands = wxSplit( simTab->GetSimCommand(), '\n' );
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
for( const wxString& command : commands )
|
|
|
|
{
|
|
|
|
wxBusyCursor wait;
|
|
|
|
m_simulator->Command( command.ToStdString() );
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
simTab->SetSpicePlotName( m_simulator->CurrentPlotName() );
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->OnSimRefresh( true );
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
m_simulator->Command( "setplot" ); // Print available plots to console
|
|
|
|
m_simulator->Command( "display" ); // Print vectors in current plot to console
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
if( m_ui->GetSimTabIndex( simTab ) == 0
|
2023-07-09 22:00:25 +00:00
|
|
|
&& m_circuitModel->GetSchTextSimCommand() != simTab->GetLastSchTextSimCommand() )
|
2021-07-02 00:10:41 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( simTab->GetLastSchTextSimCommand().IsEmpty()
|
2023-07-08 17:46:56 +00:00
|
|
|
|| IsOK( this, _( "Schematic sheet simulation command directive has changed. "
|
|
|
|
"Do you wish to update the Simulation Command?" ) ) )
|
2023-02-12 00:54:54 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
simTab->SetSimCommand( m_circuitModel->GetSchTextSimCommand() );
|
|
|
|
simTab->SetLastSchTextSimCommand( simTab->GetSimCommand() );
|
2023-06-15 12:39:04 +00:00
|
|
|
OnModify();
|
2023-02-12 00:54:54 +00:00
|
|
|
}
|
2023-03-20 09:43:16 +00:00
|
|
|
}
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !LoadSimulator( simTab->GetSimCommand(), simTab->GetSimOptions() ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
return;
|
2023-02-21 13:31:32 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
|
2023-02-21 13:31:32 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( simulatorLock.owns_lock() )
|
2023-02-21 13:31:32 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->OnSimUpdate();
|
2023-06-15 12:39:04 +00:00
|
|
|
m_simulator->Run();
|
2024-05-10 11:02:38 +00:00
|
|
|
|
|
|
|
// Netlist from schematic may have changed; update signals list, measurements list,
|
|
|
|
// etc.
|
|
|
|
m_ui->OnPlotSettingsChanged();
|
2023-02-21 13:31:32 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
2021-08-14 15:54:20 +00:00
|
|
|
{
|
2023-06-15 12:39:04 +00:00
|
|
|
DisplayErrorMessage( this, _( "Another simulation is already running." ) );
|
2021-08-14 15:54:20 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2023-02-12 14:55:00 +00:00
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
SIM_TAB* SIMULATOR_FRAME::NewSimTab( const wxString& aSimCommand )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
return m_ui->NewSimTab( aSimCommand );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
const std::vector<wxString> SIMULATOR_FRAME::SimPlotVectors()
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
return m_ui->SimPlotVectors();
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-04 10:04:20 +00:00
|
|
|
const std::vector<wxString> SIMULATOR_FRAME::Signals()
|
2016-08-11 12:41:42 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
return m_ui->Signals();
|
2016-08-11 12:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
const std::map<int, wxString>& SIMULATOR_FRAME::UserDefinedSignals()
|
2019-11-19 16:17:37 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
return m_ui->UserDefinedSignals();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2020-02-01 12:05:44 +00:00
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
void SIMULATOR_FRAME::SetUserDefinedSignals( const std::map<int, wxString>& aSignals )
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->SetUserDefinedSignals( aSignals );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2020-02-01 12:05:44 +00:00
|
|
|
|
2020-12-29 03:33:01 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
void SIMULATOR_FRAME::AddVoltageTrace( const wxString& aNetName )
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->AddTrace( aNetName, SPT_VOLTAGE );
|
2020-02-01 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
void SIMULATOR_FRAME::AddCurrentTrace( const wxString& aDeviceName )
|
2016-08-11 12:42:07 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->AddTrace( aDeviceName, SPT_CURRENT );
|
2021-05-11 23:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
void SIMULATOR_FRAME::AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol )
|
2021-05-11 23:27:34 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->AddTuner( aSheetPath, aSymbol );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-02-22 13:52:52 +00:00
|
|
|
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* SIMULATOR_FRAME::GetCurrentSimTab() const
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
return m_ui->GetCurrentSimTab();
|
2016-08-11 12:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
bool SIMULATOR_FRAME::LoadWorkbook( const wxString& aPath )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
if( m_ui->LoadWorkbook( aPath ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
UpdateTitle();
|
|
|
|
|
|
|
|
// Successfully loading a workbook does not count as modifying it. Clear the modified
|
|
|
|
// flag after all the EVT_WORKBOOK_MODIFIED events have been processed.
|
|
|
|
CallAfter( [=]()
|
|
|
|
{
|
|
|
|
m_workbookModified = false;
|
|
|
|
} );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2021-05-11 23:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
bool SIMULATOR_FRAME::SaveWorkbook( const wxString& aPath )
|
2021-05-11 23:27:34 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
if( m_ui->SaveWorkbook( aPath ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_workbookModified = false;
|
2023-07-24 06:55:34 +00:00
|
|
|
UpdateTitle();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
void SIMULATOR_FRAME::ToggleDarkModePlots()
|
2021-07-11 18:31:50 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->ToggleDarkModePlots();
|
2021-07-11 18:31:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
bool SIMULATOR_FRAME::EditAnalysis()
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
SIM_TAB* simTab = m_ui->GetCurrentSimTab();
|
2023-07-09 22:00:25 +00:00
|
|
|
DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() );
|
2024-05-18 22:44:12 +00:00
|
|
|
|
|
|
|
s_errors.clear();
|
2022-11-18 15:27:53 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !simTab )
|
2023-07-05 17:25:52 +00:00
|
|
|
return false;
|
|
|
|
|
2022-11-18 15:27:53 +00:00
|
|
|
if( !m_circuitModel->ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS,
|
2024-05-18 22:44:12 +00:00
|
|
|
s_reporter ) )
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
2024-06-24 21:47:42 +00:00
|
|
|
showNetlistErrors( s_errors );
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
2016-08-11 12:42:09 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
dlg.SetSimCommand( simTab->GetSimCommand() );
|
|
|
|
dlg.SetSimOptions( simTab->GetSimOptions() );
|
2023-07-19 15:25:57 +00:00
|
|
|
dlg.SetPlotSettings( simTab );
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2022-12-05 20:01:36 +00:00
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
simTab->SetSimCommand( dlg.GetSimCommand() );
|
2023-07-19 15:25:57 +00:00
|
|
|
dlg.ApplySettings( simTab );
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->OnPlotSettingsChanged();
|
2023-02-26 11:57:02 +00:00
|
|
|
OnModify();
|
2023-01-21 13:24:47 +00:00
|
|
|
return true;
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2023-01-21 13:24:47 +00:00
|
|
|
|
|
|
|
return false;
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
bool SIMULATOR_FRAME::canCloseWindow( wxCloseEvent& aEvent )
|
2021-05-09 23:32:49 +00:00
|
|
|
{
|
2023-02-12 14:55:00 +00:00
|
|
|
if( m_workbookModified )
|
2021-05-09 23:32:49 +00:00
|
|
|
{
|
|
|
|
wxFileName filename = m_simulator->Settings()->GetWorkbookFilename();
|
|
|
|
|
|
|
|
if( filename.GetName().IsEmpty() )
|
2021-06-30 19:27:52 +00:00
|
|
|
{
|
|
|
|
if( Prj().GetProjectName().IsEmpty() )
|
|
|
|
filename.SetFullName( wxT( "noname.wbk" ) );
|
|
|
|
else
|
|
|
|
filename.SetFullName( Prj().GetProjectName() + wxT( ".wbk" ) );
|
|
|
|
}
|
2021-05-09 23:32:49 +00:00
|
|
|
|
2023-01-29 16:01:03 +00:00
|
|
|
return HandleUnsavedChanges( this, _( "Save changes to workbook?" ),
|
|
|
|
[&]() -> bool
|
|
|
|
{
|
|
|
|
return SaveWorkbook( Prj().AbsolutePath( filename.GetFullName() ) );
|
|
|
|
} );
|
2021-05-09 23:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::doCloseWindow()
|
2016-08-11 12:41:07 +00:00
|
|
|
{
|
2021-07-06 18:58:29 +00:00
|
|
|
if( m_simulator->IsRunning() )
|
2016-08-11 12:41:19 +00:00
|
|
|
m_simulator->Stop();
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2022-05-28 20:40:24 +00:00
|
|
|
// Prevent memory leak on exit by deleting all simulation vectors
|
|
|
|
m_simulator->Clean();
|
|
|
|
|
2019-08-04 20:46:09 +00:00
|
|
|
// Cancel a running simProbe or simTune tool
|
2023-06-26 22:16:51 +00:00
|
|
|
m_schematicFrame->GetToolManager()->PostAction( ACTIONS::cancelInteractive );
|
2019-08-04 20:46:09 +00:00
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
SaveSettings( config() );
|
2022-12-11 01:29:58 +00:00
|
|
|
|
|
|
|
m_simulator->Settings() = nullptr;
|
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
Destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::setupUIConditions()
|
2023-01-01 23:37:24 +00:00
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::setupUIConditions();
|
|
|
|
|
|
|
|
ACTION_MANAGER* mgr = m_toolManager->GetActionManager();
|
|
|
|
wxASSERT( mgr );
|
|
|
|
|
|
|
|
auto showGridCondition =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
|
|
|
return plotTab && plotTab->IsGridShown();
|
2023-01-01 23:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto showLegendCondition =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
|
|
|
return plotTab && plotTab->IsLegendShown();
|
2023-01-01 23:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto showDottedCondition =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
|
|
|
return plotTab && plotTab->GetDottedSecondary();
|
2023-01-01 23:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto darkModePlotCondition =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
return m_ui->DarkModePlots();
|
2023-01-01 23:37:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto simRunning =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_simulator && m_simulator->IsRunning();
|
|
|
|
};
|
|
|
|
|
|
|
|
auto simFinished =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
return m_simFinished;
|
|
|
|
};
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
auto haveSim =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
return GetCurrentSimTab() != nullptr;
|
2023-07-05 17:25:52 +00:00
|
|
|
};
|
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
auto havePlot =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
return dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) != nullptr;
|
2023-01-01 23:37:24 +00:00
|
|
|
};
|
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
auto haveZoomUndo =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
|
|
|
return plotTab && plotTab->GetPlotWin()->UndoZoomStackSize() > 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
auto haveZoomRedo =
|
|
|
|
[this]( const SELECTION& aSel )
|
|
|
|
{
|
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
|
|
|
return plotTab && plotTab->GetPlotWin()->RedoZoomStackSize() > 0;
|
|
|
|
};
|
|
|
|
|
2023-01-01 23:37:24 +00:00
|
|
|
#define ENABLE( x ) ACTION_CONDITIONS().Enable( x )
|
|
|
|
#define CHECK( x ) ACTION_CONDITIONS().Check( x )
|
|
|
|
|
|
|
|
mgr->SetConditions( EE_ACTIONS::openWorkbook, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::saveWorkbook, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::saveWorkbookAs, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
|
|
|
|
|
|
|
|
mgr->SetConditions( EE_ACTIONS::exportPlotAsPNG, ENABLE( havePlot ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::exportPlotAsCSV, ENABLE( havePlot ) );
|
|
|
|
|
2023-09-26 12:18:28 +00:00
|
|
|
mgr->SetConditions( ACTIONS::zoomUndo, ENABLE( haveZoomUndo ) );
|
|
|
|
mgr->SetConditions( ACTIONS::zoomRedo, ENABLE( haveZoomRedo ) );
|
2023-01-01 23:37:24 +00:00
|
|
|
mgr->SetConditions( EE_ACTIONS::toggleGrid, CHECK( showGridCondition ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::toggleLegend, CHECK( showLegendCondition ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::toggleDottedSecondary, CHECK( showDottedCondition ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::toggleDarkModePlots, CHECK( darkModePlotCondition ) );
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
mgr->SetConditions( EE_ACTIONS::newAnalysisTab, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::simAnalysisProperties, ENABLE( haveSim ) );
|
2023-01-21 13:24:47 +00:00
|
|
|
mgr->SetConditions( EE_ACTIONS::runSimulation, ENABLE( !simRunning ) );
|
2023-01-01 23:37:24 +00:00
|
|
|
mgr->SetConditions( EE_ACTIONS::stopSimulation, ENABLE( simRunning ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::simProbe, ENABLE( simFinished ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::simTune, ENABLE( simFinished ) );
|
|
|
|
mgr->SetConditions( EE_ACTIONS::showNetlist, ENABLE( SELECTION_CONDITIONS::ShowAlways ) );
|
|
|
|
|
|
|
|
#undef CHECK
|
|
|
|
#undef ENABLE
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::onSimStarted( wxCommandEvent& aEvent )
|
2016-08-11 12:41:19 +00:00
|
|
|
{
|
2016-08-11 12:41:19 +00:00
|
|
|
SetCursor( wxCURSOR_ARROWWAIT );
|
2016-08-11 12:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::onSimFinished( wxCommandEvent& aEvent )
|
2016-08-11 12:41:07 +00:00
|
|
|
{
|
2022-08-31 10:07:05 +00:00
|
|
|
// Sometimes (for instance with a directive like wrdata my_file.csv "my_signal")
|
|
|
|
// the simulator is in idle state (simulation is finished), but still running, during
|
|
|
|
// the time the file is written. So gives a slice of time to fully finish the work:
|
2021-07-06 18:58:29 +00:00
|
|
|
if( m_simulator->IsRunning() )
|
2022-08-31 10:07:05 +00:00
|
|
|
{
|
|
|
|
int max_time = 40; // For a max timeout = 2s
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
wxMilliSleep( 50 );
|
|
|
|
wxYield();
|
|
|
|
|
|
|
|
if( max_time )
|
|
|
|
max_time--;
|
|
|
|
|
|
|
|
} while( max_time && m_simulator->IsRunning() );
|
|
|
|
}
|
2016-08-11 12:42:19 +00:00
|
|
|
|
2023-07-10 11:30:02 +00:00
|
|
|
// ensure the shown cursor is the default cursor, not the wxCURSOR_ARROWWAIT set when
|
|
|
|
// staring the simulator in onSimStarted:
|
|
|
|
SetCursor( wxNullCursor );
|
|
|
|
|
|
|
|
// Is a warning message useful if the simulatior is still running?
|
2023-02-22 13:52:52 +00:00
|
|
|
SCHEMATIC& schematic = m_schematicFrame->Schematic();
|
|
|
|
schematic.ClearOperatingPoints();
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
m_simFinished = true;
|
2023-02-05 20:47:27 +00:00
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->OnSimRefresh( true );
|
2021-07-09 19:35:47 +00:00
|
|
|
|
2023-02-22 13:52:52 +00:00
|
|
|
m_schematicFrame->RefreshOperatingPointDisplay();
|
2023-03-05 01:33:07 +00:00
|
|
|
m_schematicFrame->GetCanvas()->Refresh();
|
2016-08-11 12:41:07 +00:00
|
|
|
}
|
2016-08-11 12:41:19 +00:00
|
|
|
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
void SIMULATOR_FRAME::onUpdateSim( wxCommandEvent& aEvent )
|
2016-08-11 12:41:45 +00:00
|
|
|
{
|
2022-03-29 21:51:09 +00:00
|
|
|
static bool updateInProgress = false;
|
|
|
|
|
|
|
|
// skip update when events are triggered too often and previous call didn't end yet
|
|
|
|
if( updateInProgress )
|
|
|
|
return;
|
|
|
|
|
|
|
|
updateInProgress = true;
|
|
|
|
|
2021-07-06 18:58:29 +00:00
|
|
|
if( m_simulator->IsRunning() )
|
2022-03-26 15:50:15 +00:00
|
|
|
m_simulator->Stop();
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
|
|
|
|
|
|
|
|
if( simulatorLock.owns_lock() )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->OnSimUpdate();
|
2023-07-05 17:25:52 +00:00
|
|
|
m_simulator->Run();
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
DisplayErrorMessage( this, _( "Another simulation is already running." ) );
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2022-03-29 21:51:09 +00:00
|
|
|
updateInProgress = false;
|
2016-08-11 12:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::onSimReport( wxCommandEvent& aEvent )
|
2016-08-11 12:41:19 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
m_ui->OnSimReport( aEvent.GetString() );
|
2016-08-11 12:41:19 +00:00
|
|
|
}
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
|
2023-04-18 22:55:16 +00:00
|
|
|
void SIMULATOR_FRAME::onExit( wxCommandEvent& aEvent )
|
2023-01-13 13:38:23 +00:00
|
|
|
{
|
2023-04-18 22:55:16 +00:00
|
|
|
if( aEvent.GetId() == wxID_EXIT )
|
|
|
|
Kiway().OnKiCadExit();
|
|
|
|
|
|
|
|
if( aEvent.GetId() == wxID_CLOSE )
|
|
|
|
Close( false );
|
2023-01-13 13:38:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-03-03 22:36:07 +00:00
|
|
|
void SIMULATOR_FRAME::OnModify()
|
2023-02-26 11:57:02 +00:00
|
|
|
{
|
|
|
|
KIWAY_PLAYER::OnModify();
|
|
|
|
m_workbookModified = true;
|
2023-08-09 11:09:00 +00:00
|
|
|
UpdateTitle();
|
2023-02-26 11:57:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
wxDEFINE_EVENT( EVT_SIM_UPDATE, wxCommandEvent );
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDEFINE_EVENT( EVT_SIM_REPORT, wxCommandEvent );
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
wxDEFINE_EVENT( EVT_SIM_STARTED, wxCommandEvent );
|
|
|
|
wxDEFINE_EVENT( EVT_SIM_FINISHED, wxCommandEvent );
|