diff --git a/pcbnew/moduleframe.cpp b/pcbnew/moduleframe.cpp index a3af6dc5fe..bd5b92e70a 100644 --- a/pcbnew/moduleframe.cpp +++ b/pcbnew/moduleframe.cpp @@ -696,24 +696,6 @@ void FOOTPRINT_EDIT_FRAME::updateTitle() void FOOTPRINT_EDIT_FRAME::updateView() { static_cast( GetGalCanvas() )->DisplayBoard( GetBoard() ); - - m_Pcb->ComputeBoundingBox( false ); - EDA_RECT boardBbox = m_Pcb->GetBoundingBox(); - BOX2D bbox; - - if( boardBbox.GetSize().x > 0 && boardBbox.GetSize().y > 0 ) - { - bbox.SetOrigin( VECTOR2D( boardBbox.GetOrigin() ) ); - bbox.SetSize( VECTOR2D( boardBbox.GetSize() ) ); - } - else - { - // Default empty view - bbox.SetOrigin( VECTOR2D( -1000, -1000 ) ); - bbox.SetSize( VECTOR2D( 2000, 2000 ) ); - } - - GetGalCanvas()->GetView()->SetViewport( bbox ); - + m_toolManager->RunAction( COMMON_ACTIONS::zoomFitScreen ); m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD ); } diff --git a/pcbnew/modview_frame.cpp b/pcbnew/modview_frame.cpp index 75a20bcdee..3404a5b349 100644 --- a/pcbnew/modview_frame.cpp +++ b/pcbnew/modview_frame.cpp @@ -466,7 +466,7 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event ) UpdateTitle(); if( IsGalCanvasActive() ) - redrawGal(); + updateView(); Zoom_Automatique( false ); m_canvas->Refresh(); @@ -851,7 +851,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode ) Update3D_Frame(); if( IsGalCanvasActive() ) - redrawGal(); + updateView(); } @@ -880,12 +880,26 @@ void FOOTPRINT_VIEWER_FRAME::RedrawActiveWindow( wxDC* DC, bool EraseBg ) } -void FOOTPRINT_VIEWER_FRAME::redrawGal() +void FOOTPRINT_VIEWER_FRAME::updateView() { - static_cast( GetGalCanvas() )->DisplayBoard( m_Pcb ); + static_cast( GetGalCanvas() )->DisplayBoard( GetBoard() ); - // Autozoom m_Pcb->ComputeBoundingBox( false ); EDA_RECT boardBbox = m_Pcb->GetBoundingBox(); - GetGalCanvas()->GetView()->SetViewport( BOX2D( boardBbox.GetOrigin(), boardBbox.GetSize() ) ); + BOX2D bbox; + + // Autozoom + if( boardBbox.GetSize().x > 0 && boardBbox.GetSize().y > 0 ) + { + bbox.SetOrigin( VECTOR2D( boardBbox.GetOrigin() ) ); + bbox.SetSize( VECTOR2D( boardBbox.GetSize() ) ); + } + else + { + // Default empty view + bbox.SetOrigin( VECTOR2D( -1000, -1000 ) ); + bbox.SetSize( VECTOR2D( 2000, 2000 ) ); + } + + GetGalCanvas()->GetView()->SetViewport( bbox ); } diff --git a/pcbnew/modview_frame.h b/pcbnew/modview_frame.h index 4dd1210979..311f150ed8 100644 --- a/pcbnew/modview_frame.h +++ b/pcbnew/modview_frame.h @@ -172,7 +172,7 @@ private: void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) {} void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint &) {} - void redrawGal(); + void updateView(); DECLARE_EVENT_TABLE() }; diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 3eba7f495b..0a75ce975e 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -109,17 +109,29 @@ 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(); - VECTOR2I screenSize = gal->GetScreenPixelSize(); - double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; - double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0; + if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 ) + { + // Empty view + view->SetScale( 100000.0 ); + view->SetCenter( VECTOR2D( 0, 0 ) ); + } + else + { + // Autozoom to board + VECTOR2I screenSize = gal->GetScreenPixelSize(); - double bestZoom = std::max( iuPerX, iuPerY ); - double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); - double zoom = 1.0 / ( zoomFactor * bestZoom ); + double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; + double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0; + + double bestZoom = std::max( iuPerX, iuPerY ); + double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); + double zoom = 1.0 / ( zoomFactor * bestZoom ); + + view->SetScale( zoom ); + view->SetCenter( boardBBox.Centre() ); + } - view->SetScale( zoom ); - view->SetCenter( boardBBox.Centre() ); setTransitions(); return 0;