From 009944a75a61f582cba722173e2bb4e6a5bbc56c Mon Sep 17 00:00:00 2001 From: rnv Date: Thu, 28 Sep 2017 19:08:18 +0300 Subject: [PATCH] Implementation multiple selection of 'Edge of Cell' functionality. --- src/OBJECT/SMESH_Actor.cxx | 4 + src/OBJECT/SMESH_ActorDef.h | 1 + src/OBJECT/SMESH_DeviceActor.cxx | 6 + src/OBJECT/SMESH_DeviceActor.h | 1 + src/SMESHGUI/SMESHGUI_SingleEditDlg.cxx | 41 ++-- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx | 230 +++++++++++++++++++++-- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h | 13 +- src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i | 16 +- 8 files changed, 272 insertions(+), 40 deletions(-) diff --git a/src/OBJECT/SMESH_Actor.cxx b/src/OBJECT/SMESH_Actor.cxx index 5c2e918ab..7159bc197 100644 --- a/src/OBJECT/SMESH_Actor.cxx +++ b/src/OBJECT/SMESH_Actor.cxx @@ -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) { diff --git a/src/OBJECT/SMESH_ActorDef.h b/src/OBJECT/SMESH_ActorDef.h index 4366a98a6..746b5b76f 100644 --- a/src/OBJECT/SMESH_ActorDef.h +++ b/src/OBJECT/SMESH_ActorDef.h @@ -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); diff --git a/src/OBJECT/SMESH_DeviceActor.cxx b/src/OBJECT/SMESH_DeviceActor.cxx index 2f6ccd06f..3f4b78d81 100644 --- a/src/OBJECT/SMESH_DeviceActor.cxx +++ b/src/OBJECT/SMESH_DeviceActor.cxx @@ -860,6 +860,12 @@ SMESH_DeviceActor return aCoord; } +int +SMESH_DeviceActor +::GetNodeVtkId(int theObjID) +{ + return myVisualObj->GetNodeVTKId(theObjID); +} int SMESH_DeviceActor diff --git a/src/OBJECT/SMESH_DeviceActor.h b/src/OBJECT/SMESH_DeviceActor.h index 1b8ceb48e..30d7c8c42 100644 --- a/src/OBJECT/SMESH_DeviceActor.h +++ b/src/OBJECT/SMESH_DeviceActor.h @@ -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); diff --git a/src/SMESHGUI/SMESHGUI_SingleEditDlg.cxx b/src/SMESHGUI/SMESHGUI_SingleEditDlg.cxx index 08424f6d4..3a5e9227a 100755 --- a/src/SMESHGUI/SMESHGUI_SingleEditDlg.cxx +++ b/src/SMESHGUI/SMESHGUI_SingleEditDlg.cxx @@ -22,6 +22,9 @@ // File : SMESHGUI_SingleEditDlg.cxx // Author : Sergey LITONIN, Open CASCADE S.A.S. + +#include + // SMESH includes // #include "SMESHGUI_SingleEditDlg.h" @@ -42,7 +45,6 @@ #include #include -#include #include #include @@ -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(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(); diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx index cb9e5ae6f..f9527fbb8 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx @@ -24,6 +24,7 @@ // #include "libSMESH_Swig.h" +#include #include #include @@ -49,6 +50,7 @@ #include #include #include +#include // OCCT includes #include @@ -62,6 +64,10 @@ #include CORBA_SERVER_HEADER(SMESH_Gen) #include CORBA_SERVER_HEADER(SMESH_Hypothesis) +// VTK includes +#include +#include + 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( 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; @@ -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 > myIdsList; + bool myIsAppend; + +public: + TSelectListOfPairEvent(const char* id, std::vector > ids, bool append) : + myId(id), + myIdsList(ids), + myIsAppend(append) + {} + virtual void Execute() + { + + 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(); + 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 >::const_iterator anIter; + for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) { + std::vector 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 > 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(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) ); +} + +class TGetSelectedPairEvent : public SALOME_Event +{ +public: + typedef std::vector > TResult; + TResult myResult; + const char* myId; + + TGetSelectedPairEvent( const char* id) : + myResult( std::vector >() ), + 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)aMapIndex( i )[0], (int)aMapIndex( i )[1]) ); + } +}; + +std::vector > SMESH_Swig::getSelectedEdgeOfCell( const char* Mesh_Entry ) { + return ProcessEvent( new TGetSelectedPairEvent(Mesh_Entry) ); +} + diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h index c6c948fcf..f6cde6948 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.h @@ -40,13 +40,15 @@ //std includes #include +#include #include #include -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 getSelected( const char* Mesh_Entry ); + std::vector > getSelectedEdgeOfCell( 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 ); + void select( const char *id, std::vector >, bool apend = false ); private: SALOMEDS::Study_var myStudy; diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i index 73c08a5f1..5f66f9f21 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.i @@ -48,16 +48,21 @@ %include "typemaps.i" %include "std_vector.i" +%include "std_pair.i" namespace std { + %template(VectorInt) vector; + %template() std::pair; + %template(PairVector) std::vector >; }; /* 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 getSelected( const char* Mesh_Entry ); + std::vector > getSelectedEdgeOfCell( 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 ); + void select( const char *id, std::vector >, bool apend = false ); }; -- 2.39.2