]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Implementation of muti-save mode support for ASCII mode persistent
authorapo <apo@opencascade.com>
Thu, 12 Jul 2007 11:28:24 +0000 (11:28 +0000)
committerapo <apo@opencascade.com>
Thu, 12 Jul 2007 11:28:24 +0000 (11:28 +0000)
src/VISU_I/VISU_Gen_i.cc
src/VISU_I/VISU_MultiResult_i.cc
src/VISU_I/VISU_MultiResult_i.hh
src/VISU_I/VISU_Result_i.cc
src/VISU_I/VISU_Result_i.hh

index 7354538953c5fcce7f33c6eb2d8c5c322f811322..36438e8f7cae91c2e8ebe9e4ca4306e90d47ba73 100644 (file)
@@ -220,6 +220,20 @@ namespace VISU
   }
 
 
+  //----------------------------------------------------------------------------
+  SALOMEDS::ListOfFileNames*
+  GetListOfFileNames(const Result_i::TFileNames& theFileNames)
+  {
+    SALOMEDS::ListOfFileNames_var aListOfFileNames = new SALOMEDS::ListOfFileNames;
+    if(!theFileNames.empty()){
+      aListOfFileNames->length(theFileNames.size());
+      for(int aCounter = theFileNames.size(); aCounter > 0; aCounter--)
+       aListOfFileNames[aCounter-1] = theFileNames[aCounter-1].c_str();
+    }
+    return aListOfFileNames._retn();
+  }
+
+
   //----------------------------------------------------------------------------
   VISU_Gen_i
   ::VISU_Gen_i(CORBA::ORB_ptr theORB, PortableServer::POA_ptr thePOA,
@@ -379,29 +393,21 @@ namespace VISU
       if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
        aResult->Save(theComponent, 
                      theURL, 
-                     theIsMultiFile, 
+                     theIsMultiFile,
+                     false,
                      aFileNames, 
                      aFiles);
       }
     }
-
     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;
-    if(!aFiles.empty()){
-      aListOfFiles->length(aFiles.size());
-      for(int aCounter = aFiles.size(); aCounter > 0; aCounter--)
-       aListOfFiles[aCounter-1] = aFiles[aCounter-1].c_str();
-    }
-
     SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
+    if(aFileNames.empty())
+      return aStreamFile._retn();
+    
+    SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
+    SALOMEDS::ListOfFileNames_var aListOfFiles = GetListOfFileNames(aFiles);
+
     if(theIsMultiFile)
       aStreamFile = SALOMEDS_Tool::PutFilesToStream(theURL, aListOfFiles.in(), theIsMultiFile);
     else
@@ -415,39 +421,41 @@ namespace VISU
   SALOMEDS::TMPFile* 
   VISU_Gen_i
   ::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
-             const char* theTmpDir,
+             const char* theURL,
              bool theIsMultiFile)
   {
-    std::string aTmpDir = theIsMultiFile ? theTmpDir : SALOMEDS_Tool::GetTmpDir();
-    if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - "<<aTmpDir);
-    int aCounter = 0;
-    TColStd_SequenceOfAsciiString aFileNames;
+    std::string anURL = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - "<<anURL);
+
+   Result_i::TFileNames aFileNames;
+    Result_i::TFileNames aFiles;
+
     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;
+      SALOMEDS::SObject_var aSObject = anIter->Value();
+      CORBA::Object_var anObj = SObjectToObject(aSObject);
       if(Result_i* aResult = dynamic_cast<Result_i*>(GetServant(anObj).in())){
-       std::string aFileName;
-       if(aResult->SaveASCII(theComponent, aTmpDir, theIsMultiFile, aFileName)){
-         TCollection_AsciiString aString(const_cast<char*>(aFileName.c_str()));
-         aFileNames.Append(aString);
-       }
+       aResult->Save(theComponent, 
+                     anURL, 
+                     theIsMultiFile,
+                     true,
+                     aFileNames, 
+                     aFiles);
       }
     }
+    if(MYDEBUG) MESSAGE("VISU_Gen_i::SaveASCII - aFileNames.size() - "<<aFileNames.size());
+
     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, aSeq.in(), theIsMultiFile);
-      if(!theIsMultiFile)
-       SALOMEDS_Tool::RemoveTemporaryFiles(aTmpDir, aSeq.in(), true);
-    }
+    if(aFileNames.empty())
+      return aStreamFile._retn();
+
+    SALOMEDS::ListOfFileNames_var aListOfFileNames = GetListOfFileNames(aFileNames);
+    aStreamFile = SALOMEDS_Tool::PutFilesToStream(anURL, aListOfFileNames.in(), theIsMultiFile);
+
+    if(!theIsMultiFile)
+      SALOMEDS_Tool::RemoveTemporaryFiles(anURL, aListOfFileNames, true);
+
     return aStreamFile._retn();
   }
 
index 7c094e265df7e67d7d3866e8efbef77dbf6f7e79..e89e5d81fbd94d4e46b97595243396d8670d7ddc 100644 (file)
@@ -35,6 +35,7 @@
 #include "MULTIPR_API.hxx"
 
 #include "SALOMEDS_Tool.hxx"
+#include "HDFascii.hxx"
 
 #include <boost/thread/thread.hpp>
 #include <boost/bind.hpp>
@@ -578,14 +579,14 @@ VISU::MultiResult_i
 ::Save(SALOMEDS::SComponent_ptr theComponent,
        const std::string& theURL,
        bool theIsMultiFile,
+       bool theIsASCII,
        TFileNames& theFileNames,
        TFileNames& theFiles)
 {
-  INITMSG(MYDEBUG, "MultiResult_i::Save - this = "<<this<<"\n");
-
   bool anIsDone = Result_i::Save(theComponent, 
                                 theURL, 
-                                theIsMultiFile, 
+                                theIsMultiFile,
+                                theIsASCII, 
                                 theFileNames, 
                                 theFiles);
   if(!anIsDone)
@@ -594,6 +595,9 @@ VISU::MultiResult_i
   if(!myMultiprObj.isValidDistributedMEDFile())
     return true;
 
+  INITMSG(MYDEBUG, "MultiResult_i::Save - this = "<<this<<"\n");
+  INITMSGA(MYDEBUG, 0, "theIsMultiFile = "<<theIsMultiFile<<"; theIsASCII = "<<theIsASCII<<"\n");
+
   // To generate an unique prefix for the set of multi sub files
   std::string aPrefix;
   if (theIsMultiFile) {
@@ -628,16 +632,17 @@ VISU::MultiResult_i
     aFileName = aFileName + aSuffix;
     INITMSG(MYDEBUG, "aFileName = '"<<aFileName<<"'\n");
 
-    if(theIsMultiFile){
-      std::string aPathToCopy(theURL + aFileName);
-      BEGMSG(MYDEBUG, "aPathToCopy = '"<<aPathToCopy<<"'\n");
+    std::string aPathToCopy(theURL + aFileName);
+    BEGMSG(MYDEBUG, "aPathToCopy = '"<<aPathToCopy<<"'\n");
+
+    if(theIsMultiFile)
       if(!VISU::CopyFile(aFile, aPathToCopy))
        return false;
-    }
 
-    if(!theIsMultiFile)
-      theFileNames.push_back(aFileName);
+    if(theIsMultiFile || theIsASCII)
+      HDFascii::ConvertFromHDFToASCII(const_cast<char*>(aPathToCopy.c_str()), true);
 
+    theFileNames.push_back(aFileName);
     theFiles.push_back(aFile);
   }
   
@@ -675,7 +680,7 @@ VISU::MultiResult_i
   {
     std::string aBase, aSuffix;
     SplitName(GetName(), aBase, aSuffix);
-    BEGMSG(MYDEBUG, "aBase = '"<<aBase<<"'; aSuffix = '"<<aSuffix<<"'\n");
+    INITMSG(MYDEBUG, "aBase = '"<<aBase<<"'; aSuffix = '"<<aSuffix<<"'\n");
 
     QFileInfo aFileInfo(myMultiprObj.getSequentialMEDFilename());
     std::string aFilePrefix = aFileInfo.baseName(TRUE).latin1();
@@ -730,7 +735,7 @@ VISU::MultiResult_i
   
   std::string aBase, aSuffix;
   SplitName(GetName(), aBase, aSuffix);
-  BEGMSG(MYDEBUG, "aBase = '"<<aBase<<"'; aSuffix = '"<<aSuffix<<"'\n");
+  INITMSGA(MYDEBUG, 0, "aBase = '"<<aBase<<"'; aSuffix = '"<<aSuffix<<"'\n");
 
   std::string aSourceFileName = GetFileInfo().absFilePath().latin1();
   BEGMSG(MYDEBUG, "aSourceFileName = '"<<aSourceFileName<<"'\n");    
@@ -1077,7 +1082,7 @@ VISU::MultiResult_i
       }
     }
     int aRes = multipr::merge(aFileNames, theMeshName.c_str(), theFieldName.c_str(), aFileName.c_str());
-    BEGMSG(MYDEBUG, "aRes = "<<aRes<<"\n");
+    INITMSGA(MYDEBUG, 0, "aRes = "<<aRes<<"\n");
     if (aRes == 0) {
       QFile(aFileName.c_str()).remove();
       throw std::runtime_error("empty mesh"); 
index e8e6eb285b40b6eb9c1b80c88d2a4adde32019bc..beec3bb6fe2f6d575182ebda23f879c85826fa6b 100644 (file)
@@ -154,8 +154,9 @@ namespace VISU
     Save(SALOMEDS::SComponent_ptr theComponent,
         const std::string& theURL,
         bool theIsMultiFile,
+        bool theIsASCII,
         TFileNames& theFileNames,
-        TFileNames& theFullFileNames);
+        TFileNames& theFiles);
 
     virtual
     void
index 951a5b5242edf607afa92bffa929b56aad40975b..86be74bb98f07655f90f317e35139776ccf8f9c5 100644 (file)
@@ -600,6 +600,7 @@ VISU::Result_i
 ::Save(SALOMEDS::SComponent_ptr theComponent,
        const std::string& theURL,
        bool theIsMultiFile,
+       bool theIsASCII,
        TFileNames& theFileNames,
        TFileNames& theFiles)
 {
@@ -607,6 +608,7 @@ VISU::Result_i
   case Result_i::eImportFile:
   case Result_i::eCopyAndImportFile: {
     INITMSG(MYDEBUG, "Result::Save - this = "<<this<<"\n");
+    INITMSGA(MYDEBUG, 0, "theIsMultiFile = "<<theIsMultiFile<<"; theIsASCII = "<<theIsASCII<<"\n");
 
     std::string aPrefix;
     if (theIsMultiFile) {
@@ -620,16 +622,17 @@ VISU::Result_i
     std::string aFile = GetFileInfo().filePath().latin1();
     BEGMSG(MYDEBUG, "aFile = '"<<aFile<<"'\n");
 
-    if(theIsMultiFile){
-      std::string aPathToCopy(theURL + aFileName);
-      BEGMSG(MYDEBUG, "aPathToCopy = '"<<aPathToCopy<<"'\n");
+    std::string aPathToCopy(theURL + aFileName);
+    BEGMSG(MYDEBUG, "aPathToCopy = '"<<aPathToCopy<<"'\n");
+
+    if(theIsMultiFile || theIsASCII)
       if(!VISU::CopyFile(aFile, aPathToCopy))
        return false;
-    }
 
-    if(!theIsMultiFile)
-      theFileNames.push_back(aFileName);
+    if(theIsASCII)
+      HDFascii::ConvertFromHDFToASCII(const_cast<char*>(aPathToCopy.c_str()), true);
 
+    theFileNames.push_back(aFileName);
     theFiles.push_back(aFile);
 
     return true;
@@ -639,48 +642,6 @@ VISU::Result_i
 }
 
 
-//---------------------------------------------------------------
-bool
-VISU::Result_i
-::SaveASCII(SALOMEDS::SComponent_ptr theComponent,
-           const std::string& theTmpDir,
-           bool theIsMultiFile,
-           std::string& theFileName)
-{
-  switch(GetCreationId()){
-  case Result_i::eImportFile:
-  case Result_i::eCopyAndImportFile: {
-    std::string aPrefix;
-    if (theIsMultiFile) {
-      CORBA::String_var anURL = GetStudyDocument()->URL();
-      aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
-    }
-    theFileName = aPrefix + "_" + GetName();
-
-    QString aTmpDir = QDir::convertSeparators(theTmpDir.c_str());
-    QString aCommand;
-    aCommand.sprintf("%s %s%s",
-                    GetFileInfo().filePath().latin1(),
-                    aTmpDir.latin1(),
-                    theFileName.c_str());
-    aCommand = QDir::convertSeparators( aCommand );
-    aCommand.prepend( COPY_COMMAND );
-         
-    if(system(aCommand.latin1())){
-      if(MYDEBUG) MESSAGE("Result_i::SaveASCII - Can't execute the command :"<<aCommand);
-      return false;
-    }else
-      if(MYDEBUG) MESSAGE("Result_i::SaveASCII - "<<aCommand);
-
-    QString aStudyPath = aTmpDir.append(theFileName.c_str());
-    HDFascii::ConvertFromHDFToASCII(const_cast<char*>(aStudyPath.latin1()), true);
-    return true;
-  }}
-
-  return false;
-}
-
-
 //---------------------------------------------------------------
 CORBA::Boolean 
 VISU::Result_i
index d1ceb6f2d677adcdbab134652102555d60890616..b0131f861c0a17eed9da2f1e95eebebe1d1d6bfe 100644 (file)
@@ -292,15 +292,9 @@ namespace VISU
     Save(SALOMEDS::SComponent_ptr theComponent,
         const std::string& theURL,
         bool theIsMultiFile,
+        bool theIsASCII,
         TFileNames& theFileNames,
-        TFileNames& theFullFileNames);
-
-    virtual 
-    bool
-    SaveASCII(SALOMEDS::SComponent_ptr theComponent,
-             const std::string& theURL,
-             bool theIsMultiFile,
-             std::string& theFileName);
+        TFileNames& theFiles);
 
     //---------------------------------------------------------------
     virtual