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
(cherry picked from commit cecfeea947
)
This commit is contained in:
parent
7856061cf0
commit
0d64b38dbc
|
@ -1006,6 +1006,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 )
|
||||
{
|
||||
int worstPadClearance = 0;
|
||||
|
|
|
@ -53,6 +53,7 @@ public:
|
|||
void SyncWorld( PNS::NODE* aWorld ) override;
|
||||
void EraseView() override;
|
||||
bool IsAnyLayerVisible( const LAYER_RANGE& aLayer ) override;
|
||||
bool IsItemVisible( const 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 AddItem( PNS::ITEM* aItem ) override;
|
||||
|
|
|
@ -95,6 +95,7 @@ enum DRAG_MODE
|
|||
virtual void AddItem( ITEM* aItem ) = 0;
|
||||
virtual void RemoveItem( ITEM* aItem ) = 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 HideItem( ITEM* aItem ) = 0;
|
||||
virtual void Commit() = 0;
|
||||
|
|
|
@ -389,7 +389,7 @@ const VECTOR2I TOOL_BASE::snapToItem( bool aEnabled, ITEM* aItem, VECTOR2I aP)
|
|||
{
|
||||
VECTOR2I anchor;
|
||||
|
||||
if( !aItem || !aEnabled )
|
||||
if( !aItem || !aEnabled || !m_iface->IsItemVisible( aItem ) )
|
||||
{
|
||||
return m_gridHelper->Align( aP );
|
||||
}
|
||||
|
|
|
@ -35,12 +35,12 @@ using namespace std::placeholders;
|
|||
#include <class_module.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 <view/view.h>
|
||||
#include <view/view_controls.h>
|
||||
#include <gal/graphics_abstraction_layer.h>
|
||||
|
||||
#include <geometry/shape_line_chain.h>
|
||||
|
||||
#include "grid_helper.h"
|
||||
|
||||
|
@ -52,6 +52,8 @@ GRID_HELPER::GRID_HELPER( PCB_BASE_FRAME* aFrame ) :
|
|||
m_enableSnap = true;
|
||||
m_enableGrid = true;
|
||||
m_snapSize = 100;
|
||||
m_snapItem = nullptr;
|
||||
|
||||
KIGFX::VIEW* view = m_frame->GetGalCanvas()->GetView();
|
||||
|
||||
m_viewAxis.SetSize( 20000 );
|
||||
|
@ -243,8 +245,8 @@ std::set<BOARD_ITEM*> GRID_HELPER::queryVisible( const BOX2I& aArea,
|
|||
BOARD_ITEM* item = static_cast<BOARD_ITEM*>( it.first );
|
||||
|
||||
// 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 );
|
||||
}
|
||||
|
||||
|
@ -328,6 +330,9 @@ BOARD_ITEM* GRID_HELPER::GetSnapped( void ) const
|
|||
void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, const bool aFrom )
|
||||
{
|
||||
VECTOR2I origin;
|
||||
auto view = m_frame->GetGalCanvas()->GetView();
|
||||
auto activeLayers = view->GetPainter()->GetSettings()->GetActiveLayers();
|
||||
bool isHighContrast = view->GetPainter()->GetSettings()->GetHighContrast();
|
||||
|
||||
switch( aItem->Type() )
|
||||
{
|
||||
|
@ -337,8 +342,12 @@ void GRID_HELPER::computeAnchors( BOARD_ITEM* aItem, const VECTOR2I& aRefPos, co
|
|||
|
||||
for( auto pad : mod->Pads() )
|
||||
{
|
||||
if( ( aFrom || m_frame->Settings().m_magneticPads == CAPTURE_ALWAYS ) &&
|
||||
pad->GetBoundingBox().Contains( wxPoint( aRefPos.x, aRefPos.y ) ) )
|
||||
// Getting pads from the module requires re-checking that the pad is shown
|
||||
if( ( aFrom || m_frame->Settings().m_magneticPads == CAPTURE_ALWAYS )
|
||||
&& 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 );
|
||||
break;
|
||||
|
|
Loading…
Reference in New Issue