Save cursor positions in sim workbook.
This commit is contained in:
parent
83dd06e5d1
commit
1e756dbdd8
|
@ -33,7 +33,6 @@
|
|||
|
||||
#include <widgets/mathplot.h>
|
||||
#include <wx/graphics.h>
|
||||
#include <wx/module.h>
|
||||
#include <wx/image.h>
|
||||
|
||||
#include <cmath>
|
||||
|
@ -1717,11 +1716,8 @@ mpWindow::~mpWindow()
|
|||
// Free all the layers:
|
||||
DelAllLayers( true, false );
|
||||
|
||||
if( m_buff_bmp )
|
||||
{
|
||||
delete m_buff_bmp;
|
||||
m_buff_bmp = NULL;
|
||||
}
|
||||
delete m_buff_bmp;
|
||||
m_buff_bmp = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -2189,8 +2185,8 @@ void mpWindow::ZoomOut( const wxPoint& centerPoint, double zoomFactor )
|
|||
m_desiredYmax = m_posY;
|
||||
m_desiredYmin = m_posY - (m_scrY - m_marginTop - m_marginBottom) / m_scaleY; // m_desiredYmin = m_posY - m_scrY / m_scaleY;
|
||||
|
||||
if( !CheckXLimits( m_desiredXmax,
|
||||
m_desiredXmin ) || !CheckYLimits( m_desiredYmax, m_desiredYmin ) )
|
||||
if( !CheckXLimits( m_desiredXmax, m_desiredXmin )
|
||||
|| !CheckYLimits( m_desiredYmax, m_desiredYmin ) )
|
||||
{
|
||||
Fit();
|
||||
}
|
||||
|
@ -2286,7 +2282,7 @@ void mpWindow::OnSize( wxSizeEvent& WXUNUSED( event ) )
|
|||
|
||||
bool mpWindow::AddLayer( mpLayer* layer, bool refreshDisplay )
|
||||
{
|
||||
if( layer != NULL )
|
||||
if( layer )
|
||||
{
|
||||
m_layers.push_back( layer );
|
||||
|
||||
|
@ -2296,14 +2292,11 @@ bool mpWindow::AddLayer( mpLayer* layer, bool refreshDisplay )
|
|||
return true;
|
||||
}
|
||||
|
||||
;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool mpWindow::DelLayer( mpLayer* layer,
|
||||
bool alsoDeleteObject,
|
||||
bool refreshDisplay )
|
||||
bool mpWindow::DelLayer( mpLayer* layer, bool alsoDeleteObject, bool refreshDisplay )
|
||||
{
|
||||
wxLayerList::iterator layIt;
|
||||
|
||||
|
@ -2358,9 +2351,7 @@ void mpWindow::OnPaint( wxPaintEvent& WXUNUSED( event ) )
|
|||
{
|
||||
if( m_last_lx != m_scrX || m_last_ly != m_scrY )
|
||||
{
|
||||
if( m_buff_bmp )
|
||||
delete m_buff_bmp;
|
||||
|
||||
delete m_buff_bmp;
|
||||
m_buff_bmp = new wxBitmap( m_scrX, m_scrY );
|
||||
m_buff_dc.SelectObject( *m_buff_bmp );
|
||||
m_last_lx = m_scrX;
|
||||
|
|
|
@ -506,8 +506,7 @@ void SIM_PLOT_FRAME::ShowChangedLanguage()
|
|||
m_cursorsGrid->SetColLabelValue( COL_CURSOR_SIGNAL, _( "Signal" ) );
|
||||
m_cursorsGrid->SetColLabelValue( COL_CURSOR_X, _( "Time" ) );
|
||||
m_cursorsGrid->SetColLabelValue( COL_CURSOR_Y, _( "Value" ) );
|
||||
wxCommandEvent dummy;
|
||||
onCursorUpdate( dummy );
|
||||
updateCursors();
|
||||
|
||||
for( TUNER_SLIDER* tuner : m_tuners )
|
||||
tuner->ShowChangedLanguage();
|
||||
|
@ -1048,8 +1047,8 @@ void SIM_PLOT_FRAME::onCursorsGridCellChanged( wxGridEvent& aEvent )
|
|||
else if( cursorName == _( "Diff" ) && cursor1 && cursor2 )
|
||||
cursor2->SetCoordX( cursor1->GetCoords().x + value );
|
||||
|
||||
wxCommandEvent dummy;
|
||||
onCursorUpdate( dummy );
|
||||
updateCursors();
|
||||
m_workbookModified = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1342,8 +1341,7 @@ void SIM_PLOT_FRAME::removeTrace( const wxString& aSignalName )
|
|||
plotPanel->GetPlotWin()->Fit();
|
||||
|
||||
updateSignalsGrid();
|
||||
wxCommandEvent dummy;
|
||||
onCursorUpdate( dummy );
|
||||
updateCursors();
|
||||
}
|
||||
|
||||
|
||||
|
@ -1712,7 +1710,8 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath )
|
|||
|
||||
addTrace( name, (SIM_TRACE_TYPE) traceType );
|
||||
|
||||
TRACE* trace = GetCurrentPlot() ? GetCurrentPlot()->GetTrace( name ) : nullptr;
|
||||
SIM_PLOT_PANEL* plotPanel = GetCurrentPlot();
|
||||
TRACE* trace = plotPanel ? plotPanel->GetTrace( name ) : nullptr;
|
||||
|
||||
if( version >= 4 && trace )
|
||||
{
|
||||
|
@ -1725,6 +1724,20 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath )
|
|||
format->Range = text.Right( text.Length() - 1 );
|
||||
};
|
||||
|
||||
auto addCursor =
|
||||
[]( int aCursorId, SIM_PLOT_PANEL* aPlotPanel, TRACE* aTrace, double x )
|
||||
{
|
||||
CURSOR* cursor = new CURSOR( aTrace, aPlotPanel );
|
||||
mpWindow* win = aPlotPanel->GetPlotWin();
|
||||
|
||||
cursor->SetName( aTrace->GetName() );
|
||||
cursor->SetPen( wxPen( aTrace->GetTraceColour() ) );
|
||||
cursor->SetCoordX( x );
|
||||
|
||||
aTrace->SetCursor( aCursorId, cursor );
|
||||
win->AddLayer( cursor );
|
||||
};
|
||||
|
||||
wxArrayString items = wxSplit( param, '|' );
|
||||
|
||||
for( const wxString& item : items )
|
||||
|
@ -1737,29 +1750,33 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath )
|
|||
}
|
||||
else if( item.StartsWith( wxS( "cursor1" ) ) )
|
||||
{
|
||||
wxArrayString parts = wxSplit( item, '.' );
|
||||
wxArrayString parts = wxSplit( item, ':' );
|
||||
double val;
|
||||
|
||||
if( parts.size() == 3 )
|
||||
{
|
||||
parts[0].AfterFirst( '=' ).ToDouble( &val );
|
||||
readFormat( &m_cursorFormats[0][0], parts[1] );
|
||||
readFormat( &m_cursorFormats[0][1], parts[2] );
|
||||
GetCurrentPlot()->EnableCursor( name, 1, true );
|
||||
addCursor( 1, plotPanel, trace, val );
|
||||
}
|
||||
}
|
||||
else if( item.StartsWith( wxS( "cursor2" ) ) )
|
||||
{
|
||||
wxArrayString parts = wxSplit( item, '.' );
|
||||
wxArrayString parts = wxSplit( item, ':' );
|
||||
double val;
|
||||
|
||||
if( parts.size() == 3 )
|
||||
{
|
||||
parts[0].AfterFirst( '=' ).ToDouble( &val );
|
||||
readFormat( &m_cursorFormats[1][0], parts[1] );
|
||||
readFormat( &m_cursorFormats[1][1], parts[2] );
|
||||
GetCurrentPlot()->EnableCursor( name, 2, true );
|
||||
addCursor( 2, plotPanel, trace, val );
|
||||
}
|
||||
}
|
||||
else if( item.StartsWith( wxS( "cursorD" ) ) )
|
||||
{
|
||||
wxArrayString parts = wxSplit( item, '.' );
|
||||
wxArrayString parts = wxSplit( item, ':' );
|
||||
|
||||
if( parts.size() == 3 )
|
||||
{
|
||||
|
@ -1768,6 +1785,8 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath )
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
plotPanel->UpdatePlotColors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1777,9 +1796,7 @@ bool SIM_PLOT_FRAME::LoadWorkbook( const wxString& aPath )
|
|||
rebuildSignalsList();
|
||||
rebuildSignalsGrid( m_filter->GetValue() );
|
||||
updateSignalsGrid();
|
||||
|
||||
wxCommandEvent dummy;
|
||||
onCursorUpdate( dummy );
|
||||
updateCursors();
|
||||
|
||||
file.Close();
|
||||
|
||||
|
@ -1866,18 +1883,20 @@ bool SIM_PLOT_FRAME::SaveWorkbook( const wxString& aPath )
|
|||
|
||||
wxString msg = COLOR4D( trace->GetTraceColour() ).ToCSSString();
|
||||
|
||||
if( trace->GetCursor( 1 ) )
|
||||
if( CURSOR* cursor = trace->GetCursor( 1 ) )
|
||||
{
|
||||
msg += wxString::Format( wxS( "|cursor1.%d%s.%d%s" ),
|
||||
msg += wxString::Format( wxS( "|cursor1=%E:%d%s:%d%s" ),
|
||||
cursor->GetCoords().x,
|
||||
m_cursorFormats[0][0].Precision,
|
||||
m_cursorFormats[0][0].Range,
|
||||
m_cursorFormats[0][1].Precision,
|
||||
m_cursorFormats[0][1].Range );
|
||||
}
|
||||
|
||||
if( trace->GetCursor( 2 ) )
|
||||
if( CURSOR* cursor = trace->GetCursor( 2 ) )
|
||||
{
|
||||
msg += wxString::Format( wxS( "|cursor2.%d%s.%d%s" ),
|
||||
msg += wxString::Format( wxS( "|cursor2=%E:%d%s:%d%s" ),
|
||||
cursor->GetCoords().x,
|
||||
m_cursorFormats[1][0].Precision,
|
||||
m_cursorFormats[1][0].Range,
|
||||
m_cursorFormats[1][1].Precision,
|
||||
|
@ -1886,7 +1905,7 @@ bool SIM_PLOT_FRAME::SaveWorkbook( const wxString& aPath )
|
|||
|
||||
if( trace->GetCursor( 1 ) || trace->GetCursor( 2 ) )
|
||||
{
|
||||
msg += wxString::Format( wxS( "|cursorD.%d%s.%d%s" ),
|
||||
msg += wxString::Format( wxS( "|cursorD:%d%s:%d%s" ),
|
||||
m_cursorFormats[2][0].Precision,
|
||||
m_cursorFormats[2][0].Range,
|
||||
m_cursorFormats[2][1].Precision,
|
||||
|
@ -1960,17 +1979,14 @@ void SIM_PLOT_FRAME::onPlotClosed( wxAuiNotebookEvent& event )
|
|||
{
|
||||
m_signals.clear();
|
||||
rebuildSignalsGrid( m_filter->GetValue() );
|
||||
|
||||
wxCommandEvent dummy;
|
||||
onCursorUpdate( dummy );
|
||||
updateCursors();
|
||||
}
|
||||
|
||||
|
||||
void SIM_PLOT_FRAME::onPlotChanged( wxAuiNotebookEvent& event )
|
||||
{
|
||||
rebuildSignalsGrid( m_filter->GetValue() );
|
||||
wxCommandEvent dummy;
|
||||
onCursorUpdate( dummy );
|
||||
updateCursors();
|
||||
}
|
||||
|
||||
|
||||
|
@ -2101,7 +2117,7 @@ void SIM_PLOT_FRAME::doCloseWindow()
|
|||
}
|
||||
|
||||
|
||||
void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
|
||||
void SIM_PLOT_FRAME::updateCursors()
|
||||
{
|
||||
m_cursorsGrid->ClearRows();
|
||||
|
||||
|
@ -2225,7 +2241,13 @@ void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event )
|
|||
valColName = cursor1Name;
|
||||
|
||||
m_cursorsGrid->SetColLabelValue( COL_CURSOR_Y, valColName );
|
||||
}
|
||||
|
||||
|
||||
void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& aEvent )
|
||||
{
|
||||
updateCursors();
|
||||
m_workbookModified = true;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -292,6 +292,11 @@ private:
|
|||
*/
|
||||
void updateSignalsGrid();
|
||||
|
||||
/**
|
||||
* Update the cursor values (in the grid) and graphics (in the plot window).
|
||||
*/
|
||||
void updateCursors();
|
||||
|
||||
/**
|
||||
* Update a measurement in the measurements grid.
|
||||
*/
|
||||
|
|
|
@ -754,6 +754,12 @@ void SIM_PLOT_PANEL::SetTraceData( TRACE* trace, unsigned int aPoints, const dou
|
|||
else
|
||||
trace->SetScale( m_axis_x, m_axis_y1 );
|
||||
|
||||
for( auto& [ cursorId, cursor ] : trace->GetCursors() )
|
||||
{
|
||||
if( cursor )
|
||||
cursor->SetCoordX( cursor->GetCoords().x );
|
||||
}
|
||||
|
||||
m_plotWin->UpdateAll();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue