Salome HOME
Patch for MacOS (from SALOME forum)
[modules/smesh.git] / src / SMESH_I / SMESH_Gen_i.cxx
index 2397c7f6c3643c565e5b1f3c4e0ca2a1f2501e2b..d4d65b56c95b9b4a6cec955dfd5b10c018a6bb7d 100644 (file)
@@ -54,6 +54,7 @@
  #include <process.h>
 #else
  #include <dlfcn.h>
+ #include <libgen.h> // for basename function
 #endif
 
 #ifdef WIN32
@@ -63,7 +64,7 @@
  #define UnLoadLib( handle ) FreeLibrary( handle );
 #else
  #define LibHandle void*
- #define LoadLib( name ) dlopen( name, RTLD_LAZY )
+ #define LoadLib( name ) dlopen( name, RTLD_LAZY | RTLD_GLOBAL )
  #define GetProc dlsym
  #define UnLoadLib( handle ) dlclose( handle );
 #endif
@@ -382,8 +383,10 @@ GenericHypothesisCreator_i* SMESH_Gen_i::getHypothesisCreator(const char* theHyp
         !strcmp( theLibName+libNameLen-3, ".so" ))
     {
       //the old format
-#ifdef WIN32
+#if defined(WIN32)
       aPlatformLibName = std::string( theLibName+3, libNameLen-6 ) + ".dll";
+#elif defined(__APPLE__)
+      aPlatformLibName = std::string( theLibName, libNameLen-3 ) + ".dylib";
 #else
       aPlatformLibName = theLibName;
 #endif
@@ -391,11 +394,13 @@ GenericHypothesisCreator_i* SMESH_Gen_i::getHypothesisCreator(const char* theHyp
     else
     {
       //try to use new format
-#ifdef WIN32
+#if defined(WIN32)
       aPlatformLibName = theLibName;
       aPlatformLibName += ".dll";
+#elif defined(__APPLE__)
+      aPlatformLibName = std::string( "lib" ) + std::string( theLibName ) + ".dylib";
 #else
-      aPlatformLibName = "lib" + std::string( theLibName ) + ".so";
+      aPlatformLibName = std::string( "lib" ) + std::string( theLibName ) + ".so";
 #endif
     }
   }
@@ -960,7 +965,7 @@ void SMESH_Gen_i::SetOption(const char* name, const char* value)
     {
       vector<int> color;
       string str = value;
-      // color must be presented as a string of next form:
+      // color must be presented as a string of following form:
       if ( str.at(0) == '#' && str.length() == 7 ) { // hexadecimal color ("#ffaa00", for example)
         str = str.substr(1);
         for ( size_t i = 0; i < str.length()/2; i++ )
@@ -1169,7 +1174,7 @@ SMESH::mesh_array* SMESH_Gen_i::CreateMeshesFromMEDorSAUV( const char* theFileNa
   _splitpath( theFileNameForPython, NULL, NULL, bname, NULL );
   string aFileName = bname;
 #else
-  string aFileName = basename( theFileNameForPython );
+  string aFileName = basename( const_cast<char *>(theFileNameForPython) );
 #endif
   // Retrieve mesh names from the file
   DriverMED_R_SMESHDS_Mesh myReader;
@@ -1318,7 +1323,7 @@ SMESH::SMESH_Mesh_ptr SMESH_Gen_i::CreateMeshesFromSTL( const char* theFileName
   _splitpath( theFileName, NULL, NULL, bname, NULL );
   string aFileName = bname;
 #else
-  string aFileName = basename( theFileName );
+  string aFileName = basename( const_cast<char *>(theFileName) );
 #endif
   // publish mesh in the study
   if ( CanPublishInStudy( aMesh ) ) {
@@ -1447,7 +1452,7 @@ SMESH_Gen_i::CreateMeshesFromGMF( const char*             theFileName,
   _splitpath( theFileName, NULL, NULL, bname, NULL );
   string aFileName = bname;
 #else
-  string aFileName = basename( theFileName );
+  string aFileName = basename( const_cast<char *>(theFileName) );
 #endif
   // publish mesh in the study
   if ( CanPublishInStudy( aMesh ) ) {
@@ -1924,7 +1929,10 @@ CORBA::Boolean SMESH_Gen_i::Compute( SMESH::SMESH_Mesh_ptr theMesh,
       // call implementation compute
       ::SMESH_Mesh& myLocMesh = meshServant->GetImpl();
       myGen.PrepareCompute( myLocMesh, myLocShape );
-      bool ok = myGen.Compute( myLocMesh, myLocShape, myLocShape != myLocMesh.GetShapeToMesh());
+      int how = ::SMESH_Gen::COMPACT_MESH;
+      if ( myLocShape != myLocMesh.GetShapeToMesh() ) // compute a sub-mesh
+        how |= ::SMESH_Gen::SHAPE_ONLY;
+      bool ok = myGen.Compute( myLocMesh, myLocShape, how );
       meshServant->CreateGroupServants(); // algos can create groups (issue 0020918)
       myLocMesh.GetMeshDS()->Modified();
       return ok;