From 0ff6cb49d634e517517d15c9613803516103cac8 Mon Sep 17 00:00:00 2001 From: Alex Date: Fri, 27 Jan 2023 11:06:33 +0300 Subject: [PATCH] router: When dragging tracks, don't snap to parts of the original line. Fixes https://gitlab.com/kicad/code/kicad/issues/10113 --- pcbnew/router/pns_component_dragger.h | 5 +++++ pcbnew/router/pns_drag_algo.h | 5 ++++- pcbnew/router/pns_dragger.cpp | 10 ++++++++-- pcbnew/router/pns_dragger.h | 14 +++++++++++++- pcbnew/router/pns_router.cpp | 2 +- pcbnew/router/pns_tool_base.cpp | 19 ++++++++++++------- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/pcbnew/router/pns_component_dragger.h b/pcbnew/router/pns_component_dragger.h index 08e63bc29b..938aa89832 100644 --- a/pcbnew/router/pns_component_dragger.h +++ b/pcbnew/router/pns_component_dragger.h @@ -104,6 +104,11 @@ public: */ const ITEM_SET Traces() override; + virtual PNS::DRAG_MODE Mode() const override + { + return PNS::DM_COMPONENT; + } + private: struct DRAGGED_CONNECTION { diff --git a/pcbnew/router/pns_drag_algo.h b/pcbnew/router/pns_drag_algo.h index 199daf601c..5c7226244f 100644 --- a/pcbnew/router/pns_drag_algo.h +++ b/pcbnew/router/pns_drag_algo.h @@ -25,6 +25,7 @@ #include #include +#include "pns_router.h" #include "pns_algo_base.h" #include "pns_itemset.h" #include "pns_layerset.h" @@ -115,7 +116,9 @@ public: */ virtual const ITEM_SET Traces() = 0; - virtual void SetMode( int aDragMode ) {}; + virtual void SetMode( PNS::DRAG_MODE aDragMode ){}; + + virtual PNS::DRAG_MODE Mode() const = 0; protected: NODE* m_world; diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 97eb3577ea..0c3500f960 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -258,9 +258,15 @@ bool DRAGGER::Start( const VECTOR2I& aP, ITEM_SET& aPrimitives ) } -void DRAGGER::SetMode( int aMode ) +void DRAGGER::SetMode( PNS::DRAG_MODE aMode ) { - m_mode = aMode; + m_mode = static_cast( aMode ); +} + + +PNS::DRAG_MODE DRAGGER::Mode() const +{ + return static_cast( m_mode ); } diff --git a/pcbnew/router/pns_dragger.h b/pcbnew/router/pns_dragger.h index 2144dff9a1..3fcb515b6d 100644 --- a/pcbnew/router/pns_dragger.h +++ b/pcbnew/router/pns_dragger.h @@ -100,6 +100,16 @@ public: return m_draggedLine.Layer(); } + const LINE& GetOriginalLine() +{ + return m_draggedLine; + } + + const LINE& GetLastDragSolution() + { + return m_lastDragSolution; + } + /** * Function Traces() * @@ -107,7 +117,9 @@ public: */ const ITEM_SET Traces() override; - void SetMode( int aDragMode ) override; + void SetMode( PNS::DRAG_MODE aDragMode ) override; + + PNS::DRAG_MODE DRAGGER::Mode() const override; private: const ITEM_SET findViaFanoutByHandle ( NODE *aNode, const VIA_HANDLE& handle ); diff --git a/pcbnew/router/pns_router.cpp b/pcbnew/router/pns_router.cpp index bf62227e1b..d2023da43c 100644 --- a/pcbnew/router/pns_router.cpp +++ b/pcbnew/router/pns_router.cpp @@ -185,7 +185,7 @@ bool ROUTER::StartDragging( const VECTOR2I& aP, ITEM_SET aStartItems, int aDragM m_state = DRAG_SEGMENT; } - m_dragger->SetMode( aDragMode ); + m_dragger->SetMode( static_cast( aDragMode ) ); m_dragger->SetWorld( m_world.get() ); m_dragger->SetLogger( m_logger ); m_dragger->SetDebugDecorator( m_iface->GetDebugDecorator() ); diff --git a/pcbnew/router/pns_tool_base.cpp b/pcbnew/router/pns_tool_base.cpp index bdf0c79583..2884cf7505 100644 --- a/pcbnew/router/pns_tool_base.cpp +++ b/pcbnew/router/pns_tool_base.cpp @@ -33,6 +33,7 @@ using namespace std::placeholders; #include "pns_tool_base.h" #include "pns_arc.h" #include "pns_solid.h" +#include "pns_dragger.h" using namespace KIGFX; @@ -264,14 +265,18 @@ bool TOOL_BASE::checkSnap( ITEM *aItem ) // Sync PNS engine settings with the general PCB editor options. auto& pnss = m_router->Settings(); - // If we're dragging a track segment, don't try to snap to items on the same copper layer with same nets. This is not a perfect heuristic, but seems to work reasonably well :-) - // This way we avoid 'flickery' behaviour for short segments when the snap algo is trying to - // snap to the corners of the segments next to the one being dragged. + // If we're dragging a track segment, don't try to snap to items that are part of the original line. if( m_startItem && aItem && m_router->GetState() == ROUTER::DRAG_SEGMENT - && aItem->Layer() == m_startItem->Layer() && aItem->OfKind( ITEM::SEGMENT_T ) - && m_startItem->OfKind( ITEM::SEGMENT_T ) - && aItem->Net() == m_startItem->Net() ) - return false; + && m_router->GetDragger() ) + { + DRAGGER* dragger = dynamic_cast( m_router->GetDragger() ); + LINKED_ITEM* liItem = dynamic_cast( aItem ); + + if( dragger && liItem && dragger->GetOriginalLine().ContainsLink( liItem ) ) + { + return false; + } + } pnss.SetSnapToPads( frame()->GetMagneticItemsSettings()->pads == MAGNETIC_OPTIONS::CAPTURE_CURSOR_IN_TRACK_TOOL ||