From 456c02c800b5a0a77f88b00af75646d606818dd5 Mon Sep 17 00:00:00 2001 From: Tomasz Wlostowski Date: Mon, 15 Aug 2016 17:16:50 +0200 Subject: [PATCH] router: multiple fixes - fixed crash when trying to drag a locked via - prompt when the user attempts to drag a locked via/segment - removed remains of PICKED_ITEMS_LIST from the PNS_ROUTER class --- pcbnew/router/length_tuner_tool.cpp | 8 ++-- pcbnew/router/pns_dragger.cpp | 5 ++- pcbnew/router/pns_item.h | 9 ++++- pcbnew/router/pns_router.h | 19 ---------- pcbnew/router/pns_shove.cpp | 18 +++++++-- pcbnew/router/router_tool.cpp | 58 ++++++++++++++++++----------- 6 files changed, 65 insertions(+), 52 deletions(-) diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index 0317cfa4fb..06f571e838 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -229,10 +229,6 @@ void LENGTH_TUNER_TOOL::performTuning() } m_router->StopRouting(); - - // Save the recent changes in the undo buffer - m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); - m_router->ClearUndoBuffer(); m_frame->OnModify(); highlightNet( false ); @@ -280,9 +276,13 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->IsCancel() || evt->IsActivate() ) + { break; // Finish + } else if( evt->IsMotion() ) + { updateStartItem( *evt ); + } else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_StartTuning ) ) { updateStartItem( *evt ); diff --git a/pcbnew/router/pns_dragger.cpp b/pcbnew/router/pns_dragger.cpp index 65b2e23e0a..8eca5b1dd2 100644 --- a/pcbnew/router/pns_dragger.cpp +++ b/pcbnew/router/pns_dragger.cpp @@ -110,6 +110,8 @@ bool PNS_DRAGGER::Start( const VECTOR2I& aP, PNS_ITEM* aStartItem ) m_draggedItems.Clear(); m_currentMode = Settings().Mode(); + aStartItem->Unmark( MK_LOCKED ); + TRACE( 2, "StartDragging: item %p [kind %d]", aStartItem % aStartItem->Kind() ); switch( aStartItem->Kind() ) @@ -269,7 +271,8 @@ bool PNS_DRAGGER::dragShove( const VECTOR2I& aP ) if( ok ) { - m_draggedVia = newVia; + if( newVia ) + m_draggedVia = newVia; m_draggedItems.Clear(); } diff --git a/pcbnew/router/pns_item.h b/pcbnew/router/pns_item.h index a7511a7110..54b6f62d7f 100644 --- a/pcbnew/router/pns_item.h +++ b/pcbnew/router/pns_item.h @@ -300,9 +300,9 @@ public: m_marker = aMarker; } - virtual void Unmark () + virtual void Unmark (int aMarker = -1) { - m_marker = 0; + m_marker &= ~aMarker; } virtual int Marker() const @@ -330,6 +330,11 @@ public: return 0; } + bool IsLocked() const + { + return Marker() & MK_LOCKED; + } + private: bool collideSimple( const PNS_ITEM* aOther, int aClearance, bool aNeedMTV, VECTOR2I& aMTV, bool aDifferentNetsOnly ) const; diff --git a/pcbnew/router/pns_router.h b/pcbnew/router/pns_router.h index 4942ec3f89..d0e17974eb 100644 --- a/pcbnew/router/pns_router.h +++ b/pcbnew/router/pns_router.h @@ -27,7 +27,6 @@ #include #include -#include #include "pns_routing_settings.h" #include "pns_sizes_settings.h" @@ -177,23 +176,6 @@ public: void CommitRouting( PNS_NODE* aNode ); - /** - * Returns the last changes introduced by the router (since the last time ClearLastChanges() - * was called or a new track has been started). - */ - const PICKED_ITEMS_LIST& GetUndoBuffer() const - { - return m_undoBuffer; - } - - /** - * Clears the list of recent changes, saved to be stored in the undo buffer. - */ - void ClearUndoBuffer() - { - m_undoBuffer.ClearItemsList(); - } - /** * Applies stored settings. * @see Settings() @@ -289,7 +271,6 @@ private: PNS_ROUTING_SETTINGS m_settings; ///> Stores list of modified items in the current operation - PICKED_ITEMS_LIST m_undoBuffer; PNS_SIZES_SETTINGS m_sizes; PNS_ROUTER_MODE m_mode; diff --git a/pcbnew/router/pns_shove.cpp b/pcbnew/router/pns_shove.cpp index d0b18f6429..fd9669be37 100644 --- a/pcbnew/router/pns_shove.cpp +++ b/pcbnew/router/pns_shove.cpp @@ -591,6 +591,9 @@ PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::pushVia( PNS_VIA* aVia, const VECTOR2I& aForc return SH_INCOMPLETE; } + if ( aVia->IsLocked() ) + return SH_TRY_WALK; + if( jt->IsLocked() ) return SH_INCOMPLETE; @@ -1285,18 +1288,25 @@ PNS_SHOVE::SHOVE_STATUS PNS_SHOVE::ShoveDraggingVia( PNS_VIA* aVia, const VECTOR if( st == SH_OK || st == SH_HEAD_MODIFIED ) { + if( aNewVia ) + { + printf("setNewV %p", m_draggedVia); + *aNewVia = m_draggedVia; + } + pushSpringback( m_currentNode, m_draggedViaHeadSet, PNS_COST_ESTIMATOR(), m_affectedAreaSum ); } else { + if( aNewVia ) + { + *aNewVia = nullptr; + } + delete m_currentNode; m_currentNode = parent; } - if( aNewVia ) - { - *aNewVia = m_draggedVia; - } return st; } diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index b3eb80c8f1..316d3d78ee 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -487,6 +487,7 @@ bool ROUTER_TOOL::prepareInteractive() { int routingLayer = getStartLayer( m_startItem ); m_frame->SetActiveLayer( ToLAYER_ID( routingLayer ) ); + m_frame->UndoRedoBlock ( true ); // fixme: switch on invisible layer @@ -523,6 +524,8 @@ bool ROUTER_TOOL::prepareInteractive() m_endItem = NULL; m_endSnapPoint = m_startSnapPoint; + m_frame->UndoRedoBlock ( false ); + return true; } @@ -531,13 +534,7 @@ bool ROUTER_TOOL::finishInteractive() { m_router->StopRouting(); - // Save the recent changes in the undo buffer - if( m_router->GetUndoBuffer().GetCount() > 0 ) - { - m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); - m_router->ClearUndoBuffer(); - m_frame->OnModify(); - } + m_frame->OnModify(); m_ctls->SetAutoPan( false ); m_ctls->ForceCursorPosition( false ); @@ -677,7 +674,6 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) m_ctls->SetSnapping( true ); m_ctls->ShowCursor( true ); - frame->UndoRedoBlock( true ); m_startSnapPoint = getViewControls()->GetCursorPosition(); @@ -688,9 +684,17 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->IsCancel() || evt->IsActivate() ) + { break; // Finish + } + else if( evt->Action() == TA_UNDO_REDO ) + { + m_router->SyncWorld(); + } else if( evt->IsMotion() ) + { updateStartItem( *evt ); + } else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_NewTrack ) ) { updateStartItem( *evt ); @@ -711,7 +715,8 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) } else if (evt->IsAction ( &COMMON_ACTIONS::remove ) ) { deleteTraces( m_startItem, true ); - } else if (evt->IsAction ( &COMMON_ACTIONS::removeAlt ) ) + } + else if (evt->IsAction ( &COMMON_ACTIONS::removeAlt ) ) { deleteTraces( m_startItem, false ); } @@ -720,7 +725,6 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) } frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); - frame->UndoRedoBlock( false ); // Store routing settings till the next invocation m_savedSettings = m_router->Settings(); @@ -738,6 +742,12 @@ void ROUTER_TOOL::performDragging() PCB_EDIT_FRAME* frame = getEditFrame(); VIEW_CONTROLS* ctls = getViewControls(); + if ( m_startItem && m_startItem->IsLocked() ) + { + if ( !IsOK( m_frame, _( "The item is locked. Do you want to continue?" ) ) ) + return; + } + bool dragStarted = m_router->StartDragging( m_startSnapPoint, m_startItem ); if( !dragStarted ) @@ -748,6 +758,8 @@ void ROUTER_TOOL::performDragging() ctls->SetAutoPan( true ); + bool modified = false; + while( OPT_TOOL_EVENT evt = Wait() ) { ctls->ForceCursorPosition( false ); @@ -762,7 +774,10 @@ void ROUTER_TOOL::performDragging() else if( evt->IsClick( BUT_LEFT ) ) { if( m_router->FixRoute( m_endSnapPoint, m_endItem ) ) + { + modified = true; break; + } } handleCommonEvents( *evt ); @@ -771,10 +786,8 @@ void ROUTER_TOOL::performDragging() if( m_router->RoutingInProgress() ) m_router->StopRouting(); - // Save the recent changes in the undo buffer - frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); - m_router->ClearUndoBuffer(); - frame->OnModify(); + if( modified ) + frame->OnModify(); m_startItem = NULL; @@ -798,6 +811,12 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) 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 ); @@ -809,7 +828,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) ctls->SetAutoPan( true ); frame->UndoRedoBlock( true ); - bool saveUndoBuffer = true; + bool modified = false; while( OPT_TOOL_EVENT evt = Wait() ) { @@ -817,7 +836,6 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) if( evt->IsCancel() ) { - saveUndoBuffer = false; break; } else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) @@ -826,7 +844,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) } else if( evt->IsMouseUp( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) ) { - saveUndoBuffer = m_router->FixRoute( p0, NULL ); + modified = m_router->FixRoute( p0, NULL ); break; } } @@ -834,12 +852,8 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) if( m_router->RoutingInProgress() ) m_router->StopRouting(); - if( saveUndoBuffer ) - { - frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); - m_router->ClearUndoBuffer(); + if( modified ) frame->OnModify(); - } ctls->SetAutoPan( false ); ctls->ShowCursor( false );