Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[modules/visu.git] / src / VISU_I / VISU_Gen_i.cc
index ff03f9f2b308cc3d799fbdef92e285ac6e3f781b..c5a950cc427b8c7462ddfb5d9f007d1ba927e70d 100644 (file)
@@ -85,6 +85,7 @@
 #include <strstream>
 
 #include "Utils_ExceptHandlers.hxx"
+#include "CASCatch.hxx"
 
 using namespace std;
 
@@ -238,18 +239,23 @@ namespace VISU
                    const char* theFieldName, 
                    CORBA::Double theIteration)
   {
+    CASCatch_TRY{       
 #ifndef _DEXCEPT_
-    try{
+      try{
 #endif
-      if(theColoredPrs3d->Create(theMeshName,theEntity,theFieldName,int(theIteration)))
-       return true;
+       if(theColoredPrs3d->Create(theMeshName,theEntity,theFieldName,int(theIteration)))
+         return true;
 #ifndef _DEXCEPT_
-    }catch(std::exception& exc){
-      INFOS("Follow exception was occured :\n"<<exc.what());
-    }catch(...){
-      INFOS("Unknown exception was occured!");
-    }
+      }catch(std::exception& exc){
+       INFOS("Follow exception was occured :\n"<<exc.what());
+      }catch(...){
+       INFOS("Unknown exception was occured!");
+      }
 #endif
+    }CASCatch_CATCH(Standard_Failure) {
+      Handle(Standard_Failure) aFail = Standard_Failure::Caught();
+      INFOS("Follow signal was occured :\n"<<aFail->GetMessageString());
+    }
     return false;
   }
 
@@ -299,58 +305,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();
   }