2016-08-11 12:41:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-12-05 20:01:36 +00:00
|
|
|
* Copyright (C) 2016-2022 CERN
|
2023-01-19 12:59:18 +00:00
|
|
|
* Copyright (C) 2016-2023 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
|
|
|
#include <wx/stc/stc.h>
|
|
|
|
|
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:16 +00:00
|
|
|
#include <eeschema_id.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>
|
2016-08-11 12:41:42 +00:00
|
|
|
#include <dialogs/dialog_signal_list.h>
|
2022-09-16 04:56:51 +00:00
|
|
|
#include <scintilla_tricks.h>
|
2021-07-29 09:56:22 +00:00
|
|
|
#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"
|
|
|
|
#include "sim_plot_frame.h"
|
|
|
|
#include "sim_plot_panel.h"
|
|
|
|
#include "spice_simulator.h"
|
|
|
|
#include "spice_reporter.h"
|
2016-08-29 09:39:54 +00:00
|
|
|
#include <menus_helpers.h>
|
2019-06-03 13:49:17 +00:00
|
|
|
#include <tool/tool_manager.h>
|
|
|
|
#include <tools/ee_actions.h>
|
2020-01-13 01:44:19 +00:00
|
|
|
#include <eeschema_settings.h>
|
2020-12-12 18:11:51 +00:00
|
|
|
#include <wx/ffile.h>
|
2021-05-01 07:50:29 +00:00
|
|
|
#include <wx/filedlg.h>
|
2022-08-14 17:36:40 +00:00
|
|
|
#include <wx_filename.h>
|
2023-05-17 06:42:29 +00:00
|
|
|
#include <advanced_config.h> // for Incremental Connectivity option
|
2016-08-29 09:39:54 +00:00
|
|
|
|
2021-07-09 20:20:23 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
SIM_PLOT_TYPE operator|( SIM_PLOT_TYPE aFirst, SIM_PLOT_TYPE aSecond )
|
|
|
|
{
|
|
|
|
int res = (int) aFirst | (int) aSecond;
|
|
|
|
|
|
|
|
return (SIM_PLOT_TYPE) res;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
class SIM_THREAD_REPORTER : public SPICE_REPORTER
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
|
|
|
public:
|
2021-03-18 19:31:02 +00:00
|
|
|
SIM_THREAD_REPORTER( SIM_PLOT_FRAME* aParent ) :
|
|
|
|
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.
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
void OnSimStateChange( SPICE_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:
|
2016-08-11 12:41:07 +00:00
|
|
|
SIM_PLOT_FRAME* m_parent;
|
2016-08-11 12:41:01 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent ) :
|
|
|
|
SIM_PLOT_FRAME_BASE( aParent ),
|
|
|
|
m_lastSimPlot( nullptr ),
|
2021-07-09 19:35:47 +00:00
|
|
|
m_plotNumber( 0 ),
|
|
|
|
m_simFinished( false )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2016-08-11 12:41:15 +00:00
|
|
|
SetKiway( this, aKiway );
|
2021-07-12 20:10:35 +00:00
|
|
|
m_signalsIconColorList = nullptr;
|
2016-08-11 12:41:15 +00:00
|
|
|
|
2016-08-11 12:41:41 +00:00
|
|
|
m_schematicFrame = (SCH_EDIT_FRAME*) Kiway().Player( FRAME_SCH, false );
|
|
|
|
|
2021-07-12 20:10:35 +00:00
|
|
|
if( m_schematicFrame == nullptr )
|
2016-08-11 12:41:41 +00:00
|
|
|
throw std::runtime_error( "There is no schematic window" );
|
|
|
|
|
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 );
|
|
|
|
|
2022-03-05 23:49:25 +00:00
|
|
|
m_simulator = SIMULATOR::CreateInstance( "ngspice" );
|
2021-03-18 19:31:02 +00:00
|
|
|
|
|
|
|
if( !m_simulator )
|
|
|
|
{
|
|
|
|
throw std::runtime_error( "Could not create simulator instance" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-02 14:34:23 +00:00
|
|
|
// Get the previous size and position of windows:
|
|
|
|
LoadSettings( config() );
|
|
|
|
|
2020-02-01 12:05:44 +00:00
|
|
|
// Prepare the color list to plot traces
|
2021-01-21 21:17:13 +00:00
|
|
|
SIM_PLOT_COLORS::FillDefaultColorList( GetPlotBgOpt() );
|
2020-02-01 12:05:44 +00:00
|
|
|
|
2019-04-14 13:31:32 +00:00
|
|
|
// Give icons to menuitems
|
|
|
|
setIconsForMenuItems();
|
|
|
|
|
2016-08-19 13:51:19 +00:00
|
|
|
m_simulator->Init();
|
|
|
|
|
|
|
|
m_reporter = new SIM_THREAD_REPORTER( this );
|
|
|
|
m_simulator->SetReporter( m_reporter );
|
|
|
|
|
2023-01-19 12:59:18 +00:00
|
|
|
m_circuitModel.reset( new NGSPICE_CIRCUIT_MODEL( &m_schematicFrame->Schematic(), this ) );
|
2016-08-11 12:41:41 +00:00
|
|
|
|
2023-01-19 12:59:18 +00:00
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( SIM_PLOT_FRAME::menuExit ), this,
|
|
|
|
wxID_EXIT );
|
2023-01-13 13:38:23 +00:00
|
|
|
|
2021-07-12 20:10:35 +00:00
|
|
|
Bind( EVT_SIM_UPDATE, &SIM_PLOT_FRAME::onSimUpdate, this );
|
|
|
|
Bind( EVT_SIM_REPORT, &SIM_PLOT_FRAME::onSimReport, this );
|
|
|
|
Bind( EVT_SIM_STARTED, &SIM_PLOT_FRAME::onSimStarted, this );
|
|
|
|
Bind( EVT_SIM_FINISHED, &SIM_PLOT_FRAME::onSimFinished, this );
|
|
|
|
Bind( EVT_SIM_CURSOR_UPDATE, &SIM_PLOT_FRAME::onCursorUpdate, this );
|
2016-08-11 12:42:00 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
// Toolbar buttons
|
|
|
|
m_toolSimulate = m_toolBar->AddTool( ID_SIM_RUN, _( "Run/Stop Simulation" ),
|
2021-03-08 02:59:07 +00:00
|
|
|
KiBitmap( BITMAPS::sim_run ), _( "Run Simulation" ), wxITEM_NORMAL );
|
2016-08-11 12:42:17 +00:00
|
|
|
m_toolAddSignals = m_toolBar->AddTool( ID_SIM_ADD_SIGNALS, _( "Add Signals" ),
|
2021-03-08 02:59:07 +00:00
|
|
|
KiBitmap( BITMAPS::sim_add_signal ), _( "Add signals to plot" ), wxITEM_NORMAL );
|
2016-08-11 12:42:17 +00:00
|
|
|
m_toolProbe = m_toolBar->AddTool( ID_SIM_PROBE, _( "Probe" ),
|
2021-03-08 02:59:07 +00:00
|
|
|
KiBitmap( BITMAPS::sim_probe ), _( "Probe signals on the schematic" ), wxITEM_NORMAL );
|
2016-08-11 12:42:17 +00:00
|
|
|
m_toolTune = m_toolBar->AddTool( ID_SIM_TUNE, _( "Tune" ),
|
2021-03-08 02:59:07 +00:00
|
|
|
KiBitmap( BITMAPS::sim_tune ), _( "Tune component values" ), wxITEM_NORMAL );
|
2022-12-05 20:48:30 +00:00
|
|
|
m_toolSettings = m_toolBar->AddTool( wxID_ANY, _( "Sim Command" ),
|
|
|
|
KiBitmap( BITMAPS::config ), _( "Simulation command and settings" ), wxITEM_NORMAL );
|
2016-08-11 12:42:00 +00:00
|
|
|
|
2021-07-11 18:31:50 +00:00
|
|
|
// Start all toolbar buttons except settings as disabled
|
|
|
|
m_toolSimulate->Enable( false );
|
|
|
|
m_toolAddSignals->Enable( false );
|
|
|
|
m_toolProbe->Enable( false );
|
|
|
|
m_toolTune->Enable( false );
|
|
|
|
m_toolSettings->Enable( true );
|
|
|
|
|
2021-07-12 20:10:35 +00:00
|
|
|
Bind( wxEVT_UPDATE_UI, &SIM_PLOT_FRAME::menuSimulateUpdate, this, m_toolSimulate->GetId() );
|
|
|
|
Bind( wxEVT_UPDATE_UI, &SIM_PLOT_FRAME::menuAddSignalsUpdate, this,
|
|
|
|
m_toolAddSignals->GetId() );
|
|
|
|
Bind( wxEVT_UPDATE_UI, &SIM_PLOT_FRAME::menuProbeUpdate, this, m_toolProbe->GetId() );
|
|
|
|
Bind( wxEVT_UPDATE_UI, &SIM_PLOT_FRAME::menuTuneUpdate, this, m_toolTune->GetId() );
|
|
|
|
|
|
|
|
Bind( wxEVT_COMMAND_TOOL_CLICKED, &SIM_PLOT_FRAME::onSimulate, this, m_toolSimulate->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_TOOL_CLICKED, &SIM_PLOT_FRAME::onAddSignal, this,
|
|
|
|
m_toolAddSignals->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_TOOL_CLICKED, &SIM_PLOT_FRAME::onProbe, this, m_toolProbe->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_TOOL_CLICKED, &SIM_PLOT_FRAME::onTune, this, m_toolTune->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_TOOL_CLICKED, &SIM_PLOT_FRAME::onSettings, this, m_toolSettings->GetId() );
|
2016-08-11 12:42:00 +00:00
|
|
|
|
2021-07-11 18:31:50 +00:00
|
|
|
Bind( EVT_WORKBOOK_MODIFIED, &SIM_PLOT_FRAME::onWorkbookModified, this );
|
|
|
|
Bind( EVT_WORKBOOK_CLR_MODIFIED, &SIM_PLOT_FRAME::onWorkbookClrModified, this );
|
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
// Bind toolbar buttons event to existing menu event handlers, so they behave the same
|
2021-03-18 19:31:02 +00:00
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSimulate, this,
|
|
|
|
m_runSimulation->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onAddSignal, this, m_addSignals->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onProbe, this, m_probeSignals->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onTune, this, m_tuneValue->GetId() );
|
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onShowNetlist, this,
|
|
|
|
m_showNetlist->GetId() );
|
2021-07-12 20:10:35 +00:00
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSettings, this,
|
|
|
|
m_boardAdapter->GetId() );
|
2016-08-11 12:42:13 +00:00
|
|
|
|
2016-08-11 12:42:00 +00:00
|
|
|
m_toolBar->Realize();
|
2020-04-15 01:51:58 +00:00
|
|
|
|
2021-04-23 02:24:20 +00:00
|
|
|
#ifndef wxHAS_NATIVE_TABART
|
2021-07-21 21:37:49 +00:00
|
|
|
// Non-native default tab art has ugly gradients we don't want
|
2021-06-30 00:13:10 +00:00
|
|
|
m_workbook->SetArtProvider( new wxAuiSimpleTabArt() );
|
2021-04-23 02:24:20 +00:00
|
|
|
#endif
|
|
|
|
|
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();
|
|
|
|
setSubWindowsSashSize();
|
2020-04-17 23:32:29 +00:00
|
|
|
|
|
|
|
// Ensure the window is on top
|
|
|
|
Raise();
|
2021-05-04 22:35:04 +00:00
|
|
|
|
|
|
|
initWorkbook();
|
2021-07-11 18:31:50 +00:00
|
|
|
updateTitle();
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
SIM_PLOT_FRAME::~SIM_PLOT_FRAME()
|
|
|
|
{
|
2022-11-18 15:27:53 +00:00
|
|
|
NULL_REPORTER devnull;
|
|
|
|
|
|
|
|
m_simulator->Attach( nullptr, 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-29 09:39:54 +00:00
|
|
|
delete m_signalsIconColorList;
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 14:34:23 +00:00
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
void SIM_PLOT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
|
|
|
|
{
|
|
|
|
EESCHEMA_SETTINGS* cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
|
|
|
wxASSERT( cfg );
|
|
|
|
|
|
|
|
if( cfg )
|
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::LoadSettings( cfg );
|
|
|
|
|
|
|
|
// Read subwindows sizes (should be > 0 )
|
|
|
|
m_splitterLeftRightSashPosition = cfg->m_Simulator.plot_panel_width;
|
|
|
|
m_splitterPlotAndConsoleSashPosition = cfg->m_Simulator.plot_panel_height;
|
|
|
|
m_splitterSignalsSashPosition = cfg->m_Simulator.signal_panel_height;
|
|
|
|
m_splitterTuneValuesSashPosition = cfg->m_Simulator.cursors_panel_height;
|
|
|
|
m_plotUseWhiteBg = cfg->m_Simulator.white_background;
|
|
|
|
}
|
|
|
|
|
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
|
|
|
|
|
|
|
NGSPICE* currentSim = dynamic_cast<NGSPICE*>( m_simulator.get() );
|
|
|
|
|
|
|
|
if( currentSim )
|
|
|
|
m_simulator->Settings() = project.m_SchematicSettings->m_NgspiceSimulatorSettings;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void SIM_PLOT_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 );
|
|
|
|
|
2020-03-21 16:31:48 +00:00
|
|
|
if( cfg )
|
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::SaveSettings( cfg );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-03-21 16:31:48 +00:00
|
|
|
cfg->m_Simulator.plot_panel_width = m_splitterLeftRight->GetSashPosition();
|
|
|
|
cfg->m_Simulator.plot_panel_height = m_splitterPlotAndConsole->GetSashPosition();
|
|
|
|
cfg->m_Simulator.signal_panel_height = m_splitterSignals->GetSashPosition();
|
|
|
|
cfg->m_Simulator.cursors_panel_height = m_splitterTuneValues->GetSashPosition();
|
|
|
|
cfg->m_Simulator.white_background = m_plotUseWhiteBg;
|
|
|
|
}
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2021-05-01 20:38:11 +00:00
|
|
|
if( !m_isNonUserClose ) // If we're exiting the project has already been released.
|
2021-03-18 19:31:02 +00:00
|
|
|
{
|
|
|
|
PROJECT_FILE& project = Prj().GetProjectFile();
|
|
|
|
|
2021-05-01 20:38:11 +00:00
|
|
|
if( project.m_SchematicSettings )
|
|
|
|
project.m_SchematicSettings->m_NgspiceSimulatorSettings->SaveToFile();
|
|
|
|
|
|
|
|
if( m_schematicFrame )
|
2023-03-04 19:25:07 +00:00
|
|
|
m_schematicFrame->OnModify();
|
2021-03-18 19:31:02 +00:00
|
|
|
}
|
2016-12-02 14:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
WINDOW_SETTINGS* SIM_PLOT_FRAME::GetWindowSettings( 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 );
|
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
return cfg ? &cfg->m_Simulator.window : nullptr;
|
2020-01-13 01:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
void SIM_PLOT_FRAME::initWorkbook()
|
2020-01-13 01:44:19 +00:00
|
|
|
{
|
2021-07-05 22:45:15 +00:00
|
|
|
// Removed for the time being. We cannot run the simulation on simulator launch, as it may
|
|
|
|
// take a lot of time, confusing the user.
|
|
|
|
// TODO: Change workbook loading routines so that they don't run the simulation until the user
|
|
|
|
// initiates it.
|
|
|
|
|
|
|
|
/*if( !m_simulator->Settings()->GetWorkbookFilename().IsEmpty() )
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
2021-05-09 23:32:49 +00:00
|
|
|
wxFileName filename = m_simulator->Settings()->GetWorkbookFilename();
|
2021-05-04 22:35:04 +00:00
|
|
|
filename.SetPath( Prj().GetProjectPath() );
|
|
|
|
|
|
|
|
if( !loadWorkbook( filename.GetFullPath() ) )
|
2021-05-09 23:32:49 +00:00
|
|
|
m_simulator->Settings()->SetWorkbookFilename( "" );
|
2021-07-05 22:45:15 +00:00
|
|
|
}*/
|
2016-12-02 14:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-09 23:32:49 +00:00
|
|
|
void SIM_PLOT_FRAME::updateTitle()
|
|
|
|
{
|
2022-12-26 14:37:42 +00:00
|
|
|
bool unsaved = true;
|
|
|
|
bool readOnly = false;
|
|
|
|
wxString title;
|
2021-05-09 23:32:49 +00:00
|
|
|
|
2022-12-26 14:37:42 +00:00
|
|
|
if( m_simulator && m_simulator->Settings() )
|
|
|
|
{
|
|
|
|
wxFileName filename = Prj().AbsolutePath( m_simulator->Settings()->GetWorkbookFilename() );
|
2021-05-09 23:32:49 +00:00
|
|
|
|
2022-12-26 14:37:42 +00:00
|
|
|
if( filename.IsOk() && filename.FileExists() )
|
|
|
|
{
|
|
|
|
unsaved = false;
|
|
|
|
readOnly = !filename.IsFileWritable();
|
|
|
|
}
|
2021-06-20 21:46:41 +00:00
|
|
|
|
2022-12-26 14:37:42 +00:00
|
|
|
if( m_workbook->IsModified() )
|
|
|
|
title = wxT( "*" ) + filename.GetName();
|
|
|
|
else
|
|
|
|
title = filename.GetName();
|
|
|
|
}
|
2021-06-20 21:46:41 +00:00
|
|
|
|
|
|
|
if( readOnly )
|
|
|
|
title += wxS( " " ) + _( "[Read Only]" );
|
|
|
|
|
|
|
|
if( unsaved )
|
|
|
|
title += wxS( " " ) + _( "[Unsaved]" );
|
|
|
|
|
|
|
|
title += wxT( " \u2014 " ) + _( "Spice Simulator" );
|
|
|
|
|
|
|
|
SetTitle( title );
|
2021-05-09 23:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
// A small helper struct to handle bitmaps initialization in menus
|
2019-04-14 13:31:32 +00:00
|
|
|
struct BM_MENU_INIT_ITEM
|
|
|
|
{
|
|
|
|
int m_MenuId;
|
2021-03-08 02:59:07 +00:00
|
|
|
BITMAPS m_Bitmap;
|
2019-04-14 13:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::setIconsForMenuItems()
|
|
|
|
{
|
|
|
|
// Give icons to menuitems of the main menubar
|
|
|
|
BM_MENU_INIT_ITEM bm_list[]
|
|
|
|
{
|
|
|
|
// File menu:
|
2021-03-08 02:59:07 +00:00
|
|
|
{ wxID_NEW, BITMAPS::simulator },
|
|
|
|
{ wxID_OPEN, BITMAPS::directory_open },
|
|
|
|
{ wxID_SAVE, BITMAPS::save },
|
|
|
|
{ wxID_CLOSE, BITMAPS::exit },
|
2019-04-14 13:31:32 +00:00
|
|
|
|
|
|
|
// simulator menu:
|
2021-03-08 02:59:07 +00:00
|
|
|
{ ID_MENU_RUN_SIM, BITMAPS::sim_run },
|
|
|
|
{ ID_MENU_ADD_SIGNAL, BITMAPS::sim_add_signal },
|
|
|
|
{ ID_MENU_PROBE_SIGNALS, BITMAPS::sim_probe },
|
|
|
|
{ ID_MENU_TUNE_SIGNALS, BITMAPS::sim_tune },
|
|
|
|
{ ID_MENU_SHOW_NETLIST, BITMAPS::netlist },
|
|
|
|
{ ID_MENU_SET_SIMUL, BITMAPS::config },
|
2019-04-14 13:31:32 +00:00
|
|
|
|
|
|
|
// View menu
|
2021-03-08 02:59:07 +00:00
|
|
|
{ wxID_ZOOM_IN, BITMAPS::zoom_in },
|
|
|
|
{ wxID_ZOOM_OUT, BITMAPS::zoom_out },
|
|
|
|
{ wxID_ZOOM_FIT, BITMAPS::zoom_fit_in_page },
|
|
|
|
{ ID_MENU_SHOW_GRID, BITMAPS::grid },
|
|
|
|
{ ID_MENU_SHOW_LEGEND, BITMAPS::text },
|
|
|
|
{ ID_MENU_DOTTED, BITMAPS::add_dashed_line },
|
|
|
|
{ ID_MENU_WHITE_BG, BITMAPS::swap_layer },
|
|
|
|
|
|
|
|
{ 0, BITMAPS::INVALID_BITMAP } // Sentinel
|
2019-04-14 13:31:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// wxMenuItems are already created and attached to the m_mainMenu wxMenuBar.
|
|
|
|
// A problem is the fact setting bitmaps in wxMenuItems after they are attached
|
|
|
|
// to a wxMenu do not work in all cases.
|
|
|
|
// So the trick is:
|
|
|
|
// Remove the wxMenuItem from its wxMenu
|
|
|
|
// Set the bitmap
|
|
|
|
// Insert the modified wxMenuItem to its previous place
|
|
|
|
for( int ii = 0; bm_list[ii].m_MenuId; ++ii )
|
|
|
|
{
|
|
|
|
wxMenuItem* item = m_mainMenu->FindItem( bm_list[ii].m_MenuId );
|
|
|
|
|
2021-03-08 02:59:07 +00:00
|
|
|
if( !item || ( bm_list[ii].m_Bitmap == BITMAPS::INVALID_BITMAP ) )
|
2019-04-14 13:31:32 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
wxMenu* menu = item->GetMenu();
|
2021-03-18 19:31:02 +00:00
|
|
|
|
|
|
|
// Calculate the initial index of item inside the wxMenu parent.
|
2019-04-14 13:31:32 +00:00
|
|
|
wxMenuItemList& mlist = menu->GetMenuItems();
|
|
|
|
int mpos = mlist.IndexOf( item );
|
|
|
|
|
|
|
|
if( mpos >= 0 ) // Should be always the case
|
|
|
|
{
|
|
|
|
// Modify the bitmap
|
|
|
|
menu->Remove( item );
|
|
|
|
AddBitmapToMenuItem( item, KiBitmap( bm_list[ii].m_Bitmap ) );
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2019-04-14 13:31:32 +00:00
|
|
|
// Insert item to its the initial index
|
|
|
|
menu->Insert( mpos, item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-02 14:34:23 +00:00
|
|
|
void SIM_PLOT_FRAME::setSubWindowsSashSize()
|
|
|
|
{
|
|
|
|
if( m_splitterLeftRightSashPosition > 0 )
|
|
|
|
m_splitterLeftRight->SetSashPosition( m_splitterLeftRightSashPosition );
|
|
|
|
|
|
|
|
if( m_splitterPlotAndConsoleSashPosition > 0 )
|
|
|
|
m_splitterPlotAndConsole->SetSashPosition( m_splitterPlotAndConsoleSashPosition );
|
|
|
|
|
|
|
|
if( m_splitterSignalsSashPosition > 0 )
|
|
|
|
m_splitterSignals->SetSashPosition( m_splitterSignalsSashPosition );
|
|
|
|
|
|
|
|
if( m_splitterTuneValuesSashPosition > 0 )
|
|
|
|
m_splitterTuneValues->SetSashPosition( m_splitterTuneValuesSashPosition );
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2023-05-22 15:52:01 +00:00
|
|
|
void SIM_PLOT_FRAME::StartSimulation()
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2023-05-22 15:52:01 +00:00
|
|
|
if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN )
|
|
|
|
{
|
|
|
|
if( !EditSimCommand() )
|
|
|
|
return;
|
2021-07-09 19:35:47 +00:00
|
|
|
|
2023-05-22 15:52:01 +00:00
|
|
|
if( m_circuitModel->CommandToSimType( GetCurrentSimCommand() ) == ST_UNKNOWN )
|
|
|
|
return;
|
|
|
|
}
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2023-05-22 15:52:01 +00:00
|
|
|
wxString schTextSimCommand = m_circuitModel->GetSchTextSimCommand();
|
|
|
|
SIM_TYPE schTextSimType = NGSPICE_CIRCUIT_MODEL::CommandToSimType( schTextSimCommand );
|
|
|
|
SIM_PANEL_BASE* plotWindow = getCurrentPlotWindow();
|
|
|
|
|
|
|
|
if( !plotWindow )
|
|
|
|
{
|
|
|
|
plotWindow = NewPlotPanel( schTextSimCommand, m_circuitModel->GetSimOptions() );
|
|
|
|
m_workbook->SetSimCommand( plotWindow, schTextSimCommand );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_circuitModel->SetSimCommandOverride( m_workbook->GetSimCommand( plotWindow ) );
|
|
|
|
|
|
|
|
if( plotWindow->GetType() == schTextSimType
|
|
|
|
&& schTextSimCommand != m_circuitModel->GetLastSchTextSimCommand() )
|
|
|
|
{
|
|
|
|
if( IsOK( this, _( "Schematic sheet simulation command directive has changed. "
|
|
|
|
"Do you wish to update the Simulation Command?" ) ) )
|
|
|
|
{
|
|
|
|
m_circuitModel->SetSimCommandOverride( wxEmptyString );
|
|
|
|
m_workbook->SetSimCommand( plotWindow, schTextSimCommand );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-12-05 20:01:36 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
m_circuitModel->SetSimOptions( getCurrentOptions() );
|
2016-08-11 12:42:09 +00:00
|
|
|
|
2022-11-18 15:27:53 +00:00
|
|
|
wxString errors;
|
|
|
|
WX_STRING_REPORTER reporter( &errors );
|
|
|
|
|
2023-05-17 06:42:29 +00:00
|
|
|
if( !m_schematicFrame->ReadyToNetlist( _( "Simulator requires a fully annotated schematic." ) ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we are using the new connectivity, make sure that we do a full-rebuild
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
|
|
|
|
m_schematicFrame->RecalculateConnections( GLOBAL_CLEANUP );
|
|
|
|
|
|
|
|
if( !m_simulator->Attach( m_circuitModel, reporter ) )
|
2016-08-11 12:42:09 +00:00
|
|
|
{
|
2022-11-18 15:27:53 +00:00
|
|
|
DisplayErrorMessage( this, _( "Errors during netlist generation; simulation aborted.\n\n" )
|
|
|
|
+ errors );
|
2016-08-11 12:42:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2022-02-19 16:58:48 +00:00
|
|
|
std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
|
|
|
|
|
|
|
|
if( simulatorLock.owns_lock() )
|
|
|
|
{
|
2022-06-12 03:39:13 +00:00
|
|
|
wxBusyCursor toggle;
|
|
|
|
|
2023-05-22 15:52:01 +00:00
|
|
|
m_simConsole->Clear();
|
|
|
|
|
2022-02-19 16:58:48 +00:00
|
|
|
applyTuners();
|
2022-12-23 22:02:59 +00:00
|
|
|
|
2022-05-28 20:40:24 +00:00
|
|
|
// Prevents memory leak on succeding simulations by deleting old vectors
|
|
|
|
m_simulator->Clean();
|
2022-02-19 16:58:48 +00:00
|
|
|
m_simulator->Run();
|
|
|
|
}
|
|
|
|
else
|
2022-11-07 22:45:23 +00:00
|
|
|
{
|
2022-02-19 16:58:48 +00:00
|
|
|
DisplayErrorMessage( this, _( "Another simulation is already running." ) );
|
2022-11-07 22:45:23 +00:00
|
|
|
}
|
2016-08-11 12:41:07 +00:00
|
|
|
}
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
SIM_PANEL_BASE* SIM_PLOT_FRAME::NewPlotPanel( wxString aSimCommand, int aOptions )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2021-04-22 02:09:40 +00:00
|
|
|
SIM_PANEL_BASE* plotPanel = nullptr;
|
2022-03-05 23:49:25 +00:00
|
|
|
SIM_TYPE simType = NGSPICE_CIRCUIT_MODEL::CommandToSimType( aSimCommand );
|
2020-04-15 01:51:58 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( SIM_PANEL_BASE::IsPlottable( simType ) )
|
2020-04-15 01:51:58 +00:00
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* panel;
|
2023-01-14 00:17:33 +00:00
|
|
|
panel = new SIM_PLOT_PANEL( aSimCommand, aOptions, m_workbook, this, wxID_ANY );
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
panel->GetPlotWin()->EnableMouseWheelPan(
|
2020-05-17 00:19:48 +00:00
|
|
|
Pgm().GetCommonSettings()->m_Input.scroll_modifier_zoom != 0 );
|
2020-04-15 01:51:58 +00:00
|
|
|
|
|
|
|
plotPanel = dynamic_cast<SIM_PANEL_BASE*>( panel );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
SIM_NOPLOT_PANEL* panel;
|
2023-01-14 00:17:33 +00:00
|
|
|
panel = new SIM_NOPLOT_PANEL( aSimCommand, aOptions, m_workbook, wxID_ANY );
|
2020-04-15 01:51:58 +00:00
|
|
|
plotPanel = dynamic_cast<SIM_PANEL_BASE*>( panel );
|
|
|
|
}
|
2019-11-19 14:58:32 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
wxString pageTitle( m_simulator->TypeToName( simType, true ) );
|
2020-04-15 01:51:58 +00:00
|
|
|
pageTitle.Prepend( wxString::Format( _( "Plot%u - " ), (unsigned int) ++m_plotNumber ) );
|
2016-08-11 12:41:42 +00:00
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
m_workbook->AddPage( dynamic_cast<wxWindow*>( plotPanel ), pageTitle, true );
|
2016-08-11 12:42:10 +00:00
|
|
|
|
|
|
|
return plotPanel;
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
2016-08-11 12:41:07 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:41:11 +00:00
|
|
|
void SIM_PLOT_FRAME::AddVoltagePlot( const wxString& aNetName )
|
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
addPlot( aNetName, SPT_VOLTAGE );
|
2016-08-11 12:41:52 +00:00
|
|
|
}
|
2016-08-11 12:41:42 +00:00
|
|
|
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
void SIM_PLOT_FRAME::AddCurrentPlot( const wxString& aDeviceName )
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
addPlot( aDeviceName, SPT_CURRENT );
|
2016-08-11 12:41:18 +00:00
|
|
|
}
|
2016-08-11 12:41:11 +00:00
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
void SIM_PLOT_FRAME::AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PANEL_BASE* plotPanel = getCurrentPlotWindow();
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
if( !plotPanel )
|
2016-08-11 12:41:45 +00:00
|
|
|
return;
|
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
wxString ref = aSymbol->GetRef( &aSheetPath );
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2022-10-24 01:47:48 +00:00
|
|
|
// Do not add multiple instances for the same component.
|
2022-12-23 22:02:59 +00:00
|
|
|
for( TUNER_SLIDER* tuner : m_tuners )
|
|
|
|
{
|
|
|
|
if( tuner->GetSymbolRef() == ref )
|
|
|
|
return;
|
|
|
|
}
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
const SPICE_ITEM* item = GetExporter()->FindItem( std::string( ref.ToUTF8() ) );
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2022-10-24 01:47:48 +00:00
|
|
|
// Do nothing if the symbol is not tunable.
|
2022-12-23 22:02:59 +00:00
|
|
|
if( !item || !item->model->GetTunerParam() )
|
2022-10-24 01:47:48 +00:00
|
|
|
return;
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2022-12-23 22:02:59 +00:00
|
|
|
TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_tunePanel, aSheetPath, aSymbol );
|
2016-08-11 12:42:03 +00:00
|
|
|
m_tuneSizer->Add( tuner );
|
2016-08-11 12:42:07 +00:00
|
|
|
m_tuners.push_back( tuner );
|
2016-12-02 07:58:01 +00:00
|
|
|
m_tunePanel->Layout();
|
2016-08-11 12:41:45 +00:00
|
|
|
}
|
2018-06-05 11:26:37 +00:00
|
|
|
catch( const KI_PARAM_ERROR& e )
|
2016-08-11 12:41:45 +00:00
|
|
|
{
|
2021-05-04 22:35:04 +00:00
|
|
|
DisplayErrorMessage( nullptr, e.What() );
|
2016-08-11 12:41:45 +00:00
|
|
|
}
|
2016-08-11 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
2022-12-05 02:07:45 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
void SIM_PLOT_FRAME::UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, const KIID& aSymbol,
|
|
|
|
const wxString& aRef, const wxString& aValue )
|
2021-11-02 00:04:09 +00:00
|
|
|
{
|
2022-12-23 22:02:59 +00:00
|
|
|
SCH_ITEM* item = aSheetPath.GetItem( aSymbol );
|
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
|
2022-12-23 17:39:28 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
if( !symbol )
|
2021-11-02 00:04:09 +00:00
|
|
|
{
|
2022-12-24 11:30:56 +00:00
|
|
|
DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( " " )
|
|
|
|
+ wxString::Format( _( "%s not found" ), aRef ) );
|
2022-12-23 22:02:59 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-10-24 01:47:48 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
SIM_LIB_MGR mgr( &Prj() );
|
|
|
|
SIM_MODEL& model = mgr.CreateModel( &aSheetPath, *symbol ).model;
|
2021-12-14 13:00:00 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam();
|
2021-12-14 13:00:00 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
if( !tunerParam )
|
|
|
|
{
|
2022-12-24 11:30:56 +00:00
|
|
|
DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( " " )
|
|
|
|
+ wxString::Format( _( "%s is not tunable" ), aRef ) );
|
2022-12-23 22:02:59 +00:00
|
|
|
return;
|
2021-11-02 00:04:09 +00:00
|
|
|
}
|
2022-12-23 22:02:59 +00:00
|
|
|
|
|
|
|
model.SetParamValue( tunerParam->info.name, std::string( aValue.ToUTF8() ) );
|
|
|
|
model.WriteFields( symbol->GetFields() );
|
|
|
|
|
|
|
|
m_schematicFrame->UpdateItem( symbol, false, true );
|
|
|
|
m_schematicFrame->OnModify();
|
2021-11-02 00:04:09 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:11 +00:00
|
|
|
|
2016-08-11 12:42:09 +00:00
|
|
|
void SIM_PLOT_FRAME::RemoveTuner( TUNER_SLIDER* aTuner, bool aErase )
|
2016-08-11 12:41:18 +00:00
|
|
|
{
|
2016-08-11 12:42:09 +00:00
|
|
|
if( aErase )
|
|
|
|
m_tuners.remove( aTuner );
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
aTuner->Destroy();
|
2016-12-02 07:58:01 +00:00
|
|
|
m_tunePanel->Layout();
|
2016-08-11 12:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* SIM_PLOT_FRAME::GetCurrentPlot() const
|
2016-08-11 12:41:45 +00:00
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PANEL_BASE* curPage = getCurrentPlotWindow();
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
return !curPage || curPage->GetType() == ST_UNKNOWN ? nullptr
|
|
|
|
: dynamic_cast<SIM_PLOT_PANEL*>( curPage );
|
2016-08-11 12:41:18 +00:00
|
|
|
}
|
2016-08-11 12:41:11 +00:00
|
|
|
|
|
|
|
|
2022-03-05 23:49:25 +00:00
|
|
|
const NGSPICE_CIRCUIT_MODEL* SIM_PLOT_FRAME::GetExporter() const
|
2018-04-27 22:34:06 +00:00
|
|
|
{
|
2022-03-28 22:02:49 +00:00
|
|
|
return m_circuitModel.get();
|
2018-04-27 22:34:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType )
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
2022-03-28 22:02:49 +00:00
|
|
|
SIM_TYPE simType = m_circuitModel->GetSimType();
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2019-08-05 06:47:38 +00:00
|
|
|
if( simType == ST_UNKNOWN )
|
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "Error: simulation type not defined!\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
return;
|
|
|
|
}
|
2020-04-15 01:51:58 +00:00
|
|
|
else if( !SIM_PANEL_BASE::IsPlottable( simType ) )
|
2019-08-05 06:47:38 +00:00
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "Error: simulation type doesn't support plotting!\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
return;
|
|
|
|
}
|
2016-08-11 12:41:52 +00:00
|
|
|
|
|
|
|
// Create a new plot if the current one displays a different type
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = GetCurrentPlot();
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
if( !plotPanel || plotPanel->GetType() != simType )
|
2021-06-25 19:49:19 +00:00
|
|
|
{
|
2023-01-14 00:17:33 +00:00
|
|
|
plotPanel = dynamic_cast<SIM_PLOT_PANEL*>( NewPlotPanel( m_circuitModel->GetSimCommand(),
|
|
|
|
m_circuitModel->GetSimOptions() ) );
|
2021-06-25 19:49:19 +00:00
|
|
|
}
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2020-04-16 07:27:22 +00:00
|
|
|
wxASSERT( plotPanel );
|
|
|
|
|
|
|
|
if( !plotPanel ) // Something is wrong
|
|
|
|
return;
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
bool updated = false;
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_TYPE xAxisType = getXAxisType( simType );
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
if( xAxisType == SPT_LIN_FREQUENCY || xAxisType == SPT_LOG_FREQUENCY )
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
2021-05-24 20:17:29 +00:00
|
|
|
int baseType = aType & ~( SPT_AC_MAG | SPT_AC_PHASE );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2022-12-28 10:09:14 +00:00
|
|
|
// If magnitude or phase wasn't specified, then add both
|
|
|
|
if( baseType == aType )
|
|
|
|
{
|
|
|
|
updated |= updatePlot( aName, ( SIM_PLOT_TYPE )( baseType | SPT_AC_MAG ), plotPanel );
|
|
|
|
updated |= updatePlot( aName, ( SIM_PLOT_TYPE )( baseType | SPT_AC_PHASE ), plotPanel );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
updated |= updatePlot( aName, ( SIM_PLOT_TYPE )( aType ), plotPanel );
|
|
|
|
}
|
2016-08-11 12:41:52 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
updated = updatePlot( aName, aType, plotPanel );
|
2016-08-11 12:41:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( updated )
|
|
|
|
updateSignalList();
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName )
|
2016-08-11 12:41:56 +00:00
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = GetCurrentPlot();
|
2016-08-11 12:41:56 +00:00
|
|
|
|
2016-08-12 13:36:43 +00:00
|
|
|
if( !plotPanel )
|
|
|
|
return;
|
|
|
|
|
2017-03-19 13:17:33 +00:00
|
|
|
wxASSERT( plotPanel->TraceShown( aPlotName ) );
|
2021-06-30 00:13:10 +00:00
|
|
|
m_workbook->DeleteTrace( plotPanel, aPlotName );
|
2020-04-15 01:51:58 +00:00
|
|
|
plotPanel->GetPlotWin()->Fit();
|
2016-08-11 12:41:56 +00:00
|
|
|
|
|
|
|
updateSignalList();
|
2020-04-15 01:51:58 +00:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
onCursorUpdate( dummy );
|
2016-08-11 12:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
bool SIM_PLOT_FRAME::updatePlot( const wxString& aName, SIM_PLOT_TYPE aType,
|
2021-06-30 00:13:10 +00:00
|
|
|
SIM_PLOT_PANEL* aPlotPanel )
|
2016-08-11 12:41:18 +00:00
|
|
|
{
|
2022-03-28 22:02:49 +00:00
|
|
|
SIM_TYPE simType = m_circuitModel->GetSimType();
|
2016-08-11 12:41:11 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
wxString plotTitle = aName;
|
2022-11-07 22:45:23 +00:00
|
|
|
|
2021-09-07 21:18:22 +00:00
|
|
|
if( aType & SPT_AC_MAG )
|
2022-11-07 22:45:23 +00:00
|
|
|
plotTitle += _( " (mag)" );
|
2021-09-07 21:18:22 +00:00
|
|
|
else if( aType & SPT_AC_PHASE )
|
2022-11-07 22:45:23 +00:00
|
|
|
plotTitle += _( " (phase)" );
|
2021-09-07 21:18:22 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( !SIM_PANEL_BASE::IsPlottable( simType ) )
|
2016-08-11 12:41:35 +00:00
|
|
|
{
|
|
|
|
// There is no plot to be shown
|
2022-11-07 22:45:23 +00:00
|
|
|
m_simulator->Command( wxString::Format( wxT( "print %s" ), aName ).ToStdString() );
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2016-08-11 12:41:41 +00:00
|
|
|
return false;
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
// First, handle the x axis
|
|
|
|
wxString xAxisName( m_simulator->GetXAxis( simType ) );
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
if( xAxisName.IsEmpty() )
|
|
|
|
return false;
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
std::vector<double> data_x = m_simulator->GetMagPlot( (const char*) xAxisName.c_str() );
|
|
|
|
unsigned int size = data_x.size();
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
std::vector<double> data_y;
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
// Now, Y axis data
|
2022-03-28 22:02:49 +00:00
|
|
|
switch( m_circuitModel->GetSimType() )
|
2016-08-11 12:41:35 +00:00
|
|
|
{
|
2021-03-18 19:31:02 +00:00
|
|
|
case ST_AC:
|
2021-05-24 20:17:29 +00:00
|
|
|
wxASSERT_MSG( !( ( aType & SPT_AC_MAG ) && ( aType & SPT_AC_PHASE ) ),
|
2022-11-07 22:45:23 +00:00
|
|
|
wxT( "Cannot set both AC_PHASE and AC_MAG bits" ) );
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2021-05-24 20:17:29 +00:00
|
|
|
if( aType & SPT_AC_MAG )
|
2022-04-12 14:37:06 +00:00
|
|
|
data_y = m_simulator->GetMagPlot( (const char*) aName.c_str() );
|
2021-05-24 20:17:29 +00:00
|
|
|
else if( aType & SPT_AC_PHASE )
|
2022-04-12 14:37:06 +00:00
|
|
|
data_y = m_simulator->GetPhasePlot( (const char*) aName.c_str() );
|
2021-03-18 19:31:02 +00:00
|
|
|
else
|
2023-01-23 18:42:36 +00:00
|
|
|
wxFAIL_MSG( wxT( "Plot type missing AC_PHASE or AC_MAG bit" ) );
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
break;
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
case ST_NOISE:
|
|
|
|
case ST_DC:
|
|
|
|
case ST_TRANSIENT:
|
2022-04-12 14:37:06 +00:00
|
|
|
data_y = m_simulator->GetMagPlot( (const char*) aName.c_str() );
|
2016-08-11 12:41:35 +00:00
|
|
|
break;
|
2016-08-11 12:41:18 +00:00
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
default:
|
2023-01-23 18:42:36 +00:00
|
|
|
wxFAIL_MSG( wxT( "Unhandled plot type" ) );
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
2016-08-11 12:41:41 +00:00
|
|
|
|
2023-01-30 21:31:56 +00:00
|
|
|
if( data_y.size() == 0 )
|
|
|
|
return false; // Signal no longer exists
|
|
|
|
else
|
|
|
|
wxCHECK_MSG( data_y.size() >= size, false, wxT( "Not enough y data values to plot" ) );
|
2023-01-23 18:42:36 +00:00
|
|
|
|
2019-05-27 22:13:00 +00:00
|
|
|
// If we did a two-source DC analysis, we need to split the resulting vector and add traces
|
|
|
|
// for each input step
|
|
|
|
SPICE_DC_PARAMS source1, source2;
|
|
|
|
|
2022-06-12 03:39:13 +00:00
|
|
|
if( m_circuitModel->GetSimType() == ST_DC
|
|
|
|
&& m_circuitModel->ParseDCCommand( m_circuitModel->GetSimCommand(), &source1, &source2 ) )
|
2019-05-27 22:13:00 +00:00
|
|
|
{
|
|
|
|
if( !source2.m_source.IsEmpty() )
|
|
|
|
{
|
|
|
|
// Source 1 is the inner loop, so lets add traces for each Source 2 (outer loop) step
|
|
|
|
SPICE_VALUE v = source2.m_vstart;
|
|
|
|
wxString name;
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
size_t outer = ( size_t )( ( source2.m_vend - v ) / source2.m_vincrement ).ToDouble();
|
|
|
|
size_t inner = data_x.size() / ( outer + 1 );
|
|
|
|
|
|
|
|
wxASSERT( data_x.size() % ( outer + 1 ) == 0 );
|
|
|
|
|
|
|
|
for( size_t idx = 0; idx <= outer; idx++ )
|
|
|
|
{
|
2022-11-07 22:45:23 +00:00
|
|
|
name = wxString::Format( wxT( "%s (%s = %s V)" ),
|
|
|
|
plotTitle,
|
|
|
|
source2.m_source,
|
2021-09-07 21:18:22 +00:00
|
|
|
v.ToString() );
|
2019-05-27 22:13:00 +00:00
|
|
|
|
|
|
|
std::vector<double> sub_x( data_x.begin() + offset,
|
|
|
|
data_x.begin() + offset + inner );
|
|
|
|
std::vector<double> sub_y( data_y.begin() + offset,
|
|
|
|
data_y.begin() + offset + inner );
|
|
|
|
|
2021-09-07 21:18:22 +00:00
|
|
|
m_workbook->AddTrace( aPlotPanel, name, aName, inner, sub_x.data(), sub_y.data(),
|
2022-04-12 14:37:06 +00:00
|
|
|
aType );
|
2019-05-27 22:13:00 +00:00
|
|
|
|
|
|
|
v = v + source2.m_vincrement;
|
|
|
|
offset += inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2021-07-09 20:20:23 +00:00
|
|
|
|
2022-04-12 14:37:06 +00:00
|
|
|
m_workbook->AddTrace( aPlotPanel, plotTitle, aName, size, data_x.data(), data_y.data(), aType );
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2016-08-11 12:41:41 +00:00
|
|
|
return true;
|
2016-08-11 12:41:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
void SIM_PLOT_FRAME::updateSignalList()
|
2016-08-11 12:41:16 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
m_signals->ClearAll();
|
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = GetCurrentPlot();
|
2016-08-11 12:41:42 +00:00
|
|
|
|
|
|
|
if( !plotPanel )
|
|
|
|
return;
|
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
wxSize size = m_signals->GetClientSize();
|
|
|
|
m_signals->AppendColumn( _( "Signal" ), wxLIST_FORMAT_LEFT, size.x );
|
|
|
|
|
|
|
|
// Build an image list, to show the color of the corresponding trace
|
|
|
|
// in the plot panel
|
|
|
|
// This image list is used for trace and cursor lists
|
2016-08-30 12:25:10 +00:00
|
|
|
wxMemoryDC bmDC;
|
|
|
|
const int isize = bmDC.GetCharHeight();
|
2016-08-29 09:39:54 +00:00
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
if( m_signalsIconColorList == nullptr )
|
2016-08-30 12:25:10 +00:00
|
|
|
m_signalsIconColorList = new wxImageList( isize, isize, false );
|
2016-08-29 09:39:54 +00:00
|
|
|
else
|
|
|
|
m_signalsIconColorList->RemoveAll();
|
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const auto& [name, trace] : GetCurrentPlot()->GetTraces() )
|
2016-08-29 09:39:54 +00:00
|
|
|
{
|
2016-08-30 12:25:10 +00:00
|
|
|
wxBitmap bitmap( isize, isize );
|
2016-08-29 09:39:54 +00:00
|
|
|
bmDC.SelectObject( bitmap );
|
2022-12-05 23:21:18 +00:00
|
|
|
wxColour tcolor = trace->GetPen().GetColour();
|
2016-08-29 09:39:54 +00:00
|
|
|
|
2016-08-30 12:25:10 +00:00
|
|
|
wxColour bgColor = m_signals->wxWindow::GetBackgroundColour();
|
|
|
|
bmDC.SetPen( wxPen( bgColor ) );
|
|
|
|
bmDC.SetBrush( wxBrush( bgColor ) );
|
|
|
|
bmDC.DrawRectangle( 0, 0, isize, isize ); // because bmDC.Clear() does not work in wxGTK
|
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
bmDC.SetPen( wxPen( tcolor ) );
|
|
|
|
bmDC.SetBrush( wxBrush( tcolor ) );
|
2016-08-30 12:25:10 +00:00
|
|
|
bmDC.DrawRectangle( 0, isize / 4 + 1, isize, isize / 2 );
|
2016-08-29 09:39:54 +00:00
|
|
|
|
|
|
|
bmDC.SelectObject( wxNullBitmap ); // Needed to initialize bitmap
|
|
|
|
|
2016-08-30 12:25:10 +00:00
|
|
|
bitmap.SetMask( new wxMask( bitmap, *wxBLACK ) );
|
2016-08-29 09:39:54 +00:00
|
|
|
m_signalsIconColorList->Add( bitmap );
|
|
|
|
}
|
|
|
|
|
2016-08-30 12:25:10 +00:00
|
|
|
if( bmDC.IsOk() )
|
|
|
|
{
|
|
|
|
bmDC.SetBrush( wxNullBrush );
|
|
|
|
bmDC.SetPen( wxNullPen );
|
|
|
|
}
|
2016-08-29 09:39:54 +00:00
|
|
|
|
2016-08-30 12:25:10 +00:00
|
|
|
m_signals->SetImageList( m_signalsIconColorList, wxIMAGE_LIST_SMALL );
|
2016-08-29 09:39:54 +00:00
|
|
|
|
|
|
|
// Fill the signals listctrl. Keep the order of names and
|
|
|
|
// the order of icon color identical, because the icons
|
|
|
|
// are also used in cursor list, and the color index is
|
|
|
|
// calculated from the trace name index
|
|
|
|
int imgidx = 0;
|
2016-08-11 12:41:16 +00:00
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const auto& [name, trace] : plotPanel->GetTraces() )
|
2016-08-29 09:39:54 +00:00
|
|
|
{
|
2022-12-05 23:21:18 +00:00
|
|
|
m_signals->InsertItem( imgidx, name, imgidx );
|
2016-08-29 09:39:54 +00:00
|
|
|
imgidx++;
|
|
|
|
}
|
2016-08-11 12:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
void SIM_PLOT_FRAME::applyTuners()
|
2016-08-11 12:42:09 +00:00
|
|
|
{
|
2022-12-23 22:02:59 +00:00
|
|
|
wxString errors;
|
|
|
|
WX_STRING_REPORTER reporter( &errors );
|
2016-08-11 12:42:09 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
for( const TUNER_SLIDER* tuner : m_tuners )
|
2016-08-11 12:42:09 +00:00
|
|
|
{
|
2022-12-23 22:02:59 +00:00
|
|
|
SCH_SHEET_PATH sheetPath;
|
|
|
|
wxString ref = tuner->GetSymbolRef();
|
|
|
|
KIID symbolId = tuner->GetSymbol( &sheetPath );
|
|
|
|
SCH_ITEM* schItem = sheetPath.GetItem( symbolId );
|
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( schItem );
|
|
|
|
|
|
|
|
if( !symbol )
|
2016-08-11 12:42:09 +00:00
|
|
|
{
|
2022-12-24 11:30:56 +00:00
|
|
|
reporter.Report( wxString::Format( _( "%s not found" ), ref ) );
|
2022-12-23 22:02:59 +00:00
|
|
|
continue;
|
2016-08-11 12:42:09 +00:00
|
|
|
}
|
2022-12-23 22:02:59 +00:00
|
|
|
|
|
|
|
const SPICE_ITEM* item = GetExporter()->FindItem( tuner->GetSymbolRef().ToStdString() );
|
|
|
|
|
|
|
|
if( !item || !item->model->GetTunerParam() )
|
2016-08-11 12:42:09 +00:00
|
|
|
{
|
2022-12-24 11:30:56 +00:00
|
|
|
reporter.Report( wxString::Format( _( "%s is not tunable" ), ref ) );
|
2022-12-23 22:02:59 +00:00
|
|
|
continue;
|
2016-08-11 12:42:09 +00:00
|
|
|
}
|
|
|
|
|
2023-02-22 09:10:06 +00:00
|
|
|
double floatVal = tuner->GetValue().ToDouble();
|
2016-08-11 12:42:09 +00:00
|
|
|
|
2022-12-23 22:02:59 +00:00
|
|
|
m_simulator->Command( item->model->SpiceGenerator().TunerCommand( *item, floatVal ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reporter.HasMessage() )
|
2023-01-19 12:59:18 +00:00
|
|
|
DisplayErrorMessage( this,
|
|
|
|
_( "Could not apply tuned value(s):" ) + wxS( "\n\n" ) + errors );
|
2016-08-11 12:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
|
|
|
|
{
|
2021-06-30 00:13:10 +00:00
|
|
|
m_workbook->DeleteAllPages();
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
wxTextFile file( aPath );
|
|
|
|
|
2021-07-04 01:48:12 +00:00
|
|
|
#define DISPLAY_LOAD_ERROR( fmt ) DisplayErrorMessage( this, wxString::Format( _( fmt ), \
|
|
|
|
file.GetCurrentLine()+1 ) )
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
if( !file.Open() )
|
|
|
|
return false;
|
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
long version = 1;
|
|
|
|
wxString firstLine = file.GetFirstLine();
|
|
|
|
wxString plotCountLine;
|
|
|
|
|
|
|
|
if( firstLine.StartsWith( wxT( "version " ) ) )
|
|
|
|
{
|
|
|
|
if( !firstLine.substr( 8 ).ToLong( &version ) )
|
|
|
|
{
|
|
|
|
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
|
|
|
|
file.Close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
plotCountLine = file.GetNextLine();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plotCountLine = firstLine;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
long plotsCount;
|
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
if( !plotCountLine.ToLong( &plotsCount ) ) // GetFirstLine instead of GetNextLine
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
2021-07-04 01:48:12 +00:00
|
|
|
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
|
2021-05-04 22:35:04 +00:00
|
|
|
file.Close();
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
return false;
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
for( long i = 0; i < plotsCount; ++i )
|
|
|
|
{
|
|
|
|
long plotType, tracesCount;
|
|
|
|
|
|
|
|
if( !file.GetNextLine().ToLong( &plotType ) )
|
2021-05-09 23:32:49 +00:00
|
|
|
{
|
2021-07-04 01:48:12 +00:00
|
|
|
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
|
2021-07-02 00:10:41 +00:00
|
|
|
file.Close();
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
return false;
|
2021-05-09 23:32:49 +00:00
|
|
|
}
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
wxString command = UnescapeString( file.GetNextLine() );
|
|
|
|
wxString simCommand;
|
|
|
|
int simOptions = NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS;
|
|
|
|
wxStringTokenizer tokenizer( command, wxT( "\r\n" ), wxTOKEN_STRTOK );
|
|
|
|
|
|
|
|
if( version >= 2 )
|
|
|
|
{
|
|
|
|
simOptions &= ~NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS;
|
|
|
|
simOptions &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES;
|
|
|
|
simOptions &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS;
|
|
|
|
}
|
|
|
|
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
wxString line = tokenizer.GetNextToken();
|
|
|
|
|
|
|
|
if( line.StartsWith( wxT( ".kicad adjustpaths" ) ) )
|
|
|
|
simOptions |= NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS;
|
|
|
|
else if( line.StartsWith( wxT( ".save all" ) ) )
|
|
|
|
simOptions |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES;
|
|
|
|
else if( line.StartsWith( wxT( ".probe alli" ) ) )
|
|
|
|
simOptions |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS;
|
|
|
|
else
|
|
|
|
simCommand += line + wxT( "\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
NewPlotPanel( simCommand, simOptions );
|
2023-05-22 15:52:01 +00:00
|
|
|
StartSimulation();
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
// Perform simulation, so plots can be added with values
|
|
|
|
do
|
|
|
|
{
|
|
|
|
wxThread::This()->Sleep( 50 );
|
|
|
|
}
|
2021-07-06 18:58:29 +00:00
|
|
|
while( m_simulator->IsRunning() );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
if( !file.GetNextLine().ToLong( &tracesCount ) )
|
2021-05-09 23:32:49 +00:00
|
|
|
{
|
2021-07-04 01:48:12 +00:00
|
|
|
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
|
2021-07-02 00:10:41 +00:00
|
|
|
file.Close();
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
return false;
|
2021-05-09 23:32:49 +00:00
|
|
|
}
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
for( long j = 0; j < tracesCount; ++j )
|
|
|
|
{
|
|
|
|
long traceType;
|
|
|
|
wxString name, param;
|
|
|
|
|
|
|
|
if( !file.GetNextLine().ToLong( &traceType ) )
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
2021-08-14 15:54:20 +00:00
|
|
|
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is not an integer." );
|
2021-05-04 22:35:04 +00:00
|
|
|
file.Close();
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
return false;
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
name = file.GetNextLine();
|
2021-07-02 00:10:41 +00:00
|
|
|
|
|
|
|
if( name.IsEmpty() )
|
|
|
|
{
|
2021-07-04 01:48:12 +00:00
|
|
|
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is empty." );
|
2021-07-02 00:10:41 +00:00
|
|
|
file.Close();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
param = file.GetNextLine();
|
|
|
|
|
2022-10-22 10:50:26 +00:00
|
|
|
#if 0 // no longer in use
|
2021-07-02 00:10:41 +00:00
|
|
|
if( param.IsEmpty() )
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
2021-07-04 01:48:12 +00:00
|
|
|
DISPLAY_LOAD_ERROR( "Error loading workbook: Line %d is empty." );
|
2021-05-04 22:35:04 +00:00
|
|
|
file.Close();
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
return false;
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
2022-10-22 10:50:26 +00:00
|
|
|
#endif
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2023-03-20 10:06:10 +00:00
|
|
|
if( traceType != SPT_UNKNOWN )
|
|
|
|
addPlot( name, (SIM_PLOT_TYPE) traceType );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
file.Close();
|
2021-05-09 23:32:49 +00:00
|
|
|
|
2021-08-14 15:54:20 +00:00
|
|
|
wxFileName filename( aPath );
|
|
|
|
filename.MakeRelativeTo( Prj().GetProjectPath() );
|
|
|
|
|
|
|
|
// Remember the loaded workbook filename.
|
|
|
|
m_simulator->Settings()->SetWorkbookFilename( filename.GetFullPath() );
|
|
|
|
|
2021-07-21 21:37:49 +00:00
|
|
|
// Successfully loading a workbook does not count as modifying it.
|
2021-05-09 23:32:49 +00:00
|
|
|
m_workbook->ClrModified();
|
2016-08-11 12:42:12 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath )
|
|
|
|
{
|
2021-07-04 01:48:12 +00:00
|
|
|
wxFileName filename = aPath;
|
|
|
|
filename.SetExt( WorkbookFileExtension );
|
2018-01-30 10:49:51 +00:00
|
|
|
|
2021-07-04 01:48:12 +00:00
|
|
|
wxTextFile file( filename.GetFullPath() );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
if( file.Exists() )
|
|
|
|
{
|
|
|
|
if( !file.Open() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
file.Clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file.Create();
|
|
|
|
}
|
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
file.AddLine( wxT( "version 2" ) );
|
|
|
|
|
2022-11-07 22:45:23 +00:00
|
|
|
file.AddLine( wxString::Format( wxT( "%llu" ), m_workbook->GetPageCount() ) );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
for( size_t i = 0; i < m_workbook->GetPageCount(); i++ )
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
2021-06-30 00:13:10 +00:00
|
|
|
const SIM_PANEL_BASE* basePanel = dynamic_cast<const SIM_PANEL_BASE*>( m_workbook->GetPage( i ) );
|
|
|
|
|
2021-07-02 00:10:41 +00:00
|
|
|
if( !basePanel )
|
|
|
|
{
|
2022-11-07 22:45:23 +00:00
|
|
|
file.AddLine( wxString::Format( wxT( "%llu" ), 0ull ) );
|
2021-07-02 00:10:41 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2022-11-07 22:45:23 +00:00
|
|
|
file.AddLine( wxString::Format( wxT( "%d" ), basePanel->GetType() ) );
|
2023-01-14 00:17:33 +00:00
|
|
|
|
|
|
|
wxString command = m_workbook->GetSimCommand( basePanel );
|
|
|
|
int options = m_workbook->GetSimOptions( basePanel );
|
|
|
|
|
|
|
|
if( options & NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS )
|
|
|
|
command += wxT( "\n.kicad adjustpaths" );
|
|
|
|
|
|
|
|
if( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES )
|
|
|
|
command += wxT( "\n.save all" );
|
|
|
|
|
|
|
|
if( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS )
|
|
|
|
command += wxT( "\n.probe alli" );
|
|
|
|
|
|
|
|
file.AddLine( EscapeString( command, CTX_LINE ) );
|
2021-05-04 22:35:04 +00:00
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
const SIM_PLOT_PANEL* plotPanel = dynamic_cast<const SIM_PLOT_PANEL*>( basePanel );
|
2021-05-26 18:15:16 +00:00
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
if( !plotPanel )
|
2021-06-25 19:49:19 +00:00
|
|
|
{
|
2022-11-07 22:45:23 +00:00
|
|
|
file.AddLine( wxString::Format( wxT( "%llu" ), 0ull ) );
|
2021-07-02 00:10:41 +00:00
|
|
|
continue;
|
2021-06-25 19:49:19 +00:00
|
|
|
}
|
2021-05-24 20:17:29 +00:00
|
|
|
|
2022-11-07 22:45:23 +00:00
|
|
|
file.AddLine( wxString::Format( wxT( "%llu" ), plotPanel->GetTraces().size() ) );
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const auto& [name, trace] : plotPanel->GetTraces() )
|
2021-07-02 00:10:41 +00:00
|
|
|
{
|
2022-12-05 23:21:18 +00:00
|
|
|
file.AddLine( wxString::Format( wxT( "%d" ), trace->GetType() ) );
|
|
|
|
file.AddLine( trace->GetName() );
|
2022-12-07 11:33:49 +00:00
|
|
|
file.AddLine( trace->GetParam().IsEmpty() ? wxS( " " ) : trace->GetParam() );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = file.Write();
|
|
|
|
file.Close();
|
|
|
|
|
2021-08-14 15:54:20 +00:00
|
|
|
// Store the filename of the last saved workbook.
|
2021-07-02 00:10:41 +00:00
|
|
|
if( res )
|
2021-08-14 15:54:20 +00:00
|
|
|
{
|
|
|
|
filename.MakeRelativeTo( Prj().GetProjectPath() );
|
|
|
|
m_simulator->Settings()->SetWorkbookFilename( filename.GetFullPath() );
|
|
|
|
}
|
2021-07-02 00:10:41 +00:00
|
|
|
|
2021-05-09 23:32:49 +00:00
|
|
|
m_workbook->ClrModified();
|
2016-08-11 12:42:12 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-07-16 20:13:26 +00:00
|
|
|
|
2021-08-14 15:54:20 +00:00
|
|
|
wxString SIM_PLOT_FRAME::getDefaultFilename()
|
|
|
|
{
|
|
|
|
wxFileName filename = m_simulator->Settings()->GetWorkbookFilename();
|
|
|
|
|
|
|
|
if( filename.GetName().IsEmpty() )
|
|
|
|
{
|
|
|
|
if( Prj().GetProjectName().IsEmpty() )
|
|
|
|
{
|
|
|
|
filename.SetName( _( "noname" ) );
|
|
|
|
filename.SetExt( WorkbookFileExtension );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
filename.SetName( Prj().GetProjectName() );
|
|
|
|
filename.SetExt( WorkbookFileExtension );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename.GetFullName();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString SIM_PLOT_FRAME::getDefaultPath()
|
|
|
|
{
|
|
|
|
wxFileName path = m_simulator->Settings()->GetWorkbookFilename();
|
|
|
|
|
2022-08-14 17:36:40 +00:00
|
|
|
path.Normalize( FN_NORMALIZE_FLAGS | wxPATH_NORM_ENV_VARS, Prj().GetProjectPath() );
|
2021-08-14 15:54:20 +00:00
|
|
|
return path.GetPath();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_TYPE SIM_PLOT_FRAME::getXAxisType( SIM_TYPE aType ) const
|
2016-08-11 12:41:42 +00:00
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
switch( aType )
|
|
|
|
{
|
2021-06-25 19:49:19 +00:00
|
|
|
/// @todo SPT_LOG_FREQUENCY
|
|
|
|
case ST_AC: return SPT_LIN_FREQUENCY;
|
|
|
|
case ST_DC: return SPT_SWEEP;
|
|
|
|
case ST_TRANSIENT: return SPT_TIME;
|
2016-08-11 12:41:52 +00:00
|
|
|
default:
|
2022-11-07 22:45:23 +00:00
|
|
|
wxASSERT_MSG( false, wxT( "Unhandled simulation type" ) );
|
2016-08-11 12:41:52 +00:00
|
|
|
return (SIM_PLOT_TYPE) 0;
|
|
|
|
}
|
2016-08-11 12:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
void SIM_PLOT_FRAME::menuNewPlot( wxCommandEvent& aEvent )
|
|
|
|
{
|
2022-03-28 22:02:49 +00:00
|
|
|
SIM_TYPE type = m_circuitModel->GetSimType();
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( SIM_PANEL_BASE::IsPlottable( type ) )
|
2023-01-14 00:17:33 +00:00
|
|
|
NewPlotPanel( m_circuitModel->GetSimCommand(), m_circuitModel->GetSimOptions() );
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
void SIM_PLOT_FRAME::menuOpenWorkbook( wxCommandEvent& event )
|
|
|
|
{
|
2021-08-14 15:54:20 +00:00
|
|
|
wxFileDialog openDlg( this, _( "Open simulation workbook" ), getDefaultPath(), "",
|
2017-11-12 00:31:38 +00:00
|
|
|
WorkbookFileWildcard(), wxFD_OPEN | wxFD_FILE_MUST_EXIST );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
if( openDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2021-07-02 00:10:41 +00:00
|
|
|
loadWorkbook( openDlg.GetPath() );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuSaveWorkbook( wxCommandEvent& event )
|
|
|
|
{
|
2021-05-09 23:32:49 +00:00
|
|
|
if( !m_workbook->IsModified() )
|
2016-08-12 13:36:43 +00:00
|
|
|
return;
|
|
|
|
|
2021-05-09 23:32:49 +00:00
|
|
|
wxString filename = m_simulator->Settings()->GetWorkbookFilename();
|
|
|
|
|
|
|
|
if( filename.IsEmpty() )
|
|
|
|
{
|
|
|
|
menuSaveWorkbookAs( event );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-07-02 00:10:41 +00:00
|
|
|
saveWorkbook( Prj().AbsolutePath( m_simulator->Settings()->GetWorkbookFilename() ) );
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2021-05-04 22:35:04 +00:00
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuSaveWorkbookAs( wxCommandEvent& event )
|
|
|
|
{
|
2021-08-14 15:54:20 +00:00
|
|
|
wxFileDialog saveAsDlg( this, _( "Save Simulation Workbook As" ), getDefaultPath(),
|
|
|
|
getDefaultFilename(), WorkbookFileWildcard(),
|
2021-06-25 19:49:19 +00:00
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2021-05-04 22:35:04 +00:00
|
|
|
|
|
|
|
if( saveAsDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
2016-09-17 07:34:16 +00:00
|
|
|
|
2021-08-14 15:54:20 +00:00
|
|
|
saveWorkbook( Prj().AbsolutePath( saveAsDlg.GetPath() ) );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:28 +00:00
|
|
|
void SIM_PLOT_FRAME::menuSaveImage( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
if( !GetCurrentPlot() )
|
2016-08-12 13:36:43 +00:00
|
|
|
return;
|
|
|
|
|
2021-06-25 19:49:19 +00:00
|
|
|
wxFileDialog saveDlg( this, _( "Save Plot as Image" ), "", "", PngFileWildcard(),
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
|
|
|
if( saveDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
GetCurrentPlot()->GetPlotWin()->SaveScreenshot( saveDlg.GetPath(), wxBITMAP_TYPE_PNG );
|
2016-08-11 12:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
if( !GetCurrentPlot() )
|
2016-08-12 13:36:43 +00:00
|
|
|
return;
|
|
|
|
|
2016-08-11 12:41:28 +00:00
|
|
|
const wxChar SEPARATOR = ';';
|
|
|
|
|
2021-06-25 19:49:19 +00:00
|
|
|
wxFileDialog saveDlg( this, _( "Save Plot Data" ), "", "", CsvFileWildcard(),
|
|
|
|
wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
|
|
|
if( saveDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2020-12-12 18:11:51 +00:00
|
|
|
wxFFile out( saveDlg.GetPath(), "wb" );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
2022-05-25 15:00:03 +00:00
|
|
|
std::map<wxString, TRACE *> traces = GetCurrentPlot()->GetTraces();
|
2022-05-25 22:42:52 +00:00
|
|
|
|
2022-05-25 15:00:03 +00:00
|
|
|
if( traces.size() == 0 )
|
|
|
|
return;
|
2016-08-11 12:41:28 +00:00
|
|
|
|
2022-05-25 15:00:03 +00:00
|
|
|
SIM_TYPE simType = m_circuitModel->GetSimType();
|
2022-08-31 10:07:05 +00:00
|
|
|
|
2022-05-25 15:00:03 +00:00
|
|
|
std::size_t rowCount = traces.begin()->second->GetDataX().size();
|
2016-08-11 12:41:28 +00:00
|
|
|
|
2022-05-25 15:00:03 +00:00
|
|
|
// write column header names on the first row
|
|
|
|
wxString xAxisName( m_simulator->GetXAxis( simType ) );
|
2022-11-07 22:45:23 +00:00
|
|
|
out.Write( wxString::Format( wxT( "%s%c" ), xAxisName, SEPARATOR ) );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const auto& [name, trace] : traces )
|
|
|
|
out.Write( wxString::Format( wxT( "%s%c" ), name, SEPARATOR ) );
|
2022-05-25 15:00:03 +00:00
|
|
|
|
2022-11-07 22:45:23 +00:00
|
|
|
out.Write( wxS( "\r\n" ) );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
2022-05-25 15:00:03 +00:00
|
|
|
// write each row's numerical value
|
|
|
|
for ( std::size_t curRow=0; curRow < rowCount; curRow++ )
|
|
|
|
{
|
|
|
|
double xAxisValue = traces.begin()->second->GetDataX().at( curRow );
|
2022-11-07 22:45:23 +00:00
|
|
|
out.Write( wxString::Format( wxT( "%g%c" ), xAxisValue, SEPARATOR ) );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const auto& [name, trace] : traces )
|
2022-05-25 15:00:03 +00:00
|
|
|
{
|
2022-12-05 23:21:18 +00:00
|
|
|
double yAxisValue = trace->GetDataY().at( curRow );
|
2022-11-07 22:45:23 +00:00
|
|
|
out.Write( wxString::Format( wxT( "%g%c" ), yAxisValue, SEPARATOR ) );
|
2022-05-25 15:00:03 +00:00
|
|
|
}
|
2016-08-11 12:41:28 +00:00
|
|
|
|
2022-11-07 22:45:23 +00:00
|
|
|
out.Write( wxS( "\r\n" ) );
|
2016-08-11 12:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
out.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:22 +00:00
|
|
|
void SIM_PLOT_FRAME::menuZoomIn( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
if( GetCurrentPlot() )
|
|
|
|
GetCurrentPlot()->GetPlotWin()->ZoomIn();
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuZoomOut( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
if( GetCurrentPlot() )
|
|
|
|
GetCurrentPlot()->GetPlotWin()->ZoomOut();
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
if( GetCurrentPlot() )
|
|
|
|
GetCurrentPlot()->GetPlotWin()->Fit();
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
2016-08-12 13:36:43 +00:00
|
|
|
|
|
|
|
if( plot )
|
|
|
|
plot->ShowGrid( !plot->IsGridShown() );
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
void SIM_PLOT_FRAME::menuShowGridUpdate( wxUpdateUIEvent& event )
|
2016-08-11 12:41:22 +00:00
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
2016-08-12 13:36:43 +00:00
|
|
|
|
2018-01-06 05:02:28 +00:00
|
|
|
event.Check( plot ? plot->IsGridShown() : false );
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
2016-08-11 12:41:22 +00:00
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuShowLegend( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
2016-08-12 13:36:43 +00:00
|
|
|
|
|
|
|
if( plot )
|
|
|
|
plot->ShowLegend( !plot->IsLegendShown() );
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuShowLegendUpdate( wxUpdateUIEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
2016-08-11 12:41:27 +00:00
|
|
|
event.Check( plot ? plot->IsLegendShown() : false );
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
|
2019-11-19 16:17:37 +00:00
|
|
|
void SIM_PLOT_FRAME::menuShowDotted( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
2019-11-19 16:17:37 +00:00
|
|
|
|
|
|
|
if( plot )
|
|
|
|
plot->SetDottedCurrentPhase( !plot->GetDottedCurrentPhase() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuShowDottedUpdate( wxUpdateUIEvent& event )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = GetCurrentPlot();
|
2019-11-19 16:17:37 +00:00
|
|
|
|
|
|
|
event.Check( plot ? plot->GetDottedCurrentPhase() : false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-02-01 12:05:44 +00:00
|
|
|
void SIM_PLOT_FRAME::menuWhiteBackground( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
m_plotUseWhiteBg = not m_plotUseWhiteBg;
|
|
|
|
|
|
|
|
// Rebuild the color list to plot traces
|
2021-01-21 21:17:13 +00:00
|
|
|
SIM_PLOT_COLORS::FillDefaultColorList( GetPlotBgOpt() );
|
2020-02-01 12:05:44 +00:00
|
|
|
|
|
|
|
// Now send changes to all SIM_PLOT_PANEL
|
2021-06-30 00:13:10 +00:00
|
|
|
for( size_t page = 0; page < m_workbook->GetPageCount(); page++ )
|
2020-02-01 12:05:44 +00:00
|
|
|
{
|
2021-06-30 00:13:10 +00:00
|
|
|
wxWindow* curPage = m_workbook->GetPage( page );
|
2020-02-01 12:05:44 +00:00
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
// ensure it is truly a plot panel and not the (zero plots) placeholder
|
2020-12-29 03:38:02 +00:00
|
|
|
// which is only SIM_PLOT_PANEL_BASE
|
2020-12-29 03:33:01 +00:00
|
|
|
SIM_PLOT_PANEL* panel = dynamic_cast<SIM_PLOT_PANEL*>( curPage );
|
|
|
|
|
2021-06-25 19:49:19 +00:00
|
|
|
if( panel )
|
2020-12-29 03:33:01 +00:00
|
|
|
panel->UpdatePlotColors();
|
2020-02-01 12:05:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-11 00:06:11 +00:00
|
|
|
void SIM_PLOT_FRAME::menuSimulateUpdate( wxUpdateUIEvent& event )
|
|
|
|
{
|
2022-03-28 22:02:49 +00:00
|
|
|
event.Enable( m_circuitModel->CommandToSimType( getCurrentSimCommand() ) != ST_UNKNOWN );
|
2021-07-11 00:06:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuAddSignalsUpdate( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_simFinished );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuProbeUpdate( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_simFinished );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuTuneUpdate( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_simFinished );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
|
|
|
|
{
|
2021-05-11 23:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onPlotClosed( wxAuiNotebookEvent& event )
|
|
|
|
{
|
2021-09-08 20:56:33 +00:00
|
|
|
if( m_workbook->GetPageCount() == 0 )
|
|
|
|
{
|
|
|
|
m_signals->ClearAll();
|
|
|
|
m_cursors->ClearAll();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
updateSignalList();
|
|
|
|
wxCommandEvent dummy;
|
|
|
|
onCursorUpdate( dummy );
|
|
|
|
}
|
2016-08-11 12:42:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
2016-08-11 12:41:42 +00:00
|
|
|
updateSignalList();
|
2020-04-15 01:51:58 +00:00
|
|
|
wxCommandEvent dummy;
|
|
|
|
onCursorUpdate( dummy );
|
2021-05-11 23:27:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onPlotDragged( wxAuiNotebookEvent& event )
|
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
void SIM_PLOT_FRAME::onSignalDblClick( wxMouseEvent& event )
|
2016-08-11 12:41:16 +00:00
|
|
|
{
|
2016-08-11 12:41:56 +00:00
|
|
|
// Remove signal from the plot panel when double clicked
|
2016-08-29 09:39:54 +00:00
|
|
|
long idx = m_signals->GetFocusedItem();
|
2016-08-11 12:41:16 +00:00
|
|
|
|
|
|
|
if( idx != wxNOT_FOUND )
|
2016-08-29 09:39:54 +00:00
|
|
|
removePlot( m_signals->GetItemText( idx, 0 ) );
|
2016-08-11 12:41:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-19 12:44:47 +00:00
|
|
|
void SIM_PLOT_FRAME::onSignalRClick( wxListEvent& aEvent )
|
2016-08-11 12:41:25 +00:00
|
|
|
{
|
2023-01-19 12:44:47 +00:00
|
|
|
long idx = aEvent.GetIndex();
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
if( idx != wxNOT_FOUND )
|
2016-08-29 09:39:54 +00:00
|
|
|
m_signals->Select( idx );
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
idx = m_signals->GetFirstSelected();
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
if( idx != wxNOT_FOUND )
|
|
|
|
{
|
2016-08-29 09:39:54 +00:00
|
|
|
const wxString& netName = m_signals->GetItemText( idx, 0 );
|
2016-08-11 12:41:25 +00:00
|
|
|
SIGNAL_CONTEXT_MENU ctxMenu( netName, this );
|
|
|
|
m_signals->PopupMenu( &ctxMenu );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-19 12:44:47 +00:00
|
|
|
void SIM_PLOT_FRAME::onCursorRClick( wxListEvent& aEvent )
|
|
|
|
{
|
|
|
|
long idx = aEvent.GetIndex();
|
|
|
|
|
|
|
|
if( idx != wxNOT_FOUND )
|
|
|
|
m_signals->Select( idx );
|
|
|
|
|
|
|
|
idx = m_signals->GetFirstSelected();
|
|
|
|
|
|
|
|
if( idx != wxNOT_FOUND )
|
|
|
|
{
|
|
|
|
const wxString& netName = m_signals->GetItemText( idx, 0 );
|
|
|
|
CURSOR_CONTEXT_MENU ctxMenu( netName, this );
|
|
|
|
m_signals->PopupMenu( &ctxMenu );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-07-11 18:31:50 +00:00
|
|
|
void SIM_PLOT_FRAME::onWorkbookModified( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
updateTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onWorkbookClrModified( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
updateTitle();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:16 +00:00
|
|
|
void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event )
|
|
|
|
{
|
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:16 +00:00
|
|
|
else
|
|
|
|
StartSimulation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-22 15:52:01 +00:00
|
|
|
bool SIM_PLOT_FRAME::EditSimCommand()
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2022-12-05 20:01:36 +00:00
|
|
|
SIM_PANEL_BASE* plotPanelWindow = getCurrentPlotWindow();
|
2022-12-11 15:49:29 +00:00
|
|
|
DIALOG_SIM_COMMAND dlg( this, m_circuitModel, m_simulator->Settings() );
|
2022-12-05 20:01:36 +00:00
|
|
|
wxString errors;
|
|
|
|
WX_STRING_REPORTER reporter( &errors );
|
2022-11-18 15:27:53 +00:00
|
|
|
|
|
|
|
if( !m_circuitModel->ReadSchematicAndLibraries( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS,
|
|
|
|
reporter ) )
|
2021-05-04 22:35:04 +00:00
|
|
|
{
|
2022-11-18 15:27:53 +00:00
|
|
|
DisplayErrorMessage( this, _( "Errors during netlist generation; simulation aborted.\n\n" )
|
|
|
|
+ errors );
|
2023-05-22 15:52:01 +00:00
|
|
|
return false;
|
2021-05-04 22:35:04 +00:00
|
|
|
}
|
2016-08-11 12:42:09 +00:00
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND )
|
2023-01-14 00:17:33 +00:00
|
|
|
{
|
2022-12-05 20:01:36 +00:00
|
|
|
dlg.SetSimCommand( m_workbook->GetSimCommand( plotPanelWindow ) );
|
2023-01-14 00:17:33 +00:00
|
|
|
dlg.SetSimOptions( m_workbook->GetSimOptions( plotPanelWindow ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dlg.SetSimOptions( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS );
|
|
|
|
}
|
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
|
|
|
{
|
2021-05-04 22:35:04 +00:00
|
|
|
wxString oldCommand;
|
|
|
|
|
2021-06-30 00:13:10 +00:00
|
|
|
if( m_workbook->GetPageIndex( plotPanelWindow ) != wxNOT_FOUND )
|
2021-06-29 15:59:07 +00:00
|
|
|
oldCommand = m_workbook->GetSimCommand( plotPanelWindow );
|
2021-05-04 22:35:04 +00:00
|
|
|
else
|
|
|
|
oldCommand = wxString();
|
|
|
|
|
2022-12-11 21:28:04 +00:00
|
|
|
const wxString& newCommand = dlg.GetSimCommand();
|
2023-01-14 00:17:33 +00:00
|
|
|
int newOptions = dlg.GetSimOptions();
|
2022-12-11 21:28:04 +00:00
|
|
|
SIM_TYPE newSimType = NGSPICE_CIRCUIT_MODEL::CommandToSimType( newCommand );
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2022-12-23 18:20:20 +00:00
|
|
|
if( !plotPanelWindow )
|
|
|
|
{
|
|
|
|
m_circuitModel->SetSimCommandOverride( newCommand );
|
2023-01-14 00:17:33 +00:00
|
|
|
m_circuitModel->SetSimOptions( newOptions );
|
|
|
|
plotPanelWindow = NewPlotPanel( newCommand, newOptions );
|
2022-12-23 18:20:20 +00:00
|
|
|
}
|
|
|
|
// If it is a new simulation type, open a new plot. For the DC sim, check if sweep
|
|
|
|
// source type has changed (char 4 will contain 'v', 'i', 'r' or 't'.
|
|
|
|
else if( plotPanelWindow->GetType() != newSimType
|
|
|
|
|| ( newSimType == ST_DC
|
|
|
|
&& oldCommand.Lower().GetChar( 4 ) != newCommand.Lower().GetChar( 4 ) ) )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2023-01-14 00:17:33 +00:00
|
|
|
plotPanelWindow = NewPlotPanel( newCommand, newOptions );
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2021-05-26 18:15:16 +00:00
|
|
|
else
|
|
|
|
{
|
2022-12-23 18:20:20 +00:00
|
|
|
if( m_workbook->GetPageIndex( plotPanelWindow ) == 0 )
|
|
|
|
m_circuitModel->SetSimCommandOverride( newCommand );
|
|
|
|
|
2021-05-26 18:15:16 +00:00
|
|
|
// Update simulation command in the current plot
|
2021-06-29 15:59:07 +00:00
|
|
|
m_workbook->SetSimCommand( plotPanelWindow, newCommand );
|
2023-01-14 00:17:33 +00:00
|
|
|
m_workbook->SetSimOptions( plotPanelWindow, newOptions );
|
2021-05-26 18:15:16 +00:00
|
|
|
}
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
m_simulator->Init();
|
2023-05-22 15:52:01 +00:00
|
|
|
return true;
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2023-05-22 15:52:01 +00:00
|
|
|
|
|
|
|
return false;
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
void SIM_PLOT_FRAME::onAddSignal( wxCommandEvent& event )
|
|
|
|
{
|
2022-11-07 22:45:23 +00:00
|
|
|
wxCHECK_RET( m_simFinished, wxT( "No simulation results available" ) );
|
2021-05-05 18:26:56 +00:00
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = GetCurrentPlot();
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2022-03-28 22:02:49 +00:00
|
|
|
if( !plotPanel || !m_circuitModel || plotPanel->GetType() != m_circuitModel->GetSimType() )
|
2016-08-11 12:41:52 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
DisplayInfoMessage( this, _( "You need to run plot-providing simulation first." ) );
|
2016-08-11 12:41:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-03-28 22:02:49 +00:00
|
|
|
DIALOG_SIGNAL_LIST dialog( this, m_circuitModel.get() );
|
2016-08-11 12:41:42 +00:00
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onProbe( wxCommandEvent& event )
|
2016-08-11 12:41:16 +00:00
|
|
|
{
|
2022-11-07 22:45:23 +00:00
|
|
|
wxCHECK_RET( m_simFinished, wxT( "No simulation results available" ) );
|
2016-08-11 12:41:16 +00:00
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
if( m_schematicFrame == nullptr )
|
2021-05-05 18:26:56 +00:00
|
|
|
return;
|
|
|
|
|
2022-07-14 18:36:07 +00:00
|
|
|
wxWindow* blocking_dialog = m_schematicFrame->Kiway().GetBlockingDialog();
|
|
|
|
|
|
|
|
if( blocking_dialog )
|
|
|
|
blocking_dialog->Close( true );
|
|
|
|
|
2019-06-03 13:49:17 +00:00
|
|
|
m_schematicFrame->GetToolManager()->RunAction( EE_ACTIONS::simProbe );
|
2016-08-11 12:42:19 +00:00
|
|
|
m_schematicFrame->Raise();
|
2016-08-11 12:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onTune( wxCommandEvent& event )
|
|
|
|
{
|
2022-11-07 22:45:23 +00:00
|
|
|
wxCHECK_RET( m_simFinished, wxT( "No simulation results available" ) );
|
2021-07-09 19:35:47 +00:00
|
|
|
|
|
|
|
if( m_schematicFrame == nullptr )
|
2016-08-11 12:41:45 +00:00
|
|
|
return;
|
|
|
|
|
2022-07-14 18:36:07 +00:00
|
|
|
wxWindow* blocking_dialog = m_schematicFrame->Kiway().GetBlockingDialog();
|
|
|
|
|
|
|
|
if( blocking_dialog )
|
|
|
|
blocking_dialog->Close( true );
|
|
|
|
|
2019-06-03 13:49:17 +00:00
|
|
|
m_schematicFrame->GetToolManager()->RunAction( EE_ACTIONS::simTune );
|
2016-08-11 12:42:19 +00:00
|
|
|
m_schematicFrame->Raise();
|
2016-08-11 12:41:16 +00:00
|
|
|
}
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
class NETLIST_VIEW_DIALOG : public DIALOG_SHIM
|
2018-03-03 16:36:26 +00:00
|
|
|
{
|
2023-01-14 00:17:33 +00:00
|
|
|
public:
|
|
|
|
enum
|
2018-03-03 16:36:26 +00:00
|
|
|
{
|
2023-01-14 00:17:33 +00:00
|
|
|
MARGIN_LINE_NUMBERS
|
|
|
|
};
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
void onClose( wxCloseEvent& evt )
|
|
|
|
{
|
|
|
|
wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL ) );
|
|
|
|
}
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
NETLIST_VIEW_DIALOG( wxWindow* parent, const wxString& source) :
|
|
|
|
DIALOG_SHIM( parent, wxID_ANY, _( "SPICE Netlist" ), wxDefaultPosition,
|
|
|
|
wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
|
|
|
{
|
|
|
|
wxStyledTextCtrl* textCtrl = new wxStyledTextCtrl( this, wxID_ANY );
|
|
|
|
textCtrl->SetMinSize( wxSize( 600, 400 ) );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
textCtrl->SetMarginWidth( MARGIN_LINE_NUMBERS, 50 );
|
|
|
|
textCtrl->StyleSetForeground( wxSTC_STYLE_LINENUMBER, wxColour( 75, 75, 75 ) );
|
|
|
|
textCtrl->StyleSetBackground( wxSTC_STYLE_LINENUMBER, wxColour( 220, 220, 220 ) );
|
|
|
|
textCtrl->SetMarginType( MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
wxFont fixedFont = KIUI::GetMonospacedUIFont();
|
2021-06-29 18:33:41 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
for( int i = 0; i < wxSTC_STYLE_MAX; ++i )
|
|
|
|
textCtrl->StyleSetFont( i, fixedFont );
|
2021-06-29 18:33:41 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
textCtrl->StyleClearAll(); // Addresses a bug in wx3.0 where styles are not correctly set
|
2020-12-03 00:27:10 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
textCtrl->SetWrapMode( wxSTC_WRAP_WORD );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
textCtrl->SetText( source );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
textCtrl->SetLexer( wxSTC_LEX_SPICE );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
sizer->Add( textCtrl, 1, wxEXPAND | wxALL, 5 );
|
|
|
|
SetSizer( sizer );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( NETLIST_VIEW_DIALOG::onClose ),
|
|
|
|
nullptr, this );
|
2021-01-11 09:01:50 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
m_scintillaTricks = std::make_unique<SCINTILLA_TRICKS>( textCtrl, wxT( "{}" ), false );
|
2022-09-16 04:56:51 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
finishDialogSettings();
|
|
|
|
}
|
2022-09-16 04:56:51 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
std::unique_ptr<SCINTILLA_TRICKS> m_scintillaTricks;
|
|
|
|
};
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onShowNetlist( wxCommandEvent& event )
|
|
|
|
{
|
2021-07-16 20:13:26 +00:00
|
|
|
if( m_schematicFrame == nullptr || m_simulator == nullptr )
|
2018-03-03 16:36:26 +00:00
|
|
|
return;
|
|
|
|
|
2023-05-17 06:42:29 +00:00
|
|
|
if( !m_schematicFrame->ReadyToNetlist( _( "Simulator requires a fully annotated schematic." ) ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// If we are using the new connectivity, make sure that we do a full-rebuild
|
|
|
|
if( ADVANCED_CFG::GetCfg().m_IncrementalConnectivity )
|
|
|
|
m_schematicFrame->RecalculateConnections( GLOBAL_CLEANUP );
|
|
|
|
|
2022-11-18 15:27:53 +00:00
|
|
|
wxString errors;
|
|
|
|
WX_STRING_REPORTER reporter( &errors );
|
|
|
|
STRING_FORMATTER formatter;
|
2023-01-14 00:17:33 +00:00
|
|
|
|
|
|
|
m_circuitModel->SetSimOptions( getCurrentOptions() );
|
2022-11-18 15:27:53 +00:00
|
|
|
m_circuitModel->GetNetlist( &formatter, reporter );
|
2022-09-16 01:08:09 +00:00
|
|
|
|
2023-01-07 22:13:15 +00:00
|
|
|
NETLIST_VIEW_DIALOG dlg( this, errors.IsEmpty() ? wxString( formatter.GetString() ) : errors );
|
2018-03-03 16:36:26 +00:00
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:16 +00:00
|
|
|
|
2021-05-09 23:32:49 +00:00
|
|
|
bool SIM_PLOT_FRAME::canCloseWindow( wxCloseEvent& aEvent )
|
|
|
|
{
|
|
|
|
if( m_workbook->IsModified() )
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2022-12-11 13:32:37 +00:00
|
|
|
#if 0 // TODO: Enable once 8.0 opens for dev
|
|
|
|
wxString msg = _( "Save changes to workbook?" );
|
|
|
|
#else
|
2021-10-01 20:49:14 +00:00
|
|
|
wxString fullFilename = filename.GetFullName();
|
2021-06-27 13:24:02 +00:00
|
|
|
wxString msg = _( "Save changes to '%s' before closing?" );
|
2022-12-11 13:32:37 +00:00
|
|
|
msg.Printf( msg, fullFilename );
|
|
|
|
#endif
|
2021-05-09 23:32:49 +00:00
|
|
|
|
2022-12-11 13:32:37 +00:00
|
|
|
return HandleUnsavedChanges( this, msg,
|
2021-10-01 20:49:14 +00:00
|
|
|
[&]() -> bool
|
|
|
|
{
|
|
|
|
return saveWorkbook( Prj().AbsolutePath( fullFilename ) );
|
|
|
|
} );
|
2021-05-09 23:32:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-08-24 02:01:14 +00:00
|
|
|
void SIM_PLOT_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
|
|
|
|
m_schematicFrame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxSize size = m_cursors->GetClientSize();
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = GetCurrentPlot();
|
2016-08-11 12:41:27 +00:00
|
|
|
m_cursors->ClearAll();
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
if( !plotPanel )
|
|
|
|
return;
|
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
if( m_signalsIconColorList )
|
|
|
|
m_cursors->SetImageList(m_signalsIconColorList, wxIMAGE_LIST_SMALL);
|
|
|
|
|
|
|
|
// Fill the signals listctrl
|
|
|
|
m_cursors->AppendColumn( _( "Signal" ), wxLIST_FORMAT_LEFT, size.x / 2 );
|
2021-03-18 19:31:02 +00:00
|
|
|
const long X_COL = m_cursors->AppendColumn( plotPanel->GetLabelX(), wxLIST_FORMAT_LEFT,
|
|
|
|
size.x / 4 );
|
2016-08-11 12:41:56 +00:00
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
wxString labelY1 = plotPanel->GetLabelY1();
|
|
|
|
wxString labelY2 = plotPanel->GetLabelY2();
|
2016-08-11 12:41:56 +00:00
|
|
|
wxString labelY;
|
|
|
|
|
|
|
|
if( !labelY2.IsEmpty() )
|
2022-11-07 22:45:23 +00:00
|
|
|
labelY = labelY1 + wxT( " / " ) + labelY2;
|
2016-08-11 12:41:56 +00:00
|
|
|
else
|
|
|
|
labelY = labelY1;
|
|
|
|
|
|
|
|
const long Y_COL = m_cursors->AppendColumn( labelY, wxLIST_FORMAT_LEFT, size.x / 4 );
|
2016-08-11 12:41:27 +00:00
|
|
|
|
|
|
|
// Update cursor values
|
2016-08-29 09:39:54 +00:00
|
|
|
int itemidx = 0;
|
2020-04-21 10:47:48 +00:00
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const auto& [name, trace] : plotPanel->GetTraces() )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
2022-12-05 23:21:18 +00:00
|
|
|
if( CURSOR* cursor = trace->GetCursor() )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
2022-12-05 23:21:18 +00:00
|
|
|
// Find the right icon color in list.
|
2016-08-29 09:39:54 +00:00
|
|
|
// It is the icon used in m_signals list for the same trace
|
2022-12-05 23:21:18 +00:00
|
|
|
long iconColor = m_signals->FindItem( -1, name );
|
2016-08-29 09:39:54 +00:00
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
const wxRealPoint coords = cursor->GetCoords();
|
2022-12-05 23:21:18 +00:00
|
|
|
long idx = m_cursors->InsertItem( itemidx++, name, iconColor );
|
2016-08-11 12:41:55 +00:00
|
|
|
m_cursors->SetItem( idx, X_COL, SPICE_VALUE( coords.x ).ToSpiceString() );
|
|
|
|
m_cursors->SetItem( idx, Y_COL, SPICE_VALUE( coords.y ).ToSpiceString() );
|
2016-08-11 12:41:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
void SIM_PLOT_FRAME::onSimStarted( wxCommandEvent& aEvent )
|
2016-08-11 12:41:19 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( BITMAPS::sim_stop ) );
|
2016-08-11 12:41:19 +00:00
|
|
|
SetCursor( wxCURSOR_ARROWWAIT );
|
2016-08-11 12:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent )
|
2016-08-11 12:41:07 +00:00
|
|
|
{
|
2021-03-08 02:59:07 +00:00
|
|
|
m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( BITMAPS::sim_run ) );
|
2016-08-11 12:41:19 +00:00
|
|
|
SetCursor( wxCURSOR_ARROW );
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2022-03-28 22:02:49 +00:00
|
|
|
SIM_TYPE simType = m_circuitModel->GetSimType();
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
if( simType == ST_UNKNOWN )
|
|
|
|
return;
|
|
|
|
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PANEL_BASE* plotPanelWindow = getCurrentPlotWindow();
|
2016-08-11 12:41:39 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( !plotPanelWindow || plotPanelWindow->GetType() != simType )
|
2023-01-14 00:17:33 +00:00
|
|
|
{
|
|
|
|
plotPanelWindow = NewPlotPanel( m_circuitModel->GetSimCommand(),
|
|
|
|
m_circuitModel->GetSimOptions() );
|
|
|
|
}
|
2016-08-11 12:41:39 +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() );
|
|
|
|
}
|
|
|
|
// Is a warning message useful if the simulatior is still running?
|
2016-08-11 12:42:19 +00:00
|
|
|
|
2016-08-11 12:41:18 +00:00
|
|
|
// If there are any signals plotted, update them
|
2020-04-15 01:51:58 +00:00
|
|
|
if( SIM_PANEL_BASE::IsPlottable( simType ) )
|
2016-08-11 12:41:35 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = dynamic_cast<SIM_PLOT_PANEL*>( plotPanelWindow );
|
2022-11-07 22:45:23 +00:00
|
|
|
wxCHECK_RET( plotPanel, wxT( "not a SIM_PLOT_PANEL" ) );
|
2020-04-21 10:47:48 +00:00
|
|
|
|
2021-05-24 20:17:29 +00:00
|
|
|
struct TRACE_DESC
|
|
|
|
{
|
2021-06-25 19:49:19 +00:00
|
|
|
wxString m_name; ///< Name of the measured net/device
|
|
|
|
SIM_PLOT_TYPE m_type; ///< Type of the signal
|
2021-05-24 20:17:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
std::vector<struct TRACE_DESC> traceInfo;
|
|
|
|
|
|
|
|
// Get information about all the traces on the plot, remove and add again
|
2022-12-05 23:21:18 +00:00
|
|
|
for( auto& [name, trace] : plotPanel->GetTraces() )
|
2016-08-11 12:42:09 +00:00
|
|
|
{
|
2021-05-24 20:17:29 +00:00
|
|
|
struct TRACE_DESC placeholder;
|
2022-12-05 23:21:18 +00:00
|
|
|
placeholder.m_name = trace->GetName();
|
|
|
|
placeholder.m_type = trace->GetType();
|
2021-05-24 20:17:29 +00:00
|
|
|
|
|
|
|
traceInfo.push_back( placeholder );
|
|
|
|
}
|
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const struct TRACE_DESC& trace : traceInfo )
|
2021-05-24 20:17:29 +00:00
|
|
|
{
|
2022-04-12 14:37:06 +00:00
|
|
|
if( !updatePlot( trace.m_name, trace.m_type, plotPanel ) )
|
2021-06-30 00:13:10 +00:00
|
|
|
removePlot( trace.m_name );
|
2016-08-11 12:42:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
updateSignalList();
|
2020-04-15 01:51:58 +00:00
|
|
|
plotPanel->GetPlotWin()->UpdateAll();
|
2016-08-11 12:42:04 +00:00
|
|
|
plotPanel->ResetScales();
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
2020-04-15 01:51:58 +00:00
|
|
|
else if( simType == ST_OP )
|
2016-08-11 12:41:35 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
|
2022-12-05 23:21:18 +00:00
|
|
|
for( const std::string& vec : m_simulator->AllPlots() )
|
2016-08-11 12:41:35 +00:00
|
|
|
{
|
2021-04-14 19:01:39 +00:00
|
|
|
std::vector<double> val_list = m_simulator->GetRealPlot( vec, 1 );
|
2020-04-15 01:51:58 +00:00
|
|
|
|
2021-04-14 19:01:39 +00:00
|
|
|
if( val_list.size() == 0 ) // The list of values can be empty!
|
|
|
|
continue;
|
|
|
|
|
|
|
|
double val = val_list.at( 0 );
|
2020-04-15 01:51:58 +00:00
|
|
|
wxString outLine, signal;
|
2022-03-28 22:02:49 +00:00
|
|
|
SIM_PLOT_TYPE type = m_circuitModel->VectorToSignal( vec, signal );
|
2020-04-15 01:51:58 +00:00
|
|
|
|
|
|
|
const size_t tab = 25; //characters
|
|
|
|
size_t padding = ( signal.length() < tab ) ? ( tab - signal.length() ) : 1;
|
|
|
|
|
2021-06-25 19:49:19 +00:00
|
|
|
outLine.Printf( wxT( "%s%s" ),
|
|
|
|
( signal + wxT( ":" ) ).Pad( padding, wxUniChar( ' ' ) ),
|
|
|
|
SPICE_VALUE( val ).ToSpiceString() );
|
2020-04-15 01:51:58 +00:00
|
|
|
|
2022-11-07 22:45:23 +00:00
|
|
|
outLine.Append( type == SPT_CURRENT ? wxT( "A\n" ) : wxT( "V\n" ) );
|
2020-04-15 01:51:58 +00:00
|
|
|
|
|
|
|
m_simConsole->AppendText( outLine );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
2016-08-11 12:42:09 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
// @todo display calculated values on the schematic
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-09 19:35:47 +00:00
|
|
|
|
2022-03-29 21:51:09 +00:00
|
|
|
m_lastSimPlot = plotPanelWindow;
|
2021-07-09 19:35:47 +00:00
|
|
|
m_simFinished = true;
|
2016-08-11 12:41:07 +00:00
|
|
|
}
|
2016-08-11 12:41:19 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
void SIM_PLOT_FRAME::onSimUpdate( wxCommandEvent& aEvent )
|
|
|
|
{
|
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
|
|
|
|
2022-03-29 21:51:09 +00:00
|
|
|
if( getCurrentPlotWindow() != m_lastSimPlot )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
|
|
|
// We need to rerun simulation, as the simulator currently stores
|
|
|
|
// results for another plot
|
|
|
|
StartSimulation();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-19 16:58:48 +00:00
|
|
|
std::unique_lock<std::mutex> simulatorLock( m_simulator->GetMutex(), std::try_to_lock );
|
2021-07-09 20:20:23 +00:00
|
|
|
|
2022-02-19 16:58:48 +00:00
|
|
|
if( simulatorLock.owns_lock() )
|
|
|
|
{
|
|
|
|
// Incremental update
|
|
|
|
m_simConsole->Clear();
|
|
|
|
|
|
|
|
// Do not export netlist, it is already stored in the simulator
|
|
|
|
applyTuners();
|
|
|
|
|
|
|
|
m_simulator->Run();
|
|
|
|
}
|
|
|
|
else
|
2022-12-23 22:02:59 +00:00
|
|
|
{
|
2022-02-19 16:58:48 +00:00
|
|
|
DisplayErrorMessage( this, _( "Another simulation is already running." ) );
|
2022-12-23 22:02:59 +00:00
|
|
|
}
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2022-03-29 21:51:09 +00:00
|
|
|
updateInProgress = false;
|
2016-08-11 12:41:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
void SIM_PLOT_FRAME::onSimReport( wxCommandEvent& aEvent )
|
|
|
|
{
|
2016-08-11 12:41:35 +00:00
|
|
|
m_simConsole->AppendText( aEvent.GetString() + "\n" );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
2016-08-11 12:41:19 +00:00
|
|
|
}
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::SIGNAL_CONTEXT_MENU( const wxString& aSignal,
|
2021-02-16 15:17:02 +00:00
|
|
|
SIM_PLOT_FRAME* aPlotFrame ) :
|
|
|
|
m_signal( aSignal ),
|
|
|
|
m_plotFrame( aPlotFrame )
|
2016-08-11 12:41:25 +00:00
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = m_plotFrame->GetCurrentPlot();
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2022-12-28 10:20:05 +00:00
|
|
|
AddMenuItem( this, REMOVE_SIGNAL, _( "Remove Signal" ), _( "Remove the signal from the plot" ),
|
2021-03-08 02:59:07 +00:00
|
|
|
KiBitmap( BITMAPS::trash ) );
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
TRACE* trace = plot->GetTrace( m_signal );
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2022-12-28 10:20:05 +00:00
|
|
|
AppendSeparator();
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
if( trace->HasCursor() )
|
2021-03-08 02:59:07 +00:00
|
|
|
AddMenuItem( this, HIDE_CURSOR, _( "Hide Cursor" ), KiBitmap( BITMAPS::pcb_target ) );
|
2016-08-11 12:41:25 +00:00
|
|
|
else
|
2021-03-08 02:59:07 +00:00
|
|
|
AddMenuItem( this, SHOW_CURSOR, _( "Show Cursor" ), KiBitmap( BITMAPS::pcb_target ) );
|
2016-08-11 12:41:25 +00:00
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( SIGNAL_CONTEXT_MENU::onMenuEvent ),
|
2021-07-16 20:13:26 +00:00
|
|
|
nullptr, this );
|
2016-08-11 12:41:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
|
|
|
|
{
|
2021-07-09 19:35:47 +00:00
|
|
|
SIM_PLOT_PANEL* plot = m_plotFrame->GetCurrentPlot();
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
switch( aEvent.GetId() )
|
|
|
|
{
|
2022-12-28 10:20:05 +00:00
|
|
|
case REMOVE_SIGNAL: m_plotFrame->removePlot( m_signal ); break;
|
|
|
|
case SHOW_CURSOR: plot->EnableCursor( m_signal, true ); break;
|
|
|
|
case HIDE_CURSOR: plot->EnableCursor( m_signal, false ); break;
|
2016-08-11 12:41:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2023-01-19 12:44:47 +00:00
|
|
|
SIM_PLOT_FRAME::CURSOR_CONTEXT_MENU::CURSOR_CONTEXT_MENU( const wxString& aSignal,
|
|
|
|
SIM_PLOT_FRAME* aPlotFrame ) :
|
|
|
|
m_signal( aSignal ),
|
|
|
|
m_plotFrame( aPlotFrame )
|
|
|
|
{
|
|
|
|
AddMenuItem( this, HIDE_CURSOR, _( "Hide Cursor" ), KiBitmap( BITMAPS::pcb_target ) );
|
|
|
|
|
|
|
|
Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( CURSOR_CONTEXT_MENU::onMenuEvent ),
|
|
|
|
nullptr, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::CURSOR_CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
|
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plot = m_plotFrame->GetCurrentPlot();
|
|
|
|
|
2023-01-20 21:26:11 +00:00
|
|
|
if( aEvent.GetId() == HIDE_CURSOR )
|
|
|
|
plot->EnableCursor( m_signal, false );
|
2023-01-19 12:44:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-01-13 13:38:23 +00:00
|
|
|
void SIM_PLOT_FRAME::menuExit( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetId() == wxID_EXIT )
|
|
|
|
Kiway().OnKiCadExit();
|
|
|
|
|
|
|
|
if( event.GetId() == wxID_CLOSE )
|
|
|
|
Close( false );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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 );
|