From 489db6adde39fc0b1b117585940dbb7e04cef0a8 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Fri, 18 Dec 2020 15:26:37 -0800 Subject: [PATCH] Handle case where multiple pins are moved When synchronized, if multiple pins are selected to be moved, we need to match each to a matching pin in the new unit Fixes https://gitlab.com/kicad/code/kicad/issues/2589 --- eeschema/tools/symbol_editor_move_tool.cpp | 46 ++++++++++++++-------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/eeschema/tools/symbol_editor_move_tool.cpp b/eeschema/tools/symbol_editor_move_tool.cpp index 63a7a7c705..57bbfdc40c 100644 --- a/eeschema/tools/symbol_editor_move_tool.cpp +++ b/eeschema/tools/symbol_editor_move_tool.cpp @@ -111,35 +111,47 @@ int SYMBOL_EDITOR_MOVE_TOOL::Main( const TOOL_EVENT& aEvent ) { if( !m_moveInProgress ) // Prepare to start moving/dragging { - LIB_ITEM* lib_item = (LIB_ITEM*) selection.Front(); + LIB_ITEM* lib_item = static_cast( selection.Front() ); // Pick up any synchronized pins // // Careful when pasting. The pasted pin will be at the same location as it // was copied from, leading us to believe it's a synchronized pin. It's not. - if( selection.GetSize() == 1 && lib_item->Type() == LIB_PIN_T - && m_frame->SynchronizePins() + if( m_frame->SynchronizePins() && ( lib_item->GetEditFlags() & IS_PASTED ) == 0 ) { - LIB_PIN* cur_pin = (LIB_PIN*) lib_item; - LIB_PART* part = m_frame->GetCurPart(); - std::vector got_unit( part->GetUnitCount() ); + std::set sync_pins; - got_unit[cur_pin->GetUnit()] = true; - - for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) ) + for( EDA_ITEM* sel_item : selection ) { - if( !got_unit[pin->GetUnit()] - && pin->GetPosition() == cur_pin->GetPosition() - && pin->GetOrientation() == cur_pin->GetOrientation() - && pin->GetConvert() == cur_pin->GetConvert() - && pin->GetType() == cur_pin->GetType() - && pin->GetName() == cur_pin->GetName() ) + lib_item = static_cast( sel_item ); + + if( lib_item->Type() == LIB_PIN_T ) { - m_selectionTool->AddItemToSel( pin, true /*quiet mode*/ ); - got_unit[pin->GetUnit()] = true; + LIB_PIN* cur_pin = static_cast( lib_item ); + LIB_PART* part = m_frame->GetCurPart(); + std::vector got_unit( part->GetUnitCount() ); + + got_unit[cur_pin->GetUnit()] = true; + + for( LIB_PIN* pin = part->GetNextPin(); pin; pin = part->GetNextPin( pin ) ) + { + if( !got_unit[pin->GetUnit()] + && pin->GetPosition() == cur_pin->GetPosition() + && pin->GetOrientation() == cur_pin->GetOrientation() + && pin->GetConvert() == cur_pin->GetConvert() + && pin->GetType() == cur_pin->GetType() + && pin->GetName() == cur_pin->GetName() ) + { + if( sync_pins.insert( pin ).second ) + got_unit[pin->GetUnit()] = true; + } + } } } + + for( LIB_PIN* pin : sync_pins ) + m_selectionTool->AddItemToSel( pin, true /*quiet mode*/ ); } // Apply any initial offset in case we're coming from a previous command.