Save location of legend in worksheet.

Also provides a different cursor when over a legend (to make it clearer
that you can drag it).
This commit is contained in:
Jeff Young 2023-03-20 09:43:16 +00:00
parent ec6d709929
commit a14c017def
3 changed files with 59 additions and 14 deletions

View File

@ -1869,7 +1869,10 @@ void mpWindow::OnMouseMove( wxMouseEvent& event )
{ {
if( m_movingInfoLayer ) if( m_movingInfoLayer )
{ {
cursor = wxCURSOR_SIZEWE; if( dynamic_cast<mpInfoLegend*>( m_movingInfoLayer ) )
cursor = wxCURSOR_SIZING;
else
cursor = wxCURSOR_SIZEWE;
wxPoint moveVector( event.GetX() - m_mouseLClick.x, event.GetY() - m_mouseLClick.y ); wxPoint moveVector( event.GetX() - m_mouseLClick.x, event.GetY() - m_mouseLClick.y );
m_movingInfoLayer->Move( moveVector ); m_movingInfoLayer->Move( moveVector );
@ -1903,7 +1906,12 @@ void mpWindow::OnMouseMove( wxMouseEvent& event )
mpInfoLayer* infoLayer = (mpInfoLayer*) layer; mpInfoLayer* infoLayer = (mpInfoLayer*) layer;
if( infoLayer->Inside( event.GetPosition() ) ) if( infoLayer->Inside( event.GetPosition() ) )
cursor = wxCURSOR_SIZEWE; {
if( dynamic_cast<mpInfoLegend*>( infoLayer ) )
cursor = wxCURSOR_SIZING;
else
cursor = wxCURSOR_SIZEWE;
}
} }
} }

View File

@ -266,6 +266,17 @@ public:
return m_legend->IsVisible(); return m_legend->IsVisible();
} }
wxPoint GetLegendPosition() const
{
return m_legend->GetPosition();
}
void SetLegendPosition( const wxPoint& aPosition )
{
m_legend->Move( aPosition );
m_legend->UpdateReference();
}
/** /**
* Draw secondary signal traces (current or phase) with dotted lines * Draw secondary signal traces (current or phase) with dotted lines
*/ */

View File

@ -1985,10 +1985,6 @@ void SIMULATOR_FRAME::parseTraceParams( SIM_PLOT_PANEL* aPlotPanel, TRACE* aTrac
{ {
aPlotPanel->SetDottedSecondary( true ); aPlotPanel->SetDottedSecondary( true );
} }
else if( item == wxS( "showLegend" ) )
{
aPlotPanel->ShowLegend( true );
}
else if( item == wxS( "hideGrid" ) ) else if( item == wxS( "hideGrid" ) )
{ {
aPlotPanel->ShowGrid( false ); aPlotPanel->ShowGrid( false );
@ -2155,11 +2151,30 @@ bool SIMULATOR_FRAME::LoadWorkbook( const wxString& aPath )
{ {
for( const auto& [ traceType, signalName, param ] : traceInfoVector ) for( const auto& [ traceType, signalName, param ] : traceInfoVector )
{ {
wxString vectorName = vectorNameFromSignalName( signalName, nullptr ); if( traceType == SPT_UNKNOWN && signalName == wxS( "$LEGEND" ) )
TRACE* trace = plotPanel->AddTrace( vectorName, (int) traceType ); {
wxArrayString coords = wxSplit( param, ' ' );
if( version >= 4 && trace ) if( coords.size() >= 2 )
parseTraceParams( plotPanel, trace, signalName, param ); {
long x = 0;
long y = 0;
coords[0].ToLong( &x );
coords[1].ToLong( &y );
plotPanel->SetLegendPosition( wxPoint( (int) x, (int) y ) );
}
plotPanel->ShowLegend( true );
}
else
{
wxString vectorName = vectorNameFromSignalName( signalName, nullptr );
TRACE* trace = plotPanel->AddTrace( vectorName, (int) traceType );
if( version >= 4 && trace )
parseTraceParams( plotPanel, trace, signalName, param );
}
} }
plotPanel->UpdatePlotColors(); plotPanel->UpdatePlotColors();
@ -2283,7 +2298,12 @@ bool SIMULATOR_FRAME::SaveWorkbook( const wxString& aPath )
continue; continue;
} }
file.AddLine( wxString::Format( wxT( "%llu" ), plotPanel->GetTraces().size() ) ); size_t traceCount = plotPanel->GetTraces().size();
if( plotPanel->IsLegendShown() )
traceCount++;
file.AddLine( wxString::Format( wxT( "%llu" ), traceCount ) );
auto findSignalName = auto findSignalName =
[&]( const wxString& aVectorName ) -> wxString [&]( const wxString& aVectorName ) -> wxString
@ -2330,14 +2350,20 @@ bool SIMULATOR_FRAME::SaveWorkbook( const wxString& aPath )
if( plotPanel->GetDottedSecondary() ) if( plotPanel->GetDottedSecondary() )
msg += wxS( "|dottedSecondary" ); msg += wxS( "|dottedSecondary" );
if( plotPanel->IsLegendShown() )
msg += wxS( "|showLegend" );
if( !plotPanel->IsGridShown() ) if( !plotPanel->IsGridShown() )
msg += wxS( "|hideGrid" ); msg += wxS( "|hideGrid" );
file.AddLine( msg ); file.AddLine( msg );
} }
if( plotPanel->IsLegendShown() )
{
file.AddLine( wxString::Format( wxT( "%d" ), SPT_UNKNOWN ) );
file.AddLine( wxT( "$LEGEND" ) );
file.AddLine( wxString::Format( wxT( "%d %d" ),
plotPanel->GetLegendPosition().x,
plotPanel->GetLegendPosition().y - 40 ) );
}
} }
file.AddLine( wxString::Format( wxT( "%llu" ), m_userDefinedSignals.size() ) ); file.AddLine( wxString::Format( wxT( "%llu" ), m_userDefinedSignals.size() ) );