2016-08-11 12:41:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2022-12-05 20:01:36 +00:00
|
|
|
* Copyright (C) 2016-2022 CERN
|
2023-07-05 17:25:52 +00:00
|
|
|
* Copyright (C) 2016-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2016-08-11 12:41:29 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
2016-08-11 12:41:43 +00:00
|
|
|
* as published by the Free Software Foundation; either version 3
|
2016-08-11 12:41:29 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
2016-08-11 12:41:43 +00:00
|
|
|
* https://www.gnu.org/licenses/gpl-3.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 3 license,
|
2016-08-11 12:41:29 +00:00
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
#include "dialog_sim_command.h"
|
2023-07-14 09:21:58 +00:00
|
|
|
#include <sim/spice_circuit_model.h>
|
2021-03-18 19:31:02 +00:00
|
|
|
#include <sim/ngspice.h>
|
2023-07-05 17:25:52 +00:00
|
|
|
#include <sim/simulator_frame.h>
|
2023-08-08 17:19:40 +00:00
|
|
|
#include <sim/sim_plot_tab.h>
|
2016-08-11 12:41:54 +00:00
|
|
|
#include <confirm.h>
|
2024-04-27 19:57:24 +00:00
|
|
|
#include <eda_pattern_match.h>
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2016-08-11 12:42:08 +00:00
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2016-08-11 12:42:08 +00:00
|
|
|
// Helper function to shorten conditions
|
|
|
|
static bool empty( const wxTextEntryBase* aCtrl )
|
|
|
|
{
|
|
|
|
return aCtrl->GetValue().IsEmpty();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-04 15:01:56 +00:00
|
|
|
static void setStringSelection( wxChoice* aCtrl, const wxString& aStr )
|
2021-03-08 10:51:43 +00:00
|
|
|
{
|
|
|
|
aCtrl->SetSelection( aCtrl->FindString( aStr ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-05-04 15:01:56 +00:00
|
|
|
static wxString getStringSelection( const wxChoice* aCtrl )
|
2021-03-08 10:51:43 +00:00
|
|
|
{
|
2024-02-26 18:09:51 +00:00
|
|
|
if( aCtrl->GetSelection() >= 0 )
|
|
|
|
return aCtrl->GetString( aCtrl->GetSelection() );
|
|
|
|
else
|
|
|
|
return wxEmptyString;
|
2021-03-08 10:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
DIALOG_SIM_COMMAND::DIALOG_SIM_COMMAND( SIMULATOR_FRAME* aParent,
|
2023-07-14 09:21:58 +00:00
|
|
|
std::shared_ptr<SPICE_CIRCUIT_MODEL> aCircuitModel,
|
|
|
|
std::shared_ptr<SPICE_SETTINGS>& aSettings ) :
|
2022-12-11 15:49:29 +00:00
|
|
|
DIALOG_SIM_COMMAND_BASE( aParent ),
|
2023-07-05 17:25:52 +00:00
|
|
|
m_simulatorFrame( aParent ),
|
2022-03-28 22:02:49 +00:00
|
|
|
m_circuitModel( aCircuitModel ),
|
2021-03-18 19:31:02 +00:00
|
|
|
m_settings( aSettings ),
|
2021-03-08 10:51:43 +00:00
|
|
|
m_spiceEmptyValidator( true )
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2023-11-01 22:36:38 +00:00
|
|
|
m_simPages->Hide();
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
m_posIntValidator.SetMin( 1 );
|
|
|
|
|
|
|
|
m_acPointsNumber->SetValidator( m_posIntValidator );
|
2016-08-11 12:41:54 +00:00
|
|
|
m_acFreqStart->SetValidator( m_spiceValidator );
|
|
|
|
m_acFreqStop->SetValidator( m_spiceValidator );
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2023-07-04 16:01:12 +00:00
|
|
|
m_spPointsNumber->SetValidator( m_posIntValidator );
|
|
|
|
m_spFreqStart->SetValidator( m_spiceValidator );
|
|
|
|
m_spFreqStop->SetValidator( m_spiceValidator );
|
|
|
|
|
2016-08-11 12:41:54 +00:00
|
|
|
m_dcStart1->SetValidator( m_spiceValidator );
|
|
|
|
m_dcStop1->SetValidator( m_spiceValidator );
|
|
|
|
m_dcIncr1->SetValidator( m_spiceValidator );
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2016-08-11 12:41:54 +00:00
|
|
|
m_dcStart2->SetValidator( m_spiceValidator );
|
|
|
|
m_dcStop2->SetValidator( m_spiceValidator );
|
|
|
|
m_dcIncr2->SetValidator( m_spiceValidator );
|
2016-08-11 12:41:29 +00:00
|
|
|
|
|
|
|
m_noisePointsNumber->SetValidator( m_posIntValidator );
|
2016-08-11 12:41:54 +00:00
|
|
|
m_noiseFreqStart->SetValidator( m_spiceValidator );
|
|
|
|
m_noiseFreqStop->SetValidator( m_spiceValidator );
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2016-08-11 12:41:54 +00:00
|
|
|
m_transStep->SetValidator( m_spiceValidator );
|
|
|
|
m_transFinal->SetValidator( m_spiceValidator );
|
|
|
|
m_transInitial->SetValidator( m_spiceEmptyValidator );
|
2023-04-06 20:48:11 +00:00
|
|
|
m_transMaxStep->SetValidator( m_spiceEmptyValidator );
|
2016-08-11 12:41:36 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
m_inputSignalsFilter->SetDescriptiveText( _( "Filter" ) );
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
wxChar type1 = getStringSelection( m_dcSourceType1 ).Upper().GetChar( 0 );
|
|
|
|
updateDCSources( type1, m_dcSource1 );
|
|
|
|
|
|
|
|
wxChar type2 = getStringSelection( m_dcSourceType2 ).Upper().GetChar( 0 );
|
|
|
|
updateDCSources( type2, m_dcSource2 );
|
|
|
|
|
|
|
|
// NoiseRef is optional
|
|
|
|
m_noiseRef->Append( wxEmptyString );
|
|
|
|
|
|
|
|
for( const std::string& net : m_circuitModel->GetNets() )
|
|
|
|
{
|
2023-07-13 15:04:06 +00:00
|
|
|
m_pzInput->Append( net );
|
|
|
|
m_pzInputRef->Append( net );
|
|
|
|
m_pzOutput->Append( net );
|
|
|
|
m_pzOutputRef->Append( net );
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
m_noiseMeas->Append( net );
|
|
|
|
m_noiseRef->Append( net );
|
|
|
|
}
|
|
|
|
|
|
|
|
for( const SPICE_ITEM& item : m_circuitModel->GetItems() )
|
|
|
|
{
|
|
|
|
if( item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
|
|
|
|
m_noiseSrc->Append( item.refName );
|
|
|
|
}
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
if( !dynamic_cast<NGSPICE_SETTINGS*>( aSettings.get() ) )
|
|
|
|
m_compatibilityModeSizer->Show( false );
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
int minWidth = GetTextExtent( wxS( "XXX.XXXXXXX" ) ).x;
|
|
|
|
m_y1Min->SetMinSize( wxSize( minWidth, -1 ) );
|
|
|
|
m_y1Max->SetMinSize( wxSize( minWidth, -1 ) );
|
|
|
|
m_y2Min->SetMinSize( wxSize( minWidth, -1 ) );
|
|
|
|
m_y2Max->SetMinSize( wxSize( minWidth, -1 ) );
|
|
|
|
m_y3Min->SetMinSize( wxSize( minWidth, -1 ) );
|
|
|
|
m_y3Max->SetMinSize( wxSize( minWidth, -1 ) );
|
|
|
|
|
|
|
|
m_bSizerY1->Show( false );
|
|
|
|
m_bSizerY2->Show( false );
|
|
|
|
m_bSizerY3->Show( false );
|
|
|
|
|
2021-11-16 19:39:58 +00:00
|
|
|
SetupStandardButtons();
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 10:04:20 +00:00
|
|
|
bool DIALOG_SIM_COMMAND::TransferDataToWindow()
|
|
|
|
{
|
|
|
|
/// @todo one day it could interpret the sim command and fill out appropriate fields.
|
|
|
|
if( empty( m_customTxt ) )
|
|
|
|
loadDirectives();
|
|
|
|
|
|
|
|
m_fixIncludePaths->SetValue( m_settings->GetFixIncludePaths() );
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
if( NGSPICE_SETTINGS* settings = dynamic_cast<NGSPICE_SETTINGS*>( m_settings.get() ) )
|
2023-07-04 10:04:20 +00:00
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
switch( settings->GetCompatibilityMode() )
|
2023-07-04 10:04:20 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
case NGSPICE_COMPATIBILITY_MODE::USER_CONFIG: m_compatibilityMode->SetSelection( 0 ); break;
|
|
|
|
case NGSPICE_COMPATIBILITY_MODE::NGSPICE: m_compatibilityMode->SetSelection( 1 ); break;
|
|
|
|
case NGSPICE_COMPATIBILITY_MODE::PSPICE: m_compatibilityMode->SetSelection( 2 ); break;
|
|
|
|
case NGSPICE_COMPATIBILITY_MODE::LTSPICE: m_compatibilityMode->SetSelection( 3 ); break;
|
|
|
|
case NGSPICE_COMPATIBILITY_MODE::LT_PSPICE: m_compatibilityMode->SetSelection( 4 ); break;
|
|
|
|
case NGSPICE_COMPATIBILITY_MODE::HSPICE: m_compatibilityMode->SetSelection( 5 ); break;
|
2023-07-19 15:25:57 +00:00
|
|
|
default: wxFAIL_MSG( wxString::Format( "Unknown NGSPICE_COMPATIBILITY_MODE %d.",
|
|
|
|
settings->GetCompatibilityMode() ) ); break;
|
2023-07-04 10:04:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
void DIALOG_SIM_COMMAND::OnUpdateUILockY1( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_lockY1->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_COMMAND::OnUpdateUILockY2( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_lockY2->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_COMMAND::OnUpdateUILockY3( wxUpdateUIEvent& event )
|
|
|
|
{
|
|
|
|
event.Enable( m_lockY3->GetValue() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_COMMAND::SetPlotSettings( const SIM_TAB* aSimTab )
|
|
|
|
{
|
|
|
|
if( const SIM_PLOT_TAB* plotTab = dynamic_cast<const SIM_PLOT_TAB*>( aSimTab ) )
|
|
|
|
{
|
|
|
|
if( !plotTab->GetLabelY1().IsEmpty() )
|
|
|
|
{
|
|
|
|
m_bSizerY1->Show( true );
|
|
|
|
m_lockY1->SetLabel( wxString::Format( m_lockY1->GetLabel(), plotTab->GetLabelY1() ) );
|
2023-07-20 16:20:57 +00:00
|
|
|
m_y1Units->SetLabel( plotTab->GetUnitsY1() );
|
2023-07-19 15:25:57 +00:00
|
|
|
|
2024-03-23 12:34:33 +00:00
|
|
|
double min = 0.0, max = 0.0;
|
2023-07-19 15:25:57 +00:00
|
|
|
bool locked = plotTab->GetY1Scale( &min, &max );
|
|
|
|
m_lockY1->SetValue( locked );
|
|
|
|
|
|
|
|
if( !std::isnan( min ) )
|
|
|
|
m_y1Min->SetValue( SIM_VALUE::Normalize( min ) );
|
|
|
|
|
|
|
|
if( !std::isnan( max ) )
|
|
|
|
m_y1Max->SetValue( SIM_VALUE::Normalize( max ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !plotTab->GetLabelY2().IsEmpty() )
|
|
|
|
{
|
|
|
|
m_bSizerY2->Show( true );
|
|
|
|
m_lockY2->SetLabel( wxString::Format( m_lockY2->GetLabel(), plotTab->GetLabelY2() ) );
|
2023-07-20 16:20:57 +00:00
|
|
|
m_y2Units->SetLabel( plotTab->GetUnitsY2() );
|
2023-07-19 15:25:57 +00:00
|
|
|
|
2024-03-23 12:34:33 +00:00
|
|
|
double min = 0.0, max = 0.0;
|
2023-07-19 15:25:57 +00:00
|
|
|
bool locked = plotTab->GetY2Scale( &min, &max );
|
|
|
|
m_lockY2->SetValue( locked );
|
|
|
|
|
|
|
|
if( !std::isnan( min ) )
|
|
|
|
m_y2Min->SetValue( SIM_VALUE::Normalize( min ) );
|
|
|
|
|
|
|
|
if( !std::isnan( max ) )
|
|
|
|
m_y2Max->SetValue( SIM_VALUE::Normalize( max ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !plotTab->GetLabelY3().IsEmpty() )
|
|
|
|
{
|
|
|
|
m_bSizerY3->Show( true );
|
|
|
|
m_lockY3->SetLabel( wxString::Format( m_lockY3->GetLabel(), plotTab->GetLabelY3() ) );
|
2023-07-20 16:20:57 +00:00
|
|
|
m_y3Units->SetLabel( plotTab->GetUnitsY3() );
|
2023-07-19 15:25:57 +00:00
|
|
|
|
2024-03-23 12:34:33 +00:00
|
|
|
double min = 0.0, max = 0.0;
|
2023-07-19 15:25:57 +00:00
|
|
|
bool locked = plotTab->GetY3Scale( &min, &max );
|
|
|
|
m_lockY3->SetValue( locked );
|
|
|
|
|
|
|
|
if( !std::isnan( min ) )
|
|
|
|
m_y3Min->SetValue( SIM_VALUE::Normalize( min ) );
|
|
|
|
|
|
|
|
if( !std::isnan( max ) )
|
|
|
|
m_y3Max->SetValue( SIM_VALUE::Normalize( max ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_grid->SetValue( plotTab->IsGridShown() );
|
|
|
|
m_legend->SetValue( plotTab->IsLegendShown() );
|
|
|
|
m_dottedSecondary->SetValue( plotTab->GetDottedSecondary() );
|
|
|
|
|
2023-07-20 16:20:57 +00:00
|
|
|
#define GET_STR( val ) EDA_UNIT_UTILS::UI::MessageTextFromValue( unityScale, EDA_UNITS::UNSCALED, \
|
|
|
|
val, false /* no units */ )
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
m_marginLeft->SetValue( GET_STR( plotTab->GetPlotWin()->GetMarginLeft() ) );
|
|
|
|
m_marginTop->SetValue( GET_STR( plotTab->GetPlotWin()->GetMarginTop() ) );
|
|
|
|
m_marginRight->SetValue( GET_STR( plotTab->GetPlotWin()->GetMarginRight() ) );
|
|
|
|
m_marginBottom->SetValue( GET_STR( plotTab->GetPlotWin()->GetMarginBottom() ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
wxString DIALOG_SIM_COMMAND::evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart,
|
2023-07-03 14:45:58 +00:00
|
|
|
wxTextCtrl* aDcStop, wxTextCtrl* aDcIncr )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
2022-12-11 21:28:04 +00:00
|
|
|
wxString dcSource;
|
2021-01-25 21:29:13 +00:00
|
|
|
wxWindow* ctrlWithError = nullptr;
|
|
|
|
|
2022-12-11 21:28:04 +00:00
|
|
|
if( aDcSource->GetSelection() >= 0 )
|
|
|
|
dcSource = aDcSource->GetString( aDcSource->GetSelection() );
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( dcSource.IsEmpty() )
|
|
|
|
{
|
2023-07-03 14:45:58 +00:00
|
|
|
DisplayError( this, _( "A DC source must be specified." ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
ctrlWithError = aDcSource;
|
|
|
|
}
|
|
|
|
else if( !aDcStart->Validate() )
|
|
|
|
ctrlWithError = aDcStart;
|
|
|
|
else if( !aDcStop->Validate() )
|
|
|
|
ctrlWithError = aDcStop;
|
|
|
|
else if( !aDcIncr->Validate() )
|
|
|
|
ctrlWithError = aDcIncr;
|
|
|
|
|
|
|
|
if( ctrlWithError )
|
|
|
|
{
|
|
|
|
ctrlWithError->SetFocus();
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
// pick device name from exporter when something different than temperature is selected
|
|
|
|
if( dcSource.Cmp( "TEMP" ) )
|
|
|
|
dcSource = m_circuitModel->GetItemName( std::string( dcSource.ToUTF8() ) );
|
|
|
|
|
|
|
|
return wxString::Format( "%s %s %s %s", dcSource,
|
|
|
|
SPICE_VALUE( aDcStart->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( aDcStop->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( aDcIncr->GetValue() ).ToSpiceString() );
|
2021-01-25 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
bool DIALOG_SIM_COMMAND::TransferDataFromWindow()
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
// The simulator dependent settings always get transferred.
|
2023-07-19 15:25:57 +00:00
|
|
|
if( NGSPICE_SETTINGS* settings = dynamic_cast<NGSPICE_SETTINGS*>( m_settings.get() ) )
|
2021-03-18 19:31:02 +00:00
|
|
|
{
|
2023-07-14 09:21:58 +00:00
|
|
|
switch( m_compatibilityMode->GetSelection() )
|
2021-03-22 13:50:14 +00:00
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
case 0: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::USER_CONFIG ); break;
|
|
|
|
case 1: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::NGSPICE ); break;
|
|
|
|
case 2: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::PSPICE ); break;
|
|
|
|
case 3: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LTSPICE ); break;
|
|
|
|
case 4: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::LT_PSPICE ); break;
|
|
|
|
case 5: settings->SetCompatibilityMode( NGSPICE_COMPATIBILITY_MODE::HSPICE ); break;
|
2021-03-22 13:50:14 +00:00
|
|
|
}
|
2021-03-18 19:31:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 15:19:20 +00:00
|
|
|
wxString previousSimCommand = m_simCommand;
|
2016-08-11 12:41:29 +00:00
|
|
|
wxWindow* page = m_simPages->GetCurrentPage();
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
if( page == m_pgAC ) // AC small-signal analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2016-08-11 12:41:54 +00:00
|
|
|
if( !m_pgAC->Validate() )
|
2016-08-11 12:41:29 +00:00
|
|
|
return false;
|
|
|
|
|
2021-03-08 10:51:43 +00:00
|
|
|
m_simCommand.Printf( ".ac %s %s %s %s",
|
|
|
|
scaleToString( m_acScale->GetSelection() ),
|
|
|
|
m_acPointsNumber->GetValue(),
|
|
|
|
SPICE_VALUE( m_acFreqStart->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( m_acFreqStop->GetValue() ).ToSpiceString() );
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
else if( page == m_pgSP ) // S-params analysis
|
2023-07-04 16:01:12 +00:00
|
|
|
{
|
|
|
|
if( !m_pgSP->Validate() )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
m_simCommand.Printf( ".sp %s %s %s %s %s", scaleToString( m_spScale->GetSelection() ),
|
|
|
|
m_spPointsNumber->GetValue(),
|
|
|
|
SPICE_VALUE( m_spFreqStart->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( m_spFreqStop->GetValue() ).ToSpiceString(),
|
|
|
|
m_spDoNoise ? "1" : "" );
|
|
|
|
}
|
2021-03-20 15:19:20 +00:00
|
|
|
else if( page == m_pgDC ) // DC transfer analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
|
|
|
wxString simCmd = wxString( ".dc " );
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
wxString src1 = evaluateDCControls( m_dcSource1, m_dcStart1, m_dcStop1, m_dcIncr1 );
|
2021-03-08 10:51:43 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( src1.IsEmpty() )
|
|
|
|
return false;
|
|
|
|
else
|
|
|
|
simCmd += src1;
|
2016-08-11 12:41:29 +00:00
|
|
|
|
|
|
|
if( m_dcEnable2->IsChecked() )
|
|
|
|
{
|
2021-01-25 21:29:13 +00:00
|
|
|
wxString src2 = evaluateDCControls( m_dcSource2, m_dcStart2, m_dcStop2, m_dcIncr2 );
|
2021-03-08 10:51:43 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( src2.IsEmpty() )
|
2016-08-11 12:41:29 +00:00
|
|
|
return false;
|
2021-01-25 21:29:13 +00:00
|
|
|
else
|
|
|
|
simCmd += " " + src2;
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2022-01-23 15:21:53 +00:00
|
|
|
if( m_dcSource1->GetStringSelection() == m_dcSource2->GetStringSelection() )
|
2019-05-27 22:13:00 +00:00
|
|
|
{
|
2023-07-03 14:45:58 +00:00
|
|
|
DisplayError( this, _( "Source 1 and Source 2 must be different." ) );
|
2019-05-27 22:13:00 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_simCommand = simCmd;
|
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
else if( page == m_pgFFT ) // Fast Fourier transform
|
|
|
|
{
|
2023-11-04 15:08:05 +00:00
|
|
|
m_simCommand = wxEmptyString;
|
2023-07-05 17:25:52 +00:00
|
|
|
wxString vectors;
|
|
|
|
|
|
|
|
for( int ii = 0; ii < (int) m_inputSignalsList->GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
if( m_inputSignalsList->IsChecked( ii ) )
|
|
|
|
vectors += wxS( " " ) + m_inputSignalsList->GetString( ii );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( m_linearize->IsChecked() )
|
|
|
|
m_simCommand = wxT( "linearize" ) + vectors + wxS( "\n" );
|
|
|
|
|
2023-11-04 15:08:05 +00:00
|
|
|
m_simCommand += wxT( "fft" ) + vectors;
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
2023-07-13 15:04:06 +00:00
|
|
|
else if( page == m_pgPZ ) // Pole-zero analyses
|
|
|
|
{
|
|
|
|
wxString input = m_pzInput->GetStringSelection();
|
|
|
|
wxString inputRef = m_pzInputRef->GetStringSelection();
|
|
|
|
wxString output = m_pzOutput->GetStringSelection();
|
|
|
|
wxString outputRef = m_pzOutputRef->GetStringSelection();
|
|
|
|
wxString transferFunction = wxS( "vol" );
|
|
|
|
wxString analyses = wxS( "pz" );
|
|
|
|
|
|
|
|
if( m_pzFunctionType->GetSelection() == 1 )
|
|
|
|
transferFunction = wxS( "cur" );
|
|
|
|
|
|
|
|
if( m_pzAnalyses->GetSelection() == 1 )
|
|
|
|
analyses = wxS( "pol" );
|
|
|
|
else if( m_pzAnalyses->GetSelection() == 2 )
|
|
|
|
analyses = wxS( "zer" );
|
|
|
|
|
|
|
|
m_simCommand.Printf( ".pz %s %s %s %s %s %s",
|
|
|
|
input,
|
|
|
|
inputRef,
|
|
|
|
output,
|
|
|
|
outputRef,
|
|
|
|
transferFunction,
|
|
|
|
analyses );
|
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
else if( page == m_pgNOISE ) // Noise analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2023-07-03 14:45:58 +00:00
|
|
|
wxString output = m_noiseMeas->GetStringSelection();
|
|
|
|
wxString ref = m_noiseRef->GetStringSelection();
|
|
|
|
wxString noiseSource = m_noiseSrc->GetStringSelection();
|
2016-08-11 12:41:31 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
if( m_noiseFreqStart->IsEmpty() || m_noiseFreqStop->IsEmpty() )
|
2021-03-08 10:51:43 +00:00
|
|
|
{
|
2023-07-03 14:45:58 +00:00
|
|
|
DisplayError( this, _( "A frequency range must be specified." ) );
|
2016-08-11 12:41:29 +00:00
|
|
|
return false;
|
2021-03-08 10:51:43 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
if( !ref.IsEmpty() )
|
2024-03-21 01:52:19 +00:00
|
|
|
{
|
|
|
|
ref = wxS( "," )
|
|
|
|
+ wxString( m_circuitModel->GetItemName( std::string( ref.ToUTF8() ) ) );
|
|
|
|
}
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2023-07-04 10:04:20 +00:00
|
|
|
m_simCommand.Printf( ".noise v(%s%s) %s %s %s %s %s %s",
|
2023-07-03 14:45:58 +00:00
|
|
|
output,
|
|
|
|
ref,
|
|
|
|
noiseSource,
|
|
|
|
scaleToString( m_noiseScale->GetSelection() ),
|
2021-03-08 10:51:43 +00:00
|
|
|
m_noisePointsNumber->GetValue(),
|
|
|
|
SPICE_VALUE( m_noiseFreqStart->GetValue() ).ToSpiceString(),
|
2023-07-04 10:04:20 +00:00
|
|
|
SPICE_VALUE( m_noiseFreqStop->GetValue() ).ToSpiceString(),
|
|
|
|
m_saveAllNoise->GetValue() ? "1" : "" );
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
2021-03-20 15:19:20 +00:00
|
|
|
else if( page == m_pgOP ) // DC operating point analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
|
|
|
m_simCommand = wxString( ".op" );
|
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
else if( page == m_pgTRAN ) // Transient analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
if( !m_pgTRAN->Validate() )
|
2016-08-11 12:41:29 +00:00
|
|
|
return false;
|
|
|
|
|
2023-04-08 13:12:54 +00:00
|
|
|
const wxString spc = wxS( " " );
|
2023-04-06 20:48:11 +00:00
|
|
|
const SPICE_VALUE timeStep( m_transStep->GetValue() );
|
|
|
|
const SPICE_VALUE finalTime( m_transFinal->GetValue() );
|
|
|
|
|
2023-04-08 13:12:54 +00:00
|
|
|
SPICE_VALUE startTime( 0 );
|
2021-03-08 10:51:43 +00:00
|
|
|
|
|
|
|
if( !empty( m_transInitial ) )
|
2023-04-06 20:48:11 +00:00
|
|
|
startTime = SPICE_VALUE( m_transInitial->GetValue() );
|
|
|
|
|
|
|
|
wxString optionals;
|
|
|
|
|
|
|
|
if( m_useInitialConditions->GetValue() )
|
2023-04-08 13:12:54 +00:00
|
|
|
optionals = wxS( "uic" );
|
2023-04-06 20:48:11 +00:00
|
|
|
|
|
|
|
if( !empty( m_transMaxStep ) )
|
2023-07-03 14:45:58 +00:00
|
|
|
{
|
2023-04-08 13:12:54 +00:00
|
|
|
optionals = SPICE_VALUE( m_transMaxStep->GetValue() ).ToSpiceString() + spc + optionals;
|
2023-07-03 14:45:58 +00:00
|
|
|
}
|
2023-04-06 20:48:11 +00:00
|
|
|
else if( !optionals.IsEmpty() )
|
|
|
|
{
|
|
|
|
SPICE_VALUE maxStep = ( finalTime - startTime ) / 50.0;
|
2016-08-11 12:41:54 +00:00
|
|
|
|
2023-04-06 20:48:11 +00:00
|
|
|
if( maxStep > timeStep )
|
|
|
|
maxStep = timeStep;
|
|
|
|
|
2023-04-08 13:12:54 +00:00
|
|
|
optionals = maxStep.ToSpiceString() + spc + optionals;
|
2023-04-06 20:48:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if( !empty( m_transInitial ) )
|
2023-04-08 13:12:54 +00:00
|
|
|
optionals = startTime.ToSpiceString() + spc + optionals;
|
2023-04-06 20:48:11 +00:00
|
|
|
else if( !optionals.IsEmpty() )
|
2023-04-08 13:12:54 +00:00
|
|
|
optionals = wxS( "0 " ) + optionals;
|
2023-04-06 20:48:11 +00:00
|
|
|
|
2023-04-08 13:12:54 +00:00
|
|
|
m_simCommand.Printf( wxS( ".tran %s %s %s" ), timeStep.ToSpiceString(),
|
|
|
|
finalTime.ToSpiceString(), optionals );
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
2021-03-20 15:19:20 +00:00
|
|
|
else if( page == m_pgCustom ) // Custom directives
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
|
|
|
m_simCommand = m_customTxt->GetValue();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-03-20 15:19:20 +00:00
|
|
|
if( previousSimCommand != m_simCommand )
|
|
|
|
m_simCommand.Trim();
|
2016-08-11 12:41:36 +00:00
|
|
|
|
2022-12-05 20:01:36 +00:00
|
|
|
m_settings->SetFixIncludePaths( m_fixIncludePaths->GetValue() );
|
2021-07-05 22:17:11 +00:00
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
void DIALOG_SIM_COMMAND::ApplySettings( SIM_TAB* aTab )
|
|
|
|
{
|
|
|
|
int options = NETLIST_EXPORTER_SPICE::OPTION_DEFAULT_FLAGS;
|
|
|
|
|
|
|
|
if( !m_fixIncludePaths->GetValue() )
|
|
|
|
options &= ~NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS;
|
|
|
|
|
|
|
|
if( !m_saveAllVoltages->GetValue() )
|
|
|
|
options &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES;
|
|
|
|
|
|
|
|
if( !m_saveAllCurrents->GetValue() )
|
|
|
|
options &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS;
|
|
|
|
|
|
|
|
if( !m_saveAllDissipations->GetValue() )
|
|
|
|
options &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS;
|
|
|
|
|
|
|
|
aTab->SetSimOptions( options );
|
2024-02-13 14:38:02 +00:00
|
|
|
m_simulatorFrame->ReloadSimulator( m_simCommand, options );
|
2023-07-19 15:25:57 +00:00
|
|
|
|
|
|
|
#define TO_INT( ctrl ) (int) EDA_UNIT_UTILS::UI::ValueFromString( unityScale, EDA_UNITS::UNSCALED, \
|
|
|
|
ctrl->GetValue() )
|
|
|
|
|
|
|
|
if( SIM_PLOT_TAB* plotTab = dynamic_cast<SIM_PLOT_TAB*>( aTab ) )
|
|
|
|
{
|
|
|
|
if( !plotTab->GetLabelY1().IsEmpty() )
|
|
|
|
{
|
|
|
|
plotTab->SetY1Scale( m_lockY1->GetValue(),
|
|
|
|
SIM_VALUE::ToDouble( m_y1Min->GetValue().ToStdString() ),
|
|
|
|
SIM_VALUE::ToDouble( m_y1Max->GetValue().ToStdString() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !plotTab->GetLabelY2().IsEmpty() )
|
|
|
|
{
|
|
|
|
plotTab->SetY2Scale( m_lockY2->GetValue(),
|
|
|
|
SIM_VALUE::ToDouble( m_y2Min->GetValue().ToStdString() ),
|
|
|
|
SIM_VALUE::ToDouble( m_y2Max->GetValue().ToStdString() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !plotTab->GetLabelY3().IsEmpty() )
|
|
|
|
{
|
|
|
|
plotTab->SetY3Scale( m_lockY3->GetValue(),
|
|
|
|
SIM_VALUE::ToDouble( m_y3Min->GetValue().ToStdString() ),
|
|
|
|
SIM_VALUE::ToDouble( m_y3Max->GetValue().ToStdString() ) );
|
|
|
|
}
|
|
|
|
|
2023-07-20 16:41:23 +00:00
|
|
|
plotTab->GetPlotWin()->LockY( m_lockY1->GetValue()
|
|
|
|
|| m_lockY2->GetValue()
|
|
|
|
|| m_lockY3->GetValue() );
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
plotTab->ShowGrid( m_grid->GetValue() );
|
|
|
|
plotTab->ShowLegend( m_legend->GetValue() );
|
|
|
|
plotTab->SetDottedSecondary( m_dottedSecondary->GetValue() );
|
|
|
|
|
|
|
|
plotTab->GetPlotWin()->SetMarginLeft( TO_INT( m_marginLeft ) );
|
|
|
|
plotTab->GetPlotWin()->SetMarginRight( TO_INT( m_marginRight ) );
|
|
|
|
plotTab->GetPlotWin()->SetMarginTop( TO_INT( m_marginTop ) );
|
|
|
|
plotTab->GetPlotWin()->SetMarginBottom( TO_INT( m_marginBottom ) );
|
|
|
|
|
2023-07-20 16:41:23 +00:00
|
|
|
plotTab->GetPlotWin()->AdjustLimitedView();
|
2023-07-19 15:25:57 +00:00
|
|
|
plotTab->GetPlotWin()->UpdateAll();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
void DIALOG_SIM_COMMAND::updateDCSources( wxChar aType, wxChoice* aSource )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
2021-03-08 11:45:00 +00:00
|
|
|
wxString prevSelection;
|
|
|
|
|
2021-08-20 10:10:35 +00:00
|
|
|
if( !aSource->IsEmpty() )
|
|
|
|
prevSelection = aSource->GetString( aSource->GetSelection() );
|
2021-03-08 11:45:00 +00:00
|
|
|
|
2021-10-30 15:17:10 +00:00
|
|
|
std::set<wxString> sourcesList;
|
|
|
|
bool enableSrcSelection = true;
|
2016-08-11 12:41:30 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( aType != 'T' )
|
2016-08-11 12:41:30 +00:00
|
|
|
{
|
2022-12-11 21:28:04 +00:00
|
|
|
for( const SPICE_ITEM& item : m_circuitModel->GetItems() )
|
2016-08-11 12:41:30 +00:00
|
|
|
{
|
2022-12-06 14:59:49 +00:00
|
|
|
if( ( aType == 'R' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::R )
|
2022-12-11 21:28:04 +00:00
|
|
|
|| ( aType == 'V' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::V )
|
|
|
|
|| ( aType == 'I' && item.model->GetDeviceType() == SIM_MODEL::DEVICE_T::I ) )
|
2022-04-12 14:37:06 +00:00
|
|
|
{
|
|
|
|
sourcesList.insert( item.refName );
|
|
|
|
}
|
2016-08-11 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( aSource == m_dcSource2 && !m_dcEnable2->IsChecked() )
|
|
|
|
enableSrcSelection = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prevSelection = wxT( "TEMP" );
|
2021-10-30 15:17:10 +00:00
|
|
|
sourcesList.insert( prevSelection );
|
2021-01-25 21:29:13 +00:00
|
|
|
enableSrcSelection = false;
|
2016-08-11 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
aSource->Enable( enableSrcSelection );
|
|
|
|
|
|
|
|
aSource->Clear();
|
2021-03-08 10:51:43 +00:00
|
|
|
|
2021-10-30 15:17:10 +00:00
|
|
|
for( const wxString& src : sourcesList )
|
2021-01-25 21:29:13 +00:00
|
|
|
aSource->Append( src );
|
|
|
|
|
|
|
|
// Try to restore the previous selection, if possible
|
2021-03-08 10:51:43 +00:00
|
|
|
aSource->SetStringSelection( prevSelection );
|
2016-08-11 12:41:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
void DIALOG_SIM_COMMAND::parseCommand( const wxString& aCommand )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
if( aCommand.IsEmpty() )
|
2023-07-03 14:45:58 +00:00
|
|
|
return;
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
if( aCommand == wxT( "*" ) )
|
|
|
|
{
|
2023-07-19 15:25:57 +00:00
|
|
|
SetTitle( _( "New Simulation Tab" ) );
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
m_commandType->Clear();
|
|
|
|
|
2023-07-13 15:04:06 +00:00
|
|
|
for( SIM_TYPE type : { ST_OP, ST_DC, ST_AC, ST_TRAN, ST_PZ, ST_NOISE, ST_SP, ST_FFT } )
|
2023-07-05 17:25:52 +00:00
|
|
|
{
|
|
|
|
m_commandType->Append( SPICE_SIMULATOR::TypeToName( type, true )
|
|
|
|
+ wxT( " \u2014 " )
|
|
|
|
+ SPICE_SIMULATOR::TypeToName( type, false ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_commandTypeSizer->Show( true );
|
2023-07-13 22:37:48 +00:00
|
|
|
m_commandType->SetSelection( 0 );
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgOP ) );
|
2023-11-01 22:36:38 +00:00
|
|
|
m_simPages->Show();
|
2023-07-05 17:25:52 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-14 09:21:58 +00:00
|
|
|
SIM_TYPE simType = SPICE_CIRCUIT_MODEL::CommandToSimType( aCommand );
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
SetTitle( SPICE_SIMULATOR::TypeToName( simType, true )
|
|
|
|
+ wxT( " \u2014 " )
|
|
|
|
+ SPICE_SIMULATOR::TypeToName( simType, false ) );
|
|
|
|
|
|
|
|
m_commandTypeSizer->Show( false );
|
|
|
|
|
|
|
|
wxStringTokenizer tokenizer( aCommand, wxS( " \t\n\r" ), wxTOKEN_STRTOK );
|
2023-07-03 14:45:58 +00:00
|
|
|
wxString token = tokenizer.GetNextToken().Lower();
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
switch( simType )
|
2021-03-08 10:51:43 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_AC:
|
2023-07-03 14:45:58 +00:00
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgAC ) );
|
|
|
|
|
|
|
|
token = tokenizer.GetNextToken().Lower();
|
|
|
|
|
|
|
|
for( SCALE_TYPE candidate : { DECADE, OCTAVE, LINEAR } )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
2023-07-03 14:45:58 +00:00
|
|
|
if( scaleToString( candidate ) == token )
|
|
|
|
{
|
|
|
|
m_acScale->SetSelection( candidate );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
m_acPointsNumber->SetValue( tokenizer.GetNextToken() );
|
|
|
|
m_acFreqStart->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
m_acFreqStop->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
2023-07-05 17:25:52 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_SP:
|
2023-07-04 16:01:12 +00:00
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgSP ) );
|
|
|
|
|
|
|
|
token = tokenizer.GetNextToken().Lower();
|
|
|
|
|
|
|
|
for( SCALE_TYPE candidate : { DECADE, OCTAVE, LINEAR } )
|
|
|
|
{
|
|
|
|
if( scaleToString( candidate ) == token )
|
|
|
|
{
|
|
|
|
m_spScale->SetSelection( candidate );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
m_spPointsNumber->SetValue( tokenizer.GetNextToken() );
|
|
|
|
m_spFreqStart->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
m_spFreqStop->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
|
|
|
|
if( tokenizer.HasMoreTokens() )
|
2023-07-05 17:25:52 +00:00
|
|
|
m_spDoNoise->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() == "1" );
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_DC:
|
2023-07-03 14:45:58 +00:00
|
|
|
{
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgDC ) );
|
|
|
|
|
|
|
|
SPICE_DC_PARAMS src1, src2;
|
|
|
|
src2.m_vincrement = SPICE_VALUE( -1 );
|
|
|
|
|
|
|
|
m_circuitModel->ParseDCCommand( aCommand, &src1, &src2 );
|
|
|
|
|
|
|
|
if( src1.m_source.IsSameAs( wxT( "TEMP" ), false ) )
|
|
|
|
setStringSelection( m_dcSourceType1, wxT( "TEMP" ) );
|
|
|
|
else
|
|
|
|
setStringSelection( m_dcSourceType1, src1.m_source.GetChar( 0 ) );
|
|
|
|
|
|
|
|
updateDCSources( src1.m_source.GetChar( 0 ), m_dcSource1 );
|
|
|
|
m_dcSource1->SetStringSelection( src1.m_source );
|
|
|
|
m_dcStart1->SetValue( src1.m_vstart.ToSpiceString() );
|
|
|
|
m_dcStop1->SetValue( src1.m_vend.ToSpiceString() );
|
|
|
|
m_dcIncr1->SetValue( src1.m_vincrement.ToSpiceString() );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
if( src2.m_vincrement.ToDouble() != -1 )
|
|
|
|
{
|
|
|
|
if( src2.m_source.IsSameAs( wxT( "TEMP" ), false ) )
|
|
|
|
setStringSelection( m_dcSourceType2, wxT( "TEMP" ) );
|
2016-08-11 12:42:08 +00:00
|
|
|
else
|
2023-07-03 14:45:58 +00:00
|
|
|
setStringSelection( m_dcSourceType2, src2.m_source.GetChar( 0 ) );
|
|
|
|
|
|
|
|
updateDCSources( src2.m_source.GetChar( 0 ), m_dcSource2 );
|
|
|
|
m_dcSource2->SetStringSelection( src2.m_source );
|
|
|
|
m_dcStart2->SetValue( src2.m_vstart.ToSpiceString() );
|
|
|
|
m_dcStop2->SetValue( src2.m_vend.ToSpiceString() );
|
|
|
|
m_dcIncr2->SetValue( src2.m_vincrement.ToSpiceString() );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
m_dcEnable2->SetValue( true );
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
2022-12-11 21:28:04 +00:00
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
break;
|
2023-07-03 14:45:58 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
|
2023-07-13 15:04:06 +00:00
|
|
|
case ST_PZ:
|
|
|
|
{
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgPZ ) );
|
|
|
|
|
|
|
|
wxString transferFunction;
|
|
|
|
wxString input, inputRef;
|
|
|
|
wxString output, outputRef;
|
|
|
|
SPICE_PZ_ANALYSES analyses;
|
|
|
|
|
|
|
|
m_circuitModel->ParsePZCommand( aCommand, &transferFunction, &input, &inputRef, &output,
|
|
|
|
&outputRef, &analyses );
|
|
|
|
|
|
|
|
m_pzInput->SetStringSelection( input );
|
|
|
|
m_pzInputRef->SetStringSelection( inputRef );
|
|
|
|
m_pzOutput->SetStringSelection( output );
|
|
|
|
m_pzOutputRef->SetStringSelection( outputRef );
|
|
|
|
|
|
|
|
m_pzFunctionType->SetSelection( transferFunction.Lower() == "cur" ? 1 : 0 );
|
|
|
|
|
|
|
|
if( analyses.m_Poles && analyses.m_Zeros )
|
|
|
|
m_pzAnalyses->SetSelection( 0 );
|
|
|
|
else if( analyses.m_Poles )
|
|
|
|
m_pzAnalyses->SetSelection( 1 );
|
|
|
|
else
|
|
|
|
m_pzAnalyses->SetSelection( 2 );
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_NOISE:
|
2023-07-03 14:45:58 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgNOISE ) );
|
2021-03-08 10:51:43 +00:00
|
|
|
|
2023-07-03 14:45:58 +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;
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
m_circuitModel->ParseNoiseCommand( aCommand, &output, &ref, &source, &scale, &pts,
|
2023-07-04 10:04:20 +00:00
|
|
|
&fStart, &fStop, &saveAll );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
m_noiseMeas->SetStringSelection( output );
|
|
|
|
m_noiseRef->SetStringSelection( ref );
|
|
|
|
m_noiseSrc->SetStringSelection( source );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
for( SCALE_TYPE candidate : { DECADE, OCTAVE, LINEAR } )
|
|
|
|
{
|
|
|
|
if( scaleToString( candidate ) == scale )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2023-07-03 14:45:58 +00:00
|
|
|
m_noiseScale->SetSelection( candidate );
|
|
|
|
break;
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
m_noisePointsNumber->SetValue( pts.ToSpiceString() );
|
|
|
|
m_noiseFreqStart->SetValue( fStart.ToSpiceString() );
|
|
|
|
m_noiseFreqStop->SetValue( fStop.ToSpiceString() );
|
2023-07-04 10:04:20 +00:00
|
|
|
|
|
|
|
m_saveAllNoise->SetValue( saveAll );
|
2023-07-05 17:25:52 +00:00
|
|
|
break;
|
2023-07-03 14:45:58 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
case ST_TRAN:
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgTRAN ) );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
// If the fields below are empty, it will be caught by the exception handler
|
|
|
|
m_transStep->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
m_transFinal->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
2016-08-11 12:42:10 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
// Initial time is an optional field
|
|
|
|
token = tokenizer.GetNextToken();
|
2023-04-06 20:48:11 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
if( !token.IsEmpty() )
|
|
|
|
m_transInitial->SetValue( SPICE_VALUE( token ).ToSpiceString() );
|
2023-04-06 20:48:11 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
// Max step is an optional field
|
|
|
|
token = tokenizer.GetNextToken();
|
2023-04-06 20:48:11 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
if( !token.IsEmpty() )
|
|
|
|
m_transMaxStep->SetValue( SPICE_VALUE( token ).ToSpiceString() );
|
2023-04-06 20:48:11 +00:00
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
// uic is an optional field
|
|
|
|
token = tokenizer.GetNextToken();
|
|
|
|
|
|
|
|
if( token.IsSameAs( wxS( "uic" ) ) )
|
|
|
|
m_useInitialConditions->SetValue( true );
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_OP:
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgOP ) );
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ST_FFT:
|
|
|
|
{
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgFFT ) );
|
|
|
|
|
|
|
|
while( tokenizer.HasMoreTokens() )
|
|
|
|
m_fftInputSignals.insert( tokenizer.GetNextToken() );
|
|
|
|
|
|
|
|
break;
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgCustom ) );
|
|
|
|
break;
|
|
|
|
}
|
2023-11-01 22:36:38 +00:00
|
|
|
|
|
|
|
m_simPages->Show();
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_COMMAND::OnCommandType( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
int sel = ST_UNKNOWN;
|
|
|
|
wxString str = m_commandType->GetString( event.GetSelection() );
|
|
|
|
|
|
|
|
for( int type = ST_UNKNOWN; type < ST_LAST; ++type )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
if( str.StartsWith( SPICE_SIMULATOR::TypeToName( (SIM_TYPE) type, true ) ) )
|
|
|
|
sel = type;
|
2023-07-03 14:45:58 +00:00
|
|
|
}
|
2023-07-05 17:25:52 +00:00
|
|
|
|
|
|
|
switch( sel )
|
2023-07-03 14:45:58 +00:00
|
|
|
{
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_AC: m_simPages->SetSelection( m_simPages->FindPage( m_pgAC ) ); break;
|
|
|
|
case ST_SP: m_simPages->SetSelection( m_simPages->FindPage( m_pgSP ) ); break;
|
|
|
|
case ST_DC: m_simPages->SetSelection( m_simPages->FindPage( m_pgDC ) ); break;
|
2023-07-13 15:04:06 +00:00
|
|
|
case ST_PZ: m_simPages->SetSelection( m_simPages->FindPage( m_pgPZ ) ); break;
|
2023-07-05 17:25:52 +00:00
|
|
|
case ST_NOISE: m_simPages->SetSelection( m_simPages->FindPage( m_pgNOISE ) ); break;
|
|
|
|
case ST_TRAN: m_simPages->SetSelection( m_simPages->FindPage( m_pgTRAN ) ); break;
|
|
|
|
case ST_OP: m_simPages->SetSelection( m_simPages->FindPage( m_pgOP ) ); break;
|
|
|
|
case ST_FFT: m_simPages->SetSelection( m_simPages->FindPage( m_pgFFT ) ); break;
|
|
|
|
default: m_simPages->SetSelection( m_simPages->FindPage( m_pgCustom ) ); break;
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
void DIALOG_SIM_COMMAND::onSwapDCSources( wxCommandEvent& event )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
|
|
|
std::vector<std::pair<wxTextEntry*, wxTextEntry*>> textCtrl = { { m_dcStart1, m_dcStart2 },
|
|
|
|
{ m_dcStop1, m_dcStop2 },
|
|
|
|
{ m_dcIncr1, m_dcIncr2 } };
|
|
|
|
|
|
|
|
for( auto& couple : textCtrl )
|
|
|
|
{
|
|
|
|
wxString tmp = couple.first->GetValue();
|
|
|
|
couple.first->SetValue( couple.second->GetValue() );
|
|
|
|
couple.second->SetValue( tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
int src1 = m_dcSource1->GetSelection();
|
|
|
|
int src2 = m_dcSource2->GetSelection();
|
|
|
|
|
|
|
|
int sel = m_dcSourceType1->GetSelection();
|
|
|
|
m_dcSourceType1->SetSelection( m_dcSourceType2->GetSelection() );
|
|
|
|
m_dcSourceType2->SetSelection( sel );
|
|
|
|
|
2021-03-08 10:51:43 +00:00
|
|
|
wxChar type1 = getStringSelection( m_dcSourceType1 ).Upper().GetChar( 0 );
|
2021-01-25 21:29:13 +00:00
|
|
|
updateDCSources( type1, m_dcSource1 );
|
2021-03-08 10:51:43 +00:00
|
|
|
wxChar type2 = getStringSelection( m_dcSourceType2 ).Upper().GetChar( 0 );
|
2021-01-25 21:29:13 +00:00
|
|
|
updateDCSources( type2, m_dcSource2 );
|
|
|
|
|
|
|
|
m_dcSource1->SetSelection( src2 );
|
|
|
|
m_dcSource2->SetSelection( src1 );
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
updateDCUnits( type1, m_src1DCStartValUnit, m_src1DCEndValUnit, m_src1DCStepUnit );
|
|
|
|
updateDCUnits( type2, m_src2DCStartValUnit, m_src2DCEndValUnit, m_src2DCStepUnit );
|
2021-01-25 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
void DIALOG_SIM_COMMAND::onDCSource1Selected( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxChar type = m_dcSourceType1->GetString( m_dcSourceType1->GetSelection() ).Upper()[ 0 ];
|
|
|
|
updateDCSources( type, m_dcSource1 );
|
2023-07-19 15:25:57 +00:00
|
|
|
updateDCUnits( type, m_src1DCStartValUnit, m_src1DCEndValUnit, m_src1DCStepUnit );
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_COMMAND::onDCSource2Selected( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
wxChar type = m_dcSourceType2->GetString( m_dcSourceType2->GetSelection() ).Upper()[ 0 ];
|
|
|
|
updateDCSources( type, m_dcSource2 );
|
2023-07-19 15:25:57 +00:00
|
|
|
updateDCUnits( type, m_src2DCStartValUnit, m_src2DCEndValUnit, m_src2DCStepUnit );
|
2023-07-05 17:25:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
void DIALOG_SIM_COMMAND::onDCEnableSecondSource( wxCommandEvent& event )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
|
|
|
bool is2ndSrcEnabled = m_dcEnable2->IsChecked();
|
2024-02-26 18:09:51 +00:00
|
|
|
wxChar type = '?';
|
|
|
|
|
|
|
|
if( is2ndSrcEnabled )
|
|
|
|
{
|
|
|
|
wxString fullType = getStringSelection( m_dcSourceType2 ).Upper();
|
|
|
|
|
|
|
|
if( fullType.Length() > 0 )
|
|
|
|
type = fullType.GetChar( 0 );
|
|
|
|
}
|
2021-01-25 21:29:13 +00:00
|
|
|
|
|
|
|
m_dcSourceType2->Enable( is2ndSrcEnabled );
|
|
|
|
m_dcSource2->Enable( is2ndSrcEnabled && type != 'T' );
|
|
|
|
m_dcStart2->Enable( is2ndSrcEnabled );
|
|
|
|
m_dcStop2->Enable( is2ndSrcEnabled );
|
|
|
|
m_dcIncr2->Enable( is2ndSrcEnabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-07-19 15:25:57 +00:00
|
|
|
void DIALOG_SIM_COMMAND::updateDCUnits( wxChar aType, wxStaticText* aStartValUnit,
|
|
|
|
wxStaticText* aEndValUnit, wxStaticText* aStepUnit )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
|
|
|
wxString unit;
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
2023-04-14 12:00:31 +00:00
|
|
|
case 'V': unit = wxS( "V" ); break;
|
|
|
|
case 'I': unit = wxS( "A" ); break;
|
|
|
|
case 'R': unit = wxS( "Ω" ); break;
|
|
|
|
case 'T': unit = wxS( "°C" ); break;
|
2021-01-25 21:29:13 +00:00
|
|
|
}
|
2021-03-08 10:51:43 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
aStartValUnit->SetLabel( unit );
|
|
|
|
aEndValUnit->SetLabel( unit );
|
|
|
|
aStepUnit->SetLabel( unit );
|
|
|
|
|
|
|
|
m_pgDC->Refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
void DIALOG_SIM_COMMAND::loadDirectives()
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2022-03-28 22:02:49 +00:00
|
|
|
if( m_circuitModel )
|
2023-02-11 23:25:32 +00:00
|
|
|
m_customTxt->SetValue( m_circuitModel->GetSchTextSimCommand() );
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
2016-08-11 12:41:36 +00:00
|
|
|
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
void DIALOG_SIM_COMMAND::OnFilterText( wxCommandEvent& aEvent )
|
|
|
|
{
|
|
|
|
for( int ii = 0; ii < (int) m_inputSignalsList->GetCount(); ++ii )
|
|
|
|
{
|
|
|
|
if( m_inputSignalsList->IsChecked( ii ) )
|
|
|
|
m_fftInputSignals.insert( m_inputSignalsList->GetString( ii ) );
|
|
|
|
else
|
|
|
|
m_fftInputSignals.erase( m_inputSignalsList->GetString( ii ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
m_inputSignalsList->Clear();
|
|
|
|
|
|
|
|
wxString aFilter = m_inputSignalsFilter->GetValue();
|
|
|
|
|
|
|
|
if( aFilter.IsEmpty() )
|
|
|
|
aFilter = wxS( "*" );
|
|
|
|
|
|
|
|
EDA_COMBINED_MATCHER matcher( aFilter.Upper(), CTX_SIGNAL );
|
|
|
|
|
|
|
|
for( const wxString& signal : m_simulatorFrame->Signals() )
|
|
|
|
{
|
|
|
|
if( matcher.Find( signal.Upper() ) )
|
|
|
|
{
|
|
|
|
m_inputSignalsList->Append( signal );
|
|
|
|
|
|
|
|
if( m_fftInputSignals.count( signal ) )
|
|
|
|
m_inputSignalsList->Check( m_inputSignalsList->GetCount() - 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_COMMAND::OnFilterMouseMoved( wxMouseEvent& aEvent )
|
|
|
|
{
|
|
|
|
wxPoint pos = aEvent.GetPosition();
|
|
|
|
wxRect ctrlRect = m_inputSignalsFilter->GetScreenRect();
|
|
|
|
int buttonWidth = ctrlRect.GetHeight(); // Presume buttons are square
|
|
|
|
|
|
|
|
if( m_inputSignalsFilter->IsSearchButtonVisible() && pos.x < buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else if( m_inputSignalsFilter->IsCancelButtonVisible() && pos.x > ctrlRect.GetWidth() - buttonWidth )
|
|
|
|
SetCursor( wxCURSOR_ARROW );
|
|
|
|
else
|
|
|
|
SetCursor( wxCURSOR_IBEAM );
|
|
|
|
}
|
|
|
|
|
|
|
|
|