]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Multiple selection of cell edges
authorimn <imn@opencascade.com>
Tue, 26 Sep 2017 08:28:04 +0000 (11:28 +0300)
committerimn <imn@opencascade.com>
Tue, 26 Sep 2017 08:28:04 +0000 (11:28 +0300)
src/SVTK/SALOME_Actor.cxx

index eafd19747ba007a0da949ec9c543fabc5cb8381f..9082bea0828e09a8a18f8e97516f0e7964c02cdc 100644 (file)
@@ -84,9 +84,11 @@ int SALOME_LINE_WIDTH = 3;
 namespace
 {
   int
-  GetEdgeId(SALOME_Actor* theActor,
-            vtkPicker* thePicker, 
-            int theObjId)
+  GetEdgeAndNodesId(SALOME_Actor* theActor,
+                    vtkPicker* thePicker,
+                    int theObjId,
+                    int& theFirstNodeId,
+                    int& theSecondNodeId)
   {
     int anEdgeId = 0;
     if (vtkCell* aPickedCell = theActor->GetElemCell(theObjId)) {
@@ -104,6 +106,8 @@ namespace
           if (aDist < aMinDist) {
             aMinDist = aDist;
             anEdgeId = -1 - i;
+            theFirstNodeId = aSelEdge->GetPointId(0);
+            theSecondNodeId = aSelEdge->GetPointId(1);
           }
         }
       }
@@ -449,13 +453,10 @@ SALOME_Actor
       mySelector->GetIndex( getIO(), aMapIndex );
       switch( mySelectionMode ){
       case NodeSelection:
+      case EdgeOfCellSelection:
         myHighlightActor->GetProperty()->SetRepresentationToPoints();
         myHighlightActor->MapPoints( this, aMapIndex );
         break;
-      case EdgeOfCellSelection:
-        myHighlightActor->GetProperty()->SetRepresentationToWireframe();
-        myHighlightActor->MapEdge( this, aMapIndex );
-        break;
       case CellSelection:
       case EdgeSelection:
       case FaceSelection:
@@ -597,7 +598,8 @@ SALOME_Actor
       if ( aVtkId >= 0 && mySelector->IsValid( this, aVtkId )) {
         int anObjId = GetElemObjId( aVtkId );
         if ( anObjId >= 0 ) {
-          int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
+          int aFNId, aSNId;
+          int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
           myIsPreselected = anEdgeId < 0;
           if(myIsPreselected){
             const TColStd_IndexedMapOfInteger& aMapIndex = myPreHighlightActor->GetMapIndex();
@@ -789,6 +791,48 @@ SALOME_Actor
         }
       }
       
+      if ( hasIO() ) {
+        if( !anIndexes.IsEmpty() ) {
+          mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
+          mySelector->AddIObject( this );
+          anIndexes.Clear();
+        }
+        else if ( !anIsShift )
+          mySelector->RemoveIObject( this );
+      }
+      break;
+    }
+    case EdgeOfCellSelection:
+    {
+      SVTK::TPickLimiter aPickLimiter( myCellAreaPicker, this );
+      if( theSelectionEvent->myIsRectangle )
+        myCellAreaPicker->Pick( x1, y1, x2, y2, aRenderer, SVTK_AreaPicker::RectangleMode );
+      else if( theSelectionEvent->myIsPolygon )
+        myCellAreaPicker->Pick( theSelectionEvent->myPolygonPoints, aRenderer, SVTK_AreaPicker::PolygonMode );
+
+      const SVTK_AreaPicker::TVectorIdsMap& aVectorIdsMap = myCellAreaPicker->GetCellIdsMap();
+      SVTK_AreaPicker::TVectorIdsMap::const_iterator aMapIter = aVectorIdsMap.find(this);
+      TColStd_MapOfInteger anIndexes;
+      if(aMapIter != aVectorIdsMap.end()){
+        const SVTK_AreaPicker::TVectorIds& aVectorIds = aMapIter->second;
+        vtkIdType anEnd = aVectorIds.size();
+        for(vtkIdType anId = 0; anId < anEnd; anId++ ) {
+          int aCellId = aVectorIds[anId];
+          if ( !mySelector->IsValid( this, aCellId ) )
+            continue;
+
+          int anObjId = GetElemObjId( aCellId );
+          if( anObjId != -1 ) {
+            int aFNId, aSNId;
+            int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
+            if( anEdgeId < 0 ) {
+              anIndexes.Add(GetNodeObjId(aFNId));
+              anIndexes.Add(GetNodeObjId(aSNId));
+            }
+          }
+        }
+      }
+
       if ( hasIO() ) {
         if( !anIndexes.IsEmpty() ) {
           mySelector->AddOrRemoveIndex( myIO, anIndexes, anIsShift );
@@ -850,10 +894,21 @@ SALOME_Actor
       if( aVtkId >= 0 && mySelector->IsValid( this, aVtkId ) ) {
         int anObjId = GetElemObjId( aVtkId );
         if( anObjId >= 0 ) {
-          int anEdgeId = GetEdgeId(this,myCellPicker.GetPointer(),anObjId);
+          int aFNId, aSNId;
+          int anEdgeId = GetEdgeAndNodesId(this,myCellPicker.GetPointer(),anObjId,aFNId,aSNId);
           if( hasIO() && anEdgeId < 0 ) {
-            mySelector->AddOrRemoveIndex( myIO, anObjId, false );
-            mySelector->AddOrRemoveIndex( myIO, anEdgeId, true );
+               bool isFNSelected = mySelector->IsIndexSelected( myIO, GetNodeObjId(aFNId) );
+               bool isSNSelected = mySelector->IsIndexSelected( myIO, GetNodeObjId(aSNId) );
+               if ( isFNSelected == isSNSelected ) {
+              mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aFNId), anIsShift );
+              mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aSNId), true );
+               }
+               else if ( isFNSelected ) {
+                 mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aSNId), anIsShift );
+               }
+               else if ( isSNSelected ) {
+                 mySelector->AddOrRemoveIndex( myIO, GetNodeObjId(aFNId), anIsShift );
+               }
             mySelector->AddIObject( this );
           }
         }