2023-06-15 12:39:04 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016-2023 CERN
|
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
|
|
|
* @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
|
|
|
|
* as published by the Free Software Foundation; either version 3
|
|
|
|
* 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:
|
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <fmt/format.h>
|
|
|
|
#include <wx/wfstream.h>
|
|
|
|
#include <wx/stdstream.h>
|
2023-06-15 12:39:04 +00:00
|
|
|
#include <wx/debug.h>
|
|
|
|
|
|
|
|
#include <project/project_file.h>
|
|
|
|
#include <sch_edit_frame.h>
|
|
|
|
#include <confirm.h>
|
|
|
|
#include <wildcards_and_files_ext.h>
|
|
|
|
#include <widgets/tuner_slider.h>
|
|
|
|
#include <widgets/grid_color_swatch_helpers.h>
|
|
|
|
#include <widgets/wx_grid.h>
|
|
|
|
#include <grid_tricks.h>
|
|
|
|
#include <eda_pattern_match.h>
|
|
|
|
#include <string_utils.h>
|
|
|
|
#include <pgm_base.h>
|
2023-07-14 09:21:58 +00:00
|
|
|
#include <sim/simulator_frame_ui.h>
|
2023-06-15 12:39:04 +00:00
|
|
|
#include <sim/simulator_frame.h>
|
2023-07-09 22:00:25 +00:00
|
|
|
#include <sim/sim_plot_tab.h>
|
2023-06-15 12:39:04 +00:00
|
|
|
#include <sim/spice_simulator.h>
|
2023-07-05 17:25:52 +00:00
|
|
|
#include <dialogs/dialog_text_entry.h>
|
2023-06-15 12:39:04 +00:00
|
|
|
#include <dialogs/dialog_sim_format_value.h>
|
|
|
|
#include <eeschema_settings.h>
|
2023-09-19 16:03:21 +00:00
|
|
|
#include "kiplatform/app.h"
|
2024-03-11 18:14:16 +00:00
|
|
|
#include "wx/clipbrd.h"
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
SIM_TRACE_TYPE operator|( SIM_TRACE_TYPE aFirst, SIM_TRACE_TYPE aSecond )
|
|
|
|
{
|
|
|
|
int res = (int) aFirst | (int) aSecond;
|
|
|
|
|
|
|
|
return (SIM_TRACE_TYPE) res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
enum SIGNALS_GRID_COLUMNS
|
|
|
|
{
|
|
|
|
COL_SIGNAL_NAME = 0,
|
|
|
|
COL_SIGNAL_SHOW,
|
|
|
|
COL_SIGNAL_COLOR,
|
|
|
|
COL_CURSOR_1,
|
|
|
|
COL_CURSOR_2
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum CURSORS_GRID_COLUMNS
|
|
|
|
{
|
|
|
|
COL_CURSOR_NAME = 0,
|
|
|
|
COL_CURSOR_SIGNAL,
|
|
|
|
COL_CURSOR_X,
|
|
|
|
COL_CURSOR_Y
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum MEASUREMENTS_GIRD_COLUMNS
|
|
|
|
{
|
|
|
|
COL_MEASUREMENT = 0,
|
|
|
|
COL_MEASUREMENT_VALUE,
|
|
|
|
COL_MEASUREMENT_FORMAT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
MYID_MEASURE_MIN = GRIDTRICKS_FIRST_CLIENT_ID,
|
|
|
|
MYID_MEASURE_MAX,
|
|
|
|
MYID_MEASURE_AVG,
|
|
|
|
MYID_MEASURE_RMS,
|
|
|
|
MYID_MEASURE_PP,
|
|
|
|
MYID_MEASURE_MIN_AT,
|
|
|
|
MYID_MEASURE_MAX_AT,
|
|
|
|
MYID_MEASURE_INTEGRAL,
|
2023-07-04 15:53:44 +00:00
|
|
|
MYID_FOURIER,
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
MYID_FORMAT_VALUE,
|
|
|
|
MYID_DELETE_MEASUREMENT
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class SIGNALS_GRID_TRICKS : public GRID_TRICKS
|
|
|
|
{
|
|
|
|
public:
|
2023-07-14 09:21:58 +00:00
|
|
|
SIGNALS_GRID_TRICKS( SIMULATOR_FRAME_UI* aParent, WX_GRID* aGrid ) :
|
2023-06-15 12:39:04 +00:00
|
|
|
GRID_TRICKS( aGrid ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_menuRow( 0 ),
|
|
|
|
m_menuCol( 0 )
|
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
|
|
|
|
void doPopupSelection( wxCommandEvent& event ) override;
|
|
|
|
|
|
|
|
protected:
|
2023-07-14 09:21:58 +00:00
|
|
|
SIMULATOR_FRAME_UI* m_parent;
|
|
|
|
int m_menuRow;
|
|
|
|
int m_menuCol;
|
2023-06-15 12:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void SIGNALS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_menuRow = aEvent.GetRow();
|
|
|
|
m_menuCol = aEvent.GetCol();
|
|
|
|
|
|
|
|
if( m_menuCol == COL_SIGNAL_NAME )
|
|
|
|
{
|
|
|
|
if( !( m_grid->IsInSelection( m_menuRow, m_menuCol ) ) )
|
|
|
|
m_grid->ClearSelection();
|
|
|
|
|
|
|
|
m_grid->SetGridCursor( m_menuRow, m_menuCol );
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( SIM_TAB* panel = m_parent->GetCurrentSimTab() )
|
2023-07-04 15:53:44 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
if( panel->GetSimType() == ST_TRAN || panel->GetSimType() == ST_AC
|
|
|
|
|| panel->GetSimType() == ST_DC || panel->GetSimType() == ST_SP )
|
|
|
|
{
|
|
|
|
menu.Append( MYID_MEASURE_MIN, _( "Measure Min" ) );
|
|
|
|
menu.Append( MYID_MEASURE_MAX, _( "Measure Max" ) );
|
|
|
|
menu.Append( MYID_MEASURE_AVG, _( "Measure Average" ) );
|
|
|
|
menu.Append( MYID_MEASURE_RMS, _( "Measure RMS" ) );
|
|
|
|
menu.Append( MYID_MEASURE_PP, _( "Measure Peak-to-peak" ) );
|
2023-08-17 11:22:25 +00:00
|
|
|
|
|
|
|
if( panel->GetSimType() == ST_AC || panel->GetSimType() == ST_SP )
|
|
|
|
{
|
|
|
|
menu.Append( MYID_MEASURE_MIN_AT, _( "Measure Frequency of Min" ) );
|
|
|
|
menu.Append( MYID_MEASURE_MAX_AT, _( "Measure Frequency of Max" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
menu.Append( MYID_MEASURE_MIN_AT, _( "Measure Time of Min" ) );
|
|
|
|
menu.Append( MYID_MEASURE_MAX_AT, _( "Measure Time of Max" ) );
|
|
|
|
}
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
menu.Append( MYID_MEASURE_INTEGRAL, _( "Measure Integral" ) );
|
|
|
|
|
|
|
|
if( panel->GetSimType() == ST_TRAN )
|
|
|
|
{
|
|
|
|
menu.AppendSeparator();
|
|
|
|
menu.Append( MYID_FOURIER, _( "Perform Fourier Analysis..." ) );
|
|
|
|
}
|
2023-07-04 15:53:44 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
menu.AppendSeparator();
|
2024-03-11 18:14:16 +00:00
|
|
|
menu.Append( GRIDTRICKS_ID_COPY, _( "Copy Signal Name" ) + "\tCtrl+C" );
|
|
|
|
|
|
|
|
m_grid->PopupMenu( &menu );
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIGNALS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
std::vector<wxString> signals;
|
|
|
|
|
|
|
|
wxGridCellCoordsArray cells1 = m_grid->GetSelectionBlockTopLeft();
|
|
|
|
wxGridCellCoordsArray cells2 = m_grid->GetSelectionBlockBottomRight();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < cells1.Count(); i++ )
|
|
|
|
{
|
|
|
|
if( cells1[i].GetCol() == COL_SIGNAL_NAME )
|
|
|
|
{
|
|
|
|
for( int j = cells1[i].GetRow(); j < cells2[i].GetRow() + 1; j++ )
|
|
|
|
{
|
|
|
|
signals.push_back( m_grid->GetCellValue( j, cells1[i].GetCol() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxGridCellCoordsArray cells3 = m_grid->GetSelectedCells();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < cells3.Count(); i++ )
|
|
|
|
{
|
|
|
|
if( cells3[i].GetCol() == COL_SIGNAL_NAME )
|
|
|
|
signals.push_back( m_grid->GetCellValue( cells3[i].GetRow(), cells3[i].GetCol() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( signals.size() < 1 )
|
|
|
|
signals.push_back( m_grid->GetCellValue( m_menuRow, m_menuCol ) );
|
|
|
|
|
2023-07-20 20:13:19 +00:00
|
|
|
auto addMeasurement =
|
|
|
|
[this]( const wxString& cmd, wxString signal )
|
|
|
|
{
|
|
|
|
if( signal.EndsWith( _( " (phase)" ) ) )
|
|
|
|
return;
|
2023-08-17 16:41:34 +00:00
|
|
|
|
|
|
|
if( signal.EndsWith( _( " (gain)" ) ) || signal.EndsWith( _( " (amplitude)" ) ) )
|
|
|
|
{
|
2023-07-20 20:13:19 +00:00
|
|
|
signal = signal.Left( signal.length() - 7 );
|
|
|
|
|
2023-08-17 16:41:34 +00:00
|
|
|
if( signal.Upper().StartsWith( wxS( "V(" ) ) )
|
|
|
|
signal = wxS( "vdb" ) + signal.Mid( 1 );
|
|
|
|
}
|
|
|
|
|
2023-07-20 20:13:19 +00:00
|
|
|
m_parent->AddMeasurement( cmd + wxS( " " ) + signal );
|
|
|
|
};
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( event.GetId() == MYID_MEASURE_MIN )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "MIN" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_MEASURE_MAX )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "MAX" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_MEASURE_AVG )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "AVG" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_MEASURE_RMS )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "RMS" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_MEASURE_PP )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "PP" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_MEASURE_MIN_AT )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "MIN_AT" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_MEASURE_MAX_AT )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "MAX_AT" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_MEASURE_INTEGRAL )
|
|
|
|
{
|
|
|
|
for( const wxString& signal : signals )
|
2023-07-20 20:13:19 +00:00
|
|
|
addMeasurement( wxS( "INTEG" ), signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-07-04 15:53:44 +00:00
|
|
|
else if( event.GetId() == MYID_FOURIER )
|
|
|
|
{
|
|
|
|
wxString title;
|
|
|
|
wxString fundamental = wxT( "1K" );
|
|
|
|
|
|
|
|
if( signals.size() == 1 )
|
|
|
|
title.Printf( _( "Fourier Analysis of %s" ), signals[0] );
|
|
|
|
else
|
|
|
|
title = _( "Fourier Analyses of Multiple Signals" );
|
|
|
|
|
|
|
|
WX_TEXT_ENTRY_DIALOG dlg( m_parent, _( "Fundamental frequency:" ), title, fundamental );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() != wxID_OK )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if( !dlg.GetValue().IsEmpty() )
|
|
|
|
fundamental = dlg.GetValue();
|
|
|
|
|
|
|
|
for( const wxString& signal : signals )
|
|
|
|
m_parent->DoFourier( signal, fundamental );
|
|
|
|
}
|
2024-03-11 18:14:16 +00:00
|
|
|
else if( event.GetId() == GRIDTRICKS_ID_COPY )
|
2023-07-04 15:53:44 +00:00
|
|
|
{
|
2024-03-11 18:14:16 +00:00
|
|
|
wxLogNull doNotLog; // disable logging of failed clipboard actions
|
|
|
|
wxString txt;
|
|
|
|
|
|
|
|
for( const wxString& signal : signals )
|
|
|
|
{
|
|
|
|
if( !txt.IsEmpty() )
|
|
|
|
txt += '\r';
|
|
|
|
|
|
|
|
txt += signal;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( wxTheClipboard->Open() )
|
|
|
|
{
|
|
|
|
wxTheClipboard->SetData( new wxTextDataObject( txt ) );
|
|
|
|
wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
2023-07-04 15:53:44 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class CURSORS_GRID_TRICKS : public GRID_TRICKS
|
|
|
|
{
|
|
|
|
public:
|
2023-07-14 09:21:58 +00:00
|
|
|
CURSORS_GRID_TRICKS( SIMULATOR_FRAME_UI* aParent, WX_GRID* aGrid ) :
|
2023-06-15 12:39:04 +00:00
|
|
|
GRID_TRICKS( aGrid ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_menuRow( 0 ),
|
|
|
|
m_menuCol( 0 )
|
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
|
|
|
|
void doPopupSelection( wxCommandEvent& event ) override;
|
|
|
|
|
|
|
|
protected:
|
2023-07-14 09:21:58 +00:00
|
|
|
SIMULATOR_FRAME_UI* m_parent;
|
|
|
|
int m_menuRow;
|
|
|
|
int m_menuCol;
|
2023-06-15 12:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void CURSORS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_menuRow = aEvent.GetRow();
|
|
|
|
m_menuCol = aEvent.GetCol();
|
|
|
|
|
|
|
|
if( m_menuCol == COL_CURSOR_X || m_menuCol == COL_CURSOR_Y )
|
|
|
|
{
|
|
|
|
wxString msg = m_grid->GetColLabelValue( m_menuCol );
|
|
|
|
|
|
|
|
menu.Append( MYID_FORMAT_VALUE, wxString::Format( _( "Format %s..." ), msg ) );
|
|
|
|
menu.AppendSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
GRID_TRICKS::showPopupMenu( menu, aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CURSORS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
|
|
|
{
|
2023-07-20 19:49:43 +00:00
|
|
|
auto getSignalName =
|
|
|
|
[this]( int row ) -> wxString
|
|
|
|
{
|
|
|
|
wxString signal = m_grid->GetCellValue( row, COL_CURSOR_SIGNAL );
|
|
|
|
|
|
|
|
if( signal.EndsWith( "[2 - 1]" ) )
|
2023-07-20 20:13:19 +00:00
|
|
|
signal = signal.Left( signal.length() - 7 );
|
2023-07-20 19:49:43 +00:00
|
|
|
|
|
|
|
return signal;
|
|
|
|
};
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( event.GetId() == MYID_FORMAT_VALUE )
|
|
|
|
{
|
2023-07-20 19:49:43 +00:00
|
|
|
int axis = m_menuCol - COL_CURSOR_X;
|
|
|
|
SPICE_VALUE_FORMAT format = m_parent->GetCursorFormat( m_menuRow, axis );
|
2023-06-15 12:39:04 +00:00
|
|
|
DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format );
|
|
|
|
|
|
|
|
if( formatDialog.ShowModal() == wxID_OK )
|
2023-07-20 19:49:43 +00:00
|
|
|
{
|
|
|
|
for( int row = 0; row < m_grid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
if( getSignalName( row ) == getSignalName( m_menuRow ) )
|
|
|
|
m_parent->SetCursorFormat( row, axis, format );
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GRID_TRICKS::doPopupSelection( event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class MEASUREMENTS_GRID_TRICKS : public GRID_TRICKS
|
|
|
|
{
|
|
|
|
public:
|
2023-07-14 09:21:58 +00:00
|
|
|
MEASUREMENTS_GRID_TRICKS( SIMULATOR_FRAME_UI* aParent, WX_GRID* aGrid ) :
|
2023-06-15 12:39:04 +00:00
|
|
|
GRID_TRICKS( aGrid ),
|
|
|
|
m_parent( aParent ),
|
|
|
|
m_menuRow( 0 ),
|
|
|
|
m_menuCol( 0 )
|
|
|
|
{}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent ) override;
|
|
|
|
void doPopupSelection( wxCommandEvent& event ) override;
|
|
|
|
|
|
|
|
protected:
|
2023-07-14 09:21:58 +00:00
|
|
|
SIMULATOR_FRAME_UI* m_parent;
|
|
|
|
int m_menuRow;
|
|
|
|
int m_menuCol;
|
2023-06-15 12:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
void MEASUREMENTS_GRID_TRICKS::showPopupMenu( wxMenu& menu, wxGridEvent& aEvent )
|
|
|
|
{
|
|
|
|
m_menuRow = aEvent.GetRow();
|
|
|
|
m_menuCol = aEvent.GetCol();
|
|
|
|
|
|
|
|
if( !( m_grid->IsInSelection( m_menuRow, m_menuCol ) ) )
|
|
|
|
m_grid->ClearSelection();
|
|
|
|
|
|
|
|
m_grid->SetGridCursor( m_menuRow, m_menuCol );
|
|
|
|
|
|
|
|
if( m_menuCol == COL_MEASUREMENT_VALUE )
|
|
|
|
menu.Append( MYID_FORMAT_VALUE, _( "Format Value..." ) );
|
|
|
|
|
|
|
|
if( m_menuRow < ( m_grid->GetNumberRows() - 1 ) )
|
|
|
|
menu.Append( MYID_DELETE_MEASUREMENT, _( "Delete Measurement" ) );
|
|
|
|
|
|
|
|
menu.AppendSeparator();
|
|
|
|
|
|
|
|
GRID_TRICKS::showPopupMenu( menu, aEvent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MEASUREMENTS_GRID_TRICKS::doPopupSelection( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
if( event.GetId() == MYID_FORMAT_VALUE )
|
|
|
|
{
|
|
|
|
SPICE_VALUE_FORMAT format = m_parent->GetMeasureFormat( m_menuRow );
|
|
|
|
DIALOG_SIM_FORMAT_VALUE formatDialog( m_parent, &format );
|
|
|
|
|
|
|
|
if( formatDialog.ShowModal() == wxID_OK )
|
|
|
|
{
|
|
|
|
m_parent->SetMeasureFormat( m_menuRow, format );
|
|
|
|
m_parent->UpdateMeasurement( m_menuRow );
|
2023-10-21 13:26:17 +00:00
|
|
|
m_parent->OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( event.GetId() == MYID_DELETE_MEASUREMENT )
|
|
|
|
{
|
|
|
|
std::vector<int> measurements;
|
|
|
|
|
|
|
|
wxGridCellCoordsArray cells1 = m_grid->GetSelectionBlockTopLeft();
|
|
|
|
wxGridCellCoordsArray cells2 = m_grid->GetSelectionBlockBottomRight();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < cells1.Count(); i++ )
|
|
|
|
{
|
|
|
|
if( cells1[i].GetCol() == COL_MEASUREMENT )
|
|
|
|
{
|
|
|
|
for( int j = cells1[i].GetRow(); j < cells2[i].GetRow() + 1; j++ )
|
|
|
|
measurements.push_back( j );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
wxGridCellCoordsArray cells3 = m_grid->GetSelectedCells();
|
|
|
|
|
|
|
|
for( size_t i = 0; i < cells3.Count(); i++ )
|
|
|
|
{
|
|
|
|
if( cells3[i].GetCol() == COL_MEASUREMENT )
|
|
|
|
measurements.push_back( cells3[i].GetRow() );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( measurements.size() < 1 )
|
|
|
|
measurements.push_back( m_menuRow );
|
|
|
|
|
|
|
|
// When deleting a row, we'll change the indexes.
|
|
|
|
// To avoid problems, we can start with the highest indexes.
|
|
|
|
sort( measurements.begin(), measurements.end(), std::greater<>() );
|
|
|
|
|
|
|
|
for( int row : measurements )
|
|
|
|
m_parent->DeleteMeasurement( row );
|
|
|
|
|
|
|
|
m_grid->ClearSelection();
|
2023-10-21 13:26:17 +00:00
|
|
|
|
|
|
|
m_parent->OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
GRID_TRICKS::doPopupSelection( event );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class SUPPRESS_GRID_CELL_EVENTS
|
|
|
|
{
|
|
|
|
public:
|
2023-07-14 09:21:58 +00:00
|
|
|
SUPPRESS_GRID_CELL_EVENTS( SIMULATOR_FRAME_UI* aFrame ) :
|
2023-06-15 12:39:04 +00:00
|
|
|
m_frame( aFrame )
|
|
|
|
{
|
|
|
|
m_frame->m_SuppressGridEvents++;
|
|
|
|
}
|
|
|
|
|
|
|
|
~SUPPRESS_GRID_CELL_EVENTS()
|
|
|
|
{
|
|
|
|
m_frame->m_SuppressGridEvents--;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2023-07-14 09:21:58 +00:00
|
|
|
SIMULATOR_FRAME_UI* m_frame;
|
2023-06-15 12:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-06-18 15:23:38 +00:00
|
|
|
#define ID_SIM_REFRESH 10207
|
|
|
|
#define REFRESH_INTERVAL 50 // 20 frames/second.
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
SIMULATOR_FRAME_UI::SIMULATOR_FRAME_UI( SIMULATOR_FRAME* aSimulatorFrame,
|
|
|
|
SCH_EDIT_FRAME* aSchematicFrame ) :
|
|
|
|
SIMULATOR_FRAME_UI_BASE( aSimulatorFrame ),
|
2023-06-15 12:39:04 +00:00
|
|
|
m_SuppressGridEvents( 0 ),
|
|
|
|
m_simulatorFrame( aSimulatorFrame ),
|
|
|
|
m_schematicFrame( aSchematicFrame ),
|
|
|
|
m_darkMode( true ),
|
2023-06-18 15:23:38 +00:00
|
|
|
m_plotNumber( 0 ),
|
|
|
|
m_refreshTimer( this, ID_SIM_REFRESH )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
// Get the previous size and position of windows:
|
|
|
|
LoadSettings( m_schematicFrame->eeconfig() );
|
|
|
|
|
|
|
|
m_filter->SetHint( _( "Filter" ) );
|
|
|
|
|
|
|
|
m_signalsGrid->wxGrid::SetLabelFont( KIUI::GetStatusFont( this ) );
|
|
|
|
m_cursorsGrid->wxGrid::SetLabelFont( KIUI::GetStatusFont( this ) );
|
|
|
|
m_measurementsGrid->wxGrid::SetLabelFont( KIUI::GetStatusFont( this ) );
|
|
|
|
|
|
|
|
m_signalsGrid->PushEventHandler( new SIGNALS_GRID_TRICKS( this, m_signalsGrid ) );
|
|
|
|
m_cursorsGrid->PushEventHandler( new CURSORS_GRID_TRICKS( this, m_cursorsGrid ) );
|
|
|
|
m_measurementsGrid->PushEventHandler( new MEASUREMENTS_GRID_TRICKS( this, m_measurementsGrid ) );
|
|
|
|
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_signalsGrid->SetColAttr( COL_SIGNAL_NAME, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_cursorsGrid->SetColAttr( COL_CURSOR_NAME, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_cursorsGrid->SetColAttr( COL_CURSOR_SIGNAL, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_cursorsGrid->SetColAttr( COL_CURSOR_Y, attr );
|
|
|
|
|
|
|
|
for( int cursorId = 0; cursorId < 3; ++cursorId )
|
|
|
|
{
|
2023-09-17 11:41:41 +00:00
|
|
|
m_cursorFormats[ cursorId ][ 0 ] = { 3, wxS( "~s" ) };
|
|
|
|
m_cursorFormats[ cursorId ][ 1 ] = { 3, wxS( "~V" ) };
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_measurementsGrid->SetColAttr( COL_MEASUREMENT_VALUE, attr );
|
|
|
|
|
|
|
|
// Prepare the color list to plot traces
|
|
|
|
SIM_PLOT_COLORS::FillDefaultColorList( m_darkMode );
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
Bind( EVT_SIM_CURSOR_UPDATE, &SIMULATOR_FRAME_UI::onPlotCursorUpdate, this );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-06-18 15:23:38 +00:00
|
|
|
Bind( wxEVT_TIMER,
|
|
|
|
[&]( wxTimerEvent& aEvent )
|
|
|
|
{
|
|
|
|
OnSimRefresh( false );
|
|
|
|
|
|
|
|
if( m_simulatorFrame->GetSimulator()->IsRunning() )
|
|
|
|
m_refreshTimer.Start( REFRESH_INTERVAL, wxTIMER_ONE_SHOT );
|
|
|
|
},
|
|
|
|
m_refreshTimer.GetId() );
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
#ifndef wxHAS_NATIVE_TABART
|
|
|
|
// Default non-native tab art has ugly gradients we don't want
|
|
|
|
m_plotNotebook->SetArtProvider( new wxAuiSimpleTabArt() );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
SIMULATOR_FRAME_UI::~SIMULATOR_FRAME_UI()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
// Delete the GRID_TRICKS.
|
|
|
|
m_signalsGrid->PopEventHandler( true );
|
|
|
|
m_cursorsGrid->PopEventHandler( true );
|
|
|
|
m_measurementsGrid->PopEventHandler( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::ShowChangedLanguage()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
for( int ii = 0; ii < (int) m_plotNotebook->GetPageCount(); ++ii )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( ii ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxCHECK( simTab, /* void */ );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
simTab->OnLanguageChanged();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString pageTitle( simulator()->TypeToName( simTab->GetSimType(), true ) );
|
2023-07-19 15:25:57 +00:00
|
|
|
pageTitle.Prepend( wxString::Format( _( "Analysis %u - " ), ii+1 /* 1-based */ ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
m_plotNotebook->SetPageText( ii, pageTitle );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_filter->SetHint( _( "Filter" ) );
|
|
|
|
|
|
|
|
m_signalsGrid->SetColLabelValue( COL_SIGNAL_NAME, _( "Signal" ) );
|
|
|
|
m_signalsGrid->SetColLabelValue( COL_SIGNAL_SHOW, _( "Plot" ) );
|
|
|
|
m_signalsGrid->SetColLabelValue( COL_SIGNAL_COLOR, _( "Color" ) );
|
|
|
|
m_signalsGrid->SetColLabelValue( COL_CURSOR_1, _( "Cursor 1" ) );
|
|
|
|
m_signalsGrid->SetColLabelValue( COL_CURSOR_2, _( "Cursor 2" ) );
|
|
|
|
|
|
|
|
m_cursorsGrid->SetColLabelValue( COL_CURSOR_NAME, _( "Cursor" ) );
|
|
|
|
m_cursorsGrid->SetColLabelValue( COL_CURSOR_SIGNAL, _( "Signal" ) );
|
|
|
|
m_cursorsGrid->SetColLabelValue( COL_CURSOR_X, _( "Time" ) );
|
|
|
|
m_cursorsGrid->SetColLabelValue( COL_CURSOR_Y, _( "Value" ) );
|
|
|
|
updatePlotCursors();
|
|
|
|
|
|
|
|
for( TUNER_SLIDER* tuner : m_tuners )
|
|
|
|
tuner->ShowChangedLanguage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::LoadSettings( EESCHEMA_SETTINGS* aCfg )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
// Read subwindows sizes (should be > 0 )
|
|
|
|
m_splitterLeftRightSashPosition = aCfg->m_Simulator.plot_panel_width;
|
|
|
|
m_splitterPlotAndConsoleSashPosition = aCfg->m_Simulator.plot_panel_height;
|
|
|
|
m_splitterSignalsSashPosition = aCfg->m_Simulator.signal_panel_height;
|
|
|
|
m_splitterCursorsSashPosition = aCfg->m_Simulator.cursors_panel_height;
|
|
|
|
m_splitterTuneValuesSashPosition = aCfg->m_Simulator.measurements_panel_height;
|
|
|
|
m_darkMode = !aCfg->m_Simulator.white_background;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::SaveSettings( EESCHEMA_SETTINGS* aCfg )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
aCfg->m_Simulator.plot_panel_width = m_splitterLeftRight->GetSashPosition();
|
|
|
|
aCfg->m_Simulator.plot_panel_height = m_splitterPlotAndConsole->GetSashPosition();
|
|
|
|
aCfg->m_Simulator.signal_panel_height = m_splitterSignals->GetSashPosition();
|
|
|
|
aCfg->m_Simulator.cursors_panel_height = m_splitterCursors->GetSashPosition();
|
|
|
|
aCfg->m_Simulator.measurements_panel_height = m_splitterMeasurements->GetSashPosition();
|
|
|
|
aCfg->m_Simulator.white_background = !m_darkMode;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::InitWorkbook()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( !simulator()->Settings()->GetWorkbookFilename().IsEmpty() )
|
|
|
|
{
|
|
|
|
wxFileName filename = simulator()->Settings()->GetWorkbookFilename();
|
|
|
|
filename.SetPath( m_schematicFrame->Prj().GetProjectPath() );
|
|
|
|
|
|
|
|
if( !LoadWorkbook( filename.GetFullPath() ) )
|
|
|
|
simulator()->Settings()->SetWorkbookFilename( "" );
|
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
else if( m_simulatorFrame->LoadSimulator( wxEmptyString, 0 ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
wxString schTextSimCommand = circuitModel()->GetSchTextSimCommand();
|
|
|
|
|
|
|
|
if( !schTextSimCommand.IsEmpty() )
|
2023-07-19 15:25:57 +00:00
|
|
|
{
|
|
|
|
SIM_TAB* simTab = NewSimTab( schTextSimCommand );
|
|
|
|
simTab->SetSimOptions( NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
rebuildSignalsList();
|
|
|
|
rebuildSignalsGrid( m_filter->GetValue() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::SetSubWindowsSashSize()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
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_splitterCursorsSashPosition > 0 )
|
|
|
|
m_splitterCursors->SetSashPosition( m_splitterCursorsSashPosition );
|
|
|
|
|
|
|
|
if( m_splitterTuneValuesSashPosition > 0 )
|
|
|
|
m_splitterMeasurements->SetSashPosition( m_splitterTuneValuesSashPosition );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
void sortSignals( std::vector<wxString>& signals )
|
|
|
|
{
|
|
|
|
std::sort( signals.begin(), signals.end(),
|
|
|
|
[]( const wxString& lhs, const wxString& rhs )
|
|
|
|
{
|
|
|
|
// Sort voltages first
|
|
|
|
if( lhs.Upper().StartsWith( 'V' ) && !rhs.Upper().StartsWith( 'V' ) )
|
|
|
|
return true;
|
|
|
|
else if( !lhs.Upper().StartsWith( 'V' ) && rhs.Upper().StartsWith( 'V' ) )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return StrNumCmp( lhs, rhs, true /* ignore case */ ) < 0;
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::rebuildSignalsGrid( wxString aFilter )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
SUPPRESS_GRID_CELL_EVENTS raii( this );
|
|
|
|
|
|
|
|
m_signalsGrid->ClearRows();
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotPanel = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-07 15:22:29 +00:00
|
|
|
if( !plotPanel )
|
|
|
|
return;
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-10-20 13:08:39 +00:00
|
|
|
SIM_TYPE simType = plotPanel->GetSimType();
|
2023-07-07 15:22:29 +00:00
|
|
|
std::vector<wxString> signals;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
if( plotPanel->GetSimType() == ST_FFT )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
wxStringTokenizer tokenizer( plotPanel->GetSimCommand(), wxT( " \t\r\n" ), wxTOKEN_STRTOK );
|
|
|
|
|
|
|
|
while( tokenizer.HasMoreTokens() && tokenizer.GetNextToken().Lower() != wxT( "fft" ) )
|
|
|
|
{};
|
|
|
|
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
signals.emplace_back( tokenizer.GetNextToken() );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-10-20 13:08:39 +00:00
|
|
|
// NB: m_signals are already broken out into gain/phase, but m_userDefinedSignals are
|
|
|
|
// as the user typed them
|
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
for( const wxString& signal : m_signals )
|
|
|
|
signals.push_back( signal );
|
|
|
|
|
|
|
|
for( const auto& [ id, signal ] : m_userDefinedSignals )
|
2023-10-20 13:08:39 +00:00
|
|
|
{
|
|
|
|
if( simType == ST_AC )
|
|
|
|
{
|
|
|
|
signals.push_back( signal + _( " (gain)" ) );
|
|
|
|
signals.push_back( signal + _( " (phase)" ) );
|
|
|
|
}
|
|
|
|
else if( simType == ST_SP )
|
|
|
|
{
|
|
|
|
signals.push_back( signal + _( " (amplitude)" ) );
|
|
|
|
signals.push_back( signal + _( " (phase)" ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
signals.push_back( signal );
|
|
|
|
}
|
|
|
|
}
|
2023-10-03 11:55:29 +00:00
|
|
|
|
|
|
|
sortSignals( signals );
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
|
|
|
|
2023-07-07 15:22:29 +00:00
|
|
|
if( aFilter.IsEmpty() )
|
|
|
|
aFilter = wxS( "*" );
|
|
|
|
|
|
|
|
EDA_COMBINED_MATCHER matcher( aFilter.Upper(), CTX_SIGNAL );
|
|
|
|
int row = 0;
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
for( const wxString& signal : signals )
|
|
|
|
{
|
|
|
|
if( matcher.Find( signal.Upper() ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
int traceType = SPT_UNKNOWN;
|
2023-07-05 17:25:52 +00:00
|
|
|
wxString vectorName = vectorNameFromSignalName( plotPanel, signal, &traceType );
|
2024-01-04 15:57:30 +00:00
|
|
|
TRACE* trace = plotPanel->GetTrace( vectorName, traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
m_signalsGrid->AppendRows( 1 );
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_NAME, signal );
|
|
|
|
|
2024-01-04 15:57:30 +00:00
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_signalsGrid->SetAttr( row, COL_SIGNAL_SHOW, attr );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2024-01-04 15:57:30 +00:00
|
|
|
if( !trace )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2024-01-04 15:57:30 +00:00
|
|
|
attr = new wxGridCellAttr;
|
2023-06-15 12:39:04 +00:00
|
|
|
attr->SetReadOnly();
|
|
|
|
m_signalsGrid->SetAttr( row, COL_SIGNAL_COLOR, attr );
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_COLOR, wxEmptyString );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_1, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_2, attr );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2024-01-04 15:57:30 +00:00
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_SHOW, wxS( "1" ) );
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( this ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( this, m_signalsGrid ) );
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_signalsGrid->SetAttr( row, COL_SIGNAL_COLOR, attr );
|
|
|
|
KIGFX::COLOR4D color( trace->GetPen().GetColour() );
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_COLOR, color.ToCSSString() );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_1, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_2, attr );
|
|
|
|
}
|
|
|
|
|
|
|
|
row++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::rebuildSignalsList()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_signals.clear();
|
|
|
|
|
|
|
|
int options = m_simulatorFrame->GetCurrentOptions();
|
|
|
|
SIM_TYPE simType = m_simulatorFrame->GetCurrentSimType();
|
|
|
|
wxString unconnected = wxString( wxS( "unconnected-(" ) );
|
|
|
|
|
|
|
|
if( simType == ST_UNKNOWN )
|
2023-07-05 17:25:52 +00:00
|
|
|
simType = ST_TRAN;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
unconnected.Replace( '(', '_' ); // Convert to SPICE markup
|
|
|
|
|
|
|
|
auto addSignal =
|
|
|
|
[&]( const wxString& aSignalName )
|
|
|
|
{
|
|
|
|
if( simType == ST_AC )
|
|
|
|
{
|
|
|
|
m_signals.push_back( aSignalName + _( " (gain)" ) );
|
|
|
|
m_signals.push_back( aSignalName + _( " (phase)" ) );
|
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
else if( simType == ST_SP )
|
2023-07-04 16:01:12 +00:00
|
|
|
{
|
|
|
|
m_signals.push_back( aSignalName + _( " (amplitude)" ) );
|
|
|
|
m_signals.push_back( aSignalName + _( " (phase)" ) );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
m_signals.push_back( aSignalName );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2023-07-03 22:11:43 +00:00
|
|
|
if( ( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES )
|
2023-07-05 17:25:52 +00:00
|
|
|
&& ( simType == ST_TRAN || simType == ST_DC || simType == ST_AC || simType == ST_FFT) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
for( const std::string& net : circuitModel()->GetNets() )
|
|
|
|
{
|
|
|
|
// netnames are escaped (can contain "{slash}" for '/') Unscape them:
|
|
|
|
wxString netname = UnescapeString( net );
|
|
|
|
|
|
|
|
if( netname == "GND" || netname == "0" || netname.StartsWith( unconnected ) )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m_quotedNetnames[ netname ] = wxString::Format( wxS( "\"%s\"" ), netname );
|
|
|
|
addSignal( wxString::Format( wxS( "V(%s)" ), netname ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS )
|
2023-08-16 16:23:54 +00:00
|
|
|
&& ( simType == ST_TRAN || simType == ST_DC || simType == ST_AC ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
for( const SPICE_ITEM& item : circuitModel()->GetItems() )
|
|
|
|
{
|
|
|
|
// Add all possible currents for the device.
|
|
|
|
for( const std::string& name : item.model->SpiceGenerator().CurrentNames( item ) )
|
|
|
|
addSignal( name );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS )
|
2023-07-05 17:25:52 +00:00
|
|
|
&& ( simType == ST_TRAN || simType == ST_DC ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
for( const SPICE_ITEM& item : circuitModel()->GetItems() )
|
|
|
|
{
|
|
|
|
if( item.model->GetPinCount() >= 2 )
|
|
|
|
{
|
|
|
|
wxString name = item.model->SpiceGenerator().ItemName( item );
|
|
|
|
addSignal( wxString::Format( wxS( "P(%s)" ), name ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-03 22:11:43 +00:00
|
|
|
if( simType == ST_NOISE )
|
|
|
|
{
|
2023-07-04 10:04:20 +00:00
|
|
|
addSignal( wxS( "inoise_spectrum" ) );
|
|
|
|
addSignal( wxS( "onoise_spectrum" ) );
|
2023-07-03 22:11:43 +00:00
|
|
|
}
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
if( simType == ST_SP )
|
2023-07-04 16:01:12 +00:00
|
|
|
{
|
|
|
|
std::vector<std::string> portnums;
|
|
|
|
|
|
|
|
for( const SPICE_ITEM& item : circuitModel()->GetItems() )
|
|
|
|
{
|
|
|
|
wxString name = item.model->SpiceGenerator().ItemName( item );
|
|
|
|
|
|
|
|
// We are only looking for voltage sources in .SP mode
|
|
|
|
if( !name.StartsWith( "V" ) )
|
|
|
|
continue;
|
|
|
|
|
2024-02-22 16:40:14 +00:00
|
|
|
std::string portnum = "";
|
2024-02-28 18:13:27 +00:00
|
|
|
|
2024-02-22 16:40:14 +00:00
|
|
|
if( const SIM_MODEL::PARAM* portnum_param = item.model->FindParam( "portnum" ) )
|
|
|
|
portnum = SIM_VALUE::ToSpice( portnum_param->value );
|
|
|
|
|
|
|
|
if( portnum != "" )
|
|
|
|
portnums.push_back( portnum );
|
2023-07-04 16:01:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for( const std::string& portnum1 : portnums )
|
|
|
|
{
|
|
|
|
for( const std::string& portnum2 : portnums )
|
|
|
|
{
|
|
|
|
addSignal( wxString::Format( wxS( "S_%s_%s" ), portnum1, portnum2 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
// Add .PROBE directives
|
|
|
|
for( const wxString& directive : circuitModel()->GetDirectives() )
|
|
|
|
{
|
|
|
|
wxStringTokenizer tokenizer( directive, wxT( "\r\n" ), wxTOKEN_STRTOK );
|
|
|
|
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
{
|
|
|
|
wxString line = tokenizer.GetNextToken();
|
|
|
|
wxString directiveParams;
|
|
|
|
|
|
|
|
if( line.Upper().StartsWith( wxS( ".PROBE" ), &directiveParams ) )
|
|
|
|
addSignal( directiveParams.Trim( true ).Trim( false ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
SIM_TAB* SIMULATOR_FRAME_UI::NewSimTab( const wxString& aSimCommand )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* simTab = nullptr;
|
2023-07-14 09:21:58 +00:00
|
|
|
SIM_TYPE simType = SPICE_CIRCUIT_MODEL::CommandToSimType( aSimCommand );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( SIM_TAB::IsPlottable( simType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
SIM_PLOT_TAB* panel = new SIM_PLOT_TAB( aSimCommand, m_plotNotebook );
|
2023-07-09 22:00:25 +00:00
|
|
|
simTab = panel;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
COMMON_SETTINGS::INPUT cfg = Pgm().GetCommonSettings()->m_Input;
|
|
|
|
panel->GetPlotWin()->EnableMouseWheelPan( cfg.scroll_modifier_zoom != 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
simTab = new SIM_NOPLOT_TAB( aSimCommand, m_plotNotebook );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString pageTitle( simulator()->TypeToName( simType, true ) );
|
2023-07-19 15:25:57 +00:00
|
|
|
pageTitle.Prepend( wxString::Format( _( "Analysis %u - " ), (unsigned int) ++m_plotNumber ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
m_plotNotebook->AddPage( simTab, pageTitle, true );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
return simTab;
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnFilterText( wxCommandEvent& aEvent )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
rebuildSignalsGrid( m_filter->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnFilterMouseMoved( wxMouseEvent& aEvent )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
wxPoint pos = aEvent.GetPosition();
|
|
|
|
wxRect ctrlRect = m_filter->GetScreenRect();
|
|
|
|
int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
|
|
|
|
|
|
|
|
if( m_filter->IsSearchButtonVisible() && pos.x < buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else if( m_filter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else
|
|
|
|
SetCursor( wxCURSOR_IBEAM );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
wxString vectorNameFromSignalId( int aUserDefinedSignalId )
|
|
|
|
{
|
|
|
|
return wxString::Format( wxS( "user%d" ), aUserDefinedSignalId );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* For user-defined signals we display the user-oriented signal name such as "V(out)-V(in)",
|
|
|
|
* but the simulator vector we actually have to plot will be "user0" or some-such.
|
|
|
|
*/
|
2023-07-14 09:21:58 +00:00
|
|
|
wxString SIMULATOR_FRAME_UI::vectorNameFromSignalName( SIM_PLOT_TAB* aPlotTab,
|
|
|
|
const wxString& aSignalName,
|
|
|
|
int* aTraceType )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
std::map<wxString, int> suffixes;
|
2023-07-05 10:53:19 +00:00
|
|
|
suffixes[ _( " (amplitude)" ) ] = SPT_SP_AMP;
|
|
|
|
suffixes[ _( " (gain)" ) ] = SPT_AC_GAIN;
|
2023-06-15 12:39:04 +00:00
|
|
|
suffixes[ _( " (phase)" ) ] = SPT_AC_PHASE;
|
|
|
|
|
|
|
|
if( aTraceType )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( aPlotTab && aPlotTab->GetSimType() == ST_NOISE )
|
2023-07-03 22:11:43 +00:00
|
|
|
{
|
|
|
|
if( getNoiseSource().Upper().StartsWith( 'I' ) )
|
|
|
|
*aTraceType = SPT_CURRENT;
|
|
|
|
else
|
|
|
|
*aTraceType = SPT_VOLTAGE;
|
|
|
|
}
|
2023-07-04 10:04:20 +00:00
|
|
|
else
|
2023-07-03 22:11:43 +00:00
|
|
|
{
|
2023-07-04 10:04:20 +00:00
|
|
|
wxUniChar firstChar = aSignalName.Upper()[0];
|
2023-07-03 22:11:43 +00:00
|
|
|
|
|
|
|
if( firstChar == 'V' )
|
|
|
|
*aTraceType = SPT_VOLTAGE;
|
|
|
|
else if( firstChar == 'I' )
|
|
|
|
*aTraceType = SPT_CURRENT;
|
|
|
|
else if( firstChar == 'P' )
|
|
|
|
*aTraceType = SPT_POWER;
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString suffix;
|
|
|
|
wxString name = aSignalName;
|
|
|
|
|
|
|
|
for( const auto& [ candidate, type ] : suffixes )
|
|
|
|
{
|
|
|
|
if( name.EndsWith( candidate ) )
|
|
|
|
{
|
|
|
|
name = name.Left( name.Length() - candidate.Length() );
|
|
|
|
|
|
|
|
if( aTraceType )
|
|
|
|
*aTraceType |= type;
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const auto& [ id, signal ] : m_userDefinedSignals )
|
|
|
|
{
|
|
|
|
if( name == signal )
|
|
|
|
return vectorNameFromSignalId( id );
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onSignalsGridCellChanged( wxGridEvent& aEvent )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( m_SuppressGridEvents > 0 )
|
|
|
|
return;
|
|
|
|
|
2023-07-25 17:53:05 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
|
|
|
|
|
|
|
if( !plotTab )
|
|
|
|
return;
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
int row = aEvent.GetRow();
|
|
|
|
int col = aEvent.GetCol();
|
|
|
|
wxString text = m_signalsGrid->GetCellValue( row, col );
|
|
|
|
wxString signalName = m_signalsGrid->GetCellValue( row, COL_SIGNAL_NAME );
|
|
|
|
int traceType = SPT_UNKNOWN;
|
|
|
|
wxString vectorName = vectorNameFromSignalName( plotTab, signalName, &traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
if( col == COL_SIGNAL_SHOW )
|
|
|
|
{
|
|
|
|
if( text == wxS( "1" ) )
|
2023-07-09 22:00:25 +00:00
|
|
|
updateTrace( vectorName, traceType, plotTab );
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->DeleteTrace( vectorName, traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-09-22 20:40:35 +00:00
|
|
|
plotTab->GetPlotWin()->UpdateAll();
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
// Update enabled/visible states of other controls
|
|
|
|
updateSignalsGrid();
|
|
|
|
updatePlotCursors();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else if( col == COL_SIGNAL_COLOR )
|
|
|
|
{
|
|
|
|
KIGFX::COLOR4D color( m_signalsGrid->GetCellValue( row, COL_SIGNAL_COLOR ) );
|
2023-07-09 22:00:25 +00:00
|
|
|
TRACE* trace = plotTab->GetTrace( vectorName, traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
if( trace )
|
|
|
|
{
|
|
|
|
trace->SetTraceColour( color.ToColour() );
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->UpdateTraceStyle( trace );
|
|
|
|
plotTab->UpdatePlotColors();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( col == COL_CURSOR_1 || col == COL_CURSOR_2 )
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < m_signalsGrid->GetNumberRows(); ++ii )
|
|
|
|
{
|
|
|
|
signalName = m_signalsGrid->GetCellValue( ii, COL_SIGNAL_NAME );
|
2023-07-09 22:00:25 +00:00
|
|
|
vectorName = vectorNameFromSignalName( plotTab, signalName, &traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
int id = col == COL_CURSOR_1 ? 1 : 2;
|
|
|
|
bool enable = ii == row && text == wxS( "1" );
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->EnableCursor( vectorName, traceType, id, enable, signalName );
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Update cursor checkboxes (which are really radio buttons)
|
|
|
|
updateSignalsGrid();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onCursorsGridCellChanged( wxGridEvent& aEvent )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( m_SuppressGridEvents > 0 )
|
|
|
|
return;
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int row = aEvent.GetRow();
|
|
|
|
int col = aEvent.GetCol();
|
|
|
|
wxString text = m_cursorsGrid->GetCellValue( row, col );
|
|
|
|
wxString cursorName = m_cursorsGrid->GetCellValue( row, COL_CURSOR_NAME );
|
|
|
|
|
|
|
|
if( col == COL_CURSOR_X )
|
|
|
|
{
|
|
|
|
CURSOR* cursor1 = nullptr;
|
|
|
|
CURSOR* cursor2 = nullptr;
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
for( const auto& [name, trace] : plotTab->GetTraces() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( CURSOR* cursor = trace->GetCursor( 1 ) )
|
|
|
|
cursor1 = cursor;
|
|
|
|
|
|
|
|
if( CURSOR* cursor = trace->GetCursor( 2 ) )
|
|
|
|
cursor2 = cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
double value = SPICE_VALUE( text ).ToDouble();
|
|
|
|
|
|
|
|
if( cursorName == wxS( "1" ) && cursor1 )
|
|
|
|
cursor1->SetCoordX( value );
|
|
|
|
else if( cursorName == wxS( "2" ) && cursor2 )
|
|
|
|
cursor2->SetCoordX( value );
|
|
|
|
else if( cursorName == _( "Diff" ) && cursor1 && cursor2 )
|
|
|
|
cursor2->SetCoordX( cursor1->GetCoords().x + value );
|
|
|
|
|
|
|
|
updatePlotCursors();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "All other columns are supposed to be read-only!" ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
SPICE_VALUE_FORMAT SIMULATOR_FRAME_UI::GetMeasureFormat( int aRow ) const
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
SPICE_VALUE_FORMAT result;
|
|
|
|
result.FromString( m_measurementsGrid->GetCellValue( aRow, COL_MEASUREMENT_FORMAT ) );
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::SetMeasureFormat( int aRow, const SPICE_VALUE_FORMAT& aFormat )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_FORMAT, aFormat.ToString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::DeleteMeasurement( int aRow )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( aRow < ( m_measurementsGrid->GetNumberRows() - 1 ) )
|
|
|
|
m_measurementsGrid->DeleteRows( aRow, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onMeasurementsGridCellChanged( wxGridEvent& aEvent )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
int row = aEvent.GetRow();
|
|
|
|
int col = aEvent.GetCol();
|
|
|
|
wxString text = m_measurementsGrid->GetCellValue( row, col );
|
|
|
|
|
|
|
|
if( col == COL_MEASUREMENT )
|
|
|
|
{
|
|
|
|
UpdateMeasurement( row );
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
wxFAIL_MSG( wxT( "All other columns are supposed to be read-only!" ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always leave a single empty row for type-in
|
|
|
|
|
|
|
|
int rowCount = (int) m_measurementsGrid->GetNumberRows();
|
|
|
|
int emptyRows = 0;
|
|
|
|
|
|
|
|
for( row = rowCount - 1; row >= 0; row-- )
|
|
|
|
{
|
|
|
|
if( m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
|
|
|
|
emptyRows++;
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( emptyRows > 1 )
|
|
|
|
{
|
|
|
|
int killRows = emptyRows - 1;
|
|
|
|
m_measurementsGrid->DeleteRows( rowCount - killRows, killRows );
|
|
|
|
}
|
|
|
|
else if( emptyRows == 0 )
|
|
|
|
{
|
|
|
|
m_measurementsGrid->AppendRows( 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-08-09 11:09:00 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnUpdateUI( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
|
|
|
|
{
|
|
|
|
if( plotTab->GetLegendPosition() != plotTab->m_LastLegendPosition )
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-08-09 11:09:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
/**
|
|
|
|
* The user measurement looks something like:
|
|
|
|
* MAX V(out)
|
|
|
|
*
|
|
|
|
* We need to send ngspice a "MEAS" command with the analysis type, an output variable name,
|
|
|
|
* and the signal name. For our example above, this looks something like:
|
|
|
|
* MEAS TRAN meas_result_0 MAX V(out)
|
|
|
|
*
|
|
|
|
* This is also a good time to harvest the signal name prefix so we know what units to show on
|
|
|
|
* the result. For instance, for:
|
|
|
|
* MAX P(out)
|
|
|
|
* we want to show:
|
|
|
|
* 15W
|
|
|
|
*/
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::UpdateMeasurement( int aRow )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
static wxRegEx measureParamsRegEx( wxT( "^"
|
|
|
|
" *"
|
|
|
|
"([a-zA-Z_]+)"
|
|
|
|
" +"
|
2023-08-17 16:41:34 +00:00
|
|
|
"([a-zA-Z]*)\\(([^\\)]+)\\)" ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
wxString text = m_measurementsGrid->GetCellValue( aRow, COL_MEASUREMENT );
|
|
|
|
|
|
|
|
if( text.IsEmpty() )
|
|
|
|
{
|
|
|
|
m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_VALUE, wxEmptyString );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString simType = simulator()->TypeToName( plotTab->GetSimType(), true );
|
2023-06-15 12:39:04 +00:00
|
|
|
wxString resultName = wxString::Format( wxS( "meas_result_%u" ), aRow );
|
|
|
|
wxString result = wxS( "?" );
|
|
|
|
|
|
|
|
if( measureParamsRegEx.Matches( text ) )
|
|
|
|
{
|
|
|
|
wxString func = measureParamsRegEx.GetMatch( text, 1 ).Upper();
|
2023-08-17 16:41:34 +00:00
|
|
|
wxString signalType = measureParamsRegEx.GetMatch( text, 2 ).Upper();
|
2023-06-15 12:39:04 +00:00
|
|
|
wxString deviceName = measureParamsRegEx.GetMatch( text, 3 );
|
|
|
|
wxString units;
|
|
|
|
SPICE_VALUE_FORMAT fmt = GetMeasureFormat( aRow );
|
|
|
|
|
2023-08-17 16:41:34 +00:00
|
|
|
if( signalType.EndsWith( wxS( "DB" ) ) )
|
|
|
|
{
|
|
|
|
units = wxS( "dB" );
|
|
|
|
}
|
|
|
|
else if( signalType.StartsWith( 'I' ) )
|
|
|
|
{
|
2023-06-15 12:39:04 +00:00
|
|
|
units = wxS( "A" );
|
2023-08-17 16:41:34 +00:00
|
|
|
}
|
|
|
|
else if( signalType.StartsWith( 'P' ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
units = wxS( "W" );
|
|
|
|
// Our syntax is different from ngspice for power signals
|
|
|
|
text = func + " " + deviceName + ":power";
|
|
|
|
}
|
|
|
|
else
|
2023-08-17 16:41:34 +00:00
|
|
|
{
|
2023-06-15 12:39:04 +00:00
|
|
|
units = wxS( "V" );
|
2023-08-17 16:41:34 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
if( func.EndsWith( wxS( "_AT" ) ) )
|
2023-08-17 11:22:25 +00:00
|
|
|
{
|
|
|
|
if( plotTab->GetSimType() == ST_AC || plotTab->GetSimType() == ST_SP )
|
|
|
|
units = wxS( "Hz" );
|
|
|
|
else
|
|
|
|
units = wxS( "s" );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
else if( func.StartsWith( wxS( "INTEG" ) ) )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
switch( plotTab->GetSimType() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-09-19 16:37:20 +00:00
|
|
|
case ST_TRAN:
|
2023-08-17 16:41:34 +00:00
|
|
|
if ( signalType.StartsWith( 'P' ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
units = wxS( "J" );
|
|
|
|
else
|
|
|
|
units += wxS( ".s" );
|
2023-09-19 16:37:20 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
break;
|
2023-09-19 16:37:20 +00:00
|
|
|
|
|
|
|
case ST_AC:
|
|
|
|
case ST_SP:
|
|
|
|
case ST_DISTO:
|
|
|
|
case ST_NOISE:
|
|
|
|
case ST_FFT:
|
|
|
|
case ST_SENS: // If there is a vector, it is frequency
|
2023-06-15 12:39:04 +00:00
|
|
|
units += wxS( "·Hz" );
|
|
|
|
break;
|
|
|
|
|
2023-09-19 16:37:20 +00:00
|
|
|
case ST_DC: // Could be a lot of things : V, A, deg C, ohm, ...
|
|
|
|
case ST_OP: // There is no vector for integration
|
|
|
|
case ST_PZ: // There is no vector for integration
|
|
|
|
case ST_TF: // There is no vector for integration
|
|
|
|
default:
|
2023-06-15 12:39:04 +00:00
|
|
|
units += wxS( "·?" );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fmt.UpdateUnits( units );
|
|
|
|
SetMeasureFormat( aRow, fmt );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_simulatorFrame->SimFinished() )
|
|
|
|
{
|
|
|
|
wxString cmd = wxString::Format( wxS( "meas %s %s %s" ), simType, resultName, text );
|
|
|
|
simulator()->Command( "echo " + cmd.ToStdString() );
|
|
|
|
simulator()->Command( cmd.ToStdString() );
|
|
|
|
|
2023-07-05 10:53:19 +00:00
|
|
|
std::vector<double> resultVec = simulator()->GetGainVector( resultName.ToStdString() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
if( resultVec.size() > 0 )
|
|
|
|
result = SPICE_VALUE( resultVec[0] ).ToString( GetMeasureFormat( aRow ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_measurementsGrid->SetCellValue( aRow, COL_MEASUREMENT_VALUE, result );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::AddTuner( const SCH_SHEET_PATH& aSheetPath, SCH_SYMBOL* aSymbol )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
wxString ref = aSymbol->GetRef( &aSheetPath );
|
|
|
|
|
|
|
|
// Do not add multiple instances for the same component.
|
|
|
|
for( TUNER_SLIDER* tuner : m_tuners )
|
|
|
|
{
|
|
|
|
if( tuner->GetSymbolRef() == ref )
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SPICE_ITEM* item = GetExporter()->FindItem( std::string( ref.ToUTF8() ) );
|
|
|
|
|
|
|
|
// Do nothing if the symbol is not tunable.
|
|
|
|
if( !item || !item->model->GetTunerParam() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
TUNER_SLIDER* tuner = new TUNER_SLIDER( this, m_panelTuners, aSheetPath, aSymbol );
|
|
|
|
m_sizerTuners->Add( tuner );
|
|
|
|
m_tuners.push_back( tuner );
|
|
|
|
m_panelTuners->Layout();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
catch( const KI_PARAM_ERROR& e )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( nullptr, e.What() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::UpdateTunerValue( const SCH_SHEET_PATH& aSheetPath, const KIID& aSymbol,
|
|
|
|
const wxString& aRef, const wxString& aValue )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
SCH_ITEM* item = aSheetPath.GetItem( aSymbol );
|
|
|
|
SCH_SYMBOL* symbol = dynamic_cast<SCH_SYMBOL*>( item );
|
|
|
|
|
|
|
|
if( !symbol )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( " " )
|
|
|
|
+ wxString::Format( _( "%s not found" ), aRef ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-06 10:37:50 +00:00
|
|
|
NULL_REPORTER devnull;
|
|
|
|
SIM_LIB_MGR mgr( &m_schematicFrame->Prj() );
|
|
|
|
SIM_MODEL& model = mgr.CreateModel( &aSheetPath, *symbol, devnull ).model;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
const SIM_MODEL::PARAM* tunerParam = model.GetTunerParam();
|
|
|
|
|
|
|
|
if( !tunerParam )
|
|
|
|
{
|
|
|
|
DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( " " )
|
|
|
|
+ wxString::Format( _( "%s is not tunable" ), aRef ) );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
model.SetParamValue( tunerParam->info.name, std::string( aValue.ToUTF8() ) );
|
|
|
|
model.WriteFields( symbol->GetFields() );
|
|
|
|
|
|
|
|
m_schematicFrame->UpdateItem( symbol, false, true );
|
|
|
|
m_schematicFrame->OnModify();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::RemoveTuner( TUNER_SLIDER* aTuner )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_tuners.remove( aTuner );
|
|
|
|
aTuner->Destroy();
|
|
|
|
m_panelTuners->Layout();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::AddMeasurement( const wxString& aCmd )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
// -1 because the last one is for user input
|
|
|
|
for( int i = 0; i < m_measurementsGrid->GetNumberRows(); i++ )
|
|
|
|
{
|
|
|
|
if ( m_measurementsGrid->GetCellValue( i, COL_MEASUREMENT ) == aCmd )
|
|
|
|
return; // Don't create duplicates
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
return;
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString simType = simulator()->TypeToName( plotTab->GetSimType(), true );
|
2023-06-15 12:39:04 +00:00
|
|
|
int row;
|
|
|
|
|
|
|
|
for( row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
if( m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
|
|
|
|
{
|
|
|
|
m_measurementsGrid->AppendRows( 1 );
|
|
|
|
row = m_measurementsGrid->GetNumberRows() - 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_measurementsGrid->SetCellValue( row, COL_MEASUREMENT, aCmd );
|
2023-07-20 16:20:57 +00:00
|
|
|
SetMeasureFormat( row, { 2, wxS( "~V" ) } );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
UpdateMeasurement( row );
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
// Always leave at least one empty row for type-in:
|
|
|
|
row = m_measurementsGrid->GetNumberRows() - 1;
|
|
|
|
|
|
|
|
if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
|
|
|
|
m_measurementsGrid->AppendRows( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::DoFourier( const wxString& aSignal, const wxString& aFundamental )
|
2023-07-04 15:53:44 +00:00
|
|
|
{
|
|
|
|
wxString cmd = wxString::Format( wxS( "fourier %s %s" ),
|
|
|
|
SPICE_VALUE( aFundamental ).ToSpiceString(),
|
|
|
|
aSignal );
|
|
|
|
|
|
|
|
simulator()->Command( cmd.ToStdString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
const SPICE_CIRCUIT_MODEL* SIMULATOR_FRAME_UI::GetExporter() const
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
return circuitModel().get();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::AddTrace( const wxString& aName, SIM_TRACE_TYPE aType )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !GetCurrentSimTab() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "Error: no current simulation.\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
SIM_TYPE simType = SPICE_CIRCUIT_MODEL::CommandToSimType( GetCurrentSimTab()->GetSimCommand() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
if( simType == ST_UNKNOWN )
|
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "Error: simulation type not defined.\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
return;
|
|
|
|
}
|
2023-07-09 22:00:25 +00:00
|
|
|
else if( !SIM_TAB::IsPlottable( simType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "Error: simulation type doesn't support plotting.\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
|
|
|
wxCHECK( plotTab, /* void */ );
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
if( simType == ST_AC )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
updateTrace( aName, aType | SPT_AC_GAIN, plotTab );
|
|
|
|
updateTrace( aName, aType | SPT_AC_PHASE, plotTab );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
else if( simType == ST_SP )
|
2023-07-04 16:01:12 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
updateTrace( aName, aType | SPT_AC_GAIN, plotTab );
|
|
|
|
updateTrace( aName, aType | SPT_AC_PHASE, plotTab );
|
2023-07-04 16:01:12 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
updateTrace( aName, aType, plotTab );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-09-22 20:40:35 +00:00
|
|
|
plotTab->GetPlotWin()->UpdateAll();
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
updateSignalsGrid();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::SetUserDefinedSignals( const std::map<int, wxString>& aNewSignals )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
for( size_t ii = 0; ii < m_plotNotebook->GetPageCount(); ++ii )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( m_plotNotebook->GetPage( ii ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
continue;
|
|
|
|
|
|
|
|
for( const auto& [ id, existingSignal ] : m_userDefinedSignals )
|
|
|
|
{
|
|
|
|
int traceType = SPT_UNKNOWN;
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString vectorName = vectorNameFromSignalName( plotTab, existingSignal, &traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
if( aNewSignals.count( id ) == 0 )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( plotTab->GetSimType() == ST_AC )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-05 10:53:19 +00:00
|
|
|
for( int subType : { SPT_AC_GAIN, SPT_AC_PHASE } )
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->DeleteTrace( vectorName, traceType | subType );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-07-09 22:00:25 +00:00
|
|
|
else if( plotTab->GetSimType() == ST_SP )
|
2023-07-04 16:01:12 +00:00
|
|
|
{
|
|
|
|
for( int subType : { SPT_SP_AMP, SPT_AC_PHASE } )
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->DeleteTrace( vectorName, traceType | subType );
|
2023-07-04 16:01:12 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->DeleteTrace( vectorName, traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( plotTab->GetSimType() == ST_AC )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-05 10:53:19 +00:00
|
|
|
for( int subType : { SPT_AC_GAIN, SPT_AC_PHASE } )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( TRACE* trace = plotTab->GetTrace( vectorName, traceType | subType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
trace->SetName( aNewSignals.at( id ) );
|
|
|
|
}
|
|
|
|
}
|
2023-07-09 22:00:25 +00:00
|
|
|
else if( plotTab->GetSimType() == ST_SP )
|
2023-07-04 16:01:12 +00:00
|
|
|
{
|
|
|
|
for( int subType : { SPT_SP_AMP, SPT_AC_PHASE } )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( TRACE* trace = plotTab->GetTrace( vectorName, traceType | subType ) )
|
2023-07-04 16:01:12 +00:00
|
|
|
trace->SetName( aNewSignals.at( id ) );
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( TRACE* trace = plotTab->GetTrace( vectorName, traceType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
trace->SetName( aNewSignals.at( id ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_userDefinedSignals = aNewSignals;
|
|
|
|
|
|
|
|
if( m_simulatorFrame->SimFinished() )
|
|
|
|
applyUserDefinedSignals();
|
|
|
|
|
|
|
|
rebuildSignalsList();
|
|
|
|
rebuildSignalsGrid( m_filter->GetValue() );
|
|
|
|
updateSignalsGrid();
|
|
|
|
updatePlotCursors();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::updateTrace( const wxString& aVectorName, int aTraceType,
|
2023-10-03 11:55:29 +00:00
|
|
|
SIM_PLOT_TAB* aPlotTab, std::vector<double>* aDataX,
|
|
|
|
bool aClearData )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
SIM_TYPE simType = SPICE_CIRCUIT_MODEL::CommandToSimType( aPlotTab->GetSimCommand() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
aTraceType &= aTraceType & SPT_Y_AXIS_MASK;
|
|
|
|
aTraceType |= getXAxisType( simType );
|
|
|
|
|
|
|
|
wxString simVectorName = aVectorName;
|
|
|
|
|
|
|
|
if( aTraceType & SPT_POWER )
|
|
|
|
simVectorName = simVectorName.AfterFirst( '(' ).BeforeLast( ')' ) + wxS( ":power" );
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !SIM_TAB::IsPlottable( simType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
// There is no plot to be shown
|
|
|
|
simulator()->Command( wxString::Format( wxT( "print %s" ), aVectorName ).ToStdString() );
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-09-22 20:40:35 +00:00
|
|
|
std::vector<double> data_x;
|
|
|
|
std::vector<double> data_y;
|
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
if( !aDataX || aClearData )
|
2023-09-22 20:40:35 +00:00
|
|
|
aDataX = &data_x;
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
// First, handle the x axis
|
2023-10-03 11:55:29 +00:00
|
|
|
if( aDataX->empty() && !aClearData )
|
2023-09-22 20:40:35 +00:00
|
|
|
{
|
|
|
|
wxString xAxisName( simulator()->GetXAxis( simType ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-09-22 20:40:35 +00:00
|
|
|
if( xAxisName.IsEmpty() )
|
|
|
|
return;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-09-22 20:40:35 +00:00
|
|
|
*aDataX = simulator()->GetGainVector( (const char*) xAxisName.c_str() );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-09-22 20:40:35 +00:00
|
|
|
unsigned int size = aDataX->size();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-06-18 15:23:38 +00:00
|
|
|
switch( simType )
|
|
|
|
{
|
|
|
|
case ST_AC:
|
2023-07-05 10:53:19 +00:00
|
|
|
if( aTraceType & SPT_AC_GAIN )
|
2023-09-22 20:40:35 +00:00
|
|
|
data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), size );
|
2023-06-18 15:23:38 +00:00
|
|
|
else if( aTraceType & SPT_AC_PHASE )
|
2023-09-22 20:40:35 +00:00
|
|
|
data_y = simulator()->GetPhaseVector( (const char*) simVectorName.c_str(), size );
|
2023-06-18 15:23:38 +00:00
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "Plot type missing AC_PHASE or AC_MAG bit" ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-06-18 15:23:38 +00:00
|
|
|
break;
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_SP:
|
2023-07-04 16:01:12 +00:00
|
|
|
if( aTraceType & SPT_SP_AMP )
|
2023-09-22 20:40:35 +00:00
|
|
|
data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), size );
|
2023-07-04 16:01:12 +00:00
|
|
|
else if( aTraceType & SPT_AC_PHASE )
|
2023-09-22 20:40:35 +00:00
|
|
|
data_y = simulator()->GetPhaseVector( (const char*) simVectorName.c_str(), size );
|
2023-07-04 16:01:12 +00:00
|
|
|
else
|
|
|
|
wxFAIL_MSG( wxT( "Plot type missing AC_PHASE or SPT_SP_AMP bit" ) );
|
|
|
|
|
|
|
|
break;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-06-18 15:23:38 +00:00
|
|
|
case ST_DC:
|
2023-09-22 20:40:35 +00:00
|
|
|
data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), -1 );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_NOISE:
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_TRAN:
|
|
|
|
case ST_FFT:
|
2023-09-22 20:40:35 +00:00
|
|
|
data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str(), size );
|
2023-06-18 15:23:38 +00:00
|
|
|
break;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-06-18 15:23:38 +00:00
|
|
|
default:
|
|
|
|
wxFAIL_MSG( wxT( "Unhandled plot type" ) );
|
2023-06-15 12:39:04 +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( simType == ST_DC
|
2023-07-09 22:00:25 +00:00
|
|
|
&& circuitModel()->ParseDCCommand( aPlotTab->GetSimCommand(), &source1, &source2 )
|
|
|
|
&& !source2.m_source.IsEmpty() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
// Source 1 is the inner loop, so lets add traces for each Source 2 (outer loop) step
|
|
|
|
SPICE_VALUE v = source2.m_vstart;
|
|
|
|
|
|
|
|
size_t offset = 0;
|
|
|
|
size_t outer = ( size_t )( ( source2.m_vend - v ) / source2.m_vincrement ).ToDouble();
|
2023-09-22 20:40:35 +00:00
|
|
|
size_t inner = aDataX->size() / ( outer + 1 );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-09-22 20:40:35 +00:00
|
|
|
wxASSERT( aDataX->size() % ( outer + 1 ) == 0 );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
for( size_t idx = 0; idx <= outer; idx++ )
|
|
|
|
{
|
2023-10-03 11:55:19 +00:00
|
|
|
if( TRACE* trace = aPlotTab->GetOrAddTrace( aVectorName, aTraceType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( data_y.size() >= size )
|
|
|
|
{
|
2023-09-22 20:40:35 +00:00
|
|
|
std::vector<double> sub_x( aDataX->begin() + offset,
|
|
|
|
aDataX->begin() + offset + inner );
|
2023-06-15 12:39:04 +00:00
|
|
|
std::vector<double> sub_y( data_y.begin() + offset,
|
|
|
|
data_y.begin() + offset + inner );
|
|
|
|
|
2023-07-13 15:03:40 +00:00
|
|
|
aPlotTab->SetTraceData( trace, sub_x, sub_y );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
v = v + source2.m_vincrement;
|
|
|
|
offset += inner;
|
|
|
|
}
|
|
|
|
}
|
2023-10-03 11:55:19 +00:00
|
|
|
else if( TRACE* trace = aPlotTab->GetOrAddTrace( aVectorName, aTraceType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( data_y.size() >= size )
|
2023-09-22 20:40:35 +00:00
|
|
|
aPlotTab->SetTraceData( trace, *aDataX, data_y );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::updateSignalsGrid()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
for( int row = 0; row < m_signalsGrid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
wxString signalName = m_signalsGrid->GetCellValue( row, COL_SIGNAL_NAME );
|
|
|
|
int traceType = SPT_UNKNOWN;
|
2023-07-09 22:00:25 +00:00
|
|
|
wxString vectorName = vectorNameFromSignalName( plotTab, signalName, &traceType );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( TRACE* trace = plotTab ? plotTab->GetTrace( vectorName, traceType ) : nullptr )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_SHOW, wxS( "1" ) );
|
|
|
|
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new GRID_CELL_COLOR_RENDERER( this ) );
|
|
|
|
attr->SetEditor( new GRID_CELL_COLOR_SELECTOR( this, m_signalsGrid ) );
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_signalsGrid->SetAttr( row, COL_SIGNAL_COLOR, attr );
|
|
|
|
|
|
|
|
KIGFX::COLOR4D color( trace->GetPen().GetColour() );
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_COLOR, color.ToCSSString() );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_1, attr );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetRenderer( new wxGridCellBoolRenderer() );
|
|
|
|
attr->SetReadOnly(); // not really; we delegate interactivity to GRID_TRICKS
|
|
|
|
attr->SetAlignment( wxALIGN_CENTER, wxALIGN_CENTER );
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_2, attr );
|
|
|
|
|
|
|
|
if( trace->HasCursor( 1 ) )
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_CURSOR_1, wxS( "1" ) );
|
|
|
|
else
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_CURSOR_1, wxEmptyString );
|
|
|
|
|
|
|
|
if( trace->HasCursor( 2 ) )
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_CURSOR_2, wxS( "1" ) );
|
|
|
|
else
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_CURSOR_2, wxEmptyString );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_SHOW, wxEmptyString );
|
|
|
|
|
|
|
|
wxGridCellAttr* attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_signalsGrid->SetAttr( row, COL_SIGNAL_COLOR, attr );
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_SIGNAL_COLOR, wxEmptyString );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_1, attr );
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_CURSOR_1, wxEmptyString );
|
|
|
|
|
|
|
|
attr = new wxGridCellAttr;
|
|
|
|
attr->SetReadOnly();
|
|
|
|
m_signalsGrid->SetAttr( row, COL_CURSOR_2, attr );
|
|
|
|
m_signalsGrid->SetCellValue( row, COL_CURSOR_2, wxEmptyString );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::applyUserDefinedSignals()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
auto quoteNetNames =
|
|
|
|
[&]( wxString aExpression ) -> wxString
|
|
|
|
{
|
|
|
|
for( const auto& [netname, quotedNetname] : m_quotedNetnames )
|
|
|
|
aExpression.Replace( netname, quotedNetname );
|
|
|
|
|
|
|
|
return aExpression;
|
|
|
|
};
|
|
|
|
|
|
|
|
for( const auto& [ id, signal ] : m_userDefinedSignals )
|
|
|
|
{
|
|
|
|
std::string cmd = "let user{} = {}";
|
|
|
|
|
|
|
|
simulator()->Command( "echo " + fmt::format( cmd, id, signal.ToStdString() ) );
|
|
|
|
simulator()->Command( fmt::format( cmd, id, quoteNetNames( signal ).ToStdString() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::applyTuners()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
wxString errors;
|
|
|
|
WX_STRING_REPORTER reporter( &errors );
|
|
|
|
|
|
|
|
for( const TUNER_SLIDER* tuner : m_tuners )
|
|
|
|
{
|
|
|
|
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 )
|
|
|
|
{
|
|
|
|
reporter.Report( wxString::Format( _( "%s not found" ), ref ) );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SPICE_ITEM* item = GetExporter()->FindItem( tuner->GetSymbolRef().ToStdString() );
|
|
|
|
|
|
|
|
if( !item || !item->model->GetTunerParam() )
|
|
|
|
{
|
|
|
|
reporter.Report( wxString::Format( _( "%s is not tunable" ), ref ) );
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
double floatVal = tuner->GetValue().ToDouble();
|
|
|
|
|
|
|
|
simulator()->Command( item->model->SpiceGenerator().TunerCommand( *item, floatVal ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( reporter.HasMessage() )
|
|
|
|
DisplayErrorMessage( this, _( "Could not apply tuned value(s):" ) + wxS( "\n" ) + errors );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
bool SIMULATOR_FRAME_UI::LoadWorkbook( const wxString& aPath )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
wxTextFile file( aPath );
|
|
|
|
|
|
|
|
if( !file.Open() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
wxString firstLine = file.GetFirstLine();
|
2023-07-14 16:44:05 +00:00
|
|
|
long dummy;
|
|
|
|
bool legacy = firstLine.StartsWith( wxT( "version " ) ) || firstLine.ToLong( &dummy );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
file.Close();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
m_plotNotebook->DeleteAllPages();
|
|
|
|
m_userDefinedSignals.clear();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( legacy )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
if( !loadLegacyWorkbook( aPath ) )
|
|
|
|
return false;
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-07-14 16:44:05 +00:00
|
|
|
else
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
if( !loadJsonWorkbook( aPath ) )
|
|
|
|
return false;
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
rebuildSignalsList();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
rebuildSignalsGrid( m_filter->GetValue() );
|
|
|
|
updateSignalsGrid();
|
|
|
|
updatePlotCursors();
|
|
|
|
rebuildMeasurementsGrid();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
wxFileName filename( aPath );
|
|
|
|
filename.MakeRelativeTo( m_schematicFrame->Prj().GetProjectPath() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
// Remember the loaded workbook filename.
|
|
|
|
simulator()->Settings()->SetWorkbookFilename( filename.GetFullPath() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
return true;
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
bool SIMULATOR_FRAME_UI::loadJsonWorkbook( const wxString& aPath )
|
|
|
|
{
|
|
|
|
wxFFileInputStream fp( aPath, wxT( "rt" ) );
|
|
|
|
wxStdInputStream fstream( fp );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( !fp.IsOk() )
|
|
|
|
return false;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
nlohmann::json js = nlohmann::json::parse( fstream, nullptr, true, true );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
std::map<SIM_PLOT_TAB*, nlohmann::json> traceInfo;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
for( const nlohmann::json& tab_js : js[ "tabs" ] )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
wxString simCommand;
|
|
|
|
int simOptions = NETLIST_EXPORTER_SPICE::OPTION_ADJUST_PASSIVE_VALS;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
for( const nlohmann::json& cmd : tab_js[ "commands" ] )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
if( cmd == ".kicad adjustpaths" )
|
|
|
|
simOptions |= NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS;
|
|
|
|
else if( cmd == ".save all" )
|
|
|
|
simOptions |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES;
|
|
|
|
else if( cmd == ".probe alli" )
|
|
|
|
simOptions |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS;
|
|
|
|
else if( cmd == ".probe allp" )
|
|
|
|
simOptions |= NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS;
|
|
|
|
else
|
2023-10-12 23:07:12 +00:00
|
|
|
simCommand += wxString( cmd.get<wxString>() ).Trim();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
SIM_TAB* simTab = NewSimTab( simCommand );
|
2023-07-14 16:44:05 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( simTab );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
simTab->SetSimOptions( simOptions );
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
if( tab_js.contains( "traces" ) )
|
|
|
|
traceInfo[plotTab] = tab_js[ "traces" ];
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-10-20 16:23:15 +00:00
|
|
|
if( tab_js.contains( "measurements" ) )
|
2023-07-14 16:44:05 +00:00
|
|
|
{
|
|
|
|
for( const nlohmann::json& m_js : tab_js[ "measurements" ] )
|
|
|
|
plotTab->Measurements().emplace_back( m_js[ "expr" ], m_js[ "format" ] );
|
|
|
|
}
|
2023-07-13 22:50:13 +00:00
|
|
|
|
2023-07-14 19:57:55 +00:00
|
|
|
plotTab->SetDottedSecondary( tab_js[ "dottedSecondary" ] );
|
|
|
|
plotTab->ShowGrid( tab_js[ "showGrid" ] );
|
2023-07-17 21:28:05 +00:00
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
if( tab_js.contains( "fixedY1scale" ) )
|
|
|
|
{
|
|
|
|
const nlohmann::json& scale_js = tab_js[ "fixedY1scale" ];
|
|
|
|
plotTab->SetY1Scale( true, scale_js[ "min" ], scale_js[ "max" ] );
|
2023-07-20 16:41:23 +00:00
|
|
|
plotTab->GetPlotWin()->LockY( true );
|
2023-07-19 15:25:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( tab_js.contains( "fixedY2scale" ) )
|
|
|
|
{
|
|
|
|
const nlohmann::json& scale_js = tab_js[ "fixedY2scale" ];
|
|
|
|
plotTab->SetY2Scale( true, scale_js[ "min" ], scale_js[ "max" ] );
|
2023-07-20 16:41:23 +00:00
|
|
|
plotTab->GetPlotWin()->LockY( true );
|
2023-07-19 15:25:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( tab_js.contains( "fixedY3scale" ) )
|
|
|
|
{
|
2024-02-08 22:48:12 +00:00
|
|
|
plotTab->EnsureThirdYAxisExists();
|
2023-07-19 15:25:57 +00:00
|
|
|
const nlohmann::json& scale_js = tab_js[ "fixedY3scale" ];
|
|
|
|
plotTab->SetY3Scale( true, scale_js[ "min" ], scale_js[ "max" ] );
|
2023-07-20 16:41:23 +00:00
|
|
|
plotTab->GetPlotWin()->LockY( true );
|
2023-07-19 15:25:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-17 21:28:05 +00:00
|
|
|
if( tab_js.contains( "legend" ) )
|
|
|
|
{
|
|
|
|
const nlohmann::json& legend_js = tab_js[ "legend" ];
|
|
|
|
plotTab->SetLegendPosition( wxPoint( legend_js[ "x" ], legend_js[ "y" ] ) );
|
|
|
|
plotTab->ShowLegend( true );
|
|
|
|
}
|
2023-07-19 15:25:57 +00:00
|
|
|
|
|
|
|
if( tab_js.contains( "margins" ) )
|
|
|
|
{
|
|
|
|
const nlohmann::json& margins_js = tab_js[ "margins" ];
|
|
|
|
plotTab->GetPlotWin()->SetMargins( margins_js[ "top" ],
|
|
|
|
margins_js[ "right" ],
|
|
|
|
margins_js[ "bottom" ],
|
|
|
|
margins_js[ "left" ] );
|
|
|
|
}
|
2023-07-13 22:50:13 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
int ii = 0;
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( js.contains( "user_defined_signals" ) )
|
|
|
|
{
|
|
|
|
for( const nlohmann::json& signal_js : js[ "user_defined_signals" ] )
|
2023-10-12 23:07:12 +00:00
|
|
|
m_userDefinedSignals[ii++] = wxString( signal_js.get<wxString>() );
|
2023-07-14 16:44:05 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
auto addCursor =
|
|
|
|
[this]( SIM_PLOT_TAB* aPlotTab, TRACE* aTrace, const wxString& aSignalName,
|
|
|
|
int aCursorId, const nlohmann::json& aCursor_js )
|
2023-07-13 22:50:13 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
if( aCursorId == 1 || aCursorId == 2 )
|
|
|
|
{
|
|
|
|
CURSOR* cursor = new CURSOR( aTrace, aPlotTab );
|
2023-07-13 22:50:13 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
cursor->SetName( aSignalName );
|
|
|
|
cursor->SetPen( wxPen( aTrace->GetTraceColour() ) );
|
|
|
|
cursor->SetCoordX( aCursor_js[ "position" ] );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
aTrace->SetCursor( aCursorId, cursor );
|
|
|
|
aPlotTab->GetPlotWin()->AddLayer( cursor );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
m_cursorFormats[aCursorId-1][0].FromString( aCursor_js[ "x_format" ] );
|
|
|
|
m_cursorFormats[aCursorId-1][1].FromString( aCursor_js[ "y_format" ] );
|
|
|
|
};
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
for( const auto& [ plotTab, traces_js ] : traceInfo )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
for( const nlohmann::json& trace_js : traces_js )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
wxString signalName = trace_js[ "signal" ];
|
|
|
|
wxString vectorName = vectorNameFromSignalName( plotTab, signalName, nullptr );
|
2023-10-03 11:55:19 +00:00
|
|
|
TRACE* trace = plotTab->GetOrAddTrace( vectorName, trace_js[ "trace_type" ] );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( trace )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
if( trace_js.contains( "cursor1" ) )
|
|
|
|
addCursor( plotTab, trace, signalName, 1, trace_js[ "cursor1" ] );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( trace_js.contains( "cursor2" ) )
|
|
|
|
addCursor( plotTab, trace, signalName, 2, trace_js[ "cursor2" ] );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( trace_js.contains( "cursorD" ) )
|
|
|
|
addCursor( plotTab, trace, signalName, 3, trace_js[ "cursorD" ] );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( trace_js.contains( "color" ) )
|
|
|
|
{
|
|
|
|
wxColour color;
|
2023-10-12 23:07:12 +00:00
|
|
|
color.Set( wxString( trace_js["color"].get<wxString>() ) );
|
2023-07-14 16:44:05 +00:00
|
|
|
trace->SetTraceColour( color );
|
|
|
|
plotTab->UpdateTraceStyle( trace );
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
plotTab->UpdatePlotColors();
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( SIM_TAB* simTab = GetCurrentSimTab() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
m_simulatorFrame->LoadSimulator( simTab->GetSimCommand(), simTab->GetSimOptions() );
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( 0 ) );
|
2023-10-16 21:04:01 +00:00
|
|
|
|
|
|
|
wxCHECK( simTab, false );
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
simTab->SetLastSchTextSimCommand( js[ "last_sch_text_sim_command" ] );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
2023-07-14 16:44:05 +00:00
|
|
|
catch( nlohmann::json::parse_error& error )
|
|
|
|
{
|
|
|
|
wxLogTrace( traceSettings, wxT( "Json parse error reading %s: %s" ), aPath, error.what() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
return false;
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
bool SIMULATOR_FRAME_UI::SaveWorkbook( const wxString& aPath )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-10-20 16:23:15 +00:00
|
|
|
updateMeasurementsFromGrid();
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
wxFileName filename = aPath;
|
2023-12-28 02:10:01 +00:00
|
|
|
filename.SetExt( FILEEXT::WorkbookFileExtension );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
wxFile file;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
file.Create( filename.GetFullPath(), true /* overwrite */ );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( !file.IsOpened() )
|
|
|
|
return false;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
nlohmann::json tabs_js = nlohmann::json::array();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
for( size_t i = 0; i < m_plotNotebook->GetPageCount(); i++ )
|
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( i ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !simTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
continue;
|
|
|
|
|
2023-07-14 20:02:51 +00:00
|
|
|
SIM_TYPE simType = simTab->GetSimType();
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
nlohmann::json commands_js = nlohmann::json::array();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
commands_js.push_back( simTab->GetSimCommand() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
int options = simTab->GetSimOptions();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-17 14:19:22 +00:00
|
|
|
if( options & NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS )
|
2023-07-14 16:44:05 +00:00
|
|
|
commands_js.push_back( ".kicad adjustpaths" );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-17 14:19:22 +00:00
|
|
|
if( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES )
|
2023-07-14 16:44:05 +00:00
|
|
|
commands_js.push_back( ".save all" );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-17 14:19:22 +00:00
|
|
|
if( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS )
|
2023-07-14 16:44:05 +00:00
|
|
|
commands_js.push_back( ".probe alli" );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-17 14:19:22 +00:00
|
|
|
if( options & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS )
|
2023-07-14 16:44:05 +00:00
|
|
|
commands_js.push_back( ".probe allp" );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 20:02:51 +00:00
|
|
|
nlohmann::json tab_js = nlohmann::json(
|
|
|
|
{ { "analysis", SPICE_SIMULATOR::TypeToName( simType, true ) },
|
|
|
|
{ "commands", commands_js } } );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( simTab ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
nlohmann::json traces_js = nlohmann::json::array();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
auto findSignalName =
|
|
|
|
[&]( const wxString& aVectorName ) -> wxString
|
|
|
|
{
|
|
|
|
for( const auto& [ id, signal ] : m_userDefinedSignals )
|
|
|
|
{
|
|
|
|
if( aVectorName == vectorNameFromSignalId( id ) )
|
|
|
|
return signal;
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
return aVectorName;
|
|
|
|
};
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
for( const auto& [name, trace] : plotTab->GetTraces() )
|
|
|
|
{
|
|
|
|
nlohmann::json trace_js = nlohmann::json(
|
2023-07-14 20:02:51 +00:00
|
|
|
{ { "trace_type", (int) trace->GetType() },
|
|
|
|
{ "signal", findSignalName( trace->GetName() ) },
|
|
|
|
{ "color", COLOR4D( trace->GetTraceColour() ).ToCSSString() } } );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( CURSOR* cursor = trace->GetCursor( 1 ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
trace_js["cursor1"] = nlohmann::json(
|
|
|
|
{ { "position", cursor->GetCoords().x },
|
|
|
|
{ "x_format", m_cursorFormats[0][0].ToString() },
|
|
|
|
{ "y_format", m_cursorFormats[0][1].ToString() } } );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( CURSOR* cursor = trace->GetCursor( 2 ) )
|
|
|
|
{
|
|
|
|
trace_js["cursor2"] = nlohmann::json(
|
|
|
|
{ { "position", cursor->GetCoords().x },
|
|
|
|
{ "x_format", m_cursorFormats[1][0].ToString() },
|
|
|
|
{ "y_format", m_cursorFormats[1][1].ToString() } } );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( trace->GetCursor( 1 ) || trace->GetCursor( 2 ) )
|
|
|
|
{
|
|
|
|
trace_js["cursorD"] = nlohmann::json(
|
|
|
|
{ { "x_format", m_cursorFormats[2][0].ToString() },
|
|
|
|
{ "y_format", m_cursorFormats[2][1].ToString() } } );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
traces_js.push_back( trace_js );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
nlohmann::json measurements_js = nlohmann::json::array();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
for( const auto& [ measurement, format ] : plotTab->Measurements() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-14 16:44:05 +00:00
|
|
|
measurements_js.push_back( nlohmann::json( { { "expr", measurement },
|
|
|
|
{ "format", format } } ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
tab_js[ "traces" ] = traces_js;
|
|
|
|
tab_js[ "measurements" ] = measurements_js;
|
|
|
|
tab_js[ "dottedSecondary" ] = plotTab->GetDottedSecondary();
|
|
|
|
tab_js[ "showGrid" ] = plotTab->IsGridShown();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
double min, max;
|
|
|
|
|
|
|
|
if( plotTab->GetY1Scale( &min, &max ) )
|
|
|
|
tab_js[ "fixedY1scale" ] = nlohmann::json( { { "min", min }, { "max", max } } );
|
|
|
|
|
|
|
|
if( plotTab->GetY2Scale( &min, &max ) )
|
|
|
|
tab_js[ "fixedY2scale" ] = nlohmann::json( { { "min", min }, { "max", max } } );
|
|
|
|
|
|
|
|
if( plotTab->GetY3Scale( &min, &max ) )
|
|
|
|
tab_js[ "fixedY3scale" ] = nlohmann::json( { { "min", min }, { "max", max } } );
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
if( plotTab->IsLegendShown() )
|
|
|
|
{
|
|
|
|
tab_js[ "legend" ] = nlohmann::json( { { "x", plotTab->GetLegendPosition().x },
|
|
|
|
{ "y", plotTab->GetLegendPosition().y } } );
|
|
|
|
}
|
2023-07-19 15:25:57 +00:00
|
|
|
|
|
|
|
mpWindow* plotWin = plotTab->GetPlotWin();
|
|
|
|
|
|
|
|
tab_js[ "margins" ] = nlohmann::json( { { "left", plotWin->GetMarginLeft() },
|
|
|
|
{ "right", plotWin->GetMarginRight() },
|
|
|
|
{ "top", plotWin->GetMarginTop() },
|
|
|
|
{ "bottom", plotWin->GetMarginBottom() } } );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
tabs_js.push_back( tab_js );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
nlohmann::json userDefinedSignals_js = nlohmann::json::array();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
for( const auto& [ id, signal ] : m_userDefinedSignals )
|
2023-07-14 16:44:05 +00:00
|
|
|
userDefinedSignals_js.push_back( signal );
|
|
|
|
|
|
|
|
nlohmann::json js = nlohmann::json( { { "version", 6 },
|
|
|
|
{ "tabs", tabs_js },
|
|
|
|
{ "user_defined_signals", userDefinedSignals_js } } );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
// Store the value of any simulation command found on the schematic sheet in a SCH_TEXT
|
|
|
|
// object. If this changes we want to warn the user and ask them if they want to update
|
|
|
|
// the corresponding panel's sim command.
|
|
|
|
if( m_plotNotebook->GetPageCount() > 0 )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* simTab = dynamic_cast<SIM_TAB*>( m_plotNotebook->GetPage( 0 ) );
|
2023-07-14 16:44:05 +00:00
|
|
|
js[ "last_sch_text_sim_command" ] = simTab->GetLastSchTextSimCommand();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
std::stringstream buffer;
|
|
|
|
buffer << std::setw( 2 ) << js << std::endl;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-14 16:44:05 +00:00
|
|
|
bool res = file.Write( buffer.str() );
|
2023-06-15 12:39:04 +00:00
|
|
|
file.Close();
|
|
|
|
|
|
|
|
// Store the filename of the last saved workbook.
|
|
|
|
if( res )
|
|
|
|
{
|
|
|
|
filename.MakeRelativeTo( m_schematicFrame->Prj().GetProjectPath() );
|
|
|
|
simulator()->Settings()->SetWorkbookFilename( filename.GetFullPath() );
|
|
|
|
}
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
SIM_TRACE_TYPE SIMULATOR_FRAME_UI::getXAxisType( SIM_TYPE aType ) const
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
switch( aType )
|
|
|
|
{
|
|
|
|
/// @todo SPT_LOG_FREQUENCY
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_AC: return SPT_LIN_FREQUENCY;
|
|
|
|
case ST_SP: return SPT_LIN_FREQUENCY;
|
|
|
|
case ST_FFT: return SPT_LIN_FREQUENCY;
|
|
|
|
case ST_DC: return SPT_SWEEP;
|
|
|
|
case ST_TRAN: return SPT_TIME;
|
|
|
|
case ST_NOISE: return SPT_LIN_FREQUENCY;
|
|
|
|
default: wxFAIL_MSG( wxS( "Unhandled simulation type" ) ); return SPT_UNKNOWN;
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
wxString SIMULATOR_FRAME_UI::getNoiseSource() const
|
2023-07-03 22:11:43 +00:00
|
|
|
{
|
|
|
|
wxString output;
|
|
|
|
wxString ref;
|
|
|
|
wxString source;
|
|
|
|
wxString scale;
|
|
|
|
SPICE_VALUE pts;
|
|
|
|
SPICE_VALUE fStart;
|
|
|
|
SPICE_VALUE fStop;
|
2023-07-04 10:04:20 +00:00
|
|
|
bool saveAll;
|
2023-07-03 22:11:43 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( GetCurrentSimTab() )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
circuitModel()->ParseNoiseCommand( GetCurrentSimTab()->GetSimCommand(), &output, &ref,
|
2023-07-05 17:25:52 +00:00
|
|
|
&source, &scale, &pts, &fStart, &fStop, &saveAll );
|
|
|
|
}
|
2023-07-03 22:11:43 +00:00
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::ToggleDarkModePlots()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_darkMode = !m_darkMode;
|
|
|
|
|
|
|
|
// Rebuild the color list to plot traces
|
|
|
|
SIM_PLOT_COLORS::FillDefaultColorList( m_darkMode );
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
// Now send changes to all SIM_PLOT_TAB
|
2023-06-15 12:39:04 +00:00
|
|
|
for( size_t page = 0; page < m_plotNotebook->GetPageCount(); page++ )
|
|
|
|
{
|
|
|
|
wxWindow* curPage = m_plotNotebook->GetPage( page );
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
// ensure it is truly a plot plotTab and not the (zero plots) placeholder
|
|
|
|
// which is only SIM_TAB
|
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( curPage );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( plotTab )
|
|
|
|
plotTab->UpdatePlotColors();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onPlotClose( wxAuiNotebookEvent& event )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onPlotClosed( wxAuiNotebookEvent& event )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
CallAfter( [this]()
|
|
|
|
{
|
|
|
|
rebuildSignalsList();
|
|
|
|
rebuildSignalsGrid( m_filter->GetValue() );
|
|
|
|
updatePlotCursors();
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* panel = GetCurrentSimTab();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-04 15:53:44 +00:00
|
|
|
if( !panel || panel->GetSimType() != ST_OP )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
SCHEMATIC& schematic = m_schematicFrame->Schematic();
|
|
|
|
schematic.ClearOperatingPoints();
|
|
|
|
m_schematicFrame->RefreshOperatingPointDisplay();
|
|
|
|
m_schematicFrame->GetCanvas()->Refresh();
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-20 16:23:15 +00:00
|
|
|
void SIMULATOR_FRAME_UI::updateMeasurementsFromGrid()
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
std::vector<std::pair<wxString, wxString>>& measurements = plotTab->Measurements();
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
measurements.clear();
|
|
|
|
|
|
|
|
for( int row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
|
|
|
|
{
|
|
|
|
if( !m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ).IsEmpty() )
|
|
|
|
{
|
|
|
|
measurements.emplace_back( m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT ),
|
|
|
|
m_measurementsGrid->GetCellValue( row, COL_MEASUREMENT_FORMAT ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-10-20 16:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void SIMULATOR_FRAME_UI::onPlotChanging( wxAuiNotebookEvent& event )
|
|
|
|
{
|
|
|
|
updateMeasurementsFromGrid();
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnPlotSettingsChanged()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
rebuildSignalsList();
|
|
|
|
rebuildSignalsGrid( m_filter->GetValue() );
|
|
|
|
updatePlotCursors();
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
rebuildMeasurementsGrid();
|
|
|
|
|
|
|
|
for( int row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
|
|
|
|
UpdateMeasurement( row );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onPlotChanged( wxAuiNotebookEvent& event )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( SIM_TAB* simTab = GetCurrentSimTab() )
|
|
|
|
simulator()->Command( "setplot " + simTab->GetSpicePlotName().ToStdString() );
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
OnPlotSettingsChanged();
|
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::rebuildMeasurementsGrid()
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
|
|
|
m_measurementsGrid->ClearRows();
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
for( const auto& [ measurement, format ] : plotTab->Measurements() )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
|
|
|
int row = m_measurementsGrid->GetNumberRows();
|
|
|
|
m_measurementsGrid->AppendRows();
|
|
|
|
m_measurementsGrid->SetCellValue( row, COL_MEASUREMENT, measurement );
|
|
|
|
m_measurementsGrid->SetCellValue( row, COL_MEASUREMENT_FORMAT, format );
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( plotTab->GetSimType() == ST_TRAN || plotTab->GetSimType() == ST_AC
|
|
|
|
|| plotTab->GetSimType() == ST_DC || plotTab->GetSimType() == ST_SP )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
|
|
|
m_measurementsGrid->AppendRows(); // Empty row at end
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onPlotDragged( wxAuiNotebookEvent& event )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
std::shared_ptr<SPICE_SIMULATOR> SIMULATOR_FRAME_UI::simulator() const
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
return m_simulatorFrame->GetSimulator();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
std::shared_ptr<SPICE_CIRCUIT_MODEL> SIMULATOR_FRAME_UI::circuitModel() const
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
return m_simulatorFrame->GetCircuitModel();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::updatePlotCursors()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
SUPPRESS_GRID_CELL_EVENTS raii( this );
|
|
|
|
|
|
|
|
m_cursorsGrid->ClearRows();
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !plotTab )
|
2023-06-15 12:39:04 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
// Update cursor values
|
|
|
|
CURSOR* cursor1 = nullptr;
|
|
|
|
wxString cursor1Name;
|
|
|
|
wxString cursor1Units;
|
|
|
|
CURSOR* cursor2 = nullptr;
|
|
|
|
wxString cursor2Name;
|
|
|
|
wxString cursor2Units;
|
|
|
|
|
|
|
|
auto getUnitsY =
|
|
|
|
[&]( TRACE* aTrace ) -> wxString
|
|
|
|
{
|
|
|
|
if( ( aTrace->GetType() & SPT_AC_PHASE ) || ( aTrace->GetType() & SPT_CURRENT ) )
|
2023-07-09 22:00:25 +00:00
|
|
|
return plotTab->GetUnitsY2();
|
2023-06-15 12:39:04 +00:00
|
|
|
else if( aTrace->GetType() & SPT_POWER )
|
2023-07-09 22:00:25 +00:00
|
|
|
return plotTab->GetUnitsY3();
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
2023-07-09 22:00:25 +00:00
|
|
|
return plotTab->GetUnitsY1();
|
2023-06-15 12:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto getNameY =
|
|
|
|
[&]( TRACE* aTrace ) -> wxString
|
|
|
|
{
|
|
|
|
if( ( aTrace->GetType() & SPT_AC_PHASE ) || ( aTrace->GetType() & SPT_CURRENT ) )
|
2023-07-09 22:00:25 +00:00
|
|
|
return plotTab->GetLabelY2();
|
2023-06-15 12:39:04 +00:00
|
|
|
else if( aTrace->GetType() & SPT_POWER )
|
2023-07-09 22:00:25 +00:00
|
|
|
return plotTab->GetLabelY3();
|
2023-06-15 12:39:04 +00:00
|
|
|
else
|
2023-07-09 22:00:25 +00:00
|
|
|
return plotTab->GetLabelY1();
|
2023-06-15 12:39:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
auto formatValue =
|
|
|
|
[this]( double aValue, int aCursorId, int aCol ) -> wxString
|
|
|
|
{
|
2023-09-17 18:23:20 +00:00
|
|
|
if( ( !m_simulatorFrame->SimFinished() && aCol == 1 ) || std::isnan( aValue ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
return wxS( "--" );
|
|
|
|
else
|
|
|
|
return SPICE_VALUE( aValue ).ToString( m_cursorFormats[ aCursorId ][ aCol ] );
|
|
|
|
};
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
for( const auto& [name, trace] : plotTab->GetTraces() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( CURSOR* cursor = trace->GetCursor( 1 ) )
|
|
|
|
{
|
|
|
|
cursor1 = cursor;
|
|
|
|
cursor1Name = getNameY( trace );
|
|
|
|
cursor1Units = getUnitsY( trace );
|
|
|
|
|
|
|
|
wxRealPoint coords = cursor->GetCoords();
|
|
|
|
int row = m_cursorsGrid->GetNumberRows();
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
m_cursorFormats[0][0].UpdateUnits( plotTab->GetUnitsX() );
|
2023-06-15 12:39:04 +00:00
|
|
|
m_cursorFormats[0][1].UpdateUnits( cursor1Units );
|
|
|
|
|
|
|
|
m_cursorsGrid->AppendRows( 1 );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_NAME, wxS( "1" ) );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_SIGNAL, cursor->GetName() );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_X, formatValue( coords.x, 0, 0 ) );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_Y, formatValue( coords.y, 0, 1 ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
for( const auto& [name, trace] : plotTab->GetTraces() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
if( CURSOR* cursor = trace->GetCursor( 2 ) )
|
|
|
|
{
|
|
|
|
cursor2 = cursor;
|
|
|
|
cursor2Name = getNameY( trace );
|
|
|
|
cursor2Units = getUnitsY( trace );
|
|
|
|
|
|
|
|
wxRealPoint coords = cursor->GetCoords();
|
|
|
|
int row = m_cursorsGrid->GetNumberRows();
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
m_cursorFormats[1][0].UpdateUnits( plotTab->GetUnitsX() );
|
2023-06-15 12:39:04 +00:00
|
|
|
m_cursorFormats[1][1].UpdateUnits( cursor2Units );
|
|
|
|
|
|
|
|
m_cursorsGrid->AppendRows( 1 );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_NAME, wxS( "2" ) );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_SIGNAL, cursor->GetName() );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_X, formatValue( coords.x, 1, 0 ) );
|
|
|
|
m_cursorsGrid->SetCellValue( row, COL_CURSOR_Y, formatValue( coords.y, 1, 1 ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( cursor1 && cursor2 && cursor1Units == cursor2Units )
|
|
|
|
{
|
|
|
|
wxRealPoint coords = cursor2->GetCoords() - cursor1->GetCoords();
|
|
|
|
wxString signal;
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
m_cursorFormats[2][0].UpdateUnits( plotTab->GetUnitsX() );
|
2023-06-15 12:39:04 +00:00
|
|
|
m_cursorFormats[2][1].UpdateUnits( cursor1Units );
|
|
|
|
|
|
|
|
if( cursor1->GetName() == cursor2->GetName() )
|
|
|
|
signal = wxString::Format( wxS( "%s[2 - 1]" ), cursor2->GetName() );
|
|
|
|
else
|
|
|
|
signal = wxString::Format( wxS( "%s - %s" ), cursor2->GetName(), cursor1->GetName() );
|
|
|
|
|
|
|
|
m_cursorsGrid->AppendRows( 1 );
|
|
|
|
m_cursorsGrid->SetCellValue( 2, COL_CURSOR_NAME, _( "Diff" ) );
|
|
|
|
m_cursorsGrid->SetCellValue( 2, COL_CURSOR_SIGNAL, signal );
|
|
|
|
m_cursorsGrid->SetCellValue( 2, COL_CURSOR_X, formatValue( coords.x, 2, 0 ) );
|
|
|
|
m_cursorsGrid->SetCellValue( 2, COL_CURSOR_Y, formatValue( coords.y, 2, 1 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set up the labels
|
2023-07-09 22:00:25 +00:00
|
|
|
m_cursorsGrid->SetColLabelValue( COL_CURSOR_X, plotTab->GetLabelX() );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
wxString valColName = _( "Value" );
|
|
|
|
|
|
|
|
if( !cursor1Name.IsEmpty() )
|
|
|
|
{
|
|
|
|
if( cursor2Name.IsEmpty() || cursor1Name == cursor2Name )
|
|
|
|
valColName = cursor1Name;
|
|
|
|
}
|
|
|
|
else if( !cursor2Name.IsEmpty() )
|
|
|
|
{
|
|
|
|
valColName = cursor2Name;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_cursorsGrid->SetColLabelValue( COL_CURSOR_Y, valColName );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::onPlotCursorUpdate( wxCommandEvent& aEvent )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
updatePlotCursors();
|
2023-10-21 13:26:17 +00:00
|
|
|
OnModify();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnSimUpdate()
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-09 22:00:25 +00:00
|
|
|
if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( GetCurrentSimTab() ) )
|
|
|
|
plotTab->ResetScales( true );
|
2023-06-18 15:23:38 +00:00
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
m_simConsole->Clear();
|
|
|
|
|
|
|
|
// Do not export netlist, it is already stored in the simulator
|
|
|
|
applyTuners();
|
2023-06-18 15:23:38 +00:00
|
|
|
|
|
|
|
m_refreshTimer.Start( REFRESH_INTERVAL, wxTIMER_ONE_SHOT );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnSimReport( const wxString& aMsg )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_simConsole->AppendText( aMsg + "\n" );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
std::vector<wxString> SIMULATOR_FRAME_UI::SimPlotVectors() const
|
2023-07-04 10:04:20 +00:00
|
|
|
{
|
|
|
|
std::vector<wxString> signals;
|
|
|
|
|
|
|
|
for( const std::string& vec : simulator()->AllVectors() )
|
|
|
|
signals.emplace_back( vec );
|
|
|
|
|
|
|
|
return signals;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
std::vector<wxString> SIMULATOR_FRAME_UI::Signals() const
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
|
|
|
std::vector<wxString> signals;
|
|
|
|
|
|
|
|
for( const wxString& signal : m_signals )
|
|
|
|
signals.emplace_back( signal );
|
|
|
|
|
|
|
|
for( const auto& [ id, signal ] : m_userDefinedSignals )
|
|
|
|
signals.emplace_back( signal );
|
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
sortSignals( signals );
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
return signals;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnSimRefresh( bool aFinal )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-10-03 11:55:29 +00:00
|
|
|
if( aFinal )
|
|
|
|
m_refreshTimer.Stop();
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_TAB* simTab = GetCurrentSimTab();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
if( !simTab )
|
2023-07-05 17:25:52 +00:00
|
|
|
return;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
SIM_TYPE simType = simTab->GetSimType();
|
|
|
|
wxString msg;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
if( aFinal )
|
|
|
|
applyUserDefinedSignals();
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
// If there are any signals plotted, update them
|
2023-07-09 22:00:25 +00:00
|
|
|
if( SIM_TAB::IsPlottable( simType ) )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-11-04 15:35:25 +00:00
|
|
|
simTab->SetSpicePlotName( simulator()->CurrentPlotName() );
|
|
|
|
|
2023-07-03 22:11:43 +00:00
|
|
|
if( simType == ST_NOISE && aFinal )
|
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
|
2023-07-05 10:53:19 +00:00
|
|
|
// The simulator will create noise1 & noise2 on the first run, noise3 and noise4
|
|
|
|
// on the second, etc. The first plot for each run contains the spectral density
|
|
|
|
// noise vectors and second contains the integrated noise.
|
2023-07-05 17:25:52 +00:00
|
|
|
long number;
|
|
|
|
simulator()->CurrentPlotName().Mid( 5 ).ToLong( &number );
|
2023-07-04 10:04:20 +00:00
|
|
|
|
|
|
|
for( const std::string& vec : simulator()->AllVectors() )
|
2023-07-03 22:11:43 +00:00
|
|
|
{
|
2023-07-05 10:53:19 +00:00
|
|
|
std::vector<double> val_list = simulator()->GetRealVector( vec, 1 );
|
2023-07-03 22:11:43 +00:00
|
|
|
wxString value = SPICE_VALUE( val_list[ 0 ] ).ToSpiceString();
|
|
|
|
|
|
|
|
msg.Printf( wxS( "%s: %sV\n" ), vec, value );
|
|
|
|
|
|
|
|
m_simConsole->AppendText( msg );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
}
|
2023-07-04 10:04:20 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
simulator()->Command( fmt::format( "setplot noise{}", number - 1 ) );
|
2023-07-09 22:00:25 +00:00
|
|
|
simTab->SetSpicePlotName( simulator()->CurrentPlotName() );
|
2023-07-03 22:11:43 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( simTab );
|
|
|
|
wxCHECK_RET( plotTab, wxT( "not a SIM_PLOT_TAB" ) );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
struct TRACE_INFO
|
|
|
|
{
|
|
|
|
wxString Vector;
|
|
|
|
int TraceType;
|
|
|
|
bool ClearData;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::map<TRACE*, TRACE_INFO> traceMap;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
for( const auto& [ name, trace ] : plotTab->GetTraces() )
|
2023-10-03 11:55:29 +00:00
|
|
|
traceMap[ trace ] = { wxEmptyString, SPT_UNKNOWN, false };
|
|
|
|
|
2023-10-20 13:08:39 +00:00
|
|
|
// NB: m_signals are already broken out into gain/phase, but m_userDefinedSignals are
|
|
|
|
// as the user typed them
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
for( const wxString& signal : m_signals )
|
2023-10-20 13:08:39 +00:00
|
|
|
{
|
|
|
|
int traceType = SPT_UNKNOWN;
|
|
|
|
wxString vectorName = vectorNameFromSignalName( plotTab, signal, &traceType );
|
|
|
|
|
|
|
|
if( TRACE* trace = plotTab->GetTrace( vectorName, traceType ) )
|
|
|
|
traceMap[ trace ] = { vectorName, traceType, false };
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
for( const auto& [ id, signal ] : m_userDefinedSignals )
|
2023-10-20 13:08:39 +00:00
|
|
|
{
|
|
|
|
int traceType = SPT_UNKNOWN;
|
|
|
|
wxString vectorName = vectorNameFromSignalName( plotTab, signal, &traceType );
|
|
|
|
|
|
|
|
if( simType == ST_AC )
|
|
|
|
{
|
|
|
|
int baseType = traceType &= ~( SPT_AC_GAIN | SPT_AC_PHASE );
|
|
|
|
|
|
|
|
for( int subType : { baseType | SPT_AC_GAIN, baseType | SPT_AC_PHASE } )
|
|
|
|
{
|
|
|
|
if( TRACE* trace = plotTab->GetTrace( vectorName, subType ) )
|
|
|
|
traceMap[ trace ] = { vectorName, subType, !aFinal };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( simType == ST_SP )
|
|
|
|
{
|
|
|
|
int baseType = traceType &= ~( SPT_SP_AMP | SPT_AC_PHASE );
|
|
|
|
|
|
|
|
for( int subType : { baseType | SPT_SP_AMP, baseType | SPT_AC_PHASE } )
|
|
|
|
{
|
|
|
|
if( TRACE* trace = plotTab->GetTrace( vectorName, subType ) )
|
|
|
|
traceMap[trace] = { vectorName, subType, !aFinal };
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( TRACE* trace = plotTab->GetTrace( vectorName, traceType ) )
|
|
|
|
traceMap[ trace ] = { vectorName, traceType, !aFinal };
|
|
|
|
}
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
// Two passes so that DC-sweep sub-traces get deleted and re-created:
|
|
|
|
|
|
|
|
for( const auto& [ trace, traceInfo ] : traceMap )
|
|
|
|
{
|
2023-10-03 11:55:29 +00:00
|
|
|
if( traceInfo.Vector.IsEmpty() )
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->DeleteTrace( trace );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
for( const auto& [ trace, info ] : traceMap )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-09-22 20:40:35 +00:00
|
|
|
std::vector<double> data_x;
|
|
|
|
|
2023-10-03 11:55:29 +00:00
|
|
|
if( !info.Vector.IsEmpty() )
|
|
|
|
updateTrace( info.Vector, info.TraceType, plotTab, &data_x, info.ClearData );
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->GetPlotWin()->UpdateAll();
|
2023-06-18 15:23:38 +00:00
|
|
|
|
|
|
|
if( aFinal )
|
2023-09-20 16:34:16 +00:00
|
|
|
{
|
|
|
|
for( int row = 0; row < m_measurementsGrid->GetNumberRows(); ++row )
|
|
|
|
UpdateMeasurement( row );
|
|
|
|
|
2023-07-09 22:00:25 +00:00
|
|
|
plotTab->ResetScales( true );
|
2023-09-20 16:34:16 +00:00
|
|
|
}
|
2023-06-18 15:23:38 +00:00
|
|
|
|
2023-07-20 16:20:57 +00:00
|
|
|
plotTab->GetPlotWin()->Fit();
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
updatePlotCursors();
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
2023-07-13 15:04:06 +00:00
|
|
|
else if( simType == ST_OP && aFinal )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
|
2023-07-04 10:04:20 +00:00
|
|
|
for( const std::string& vec : simulator()->AllVectors() )
|
2023-06-15 12:39:04 +00:00
|
|
|
{
|
2023-07-05 10:53:19 +00:00
|
|
|
std::vector<double> val_list = simulator()->GetRealVector( vec, 1 );
|
2023-12-18 14:43:40 +00:00
|
|
|
|
2024-01-25 15:36:30 +00:00
|
|
|
if( val_list.empty() )
|
|
|
|
continue;
|
2023-12-18 14:43:40 +00:00
|
|
|
|
2023-07-03 22:11:43 +00:00
|
|
|
wxString value = SPICE_VALUE( val_list[ 0 ] ).ToSpiceString();
|
|
|
|
wxString signal;
|
|
|
|
SIM_TRACE_TYPE type = circuitModel()->VectorToSignal( vec, signal );
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-07-03 22:11:43 +00:00
|
|
|
const size_t tab = 25; //characters
|
|
|
|
size_t padding = ( signal.length() < tab ) ? ( tab - signal.length() ) : 1;
|
2023-06-15 12:39:04 +00:00
|
|
|
|
2023-09-19 16:37:20 +00:00
|
|
|
switch( type )
|
|
|
|
{
|
2023-10-20 13:08:39 +00:00
|
|
|
case SPT_VOLTAGE: value.Append( wxS( "V" ) ); break;
|
|
|
|
case SPT_CURRENT: value.Append( wxS( "A" ) ); break;
|
|
|
|
case SPT_POWER: value.Append( wxS( "W" ) ); break;
|
|
|
|
default: value.Append( wxS( "?" ) ); break;
|
2023-09-19 16:37:20 +00:00
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
|
|
|
|
msg.Printf( wxT( "%s%s\n" ),
|
|
|
|
( signal + wxT( ":" ) ).Pad( padding, wxUniChar( ' ' ) ),
|
|
|
|
value );
|
|
|
|
|
|
|
|
m_simConsole->AppendText( msg );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
|
2024-03-04 14:24:00 +00:00
|
|
|
if( type == SPT_VOLTAGE || type == SPT_CURRENT || type == SPT_POWER )
|
2023-06-15 12:39:04 +00:00
|
|
|
signal = signal.SubString( 2, signal.Length() - 2 );
|
|
|
|
|
2024-03-04 14:24:00 +00:00
|
|
|
if( type == SPT_POWER )
|
|
|
|
signal += wxS( ":power" );
|
|
|
|
|
2023-06-15 12:39:04 +00:00
|
|
|
m_schematicFrame->Schematic().SetOperatingPoint( signal, val_list.at( 0 ) );
|
|
|
|
}
|
|
|
|
}
|
2023-07-13 15:04:06 +00:00
|
|
|
else if( simType == ST_PZ && aFinal )
|
|
|
|
{
|
|
|
|
m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
|
|
|
|
m_simConsole->SetInsertionPointEnd();
|
|
|
|
simulator()->Command( "print all" );
|
|
|
|
}
|
2023-06-15 12:39:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-10-21 13:26:17 +00:00
|
|
|
void SIMULATOR_FRAME_UI::OnModify()
|
|
|
|
{
|
|
|
|
m_simulatorFrame->OnModify();
|
|
|
|
}
|