Make sure to create power axis when restoring state

Fixes https://gitlab.com/kicad/code/kicad/-/issues/16912
This commit is contained in:
Jon Evans 2024-02-08 17:48:12 -05:00
parent 7929d7cda2
commit ca6b40ef1c
3 changed files with 21 additions and 9 deletions

View File

@ -469,18 +469,21 @@ SIM_PLOT_TAB::~SIM_PLOT_TAB()
void SIM_PLOT_TAB::SetY1Scale( bool aLock, double aMin, double aMax ) void SIM_PLOT_TAB::SetY1Scale( bool aLock, double aMin, double aMax )
{ {
wxCHECK( m_axis_y1, /* void */ );
m_axis_y1->SetAxisMinMax( aLock, aMin, aMax ); m_axis_y1->SetAxisMinMax( aLock, aMin, aMax );
} }
void SIM_PLOT_TAB::SetY2Scale( bool aLock, double aMin, double aMax ) void SIM_PLOT_TAB::SetY2Scale( bool aLock, double aMin, double aMax )
{ {
wxCHECK( m_axis_y2, /* void */ );
m_axis_y2->SetAxisMinMax( aLock, aMin, aMax ); m_axis_y2->SetAxisMinMax( aLock, aMin, aMax );
} }
void SIM_PLOT_TAB::SetY3Scale( bool aLock, double aMin, double aMax ) void SIM_PLOT_TAB::SetY3Scale( bool aLock, double aMin, double aMax )
{ {
wxCHECK( m_axis_y3, /* void */ );
m_axis_y3->SetAxisMinMax( aLock, aMin, aMax ); m_axis_y3->SetAxisMinMax( aLock, aMin, aMax );
} }
@ -772,15 +775,8 @@ void SIM_PLOT_TAB::prepareDCAxes( int aNewTraceType )
m_axis_y1->SetName( _( "Voltage (measured)" ) ); m_axis_y1->SetName( _( "Voltage (measured)" ) );
m_axis_y2->SetName( _( "Current" ) ); m_axis_y2->SetName( _( "Current" ) );
if( ( aNewTraceType & SPT_POWER ) && !m_axis_y3 ) if( ( aNewTraceType & SPT_POWER ) )
{ EnsureThirdYAxisExists();
m_plotWin->SetMargins( 30, 140, 45, 70 );
m_axis_y3 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "W" ), mpALIGN_FAR_RIGHT );
m_axis_y3->SetNameAlign( mpALIGN_FAR_RIGHT );
m_axis_y3->SetMasterScale( m_axis_y1 );
m_plotWin->AddLayer( m_axis_y3 );
}
if( m_axis_y3 ) if( m_axis_y3 )
m_axis_y3->SetName( _( "Power" ) ); m_axis_y3->SetName( _( "Power" ) );
@ -788,6 +784,19 @@ void SIM_PLOT_TAB::prepareDCAxes( int aNewTraceType )
} }
void SIM_PLOT_TAB::EnsureThirdYAxisExists()
{
if( !m_axis_y3 )
{
m_plotWin->SetMargins( 30, 140, 45, 70 );
m_axis_y3 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "W" ), mpALIGN_FAR_RIGHT );
m_axis_y3->SetNameAlign( mpALIGN_FAR_RIGHT );
m_axis_y3->SetMasterScale( m_axis_y1 );
m_plotWin->AddLayer( m_axis_y3 );
}
}
void SIM_PLOT_TAB::UpdatePlotColors() void SIM_PLOT_TAB::UpdatePlotColors()
{ {
// Update bg and fg colors: // Update bg and fg colors:

View File

@ -353,6 +353,8 @@ public:
std::vector<std::pair<wxString, wxString>>& Measurements() { return m_measurements; } std::vector<std::pair<wxString, wxString>>& Measurements() { return m_measurements; }
void EnsureThirdYAxisExists();
public: public:
wxPoint m_LastLegendPosition; wxPoint m_LastLegendPosition;

View File

@ -1976,6 +1976,7 @@ bool SIMULATOR_FRAME_UI::loadJsonWorkbook( const wxString& aPath )
if( tab_js.contains( "fixedY3scale" ) ) if( tab_js.contains( "fixedY3scale" ) )
{ {
plotTab->EnsureThirdYAxisExists();
const nlohmann::json& scale_js = tab_js[ "fixedY3scale" ]; const nlohmann::json& scale_js = tab_js[ "fixedY3scale" ];
plotTab->SetY3Scale( true, scale_js[ "min" ], scale_js[ "max" ] ); plotTab->SetY3Scale( true, scale_js[ "min" ], scale_js[ "max" ] );
plotTab->GetPlotWin()->LockY( true ); plotTab->GetPlotWin()->LockY( true );