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-03 14:45:58 +00:00
|
|
|
* Copyright (C) 2021-2023 KiCad Developers, see AUTHORS.txt for contributors.
|
2021-03-18 19:31:02 +00:00
|
|
|
*
|
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
|
|
|
#ifndef DIALOG_SIM_COMMAND_H
|
|
|
|
#define DIALOG_SIM_COMMAND_H
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
#include "dialog_sim_command_base.h"
|
2023-01-14 00:17:33 +00:00
|
|
|
#include <netlist_exporter_spice.h>
|
2016-08-11 12:41:54 +00:00
|
|
|
#include <sim/spice_value.h>
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
#include <wx/valnum.h>
|
|
|
|
|
2022-03-05 23:49:25 +00:00
|
|
|
class NGSPICE_CIRCUIT_MODEL;
|
2021-03-18 19:31:02 +00:00
|
|
|
class SPICE_SIMULATOR_SETTINGS;
|
2023-07-05 17:25:52 +00:00
|
|
|
class SIMULATOR_FRAME;
|
2021-03-18 19:31:02 +00:00
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
class DIALOG_SIM_COMMAND : public DIALOG_SIM_COMMAND_BASE
|
2016-08-11 12:41:29 +00:00
|
|
|
{
|
|
|
|
public:
|
2023-07-05 17:25:52 +00:00
|
|
|
DIALOG_SIM_COMMAND( SIMULATOR_FRAME* aParent, std::shared_ptr<NGSPICE_CIRCUIT_MODEL> aCircuitModel,
|
2022-12-11 21:28:04 +00:00
|
|
|
std::shared_ptr<SPICE_SIMULATOR_SETTINGS>& aSettings );
|
2016-08-11 12:41:29 +00:00
|
|
|
|
|
|
|
const wxString& GetSimCommand() const
|
|
|
|
{
|
|
|
|
return m_simCommand;
|
|
|
|
}
|
|
|
|
|
2023-07-03 14:45:58 +00:00
|
|
|
void SetSimCommand( const wxString& aCommand )
|
2016-08-11 12:42:08 +00:00
|
|
|
{
|
2023-07-03 14:45:58 +00:00
|
|
|
parseCommand( aCommand );
|
|
|
|
m_simCommand = aCommand;
|
2023-07-05 17:25:52 +00:00
|
|
|
refreshUIControls();
|
2016-08-11 12:42:08 +00:00
|
|
|
}
|
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
int GetSimOptions() const
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
|
2023-02-20 18:12:58 +00:00
|
|
|
if( !m_saveAllDissipations->GetValue() )
|
|
|
|
options &= ~NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS;
|
|
|
|
|
2023-01-14 00:17:33 +00:00
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetSimOptions( int aOptions )
|
|
|
|
{
|
|
|
|
m_fixIncludePaths->SetValue( aOptions & NETLIST_EXPORTER_SPICE::OPTION_ADJUST_INCLUDE_PATHS );
|
|
|
|
m_saveAllVoltages->SetValue( aOptions & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_VOLTAGES );
|
|
|
|
m_saveAllCurrents->SetValue( aOptions & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_CURRENTS );
|
2023-02-10 20:52:52 +00:00
|
|
|
m_saveAllDissipations->SetValue( aOptions & NETLIST_EXPORTER_SPICE::OPTION_SAVE_ALL_DISSIPATIONS );
|
2023-01-14 00:17:33 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
bool TransferDataFromWindow() override;
|
|
|
|
bool TransferDataToWindow() override;
|
|
|
|
|
2016-09-17 12:38:34 +00:00
|
|
|
// The default dialog Validate() calls the validators of all widgets.
|
|
|
|
// This is not what we want; We want only validators of the selected page
|
2021-03-18 19:31:02 +00:00
|
|
|
// of the notebooks. So disable the wxDialog::Validate(), and let our
|
2016-09-17 12:38:34 +00:00
|
|
|
// TransferDataFromWindow doing the job.
|
|
|
|
virtual bool Validate() override
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
private:
|
|
|
|
enum SCALE_TYPE
|
|
|
|
{
|
|
|
|
DECADE,
|
|
|
|
OCTAVE,
|
|
|
|
LINEAR
|
|
|
|
};
|
|
|
|
|
2021-03-18 19:31:02 +00:00
|
|
|
///< Generate events to update UI state.
|
2021-01-25 21:29:13 +00:00
|
|
|
void refreshUIControls()
|
|
|
|
{
|
|
|
|
wxQueueEvent( m_dcEnable2, new wxCommandEvent( wxEVT_CHECKBOX ) );
|
|
|
|
wxQueueEvent( m_dcSourceType1, new wxCommandEvent( wxEVT_RADIOBOX ) );
|
|
|
|
wxQueueEvent( m_dcSourceType2, new wxCommandEvent( wxEVT_RADIOBOX ) );
|
2023-07-05 17:25:52 +00:00
|
|
|
wxQueueEvent( m_inputSignalsFilter, new wxCommandEvent( wxEVT_TEXT ) );
|
2021-01-25 21:29:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-03-18 19:31:02 +00:00
|
|
|
* Read values from one DC sweep source to form a part of simulation command.
|
|
|
|
*
|
2021-01-25 21:29:13 +00:00
|
|
|
* @return string of four SPICE values if values are correct, empty string upon error.
|
|
|
|
*/
|
|
|
|
wxString evaluateDCControls( wxChoice* aDcSource, wxTextCtrl* aDcStart, wxTextCtrl* aDcStop,
|
|
|
|
wxTextCtrl* aDcIncr );
|
|
|
|
|
|
|
|
/**
|
2021-06-14 18:00:08 +00:00
|
|
|
* Update DC sweep source with symbols from schematic.
|
2021-01-25 21:29:13 +00:00
|
|
|
*/
|
|
|
|
void updateDCSources( wxChar aType, wxChoice* aSource );
|
|
|
|
|
|
|
|
/**
|
2021-03-18 19:31:02 +00:00
|
|
|
* Update units on labels depending on selected source.
|
2021-01-25 21:29:13 +00:00
|
|
|
*/
|
|
|
|
void updateDCUnits( wxChar aType, wxChoice* aSource, wxStaticText* aStartValUnit,
|
|
|
|
wxStaticText* aEndValUnit, wxStaticText* aStepUnit );
|
|
|
|
|
2016-08-20 15:25:51 +00:00
|
|
|
virtual void onInitDlg( wxInitDialogEvent& event ) override
|
|
|
|
{
|
|
|
|
// Call the default wxDialog handler of a wxInitDialogEvent
|
|
|
|
TransferDataToWindow();
|
|
|
|
|
|
|
|
// Now all widgets have the size fixed, call FinishDialogSettings
|
2020-11-16 11:16:44 +00:00
|
|
|
finishDialogSettings();
|
2016-08-20 15:25:51 +00:00
|
|
|
}
|
|
|
|
|
2016-08-11 12:42:08 +00:00
|
|
|
/**
|
2021-03-18 19:31:02 +00:00
|
|
|
* Parse a Spice directive.
|
|
|
|
*
|
2016-08-11 12:42:08 +00:00
|
|
|
* @param aCommand is the directive to be parsed (e.g. ".tran 10n 1000n").
|
|
|
|
*/
|
2023-07-03 14:45:58 +00:00
|
|
|
void parseCommand( const wxString& aCommand );
|
2016-08-11 12:42:08 +00:00
|
|
|
|
2016-08-11 12:41:36 +00:00
|
|
|
void onLoadDirectives( wxCommandEvent& event ) override
|
|
|
|
{
|
|
|
|
loadDirectives();
|
|
|
|
}
|
2016-08-11 12:41:29 +00:00
|
|
|
|
2021-01-25 21:29:13 +00:00
|
|
|
void onDCEnableSecondSource( wxCommandEvent& event ) override;
|
|
|
|
void onSwapDCSources( wxCommandEvent& event ) override;
|
2023-07-05 17:25:52 +00:00
|
|
|
void onDCSource1Selected( wxCommandEvent& event ) override;
|
|
|
|
void onDCSource2Selected( wxCommandEvent& event ) override;
|
2021-01-25 21:29:13 +00:00
|
|
|
|
2016-08-11 12:41:29 +00:00
|
|
|
static wxString scaleToString( int aOption )
|
|
|
|
{
|
|
|
|
switch( aOption )
|
|
|
|
{
|
2022-12-05 20:01:36 +00:00
|
|
|
case DECADE: return wxString( "dec" );
|
|
|
|
case OCTAVE: return wxString( "oct" );
|
|
|
|
case LINEAR: return wxString( "lin" );
|
|
|
|
default: wxFAIL_MSG( "Unhandled scale type" ); return wxEmptyString;
|
2016-08-11 12:41:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-05 17:25:52 +00:00
|
|
|
void OnCommandType( wxCommandEvent& event ) override;
|
|
|
|
void OnFilterMouseMoved( wxMouseEvent& event ) override;
|
|
|
|
void OnFilterText( wxCommandEvent& event ) override;
|
|
|
|
|
2016-08-11 12:41:36 +00:00
|
|
|
void loadDirectives();
|
2016-08-11 12:41:36 +00:00
|
|
|
|
2022-12-05 20:01:36 +00:00
|
|
|
private:
|
2023-07-05 17:25:52 +00:00
|
|
|
SIMULATOR_FRAME* m_simulatorFrame;
|
2022-12-05 20:01:36 +00:00
|
|
|
wxString m_simCommand;
|
|
|
|
std::shared_ptr<NGSPICE_CIRCUIT_MODEL> m_circuitModel;
|
2021-03-18 19:31:02 +00:00
|
|
|
std::shared_ptr<SPICE_SIMULATOR_SETTINGS> m_settings;
|
2022-12-05 20:01:36 +00:00
|
|
|
SPICE_VALIDATOR m_spiceValidator;
|
|
|
|
SPICE_VALIDATOR m_spiceEmptyValidator;
|
|
|
|
wxIntegerValidator<int> m_posIntValidator;
|
2023-07-05 17:25:52 +00:00
|
|
|
std::set<wxString> m_fftInputSignals;
|
2016-08-11 12:41:29 +00:00
|
|
|
};
|
|
|
|
|
2022-12-11 15:49:29 +00:00
|
|
|
#endif /* DIALOG_SIM_COMMAND_H */
|