diff --git a/common/class_undoredo_container.cpp b/common/class_undoredo_container.cpp index 2dd862ef01..9c71d1ad2d 100644 --- a/common/class_undoredo_container.cpp +++ b/common/class_undoredo_container.cpp @@ -343,7 +343,6 @@ PICKED_ITEMS_LIST* UNDO_REDO_CONTAINER::PopCommand() m_CommandsList.pop_back(); return item; } + return NULL; } - - diff --git a/pcbnew/board_undo_redo.cpp b/pcbnew/board_undo_redo.cpp index 8e0a6290c9..dd221f74d5 100644 --- a/pcbnew/board_undo_redo.cpp +++ b/pcbnew/board_undo_redo.cpp @@ -635,6 +635,9 @@ void PCB_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList, bool aRed void PCB_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) { + if( UndoRedoBlocked() ) + return; + if( GetScreen()->GetUndoCommandCount() <= 0 ) return; @@ -644,6 +647,7 @@ void PCB_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) /* Get the old list */ PICKED_ITEMS_LIST* List = GetScreen()->PopCommandFromUndoList(); + /* Undo the command */ PutDataInPreviousState( List, false ); @@ -658,6 +662,9 @@ void PCB_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) void PCB_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent ) { + if( UndoRedoBlocked() ) + return; + if( GetScreen()->GetRedoCommandCount() == 0 ) return; diff --git a/pcbnew/modedit_undo_redo.cpp b/pcbnew/modedit_undo_redo.cpp index 2aa62c2134..ac72fd672f 100644 --- a/pcbnew/modedit_undo_redo.cpp +++ b/pcbnew/modedit_undo_redo.cpp @@ -129,6 +129,9 @@ void FOOTPRINT_EDIT_FRAME::RestoreCopyFromRedoList( wxCommandEvent& aEvent ) void FOOTPRINT_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) { + if( UndoRedoBlocked() ) + return; + if( GetScreen()->GetUndoCommandCount() <= 0 ) return; @@ -136,6 +139,9 @@ void FOOTPRINT_EDIT_FRAME::RestoreCopyFromUndoList( wxCommandEvent& aEvent ) TOOL_EVENT event( TC_MESSAGE, TA_UNDO_REDO, AS_GLOBAL ); m_toolManager->ProcessEvent( event ); + if( UndoRedoBlocked() ) + return; + // Save current module state in redo list PICKED_ITEMS_LIST* lastcmd = new PICKED_ITEMS_LIST(); MODULE* module = GetBoard()->m_Modules.PopFront(); diff --git a/pcbnew/pcb_base_edit_frame.h b/pcbnew/pcb_base_edit_frame.h index 4ad0de4385..3bb6cdec4e 100644 --- a/pcbnew/pcb_base_edit_frame.h +++ b/pcbnew/pcb_base_edit_frame.h @@ -37,7 +37,7 @@ public: const wxString& aTitle, const wxPoint& aPos, const wxSize& aSize, long aStyle, const wxString& aFrameName ) : PCB_BASE_FRAME( aKiway, aParent, aFrameType, aTitle, aPos, aSize, aStyle, aFrameName ), - m_rotationAngle( 900 ) + m_rotationAngle( 900 ), m_undoRedoBlocked( false ) {} virtual ~PCB_BASE_EDIT_FRAME() {}; @@ -71,10 +71,31 @@ public: bool PostCommandMenuEvent( int evt_type ); + /** + * Function UndoRedoBlocked + * Checks if the undo and redo operations are currently blocked. + */ + bool UndoRedoBlocked() const + { + return m_undoRedoBlocked; + } + + /** + * Function UndoRedoBlock + * Enables/disable undo and redo operations. + */ + void UndoRedoBlock( bool aBlock = true ) + { + m_undoRedoBlocked = aBlock; + } + protected: /// User defined rotation angle (in tenths of a degree). int m_rotationAngle; + /// Is undo/redo operation currently blocked? + bool m_undoRedoBlocked; + /** * Function createArray * Create an array of the selected item (invokes the dialogue) diff --git a/pcbnew/pcbframe.cpp b/pcbnew/pcbframe.cpp index 8107d30c9b..33faef8e6c 100644 --- a/pcbnew/pcbframe.cpp +++ b/pcbnew/pcbframe.cpp @@ -679,6 +679,9 @@ void PCB_EDIT_FRAME::UseGalCanvas( bool aEnable ) // Redirect all events to the legacy canvas GetGalCanvas()->SetEventDispatcher( NULL ); + + // No matter what, reenable undo/redo + UndoRedoBlock( false ); } enableGALSpecificMenus(); diff --git a/pcbnew/router/length_tuner_tool.cpp b/pcbnew/router/length_tuner_tool.cpp index 31877b997a..cc6bfd74bd 100644 --- a/pcbnew/router/length_tuner_tool.cpp +++ b/pcbnew/router/length_tuner_tool.cpp @@ -155,8 +155,6 @@ void LENGTH_TUNER_TOOL::updateStatusPopup( PNS_TUNE_STATUS_POPUP& aPopup ) void LENGTH_TUNER_TOOL::performTuning() { - bool saveUndoBuffer = true; - if( m_startItem ) { m_frame->SetActiveLayer( ToLAYER_ID ( m_startItem->Layers().Start() ) ); @@ -187,16 +185,10 @@ void LENGTH_TUNER_TOOL::performTuning() m_router->Move( end, NULL ); updateStatusPopup( statusPopup ); - while( OPT_TOOL_EVENT evt = Wait() ) { if( evt->IsCancel() || evt->IsActivate() ) break; - else if( evt->Action() == TA_UNDO_REDO ) - { - saveUndoBuffer = false; - break; - } else if( evt->IsMotion() ) { end = evt->Position(); @@ -239,21 +231,11 @@ void LENGTH_TUNER_TOOL::performTuning() m_router->StopRouting(); - if( saveUndoBuffer ) - { - // Save the recent changes in the undo buffer - m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); - m_router->ClearUndoBuffer(); - m_frame->OnModify(); - } - else - { - // It was interrupted by TA_UNDO_REDO event, so we have to sync the world now - m_needsSync = true; - } + // Save the recent changes in the undo buffer + m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); + m_router->ClearUndoBuffer(); + m_frame->OnModify(); - m_ctls->SetAutoPan( false ); - m_ctls->ForceCursorPosition( false ); highlightNet( false ); } @@ -290,6 +272,7 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) m_ctls->SetSnapping( true ); m_ctls->ShowCursor( true ); + m_frame->UndoRedoBlock( true ); std::auto_ptr ctxMenu( new TUNER_TOOL_MENU( m_board ) ); SetContextMenu( ctxMenu.get() ); @@ -306,23 +289,19 @@ int LENGTH_TUNER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) if( evt->IsCancel() || evt->IsActivate() ) break; // Finish - else if( evt->Action() == TA_UNDO_REDO ) - m_needsSync = true; else if( evt->IsMotion() ) updateStartItem( *evt ); else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_StartTuning ) ) { updateStartItem( *evt ); - performTuning( ); + performTuning(); } handleCommonEvents( *evt ); } - // Restore the default settings - m_ctls->SetAutoPan( false ); - m_ctls->ShowCursor( false ); m_frame->SetToolID( ID_NO_TOOL_SELECTED, wxCURSOR_DEFAULT, wxEmptyString ); + m_frame->UndoRedoBlock( false ); // Store routing settings till the next invocation m_savedSettings = m_router->Settings(); diff --git a/pcbnew/router/router_tool.cpp b/pcbnew/router/router_tool.cpp index 2162fa5eaf..dc32cb95b8 100644 --- a/pcbnew/router/router_tool.cpp +++ b/pcbnew/router/router_tool.cpp @@ -471,22 +471,14 @@ bool ROUTER_TOOL::prepareInteractive() } -bool ROUTER_TOOL::finishInteractive( bool aSaveUndoBuffer ) +bool ROUTER_TOOL::finishInteractive() { m_router->StopRouting(); - if( aSaveUndoBuffer ) - { - // Save the recent changes in the undo buffer - m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); - m_router->ClearUndoBuffer(); - m_frame->OnModify(); - } - else - { - // It was interrupted by TA_UNDO_REDO event, so we have to sync the world now - m_needsSync = true; - } + // Save the recent changes in the undo buffer + m_frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); + m_router->ClearUndoBuffer(); + m_frame->OnModify(); m_ctls->SetAutoPan( false ); m_ctls->ForceCursorPosition( false ); @@ -498,8 +490,6 @@ bool ROUTER_TOOL::finishInteractive( bool aSaveUndoBuffer ) void ROUTER_TOOL::performRouting() { - bool saveUndoBuffer = true; - if( !prepareInteractive() ) return; @@ -507,11 +497,6 @@ void ROUTER_TOOL::performRouting() { if( evt->IsCancel() || evt->IsActivate() ) break; - else if( evt->Action() == TA_UNDO_REDO ) - { - saveUndoBuffer = false; - break; - } else if( evt->IsMotion() ) { updateEndItem( *evt ); @@ -565,7 +550,7 @@ void ROUTER_TOOL::performRouting() handleCommonEvents( *evt ); } - finishInteractive( saveUndoBuffer ); + finishInteractive(); } @@ -628,6 +613,7 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) m_ctls->SetSnapping( true ); m_ctls->ShowCursor( true ); + frame->UndoRedoBlock( true ); m_startSnapPoint = getViewControls()->GetCursorPosition(); @@ -646,8 +632,6 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) if( evt->IsCancel() || evt->IsActivate() ) break; // Finish - else if( evt->Action() == TA_UNDO_REDO ) - m_needsSync = true; else if( evt->IsMotion() ) updateStartItem( *evt ); else if( evt->IsClick( BUT_LEFT ) || evt->IsAction( &ACT_NewTrack ) ) @@ -669,6 +653,7 @@ 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(); @@ -681,7 +666,6 @@ int ROUTER_TOOL::mainLoop( PNS_ROUTER_MODE aMode ) void ROUTER_TOOL::performDragging() { PCB_EDIT_FRAME* frame = getEditFrame(); - bool saveUndoBuffer = true; VIEW_CONTROLS* ctls = getViewControls(); bool dragStarted = m_router->StartDragging( m_startSnapPoint, m_startItem ); @@ -699,11 +683,6 @@ void ROUTER_TOOL::performDragging() { if( evt->IsCancel() || evt->IsActivate() ) break; - else if( evt->Action() == TA_UNDO_REDO ) - { - saveUndoBuffer = false; - break; - } else if( evt->IsMotion() ) { updateEndItem( *evt ); @@ -721,18 +700,10 @@ void ROUTER_TOOL::performDragging() if( m_router->RoutingInProgress() ) m_router->StopRouting(); - if( saveUndoBuffer ) - { - // Save the recent changes in the undo buffer - frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); - m_router->ClearUndoBuffer(); - frame->OnModify(); - } - else - { - // It was interrupted by TA_UNDO_REDO event, so we have to sync the world now - m_needsSync = true; - } + // Save the recent changes in the undo buffer + frame->SaveCopyInUndoList( m_router->GetUndoBuffer(), UR_UNSPECIFIED ); + m_router->ClearUndoBuffer(); + frame->OnModify(); m_startItem = NULL; @@ -766,6 +737,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) ctls->ForceCursorPosition( false ); ctls->SetAutoPan( true ); + frame->UndoRedoBlock( true ); bool saveUndoBuffer = true; @@ -778,7 +750,6 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) saveUndoBuffer = false; break; } - else if( evt->IsMotion() || evt->IsDrag( BUT_LEFT ) ) { m_router->Move( p0, NULL ); @@ -802,6 +773,7 @@ int ROUTER_TOOL::InlineDrag( const TOOL_EVENT& aEvent ) ctls->SetAutoPan( false ); ctls->ShowCursor( false ); + frame->UndoRedoBlock( false ); return 0; } diff --git a/pcbnew/router/router_tool.h b/pcbnew/router/router_tool.h index 1dee8c1a31..08f2f84827 100644 --- a/pcbnew/router/router_tool.h +++ b/pcbnew/router/router_tool.h @@ -56,8 +56,8 @@ private: void switchLayerOnViaPlacement(); bool onViaCommand( VIATYPE_T aType ); - bool prepareInteractive( ); - bool finishInteractive( bool aSaveUndoBuffer ); + bool prepareInteractive(); + bool finishInteractive(); }; #endif