pcbnew: Remove snapping to hidden items

Items and layers that are hidden in the view should not be used as snap
points.  This happens in multiple locations:
1) Grid Helper for normal tools
2) TOOL_BASE::snapToItem for router

Resolves KiPro Issue #116

Fixes: lp:1833128
* https://bugs.launchpad.net/kicad/+bug/1833128
This commit is contained in:
Seth Hillbrand 2019-10-10 06:33:21 -07:00
parent 89e9857f3d
commit cecfeea947
5 changed files with 34 additions and 6 deletions

View File

@ -1069,6 +1069,23 @@ bool PNS_KICAD_IFACE::IsAnyLayerVisible( const LAYER_RANGE& aLayer )
} }
bool PNS_KICAD_IFACE::IsItemVisible( const PNS::ITEM* aItem )
{
if( !m_view )
return false;
auto item = aItem->Parent();
auto activeLayers = m_view->GetPainter()->GetSettings()->GetActiveLayers();
bool isHighContrast = m_view->GetPainter()->GetSettings()->GetHighContrast();
if( m_view->IsVisible( item ) && ( !isHighContrast || activeLayers.count( item->GetLayer() ) )
&& item->ViewGetLOD( item->GetLayer(), m_view ) < m_view->GetScale() )
return true;
return false;
}
void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld ) void PNS_KICAD_IFACE::SyncWorld( PNS::NODE *aWorld )
{ {
int worstPadClearance = 0; int worstPadClearance = 0;

View File

@ -53,6 +53,7 @@ public:
void SyncWorld( PNS::NODE* aWorld ) override; void SyncWorld( PNS::NODE* aWorld ) override;
void EraseView() override; void EraseView() override;
bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) override; bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) override;
bool IsItemVisible( const PNS::ITEM* aItem ) override;
void HideItem( PNS::ITEM* aItem ) override; void HideItem( PNS::ITEM* aItem ) override;
void DisplayItem( const PNS::ITEM* aItem, int aColor = 0, int aClearance = 0, bool aEdit = false ) override; void DisplayItem( const PNS::ITEM* aItem, int aColor = 0, int aClearance = 0, bool aEdit = false ) override;
void AddItem( PNS::ITEM* aItem ) override; void AddItem( PNS::ITEM* aItem ) override;

View File

@ -95,6 +95,7 @@ enum DRAG_MODE
virtual void AddItem( ITEM* aItem ) = 0; virtual void AddItem( ITEM* aItem ) = 0;
virtual void RemoveItem( ITEM* aItem ) = 0; virtual void RemoveItem( ITEM* aItem ) = 0;
virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) = 0; virtual bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) = 0;
virtual bool IsItemVisible( const PNS::ITEM* aItem ) = 0;
virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0; virtual void DisplayItem( const ITEM* aItem, int aColor = -1, int aClearance = -1, bool aEdit = false ) = 0;
virtual void HideItem( ITEM* aItem ) = 0; virtual void HideItem( ITEM* aItem ) = 0;
virtual void Commit() = 0; virtual void Commit() = 0;

View File

@ -382,7 +382,7 @@ const VECTOR2I TOOL_BASE::snapToItem( bool aEnabled, ITEM* aItem, VECTOR2I aP)
{ {
VECTOR2I anchor; VECTOR2I anchor;
if( !aItem || !aEnabled ) if( !aItem || !aEnabled || !m_iface->IsItemVisible( aItem ) )
{ {
return m_gridHelper->Align( aP ); return m_gridHelper->Align( aP );
} }

View File

@ -35,12 +35,12 @@ using namespace std::placeholders;
#include <class_module.h> #include <class_module.h>
#include <class_zone.h> #include <class_zone.h>
#include <gal/graphics_abstraction_layer.h>
#include <geometry/shape_line_chain.h>
#include <math/vector2d.h>
#include <painter.h> #include <painter.h>
#include <view/view.h> #include <view/view.h>
#include <view/view_controls.h> #include <view/view_controls.h>
#include <gal/graphics_abstraction_layer.h>
#include <geometry/shape_line_chain.h>
#include "grid_helper.h" #include "grid_helper.h"
@ -51,6 +51,7 @@ GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) :
m_enableSnap = true; m_enableSnap = true;
m_enableGrid = true; m_enableGrid = true;
m_snapSize = 100; m_snapSize = 100;
m_snapItem = nullptr;
KIGFX::VIEW* view = m_frame->GetCanvas()->GetView(); KIGFX::VIEW* view = m_frame->GetCanvas()->GetView();
m_viewAxis.SetSize( 20000 ); m_viewAxis.SetSize( 20000 );
@ -228,7 +229,8 @@ std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first ); BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
// The item must be visible and on an active layer // The item must be visible and on an active layer
if( view->IsVisible( item ) && ( !isHighContrast || activeLayers.count( it.second ) ) ) if( view->IsVisible( item ) && ( !isHighContrast || activeLayers.count( it.second ) )
&& item->ViewGetLOD( it.second, view ) < view->GetScale() )
items.insert ( item ); items.insert ( item );
} }
@ -310,6 +312,9 @@ BOARD_ITEM* GRID_HELPER::GetSnapped( void ) const
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom ) void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bool aFrom )
{ {
VECTOR2I origin; VECTOR2I origin;
auto view = m_frame->GetCanvas()->GetView();
auto activeLayers = view->GetPainter()->GetSettings()->GetActiveLayers();
bool isHighContrast = view->GetPainter()->GetSettings()->GetHighContrast();
switch( aItem->Type() ) switch( aItem->Type() )
{ {
@ -319,8 +324,12 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, bo
for( auto pad : mod->Pads() ) for( auto pad : mod->Pads() )
{ {
// Getting pads from the module requires re-checking that the pad is shown
if( ( aFrom || m_frame->Settings().m_MagneticPads == CAPTURE_ALWAYS ) if( ( aFrom || m_frame->Settings().m_MagneticPads == CAPTURE_ALWAYS )
&& pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) ) && pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) )
&& view->IsVisible( pad )
&& ( !isHighContrast || activeLayers.count( pad->GetLayer() ) )
&& pad->ViewGetLOD( pad->GetLayer(), view ) < view->GetScale() )
{ {
addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad ); addAnchor( pad->GetPosition(), CORNER | SNAPPABLE, pad );
break; break;