mirror of
https://git.salome-platform.org/gitpub/modules/smesh.git
synced 2025-03-17 03:37:54 +05:00
Implementation multiple selection of 'Edge of Cell' functionality.
This commit is contained in:
parent
4b2ed66f4e
commit
22b868ddaa
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
@ -860,6 +860,12 @@ SMESH_DeviceActor
|
||||
return aCoord;
|
||||
}
|
||||
|
||||
int
|
||||
SMESH_DeviceActor
|
||||
::GetNodeVtkId(int theObjID)
|
||||
{
|
||||
return myVisualObj->GetNodeVTKId(theObjID);
|
||||
}
|
||||
|
||||
int
|
||||
SMESH_DeviceActor
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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>
|
||||
@ -62,6 +64,10 @@
|
||||
#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) );
|
||||
}
|
||||
|
||||
|
@ -40,13 +40,15 @@
|
||||
|
||||
//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;
|
||||
|
@ -48,16 +48,21 @@
|
||||
|
||||
%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 );
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user