From 929008c6c33133198544c7f9a1a6b168cf84aa5f Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Tue, 13 May 2014 11:22:51 +0200 Subject: [PATCH] SELECTION_TOOL updates dragging offset after rotating/flipping. Cursor position is saved as a field in order to avoid drifting of items while they are being dragged and rotated/flipped. --- pcbnew/tools/edit_tool.cpp | 28 ++++++++++++++++------------ pcbnew/tools/edit_tool.h | 6 ++++++ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 8dac46385c..36814e541d 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -92,9 +92,6 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) // By default, modified items need to update their geometry m_updateFlag = KIGFX::VIEW_ITEM::GEOMETRY; - // Offset from the dragged item's center (anchor) - wxPoint offset; - KIGFX::VIEW_CONTROLS* controls = getViewControls(); PCB_EDIT_FRAME* editFrame = static_cast( m_toolMgr->GetEditFrame() ); controls->ShowCursor( true ); @@ -141,18 +138,18 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) { - VECTOR2I cursor( controls->GetCursorPosition() ); + m_cursor = controls->GetCursorPosition(); if( m_dragging ) { - wxPoint movement = wxPoint( cursor.x, cursor.y ) - + wxPoint movement = wxPoint( m_cursor.x, m_cursor.y ) - static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition(); // Drag items to the current cursor position for( unsigned int i = 0; i < selection.items.GetCount(); ++i ) { BOARD_ITEM* item = static_cast( selection.items.GetPickedItem( i ) ); - item->Move( movement + offset ); + item->Move( movement + m_offset ); } updateRatsnest( true ); @@ -163,8 +160,9 @@ int EDIT_TOOL::Main( TOOL_EVENT& aEvent ) editFrame->OnModify(); editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); - offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - - wxPoint( cursor.x, cursor.y ); + // 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; } @@ -227,14 +225,13 @@ int EDIT_TOOL::Properties( TOOL_EVENT& aEvent ) { // Display properties dialog BOARD_ITEM* item = static_cast( selection.items.GetPickedItem( 0 ) ); - VECTOR2I cursor = getViewControls()->GetCursorPosition(); // Check if user wants to edit pad or module properties if( item->Type() == PCB_MODULE_T ) { for( D_PAD* pad = static_cast( item )->Pads(); pad; pad = pad->Next() ) { - if( pad->ViewBBox().Contains( cursor ) ) + if( pad->ViewBBox().Contains( m_cursor ) ) { // Turns out that user wants to edit a pad properties item = pad; @@ -298,6 +295,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 @@ -348,6 +349,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 @@ -487,8 +492,7 @@ wxPoint EDIT_TOOL::getModificationPoint( const SELECTION_TOOL::SELECTION& aSelec } else { - VECTOR2I cursor = getViewControls()->GetCursorPosition(); - return wxPoint( cursor.x, cursor.y ); + return wxPoint( m_cursor.x, m_cursor.y ); } } diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index b5f6f1fc0d..d3792766ff 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -98,6 +98,12 @@ 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 + VECTOR2I m_cursor; + ///> Removes and frees a single BOARD_ITEM. void remove( BOARD_ITEM* aItem );