diff --git a/pcbnew/router/CMakeLists.txt b/pcbnew/router/CMakeLists.txt index be9b7c386a..a5c1152b12 100644 --- a/pcbnew/router/CMakeLists.txt +++ b/pcbnew/router/CMakeLists.txt @@ -7,6 +7,7 @@ include_directories( ../../3d-viewer ../../pcbnew ../../polygon + ../dialogs ${INC_AFTER} ) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index e773fe1d95..7afa189968 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -738,55 +738,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) VECTOR2I rp = selection.GetCenter(); wxPoint rotPoint( rp.x, rp.y ); - // Begin at the center of the selection determined above - wxPoint anchorPoint = rotPoint; - - // If the anchor is not ANCHOR_FROM_LIBRARY then the user applied an override. - // Also run through this block if only one item is slected because it may be a module, - // in which case we want something different than the center of the selection - if( ( params.anchor != ANCHOR_FROM_LIBRARY ) || ( selection.GetSize() == 1 ) ) - { - BOARD_ITEM* topLeftItem = static_cast( selection.GetTopLeftModule() ); - - // no module found if the GetTopLeftModule() returns null, retry for - if( topLeftItem == nullptr ) - { - topLeftItem = static_cast( selection.GetTopLeftItem() ); - anchorPoint = topLeftItem->GetPosition(); - } - - if( topLeftItem->Type() == PCB_MODULE_T ) - { - // Cast to module to allow access to the pads - MODULE* mod = static_cast( topLeftItem ); - - switch( params.anchor ) - { - case ANCHOR_FROM_LIBRARY: - anchorPoint = mod->GetPosition(); - break; - case ANCHOR_TOP_LEFT_PAD: - topLeftItem = mod->GetTopLeftPad(); - break; - case ANCHOR_CENTER_FOOTPRINT: - anchorPoint = mod->GetFootprintRect().GetCenter(); - break; - } - } - - if( topLeftItem->Type() == PCB_PAD_T ) - { - if( static_cast( topLeftItem )->GetAttribute() == PAD_ATTRIB_SMD ) - { - // Use the top left corner of SMD pads as an anchor instead of the center - anchorPoint = topLeftItem->GetBoundingBox().GetPosition(); - } - else - { - anchorPoint = topLeftItem->GetPosition(); - } - } - } + wxPoint anchorPoint = getAnchorPoint( selection, params ); wxPoint finalMoveVector = params.translation - anchorPoint; @@ -814,6 +766,77 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent ) return 0; } +wxPoint EDIT_TOOL::getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS ¶ms ) const +{ + wxPoint anchorPoint; + + if( params.origin == RELATIVE_TO_CURRENT_POSITION ) + { + return wxPoint( 0, 0 ); + } + + // set default anchor + VECTOR2I rp = selection.GetCenter(); + anchorPoint = wxPoint( rp.x, rp.y ); + + // If the anchor is not ANCHOR_FROM_LIBRARY then the user applied an override. + // Also run through this block if only one item is slected because it may be a module, + // in which case we want something different than the center of the selection + if( ( params.anchor != ANCHOR_FROM_LIBRARY ) || ( selection.GetSize() == 1 ) ) + { + BOARD_ITEM* topLeftItem = static_cast( selection.GetTopLeftModule() ); + + // no module found if the GetTopLeftModule() returns null + if( topLeftItem != nullptr ) + { + + if( topLeftItem->Type() == PCB_MODULE_T ) + { + // Cast to module to allow access to the pads + MODULE* mod = static_cast( topLeftItem ); + + switch( params.anchor ) + { + case ANCHOR_FROM_LIBRARY: + anchorPoint = mod->GetPosition(); + break; + case ANCHOR_TOP_LEFT_PAD: + topLeftItem = mod->GetTopLeftPad(); + break; + case ANCHOR_CENTER_FOOTPRINT: + anchorPoint = mod->GetFootprintRect().GetCenter(); + break; + } + } + + if( topLeftItem->Type() == PCB_PAD_T ) + { + if( static_cast( topLeftItem )->GetAttribute() == PAD_ATTRIB_SMD ) + { + // Use the top left corner of SMD pads as an anchor instead of the center + anchorPoint = topLeftItem->GetBoundingBox().GetPosition(); + } + else + { + anchorPoint = topLeftItem->GetPosition(); + } + } + } + else // no module found in the selection + { + // in a selection of non-modules + if( params.anchor == ANCHOR_TOP_LEFT_PAD ) + { + // approach the top left pad override for non-modules by using the position of + // the topleft item as an anchor + topLeftItem = static_cast( selection.GetTopLeftItem() ); + anchorPoint = topLeftItem->GetPosition(); + } + } + } + return anchorPoint; +} + int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) { diff --git a/pcbnew/tools/edit_tool.h b/pcbnew/tools/edit_tool.h index 71ff819fe2..c3e3287e1a 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -28,6 +28,7 @@ #include #include +#include class BOARD_COMMIT; class BOARD_ITEM; @@ -205,6 +206,8 @@ private: } std::unique_ptr m_commit; + + wxPoint getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS ¶ms ) const; }; #endif