Fixed failing undo while routing.

This commit is contained in:
Maciej Suminski 2015-08-04 23:08:13 +02:00
parent b6f61ff676
commit d624115f35
8 changed files with 62 additions and 75 deletions

View File

@ -343,7 +343,6 @@ PICKED_ITEMS_LIST* UNDO_REDO_CONTAINER::PopCommand()
m_CommandsList.pop_back();
return item;
}
return NULL;
}

View File

@ -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;

View File

@ -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();

View File

@ -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)

View File

@ -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();

View File

@ -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<TUNER_TOOL_MENU> 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();

View File

@ -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<PCB_EDIT_FRAME>();
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;
}

View File

@ -56,8 +56,8 @@ private:
void switchLayerOnViaPlacement();
bool onViaCommand( VIATYPE_T aType );
bool prepareInteractive( );
bool finishInteractive( bool aSaveUndoBuffer );
bool prepareInteractive();
bool finishInteractive();
};
#endif