From 01cf6d76d8ffa382cc594ef2a9a39990b58cfc4d Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Wed, 30 Nov 2022 13:45:31 -0800 Subject: [PATCH] Remove newly dangling lines when dragging These lines are remnants from drag operations that should be cleaned after commiting the new line positions Fixes https://gitlab.com/kicad/code/kicad/issues/12870 --- eeschema/tools/sch_move_tool.cpp | 37 ++++++++++++++++++++++++++++++-- eeschema/tools/sch_move_tool.h | 3 +++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 8c39a02a0a..f3df498f69 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -904,9 +904,11 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) m_toolMgr->RunAction( EE_ACTIONS::trimOverlappingWires, true, &selectionCopy ); m_toolMgr->RunAction( EE_ACTIONS::addNeededJunctions, true, &selectionCopy ); - m_frame->RecalculateConnections( LOCAL_CLEANUP ); - m_frame->TestDanglingEnds(); + // This needs to run prior to `RecalculateConnections` because we need to identify + // the lines that are newly dangling + trimDanglingLines(); + m_frame->RecalculateConnections( LOCAL_CLEANUP ); m_frame->OnModify(); } @@ -923,6 +925,37 @@ int SCH_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) } +void SCH_MOVE_TOOL::trimDanglingLines() +{ + // Need a local cleanup first to ensure we remove unneeded junctions + m_frame->SchematicCleanUp( m_frame->GetScreen() ); + + std::set danglers; + + std::function changeHandler = + [&]( SCH_ITEM* aChangedItem ) -> void + { + m_toolMgr->GetView()->Update( aChangedItem, KIGFX::REPAINT ); + + // Delete newly dangling lines + if( aChangedItem->IsDangling() && aChangedItem->IsType( {SCH_LINE_T } ) ) + danglers.insert( aChangedItem ); + }; + + m_frame->GetScreen()->TestDanglingEnds( nullptr, &changeHandler ); + + for( SCH_ITEM* line : danglers ) + { + line->SetFlags( STRUCT_DELETED ); + saveCopyInUndoList( line, UNDO_REDO::DELETED, true ); + + updateItem( line, false ); + + m_frame->RemoveFromScreen( line, m_frame->GetScreen() ); + } +} + + void SCH_MOVE_TOOL::getConnectedItems( SCH_ITEM* aOriginalItem, const VECTOR2I& aPoint, EDA_ITEMS& aList ) { diff --git a/eeschema/tools/sch_move_tool.h b/eeschema/tools/sch_move_tool.h index 5f58e0ec4b..5b38d25e66 100644 --- a/eeschema/tools/sch_move_tool.h +++ b/eeschema/tools/sch_move_tool.h @@ -84,6 +84,9 @@ private: ///< Set up handlers for various events. void setTransitions() override; + ///< Cleanup dangling lines left after a drag + void trimDanglingLines(); + private: ///< Re-entrancy guard bool m_inMoveTool;