From: mzn Date: Thu, 12 Dec 2013 13:30:11 +0000 (+0000) Subject: Bug #161: Undo operation works incorrect after drag the point. X-Git-Tag: BR_hydro_v_0_5~17 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=97c743a2841f1a7985dcbe9a8532ae94e0825f22;p=modules%2Fhydro.git Bug #161: Undo operation works incorrect after drag the point. --- diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.cxx b/src/HYDROCurveCreator/CurveCreator_Curve.cxx index 8e3a4328..a4f9947c 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.cxx @@ -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); } diff --git a/src/HYDROCurveCreator/CurveCreator_Curve.hxx b/src/HYDROCurveCreator/CurveCreator_Curve.hxx index ab073b7b..34ff73f3 100644 --- a/src/HYDROCurveCreator/CurveCreator_Curve.hxx +++ b/src/HYDROCurveCreator/CurveCreator_Curve.hxx @@ -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 ***/ /***********************************************/ diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.cxx b/src/HYDROCurveCreator/CurveCreator_Diff.cxx index 128deb7c..b2cecfd8 100644 --- a/src/HYDROCurveCreator/CurveCreator_Diff.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Diff.cxx @@ -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: diff --git a/src/HYDROCurveCreator/CurveCreator_Diff.hxx b/src/HYDROCurveCreator/CurveCreator_Diff.hxx index b94dadaf..fb69edf4 100644 --- a/src/HYDROCurveCreator/CurveCreator_Diff.hxx +++ b/src/HYDROCurveCreator/CurveCreator_Diff.hxx @@ -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. */ diff --git a/src/HYDROCurveCreator/CurveCreator_ICurve.hxx b/src/HYDROCurveCreator/CurveCreator_ICurve.hxx index 229256ce..a535dc65 100644 --- a/src/HYDROCurveCreator/CurveCreator_ICurve.hxx +++ b/src/HYDROCurveCreator/CurveCreator_ICurve.hxx @@ -152,7 +152,8 @@ public: const std::deque& 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 ***/ /***********************************************/ diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index c97f87c4..28f7c5b5 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -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 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; } diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h index ae382682..a5e8ba13 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -216,6 +216,7 @@ private: QPoint myDragStartPosition; int myDragInteractionStyle; CurveCreator_ICurve::SectionToPointList myDragPoints; + CurveCreator_ICurve::SectionToPointCoordsList myInitialDragPointsCoords; bool myDragged; QByteArray myGuiState; };