diff --git a/pcbnew/router/pns_node.cpp b/pcbnew/router/pns_node.cpp index 831dc79cd2..2c5f2d41a5 100644 --- a/pcbnew/router/pns_node.cpp +++ b/pcbnew/router/pns_node.cpp @@ -1241,3 +1241,14 @@ void PNS_NODE::SetCollisionFilter( PNS_COLLISION_FILTER* aFilter ) { m_collisionFilter = aFilter; } + +PNS_ITEM *PNS_NODE::FindItemByParent ( const BOARD_CONNECTED_ITEM *aParent ) +{ + PNS_INDEX::NET_ITEMS_LIST* l_cur = m_index->GetItemsForNet( aParent->GetNetCode() ); + + BOOST_FOREACH( PNS_ITEM*item, *l_cur ) + if ( item->Parent() == aParent ) + return item; + + return NULL; +} \ No newline at end of file diff --git a/pcbnew/router/pns_node.h b/pcbnew/router/pns_node.h index 915d0b044d..3ef4206efd 100644 --- a/pcbnew/router/pns_node.h +++ b/pcbnew/router/pns_node.h @@ -373,6 +373,8 @@ public: int RemoveByMarker( int aMarker ); void SetCollisionFilter( PNS_COLLISION_FILTER* aFilter ); + PNS_ITEM *FindItemByParent ( const BOARD_CONNECTED_ITEM *aParent ); + private: struct OBSTACLE_VISITOR; typedef boost::unordered_multimap JOINT_MAP; diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index b0e1467a14..8c0032a29f 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -279,7 +279,7 @@ void ROUTER_TOOL::Reset( RESET_REASON aReason ) Go( &ROUTER_TOOL::RouteDiffPair, COMMON_ACTIONS::routerActivateDiffPair.MakeEvent() ); Go( &ROUTER_TOOL::DpDimensionsDialog, COMMON_ACTIONS::routerActivateDpDimensionsDialog.MakeEvent() ); Go( &ROUTER_TOOL::SettingsDialog, COMMON_ACTIONS::routerActivateSettingsDialog.MakeEvent() ); - + Go( &ROUTER_TOOL::InlineDrag, COMMON_ACTIONS::routerInlineDrag.MakeEvent() ); } @@ -770,6 +770,62 @@ 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(); + + m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); + + Activate(); + + m_router->SyncWorld(); + m_router->SetView( getView() ); + + m_startItem = m_router->GetWorld()->FindItemByParent( item ); + + VECTOR2I p0 = ctls->GetCursorPosition(); + + bool dragStarted = m_router->StartDragging( p0, m_startItem ); + + if( !dragStarted ) + return 0; + + ctls->ForceCursorPosition( false ); + ctls->SetAutoPan( true ); + + bool saveUndoBuffer = true; + + while( OPT_TOOL_EVENT evt = Wait() ) + { + p0 = ctls->GetCursorPosition(); + + if( evt->IsCancel() ) + { + saveUndoBuffer = false; + break; + } + + else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) + { + m_router->Move( p0, NULL ); + } + else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) + { + saveUndoBuffer = m_router->FixRoute( p0, NULL ); + break; + } + } + + if(saveUndoBuffer) + { + frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); + m_router->ClearUndoBuffer(); + frame->OnModify(); + } + + ctls->SetAutoPan( false ); + ctls->ForceCursorPosition( false ); + return 0; } diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 5ed0fd3d17..1b03be6b0e 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -105,10 +105,12 @@ bool EDIT_TOOL::invokeInlineRouter() TRACK* track = uniqueSelected(); VIA* via = uniqueSelected(); + if ( !GetSettings().Get("DragInvokesRouter", false ) ) + return false; + if( track || via ) { - //printf("Calling interactive drag\n"); - m_toolMgr->RunAction( COMMON_ACTIONS::routerInlineDrag, true ); + m_toolMgr->RunAction( COMMON_ACTIONS::routerInlineDrag, true, track ? track : via ); return true; } @@ -243,57 +245,60 @@ int EDIT_TOOL::Main( const TOOL_EVENT& aEvent ) } else // Prepare to start dragging { - m_selectionTool->SanitizeSelection(); - - if( selection.Empty() ) - break; - - // deal with locked items (override lock or abort the operation) - SELECTION_LOCK_FLAGS lockFlags = m_selectionTool->CheckLock(); - - if( lockFlags == SELECTION_LOCKED ) - break; - else if( lockFlags == SELECTION_LOCK_OVERRIDE ) - lockOverride = true; - - // Save items, so changes can be undone - if( !isUndoInhibited() ) + if( !isDragAndDrop || !invokeInlineRouter() ) { - editFrame->OnModify(); - editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + m_selectionTool->SanitizeSelection(); + + if( selection.Empty() ) + break; + + // deal with locked items (override lock or abort the operation) + SELECTION_LOCK_FLAGS lockFlags = m_selectionTool->CheckLock(); + + if( lockFlags == SELECTION_LOCKED ) + break; + else if( lockFlags == SELECTION_LOCK_OVERRIDE ) + lockOverride = true; + + // Save items, so changes can be undone + if( !isUndoInhibited() ) + { + editFrame->OnModify(); + editFrame->SaveCopyInUndoList( selection.items, UR_CHANGED ); + } + + VECTOR2I origin; + + if( evt->IsDrag( BUT_LEFT ) ) + mousePos = evt->DragOrigin(); + + // origin = grid.Align ( evt->DragOrigin() ); + //else + origin = grid.Align( mousePos ); + + if( selection.Size() == 1 ) + { + // Set the current cursor position to the first dragged item origin, so the + // movement vector could be computed later + m_cursor = grid.BestDragOrigin( mousePos, selection.Item( 0 ) ); + getViewControls()->ForceCursorPosition( true, m_cursor ); + grid.SetAuxAxes( true, m_cursor ); + + VECTOR2I o = VECTOR2I( selection.Item( 0 )->GetPosition() ); + m_offset.x = o.x - m_cursor.x; + m_offset.y = o.y - m_cursor.y; + } + else + { + m_offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - + wxPoint( origin.x, origin.y ); + getViewControls()->ForceCursorPosition( true, origin ); + } + + controls->SetAutoPan( true ); + m_dragging = true; + incUndoInhibit(); } - - VECTOR2I origin; - - if( evt->IsDrag( BUT_LEFT ) ) - mousePos = evt->DragOrigin(); - - // origin = grid.Align ( evt->DragOrigin() ); - //else - origin = grid.Align( mousePos ); - - if( selection.Size() == 1 ) - { - // Set the current cursor position to the first dragged item origin, so the - // movement vector could be computed later - m_cursor = grid.BestDragOrigin( mousePos, selection.Item( 0 ) ); - getViewControls()->ForceCursorPosition( true, m_cursor ); - grid.SetAuxAxes( true, m_cursor ); - - VECTOR2I o = VECTOR2I( selection.Item( 0 )->GetPosition() ); - m_offset.x = o.x - m_cursor.x; - m_offset.y = o.y - m_cursor.y; - } - else - { - m_offset = static_cast( selection.items.GetPickedItem( 0 ) )->GetPosition() - - wxPoint( origin.x, origin.y ); - getViewControls()->ForceCursorPosition( true, origin ); - } - - controls->SetAutoPan( true ); - m_dragging = true; - incUndoInhibit(); } selection.group->ViewUpdate( KIGFX::VIEW_ITEM::GEOMETRY );