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 )
{
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 );
m_movingInfoLayer->Move( moveVector );
@ -1903,7 +1906,12 @@ void mpWindow::OnMouseMove( wxMouseEvent& event )
mpInfoLayer* infoLayer = (mpInfoLayer*) layer;
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();
}
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
*/

View File

@ -1985,10 +1985,6 @@ void SIMULATOR_FRAME::parseTraceParams( SIM_PLOT_PANEL* aPlotPanel, TRACE* aTrac
{
aPlotPanel->SetDottedSecondary( true );
}
else if( item == wxS( "showLegend" ) )
{
aPlotPanel->ShowLegend( true );
}
else if( item == wxS( "hideGrid" ) )
{
aPlotPanel->ShowGrid( false );
@ -2155,11 +2151,30 @@ bool SIMULATOR_FRAME::LoadWorkbook( const wxString& aPath )
{
for( const auto& [ traceType, signalName, param ] : traceInfoVector )
{
wxString vectorName = vectorNameFromSignalName( signalName, nullptr );
TRACE* trace = plotPanel->AddTrace( vectorName, (int) traceType );
if( traceType == SPT_UNKNOWN && signalName == wxS( "$LEGEND" ) )
{
wxArrayString coords = wxSplit( param, ' ' );
if( version >= 4 && trace )
parseTraceParams( plotPanel, trace, signalName, param );
if( coords.size() >= 2 )
{
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();
@ -2283,7 +2298,12 @@ bool SIMULATOR_FRAME::SaveWorkbook( const wxString& aPath )
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 =
[&]( const wxString& aVectorName ) -> wxString
@ -2330,14 +2350,20 @@ bool SIMULATOR_FRAME::SaveWorkbook( const wxString& aPath )
if( plotPanel->GetDottedSecondary() )
msg += wxS( "|dottedSecondary" );
if( plotPanel->IsLegendShown() )
msg += wxS( "|showLegend" );
if( !plotPanel->IsGridShown() )
msg += wxS( "|hideGrid" );
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() ) );