Sort out terminology issues between vectors and plots.

This commit is contained in:
Jeff Young 2023-07-05 11:53:19 +01:00
parent 443a5dc3bb
commit d5d2800b03
10 changed files with 87 additions and 89 deletions

View File

@ -84,6 +84,12 @@ void NGSPICE::Init( const SPICE_SIMULATOR_SETTINGS* aSettings )
}
wxString NGSPICE::CurrentPlotName() const
{
return wxString( m_ngSpice_CurPlot() );
}
std::vector<std::string> NGSPICE::AllVectors() const
{
LOCALE_IO c_locale; // ngspice works correctly only with C locale
@ -112,7 +118,7 @@ std::vector<std::string> NGSPICE::AllVectors() const
}
std::vector<COMPLEX> NGSPICE::GetPlot( const std::string& aName, int aMaxLen )
std::vector<COMPLEX> NGSPICE::GetComplexVector( const std::string& aName, int aMaxLen )
{
LOCALE_IO c_locale; // ngspice works correctly only with C locale
std::vector<COMPLEX> data;
@ -139,7 +145,7 @@ std::vector<COMPLEX> NGSPICE::GetPlot( const std::string& aName, int aMaxLen )
}
std::vector<double> NGSPICE::GetRealPlot( const std::string& aName, int aMaxLen )
std::vector<double> NGSPICE::GetRealVector( const std::string& aName, int aMaxLen )
{
LOCALE_IO c_locale; // ngspice works correctly only with C locale
std::vector<double> data;
@ -169,7 +175,7 @@ std::vector<double> NGSPICE::GetRealPlot( const std::string& aName, int aMaxLen
}
std::vector<double> NGSPICE::GetImagPlot( const std::string& aName, int aMaxLen )
std::vector<double> NGSPICE::GetImaginaryVector( const std::string& aName, int aMaxLen )
{
LOCALE_IO c_locale; // ngspice works correctly only with C locale
std::vector<double> data;
@ -191,7 +197,7 @@ std::vector<double> NGSPICE::GetImagPlot( const std::string& aName, int aMaxLen
}
std::vector<double> NGSPICE::GetMagPlot( const std::string& aName, int aMaxLen )
std::vector<double> NGSPICE::GetGainVector( const std::string& aName, int aMaxLen )
{
LOCALE_IO c_locale; // ngspice works correctly only with C locale
std::vector<double> data;
@ -218,7 +224,7 @@ std::vector<double> NGSPICE::GetMagPlot( const std::string& aName, int aMaxLen )
}
std::vector<double> NGSPICE::GetPhasePlot( const std::string& aName, int aMaxLen )
std::vector<double> NGSPICE::GetPhaseVector( const std::string& aName, int aMaxLen )
{
LOCALE_IO c_locale; // ngspice works correctly only with C locale
std::vector<double> data;

View File

@ -80,23 +80,26 @@ public:
///< @copydoc SPICE_SIMULATOR::GetXAxis()
wxString GetXAxis( SIM_TYPE aType ) const override final;
///< @copydoc SPICE_SIMULATOR::CurrentPlotName()
wxString CurrentPlotName() const override final;
///< @copydoc SPICE_SIMULATOR::AllVectors()
std::vector<std::string> AllVectors() const override final;
///< @copydoc SPICE_SIMULATOR::GetPlot()
std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetComplexVector()
std::vector<COMPLEX> GetComplexVector( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetRealPlot()
std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetRealVector()
std::vector<double> GetRealVector( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetImagPlot()
std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetImaginaryVector()
std::vector<double> GetImaginaryVector( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetMagPlot()
std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetGainVector()
std::vector<double> GetGainVector( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetPhasePlot()
std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) override final;
///< @copydoc SPICE_SIMULATOR::GetPhaseVector()
std::vector<double> GetPhaseVector( const std::string& aName, int aMaxLen = -1 ) override final;
std::vector<std::string> GetSettingCommands() const override final;

View File

@ -145,7 +145,7 @@ public:
mpFXYVector::SetName( aName );
if( m_type & SPT_AC_MAG )
if( m_type & SPT_AC_GAIN )
m_displayName = aName + _( " (gain)" );
else if( m_type & SPT_AC_PHASE )
m_displayName = aName + _( " (phase)" );

View File

@ -50,7 +50,7 @@ enum SIM_TRACE_TYPE
SPT_VOLTAGE = 0x0001,
SPT_CURRENT = 0x0002,
SPT_AC_PHASE = 0x0004,
SPT_AC_MAG = 0x0008,
SPT_AC_GAIN = 0x0008,
SPT_POWER = 0x0010,
SPT_SP_AMP = 0x0020,
SPT_Y_AXIS_MASK = 0x00FF,

View File

@ -907,8 +907,8 @@ wxString vectorNameFromSignalId( int aUserDefinedSignalId )
wxString SIMULATOR_PANEL::vectorNameFromSignalName( const wxString& aSignalName, int* aTraceType )
{
std::map<wxString, int> suffixes;
suffixes[_( " (amplitude)" )] = SPT_SP_AMP;
suffixes[ _( " (gain)" ) ] = SPT_AC_MAG;
suffixes[ _( " (amplitude)" ) ] = SPT_SP_AMP;
suffixes[ _( " (gain)" ) ] = SPT_AC_GAIN;
suffixes[ _( " (phase)" ) ] = SPT_AC_PHASE;
if( aTraceType )
@ -1234,7 +1234,7 @@ void SIMULATOR_PANEL::UpdateMeasurement( int aRow )
simulator()->Command( "echo " + cmd.ToStdString() );
simulator()->Command( cmd.ToStdString() );
std::vector<double> resultVec = simulator()->GetMagPlot( resultName.ToStdString() );
std::vector<double> resultVec = simulator()->GetGainVector( resultName.ToStdString() );
if( resultVec.size() > 0 )
result = SPICE_VALUE( resultVec[0] ).ToString( GetMeasureFormat( aRow ) );
@ -1410,12 +1410,12 @@ void SIMULATOR_PANEL::AddTrace( const wxString& aName, SIM_TRACE_TYPE aType )
if( simType == ST_AC )
{
updateTrace( aName, aType | SPT_AC_MAG, plotPanel );
updateTrace( aName, aType | SPT_AC_GAIN, plotPanel );
updateTrace( aName, aType | SPT_AC_PHASE, plotPanel );
}
if( simType == ST_S_PARAM )
{
updateTrace( aName, aType | SPT_AC_MAG, plotPanel );
updateTrace( aName, aType | SPT_AC_GAIN, plotPanel );
updateTrace( aName, aType | SPT_AC_PHASE, plotPanel );
}
else
@ -1446,7 +1446,7 @@ void SIMULATOR_PANEL::SetUserDefinedSignals( const std::map<int, wxString>& aNew
{
if( plotPanel->GetSimType() == ST_AC )
{
for( int subType : { SPT_AC_MAG, SPT_AC_PHASE } )
for( int subType : { SPT_AC_GAIN, SPT_AC_PHASE } )
plotPanel->DeleteTrace( vectorName, traceType | subType );
}
else if( plotPanel->GetSimType() == ST_S_PARAM )
@ -1463,7 +1463,7 @@ void SIMULATOR_PANEL::SetUserDefinedSignals( const std::map<int, wxString>& aNew
{
if( plotPanel->GetSimType() == ST_AC )
{
for( int subType : { SPT_AC_MAG, SPT_AC_PHASE } )
for( int subType : { SPT_AC_GAIN, SPT_AC_PHASE } )
{
if( TRACE* trace = plotPanel->GetTrace( vectorName, traceType | subType ) )
trace->SetName( aNewSignals.at( id ) );
@ -1529,24 +1529,24 @@ void SIMULATOR_PANEL::updateTrace( const wxString& aVectorName, int aTraceType,
std::vector<double> data_x;
std::vector<double> data_y;
data_x = simulator()->GetMagPlot( (const char*) xAxisName.c_str() );
data_x = simulator()->GetGainVector( (const char*) xAxisName.c_str() );
switch( simType )
{
case ST_AC:
if( aTraceType & SPT_AC_MAG )
data_y = simulator()->GetMagPlot( (const char*) simVectorName.c_str() );
if( aTraceType & SPT_AC_GAIN )
data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str() );
else if( aTraceType & SPT_AC_PHASE )
data_y = simulator()->GetPhasePlot( (const char*) simVectorName.c_str() );
data_y = simulator()->GetPhaseVector( (const char*) simVectorName.c_str() );
else
wxFAIL_MSG( wxT( "Plot type missing AC_PHASE or AC_MAG bit" ) );
break;
case ST_S_PARAM:
if( aTraceType & SPT_SP_AMP )
data_y = simulator()->GetMagPlot( (const char*) simVectorName.c_str() );
data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str() );
else if( aTraceType & SPT_AC_PHASE )
data_y = simulator()->GetPhasePlot( (const char*) simVectorName.c_str() );
data_y = simulator()->GetPhaseVector( (const char*) simVectorName.c_str() );
else
wxFAIL_MSG( wxT( "Plot type missing AC_PHASE or SPT_SP_AMP bit" ) );
@ -1555,7 +1555,7 @@ void SIMULATOR_PANEL::updateTrace( const wxString& aVectorName, int aTraceType,
case ST_NOISE:
case ST_DC:
case ST_TRANSIENT:
data_y = simulator()->GetMagPlot( (const char*) simVectorName.c_str() );
data_y = simulator()->GetGainVector( (const char*) simVectorName.c_str() );
break;
default:
@ -2524,11 +2524,14 @@ void SIMULATOR_PANEL::OnSimRefresh( bool aFinal )
m_simConsole->AppendText( _( "\n\nSimulation results:\n\n" ) );
m_simConsole->SetInsertionPointEnd();
// 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.
simulator()->Command( "setplot noise2" );
for( const std::string& vec : simulator()->AllVectors() )
{
std::vector<double> val_list = simulator()->GetRealPlot( vec, 1 );
std::vector<double> val_list = simulator()->GetRealVector( vec, 1 );
wxString value = SPICE_VALUE( val_list[ 0 ] ).ToSpiceString();
msg.Printf( wxS( "%s: %sV\n" ), vec, value );
@ -2556,7 +2559,7 @@ void SIMULATOR_PANEL::OnSimRefresh( bool aFinal )
if( simType == ST_AC )
{
for( int subType : { SPT_AC_MAG, SPT_AC_PHASE } )
for( int subType : { SPT_AC_GAIN, SPT_AC_PHASE } )
{
if( TRACE* trace = plotPanel->GetTrace( vectorName, traceType | subType ) )
traceMap[ trace ] = { vectorName, traceType };
@ -2608,7 +2611,7 @@ void SIMULATOR_PANEL::OnSimRefresh( bool aFinal )
for( const std::string& vec : simulator()->AllVectors() )
{
std::vector<double> val_list = simulator()->GetRealPlot( vec, 1 );
std::vector<double> val_list = simulator()->GetRealVector( vec, 1 );
wxString value = SPICE_VALUE( val_list[ 0 ] ).ToSpiceString();
wxString signal;
SIM_TRACE_TYPE type = circuitModel()->VectorToSignal( vec, signal );

View File

@ -28,6 +28,7 @@
// Include simulator headers after wxWidgets headers to avoid conflicts with Windows headers
// (especially on msys2 + wxWidgets 3.0.x)
#include "ngspice.h"
#include "macros.h"
std::shared_ptr<SPICE_SIMULATOR> SIMULATOR::CreateInstance( const std::string& )
{
@ -53,44 +54,19 @@ wxString SPICE_SIMULATOR::TypeToName( SIM_TYPE aType, bool aShortName )
{
switch( aType )
{
case ST_OP:
return aShortName ? wxString( wxT( "OP" ) )
: _( "Operating Point" );
case ST_AC:
return "AC";
case ST_DC:
return aShortName ? wxString( wxT( "DC" ) )
: _( "DC Sweep" );
case ST_TRANSIENT:
return aShortName ? wxString( wxT( "TRAN" ) )
: _( "Transient" );
case ST_DISTORTION:
return aShortName ? wxString( wxT( "DISTO" ) )
: _( "Distortion" );
case ST_NOISE:
return aShortName ? wxString( wxT( "NOISE" ) )
: _( "Noise" );
case ST_POLE_ZERO:
return aShortName ? wxString( wxT( "PZ" ) )
: _( "Pole-zero" );
case ST_SENSITIVITY:
return aShortName ? wxString( wxT( "SENS" ) )
: _( "Sensitivity" );
case ST_TRANS_FUNC:
return aShortName ? wxString( wxT( "TF" ) )
: _( "Transfer function" );
case ST_S_PARAM: return aShortName ? wxString( wxT( "SP" ) ) : _( "S-Parameters" );
case ST_OP: return aShortName ? wxString( wxT( "OP" ) ) : _( "Operating Point" );
case ST_AC: return aShortName ? wxString( wxT( "AC" ) ) : _( "AC" );
case ST_DC: return aShortName ? wxString( wxT( "DC" ) ) : _( "DC Sweep" );
case ST_TRANSIENT: return aShortName ? wxString( wxT( "TRAN" ) ) : _( "Transient" );
case ST_DISTORTION: return aShortName ? wxString( wxT( "DISTO" ) ) : _( "Distortion" );
case ST_NOISE: return aShortName ? wxString( wxT( "NOISE" ) ) : _( "Noise" );
case ST_POLE_ZERO: return aShortName ? wxString( wxT( "PZ" ) ) : _( "Pole-zero" );
case ST_SENSITIVITY: return aShortName ? wxString( wxT( "SENS" ) ) : _( "Sensitivity" );
case ST_TRANS_FUNC: return aShortName ? wxString( wxT( "TF" ) ) : _( "Transfer function" );
case ST_S_PARAM: return aShortName ? wxString( wxT( "SP" ) ) : _( "S-Parameters" );
default:
case ST_UNKNOWN:
return aShortName ? _( "UNKNOWN!" ) : _( "Unknown" );
case ST_UNKNOWN: return aShortName ? wxString( wxT( "??" ) ) : _( "Unknown" );
}
}

View File

@ -87,9 +87,12 @@ public:
}
/**
* Return a list with all vectors generated in current simulation.
*
* @return List of vector names. ?May not match to the net name elements.
* @return the current simulation plot name (tran1, tran2, etc.)
*/
virtual wxString CurrentPlotName() const = 0;
/**
* @return list of simulation vector (signal) names.
*/
virtual std::vector<std::string> AllVectors() const = 0;
@ -102,7 +105,7 @@ public:
* if -1 (default) all available values are returned.
* @return Requested vector. It might be empty if there is no vector with requested name.
*/
virtual std::vector<COMPLEX> GetPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<COMPLEX> GetComplexVector( const std::string& aName, int aMaxLen = -1 ) = 0;
/**
* Return a requested vector with real values. If the vector is complex, then
@ -113,7 +116,7 @@ public:
* if -1 (default) all available values are returned.
* @return Requested vector. It might be empty if there is no vector with requested name.
*/
virtual std::vector<double> GetRealPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetRealVector( const std::string& aName, int aMaxLen = -1 ) = 0;
/**
* Return a requested vector with imaginary values. If the vector is complex, then
@ -124,7 +127,7 @@ public:
* if -1 (default) all available values are returned.
* @return Requested vector. It might be empty if there is no vector with requested name.
*/
virtual std::vector<double> GetImagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetImaginaryVector( const std::string& aName, int aMaxLen = -1 ) = 0;
/**
* Return a requested vector with magnitude values.
@ -134,7 +137,7 @@ public:
* if -1 (default) all available values are returned.
* @return Requested vector. It might be empty if there is no vector with requested name.
*/
virtual std::vector<double> GetMagPlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetGainVector( const std::string& aName, int aMaxLen = -1 ) = 0;
/**
* Return a requested vector with phase values.
@ -144,7 +147,7 @@ public:
* if -1 (default) all available values are returned.
* @return Requested vector. It might be empty if there is no vector with requested name.
*/
virtual std::vector<double> GetPhasePlot( const std::string& aName, int aMaxLen = -1 ) = 0;
virtual std::vector<double> GetPhaseVector( const std::string& aName, int aMaxLen = -1 ) = 0;
/**
* Return current SPICE netlist used by the simulator.

View File

@ -1195,14 +1195,20 @@ TOOL_ACTION EE_ACTIONS::simTune( "eeschema.Simulation.tune",
_( "Add Tuned Value..." ), _( "Select a value to be tuned" ),
BITMAPS::sim_tune );
TOOL_ACTION EE_ACTIONS::editUserDefinedSignals( "eeschema.Simulation.editUserDefinedSignals",
AS_GLOBAL, 0, "",
_( "User-defined Signals..." ),
_( "Add, edit or delete user-defined simulation signals" ),
BITMAPS::sim_add_signal );
TOOL_ACTION EE_ACTIONS::showFFT( "eeschema.Simulation.showFFT",
AS_GLOBAL, 0, "",
_( "Show FFT" ),
_( "Show frequency distribution of transient analysis data using fast Fourier transform" ),
BITMAPS::mw_add_shape );
TOOL_ACTION EE_ACTIONS::showNetlist( "eeschema.Simulation.showNetlist",
AS_GLOBAL, 0, "",
_( "Show SPICE Netlist" ), "",
BITMAPS::netlist );
TOOL_ACTION EE_ACTIONS::editUserDefinedSignals( "eeschema.Simulation.editUserDefinedSignals",
AS_GLOBAL, 0, "",
_( "User-defined Signals" ),
_( "Add, edit or delete user-defined simulation signals" ),
BITMAPS::sim_add_signal );

View File

@ -277,6 +277,7 @@ public:
static TOOL_ACTION runSimulation;
static TOOL_ACTION stopSimulation;
static TOOL_ACTION editUserDefinedSignals;
static TOOL_ACTION showFFT;
static TOOL_ACTION showNetlist;
// Net highlighting

View File

@ -193,7 +193,7 @@ public:
{
NGSPICE* ngspice = static_cast<NGSPICE*>( m_simulator.get() );
std::vector<double> vector = ngspice->GetRealPlot( aVectorName );
std::vector<double> vector = ngspice->GetRealVector( aVectorName );
BOOST_REQUIRE_EQUAL( vector.size(), 1 );
@ -214,7 +214,7 @@ public:
{
NGSPICE* ngspice = static_cast<NGSPICE*>( m_simulator.get() );
std::vector<double> xVector = ngspice->GetRealPlot( aXVectorName );
std::vector<double> xVector = ngspice->GetRealVector( aXVectorName );
std::size_t i = 0;
for(; i < xVector.size(); ++i )
@ -237,7 +237,7 @@ public:
for( auto& [vectorName, refValue] : aTestVectorsAndValues )
{
std::vector<double> yVector = ngspice->GetMagPlot( vectorName );
std::vector<double> yVector = ngspice->GetGainVector( vectorName );
BOOST_REQUIRE_GE( yVector.size(), i + 1 );