From: adv Date: Fri, 6 Sep 2013 10:08:40 +0000 (+0000) Subject: Base implementation of dumping study document in to Python script (Feature #14). X-Git-Tag: BR_hydro_v_0_1~63 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d3a78deaed27c428589ef3474c1c346324962f2;p=modules%2Fhydro.git Base implementation of dumping study document in to Python script (Feature #14). --- diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index bfc30b84..722a39e8 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -6,6 +6,10 @@ #include +#include +#include +#include + 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 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& 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(); diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index fbda6994..1ec24ee7 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -6,6 +6,9 @@ #include +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& 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 diff --git a/src/HYDROData/HYDROData_Object.cxx b/src/HYDROData/HYDROData_Object.cxx index 23f9038c..eb9d0f72 100644 --- a/src/HYDROData/HYDROData_Object.cxx +++ b/src/HYDROData/HYDROData_Object.cxx @@ -8,6 +8,9 @@ #include #include +#include +#include + 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(); diff --git a/src/HYDROData/HYDROData_Object.h b/src/HYDROData/HYDROData_Object.h index e5bfa5fb..4f2ae435 100644 --- a/src/HYDROData/HYDROData_Object.h +++ b/src/HYDROData/HYDROData_Object.h @@ -6,7 +6,9 @@ #include #include #include -#include + +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