From 094d2653131d6b8452c1ad7705d99b45a77192ca Mon Sep 17 00:00:00 2001 From: Seth Hillbrand <seth@kipro-pcb.com> Date: Thu, 8 Aug 2024 14:28:58 -0700 Subject: [PATCH] Re-enable grid snap line This was accidentally disabled by 4039b7da6b9095b14e50eed37d76d29cee5f4111 --- common/tool/grid_helper.cpp | 2 +- eeschema/tools/ee_grid_helper.cpp | 2 +- include/tool/grid_helper.h | 3 +-- pcbnew/tools/pcb_grid_helper.cpp | 4 ++-- pcbnew/tools/pcb_grid_helper.h | 11 ++++++++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/common/tool/grid_helper.cpp b/common/tool/grid_helper.cpp index 25ff0cf2c8..d94611d586 100644 --- a/common/tool/grid_helper.cpp +++ b/common/tool/grid_helper.cpp @@ -41,7 +41,7 @@ GRID_HELPER::GRID_HELPER( TOOL_MANAGER* aToolMgr ) : m_enableSnap = true; m_enableSnapLine = true; m_enableGrid = true; - m_snapItem = nullptr; + m_snapItem = std::nullopt; } diff --git a/eeschema/tools/ee_grid_helper.cpp b/eeschema/tools/ee_grid_helper.cpp index 16fea65888..f70f90b39f 100644 --- a/eeschema/tools/ee_grid_helper.cpp +++ b/eeschema/tools/ee_grid_helper.cpp @@ -236,7 +236,7 @@ VECTOR2I EE_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, GRID_HELPER_GR } else if( snapPoint ) { - m_snapItem = nearest; + m_snapItem = *nearest; m_viewSnapPoint.SetPosition( pt ); m_viewSnapLine.SetPosition( pt ); diff --git a/include/tool/grid_helper.h b/include/tool/grid_helper.h index a8af1a2a55..c4d38cdfbb 100644 --- a/include/tool/grid_helper.h +++ b/include/tool/grid_helper.h @@ -154,7 +154,6 @@ protected: void clearAnchors() { m_anchors.clear(); - m_snapItem = nullptr; } /** @@ -177,7 +176,7 @@ protected: bool m_enableSnap; // Allow snapping to other items on the layers bool m_enableGrid; // If true, allow snapping to grid bool m_enableSnapLine; // Allow drawing lines from snap points - ANCHOR* m_snapItem; // Pointer to the currently snapped item in m_anchors + std::optional<ANCHOR> m_snapItem; // Pointer to the currently snapped item in m_anchors // (NULL if not snapped) VECTOR2I m_skipPoint; // When drawing a line, we avoid snapping to the // source point diff --git a/pcbnew/tools/pcb_grid_helper.cpp b/pcbnew/tools/pcb_grid_helper.cpp index a3d47ba9c4..f8ef52eade 100644 --- a/pcbnew/tools/pcb_grid_helper.cpp +++ b/pcbnew/tools/pcb_grid_helper.cpp @@ -370,12 +370,12 @@ VECTOR2I PCB_GRID_HELPER::BestSnapAnchor( const VECTOR2I& aOrigin, const LSET& a else m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, true ); - m_snapItem = nearest; + m_snapItem = *nearest; return nearest->pos; } } - m_snapItem = nullptr; + m_snapItem = std::nullopt; m_toolMgr->GetView()->SetVisible( &m_viewSnapPoint, false ); m_toolMgr->GetView()->SetVisible( &m_viewSnapLine, false ); return nearestGrid; diff --git a/pcbnew/tools/pcb_grid_helper.h b/pcbnew/tools/pcb_grid_helper.h index 8f8dc83ae0..0061ce63b9 100644 --- a/pcbnew/tools/pcb_grid_helper.h +++ b/pcbnew/tools/pcb_grid_helper.h @@ -30,6 +30,7 @@ #include <pcb_item_containers.h> #include <tool/grid_helper.h> +#include <board.h> class LSET; class SHAPE_ARC; @@ -37,7 +38,7 @@ class TOOL_MANAGER; struct MAGNETIC_SETTINGS; struct PCB_SELECTION_FILTER_OPTIONS; -class PCB_GRID_HELPER : public GRID_HELPER +class PCB_GRID_HELPER : public GRID_HELPER, public BOARD_LISTENER { public: @@ -66,6 +67,14 @@ public: VECTOR2I AlignToNearestPad( const VECTOR2I& aMousePos, std::deque<PAD*>& aPads ); + virtual void OnBoardItemRemoved( BOARD& aBoard, BOARD_ITEM* aBoardItem ) override + { + if( m_snapItem->item == aBoardItem ) + { + m_snapItem = std::nullopt; + } + } + /** * Chooses the "best" snap anchor around the given point, optionally taking layers from * the reference item. The reference item will not be snapped to (it is being dragged or