Salome HOME
Merge remote branch 'origin/V8_5_asterstudy'
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_HypothesesUtils.cxx
index 71b8125667e593efec3c64ffebb7b0ac51bd6c9d..7aff8c6ce1b4b281c333e3d19cadf152d9832d07 100644 (file)
 #include "SMESHGUI_HypothesesUtils.h"
 
 #include "SMESHGUI.h"
+#include "SMESHGUI_GEOMGenUtils.h"
 #include "SMESHGUI_Hypotheses.h"
-#include "SMESHGUI_XmlHandler.h"
 #include "SMESHGUI_Utils.h"
-#include "SMESHGUI_GEOMGenUtils.h"
+#include "SMESHGUI_VTKUtils.h"
+#include "SMESHGUI_XmlHandler.h"
+
+#include "SMESH_Actor.h"
 
 // SALOME GUI includes
 #include <SUIT_Desktop.h>
 #endif
 
 #ifdef WIN32
-#define LibHandle HMODULE
-#define LoadLib( name ) LoadLibrary( name )
-#define GetProc GetProcAddress
-#define UnLoadLib( handle ) FreeLibrary( handle );
-#else
-#define LibHandle void*
-#define LoadLib( name ) dlopen( name, RTLD_LAZY )
-#define GetProc dlsym
-#define UnLoadLib( handle ) dlclose( handle );
-#endif
+ #define LibHandle HMODULE
+ #define LoadLib( name ) LoadLibrary( name )
+ #define GetProc GetProcAddress
+ #define UnLoadLib( handle ) FreeLibrary( handle );
+#else // WIN32
+ #define LibHandle void*
+ #ifdef DYNLOAD_LOCAL
+  #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_LOCAL )
+ #else // DYNLOAD_LOCAL
+  #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL )
+ #endif // DYNLOAD_LOCAL
+ #define GetProc dlsym
+ #define UnLoadLib( handle ) dlclose( handle );
+#endif // WIN32
 
 #ifdef _DEBUG_
 static int MYDEBUG = 0;
@@ -282,14 +289,14 @@ namespace SMESH
   QStringList GetAvailableHypotheses( const bool isAlgo,
                                       const int  theDim,
                                       const bool isAux,
-                                      const bool isNeedGeometry,
+                                      const bool hasGeometry,
                                       const bool isSubMesh)
   {
     QStringList aHypList;
 
     // Init list of available hypotheses, if needed
     InitAvailableHypotheses();
-    bool checkGeometry = ( !isNeedGeometry && isAlgo );
+    bool checkGeometry = ( isAlgo );
     const char* context = isSubMesh ? "LOCAL" : "GLOBAL";
     // fill list of hypotheses/algorithms
     THypothesisDataMap& pMap = isAlgo ? myAlgorithmsMap : myHypothesesMap;
@@ -301,7 +308,8 @@ namespace SMESH
           ( theDim < 0              || aData->Dim.contains( theDim )) &&
           ( isAlgo                  || aData->IsAuxOrNeedHyp == isAux ) &&
           ( aData->Context == "ANY" || aData->Context == context ) &&
-          ( !checkGeometry          || aData->IsNeedGeometry == isNeedGeometry ))
+          ( !checkGeometry          || (!aData->IsNeedGeometry  ||
+                                        ( aData->IsNeedGeometry > 0 ) == hasGeometry)))
       {
         aHypList.append(anIter.key());
       }
@@ -386,7 +394,7 @@ namespace SMESH
       QList<int> dummyIL; dummyIL << 1;
       QStringList dummySL;
       HypothesisData group( dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,dummyS,-1,-1,
-                            dummyIL, 0, dummySL,dummySL,dummySL,dummySL );
+                            dummyIL, 0, dummySL,dummySL,dummySL,dummySL,0,0 );
       // no group
       int key = 0;
       theGroups[ key ].push_back( group );
@@ -513,9 +521,19 @@ namespace SMESH
       try {
         // load plugin library
         if(MYDEBUG) MESSAGE("Loading client meshers plugin library ...");
-        LibHandle libHandle = LoadLib( aClientLibName.toLatin1().data() );
+#ifdef WIN32
+#ifdef UNICODE
+               LPTSTR path = new TCHAR[aClientLibName.length() + 1];
+               path[aClientLibName.toWCharArray(path)] = '\0';
+#else
+               const char* path = aClientLibName.toUtf8().data();
+#endif
+#else
+               char* path = aClientLibName.toUtf8().data();
+#endif
+        LibHandle libHandle = LoadLib( path );
         if (!libHandle) {
-          // report any error, if occured
+          // report any error, if occurred
           {
 #ifdef WIN32
             const char* anError = "Can't load client meshers plugin library";
@@ -577,7 +595,7 @@ namespace SMESH
     try {
       SMESH::SMESH_Hypothesis_var aHypothesis;
       aHypothesis = SMESHGUI::GetSMESHGen()->CreateHypothesis(aHypType.toLatin1().data(),
-                                                              aServLib.toLatin1().data());
+                                                              aServLib.toUtf8().data());
       if (!aHypothesis->_is_nil()) {
         _PTR(SObject) aHypSObject = SMESH::FindSObject(aHypothesis.in());
         if (aHypSObject) {
@@ -605,7 +623,7 @@ namespace SMESH
     HypothesisData* aHypData = GetHypothesisData(aHypType);
     QString aServLib = aHypData->ServerLibName;
     return SMESHGUI::GetSMESHGen()->IsApplicable( aHypType.toLatin1().data(),
-                                                  aServLib.toLatin1().data(),
+                                                  aServLib.toUtf8().data(),
                                                   theGeomObject,
                                                   toCheckAll);
   }
@@ -623,12 +641,6 @@ namespace SMESH
       try {
         CORBA::String_var error;
         res = aMesh->AddHypothesis(aShapeObject, aHyp, error.out());
-        if (res < SMESH::HYP_UNKNOWN_FATAL) {
-          _PTR(SObject) aSH = SMESH::FindSObject(aHyp);
-          if (SM && aSH) {
-            SMESH::ModifiedMesh(SM, false, aMesh->NbNodes()==0);
-          }
-        }
         if (res > SMESH::HYP_OK) {
           wc.suspend();
           processHypothesisStatus(res, aHyp, true, error.in() );
@@ -660,11 +672,6 @@ namespace SMESH
         {
           CORBA::String_var error;
           res = aMesh->AddHypothesis( aShapeObject, aHyp, error.out() );
-          if (res < SMESH::HYP_UNKNOWN_FATAL)  {
-            _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
-            if (meshSO)
-              SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
-          }
           if (res > SMESH::HYP_OK) {
             wc.suspend();
             processHypothesisStatus( res, aHyp, true, error.in() );
@@ -697,32 +704,32 @@ namespace SMESH
     SUIT_OverrideCursor wc;
 
     try {
-      _PTR(Study) aStudy = GetActiveStudyDocument();
+      _PTR(Study) aStudy = getStudy();
       _PTR(SObject) aHypObj = aStudy->FindObjectID( IObject->getEntry() );
       if( aHypObj )
+      {
+        _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
+        _PTR(SObject) aRealHypo;
+        if( aHypObj->ReferencedObject( aRealHypo ) )
         {
-          _PTR(SObject) MorSM = SMESH::GetMeshOrSubmesh( aHypObj );
-          _PTR(SObject) aRealHypo;
-          if( aHypObj->ReferencedObject( aRealHypo ) )
-            {
-              SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
-              RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
-            }
-          else
-            {
-              SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
-              SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
-              for( size_t i = 0; i < meshList.size(); i++ )
-                RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
-            }
+          SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aRealHypo ) );
+          RemoveHypothesisOrAlgorithmOnMesh( MorSM, hypo );
         }
+        else
+        {
+          SMESH_Hypothesis_var hypo = SMESH_Hypothesis::_narrow( SObjectToObject( aHypObj ) );
+          SObjectList meshList = GetMeshesUsingAlgoOrHypothesis( hypo );
+          for( size_t i = 0; i < meshList.size(); i++ )
+            RemoveHypothesisOrAlgorithmOnMesh( meshList[ i ], hypo );
+        }
+      }
     }
     catch(const SALOME::SALOME_Exception& S_ex)
-      {
-        wc.suspend();
-        SalomeApp_Tools::QtCatchCorbaException(S_ex);
-        res = SMESH::HYP_UNKNOWN_FATAL;
-      }
+    {
+      wc.suspend();
+      SalomeApp_Tools::QtCatchCorbaException(S_ex);
+      res = SMESH::HYP_UNKNOWN_FATAL;
+    }
     return res < SMESH::HYP_UNKNOWN_FATAL;
   }
 
@@ -744,26 +751,21 @@ namespace SMESH
         if (!aMesh->_is_nil()) {
           if (aMesh->HasShapeToMesh() && !aShapeObject->_is_nil()) {
             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
-            if (res < SMESH::HYP_UNKNOWN_FATAL) {
-              _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
-              if (meshSO)
-                SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
-            }
-
           }
           else if(!aMesh->HasShapeToMesh()){
             res = aMesh->RemoveHypothesis(aShapeObject, anHyp);
-            if (res < SMESH::HYP_UNKNOWN_FATAL) {
-              _PTR(SObject) meshSO = SMESH::FindSObject(aMesh);
-              if (meshSO)
-                SMESH::ModifiedMesh(meshSO, false, aMesh->NbNodes()==0);
-            }
           }
           if (res > SMESH::HYP_OK) {
             wc.suspend();
             processHypothesisStatus(res, anHyp, false);
             wc.resume();
           }
+          if ( _PTR(SObject) meshSO = SMESH::FindSObject(aMesh) )
+          {
+            if ( SMESH_Actor* actor = SMESH::FindActorByEntry( meshSO->GetID().c_str() ))
+              if( actor->GetVisibility() )
+                actor->Update();
+          }
         }
       } catch(const SALOME::SALOME_Exception& S_ex) {
         wc.suspend();
@@ -783,8 +785,7 @@ namespace SMESH
     if (!AlgoOrHyp->_is_nil()) {
       _PTR(SObject) SO_Hypothesis = SMESH::FindSObject(AlgoOrHyp);
       if (SO_Hypothesis) {
-        SObjectList listSO =
-          SMESHGUI::activeStudy()->studyDS()->FindDependances(SO_Hypothesis);
+        SObjectList listSO = SMESH::getStudy()->FindDependances(SO_Hypothesis);
 
         if(MYDEBUG) MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO.size());
         for (unsigned int i = 0; i < listSO.size(); i++) {