Salome HOME
Ref #250 - Fatal error after Join all selections operation
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Widget.cxx
index 5fdb921d28de21b5c9065dfc83344833641964c2..e997fe69fe3fc1e9bab18fbe1ee083c040a3e9c2 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,17 @@ 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] );
+  }
+
+  if ( myCurve->join( aSectionsToJoin ) )
+  {
+    for( int i = 0, aSectionsSize = aSectionsToJoin.size(); i < aSectionsSize; i++ )
+      mySectionView->sectionsRemoved( i );
   }
-  int aNewSectSize = myCurve->getNbPoints(aMainSect);
-  if( aNewSectSize != aMainSectSize )
-    mySectionView->pointsAdded( aMainSect, aMainSectSize, aNewSectSize-aMainSectSize );
+
   updateUndoRedo();
 }
 
@@ -719,7 +712,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 +872,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 +971,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 +1118,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);
@@ -1174,7 +1155,6 @@ void CurveCreator_Widget::addNewPoint(const CurveCreator::Coordinates& theCoords
   }
   int aSection = aSections[0];
   myCurve->addPoints(theCoords, aSection); // add to the end of section
-  mySectionView->pointsAdded( aSection, myCurve->getNbPoints( aSection ) );
   updateActionsStates();
   updateUndoRedo();
 }
@@ -1237,7 +1217,6 @@ void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
     anInsertPos = aPoint1Id < aPoint2Id ? aPoint1Id + 1 : aPoint2Id + 1;
 
   myCurve->addPoints( aCoords, aSectionId, anInsertPos );
-  mySectionView->pointsAdded( aSectionId, myCurve->getNbPoints( aSectionId ) );
 
   finishCurveModification( aSelPoints );
 
@@ -1307,11 +1286,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 );
   }