From 720de6bae193ef15fb749ac52758b32e0f9aaa78 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 3 Sep 2019 17:16:27 +0100 Subject: [PATCH] Cleanup. --- pcbnew/class_board.cpp | 3 +- pcbnew/tools/edit_tool.cpp | 57 ++++++++++---------------------------- 2 files changed, 15 insertions(+), 45 deletions(-) diff --git a/pcbnew/class_board.cpp b/pcbnew/class_board.cpp index 14fe280ab2..04dc0a6c1d 100644 --- a/pcbnew/class_board.cpp +++ b/pcbnew/class_board.cpp @@ -1645,8 +1645,7 @@ bool BOARD::NormalizeAreaPolygon( PICKED_ITEMS_LIST * aNewZonesList, ZONE_CONTAI } -BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, - bool aAddToBoard ) +BOARD_ITEM* BOARD::Duplicate( const BOARD_ITEM* aItem, bool aAddToBoard ) { BOARD_ITEM* new_item = NULL; diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 1fe4de26af..a548487419 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -323,14 +323,14 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) { if( m_dragging && evt->Category() == TC_MOUSE ) { - m_cursor = grid.BestSnapAnchor( controls->GetMousePosition(), item_layers, - sel_items ); + VECTOR2I mousePos( controls->GetMousePosition() ); + m_cursor = grid.BestSnapAnchor( mousePos, item_layers, sel_items ); controls->ForceCursorPosition( true, m_cursor ); - VECTOR2I movement( m_cursor - prevPos ); selection.SetReferencePoint( m_cursor ); - totalMovement += movement; + VECTOR2I movement( m_cursor - prevPos ); prevPos = m_cursor; + totalMovement += movement; // Drag items to the current cursor position // @@ -375,7 +375,7 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) else { // Save items, so changes can be undone - for( auto item : selection ) + for( EDA_ITEM* item : selection ) { // Don't double move footprint pads, fields, etc. if( item->GetParent() && item->GetParent()->IsSelected() ) @@ -396,7 +396,7 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) auto delta = m_cursor - selection.GetReferencePoint(); // Drag items to the current cursor position - for( auto item : selection ) + for( EDA_ITEM* item : selection ) { // Don't double move footprint pads, fields, etc. if( item->GetParent() && item->GetParent()->IsSelected() ) @@ -411,7 +411,7 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) { std::vector items; - for( auto item : selection.Items() ) + for( EDA_ITEM* item : selection ) items.push_back( static_cast( item ) ); // Set the current cursor position to the first dragged item origin, so the @@ -448,50 +448,34 @@ int EDIT_TOOL::Move( const TOOL_EVENT& aEvent ) { if( evt->IsAction( &ACTIONS::doDelete ) ) { - // exit the loop, as there is no further processing for removed items - break; + break; // finish -- there is no further processing for removed items } else if( evt->IsAction( &ACTIONS::duplicate ) ) { - // On duplicate, stop moving this item - // The duplicate tool should then select the new item and start - // a new move procedure - break; + break; // finish -- Duplicate tool will start a new Move with the dup'ed items } else if( evt->IsAction( &PCB_ACTIONS::moveExact ) ) { - // Can't do this, because the selection will then contain - // stale pointers and it will all go horribly wrong... - //editFrame->RestoreCopyFromUndoList( dummy ); - // - // So, instead, reset the position manually - for( auto item : selection ) + // Reset positions so the Move Exactly is from the start. + for( EDA_ITEM* item : selection ) { BOARD_ITEM* i = static_cast( item ); i->Move( -totalMovement ); - - // And what about flipping and rotation? - // for now, they won't be undone, but maybe that is how - // it should be, so you can flip and move exact in the - // same action? } - // This causes a double event, so we will get the dialogue - // correctly, somehow - why does Rotate not? - //MoveExact( aEvent ); - break; // exit the loop - we move exactly, so we have finished moving + break; // finish -- we moved exactly, so we are finished } } else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) { - break; // Finish + break; // finish } else evt->SetPassEvent(); - } while( ( evt = Wait() ) ); //Should be assignment not equality test + } while( ( evt = Wait() ) ); // Assignment (instead of equality test) is intentional m_lockedSelected = false; controls->ForceCursorPosition( false ); @@ -1030,25 +1014,12 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) // Old selection is cleared, and new items are then selected. for( EDA_ITEM* item : selection ) { - if( !item ) - continue; - orig_item = static_cast( item ); if( m_editModules ) - { dupe_item = editFrame->GetBoard()->GetFirstModule()->Duplicate( orig_item, increment ); - } else - { -#if 0 - // @TODO: see if we allow zone duplication here - // Duplicate zones is especially tricky (overlaping zones must be merged) - // so zones are not duplicated - if( item->Type() != PCB_ZONE_AREA_T ) -#endif dupe_item = editFrame->GetBoard()->Duplicate( orig_item ); - } if( dupe_item ) {