Salome HOME
17.12.2013. Added Partition algorithm (draft version).
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Widget.cxx
index 6961f01b44933e1707915be691da17cc9dcdd09f..a808b1406c1442132ca2f63ad7fd01e9a5813761 100644 (file)
@@ -719,7 +719,7 @@ void CurveCreator_Widget::onJoinAll()
   if( !myCurve )
     return;
   stopActionMode();
-  myCurve->join( 0, myCurve->getNbSections() );
+  myCurve->join( 0, myCurve->getNbSections()-1 );
   mySectionView->reset();
   updateActionsStates();
   updateUndoRedo();
@@ -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<CurveCreator_ICurve::SectionToPoint, std::deque< float > > 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;
@@ -1287,11 +1307,8 @@ void CurveCreator_Widget::updateLocalPointView()
 
   if ( !isRowLimit ) {
     bool isBlocked = myLocalPointView->blockSignals(true);
-    myLocalPointView->setRowCount( 0 );
-    CurveCreator_ICurve::SectionToPointList::const_iterator anIt = myLocalPoints.begin(),
-                                                            aLast = myLocalPoints.end();
-    for ( ; anIt != aLast; anIt++ )
-      myLocalPointView->addLocalPointToTable( *anIt );
+
+    myLocalPointView->setLocalPointsToTable( myLocalPoints );
 
     myLocalPointView->blockSignals( isBlocked );
   }