Salome HOME
Fix for bug Bug IPAL20288 (4x: CRASH after trying to build a sketch).
[modules/geom.git] / src / GEOMImpl / GEOMImpl_IInsertOperations.cxx
index 54155661bac4ab7de8dcf9007c320b1c3fb2b852..3dbe49e5dd0e3fc6386227cced2045d237c98df9 100644 (file)
@@ -42,6 +42,7 @@
 
 #include <GEOMImpl_Types.hxx>
 
+#include <Standard_Failure.hxx>
 #include <Standard_ErrorHandler.hxx> // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC
 
 //=============================================================================
@@ -98,6 +99,9 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::MakeCopy(Handle(GEOM_Object) the
 
   //Compute the Copy value
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Copy driver failed");
       return NULL;
@@ -155,8 +159,11 @@ void GEOMImpl_IInsertOperations::Export
 
   //Perform the Export
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
-      SetErrorCode("Export driver failed");
+      SetErrorCode("Not enough space on disk, or you haven't permissions to write this directory");
       return;
     }
   }
@@ -210,6 +217,9 @@ Handle(GEOM_Object) GEOMImpl_IInsertOperations::Import
 
   //Perform the Import
   try {
+#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
+    OCC_CATCH_SIGNALS;
+#endif
     if (!GetSolver()->ComputeFunction(aFunction)) {
       SetErrorCode("Import driver failed");
       return NULL;
@@ -250,7 +260,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
 
   if (!InitResMgr()) return Standard_False;
 
-  // Read Import formats list
+  // Read Import formats list from install directory
   if (myResMgr->Find("Import")) {
     TCollection_AsciiString aFormats (myResMgr->Value("Import"));
     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
@@ -260,6 +270,25 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
     }
   }
 
+  // Read Import formats from user directory
+  if (myResMgrUser->Find("Import")) {
+    TCollection_AsciiString aFormats (myResMgrUser->Value("Import"));
+    TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
+    int i = 1;
+    for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
+      int aLenFormats = theFormats->Length();
+      bool isFound = false;
+      for(int aInd=1;aInd<=aLenFormats;aInd++){
+       if( theFormats->Value(aInd) == aToken){
+         isFound = true;
+         break;
+       }
+      }
+      if(!isFound)
+       theFormats->Append(aToken);
+    }
+  }
+
   // Read Patterns for each supported format
   int j = 1, len = theFormats->Length();
   for (; j <= len; j++) {
@@ -267,10 +296,14 @@ Standard_Boolean GEOMImpl_IInsertOperations::ImportTranslators
     aKey = theFormats->Value(j) + ".ImportPattern";
     if (myResMgr->Find(aKey.ToCString()))
       aPattern = myResMgr->Value(aKey.ToCString());
+    else if(myResMgrUser->Find(aKey.ToCString()))
+      aPattern = myResMgrUser->Value(aKey.ToCString());
     else {
       aKey = theFormats->Value(j) + ".Pattern";
       if (myResMgr->Find(aKey.ToCString()))
         aPattern = myResMgr->Value(aKey.ToCString());
+      else if(myResMgrUser->Find(aKey.ToCString()))
+       aPattern = myResMgrUser->Value(aKey.ToCString());
       else {
         aPattern = theFormats->Value(j);
         aPattern += " Files ( *.* )";
@@ -303,7 +336,7 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
 
   if (!InitResMgr()) return Standard_False;
 
-  // Read Export formats list
+  // Read Export formats list from install directory
   if (myResMgr->Find("Export")) {
     TCollection_AsciiString aFormats (myResMgr->Value("Export"));
     TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
@@ -313,6 +346,25 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
     }
   }
 
+  // Read Export formats list from user directory
+  if (myResMgrUser->Find("Export")) {
+    TCollection_AsciiString aFormats (myResMgrUser->Value("Export"));
+    TCollection_AsciiString aToken = aFormats.Token("| \t", 1);
+    int i = 1;
+    for (; !aToken.IsEmpty(); aToken = aFormats.Token("| \t", ++i)) {
+      int aLenFormats = theFormats->Length();
+      bool isFound = false;
+      for(int aInd=1;aInd<=aLenFormats;aInd++){
+       if( theFormats->Value(aInd) == aToken){
+         isFound = true;
+         break;
+       }
+      }
+      if(!isFound)
+       theFormats->Append(aToken);
+    }
+  }
+
   // Read Patterns for each supported format
   int j = 1, len = theFormats->Length();
   for (; j <= len; j++) {
@@ -320,10 +372,14 @@ Standard_Boolean GEOMImpl_IInsertOperations::ExportTranslators
     aKey = theFormats->Value(j) + ".ExportPattern";
     if (myResMgr->Find(aKey.ToCString()))
       aPattern = myResMgr->Value(aKey.ToCString());
+    else if (myResMgrUser->Find(aKey.ToCString()))
+      aPattern = myResMgrUser->Value(aKey.ToCString());
     else {
       aKey = theFormats->Value(j) + ".Pattern";
       if (myResMgr->Find(aKey.ToCString()))
         aPattern = myResMgr->Value(aKey.ToCString());
+      else if (myResMgrUser->Find(aKey.ToCString()))
+       aPattern = myResMgrUser->Value(aKey.ToCString());
       else {
         aPattern = theFormats->Value(j);
         aPattern += " Files ( *.* )";
@@ -353,7 +409,8 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
   if (isImport) aMode = "Import";
   else aMode = "Export";
 
-  // Read supported formats for the certain mode
+  
+  // Read supported formats for the certain mode from install directory
   if (myResMgr->Find(aMode.ToCString())) {
     TCollection_AsciiString aFormats (myResMgr->Value(aMode.ToCString()));
     if (aFormats.Search(theFormat) > -1) {
@@ -362,13 +419,34 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
       aKey += ".";
       aKey += aMode;
       if (myResMgr->Find(aKey.ToCString())) {
-        TCollection_AsciiString aLibName (myResMgr->Value(aKey.ToCString()));
+        TCollection_AsciiString aLibName (myResMgr->Value(aKey.ToCString()));        
+#ifndef WNT
+        aLibName += ".so";     
+#else
+        aLibName += ".dll";
+#endif
         theLibName = new TCollection_HAsciiString (aLibName);
         return Standard_True;
       }
     }
   }
-
+  
+  // Read supported formats for the certain mode from user directory
+  if (myResMgrUser->Find(aMode.ToCString())) {
+    TCollection_AsciiString aFormats (myResMgrUser->Value(aMode.ToCString()));
+    if (aFormats.Search(theFormat) > -1) {
+      // Read library name for the supported format
+      TCollection_AsciiString aKey (theFormat);
+      aKey += ".";
+      aKey += aMode;
+      if (myResMgrUser->Find(aKey.ToCString())) {
+        TCollection_AsciiString aLibName (myResMgrUser->Value(aKey.ToCString()));
+        theLibName = new TCollection_HAsciiString (aLibName);
+        return Standard_True;
+      }
+    }
+  }
+  
   return Standard_False;
 }
 
@@ -379,16 +457,34 @@ Standard_Boolean GEOMImpl_IInsertOperations::IsSupported
 //=============================================================================
 Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
 {
+  bool isResourceFound     = false;
+  bool isResourceFoundUser = false;
+  TCollection_AsciiString aUserResDir,aResDir;
+  
   if (myResMgr.IsNull()) {
     // Initialize the Resource Manager
-    TCollection_AsciiString aResDir (getenv("GEOM_ROOT_DIR"));
+    TCollection_AsciiString aNull;
+    aResDir = TCollection_AsciiString(getenv("GEOM_ROOT_DIR"));
 #ifdef WNT
-    aResDir += "\\share\\salome\\resources";
+    aResDir += "\\share\\salome\\resources\\geom";
 #else
-    aResDir += "/share/salome/resources";
+    aResDir += "/share/salome/resources/geom";
 #endif
+    
+    myResMgr = new Resource_Manager ("ImportExport", aResDir, aNull, Standard_False);
+
+    isResourceFound = true;
+    if (!myResMgr->Find("Import") && !myResMgr->Find("Export")) {
+      // instead of complains in Resource_Manager
+      isResourceFound = false;
+      INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
+    }
+  } else
+    isResourceFound = true;
+
+  if (myResMgrUser.IsNull()) {
     char * dir = getenv("GEOM_ENGINE_RESOURCES_DIR");
-    TCollection_AsciiString aUserResDir;
+    TCollection_AsciiString aNull;
     if ( dir )
     {
       aUserResDir = dir;
@@ -402,14 +498,24 @@ Standard_Boolean GEOMImpl_IInsertOperations::InitResMgr()
       aUserResDir += "/.salome/resources";
 #endif
     }
-    myResMgr = new Resource_Manager ("ImportExport", aResDir, aUserResDir, Standard_False);
 
-    if (!myResMgr->Find("Import") && !myResMgr->Find("Export")) {
+    myResMgrUser = new Resource_Manager ("ImportExport", aNull, aUserResDir, Standard_False);
+
+    isResourceFoundUser = true;
+    
+    if (!myResMgrUser->Find("Import") && !myResMgrUser->Find("Export")) {
       // instead of complains in Resource_Manager
-      INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString() <<
-            " and in " << aUserResDir.ToCString() );
+      isResourceFoundUser = false;
     }
+      
+  } else
+    isResourceFoundUser = true;
+    
+  if(!isResourceFound && !isResourceFoundUser){
+    INFOS("No valid file \"ImportExport\" found in " << aResDir.ToCString());
+    INFOS("No valid file \"ImportExport\" found in " << aUserResDir.ToCString() );
   }
 
-  return ( myResMgr->Find("Import") || myResMgr->Find("Export") );
+  return ( myResMgr->Find("Import") || myResMgr->Find("Export") ||
+          myResMgrUser->Find("Import") || myResMgrUser->Find("Export"));
 }