2016-05-10 15:57:21 +00:00
|
|
|
/*
|
|
|
|
* This program source code file is part of KiCad, a free EDA CAD application.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 CERN
|
|
|
|
* @author Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
|
2016-09-02 14:38:40 +00:00
|
|
|
* @author Maciej Suminski <maciej.suminski@cern.ch>
|
2016-05-10 15:57:21 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, you may find one here:
|
|
|
|
* http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
|
|
|
* or you may search the http://www.gnu.org website for the version 2 license,
|
|
|
|
* or you may write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <commit.h>
|
2016-06-09 12:28:54 +00:00
|
|
|
#include <base_struct.h>
|
2016-05-10 15:57:21 +00:00
|
|
|
|
|
|
|
COMMIT::COMMIT()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COMMIT::~COMMIT()
|
|
|
|
{
|
2016-06-15 08:15:10 +00:00
|
|
|
for( COMMIT_LINE& ent : m_changes )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2016-06-15 08:15:10 +00:00
|
|
|
if( ent.m_copy )
|
|
|
|
delete ent.m_copy;
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
COMMIT& COMMIT::Stage( EDA_ITEM* aItem, CHANGE_TYPE aChangeType )
|
|
|
|
{
|
2016-08-18 14:28:04 +00:00
|
|
|
assert( aChangeType != ( CHT_MODIFY | CHT_DONE ) ); // CHT_MODIFY and CHT_DONE are not compatible
|
|
|
|
|
|
|
|
int flag = aChangeType & CHT_FLAGS;
|
|
|
|
|
|
|
|
switch( aChangeType & CHT_TYPE )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
|
|
|
case CHT_ADD:
|
|
|
|
assert( m_changedItems.find( aItem ) == m_changedItems.end() );
|
2016-08-18 14:28:04 +00:00
|
|
|
makeEntry( aItem, CHT_ADD | flag );
|
2016-05-10 15:57:21 +00:00
|
|
|
return *this;
|
|
|
|
|
|
|
|
case CHT_REMOVE:
|
2016-08-18 14:28:04 +00:00
|
|
|
makeEntry( aItem, CHT_REMOVE | flag );
|
2016-05-10 15:57:21 +00:00
|
|
|
return *this;
|
|
|
|
|
|
|
|
case CHT_MODIFY:
|
|
|
|
{
|
|
|
|
EDA_ITEM* parent = parentObject( aItem );
|
|
|
|
|
|
|
|
if( m_changedItems.find( parent ) != m_changedItems.end() )
|
2016-08-18 14:28:04 +00:00
|
|
|
return *this; // item has been already modified once
|
2016-05-10 15:57:21 +00:00
|
|
|
|
2016-08-18 14:28:04 +00:00
|
|
|
makeEntry( parent, CHT_MODIFY | flag, parent->Clone() );
|
2016-06-09 12:28:54 +00:00
|
|
|
|
2016-05-10 15:57:21 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
}
|
2016-06-09 12:28:54 +00:00
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-09-02 14:38:40 +00:00
|
|
|
COMMIT& COMMIT::Modified( EDA_ITEM* aItem, EDA_ITEM* aCopy )
|
2016-06-09 12:28:54 +00:00
|
|
|
{
|
|
|
|
EDA_ITEM* parent = parentObject( aItem );
|
|
|
|
|
|
|
|
if( m_changedItems.find( parent ) != m_changedItems.end() )
|
2016-08-18 14:28:04 +00:00
|
|
|
return *this; // item has been already modified once
|
2016-06-09 12:28:54 +00:00
|
|
|
|
|
|
|
makeEntry( parent, CHT_MODIFY, aCopy );
|
|
|
|
|
|
|
|
return *this;
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-09 12:28:06 +00:00
|
|
|
COMMIT& COMMIT::Stage( std::vector<EDA_ITEM*>& container, CHANGE_TYPE aChangeType )
|
|
|
|
{
|
|
|
|
for( EDA_ITEM* item : container )
|
|
|
|
{
|
|
|
|
Stage( item, aChangeType );
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-06-09 12:28:54 +00:00
|
|
|
COMMIT& COMMIT::Stage( const PICKED_ITEMS_LIST& aItems, UNDO_REDO_T aModFlag )
|
2016-05-10 15:57:21 +00:00
|
|
|
{
|
2016-05-12 11:55:58 +00:00
|
|
|
for( unsigned int i = 0; i < aItems.GetCount(); i++ )
|
2016-06-09 12:28:54 +00:00
|
|
|
{
|
|
|
|
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
|
2016-09-02 14:38:40 +00:00
|
|
|
Modified( item, copy );
|
2016-06-09 12:28:54 +00:00
|
|
|
}
|
|
|
|
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
|
2016-08-18 14:28:04 +00:00
|
|
|
assert( !!aCopy == ( ( aType & CHT_TYPE ) == CHT_MODIFY ) );
|
2016-06-09 12:28:54 +00:00
|
|
|
|
|
|
|
COMMIT_LINE ent;
|
|
|
|
|
|
|
|
ent.m_item = aItem;
|
|
|
|
ent.m_type = aType;
|
|
|
|
ent.m_copy = aCopy;
|
|
|
|
|
|
|
|
m_changedItems.insert( aItem );
|
|
|
|
m_changes.push_back( ent );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-08-18 14:28:04 +00:00
|
|
|
CHANGE_TYPE COMMIT::convert( UNDO_REDO_T aType ) const
|
2016-06-09 12:28:54 +00:00
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
2016-05-10 15:57:21 +00:00
|
|
|
}
|
|
|
|
|