2016-08-11 12:41:29 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
2021-03-08 10:51:43 +00:00
|
|
|
* Copyright (C) 2016-2021 CERN
|
2021-03-18 19:31:02 +00:00
|
|
|
* Copyright (C) 2016-2021 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
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "dialog_sim_settings.h"
|
2016-08-11 12:41:30 +00:00
|
|
|
#include <sim/netlist_exporter_pspice_sim.h>
|
2021-03-18 19:31:02 +00:00
|
|
|
#include <sim/ngspice.h>
|
|
|
|
|
2016-08-11 12:41:54 +00:00
|
|
|
#include <confirm.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
|
|
|
/// @todo ngspice offers more types of analysis,
|
|
|
|
//so there are a few tabs missing (e.g. pole-zero, distortion, sensitivity)
|
|
|
|
|
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
|
|
|
{
|
|
|
|
return aCtrl->GetString( aCtrl->GetSelection() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
DIALOG_SIM_SETTINGS::DIALOG_SIM_SETTINGS( wxWindow* aParent,
|
|
|
|
std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& aSettings ) :
|
2021-03-08 10:51:43 +00:00
|
|
|
DIALOG_SIM_SETTINGS_BASE( aParent ),
|
|
|
|
m_exporter( nullptr ),
|
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
|
|
|
{
|
|
|
|
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
|
|
|
|
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 );
|
2016-08-11 12:41:36 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
refreshUIControls();
|
|
|
|
|
2019-04-14 18:53:07 +00:00
|
|
|
// Hide pages that aren't fully implemented yet
|
|
|
|
// wxPanel::Hide() isn't enough on some platforms
|
|
|
|
m_simPages->RemovePage( m_simPages->FindPage( m_pgDistortion ) );
|
|
|
|
m_simPages->RemovePage( m_simPages->FindPage( m_pgNoise ) );
|
|
|
|
m_simPages->RemovePage( m_simPages->FindPage( m_pgPoleZero ) );
|
|
|
|
m_simPages->RemovePage( m_simPages->FindPage( m_pgSensitivity ) );
|
|
|
|
m_simPages->RemovePage( m_simPages->FindPage( m_pgTransferFunction ) );
|
|
|
|
|
2021-03-22 13:50:14 +00:00
|
|
|
if( !dynamic_cast<NGSPICE_SIMULATOR_SETTINGS*>( aSettings.get() ) )
|
|
|
|
m_compatibilityMode->Show( false );
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2016-08-11 12:41:40 +00:00
|
|
|
m_sdbSizerOK->SetDefault();
|
2016-08-11 12:41:36 +00:00
|
|
|
updateNetlistOpts();
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
wxString DIALOG_SIM_SETTINGS::evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart,
|
|
|
|
wxTextCtrl* aDcStop, wxTextCtrl* aDcIncr )
|
|
|
|
{
|
|
|
|
wxString dcSource = aDcSource->GetString( aDcSource->GetSelection() );
|
|
|
|
wxWindow* ctrlWithError = nullptr;
|
|
|
|
|
|
|
|
if( dcSource.IsEmpty() )
|
|
|
|
{
|
|
|
|
DisplayError( this, _( "You need to select DC source" ) );
|
|
|
|
ctrlWithError = aDcSource;
|
|
|
|
}
|
|
|
|
/// @todo for some reason it does not trigger the assigned SPICE_VALIDATOR,
|
|
|
|
// hence try..catch below
|
|
|
|
else if( !aDcStart->Validate() )
|
|
|
|
ctrlWithError = aDcStart;
|
|
|
|
else if( !aDcStop->Validate() )
|
|
|
|
ctrlWithError = aDcStop;
|
|
|
|
else if( !aDcIncr->Validate() )
|
|
|
|
ctrlWithError = aDcIncr;
|
|
|
|
|
|
|
|
if( ctrlWithError )
|
|
|
|
{
|
|
|
|
ctrlWithError->SetFocus();
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
// pick device name from exporter when something different than temperature is selected
|
2022-02-08 23:14:18 +00:00
|
|
|
if( dcSource.Cmp( wxT( "TEMP" ) ) )
|
2021-01-25 21:29:13 +00:00
|
|
|
dcSource = m_exporter->GetSpiceDevice( dcSource );
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
return wxString::Format( wxT( "%s %s %s %s" ), dcSource,
|
2021-01-25 21:29:13 +00:00
|
|
|
SPICE_VALUE( aDcStart->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( aDcStop->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( aDcIncr->GetValue() ).ToSpiceString() );
|
|
|
|
}
|
|
|
|
catch( std::exception& e )
|
|
|
|
{
|
|
|
|
DisplayError( this, e.what() );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
catch( const KI_PARAM_ERROR& e )
|
|
|
|
{
|
|
|
|
DisplayError( this, e.What() );
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
return wxEmptyString;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
|
|
|
|
bool DIALOG_SIM_SETTINGS::TransferDataFromWindow()
|
|
|
|
{
|
|
|
|
if( !wxDialog::TransferDataFromWindow() )
|
|
|
|
return false;
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
// The simulator dependent settings always get transferred.
|
|
|
|
NGSPICE_SIMULATOR_SETTINGS* ngspiceSettings =
|
|
|
|
dynamic_cast<NGSPICE_SIMULATOR_SETTINGS*>( m_settings.get() );
|
|
|
|
|
|
|
|
if( ngspiceSettings )
|
|
|
|
{
|
2021-03-22 13:50:14 +00:00
|
|
|
switch( m_compatibilityModeChoice->GetSelection() )
|
|
|
|
{
|
|
|
|
case 0: ngspiceSettings->SetModelMode( NGSPICE_MODEL_MODE::USER_CONFIG ); break;
|
|
|
|
case 1: ngspiceSettings->SetModelMode( NGSPICE_MODEL_MODE::NGSPICE ); break;
|
|
|
|
case 2: ngspiceSettings->SetModelMode( NGSPICE_MODEL_MODE::PSPICE ); break;
|
|
|
|
case 3: ngspiceSettings->SetModelMode( NGSPICE_MODEL_MODE::LTSPICE ); break;
|
|
|
|
case 4: ngspiceSettings->SetModelMode( NGSPICE_MODEL_MODE::LT_PSPICE ); break;
|
|
|
|
case 5: ngspiceSettings->SetModelMode( NGSPICE_MODEL_MODE::HSPICE ); break;
|
|
|
|
}
|
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();
|
|
|
|
|
2021-03-20 15:19:20 +00:00
|
|
|
if( page == m_pgAC ) // AC 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;
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
m_simCommand.Printf( wxT( ".ac %s %s %s %s" ),
|
2021-03-08 10:51:43 +00:00
|
|
|
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
|
|
|
}
|
2021-03-20 15:19:20 +00:00
|
|
|
else if( page == m_pgDC ) // DC transfer analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
wxString simCmd = wxString( wxT( ".dc " ) );
|
2016-08-11 12:41:29 +00:00
|
|
|
|
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
|
2022-02-08 23:14:18 +00:00
|
|
|
simCmd += wxT( " " ) + 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
|
|
|
{
|
|
|
|
DisplayError( this, _( "Source 1 and Source 2 must be different" ) );
|
|
|
|
return false;
|
|
|
|
}
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_simCommand = simCmd;
|
|
|
|
}
|
2021-03-20 15:19:20 +00:00
|
|
|
else if( page == m_pgNoise ) // Noise analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2021-07-28 20:04:53 +00:00
|
|
|
const std::map<wxString, int>& netMap = m_exporter->GetNetIndexMap();
|
2016-08-11 12:41:31 +00:00
|
|
|
|
2016-08-11 12:42:08 +00:00
|
|
|
if( empty( m_noiseMeas ) || empty( m_noiseSrc ) || empty( m_noisePointsNumber )
|
|
|
|
|| empty( m_noiseFreqStart ) || empty( m_noiseFreqStop ) )
|
2021-03-08 10:51:43 +00:00
|
|
|
{
|
2016-08-11 12:41:29 +00:00
|
|
|
return false;
|
2021-03-08 10:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
wxString ref;
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2021-03-08 10:51:43 +00:00
|
|
|
if( !empty( m_noiseRef ) )
|
2022-02-08 23:14:18 +00:00
|
|
|
ref = wxString::Format( wxT( ", %d" ), netMap.at( m_noiseRef->GetValue() ) );
|
2016-08-11 12:41:31 +00:00
|
|
|
|
2018-04-27 22:34:06 +00:00
|
|
|
wxString noiseSource = m_exporter->GetSpiceDevice( m_noiseSrc->GetValue() );
|
2018-04-27 21:09:18 +00:00
|
|
|
|
|
|
|
// Add voltage source prefix if needed
|
|
|
|
if( noiseSource[0] != 'v' && noiseSource[0] != 'V' )
|
|
|
|
noiseSource += 'v' + noiseSource;
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
m_simCommand.Printf( wxT( ".noise v(%d%s) %s %s %s %s %s" ),
|
2021-03-08 10:51:43 +00:00
|
|
|
netMap.at( m_noiseMeas->GetValue() ), ref,
|
|
|
|
noiseSource, scaleToString( m_noiseScale->GetSelection() ),
|
|
|
|
m_noisePointsNumber->GetValue(),
|
|
|
|
SPICE_VALUE( m_noiseFreqStart->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( m_noiseFreqStop->GetValue() ).ToSpiceString() );
|
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
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
m_simCommand = wxString( wxT( ".op" ) );
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
2021-03-20 15:19:20 +00:00
|
|
|
else if( page == m_pgTransient ) // Transient analysis
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2016-08-11 12:41:54 +00:00
|
|
|
if( !m_pgTransient->Validate() )
|
2016-08-11 12:41:29 +00:00
|
|
|
return false;
|
|
|
|
|
2021-03-08 10:51:43 +00:00
|
|
|
wxString initial;
|
|
|
|
|
|
|
|
if( !empty( m_transInitial ) )
|
|
|
|
initial = SPICE_VALUE( m_transInitial->GetValue() ).ToSpiceString();
|
2016-08-11 12:41:54 +00:00
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
m_simCommand.Printf( wxT( ".tran %s %s %s" ),
|
2021-03-08 10:51:43 +00:00
|
|
|
SPICE_VALUE( m_transStep->GetValue() ).ToSpiceString(),
|
|
|
|
SPICE_VALUE( m_transFinal->GetValue() ).ToSpiceString(),
|
|
|
|
initial );
|
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
|
|
|
|
{
|
2021-03-20 15:19:20 +00:00
|
|
|
wxString extendedMsg;
|
|
|
|
|
|
|
|
if( m_simCommand.IsEmpty() )
|
|
|
|
{
|
|
|
|
KIDIALOG dlg( this, _( "No valid simulation is configured." ), _( "Warning" ),
|
|
|
|
wxOK | wxCANCEL | wxICON_EXCLAMATION | wxCENTER );
|
|
|
|
|
|
|
|
dlg.SetExtendedMessage( _( "A valid simulation can be configured by selecting a "
|
|
|
|
"simulation tab, setting the simulation parameters and "
|
|
|
|
"clicking the OK button with the tab selected." ) );
|
|
|
|
dlg.SetOKCancelLabels(
|
|
|
|
wxMessageDialog::ButtonLabel( _( "Exit Without Valid Simulation" ) ),
|
|
|
|
wxMessageDialog::ButtonLabel( _( "Configure Valid Simulation" ) ) );
|
|
|
|
dlg.DoNotShowCheckbox( __FILE__, __LINE__ );
|
|
|
|
|
|
|
|
if( dlg.ShowModal() == wxID_OK )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
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
|
|
|
|
2021-05-27 13:56:58 +00:00
|
|
|
updateNetlistOpts();
|
|
|
|
|
2021-07-05 22:17:11 +00:00
|
|
|
m_settings->SetFixPassiveVals( m_netlistOpts & NET_ADJUST_PASSIVE_VALS );
|
|
|
|
m_settings->SetFixIncludePaths( m_netlistOpts & NET_ADJUST_INCLUDE_PATHS );
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool DIALOG_SIM_SETTINGS::TransferDataToWindow()
|
|
|
|
{
|
2021-03-18 19:31:02 +00:00
|
|
|
/// @todo one day it could interpret the sim command and fill out appropriate fields.
|
2016-08-11 12:42:08 +00:00
|
|
|
if( empty( m_customTxt ) )
|
2016-08-11 12:41:36 +00:00
|
|
|
loadDirectives();
|
|
|
|
|
2021-07-05 22:17:11 +00:00
|
|
|
m_fixPassiveVals->SetValue( m_settings->GetFixPassiveVals() );
|
|
|
|
m_fixIncludePaths->SetValue( m_settings->GetFixIncludePaths() );
|
|
|
|
updateNetlistOpts();
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
NGSPICE_SIMULATOR_SETTINGS* ngspiceSettings =
|
|
|
|
dynamic_cast<NGSPICE_SIMULATOR_SETTINGS*>( m_settings.get() );
|
|
|
|
|
|
|
|
if( ngspiceSettings )
|
|
|
|
{
|
|
|
|
switch( ngspiceSettings->GetModelMode() )
|
|
|
|
{
|
2021-03-22 13:50:14 +00:00
|
|
|
case NGSPICE_MODEL_MODE::USER_CONFIG: m_compatibilityModeChoice->SetSelection( 0 ); break;
|
|
|
|
case NGSPICE_MODEL_MODE::NGSPICE: m_compatibilityModeChoice->SetSelection( 1 ); break;
|
|
|
|
case NGSPICE_MODEL_MODE::PSPICE: m_compatibilityModeChoice->SetSelection( 2 ); break;
|
|
|
|
case NGSPICE_MODEL_MODE::LTSPICE: m_compatibilityModeChoice->SetSelection( 3 ); break;
|
|
|
|
case NGSPICE_MODEL_MODE::LT_PSPICE: m_compatibilityModeChoice->SetSelection( 4 ); break;
|
|
|
|
case NGSPICE_MODEL_MODE::HSPICE: m_compatibilityModeChoice->SetSelection( 5 ); break;
|
2021-03-18 19:31:02 +00:00
|
|
|
default:
|
2022-02-08 23:14:18 +00:00
|
|
|
wxFAIL_MSG( wxString::Format( wxT( "Unknown NGSPICE_MODEL_MODE %d." ),
|
2021-03-18 19:31:02 +00:00
|
|
|
ngspiceSettings->GetModelMode() ) );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 20:54:19 +00:00
|
|
|
if( !m_dcSource1->GetCount() )
|
|
|
|
{
|
|
|
|
wxChar type1 = getStringSelection( m_dcSourceType1 ).Upper().GetChar( 0 );
|
|
|
|
updateDCSources( type1, m_dcSource1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !m_dcSource2->GetCount() )
|
|
|
|
{
|
|
|
|
wxChar type2 = getStringSelection( m_dcSourceType2 ).Upper().GetChar( 0 );
|
|
|
|
updateDCSources( type2, m_dcSource2 );
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:08 +00:00
|
|
|
if( m_simCommand.IsEmpty() && !empty( m_customTxt ) )
|
|
|
|
return parseCommand( m_customTxt->GetValue() );
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:30 +00:00
|
|
|
int DIALOG_SIM_SETTINGS::ShowModal()
|
|
|
|
{
|
2018-04-08 10:28:57 +00:00
|
|
|
// Fill out comboboxes that allows one to select nets
|
2016-08-11 12:41:30 +00:00
|
|
|
// Map comoboxes to their current values
|
|
|
|
std::map<wxComboBox*, wxString> cmbNet = {
|
|
|
|
{ m_noiseMeas, m_noiseMeas->GetStringSelection() },
|
|
|
|
{ m_noiseRef, m_noiseRef->GetStringSelection() }
|
|
|
|
};
|
|
|
|
|
|
|
|
for( auto c : cmbNet )
|
|
|
|
c.first->Clear();
|
|
|
|
|
2019-12-05 15:20:59 +00:00
|
|
|
for( const auto& net : m_exporter->GetNetIndexMap() )
|
2016-08-11 12:41:30 +00:00
|
|
|
{
|
|
|
|
for( auto c : cmbNet )
|
|
|
|
c.first->Append( net.first );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Try to restore the previous selection, if possible
|
|
|
|
for( auto c : cmbNet )
|
|
|
|
{
|
|
|
|
int idx = c.first->FindString( c.second );
|
|
|
|
|
|
|
|
if( idx != wxNOT_FOUND )
|
|
|
|
c.first->SetSelection( idx );
|
|
|
|
}
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
return DIALOG_SIM_SETTINGS_BASE::ShowModal();
|
|
|
|
}
|
2016-08-11 12:41:30 +00:00
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
void DIALOG_SIM_SETTINGS::updateDCSources( wxChar aType, wxChoice* aSource )
|
|
|
|
{
|
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
|
|
|
{
|
2021-01-25 21:29:13 +00:00
|
|
|
for( const auto& item : m_exporter->GetSpiceItems() )
|
2016-08-11 12:41:30 +00:00
|
|
|
{
|
2021-10-30 15:17:10 +00:00
|
|
|
if( item.m_primitive == aType && !item.m_refName.IsEmpty() )
|
|
|
|
sourcesList.insert( item.m_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
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:42:08 +00:00
|
|
|
bool DIALOG_SIM_SETTINGS::parseCommand( const wxString& aCommand )
|
|
|
|
{
|
|
|
|
if( aCommand.IsEmpty() )
|
|
|
|
return false;
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
wxStringTokenizer tokenizer( aCommand, wxT( " " ) );
|
2016-08-11 12:42:08 +00:00
|
|
|
wxString tkn = tokenizer.GetNextToken().Lower();
|
|
|
|
|
2021-03-08 10:51:43 +00:00
|
|
|
try
|
|
|
|
{
|
2022-02-08 23:14:18 +00:00
|
|
|
if( tkn == wxT( ".ac" ) )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgAC ) );
|
|
|
|
|
|
|
|
tkn = tokenizer.GetNextToken().Lower();
|
|
|
|
|
2022-02-08 23:14:18 +00:00
|
|
|
if( tkn == wxT( "dec" ) )
|
2016-08-11 12:42:08 +00:00
|
|
|
m_acScale->SetSelection( 0 );
|
2022-02-08 23:14:18 +00:00
|
|
|
if( tkn == wxT( "oct" ) )
|
2016-08-11 12:42:08 +00:00
|
|
|
m_acScale->SetSelection( 1 );
|
2022-02-08 23:14:18 +00:00
|
|
|
if( tkn == wxT( "lin" ) )
|
2016-08-11 12:42:08 +00:00
|
|
|
m_acScale->SetSelection( 2 );
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
// If the fields below are empty, it will be caught by the exception handler
|
2016-08-11 12:42:08 +00:00
|
|
|
m_acPointsNumber->SetValue( tokenizer.GetNextToken() );
|
|
|
|
m_acFreqStart->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
m_acFreqStop->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( tkn == wxT( ".dc" ) )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
2021-01-25 21:29:13 +00:00
|
|
|
SPICE_DC_PARAMS src1, src2;
|
|
|
|
src2.m_vincrement = SPICE_VALUE( -1 );
|
2021-03-08 10:51:43 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( !m_exporter->ParseDCCommand( aCommand, &src1, &src2 ) )
|
|
|
|
return false;
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgDC ) );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2021-03-08 10:51:43 +00:00
|
|
|
if( src1.m_source.IsSameAs( wxT( "TEMP" ), false ) )
|
|
|
|
setStringSelection( m_dcSourceType1, wxT( "TEMP" ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
else
|
2021-03-08 10:51:43 +00:00
|
|
|
setStringSelection( m_dcSourceType1, src1.m_source.GetChar( 0 ) );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
updateDCSources( src1.m_source.GetChar( 0 ), m_dcSource1 );
|
2021-03-08 10:51:43 +00:00
|
|
|
m_dcSource1->SetStringSelection( src1.m_source );
|
2021-01-25 21:29:13 +00:00
|
|
|
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
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
if( src2.m_vincrement.ToDouble() != -1 )
|
2016-08-11 12:42:10 +00:00
|
|
|
{
|
2021-03-08 10:51:43 +00:00
|
|
|
if( src2.m_source.IsSameAs( wxT( "TEMP" ), false ) )
|
|
|
|
setStringSelection( m_dcSourceType2, wxT( "TEMP" ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
else
|
2021-03-08 10:51:43 +00:00
|
|
|
setStringSelection( m_dcSourceType2, src2.m_source.GetChar( 0 ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
|
|
|
|
updateDCSources( src2.m_source.GetChar( 0 ), m_dcSource2 );
|
2021-03-08 10:51:43 +00:00
|
|
|
m_dcSource2->SetStringSelection( src2.m_source );
|
2021-01-25 21:29:13 +00:00
|
|
|
m_dcStart2->SetValue( src2.m_vstart.ToSpiceString() );
|
|
|
|
m_dcStop2->SetValue( src2.m_vend.ToSpiceString() );
|
|
|
|
m_dcIncr2->SetValue( src2.m_vincrement.ToSpiceString() );
|
|
|
|
|
|
|
|
m_dcEnable2->SetValue( true );
|
2016-08-11 12:42:10 +00:00
|
|
|
}
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
refreshUIControls();
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( tkn == wxT( ".tran" ) )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgTransient ) );
|
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
// If the fields below are empty, it will be caught by the exception handler
|
2016-08-11 12:42:08 +00:00
|
|
|
m_transStep->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
m_transFinal->SetValue( SPICE_VALUE( tokenizer.GetNextToken() ).ToSpiceString() );
|
|
|
|
|
2016-08-11 12:42:10 +00:00
|
|
|
// Initial time is an optional field
|
|
|
|
tkn = tokenizer.GetNextToken();
|
|
|
|
|
|
|
|
if( !tkn.IsEmpty() )
|
|
|
|
m_transInitial->SetValue( SPICE_VALUE( tkn ).ToSpiceString() );
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
2022-02-08 23:14:18 +00:00
|
|
|
else if( tkn == wxT( ".op" ) )
|
2021-01-25 21:29:13 +00:00
|
|
|
{
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgOP ) );
|
|
|
|
}
|
2021-03-18 19:31:02 +00:00
|
|
|
else if( !empty( m_customTxt ) ) // Custom directives
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
|
|
|
m_simPages->SetSelection( m_simPages->FindPage( m_pgCustom ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ... )
|
|
|
|
{
|
|
|
|
// Nothing really bad has happened
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
void DIALOG_SIM_SETTINGS::onSwapDCSources( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
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 );
|
|
|
|
|
|
|
|
updateDCUnits( type1, m_dcSource1, m_src1DCStartValUnit, m_src1DCEndValUnit, m_src1DCStepUnit );
|
|
|
|
updateDCUnits( type2, m_dcSource2, m_src2DCStartValUnit, m_src2DCEndValUnit, m_src2DCStepUnit );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_SETTINGS::onDCEnableSecondSource( wxCommandEvent& event )
|
|
|
|
{
|
|
|
|
bool is2ndSrcEnabled = m_dcEnable2->IsChecked();
|
2021-03-08 10:51:43 +00:00
|
|
|
wxChar type = getStringSelection( m_dcSourceType2 ).Upper().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 );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_SETTINGS::updateDCUnits( wxChar aType, wxChoice* aSource,
|
|
|
|
wxStaticText* aStartValUnit, wxStaticText* aEndValUnit,
|
|
|
|
wxStaticText* aStepUnit )
|
|
|
|
{
|
|
|
|
wxString unit;
|
|
|
|
|
|
|
|
switch( aType )
|
|
|
|
{
|
2021-03-08 10:51:43 +00:00
|
|
|
case 'V': unit = _( "Volts" ); break;
|
|
|
|
case 'I': unit = _( "Amperes" ); break;
|
|
|
|
case 'R': unit = _( "Ohms" ); break;
|
2021-01-25 21:29:13 +00:00
|
|
|
case 'T': unit = wxT( "\u00B0C" ); break;
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-11 12:41:36 +00:00
|
|
|
void DIALOG_SIM_SETTINGS::loadDirectives()
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
2016-08-11 12:41:30 +00:00
|
|
|
if( m_exporter )
|
|
|
|
m_customTxt->SetValue( m_exporter->GetSheetSimCommand() );
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
2016-08-11 12:41:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
void DIALOG_SIM_SETTINGS::updateNetlistOpts()
|
|
|
|
{
|
|
|
|
m_netlistOpts = NET_ALL_FLAGS;
|
|
|
|
|
|
|
|
if( !m_fixPassiveVals->IsChecked() )
|
|
|
|
m_netlistOpts &= ~NET_ADJUST_PASSIVE_VALS;
|
|
|
|
|
|
|
|
if( !m_fixIncludePaths->IsChecked() )
|
|
|
|
m_netlistOpts &= ~NET_ADJUST_INCLUDE_PATHS;
|
|
|
|
}
|