+
+/*!
+ \brief Helper class for selection event.
+*/
+class TSelectListEvent: public SALOME_Event
+{
+ const char* myId;
+ std::vector<int> myIdsList;
+ bool myIsAppend;
+
+public:
+ TSelectListEvent(const char* id, std::vector<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() == ActorSelection ) {
+ return;
+ }
+
+ TColStd_MapOfInteger aMap;
+ std::vector<int>::const_iterator anIter;
+ for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) {
+ aMap.Add(*anIter);
+ }
+
+ // Set new selection
+ SVTK_Selector* aSelector = aViewWindow->GetSelector();
+ aSelector->AddOrRemoveIndex(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<int> ids, bool append ) {
+ ProcessVoidEvent( new TSelectListEvent( id, ids, append ) );
+}
+
+/*!
+ \brief Select the elements on the mesh, sub-mesh or group.
+ \param id object entry
+ \param id id of the element
+ \param mode selection mode
+*/
+void SMESH_Swig::select( const char* id, int id1, bool append ) {
+ std::vector<int> ids;
+ ids.push_back( id1 );
+ 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 SelectionMode TResult;
+ TResult myResult;
+ TGetSelectionModeEvent() : myResult( Undefined ) {}
+ virtual void Execute()
+ {
+ SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( );
+ if(!aViewWindow)
+ return;
+
+ myResult = (SelectionMode) aViewWindow->SelectionMode();
+ }
+};
+
+/*!
+ \brief Get selection mode of the active VTK View window.
+*/
+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) );
+}
+