]> SALOME platform Git repositories - modules/kernel.git/commitdiff
Salome HOME
Issue 0013373: EDF PAL 273 : Option Single/Multi file dump
authorouv <ouv@opencascade.com>
Tue, 29 Mar 2011 07:34:47 +0000 (07:34 +0000)
committerouv <ouv@opencascade.com>
Tue, 29 Mar 2011 07:34:47 +0000 (07:34 +0000)
18 files changed:
idl/SALOMEDS.idl
idl/SALOME_Component.idl
src/Container/Component_i.cxx
src/Container/SALOME_ComponentPy.py
src/Container/SALOME_Component_i.hxx
src/ParallelContainer/SALOME_ParallelComponent_i.cxx
src/ParallelContainer/SALOME_ParallelComponent_i.hxx
src/SALOMEDS/SALOMEDS_Driver_i.cxx
src/SALOMEDS/SALOMEDS_Driver_i.hxx
src/SALOMEDS/SALOMEDS_Study.cxx
src/SALOMEDS/SALOMEDS_Study.hxx
src/SALOMEDS/SALOMEDS_Study_i.cxx
src/SALOMEDS/SALOMEDS_Study_i.hxx
src/SALOMEDS/Test/SALOMEDSTest_Study.cxx
src/SALOMEDSClient/SALOMEDSClient_Study.hxx
src/SALOMEDSImpl/SALOMEDSImpl_Driver.hxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.cxx
src/SALOMEDSImpl/SALOMEDSImpl_Study.hxx

index 86da762303fa571d444bf563d8ae870464ff3da7..6b0c15abdd16ac2e546bfd0f7bd9843ef4c5c12d 100644 (file)
@@ -352,7 +352,10 @@ during each working session.
 
     void UndoPostponed(in long theWay);
 
-    boolean DumpStudy(in string thePath, in string theBaseName, in boolean isPublished);
+    boolean DumpStudy(in string thePath,
+                      in string theBaseName,
+                      in boolean isPublished,
+                      in boolean isMultiFile);
 
 /*! \brief  Get an AttributeParameter used to store common parameters for given %theSavePoint.
 
index 53209d1e79eb67a57116f33fc0ecad872b4703dc..9fbfff0f5fa3b1f9a3a9af30709def6e5ef1b088 100644 (file)
@@ -323,7 +323,8 @@ module Engines
       the data model of component
     */    
     TMPFile DumpPython(in Object theStudy,
-                       in boolean isPublished, 
+                       in boolean isPublished,
+                       in boolean isMultiFile,
                        out boolean isValidScript);
 
     
index 20c33c4397a83faebac9f9f67a8b4f263027bbe0..1a619a7aa1145c8ba0663fb9f5b143c786be0497 100644 (file)
@@ -882,9 +882,10 @@ std::string Engines_Component_i::GetDynLibraryName(const char *componentName)
 
 Engines::TMPFile* Engines_Component_i::DumpPython(CORBA::Object_ptr theStudy, 
                                                   CORBA::Boolean isPublished, 
+                                                  CORBA::Boolean isMultiFile, 
                                                   CORBA::Boolean& isValidScript)
 {
-  const char* aScript = "def RebuildData(theStudy): pass";
+  const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : "";
   char* aBuffer = new char[strlen(aScript)+1];
   strcpy(aBuffer, aScript);
   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
index dc6187078ff69987fdf8130f3bf3b2805d594579..30fedebf718018e71ada91e16f5d37e35a9794b4 100755 (executable)
@@ -293,8 +293,10 @@ class SALOME_ComponentPy_i (Engines__POA.EngineComponent):
 
     #-------------------------------------------------------------------------
    
-    def DumpPython(self, theStudy, isPublished):
-        aBuffer = "def RebuildData(theStudy): pass\n\0"
+    def DumpPython(self, theStudy, isPublished, isMultiFile):
+        aBuffer = "\0"
+        if isMultiFile :
+            aBuffer = "def RebuildData(theStudy): pass\n\0"
         return (aBuffer, 1)
 
     #-------------------------------------------------------------------------    
index 04b8b64eb393a75f137272ac18ac5f1c59270f9d..9faa316fa30631aa43bd6adad33ad619664d41d2 100644 (file)
@@ -96,6 +96,7 @@ public:
 
   virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
                                        CORBA::Boolean isPublished,
+                                       CORBA::Boolean isMultiFile,
                                        CORBA::Boolean& isValidScript);
 
   // CORBA operations for Salome_file
index f45839afa9cdae1a25b0a79aad48db1959c841b6..6a9f198e3fa29f6486cbe7b6911327aac3fe6fdd 100644 (file)
@@ -839,9 +839,10 @@ std::string Engines_Parallel_Component_i::GetDynLibraryName(const char *componen
 
 Engines::TMPFile* Engines_Parallel_Component_i::DumpPython(CORBA::Object_ptr theStudy, 
                                                            CORBA::Boolean isPublished, 
+                                                           CORBA::Boolean isMultiFile,
                                                            CORBA::Boolean& isValidScript)
 {
-  const char* aScript = "def RebuildData(theStudy): pass";
+  const char* aScript = isMultiFile ? "def RebuildData(theStudy): pass" : "";
   char* aBuffer = new char[strlen(aScript)+1];
   strcpy(aBuffer, aScript);
   CORBA::Octet* anOctetBuf =  (CORBA::Octet*)aBuffer;
index 0fcb3724c040472306de5a5d79840652a03e3a4a..99597a5d6aab9932ee0b313c8bec18a1158ffa4b 100644 (file)
@@ -95,6 +95,7 @@ public:
 
  virtual Engines::TMPFile* DumpPython(CORBA::Object_ptr theStudy,
                                       CORBA::Boolean isPublished,
+                                      CORBA::Boolean isMultiFile,
                                       CORBA::Boolean& isValidScript);
 
  // CORBA operations for Salome_file
index 7d845471c1869e1203f4a16c501c333a33aaed52..b5d0b241f47e31060c1928d5f1a51b8eb4729623 100644 (file)
@@ -213,6 +213,7 @@ std::string SALOMEDS_Driver_i::PasteInto(const unsigned char* theStream,
 
 SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy, 
                                                     bool isPublished, 
+                                                    bool isMultiFile,
                                                     bool& isValidScript,
                                                     long& theStreamLength)
 {
@@ -222,7 +223,7 @@ SALOMEDSImpl_TMPFile* SALOMEDS_Driver_i::DumpPython(SALOMEDSImpl_Study* theStudy
 
   SALOMEDS::unlock();
   CORBA::Boolean aValidScript, aPublished = isPublished;
-  Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, aValidScript);
+  Engines::TMPFile_var aStream = aComponent->DumpPython(st.in(), aPublished, isMultiFile, aValidScript);
   SALOMEDSImpl_TMPFile* aTMPFile = new Engines_TMPFile_i(aStream._retn());
   theStreamLength = aTMPFile->Size();
   isValidScript = aValidScript;
index 3d69eb9d1020b9d46e0598bbb4e1ca9095174f6e..9f43fa4d8a7c7545a23b26207010d040109db7ae 100644 (file)
@@ -111,6 +111,7 @@ public:
 
   virtual SALOMEDSImpl_TMPFile* DumpPython(SALOMEDSImpl_Study* theStudy, 
                                            bool isPublished, 
+                                           bool isMultiFile,
                                            bool& isValidScript,
                                            long& theStreamLength);
 };
index 08d9eb347b6f667d0c2632c5ed347704af1c1282..edfb93def79d8f7ab046317bc9e6989c58cdb772 100644 (file)
@@ -629,11 +629,14 @@ void SALOMEDS_Study::EnableUseCaseAutoFilling(bool isEnabled)
   else _corba_impl->EnableUseCaseAutoFilling(isEnabled);
 }
 
-bool SALOMEDS_Study::DumpStudy(const std::string& thePath, const std::string& theBaseName, bool isPublished)
+bool SALOMEDS_Study::DumpStudy(const std::string& thePath,
+                               const std::string& theBaseName,
+                               bool isPublished,
+                               bool isMultiFile)
 {
   //SRN: Pure CORBA DumpStudy as it does more cleaning than the local one
   if(CORBA::is_nil(_corba_impl)) GetStudy(); //If CORBA implementation is null then retrieve it
-  bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished);
+  bool ret = _corba_impl->DumpStudy(thePath.c_str(), theBaseName.c_str(), isPublished, isMultiFile);
   return ret;
 }     
 
index c84261e249d779697c2e7899f958307f55d4db01..44cead1420e4a984c115e0d83ce63fbcb66ec34b 100644 (file)
@@ -90,7 +90,7 @@ public:
   virtual _PTR(UseCaseBuilder) GetUseCaseBuilder();
   virtual void Close();
   virtual void EnableUseCaseAutoFilling(bool isEnabled);
-  virtual bool DumpStudy(const std::string& thePath,const std::string& theBaseName,bool isPublished); 
+  virtual bool DumpStudy(const std::string& thePath,const std::string& theBaseName,bool isPublished,bool isMultiFile); 
   virtual _PTR(AttributeParameter) GetCommonParameters(const std::string& theID, int theSavePoint);
   virtual _PTR(AttributeParameter) GetModuleParameters(const std::string& theID, 
                                                        const std::string& theModuleName, int theSavePoint);
index 4213401ae5253272a7b427fd46a0b92e23df6710..e0f1bb3654a7b9c3e08e596039ed9e0220dcb449 100644 (file)
@@ -873,13 +873,14 @@ void SALOMEDS_Study_i::UndoPostponed(CORBA::Long theWay)
 //============================================================================
 CORBA::Boolean SALOMEDS_Study_i::DumpStudy(const char* thePath, 
                                            const char* theBaseName, 
-                                           CORBA::Boolean isPublished)
+                                           CORBA::Boolean isPublished,
+                                           CORBA::Boolean isMultiFile)
 {
   SALOMEDS::Locker lock; 
 
   std::string aPath((char*)thePath), aBaseName((char*)theBaseName);
   SALOMEDS_DriverFactory_i* factory = new SALOMEDS_DriverFactory_i(_orb);
-  CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, factory);
+  CORBA::Boolean ret = _impl->DumpStudy(aPath, aBaseName, isPublished, isMultiFile, factory);
   delete factory;
   return ret;
 }
index a0146ccc9b543cdad8097394d9eb7e0f457f9996..96c17a8e88a8d65ade584297958d3380ec66370c 100644 (file)
@@ -342,7 +342,10 @@ public:
 
   virtual char* GetDefaultScript(const char* theModuleName, const char* theShift);
 
-  virtual CORBA::Boolean DumpStudy(const char* thePath, const char* theBaseName, CORBA::Boolean isPublished);
+  virtual CORBA::Boolean DumpStudy(const char* thePath,
+                                   const char* theBaseName,
+                                   CORBA::Boolean isPublished,
+                                   CORBA::Boolean isMultiFile);
 
   virtual SALOMEDSImpl_Study* GetImpl() { return _impl; }
 
index 1ab19ae461f8d8c6ef74bf205d03f72a32d2b546..73878f05606df396b84d3ea2060885219e7edfcb 100755 (executable)
@@ -324,7 +324,7 @@ void SALOMEDSTest::testStudy()
   CPPUNIT_ASSERT(va2.size() == 1); // +AttributeTreeNode
 
   //Check method DumpStudy
-  study->DumpStudy(".", "SRN", false);
+  study->DumpStudy(".", "SRN", false, false);
 
   std::fstream f("SRN.py");
   char buffer[128];
index 2ccc8cf91277f8d34e2e9191588846ec294a9d61..9406b63e3995f3343c3697698d7e8f223ad1dc39 100644 (file)
@@ -89,7 +89,8 @@ public:
   virtual void EnableUseCaseAutoFilling(bool isEnabled) = 0;
   virtual bool DumpStudy(const std::string& thePath, 
                          const std::string& theBaseName, 
-                         bool isPublished) = 0;
+                         bool isPublished,
+                         bool isMultiFile) = 0;
   virtual _PTR(AttributeParameter) GetCommonParameters(const std::string& theID, int theSavePoint) = 0;
   virtual _PTR(AttributeParameter) GetModuleParameters(const std::string& theID, 
                                                        const std::string& theModuleName, int theSavePoint) = 0;
index 86be83c42b3b7500c0bc6f73aca8d382e12a114b..8180354ab6dac31596d285b31e8dc5adea07f7ca 100644 (file)
@@ -88,6 +88,7 @@ public:
 
   virtual SALOMEDSImpl_TMPFile* DumpPython(SALOMEDSImpl_Study* theStudy, 
     bool isPublished, 
+    bool isMultiFile, 
     bool& isValidScript,
     long& theStreamLength) = 0;
 };
index bf8de48e4b44addf61303ddc68480d3870d11a15..67c8ce04eb123975869764a95e322bf684679aea 100644 (file)
@@ -1189,6 +1189,15 @@ static std::string replace_tabs( const std::string& in )
   return out;
 }
 
+static std::string GetComponentHeader(const char* theComponentName)
+{
+  std::stringstream txt;
+  txt << "###" << std::endl;
+  txt << "### " << theComponentName << " component" << std::endl;
+  txt << "###" << std::endl;
+  return txt.str();
+}
+
 //============================================================================
 /*! Function : DumpStudy
  *  Purpose  :
@@ -1197,6 +1206,7 @@ static std::string replace_tabs( const std::string& in )
 bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
                                    const std::string& theBaseName,
                                    bool isPublished,
+                                   bool isMultiFile,
                                    SALOMEDSImpl_DriverFactory* theFactory)
 {
   _errorCode = "";
@@ -1321,55 +1331,62 @@ bool SALOMEDSImpl_Study::DumpStudy(const std::string& thePath,
 
     bool isValidScript;
     long aStreamLength  = 0;
-    SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isValidScript, aStreamLength);
+    SALOMEDSImpl_TMPFile* aStream = aDriver->DumpPython(this, isPublished, isMultiFile, isValidScript, aStreamLength);
     if ( !isValidScript )
       isOk = false;
 
-    //Create a file that will contain the component specific script
-    std::fstream fp2;
+    std::stringstream sfp2;
+    
+    //Output the Python script generated by the component in the newly created file.
+    if ( isMultiFile )
+      sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
+    else
+      sfp2 << GetComponentHeader( aCompType.c_str() ) << std::endl;
+    sfp2 << aStream->Data();
+    
+    if ( isMultiFile ) {
+      //Create a file that will contain the component specific script
+      std::fstream fp2;
 #ifdef WIN32
-    aFileName=thePath+std::string("\\");
+      aFileName=thePath+std::string("\\");
 #else
-    aFileName=thePath+std::string("/");
+      aFileName=thePath+std::string("/");
 #endif
-    std::string aScriptName;
-    aScriptName += theBaseName;
-    aScriptName += "_";
-    aScriptName += aCompType;
-
-    aFileName += aScriptName+ std::string(".py");
-    aSeqOfFileNames.push_back(aFileName);
-
-    fp2.open(aFileName.c_str(), std::ios::out);
-
+      std::string aScriptName;
+      aScriptName += theBaseName;
+      aScriptName += "_";
+      aScriptName += aCompType;
+      
+      aFileName += aScriptName+ std::string(".py");
+      aSeqOfFileNames.push_back(aFileName);
+      
+      fp2.open(aFileName.c_str(), std::ios::out);
+      
 #ifdef WIN32
-    isOpened = fp2.is_open();
+      isOpened = fp2.is_open();
 #else
-    isOpened = fp2.rdbuf()->is_open();
+      isOpened = fp2.rdbuf()->is_open();
 #endif
-
-    if(!isOpened) {
-      _errorCode = std::string("Can't create a file ")+aFileName;
-      SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
-      return false;
-    }
+      
+      if(!isOpened) {
+       _errorCode = std::string("Can't create a file ")+aFileName;
+       SALOMEDSImpl_Tool::RemoveTemporaryFiles(thePath, aSeqOfFileNames, false);
+       return false;
+      }
      
-    std::stringstream sfp2;
-    
-    //Output the Python script generated by the component in the newly created file.
-    sfp2 << GetDumpStudyComment( aCompType.c_str() ) << std::endl;
-    sfp2 << aStream->Data();
-    
-    // replace '\t' symbols
-    fp2 << replace_tabs( sfp2.str() );
+      // replace '\t' symbols
+      fp2 << replace_tabs( sfp2.str() );
 
-    fp2.close();
+      fp2.close();
 
-    if(aStream) delete aStream;
+      //Add to the main script a call to RebuildData of the generated by the component the Python script
+      sfp << "import " << aScriptName << std::endl;
+      sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
+    }
+    else
+      sfp << sfp2.str();
 
-    //Add to the main script a call to RebuildData of the generated by the component the Python script
-    sfp << "import " << aScriptName << std::endl;
-    sfp << aScriptName << ".RebuildData(" << aBatchModeScript << ".myStudy)" << std::endl;
+    if(aStream) delete aStream;
   }
 
   sfp << std::endl;
index a257da08e4224286ac489a50b56868c2accbf264..0745ef29571c387df5f83828ce831180ff7fe28a 100644 (file)
@@ -228,9 +228,10 @@ public:
   virtual bool HasCurrentContext() { return !_current.IsNull(); }
 
   virtual bool DumpStudy(const std::string& thePath, 
-                                         const std::string& theBaseName, 
-                                         bool isPublished,
-                                         SALOMEDSImpl_DriverFactory* theFactory);
+                         const std::string& theBaseName, 
+                         bool isPublished,
+                         bool isMultiFile,
+                         SALOMEDSImpl_DriverFactory* theFactory);
 
   static std::string GetDumpStudyComment(const char* theComponentName = 0);