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

Fixes: lp:1116457
* https://bugs.launchpad.net/kicad/+bug/1116457
This commit is contained in:
Jon Evans 2019-05-25 10:43:55 -04:00
parent fb80ee5a0e
commit ede2575018
4 changed files with 25 additions and 3 deletions

View File

@ -232,12 +232,18 @@ int COMMON_TOOLS::ZoomFitScreen( const TOOL_EVENT& aEvent )
EDA_BASE_FRAME* frame = getEditFrame<EDA_BASE_FRAME>();
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();

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

@ -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

View File

@ -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();