From 9a0aeb4344fe372304c0211815f07e4d77edd7e7 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 25 Feb 2023 11:38:27 +0000 Subject: [PATCH] Adjust AC-small-signal plot names when saving placeholders. Fixes https://gitlab.com/kicad/code/kicad/issues/14016 --- common/widgets/mathplot.cpp | 5 ++++ eeschema/sim/sim_model.cpp | 6 +++-- eeschema/sim/sim_plot_frame.cpp | 41 +++++++++++++++++++++------------ eeschema/sim/sim_plot_frame.h | 9 +++++--- 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/common/widgets/mathplot.cpp b/common/widgets/mathplot.cpp index e8968fb261..4b9d1c16af 100644 --- a/common/widgets/mathplot.cpp +++ b/common/widgets/mathplot.cpp @@ -563,6 +563,11 @@ void mpFXY::UpdateViewBoundary( wxCoord xnew, wxCoord ynew ) void mpFXY::Plot( wxDC& dc, mpWindow& w ) { + // If trace doesn't have any data yet then it won't have any scale set. In any case, there's + // nothing to plot. + if( !GetCount() ) + return; + wxCHECK_RET( m_scaleX, wxS( "X scale was not set" ) ); wxCHECK_RET( m_scaleY, wxS( "Y scale was not set" ) ); diff --git a/eeschema/sim/sim_model.cpp b/eeschema/sim/sim_model.cpp index aebc75e050..fd6c506d4a 100644 --- a/eeschema/sim/sim_model.cpp +++ b/eeschema/sim/sim_model.cpp @@ -859,8 +859,10 @@ void SIM_MODEL::doSetParamValue( int aParamIndex, const std::string& aValue ) void SIM_MODEL::SetParamValue( int aParamIndex, const std::string& aValue, SIM_VALUE::NOTATION aNotation ) { - // Note: also converts decimal separators to '.' - std::string value = SIM_VALUE::ConvertNotation( aValue, aNotation, SIM_VALUE::NOTATION::SI ); + std::string value = aValue; + + if( aNotation != SIM_VALUE::NOTATION::SI || aValue.find( ',' ) >= 0 ) + value = SIM_VALUE::ConvertNotation( value, aNotation, SIM_VALUE::NOTATION::SI ); doSetParamValue( aParamIndex, value ); } diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 45473ccba2..5b17a1dfe9 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -1138,6 +1138,20 @@ wxString SIM_PLOT_FRAME::getTraceName( int aRow ) } +/** + * AC-small-signal analyses have two traces per signal, so we suffix the names. + */ +wxString SIM_PLOT_FRAME::getTraceTitle( const wxString& aName, SIM_TRACE_TYPE aTraceType ) +{ + if( aTraceType & SPT_AC_MAG ) + return aName + _( " (gain)" ); + else if( aTraceType & SPT_AC_PHASE ) + return aName + _( " (phase)" ); + else + return aName; +} + + void SIM_PLOT_FRAME::onSignalsGridCellChanged( wxGridEvent& aEvent ) { if( m_SuppressGridEvents > 0 ) @@ -1694,14 +1708,9 @@ void SIM_PLOT_FRAME::updateTrace( const wxString& aName, SIM_TRACE_TYPE aTraceTy aTraceType = (SIM_TRACE_TYPE) ( aTraceType & SPT_Y_AXIS_MASK ); aTraceType = (SIM_TRACE_TYPE) ( aTraceType | getXAxisType( simType ) ); - wxString traceTitle = aName; + wxString traceTitle = getTraceTitle( aName, aTraceType ); wxString vectorName = aName; - if( aTraceType & SPT_AC_MAG ) - traceTitle += _( " (gain)" ); - else if( aTraceType & SPT_AC_PHASE ) - traceTitle += _( " (phase)" ); - if( aTraceType & SPT_POWER ) vectorName = vectorName.AfterFirst( '(' ).BeforeLast( ')' ) + wxS( ":power" ); @@ -2233,7 +2242,7 @@ bool SIM_PLOT_FRAME::SaveWorkbook( const wxString& aPath ) for( const auto& [name, trace] : plotPanel->GetTraces() ) { file.AddLine( wxString::Format( wxT( "%d" ), trace->GetType() ) ); - file.AddLine( trace->GetName() ); + file.AddLine( getTraceTitle( trace->GetName(), trace->GetType() ) ); wxString msg = COLOR4D( trace->GetTraceColour() ).ToCSSString(); @@ -2776,12 +2785,13 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent ) struct TRACE_DESC { - wxString m_name; ///< Name of the measured net/device + wxString m_name; ///< Name of the measured SPICE vector + wxString m_title; ///< User-friendly signal name SIM_TRACE_TYPE m_type; ///< Type of the signal bool m_current; }; - std::vector traceInfo; + std::vector placeholders; // Get information about all the traces on the plot; update those that are still in // the signals list and remove any that aren't @@ -2789,27 +2799,28 @@ void SIM_PLOT_FRAME::onSimFinished( wxCommandEvent& aEvent ) { struct TRACE_DESC placeholder; placeholder.m_name = trace->GetName(); + placeholder.m_title = getTraceTitle( trace->GetName(), trace->GetType() ); placeholder.m_type = trace->GetType(); placeholder.m_current = false; for( const wxString& signal : m_signals ) { - if( getTraceName( signal ) == placeholder.m_name ) + if( getTraceName( signal ) == placeholder.m_title ) { placeholder.m_current = true; break; } } - traceInfo.push_back( placeholder ); + placeholders.push_back( placeholder ); } - for( const struct TRACE_DESC& trace : traceInfo ) + for( const struct TRACE_DESC& placeholder : placeholders ) { - if( trace.m_current ) - updateTrace( trace.m_name, trace.m_type, plotPanel ); + if( placeholder.m_current ) + updateTrace( placeholder.m_name, placeholder.m_type, plotPanel ); else - removeTrace( trace.m_name ); + removeTrace( placeholder.m_name ); } rebuildSignalsGrid( m_filter->GetValue() ); diff --git a/eeschema/sim/sim_plot_frame.h b/eeschema/sim/sim_plot_frame.h index 4a43e48de8..572037aee9 100644 --- a/eeschema/sim/sim_plot_frame.h +++ b/eeschema/sim/sim_plot_frame.h @@ -268,6 +268,12 @@ private: wxString getTraceName( const wxString& aSignalName ); wxString getTraceName( int aRow ); + /** + * AC-small-signal analyses have specific trace titles. Other analyses use the raw signal + * names. + */ + wxString getTraceTitle( const wxString& aSignalName, SIM_TRACE_TYPE aTraceType ); + /** * Remove a plot with a specific title. * @@ -326,9 +332,6 @@ private: return dynamic_cast( m_plotNotebook->GetCurrentPage() ); } - /** - * - */ /** * Return X axis for a given simulation type. */