From d73ab976df192ee794dd39f7bc02af26982ae1fb Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Wed, 9 Jul 2014 14:01:06 +0200 Subject: [PATCH] Added support for placing the footprint anchor. --- pcbnew/tools/common_actions.cpp | 9 ++++++- pcbnew/tools/common_actions.h | 3 +++ pcbnew/tools/drawing_tool.cpp | 47 +++++++++++++++++++++++++++++++++ pcbnew/tools/drawing_tool.h | 6 +++++ pcbnew/tools/pcbnew_control.cpp | 2 +- 5 files changed, 65 insertions(+), 2 deletions(-) diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 45305cc83e..41fbea71e8 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -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 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 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(); } diff --git a/pcbnew/tools/common_actions.h b/pcbnew/tools/common_actions.h index 9c812414df..f971116d6e 100644 --- a/pcbnew/tools/common_actions.h +++ b/pcbnew/tools/common_actions.h @@ -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; diff --git a/pcbnew/tools/drawing_tool.cpp b/pcbnew/tools/drawing_tool.cpp index fff955bfca..d3da87ce44 100644 --- a/pcbnew/tools/drawing_tool.cpp +++ b/pcbnew/tools/drawing_tool.cpp @@ -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() ); } diff --git a/pcbnew/tools/drawing_tool.h b/pcbnew/tools/drawing_tool.h index 29b87560ea..293674a81f 100644 --- a/pcbnew/tools/drawing_tool.h +++ b/pcbnew/tools/drawing_tool.h @@ -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 diff --git a/pcbnew/tools/pcbnew_control.cpp b/pcbnew/tools/pcbnew_control.cpp index 89b356c38c..3a46cbacff 100644 --- a/pcbnew/tools/pcbnew_control.cpp +++ b/pcbnew/tools/pcbnew_control.cpp @@ -452,7 +452,7 @@ int PCBNEW_CONTROL::GridSetOrigin( TOOL_EVENT& aEvent ) getView()->MarkDirty(); } - else if( evt->IsCancel() ) + else if( evt->IsCancel() || evt->IsActivate() ) break; }