// File : SMESHGUI_SingleEditDlg.cxx
// Author : Sergey LITONIN, Open CASCADE S.A.S.
+
+#include <SVTK_Selector.h>
+
// SMESH includes
//
#include "SMESHGUI_SingleEditDlg.h"
#include <SUIT_Desktop.h>
#include <SUIT_Session.h>
-#include <SVTK_Selector.h>
#include <SVTK_ViewWindow.h>
#include <SALOME_ListIO.hxx>
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) )
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 );
}
}
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);
// update actor
if (aResult) {
mySelector->ClearIndex();
+ mySelector->ClearCompositeIndex();
mySelectionMgr->setSelectedObjects(aList, false);
onSelectionDone();
SMESH::UpdateView();
//
#include "libSMESH_Swig.h"
+#include <SVTK_Selector.h>
#include <SMESHGUI.h>
#include <SMESHGUI_Utils.h>
#include <SalomeApp_Application.h>
#include <LightApp_SelectionMgr.h>
#include <SVTK_RenderWindowInteractor.h>
+#include <VTKViewer_Algorithm.h>
// OCCT includes
#include <TopAbs.hxx>
#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
{}
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;
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) );
+}
+