From: mzn Date: Fri, 13 Dec 2013 11:03:46 +0000 (+0000) Subject: Fix fo bug: when move profile point and sorting - undo works incorrect (restore posit... X-Git-Tag: BR_hydro_v_0_5~4 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=501641315774cfc081c011e2b8af10281785b492;p=modules%2Fhydro.git Fix fo bug: when move profile point and sorting - undo works incorrect (restore position of another points, getting the point by ID). --- diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.cxx b/src/HYDROCurveCreator/CurveCreator_Widget.cxx index 6961f01b..5fdb921d 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.cxx +++ b/src/HYDROCurveCreator/CurveCreator_Widget.cxx @@ -977,7 +977,7 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven if ( myDragStarted ) { bool isDragged = myDragged; CurveCreator_ICurve::SectionToPointList aDraggedPoints; - CurveCreator_ICurve::SectionToPointCoordsList anInitialDragPointsCoords; + QMap> anInitialDragPointsCoords; if ( myDragged ) { aDraggedPoints = myDragPoints; anInitialDragPointsCoords = myInitialDragPointsCoords; @@ -986,7 +986,31 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven setDragStarted( false ); if ( aDraggedPoints.size() > 0 ) { + // Collect old coordinates of the dragged points + CurveCreator_ICurve::SectionToPointCoordsList anOldPoints; + foreach ( const CurveCreator_ICurve::SectionToPoint aSectionToPoint, anInitialDragPointsCoords.keys() ) { + CurveCreator::Coordinates aCoords = anInitialDragPointsCoords.value( aSectionToPoint ); + anOldPoints.push_back( std::make_pair( aSectionToPoint, aCoords ) ); + } + if ( myCurve->canPointsBeSorted() ) { + // Add old coordinates of the curve points (except the dragged points) to the list + for( int aSectionId = 0 ; aSectionId < myCurve->getNbSections() ; aSectionId++ ) { + CurveCreator::Coordinates aCoords; + for ( int aPointId = 0, aNb = myCurve->getNbPoints( aSectionId ); aPointId < aNb; aPointId++ ) { + aCoords = myCurve->getPoint( aSectionId, aPointId ); + if ( aCoords.size() < 2 ) { + continue; + } + + CurveCreator_ICurve::SectionToPoint aSectionToPoint = std::make_pair( aSectionId, aPointId ); + + if ( !anInitialDragPointsCoords.contains( aSectionToPoint ) ) { + anOldPoints.push_back( std::make_pair( aSectionToPoint, aCoords ) ); + } + } + } + // Apply points sorting CurveCreator_ICurve::SectionToPointList aPoints; startCurveModification( aPoints, false ); @@ -1010,15 +1034,13 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven finishCurveModification( aDraggedPoints ); } else { // if the drag of some points has happened, restore the drag selection - if ( aDraggedPoints.size() > 0 ) { - START_MEASURE_TIME; - setSelectedPoints( aDraggedPoints ); - END_MEASURE_TIME( "drop" ); - } + START_MEASURE_TIME; + setSelectedPoints( aDraggedPoints ); + END_MEASURE_TIME( "drop" ); } // Save drag difference - myCurve->saveCoordDiff( anInitialDragPointsCoords ); + myCurve->saveCoordDiff( anOldPoints ); } } else // check whether the segment is clicked an a new point should be added to the segment @@ -1253,9 +1275,7 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition, // Remember drag points coordinates if ( !myDragged ) { - myInitialDragPointsCoords.push_back( - std::make_pair(std::make_pair( aSectionId, aPointId ), - aChangedPos )); + myInitialDragPointsCoords.insert( std::make_pair( aSectionId, aPointId ), aChangedPos ); } aChangedPos[0] = aChangedPos[0] - aXDelta; diff --git a/src/HYDROCurveCreator/CurveCreator_Widget.h b/src/HYDROCurveCreator/CurveCreator_Widget.h index a5e8ba13..2d8a3e02 100644 --- a/src/HYDROCurveCreator/CurveCreator_Widget.h +++ b/src/HYDROCurveCreator/CurveCreator_Widget.h @@ -216,7 +216,7 @@ private: QPoint myDragStartPosition; int myDragInteractionStyle; CurveCreator_ICurve::SectionToPointList myDragPoints; - CurveCreator_ICurve::SectionToPointCoordsList myInitialDragPointsCoords; + QMap myInitialDragPointsCoords; bool myDragged; QByteArray myGuiState; };