int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) { const BOARD_CONNECTED_ITEM* item = aEvent.Parameter<const BOARD_CONNECTED_ITEM*>(); PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>(); VIEW_CONTROLS* ctls = getViewControls(); m_toolMgr->RunAction( COMMON_ACTIONS::selectionClear, true ); Activate(); m_router->SyncWorld(); m_startItem = m_router->GetWorld()->FindItemByParent( item ); if( m_startItem && m_startItem->IsLocked() ) { if( !IsOK( m_frame, _( "The item is locked. Do you want to continue?" ) ) ) return false; } VECTOR2I p0 = ctls->GetCursorPosition(); bool dragStarted = m_router->StartDragging( p0, m_startItem ); if( !dragStarted ) return 0; ctls->ForceCursorPosition( false ); ctls->SetAutoPan( true ); frame->UndoRedoBlock( true ); while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->IsCancel() ) { break; } else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) { updateEndItem( *evt ); m_router->Move( m_endSnapPoint, m_endItem ); } else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) { updateEndItem( *evt ); m_router->FixRoute( m_endSnapPoint, m_endItem ); break; } } if( m_router->RoutingInProgress() ) m_router->StopRouting(); ctls->SetAutoPan( false ); ctls->ShowCursor( false ); frame->UndoRedoBlock( false ); return 0; }
int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) { const BOARD_CONNECTED_ITEM *item = aEvent.Parameter<const BOARD_CONNECTED_ITEM*>(); PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>(); 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 ); frame->UndoRedoBlock( 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( m_router->RoutingInProgress() ) m_router->StopRouting(); if( saveUndoBuffer ) { frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); m_router->ClearUndoBuffer(); frame->OnModify(); } ctls->SetAutoPan( false ); ctls->ShowCursor( false ); frame->UndoRedoBlock( false ); return 0; }
int ROUTER_TOOL::mainLoop( PNS::ROUTER_MODE aMode ) { PCB_EDIT_FRAME* frame = getEditFrame<PCB_EDIT_FRAME>(); // Deselect all items m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true ); Activate(); m_router->SetMode( aMode ); VIEW_CONTROLS* ctls = getViewControls(); ctls->ShowCursor( true ); ctls->ForceCursorPosition( false ); m_startSnapPoint = ctls->GetCursorPosition(); std::unique_ptr<ROUTER_TOOL_MENU> ctxMenu( new ROUTER_TOOL_MENU( *frame, aMode ) ); SetContextMenu( ctxMenu.get() ); // Main loop: keep receiving events while( OPT_TOOL_EVENT evt = Wait() ) { if( TOOL_EVT_UTILS::IsCancelInteractive( *evt ) ) { break; // Finish } else if( evt->Action() == TA_UNDO_REDO_PRE ) { m_router->ClearWorld(); } else if( evt->Action() == TA_UNDO_REDO_POST || evt->Action() == TA_MODEL_CHANGE ) { m_router->SyncWorld(); } else if( evt->IsMotion() ) { updateStartItem( *evt ); } else if( evt->IsAction( &PCB_ACTIONS::dragFreeAngle ) ) { updateStartItem( *evt, true ); performDragging( PNS::DM_ANY | PNS::DM_FREE_ANGLE ); } else if( evt->IsAction( &PCB_ACTIONS::drag45Degree ) ) { updateStartItem( *evt, true ); performDragging( PNS::DM_ANY ); } else if( evt->IsAction( &PCB_ACTIONS::breakTrack ) ) { updateStartItem( *evt, true ); breakTrack( ); } else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_NewTrack ) ) { updateStartItem( *evt ); if( evt->Modifier( MD_CTRL ) ) performDragging( PNS::DM_ANY ); else performRouting(); } else if( evt->IsAction( &ACT_PlaceThroughVia ) ) { m_toolMgr->RunAction( PCB_ACTIONS::layerToggle, true ); } } frame->SetNoToolSelected(); SetContextMenu( nullptr ); // Store routing settings till the next invocation m_savedSettings = m_router->Settings(); m_savedSizes = m_router->Sizes(); return 0; }