Salome HOME
Implementation multiple selection of 'Edge of Cell' functionality.
authorrnv <rnv@opencascade.com>
Thu, 28 Sep 2017 16:08:18 +0000 (19:08 +0300)
committerrnv <rnv@opencascade.com>
Thu, 5 Oct 2017 07:04:16 +0000 (10:04 +0300)
src/OBJECT/SMESH_Actor.cxx
src/OBJECT/SMESH_ActorDef.h
src/OBJECT/SMESH_DeviceActor.cxx
src/OBJECT/SMESH_DeviceActor.h
src/SMESHGUI/SMESHGUI_SingleEditDlg.cxx
src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx
src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h
src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i

index 5c2e918ab00908321c1b5a94d495cea394842f48..7159bc19763bbb3b6ae0456b6bcacf2f69dc1869 100644 (file)
@@ -1429,6 +1429,10 @@ double* SMESH_ActorDef::GetNodeCoord(int theObjID)
   return myPickableActor->GetNodeCoord(theObjID);
 }
 
+int SMESH_ActorDef::GetNodeVtkId(int theObjID)
+{
+  return myPickableActor->GetNodeVtkId(theObjID);
+}
 
 int SMESH_ActorDef::GetElemObjId(int theVtkID)
 {
index 4366a98a6c87264dd18a4af04def9e5dfe2df2db..746b5b76f504599d20e2745bdffddffbc3c61439 100644 (file)
@@ -150,6 +150,7 @@ class SMESH_ActorDef : public SMESH_Actor
 
   virtual int GetNodeObjId(int theVtkID);
   virtual double* GetNodeCoord(int theObjID);
+  virtual int GetNodeVtkId(int theObjID);
 
   virtual int GetElemObjId(int theVtkID);
   virtual vtkCell* GetElemCell(int theObjID);
index 2f6ccd06f0044e7a26e03d7b5a87c80db50f26f9..3f4b78d818e9e90b6257d7837c4ee1a15a58feee 100644 (file)
@@ -860,6 +860,12 @@ SMESH_DeviceActor
   return aCoord;
 }
 
+int
+SMESH_DeviceActor
+::GetNodeVtkId(int theObjID) 
+{
+  return myVisualObj->GetNodeVTKId(theObjID);
+}
 
 int
 SMESH_DeviceActor
index 1b8ceb48ebe216b8bca4876a5c0628dd8e6fae6c..30d7c8c42fad16257bb7734e0243be1b8325e84e 100644 (file)
@@ -70,6 +70,7 @@ class SMESHOBJECT_EXPORT SMESH_DeviceActor: public vtkLODActor{
 
   virtual int GetNodeObjId(int theVtkID);
   virtual double* GetNodeCoord(int theObjID);
+  virtual int GetNodeVtkId(int theObjID);
 
   virtual int GetElemObjId(int theVtkID);
   virtual vtkCell* GetElemCell(int theObjID);
index 08424f6d49a6d91fe65eae2ac847c5092df9ecf9..3a5e9227ae8e6dd25213c0fbd236a2a5a931259c 100755 (executable)
@@ -22,6 +22,9 @@
 
 // File   : SMESHGUI_SingleEditDlg.cxx
 // Author : Sergey LITONIN, Open CASCADE S.A.S.
+
+#include <SVTK_Selector.h>
+
 // SMESH includes
 //
 #include "SMESHGUI_SingleEditDlg.h"
@@ -42,7 +45,6 @@
 #include <SUIT_Desktop.h>
 #include <SUIT_Session.h>
 
-#include <SVTK_Selector.h>
 #include <SVTK_ViewWindow.h>
 #include <SALOME_ListIO.hxx>
 
@@ -347,9 +349,9 @@ void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
       aList.Append(anIO);
       mySelectionMgr->setSelectedObjects(aList,false);
       
-      TColStd_IndexedMapOfInteger selectedIndices;
-      TColStd_MapOfInteger newIndices;
-      mySelector->GetIndex(anIO,selectedIndices);
+      SVTK_IndexedMapOfIds selectedIndices;
+      SVTK_ListOfInteger newIndices;
+      mySelector->GetCompositeIndex(anIO,selectedIndices);
 
       int id1, id2;
       if ( !getNodeIds(myEdge->text(), id1, id2) )
@@ -367,25 +369,13 @@ void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
 
       if ( findTriangles(aNode1,aNode2,tria1,tria2) )
       {
-        newIndices.Add(tria1->GetID());
-
-        const SMDS_MeshNode* a3Nodes[3];
-        SMDS_ElemIteratorPtr it;
-        int edgeInd = 2, i;
-        for (i = 0, it = tria1->nodesIterator(); it->more(); i++) {
-          a3Nodes[ i ] = static_cast<const SMDS_MeshNode*>(it->next());
-          if (i > 0 && ( (a3Nodes[ i ] == aNode1 && a3Nodes[ i - 1] == aNode2) ||
-                         (a3Nodes[ i ] == aNode2 && a3Nodes[ i - 1] == aNode1) ) ) {
-            edgeInd = i - 1;
-            break;
-          }
-        }
-        newIndices.Add(-edgeInd-1);
+       newIndices.push_back( aNode1->GetID() );
+       newIndices.push_back( aNode2->GetID() );
         
         myOkBtn->setEnabled(true);
         myApplyBtn->setEnabled(true);
       }
-      mySelector->AddOrRemoveIndex(anIO,newIndices, false);
+      mySelector->AddOrRemoveCompositeIndex(anIO, newIndices, false);
       SMESH::GetViewWindow(mySMESHGUI)->highlight( anIO, true, true );
     }
   }
@@ -420,7 +410,17 @@ void SMESHGUI_SingleEditDlg::onSelectionDone()
     if(SMDS_Mesh* aMesh = aVisualObj->GetMesh())
     {
       const SMDS_MeshElement* tria[2];
-      if( SMESH::GetEdgeNodes( mySelector, aVisualObj, anId1, anId2 ) >= 1 &&
+      
+      bool valid = false;      
+      SVTK_IndexedMapOfIds anIds;
+      mySelector->GetCompositeIndex(anIO,anIds);
+      if( anIds.Extent() == 1 && anIds(1).size() == 2 ) {
+       anId1 = anIds(1)[0];
+       anId2 = anIds(1)[1];
+       valid = true;
+      }
+             
+      if( valid &&
           findTriangles( aMesh->FindNode( anId1 ), aMesh->FindNode( anId2 ), tria[0],tria[1] ) )
       {
         QString aText = QString("%1-%2").arg(anId1).arg(anId2);
@@ -523,6 +523,7 @@ bool SMESHGUI_SingleEditDlg::onApply()
   // update actor
   if (aResult) {
     mySelector->ClearIndex();
+    mySelector->ClearCompositeIndex();
     mySelectionMgr->setSelectedObjects(aList, false);
     onSelectionDone();
     SMESH::UpdateView();
index cb9e5ae6f2aa451946bfd215712a7783f95e9a14..f9527fbb8c7c8a2d47cab26d33240d5354f03b59 100644 (file)
@@ -24,6 +24,7 @@
 //
 #include "libSMESH_Swig.h"
 
+#include <SVTK_Selector.h>
 
 #include <SMESHGUI.h>
 #include <SMESHGUI_Utils.h>
@@ -49,6 +50,7 @@
 #include <SalomeApp_Application.h>
 #include <LightApp_SelectionMgr.h>
 #include <SVTK_RenderWindowInteractor.h>
+#include <VTKViewer_Algorithm.h>
 
 // OCCT includes
 #include <TopAbs.hxx>
 #include CORBA_SERVER_HEADER(SMESH_Gen)
 #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
 
+// VTK includes
+#include <vtkActorCollection.h>
+#include <vtkRenderer.h>
+
 static CORBA::ORB_var anORB;
 
 namespace
@@ -755,17 +761,18 @@ public:
   {}
   virtual void Execute()
   {
-    SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
-    if( !aSMESHGUI ) 
-      return;
     
-    LightApp_SelectionMgr* selMgr = SMESH::GetSelectionMgr( aSMESHGUI );
+    LightApp_SelectionMgr* selMgr = 0;
+    SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+    if( anApp )
+      selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
+
     if( !selMgr )
       return;
     
     selMgr->clearFilters();
 
-    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
     if(!aViewWindow)
       return;
 
@@ -819,30 +826,225 @@ void SMESH_Swig::select( const char* id, int id1, bool append ) {
   ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
 }
 
+/*!
+  \brief Helper class for selection edges of cell event
+*/
+class TSelectListOfPairEvent: public SALOME_Event
+{
+  const char*                        myId;
+  std::vector<std::pair<int, int> >  myIdsList;
+  bool                               myIsAppend;
+
+public:
+  TSelectListOfPairEvent(const char* id, std::vector<std::pair<int, int> > ids, bool append) :
+    myId(id),
+    myIdsList(ids),
+    myIsAppend(append)
+  {}
+  virtual void Execute()
+  {
+    
+    LightApp_SelectionMgr* selMgr = 0;
+    SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>( SUIT_Session::session()->activeApplication() );
+    if( anApp )
+      selMgr = dynamic_cast<LightApp_SelectionMgr*>( anApp->selectionMgr() );
+
+    if( !selMgr )
+      return;
+    
+    selMgr->clearFilters();
+
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
+    if(!aViewWindow)
+      return;
+
+    SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
+    
+    if (!anActor || !anActor->hasIO())
+      return;
+    
+    Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
+    SALOME_ListIO aList;
+    aList.Append(anIO);
+    selMgr->setSelectedObjects(aList, false);
+
+    if ( aViewWindow->SelectionMode() !=  EdgeOfCellSelection ) {
+      return;
+    }
+        
+    SVTK_IndexedMapOfIds aMap;
+    std::vector<std::pair<int, int> >::const_iterator anIter;
+    for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
+      std::vector<int> aCompositeId;
+      aCompositeId.push_back((*anIter).first);
+      aCompositeId.push_back((*anIter).second);
+      aMap.Add(aCompositeId);
+    }
+
+    // Set new selection
+    SVTK_Selector* aSelector  = aViewWindow->GetSelector();
+    aSelector->AddOrRemoveCompositeIndex(anIO, aMap, myIsAppend);
+    aViewWindow->highlight( anIO, true, true );
+    aViewWindow->GetInteractor()->onEmitSelectionChanged();
+  }
+};
+
+/*!
+  \brief Select the elements on the mesh, sub-mesh or group.
+  \param id object entry
+  \param ids list of the element ids
+  \param mode selection mode
+*/
+void SMESH_Swig::select( const char* id, std::vector<std::pair<int,int> > ids, bool append ) {
+  ProcessVoidEvent( new TSelectListOfPairEvent( id, ids, append ) );
+}
 
 class TGetSelectionModeEvent : public SALOME_Event
 {
 public:
-  typedef int TResult;
+  typedef SelectionMode TResult;
   TResult myResult;
-  TGetSelectionModeEvent() : myResult( -1 ) {}
+  TGetSelectionModeEvent() : myResult( Undefined ) {}
   virtual void Execute()
   {
-    SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
-    if( !aSMESHGUI ) 
-      return;
-
-    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( );
     if(!aViewWindow)
       return;
     
-    myResult = aViewWindow->SelectionMode();
+    myResult = (SelectionMode) aViewWindow->SelectionMode();
   }
 };
 
 /*!
   \brief Get selection mode of the active VTK View window.
 */
-int SMESH_Swig::getSelectionMode() {
+SelectionMode SMESH_Swig::getSelectionMode() {
   return ProcessEvent( new TGetSelectionModeEvent() );
 }
+
+
+/*!
+ * Event to set selection mode
+*/
+class TSetSelectionModeEvent : public SALOME_Event
+{
+  SelectionMode mySelectionMode;
+
+public:
+
+  TSetSelectionModeEvent(const SelectionMode selectionMode) :
+    mySelectionMode(selectionMode) 
+  {}
+
+  virtual void Execute()
+  {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
+    if(!aViewWindow)
+      return;
+
+    Selection_Mode prevMode = aViewWindow->SelectionMode();
+    bool changePointRepresentation = ( prevMode == NodeSelection && mySelectionMode != Node ) ||
+      (prevMode != NodeSelection && mySelectionMode == Node);
+      
+    if( changePointRepresentation ) {
+      vtkRenderer *aRenderer = aViewWindow->getRenderer();
+      VTK::ActorCollectionCopy aCopy(aRenderer->GetActors());
+      vtkActorCollection *aCollection = aCopy.GetActors();
+      aCollection->InitTraversal();
+      while(vtkActor *anAct = aCollection->GetNextActor()){
+       if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
+         if(anActor->GetVisibility()){
+           anActor->SetPointRepresentation(mySelectionMode == Node);
+         }
+       }
+      }
+    }
+    aViewWindow->SetSelectionMode(mySelectionMode);
+  }
+};
+
+void SMESH_Swig::setSelectionMode(SelectionMode selectionMode){
+  ProcessVoidEvent( new TSetSelectionModeEvent( selectionMode ) ); 
+}
+
+class TGetSelectedEvent : public SALOME_Event
+{
+public:
+  typedef std::vector<int> TResult;
+  TResult myResult;
+  const char* myId;
+  
+  TGetSelectedEvent( const char* id) : 
+    myResult( std::vector<int>() ),
+    myId(id)
+  {}
+  
+  virtual void Execute()
+  {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
+    if( !aViewWindow )
+      return;
+
+    SVTK_Selector* aSelector  = aViewWindow->GetSelector();    
+    if( !aSelector )
+      return;
+
+    SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
+    
+    if ( !anActor || !anActor->hasIO() )
+      return;
+
+    TColStd_IndexedMapOfInteger aMapIndex;
+    aSelector->GetIndex(anActor->getIO(),aMapIndex);
+
+    for( int i = 1; i <= aMapIndex.Extent(); i++ )
+      myResult.push_back( aMapIndex( i ) );
+  }
+};
+
+std::vector<int> SMESH_Swig::getSelected( const char* Mesh_Entry ) {
+  return ProcessEvent( new TGetSelectedEvent(Mesh_Entry) );
+}
+
+class TGetSelectedPairEvent : public SALOME_Event
+{
+public:
+  typedef std::vector<std::pair<int, int> > TResult;
+  TResult myResult;
+  const char* myId;
+  
+  TGetSelectedPairEvent( const char* id) : 
+    myResult( std::vector<std::pair<int,int> >() ),
+    myId(id)
+  {}
+  
+  virtual void Execute()
+  {
+    SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
+    if( !aViewWindow )
+      return;
+
+    if(aViewWindow->SelectionMode() != EdgeOfCellSelection )
+      return;
+
+    SVTK_Selector* aSelector  = aViewWindow->GetSelector();    
+    if( !aSelector )
+      return;
+
+    SMESH_Actor* anActor = SMESH::FindActorByEntry( myId );
+    
+    if ( !anActor || !anActor->hasIO() )
+      return;
+
+    SVTK_IndexedMapOfIds aMapIndex;
+    aSelector->GetCompositeIndex(anActor->getIO(),aMapIndex);
+
+    for( int i = 1; i <= aMapIndex.Extent(); i++ )
+      myResult.push_back( std::make_pair<int,int>( (int)aMapIndex( i )[0], (int)aMapIndex( i )[1]) );
+  }
+};
+
+std::vector<std::pair<int,int> > SMESH_Swig::getSelectedEdgeOfCell( const char* Mesh_Entry ) {
+  return ProcessEvent( new TGetSelectedPairEvent(Mesh_Entry) );
+}
+
index c6c948fcf37e2b2b41db4b90d98f1a9b1183f225..f6cde69485b393271817ac8114656b37d31a96ed 100644 (file)
 
 //std includes
 #include <vector>
+#include <utility>
 
 #include <SVTK_Selection.h>
 
 #include <SVTK_Selection.h>
 
-enum
+typedef enum
   {
+    Undefined  = -1,
     Node       = NodeSelection,
     Cell       = CellSelection,
     EdgeOfCell = EdgeOfCellSelection,
@@ -56,7 +58,7 @@ enum
     Actor      = ActorSelection,
     Elem0D     = Elem0DSelection,
     Ball       = BallSelection
-  };
+  } SelectionMode;
 
 class SMESH_SWIG_EXPORT SMESH_Swig
 {
@@ -94,10 +96,15 @@ public:
    */
   void                       SetMeshIcon( const char*, const bool, const bool );
 
+  void setSelectionMode( SelectionMode selectionMode );
+  std::vector<int> getSelected( const char* Mesh_Entry );
+  std::vector<std::pair<int, int> > getSelectedEdgeOfCell( const char* Mesh_Entry );
+
   // --------------------- for the test purposes -----------------------
-  int  getSelectionMode();
+  SelectionMode getSelectionMode();
   void select( const char *id, std::vector<int> ids, bool append = false );
   void select( const char *id, int id1, bool append = false );
+  void select( const char *id, std::vector<std::pair<int,int> >, bool apend = false );
 
 private:
   SALOMEDS::Study_var        myStudy;
index 73c08a5f1efc1faa930b6784887641c84a937496..5f66f9f21011d7b066c187bc43bc681de1c238bf 100644 (file)
 
 %include "typemaps.i"
 %include "std_vector.i"
+%include "std_pair.i"
 
 namespace std {
+  
     %template(VectorInt) vector<int>;
+    %template() std::pair<int,int>;
+    %template(PairVector) std::vector<std::pair<int,int> >;
 };
 
 
 /* Selection mode enumeration (corresponds to constants from the SALOME_Selection.h) */
-enum
+enum SelectionMode
   {
-    Node,
+    Undefined = -1,
+    Node = 0,
     Cell,
     EdgeOfCell,
     Edge,
@@ -97,9 +102,14 @@ class SMESH_Swig
   void CreateAndDisplayActor( const char* Mesh_Entry );
   void EraseActor( const char* Mesh_Entry, const bool allViewers = false );
 
+  void setSelectionMode( SelectionMode selectionMode);
+  std::vector<int> getSelected( const char* Mesh_Entry );
+  std::vector<std::pair<int,int> > getSelectedEdgeOfCell( const char* Mesh_Entry );
+
   // --------------------- for the test purposes -----------------------
-  int  getSelectionMode();
+  SelectionMode  getSelectionMode();
   void select( const char *id, std::vector<int> ids, bool append = false );
   void select( const char *id, int id1, bool append = false );
+  void select( const char *id, std::vector<std::pair<int,int> >, bool apend = false );
 
 };