From 8672cdb3bd58e421adbbc810de81d740da6a50d5 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 19 Sep 2023 17:37:20 +0100 Subject: [PATCH] Handle power operating points. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15689 --- eeschema/sim/simulator_frame_ui.cpp | 41 +++++++++++++++++++--------- eeschema/sim/spice_circuit_model.cpp | 7 +++++ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/eeschema/sim/simulator_frame_ui.cpp b/eeschema/sim/simulator_frame_ui.cpp index 2c0cdc1888..aa26de4df8 100644 --- a/eeschema/sim/simulator_frame_ui.cpp +++ b/eeschema/sim/simulator_frame_ui.cpp @@ -1301,26 +1301,28 @@ void SIMULATOR_FRAME_UI::UpdateMeasurement( int aRow ) { switch( plotTab->GetSimType() ) { - case SIM_TYPE::ST_TRAN: + case ST_TRAN: if ( signalType.StartsWith( 'P' ) ) units = wxS( "J" ); else units += wxS( ".s" ); + break; - case SIM_TYPE::ST_AC: - case SIM_TYPE::ST_SP: - case SIM_TYPE::ST_DISTO: - case SIM_TYPE::ST_NOISE: - case SIM_TYPE::ST_FFT: - case SIM_TYPE::ST_SENS: // If there is a vector, it is frequency + + case ST_AC: + case ST_SP: + case ST_DISTO: + case ST_NOISE: + case ST_FFT: + case ST_SENS: // If there is a vector, it is frequency units += wxS( "·Hz" ); break; - case SIM_TYPE::ST_DC: // Could be a lot of things : V, A, deg C, ohm, ... - case SIM_TYPE::ST_OP: // There is no vector for integration - case SIM_TYPE::ST_PZ: // There is no vector for integration - case SIM_TYPE::ST_TF: // There is no vector for integration - default: + case ST_DC: // Could be a lot of things : V, A, deg C, ohm, ... + case ST_OP: // There is no vector for integration + case ST_PZ: // There is no vector for integration + case ST_TF: // There is no vector for integration + default: units += wxS( "·?" ); break; } @@ -2713,7 +2715,20 @@ void SIMULATOR_FRAME_UI::OnSimRefresh( bool aFinal ) const size_t tab = 25; //characters size_t padding = ( signal.length() < tab ) ? ( tab - signal.length() ) : 1; - value.Append( type == SPT_CURRENT ? wxS( "A" ) : wxS( "V" ) ); + switch( type ) + { + case SPT_VOLTAGE: + value.Append( wxS( "V" ) ); + break; + + case SPT_CURRENT: + value.Append( wxS( "A" ) ); + break; + + case SPT_POWER: + value.Append( wxS( "W" ) ); + break; + } msg.Printf( wxT( "%s%s\n" ), ( signal + wxT( ":" ) ).Pad( padding, wxUniChar( ' ' ) ), diff --git a/eeschema/sim/spice_circuit_model.cpp b/eeschema/sim/spice_circuit_model.cpp index 8be5e29382..ce288eb130 100644 --- a/eeschema/sim/spice_circuit_model.cpp +++ b/eeschema/sim/spice_circuit_model.cpp @@ -34,6 +34,8 @@ SIM_TRACE_TYPE SPICE_CIRCUIT_MODEL::VectorToSignal( const std::string& aVector, wxString& aSignal ) const { static wxString BRANCH( wxS( "#branch" ) ); + static wxString POWER( wxS( ":power" ) ); + // See ngspice manual chapt. 31.1 "Accessing internal device parameters" static wxRegEx internalDevParameter( wxS( "^@(\\w*[\\.\\w+]*)\\[(\\w*)\\]$" ), wxRE_ADVANCED ); @@ -46,6 +48,11 @@ SIM_TRACE_TYPE SPICE_CIRCUIT_MODEL::VectorToSignal( const std::string& aVector, aSignal = wxT( "I(" ) + vector.Left( vector.Length() - BRANCH.Length() ) + wxT( ")" ); return SPT_CURRENT; } + else if( vector.EndsWith( POWER ) ) + { + aSignal = wxT( "P(" ) + vector.Left( vector.Length() - POWER.Length() ) + wxT( ")" ); + return SPT_POWER; + } else { aSignal = wxT( "V(" ) + vector + wxT( ")" );