Salome HOME
NPAL14828: Impossible to load a study created in batch mode. Improve getting a direct... V3_2_5
authorjfa <jfa@opencascade.com>
Thu, 8 Feb 2007 11:42:07 +0000 (11:42 +0000)
committerjfa <jfa@opencascade.com>
Thu, 8 Feb 2007 11:42:07 +0000 (11:42 +0000)
src/SALOMEDSImpl/SALOMEDSImpl_StudyBuilder.cxx

index 05d9dec5e8378a2f93a19adc0eb54a459c6b03ad..09c214714bde6028225ae0f3c24c5fa11ae4d7aa 100644 (file)
@@ -33,13 +33,16 @@ using namespace std;
 #include "SALOMEDSImpl_SComponent.hxx"
 #include "SALOMEDSImpl_Tool.hxx"
 
+#include <SALOMEDSImpl_ChildNodeIterator.hxx>
+
 #include <TDF_ChildIterator.hxx>
 #include <TDF_Label.hxx>
 #include <TDF_Tool.hxx>
 #include <TDF_Data.hxx>
-#include <SALOMEDSImpl_ChildNodeIterator.hxx>
 #include <TDF_ListIteratorOfAttributeList.hxx>
 
+#include <OSD_Path.hxx>
+
 #include <HDFOI.hxx>
 #include <stdlib.h> 
 
@@ -294,6 +297,7 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const Handle(SALOMEDSImpl_SComponent)&
     if (aLocked) anSCO->GetStudy()->GetProperties()->SetLocked(false);
 
     TCollection_ExtendedString Res(Att->Value());
+    TCollection_AsciiString aHDFPath(Res);
 
     Handle(SALOMEDSImpl_AttributeComment) type;
     TCollection_ExtendedString DataType;
@@ -315,8 +319,6 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const Handle(SALOMEDSImpl_SComponent)&
 
     DefineComponentInstance (anSCO, aDriver->GetIOR());
 
-    TCollection_AsciiString aHDFPath(Res);
-
     TCollection_AsciiString aHDFUrl;
     bool isASCII = false;
     if (HDFascii::isASCII(aHDFPath.ToCString())) {
@@ -364,18 +366,20 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const Handle(SALOMEDSImpl_SComponent)&
       ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
 
       // set path without file name from URL 
-      int aFileNameSize = Res.Length();
-      char* aDir = new char[aFileNameSize];
-      memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
-      for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
-       if (aDir[aCounter] == '/') {
-         aDir[aCounter+1] = 0;
-         break;
-       }
+      //int aFileNameSize = Res.Length();
+      //char* aDir = new char[aFileNameSize];
+      //memcpy(aDir, TCollection_AsciiString(Res).ToCString(), aFileNameSize);
+      //for(int aCounter = aFileNameSize-1; aCounter>=0; aCounter--)
+      //if (aDir[aCounter] == '/') {
+      //  aDir[aCounter+1] = 0;
+      //  break;
+      //}
+      // Above code was working wrong for paths without '/' inside.
+      TCollection_AsciiString aDir = SALOMEDSImpl_Tool::GetDirFromPath(Res);
 
       bool aResult = (ASCIIfileState[0]=='A')?
-       aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir, aMultifileState[0]=='M'):
-       aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir, aMultifileState[0]=='M');
+       aDriver->LoadASCII(anSCO, aStreamFile, aStreamSize, aDir.ToCString(), aMultifileState[0]=='M'):
+       aDriver->Load(anSCO, aStreamFile, aStreamSize, aDir.ToCString(), aMultifileState[0]=='M');
 
       if(aStreamFile != NULL) delete []aStreamFile; 
 
@@ -386,7 +390,7 @@ bool SALOMEDSImpl_StudyBuilder::LoadWith(const Handle(SALOMEDSImpl_SComponent)&
        throw HDFexception("Unable to load component");
       }
 
-      if(aDir != NULL) delete []aDir;
+      //if(aDir != NULL) delete []aDir;
 
       multifile_hdf_dataset->CloseOnDisk();
       multifile_hdf_dataset = 0;