]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Bug #161: Undo operation works incorrect after drag the point.
authormzn <mzn@opencascade.com>
Thu, 12 Dec 2013 13:30:11 +0000 (13:30 +0000)
committermzn <mzn@opencascade.com>
Thu, 12 Dec 2013 13:30:11 +0000 (13:30 +0000)
src/HYDROCurveCreator/CurveCreator_Curve.cxx
src/HYDROCurveCreator/CurveCreator_Curve.hxx
src/HYDROCurveCreator/CurveCreator_Diff.cxx
src/HYDROCurveCreator/CurveCreator_Diff.hxx
src/HYDROCurveCreator/CurveCreator_ICurve.hxx
src/HYDROCurveCreator/CurveCreator_Widget.cxx
src/HYDROCurveCreator/CurveCreator_Widget.h

index 8e3a432827f0d91f158a97c411904e283382aa58..a4f9947cfb14327c7a7d95d8f730329b0f65f5df 100644 (file)
@@ -551,6 +551,20 @@ bool CurveCreator_Curve::canPointsBeSorted()
   return false;
 }
 
+/**
+ * Saves points coordinates difference.
+ * \param theOldCoords the old points coordinates
+ */
+void CurveCreator_Curve::saveCoordDiff( const SectionToPointCoordsList &theOldCoords )
+{
+  // Set the difference.
+  startOperation();
+  if (addEmptyDiff()) {
+    myListDiffs.back().init(this, theOldCoords);
+  }
+  finishOperation();
+}
+
 //! Get "closed" flag of the specified section
 bool CurveCreator_Curve::isClosed( const int theISection ) const
 {
@@ -806,12 +820,13 @@ bool CurveCreator_Curve::setPoint( const int theISection,
 }
 
 //! Set coordinates of specified points from different sections
-bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords)
+bool CurveCreator_Curve::setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
+                                           const bool theIsToSaveDiff )
 {
   bool res = false;
   // Set the difference.
   startOperation();
-  if (addEmptyDiff()) {
+  if (theIsToSaveDiff && addEmptyDiff()) {
     myListDiffs.back().init(this, CurveCreator_Operation::SetCoordinates,
                             theSectionToPntCoords);
   }
index ab073b7b0a7fd665a31b1d4fad8859c652e6d510..34ff73f3ca1957caaff80311ccfca36782e231eb 100644 (file)
@@ -228,7 +228,8 @@ public:
                          const CurveCreator::Coordinates& theNewCoords );
 
   //! Set coordinates of specified points from different sections
-  virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords);
+  virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
+                                 const bool theIsToSaveDiff = true );
 
   //! For internal use only! Undo/Redo are not used here.
   virtual bool removePointsInternal( const SectionToPointList &thePoints );
@@ -264,6 +265,12 @@ public:
    */
   virtual bool canPointsBeSorted();
 
+  /**
+   * Saves points coordinates difference.
+   * \param theOldCoords the old points coordinates
+   */
+  virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords );
+
   /***********************************************/
   /***       Presentation methods              ***/
   /***********************************************/
index 128deb7c10727e90b85192a5af5a90df032d2232..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:
index b94dadafbd106d6421b3701854408d0720b28b8f..fb69edf40042fea519138a32f20cfa952c4510a5 100644 (file)
@@ -166,6 +166,15 @@ public:
             const CurveCreator_Operation::Type theType,
             const CurveCreator_ICurve::SectionToPointCoordsList &theParamList);
 
+  /**
+   * This method initializes the difference with an operation with 
+   * list of pairs of integer parameters with point coordinates.
+   * \param theCurve the modified curve
+   * \param theOldParamList the old parameters (to be saved for undo)
+   */
+  bool init(const CurveCreator_Curve *theCurve,
+            const CurveCreator_ICurve::SectionToPointCoordsList &theOldParamList);
+
   /**
    * This method applies undo operation to theCurve.
    */
index 229256ce082e333c8e9d92b9fe42bd84886b871c..a535dc65a004086ba759689e4abedcb6a21b4583 100644 (file)
@@ -152,7 +152,8 @@ public:
                          const std::deque<float>& theNewCoords ) = 0;
   
   //! Set coordinates of specified points from different sections
-  virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords) = 0;
+  virtual bool setSeveralPoints( const SectionToPointCoordsList &theSectionToPntCoords,
+                                 const bool theIsToSaveDiff = true ) = 0;
 
   //! Remove point with given id
   virtual bool removePoint( const int theISection, const int theIPnt = -1 ) = 0;
@@ -184,6 +185,12 @@ public:
    */
   virtual bool canPointsBeSorted() = 0;
 
+  /**
+   * Saves points coordinates difference.
+   * \param theOldCoords the old points coordinates
+   */
+  virtual void saveCoordDiff( const SectionToPointCoordsList &theOldCoords ) = 0;
+
   /***********************************************/
   /***       Presentation methods              ***/
   /***********************************************/
index c97f87c4bef9278f73c27021a05155d11ce11909..28f7c5b5a3a523fe2bd7ea1719cb3780b6049952 100644 (file)
@@ -972,8 +972,11 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
   if ( myDragStarted ) {
     bool isDragged = myDragged;
     CurveCreator_ICurve::SectionToPointList aDraggedPoints;
-    if ( myDragged )
+    CurveCreator_ICurve::SectionToPointCoordsList anInitialDragPointsCoords;
+    if ( myDragged ) {
       aDraggedPoints = myDragPoints;
+      anInitialDragPointsCoords = myInitialDragPointsCoords;
+    }
 
     setDragStarted( false );
 
@@ -992,12 +995,12 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
           int aSectionId = anIt->first;
           int aPointId = anIt->second;
           std::deque<float> aPos = myCurve->getPoint( aSectionId, aPointId );
-    
+
           aCoordList.push_back(
             std::make_pair( std::make_pair( aSectionId, aPointId ), aPos ) );
         }
 
-        myCurve->setSeveralPoints( aCoordList );
+        myCurve->setSeveralPoints( aCoordList, false );
     
         finishCurveModification( aDraggedPoints );
       } else {
@@ -1008,6 +1011,9 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
           END_MEASURE_TIME( "drop" );
         }
       }
+
+      // Save drag difference
+      myCurve->saveCoordDiff( anInitialDragPointsCoords );
     }
   }
   else // check whether the segment is clicked an a new point should be added to the segment
@@ -1239,6 +1245,14 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
     aChangedPos = myCurve->getPoint( aSectionId, aPointId );
     if ( aChangedPos.size() < 2 )
       continue;
+
+    // Remember drag points coordinates
+    if ( !myDragged ) {
+      myInitialDragPointsCoords.push_back(
+        std::make_pair(std::make_pair( aSectionId, aPointId ), 
+                       aChangedPos ));
+    }
+
     aChangedPos[0] = aChangedPos[0] - aXDelta;
     aChangedPos[1] = aChangedPos[1] - anYDelta;
     
@@ -1246,7 +1260,7 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
       std::make_pair(std::make_pair( aSectionId, aPointId ), 
                      aChangedPos ));
   }
-  myCurve->setSeveralPoints( aCoordList );
+  myCurve->setSeveralPoints( aCoordList, false );
 
   myDragged = true;
   finishCurveModification( myDragPoints );
@@ -1311,6 +1325,7 @@ void CurveCreator_Widget::setDragStarted( const bool theState, const QPoint& the
       changeInteractionStyle( myDragInteractionStyle );
     myDragStarted = false;
     myDragPoints.clear();
+    myInitialDragPointsCoords.clear();
   }
   myDragged = false;
 }
index ae382682d7f84057a6c93f8619d3e4f1cfcfc2e8..a5e8ba136c99997d3c1f7835080697523112aeb7 100644 (file)
@@ -216,6 +216,7 @@ private:
   QPoint                      myDragStartPosition;
   int                         myDragInteractionStyle;
   CurveCreator_ICurve::SectionToPointList myDragPoints;
+  CurveCreator_ICurve::SectionToPointCoordsList myInitialDragPointsCoords;
   bool                        myDragged;
   QByteArray                  myGuiState;
 };