Implement align-to-grid for sheets.
Fixes https://gitlab.com/kicad/code/kicad/issues/11201
(cherry picked from commit 8dc680adbb
)
This commit is contained in:
parent
e98e9f72df
commit
f89256e51e
|
@ -753,8 +753,8 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
|
|||
if( aItem->HasFlag( ENDPOINT ) )
|
||||
line->MoveEnd( (wxPoint) aDelta );
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case SCH_PIN_T:
|
||||
case SCH_FIELD_T:
|
||||
|
@ -778,13 +778,16 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
case SCH_SHEET_PIN_T:
|
||||
{
|
||||
SCH_SHEET_PIN* pin = (SCH_SHEET_PIN*) aItem;
|
||||
|
||||
pin->SetStoredPos( pin->GetStoredPos() + (wxPoint) aDelta );
|
||||
pin->ConstrainOnEdge( pin->GetStoredPos() );
|
||||
break;
|
||||
}
|
||||
|
||||
case SCH_LABEL_T:
|
||||
{
|
||||
SCH_TEXT* label = static_cast<SCH_TEXT*>( aItem );
|
||||
|
@ -802,6 +805,7 @@ void SCH_MOVE_TOOL::moveItem( EDA_ITEM* aItem, const VECTOR2I& aDelta )
|
|||
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
static_cast<SCH_ITEM*>( aItem )->Move( (wxPoint) aDelta );
|
||||
break;
|
||||
|
@ -818,6 +822,17 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
|
|||
EE_SELECTION& selection = m_selectionTool->RequestSelection( EE_COLLECTOR::MovableItems );
|
||||
bool append_undo = false;
|
||||
|
||||
auto doMoveItem =
|
||||
[&]( EDA_ITEM* item, const VECTOR2I& delta )
|
||||
{
|
||||
saveCopyInUndoList( item, UNDO_REDO::CHANGED, append_undo );
|
||||
append_undo = true;
|
||||
|
||||
moveItem( item, delta );
|
||||
item->ClearFlags( IS_MOVING );
|
||||
updateItem( item, true );
|
||||
};
|
||||
|
||||
for( SCH_ITEM* it : m_frame->GetScreen()->Items() )
|
||||
{
|
||||
if( !it->IsSelected() )
|
||||
|
@ -861,12 +876,7 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
|
|||
if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
|
||||
continue;
|
||||
|
||||
saveCopyInUndoList( dragItem, UNDO_REDO::CHANGED, append_undo );
|
||||
append_undo = true;
|
||||
|
||||
moveItem( dragItem, gridpt );
|
||||
dragItem->ClearFlags( IS_MOVING );
|
||||
updateItem( dragItem, true );
|
||||
doMoveItem( dragItem, gridpt );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -876,13 +886,49 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
|
|||
VECTOR2I gridpt = grid.AlignGrid( item->GetPosition() ) - item->GetPosition();
|
||||
|
||||
if( gridpt != VECTOR2I( 0, 0 ) )
|
||||
{
|
||||
saveCopyInUndoList( item, UNDO_REDO::CHANGED, append_undo );
|
||||
append_undo = true;
|
||||
doMoveItem( item, gridpt );
|
||||
}
|
||||
else if( item->Type() == SCH_SHEET_T )
|
||||
{
|
||||
SCH_SHEET* sheet = static_cast<SCH_SHEET*>( item );
|
||||
VECTOR2I topRight = sheet->GetPosition();
|
||||
VECTOR2I bottomRight = topRight + sheet->GetSize();
|
||||
VECTOR2I tl_gridpt = grid.AlignGrid( topRight ) - topRight;
|
||||
VECTOR2I br_gridpt = grid.AlignGrid( bottomRight ) - bottomRight;
|
||||
|
||||
moveItem( item, gridpt );
|
||||
updateItem( item, true );
|
||||
item->ClearFlags( IS_MOVING );
|
||||
if( tl_gridpt != VECTOR2I( 0, 0 ) || br_gridpt != VECTOR2I( 0, 0 ) )
|
||||
{
|
||||
doMoveItem( sheet, tl_gridpt );
|
||||
|
||||
VECTOR2I newSize = (VECTOR2I) sheet->GetSize() - tl_gridpt + br_gridpt;
|
||||
sheet->SetSize( wxSize( newSize.x, newSize.y ) );
|
||||
updateItem( sheet, true );
|
||||
|
||||
for( SCH_SHEET_PIN* pin : sheet->GetPins() )
|
||||
{
|
||||
VECTOR2I gridpt;
|
||||
|
||||
if( pin->GetSide() == SHEET_SIDE::TOP || pin->GetSide() == SHEET_SIDE::LEFT )
|
||||
gridpt = tl_gridpt;
|
||||
else
|
||||
gridpt = br_gridpt;
|
||||
|
||||
if( gridpt != VECTOR2I( 0, 0 ) )
|
||||
{
|
||||
EDA_ITEMS drag_items;
|
||||
getConnectedDragItems( pin, pin->GetConnectionPoints()[0], drag_items );
|
||||
|
||||
doMoveItem( pin, gridpt );
|
||||
|
||||
for( EDA_ITEM* dragItem : drag_items )
|
||||
{
|
||||
if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
|
||||
continue;
|
||||
|
||||
doMoveItem( dragItem, gridpt );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -918,12 +964,7 @@ int SCH_MOVE_TOOL::AlignElements( const TOOL_EVENT& aEvent )
|
|||
if( dragItem->GetParent() && dragItem->GetParent()->IsSelected() )
|
||||
continue;
|
||||
|
||||
saveCopyInUndoList( dragItem, UNDO_REDO::CHANGED, append_undo );
|
||||
append_undo = true;
|
||||
|
||||
moveItem( dragItem, most_common );
|
||||
dragItem->ClearFlags( IS_MOVING );
|
||||
updateItem( dragItem, true );
|
||||
doMoveItem( dragItem, most_common );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue