]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Final fix for Bug GVIEW10647
authorapo <apo@opencascade.com>
Fri, 10 Feb 2006 14:12:44 +0000 (14:12 +0000)
committerapo <apo@opencascade.com>
Fri, 10 Feb 2006 14:12:44 +0000 (14:12 +0000)
   Crash saving the model
(to avoid usage of the temporary directory during the saving)

src/VISU_I/VISU_Gen_i.cc

index ff03f9f2b308cc3d799fbdef92e285ac6e3f781b..f4cdedbe7cf2b573e60295d9bb477a32f4326b04 100644 (file)
@@ -299,58 +299,69 @@ namespace VISU
   //===========================================================================
   SALOMEDS::TMPFile* VISU_Gen_i::Save(SALOMEDS::SComponent_ptr theComponent,
                                      const char* theURL,
-                                     bool isMultiFile)
+                                     bool theIsMultiFile)
   {
     Mutex mt(myMutex);
-    string aDir = isMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
-    TCollection_AsciiString aTmpDir (const_cast<char*>(aDir.c_str()));
+    string aTmpDir = theURL;
     if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
-    int aCounter = 0;
-    TColStd_SequenceOfAsciiString aFileNames;
-    SALOMEDS::Study_var aStudy = theComponent->GetStudy();
-
-    //CORBA::Boolean anIsValidScript;
-    //Engines::TMPFile_var aDump = DumpPython(aStudy,false,anIsValidScript);
+    
+    typedef std::vector<std::string> TFileNames;
+    TFileNames aFileNames;
+    TFileNames aFiles;
 
-    SALOMEDS::ChildIterator_var itBig = aStudy->NewChildIterator(theComponent);
-    for (; itBig->More(); itBig->Next()) {
-      SALOMEDS::SObject_var gotBranch = itBig->Value();
+    SALOMEDS::Study_var aStudy = theComponent->GetStudy();
+    SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
+    for (; anIter->More(); anIter->Next()) {
+      SALOMEDS::SObject_var gotBranch = anIter->Value();
       CORBA::Object_var anObj = SObjectToObject(gotBranch);
       if(CORBA::is_nil(anObj)) continue;
-      if(Result_i* pResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
-       switch(pResult->GetCreationId()){
+      if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
+       switch(aResult->GetCreationId()){
        case Result_i::eImportFile:
        case Result_i::eCopyAndImportFile: {
-         const QFileInfo& aFileInfo = pResult->GetFileInfo();
-         QString aPrefix("");
-         if (isMultiFile) aPrefix = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()).c_str();
-         QString aFileName = aPrefix + "_" + (pResult->GetName()).c_str();
-         static QString aCommand;
-         aCommand.sprintf("cp %s %s%s",aFileInfo.filePath().latin1(),aTmpDir.ToCString(),aFileName.latin1());
-
-         int aRes = system(aCommand);
-         if(aRes){
-           if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
-           continue;
-         }else
-           if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aCommand = "<<aCommand);
-
-         TCollection_AsciiString aString(strdup(aFileName.latin1()));
-         aFileNames.Append(aString);
+         const QFileInfo& aFileInfo = aResult->GetFileInfo();
+         const std::string& aName = aResult->GetName();
+         std::string aFileName = std::string("_") + aName;
+         std::string aFile = aFileInfo.filePath().latin1();
+         if(theIsMultiFile){
+           aFileName = SALOMEDS_Tool::GetNameFromPath(aStudy->URL()) + aFileName;
+
+           std::ostringstream aStream;
+           aStream<<"cp "<<aFile<<" "<<aTmpDir<<aFileName;
+           std::string aCommand = aStream.str();
+           if(system(aCommand.c_str()) != 0){
+             INFOS("VISU_Gen_i::Save - Cann't execute the command :"<<aCommand);
+             continue;
+           }
+         }
+         aFileNames.push_back(aFileName);
+         aFiles.push_back(aFile);
        }}
       }
     }
-    SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.Length() - "<<aFileNames.Length());
-    if(aFileNames.Length() > 0){
-      SALOMEDS::ListOfFileNames_var aSeq = new SALOMEDS::ListOfFileNames;
-      aSeq->length(aFileNames.Length());
-      for(aCounter = aFileNames.Length(); aCounter > 0; aCounter--)
-       aSeq[aCounter-1] = CORBA::string_dup(aFileNames.Value(aCounter).ToCString());
-      aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir.ToCString(), aSeq.in(), isMultiFile);
-      if(!isMultiFile)
-       SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir.ToCString(), aSeq.in(), true);
+
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aFileNames.size() - "<<aFileNames.size());
+
+    SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
+    if(!aFileNames.empty()){
+      aListOfFileNames->length(aFileNames.size());
+      for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--)
+       aListOfFileNames[aCounter-1] = aFileNames[aCounter-1].c_str();
     }
+
+    SALOMEDS::ListOfFileNames_var aListOfFiles = new SALOMEDS::ListOfFileNames;
+    aListOfFiles->length(aFiles.size());
+    if(!aFiles.empty()){
+      for(int aCounter = aFileNames.size(); aCounter > 0; aCounter--)
+       aListOfFiles[aCounter-1] = aFiles[aCounter-1].c_str();
+    }
+
+    SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
+    if(theIsMultiFile)
+      aStreamFile = SALOMEDS_Tool::PutFilesToStream(aTmpDir, aListOfFiles.in(), theIsMultiFile);
+    else
+      aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFiles.in(), aListOfFileNames.in());
+
     return aStreamFile._retn();
   }