From cb01ac53fa89e62d5acf3177caecefa31aa5d324 Mon Sep 17 00:00:00 2001 From: Mike Williams Date: Sat, 8 Jul 2023 20:26:26 -0400 Subject: [PATCH] Schematic: allowing swapping sheet pins on same sheet Fixes: https://gitlab.com/kicad/code/kicad/-/issues/15122 --- eeschema/tools/sch_edit_tool.cpp | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/eeschema/tools/sch_edit_tool.cpp b/eeschema/tools/sch_edit_tool.cpp index 76b6dcc28a..b958543b26 100644 --- a/eeschema/tools/sch_edit_tool.cpp +++ b/eeschema/tools/sch_edit_tool.cpp @@ -1135,6 +1135,7 @@ const std::vector swappableItems = { SCH_TEXT_T, SCH_TEXTBOX_T, SCH_LABEL_T, + SCH_SHEET_PIN_T, SCH_GLOBAL_LABEL_T, SCH_HIER_LABEL_T, SCH_DIRECTIVE_LABEL_T, @@ -1152,6 +1153,26 @@ int SCH_EDIT_TOOL::Swap( const TOOL_EVENT& aEvent ) EE_SELECTION& selection = m_selectionTool->RequestSelection( swappableItems ); std::vector sorted = selection.GetItemsSortedBySelectionOrder(); + // Sheet pins are special, we need to make sure if we have any sheet pins, + // that we only have sheet pins, and that they have the same parent + if( selection.CountType( SCH_SHEET_PIN_T ) > 0 ) + { + if( !selection.OnlyContains( { SCH_SHEET_PIN_T } ) ) + return 0; + + SCH_SHEET_PIN* firstPin = static_cast( selection.Front() ); + SCH_SHEET* parent = firstPin->GetParent(); + + for( EDA_ITEM* item : selection ) + { + SCH_SHEET_PIN* pin = static_cast( item ); + + if( pin->GetParent() != parent ) + return 0; + } + } + + if( selection.Size() < 2 ) return 0; @@ -1173,6 +1194,18 @@ int SCH_EDIT_TOOL::Swap( const TOOL_EVENT& aEvent ) appendUndo = true; saveCopyInUndoList( b, UNDO_REDO::CHANGED, appendUndo ); + // Sheet pins need to have their sides swapped before we change their + // positions + if( a->Type() == SCH_SHEET_PIN_T ) + { + SCH_SHEET_PIN* aPin = static_cast( a ); + SCH_SHEET_PIN* bPin = static_cast( b ); + SHEET_SIDE aSide = aPin->GetSide(), bSide = bPin->GetSide(); + std::swap( aSide, bSide ); + aPin->SetSide( aSide ); + bPin->SetSide( bSide ); + } + a->SetPosition( aPos ); b->SetPosition( bPos );