}
}
break;
- case CurveCreator_Operation::RemovePoints:
- {
- // Construct undo for RemovePoints command.
- const CurveCreator::Dimension aDim = theCurve->getDimension();
- const CurveCreator::Coordinates &aPoints =
- theCurve->getPoints(theIntParam1);
- CurveCreator::Coordinates::const_iterator anIterBegin =
- aPoints.begin() + (aDim*theIntParam2);
- CurveCreator::Coordinates::const_iterator anIterEnd;
-
- anIterEnd = aPoints.end();
-
- CurveCreator::Coordinates aPointsToAdd;
-
- setNbUndos(1);
- aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd);
- isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints,
- aPointsToAdd, theIntParam1, theIntParam2);
- }
- break;
default:
break;
}
return isOK;
}
-//=======================================================================
-// function: init
-// purpose:
-//=======================================================================
bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
- const CurveCreator::Coordinates &theCoords,
- const int theIntParam1,
- const int theIntParam2)
+ const std::string &theName,
+ const int theIntParam1 )
+{
+ bool isOK = false;
+ myPRedo = new CurveCreator_Operation;
+
+ if (myPRedo->init(theType, theName, theIntParam1 )) {
+ // Construct undo for different commands.
+ switch (theType) {
+ case CurveCreator_Operation::RenameSection:
+ setNbUndos(1);
+ isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection,
+ theCurve->getSectionName(theIntParam1), theIntParam1);
+ break;
+ }
+ }
+ if( !isOK ){
+ clear();
+ }
+ return isOK;
+}
+
+bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
+ const CurveCreator_Operation::Type theType,
+ const CurveCreator_ICurve::SectionToPointList &theParamList1)
{
bool isOK = false;
// Set redo.
myPRedo = new CurveCreator_Operation;
- if (myPRedo->init(theType, theCoords, theIntParam1, theIntParam2)) {
+ if (myPRedo->init(theType, theParamList1)) {
// Construct undo for different commands.
switch (theType) {
- case CurveCreator_Operation::InsertPoints:
+ case CurveCreator_Operation::RemovePoints:
{
+ // Construct undo for RemovePoints command.
+ CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointCoords;
+ CurveCreator::Coordinates aPointsToAdd;
const CurveCreator::Dimension aDim = theCurve->getDimension();
- const int aNbPoints = (theCoords.size()/aDim);
- const int aSectionInd = getSectionIndex(theCurve, theIntParam1);
- int aPointInd;
-
- if (theIntParam2 == -1) {
- aPointInd = theCurve->getNbPoints(aSectionInd);
- } else {
- aPointInd = theIntParam2;
+ CurveCreator_ICurve::SectionToPointList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end();
+ std::list<int> aPoints;
+ int aSectionId, aPointId;
+ for ( ; anIt != aLast; anIt++ ) {
+ aPointsToAdd.clear();
+ aSectionId = anIt->first;
+ aPointId = anIt->second;
+ const CurveCreator::Coordinates &aPoints =
+ theCurve->getPoints(aSectionId);
+ CurveCreator::Coordinates::const_iterator anIterBegin =
+ aPoints.begin() + (aDim*aPointId);
+ CurveCreator::Coordinates::const_iterator anIterEnd =
+ anIterBegin + aDim;
+ aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd);
+ aSectionToPointCoords.push_back(std::make_pair(*anIt, aPointsToAdd));
}
-
setNbUndos(1);
- isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
- aSectionInd, aPointInd);
- }
- break;
- case CurveCreator_Operation::SetCoordinates:
- {
- const CurveCreator::Coordinates anOldCoords =
- theCurve->getPoint(theIntParam1, theIntParam2);
-
- setNbUndos(1);
- isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates,
- anOldCoords, theIntParam1, theIntParam2);
+ isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints,
+ aSectionToPointCoords);
}
break;
default:
bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
const CurveCreator_Operation::Type theType,
- const std::string &theName,
- const int theIntParam1 )
+ const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1)
{
bool isOK = false;
- myPRedo = new CurveCreator_Operation;
- if (myPRedo->init(theType, theName, theIntParam1 )) {
- // Construct undo for different commands.
- switch (theType) {
- case CurveCreator_Operation::RenameSection:
- setNbUndos(1);
- isOK = myPUndo[0].init(CurveCreator_Operation::RenameSection,
- theCurve->getSectionName(theIntParam1), theIntParam1);
- break;
- }
- }
- if( !isOK ){
+ if (theCurve != NULL) {
clear();
+
+ // Set redo.
+ myPRedo = new CurveCreator_Operation;
+
+ if (myPRedo->init(theType, theParamList1)) {
+ // Construct undo for different commands.
+ switch (theType) {
+ case CurveCreator_Operation::InsertPoints:
+ {
+ // Construct undo for RemovePoints command.
+ CurveCreator_ICurve::SectionToPointList aSectionToPointList;
+ CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end();
+ int aSectionId, aPointId;
+ for ( ; anIt != aLast; anIt++ ) {
+ aSectionToPointList.push_back(anIt->first);
+ }
+ setNbUndos(1);
+ isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
+ aSectionToPointList);
+ }
+ break;
+ case CurveCreator_Operation::SetCoordinates:
+ {
+ // Construct undo for SetCoordinates command.
+ CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointOldCoords;
+ CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = theParamList1.begin(), aLast = theParamList1.end();
+ for ( ; anIt != aLast; anIt++ ) {
+ CurveCreator::Coordinates anOldCoords = theCurve->getPoint(anIt->first.first, anIt->first.second);
+ aSectionToPointOldCoords.push_back(std::make_pair(anIt->first, anOldCoords));
+ }
+
+ setNbUndos(1);
+ isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates,
+ aSectionToPointOldCoords);
+ }
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (!isOK) {
+ clear();
+ }
}
+
return isOK;
}
const int theIndex,
CurveCreator_Operation &theOperation) const
{
+ const std::string aName = theCurve->getSectionName(theIndex);
const CurveCreator::Coordinates &aPnts = theCurve->getPoints(theIndex);
const CurveCreator::SectionType aType = theCurve->getSectionType(theIndex);
const bool isClosed = theCurve->isClosed(theIndex);
bool isOK = theOperation.init(CurveCreator_Operation::AddSection,
- aPnts, aType, isClosed);
+ aName, aPnts, aType, isClosed);
return isOK;
}