Fixed autozooming with empty board/module.

This commit is contained in:
Maciej Suminski 2014-07-09 15:10:32 +02:00
parent 31e25ac4cf
commit 15f5c228cc
4 changed files with 42 additions and 34 deletions

View File

@ -696,24 +696,6 @@ void FOOTPRINT_EDIT_FRAME::updateTitle()
void FOOTPRINT_EDIT_FRAME::updateView() void FOOTPRINT_EDIT_FRAME::updateView()
{ {
static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->DisplayBoard( GetBoard() ); static_cast<PCB_DRAW_PANEL_GAL*>( GetGalCanvas() )->DisplayBoard( GetBoard() );
m_toolManager->RunAction( COMMON_ACTIONS::zoomFitScreen );
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->ResetTools( TOOL_BASE::MODEL_RELOAD ); m_toolManager->ResetTools( TOOL_BASE::MODEL_RELOAD );
} }

View File

@ -466,7 +466,7 @@ void FOOTPRINT_VIEWER_FRAME::ClickOnFootprintList( wxCommandEvent& event )
UpdateTitle(); UpdateTitle();
if( IsGalCanvasActive() ) if( IsGalCanvasActive() )
redrawGal(); updateView();
Zoom_Automatique( false ); Zoom_Automatique( false );
m_canvas->Refresh(); m_canvas->Refresh();
@ -851,7 +851,7 @@ void FOOTPRINT_VIEWER_FRAME::SelectAndViewFootprint( int aMode )
Update3D_Frame(); Update3D_Frame();
if( IsGalCanvasActive() ) 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 ); m_Pcb->ComputeBoundingBox( false );
EDA_RECT boardBbox = m_Pcb->GetBoundingBox(); 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 );
} }

View File

@ -172,7 +172,7 @@ private:
void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) {} void SaveCopyInUndoList( BOARD_ITEM*, UNDO_REDO_T, const wxPoint& ) {}
void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint &) {} void SaveCopyInUndoList( const PICKED_ITEMS_LIST&, UNDO_REDO_T, const wxPoint &) {}
void redrawGal(); void updateView();
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };

View File

@ -109,17 +109,29 @@ int PCBNEW_CONTROL::ZoomFitScreen( TOOL_EVENT& aEvent )
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView(); KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL(); KIGFX::GAL* gal = m_frame->GetGalCanvas()->GetGAL();
BOX2I boardBBox = getModel<BOARD>()->ViewBBox(); BOX2I boardBBox = getModel<BOARD>()->ViewBBox();
VECTOR2I screenSize = gal->GetScreenPixelSize();
double iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0; if( boardBBox.GetSize().x == 0 || boardBBox.GetSize().y == 0 )
double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.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 iuPerX = screenSize.x ? boardBBox.GetWidth() / screenSize.x : 1.0;
double zoomFactor = gal->GetWorldScale() / gal->GetZoomFactor(); double iuPerY = screenSize.y ? boardBBox.GetHeight() / screenSize.y : 1.0;
double zoom = 1.0 / ( zoomFactor * bestZoom );
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(); setTransitions();
return 0; return 0;