]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Implementation of Undo/Redo of 'SetPoints', 'AddPoints', 'RemovePoints'.
authorakl <akl@opencascade.com>
Thu, 21 Nov 2013 16:55:08 +0000 (16:55 +0000)
committerakl <akl@opencascade.com>
Thu, 21 Nov 2013 16:55:08 +0000 (16:55 +0000)
src/HYDROCurveCreator/CMakeLists.txt
src/HYDROCurveCreator/CurveCreator.hxx
src/HYDROCurveCreator/CurveCreator_Curve.cxx
src/HYDROCurveCreator/CurveCreator_Curve.hxx
src/HYDROCurveCreator/CurveCreator_Diff.cxx
src/HYDROCurveCreator/CurveCreator_Diff.hxx
src/HYDROCurveCreator/CurveCreator_Operation.cxx
src/HYDROCurveCreator/CurveCreator_Operation.hxx
src/HYDROCurveCreator/CurveCreator_Widget.cxx

index e225ade5d26b8ea9eebaea1e31ff54c358c06851..b2aaec5b5acdf4cb468d6d3243966fc6e69f3d39 100644 (file)
@@ -75,6 +75,7 @@ SET(_other_HEADERS
   CurveCreator_Operation.hxx
   CurveCreator_Section.hxx
   CurveCreator_Utils.h
+  CurveCreator_PosPoint.hxx
 )
 
 # header files / to install
index 031f7a5b921fef62732595c899208091ed4a148f..9cd7ec720723ca117438fbac5f5e60928be73ae7 100644 (file)
 #define _CurveCreator_HeaderFile
 
 #include <deque>
+#include <map>
+#include <list>
 
 struct CurveCreator_Section;
+struct CurveCreator_PosPoint;
 
 namespace CurveCreator
 {
@@ -41,6 +44,10 @@ namespace CurveCreator
   //! List of sections
   typedef std::deque<CurveCreator_Section *> Sections;
 
+  // List of positioned points (points with coordinates)
+  typedef std::list<CurveCreator_PosPoint*> PosPointsList;
+  //! Map of sections with positioned points
+  typedef std::map<int,PosPointsList> SectionsMap;
 };
 
 #endif
index 51cf063e266a9aba11549e002ed9997ad5976529..c95d151ba70f7197e94e96e7acb64d30ddde17e4 100644 (file)
@@ -23,6 +23,7 @@
 #include "CurveCreator_Curve.hxx"
 
 #include "CurveCreator.hxx"
+#include "CurveCreator_PosPoint.hxx"
 #include "CurveCreator_Section.hxx"
 #include "CurveCreator_Displayer.h"
 
@@ -398,6 +399,25 @@ bool CurveCreator_Curve::moveSection(const int theISection,
   return res;
 }
 
+void CurveCreator_Curve::convert( const SectionToPointList& thePoints,
+                                 std::map<int,std::list<int>>& theConvPoints )
+{
+  theConvPoints.clear();
+
+  SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
+  std::list<int> aPoints;
+  int aSectionId, aPointId;
+  for ( ; anIt != aLast; anIt++ ) {
+    aSectionId = anIt->first;
+    aPointId = anIt->second;
+    aPoints.clear();
+    if ( theConvPoints.find( aSectionId ) != theConvPoints.end() )
+      aPoints = theConvPoints[aSectionId];
+    aPoints.push_back( aPointId );
+    theConvPoints[aSectionId] = aPoints;
+  }
+}
+
 /************   Implementation of INTERFACE methods   ************/
 
 /***********************************************/
@@ -775,35 +795,35 @@ bool CurveCreator_Curve::setSectionType( const int theISection,
 /***********************************************/
 
 //! For internal use only! Undo/Redo are not used here.
-bool CurveCreator_Curve::addPointsInternal( const CurveCreator::Coordinates& theCoords,
-                                            const std::vector<int> &theISections,
-                                            const std::vector<int> &theIPnts  )
+bool CurveCreator_Curve::addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap )
 {
   bool res = false;
-  if( (theCoords.size()/getDimension()) == theISections.size() == theIPnts.size() ) {
-    for( int ind = 0; ind < theISections.size(); ind++ ) {
-      int anISection = theISections.at(ind);
-      CurveCreator_Section *aSection =
-        (anISection == -1 ? mySections.back() : mySections.at(anISection));
-
-      if( aSection ) {
-        int anIPnt = theIPnts.at(ind);
+  CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
+  CurveCreator_Section *aSection = 0;
+  for ( ; anIt != theSectionsMap.end(); anIt++ ) {
+    int anISection = anIt->first;
+    aSection = mySections.at(anISection);
+    if( aSection ) {
+      CurveCreator::PosPointsList aSectionPoints = anIt->second;
+      CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
+      for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
+        int anIPnt = (*aPntIt)->myID;
+        CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
         CurveCreator::Coordinates::iterator anIterPosition;
         if(anIPnt == -1)
           anIterPosition = aSection->myPoints.end();
         else
           anIterPosition = aSection->myPoints.begin() + toICoord(anIPnt);
         CurveCreator::Coordinates::const_iterator aFirstPosition = 
-          theCoords.begin() + toICoord(ind);        
+          aCoords.begin();
         aSection->myPoints.insert(anIterPosition,
-                                  aFirstPosition, 
-                                  aFirstPosition + getDimension());
-        res = true;
+                                  aCoords.begin(), aCoords.end());
       }
+      res = true;
     }
-    if(res)
-      redisplayCurve();
   }
+  if(res)
+    redisplayCurve();
   return res;
 }
 
@@ -820,34 +840,47 @@ bool CurveCreator_Curve::addPoints( const CurveCreator::Coordinates& theCoords,
   // Set the difference.
   startOperation();
   if (addEmptyDiff()) {
+    CurveCreator_ICurve::SectionToPointCoordsList aList;
+    aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theCoords));
     myListDiffs.back().init(this, CurveCreator_Operation::InsertPoints,
-                            theCoords, theISection, theIPnt);
+                            aList);
   }
-  std::vector<int> anISections, anIPnts;
-  anISections.push_back( theISection );
-  anIPnts.push_back( theIPnt );
-  res = addPointsInternal( theCoords, anISections, anIPnts );
+  CurveCreator::SectionsMap aSectionsMap;
+  CurveCreator::PosPointsList aPoints;
+  CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theCoords );
+  aPoints.push_back( aPosPoint );
+  aSectionsMap[theISection] = aPoints;
+
+  res = addPointsInternal( aSectionsMap );
+
   finishOperation();
   return res;
 }
 
 //! For internal use only! Undo/Redo are not used here.
-bool CurveCreator_Curve::setPointInternal( const int theISection,
-                                           const int theIPnt,
-                                           const CurveCreator::Coordinates& theNewCoords )
+bool CurveCreator_Curve::setPointInternal( const CurveCreator::SectionsMap &theSectionsMap )
 {
   bool res = false;
   // Update the curve.
-  if (theNewCoords.size() == myDimension) {
-    CurveCreator_Section *aSection = mySections.at(theISection);
-    int i;
-    for (i = 0; i < myDimension; i++) {
-      aSection->myPoints.at(toICoord(theIPnt) + i) = theNewCoords[i];
+  CurveCreator::SectionsMap::const_iterator anIt = theSectionsMap.begin();
+  CurveCreator_Section *aSection = 0;
+  for ( ; anIt != theSectionsMap.end(); anIt++ ) {
+    int anISection = anIt->first;
+    aSection = mySections.at(anISection);
+    if( aSection ) { 
+      CurveCreator::PosPointsList aSectionPoints = anIt->second;
+      CurveCreator::PosPointsList::const_iterator aPntIt = aSectionPoints.begin();
+      for( ; aPntIt != aSectionPoints.end(); aPntIt++ ){
+        int anIPnt = (*aPntIt)->myID;
+        CurveCreator::Coordinates aCoords = (*aPntIt)->myCoords;
+        aSection->myPoints.assign(aCoords.begin(), aCoords.end());
+      }
+      res = true;
     }
-    redisplayCurve();
-    
-    res = true;
   }
+  if(res)
+    redisplayCurve();
+  
   return res;
 }
 
@@ -860,10 +893,18 @@ bool CurveCreator_Curve::setPoint( const int theISection,
   // Set the difference.
   startOperation();
   if (addEmptyDiff()) {
+    CurveCreator_ICurve::SectionToPointCoordsList aList;
+    aList.push_back(std::make_pair(std::make_pair(theISection, theIPnt), theNewCoords));
     myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
-                            theNewCoords, theISection, theIPnt);
+                            aList);
   }
-  res = setPointInternal( theISection, theIPnt, theNewCoords );
+  CurveCreator::SectionsMap aSectionsMap;
+  CurveCreator::PosPointsList aPoints;
+  CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( theIPnt, theNewCoords );
+  aPoints.push_back( aPosPoint );
+  aSectionsMap[theISection] = aPoints;
+
+  res = setPointInternal( aSectionsMap );
   finishOperation();
 
   return res; 
@@ -876,28 +917,35 @@ bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSe
 }
 
 //! For internal use only! Undo/Redo are not used here.
-bool CurveCreator_Curve::removePointsInternal( const std::vector<int> &theISections, 
-                                               const std::vector<int> &theIPnts )
+bool CurveCreator_Curve::removePointsInternal( const SectionToPointList &thePoints )
 {
   bool res = false;
-  if( theISections.size() == theIPnts.size() ) {
-    for( int ind = 0; ind < theISections.size(); ind++ ) {
-      int anISection = theISections.at(ind);
-      CurveCreator_Section *aSection = mySections.at(anISection);
-      if( aSection ) {
-        int anIPnt = theIPnts.at(ind);
+  std::map<int, std::list<int> > aConvPoints;
+  convert( thePoints, aConvPoints );
+  std::map<int, std::list<int> >::const_iterator anIt = aConvPoints.begin(),
+                                          aLast = aConvPoints.end();
+  CurveCreator_Section *aSection = 0;
+  for ( ; anIt != aLast; anIt++ ) {
+    int aSectionId = anIt->first;
+    aSection = mySections.at(aSectionId);
+    if( aSection ) {
+      std::list<int> aSectionPoints = anIt->second;
+      aSectionPoints.sort();
+      std::list<int>::const_reverse_iterator aPntIt = aSectionPoints.rbegin();
+      for( ; aPntIt != aSectionPoints.rend(); aPntIt++ ){
+        int aPntIndx = *aPntIt;
         CurveCreator::Coordinates::iterator aFirstPosition;
-        if(anIPnt == -1)
-          aFirstPosition = aSection->myPoints.end();
+        if(aPntIndx == -1)
+          aFirstPosition = aSection->myPoints.end() - getDimension();
         else
-          aFirstPosition = aSection->myPoints.begin() + toICoord(anIPnt);
+          aFirstPosition = aSection->myPoints.begin() + toICoord(aPntIndx);
         aSection->myPoints.erase( aFirstPosition, aFirstPosition + getDimension() );
         res = true;
       }
     }
-    if(res)
-      redisplayCurve();
   }
+  if(res)
+    redisplayCurve();
   return res;
 }
 
@@ -911,10 +959,9 @@ bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt )
     myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
                             theISection, theIPnt);
   }
-  std::vector<int> anISections, anIPnts;
-  anISections.push_back( theISection );
-  anIPnts.push_back( theIPnt );
-  res = removePointsInternal( anISections, anIPnts );
+  SectionToPointList aListOfSectionsToPoints;
+  aListOfSectionsToPoints.push_back(std::make_pair(theISection, theIPnt));
+  res = removePointsInternal( aListOfSectionsToPoints );
   finishOperation();
   return res;
 }
@@ -922,7 +969,16 @@ bool CurveCreator_Curve::removePoint( const int theISection, const int theIPnt )
 //! Remove several points from different sections with given ids
 bool CurveCreator_Curve::removeSeveralPoints( const SectionToPointList &theSectionToPntIDs)
 {
-  return false;
+  bool res = false;
+  // Set the difference.
+  startOperation();
+  if (addEmptyDiff()) {
+    myListDiffs.back().init(this, CurveCreator_Operation::RemovePoints,
+                            theSectionToPntIDs);
+  }
+  res = removePointsInternal( theSectionToPntIDs );
+  finishOperation();
+  return res;
 }
 
   //=======================================================================
index cc6d97b21aa039ef7624d0e4adb86aa19daba7fe..5747dd8bbc2dce64eb6006d3a7b565b098701345 100644 (file)
@@ -34,6 +34,7 @@
 #include <AIS_InteractiveObject.hxx>
 
 #include <list>
+#include <map>
 
 struct CurveCreator_Section;
 class CurveCreator_Displayer;
@@ -114,6 +115,9 @@ protected:
 
   void redisplayCurve();
 
+  void convert( const SectionToPointList &thePoints,
+                std::map<int, std::list<int> > &theConvPoints );
+
 public:
   /************   Implementation of INTERFACE methods   ************/
 
@@ -215,9 +219,7 @@ public:
   /***********************************************/
 
   //! For internal use only! Undo/Redo are not used here.
-  virtual bool addPointsInternal( const CurveCreator::Coordinates &theCoords,
-                                  const std::vector<int> &theISections,
-                                  const std::vector<int> &theIPnts );
+  virtual bool addPointsInternal( const CurveCreator::SectionsMap &theSectionsMap );
   /**
    *  Add one point to the specified section starting from the given theIPnt index
    *  (or at the end of points if \a theIPnt is -1).
@@ -227,9 +229,7 @@ public:
                           const int theIPnt = -1 );
 
   //! For internal use only! Undo/Redo are not used here.
-  virtual bool setPointInternal( const int theISection,
-                                 const int theIPnt,
-                                 const CurveCreator::Coordinates& theNewCoords );
+  virtual bool setPointInternal( const CurveCreator::SectionsMap &theSectionsMap );
    //! Set coordinates of specified point
   virtual bool setPoint( const int theISection,
                          const int theIPnt,
@@ -239,8 +239,7 @@ public:
   virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords);
 
   //! For internal use only! Undo/Redo are not used here.
-  virtual bool removePointsInternal( const std::vector<int> &theISections, 
-                                     const std::vector<int> &theIPnts );
+  virtual bool removePointsInternal( const SectionToPointList &thePoints );
   /** Remove point with given id */
   virtual bool removePoint( const int theISection, const int theIPnt = -1 );
 
index 1e21a31c6cd1c3cdda2fdf5cc0fe65a0704274f0..fba15d131dc6ca6ff3fb7f299fca872873ddcf94 100644 (file)
@@ -203,25 +203,6 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
             }
           }
           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 = 
-              anIterBegin + aDim;
-
-            CurveCreator::Coordinates aPointsToAdd;
-
-            setNbUndos(1);
-            aPointsToAdd.insert(aPointsToAdd.end(), anIterBegin, anIterEnd);
-            isOK = myPUndo[0].init(CurveCreator_Operation::InsertPoints,
-                                   aPointsToAdd, theIntParam1, theIntParam2);
-          }
-          break;
         default:
           break;
       }
@@ -336,15 +317,33 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
     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;
 
@@ -354,35 +353,34 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
     // 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:
@@ -400,25 +398,58 @@ bool CurveCreator_Diff::init(const CurveCreator_Curve *theCurve,
 
 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;
 }
 
index 291aaee35e2db91156040e168ac12d826d5faedb..b94dadafbd106d6421b3701854408d0720b28b8f 100644 (file)
@@ -116,46 +116,55 @@ public:
 
   /**
    * This method initializes the difference with an operation with one
-   * CurveCreator::Coordinates parameter and two integer parameters.
+   * Name, one CurveCreator::Coordinates parameter and two integer parameters.
    * It is applicable to the following operations:
    * <UL>
-   *   <LI>InsertPoints</LI>
-   *   <LI>SetCoordinates</LI>
+   *   <LI>AddSection</LI>
    * </UL>
    */
   bool init(const CurveCreator_Curve *theCurve,
             const CurveCreator_Operation::Type theType,
+            const std::string& theName,
             const CurveCreator::Coordinates &theCoords,
             const int theIntParam1,
             const int theIntParam2);
 
   /**
    * This method initializes the difference with an operation with one
-   * Name, one CurveCreator::Coordinates parameter and two integer parameters.
+   * string and one integer parameters.
    * It is applicable to the following operations:
    * <UL>
-   *   <LI>AddSection</LI>
+   *   <LI>RenameSection</LI>
    * </UL>
    */
   bool init(const CurveCreator_Curve *theCurve,
             const CurveCreator_Operation::Type theType,
-            const std::string& theName,
-            const CurveCreator::Coordinates &theCoords,
-            const int theIntParam1,
-            const int theIntParam2);
+            const std::string &theName,
+            const int theIntParam1 );
 
   /**
-   * This method initializes the difference with an operation with one
-   * string and one integer parameters.
+   * This method initializes the difference with an operation with 
+   * list of pairs of integer parameters.
    * It is applicable to the following operations:
    * <UL>
-   *   <LI>RenameSection</LI>
+   *   <LI>RemovePoints</LI>
    * </UL>
    */
   bool init(const CurveCreator_Curve *theCurve,
             const CurveCreator_Operation::Type theType,
-            const std::string &theName,
-            const int theIntParam1 );
+            const CurveCreator_ICurve::SectionToPointList &theParamList);
+
+  /**
+   * This method initializes the difference with an operation with 
+   * list of pairs of integer parameters with point coordinates.
+   * It is applicable to the following operations:
+   * <UL>
+   *   <LI>RemovePoints</LI>
+   * </UL>
+   */
+  bool init(const CurveCreator_Curve *theCurve,
+            const CurveCreator_Operation::Type theType,
+            const CurveCreator_ICurve::SectionToPointCoordsList &theParamList);
 
   /**
    * This method applies undo operation to theCurve.
index ce73d1ccfe4abe52c9b046c0952a2aa2da5c8a15..fa9cdb071f753de652069a14ed1307fd8bb4c980 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "CurveCreator_Operation.hxx"
 #include "CurveCreator_Curve.hxx"
+#include "CurveCreator.hxx"
 
 #include <string>
 #include <stdlib.h>
@@ -46,6 +47,11 @@ CurveCreator_Operation::~CurveCreator_Operation()
   clear();
 }
 
+bool compId(CurveCreator_PosPoint* p1, CurveCreator_PosPoint* p2)
+{
+  return p1->myID < p2->myID;
+}
+
 //=======================================================================
 // function: Constructor
 // purpose:
@@ -178,9 +184,7 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
 {
   bool isOK = false;
 
-  if (theType == CurveCreator_Operation::AddSection   ||
-      theType == CurveCreator_Operation::InsertPoints ||
-      theType == CurveCreator_Operation::SetCoordinates) {
+  if (theType == CurveCreator_Operation::AddSection) {
     const int aNbCoords = theCoords.size();
     const size_t aSize =
       3*sizeof(theIntParam1) + aNbCoords*sizeof(CurveCreator::TypeCoord);
@@ -270,6 +274,84 @@ bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
     return false;
 }
 
+bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
+                                  const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1)
+{
+  bool isOK = false;
+
+  if (theType == CurveCreator_Operation::InsertPoints ||
+      theType == CurveCreator_Operation::SetCoordinates ) {
+
+    const int aNbPoints = theParamList1.size();
+
+    CurveCreator_ICurve::SectionToPointCoordsList::const_iterator anIt = 
+      theParamList1.begin();
+    const int aNbCoords = anIt->second.size();
+
+    const size_t aSize =
+      sizeof(aNbPoints) + sizeof(aNbCoords) + 
+      aNbPoints * (3*sizeof(int) + aNbCoords*sizeof(CurveCreator::TypeCoord));
+    int *pIntData = (int *)allocate(aSize);
+
+    *pIntData++ = aNbPoints;
+    *pIntData++ = aNbCoords;
+    int aSectionId, aPointId;
+    for ( ; anIt != theParamList1.end(); anIt++ ) {
+      aSectionId = anIt->first.first;
+      aPointId = anIt->first.second;
+
+      *pIntData++ = aSectionId;
+      *pIntData++ = aPointId;
+      *pIntData++ = aNbCoords;
+
+      const CurveCreator::Coordinates &aCoords = anIt->second;
+      CurveCreator::TypeCoord *pRealData = (CurveCreator::TypeCoord *)pIntData;
+      for (int i = 0; i < aNbCoords; i++) {
+        *pRealData++ = aCoords[i];
+      }
+      pIntData = (int *)pRealData;
+    }
+
+    myType = theType;
+    isOK   = true;
+  }
+
+  return isOK;
+}
+
+bool CurveCreator_Operation::init(const CurveCreator_Operation::Type theType,
+                                  const CurveCreator_ICurve::SectionToPointList &theParamList1)
+{
+  bool isOK = false;
+
+  if (theType == CurveCreator_Operation::RemovePoints) {
+    const int aNbPoints = theParamList1.size();
+
+    CurveCreator_ICurve::SectionToPointList::const_iterator anIt = 
+      theParamList1.begin();
+
+    const size_t aSize =
+      sizeof(aNbPoints) +
+      aNbPoints * (2*sizeof(int));
+    int *pIntData = (int *)allocate(aSize);
+
+    *pIntData++ = aNbPoints;
+    int aSectionId, aPointId;
+    for ( ; anIt != theParamList1.end(); anIt++ ) {
+      aSectionId = anIt->first;
+      aPointId = anIt->second;
+
+      *pIntData++ = aSectionId;
+      *pIntData++ = aPointId;
+    }
+
+    myType = theType;
+    isOK   = true;
+  }
+
+  return isOK;
+}
+
 //=======================================================================
 // function: apply
 // purpose:
@@ -282,22 +364,48 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve)
     switch (myType) {
       case CurveCreator_Operation::AddPoints:
       case CurveCreator_Operation::InsertPoints:
+      case CurveCreator_Operation::SetCoordinates:
         {
+          int aSectionId, aPointId;
+          CurveCreator::SectionsMap aSectionsMap;
+          CurveCreator::PosPointsList aPoints;
           CurveCreator::Coordinates aCoords;
 
-          getCoords(&pInt[2], aCoords);
-          std::vector<int> anISections, anIPnts;
-          anISections.push_back( pInt[0] );
-          anIPnts.push_back( pInt[1] );
-          theCurve->addPointsInternal(aCoords, anISections, anIPnts);
+          int nbPoints = pInt[0];
+          int nbCoords = pInt[1];
+          int nbParams = 3+nbCoords;
+          for (int i = 0; i < nbPoints*nbParams; i=i+nbParams) {
+            aCoords.clear();
+            aPoints.clear();
+            getCoords(&pInt[4+i], aCoords);
+            aSectionId = pInt[2+i];
+            aPointId = pInt[3+i];
+            if ( aSectionsMap.find( aSectionId ) != aSectionsMap.end() )
+              aPoints = aSectionsMap[aSectionId];
+            CurveCreator_PosPoint* aPosPoint = new CurveCreator_PosPoint( aPointId, aCoords );
+            aPoints.push_back( aPosPoint );
+            aPoints.sort(compId);
+            aSectionsMap[aSectionId] = aPoints;
+          }
+          switch (myType) {
+            case CurveCreator_Operation::AddPoints:
+            case CurveCreator_Operation::InsertPoints:
+              theCurve->addPointsInternal( aSectionsMap );
+              break;
+            case CurveCreator_Operation::SetCoordinates:
+              theCurve->setPointInternal( aSectionsMap );
+              break;
+          }
         }
         break;
       case CurveCreator_Operation::RemovePoints:
         {
-          std::vector<int> anISections, anIPnts;
-          anISections.push_back( pInt[0] );
-          anIPnts.push_back( pInt[1] );
-          theCurve->removePointsInternal(anISections, anIPnts);
+          CurveCreator_ICurve::SectionToPointList aListOfSectionsToPoints;
+          int nbPoints = pInt[0];
+          for (int i = 1; i < nbPoints*2; i=i+2) {
+            aListOfSectionsToPoints.push_back(std::make_pair(pInt[i], pInt[i+1]));
+          }
+          theCurve->removePointsInternal(aListOfSectionsToPoints);
         }
         break;
       case CurveCreator_Operation::SetType:
@@ -310,14 +418,6 @@ void CurveCreator_Operation::apply(CurveCreator_Curve *theCurve)
       case CurveCreator_Operation::Clear:
         theCurve->clearInternal();
         break;
-      case CurveCreator_Operation::SetCoordinates:
-        {
-          CurveCreator::Coordinates aCoords;
-
-          getCoords(&pInt[2], aCoords);
-          theCurve->setPointInternal(pInt[0], pInt[1], aCoords);
-        }
-        break;
       case CurveCreator_Operation::SetClosed:
         theCurve->setClosedInternal((pInt[0] != 0), pInt[1]);
         break;
index 0c84c4689a89b28eb5efeb22fbc4cd5d0c487a66..be8ceef616e7c445f3e22a7f6da1d8d1b24a3402 100644 (file)
 #define _CurveCreator_Operation_HeaderFile
 
 #include "CurveCreator.hxx"
+#include "CurveCreator_ICurve.hxx"
+#include "CurveCreator_PosPoint.hxx"
 
 #include <string>
+#include <vector>
 
 class CurveCreator_Curve;
 
@@ -104,6 +107,18 @@ public:
   bool init(const Type theType, const int theIntParam1,
             const int theIntParam2);
 
+  /**
+   * This method initializes the object with an operation with 
+   * list of pairs of integer parameters. 
+   * It is applicable to the following operations:
+   * <UL>
+   *   <LI>RemovePoints</LI>
+   * </UL>
+   * @return true in case of success; false otherwise.
+   */
+  bool init(const Type theType, 
+    const CurveCreator_ICurve::SectionToPointList &theParamList1);
+
   /**
    * This method initializes the object with an operation with three integer
    * parameters. It is applicable to the following operations:
@@ -140,6 +155,17 @@ public:
    */
   bool init(const Type theType, const CurveCreator::Coordinates &theCoords,
             const int theIntParam1, const int theIntParam2);
+  /**
+   * This method initializes the object with an operation with
+   * list of pairs of integer parameters and CurveCreator::Coordinates parameters.
+   * It is applicable to the following operations:
+   * <UL>
+   *   <LI>InsertPoints</LI>
+   * </UL>
+   * @return true in case of success; false otherwise.
+   */
+  bool init(const Type theType, 
+            const CurveCreator_ICurve::SectionToPointCoordsList &theParamList1);
 
   /**
    * This method initializes the object with an operation with one
index b054e983fbdcb7ce31105719a243489e44eeb7d6..fa6ae3d15f4abf17413d12524e4b19425cea7b74 100644 (file)
@@ -75,8 +75,6 @@ const int POINT_INDEX_COLUMN_WIDTH = 40;
 
 const int SCENE_PIXEL_TOLERANCE = 10;
 
-//#define USE_SEVERAL_POINTS
-
 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
                                          CurveCreator_ICurve *theCurve,
                                          Qt::WindowFlags fl)
@@ -1026,26 +1024,7 @@ void CurveCreator_Widget::removePoint()
   SectionToPointList aSelPoints;
   startCurveModification( aSelPoints, false );
 
-#ifdef USE_SEVERAL_POINTS
   myCurve->removeSeveralPoints( aPoints );
-#else
-  // the points should be removed in a decreased order
-  QMap<int, QList<int> > aConvPoints;
-  convert( aPoints, aConvPoints );
-  QMap<int, QList<int> >::const_iterator anIt = aConvPoints.begin(),
-                                          aLast = aConvPoints.end();
-  for ( ; anIt != aLast; anIt++ ) {
-    int aSectionId = anIt.key();
-
-    QList<int> aSectionPoints = anIt.value();
-    qSort( aSectionPoints );
-    for( int i = aSectionPoints.size()-1; i >= 0; i-- ){
-      int aPntIndx = aSectionPoints[i];
-      myCurve->removePoint( aSectionId, aPntIndx );
-      mySectionView->pointsRemoved( aSectionId, aPntIndx );
-    }
-  }
-#endif
   finishCurveModification( SectionToPointList() );
 }
 
@@ -1150,13 +1129,8 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
       continue;
     aChangedPos[0] = aChangedPos[0] - aXDelta;
     aChangedPos[1] = aChangedPos[1] - anYDelta;
-#ifndef USE_SEVERAL_POINTS
-    myCurve->setPoint( anIt->first, anIt->second, aChangedPos );
-#endif
   }
-#ifdef USE_SEVERAL_POINTS
   myCurve->setSeveralPoints( aCoordList );
-#endif
 
   myDragged = true;
   finishCurveModification( myDragPoints );