From fcd3bbecdfde7bbc97006a9f53d953f6a96ed946 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 18 Sep 2013 17:36:54 +0200 Subject: [PATCH] Added limits for VIEW scale values & panning area. --- common/view/view.cpp | 24 +++++++++++++++++++++++- include/view/view.h | 29 +++++++++++++++++++++++++++++ pcbnew/basepcbframe.cpp | 1 + 3 files changed, 53 insertions(+), 1 deletion(-) diff --git a/common/view/view.cpp b/common/view/view.cpp index 529b966d49..5d529f4559 100644 --- a/common/view/view.cpp +++ b/common/view/view.cpp @@ -45,8 +45,11 @@ VIEW::VIEW( bool aIsDynamic ) : m_scale( 1.0 ), m_painter( NULL ), m_gal( NULL ), - m_dynamic( aIsDynamic ) + m_dynamic( aIsDynamic ), + m_scaleLimits( 15000.0, 1.0 ) { + m_panBoundary.SetMaximum(); + // Redraw everything at the beginning for( int i = 0; i < TARGETS_NUMBER; ++i ) MarkTargetDirty( i ); @@ -290,6 +293,11 @@ void VIEW::SetScale( double aScale ) void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor ) { + if( aScale > m_scaleLimits.x ) + aScale = m_scaleLimits.x; + else if( aScale < m_scaleLimits.y ) + aScale = m_scaleLimits.y; + VECTOR2D a = ToScreen( aAnchor ); m_gal->SetZoomFactor( aScale ); @@ -308,6 +316,20 @@ void VIEW::SetScale( double aScale, const VECTOR2D& aAnchor ) void VIEW::SetCenter( const VECTOR2D& aCenter ) { m_center = aCenter; + + if( !m_panBoundary.Contains( aCenter ) ) + { + if( aCenter.x < m_panBoundary.GetLeft() ) + m_center.x = m_panBoundary.GetLeft(); + else if( aCenter.x > m_panBoundary.GetRight() ) + m_center.x = m_panBoundary.GetRight(); + + if( aCenter.y < m_panBoundary.GetTop() ) + m_center.y = m_panBoundary.GetTop(); + else if( aCenter.y > m_panBoundary.GetBottom() ) + m_center.y = m_panBoundary.GetBottom(); + } + m_gal->SetLookAtPoint( m_center ); m_gal->ComputeWorldScreenMatrix(); diff --git a/include/view/view.h b/include/view/view.h index 714283ef44..dc6a27691a 100644 --- a/include/view/view.h +++ b/include/view/view.h @@ -455,6 +455,29 @@ public: m_dirtyTargets[i] = true; } + /** + * Function SetPanBoundary() + * Sets limits for panning area. + * @param aBoundary is the box that limits panning area. + */ + void SetPanBoundary( const BOX2I& aBoundary ) + { + m_panBoundary = aBoundary; + } + + /** + * Function SetScaleLimits() + * Sets minimum and maximum values for scale. + * @param aMaximum is the maximum value for scale.. + * @param aMinimum is the minimum value for scale. + */ + void SetScaleLimits( double aMaximum, double aMinimum ) + { + wxASSERT_MSG( aMaximum > aMinimum, wxT( "I guess you passed parameters in wrong order" ) ); + + m_scaleLimits = VECTOR2D( aMaximum, aMinimum ); + } + static const int VIEW_MAX_LAYERS = 128; ///* maximum number of layers that may be shown private: @@ -588,6 +611,12 @@ private: /// Rendering order modifier for layers that are marked as top layers static const int TOP_LAYER_MODIFIER = -VIEW_MAX_LAYERS; + + /// Panning boundaries + BOX2I m_panBoundary; + + /// Zoom limits + VECTOR2D m_scaleLimits; }; } // namespace KiGfx diff --git a/pcbnew/basepcbframe.cpp b/pcbnew/basepcbframe.cpp index bd23efa35c..a6c0ec42ec 100644 --- a/pcbnew/basepcbframe.cpp +++ b/pcbnew/basepcbframe.cpp @@ -217,6 +217,7 @@ void PCB_BASE_FRAME::ViewReloadBoard( const BOARD* aBoard ) const view->Add( worksheet ); + view->SetPanBoundary( worksheet->ViewBBox() ); view->RecacheAllItems( true ); if( m_galCanvasActive )