From 1d378cfcd15f72df5392c036599f5eacaeb102aa Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 23 Jul 2014 12:06:24 +0200 Subject: [PATCH] View is automatically centered when a module editor or viewer are opened (GAL). --- common/gal/cairo/cairo_compositor.cpp | 4 ++-- pcbnew/moduleframe.cpp | 2 +- pcbnew/modview_frame.cpp | 22 ++++------------------ pcbnew/tools/pcbnew_control.cpp | 4 +++- 4 files changed, 10 insertions(+), 22 deletions(-) diff --git a/common/gal/cairo/cairo_compositor.cpp b/common/gal/cairo/cairo_compositor.cpp index 5afa67d55a..d94b19b3c0 100644 --- a/common/gal/cairo/cairo_compositor.cpp +++ b/common/gal/cairo/cairo_compositor.cpp @@ -55,8 +55,8 @@ void CAIRO_COMPOSITOR::Resize( unsigned int aWidth, unsigned int aHeight ) { clean(); - assert( m_width > 0 ); - assert( m_height > 0 ); + assert( aWidth > 0 ); + assert( aHeight > 0 ); m_width = aWidth; m_height = aHeight; diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index 58dc823b44..88212e408a 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -696,6 +696,6 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() void FOOTPRINT_EDIT_FRAME::updateView() { static_cast( GetGalCanvas() )->DisplayBoard( GetBoard() ); - m_toolManager->RunAction( COMMON_ACTIONS::zoomFitScreen ); m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); + m_toolManager->RunAction( COMMON_ACTIONS::zoomFitScreen, true ); } diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index d83e220234..29c194b75e 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -884,24 +884,10 @@ void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) void FOOTPRINT_VIEWER_FRAME::updateView() { - static_cast( GetGalCanvas() )->DisplayBoard( GetBoard() ); - - m_Pcb->ComputeBoundingBox( false ); - EDA_RECT boardBbox = m_Pcb->GetBoundingBox(); - BOX2D bbox; - - // Autozoom - if( boardBbox.GetSize().x > 0 && boardBbox.GetSize().y > 0 ) + if( IsGalCanvasActive() ) { - bbox.SetOrigin( VECTOR2D( boardBbox.GetOrigin() ) ); - bbox.SetSize( VECTOR2D( boardBbox.GetSize() ) ); + static_cast( GetGalCanvas() )->DisplayBoard( GetBoard() ); + m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); + m_toolManager->RunAction( COMMON_ACTIONS::zoomFitScreen, true ); } - else - { - // Default empty view - bbox.SetOrigin( VECTOR2D( -1000, -1000 ) ); - bbox.SetSize( VECTOR2D( 2000, 2000 ) ); - } - - GetGalCanvas()->GetView()->SetViewport( bbox ); } diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index a0573b3118..da1d028aca 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -109,7 +109,9 @@ int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent ) { KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); - BOX2I boardBBox = getModel()->ViewBBox(); + BOARD* board = getModel(); + board->ComputeBoundingBox(); + BOX2I boardBBox = board->ViewBBox(); if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 ) {