]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Base implementation of dumping study document in to Python script (Feature #14).
authoradv <adv@opencascade.com>
Fri, 6 Sep 2013 10:08:40 +0000 (10:08 +0000)
committeradv <adv@opencascade.com>
Fri, 6 Sep 2013 10:08:40 +0000 (10:08 +0000)
src/HYDROData/HYDROData_Document.cxx
src/HYDROData/HYDROData_Document.h
src/HYDROData/HYDROData_Object.cxx
src/HYDROData/HYDROData_Object.h

index bfc30b84ba90d77b320a9068f3e17ab53af411ba..722a39e84c9dff6b01e4678b99b3a64b8b6e82e3 100644 (file)
@@ -6,6 +6,10 @@
 
 #include <TDF_Delta.hxx>
 
+#include <QFile>
+#include <QStringList>
+#include <QTextStream>
+
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Document,MMgt_TShared)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
 
@@ -126,6 +130,61 @@ void HYDROData_Document::Close()
   HYDROData_Application::GetApplication()->RemoveDocument(this);
 }
 
+bool HYDROData_Document::DumpToPython( const QString& theFileName ) const
+{
+  // Try to open the file
+  QFile aFile( theFileName );
+  if ( !aFile.exists() || !aFile.open( QIODevice::WriteOnly ) )
+    return false;
+
+  QMap<QString,Handle(HYDROData_Object)> aDumpedObjects;
+
+  bool aRes =    dumpPartitionToPython( aFile, aDumpedObjects, KIND_IMAGE      );
+  aRes = aRes && dumpPartitionToPython( aFile, aDumpedObjects, KIND_POLYLINE   );
+  aRes = aRes && dumpPartitionToPython( aFile, aDumpedObjects, KIND_BATHYMETRY );
+
+  return aRes;
+}
+
+bool HYDROData_Document::dumpPartitionToPython(
+  QFile&                                  theFile,
+  QMap<QString,Handle(HYDROData_Object)>& theDumpedObjects,
+  const ObjectKind&                       theObjectKind ) const
+{
+  if ( !theFile.isOpen() )
+    return false;
+
+  QTextStream anOutStream( &theFile );
+
+  bool aRes = true;
+
+  HYDROData_Iterator anIterator( this, theObjectKind );
+  for( ; anIterator.More(); anIterator.Next() )
+  {
+    Handle(HYDROData_Object) anObject = anIterator.Current();
+    if ( anObject.IsNull() )
+      continue;
+
+    QString anObjName = anObject->GetName();
+    if ( theDumpedObjects.contains( anObjName ) )
+      continue;
+
+    theDumpedObjects.insert( anObjName, anObject );
+
+    QStringList anObjDump = anObject->DumpToPython();
+    if ( anObjDump.isEmpty() )
+      continue;
+    
+    QString anObjDumpStr = anObjDump.join( "\n" );
+    if ( anObjDumpStr.isEmpty() )
+      continue;
+
+    anOutStream << anObjDumpStr << "\n";
+  }
+  
+  return aRes;
+}
+
 void HYDROData_Document::StartOperation()
 {
   myDoc->NewCommand();
index fbda69941454765aba8e1be88e169ef2f871cc14..1ec24ee7e11540fc86a1c47665f771660f690094 100644 (file)
@@ -6,6 +6,9 @@
 
 #include <TDocStd_Document.hxx>
 
+class QFile;
+
+
 /**
  * Errors that could appear on document open/save actions.
  * If there is no error, it is "OK".
@@ -56,6 +59,11 @@ public:
   //! Removes document data
   HYDRODATA_EXPORT void Close();
 
+  //! Dump study document to Python script representation.
+  //! \param theFileName full name of the file to store
+  //! \returns true if document has been successfuly dumped
+  HYDRODATA_EXPORT bool DumpToPython( const QString& theFileName ) const;
+
   //! Starts a new operation (opens a tansaction)
   HYDRODATA_EXPORT void StartOperation();
   //! Finishes the previously started operation (closes the transaction)
@@ -109,6 +117,13 @@ protected:
   //! Returns the label where the objects are located (used by Iterator)
   TDF_Label LabelOfObjects();
 
+private:
+  
+  // Dump objects of type \c theObjectKind to file \c theFile
+  bool dumpPartitionToPython( QFile&                                  theFile,
+                              QMap<QString,Handle(HYDROData_Object)>& theDumpedObjects,
+                              const ObjectKind&                       theObjectKind ) const;
+
 private:
   Handle(TDocStd_Document) myDoc; ///< OCAF document instance corresponding for keeping all persistent data
   int myTransactionsAfterSave; ///< number of transactions after the last "save" call, used for "IsModified" method
index 23f9038cdd8dbe09584119c54768909e06513413..eb9d0f7205de109e43a843c725ad74ae8b021a6e 100644 (file)
@@ -8,6 +8,9 @@
 #include <TDataStd_RealArray.hxx>
 #include <TDF_CopyLabel.hxx>
 
+#include <QString>
+#include <QStringList>
+
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Object,MMgt_TShared)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Object,MMgt_TShared)
 
@@ -32,6 +35,12 @@ void HYDROData_Object::SetName(const QString& theName)
   TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData()));
 }
 
+QStringList HYDROData_Object::DumpToPython() const
+{
+  QStringList anEmptyList;
+  return anEmptyList;
+}
+
 bool HYDROData_Object::IsRemoved() const
 {
   return !myLab.HasAttribute();
index e5bfa5fb2945a3337fd4d9f5f465d4d5af1a454d..4f2ae435e1570f20557053379f822131c98c1a70 100644 (file)
@@ -6,7 +6,9 @@
 #include <NCollection_Sequence.hxx>
 #include <TDF_Label.hxx>
 #include <QMap>
-#include <QString>
+
+class QString;
+class QStringList;
 
 ///! Kind of an object in a document
 typedef int ObjectKind;
@@ -56,6 +58,14 @@ public:
    */
   HYDRODATA_EXPORT void SetName(const QString& theName);
 
+  /**
+   * Dump object to Python script representation.
+   * Base implementation returns empty list,
+   * You should reimplement this function in your derived class if it
+   * has Python API and can be imported/exported from/to Python script.
+   */
+  HYDRODATA_EXPORT virtual QStringList DumpToPython() const;
+
   /**
    * Checks is object exists in the data structure.
    * \returns true is object is not exists in the data model