Fixed autozooming with empty board/module.
This commit is contained in:
parent
31e25ac4cf
commit
15f5c228cc
|
@ -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,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<BOARD>()->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;
|
||||
|
|
Loading…
Reference in New Issue