//
#include "libSMESH_Swig.h"
+#include <SVTK_Selector.h>
#include <SMESHGUI.h>
#include <SMESHGUI_Utils.h>
#include <Utils_ORB_INIT.hxx>
#include <Utils_SINGLETON.hxx>
#include <SALOMEDSClient_ClientFactory.hxx>
+#include <SALOME_KernelServices.hxx>
#include <utilities.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
void
SetDomain(const char* theMeshOrSubMeshEntry,
const char* theDomainEntry,
- const SALOMEDS::Study_var& theStudy,
const SALOMEDS::StudyBuilder_var& theStudyBuilder,
long theRefOnAppliedDomainTag,
const QString& theAppliedDomainMEN,
const QString& theAppliedDomainICON)
{
- SALOMEDS::SObject_var aMeshOrSubMeshSO = theStudy->FindObjectID(theMeshOrSubMeshEntry);
- SALOMEDS::SObject_var aHypothesisSO = theStudy->FindObjectID(theDomainEntry);
+ SALOMEDS::SObject_var aMeshOrSubMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshOrSubMeshEntry);
+ SALOMEDS::SObject_var aHypothesisSO = KERNEL::getStudyServant()->FindObjectID(theDomainEntry);
if(!aMeshOrSubMeshSO->_is_nil() && !aHypothesisSO->_is_nil()){
//Find or Create Applied Hypothesis root
void
SetHypothesis(const char* theMeshOrSubMeshEntry,
const char* theDomainEntry,
- const SALOMEDS::Study_var& theStudy,
const SALOMEDS::StudyBuilder_var& theStudyBuilder)
{
SetDomain(theMeshOrSubMeshEntry,
theDomainEntry,
- theStudy,
theStudyBuilder,
SMESH::Tag_RefOnAppliedHypothesis,
QObject::tr("SMESH_MEN_APPLIED_HYPOTHESIS"),
void
SetAlgorithms(const char* theMeshOrSubMeshEntry,
const char* theDomainEntry,
- const SALOMEDS::Study_var& theStudy,
const SALOMEDS::StudyBuilder_var& theStudyBuilder)
{
SetDomain(theMeshOrSubMeshEntry,
theDomainEntry,
- theStudy,
theStudyBuilder,
SMESH::Tag_RefOnAppliedAlgorithms,
QObject::tr("SMESH_MEN_APPLIED_ALGORIHTMS"),
//===============================================================
void
-SMESH_Swig::Init(int theStudyID)
+SMESH_Swig::Init()
{
class TEvent: public SALOME_Event
{
- int myStudyID;
- SALOMEDS::Study_var& myStudy;
SALOMEDS::StudyBuilder_var& myStudyBuilder;
SALOMEDS::SComponent_var& mySComponentMesh;
public:
- TEvent(int theStudyID,
- SALOMEDS::Study_var& theStudy,
- SALOMEDS::StudyBuilder_var& theStudyBuilder,
+ TEvent(SALOMEDS::StudyBuilder_var& theStudyBuilder,
SALOMEDS::SComponent_var& theSComponentMesh):
- myStudyID (theStudyID),
- myStudy (theStudy),
myStudyBuilder (theStudyBuilder),
mySComponentMesh(theSComponentMesh)
{}
SUIT_Application* anApplication = aSession->activeApplication();
SalomeApp_Application* anApp = dynamic_cast<SalomeApp_Application*>(anApplication);
- SALOME_NamingService* aNamingService = anApp->namingService();
- CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager");
- SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject);
- myStudy = aStudyMgr->GetStudyByID(myStudyID);
+ SALOMEDS::Study_var aStudy = KERNEL::getStudyServant();
SMESH::SMESH_Gen_var aSMESHGen = SMESHGUI::GetSMESHGen();
- aSMESHGen->SetCurrentStudy( myStudy.in() );
- myStudyBuilder = myStudy->NewBuilder();
+ myStudyBuilder = aStudy->NewBuilder();
SALOMEDS::GenericAttribute_var anAttr;
SALOMEDS::AttributeName_var aName;
SALOMEDS::AttributePixMap_var aPixmap;
- SALOMEDS::SComponent_var aSComponent = myStudy->FindComponent("SMESH");
+ SALOMEDS::SComponent_var aSComponent = aStudy->FindComponent("SMESH");
if ( aSComponent->_is_nil() )
{
- bool aLocked = myStudy->GetProperties()->IsLocked();
+ bool aLocked = aStudy->GetProperties()->IsLocked();
if (aLocked)
- myStudy->GetProperties()->SetLocked(false);
+ aStudy->GetProperties()->SetLocked(false);
SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI();
//SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded
aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" );
aPixmap->UnRegister();
- SALOMEDS::UseCaseBuilder_var useCaseBuilder = myStudy->GetUseCaseBuilder();
+ SALOMEDS::UseCaseBuilder_var useCaseBuilder = KERNEL::getStudyServant()->GetUseCaseBuilder();
useCaseBuilder->SetRootCurrent();
useCaseBuilder->Append( aSComponent.in() );
myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen);
if (aLocked)
- myStudy->GetProperties()->SetLocked(true);
+ KERNEL::getStudyServant()->GetProperties()->SetLocked(true);
}
mySComponentMesh = SALOMEDS::SComponent::_narrow(aSComponent);
//MESSAGE("Init");
- ProcessVoidEvent(new TEvent(theStudyID,
- myStudy,
- myStudyBuilder,
+ ProcessVoidEvent(new TEvent(myStudyBuilder,
mySComponentMesh));
}
{
// VSR: added temporarily - to be removed - objects are published automatically by engine
- SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR);
+ SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectIOR(theIOR);
if (aSObject->_is_nil())
{
//Find or Create Hypothesis root
void SMESH_Swig::SetShape(const char* theShapeEntry,
const char* theMeshEntry)
{
- SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID( theShapeEntry );
- SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry );
+ SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID( theShapeEntry );
+ SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID( theMeshEntry );
if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){
SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape);
{
::SetHypothesis(theMeshOrSubMeshEntry,
theDomainEntry,
- myStudy,
myStudyBuilder);
}
{
::SetAlgorithms(theMeshOrSubMeshEntry,
theDomainEntry,
- myStudy,
myStudyBuilder);
}
void
SMESH_Swig::UnSetHypothesis(const char* theDomainEntry)
{
- SALOMEDS::SObject_var aDomainSO = myStudy->FindObjectID(theDomainEntry);
+ SALOMEDS::SObject_var aDomainSO = KERNEL::getStudyServant()->FindObjectID(theDomainEntry);
if(!aDomainSO->_is_nil())
myStudyBuilder->RemoveObject(aDomainSO);
}
const char* theSubMeshIOR,
int theShapeType)
{
- SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(theMeshEntry);
+ SALOMEDS::SObject_var aMeshSO = KERNEL::getStudyServant()->FindObjectID(theMeshEntry);
if(!aMeshSO->_is_nil()) {
long aShapeTag;
QString aSubMeshName;
const char* theSubMeshIOR,
int ShapeType)
{
- SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID(theGeomShapeEntry);
+ SALOMEDS::SObject_var aGeomShapeSO = KERNEL::getStudyServant()->FindObjectID(theGeomShapeEntry);
if(!aGeomShapeSO->_is_nil())
{
const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType);
- SALOMEDS::SObject_var aSubMeshSO = myStudy->FindObjectID(aSubMeshEntry);
+ SALOMEDS::SObject_var aSubMeshSO = KERNEL::getStudyServant()->FindObjectID(aSubMeshEntry);
if ( !aSubMeshSO->_is_nil()) {
SetShape( theGeomShapeEntry, aSubMeshEntry );
CORBA::String_var aString = aSubMeshSO->GetID();
ProcessVoidEvent(new TEvent(Mesh_Entry, allViewers));
}
+void SMESH_Swig::UpdateActor( const char* Mesh_Entry ) {
+ class TEvent: public SALOME_Event
+ {
+ private:
+ const char* _entry;
+ public:
+ TEvent( const char* Mesh_Entry ) {
+ _entry = Mesh_Entry;
+ }
+ virtual void Execute() {
+ Handle(SALOME_InteractiveObject) anIO = new SALOME_InteractiveObject
+ ( _entry, "SMESH", "" );
+ SMESH::Update( anIO, true );
+ }
+ };
+
+ ProcessVoidEvent( new TEvent(Mesh_Entry) );
+}
+
void SMESH_Swig::SetName(const char* theEntry,
const char* theName)
{
- SALOMEDS::SObject_var aSObject = myStudy->FindObjectID(theEntry);
+ SALOMEDS::SObject_var aSObject = KERNEL::getStudyServant()->FindObjectID(theEntry);
SALOMEDS::GenericAttribute_var anAttr;
SALOMEDS::AttributeName_var aName;
if(!aSObject->_is_nil()){
{
class TEvent: public SALOME_Event
{
- SALOMEDS::Study_var myStudy;
std::string myMeshEntry;
bool myIsComputed, myIsEmpty;
public:
- TEvent(const SALOMEDS::Study_var& theStudy,
- const std::string& theMeshEntry,
+ TEvent(const std::string& theMeshEntry,
const bool theIsComputed,
const bool isEmpty):
- myStudy (theStudy),
myMeshEntry (theMeshEntry),
myIsComputed(theIsComputed),
myIsEmpty (isEmpty)
void
Execute()
{
- SALOMEDS::SObject_ptr aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str());
+ SALOMEDS::SObject_ptr aMeshSO = KERNEL::getStudyServant()->FindObjectID(myMeshEntry.c_str());
if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO))
SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty);
// aMeshSO->UnRegister(); ~aMesh() already called UnRegister()!
}
};
- ProcessVoidEvent(new TEvent(myStudy,
- theMeshEntry,
+ ProcessVoidEvent(new TEvent(theMeshEntry,
theIsComputed,
isEmpty));
}
{}
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) );
+}
+