From ede25750181a13de15c8e9606f397f9835ca30a4 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Sat, 25 May 2019 10:43:55 -0400 Subject: [PATCH] Exclude invisible items from view bounding box for zoom-to-fit Fixes: lp:1116457 * https://bugs.launchpad.net/kicad/+bug/1116457 --- common/tool/common_tools.cpp | 8 +++++++- gerbview/gerbview_draw_panel_gal.cpp | 2 +- pcbnew/class_board.cpp | 16 ++++++++++++++++ pcbnew/pcb_draw_panel_gal.cpp | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/common/tool/common_tools.cpp b/common/tool/common_tools.cpp index d550e7365b..8e6bfa8831 100644 --- a/common/tool/common_tools.cpp +++ b/common/tool/common_tools.cpp @@ -232,12 +232,18 @@ int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent ) EDA_BASE_FRAME* frame = getEditFrame(); BOX2I bBox = model->ViewBBox(); + 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(); diff --git a/gerbview/gerbview_draw_panel_gal.cpp b/gerbview/gerbview_draw_panel_gal.cpp index 31b0a16e4e..2483e49035 100644 --- a/gerbview/gerbview_draw_panel_gal.cpp +++ b/gerbview/gerbview_draw_panel_gal.cpp @@ -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(); diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 6cbb2e7a32..31588d847d 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1122,6 +1122,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() ) @@ -1129,6 +1130,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 @@ -1142,6 +1146,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 @@ -1153,6 +1160,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 @@ -1164,6 +1174,9 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const // Check segment zones for( TRACK* track = m_SegZoneDeprecated; track; track = track->Next() ) { + if( !( track->GetLayerSet() & visible ).any() ) + continue; + if( !hasItems ) area = track->GetBoundingBox(); else @@ -1175,6 +1188,9 @@ EDA_RECT BOARD::ComputeBoundingBox( bool aBoardEdgesOnly ) const // Check polygonal zones for( auto aZone : m_ZoneDescriptorList ) { + if( !( aZone->GetLayerSet() & visible ).any() ) + continue; + if( !hasItems ) area = aZone->GetBoundingBox(); else diff --git a/pcbnew/pcb_draw_panel_gal.cpp b/pcbnew/pcb_draw_panel_gal.cpp index 0ec293dfd9..c1e3369ef1 100644 --- a/pcbnew/pcb_draw_panel_gal.cpp +++ b/pcbnew/pcb_draw_panel_gal.cpp @@ -436,7 +436,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();