COMMIT: Added an interface to store items that already have a copy created.
This commit is contained in:
parent
0223425d30
commit
b8350f037b
|
@ -23,8 +23,7 @@
|
|||
*/
|
||||
|
||||
#include <commit.h>
|
||||
#include <class_undoredo_container.h>
|
||||
|
||||
#include <base_struct.h>
|
||||
|
||||
COMMIT::COMMIT()
|
||||
{
|
||||
|
@ -45,30 +44,17 @@ COMMIT::~COMMIT()
|
|||
}
|
||||
|
||||
|
||||
void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE type, bool saveCopy )
|
||||
{
|
||||
COMMIT_LINE ent;
|
||||
|
||||
ent.m_item = aItem;
|
||||
ent.m_type = type;
|
||||
ent.m_copy = saveCopy ? (EDA_ITEM*) aItem->Clone() : NULL;
|
||||
|
||||
m_changedItems.insert( aItem );
|
||||
m_changes.push_back( ent );
|
||||
}
|
||||
|
||||
|
||||
COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType )
|
||||
{
|
||||
switch( aChangeType )
|
||||
{
|
||||
case CHT_ADD:
|
||||
assert( m_changedItems.find( aItem ) == m_changedItems.end() );
|
||||
makeEntry( aItem, CHT_ADD, false );
|
||||
makeEntry( aItem, CHT_ADD );
|
||||
return *this;
|
||||
|
||||
case CHT_REMOVE:
|
||||
makeEntry( aItem, CHT_REMOVE, false );
|
||||
makeEntry( aItem, CHT_REMOVE );
|
||||
return *this;
|
||||
|
||||
case CHT_MODIFY:
|
||||
|
@ -78,13 +64,29 @@ COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType )
|
|||
if( m_changedItems.find( parent ) != m_changedItems.end() )
|
||||
return *this; // item already modifed once
|
||||
|
||||
makeEntry( parent, CHT_MODIFY, true );
|
||||
makeEntry( parent, CHT_MODIFY, parent->Clone() );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
default:
|
||||
assert( false );
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
COMMIT& COMMIT::Stage( EDA_ITEM* aItem, EDA_ITEM* aCopy )
|
||||
{
|
||||
EDA_ITEM* parent = parentObject( aItem );
|
||||
|
||||
if( m_changedItems.find( parent ) != m_changedItems.end() )
|
||||
return *this; // item already modifed once
|
||||
|
||||
makeEntry( parent, CHT_MODIFY, aCopy );
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
|
@ -99,9 +101,75 @@ COMMIT& COMMIT::Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeTyp
|
|||
}
|
||||
|
||||
|
||||
void COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType )
|
||||
COMMIT& COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag )
|
||||
{
|
||||
for( unsigned int i = 0; i < aItems.GetCount(); i++ )
|
||||
Stage( aItems.GetPickedItem( i ), aChangeType );
|
||||
{
|
||||
UNDO_REDO_T change_type = aItems.GetPickedItemStatus( i );
|
||||
EDA_ITEM* item = aItems.GetPickedItem( i );
|
||||
EDA_ITEM* copy = NULL;
|
||||
|
||||
if( change_type == UR_UNSPECIFIED )
|
||||
change_type = aItems.m_Status;
|
||||
|
||||
if( change_type == UR_UNSPECIFIED )
|
||||
change_type = aModFlag;
|
||||
|
||||
if( ( copy = aItems.GetPickedItemLink( i ) ) )
|
||||
{
|
||||
assert( change_type == UR_CHANGED );
|
||||
|
||||
// There was already a copy created, so use it
|
||||
Stage( item, copy );
|
||||
}
|
||||
else
|
||||
{
|
||||
Stage( item, convert( change_type ) );
|
||||
}
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void COMMIT::makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy )
|
||||
{
|
||||
// Expect an item copy if it is going to be modified
|
||||
assert( !!aCopy == ( aType == CHT_MODIFY ) );
|
||||
|
||||
COMMIT_LINE ent;
|
||||
|
||||
ent.m_item = aItem;
|
||||
ent.m_type = aType;
|
||||
ent.m_copy = aCopy;
|
||||
|
||||
m_changedItems.insert( aItem );
|
||||
m_changes.push_back( ent );
|
||||
}
|
||||
|
||||
|
||||
COMMIT::CHANGE_TYPE COMMIT::convert( UNDO_REDO_T aType ) const
|
||||
{
|
||||
switch( aType )
|
||||
{
|
||||
case UR_NEW:
|
||||
return CHT_ADD;
|
||||
|
||||
case UR_DELETED:
|
||||
return CHT_REMOVE;
|
||||
|
||||
default:
|
||||
assert( false );
|
||||
// fall through
|
||||
|
||||
case UR_CHANGED:
|
||||
case UR_MOVED:
|
||||
case UR_MIRRORED_X:
|
||||
case UR_MIRRORED_Y:
|
||||
case UR_ROTATED:
|
||||
case UR_ROTATED_CLOCKWISE:
|
||||
case UR_FLIPPED:
|
||||
return CHT_MODIFY;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -27,10 +27,10 @@
|
|||
|
||||
#include <set>
|
||||
#include <vector>
|
||||
#include <base_struct.h>
|
||||
|
||||
#include <class_undoredo_container.h>
|
||||
|
||||
class PICKED_ITEMS_LIST;
|
||||
class EDA_ITEM;
|
||||
|
||||
/**
|
||||
* Class COMMIT
|
||||
|
@ -74,10 +74,14 @@ public:
|
|||
}
|
||||
|
||||
///> Adds a change of the item aItem of type aChangeType to the change list.
|
||||
virtual COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType );
|
||||
COMMIT& Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType );
|
||||
|
||||
///> Adds a change of an item with its copy done before the change has occurred.
|
||||
COMMIT& Stage( EDA_ITEM* aItem, EDA_ITEM* aCopy );
|
||||
|
||||
void Stage( const PICKED_ITEMS_LIST& aItems, CHANGE_TYPE aChangeType );
|
||||
COMMIT& Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType );
|
||||
|
||||
COMMIT& Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag = UR_UNSPECIFIED );
|
||||
|
||||
///> Executes the changes.
|
||||
virtual void Push( const wxString& aMessage ) = 0;
|
||||
|
@ -93,9 +97,12 @@ protected:
|
|||
CHANGE_TYPE m_type;
|
||||
};
|
||||
|
||||
virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE type, bool saveCopy );
|
||||
virtual void makeEntry( EDA_ITEM* aItem, CHANGE_TYPE aType, EDA_ITEM* aCopy = NULL );
|
||||
|
||||
virtual EDA_ITEM* parentObject( EDA_ITEM* aItem ) const = 0;
|
||||
|
||||
CHANGE_TYPE convert( UNDO_REDO_T aType ) const;
|
||||
|
||||
bool m_committed;
|
||||
|
||||
std::set<EDA_ITEM*> m_changedItems;
|
||||
|
|
Loading…
Reference in New Issue