From f12c3bb6ffc246f163a84c2a8b0dde143fa1f731 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Mon, 28 Aug 2023 16:34:48 +0100 Subject: [PATCH] Align sheetpins to grid even when parent sheet is already on grid. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15050 --- eeschema/tools/sch_move_tool.cpp | 63 ++++++++++++++++---------------- 1 file changed, 32 insertions(+), 31 deletions(-) diff --git a/eeschema/tools/sch_move_tool.cpp b/eeschema/tools/sch_move_tool.cpp index 17e7bdc9c7..98ecb3505a 100644 --- a/eeschema/tools/sch_move_tool.cpp +++ b/eeschema/tools/sch_move_tool.cpp @@ -1619,68 +1619,69 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent ) getConnectedDragItems( &commit, line, pts[ii], drag_items ); std::set unique_items( drag_items.begin(), drag_items.end() ); - VECTOR2I gridpt = grid.AlignGrid( pts[ii], selectionGrid ) - pts[ii]; + VECTOR2I delta = grid.AlignGrid( pts[ii], selectionGrid ) - pts[ii]; - if( gridpt != VECTOR2I( 0, 0 ) ) + if( delta != VECTOR2I( 0, 0 ) ) { for( EDA_ITEM* dragItem : unique_items ) { if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() ) continue; - doMoveItem( dragItem, gridpt ); + doMoveItem( dragItem, delta ); } } } } else if( item->Type() == SCH_FIELD_T || item->Type() == SCH_TEXT_T ) { - VECTOR2I gridpt = - grid.AlignGrid( item->GetPosition(), selectionGrid ) - item->GetPosition(); + VECTOR2I delta = grid.AlignGrid( item->GetPosition(), selectionGrid ) - item->GetPosition(); - if( gridpt != VECTOR2I( 0, 0 ) ) - doMoveItem( item, gridpt ); + if( delta != VECTOR2I( 0, 0 ) ) + doMoveItem( item, delta ); } else if( item->Type() == SCH_SHEET_T ) { SCH_SHEET* sheet = static_cast( item ); VECTOR2I topLeft = sheet->GetPosition(); VECTOR2I bottomRight = topLeft + sheet->GetSize(); - VECTOR2I tl_gridpt = grid.AlignGrid( topLeft, selectionGrid ) - topLeft; - VECTOR2I br_gridpt = grid.AlignGrid( bottomRight, selectionGrid ) - bottomRight; + VECTOR2I tl_delta = grid.AlignGrid( topLeft, selectionGrid ) - topLeft; + VECTOR2I br_delta = grid.AlignGrid( bottomRight, selectionGrid ) - bottomRight; - if( tl_gridpt != VECTOR2I( 0, 0 ) || br_gridpt != VECTOR2I( 0, 0 ) ) + if( tl_delta != VECTOR2I( 0, 0 ) || br_delta != VECTOR2I( 0, 0 ) ) { - doMoveItem( sheet, tl_gridpt ); + doMoveItem( sheet, tl_delta ); - VECTOR2I newSize = (VECTOR2I) sheet->GetSize() - tl_gridpt + br_gridpt; + VECTOR2I newSize = (VECTOR2I) sheet->GetSize() - tl_delta + br_delta; sheet->SetSize( VECTOR2I( newSize.x, newSize.y ) ); updateItem( sheet, true ); + } - for( SCH_SHEET_PIN* pin : sheet->GetPins() ) + for( SCH_SHEET_PIN* pin : sheet->GetPins() ) + { + VECTOR2I newPos; + + if( pin->GetSide() == SHEET_SIDE::TOP || pin->GetSide() == SHEET_SIDE::LEFT ) + newPos = pin->GetPosition() + tl_delta; + else + newPos = pin->GetPosition() + br_delta; + + VECTOR2I delta = grid.AlignGrid( newPos, selectionGrid ) - pin->GetPosition(); + + if( delta != VECTOR2I( 0, 0 ) ) { - VECTOR2I gridpt; + EDA_ITEMS drag_items; + getConnectedDragItems( &commit, pin, pin->GetConnectionPoints()[0], + drag_items ); - if( pin->GetSide() == SHEET_SIDE::TOP || pin->GetSide() == SHEET_SIDE::LEFT ) - gridpt = tl_gridpt; - else - gridpt = br_gridpt; + doMoveItem( pin, delta ); - if( gridpt != VECTOR2I( 0, 0 ) ) + for( EDA_ITEM* dragItem : drag_items ) { - EDA_ITEMS drag_items; - getConnectedDragItems( &commit, pin, pin->GetConnectionPoints()[0], - drag_items ); + if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() ) + continue; - doMoveItem( pin, gridpt ); - - for( EDA_ITEM* dragItem : drag_items ) - { - if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() ) - continue; - - doMoveItem( dragItem, gridpt ); - } + doMoveItem( dragItem, delta ); } } }