Salome HOME
Fix JoinAll operation
[modules/hydro.git] / src / HYDROCurveCreator / CurveCreator_Widget.cxx
index 3cf3975e1ea1cb802678b31ea8431805548cf452..511810438fad8014df53312582e487d0e477eda9 100644 (file)
@@ -75,8 +75,6 @@ const int POINT_INDEX_COLUMN_WIDTH = 40;
 
 const int SCENE_PIXEL_TOLERANCE = 10;
 
-//#define USE_SEVERAL_POINTS
-
 CurveCreator_Widget::CurveCreator_Widget(QWidget* parent,
                                          CurveCreator_ICurve *theCurve,
                                          Qt::WindowFlags fl)
@@ -573,9 +571,14 @@ void CurveCreator_Widget::onModifySection()
   bool isClosed = myNewSectionEditor->isClosed();
   CurveCreator::SectionType aSectType = myNewSectionEditor->getSectionType();
 //  myCurve->startOperation();
-  myCurve->setClosed( isClosed, mySection );
-  myCurve->setSectionName( mySection , aName.toStdString() );
-  myCurve->setSectionType( mySection, aSectType );
+  if( myCurve->getSectionName(mySection) != aName.toStdString() )
+    myCurve->setSectionName( mySection , aName.toStdString() );
+
+  if( myCurve->getSectionType(mySection) != aSectType )
+    myCurve->setSectionType( mySection, aSectType );
+
+  if( myCurve->isClosed(mySection) != isClosed )
+    myCurve->setClosed( mySection, isClosed );
 //  myCurve->finishOperation();
   mySectionView->sectionChanged(mySection);
   updateUndoRedo();
@@ -708,7 +711,7 @@ void CurveCreator_Widget::onCloseSections()
 //  myCurve->startOperation();
   QList<int> aSelSections = mySectionView->getSelectedSections();
   for( int i = 0 ; i < aSelSections.size() ; i++ ){
-    myCurve->setClosed(true, aSelSections[i]);
+    myCurve->setClosed(aSelSections[i], true);
     mySectionView->sectionChanged(aSelSections[i]);
   }
 //  myCurve->finishOperation();
@@ -722,7 +725,7 @@ void CurveCreator_Widget::onUncloseSections()
 //  myCurve->startOperation();
   QList<int> aSelSections = mySectionView->getSelectedSections();
   for( int i = 0 ; i < aSelSections.size() ; i++ ){
-    myCurve->setClosed(false, aSelSections[i]);
+    myCurve->setClosed(aSelSections[i], false);
     mySectionView->sectionChanged(aSelSections[i]);
   }
 //  myCurve->finishOperation();
@@ -739,7 +742,6 @@ void CurveCreator_Widget::onUndo()
     myCurve->undo();
     finishCurveModification();
     mySectionView->reset();
-    updateUndoRedo();
 }
 
 void CurveCreator_Widget::onRedo()
@@ -751,7 +753,6 @@ void CurveCreator_Widget::onRedo()
     myCurve->redo();
     finishCurveModification();
     mySectionView->reset();
-    updateUndoRedo();
 }
 
 void CurveCreator_Widget::updateUndoRedo()
@@ -1026,26 +1027,7 @@ void CurveCreator_Widget::removePoint()
   SectionToPointList aSelPoints;
   startCurveModification( aSelPoints, false );
 
-#ifdef USE_SEVERAL_POINTS
   myCurve->removeSeveralPoints( aPoints );
-#else
-  // the points should be removed in a decreased order
-  QMap<int, QList<int> > aConvPoints;
-  convert( aPoints, aConvPoints );
-  QMap<int, QList<int> >::const_iterator anIt = aConvPoints.begin(),
-                                          aLast = aConvPoints.end();
-  for ( ; anIt != aLast; anIt++ ) {
-    int aSectionId = anIt.key();
-
-    QList<int> aSectionPoints = anIt.value();
-    qSort( aSectionPoints );
-    for( int i = aSectionPoints.size()-1; i >= 0; i-- ){
-      int aPntIndx = aSectionPoints[i];
-      myCurve->removePoint( aSectionId, aPntIndx );
-      mySectionView->pointsRemoved( aSectionId, aPntIndx );
-    }
-  }
-#endif
   finishCurveModification( SectionToPointList() );
 }
 
@@ -1118,7 +1100,6 @@ void CurveCreator_Widget::insertPointToSelectedSegment( const int theX,
   finishCurveModification( aSelPoints );
 
   setSelectedPonts();
-  updateUndoRedo();
 }
 
 void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
@@ -1145,18 +1126,19 @@ void CurveCreator_Widget::moveSelectedPoints( const int theXPosition,
   std::deque<float> aChangedPos;
   SectionToPointList::const_iterator anIt = myDragPoints.begin(), aLast = myDragPoints.end();
   for ( ; anIt != aLast; anIt++ ) {
-    aChangedPos = myCurve->getPoint( anIt->first, anIt->second );
+    int aSectionId = anIt->first;
+    int aPointId = anIt->second;
+    aChangedPos = myCurve->getPoint( aSectionId, aPointId );
     if ( aChangedPos.size() < 2 )
       continue;
     aChangedPos[0] = aChangedPos[0] - aXDelta;
     aChangedPos[1] = aChangedPos[1] - anYDelta;
-#ifndef USE_SEVERAL_POINTS
-    myCurve->setPoint( anIt->first, anIt->second, aChangedPos );
-#endif
+    
+    aCoordList.push_back(
+      std::make_pair(std::make_pair( aSectionId, aPointId ), 
+                     aChangedPos ));
   }
-#ifdef USE_SEVERAL_POINTS
   myCurve->setSeveralPoints( aCoordList );
-#endif
 
   myDragged = true;
   finishCurveModification( myDragPoints );
@@ -1361,31 +1343,38 @@ void CurveCreator_Widget::setSelectedPonts( const CurveCreator_Widget::SectionTo
 
   AIS_ListOfInteractive aDisplayedList;
   ic->DisplayedObjects( aDisplayedList );
-  for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
-  {
-    Handle(AIS_InteractiveObject) anAIS = it.Value();
-    if ( anAIS.IsNull() )
-      continue;
-    Handle(AIS_Point) anAISPoint = Handle(AIS_Point)::DownCast( anAIS );
-    if ( anAISPoint.IsNull() )
-      continue;
 
-    TopoDS_Vertex aVertex = TopoDS::Vertex( anAISPoint->Vertex() );
+  SectionToPointList::const_iterator anIt = thePoints.begin(), aLast = thePoints.end();
+  SectionToPoint aSToPoint;
+  for( ; anIt != aLast; anIt++ ) {
+    aSToPoint = *anIt;
+
+    for ( AIS_ListIteratorOfListOfInteractive it( aDisplayedList ); it.More(); it.Next() )
+    {
+      Handle(AIS_InteractiveObject) anAIS = it.Value();
+      if ( anAIS.IsNull() )
+        continue;
+      Handle(AIS_Point) anAISPoint = Handle(AIS_Point)::DownCast( anAIS );
+      if ( anAISPoint.IsNull() )
+        continue;
 
-    if ( aVertex.IsNull() )
-      continue;
+      TopoDS_Vertex aVertex = TopoDS::Vertex( anAISPoint->Vertex() );
 
-    gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
+      if ( aVertex.IsNull() )
+        continue;
+
+      gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
 
-    SectionToPointList aPoints;
-    findSectionsToPoints( aPnt.X(), aPnt.Y(), aPoints );
+      SectionToPointList aPoints;
+      findSectionsToPoints( aPnt.X(), aPnt.Y(), aPoints );
 
-    SectionToPointList::const_iterator anIt = aPoints.begin(), aLast = aPoints.end();
-    SectionToPoint aPoint;
-    for ( ; anIt != aLast; anIt++ ) {
-      aPoint = *anIt;
-      if ( contains( thePoints, aPoint ) )
-        aListToSelect.Append( anAIS );
+      SectionToPointList::const_iterator anIt = aPoints.begin(), aLast = aPoints.end();
+      SectionToPoint aPoint;
+      for ( ; anIt != aLast; anIt++ ) {
+        aPoint = *anIt;
+        if ( aPoint.first == aSToPoint.first && aPoint.second == aSToPoint.second )
+          aListToSelect.Append( anAIS );
+      }
     }
   }
 
@@ -1425,6 +1414,7 @@ void CurveCreator_Widget::finishCurveModification(
   if ( getActionMode() == ModificationMode )
     setLocalPointContext( true );
   setSelectedPonts( thePoints );
+  updateUndoRedo();
 }
 
 /**