diff --git a/pcbnew/dialogs/dialog_move_exact.cpp b/pcbnew/dialogs/dialog_move_exact.cpp index f2f2ae0137..b3bc94c56f 100644 --- a/pcbnew/dialogs/dialog_move_exact.cpp +++ b/pcbnew/dialogs/dialog_move_exact.cpp @@ -311,7 +311,7 @@ void DIALOG_MOVE_EXACT::OnOkClick( wxCommandEvent& event ) // -> set origin and anchor to zero origin = wxPoint( 0, 0 ); break; - } + } m_translation = move_vector + origin; diff --git a/pcbnew/router/CMakeLists.txt b/pcbnew/router/CMakeLists.txt index a5c1152b12..be9b7c386a 100644 --- a/pcbnew/router/CMakeLists.txt +++ b/pcbnew/router/CMakeLists.txt @@ -7,7 +7,6 @@ include_directories( ../../3d-viewer ../../pcbnew ../../polygon - ../dialogs ${INC_AFTER} ) diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 7afa189968..673cba764e 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -158,6 +158,82 @@ TOOL_ACTION PCB_ACTIONS::measureTool( "pcbnew.InteractiveEdit.measureTool", nullptr, AF_ACTIVATE ); +static wxPoint getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS ¶ms ) +{ + 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; +} + + + + EDIT_TOOL::EDIT_TOOL() : PCB_TOOL( "pcbnew.InteractiveEdit" ), m_selectionTool( NULL ), m_dragging( false ) @@ -223,8 +299,6 @@ bool EDIT_TOOL::Init() bool EDIT_TOOL::invokeInlineRouter() - - { TRACK* track = uniqueSelected(); VIA* via = uniqueSelected(); @@ -766,77 +840,6 @@ 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 c3e3287e1a..71ff819fe2 100644 --- a/pcbnew/tools/edit_tool.h +++ b/pcbnew/tools/edit_tool.h @@ -28,7 +28,6 @@ #include #include -#include class BOARD_COMMIT; class BOARD_ITEM; @@ -206,8 +205,6 @@ private: } std::unique_ptr m_commit; - - wxPoint getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS ¶ms ) const; }; #endif