X-Git-Url: http://git.salome-platform.org/gitweb/?p=modules%2Fsmesh.git;a=blobdiff_plain;f=src%2FSMESH_SWIG_WITHIHM%2FlibSMESH_Swig.cxx;h=e5a7aeeb068b838349bca1e1a913d45b8a99ec4b;hp=679a8d8532f5d04f6c26bc661b19270cff099aba;hb=d8bc11015235c68631ac85d7e8cf278edc9809d1;hpb=f5016d85b7b4b88623723027a1585c6414c4dc66 diff --git a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx index 679a8d853..e5a7aeeb0 100644 --- a/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx +++ b/src/SMESH_SWIG_WITHIHM/libSMESH_Swig.cxx @@ -1,9 +1,9 @@ -// Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE +// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either -// version 2.1 of the License. +// version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,9 +24,13 @@ // #include "libSMESH_Swig.h" +#include + #include #include #include +#include +#include // SALOME KERNEL includes #include @@ -40,12 +44,17 @@ #include #include #include +#include #include #include #include +#include +#include +#include // OCCT includes #include +#include // Qt includes #include @@ -55,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 @@ -83,12 +96,15 @@ namespace SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(theName.toLatin1().data()); + aName->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap(thePixmap.toLatin1().data()); + aPixmap->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(aDomainRoot,"AttributeSelectable"); SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); aSelAttr->SetSelectable(false); + aSelAttr->UnRegister(); } return aDomainRoot; @@ -126,12 +142,12 @@ namespace //--------------------------------------------------------------- inline SALOMEDS::SObject_var - AddToDomain(const std::string& theIOR, - const SALOMEDS::SComponent_var& theSComponentMesh, + AddToDomain(const std::string& theIOR, + const SALOMEDS::SComponent_var& theSComponentMesh, const SALOMEDS::StudyBuilder_var& theStudyBuilder, - CORBA::Long theDomainRootTag, - const QString& theDomainName, - const QString& theDomainPixmap) + CORBA::Long theDomainRootTag, + const QString& theDomainName, + const QString& theDomainPixmap) { SALOMEDS::SObject_var aDomain = GetDomainRoot(theSComponentMesh, theStudyBuilder, @@ -140,6 +156,7 @@ namespace theDomainPixmap); // Add New Hypothesis SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(aDomain); + aDomain->UnRegister(); SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); CORBA::Object_var anObject = StringToObject(theIOR); @@ -147,9 +164,11 @@ namespace CORBA::String_var aType = aDomainItem->GetName(); QString aPixmapName = theDomainPixmap + "_" + aType.in(); aPixmap->SetPixMap(aPixmapName.toLatin1().data()); + aPixmap->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); anIOR->SetValue(theIOR.c_str()); + anIOR->UnRegister(); return aSObject; } @@ -187,44 +206,52 @@ namespace //--------------------------------------------------------------- void - SetDomain(const char* theMeshOrSubMeshEntry, - const char* theDomainEntry, - const SALOMEDS::Study_var& theStudy, + 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) + 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 aHypothesisSO = theStudy->FindObjectID(theDomainEntry); if(!aMeshOrSubMeshSO->_is_nil() && !aHypothesisSO->_is_nil()){ //Find or Create Applied Hypothesis root SALOMEDS::SObject_var anAppliedDomainSO; - if(!aMeshOrSubMeshSO->FindSubObject(theRefOnAppliedDomainTag,anAppliedDomainSO)){ + if( !aMeshOrSubMeshSO->FindSubObject( theRefOnAppliedDomainTag, anAppliedDomainSO )) + { anAppliedDomainSO = theStudyBuilder->NewObjectToTag(aMeshOrSubMeshSO,theRefOnAppliedDomainTag); SALOMEDS::GenericAttribute_var anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(theAppliedDomainMEN.toLatin1().data()); + aName->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributeSelectable"); SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); aSelAttr->SetSelectable(false); + aSelAttr->UnRegister(); anAttr = theStudyBuilder->FindOrCreateAttribute(anAppliedDomainSO,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap(theAppliedDomainICON.toLatin1().data()); + aPixmap->UnRegister(); } SALOMEDS::SObject_var aSObject = theStudyBuilder->NewObject(anAppliedDomainSO); theStudyBuilder->Addreference(aSObject,aHypothesisSO); + aSObject->UnRegister(); + anAppliedDomainSO->UnRegister(); } + if ( !aMeshOrSubMeshSO->_is_nil() ) aMeshOrSubMeshSO->UnRegister(); + if ( !aHypothesisSO->_is_nil()) aHypothesisSO->UnRegister(); } //--------------------------------------------------------------- void - SetHypothesis(const char* theMeshOrSubMeshEntry, - const char* theDomainEntry, - const SALOMEDS::Study_var& theStudy, + SetHypothesis(const char* theMeshOrSubMeshEntry, + const char* theDomainEntry, + const SALOMEDS::Study_var& theStudy, const SALOMEDS::StudyBuilder_var& theStudyBuilder) { SetDomain(theMeshOrSubMeshEntry, @@ -239,9 +266,9 @@ namespace //--------------------------------------------------------------- void - SetAlgorithms(const char* theMeshOrSubMeshEntry, - const char* theDomainEntry, - const SALOMEDS::Study_var& theStudy, + SetAlgorithms(const char* theMeshOrSubMeshEntry, + const char* theDomainEntry, + const SALOMEDS::Study_var& theStudy, const SALOMEDS::StudyBuilder_var& theStudyBuilder) { SetDomain(theMeshOrSubMeshEntry, @@ -281,7 +308,7 @@ SMESH_Swig::SMESH_Swig() } }; - MESSAGE("Constructeur"); + //MESSAGE("Constructeur"); if(CORBA::is_nil(anORB)) ProcessVoidEvent(new TEvent(anORB)); @@ -296,31 +323,36 @@ SMESH_Swig::Init(int theStudyID) { class TEvent: public SALOME_Event { - int myStudyID; - SALOMEDS::Study_var& myStudy; + int myStudyID; + SALOMEDS::Study_var& myStudy; SALOMEDS::StudyBuilder_var& myStudyBuilder; - SALOMEDS::SComponent_var& mySComponentMesh; + SALOMEDS::SComponent_var& mySComponentMesh; public: - TEvent(int theStudyID, - SALOMEDS::Study_var& theStudy, + TEvent(int theStudyID, + SALOMEDS::Study_var& theStudy, SALOMEDS::StudyBuilder_var& theStudyBuilder, - SALOMEDS::SComponent_var& theSComponentMesh): - myStudyID(theStudyID), - myStudy(theStudy), - myStudyBuilder(theStudyBuilder), + SALOMEDS::SComponent_var& theSComponentMesh): + myStudyID (theStudyID), + myStudy (theStudy), + myStudyBuilder (theStudyBuilder), mySComponentMesh(theSComponentMesh) {} + ~TEvent() + { + if ( !mySComponentMesh->_is_nil() ) mySComponentMesh->UnRegister(); + } + virtual void Execute() { - SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Session* aSession = SUIT_Session::session(); SUIT_Application* anApplication = aSession->activeApplication(); - SalomeApp_Application* anApp = dynamic_cast(anApplication); + SalomeApp_Application* anApp = dynamic_cast(anApplication); SALOME_NamingService* aNamingService = anApp->namingService(); - CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager"); + CORBA::Object_var anObject = aNamingService->Resolve("/myStudyManager"); SALOMEDS::StudyManager_var aStudyMgr = SALOMEDS::StudyManager::_narrow(anObject); myStudy = aStudyMgr->GetStudyByID(myStudyID); @@ -334,26 +366,37 @@ SMESH_Swig::Init(int theStudyID) SALOMEDS::AttributePixMap_var aPixmap; SALOMEDS::SComponent_var aSComponent = myStudy->FindComponent("SMESH"); - if(aSComponent->_is_nil()){ + if ( aSComponent->_is_nil() ) + { bool aLocked = myStudy->GetProperties()->IsLocked(); if (aLocked) myStudy->GetProperties()->SetLocked(false); - - aSComponent = myStudyBuilder->NewComponent("SMESH"); - anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName"); - aName = SALOMEDS::AttributeName::_narrow(anAttr); - SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded - if (!aSMESHGUI){ + SMESHGUI* aSMESHGUI = SMESHGUI::GetSMESHGUI(); + //SRN: BugID IPAL9186, load a SMESH gui if it hasn't been loaded + if (!aSMESHGUI) { CAM_Module* aModule = anApp->module("Mesh"); if(!aModule) - aModule = anApp->loadModule("Mesh"); + aModule = anApp->loadModule("Mesh"); aSMESHGUI = dynamic_cast(aModule); } //SRN: BugID IPAL9186: end of a fix + + aSComponent = myStudyBuilder->NewComponent("SMESH"); + + anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributeName"); + aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(aSMESHGUI->moduleName().toLatin1().data()); + aName->UnRegister(); + anAttr = myStudyBuilder->FindOrCreateAttribute(aSComponent,"AttributePixMap"); aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap( "ICON_OBJBROWSER_SMESH" ); + aPixmap->UnRegister(); + + SALOMEDS::UseCaseBuilder_var useCaseBuilder = myStudy->GetUseCaseBuilder(); + useCaseBuilder->SetRootCurrent(); + useCaseBuilder->Append( aSComponent.in() ); + myStudyBuilder->DefineComponentInstance(aSComponent,aSMESHGen); if (aLocked) myStudy->GetProperties()->SetLocked(true); @@ -365,7 +408,7 @@ SMESH_Swig::Init(int theStudyID) } }; - MESSAGE("Init"); + //MESSAGE("Init"); ProcessVoidEvent(new TEvent(theStudyID, myStudy, @@ -377,33 +420,39 @@ SMESH_Swig::Init(int theStudyID) //=============================================================== SMESH_Swig::~SMESH_Swig() { - MESSAGE("Destructeur"); + //MESSAGE("Destructeur"); } //=============================================================== const char* SMESH_Swig::AddNewMesh(const char* theIOR) { - MESSAGE("AddNewMesh"); // VSR: added temporarily - to be removed - objects are published automatically by engine SALOMEDS::SObject_var aSObject = myStudy->FindObjectIOR(theIOR); - if (aSObject->_is_nil()){ + if (aSObject->_is_nil()) + { //Find or Create Hypothesis root - GetHypothesisRoot(mySComponentMesh,myStudyBuilder); - GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder); + SALOMEDS::SObject_var hroot = GetHypothesisRoot(mySComponentMesh,myStudyBuilder); + SALOMEDS::SObject_var aroot = GetAlgorithmsRoot(mySComponentMesh,myStudyBuilder); + hroot->UnRegister(); + aroot->UnRegister(); // Add New Mesh aSObject = myStudyBuilder->NewObject(mySComponentMesh); SALOMEDS::GenericAttribute_var anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributePixMap"); SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow(anAttr); aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH" ); + aPixmap->UnRegister(); + anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject, "AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); anIOR->SetValue(theIOR); + anIOR->UnRegister(); } CORBA::String_var anEntry = aSObject->GetID(); + aSObject->UnRegister(); return anEntry._retn(); } @@ -412,12 +461,12 @@ const char* SMESH_Swig::AddNewMesh(const char* theIOR) //=============================================================== const char* SMESH_Swig::AddNewHypothesis(const char* theIOR) { - MESSAGE("AddNewHypothesis"); - SALOMEDS::SObject_var aSObject = ::AddHypothesis(theIOR, mySComponentMesh, myStudyBuilder); CORBA::String_var anEntry = aSObject->GetID(); + aSObject->UnRegister(); + return anEntry._retn(); } @@ -425,12 +474,12 @@ const char* SMESH_Swig::AddNewHypothesis(const char* theIOR) //=============================================================== const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR) { - MESSAGE("AddNewAlgorithms"); - SALOMEDS::SObject_var aSObject = ::AddAlgorithms(theIOR, mySComponentMesh, myStudyBuilder); CORBA::String_var anEntry = aSObject->GetID(); + aSObject->UnRegister(); + return anEntry._retn(); } @@ -439,13 +488,16 @@ const char* SMESH_Swig::AddNewAlgorithms(const char* theIOR) void SMESH_Swig::SetShape(const char* theShapeEntry, const char* theMeshEntry) { - SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry ); SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID( theShapeEntry ); + SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID( theMeshEntry ); if(!aMeshSO->_is_nil() && !aGeomShapeSO->_is_nil()){ SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObjectToTag(aMeshSO, SMESH::Tag_RefOnShape); myStudyBuilder->Addreference(aSObject,aGeomShapeSO); + aSObject->UnRegister(); } + if ( !aMeshSO->_is_nil() ) aMeshSO->UnRegister(); + if ( !aGeomShapeSO->_is_nil() ) aGeomShapeSO->UnRegister(); } @@ -485,49 +537,57 @@ const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry, int theShapeType) { SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(theMeshEntry); - if(!aMeshSO->_is_nil()){ + if(!aMeshSO->_is_nil()) { long aShapeTag; QString aSubMeshName; - switch(theShapeType){ + switch(theShapeType) { case TopAbs_SOLID: - aShapeTag = SMESH::Tag_SubMeshOnSolid; + aShapeTag = SMESH::Tag_SubMeshOnSolid; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnSolid"); break; case TopAbs_FACE: - aShapeTag = SMESH::Tag_SubMeshOnFace; + aShapeTag = SMESH::Tag_SubMeshOnFace; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnFace"); break; case TopAbs_EDGE: - aShapeTag = SMESH::Tag_SubMeshOnEdge; + aShapeTag = SMESH::Tag_SubMeshOnEdge; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnEdge"); break; case TopAbs_VERTEX: - aShapeTag = SMESH::Tag_SubMeshOnVertex; + aShapeTag = SMESH::Tag_SubMeshOnVertex; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnVertex"); break; default: - aShapeTag = SMESH::Tag_SubMeshOnCompound; + aShapeTag = SMESH::Tag_SubMeshOnCompound; aSubMeshName = QObject::tr("SMESH_MEN_SubMeshesOnCompound"); } - SALOMEDS::SObject_var aSubMeshesRoot; SALOMEDS::GenericAttribute_var anAttr; - if(!aMeshSO->FindSubObject(aShapeTag,aSubMeshesRoot)){ + SALOMEDS::SObject_var aSubMeshesRoot; + if ( !aMeshSO->FindSubObject( aShapeTag, aSubMeshesRoot ) ) + { aSubMeshesRoot = myStudyBuilder->NewObjectToTag(aMeshSO,aShapeTag); anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeName"); SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(aSubMeshName.toLatin1().data()); + aName->UnRegister(); anAttr = myStudyBuilder->FindOrCreateAttribute(aSubMeshesRoot,"AttributeSelectable"); SALOMEDS::AttributeSelectable_var aSelAttr = SALOMEDS::AttributeSelectable::_narrow(anAttr); aSelAttr->SetSelectable(false); + aSelAttr->UnRegister(); } + aSubMeshesRoot->UnRegister(); + aMeshSO->UnRegister(); SALOMEDS::SObject_var aSObject = myStudyBuilder->NewObject(aSubMeshesRoot); anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeIOR"); SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr); anIOR->SetValue(theSubMeshIOR); + anIOR->UnRegister(); CORBA::String_var aString = aSObject->GetID(); + aSObject->UnRegister(); + return aString._retn(); } @@ -537,22 +597,167 @@ const char* SMESH_Swig::AddSubMesh(const char* theMeshEntry, const char* SMESH_Swig::AddSubMeshOnShape(const char* theMeshEntry, const char* theGeomShapeEntry, const char* theSubMeshIOR, - int ShapeType) + int ShapeType) { SALOMEDS::SObject_var aGeomShapeSO = myStudy->FindObjectID(theGeomShapeEntry); - if(!aGeomShapeSO->_is_nil()){ - const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType); + if(!aGeomShapeSO->_is_nil()) + { + const char * aSubMeshEntry = AddSubMesh(theMeshEntry,theSubMeshIOR,ShapeType); SALOMEDS::SObject_var aSubMeshSO = myStudy->FindObjectID(aSubMeshEntry); - if(!aSubMeshSO->_is_nil()){ - SetShape(theGeomShapeEntry,aSubMeshEntry); + if ( !aSubMeshSO->_is_nil()) { + SetShape( theGeomShapeEntry, aSubMeshEntry ); CORBA::String_var aString = aSubMeshSO->GetID(); + aSubMeshSO->UnRegister(); return aString._retn(); } + aGeomShapeSO->UnRegister(); } return ""; } +/*! + \brief Gets window with specified identifier + \internal + \param id window identifier + \return pointer on the window +*/ + +SUIT_ViewWindow* getWnd( const int id ) +{ + SUIT_ViewWindow* resWnd = 0; + SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Application* anApplication = aSession->activeApplication(); + SalomeApp_Application* app = dynamic_cast(anApplication); + if ( app ) { + ViewManagerList vmlist = app->viewManagers(); + foreach( SUIT_ViewManager* vm, vmlist ) { + QVector vwlist = vm->getViews(); + foreach ( SUIT_ViewWindow* vw, vwlist ) { + if ( id == vw->getId() ) { + resWnd = vw; + break; + } + } + } + } + return resWnd; +} + +class TGetActorAspect: public SALOME_Event +{ +public: + typedef actorAspect TResult; + TResult myResult; + const char* _entry; + int _wid; + TGetActorAspect( const char* Mesh_Entry, int viewId ) + { + _entry = Mesh_Entry; + _wid = viewId; + } + virtual void Execute() + { + SMESH_Actor* anActor; + if (_wid) + { + SUIT_ViewWindow* w = getWnd(_wid); + anActor = SMESH::FindActorByEntry( w, _entry ); + } + else + anActor = SMESH::FindActorByEntry( _entry ); + if ( !anActor ) + { + MESSAGE("GetActorAspect: no actor corresponding to: " << _entry); + return; + } + anActor->GetSufaceColor(myResult.surfaceColor.r, + myResult.surfaceColor.g, + myResult.surfaceColor.b, + myResult.surfaceColor.delta); + anActor->GetVolumeColor(myResult.volumeColor.r, + myResult.volumeColor.g, + myResult.volumeColor.b, + myResult.volumeColor.delta); + anActor->GetEdgeColor(myResult.edgeColor.r, + myResult.edgeColor.g, + myResult.edgeColor.b); + anActor->GetNodeColor(myResult.nodeColor.r, + myResult.nodeColor.g, + myResult.nodeColor.b); + myResult.opacity= anActor->GetOpacity(); + MESSAGE("opacity: " << myResult.opacity); + } +}; + +actorAspect SMESH_Swig::GetActorAspect( const char* Mesh_Entry, int viewId ) +{ + return ProcessEvent(new TGetActorAspect( Mesh_Entry, viewId)); +} + +void SMESH_Swig::SetActorAspect( const actorAspect& actorPres, const char* Mesh_Entry, int viewId ) +{ + class TSetActorAspect: public SALOME_Event + { + public: + const char* _entry; + actorAspect _actorPres; + int _wid; + TSetActorAspect(const actorAspect& actorPres, const char* Mesh_Entry, int viewId ) + { + _entry = Mesh_Entry; + _actorPres = actorPres; + _wid = viewId; + } + virtual void Execute() + { + SMESH_Actor* anActor; + if (_wid) + { + SUIT_ViewWindow* w = getWnd(_wid); + anActor = SMESH::FindActorByEntry( w, _entry ); + } + else + anActor = SMESH::FindActorByEntry( _entry ); + if ( !anActor ) + { + MESSAGE("SetActorAspect: no actor corresponding to: " << _entry); + return; + } + anActor->SetSufaceColor(_actorPres.surfaceColor.r, + _actorPres.surfaceColor.g, + _actorPres.surfaceColor.b, + _actorPres.surfaceColor.delta); + anActor->SetVolumeColor(_actorPres.volumeColor.r, + _actorPres.volumeColor.g, + _actorPres.volumeColor.b, + _actorPres.volumeColor.delta); + anActor->SetEdgeColor(_actorPres.edgeColor.r, + _actorPres.edgeColor.g, + _actorPres.edgeColor.b); + anActor->SetNodeColor(_actorPres.nodeColor.r, + _actorPres.nodeColor.g, + _actorPres.nodeColor.b); + anActor->SetOpacity(_actorPres.opacity); + if (_wid) + { + SUIT_ViewWindow* w = getWnd(_wid); + w->repaint(); + } + else + { + SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Application* anApplication = aSession->activeApplication(); + SalomeApp_Application* anApp = dynamic_cast(anApplication); + SUIT_ViewManager* vman = anApp->getViewManager(VTKViewer_Viewer::Type(),true); + vman->getActiveView()->repaint(); + } + } + }; + + ProcessVoidEvent(new TSetActorAspect(actorPres, Mesh_Entry, viewId)); +} + void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry ) { // SMESH_Actor* Mesh = smeshGUI->ReadScript(aM); @@ -566,11 +771,11 @@ void SMESH_Swig::CreateAndDisplayActor( const char* Mesh_Entry ) } virtual void Execute() { //SMESH::UpdateView(SMESH::eDisplay, _entry); - SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Session* aSession = SUIT_Session::session(); SUIT_Application* anApplication = aSession->activeApplication(); - SalomeApp_Application* anApp = dynamic_cast(anApplication); - /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true); - SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); + SalomeApp_Application* anApp = dynamic_cast(anApplication); + /*SUIT_ViewManager* vman = */anApp->getViewManager(VTKViewer_Viewer::Type(),true); + SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); aDisp->Display(_entry,1); } }; @@ -584,31 +789,31 @@ void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers ) { private: const char* _entry; - bool _allViewers; + bool _allViewers; public: TEvent(const char* Mesh_Entry, const bool allViewers ) { _entry = Mesh_Entry; _allViewers = allViewers; } virtual void Execute() { - SUIT_Session* aSession = SUIT_Session::session(); + SUIT_Session* aSession = SUIT_Session::session(); SUIT_Application* anApplication = aSession->activeApplication(); - SalomeApp_Application* anApp = dynamic_cast(anApplication); - SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); + SalomeApp_Application* anApp = dynamic_cast(anApplication); + SMESHGUI_Displayer* aDisp = new SMESHGUI_Displayer(anApp); ViewManagerList aManagers; if ( !_allViewers ) { - aManagers << anApp->activeViewManager(); + aManagers << anApp->activeViewManager(); } else { - aManagers = anApp->viewManagers(); + aManagers = anApp->viewManagers(); } foreach( SUIT_ViewManager* aMgr, aManagers ) { - if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) { - SALOME_View* aSalomeView = dynamic_cast(aMgr->getViewModel()); - if (aSalomeView) { - aDisp->Erase(_entry,true, true, aSalomeView); - } - } + if ( aMgr && aMgr->getType() == VTKViewer_Viewer::Type() ) { + SALOME_View* aSalomeView = dynamic_cast(aMgr->getViewModel()); + if (aSalomeView) { + aDisp->Erase(_entry,true, true, aSalomeView); + } + } } } }; @@ -616,6 +821,25 @@ void SMESH_Swig::EraseActor( const char* Mesh_Entry, const bool allViewers ) 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) { @@ -626,6 +850,8 @@ void SMESH_Swig::SetName(const char* theEntry, anAttr = myStudyBuilder->FindOrCreateAttribute(aSObject,"AttributeName"); aName = SALOMEDS::AttributeName::_narrow(anAttr); aName->SetValue(theName); + aName->UnRegister(); + aSObject->UnRegister(); } } @@ -638,33 +864,33 @@ void SMESH_Swig::SetName(const char* theEntry, //================================================================================ void SMESH_Swig::SetMeshIcon(const char* theMeshEntry, - const bool theIsComputed, - const bool isEmpty) + const bool theIsComputed, + const bool isEmpty) { class TEvent: public SALOME_Event { SALOMEDS::Study_var myStudy; - std::string myMeshEntry; - bool myIsComputed, myIsEmpty; + std::string myMeshEntry; + bool myIsComputed, myIsEmpty; public: TEvent(const SALOMEDS::Study_var& theStudy, - const std::string& theMeshEntry, - const bool theIsComputed, - const bool isEmpty): - myStudy(theStudy), - myMeshEntry(theMeshEntry), + const std::string& theMeshEntry, + const bool theIsComputed, + const bool isEmpty): + myStudy (theStudy), + myMeshEntry (theMeshEntry), myIsComputed(theIsComputed), - myIsEmpty(isEmpty) + myIsEmpty (isEmpty) {} virtual void Execute() { - SALOMEDS::SObject_var aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str()); - if(!aMeshSO->_is_nil()) - if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO)) - SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty); + SALOMEDS::SObject_ptr aMeshSO = myStudy->FindObjectID(myMeshEntry.c_str()); + if(_PTR(SObject) aMesh = ClientFactory::SObject(aMeshSO)) + SMESH::ModifiedMesh(aMesh,myIsComputed,myIsEmpty); + // aMeshSO->UnRegister(); ~aMesh() already called UnRegister()! } }; @@ -673,3 +899,308 @@ void SMESH_Swig::SetMeshIcon(const char* theMeshEntry, theIsComputed, isEmpty)); } + +/*! + \brief Helper class for selection event. +*/ +class TSelectListEvent: public SALOME_Event +{ + const char* myId; + std::vector myIdsList; + bool myIsAppend; + +public: + TSelectListEvent(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() == ActorSelection ) { + return; + } + + TColStd_MapOfInteger aMap; + std::vector::const_iterator anIter; + for (anIter = myIdsList.begin(); anIter != myIdsList.end(); ++anIter) { + aMap.Add(*anIter); + } + + // Set new selection + SVTK_Selector* aSelector = aViewWindow->GetSelector(); + aSelector->AddOrRemoveIndex(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 TSelectListEvent( id, ids, append ) ); +} + +/*! + \brief Select the elements on the mesh, sub-mesh or group. + \param id object entry + \param id id of the element + \param mode selection mode +*/ +void SMESH_Swig::select( const char* id, int id1, bool append ) { + std::vector ids; + ids.push_back( id1 ); + 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 SelectionMode TResult; + TResult myResult; + TGetSelectionModeEvent() : myResult( Undefined ) {} + virtual void Execute() + { + SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( ); + if(!aViewWindow) + return; + + myResult = (SelectionMode) aViewWindow->SelectionMode(); + } +}; + +/*! + \brief Get selection mode of the active VTK View window. +*/ +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) ); +} +