Skip to content

Commit

Permalink
Multiple fixes for undo of event and event assignments.
Browse files Browse the repository at this point in the history
  • Loading branch information
shoops committed May 4, 2018
1 parent dbee10d commit 36aa5a4
Show file tree
Hide file tree
Showing 8 changed files with 61 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -61,3 +61,4 @@ StructuralDependencies\.dot
AppendAllDependents\.dot

\.pydevproject
callgrind.out.*
4 changes: 2 additions & 2 deletions copasi/UI/CQReactionDM.cpp
Expand Up @@ -202,15 +202,15 @@ bool CQReactionDM::setData(const QModelIndex &index, const QVariant &value,
case COL_NAME_REACTIONS:
if (mpReactions->getIndex(TO_UTF8(value.toString())) == C_INVALID_INDEX)
{
changed &= Data.addProperty(CData::OBJECT_NAME,
changed |= Data.addProperty(CData::OBJECT_NAME,
Reaction.getObjectName(),
TO_UTF8(value.toString()));
}

break;

case COL_EQUATION:
changed &= setEquation(Reaction, value, Data);
changed |= setEquation(Reaction, value, Data);
break;
}

Expand Down
2 changes: 1 addition & 1 deletion copasi/core/CDataObject.cpp
Expand Up @@ -542,7 +542,7 @@ void CDataObject::createUndoData(CUndoData & undoData, const CUndoData::Type & t
return;
}

undoData = CUndoData(CUndoData::Type::CHANGE, this);
undoData = CUndoData(CUndoData::Type::CHANGE, oldData);

undoData.addProperty(CData::OBJECT_NAME, oldData.getProperty(CData::OBJECT_NAME), mObjectName);
undoData.addProperty(CData::OBJECT_UUID, oldData.getProperty(CData::OBJECT_UUID), getUuid().str());
Expand Down
6 changes: 2 additions & 4 deletions copasi/core/CDataObject.h
Expand Up @@ -35,7 +35,7 @@ template <class CType> class CDataObjectReference;

//********************************************************************************

class CDataObject: public CObjectInterface, public virtual CUndoObjectInterface
class CDataObject: public CObjectInterface, public CUndoObjectInterface
{
public:
typedef std::set< const CDataObject * > DataObjectSet;
Expand Down Expand Up @@ -73,8 +73,6 @@ class CDataObject: public CObjectInterface, public virtual CUndoObjectInterface
const std::string & type = "CN",
const CFlags< Flag > & flag = CFlags< Flag >::None);

CDataObject(const CDataObject & src);

public:
/**
* Static method to create a CDataObject based on the provided data
Expand Down Expand Up @@ -118,7 +116,7 @@ class CDataObject: public CObjectInterface, public virtual CUndoObjectInterface
static void sanitizeObjectName(std::string & name);

CDataObject(const CDataObject & src,
const CDataContainer * pParent);
const CDataContainer * pParent = NULL);

virtual ~CDataObject();

Expand Down
45 changes: 31 additions & 14 deletions copasi/core/CDataVector.h
Expand Up @@ -3,7 +3,6 @@
// of Connecticut School of Medicine.
// All rights reserved.


#ifndef COPASI_CDataVector
#define COPASI_CDataVector

Expand Down Expand Up @@ -300,9 +299,20 @@ template < class CType > class CDataVector:
}
}

std::vector< CUndoData > PreProcessData;

// Removal must be done in reverse order
for (; itOld != endOld; ++itOld)
{
undoData.addPreProcessData(CUndoData(CUndoData::Type::REMOVE, *itOld));
PreProcessData.push_back(CUndoData(CUndoData::Type::REMOVE, *itOld));
}

std::vector< CUndoData >::const_reverse_iterator itPre = PreProcessData.rbegin();
std::vector< CUndoData >::const_reverse_iterator endPre = PreProcessData.rbegin();

for (; itPre != endPre; ++itPre)
{
undoData.addPreProcessData(*itPre);
}

for (; itNew != endNew; ++itNew)
Expand Down Expand Up @@ -337,7 +347,7 @@ template < class CType > class CDataVector:
}
else
{
updateIndex(Index, pNew);
updateIndex(Index, dynamic_cast< CDataObject * >(pNew));
}

CDataContainer::add(pNew, false);
Expand All @@ -362,7 +372,7 @@ template < class CType > class CDataVector:
}
}

return pNew;
return dynamic_cast< CDataObject * >(pNew);
}

/**
Expand Down Expand Up @@ -566,7 +576,7 @@ template < class CType > class CDataVector:
{
CDataContainer::remove(*it);
(*it)->setObjectParent(NULL);
delete(*it);
delete (*it);
*it = NULL;
}

Expand Down Expand Up @@ -1048,16 +1058,19 @@ template < class CType > class CDataVectorN: public CDataVector < CType >
while (itOld != endOld &&
itNew != endNew)
{
const std::string OldName = itOld->getProperty(CData::OBJECT_NAME).toString();
const std::string NewName = itNew->getObjectName();
const std::string & OldName = itOld->getProperty(CData::OBJECT_NAME).toString();
const std::string & NewName = itNew->getObjectName();
std::cout << "Old Name: " << OldName << " New Name: " << NewName << std::endl;

if (OldName < NewName)
{
std::cout << "REMOVE: " << OldName << std::endl;
Deleted[itOld->getProperty(CData::OBJECT_INDEX).toSizeT()] = *itOld;
++itOld;
}
else if (OldName < NewName)
else if (OldName > NewName)
{
std::cout << "INSERT: " << NewName << std::endl;
Inserted[CDataVector< CType >::getIndex(*itNew)] = itNew->toData();
++itNew;
}
Expand All @@ -1068,6 +1081,7 @@ template < class CType > class CDataVectorN: public CDataVector < CType >

if (!UndoData.empty())
{
std::cout << "CHANGE: " << NewName << std::endl;
OldData[itOld->getProperty(CData::OBJECT_INDEX).toSizeT()] = UndoData.getOldData();
NewData[CDataVector< CType >::getIndex(*itNew)] = UndoData.getNewData();
}
Expand All @@ -1079,24 +1093,27 @@ template < class CType > class CDataVectorN: public CDataVector < CType >

for (; itOld != endOld; ++itOld)
{
std::cout << "REMOVE: " << itOld->getProperty(CData::OBJECT_NAME).toString() << std::endl;
Deleted[itOld->getProperty(CData::OBJECT_INDEX).toSizeT()] = *itOld;
}

for (; itNew != endNew; ++itNew)
{
std::cout << "INSERT: " << itNew->getObjectName() << std::endl;
Inserted[CDataVector< CType >::getIndex(*itNew)] = itNew->toData();
}

std::map< size_t, CData >::iterator it = Deleted.begin();
std::map< size_t, CData >::iterator end = Deleted.end();
// Removal must be done in reverse order
std::map< size_t, CData >::reverse_iterator itReverse = Deleted.rbegin();
std::map< size_t, CData >::reverse_iterator endReverse = Deleted.rend();

for (; it != end; ++it)
for (; itReverse != endReverse; ++itReverse)
{
undoData.addPreProcessData(CUndoData(CUndoData::Type::REMOVE, it->second));
undoData.addPreProcessData(CUndoData(CUndoData::Type::REMOVE, itReverse->second));
}

it = Inserted.begin();
end = Inserted.end();
std::map< size_t, CData >::iterator it = Inserted.begin();
std::map< size_t, CData >::iterator end = Inserted.end();

for (; it != end; ++it)
{
Expand Down
2 changes: 1 addition & 1 deletion copasi/model/CModelParameter.h
Expand Up @@ -25,7 +25,7 @@ class CModel;
class CReaction;
class CValidatedUnit;

class CModelParameter : public virtual CUndoObjectInterface
class CModelParameter : public CUndoObjectInterface
{
friend std::ostream &operator<<(std::ostream &os, const CModelParameter & o);

Expand Down
4 changes: 1 addition & 3 deletions copasi/model/CModelParameterSet.cpp
Expand Up @@ -8,8 +8,6 @@
// of Manchester.
// All rights reserved.



#include "copasi/copasi.h"

#include "CModelParameterSet.h"
Expand Down Expand Up @@ -76,7 +74,7 @@ void CModelParameterSet::createUndoData(CUndoData & undoData,
// virtual
CUndoObjectInterface * CModelParameterSet::insert(const CData & data)
{
CModelParameter * pParameter = CModelParameter::fromData(data, this);
CModelParameter * pParameter = CModelParameter::fromData(data, dynamic_cast< CDataObject * >(this));

switch (CModelParameter::TypeNames.toEnum(data.getProperty(CData::OBJECT_TYPE).toString(), CModelParameter::Type::unknown))
{
Expand Down
26 changes: 22 additions & 4 deletions copasi/undo/CUndoData.cpp
Expand Up @@ -83,7 +83,7 @@ CUndoData::CUndoData(const Type & type, const CDataObject * pObject, const size_
}

CUndoData::CUndoData(const Type & type, const CData & data, const size_t & authorId):
mType(CUndoData::Type::CHANGE),
mType(type),
mOldData(),
mNewData(),
mPreProcessData(),
Expand Down Expand Up @@ -594,7 +594,7 @@ bool CUndoData::operator < (const CUndoData & rhs) const

bool CUndoData::empty() const
{
return mChangedProperties.empty();
return mChangedProperties.empty() && mPreProcessData.empty() && mPostProcessData.empty();
}

void CUndoData::clear()
Expand Down Expand Up @@ -826,7 +826,7 @@ CUndoObjectInterface * CUndoData::getObject(const CDataModel & dataModel, const
}
else if ((pSet = dynamic_cast< CModelParameterSet * >(pParent)) != NULL)
{
pObject = pSet->getModelParameter(data.getProperty(CData::OBJECT_NAME).toString());
pObject = pSet->getModelParameter(CCommonName::escape(data.getProperty(CData::OBJECT_NAME).toString()));
}
else if (data.isSetProperty(CData::OBJECT_HASH))
{
Expand All @@ -850,7 +850,7 @@ CUndoObjectInterface * CUndoData::getObject(const CDataModel & dataModel, const

if (pObject == NULL)
{
pObject = dynamic_cast< const CDataObject * >(pParent->getObject(data.getProperty(CData::OBJECT_TYPE).toString() + "=" + data.getProperty(CData::OBJECT_NAME).toString()));
pObject = dynamic_cast< const CDataObject * >(pParent->getObject(data.getProperty(CData::OBJECT_TYPE).toString() + "=" + CCommonName::escape(data.getProperty(CData::OBJECT_NAME).toString())));
}
}

Expand All @@ -860,8 +860,26 @@ CUndoObjectInterface * CUndoData::getObject(const CDataModel & dataModel, const
std::ostream & operator << (std::ostream & os, const CUndoData & o)
{
os << "Type: " << CUndoData::TypeName[o.mType] << std::endl;

os << "Pre:" << std::endl;
std::vector< CUndoData >::const_iterator it = o.mPreProcessData.begin();
std::vector< CUndoData >::const_iterator end = o.mPreProcessData.end();

for (; it != end; ++it)
{
os << *it << std::endl;
}

os << "Old: " << std::endl << o.mOldData << std::endl;
os << "New: " << std::endl << o.mNewData << std::endl;
os << "Post:" << std::endl;
it = o.mPostProcessData.begin();
end = o.mPostProcessData.end();

for (; it != end; ++it)
{
os << *it << std::endl;
}

return os;
}

0 comments on commit 36aa5a4

Please sign in to comment.