Better way of handling changes in EDIT_TOOL (GAL).

This commit is contained in:
Maciej Suminski 2015-07-31 17:40:19 +02:00
parent 27a2098e0a
commit e3cbfb0609
2 changed files with 38 additions and 10 deletions

View File

@ -391,22 +391,23 @@ int EDIT_TOOL::Properties( const TOOL_EVENT& aEvent )
STATUS_FLAGS flags = item->GetFlags();
item->ClearFlags();
// It is necessary to determine if anything has changed
unsigned int oldSize = undoList.size();
// It is necessary to determine if anything has changed, so store the current undo save point
PICKED_ITEMS_LIST* undoSavePoint = undoList.empty() ? NULL : undoList.back();
// Display properties dialog provided by the legacy canvas frame
editFrame->OnEditItemRequest( NULL, item );
for( unsigned int i = oldSize; i < undoList.size(); ++i )
processChanges( undoList[i] );
if( oldSize != undoList.size() ) // Something has changed
if( !undoList.empty() && undoList.back() != undoSavePoint ) // Undo buffer has changed
{
item->ViewUpdate();
// Process changes stored after undoSavePoint
processUndoBuffer( undoSavePoint );
// Update the modified item
item->ViewUpdate();
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();
ratsnest->Recalculate();
// TODO OBSERVER! I miss you so much..
m_toolMgr->RunAction( COMMON_ACTIONS::pointEditorUpdate, true );
}
@ -1039,8 +1040,31 @@ bool EDIT_TOOL::hoverSelection( const SELECTION& aSelection, bool aSanitize )
return !aSelection.Empty();
}
void EDIT_TOOL::processUndoBuffer( const PICKED_ITEMS_LIST* aLastChange )
{
PCB_BASE_EDIT_FRAME* editFrame = getEditFrame<PCB_BASE_EDIT_FRAME>();
const std::vector<PICKED_ITEMS_LIST*>& undoList = editFrame->GetScreen()->m_UndoList.m_CommandsList;
bool process = false;
void EDIT_TOOL::processChanges( const PICKED_ITEMS_LIST* aList )
BOOST_FOREACH( const PICKED_ITEMS_LIST* list, undoList )
{
if( process )
processPickedList( list );
else if( list == aLastChange )
process = true; // Start processing starting with the next undo save point
}
// If we could not find the requested save point in the current undo list
// then the undo list must have been completely altered, so process everything
if( !process )
{
BOOST_FOREACH( const PICKED_ITEMS_LIST* list, undoList )
processPickedList( list );
}
}
void EDIT_TOOL::processPickedList( const PICKED_ITEMS_LIST* aList )
{
KIGFX::VIEW* view = getView();
RN_DATA* ratsnest = getModel<BOARD>()->GetRatsnest();

View File

@ -178,8 +178,12 @@ private:
///> the cursor or displays a disambiguation menu if there are multpile items.
bool hoverSelection( const SELECTION& aSelection, bool aSanitize = true );
///> Updates view with the changes in the list.
void processChanges( const PICKED_ITEMS_LIST* aList );
///> Processes the current undo buffer since the last change. If the last change does not occur
///> in the current buffer, then the whole list is processed.
void processUndoBuffer( const PICKED_ITEMS_LIST* aLastChange );
///> Updates items stored in the list.
void processPickedList( const PICKED_ITEMS_LIST* aList );
/**
* Increments the undo inhibit counter. This will indicate that tools