From 7c1bf48314fbbb5c3c69a8dcbf70372a99189dd0 Mon Sep 17 00:00:00 2001 From: rnv Date: Wed, 2 Aug 2017 15:10:31 +0300 Subject: [PATCH] Implementation a selection of a mesh entries from python. --- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx | 114 ++++++++++++++++++++--- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h | 10 +- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i | 10 +- 3 files changed, 114 insertions(+), 20 deletions(-) diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx index 231dd33b5..0a111304e 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx @@ -49,6 +49,7 @@ #include #include #include +#include // OCCT includes #include @@ -62,6 +63,10 @@ #include CORBA_SERVER_HEADER(SMESH_Gen) #include CORBA_SERVER_HEADER(SMESH_Hypothesis) +// VTK includes +#include +#include + static CORBA::ORB_var anORB; namespace @@ -892,17 +897,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( SUIT_Session::session()->activeApplication() ); + if( anApp ) + selMgr = dynamic_cast( anApp->selectionMgr() ); + if( !selMgr ) return; selMgr->clearFilters(); - SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI ); + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow(); if(!aViewWindow) return; @@ -960,26 +966,106 @@ void SMESH_Swig::select( const char* id, int id1, bool 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(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 TResult; + TResult myResult; + const char* myId; + + TGetSelectedEvent( const char* id) : + myResult( std::vector() ), + 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 SMESH_Swig::getSelected( const char* Mesh_Entry ) { + return ProcessEvent( new TGetSelectedEvent(Mesh_Entry) ); +} diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h index 86682ff5b..5522e95a2 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h @@ -45,8 +45,9 @@ #include -enum +typedef enum { + Undefined = -1, Node = NodeSelection, Cell = CellSelection, EdgeOfCell = EdgeOfCellSelection, @@ -56,7 +57,7 @@ enum Actor = ActorSelection, Elem0D = Elem0DSelection, Ball = BallSelection - }; + } SelectionMode; typedef struct { @@ -128,8 +129,11 @@ public: actorAspect GetActorAspect(const char* Mesh_Entry, int viewId = 0 ); void SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId = 0 ); + void setSelectionMode( SelectionMode selectionMode ); + std::vector getSelected( const char* Mesh_Entry ); + // --------------------- for the test purposes ----------------------- - int getSelectionMode(); + SelectionMode getSelectionMode(); void select( const char *id, std::vector ids, bool append = false ); void select( const char *id, int id1, bool append = false ); diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i index ac732d467..339668801 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i @@ -55,9 +55,10 @@ namespace std { /* Selection mode enumeration (corresponds to constants from the SALOME_Selection.h) */ -enum +enum SelectionMode { - Node, + Undefined = -1, + Node = 0, Cell, EdgeOfCell, Edge, @@ -131,8 +132,11 @@ class SMESH_Swig actorAspect GetActorAspect(const char* Mesh_Entry, int viewId = 0 ); void SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId = 0 ); + void setSelectionMode( SelectionMode selectionMode); + std::vector getSelected( const char* Mesh_Entry ); + // --------------------- for the test purposes ----------------------- - int getSelectionMode(); + SelectionMode getSelectionMode(); void select( const char *id, std::vector ids, bool append = false ); void select( const char *id, int id1, bool append = false ); -- 2.30.2