Salome HOME
A fix for a refs #266 - Point insertion in a polyline with type spline
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Widget.cxx
index 72d7ffa7e52de76a9e9dc41dd18f229f2dfb66df..5880c724cfd95d825ec0d82840614a76c23b6acc 100644 (file)
@@ -343,7 +343,6 @@ void CurveCreator_Widget::updateActionsStates()
     if ( removeEnabled() )
       anEnabledAct << REMOVE_ID;
     QList<int> aSelSections = mySectionView->getSelectedSections();
-    QList< QPair< int, int > > aSelPoints = mySectionView->getSelectedPoints();
     CurveCreator_TreeView::SelectionType aSelType = mySectionView->getSelectionType();
     switch( aSelType ){
     case CurveCreator_TreeView::ST_NOSEL:{
@@ -455,13 +454,6 @@ void CurveCreator_Widget::onAdditionMode(bool checked)
   if( aSelSection.size() > 0 ){
     mySection = aSelSection[0];
   }
-  else{
-    QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
-    if( aSelPoints.size() > 0 ){
-      mySection = aSelPoints[0].first;
-      myPointNum = aSelPoints[0].second + 1;
-    }
-  }
 //  emit subOperationStarted( myNewPointEditor );
 }
 
@@ -673,16 +665,26 @@ void CurveCreator_Widget::onJoin()
   }
   stopActionMode();
 
-  int aMainSect = aSections[0];
-  int aMainSectSize = myCurve->getNbPoints(aMainSect);
-  for( int i = 1 ; i < aSections.size() ; i++ ){
-    int aSectNum = aSections[i] - (i-1);
-    myCurve->join( aMainSect, aSectNum );
-    mySectionView->sectionsRemoved( aSectNum );
+  std::list<int> aSectionsToJoin;
+  for( int i = 0; i < aSections.size() ; i++ ){
+    aSectionsToJoin.push_back( aSections[i] );
+  }
+  //int aMainSect = aSectionsToJoin.front();
+  //int aMainSectSize = myCurve->getNbPoints(aMainSect);
+  if ( myCurve->join( aSectionsToJoin ) )
+  {
+    std::list<int>::const_iterator anIt = aSectionsToJoin.begin(),
+                                   aLast = aSectionsToJoin.end();
+    // the first section should be skipped. It is not removed, but is modified
+    anIt++;
+    for ( ; anIt != aLast; anIt++ )
+      mySectionView->sectionsRemoved( *anIt );
   }
+
+  /* The update for the points of the main section
   int aNewSectSize = myCurve->getNbPoints(aMainSect);
   if( aNewSectSize != aMainSectSize )
-    mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
+    mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );*/
   updateUndoRedo();
 }
 
@@ -719,7 +721,13 @@ void CurveCreator_Widget::onJoinAll()
   if( !myCurve )
     return;
   stopActionMode();
-  myCurve->join( 0, myCurve->getNbSections() );
+
+  std::list<int> aSectionsToJoin;
+  for( int i = 0, aNb = myCurve->getNbSections(); i < aNb ; i++ ){
+    aSectionsToJoin.push_back( i );
+  }
+  bool aRes = myCurve->join( aSectionsToJoin );
+
   mySectionView->reset();
   updateActionsStates();
   updateUndoRedo();
@@ -873,11 +881,6 @@ QList<int> CurveCreator_Widget::getSelectedSections()
   return mySectionView->getSelectedSections();
 }
 
-QList< QPair< int, int > > CurveCreator_Widget::getSelectedPoints()
-{
-  return mySectionView->getSelectedPoints();
-}
-
 /**
  * According to the widget state, performs the remove action
  */
@@ -977,7 +980,7 @@ void CurveCreator_Widget::onMouseRelease( SUIT_ViewWindow*, QMouseEvent* theEven
   if ( myDragStarted ) {
     bool isDragged = myDragged;
     CurveCreator_ICurve::SectionToPointList aDraggedPoints;
-    QMap<CurveCreator_ICurve::SectionToPoint, std::deque< float >> anInitialDragPointsCoords;
+    QMap<CurveCreator_ICurve::SectionToPoint, std::deque< float > > anInitialDragPointsCoords;
     if ( myDragged ) {
       aDraggedPoints = myDragPoints;
       anInitialDragPointsCoords = myInitialDragPointsCoords;
@@ -1124,19 +1127,6 @@ void CurveCreator_Widget::removeSection()
 {
   stopActionMode();
 
-  QList< QPair<int,int> > aSelPoints = mySectionView->getSelectedPoints();
-  int aCurrSect=-1;
-  int aRemoveCnt = 0;
-  for( int i = 0 ; i < aSelPoints.size() ; i++ ){
-    if( aCurrSect != aSelPoints[i].first ){
-      aRemoveCnt = 0;
-      aCurrSect = aSelPoints[i].first;
-    }
-    int aPntIndx = aSelPoints[i].second - aRemoveCnt;
-    myCurve->removePoint( aCurrSect, aPntIndx );
-    mySectionView->pointsRemoved( aCurrSect, aPntIndx );
-    aRemoveCnt++;
-  }
   QList<int> aSections = mySectionView->getSelectedSections();
   for( int i = 0 ; i < aSections.size() ; i++ ){
     int aSectNum = aSections[i] - (i);
@@ -1213,6 +1203,7 @@ void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
   CurveCreator_ICurve::SectionToPointList::const_iterator anIt = aPoints1.begin(),
                                                           aLast = aPoints1.end();
   int aSectionId = -1;
+  // find the indices of the neighbour point
   // there can be a case when a new point is added into two sections
   int aPoint1Id = -1, aPoint2Id = -1;
   for ( ; anIt != aLast && aSectionId < 0; anIt++ ) {