Implementation multiple selection of 'Edge of Cell' functionality.

This commit is contained in:
rnv 2017-09-28 19:08:18 +03:00
parent 4b2ed66f4e
commit 22b868ddaa
8 changed files with 272 additions and 40 deletions

View File

@ -1429,6 +1429,10 @@ double* SMESH_ActorDef::GetNodeCoord(int theObjID)
return myPickableActor->GetNodeCoord(theObjID); return myPickableActor->GetNodeCoord(theObjID);
} }
int SMESH_ActorDef::GetNodeVtkId(int theObjID)
{
return myPickableActor->GetNodeVtkId(theObjID);
}
int SMESH_ActorDef::GetElemObjId(int theVtkID) int SMESH_ActorDef::GetElemObjId(int theVtkID)
{ {

View File

@ -150,6 +150,7 @@ class SMESH_ActorDef : public SMESH_Actor
virtual int GetNodeObjId(int theVtkID); virtual int GetNodeObjId(int theVtkID);
virtual double* GetNodeCoord(int theObjID); virtual double* GetNodeCoord(int theObjID);
virtual int GetNodeVtkId(int theObjID);
virtual int GetElemObjId(int theVtkID); virtual int GetElemObjId(int theVtkID);
virtual vtkCell* GetElemCell(int theObjID); virtual vtkCell* GetElemCell(int theObjID);

View File

@ -860,6 +860,12 @@ SMESH_DeviceActor
return aCoord; return aCoord;
} }
int
SMESH_DeviceActor
::GetNodeVtkId(int theObjID)
{
return myVisualObj->GetNodeVTKId(theObjID);
}
int int
SMESH_DeviceActor SMESH_DeviceActor

View File

@ -70,6 +70,7 @@ class SMESHOBJECT_EXPORT SMESH_DeviceActor: public vtkLODActor{
virtual int GetNodeObjId(int theVtkID); virtual int GetNodeObjId(int theVtkID);
virtual double* GetNodeCoord(int theObjID); virtual double* GetNodeCoord(int theObjID);
virtual int GetNodeVtkId(int theObjID);
virtual int GetElemObjId(int theVtkID); virtual int GetElemObjId(int theVtkID);
virtual vtkCell* GetElemCell(int theObjID); virtual vtkCell* GetElemCell(int theObjID);

View File

@ -22,6 +22,9 @@
// File : SMESHGUI_SingleEditDlg.cxx // File : SMESHGUI_SingleEditDlg.cxx
// Author : Sergey LITONIN, Open CASCADE S.A.S. // Author : Sergey LITONIN, Open CASCADE S.A.S.
#include <SVTK_Selector.h>
// SMESH includes // SMESH includes
// //
#include "SMESHGUI_SingleEditDlg.h" #include "SMESHGUI_SingleEditDlg.h"
@ -42,7 +45,6 @@
#include <SUIT_Desktop.h> #include <SUIT_Desktop.h>
#include <SUIT_Session.h> #include <SUIT_Session.h>
#include <SVTK_Selector.h>
#include <SVTK_ViewWindow.h> #include <SVTK_ViewWindow.h>
#include <SALOME_ListIO.hxx> #include <SALOME_ListIO.hxx>
@ -347,9 +349,9 @@ void SMESHGUI_SingleEditDlg::onTextChange (const QString& theNewText)
aList.Append(anIO); aList.Append(anIO);
mySelectionMgr->setSelectedObjects(aList,false); mySelectionMgr->setSelectedObjects(aList,false);
TColStd_IndexedMapOfInteger selectedIndices; SVTK_IndexedMapOfIds selectedIndices;
TColStd_MapOfInteger newIndices; SVTK_ListOfInteger newIndices;
mySelector->GetIndex(anIO,selectedIndices); mySelector->GetCompositeIndex(anIO,selectedIndices);
int id1, id2; int id1, id2;
if ( !getNodeIds(myEdge->text(), 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) ) if ( findTriangles(aNode1,aNode2,tria1,tria2) )
{ {
newIndices.Add(tria1->GetID()); newIndices.push_back( aNode1->GetID() );
newIndices.push_back( aNode2->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);
myOkBtn->setEnabled(true); myOkBtn->setEnabled(true);
myApplyBtn->setEnabled(true); myApplyBtn->setEnabled(true);
} }
mySelector->AddOrRemoveIndex(anIO,newIndices, false); mySelector->AddOrRemoveCompositeIndex(anIO, newIndices, false);
SMESH::GetViewWindow(mySMESHGUI)->highlight( anIO, true, true ); SMESH::GetViewWindow(mySMESHGUI)->highlight( anIO, true, true );
} }
} }
@ -420,7 +410,17 @@ void SMESHGUI_SingleEditDlg::onSelectionDone()
if(SMDS_Mesh* aMesh = aVisualObj->GetMesh()) if(SMDS_Mesh* aMesh = aVisualObj->GetMesh())
{ {
const SMDS_MeshElement* tria[2]; 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] ) ) findTriangles( aMesh->FindNode( anId1 ), aMesh->FindNode( anId2 ), tria[0],tria[1] ) )
{ {
QString aText = QString("%1-%2").arg(anId1).arg(anId2); QString aText = QString("%1-%2").arg(anId1).arg(anId2);
@ -523,6 +523,7 @@ bool SMESHGUI_SingleEditDlg::onApply()
// update actor // update actor
if (aResult) { if (aResult) {
mySelector->ClearIndex(); mySelector->ClearIndex();
mySelector->ClearCompositeIndex();
mySelectionMgr->setSelectedObjects(aList, false); mySelectionMgr->setSelectedObjects(aList, false);
onSelectionDone(); onSelectionDone();
SMESH::UpdateView(); SMESH::UpdateView();

View File

@ -24,6 +24,7 @@
// //
#include "libSMESH_Swig.h" #include "libSMESH_Swig.h"
#include <SVTK_Selector.h>
#include <SMESHGUI.h> #include <SMESHGUI.h>
#include <SMESHGUI_Utils.h> #include <SMESHGUI_Utils.h>
@ -49,6 +50,7 @@
#include <SalomeApp_Application.h> #include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h> #include <LightApp_SelectionMgr.h>
#include <SVTK_RenderWindowInteractor.h> #include <SVTK_RenderWindowInteractor.h>
#include <VTKViewer_Algorithm.h>
// OCCT includes // OCCT includes
#include <TopAbs.hxx> #include <TopAbs.hxx>
@ -62,6 +64,10 @@
#include CORBA_SERVER_HEADER(SMESH_Gen) #include CORBA_SERVER_HEADER(SMESH_Gen)
#include CORBA_SERVER_HEADER(SMESH_Hypothesis) #include CORBA_SERVER_HEADER(SMESH_Hypothesis)
// VTK includes
#include <vtkActorCollection.h>
#include <vtkRenderer.h>
static CORBA::ORB_var anORB; static CORBA::ORB_var anORB;
namespace namespace
@ -755,17 +761,18 @@ public:
{} {}
virtual void Execute() 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 ) if( !selMgr )
return; return;
selMgr->clearFilters(); selMgr->clearFilters();
SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI ); SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow();
if(!aViewWindow) if(!aViewWindow)
return; return;
@ -819,30 +826,225 @@ void SMESH_Swig::select( const char* id, int id1, bool append ) {
ProcessVoidEvent( new TSelectListEvent( id, ids, 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 class TGetSelectionModeEvent : public SALOME_Event
{ {
public: public:
typedef int TResult; typedef SelectionMode TResult;
TResult myResult; TResult myResult;
TGetSelectionModeEvent() : myResult( -1 ) {} TGetSelectionModeEvent() : myResult( Undefined ) {}
virtual void Execute() virtual void Execute()
{ {
SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( );
if( !aSMESHGUI )
return;
SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( aSMESHGUI );
if(!aViewWindow) if(!aViewWindow)
return; return;
myResult = aViewWindow->SelectionMode(); myResult = (SelectionMode) aViewWindow->SelectionMode();
} }
}; };
/*! /*!
\brief Get selection mode of the active VTK View window. \brief Get selection mode of the active VTK View window.
*/ */
int SMESH_Swig::getSelectionMode() { SelectionMode SMESH_Swig::getSelectionMode() {
return ProcessEvent( new TGetSelectionModeEvent() ); 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) );
}

View File

@ -40,13 +40,15 @@
//std includes //std includes
#include <vector> #include <vector>
#include <utility>
#include <SVTK_Selection.h> #include <SVTK_Selection.h>
#include <SVTK_Selection.h> #include <SVTK_Selection.h>
enum typedef enum
{ {
Undefined = -1,
Node = NodeSelection, Node = NodeSelection,
Cell = CellSelection, Cell = CellSelection,
EdgeOfCell = EdgeOfCellSelection, EdgeOfCell = EdgeOfCellSelection,
@ -56,7 +58,7 @@ enum
Actor = ActorSelection, Actor = ActorSelection,
Elem0D = Elem0DSelection, Elem0D = Elem0DSelection,
Ball = BallSelection Ball = BallSelection
}; } SelectionMode;
class SMESH_SWIG_EXPORT SMESH_Swig class SMESH_SWIG_EXPORT SMESH_Swig
{ {
@ -94,10 +96,15 @@ public:
*/ */
void SetMeshIcon( const char*, const bool, const bool ); 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 ----------------------- // --------------------- 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, std::vector<int> ids, bool append = false );
void select( const char *id, int id1, 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: private:
SALOMEDS::Study_var myStudy; SALOMEDS::Study_var myStudy;

View File

@ -48,16 +48,21 @@
%include "typemaps.i" %include "typemaps.i"
%include "std_vector.i" %include "std_vector.i"
%include "std_pair.i"
namespace std { namespace std {
%template(VectorInt) vector<int>; %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) */ /* Selection mode enumeration (corresponds to constants from the SALOME_Selection.h) */
enum enum SelectionMode
{ {
Node, Undefined = -1,
Node = 0,
Cell, Cell,
EdgeOfCell, EdgeOfCell,
Edge, Edge,
@ -97,9 +102,14 @@ class SMESH_Swig
void CreateAndDisplayActor( const char* Mesh_Entry ); void CreateAndDisplayActor( const char* Mesh_Entry );
void EraseActor( const char* Mesh_Entry, const bool allViewers = false ); 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 ----------------------- // --------------------- 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, std::vector<int> ids, bool append = false );
void select( const char *id, int id1, 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 );
}; };