// function: init
// purpose:
//=======================================================================
-bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
- const CurveCreator_Operation::Type theType)
+bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve)
{
+ CurveCreator_Operation::Type aType = CurveCreator_Operation::Clear;
bool isOK = false;
if (theCurve != NULL) {
// Set redo.
myPRedo = new CurveCreator_Operation;
- if (myPRedo->init(theType)) {
+ if (myPRedo->init(aType)) {
isOK = true;
const int aNbSections = theCurve->getNbSections();
- if (theType == CurveCreator_Operation::Clear) {
- // Construct undo for Clear command.
- if (aNbSections > 0) {
- setNbUndos(aNbSections);
+ // Construct undo for Clear command.
+ if (aNbSections > 0) {
+ setNbUndos(aNbSections);
- for (int i = 0; i < aNbSections && isOK; i++) {
- // Add AddSection command.
- isOK = addSectionToUndo(theCurve, i, myPUndo[i]);
- }
- }
- } else { // theType == CurveCreator_Operation::Join
- // Construct undo for Join command.
- if (aNbSections > 1) {
- // Add the RemovePoints command to remove points of
- // the second section fron the first one.
- const int aNbPoints = theCurve->getNbPoints(0);
-
- setNbUndos(aNbSections);
- isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
- 0, aNbPoints, -1);
-
- for (int i = 1; i < aNbSections && isOK; i++) {
- // Add AddSection command.
- isOK = addSectionToUndo(theCurve, i, myPUndo[i]);
- }
+ for (int i = 0; i < aNbSections && isOK; i++) {
+ // Add AddSection command.
+ isOK = addSectionToUndo(theCurve, i, myPUndo[i]);
}
}
}
setNbUndos(3);
}
+ // Construct undo for RemovePoints command.
+ int anISection = theIntParam1;
+ const int aNbPoints2 = theCurve->getNbPoints(theIntParam2);
+ CurveCreator_ICurve::SectionToPointList aSectionToPointList;
+ int aJoinedSize = aNbPoints + aNbPoints2;
+ for (int anIPoint = aNbPoints; anIPoint < aJoinedSize; anIPoint++)
+ aSectionToPointList.push_back(std::make_pair( anISection, anIPoint ) );
isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
- theIntParam1, aNbPoints, -1);
+ aSectionToPointList);
+
+ //isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
+ // theIntParam1, aNbPoints, -1);
if (isOK) {
isOK = addSectionToUndo(theCurve, theIntParam2, myPUndo[1]);
return isOK;
}
-//=======================================================================
-// function: init
-// purpose:
-//=======================================================================
-bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
- const CurveCreator_Operation::Type theType,
- const int theIntParam1,
- const int theIntParam2,
- const int theIntParam3)
-{
- bool isOK = false;
-
- if (theCurve != NULL) {
- clear();
-
- // Set redo.
- myPRedo = new CurveCreator_Operation;
-
- if (myPRedo->init(theType, theIntParam1, theIntParam2, theIntParam3)) {
- }
-
- if (!isOK) {
- clear();
- }
- }
-
- return isOK;
-}
-
-//=======================================================================
-// function: init
-// purpose:
-//=======================================================================
-bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
- const CurveCreator_Operation::Type theType,
- const CurveCreator::Coordinates &theCoords,
- const int theIntParam)
-{
- bool isOK = false;
-
- if (theCurve != NULL) {
- clear();
-
- // Set redo.
- myPRedo = new CurveCreator_Operation;
-
- if (myPRedo->init(theType, theCoords, theIntParam)) {
- // Construct undo for AddPoints command.
- const int aSectionInd = getSectionIndex(theCurve, theIntParam);
- const CurveCreator::Dimension aDim = theCurve->getDimension();
- const CurveCreator::Coordinates &aPoints =
- theCurve->getPoints(aSectionInd);
- const int aNbPoints = (aPoints.size()/aDim);
-
- setNbUndos(1);
- isOK = myPUndo[0].init(CurveCreator_Operation::RemovePoints,
- aSectionInd, aNbPoints, -1);
- }
-
- if (!isOK) {
- clear();
- }
- }
-
- return isOK;
-}
-
//=======================================================================
// function: init
// purpose:
// 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);
}
return isOK;
}
+bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
+ const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList)
+{
+ bool isOK = false;
+
+ if (theCurve != NULL && theOldParamList.size() > 0) {
+ clear();
+
+ // Set redo.
+ myPRedo = new CurveCreator_Operation;
+
+ // Construct redo for SetCoordinates command.
+ CurveCreator_ICurve::SectionToPointCoordsList aSectionToPointActualCoords;
+ CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt =
+ theOldParamList.begin(), aLast = theOldParamList.end();
+ for ( ; anIt != aLast; anIt++ ) {
+ CurveCreator::Coordinates anActualCoords = theCurve->getPoint(anIt->first.first, anIt->first.second);
+ aSectionToPointActualCoords.push_back(std::make_pair(anIt->first, anActualCoords));
+ }
+
+ if (myPRedo->init(CurveCreator_Operation::SetCoordinates, aSectionToPointActualCoords)) {
+ // Undo for SetCoordinates command.
+ setNbUndos(1);
+ isOK = myPUndo[0].init(CurveCreator_Operation::SetCoordinates,
+ theOldParamList);
+ }
+
+ if (!isOK) {
+ clear();
+ }
+ }
+
+ return isOK;
+}
+
//=======================================================================
// function: applyUndo
// purpose: