From aaa44b7348ae24a219d2da7630a0f3de8efbf826 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 20 Aug 2019 19:40:26 +0100 Subject: [PATCH] Honor the {0, 0} reference on the clipboard. Fixes: lp:1840819 * https://bugs.launchpad.net/kicad/+bug/1840819 --- pcbnew/kicad_clipboard.cpp | 4 ++-- pcbnew/tools/edit_tool.cpp | 2 +- pcbnew/tools/pcbnew_control.cpp | 24 ++++++++++++++++-------- pcbnew/tools/pcbnew_control.h | 13 ++++++++----- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/pcbnew/kicad_clipboard.cpp b/pcbnew/kicad_clipboard.cpp index 701c4729ff..d2a3d0edb6 100644 --- a/pcbnew/kicad_clipboard.cpp +++ b/pcbnew/kicad_clipboard.cpp @@ -131,7 +131,7 @@ void CLIPBOARD_IO::SaveSelection( const PCBNEW_SELECTION& aSelected ) partialModule.Add( clone ); // locate the reference point at (0, 0) in the copied items - clone->Move( wxPoint(-refPoint.x, -refPoint.y ) ); + clone->Move( (wxPoint) -refPoint ); } // Set the new relative internal local coordinates of copied items @@ -173,7 +173,7 @@ void CLIPBOARD_IO::SaveSelection( const PCBNEW_SELECTION& aSelected ) std::unique_ptr clone( static_cast ( item->Clone() ) ); // locate the reference point at (0, 0) in the copied items - clone->Move( wxPoint(-refPoint.x, -refPoint.y ) ); + clone->Move( (wxPoint) -refPoint ); Format( clone.get(), 1 ); } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index c11bac377e..3ad5a12f23 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -331,7 +331,7 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) { m_cursor = grid.BestSnapAnchor( controls->GetMousePosition(), item_layers, sel_items ); - controls->ForceCursorPosition(true, m_cursor ); + controls->ForceCursorPosition( true, m_cursor ); VECTOR2I movement( m_cursor - prevPos ); selection.SetReferencePoint( m_cursor ); diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 3140a30352..b9963d6d61 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -606,7 +606,7 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent ) return 0; } - placeBoardItems( static_cast( clipItem ) ); + placeBoardItems( static_cast( clipItem ), true ); break; } @@ -642,7 +642,7 @@ int PCBNEW_CONTROL::Paste( const TOOL_EVENT& aEvent ) items.push_back( clipItem ); } - placeBoardItems( items, true ); + placeBoardItems( items, true, true ); break; } @@ -731,7 +731,7 @@ static void moveNoFlagToVector( ZONE_CONTAINERS& aList, std::vectorDrawings(), items, isNew ); moveNoFlagToVector( aBoard->Zones(), items, isNew ); - return placeBoardItems( items, isNew ); + return placeBoardItems( items, isNew, aAnchorAtOrigin ); } -int PCBNEW_CONTROL::placeBoardItems( std::vector& aItems, bool aIsNew ) +int PCBNEW_CONTROL::placeBoardItems( std::vector& aItems, bool aIsNew, + bool aAnchorAtOrigin ) { m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); @@ -769,9 +770,16 @@ int PCBNEW_CONTROL::placeBoardItems( std::vector& aItems, bool aIsN if( selection.Size() > 0 ) { - BOARD_ITEM* item = (BOARD_ITEM*) selection.GetTopLeftItem(); + if( aAnchorAtOrigin ) + { + selection.SetReferencePoint( VECTOR2I( 0, 0 ) ); + } + else + { + BOARD_ITEM* item = (BOARD_ITEM*) selection.GetTopLeftItem(); + selection.SetReferencePoint( item->GetPosition() ); + } - selection.SetReferencePoint( item->GetPosition() ); getViewControls()->SetCursorPosition( getViewControls()->GetMousePosition(), false ); m_toolMgr->ProcessEvent( EVENTS::SelectedEvent ); @@ -855,7 +863,7 @@ int PCBNEW_CONTROL::AppendBoard( PLUGIN& pi, wxString& fileName ) brd->SetEnabledLayers( enabledLayers ); brd->SetVisibleLayers( enabledLayers ); - return placeBoardItems( brd ); + return placeBoardItems( brd, false ); } diff --git a/pcbnew/tools/pcbnew_control.h b/pcbnew/tools/pcbnew_control.h index b13e06be3e..2bc7a309cf 100644 --- a/pcbnew/tools/pcbnew_control.h +++ b/pcbnew/tools/pcbnew_control.h @@ -97,14 +97,17 @@ public: void setTransitions() override; private: - int placeBoardItems( BOARD* aBoard ); - - /** add and selec or just select for move/place command a list of board items. + /** + * Add and select or just select for move/place command a list of board items. * @param aItems is the list of items * @param aIsNew = true to add items to the current board, false to just select if - * items are already managed by the current board + * items are already managed by the current board + * @param aAnchorAtOrigin = true if the items are translated so that the anchor is {0, 0} + * (if false, the top-left item's origin will be used) */ - int placeBoardItems( std::vector& aItems, bool aIsNew ); + int placeBoardItems( std::vector& aItems, bool aIsNew, bool aAnchorAtOrigin ); + + int placeBoardItems( BOARD* aBoard, bool aAnchorAtOrigin ); ///> Pointer to the currently used edit frame. PCB_BASE_FRAME* m_frame;