Browse Source

Clean up third axis

Ensure that there are better displays and detects potential power
signals

Fixes https://gitlab.com/kicad/code/kicad/-/issues/21645

(cherry picked from commit c00e818688)
9.0
Seth Hillbrand 1 week ago
parent
commit
a33003cf62
  1. 47
      eeschema/sim/sim_plot_tab.cpp
  2. 27
      eeschema/sim/simulator_frame_ui.cpp

47
eeschema/sim/sim_plot_tab.cpp

@ -659,15 +659,8 @@ void SIM_PLOT_TAB::updateAxes( int aNewTraceType )
m_axis_y1->SetName( _( "Voltage" ) );
m_axis_y2->SetName( _( "Current" ) );
if( ( aNewTraceType & SPT_POWER ) && !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 );
}
if( aNewTraceType & SPT_POWER )
EnsureThirdYAxisExists();
if( m_axis_y3 )
m_axis_y3->SetName( _( "Power" ) );
@ -679,6 +672,27 @@ void SIM_PLOT_TAB::updateAxes( int aNewTraceType )
break;
}
if( GetSimType() == ST_TRAN || GetSimType() == ST_DC )
{
if( m_axis_y3 )
{
m_plotWin->SetMargins( 30, 160, 45, 70 );
if( m_axis_y2 )
m_axis_y2->SetNameAlign( mpALIGN_BORDER_RIGHT );
m_axis_y3->SetAlign( mpALIGN_BORDER_RIGHT );
m_axis_y3->SetNameAlign( mpALIGN_BORDER_RIGHT );
}
else
{
m_plotWin->SetMargins( 30, 70, 45, 70 );
if( m_axis_y2 )
m_axis_y2->SetNameAlign( mpALIGN_RIGHT );
}
}
if( m_axis_x )
m_axis_x->SetFont( KIUI::GetStatusFont( m_plotWin ) );
@ -792,12 +806,21 @@ 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_plotWin->SetMargins( 30, 160, 45, 70 );
m_axis_y3 = new LIN_SCALE<mpScaleY>( wxEmptyString, wxT( "W" ), mpALIGN_BORDER_RIGHT );
m_axis_y3->SetNameAlign( mpALIGN_BORDER_RIGHT );
m_axis_y3->SetMasterScale( m_axis_y1 );
m_plotWin->AddLayer( m_axis_y3 );
}
if( m_axis_y3 )
{
m_axis_y3->SetAlign( mpALIGN_BORDER_RIGHT );
m_axis_y3->SetNameAlign( mpALIGN_BORDER_RIGHT );
}
if( m_axis_y2 )
m_axis_y2->SetNameAlign( mpALIGN_BORDER_RIGHT );
}

27
eeschema/sim/simulator_frame_ui.cpp

@ -1045,6 +1045,25 @@ wxString SIMULATOR_FRAME_UI::vectorNameFromSignalName( SIM_PLOT_TAB* aPlotTab,
const wxString& aSignalName,
int* aTraceType )
{
auto looksLikePower = []( const wxString& aExpression ) -> bool
{
wxString exprUpper = aExpression.Upper();
if( exprUpper.Contains( wxS( ":POWER" ) ) )
return true;
if( exprUpper.Find( '*' ) == wxNOT_FOUND )
return false;
if( !exprUpper.Contains( wxS( "V(" ) ) )
return false;
if( !exprUpper.Contains( wxS( "I(" ) ) )
return false;
return true;
};
std::map<wxString, int> suffixes;
suffixes[ _( " (amplitude)" ) ] = SPT_SP_AMP;
suffixes[ _( " (gain)" ) ] = SPT_AC_GAIN;
@ -1091,7 +1110,15 @@ wxString SIMULATOR_FRAME_UI::vectorNameFromSignalName( SIM_PLOT_TAB* aPlotTab,
for( const auto& [ id, signal ] : m_userDefinedSignals )
{
if( name == signal )
{
if( aTraceType && looksLikePower( signal ) )
{
int suffixBits = *aTraceType & ( SPT_AC_GAIN | SPT_AC_PHASE | SPT_SP_AMP );
*aTraceType = suffixBits | SPT_POWER;
}
return vectorNameFromSignalId( id );
}
}
return name;

Loading…
Cancel
Save