Exclude invisible items from view bounding box for zoom-to-fit

Fixes: lp:1116457
* https://bugs.launchpad.net/kicad/+bug/1116457

(cherry picked from commit ede2575018)
This commit is contained in:
Jon Evans 2019-05-25 10:43:55 -04:00
parent b5c80fe689
commit 549b76739e
4 changed files with 22 additions and 3 deletions

View File

@ -222,12 +222,18 @@ int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent )
EDA_DRAW_FRAME* frame = getEditFrame<EDA_DRAW_FRAME>();
BOX2I bBox = frame->GetDocumentExtents();
BOX2I defaultBox = galCanvas->GetDefaultViewBBox();
VECTOR2D scrollbarSize = VECTOR2D( galCanvas->GetSize() - galCanvas->GetClientSize() );
VECTOR2D screenSize = view->ToWorld( galCanvas->GetClientSize(), false );
if( bBox.GetWidth() == 0 || bBox.GetHeight() == 0 )
{
bBox = galCanvas->GetDefaultViewBBox();
bBox = defaultBox;
}
else if( defaultBox.GetWidth() > 0 && defaultBox.GetHeight() > 0 )
{
// Ensure worksheet is included in bounding box
bBox.Merge( defaultBox );
}
VECTOR2D vsize = bBox.GetSize();

View File

@ -211,7 +211,7 @@ void GERBVIEW_DRAW_PANEL_GAL::SetTopLayer( int aLayer )
BOX2I GERBVIEW_DRAW_PANEL_GAL::GetDefaultViewBBox() const
{
if( m_worksheet )
if( m_worksheet && m_view->IsLayerVisible( LAYER_WORKSHEET ) )
return m_worksheet->ViewBBox();
return BOX2I();

View File

@ -1104,6 +1104,7 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
{
bool hasItems = false;
EDA_RECT area;
LSET visible = GetVisibleLayers();
// Check segments, dimensions, texts, and fiducials
for( BOARD_ITEM* item = m_Drawings; item; item = item->Next() )
@ -1111,6 +1112,9 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
if( aBoardEdgesOnly && (item->Type() != PCB_LINE_T || item->GetLayer() != Edge_Cuts ) )
continue;
if( !( item->GetLayerSet() & visible ).any() )
continue;
if( !hasItems )
area = item->GetBoundingBox();
else
@ -1124,6 +1128,9 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
// Check modules
for( MODULE* module = m_Modules; module; module = module->Next() )
{
if( !( module->GetLayerSet() & visible ).any() )
continue;
if( !hasItems )
area = module->GetBoundingBox();
else
@ -1135,6 +1142,9 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
// Check tracks
for( TRACK* track = m_Track; track; track = track->Next() )
{
if( !( track->GetLayerSet() & visible ).any() )
continue;
if( !hasItems )
area = track->GetBoundingBox();
else
@ -1146,6 +1156,9 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const
// Check zones
for( auto aZone : m_ZoneDescriptorList )
{
if( !( aZone->GetLayerSet() & visible ).any() )
continue;
if( !hasItems )
area = aZone->GetBoundingBox();
else

View File

@ -432,7 +432,7 @@ void PCB_DRAW_PANEL_GAL::RedrawRatsnest()
BOX2I PCB_DRAW_PANEL_GAL::GetDefaultViewBBox() const
{
if( m_worksheet )
if( m_worksheet && m_view->IsLayerVisible( LAYER_WORKSHEET ) )
return m_worksheet->ViewBBox();
return BOX2I();