pcbnew - refactor move exactly tool (2/2)
This patch does the following: * extracts a method to determine the anchor point of the move * improves the logic of the anchor point determination for selections of multiple objects which do not contain footprints
This commit is contained in:
parent
bf832dd941
commit
b7f2525c5d
|
@ -7,6 +7,7 @@ include_directories(
|
||||||
../../3d-viewer
|
../../3d-viewer
|
||||||
../../pcbnew
|
../../pcbnew
|
||||||
../../polygon
|
../../polygon
|
||||||
|
../dialogs
|
||||||
${INC_AFTER}
|
${INC_AFTER}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -738,55 +738,7 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
|
||||||
VECTOR2I rp = selection.GetCenter();
|
VECTOR2I rp = selection.GetCenter();
|
||||||
wxPoint rotPoint( rp.x, rp.y );
|
wxPoint rotPoint( rp.x, rp.y );
|
||||||
|
|
||||||
// Begin at the center of the selection determined above
|
wxPoint anchorPoint = getAnchorPoint( selection, params );
|
||||||
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<BOARD_ITEM*>( selection.GetTopLeftModule() );
|
|
||||||
|
|
||||||
// no module found if the GetTopLeftModule() returns null, retry for
|
|
||||||
if( topLeftItem == nullptr )
|
|
||||||
{
|
|
||||||
topLeftItem = static_cast<BOARD_ITEM*>( selection.GetTopLeftItem() );
|
|
||||||
anchorPoint = topLeftItem->GetPosition();
|
|
||||||
}
|
|
||||||
|
|
||||||
if( topLeftItem->Type() == PCB_MODULE_T )
|
|
||||||
{
|
|
||||||
// Cast to module to allow access to the pads
|
|
||||||
MODULE* mod = static_cast<MODULE*>( 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<D_PAD*>( 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 finalMoveVector = params.translation - anchorPoint;
|
wxPoint finalMoveVector = params.translation - anchorPoint;
|
||||||
|
|
||||||
|
@ -814,6 +766,77 @@ int EDIT_TOOL::MoveExact( const TOOL_EVENT& aEvent )
|
||||||
return 0;
|
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<BOARD_ITEM*>( 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<MODULE*>( 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<D_PAD*>( 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<BOARD_ITEM*>( selection.GetTopLeftItem() );
|
||||||
|
anchorPoint = topLeftItem->GetPosition();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return anchorPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
#include <math/vector2d.h>
|
#include <math/vector2d.h>
|
||||||
#include <tools/pcb_tool.h>
|
#include <tools/pcb_tool.h>
|
||||||
|
#include <dialogs/dialog_move_exact.h>
|
||||||
|
|
||||||
class BOARD_COMMIT;
|
class BOARD_COMMIT;
|
||||||
class BOARD_ITEM;
|
class BOARD_ITEM;
|
||||||
|
@ -205,6 +206,8 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<BOARD_COMMIT> m_commit;
|
std::unique_ptr<BOARD_COMMIT> m_commit;
|
||||||
|
|
||||||
|
wxPoint getAnchorPoint( const SELECTION &selection, const MOVE_PARAMETERS ¶ms ) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue