]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Join HDF persistence for light modules from branch BR_L_2_3_5.
authorjfa <jfa@opencascade.com>
Fri, 10 Mar 2006 09:20:17 +0000 (09:20 +0000)
committerjfa <jfa@opencascade.com>
Fri, 10 Mar 2006 09:20:17 +0000 (09:20 +0000)
src/LightApp/LightApp_Application.cxx
src/LightApp/LightApp_HDFDriver.cxx [new file with mode: 0644]
src/LightApp/LightApp_HDFDriver.h [new file with mode: 0644]
src/LightApp/LightApp_Study.cxx
src/LightApp/Makefile.in

index 28f528334b3df8a66bc9c1d7caef83c2bccde566..5affcb5d9a7ac3a78fee4225d183c74aa3d85e05 100644 (file)
@@ -1308,9 +1308,9 @@ void LightApp_Application::onDesktopActivated()
  */
 QString LightApp_Application::getFileFilter() const
 {
-  return "(*.bin)";
-  // HDF persistence not yet completed - to be uncommented later
-  //return "(*.hdf)";
+  //return "(*.bin)";
+  // HDF persistence
+  return "(*.hdf)";
 }
 
 /*! Gets file name*/
diff --git a/src/LightApp/LightApp_HDFDriver.cxx b/src/LightApp/LightApp_HDFDriver.cxx
new file mode 100644 (file)
index 0000000..bf003ae
--- /dev/null
@@ -0,0 +1,347 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
+#include "LightApp_HDFDriver.h"
+
+#include "HDFexplorer.hxx"
+#include "HDFOI.hxx"
+
+// OCCT Includes
+#include <TCollection_AsciiString.hxx>
+
+/*! Constructor.*/
+LightApp_HDFDriver::LightApp_HDFDriver()
+{
+}
+
+/*! Destructor.*/
+LightApp_HDFDriver::~LightApp_HDFDriver()
+{
+}
+
+using namespace std;
+
+//================================================================
+//  Function : SaveDatasInFile
+/*! Purpose  : save in file 'theFileName' datas from this driver*/
+//================================================================
+bool LightApp_HDFDriver::SaveDatasInFile( const char* theFileName, bool isMultiFile )
+{
+  bool isASCII = false;
+  bool isError = false;
+
+  HDFfile *hdf_file = 0;
+  HDFgroup *hdf_group_datacomponent = 0;
+  HDFgroup *hdf_group_study_structure = 0;
+  HDFgroup *hdf_sco_group  = 0;
+  HDFgroup *hdf_sco_group2 = 0;
+  HDFdataset *hdf_dataset = 0;
+  hdf_size aHDFSize[1];
+
+  try {
+    hdf_file = new HDFfile ((char*)theFileName);
+    hdf_file->CreateOnDisk();
+
+    //-----------------------------------------------------------------------
+    // 1 - Create a groupe for each SComponent and Update the PersistanceRef
+    //-----------------------------------------------------------------------
+    hdf_group_datacomponent = new HDFgroup ("DATACOMPONENT", hdf_file);
+    hdf_group_datacomponent->CreateOnDisk();
+
+    std::map<std::string, std::string> mapNameEntry;
+
+    int tag = 1;
+    std::map<std::string, ListOfFiles>::const_iterator it;
+    for (it = myMap.begin(); it != myMap.end(); ++it, ++tag) {
+      std::string aName (it->first);
+      char* aModuleName = const_cast<char*>(aName.c_str());
+      unsigned char* aBuffer;
+      long           aBufferSize;
+      PutFilesToStream(aName, aBuffer, aBufferSize, isMultiFile);
+
+      //Handle(SALOMEDSImpl_SComponent) sco = itcomponent.Value();
+      //TCollection_AsciiString scoid = sco->GetID();
+      //hdf_sco_group = new HDFgroup(scoid.ToCString(), hdf_group_datacomponent);
+
+      TCollection_AsciiString entry ("0:1:");
+      entry += TCollection_AsciiString(tag);
+      mapNameEntry[aModuleName] = entry.ToCString();
+
+      //hdf_sco_group = new HDFgroup (aModuleName, hdf_group_datacomponent);
+      hdf_sco_group = new HDFgroup (entry.ToCString(), hdf_group_datacomponent);
+      hdf_sco_group->CreateOnDisk();
+
+      aHDFSize[0] = aBufferSize;
+
+      hdf_dataset = new HDFdataset ("FILE_STREAM", hdf_sco_group, HDF_STRING, aHDFSize, 1);
+      hdf_dataset->CreateOnDisk();
+      hdf_dataset->WriteOnDisk(aBuffer); //Save the stream in the HDF file
+      hdf_dataset->CloseOnDisk();
+      hdf_dataset = 0; //will be deleted by hdf_sco_group destructor
+
+      // store multifile state
+      aHDFSize[0] = 2;
+      hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
+      hdf_dataset->CreateOnDisk();
+      hdf_dataset->WriteOnDisk((void*)(isMultiFile ? "M" : "S")); // save: multi or single
+      hdf_dataset->CloseOnDisk();
+      hdf_dataset = 0; //will be deleted by hdf_sco_group destructor
+
+      // store ASCII state
+      aHDFSize[0] = 2;
+      hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group, HDF_STRING, aHDFSize, 1);
+      hdf_dataset->CreateOnDisk();
+      hdf_dataset->WriteOnDisk((void*)(isASCII ? "A" : "B")); // save: ASCII or BINARY
+      hdf_dataset->CloseOnDisk();
+      hdf_dataset = 0; //will be deleted by hdf_sco_group destructor
+
+      hdf_sco_group->CloseOnDisk();
+      hdf_sco_group = 0; // will be deleted by hdf_group_datacomponent destructor
+
+      delete [] aBuffer;
+    }
+
+    hdf_group_datacomponent->CloseOnDisk();
+    hdf_group_datacomponent = 0; // will be deleted by hdf_file destructor
+
+    //-----------------------------------------------------------------------
+    // 3 - Write the Study Structure
+    //-----------------------------------------------------------------------
+    hdf_group_study_structure = new HDFgroup ("STUDY_STRUCTURE", hdf_file);
+    hdf_group_study_structure->CreateOnDisk();
+
+    for (it = myMap.begin(); it != myMap.end(); ++it) {
+      std::string aName (it->first);
+      char* aModuleName = const_cast<char*>(aName.c_str());
+
+      //hdf_sco_group2 = new HDFgroup(scid.ToCString(), hdf_group_study_structure);
+      char* entry = (char*)(mapNameEntry[aModuleName].c_str());
+      hdf_sco_group2 = new HDFgroup (entry, hdf_group_study_structure);
+      hdf_sco_group2->CreateOnDisk();
+
+      // ComponentDataType treatment
+      hdf_int32 name_len = (hdf_int32)strlen(aModuleName);
+      aHDFSize[0] = name_len + 1;
+      hdf_dataset = new HDFdataset ("COMPONENTDATATYPE", hdf_sco_group2, HDF_STRING, aHDFSize, 1);
+      hdf_dataset->CreateOnDisk();
+      hdf_dataset->WriteOnDisk(aModuleName);
+      hdf_dataset->CloseOnDisk();
+      hdf_dataset = 0; //will be deleted by hdf_sco_group2 destructor
+
+      hdf_sco_group2->CloseOnDisk();
+      hdf_sco_group2 = 0; // will be deleted by hdf_group_study_structure destructor
+    }
+
+    hdf_group_study_structure->CloseOnDisk();
+    hdf_group_study_structure = 0; // will be deleted by hdf_file destructor
+
+    hdf_file->CloseOnDisk();
+    delete hdf_file; // recursively deletes all hdf objects...
+
+  } catch (HDFexception) {
+    isError = true;
+  }
+  if (isASCII && !isError) { // save file in ASCII format
+    HDFascii::ConvertFromHDFToASCII(theFileName, true);
+  }
+
+  return !isError;
+}
+
+//=======================================================================
+//  Function : ReadDatasFromFile
+/*! Purpose  : filling current driver from file 'theFileName'*/
+//=======================================================================
+bool LightApp_HDFDriver::ReadDatasFromFile( const char* theFileName, bool isMultiFile )
+{
+  bool isASCII = false;
+  bool isError = false;
+  TCollection_AsciiString aHDFUrl;
+
+  HDFfile *hdf_file = 0;
+  HDFgroup *hdf_group_datacomponent = 0;
+  HDFgroup *hdf_group_study_structure = 0;
+  HDFgroup *hdf_sco_group  = 0;
+  HDFgroup *hdf_sco_group2 = 0;
+
+  std::map<std::string, std::string> mapEntryName;
+
+  if (HDFascii::isASCII(theFileName)) {
+    isASCII = true;
+    char* aResultPath = HDFascii::ConvertFromASCIIToHDF(theFileName);
+    aHDFUrl = aResultPath;
+    aHDFUrl += "hdf_from_ascii.hdf";
+    delete(aResultPath);
+  } else {
+    aHDFUrl = (char*)theFileName;
+  }
+
+  hdf_file = new HDFfile((char*)aHDFUrl.ToCString());
+
+  char aMultifileState[2];
+  char ASCIIfileState[2];
+
+  try {
+    hdf_file->OpenOnDisk(HDF_RDONLY);
+
+  } catch (HDFexception) {
+    //char *eStr = new char[strlen(aUrl.ToCString()) + 17];
+    //sprintf(eStr,"Can't open file %s", aUrl.ToCString());
+    //_errorCode = TCollection_AsciiString(eStr);
+    //delete [] eStr;
+    return false;
+  }
+
+  try {
+    if (!hdf_file->ExistInternalObject("STUDY_STRUCTURE")) {
+      //_errorCode = "Study is empty";
+      isError = true;
+    } else {
+      hdf_group_study_structure = new HDFgroup ("STUDY_STRUCTURE", hdf_file);
+      hdf_group_study_structure->OpenOnDisk();
+
+      char name[HDF_NAME_MAX_LEN + 1];
+      Standard_Integer nbsons = hdf_group_study_structure->nInternalObjects();
+      for (Standard_Integer i = 0; i < nbsons; i++) {
+        hdf_group_study_structure->InternalObjectIndentify(i, name);
+        if (strncmp(name, "INTERNAL_COMPLEX", 16) == 0) continue;
+        hdf_object_type type = hdf_group_study_structure->InternalObjectType(name);
+        if (type == HDF_GROUP) {
+          hdf_sco_group2 = new HDFgroup (name, hdf_group_study_structure);
+          hdf_sco_group2->OpenOnDisk();
+
+          // Read component data
+          char* aCompDataType = NULL;
+          int aDataSize = 0;
+
+          if (hdf_sco_group2->ExistInternalObject("COMPONENTDATATYPE")) {
+            HDFdataset *hdf_dataset = new HDFdataset("COMPONENTDATATYPE", hdf_sco_group2);
+            hdf_dataset->OpenOnDisk();
+            aDataSize = hdf_dataset->GetSize();
+            aCompDataType = new char[aDataSize];
+            if (aCompDataType == NULL) {
+              isError = true;
+            } else {
+              hdf_dataset->ReadFromDisk(aCompDataType);
+
+              mapEntryName[name] = aCompDataType;
+
+              delete [] aCompDataType;
+            }
+
+            hdf_dataset->CloseOnDisk();
+            hdf_dataset = 0;
+          }
+
+          hdf_sco_group2->CloseOnDisk();
+        }
+      }
+
+      hdf_group_study_structure->CloseOnDisk();
+    }
+
+    if (!hdf_file->ExistInternalObject("DATACOMPONENT")) {
+      //_errorCode = "No components stored";
+      isError = true;
+    } else {
+      hdf_group_datacomponent = new HDFgroup ("DATACOMPONENT", hdf_file);
+      hdf_group_datacomponent->OpenOnDisk();
+
+      char name[HDF_NAME_MAX_LEN + 1];
+      Standard_Integer nbsons = hdf_group_datacomponent->nInternalObjects();
+      for (Standard_Integer i = 0; i < nbsons; i++) {
+        hdf_group_datacomponent->InternalObjectIndentify(i, name);
+        if (strncmp(name, "INTERNAL_COMPLEX", 16) == 0) continue;
+        hdf_object_type type = hdf_group_datacomponent->InternalObjectType(name);
+        if (type == HDF_GROUP) {
+          hdf_sco_group = new HDFgroup (name, hdf_group_datacomponent);
+          hdf_sco_group->OpenOnDisk();
+
+          // Read component data
+          unsigned char* aStreamFile = NULL;
+          int aStreamSize = 0;
+
+          if (hdf_sco_group->ExistInternalObject("FILE_STREAM")) {
+            HDFdataset *hdf_dataset = new HDFdataset("FILE_STREAM", hdf_sco_group);
+            hdf_dataset->OpenOnDisk();
+            aStreamSize = hdf_dataset->GetSize();
+            aStreamFile = new unsigned char[aStreamSize];
+            if (aStreamFile == NULL) {
+              isError = true;
+            } else {
+              hdf_dataset->ReadFromDisk(aStreamFile);
+            }
+
+            hdf_dataset->CloseOnDisk();
+            hdf_dataset = 0;
+          }
+
+          HDFdataset *multifile_hdf_dataset = new HDFdataset("MULTIFILE_STATE", hdf_sco_group);
+          multifile_hdf_dataset->OpenOnDisk();
+          multifile_hdf_dataset->ReadFromDisk(aMultifileState);
+          multifile_hdf_dataset->CloseOnDisk();
+          multifile_hdf_dataset = 0;
+
+          HDFdataset *ascii_hdf_dataset = new HDFdataset("ASCII_STATE", hdf_sco_group);
+          ascii_hdf_dataset->OpenOnDisk();
+          ascii_hdf_dataset->ReadFromDisk(ASCIIfileState);
+          ascii_hdf_dataset->CloseOnDisk();
+          ascii_hdf_dataset = 0;
+
+          isASCII = (ASCIIfileState[0] == 'A') ? true : false;
+
+          if (aStreamFile != NULL) {
+            // Put buffer to aListOfFiles and set to myMap
+            ListOfFiles aListOfFiles = PutStreamToFiles(aStreamFile, aStreamSize, isMultiFile);
+            char* aCompDataType = (char*)(mapEntryName[name].c_str());
+            SetListOfFiles(aCompDataType, aListOfFiles);
+
+            delete [] aStreamFile;
+          }
+
+          hdf_sco_group->CloseOnDisk();
+        }
+      }
+
+      hdf_group_datacomponent->CloseOnDisk();
+    }
+  } catch (HDFexception) {
+    isError = true;
+
+    //Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString;
+    //aFilesToRemove->Append(aHDFUrl);
+    //RemoveFiles(aFilesToRemove, true);
+  }
+
+  hdf_file->CloseOnDisk();
+  delete hdf_file; // all related hdf objects will be deleted
+
+  if (isASCII && !isError) {
+    //Handle(TColStd_HSequenceOfAsciiString) aFilesToRemove = new TColStd_HSequenceOfAsciiString;
+    //aFilesToRemove->Append(aHDFUrl);
+    //RemoveFiles(aFilesToRemove, true);
+  }
+
+  //std::map<std::string, std::string>::const_iterator it;
+  //for (it = mapEntryName.begin(); it != mapEntryName.end(); ++it) {
+  //  cout << "Read Component: entry = " << it->first
+  //       << ", Component data type = " << it->second << endl;
+  //}
+
+  return !isError;
+}
diff --git a/src/LightApp/LightApp_HDFDriver.h b/src/LightApp/LightApp_HDFDriver.h
new file mode 100644 (file)
index 0000000..5a978ea
--- /dev/null
@@ -0,0 +1,23 @@
+#ifndef LIGHTAPP_HDFDRIVER_H
+#define LIGHTAPP_HDFDRIVER_H
+
+#include <LightApp.h>
+#include <LightApp_Driver.h>
+
+#ifdef WIN32
+#pragma warning( disable:4251 )
+#endif
+
+/*!Description : Driver can save to file and read from file list of files for light modules*/
+
+class LIGHTAPP_EXPORT LightApp_HDFDriver : public LightApp_Driver
+{
+public:
+  LightApp_HDFDriver();
+  virtual ~LightApp_HDFDriver();
+
+  virtual bool        SaveDatasInFile   (const char* theFileName, bool isMultiFile);
+  virtual bool        ReadDatasFromFile (const char* theFileName, bool isMultiFile);
+};
+
+#endif
index a2e5e4ba93cc2e947219e8260acb3e218b4b3702..31cb225949be067c1e243494da1cfa58fab4b733 100644 (file)
@@ -23,8 +23,7 @@
 #include "LightApp_DataModel.h"
 #include "LightApp_DataObject.h"
 #include "LightApp_RootObject.h"
-// HDF persistence not yet completed
-//#include "LightApp_HDFDriver.h"
+#include "LightApp_HDFDriver.h"
 
 #include "SUIT_ResourceMgr.h"
 #include "SUIT_DataObjectIterator.h"
 LightApp_Study::LightApp_Study( SUIT_Application* app )
 : CAM_Study( app )
 {
-  // HDF persistence not yet completed
-  //myDriver = new LightApp_HDFDriver();
-  myDriver = new LightApp_Driver();
+  // HDF persistence
+  myDriver = new LightApp_HDFDriver();
+  //myDriver = new LightApp_Driver();
 }
+
 /*!
   Destructor.
 */
index fc43d9593b99c8cfd1c79c4784cb751207161ecc..c26adb88277cf96a7d0f07fa74787c0b083e2e06 100755 (executable)
@@ -22,6 +22,7 @@ EXPORT_HEADERS= LightApp.h \
                LightApp_Dialog.h \
                LightApp_Displayer.h \
                LightApp_Driver.h \
+               LightApp_HDFDriver.h \
                LightApp_Module.h \
                LightApp_ModuleDlg.h \
                LightApp_NameDlg.h \
@@ -38,7 +39,6 @@ EXPORT_HEADERS= LightApp.h \
                LightApp_RootObject.h \
                LightApp_UpdateFlags.h \
                LightApp_WidgetContainer.h
-#               LightApp_HDFDriver.h \
 
 ifneq ($(DISABLE_VTKVIEWER),yes)
 ifneq ($(DISABLE_SALOMEOBJECT),yes)
@@ -68,6 +68,7 @@ LIB_SRC= LightApp_AboutDlg.cxx \
         LightApp_Dialog.cxx \
         LightApp_Displayer.cxx \
         LightApp_Driver.cxx \
+        LightApp_HDFDriver.cxx \
         LightApp_Module.cxx \
         LightApp_ModuleDlg.cxx \
         LightApp_NameDlg.cxx \
@@ -82,7 +83,6 @@ LIB_SRC= LightApp_AboutDlg.cxx \
         LightApp_Preferences.cxx \
         LightApp_PreferencesDlg.cxx \
         LightApp_WidgetContainer.cxx
-#        LightApp_HDFDriver.cxx \
 
 ifneq ($(DISABLE_VTKVIEWER),yes)
 ifneq ($(DISABLE_SALOMEOBJECT),yes)
@@ -134,8 +134,8 @@ RESOURCES_FILES = icon_about.png \
                  LightApp.ini \
                  LightApp.xml
 
-CPPFLAGS+=$(PYTHON_INCLUDES) $(QT_INCLUDES) $(OCC_INCLUDES)
-       #$(HDF5_INCLUDES)
+CPPFLAGS+=$(PYTHON_INCLUDES) $(QT_INCLUDES) $(OCC_INCLUDES) \
+       $(HDF5_INCLUDES) -I${KERNEL_ROOT_DIR}/include/salome
 
 ifneq ($(DISABLE_VTKVIEWER),yes)
   CPPFLAGS+= $(VTK_INCLUDES)
@@ -170,8 +170,9 @@ ifneq ($(DISABLE_PYCONSOLE),yes)
   LDFLAGS+= $(PYTHON_LIBS)
 endif
 
-LIBS+= -lsuit -lstd -lCAM -lObjBrowser -lLogWindow $(CAS_KERNEL) -lSalomePrs
-       #$(HDF5_LIBS) -lSalomeHDFPersistCopy
+LIBS+= -lsuit -lstd -lCAM -lObjBrowser -lLogWindow $(CAS_KERNEL) -lSalomePrs \
+       $(HDF5_LIBS) -L$(KERNEL_ROOT_DIR)/lib/salome -lSalomeHDFPersist
+
 ifneq ($(DISABLE_SALOMEOBJECT),yes)
   LIBS+= -lSalomeObject
 endif