From ec6d709929df64f1e463511774dd345b081c5c53 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 19 Mar 2023 23:02:23 +0000 Subject: [PATCH] Make sure legend reflects gain/phase for AC small signal analyses. Fixes https://gitlab.com/kicad/code/kicad/issues/14301 --- common/widgets/mathplot.cpp | 4 ++-- eeschema/sim/sim_plot_panel.h | 11 ++++++++++- include/widgets/mathplot.h | 27 +++++++++++++++++---------- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/common/widgets/mathplot.cpp b/common/widgets/mathplot.cpp index 6c38249c45..0526ee1065 100644 --- a/common/widgets/mathplot.cpp +++ b/common/widgets/mathplot.cpp @@ -345,7 +345,7 @@ void mpInfoLegend::Plot( wxDC& dc, mpWindow& w ) if( layer->GetLayerType() == mpLAYER_PLOT && layer->IsVisible() ) { - label = layer->GetName(); + label = layer->GetDisplayName(); dc.GetTextExtent( label, &tmpX, &tmpY ); textX = ( textX > tmpX + baseWidth ) ? textX : tmpX + baseWidth + mpLEGEND_MARGIN; textY += tmpY; @@ -368,7 +368,7 @@ void mpInfoLegend::Plot( wxDC& dc, mpWindow& w ) if( layer->GetLayerType() == mpLAYER_PLOT && layer->IsVisible() ) { - label = layer->GetName(); + label = layer->GetDisplayName(); lpen = layer->GetPen(); dc.GetTextExtent( label, &tmpX, &tmpY ); dc.SetPen( lpen ); diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index b94883ebd5..00f9f08939 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -131,9 +131,11 @@ public: SetContinuity( true ); SetDrawOutsideMargins( false ); ShowName( false ); + + SetName( aName ); } - void SetName( wxString aName ) override + void SetName( const wxString& aName ) override { for( auto& [ idx, cursor ] : m_cursors ) { @@ -142,6 +144,13 @@ public: } mpFXYVector::SetName( aName ); + + if( m_type & SPT_AC_MAG ) + m_displayName = aName + _( " (gain)" ); + else if( m_type & SPT_AC_PHASE ) + m_displayName = aName + _( " (phase)" ); + else + m_displayName = aName; } /** diff --git a/include/widgets/mathplot.h b/include/widgets/mathplot.h index a57cd823f2..5c31fec181 100644 --- a/include/widgets/mathplot.h +++ b/include/widgets/mathplot.h @@ -237,6 +237,11 @@ public: */ const wxString& GetName() const { return m_name; } + const wxString& GetDisplayName() const + { + return m_displayName.IsEmpty() ? m_name : m_displayName; + } + /** Get font set for this layer. * @return Font */ @@ -264,7 +269,7 @@ public: /** Set layer name * @param name Name, will be copied to internal class member */ - virtual void SetName( wxString name ) { m_name = name; } + virtual void SetName( const wxString& name ) { m_name = name; } /** Set layer font * @param font Font, will be copied to internal class member @@ -311,15 +316,17 @@ public: protected: - wxFont m_font; // !< Layer's font - wxPen m_pen; // !< Layer's pen - wxBrush m_brush; // !< Layer's brush - wxString m_name; // !< Layer's name - bool m_continuous; // !< Specify if the layer will be plotted as a continuous line or a set of points. - bool m_showName; // !< States whether the name of the layer must be shown (default is true). - bool m_drawOutsideMargins; // !< select if the layer should draw only inside margins or over all DC - mpLayerType m_type; // !< Define layer type, which is assigned by constructor - bool m_visible; // !< Toggles layer visibility + wxFont m_font; // !< Layer's font + wxPen m_pen; // !< Layer's pen + wxBrush m_brush; // !< Layer's brush + wxString m_name; // !< Layer's name + wxString m_displayName; + bool m_continuous; // !< Specify if the layer will be plotted as a continuous line or a set of points. + bool m_showName; // !< States whether the name of the layer must be shown (default is true). + bool m_drawOutsideMargins; // !< select if the layer should draw only inside margins or over all DC + mpLayerType m_type; // !< Define layer type, which is assigned by constructor + bool m_visible; // !< Toggles layer visibility + DECLARE_DYNAMIC_CLASS( mpLayer ) };