]> SALOME platform Git repositories - modules/visu.git/commitdiff
Salome HOME
Introduction of the first version of Persistent for MULTIPR extension in VISU functio...
authorapo <apo@opencascade.com>
Thu, 12 Jul 2007 07:46:37 +0000 (07:46 +0000)
committerapo <apo@opencascade.com>
Thu, 12 Jul 2007 07:46:37 +0000 (07:46 +0000)
src/VISU_I/VISUConfig.cc
src/VISU_I/VISU_GaussPoints_i.cc
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_ResultUtils.cc
src/VISU_I/VISU_ResultUtils.hh
src/VISU_I/VISU_Result_i.cc
src/VISU_I/VISU_Result_i.hh

index 03eb570918e10343fca02fb5409e9eefb48f439e..9b23b2819701562f5f193e2d1ad31de859af20f3 100644 (file)
@@ -658,13 +658,13 @@ namespace VISU
 
   //---------------------------------------------------------------
   QString 
-  GenerateName(const string& theFmt, int theId)
+  GenerateName(const std::string& theFmt, int theId)
   {
-    static QString aName;
+    QString aName;
     if(theId > 0)
-      aName.sprintf("%s:%d",theFmt.c_str(),theId);
+      aName.sprintf("%s:%d", theFmt.c_str(), theId);
     else
-      aName.sprintf("%s",theFmt.c_str());
+      aName.sprintf("%s", theFmt.c_str());
     return aName;
   }
 
index 1eebef219d145e35390ddabd5b6467ed1059b008..3e8ea2434fa56439e89e86d3a02d9c78f7f5526b 100644 (file)
@@ -70,9 +70,12 @@ VISU::GaussPoints_i
     return aResult;
   try{
     bool anIsEstimated = true;
-    VISU::Result_i::PInput anInput = theResult->GetInput();
+    VISU::Result_i::PInput anInput = theResult->GetInput(theMeshName,
+                                                        theEntity,
+                                                        theFieldName,
+                                                        theTimeStampNumber);
     size_t aSize = anInput->GetTimeStampOnGaussPtsSize(theMeshName,
-                                                      (VISU::TEntity)theEntity,
+                                                      VISU::TEntity(theEntity),
                                                       theFieldName,
                                                       theTimeStampNumber,
                                                       anIsEstimated);
index 426b4052ba21e4decbda421caae835f76e342aa1..249561fe43c866d5b7ad69ccc26ba98a486341a3 100644 (file)
@@ -367,10 +367,9 @@ namespace VISU
         bool theIsMultiFile)
   {
     if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - theURL = '"<<theURL<<"'");
-    
+
     Result_i::TFileNames aFileNames;
     Result_i::TFileNames aFullFileNames;
-    Result_i::TFileNames aTemporaryDirs;
 
     SALOMEDS::Study_var aStudy = theComponent->GetStudy();
     SALOMEDS::ChildIterator_var anIter = aStudy->NewChildIterator(theComponent);
@@ -382,8 +381,7 @@ namespace VISU
                      theURL, 
                      theIsMultiFile, 
                      aFileNames, 
-                     aFullFileNames,
-                     aTemporaryDirs);
+                     aFullFileNames);
       }
     }
 
@@ -406,17 +404,9 @@ namespace VISU
     SALOMEDS::TMPFile_var aStreamFile = new SALOMEDS::TMPFile(0);
     if(theIsMultiFile)
       aStreamFile = SALOMEDS_Tool::PutFilesToStream(theURL, aListOfFullFileNames.in(), theIsMultiFile);
-    else{
+    else
       aStreamFile = SALOMEDS_Tool::PutFilesToStream(aListOfFullFileNames.in(), aListOfFileNames.in());
-      Result_i::TFileNames::const_iterator anIter = aTemporaryDirs.begin();
-      for(; anIter != aTemporaryDirs.end(); anIter++){
-       filesystem::path aDirName(*anIter);
-       if(filesystem::exists(aDirName)){
-         filesystem::remove_all(aDirName);
-         if(MYDEBUG) MESSAGE("VISU_Gen_i::Save - aDirName  ='"<<aDirName.string()<<"'\n");
-       }
-      }
-    }
+
     return aStreamFile._retn();
   }
 
index faee5c18db6406c3e87aa5e07519cdea1b46f5fb..d114f15b2c0f6c4319dce9864edd095b59b95a20 100644 (file)
 #include <boost/thread/thread.hpp>
 #include <boost/bind.hpp>
 
-#include <qfileinfo.h>
-#include <qfile.h>
-#include <qdir.h>
-
 #include <strstream>
 
 #include <boost/filesystem/path.hpp>
@@ -60,6 +56,86 @@ static int MYTIMEDEBUG = 0;
 
 namespace VISU
 {
+  //---------------------------------------------------------------
+  class TSubString: public std::string
+  {
+  public:
+    typedef std::string::size_type size_type;
+
+    TSubString(std::string& theSource, 
+              const std::string& theTarget):
+      mySource(theSource),
+      myPosition(theSource.find(theTarget)),
+      mySize(theTarget.length())
+    {}
+
+    TSubString&
+    operator = (const std::string& theTarget)
+    {
+      if(myPosition != std::string::npos)
+       mySource.replace(myPosition, mySize, theTarget);
+      return *this;
+    }
+
+  private:
+    std::string& mySource;
+    size_type myPosition;
+    size_type mySize;
+  };
+
+
+  //---------------------------------------------------------------
+  inline
+  std::ostream& 
+  operator<<(std::ostream& theStream,
+            const MultiResult_i::TPartInfo& thePartInfo)
+  {
+    theStream<<(thePartInfo.myMeshName)<<" ";
+    theStream<<(thePartInfo.myPartID)<<" ";
+    theStream<<(thePartInfo.myName)<<" ";
+    theStream<<(thePartInfo.myPath)<<" ";
+    theStream<<(thePartInfo.myFileName);
+    return theStream;
+  }
+
+
+  //---------------------------------------------------------------
+  inline
+  std::istream& 
+  operator>>(std::istream& theStream,
+            MultiResult_i::TPartInfo& thePartInfo)
+  {
+    theStream>>(thePartInfo.myMeshName);
+    theStream>>(thePartInfo.myPartID);
+    theStream>>(thePartInfo.myName);
+    theStream>>(thePartInfo.myPath);
+    theStream>>(thePartInfo.myFileName);
+    return theStream;
+  }
+
+
+  //---------------------------------------------------------------
+  inline
+  MultiResult_i::TPartInfo
+  GetPartInfo(const std::string theInfoString)
+  {
+    MultiResult_i::TPartInfo aPartInfo;
+    std::istrstream anOutputStream(theInfoString.c_str());
+    anOutputStream>>aPartInfo;
+    return aPartInfo;
+  }
+
+
+  //---------------------------------------------------------------
+  inline
+  MultiResult_i::TPartInfo
+  GetPartInfo(multipr::Obj& theMultiprObj,
+             const MultiResult_i::TPartName& thePartName)
+  {
+    return GetPartInfo(theMultiprObj.getPartInfo(thePartName.c_str()));
+  }
+
+
   //---------------------------------------------------------------
   inline
   std::string
@@ -203,7 +279,8 @@ namespace VISU
             MultiResult_i::TMainPart2SubPartNames* theMainPart2SubPartNames,
             CORBA::Boolean* theIsDone,
             CORBA::Boolean theIsBuild,
-            _PTR(Study) theStudy)
+            _PTR(Study) theStudy,
+            bool thePublishInStudy)
   {
     if(!theIsBuild || *theIsDone)
       return;
@@ -213,13 +290,14 @@ namespace VISU
     TTransactionManager aTransactionManager(theStudy);
     
     try {
-       multipr::Obj& aMultiprObj = *theMultiprObj;
-       const VISU::TMeshMap& aMeshMap = theInput->GetMeshMap();
-       VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
-       const VISU::PMesh& aMesh = aMeshMapIter->second;
-       
-       MultiResult_i::TPartNames aPartNames = aMultiprObj.getParts();
-       
+      multipr::Obj& aMultiprObj = *theMultiprObj;
+      const VISU::TMeshMap& aMeshMap = theInput->GetMeshMap();
+      VISU::TMeshMap::const_iterator aMeshMapIter = aMeshMap.begin();
+      const VISU::PMesh& aMesh = aMeshMapIter->second;
+      
+      MultiResult_i::TPartNames aPartNames = aMultiprObj.getParts();
+      
+      if(thePublishInStudy){
        QString aComment = "Sub-parts: #";
        aComment += QString::number(aPartNames.size());
        
@@ -231,73 +309,69 @@ namespace VISU
                         NO_PERFSITENT_REF,
                         aComment.latin1(),
                         false);
+       }
+      
+      MultiResult_i::TPartInfos& aPartInfos = *thePartInfos;
+      MultiResult_i::TPartName2FileName& aPartName2FileName = *thePartName2FileName;
+      MultiResult_i::TPartName2Resolution& aPartName2Resolution = *thePartName2Resolution;
+      
+      MultiResult_i::TMainPart2SubPartNames& aMainPart2SubPartNames = *theMainPart2SubPartNames;
+      
+      for (size_t aPartID = 0 ; aPartID < aPartNames.size() ; aPartID++) {
+       const MultiResult_i::TPartName& aPartName = aPartNames[aPartID];
+       MultiResult_i::TPartName aMainPart = ExtractMainPart(aPartName);
+       aMainPart2SubPartNames[aMainPart].insert(aPartName);
+      }
+      
+      std::string aLastEntry;
+      for (size_t aPartID = 0 ; aPartID < aPartNames.size() ; aPartID++) {
+       const MultiResult_i::TPartName& aPartName = aPartNames[aPartID];
+       MultiResult_i::TPartInfo aPartInfo = GetPartInfo(aMultiprObj, aPartName);
+
+       QFileInfo aFileInfo(aPartInfo.myFileName.c_str());
+       aPartInfos[aFileInfo.fileName()] = aPartInfo;
        
-       MultiResult_i::TPartInfos& aPartInfos = *thePartInfos;
-       MultiResult_i::TPartName2FileName& aPartName2FileName = *thePartName2FileName;
-       MultiResult_i::TPartName2Resolution& aPartName2Resolution = *thePartName2Resolution;
-       
-       MultiResult_i::TMainPart2SubPartNames& aMainPart2SubPartNames = *theMainPart2SubPartNames;
+       aPartName2FileName[aPartInfo.myName] = aPartInfo.myFileName;
        
-       for (size_t aPartID = 0 ; aPartID < aPartNames.size() ; aPartID++) {
-         const MultiResult_i::TPartName& aPartName = aPartNames[aPartID];
-         MultiResult_i::TPartName aMainPart = ExtractMainPart(aPartName);
-         aMainPart2SubPartNames[aMainPart].insert(aPartName);
-       }
+       if(!thePublishInStudy)
+         continue;
        
-       std::string aLastEntry;
-       for (size_t aPartID = 0 ; aPartID < aPartNames.size() ; aPartID++) {
-         const MultiResult_i::TPartName& aPartName = aPartNames[aPartID];
-         std::string aStringInfo = aMultiprObj.getPartInfo(aPartName.c_str());
-         
-         MultiResult_i::TPartInfo aPartInfo;
-         std::istrstream anOutputStream(aStringInfo.c_str());
-         anOutputStream>>(aPartInfo.myMeshName);
-         anOutputStream>>(aPartInfo.myPartID);
-         anOutputStream>>(aPartInfo.myName);
-         anOutputStream>>(aPartInfo.myPath);
-         anOutputStream>>(aPartInfo.myFileName);
-         
-         QFileInfo aFileInfo(aPartInfo.myFileName.c_str());
-         aPartInfos[aFileInfo.fileName()] = aPartInfo;
-         
-         aPartName2FileName[aPartInfo.myName] = aPartInfo.myFileName;
-         
-         QString aComment = "";
-         MultiResult_i::TResolutions aResoltutions = GetResolutions(aMainPart2SubPartNames, aPartInfo.myName);
-         std::string aResoltutionsString = Resolutions2String(aResoltutions);
-         if ( IsFullResolution(aPartInfo.myName) ) {
-           std::string anIconName = GetIconName(aMainPart2SubPartNames, aPartInfo.myName);
-           VISU::Result::Resolution aResolution = GetResolution(aMainPart2SubPartNames, aPartInfo.myName);
-           aComment.sprintf("myComment=PART;myMeshName=%s;myFile=%s;myResolutions=%s;myState=%c", 
-                            aPartInfo.myMeshName.c_str(), aPartInfo.myFileName.c_str(), aResoltutionsString.c_str(), aResolution); 
-           aLastEntry = CreateAttributes(theStudy,
-                                         aMesh->myPartsEntry,
-                                         anIconName,
-                                         NO_IOR,
-                                         aPartInfo.myName,
-                                         NO_PERFSITENT_REF,
-                                         aComment.latin1(),
-                                         true);
-           aPartName2Resolution[aPartInfo.myName] = aResolution;
-         } else {
-           aComment.sprintf("myComment=PART;myMeshName=%s;myFile=%s;myResolutions=%s", 
-                             aPartInfo.myMeshName.c_str(), aPartInfo.myFileName.c_str(), aResoltutionsString.c_str()); 
-           CreateAttributes(theStudy,
-                            aLastEntry,
-                            NO_ICON,
-                            NO_IOR,
-                            aPartInfo.myName,
-                            NO_PERFSITENT_REF,
-                            aComment.latin1(),
-                            true);
-         }
+       QString aComment = "";
+       MultiResult_i::TResolutions aResoltutions = GetResolutions(aMainPart2SubPartNames, aPartInfo.myName);
+       std::string aResoltutionsString = Resolutions2String(aResoltutions);
+       if ( IsFullResolution(aPartInfo.myName) ) {
+         std::string anIconName = GetIconName(aMainPart2SubPartNames, aPartInfo.myName);
+         VISU::Result::Resolution aResolution = GetResolution(aMainPart2SubPartNames, aPartInfo.myName);
+         aComment.sprintf("myComment=PART;myMeshName=%s;myName=%s;myResolutions=%s;myState=%d", 
+                          aPartInfo.myMeshName.c_str(), aPartInfo.myName.c_str(), aResoltutionsString.c_str(), aResolution); 
+         aLastEntry = CreateAttributes(theStudy,
+                                       aMesh->myPartsEntry,
+                                       anIconName,
+                                       NO_IOR,
+                                       aPartInfo.myName,
+                                       NO_PERFSITENT_REF,
+                                       aComment.latin1(),
+                                       true);
+         aPartName2Resolution[aPartInfo.myName] = aResolution;
+       } else {
+         aComment.sprintf("myComment=PART;myMeshName=%s;myName=%s;myResolutions=%s", 
+                          aPartInfo.myMeshName.c_str(), aPartInfo.myName.c_str(), aResoltutionsString.c_str()); 
+         CreateAttributes(theStudy,
+                          aLastEntry,
+                          NO_ICON,
+                          NO_IOR,
+                          aPartInfo.myName,
+                          NO_PERFSITENT_REF,
+                          aComment.latin1(),
+                          true);
        }
-       
-       *theIsDone = true;
+      }
+      
+      *theIsDone = true;
     }catch(std::exception& exc){
-       INFOS("Follow exception was occured :\n"<<exc.what());
+      INFOS("Follow exception was occured :\n"<<exc.what());
     }catch(...){
-       INFOS("Unknown exception was occured!");
+      INFOS("Unknown exception was occured!");
     }
     
     ProcessVoidEvent(new TUpdateObjBrowser(theStudy->StudyId(), theIsDone));
@@ -317,6 +391,7 @@ namespace VISU
     CORBA::Boolean* myIsDone;
     CORBA::Boolean myIsBuild;
     _PTR(Study) myStudy;
+    bool myPublishInStudy;
 
     TBuildPartsArgs(Result_i* theResult,
                    Result_i::PInput theInput,
@@ -327,7 +402,8 @@ namespace VISU
                    MultiResult_i::TMainPart2SubPartNames* theMainPart2SubPartNames,
                    CORBA::Boolean* theIsDone,
                    CORBA::Boolean theIsBuild,
-                   _PTR(Study) theStudy):
+                   _PTR(Study) theStudy,
+                   bool thePublishInStudy):
       myResult(theResult),
       myInput(theInput),
       myMultiprObj(theMultiprObj),
@@ -337,7 +413,8 @@ namespace VISU
       myMainPart2SubPartNames(theMainPart2SubPartNames),
       myIsDone(theIsDone),
       myIsBuild(theIsBuild),
-      myStudy(theStudy)
+      myStudy(theStudy),
+      myPublishInStudy(thePublishInStudy)
     {}
   };
 
@@ -355,7 +432,8 @@ namespace VISU
               theArgs.myMainPart2SubPartNames,
               theArgs.myIsDone,
               theArgs.myIsBuild,
-              theArgs.myStudy);
+              theArgs.myStudy,
+              theArgs.myPublishInStudy);
   }
 
 
@@ -419,7 +497,8 @@ VISU::MultiResult_i
               &myMainPart2SubPartNames,
               &myIsPartsDone,
               myIsBuildParts,
-              myStudy);
+              myStudy,
+              true);
   }
 
   return this;
@@ -450,7 +529,8 @@ VISU::MultiResult_i
                           &myMainPart2SubPartNames,
                           &myIsPartsDone,
                           myIsBuildParts,
-                          myStudy);
+                          myStudy,
+                          true);
 
     boost::thread aThread(boost::bind(&BuildParts, anArgs));
   }
@@ -503,52 +583,57 @@ VISU::MultiResult_i
        const std::string& theURL,
        bool theIsMultiFile,
        TFileNames& theFileNames,
-       TFileNames& theFullFileNames,
-       TFileNames& theTemporaryDirs)
+       TFileNames& theFullFileNames)
 {
+  INITMSG(MYDEBUG, "MultiResult_i::Save - this = "<<this<<"\n");
+
   bool anIsDone = Result_i::Save(theComponent, 
                                 theURL, 
                                 theIsMultiFile, 
                                 theFileNames, 
-                                theFullFileNames,
-                                theTemporaryDirs);
+                                theFullFileNames);
   if(!anIsDone)
     return false;
 
   if(!myMultiprObj.isValidDistributedMEDFile())
     return true;
-    
-  // Obtain a temporary directory
-  filesystem::path aTmpDir = theIsMultiFile ? theURL : SALOMEDS_Tool::GetTmpDir();
-  aTmpDir /= GetName();
-  cout<<"aTmpDir = '"<<aTmpDir.string()<<endl;
 
-  filesystem::create_directory(aTmpDir);
-  if(!theIsMultiFile)
-    theTemporaryDirs.push_back(aTmpDir.string());
+  // To generate an unique prefix for the set of multi sub files
+  std::string aPrefix;
+  if (theIsMultiFile) {
+    CORBA::String_var anURL = GetStudyDocument()->URL();
+    aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
+  }
+
+  std::string aBase, aSuffix;
+  SplitName(GetName(), aBase, aSuffix);
+  BEGMSG(MYDEBUG, "aBase = '"<<aBase<<"'; aSuffix = '"<<aSuffix<<"'\n");
 
-  myMultiprObj.savePersistent(aTmpDir.string().c_str());
+  aPrefix = aPrefix + "_" + aBase;
+  VISU::TSubString(aPrefix, ".med") = "";
+
+  BEGMSG(MYDEBUG, "aPrefix = '"<<aPrefix<<"'\n");
+
+  // To get a common prefix used in the multi file
+  QFileInfo aFileInfo(myMultiprObj.getSequentialMEDFilename());
+  std::string aFilePrefix = aFileInfo.baseName(TRUE).latin1();
 
-  cout<<"myMultiprObj.getMEDFilename() = '"<<myMultiprObj.getMEDFilename()<<endl;
   MultiResult_i::TPartNames aPartNames = myMultiprObj.getParts();
   for (size_t aPartID = 0 ; aPartID < aPartNames.size() ; aPartID++) {
     const MultiResult_i::TPartName& aPartName = aPartNames[aPartID];
-    std::string aStringInfo = myMultiprObj.getPartInfo(aPartName.c_str());
-         
-    MultiResult_i::TPartInfo aPartInfo;
-    std::istrstream anOutputStream(aStringInfo.c_str());
-    anOutputStream>>(aPartInfo.myMeshName);
-    anOutputStream>>(aPartInfo.myPartID);
-    anOutputStream>>(aPartInfo.myName);
-    anOutputStream>>(aPartInfo.myPath);
-    anOutputStream>>(aPartInfo.myFileName);
+    MultiResult_i::TPartInfo aPartInfo = GetPartInfo(myMultiprObj, aPartName);
 
-    cout<<"aPartInfo.myFileName = '"<<(aPartInfo.myFileName)<<endl;
-    filesystem::path aFile(aPartInfo.myFileName);
-    theFileNames.push_back(aFile.leaf());
-    theFullFileNames.push_back(aFile.branch_path().string());
-  }
+    QFileInfo aFileInfo(aPartInfo.myFileName.c_str());
+    theFullFileNames.push_back(aFileInfo.absFilePath());
 
+    std::string aFileName = aFileInfo.fileName().latin1();
+    VISU::TSubString(aFileName, aFilePrefix) = aPrefix;
+    VISU::TSubString(aFileName, aSuffix) = "";
+    aFileName = aFileName + aSuffix;
+    INITMSG(MYDEBUG, "aFileName = '"<<aFileName<<"'\n");
+    theFileNames.push_back(aFileName);
+  }
+  
   return true;
 }
 
@@ -558,22 +643,54 @@ void
 VISU::MultiResult_i
 ::ToStream(std::ostringstream& theStr)
 {
+  INITMSG(MYDEBUG, "MultiResult_i::ToStream - this = "<<this<<"\n");
+
   TSuperClass::ToStream(theStr);
 
-  std::ostringstream aPartNames, aResolutions;
-  TPartName2Resolution::const_iterator anIter = myPartName2Resolution.begin();
-  for ( ; anIter != myPartName2Resolution.end() ; anIter++) {
-    const TPartName& aPartName = anIter->first;
-    aPartNames<<aPartName<<"|";
-    const VISU::Result::Resolution& aResolution = anIter->second;
-    aResolutions<<aResolution<<"|";
+  Storable::DataToStream(theStr,"myIsBuildParts", myIsPartsDone);
+  if(!myIsPartsDone)
+    return;
+
+  {
+    std::ostringstream aPartNames, aResolutions;
+    TPartName2Resolution::const_iterator anIter = myPartName2Resolution.begin();
+    for ( ; anIter != myPartName2Resolution.end() ; anIter++) {
+      const TPartName& aPartName = anIter->first;
+      aPartNames<<aPartName<<"|";
+      const VISU::Result::Resolution& aResolution = anIter->second;
+      aResolutions<<aResolution<<"|";
+    }
+    
+    Storable::DataToStream(theStr, "myPartNames",  aPartNames.str().c_str());   
+    Storable::DataToStream(theStr, "myResolutions", aResolutions.str().c_str());
   }
 
-  Storable::DataToStream( theStr, "myPartNames",  aPartNames.str().c_str());
-  if(MYDEBUG) MESSAGE("MultiResult_i::ToStream - aPartNames = "<<aPartNames.str());
+  {
+    std::string aBase, aSuffix;
+    SplitName(GetName(), aBase, aSuffix);
+    BEGMSG(MYDEBUG, "aBase = '"<<aBase<<"'; aSuffix = '"<<aSuffix<<"'\n");
+
+    QFileInfo aFileInfo(myMultiprObj.getSequentialMEDFilename());
+    std::string aFilePrefix = aFileInfo.baseName(TRUE).latin1();
+    BEGMSG(MYDEBUG, "aFilePrefix = '"<<aFilePrefix<<"'\n");
+
+    std::ostringstream aPartInfos;
+    MultiResult_i::TPartNames aPartNames = myMultiprObj.getParts();
+    for (size_t aPartID = 0 ; aPartID < aPartNames.size() ; aPartID++) {
+      const MultiResult_i::TPartName& aPartName = aPartNames[aPartID];
+      MultiResult_i::TPartInfo aPartInfo = GetPartInfo(myMultiprObj, aPartName);
+
+      QFileInfo aFileInfo(aPartInfo.myFileName.c_str());
+      std::string aFileName = aFileInfo.fileName().latin1();
+      VISU::TSubString(aFileName, aFilePrefix + "_") = "";      
+      aPartInfo.myFileName = aFileName + aSuffix;
+      aPartInfos<<aPartInfo<<"|";
+
+      INITMSG(MYDEBUG, "aFileName = '"<<aPartInfo.myFileName<<"'\n");
+    }
 
-  Storable::DataToStream( theStr, "myResolutions", aResolutions.str().c_str());
-  if(MYDEBUG) MESSAGE("MultiResult_i::ToStream - aResolutions = "<<aResolutions.str());
+    Storable::DataToStream(theStr, "myPartInfos", aPartInfos.str().c_str());
+  }
 }
 
 
@@ -585,23 +702,72 @@ VISU::MultiResult_i
          const std::string& thePrefix,
          CORBA::Boolean theIsMultiFile)
 {
+  INITMSG(MYDEBUG, "MultiResult_i::Restore - this = "<<this<<"\n");
+
   if(!TSuperClass::Restore(theSObject, theMap, thePrefix, theIsMultiFile))
     return NULL;
 
+  myIsBuildParts = Storable::FindValue(theMap, "myIsBuildParts", "0").toInt();
+  if(!myIsBuildParts)
+    return this;
+  
   QStringList aResolutions = QStringList::split("|", VISU::Storable::FindValue(theMap, "myResolutions"));
   QStringList aPartNames = QStringList::split("|",VISU::Storable::FindValue(theMap, "myPartNames") );
   for(size_t anId = 0, anEnd = aPartNames.size(); anId < anEnd; anId++){
     const QString& aPartName = aPartNames[anId];
-    const QString& aResolution = aResolutions[anId];
-    if(MYDEBUG) MESSAGE("MultiResult_i::Restore - aPartName = '"<<aPartName<<"' = "<<aResolution);
-    if(aResolution[0] == 'F')
-      myPartName2Resolution[aPartName.latin1()] = VISU::Result::FULL;
-    if(aResolution[0] == 'M')
-      myPartName2Resolution[aPartName.latin1()] = VISU::Result::MEDIUM;
-    if(aResolution[0] == 'L')
-      myPartName2Resolution[aPartName.latin1()] = VISU::Result::LOW;
+    VISU::Result::Resolution aResolution = VISU::Result::Resolution(aResolutions[anId].toInt());
+    myPartName2Resolution[aPartName.latin1()] = aResolution;
+    INITMSG(MYDEBUG, "aPartName = '"<<aPartName<<"' = "<<aResolution<<"\n");
   }
   
+  std::string aBase, aSuffix;
+  SplitName(GetName(), aBase, aSuffix);
+  BEGMSG(MYDEBUG, "aBase = '"<<aBase<<"'; aSuffix = '"<<aSuffix<<"'\n");
+
+  std::string aSourceFileName = GetFileInfo().absFilePath().latin1();
+  BEGMSG(MYDEBUG, "aSourceFileName = '"<<aSourceFileName<<"'\n");    
+  
+  std::string aPrefix = aSourceFileName;
+  VISU::TSubString(aPrefix, ".med") = "";
+  VISU::TSubString(aPrefix, aSuffix) = "";
+  BEGMSG(MYDEBUG, "aPrefix = '"<<aPrefix<<"'\n");    
+  
+  std::string aMultiFileName(aPrefix + "_grains_maitre.med" + aSuffix);
+  BEGMSG(MYDEBUG, "aMultiFileName = '"<<aMultiFileName<<"'\n");    
+
+  {
+    std::ofstream aMultiFileStream(aMultiFileName.c_str());
+    aMultiFileStream<<"# MED file v2.3 - Master file created by VISU\n";
+    aMultiFileStream<<"#\n";
+    aMultiFileStream<<"# [SOURCE]="<<aSourceFileName<<"\n";
+    aMultiFileStream<<"#\n";
+
+    QStringList aPartInfos = QStringList::split("|", VISU::Storable::FindValue(theMap, "myPartInfos"));
+    aMultiFileStream<<aPartInfos.size()<<"\n";
+
+    for(size_t anId = 0, anEnd = aPartInfos.size(); anId < anEnd; anId++){
+      MultiResult_i::TPartInfo aPartInfo = GetPartInfo(aPartInfos[anId].latin1());
+      aPartInfo.myFileName = aPrefix + "_" + aPartInfo.myFileName;
+      INITMSG(MYDEBUG, "aPartInfo.myFileName = '"<<aPartInfo.myFileName<<"'\n");    
+      aMultiFileStream<<aPartInfo<<"\n";
+    }
+  }
+
+  {
+    myMultiprObj.create(aMultiFileName.c_str());
+    BuildParts(this,
+              GetInput(),
+              &myMultiprObj,
+              &myPartInfos,
+              &myPartName2FileName,
+              &myPartName2Resolution,
+              &myMainPart2SubPartNames,
+              &myIsPartsDone,
+              myIsBuildParts,
+              myStudy,
+              false);
+  }
+
   return this;
 }
 
@@ -632,12 +798,8 @@ VISU::MultiResult_i
     if(!IsFullResolution(aPartName))
       continue;
 
-    std::string aStringInfo = myMultiprObj.getPartInfo(aPartName.c_str());
-    std::istrstream anOutputStream(aStringInfo.c_str());
-         
-    TMeshName aMeshName;
-    anOutputStream>>aMeshName;
-    if(aMeshName == theMeshName)
+    MultiResult_i::TPartInfo aPartInfo = GetPartInfo(myMultiprObj, aPartName);
+    if(aPartInfo.myMeshName == theMeshName)
       aMeshParts.push_back(aPartName);
   }
 
@@ -669,12 +831,8 @@ VISU::MultiResult_i
     if(aMainPart != thePartName)
       continue;
 
-    std::string aStringInfo = myMultiprObj.getPartInfo(aPartName.c_str());       
-    std::istrstream anOutputStream(aStringInfo.c_str());
-
-    TMeshName aMeshName;
-    anOutputStream>>aMeshName;
-    if(aMeshName != theMeshName)
+    MultiResult_i::TPartInfo aPartInfo = GetPartInfo(myMultiprObj, aPartName);
+    if(aPartInfo.myMeshName != theMeshName)
       continue;
 
     MultiResult_i::TResolutions aResolutions = VISU::GetResolutions(myMainPart2SubPartNames, thePartName);
@@ -724,26 +882,25 @@ VISU::MultiResult_i
   if(aResolution == theResolution)
     return;
 
-  TPartName2FileName::iterator aFileNameIter = myPartName2FileName.find(thePartName);
-  if(aFileNameIter == myPartName2FileName.end())
-    return;
-  const TFileName& aFileName = aFileNameIter->second;
-
   VISU::Storable::TRestoringMap aRestoringMap;
   aRestoringMap["myComment"] = "PART";
   aRestoringMap["myMeshName"] = theMeshName;
-  aRestoringMap["myFile"] = aFileName;
+  aRestoringMap["myName"] = thePartName;
 
   const VISU::TMeshMap& aMeshMap = Result_i::GetInput()->GetMeshMap();
   VISU::TMeshMap::const_iterator aMeshIter = aMeshMap.find(theMeshName);
   if(aMeshIter == aMeshMap.end())
     return;
 
-  const VISU::PMesh& aMesh = aMeshIter->second;    
-  std::string aFatherEntry = Storable::FindEntry(GetStudyDocument(),
-                                                aMesh->myPartsEntry,
-                                                aRestoringMap);
-
+  std::string aFatherEntry;
+  const VISU::PMesh& aMesh = aMeshIter->second;
+  if(aMesh->myPartsEntry != "")
+    aFatherEntry = Storable::FindEntry(GetStudyDocument(),
+                                      aMesh->myPartsEntry,
+                                      aRestoringMap);
+  else
+    aFatherEntry = Result_i::GetEntry(aRestoringMap);
+  
   std::string anIconName = "ICON_MULTIPR_VIEW_HIDE";
   if(theResolution == VISU::Result::FULL)
     anIconName = "ICON_MULTIPR_VIEW_FULL";
@@ -758,10 +915,11 @@ VISU::MultiResult_i
 
   std::ostrstream anOutputStream;
   anOutputStream<<"myComment=PART;";
-  anOutputStream<<"myFile="<<aFileName<<";";
+  anOutputStream<<"myName="<<thePartName<<";";
   anOutputStream<<"myMeshName="<<theMeshName<<";";
   anOutputStream<<"myResolutions="<<aRestoringMap["myResolutions"]<<";";
   anOutputStream<<"myState="<<theResolution;
+  anOutputStream<<ends;
 
   CreateAttributes(aStudy,
                   aFatherEntry,
@@ -780,15 +938,26 @@ VISU::MultiResult_i
 VISU::MultiResult_i
 ::~MultiResult_i()
 {
-  if(MYDEBUG) MESSAGE("MultiResult_i::~MultiResult_i - this = "<<this<<": "<<myRepresentation2Input.size());
-  TRepresentation2Input::iterator anIter = myRepresentation2Input.begin();
-  for ( ; anIter != myRepresentation2Input.end() ; anIter++) {
-    const PInput& anInput = anIter->second;
-    std::string aFileName = anInput->GetName();
-    if(MYDEBUG) MESSAGE("'"<<aFileName<<"'; ");
-    QFileInfo aFileInfo(aFileName.c_str());
-    QFile(aFileInfo.absFilePath()).remove();
-    QDir().rmdir(aFileInfo.dirPath(TRUE));
+  INITMSG(MYDEBUG, "MultiResult_i::~MultiResult_i - this = "<<this<<"\n");
+  if(myIsBuildParts){
+    TRepresentation2Input::iterator anIter = myRepresentation2Input.begin();
+    for ( ; anIter != myRepresentation2Input.end() ; anIter++) {
+      const PInput& anInput = anIter->second;
+      std::string aFileName = anInput->GetName();
+      INITMSG(MYDEBUG, "RemoveFile - aFileName = '"<<aFileName<<"'\n");
+      VISU::RemoveFile(aFileName);
+    }
+    if (GetSourceId() == eRestoredFile) {
+      INITMSG(MYDEBUG, "RemoveFile - myMultiprObj.getMEDFilename = '"<<myMultiprObj.getMEDFilename()<<"'\n");
+      VISU::RemoveFile(myMultiprObj.getMEDFilename());
+      MultiResult_i::TPartNames aPartNames = myMultiprObj.getParts();
+      for (size_t aPartID = 0 ; aPartID < aPartNames.size() ; aPartID++) {
+       const MultiResult_i::TPartName& aPartName = aPartNames[aPartID];
+       MultiResult_i::TPartInfo aPartInfo = GetPartInfo(myMultiprObj, aPartName);
+       INITMSG(MYDEBUG, "RemoveFile - aPartInfo.myFileName = '"<<aPartInfo.myFileName<<"'\n");
+       VISU::RemoveFile(aPartInfo.myFileName);
+      }
+    }
   }
 }
 
@@ -889,17 +1058,18 @@ VISU::MultiResult_i
 
   TRepresentation2Input::iterator anIter = myRepresentation2Input.find(aRepresentationKey);
   if(anIter == myRepresentation2Input.end()){
+    INITMSG(MYDEBUG, "MultiResult_i::GetInput - this = "<<this<<"\n");
     std::string aFileName = SALOMEDS_Tool::GetTmpDir() + "tmp.med";
     if(MYDEBUG){
-      MESSAGE("MultiResult_i::GetInput - '"<<aFileName<<"': ");
+      INITMSG(MYDEBUG, "aFileName = '"<<aFileName<<"':\n");
       TFileNames::const_iterator anIter = aFileNames.begin();
       for ( ; anIter != aFileNames.end() ; anIter++) {
        const MultiResult_i::TFileName& aFileName = *anIter;
-       MESSAGE("'"<<aFileName<<"'; ");
+       INITMSG(MYDEBUG, "'"<<aFileName<<"'\n");
       }
     }
     int aRes = multipr::merge(aFileNames, theMeshName.c_str(), theFieldName.c_str(), aFileName.c_str());
-    if(MYDEBUG) MESSAGE("aRes = "<<aRes);
+    BEGMSG(MYDEBUG, "aRes = "<<aRes<<"\n");
     if (aRes == 0) {
       QFile(aFileName.c_str()).remove();
       throw std::runtime_error("empty mesh"); 
index 54c9a7769ad14ff2cffa936080f58961893250c8..e8e6eb285b40b6eb9c1b80c88d2a4adde32019bc 100644 (file)
@@ -155,8 +155,7 @@ namespace VISU
         const std::string& theURL,
         bool theIsMultiFile,
         TFileNames& theFileNames,
-        TFileNames& theFullFileNames,
-        TFileNames& theTemporaryDirs);
+        TFileNames& theFullFileNames);
 
     virtual
     void
index afab2a860ef2a95351414c94b88b44eed7045eb0..bdcef89877825322bdc824489215560ea58ff7be 100644 (file)
 #include "VISU_Convertor.hxx"
 #include "VISU_ConvertorUtils.hxx"
 
+#include <qfileinfo.h>
+#include <qfile.h>
+#include <qdir.h>
+
 #include <boost/thread/recursive_mutex.hpp>
 #include <boost/thread/thread.hpp>
 #include <boost/bind.hpp>
 
+#include <boost/filesystem/path.hpp>
+#include <boost/filesystem/operations.hpp>
+namespace filesystem = boost::filesystem;
+
 #ifdef _DEBUG_
 static int MYTIMEDEBUG = 0;
 #else
@@ -144,6 +152,26 @@ namespace VISU
   }
   
 
+  //----------------------------------------------------------------------------
+  bool
+  SplitName(const std::string& theName,
+           std::string& theBase,
+           std::string& theSuffix,
+           char theDelimeter)
+  {
+    size_t aPosition = theName.find(theDelimeter);
+    if(aPosition == std::string::npos){
+      theBase = theName;
+      theSuffix = "";
+      return false;
+    }
+
+    theBase = theName.substr(0, aPosition);
+    theSuffix = theName.substr(aPosition);
+    return true;
+  }
+  
+
   //----------------------------------------------------------------------------
   QString 
   GenerateFieldName (const string& theName, const string& theUnits)
@@ -598,5 +626,20 @@ namespace VISU
   }
 
 
+  //----------------------------------------------------------------------------
+  bool
+  RemoveFile(const std::string& theFileName,
+            bool theRemoveEmptyDir)
+  {
+    QFileInfo aFileInfo(theFileName);
+    QFile(aFileInfo.absFilePath()).remove();
+    
+    if(theRemoveEmptyDir)
+      QDir().rmdir(aFileInfo.dirPath(TRUE));
+
+    return aFileInfo.exists();
+  }
+
+
   //----------------------------------------------------------------------------
 }
index 1f93c7cf8203bb81bead7bfd5ef23d287da253ed..335849f1289ddd00bdc5164072112169d59f50d3 100644 (file)
@@ -74,6 +74,14 @@ namespace VISU
   GenerateName(const std::string& theName);
 
 
+  //----------------------------------------------------------------------------
+  bool
+  SplitName(const std::string& theName,
+           std::string& theBase,
+           std::string& theSuffix,
+           char theDelimeter = ':');
+
+
   //----------------------------------------------------------------------------
   void
   BuildEntities(Result_i* theResult,
@@ -126,6 +134,11 @@ namespace VISU
                     _PTR(Study) theStudy);
 
   //----------------------------------------------------------------------------
+  bool
+  RemoveFile(const std::string& theFileName,
+            bool theRemoveEmptyDir = true);
+
+  //----------------------------------------------------------------------------
 }
 
 
index ff1b63f8e6e9e23a2faa40c00e8335f7269c3cbc..f07256d4fd4c4e86d1a35eb068e4502c26253459 100644 (file)
@@ -172,7 +172,14 @@ VISU::Result_i
 
 //---------------------------------------------------------------
 VISU::Result_i
-::Result_i()
+::Result_i():
+  myIsEntitiesDone(false),
+  myIsFieldsDone(false),
+  myIsGroupsDone(false),
+  myIsMinMaxDone(false),
+  myIsAllDone(false),
+  myIsBuildParts(false),
+  myIsPartsDone(false)
 {}
 
 
@@ -599,26 +606,38 @@ VISU::Result_i
        const std::string& theURL,
        bool theIsMultiFile,
        TFileNames& theFileNames,
-       TFileNames& theFullFileNames,
-       TFileNames& theTemporaryDirs)
+       TFileNames& theFullFileNames)
 {
   switch(GetCreationId()){
   case Result_i::eImportFile:
   case Result_i::eCopyAndImportFile: {
-    filesystem::path aFileName = std::string("_") + GetName();
-    filesystem::path aFilePath = GetFileInfo().filePath().latin1();
+    std::string aPrefix;
+    if (theIsMultiFile) {
+      CORBA::String_var anURL = GetStudyDocument()->URL();
+      aPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
+    }
+
+    std::string aFileName = aPrefix + "_" + GetName();
+    std::string aFilePath = GetFileInfo().filePath().latin1();
+
     if(theIsMultiFile){
       CORBA::String_var anURL = GetStudyDocument()->URL();
-      aFilePath = SALOMEDS_Tool::GetNameFromPath(anURL.in()) + aFilePath.string();
+      aFilePath = SALOMEDS_Tool::GetNameFromPath(anURL.in()) + aFilePath;
+
       filesystem::path aPathToCopy = filesystem::path(theURL) / aFileName;
       filesystem::copy_file(aFilePath, aPathToCopy);
       if(!filesystem::exists(aPathToCopy))
        return false;
     }
-    if(MYDEBUG) MESSAGE("Result_i::Save - aFileName  ='"<<aFileName.string()
-                       <<"'; aFilePath = '"<<aFilePath.string()<<"'\n");
-    theFileNames.push_back(aFileName.string());
-    theFullFileNames.push_back(aFilePath.string());
+
+    if(MYDEBUG){
+      MESSAGE("Result_i::Save - aFileName  ='"<<aFileName<<"'");
+      MESSAGE("Result_i::Save - aFilePath  ='"<<aFileName<<"'");
+    }
+
+    theFileNames.push_back(aFileName);
+    theFullFileNames.push_back(aFilePath);
+
     return true;
   }}
 
@@ -730,6 +749,7 @@ VISU::Result_i
   mySObject = SALOMEDS::SObject::_duplicate(theSObject);
   mySComponent = mySObject->GetFatherComponent();
   myStudyDocument = theSObject->GetStudy();
+  myStudy = VISU::GetStudy(myStudyDocument);
 
   myCreationId = ECreationId(Storable::FindValue(theMap, "myCreationId").toInt());
   mySourceId = eRestoredFile;
@@ -739,18 +759,16 @@ VISU::Result_i
   myIsBuildFields = Storable::FindValue(theMap, "myIsBuildFields", "1").toInt();
   myIsBuildMinMax = Storable::FindValue(theMap, "myIsBuildMinMax", "1").toInt();
   myIsBuildGroups = Storable::FindValue(theMap, "myIsBuildGroups", "1").toInt();
-  myIsBuildParts = Storable::FindValue(theMap, "myIsBuildParts", "0").toInt();
 
   myIsBuildImmediately = true;
 
   try {
     myName = VISU::Storable::FindValue(theMap, "myName").latin1();
+    VISU::GenerateName(myName); // To register the name in global naming map
     SetFileName(VISU::Storable::FindValue(theMap, "myInitFileName").latin1());
     
     SALOMEDS::SObject_var aRefSObj, aTargetRefSObj;
-    if (mySObject->FindSubObject(1, aRefSObj) &&
-       aRefSObj->ReferencedObject(aTargetRefSObj)) 
-    {
+    if (theSObject->FindSubObject(1, aRefSObj) && aRefSObj->ReferencedObject(aTargetRefSObj)) {
       if(MYDEBUG) MESSAGE("Result_i::GetInput - There is some reference.");
       SALOMEDS::SComponent_var aCompRefSObj = aTargetRefSObj->GetFatherComponent();
       CORBA::String_var aDataType = aCompRefSObj->ComponentDataType();
@@ -782,9 +800,11 @@ VISU::Result_i
     } else {
       myFileInfo.setFile(thePrefix.c_str());
 
-      string aStudyPrefix ("");
-      if (theIsMultiFile)
-       aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(myStudyDocument->URL());
+      std::string aStudyPrefix ("");
+      if (theIsMultiFile) {
+       CORBA::String_var anURL(GetStudyDocument()->URL());
+       aStudyPrefix = SALOMEDS_Tool::GetNameFromPath(anURL.in());
+      }
       if (!myFileInfo.isFile()) {
        string aFileName = thePrefix + aStudyPrefix + "_" + myName;
        myFileInfo.setFile(aFileName.c_str());
@@ -1324,7 +1344,6 @@ VISU::Result_i
   Storable::DataToStream(theStr,"myIsBuildFields", myIsFieldsDone);
   Storable::DataToStream(theStr,"myIsBuildMinMax", myIsMinMaxDone);
   Storable::DataToStream(theStr,"myIsBuildGroups", myIsGroupsDone);
-  Storable::DataToStream(theStr,"myIsBuildParts", myIsBuildParts);
 }
 
 
@@ -1429,24 +1448,8 @@ VISU::Result_i
 ::~Result_i()
 {
   MESSAGE("Result_i::~Result_i() - this = "<<this);
-  if (mySourceId == eRestoredFile) {
-    static QString aCommand;
-#ifndef WNT
-    aCommand.sprintf("rm %s",myFileInfo.filePath().latin1());
-#else
-    aCommand.sprintf("del /F %s",myFileInfo.filePath().latin1());
-#endif
-    int res = system(aCommand);
-    MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<res);
-
-#ifndef WNT
-    aCommand.sprintf("rmdir --ignore-fail-on-non-empty %s",myFileInfo.dirPath().latin1());
-#else
-    aCommand.sprintf("del /F %s",myFileInfo.dirPath().latin1());
-#endif
-
-    res = system(aCommand);
-    MESSAGE("Result_i::~Result_i - system("<<aCommand<<") = "<<res);
+  if (GetSourceId() == eRestoredFile) {
+    VISU::RemoveFile(myFileInfo.filePath().latin1());
   }
 }
 
index 9b278f271ce56c4c328a02dd5230c4b046f0e9ac..d1ceb6f2d677adcdbab134652102555d60890616 100644 (file)
@@ -293,8 +293,7 @@ namespace VISU
         const std::string& theURL,
         bool theIsMultiFile,
         TFileNames& theFileNames,
-        TFileNames& theFullFileNames,
-        TFileNames& theTemporaryDirs);
+        TFileNames& theFullFileNames);
 
     virtual 
     bool