Commit 15f5c228 authored by Maciej Suminski's avatar Maciej Suminski

Fixed autozooming with empty board/module.

parent 31e25ac4
......@@ -696,24 +696,6 @@ void FOOTPRINT_EDIT_FRAME::updateTitle()
void FOOTPRINT_EDIT_FRAME::updateView()
{
static_cast<PCB_DRAW_PANEL_GAL*>( 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 );
}
......@@ -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<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->DisplayBoard( m_Pcb );
static_cast<PCB_DRAW_PANEL_GAL*>( 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 );
}
......@@ -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()
};
......
......@@ -109,6 +109,16 @@ int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent )
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL();
BOX2I boardBBox = getModel<BOARD>()->ViewBBox();
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 iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0;
......@@ -120,6 +130,8 @@ int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent )
view->SetScale( zoom );
view->SetCenter( boardBBox.Centre() );
}
setTransitions();
return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment