From 7806cb7bca2279df3a7917d8532927e50e969d29 Mon Sep 17 00:00:00 2001 From: Maciej Suminski Date: Thu, 9 Feb 2017 12:03:07 +0100 Subject: [PATCH] Drag tracks/vias menu entry (GAL) --- pcbnew/router/router_tool.cpp | 48 +++++++++++++++++---------------- pcbnew/tools/common_actions.cpp | 5 ++-- pcbnew/tools/edit_tool.cpp | 2 +- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 59c18fc9c0..4793637d0c 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -71,10 +71,6 @@ static const TOOL_ACTION ACT_EndTrack( "pcbnew.InteractiveRouter.EndTrack", AS_C static const TOOL_ACTION ACT_AutoEndRoute( "pcbnew.InteractiveRouter.AutoEndRoute", AS_CONTEXT, 'F', _( "Auto-end Track" ), _( "Automagically finishes currently routed track." ) ); -static const TOOL_ACTION ACT_Drag( "pcbnew.InteractiveRouter.Drag", AS_CONTEXT, - TOOL_ACTION::LegacyHotKey( HK_DRAG_TRACK_KEEP_SLOPE ), - _( "Drag Track/Via" ), _( "Drags a track or a via." ), drag_track_segment_xpm ); - static const TOOL_ACTION ACT_PlaceThroughVia( "pcbnew.InteractiveRouter.PlaceVia", AS_CONTEXT, TOOL_ACTION::LegacyHotKey( HK_ADD_THROUGH_VIA ), _( "Place Through Via" ), @@ -226,7 +222,6 @@ public: Add( ACT_NewTrack ); Add( ACT_EndTrack ); // Add( ACT_AutoEndRoute ); // fixme: not implemented yet. Sorry. - Add( ACT_Drag ); Add( ACT_PlaceThroughVia ); Add( ACT_PlaceBlindVia ); Add( ACT_PlaceMicroVia ); @@ -273,6 +268,12 @@ ROUTER_TOOL::~ROUTER_TOOL() bool ROUTER_TOOL::Init() { + // Track & via dragging menu entry + auto selectionTool = m_toolMgr->GetTool(); + CONDITIONAL_MENU& menu = selectionTool->GetToolMenu().GetMenu(); + menu.AddItem( COMMON_ACTIONS::routerInlineDrag, SELECTION_CONDITIONS::Count( 1 ) + && SELECTION_CONDITIONS::OnlyTypes( { PCB_TRACE_T, PCB_VIA_T, EOT } ) ); + m_savedSettings.Load( GetSettings() ); return true; } @@ -717,11 +718,6 @@ int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) else performRouting(); } - else if( evt->IsAction( &ACT_Drag ) ) - { - updateStartItem( *evt ); - performDragging(); - } else if( evt->IsAction( &ACT_PlaceThroughVia ) ) { m_toolMgr->RunAction( COMMON_ACTIONS::layerToggle, true ); @@ -802,16 +798,22 @@ void ROUTER_TOOL::performDragging() int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) { - const BOARD_CONNECTED_ITEM* item = aEvent.Parameter(); - PCB_EDIT_FRAME* frame = getEditFrame(); - VIEW_CONTROLS* ctls = getViewControls(); + // Get the item under the cursor + m_toolMgr->RunAction( COMMON_ACTIONS::selectionCursor, true ); + const auto& selection = m_toolMgr->GetTool()->GetSelection(); - m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + if( selection.Size() != 1 ) + return 0; + + const BOARD_CONNECTED_ITEM* item = static_cast( selection.Front() ); + + if( item->Type() != PCB_TRACE_T && item->Type() != PCB_VIA_T ) + return 0; Activate(); + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); m_router->SyncWorld(); - m_startItem = m_router->GetWorld()->FindItemByParent( item ); if( m_startItem && m_startItem->IsLocked() ) @@ -820,20 +822,20 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) return false; } - VECTOR2I p0 = ctls->GetCursorPosition(); + VECTOR2I p0 = m_ctls->GetCursorPosition(); bool dragStarted = m_router->StartDragging( p0, m_startItem ); if( !dragStarted ) return 0; - ctls->ForceCursorPosition( false ); - ctls->SetAutoPan( true ); - frame->UndoRedoBlock( true ); + m_ctls->ShowCursor( true ); + m_ctls->ForceCursorPosition( false ); + m_ctls->SetAutoPan( true ); + m_frame->UndoRedoBlock( true ); while( OPT_TOOL_EVENT evt = Wait() ) { - if( evt->IsCancel() ) { break; @@ -854,9 +856,9 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) if( m_router->RoutingInProgress() ) m_router->StopRouting(); - ctls->SetAutoPan( false ); - ctls->ShowCursor( false ); - frame->UndoRedoBlock( false ); + m_ctls->SetAutoPan( false ); + m_ctls->ShowCursor( false ); + m_frame->UndoRedoBlock( false ); return 0; } diff --git a/pcbnew/tools/common_actions.cpp b/pcbnew/tools/common_actions.cpp index 8b8260d040..2d8d64285f 100644 --- a/pcbnew/tools/common_actions.cpp +++ b/pcbnew/tools/common_actions.cpp @@ -591,8 +591,9 @@ TOOL_ACTION COMMON_ACTIONS::routerActivateTuneDiffPairSkew( "pcbnew.LengthTuner. _( "Tune skew of a differential pair" ), "", NULL, AF_ACTIVATE ); TOOL_ACTION COMMON_ACTIONS::routerInlineDrag( "pcbnew.InteractiveRouter.InlineDrag", - AS_GLOBAL, 0, - "", "" ); + AS_GLOBAL, TOOL_ACTION::LegacyHotKey( HK_DRAG_TRACK_KEEP_SLOPE ), + _( "Drag track/via" ), _( "Drags tracks and vias without breaking connections" ), + drag_track_segment_xpm ); // Point editor TOOL_ACTION COMMON_ACTIONS::pointEditorAddCorner( "pcbnew.PointEditor.addCorner", diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index d2ea6dfa2a..be72d49646 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -135,7 +135,7 @@ bool EDIT_TOOL::invokeInlineRouter() if( !theRouter->PNSSettings().InlineDragEnabled() ) return false; - m_toolMgr->RunAction( COMMON_ACTIONS::routerInlineDrag, true, track ? track : via ); + m_toolMgr->RunAction( COMMON_ACTIONS::routerInlineDrag, true ); return true; }