Salome HOME
refs #250 - Fatal error after Join all selections operation
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Diff.cxx
index fba15d131dc6ca6ff3fb7f299fca872873ddcf94..b2cecfd8c5c12cf66a2fdf0802407d0c16fda75b 100644 (file)
@@ -416,7 +416,6 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
             // 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);
             }
@@ -453,6 +452,41 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
   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:
@@ -525,12 +559,13 @@ bool CurveCreator_Diff::addSectionToUndo
                        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;
 }