#include <TDF_Delta.hxx>
+#include <QFile>
+#include <QStringList>
+#include <QTextStream>
+
IMPLEMENT_STANDARD_HANDLE(HYDROData_Document,MMgt_TShared)
IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Document,MMgt_TShared)
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();
#include <TDocStd_Document.hxx>
+class QFile;
+
+
/**
* Errors that could appear on document open/save actions.
* If there is no error, it is "OK".
//! 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)
//! 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
#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)
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();
#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;
*/
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