2016-08-11 12:41:07 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
2021-01-11 09:01:50 +00:00
|
|
|
* Copyright (C) 2016-2021 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
|
|
|
|
2018-03-03 16:36:26 +00:00
|
|
|
#include <wx/stc/stc.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>
|
2016-08-11 12:41:30 +00:00
|
|
|
#include "netlist_exporter_pspice_sim.h"
|
2016-09-17 07:34:16 +00:00
|
|
|
#include <pgm_base.h>
|
2016-08-11 12:41:01 +00:00
|
|
|
#include "sim_plot_frame.h"
|
|
|
|
#include "sim_plot_panel.h"
|
|
|
|
#include "spice_simulator.h"
|
2016-08-11 12:41:19 +00:00
|
|
|
#include "spice_reporter.h"
|
2016-08-29 09:39:54 +00:00
|
|
|
#include <menus_helpers.h>
|
2020-05-17 00:19:48 +00:00
|
|
|
#include <settings/common_settings.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-01-11 09:01:50 +00:00
|
|
|
#include <dialog_shim.h>
|
2016-08-29 09:39:54 +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:
|
2016-08-11 12:41:07 +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
|
|
|
{
|
2016-08-11 12:41:19 +00:00
|
|
|
wxCommandEvent* event = NULL;
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
switch( aNewState )
|
|
|
|
{
|
|
|
|
case SIM_IDLE:
|
2016-08-11 12:41:27 +00:00
|
|
|
event = new wxCommandEvent( EVT_SIM_FINISHED );
|
2016-08-11 12:41:19 +00:00
|
|
|
break;
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-08-11 12:41:19 +00:00
|
|
|
case SIM_RUNNING:
|
2016-08-11 12:41:27 +00:00
|
|
|
event = new wxCommandEvent( EVT_SIM_STARTED );
|
2016-08-11 12:41:19 +00:00
|
|
|
break;
|
2018-03-22 10:58:55 +00:00
|
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
TRACE_DESC::TRACE_DESC( const NETLIST_EXPORTER_PSPICE_SIM& aExporter, const wxString& aName,
|
|
|
|
SIM_PLOT_TYPE aType, const wxString& aParam )
|
|
|
|
: m_name( aName ), m_type( aType ), m_param( aParam )
|
|
|
|
{
|
|
|
|
// Title generation
|
|
|
|
m_title = wxString::Format( "%s(%s)", aParam, aName );
|
|
|
|
|
|
|
|
if( aType & SPT_AC_MAG )
|
|
|
|
m_title += " (mag)";
|
|
|
|
else if( aType & SPT_AC_PHASE )
|
|
|
|
m_title += " (phase)";
|
|
|
|
}
|
|
|
|
|
2016-09-17 07:34:16 +00:00
|
|
|
// Store the path of saved workbooks during the session
|
|
|
|
wxString SIM_PLOT_FRAME::m_savedWorkbooksPath;
|
2016-08-11 12:41:52 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
SIM_PLOT_FRAME::SIM_PLOT_FRAME( KIWAY* aKiway, wxWindow* aParent )
|
2020-04-15 01:51:58 +00:00
|
|
|
: SIM_PLOT_FRAME_BASE( aParent ),
|
|
|
|
m_lastSimPlot( nullptr ),
|
|
|
|
m_welcomePanel( nullptr ),
|
|
|
|
m_plotNumber( 0 )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2016-08-11 12:41:15 +00:00
|
|
|
SetKiway( this, aKiway );
|
2016-08-29 09:39:54 +00:00
|
|
|
m_signalsIconColorList = NULL;
|
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 );
|
|
|
|
|
|
|
|
if( m_schematicFrame == NULL )
|
|
|
|
throw std::runtime_error( "There is no schematic window" );
|
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
// Give an icon
|
|
|
|
wxIcon icon;
|
|
|
|
icon.CopyFromBitmap( KiBitmap( simulator_xpm ) );
|
|
|
|
SetIcon( icon );
|
|
|
|
|
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
|
|
|
|
fillDefaultColorList( GetPlotBgOpt() );
|
|
|
|
|
2019-04-14 13:31:32 +00:00
|
|
|
// Give icons to menuitems
|
|
|
|
setIconsForMenuItems();
|
|
|
|
|
2016-08-19 13:51:19 +00:00
|
|
|
m_simulator = SPICE_SIMULATOR::CreateInstance( "ngspice" );
|
|
|
|
|
|
|
|
if( !m_simulator )
|
|
|
|
{
|
|
|
|
throw std::runtime_error( "Could not create simulator instance" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_simulator->Init();
|
|
|
|
|
2016-09-17 07:34:16 +00:00
|
|
|
if( m_savedWorkbooksPath.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_savedWorkbooksPath = Prj().GetProjectPath();
|
|
|
|
}
|
|
|
|
|
2016-08-19 13:51:19 +00:00
|
|
|
m_reporter = new SIM_THREAD_REPORTER( this );
|
|
|
|
m_simulator->SetReporter( m_reporter );
|
|
|
|
|
2021-01-26 21:34:27 +00:00
|
|
|
// the settings dialog will be created later, on demand.
|
|
|
|
// if created in the ctor, for some obscure reason, there is an issue
|
|
|
|
// on Windows: when open it, the simulator frame is sent to the background.
|
|
|
|
// instead of being behind the dialog frame (as it does)
|
|
|
|
m_settingsDlg = nullptr;
|
|
|
|
|
2016-08-11 12:41:41 +00:00
|
|
|
updateNetlistExporter();
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
Connect( EVT_SIM_UPDATE, wxCommandEventHandler( SIM_PLOT_FRAME::onSimUpdate ), NULL, this );
|
2016-08-11 12:41:27 +00:00
|
|
|
Connect( EVT_SIM_REPORT, wxCommandEventHandler( SIM_PLOT_FRAME::onSimReport ), NULL, this );
|
|
|
|
Connect( EVT_SIM_STARTED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimStarted ), NULL, this );
|
|
|
|
Connect( EVT_SIM_FINISHED, wxCommandEventHandler( SIM_PLOT_FRAME::onSimFinished ), NULL, this );
|
2016-08-11 12:41:27 +00:00
|
|
|
Connect( EVT_SIM_CURSOR_UPDATE, wxCommandEventHandler( SIM_PLOT_FRAME::onCursorUpdate ), NULL, 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" ),
|
|
|
|
KiBitmap( sim_run_xpm ), _( "Run Simulation" ), wxITEM_NORMAL );
|
|
|
|
m_toolAddSignals = m_toolBar->AddTool( ID_SIM_ADD_SIGNALS, _( "Add Signals" ),
|
|
|
|
KiBitmap( sim_add_signal_xpm ), _( "Add signals to plot" ), wxITEM_NORMAL );
|
|
|
|
m_toolProbe = m_toolBar->AddTool( ID_SIM_PROBE, _( "Probe" ),
|
|
|
|
KiBitmap( sim_probe_xpm ), _( "Probe signals on the schematic" ), wxITEM_NORMAL );
|
|
|
|
m_toolTune = m_toolBar->AddTool( ID_SIM_TUNE, _( "Tune" ),
|
|
|
|
KiBitmap( sim_tune_xpm ), _( "Tune component values" ), wxITEM_NORMAL );
|
2021-01-31 09:36:26 +00:00
|
|
|
m_toolSettings = m_toolBar->AddTool( wxID_ANY, _( "Sim Parameters" ),
|
2021-01-27 18:12:18 +00:00
|
|
|
KiBitmap( config_xpm ), _( "Simulation parameters and settings" ), wxITEM_NORMAL );
|
2016-08-11 12:42:00 +00:00
|
|
|
|
2016-12-02 14:34:23 +00:00
|
|
|
Connect( m_toolSimulate->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler( SIM_PLOT_FRAME::onSimulate ), NULL, this );
|
|
|
|
Connect( m_toolAddSignals->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler( SIM_PLOT_FRAME::onAddSignal ), NULL, this );
|
|
|
|
Connect( m_toolProbe->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler( SIM_PLOT_FRAME::onProbe ), NULL, this );
|
|
|
|
Connect( m_toolTune->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler( SIM_PLOT_FRAME::onTune ), NULL, this );
|
|
|
|
Connect( m_toolSettings->GetId(), wxEVT_COMMAND_TOOL_CLICKED,
|
|
|
|
wxCommandEventHandler( SIM_PLOT_FRAME::onSettings ), NULL, this );
|
2016-08-11 12:42:00 +00:00
|
|
|
|
2016-08-11 12:42:17 +00:00
|
|
|
// Bind toolbar buttons event to existing menu event handlers, so they behave the same
|
2018-03-03 16:36:26 +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() );
|
|
|
|
Bind( wxEVT_COMMAND_MENU_SELECTED, &SIM_PLOT_FRAME::onSettings, this, m_settings->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-01-25 21:29:13 +00:00
|
|
|
m_welcomePanel = new SIM_PANEL_BASE( wxEmptyString, m_plotNotebook, wxID_ANY );
|
2020-04-15 01:51:58 +00:00
|
|
|
m_plotNotebook->AddPage( m_welcomePanel, _( "Welcome!" ), 1, true );
|
2016-08-20 17:51:33 +00:00
|
|
|
|
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();
|
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()
|
|
|
|
{
|
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-20 17:51:33 +00:00
|
|
|
|
|
|
|
if( m_settingsDlg )
|
|
|
|
m_settingsDlg->Destroy();
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
|
|
|
|
2016-12-02 14:34:23 +00:00
|
|
|
|
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
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
|
|
|
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;
|
|
|
|
}
|
2016-12-02 14:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-01-13 01:44:19 +00:00
|
|
|
void SIM_PLOT_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
|
2016-12-02 14:34:23 +00:00
|
|
|
{
|
2020-01-13 01:44:19 +00:00
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
|
|
|
wxASSERT( cfg );
|
|
|
|
|
2020-03-21 16:31:48 +00:00
|
|
|
if( cfg )
|
|
|
|
{
|
|
|
|
EDA_BASE_FRAME::LoadSettings( cfg );
|
2020-01-13 01:44:19 +00:00
|
|
|
|
2020-03-21 16:31:48 +00:00
|
|
|
// 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;
|
|
|
|
}
|
2020-01-13 01:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WINDOW_SETTINGS* SIM_PLOT_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
|
|
|
|
{
|
|
|
|
auto cfg = dynamic_cast<EESCHEMA_SETTINGS*>( aCfg );
|
|
|
|
wxASSERT( cfg );
|
2020-03-21 16:31:48 +00:00
|
|
|
|
|
|
|
return cfg ? &cfg->m_Simulator.window : nullptr;
|
2016-12-02 14:34:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-04-14 13:31:32 +00:00
|
|
|
// A small helper struct to handle bitmaps initialisation in menus
|
|
|
|
struct BM_MENU_INIT_ITEM
|
|
|
|
{
|
|
|
|
int m_MenuId;
|
|
|
|
BITMAP_DEF m_Bitmap;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::setIconsForMenuItems()
|
|
|
|
{
|
|
|
|
// Give icons to menuitems of the main menubar
|
|
|
|
BM_MENU_INIT_ITEM bm_list[]
|
|
|
|
{
|
|
|
|
// File menu:
|
|
|
|
{ wxID_NEW, simulator_xpm },
|
2021-01-03 17:40:07 +00:00
|
|
|
{ wxID_OPEN, directory_open_xpm },
|
|
|
|
{ wxID_SAVE, save_xpm},
|
2019-04-14 13:31:32 +00:00
|
|
|
{ ID_SAVE_AS_IMAGE, export_xpm},
|
|
|
|
{ ID_SAVE_AS_CSV, export_xpm},
|
|
|
|
{ wxID_CLOSE, exit_xpm},
|
|
|
|
|
|
|
|
// simulator menu:
|
|
|
|
{ ID_MENU_RUN_SIM, sim_run_xpm},
|
|
|
|
{ ID_MENU_ADD_SIGNAL, sim_add_signal_xpm},
|
|
|
|
{ ID_MENU_PROBE_SIGNALS, sim_probe_xpm},
|
|
|
|
{ ID_MENU_TUNE_SIGNALS, sim_tune_xpm},
|
|
|
|
{ ID_MENU_SHOW_NETLIST, netlist_xpm},
|
2021-01-27 18:12:18 +00:00
|
|
|
{ ID_MENU_SET_SIMUL, config_xpm},
|
2019-04-14 13:31:32 +00:00
|
|
|
|
|
|
|
// View menu
|
|
|
|
{ wxID_ZOOM_IN, zoom_in_xpm},
|
|
|
|
{ wxID_ZOOM_OUT, zoom_out_xpm},
|
|
|
|
{ wxID_ZOOM_FIT, zoom_fit_in_page_xpm},
|
|
|
|
{ ID_MENU_SHOW_GRID, grid_xpm},
|
|
|
|
{ ID_MENU_SHOW_LEGEND, text_xpm},
|
2020-02-01 12:05:44 +00:00
|
|
|
{ ID_MENU_DOTTED, add_dashed_line_xpm},
|
|
|
|
{ ID_MENU_WHITE_BG, swap_layer_xpm},
|
2019-04-14 13:31:32 +00:00
|
|
|
|
|
|
|
{ 0, nullptr } // Sentinel
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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 );
|
|
|
|
|
|
|
|
if( !item || !bm_list[ii].m_Bitmap)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
wxMenu* menu = item->GetMenu();
|
|
|
|
// Calculate the initial index of item inside the wxMenu parent
|
|
|
|
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 ) );
|
|
|
|
// 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
|
|
|
|
2020-02-01 12:05:44 +00:00
|
|
|
wxColor SIM_PLOT_FRAME::GetPlotColor( int aColorId )
|
|
|
|
{
|
|
|
|
// return the wxColor selected in color list or BLACK is not in list
|
|
|
|
if( aColorId >= 0 && aColorId < (int)m_colorList.size() )
|
|
|
|
return m_colorList[aColorId];
|
|
|
|
|
|
|
|
return wxColor( 0, 0, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::fillDefaultColorList( bool aWhiteBg )
|
|
|
|
{
|
|
|
|
m_colorList.clear();
|
|
|
|
|
|
|
|
if( aWhiteBg )
|
|
|
|
{
|
|
|
|
m_colorList.emplace_back( 255, 255, 255 ); // Bg color
|
|
|
|
m_colorList.emplace_back( 0, 0, 0 ); // Fg color (texts)
|
|
|
|
m_colorList.emplace_back( 130, 130, 130 ); // Axis color
|
|
|
|
m_colorList.emplace_back( 0, 0, 0 ); // cursors color
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_colorList.emplace_back( 0, 0, 0 ); // Bg color
|
|
|
|
m_colorList.emplace_back( 255, 255, 255 ); // Fg color (texts)
|
|
|
|
m_colorList.emplace_back( 130, 130, 130 ); // Axis color
|
|
|
|
m_colorList.emplace_back( 255, 255, 255 ); // cursors color
|
|
|
|
}
|
|
|
|
|
|
|
|
// Add a list of color for traces, starting at index SIM_TRACE_COLOR
|
|
|
|
m_colorList.emplace_back( 0xE4, 0x1A, 0x1C );
|
|
|
|
m_colorList.emplace_back( 0x37, 0x7E, 0xB8 );
|
|
|
|
m_colorList.emplace_back( 0x4D, 0xAF, 0x4A );
|
|
|
|
m_colorList.emplace_back( 0x98, 0x4E, 0xA3 );
|
|
|
|
m_colorList.emplace_back( 0xFF, 0x7F, 0x00 );
|
|
|
|
m_colorList.emplace_back( 0xFF, 0xFF, 0x33 );
|
|
|
|
m_colorList.emplace_back( 0xA6, 0x56, 0x28 );
|
|
|
|
m_colorList.emplace_back( 0xF7, 0x81, 0xBF );
|
|
|
|
m_colorList.emplace_back( 0x66, 0xC2, 0xA5 );
|
|
|
|
m_colorList.emplace_back( 0xFC, 0x8D, 0x62 );
|
|
|
|
m_colorList.emplace_back( 0x8D, 0xA0, 0xCB );
|
|
|
|
m_colorList.emplace_back( 0xE7, 0x8A, 0xC3 );
|
|
|
|
m_colorList.emplace_back( 0xA6, 0xD8, 0x54 );
|
|
|
|
m_colorList.emplace_back( 0xFF, 0xD9, 0x2F );
|
|
|
|
m_colorList.emplace_back( 0xE5, 0xC4, 0x94 );
|
|
|
|
m_colorList.emplace_back( 0xB3, 0xB3, 0xB3 );
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
void SIM_PLOT_FRAME::StartSimulation( const wxString& aSimCommand )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2016-08-11 12:41:30 +00:00
|
|
|
STRING_FORMATTER formatter;
|
|
|
|
|
2016-08-20 17:51:33 +00:00
|
|
|
if( !m_settingsDlg )
|
|
|
|
m_settingsDlg = new DIALOG_SIM_SETTINGS( this );
|
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
m_simConsole->Clear();
|
2016-08-11 12:41:45 +00:00
|
|
|
updateNetlistExporter();
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( aSimCommand.IsEmpty() )
|
|
|
|
{
|
|
|
|
SIM_PANEL_BASE* plotPanel = currentPlotWindow();
|
2021-01-31 09:36:26 +00:00
|
|
|
|
2021-01-30 00:41:50 +00:00
|
|
|
if( plotPanel && m_plots.count( plotPanel ) != 0 )
|
2020-04-15 01:51:58 +00:00
|
|
|
m_exporter->SetSimCommand( m_plots[plotPanel].m_simCommand );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_exporter->SetSimCommand( aSimCommand );
|
|
|
|
}
|
2016-08-11 12:42:09 +00:00
|
|
|
|
2016-08-20 17:51:33 +00:00
|
|
|
if( !m_exporter->Format( &formatter, m_settingsDlg->GetNetlistOptions() ) )
|
2016-08-11 12:42:09 +00:00
|
|
|
{
|
2016-08-20 15:37:51 +00:00
|
|
|
DisplayError( this, _( "There were errors during netlist export, aborted." ) );
|
2016-08-11 12:42:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
if( m_exporter->GetSimType() == ST_UNKNOWN )
|
|
|
|
{
|
2016-08-20 15:37:51 +00:00
|
|
|
DisplayInfoMessage( this, _( "You need to select the simulation settings first." ) );
|
2016-08-11 12:41:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2016-08-11 12:41:01 +00:00
|
|
|
m_simulator->LoadNetlist( formatter.GetString() );
|
2016-08-11 12:42:09 +00:00
|
|
|
updateTuners();
|
2016-08-11 12:42:07 +00:00
|
|
|
applyTuners();
|
2016-08-11 12:41:19 +00:00
|
|
|
m_simulator->Run();
|
2016-08-11 12:41:07 +00:00
|
|
|
}
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::StopSimulation()
|
|
|
|
{
|
2016-08-19 13:51:19 +00:00
|
|
|
m_simulator->Stop();
|
2016-08-11 12:41:01 +00:00
|
|
|
}
|
2016-08-11 12:41:01 +00:00
|
|
|
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
bool SIM_PLOT_FRAME::IsSimulationRunning()
|
|
|
|
{
|
|
|
|
return m_simulator ? m_simulator->IsRunning() : false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
SIM_PANEL_BASE* SIM_PLOT_FRAME::NewPlotPanel( wxString aSimCommand )
|
2016-08-11 12:41:01 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
SIM_PANEL_BASE* plotPanel;
|
2021-01-25 21:29:13 +00:00
|
|
|
SIM_TYPE simType = NETLIST_EXPORTER_PSPICE_SIM::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;
|
2021-01-25 21:29:13 +00:00
|
|
|
panel = new SIM_PLOT_PANEL( aSimCommand, m_plotNotebook, 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;
|
2021-01-25 21:29:13 +00:00
|
|
|
panel = new SIM_NOPLOT_PANEL( aSimCommand, m_plotNotebook, 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
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
if( m_welcomePanel )
|
|
|
|
{
|
|
|
|
m_plotNotebook->DeletePage( 0 );
|
|
|
|
m_welcomePanel = nullptr;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
m_plotNotebook->AddPage( dynamic_cast<wxWindow*>( plotPanel ), pageTitle, true );
|
2016-08-11 12:42:10 +00:00
|
|
|
m_plots[plotPanel] = PLOT_INFO();
|
|
|
|
|
|
|
|
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 )
|
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
addPlot( aNetName, SPT_VOLTAGE, "V" );
|
|
|
|
}
|
2016-08-11 12:41:42 +00:00
|
|
|
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
void SIM_PLOT_FRAME::AddCurrentPlot( const wxString& aDeviceName, const wxString& aParam )
|
|
|
|
{
|
|
|
|
addPlot( aDeviceName, SPT_CURRENT, aParam );
|
2016-08-11 12:41:18 +00:00
|
|
|
}
|
2016-08-11 12:41:11 +00:00
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
void SIM_PLOT_FRAME::AddTuner( SCH_COMPONENT* aComponent )
|
2016-08-11 12:41:21 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
SIM_PANEL_BASE* plotPanel = currentPlotWindow();
|
2016-08-11 12:41:45 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( !plotPanel || plotPanel == m_welcomePanel )
|
2016-08-11 12:41:45 +00:00
|
|
|
return;
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
// For now limit the tuner tool to RLC components
|
2016-08-11 12:41:51 +00:00
|
|
|
char primitiveType = NETLIST_EXPORTER_PSPICE::GetSpiceField( SF_PRIMITIVE, aComponent, 0 )[0];
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
if( primitiveType != SP_RESISTOR && primitiveType != SP_CAPACITOR && primitiveType != SP_INDUCTOR )
|
|
|
|
return;
|
|
|
|
|
2020-11-12 21:31:41 +00:00
|
|
|
const wxString componentName = aComponent->GetField( REFERENCE_FIELD )->GetText();
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
// Do not add multiple instances for the same component
|
2016-08-11 12:42:07 +00:00
|
|
|
auto tunerIt = std::find_if( m_tuners.begin(), m_tuners.end(), [&]( const TUNER_SLIDER* t )
|
2016-08-11 12:41:45 +00:00
|
|
|
{
|
|
|
|
return t->GetComponentName() == componentName;
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
if( tunerIt != m_tuners.end() )
|
2016-08-11 12:41:45 +00:00
|
|
|
return; // We already have it
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2016-12-02 07:58:01 +00:00
|
|
|
TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_tunePanel, aComponent );
|
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
|
|
|
{
|
|
|
|
// Sorry, no bonus
|
2018-06-05 11:26:37 +00:00
|
|
|
DisplayError( nullptr, e.What() );
|
2016-08-11 12:41:45 +00:00
|
|
|
}
|
2016-08-11 12:41:21 +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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SIM_PLOT_PANEL* SIM_PLOT_FRAME::CurrentPlot() const
|
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
SIM_PANEL_BASE* curPage = currentPlotWindow();
|
2016-08-11 12:42:12 +00:00
|
|
|
|
2020-04-15 01:51:58 +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
|
|
|
|
|
|
|
|
2018-04-27 22:34:06 +00:00
|
|
|
const NETLIST_EXPORTER_PSPICE_SIM* SIM_PLOT_FRAME::GetExporter() const
|
|
|
|
{
|
|
|
|
return m_exporter.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
void SIM_PLOT_FRAME::addPlot( const wxString& aName, SIM_PLOT_TYPE aType, const wxString& aParam )
|
|
|
|
{
|
|
|
|
SIM_TYPE simType = m_exporter->GetSimType();
|
|
|
|
|
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
|
|
|
|
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
if( !plotPanel || plotPanel->GetType() != simType )
|
2021-01-25 21:29:13 +00:00
|
|
|
plotPanel =
|
|
|
|
dynamic_cast<SIM_PLOT_PANEL*>( NewPlotPanel( m_exporter->GetUsedSimCommand() ) );
|
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
|
|
|
TRACE_DESC descriptor( *m_exporter, aName, aType, aParam );
|
|
|
|
|
|
|
|
bool updated = false;
|
2016-08-11 12:41:52 +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
|
|
|
{
|
2016-08-11 12:42:12 +00:00
|
|
|
int baseType = descriptor.GetType() & ~( SPT_AC_MAG | SPT_AC_PHASE );
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
// Add two plots: magnitude & phase
|
2016-08-11 12:42:12 +00:00
|
|
|
TRACE_DESC mag_desc( *m_exporter, descriptor, (SIM_PLOT_TYPE)( baseType | SPT_AC_MAG ) );
|
|
|
|
TRACE_DESC phase_desc( *m_exporter, descriptor, (SIM_PLOT_TYPE)( baseType | SPT_AC_PHASE ) );
|
2016-08-11 12:41:52 +00:00
|
|
|
|
|
|
|
updated |= updatePlot( mag_desc, plotPanel );
|
|
|
|
updated |= updatePlot( phase_desc, plotPanel );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
updated = updatePlot( descriptor, plotPanel );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( updated )
|
|
|
|
{
|
|
|
|
updateSignalList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
|
2016-08-11 12:42:09 +00:00
|
|
|
void SIM_PLOT_FRAME::removePlot( const wxString& aPlotName, bool aErase )
|
2016-08-11 12:41:56 +00:00
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
|
|
|
|
|
2016-08-12 13:36:43 +00:00
|
|
|
if( !plotPanel )
|
|
|
|
return;
|
|
|
|
|
2016-08-11 12:42:09 +00:00
|
|
|
if( aErase )
|
|
|
|
{
|
|
|
|
auto& traceMap = m_plots[plotPanel].m_traces;
|
|
|
|
auto traceIt = traceMap.find( aPlotName );
|
|
|
|
wxASSERT( traceIt != traceMap.end() );
|
|
|
|
traceMap.erase( traceIt );
|
|
|
|
}
|
2016-08-11 12:41:56 +00:00
|
|
|
|
2017-03-19 13:17:33 +00:00
|
|
|
wxASSERT( plotPanel->TraceShown( aPlotName ) );
|
2016-08-11 12:41:56 +00:00
|
|
|
plotPanel->DeleteTrace( 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:30 +00:00
|
|
|
void SIM_PLOT_FRAME::updateNetlistExporter()
|
|
|
|
{
|
2020-05-21 03:40:31 +00:00
|
|
|
m_exporter.reset( new NETLIST_EXPORTER_PSPICE_SIM( &m_schematicFrame->Schematic() ) );
|
2021-01-26 21:34:27 +00:00
|
|
|
if( m_settingsDlg )
|
|
|
|
m_settingsDlg->SetNetlistExporter( m_exporter.get() );
|
2016-08-11 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
bool SIM_PLOT_FRAME::updatePlot( const TRACE_DESC& aDescriptor, SIM_PLOT_PANEL* aPanel )
|
2016-08-11 12:41:18 +00:00
|
|
|
{
|
2016-08-11 12:41:35 +00:00
|
|
|
SIM_TYPE simType = m_exporter->GetSimType();
|
2020-04-15 01:51:58 +00:00
|
|
|
wxString spiceVector = m_exporter->ComponentToVector(
|
|
|
|
aDescriptor.GetName(), aDescriptor.GetType(), aDescriptor.GetParam() );
|
2016-08-11 12:41:11 +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
|
2016-08-11 12:41:52 +00:00
|
|
|
m_simulator->Command( wxString::Format( "print %s", spiceVector ).ToStdString() );
|
|
|
|
|
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
|
|
|
|
|
|
|
auto data_x = m_simulator->GetMagPlot( (const char*) xAxisName.c_str() );
|
2016-08-11 12:41:52 +00:00
|
|
|
unsigned int size = data_x.size();
|
2016-08-11 12:41:35 +00:00
|
|
|
|
|
|
|
if( data_x.empty() )
|
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
|
|
|
SIM_PLOT_TYPE plotType = aDescriptor.GetType();
|
|
|
|
std::vector<double> data_y;
|
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
// Now, Y axis data
|
|
|
|
switch( m_exporter->GetSimType() )
|
|
|
|
{
|
|
|
|
case ST_AC:
|
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
wxASSERT_MSG( !( ( plotType & SPT_AC_MAG ) && ( plotType & SPT_AC_PHASE ) ),
|
|
|
|
"Cannot set both AC_PHASE and AC_MAG bits" );
|
|
|
|
|
|
|
|
if( plotType & SPT_AC_MAG )
|
|
|
|
data_y = m_simulator->GetMagPlot( (const char*) spiceVector.c_str() );
|
|
|
|
else if( plotType & SPT_AC_PHASE )
|
|
|
|
data_y = m_simulator->GetPhasePlot( (const char*) spiceVector.c_str() );
|
|
|
|
else
|
|
|
|
wxASSERT_MSG( false, "Plot type missing AC_PHASE or AC_MAG bit" );
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_NOISE:
|
|
|
|
case ST_DC:
|
|
|
|
case ST_TRANSIENT:
|
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
data_y = m_simulator->GetMagPlot( (const char*) spiceVector.c_str() );
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
|
|
|
break;
|
2016-08-11 12:41:18 +00:00
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
default:
|
2016-08-11 12:41:41 +00:00
|
|
|
wxASSERT_MSG( false, "Unhandled plot type" );
|
|
|
|
return false;
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
2016-08-11 12:41:41 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
if( data_y.size() != size )
|
|
|
|
return false;
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
if( m_exporter->GetSimType() == ST_DC &&
|
|
|
|
m_exporter->ParseDCCommand( m_exporter->GetUsedSimCommand(), &source1, &source2 ) )
|
|
|
|
{
|
|
|
|
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++ )
|
|
|
|
{
|
|
|
|
name = wxString::Format( "%s (%s = %s V)", aDescriptor.GetTitle(),
|
|
|
|
source2.m_source, v.ToString() );
|
|
|
|
|
|
|
|
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 );
|
|
|
|
|
|
|
|
if( aPanel->AddTrace( name, inner,
|
|
|
|
sub_x.data(), sub_y.data(), aDescriptor.GetType() ) )
|
|
|
|
{
|
|
|
|
m_plots[aPanel].m_traces.insert( std::make_pair( name, aDescriptor ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
v = v + source2.m_vincrement;
|
|
|
|
offset += inner;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
if( aPanel->AddTrace( aDescriptor.GetTitle(), size,
|
|
|
|
data_x.data(), data_y.data(), aDescriptor.GetType() ) )
|
|
|
|
{
|
|
|
|
m_plots[aPanel].m_traces.insert( std::make_pair( aDescriptor.GetTitle(), aDescriptor ) );
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
if( m_signalsIconColorList == NULL )
|
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();
|
|
|
|
|
|
|
|
for( const auto& trace : CurrentPlot()->GetTraces() )
|
|
|
|
{
|
2016-08-30 12:25:10 +00:00
|
|
|
wxBitmap bitmap( isize, isize );
|
2016-08-29 09:39:54 +00:00
|
|
|
bmDC.SelectObject( bitmap );
|
2017-02-20 16:57:41 +00:00
|
|
|
wxColour tcolor = trace.second->GetTraceColour();
|
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
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
for( const auto& trace : m_plots[plotPanel].m_traces )
|
2016-08-29 09:39:54 +00:00
|
|
|
{
|
|
|
|
m_signals->InsertItem( imgidx, trace.first, imgidx );
|
|
|
|
imgidx++;
|
|
|
|
}
|
2016-08-11 12:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:09 +00:00
|
|
|
void SIM_PLOT_FRAME::updateTuners()
|
|
|
|
{
|
|
|
|
const auto& spiceItems = m_exporter->GetSpiceItems();
|
|
|
|
|
|
|
|
for( auto it = m_tuners.begin(); it != m_tuners.end(); /* iteration inside the loop */ )
|
|
|
|
{
|
|
|
|
const wxString& ref = (*it)->GetComponentName();
|
|
|
|
|
|
|
|
if( std::find_if( spiceItems.begin(), spiceItems.end(), [&]( const SPICE_ITEM& item )
|
|
|
|
{
|
|
|
|
return item.m_refName == ref;
|
|
|
|
}) == spiceItems.end() )
|
|
|
|
{
|
|
|
|
// The component does not exist anymore, remove the associated tuner
|
|
|
|
TUNER_SLIDER* tuner = *it;
|
|
|
|
it = m_tuners.erase( it );
|
|
|
|
RemoveTuner( tuner, false );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
void SIM_PLOT_FRAME::applyTuners()
|
2016-08-11 12:41:56 +00:00
|
|
|
{
|
2016-08-11 12:42:07 +00:00
|
|
|
for( auto& tuner : m_tuners )
|
|
|
|
{
|
|
|
|
/// @todo no ngspice hardcoding
|
2016-08-31 09:51:17 +00:00
|
|
|
std::string command( "alter @" + tuner->GetSpiceName()
|
2016-08-11 12:42:07 +00:00
|
|
|
+ "=" + tuner->GetValue().ToSpiceString() );
|
2016-08-19 13:51:19 +00:00
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
m_simulator->Command( command );
|
|
|
|
}
|
2016-08-11 12:41:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
bool SIM_PLOT_FRAME::loadWorkbook( const wxString& aPath )
|
|
|
|
{
|
|
|
|
m_plots.clear();
|
|
|
|
m_plotNotebook->DeleteAllPages();
|
|
|
|
|
|
|
|
wxTextFile file( aPath );
|
|
|
|
|
|
|
|
if( !file.Open() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
long plotsCount;
|
|
|
|
|
|
|
|
if( !file.GetFirstLine().ToLong( &plotsCount ) ) // GetFirstLine instead of GetNextLine
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( long i = 0; i < plotsCount; ++i )
|
|
|
|
{
|
|
|
|
long plotType, tracesCount;
|
|
|
|
|
|
|
|
if( !file.GetNextLine().ToLong( &plotType ) )
|
|
|
|
return false;
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
wxString simCommand = file.GetNextLine();
|
|
|
|
SIM_PANEL_BASE* plotPanel = NewPlotPanel( simCommand );
|
|
|
|
m_plots[plotPanel].m_simCommand = simCommand;
|
2020-04-15 01:51:58 +00:00
|
|
|
StartSimulation( m_plots[plotPanel].m_simCommand );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
// Perform simulation, so plots can be added with values
|
|
|
|
do
|
|
|
|
{
|
|
|
|
wxThread::This()->Sleep( 50 );
|
|
|
|
}
|
|
|
|
while( IsSimulationRunning() );
|
|
|
|
|
|
|
|
if( !file.GetNextLine().ToLong( &tracesCount ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
for( long j = 0; j < tracesCount; ++j )
|
|
|
|
{
|
|
|
|
long traceType;
|
|
|
|
wxString name, param;
|
|
|
|
|
|
|
|
if( !file.GetNextLine().ToLong( &traceType ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
name = file.GetNextLine();
|
|
|
|
param = file.GetNextLine();
|
|
|
|
|
|
|
|
if( name.IsEmpty() || param.IsEmpty() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
addPlot( name, (SIM_PLOT_TYPE) traceType, param );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool SIM_PLOT_FRAME::saveWorkbook( const wxString& aPath )
|
|
|
|
{
|
2018-01-04 19:28:54 +00:00
|
|
|
wxString savePath = aPath;
|
2018-01-30 10:49:51 +00:00
|
|
|
|
2020-11-24 22:16:41 +00:00
|
|
|
if( !savePath.Lower().EndsWith(".wbk") )
|
2018-01-04 19:28:54 +00:00
|
|
|
savePath += ".wbk";
|
2018-01-30 10:49:51 +00:00
|
|
|
|
2018-01-04 19:28:54 +00:00
|
|
|
wxTextFile file( savePath );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
if( file.Exists() )
|
|
|
|
{
|
|
|
|
if( !file.Open() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
file.Clear();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
file.Create();
|
|
|
|
}
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
file.AddLine( wxString::Format( "%llu", m_plots.size() ) );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
for( const auto& plot : m_plots )
|
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
if( plot.first )
|
2016-08-11 12:42:12 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
file.AddLine( wxString::Format( "%d", plot.first->GetType() ) );
|
|
|
|
file.AddLine( plot.second.m_simCommand );
|
|
|
|
file.AddLine( wxString::Format( "%llu", plot.second.m_traces.size() ) );
|
|
|
|
|
|
|
|
for( const auto& trace : plot.second.m_traces )
|
|
|
|
{
|
|
|
|
file.AddLine( wxString::Format( "%d", trace.second.GetType() ) );
|
|
|
|
file.AddLine( trace.second.GetName() );
|
|
|
|
file.AddLine( trace.second.GetParam() );
|
|
|
|
}
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool res = file.Write();
|
|
|
|
file.Close();
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:52 +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 )
|
|
|
|
{
|
|
|
|
case ST_AC:
|
2016-08-11 12:41:52 +00:00
|
|
|
return SPT_LIN_FREQUENCY;
|
|
|
|
/// @todo SPT_LOG_FREQUENCY
|
2016-08-11 12:41:52 +00:00
|
|
|
|
|
|
|
case ST_DC:
|
|
|
|
return SPT_SWEEP;
|
2016-08-11 12:41:18 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
case ST_TRANSIENT:
|
|
|
|
return SPT_TIME;
|
2016-08-11 12:41:16 +00:00
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
default:
|
|
|
|
wxASSERT_MSG( false, "Unhandled simulation type" );
|
|
|
|
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 )
|
|
|
|
{
|
2016-08-11 12:41:42 +00:00
|
|
|
SIM_TYPE type = m_exporter->GetSimType();
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( SIM_PANEL_BASE::IsPlottable( type ) )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* prevPlot = CurrentPlot();
|
2021-01-25 21:29:13 +00:00
|
|
|
SIM_PLOT_PANEL* newPlot =
|
|
|
|
dynamic_cast<SIM_PLOT_PANEL*>( NewPlotPanel( m_exporter->GetUsedSimCommand() ) );
|
2016-08-11 12:42:10 +00:00
|
|
|
|
|
|
|
// If the previous plot had the same type, copy the simulation command
|
|
|
|
if( prevPlot )
|
|
|
|
m_plots[newPlot].m_simCommand = m_plots[prevPlot].m_simCommand;
|
|
|
|
}
|
2016-08-11 12:41:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
void SIM_PLOT_FRAME::menuOpenWorkbook( wxCommandEvent& event )
|
|
|
|
{
|
2016-09-17 07:34:16 +00:00
|
|
|
wxFileDialog openDlg( this, _( "Open simulation workbook" ), m_savedWorkbooksPath, "",
|
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;
|
|
|
|
|
2016-09-17 07:34:16 +00:00
|
|
|
m_savedWorkbooksPath = openDlg.GetDirectory();
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
if( !loadWorkbook( openDlg.GetPath() ) )
|
2016-09-17 07:34:16 +00:00
|
|
|
DisplayError( this, _( "There was an error while opening the workbook file" ) );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuSaveWorkbook( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-12 13:36:43 +00:00
|
|
|
if( !CurrentPlot() )
|
|
|
|
return;
|
|
|
|
|
2017-11-12 00:31:38 +00:00
|
|
|
wxFileDialog saveDlg( this, _( "Save Simulation Workbook" ), m_savedWorkbooksPath, "",
|
|
|
|
WorkbookFileWildcard(), wxFD_SAVE | wxFD_OVERWRITE_PROMPT );
|
2016-08-11 12:42:12 +00:00
|
|
|
|
|
|
|
if( saveDlg.ShowModal() == wxID_CANCEL )
|
|
|
|
return;
|
|
|
|
|
2016-09-17 07:34:16 +00:00
|
|
|
m_savedWorkbooksPath = saveDlg.GetDirectory();
|
|
|
|
|
2016-08-11 12:42:12 +00:00
|
|
|
if( !saveWorkbook( saveDlg.GetPath() ) )
|
2016-08-20 15:37:51 +00:00
|
|
|
DisplayError( this, _( "There was an error while saving the workbook file" ) );
|
2016-08-11 12:42:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:28 +00:00
|
|
|
void SIM_PLOT_FRAME::menuSaveImage( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-12 13:36:43 +00:00
|
|
|
if( !CurrentPlot() )
|
|
|
|
return;
|
|
|
|
|
2017-11-12 00:31:38 +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;
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
CurrentPlot()->GetPlotWin()->SaveScreenshot( saveDlg.GetPath(), wxBITMAP_TYPE_PNG );
|
2016-08-11 12:41:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuSaveCsv( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-12 13:36:43 +00:00
|
|
|
if( !CurrentPlot() )
|
|
|
|
return;
|
|
|
|
|
2016-08-11 12:41:28 +00:00
|
|
|
const wxChar SEPARATOR = ';';
|
|
|
|
|
2017-11-12 00:31:38 +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
|
|
|
bool timeWritten = false;
|
|
|
|
|
|
|
|
for( const auto& t : CurrentPlot()->GetTraces() )
|
|
|
|
{
|
|
|
|
const TRACE* trace = t.second;
|
|
|
|
|
|
|
|
if( !timeWritten )
|
|
|
|
{
|
|
|
|
out.Write( wxString::Format( "Time%c", SEPARATOR ) );
|
|
|
|
|
|
|
|
for( double v : trace->GetDataX() )
|
2020-11-30 21:24:32 +00:00
|
|
|
out.Write( wxString::Format( "%g%c", v, SEPARATOR ) );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
|
|
|
out.Write( "\r\n" );
|
|
|
|
timeWritten = true;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
out.Write( wxString::Format( "%s%c", t.first, SEPARATOR ) );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
|
|
|
for( double v : trace->GetDataY() )
|
2020-11-30 21:24:32 +00:00
|
|
|
out.Write( wxString::Format( "%g%c", v, SEPARATOR ) );
|
2016-08-11 12:41:28 +00:00
|
|
|
|
|
|
|
out.Write( "\r\n" );
|
|
|
|
}
|
|
|
|
|
|
|
|
out.Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:22 +00:00
|
|
|
void SIM_PLOT_FRAME::menuZoomIn( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-12 13:36:43 +00:00
|
|
|
if( CurrentPlot() )
|
2020-04-15 01:51:58 +00:00
|
|
|
CurrentPlot()->GetPlotWin()->ZoomIn();
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuZoomOut( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-12 13:36:43 +00:00
|
|
|
if( CurrentPlot() )
|
2020-04-15 01:51:58 +00:00
|
|
|
CurrentPlot()->GetPlotWin()->ZoomOut();
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuZoomFit( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-12 13:36:43 +00:00
|
|
|
if( CurrentPlot() )
|
2020-04-15 01:51:58 +00:00
|
|
|
CurrentPlot()->GetPlotWin()->Fit();
|
2016-08-11 12:41:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuShowGrid( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
SIM_PLOT_PANEL* plot = CurrentPlot();
|
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
|
|
|
{
|
2016-08-11 12:41:27 +00:00
|
|
|
SIM_PLOT_PANEL* plot = CurrentPlot();
|
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 )
|
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plot = CurrentPlot();
|
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 )
|
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plot = CurrentPlot();
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plot = CurrentPlot();
|
|
|
|
|
|
|
|
if( plot )
|
|
|
|
plot->SetDottedCurrentPhase( !plot->GetDottedCurrentPhase() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::menuShowDottedUpdate( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plot = CurrentPlot();
|
|
|
|
|
|
|
|
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
|
|
|
|
fillDefaultColorList( GetPlotBgOpt() );
|
|
|
|
|
|
|
|
// Now send changes to all SIM_PLOT_PANEL
|
|
|
|
for( size_t page = 0; page < m_plotNotebook->GetPageCount(); page++ )
|
|
|
|
{
|
|
|
|
wxWindow* curPage = m_plotNotebook->GetPage( page );
|
|
|
|
|
|
|
|
if( curPage == m_welcomePanel )
|
|
|
|
continue;
|
|
|
|
|
2020-12-29 03:38:02 +00:00
|
|
|
// ensure it is truely a plot panel and not the (zero plots) placeholder
|
|
|
|
// 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 );
|
|
|
|
|
|
|
|
if( panel != nullptr )
|
|
|
|
{
|
|
|
|
panel->UpdatePlotColors();
|
|
|
|
}
|
2020-02-01 12:05:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
void SIM_PLOT_FRAME::onPlotClose( wxAuiNotebookEvent& event )
|
|
|
|
{
|
|
|
|
int idx = event.GetSelection();
|
|
|
|
|
|
|
|
if( idx == wxNOT_FOUND )
|
|
|
|
return;
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
SIM_PANEL_BASE* plotPanel =
|
|
|
|
dynamic_cast<SIM_PANEL_BASE*>( m_plotNotebook->GetPage( idx ) );
|
2016-08-11 12:42:07 +00:00
|
|
|
|
|
|
|
m_plots.erase( plotPanel );
|
|
|
|
updateSignalList();
|
2020-04-15 01:51:58 +00:00
|
|
|
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 );
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-29 09:39:54 +00:00
|
|
|
void SIM_PLOT_FRAME::onSignalRClick( wxListEvent& event )
|
2016-08-11 12:41:25 +00:00
|
|
|
{
|
2016-08-29 09:39:54 +00:00
|
|
|
int idx = event.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 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:16 +00:00
|
|
|
void SIM_PLOT_FRAME::onSimulate( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-11 12:41:45 +00:00
|
|
|
if( IsSimulationRunning() )
|
2016-08-11 12:41:16 +00:00
|
|
|
StopSimulation();
|
|
|
|
else
|
|
|
|
StartSimulation();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
void SIM_PLOT_FRAME::onSettings( wxCommandEvent& event )
|
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
SIM_PANEL_BASE* plotPanelWindow = currentPlotWindow();
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2021-01-26 21:34:27 +00:00
|
|
|
if( !m_settingsDlg )
|
|
|
|
m_settingsDlg = new DIALOG_SIM_SETTINGS( this );
|
|
|
|
|
2016-08-11 12:42:09 +00:00
|
|
|
// Initial processing is required to e.g. display a list of power sources
|
2016-08-11 12:41:30 +00:00
|
|
|
updateNetlistExporter();
|
2016-08-11 12:42:09 +00:00
|
|
|
|
|
|
|
if( !m_exporter->ProcessNetlist( NET_ALL_FLAGS ) )
|
|
|
|
{
|
2016-08-20 15:37:51 +00:00
|
|
|
DisplayError( this, _( "There were errors during netlist export, aborted." ) );
|
2016-08-11 12:42:09 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( plotPanelWindow != m_welcomePanel )
|
|
|
|
m_settingsDlg->SetSimCommand( m_plots[plotPanelWindow].m_simCommand );
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2016-08-20 17:51:33 +00:00
|
|
|
if( m_settingsDlg->ShowModal() == wxID_OK )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2021-01-25 21:29:13 +00:00
|
|
|
wxString oldCommand = m_plots[plotPanelWindow].m_simCommand;
|
2016-08-20 17:51:33 +00:00
|
|
|
wxString newCommand = m_settingsDlg->GetSimCommand();
|
2016-08-11 12:42:10 +00:00
|
|
|
SIM_TYPE newSimType = NETLIST_EXPORTER_PSPICE_SIM::CommandToSimType( newCommand );
|
|
|
|
|
|
|
|
// If it is a new simulation type, open a new plot
|
2021-01-25 21:29:13 +00:00
|
|
|
// For the DC sim, check if sweep source type has changed (char 4 will contain 'v', 'i', 'r' or 't'
|
2021-01-31 09:36:26 +00:00
|
|
|
if( !plotPanelWindow
|
2021-01-25 21:29:13 +00:00
|
|
|
|| ( plotPanelWindow && plotPanelWindow->GetType() != newSimType )
|
|
|
|
|| ( newSimType == ST_DC
|
|
|
|
&& oldCommand.Lower().GetChar( 4 ) != newCommand.Lower().GetChar( 4 ) ) )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2021-01-25 21:29:13 +00:00
|
|
|
plotPanelWindow = NewPlotPanel( newCommand );
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
m_plots[plotPanelWindow].m_simCommand = newCommand;
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
void SIM_PLOT_FRAME::onAddSignal( wxCommandEvent& event )
|
|
|
|
{
|
2016-08-11 12:41:52 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
|
|
|
|
|
|
|
|
if( !plotPanel || !m_exporter || plotPanel->GetType() != m_exporter->GetSimType() )
|
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:42 +00:00
|
|
|
DIALOG_SIGNAL_LIST dialog( this, m_exporter.get() );
|
|
|
|
dialog.ShowModal();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::onProbe( wxCommandEvent& event )
|
2016-08-11 12:41:16 +00:00
|
|
|
{
|
|
|
|
if( m_schematicFrame == NULL )
|
|
|
|
return;
|
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
if( m_schematicFrame == NULL )
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2018-03-03 16:36:26 +00:00
|
|
|
void SIM_PLOT_FRAME::onShowNetlist( wxCommandEvent& event )
|
|
|
|
{
|
2021-01-11 09:01:50 +00:00
|
|
|
class NETLIST_VIEW_DIALOG : public DIALOG_SHIM
|
2018-03-03 16:36:26 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MARGIN_LINE_NUMBERS
|
|
|
|
};
|
|
|
|
|
|
|
|
void onClose( wxCloseEvent& evt )
|
|
|
|
{
|
|
|
|
EndModal( GetReturnCode() );
|
|
|
|
}
|
|
|
|
|
2021-01-11 09:01:50 +00:00
|
|
|
NETLIST_VIEW_DIALOG( wxWindow* parent, wxString source) :
|
|
|
|
DIALOG_SHIM( parent, wxID_ANY, "SPICE Netlist",
|
|
|
|
wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER )
|
2018-03-03 16:36:26 +00:00
|
|
|
{
|
2018-03-21 16:20:35 +00:00
|
|
|
wxStyledTextCtrl* text = new wxStyledTextCtrl( this, wxID_ANY );
|
2021-01-11 09:01:50 +00:00
|
|
|
text->SetMinSize( wxSize( 600, 400 ) );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2018-03-21 16:20:35 +00:00
|
|
|
text->SetMarginWidth( MARGIN_LINE_NUMBERS, 50 );
|
|
|
|
text->StyleSetForeground( wxSTC_STYLE_LINENUMBER, wxColour( 75, 75, 75 ) );
|
|
|
|
text->StyleSetBackground( wxSTC_STYLE_LINENUMBER, wxColour( 220, 220, 220 ) );
|
|
|
|
text->SetMarginType( MARGIN_LINE_NUMBERS, wxSTC_MARGIN_NUMBER );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2020-12-03 00:27:10 +00:00
|
|
|
wxFont font = wxFont( wxNORMAL_FONT->GetPointSize(), wxFONTFAMILY_TELETYPE,
|
|
|
|
wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString );
|
|
|
|
text->StyleSetFont( wxSTC_STYLE_DEFAULT, font );
|
|
|
|
|
2018-03-21 16:20:35 +00:00
|
|
|
text->SetWrapMode( wxSTC_WRAP_WORD );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
|
|
|
text->SetText( source );
|
|
|
|
|
|
|
|
text->StyleClearAll();
|
2018-03-21 16:20:35 +00:00
|
|
|
text->SetLexer( wxSTC_LEX_SPICE );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2018-03-21 16:20:35 +00:00
|
|
|
wxBoxSizer* sizer = new wxBoxSizer( wxVERTICAL );
|
|
|
|
sizer->Add( text, 1, wxEXPAND );
|
|
|
|
SetSizer( sizer );
|
2018-03-03 16:36:26 +00:00
|
|
|
|
2018-03-21 16:20:35 +00:00
|
|
|
Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( NETLIST_VIEW_DIALOG::onClose ), NULL,
|
|
|
|
this );
|
2021-01-11 09:01:50 +00:00
|
|
|
|
|
|
|
finishDialogSettings();
|
2018-03-03 16:36:26 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if( m_schematicFrame == NULL || m_simulator == NULL )
|
|
|
|
return;
|
|
|
|
|
|
|
|
NETLIST_VIEW_DIALOG dlg( this, m_simulator->GetNetlist() );
|
|
|
|
dlg.ShowModal();
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:16 +00:00
|
|
|
|
2020-08-24 02:01:14 +00:00
|
|
|
void SIM_PLOT_FRAME::doCloseWindow()
|
2016-08-11 12:41:07 +00:00
|
|
|
{
|
2016-12-02 14:34:23 +00:00
|
|
|
SaveSettings( config() );
|
|
|
|
|
2016-08-11 12:41:45 +00:00
|
|
|
if( IsSimulationRunning() )
|
2016-08-11 12:41:19 +00:00
|
|
|
m_simulator->Stop();
|
2016-08-11 12:41:07 +00:00
|
|
|
|
2019-08-04 20:46:09 +00:00
|
|
|
// Cancel a running simProbe or simTune tool
|
|
|
|
m_schematicFrame->GetToolManager()->RunAction( ACTIONS::cancelInteractive );
|
|
|
|
|
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();
|
2016-08-11 12:42:07 +00:00
|
|
|
SIM_PLOT_PANEL* plotPanel = CurrentPlot();
|
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 );
|
2016-08-11 12:42:07 +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() )
|
|
|
|
labelY = labelY1 + " / " + labelY2;
|
|
|
|
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
|
|
|
|
2016-08-11 12:42:07 +00:00
|
|
|
for( const auto& trace : plotPanel->GetTraces() )
|
2016-08-11 12:41:27 +00:00
|
|
|
{
|
|
|
|
if( CURSOR* cursor = trace.second->GetCursor() )
|
|
|
|
{
|
2016-08-29 09:39:54 +00:00
|
|
|
// Find the right icon color in list.
|
|
|
|
// It is the icon used in m_signals list for the same trace
|
|
|
|
long iconColor = m_signals->FindItem( -1, trace.first );
|
|
|
|
|
2016-08-11 12:41:27 +00:00
|
|
|
const wxRealPoint coords = cursor->GetCoords();
|
2016-08-29 09:39:54 +00:00
|
|
|
long idx = m_cursors->InsertItem( itemidx++, trace.first, 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
|
|
|
{
|
2016-08-11 12:42:06 +00:00
|
|
|
m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( sim_stop_xpm ) );
|
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
|
|
|
{
|
2016-08-11 12:42:06 +00:00
|
|
|
m_toolBar->SetToolNormalBitmap( ID_SIM_RUN, KiBitmap( sim_run_xpm ) );
|
2016-08-11 12:41:19 +00:00
|
|
|
SetCursor( wxCURSOR_ARROW );
|
2016-08-11 12:41:10 +00:00
|
|
|
|
2016-08-11 12:41:35 +00:00
|
|
|
SIM_TYPE simType = m_exporter->GetSimType();
|
2016-08-11 12:41:45 +00:00
|
|
|
|
|
|
|
if( simType == ST_UNKNOWN )
|
|
|
|
return;
|
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
SIM_PANEL_BASE* plotPanelWindow = currentPlotWindow();
|
2016-08-11 12:41:39 +00:00
|
|
|
|
2020-04-15 01:51:58 +00:00
|
|
|
if( !plotPanelWindow || plotPanelWindow->GetType() != simType )
|
2021-01-25 21:29:13 +00:00
|
|
|
plotPanelWindow = NewPlotPanel( m_exporter->GetUsedSimCommand() );
|
2016-08-11 12:41:39 +00:00
|
|
|
|
2016-08-11 12:42:19 +00:00
|
|
|
if( IsSimulationRunning() )
|
|
|
|
return;
|
|
|
|
|
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
|
|
|
TRACE_MAP& traceMap = m_plots[plotPanelWindow].m_traces;
|
|
|
|
SIM_PLOT_PANEL* plotPanel = dynamic_cast<SIM_PLOT_PANEL*>( plotPanelWindow );
|
2016-08-11 12:41:35 +00:00
|
|
|
|
2020-04-21 10:47:48 +00:00
|
|
|
wxCHECK_RET( plotPanel, "not a SIM_PLOT_PANEL" );
|
|
|
|
|
2016-08-11 12:42:09 +00:00
|
|
|
for( auto it = traceMap.begin(); it != traceMap.end(); /* iteration occurs in the loop */)
|
|
|
|
{
|
|
|
|
if( !updatePlot( it->second, plotPanel ) )
|
|
|
|
{
|
|
|
|
removePlot( it->first, false );
|
|
|
|
it = traceMap.erase( it ); // remove a plot that does not exist anymore
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
for( const auto& vec : m_simulator->AllPlots() )
|
2016-08-11 12:41:35 +00:00
|
|
|
{
|
2020-04-15 01:51:58 +00:00
|
|
|
double val = m_simulator->GetRealPlot( vec, 1 ).at( 0 );
|
|
|
|
|
|
|
|
wxString outLine, signal;
|
|
|
|
SIM_PLOT_TYPE type = m_exporter->VectorToSignal( vec, signal );
|
|
|
|
|
|
|
|
const size_t tab = 25; //characters
|
|
|
|
size_t padding = ( signal.length() < tab ) ? ( tab - signal.length() ) : 1;
|
|
|
|
|
|
|
|
outLine.Printf( wxT( "%s%s" ), ( signal + wxT( ":" ) ).Pad( padding, wxUniChar( ' ' ) ),
|
|
|
|
SPICE_VALUE( val ).ToSpiceString() );
|
|
|
|
|
|
|
|
outLine.Append( type == SPT_CURRENT ? "A\n" : "V\n" );
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
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 )
|
|
|
|
{
|
|
|
|
if( IsSimulationRunning() )
|
|
|
|
StopSimulation();
|
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
if( CurrentPlot() != m_lastSimPlot )
|
|
|
|
{
|
|
|
|
// We need to rerun simulation, as the simulator currently stores
|
|
|
|
// results for another plot
|
|
|
|
StartSimulation();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Incremental update
|
|
|
|
m_simConsole->Clear();
|
|
|
|
// Do not export netlist, it is already stored in the simulator
|
|
|
|
applyTuners();
|
|
|
|
m_simulator->Run();
|
|
|
|
}
|
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,
|
|
|
|
SIM_PLOT_FRAME* aPlotFrame )
|
|
|
|
: m_signal( aSignal ), m_plotFrame( aPlotFrame )
|
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plot = m_plotFrame->CurrentPlot();
|
|
|
|
|
2018-02-09 16:28:33 +00:00
|
|
|
AddMenuItem( this, HIDE_SIGNAL, _( "Hide Signal" ),
|
2016-08-29 09:39:54 +00:00
|
|
|
_( "Erase the signal from plot screen" ),
|
2021-01-02 20:48:43 +00:00
|
|
|
KiBitmap( trash_xpm ) );
|
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
|
|
|
|
2016-08-11 12:41:52 +00:00
|
|
|
if( trace->HasCursor() )
|
2018-05-14 17:34:18 +00:00
|
|
|
AddMenuItem( this, HIDE_CURSOR, _( "Hide Cursor" ), KiBitmap( pcb_target_xpm ) );
|
2016-08-11 12:41:25 +00:00
|
|
|
else
|
2018-05-14 17:34:18 +00:00
|
|
|
AddMenuItem( this, SHOW_CURSOR, _( "Show Cursor" ), KiBitmap( pcb_target_xpm ) );
|
2016-08-11 12:41:25 +00:00
|
|
|
|
|
|
|
Connect( wxEVT_COMMAND_MENU_SELECTED, wxMenuEventHandler( SIGNAL_CONTEXT_MENU::onMenuEvent ), NULL, this );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIM_PLOT_FRAME::SIGNAL_CONTEXT_MENU::onMenuEvent( wxMenuEvent& aEvent )
|
|
|
|
{
|
|
|
|
SIM_PLOT_PANEL* plot = m_plotFrame->CurrentPlot();
|
|
|
|
|
|
|
|
switch( aEvent.GetId() )
|
|
|
|
{
|
|
|
|
case HIDE_SIGNAL:
|
2016-08-11 12:41:56 +00:00
|
|
|
m_plotFrame->removePlot( m_signal );
|
2016-08-11 12:41:25 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SHOW_CURSOR:
|
|
|
|
plot->EnableCursor( m_signal, true );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case HIDE_CURSOR:
|
|
|
|
plot->EnableCursor( m_signal, false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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 );
|