From b25781814df142dd42f8e805e4202c8ead4d95f9 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 11 Aug 2016 14:41:55 +0200 Subject: [PATCH] Fixed cursors --- common/widgets/mathplot.cpp | 25 +++++++++++++++++++++++++ eeschema/sim/sim_plot_frame.cpp | 4 ++-- eeschema/sim/sim_plot_panel.cpp | 31 +++++++++++++++++++++++++------ eeschema/sim/sim_plot_panel.h | 20 +++----------------- include/widgets/mathplot.h | 8 ++++++-- 5 files changed, 61 insertions(+), 27 deletions(-) diff --git a/common/widgets/mathplot.cpp b/common/widgets/mathplot.cpp index e9ec1c0f4a..3ff858e92b 100644 --- a/common/widgets/mathplot.cpp +++ b/common/widgets/mathplot.cpp @@ -3604,3 +3604,28 @@ void mpFXY::SetScale ( mpScaleBase *scaleX, mpScaleBase *scaleY ) m_scaleY->ExtendDataRange(GetMinY(), GetMaxY()); } } + + +double mpFXY::s2x(double plotCoordX) const +{ + return m_scaleX->TransformFromPlot( plotCoordX ); +} + + +double mpFXY::s2y(double plotCoordY) const +{ + return m_scaleY->TransformFromPlot( plotCoordY ); +} + + +double mpFXY::x2s(double x) const +{ + return m_scaleX->TransformToPlot( x ); +} + + +double mpFXY::y2s(double y) const +{ + return m_scaleY->TransformToPlot( y ); +} + diff --git a/eeschema/sim/sim_plot_frame.cpp b/eeschema/sim/sim_plot_frame.cpp index 1c7c24d4ce..dcbd344343 100644 --- a/eeschema/sim/sim_plot_frame.cpp +++ b/eeschema/sim/sim_plot_frame.cpp @@ -678,8 +678,8 @@ void SIM_PLOT_FRAME::onCursorUpdate( wxCommandEvent& event ) { const wxRealPoint coords = cursor->GetCoords(); long idx = m_cursors->InsertItem( SIGNAL_COL, trace.first ); - m_cursors->SetItem( idx, X_COL, wxString::Format( "%f", coords.x ) ); - m_cursors->SetItem( idx, Y_COL, wxString::Format( "%f", coords.y ) ); + m_cursors->SetItem( idx, X_COL, SPICE_VALUE( coords.x ).ToSpiceString() ); + m_cursors->SetItem( idx, Y_COL, SPICE_VALUE( coords.y ).ToSpiceString() ); } } } diff --git a/eeschema/sim/sim_plot_panel.cpp b/eeschema/sim/sim_plot_panel.cpp index 04999fd291..5d5227db19 100644 --- a/eeschema/sim/sim_plot_panel.cpp +++ b/eeschema/sim/sim_plot_panel.cpp @@ -196,7 +196,6 @@ public: return formatSI ( m_labeledTicks[n], wxT("A"), 3, AbsVisibleMaxValue() ); } }; - void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow ) { if( !m_window ) @@ -213,7 +212,7 @@ void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow ) if( m_updateRequired ) { - m_coords.x = aWindow.p2x( m_dim.x ); + m_coords.x = m_trace->s2x( aWindow.p2x( m_dim.x ) ); // Find the closest point coordinates auto maxXIt = std::upper_bound( dataX.begin(), dataX.end(), m_coords.x ); @@ -239,6 +238,7 @@ void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow ) const double leftY = dataY[minIdx]; const double rightY = dataY[maxIdx]; + // Linear interpolation m_coords.y = leftY + ( rightY - leftY ) / ( rightX - leftX ) * ( m_coords.x - leftX ); m_updateRequired = false; @@ -254,15 +254,34 @@ void CURSOR::Plot( wxDC& aDC, mpWindow& aWindow ) const int horLen = aWindow.GetScrX(); const int verLen = aWindow.GetScrY(); - const wxPoint cursorPos( aWindow.x2p( m_coords.x ), aWindow.y2p( m_coords.y ) ); - - aDC.SetPen( wxPen( *wxBLACK, 1, m_continuous ? wxSOLID : wxLONG_DASH ) ); - + const wxPoint cursorPos( aWindow.x2p( m_trace->x2s( m_coords.x ) ), + aWindow.y2p( m_trace->y2s( m_coords.y ) ) ); + aDC.SetPen( wxPen( *wxWHITE, 1, m_continuous ? wxSOLID : wxLONG_DASH ) ); aDC.DrawLine( -horLen, cursorPos.y, horLen, cursorPos.y ); aDC.DrawLine( cursorPos.x, -verLen, cursorPos.x, verLen ); } +bool CURSOR::Inside( wxPoint& aPoint ) +{ + if( !m_window ) + return false; + + return ( std::abs( aPoint.x - m_window->x2p( m_trace->x2s( m_coords.x ) ) ) <= DRAG_MARGIN ) + && ( std::abs( aPoint.y - m_window->y2p( m_trace->y2s( m_coords.y ) ) ) <= DRAG_MARGIN ); +} + + +void CURSOR::UpdateReference() +{ + if( !m_window ) + return; + + m_reference.x = m_window->x2p( m_trace->x2s( m_coords.x ) ); + m_reference.y = m_window->y2p( m_trace->y2s( m_coords.y ) ); +} + + SIM_PLOT_PANEL::SIM_PLOT_PANEL( SIM_TYPE aType, wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style, const wxString& name ) : mpWindow( parent, id, pos, size, style ), m_colorIdx( 0 ), diff --git a/eeschema/sim/sim_plot_panel.h b/eeschema/sim/sim_plot_panel.h index e07aa15286..371fe9ae82 100644 --- a/eeschema/sim/sim_plot_panel.h +++ b/eeschema/sim/sim_plot_panel.h @@ -37,7 +37,7 @@ class CURSOR : public mpInfoLayer public: CURSOR( const TRACE* aTrace ) : mpInfoLayer( wxRect( 0, 0, DRAG_MARGIN, DRAG_MARGIN ), wxTRANSPARENT_BRUSH ), - m_trace( aTrace ), m_updateRequired( false ), m_coords( 0.0, 0.0 ), m_window( nullptr ) + m_trace( aTrace ), m_updateRequired( true ), m_coords( 0.0, 0.0 ), m_window( nullptr ) { } @@ -48,14 +48,7 @@ public: m_updateRequired = true; } - bool Inside( wxPoint& aPoint ) - { - if( !m_window ) - return false; - - return ( std::abs( aPoint.x - m_window->x2p( m_coords.x ) ) <= DRAG_MARGIN ) - && ( std::abs( aPoint.y - m_window->y2p( m_coords.y ) ) <= DRAG_MARGIN ); - } + bool Inside( wxPoint& aPoint ) override; void Move( wxPoint aDelta ) override { @@ -63,14 +56,7 @@ public: mpInfoLayer::Move( aDelta ); } - void UpdateReference() - { - if( !m_window ) - return; - - m_reference.x = m_window->x2p( m_coords.x ); - m_reference.y = m_window->y2p( m_coords.y ); - } + void UpdateReference(); const wxRealPoint& GetCoords() const { diff --git a/include/widgets/mathplot.h b/include/widgets/mathplot.h index c19fb485ba..ae085834f4 100644 --- a/include/widgets/mathplot.h +++ b/include/widgets/mathplot.h @@ -583,7 +583,6 @@ class WXDLLIMPEXP_MATHPLOT mpFY : public mpLayer Optionally implement a constructor and pass a name (label) and a label alignment to the constructor mpFXY::mpFXY. If the layer name is empty, no label will be plotted. */ -class mpScaleBase; class WXDLLIMPEXP_MATHPLOT mpFXY : public mpLayer { @@ -611,8 +610,13 @@ class WXDLLIMPEXP_MATHPLOT mpFXY : public mpLayer */ virtual void Plot(wxDC & dc, mpWindow & w); - virtual void SetScale ( mpScaleBase *scaleX, mpScaleBase *scaleY ); + virtual void SetScale(mpScaleBase *scaleX, mpScaleBase *scaleY); + double s2x(double plotCoordX) const; + double s2y(double plotCoordY) const; + + double x2s(double x) const; + double y2s(double y) const; protected: int m_flags; //!< Holds label alignment