Commit d73ab976 authored by Maciej Suminski's avatar Maciej Suminski

Added support for placing the footprint anchor.

parent 637919a6
......@@ -101,6 +101,11 @@ TOOL_ACTION COMMON_ACTIONS::placePad( "pcbnew.InteractiveDrawing.placePad",
AS_GLOBAL, 0,
"Add pads", "Add pads", AF_ACTIVATE );
TOOL_ACTION COMMON_ACTIONS::setAnchor( "pcbnew.InteractiveDrawing.setAnchor",
AS_GLOBAL, 0,
"Place the footprint anchor", "Place the footprint anchor",
AF_ACTIVATE );
// View Controls
TOOL_ACTION COMMON_ACTIONS::zoomIn( "pcbnew.Control.zoomIn",
AS_GLOBAL, WXK_F1,
......@@ -313,6 +318,9 @@ boost::optional<TOOL_EVENT> COMMON_ACTIONS::TranslateLegacyId( int aId )
case ID_MODEDIT_PAD_TOOL:
return COMMON_ACTIONS::placePad.MakeEvent();
case ID_MODEDIT_ANCHOR_TOOL:
return COMMON_ACTIONS::setAnchor.MakeEvent();
case ID_PCB_PLACE_GRID_COORD_BUTT:
case ID_MODEDIT_PLACE_GRID_COORD:
return COMMON_ACTIONS::gridSetOrigin.MakeEvent();
......@@ -336,7 +344,6 @@ boost::optional<TOOL_EVENT> COMMON_ACTIONS::TranslateLegacyId( int aId )
case ID_MENU_PCB_SHOW_HIDE_MUWAVE_TOOLBAR:
case ID_MICROWAVE_V_TOOLBAR:
case ID_MODEDIT_DELETE_TOOL:
case ID_MODEDIT_ANCHOR_TOOL:
return COMMON_ACTIONS::toBeDone.MakeEvent();
}
......
......@@ -93,6 +93,9 @@ public:
/// Activation of the drawing tool (placing a PAD)
static TOOL_ACTION placePad;
/// Activation of the drawing tool (placing the footprint anchor)
static TOOL_ACTION setAnchor;
// Push and Shove Router Tool
/// Activation of the Push and Shove router
static TOOL_ACTION routerActivate;
......
......@@ -700,6 +700,52 @@ int DRAWING_TOOL::PlacePad( TOOL_EVENT& aEvent )
}
int DRAWING_TOOL::SetAnchor( TOOL_EVENT& aEvent )
{
assert( m_editModules );
Activate();
m_frame->SetToolID( ID_MODEDIT_ANCHOR_TOOL, wxCURSOR_PENCIL,
_( "Place the footprint anchor" ) );
KIGFX::VIEW_CONTROLS* controls = getViewControls();
controls->ShowCursor( true );
controls->SetSnapping( true );
controls->SetAutoPan( true );
while( OPT_TOOL_EVENT evt = Wait() )
{
if( evt->IsClick( BUT_LEFT ) )
{
MODULE* module = m_board->m_Modules;
m_frame->SaveCopyInUndoList( module, UR_MODEDIT );
// set the new relative internal local coordinates of footprint items
VECTOR2I cursorPos = controls->GetCursorPosition();
wxPoint moveVector = module->GetPosition() - wxPoint( cursorPos.x, cursorPos.y );
module->MoveAnchorPosition( moveVector );
// Usually, we do not need to change twice the anchor position,
// so deselect the active tool
break;
}
else if( evt->IsCancel() || evt->IsActivate() )
break;
}
controls->SetAutoPan( false );
controls->SetSnapping( false );
controls->ShowCursor( false );
setTransitions();
m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString );
return 0;
}
bool DRAWING_TOOL::drawSegment( int aShape, DRAWSEGMENT* aGraphic )
{
// Only two shapes are currently supported
......@@ -1534,4 +1580,5 @@ void DRAWING_TOOL::setTransitions()
Go( &DRAWING_TOOL::PlaceTarget, COMMON_ACTIONS::placeTarget.MakeEvent() );
Go( &DRAWING_TOOL::PlaceModule, COMMON_ACTIONS::placeModule.MakeEvent() );
Go( &DRAWING_TOOL::PlacePad, COMMON_ACTIONS::placePad.MakeEvent() );
Go( &DRAWING_TOOL::SetAnchor, COMMON_ACTIONS::setAnchor.MakeEvent() );
}
......@@ -126,6 +126,12 @@ public:
*/
int PlacePad( TOOL_EVENT& aEvent );
/**
* Function SetAnchor()
* Places the footprint anchor (only in module editor).
*/
int SetAnchor( TOOL_EVENT& aEvent );
/**
* Function EditModules()
* Toggles edit module mode. When enabled, one may select parts of modules individually
......
......@@ -452,7 +452,7 @@ int PCBNEW_CONTROL::GridSetOrigin( TOOL_EVENT& aEvent )
getView()->MarkDirty();
}
else if( evt->IsCancel() )
else if( evt->IsCancel() || evt->IsActivate() )
break;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment