diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 93e878031c..db08a607a5 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -147,7 +147,7 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) // Drag items to the current cursor position for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) - selection.Item( i )->Move( movement ); + selection.Item( i )->Move( movement + m_offset ); updateRatsnest( true ); } @@ -157,9 +157,21 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) editFrame->OnModify(); editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - // Set the current cursor position to the first dragged item origin, so the - // movement vector could be computed later - m_cursor = VECTOR2I( selection.Item( 0 )->GetPosition() ); + if( evt->Modifier( MD_CTRL ) ) + { + // Set the current cursor position to the first dragged item origin, so the + // movement vector could be computed later + m_cursor = VECTOR2I( selection.Item( 0 )->GetPosition() ); + m_offset.x = 0; + m_offset.y = 0; + } + else + { + // Update dragging offset (distance between cursor and the first dragged item) + m_offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - + wxPoint( m_cursor.x, m_cursor.y ); + } + m_dragging = true; } @@ -309,6 +321,10 @@ int EDIT_TOOL::Rotate( TOOL_EVENT& aEvent ) updateRatsnest( m_dragging ); + // Update dragging offset (distance between cursor and the first dragged item) + m_offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - + rotatePoint; + if( m_dragging ) selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); else @@ -359,6 +375,10 @@ int EDIT_TOOL::Flip( TOOL_EVENT& aEvent ) updateRatsnest( m_dragging ); + // Update dragging offset (distance between cursor and the first dragged item) + m_offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - + flipPoint; + if( m_dragging ) selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY ); else @@ -491,7 +511,7 @@ wxPoint EDIT_TOOL::getModificationPoint( const SELECTION_TOOL::SELECTION& aSelec { if( aSelection.Size() == 1 ) { - return aSelection.Item( 0 )->GetPosition(); + return aSelection.Item( 0 )->GetPosition() - m_offset; } else { diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index fb74135b86..207e446493 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -98,6 +98,9 @@ private: ///> Flag determining if anything is being dragged right now bool m_dragging; + ///> Offset from the dragged item's center (anchor) + wxPoint m_offset; + ///> Last cursor position (needed for getModificationPoint() to avoid changes ///> of edit reference point). VECTOR2I m_cursor;