From 9dd90968eb8ad86e7e6ae67f48bb6110bd4ffbdc Mon Sep 17 00:00:00 2001 From: asl Date: Fri, 13 Nov 2015 16:42:59 +0300 Subject: [PATCH] refs #651: wrapping for Python --- src/HYDROData/HYDROData_AltitudeObject.cxx | 3 +- src/HYDROData/HYDROData_AltitudeObject.h | 3 +- src/HYDROData/HYDROData_Bathymetry.cxx | 3 +- src/HYDROData/HYDROData_Bathymetry.h | 3 +- src/HYDROData/HYDROData_CalculationCase.cxx | 12 ++- src/HYDROData/HYDROData_CalculationCase.h | 8 +- src/HYDROData/HYDROData_Channel.cxx | 7 +- src/HYDROData/HYDROData_Channel.h | 3 +- src/HYDROData/HYDROData_Confluence.cxx | 3 +- src/HYDROData/HYDROData_Confluence.h | 3 +- src/HYDROData/HYDROData_Document.cxx | 61 ++++++++---- src/HYDROData/HYDROData_Document.h | 10 +- src/HYDROData/HYDROData_Entity.cxx | 13 ++- src/HYDROData/HYDROData_Entity.h | 9 +- src/HYDROData/HYDROData_Image.cxx | 7 +- src/HYDROData/HYDROData_Image.h | 3 +- src/HYDROData/HYDROData_ImmersibleZone.cxx | 7 +- src/HYDROData/HYDROData_ImmersibleZone.h | 3 +- src/HYDROData/HYDROData_LandCoverMap.cxx | 42 ++++++-- src/HYDROData/HYDROData_LandCoverMap.h | 5 +- src/HYDROData/HYDROData_Obstacle.cxx | 3 +- src/HYDROData/HYDROData_Obstacle.h | 3 +- src/HYDROData/HYDROData_Polyline3D.cxx | 11 ++- src/HYDROData/HYDROData_Polyline3D.h | 3 +- src/HYDROData/HYDROData_PolylineXY.cxx | 3 +- src/HYDROData/HYDROData_PolylineXY.h | 3 +- src/HYDROData/HYDROData_Profile.cxx | 3 +- src/HYDROData/HYDROData_Profile.h | 3 +- src/HYDROData/HYDROData_Region.cxx | 5 +- src/HYDROData/HYDROData_Region.h | 3 +- src/HYDROData/HYDROData_River.cxx | 3 +- src/HYDROData/HYDROData_River.h | 3 +- src/HYDROData/HYDROData_Stream.cxx | 9 +- src/HYDROData/HYDROData_Stream.h | 3 +- src/HYDROData/HYDROData_StricklerTable.cxx | 3 +- src/HYDROData/HYDROData_StricklerTable.h | 3 +- src/HYDROPy/HYDROData_Document.sip | 5 + src/HYDROPy/HYDROData_Entity.sip | 5 + src/HYDROPy/HYDROData_LandCoverMap.sip | 3 +- src/HYDRO_tests/reference_data/lc_dump.dbf | Bin 0 -> 65 bytes src/HYDRO_tests/reference_data/lc_dump.py | 91 ++++++++++++++++++ src/HYDRO_tests/reference_data/test_LCM.dbf | Bin 0 -> 65 bytes .../test_HYDROData_LandCoverMap.cxx | 14 ++- 43 files changed, 297 insertions(+), 93 deletions(-) create mode 100644 src/HYDRO_tests/reference_data/lc_dump.dbf create mode 100644 src/HYDRO_tests/reference_data/lc_dump.py create mode 100644 src/HYDRO_tests/reference_data/test_LCM.dbf diff --git a/src/HYDROData/HYDROData_AltitudeObject.cxx b/src/HYDROData/HYDROData_AltitudeObject.cxx index deac2dc0..44e21d08 100644 --- a/src/HYDROData/HYDROData_AltitudeObject.cxx +++ b/src/HYDROData/HYDROData_AltitudeObject.cxx @@ -33,7 +33,8 @@ HYDROData_AltitudeObject::~HYDROData_AltitudeObject() { } -QStringList HYDROData_AltitudeObject::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_AltitudeObject::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aName = GetObjPyName(); diff --git a/src/HYDROData/HYDROData_AltitudeObject.h b/src/HYDROData/HYDROData_AltitudeObject.h index 3d542337..3d10f39b 100644 --- a/src/HYDROData/HYDROData_AltitudeObject.h +++ b/src/HYDROData/HYDROData_AltitudeObject.h @@ -55,7 +55,8 @@ public: /** * Dump Altitude object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; public: diff --git a/src/HYDROData/HYDROData_Bathymetry.cxx b/src/HYDROData/HYDROData_Bathymetry.cxx index 73e763ef..b1204e6f 100644 --- a/src/HYDROData/HYDROData_Bathymetry.cxx +++ b/src/HYDROData/HYDROData_Bathymetry.cxx @@ -56,7 +56,8 @@ HYDROData_Bathymetry::~HYDROData_Bathymetry() { } -QStringList HYDROData_Bathymetry::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Bathymetry::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aBathymetryName = GetObjPyName(); diff --git a/src/HYDROData/HYDROData_Bathymetry.h b/src/HYDROData/HYDROData_Bathymetry.h index 5c355199..0842b12f 100644 --- a/src/HYDROData/HYDROData_Bathymetry.h +++ b/src/HYDROData/HYDROData_Bathymetry.h @@ -66,7 +66,8 @@ public: /** * Dump Bathymetry object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; public: // Public methods to work with Bathymetry altitudes. diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 34b413fa..d0927c2b 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -115,7 +115,8 @@ void HYDROData_CalculationCase::SetName( const QString& theName ) HYDROData_Entity::SetName( theName ); } -QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_CalculationCase::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); aResList.prepend( "# Calculation case" ); @@ -132,7 +133,7 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre { Handle(HYDROData_Object) aRefGeomObj = Handle(HYDROData_Object)::DownCast( anIter.Value() ); - setPythonReferenceObject( theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGeomObj, "AddGeometryObject" ); } aResList << QString( "" ); @@ -160,7 +161,7 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre } Handle(HYDROData_PolylineXY) aBoundaryPolyline = GetBoundaryPolyline(); - setPythonReferenceObject( theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBoundaryPolyline, "SetBoundaryPolyline" ); if( aMode==AUTOMATIC ) DumpRulesToPython( aCalculName, aResList ); @@ -173,7 +174,7 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre { // Now we restore the // - regions and zones order - DumpRegionsToPython( aResList, theTreatedObjects, GetRegions() ); + DumpRegionsToPython( aResList, thePyScriptPath, theTreatedObjects, GetRegions() ); } // Export calculation case @@ -1291,6 +1292,7 @@ void HYDROData_CalculationCase::UpdateRegionsNames( const HYDROData_SequenceOfOb } void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList, + const QString& thePyScriptPath, MapOfTreatedObjects& theTreatedObjects, const HYDROData_SequenceOfObjects& theRegions ) const { @@ -1304,7 +1306,7 @@ void HYDROData_CalculationCase::DumpRegionsToPython( QStringList& theResList, continue; theTreatedObjects.insert( aRegion->GetName(), aRegion ); - QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects ); + QStringList aRegDump = aRegion->DumpToPython( thePyScriptPath, theTreatedObjects ); theResList << aRegDump; } } diff --git a/src/HYDROData/HYDROData_CalculationCase.h b/src/HYDROData/HYDROData_CalculationCase.h index 4f09be72..7db0d86b 100644 --- a/src/HYDROData/HYDROData_CalculationCase.h +++ b/src/HYDROData/HYDROData_CalculationCase.h @@ -124,7 +124,8 @@ public: /** * Dump Calculation object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Update the calcualtion case object. @@ -444,8 +445,9 @@ private: const QString& theOldCaseName, const QString& theName ); - void DumpRegionsToPython( QStringList& theResList, - MapOfTreatedObjects& theTreatedObjects, + void DumpRegionsToPython( QStringList& theResList, + const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, const HYDROData_SequenceOfObjects& theRegions ) const; protected: diff --git a/src/HYDROData/HYDROData_Channel.cxx b/src/HYDROData/HYDROData_Channel.cxx index 9a8fae86..cd4800b4 100644 --- a/src/HYDROData/HYDROData_Channel.cxx +++ b/src/HYDROData/HYDROData_Channel.cxx @@ -80,16 +80,17 @@ HYDROData_Channel::~HYDROData_Channel() { } -QStringList HYDROData_Channel::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Channel::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aName = GetObjPyName(); Handle(HYDROData_Polyline3D) aRefGideLine = GetGuideLine(); - setPythonReferenceObject( theTreatedObjects, aResList, aRefGideLine, "SetGuideLine" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefGideLine, "SetGuideLine" ); Handle(HYDROData_Profile) aRefProfile = GetProfile(); - setPythonReferenceObject( theTreatedObjects, aResList, aRefProfile, "SetProfile" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefProfile, "SetProfile" ); aResList << QString( "" ); aResList << QString( "%1.Update();" ).arg( aName ); diff --git a/src/HYDROData/HYDROData_Channel.h b/src/HYDROData/HYDROData_Channel.h index 86ed56b0..372e57a7 100644 --- a/src/HYDROData/HYDROData_Channel.h +++ b/src/HYDROData/HYDROData_Channel.h @@ -83,7 +83,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns the list of all reference objects of this object. diff --git a/src/HYDROData/HYDROData_Confluence.cxx b/src/HYDROData/HYDROData_Confluence.cxx index e3995a69..aec5701b 100644 --- a/src/HYDROData/HYDROData_Confluence.cxx +++ b/src/HYDROData/HYDROData_Confluence.cxx @@ -37,7 +37,8 @@ HYDROData_Confluence::~HYDROData_Confluence() { } -QStringList HYDROData_Confluence::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Confluence::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aName = GetObjPyName(); diff --git a/src/HYDROData/HYDROData_Confluence.h b/src/HYDROData/HYDROData_Confluence.h index ec0ac2fe..e96a6a9a 100644 --- a/src/HYDROData/HYDROData_Confluence.h +++ b/src/HYDROData/HYDROData_Confluence.h @@ -49,7 +49,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; HYDRODATA_EXPORT virtual void UpdateLocalCS( double theDx, double theDy ); diff --git a/src/HYDROData/HYDROData_Document.cxx b/src/HYDROData/HYDROData_Document.cxx index ae714b17..653ddb8e 100644 --- a/src/HYDROData/HYDROData_Document.cxx +++ b/src/HYDROData/HYDROData_Document.cxx @@ -232,18 +232,18 @@ void HYDROData_Document::SetDefaultStricklerCoefficient( double theCoeff ) const } } -bool HYDROData_Document::DumpToPython( const QString& theFileName, +bool HYDROData_Document::DumpToPython( const QString& thePyScriptPath, const bool theIsMultiFile ) const { // Try to open the file - QFile aFile( theFileName ); + QFile aFile( thePyScriptPath ); if ( !aFile.open( QIODevice::WriteOnly ) ) return false; MapOfTreatedObjects aTreatedObjects; // Dump header for python script - QStringList aHeaderDump = DumpToPython( aTreatedObjects, theIsMultiFile ); + QStringList aHeaderDump = DumpToPython( thePyScriptPath, aTreatedObjects, theIsMultiFile ); if ( aHeaderDump.isEmpty() ) return false; @@ -259,19 +259,19 @@ bool HYDROData_Document::DumpToPython( const QString& theFileName, HYDROData_Tool::WriteStringsToFile( aFile, QStringList() << aLCS ); // Dump all model objects to Python script - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_IMAGE ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_PROFILE ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_POLYLINE ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_STREAM ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_CHANNEL ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_DIGUE ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP ); - aRes = aRes && dumpPartitionToPython( aFile, theIsMultiFile, aTreatedObjects, KIND_CALCULATION ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMAGE ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STRICKLER_TABLE ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINEXY ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_BATHYMETRY ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_PROFILE ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_POLYLINE ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_IMMERSIBLE_ZONE ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_STREAM ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CHANNEL ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_DIGUE ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_OBSTACLE ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_LAND_COVER_MAP ); + aRes = aRes && dumpPartitionToPython( aFile, thePyScriptPath, theIsMultiFile, aTreatedObjects, KIND_CALCULATION ); // Dump code to close python fuction if ( aRes && theIsMultiFile ) @@ -298,7 +298,8 @@ QString HYDROData_Document::GetDocPyName() const return aDocName; } -QStringList HYDROData_Document::DumpToPython( MapOfTreatedObjects& theTreatedObjects, +QStringList HYDROData_Document::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, const bool theIsMultiFile ) const { QString aDocName = GetDocPyName(); @@ -333,6 +334,7 @@ QStringList HYDROData_Document::DumpToPython( MapOfTreatedObjects& theTreatedObj } bool HYDROData_Document::dumpPartitionToPython( QFile& theFile, + const QString& thePyScriptPath, const bool theIsMultiFile, MapOfTreatedObjects& theTreatedObjects, const ObjectKind& theObjectKind ) const @@ -357,7 +359,7 @@ bool HYDROData_Document::dumpPartitionToPython( QFile& theFile, theTreatedObjects.insert( anObjName, anObject ); - QStringList anObjDump = anObject->DumpToPython( theTreatedObjects ); + QStringList anObjDump = anObject->DumpToPython( thePyScriptPath, theTreatedObjects ); if ( theIsMultiFile ) { @@ -885,4 +887,25 @@ QColor HYDROData_Document::GetAssociatedColor( const QString& theStricklerType, return aTable->GetColor( theStricklerType ); } return QColor(); -} \ No newline at end of file +} + +void HYDROData_Document::CollectQGISValues( const QString& theAttrName, + QStringList& theAttrValues, + QStringList& theStricklerTypes ) const +{ + HYDROData_Iterator It( this, KIND_STRICKLER_TABLE ); + for( ; It.More(); It.Next() ) + { + Handle(HYDROData_StricklerTable) aTable = Handle(HYDROData_StricklerTable)::DownCast( It.Current() ); + if( !aTable.IsNull() && aTable->GetAttrName()==theAttrName ) + { + theAttrValues.clear(); + theStricklerTypes = aTable->GetTypes(); + foreach( QString aType, theStricklerTypes ) + { + QString anAttrValue = aTable->GetAttrValue( aType ); + theAttrValues.append( anAttrValue ); + } + } + } +} diff --git a/src/HYDROData/HYDROData_Document.h b/src/HYDROData/HYDROData_Document.h index 3601a6b6..e3c7b1c8 100644 --- a/src/HYDROData/HYDROData_Document.h +++ b/src/HYDROData/HYDROData_Document.h @@ -103,13 +103,18 @@ public: //! 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, + HYDRODATA_EXPORT bool DumpToPython( const QString& thePyScriptPath, const bool theIsMultiFile ) const; //! Dump model data to Python script representation. - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects, + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, const bool theIsMultiFile ) const; + HYDRODATA_EXPORT void CollectQGISValues( const QString& theAttrName, + QStringList& theAttrValues, + QStringList& theStricklerTypes ) const; + public: // Methods to work with objects presentation. @@ -254,6 +259,7 @@ private: // Dump objects of type \c theObjectKind to file \c theFile bool dumpPartitionToPython( QFile& theFile, + const QString& thePyScriptPath, const bool theIsMultiFile, MapOfTreatedObjects& theDumpedObjects, const ObjectKind& theObjectKind ) const; diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index f0b9e5fb..7857cbc7 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -87,7 +87,8 @@ void HYDROData_Entity::SetName(const QString& theName) TDataStd_Name::Set(myLab, TCollection_ExtendedString(theName.toLatin1().constData())); } -QStringList HYDROData_Entity::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Entity::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList anEmptyList; return anEmptyList; @@ -654,12 +655,13 @@ QString HYDROData_Entity::getPyTypeID() const } } -void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, +void HYDROData_Entity::setPythonReferenceObject( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, QStringList& theScript, const Handle(HYDROData_Entity)& theRefObject, const QString& theMethod ) const { - if ( !checkObjectPythonDefinition( theTreatedObjects, theScript, theRefObject ) ) + if ( !checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, theScript, theRefObject ) ) return; QString aRefObjName = theRefObject->GetObjPyName(); @@ -669,7 +671,8 @@ void HYDROData_Entity::setPythonReferenceObject( MapOfTreatedObjects& .arg( anObjName ).arg( theMethod ).arg( aRefObjName ); } -bool HYDROData_Entity::checkObjectPythonDefinition( MapOfTreatedObjects& theTreatedObjects, +bool HYDROData_Entity::checkObjectPythonDefinition( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, QStringList& theScript, const Handle(HYDROData_Entity)& theRefObject ) const { @@ -684,7 +687,7 @@ bool HYDROData_Entity::checkObjectPythonDefinition( MapOfTreatedObjects& return true; // The definition of reference object must be dumped before this - QStringList aRefObjDump = theRefObject->DumpToPython( theTreatedObjects ); + QStringList aRefObjDump = theRefObject->DumpToPython( thePyScriptPath, theTreatedObjects ); if ( aRefObjDump.isEmpty() ) return false; diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index 0c612ba2..7e22bf79 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -145,7 +145,8 @@ public: * 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( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Updates object state. Base implementation dose nothing. @@ -410,12 +411,14 @@ protected: */ QString getPyTypeID() const; - void setPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, + void setPythonReferenceObject( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, QStringList& theScript, const Handle(HYDROData_Entity)& theRefObject, const QString& theMethod ) const; - bool checkObjectPythonDefinition( MapOfTreatedObjects& theTreatedObjects, + bool checkObjectPythonDefinition( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects, QStringList& theScript, const Handle(HYDROData_Entity)& theRefObject ) const; diff --git a/src/HYDROData/HYDROData_Image.cxx b/src/HYDROData/HYDROData_Image.cxx index 4e91edaf..0874417f 100644 --- a/src/HYDROData/HYDROData_Image.cxx +++ b/src/HYDROData/HYDROData_Image.cxx @@ -62,7 +62,8 @@ HYDROData_Image::~HYDROData_Image() { } -QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Image::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString anImageName = GetObjPyName(); @@ -127,7 +128,7 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject if ( aTransformationMode == ReferenceImage ) { Handle(HYDROData_Image) aRefImg = GetTrsfReferenceImage(); - setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "SetTrsfReferenceImage" ); } } } @@ -170,7 +171,7 @@ QStringList HYDROData_Image::DumpToPython( MapOfTreatedObjects& theTreatedObject for ( int i = 0; i < aNbReferences; ++i ) { Handle(HYDROData_Image) aRefImg = Handle(HYDROData_Image)::DownCast( Reference( i ) ); - setPythonReferenceObject( theTreatedObjects, aResList, aRefImg, "AppendReference" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefImg, "AppendReference" ); } } } diff --git a/src/HYDROData/HYDROData_Image.h b/src/HYDROData/HYDROData_Image.h index fcbb657f..255e0575 100644 --- a/src/HYDROData/HYDROData_Image.h +++ b/src/HYDROData/HYDROData_Image.h @@ -78,7 +78,8 @@ public: /** * Dump Image object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Updates object state. diff --git a/src/HYDROData/HYDROData_ImmersibleZone.cxx b/src/HYDROData/HYDROData_ImmersibleZone.cxx index f3c54679..f3b7d675 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.cxx +++ b/src/HYDROData/HYDROData_ImmersibleZone.cxx @@ -57,17 +57,18 @@ HYDROData_ImmersibleZone::~HYDROData_ImmersibleZone() { } -QStringList HYDROData_ImmersibleZone::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_ImmersibleZone::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aZoneName = GetObjPyName(); Handle(HYDROData_IAltitudeObject) aRefAltitude = GetAltitudeObject(); - setPythonReferenceObject( theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefAltitude, "SetAltitudeObject" ); Handle(HYDROData_PolylineXY) aRefPolyline = GetPolyline(); - setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolyline" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefPolyline, "SetPolyline" ); aResList << QString( "" ); diff --git a/src/HYDROData/HYDROData_ImmersibleZone.h b/src/HYDROData/HYDROData_ImmersibleZone.h index 0a9cf542..3e4d6e84 100644 --- a/src/HYDROData/HYDROData_ImmersibleZone.h +++ b/src/HYDROData/HYDROData_ImmersibleZone.h @@ -52,7 +52,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns the list of all reference objects of this object. diff --git a/src/HYDROData/HYDROData_LandCoverMap.cxx b/src/HYDROData/HYDROData_LandCoverMap.cxx index 53ac69ae..aceb28a9 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.cxx +++ b/src/HYDROData/HYDROData_LandCoverMap.cxx @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -249,10 +250,14 @@ HYDROData_LandCoverMap::DBFStatus HYDROData_LandCoverMap::ImportDBF( const QStri for( ; anIt.More(); anIt.Next() ) { int CurIndex = anIt.Index(); - HYDROData_ShapeFile::DBF_AttrValue AValue = theAttrV[theIndices[CurIndex]]; - int StricklerTypesInd = theDBFValues.indexOf(QString(AValue.myStrVal)); + int anIndex = CurIndex; + if( !theIndices.isEmpty() ) + anIndex = theIndices[CurIndex]; + + HYDROData_ShapeFile::DBF_AttrValue AValue = theAttrV[anIndex]; + int StricklerTypesInd = theDBFValues.indexOf( QString( AValue.myStrVal ) ); if ( StricklerTypesInd != -1) - anIt.SetStricklerType(theStricklerTypes[StricklerTypesInd]); + anIt.SetStricklerType( theStricklerTypes[StricklerTypesInd] ); else allOK = false; } @@ -897,20 +902,41 @@ TopoDS_Face HYDROData_LandCoverMap::FindByPoint( const gp_Pnt2d& thePoint, QStri return TopoDS_Face(); } +void Dump( const QString& theName, const QStringList& theList, QStringList& theLines ) +{ + theLines.append( QString( "%1 = QStringList()" ).arg( theName ) ); + foreach( QString anItem, theList ) + theLines.append( QString( "%1.append( u\"%2\" )" ).arg( theName ).arg( anItem ) ); +} + /** Dump to Python @param theTreatedObjects the map of treated objects */ -QStringList HYDROData_LandCoverMap::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_LandCoverMap::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aName = GetObjPyName(); - QString aShapeFileName = aName + ".shp"; - QString aDbfFileName = aName + ".dbf"; + QString aShapeFileName = thePyScriptPath; + aShapeFileName.replace( ".py", ".shp" ); + QString aDbfFileName = thePyScriptPath; + aDbfFileName.replace( ".py", ".dbf" ); + + //TODO: export shape file + + QString anAttr = "CODE_06"; //TODO: some custom choice + QStringList anAttrValues, aTypes; + HYDROData_Document::Document( myLab )->CollectQGISValues( anAttr, anAttrValues, aTypes ); + ExportDBF( aDbfFileName, anAttr, anAttrValues, aTypes ); + + //TODO: insert command to import shape file - QString anAttr = "CODE_06"; - //ExportDBF( aDbfFileName, anAttr, + Dump( "attr_values", anAttrValues, aResList ); + Dump( "types", aTypes, aResList ); + aResList << QString( "%1.ImportDBF( '%2', '%3', attr_values, types )" ). + arg( aName ).arg( aDbfFileName ).arg( anAttr ); return aResList; } diff --git a/src/HYDROData/HYDROData_LandCoverMap.h b/src/HYDROData/HYDROData_LandCoverMap.h index e078ddd0..3a671664 100644 --- a/src/HYDROData/HYDROData_LandCoverMap.h +++ b/src/HYDROData/HYDROData_LandCoverMap.h @@ -91,7 +91,7 @@ public: const QString& theFieldName, const QStringList& DBFValues, const QStringList& StricklerTypes, - const QList& theIndices ); + const QList& theIndices = QList() ); HYDRODATA_EXPORT void ExportDBF( const QString& theDBFFileName, const QString& theFieldName, @@ -118,7 +118,8 @@ public: HYDRODATA_EXPORT QString StricklerType( const TopoDS_Face& ) const; - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; HYDRODATA_EXPORT int GetLCCount() const; HYDRODATA_EXPORT bool IsEmpty() const; diff --git a/src/HYDROData/HYDROData_Obstacle.cxx b/src/HYDROData/HYDROData_Obstacle.cxx index 6af8456d..9c738a11 100644 --- a/src/HYDROData/HYDROData_Obstacle.cxx +++ b/src/HYDROData/HYDROData_Obstacle.cxx @@ -88,7 +88,8 @@ HYDROData_Obstacle::~HYDROData_Obstacle() { } -QStringList HYDROData_Obstacle::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Obstacle::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); diff --git a/src/HYDROData/HYDROData_Obstacle.h b/src/HYDROData/HYDROData_Obstacle.h index 3c792a16..bbf690a2 100644 --- a/src/HYDROData/HYDROData_Obstacle.h +++ b/src/HYDROData/HYDROData_Obstacle.h @@ -52,7 +52,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Update the immersible zone object. diff --git a/src/HYDROData/HYDROData_Polyline3D.cxx b/src/HYDROData/HYDROData_Polyline3D.cxx index d11aaf93..564f4f2c 100644 --- a/src/HYDROData/HYDROData_Polyline3D.cxx +++ b/src/HYDROData/HYDROData_Polyline3D.cxx @@ -63,20 +63,21 @@ HYDROData_Polyline3D::~HYDROData_Polyline3D() { } -QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Polyline3D::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aPolylineName = GetObjPyName(); Handle(HYDROData_PolylineXY) aRefPolyline = GetPolylineXY(); - setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" ); Handle(HYDROData_ProfileUZ) aRefProfileUZ = GetProfileUZ(); if ( !aRefProfileUZ.IsNull() ) { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aRefProfileUZ->GetFatherObject() ); - if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) ) + if ( checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, aResList, aProfile ) ) { QString aProfileName = aProfile->GetObjPyName(); if ( !aProfileName.isEmpty() ) @@ -96,7 +97,7 @@ QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedO { Handle(HYDROData_Profile) aProfile = Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() ); - if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) ) + if ( checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, aResList, aProfile ) ) { QString aProfileName = aProfile->GetObjPyName(); if ( !aProfileName.isEmpty() ) @@ -107,7 +108,7 @@ QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedO } } - setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" ); } } diff --git a/src/HYDROData/HYDROData_Polyline3D.h b/src/HYDROData/HYDROData_Polyline3D.h index 2506681e..1705f29a 100644 --- a/src/HYDROData/HYDROData_Polyline3D.h +++ b/src/HYDROData/HYDROData_Polyline3D.h @@ -61,7 +61,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns the list of all reference objects of this object. diff --git a/src/HYDROData/HYDROData_PolylineXY.cxx b/src/HYDROData/HYDROData_PolylineXY.cxx index 559947e6..5127c91b 100644 --- a/src/HYDROData/HYDROData_PolylineXY.cxx +++ b/src/HYDROData/HYDROData_PolylineXY.cxx @@ -130,7 +130,8 @@ HYDROData_PolylineXY::~HYDROData_PolylineXY() { } -QStringList HYDROData_PolylineXY::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_PolylineXY::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aPolylineName = GetObjPyName(); diff --git a/src/HYDROData/HYDROData_PolylineXY.h b/src/HYDROData/HYDROData_PolylineXY.h index 611a2a30..e9181876 100644 --- a/src/HYDROData/HYDROData_PolylineXY.h +++ b/src/HYDROData/HYDROData_PolylineXY.h @@ -57,7 +57,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Update the wire contour on the basis of the polyline data. diff --git a/src/HYDROData/HYDROData_Profile.cxx b/src/HYDROData/HYDROData_Profile.cxx index 217c49c9..76b0bed2 100644 --- a/src/HYDROData/HYDROData_Profile.cxx +++ b/src/HYDROData/HYDROData_Profile.cxx @@ -64,7 +64,8 @@ HYDROData_Profile::~HYDROData_Profile() { } -QStringList HYDROData_Profile::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Profile::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aProfileName = GetObjPyName(); diff --git a/src/HYDROData/HYDROData_Profile.h b/src/HYDROData/HYDROData_Profile.h index f1f52380..5bcc450d 100644 --- a/src/HYDROData/HYDROData_Profile.h +++ b/src/HYDROData/HYDROData_Profile.h @@ -63,7 +63,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns the top shape of the object. diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index 582357e8..60210bbc 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -388,7 +388,8 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* return aResShape; } -QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Region::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList; @@ -433,7 +434,7 @@ QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjec } // add zone - setPythonReferenceObject( theTreatedObjects, aResList, aZone, "AddZone" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aZone, "AddZone" ); } return aResList; diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index b8da0556..f92ae0e1 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -59,7 +59,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns flag indicating that object is updateble or not. diff --git a/src/HYDROData/HYDROData_River.cxx b/src/HYDROData/HYDROData_River.cxx index 406ca4b1..7f28594a 100644 --- a/src/HYDROData/HYDROData_River.cxx +++ b/src/HYDROData/HYDROData_River.cxx @@ -37,7 +37,8 @@ HYDROData_River::~HYDROData_River() { } -QStringList HYDROData_River::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_River::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aName = GetObjPyName(); diff --git a/src/HYDROData/HYDROData_River.h b/src/HYDROData/HYDROData_River.h index dee7d624..0873ce15 100644 --- a/src/HYDROData/HYDROData_River.h +++ b/src/HYDROData/HYDROData_River.h @@ -49,7 +49,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Update the immersible zone object. diff --git a/src/HYDROData/HYDROData_Stream.cxx b/src/HYDROData/HYDROData_Stream.cxx index c2def15f..5f6f828f 100644 --- a/src/HYDROData/HYDROData_Stream.cxx +++ b/src/HYDROData/HYDROData_Stream.cxx @@ -103,25 +103,26 @@ HYDROData_Stream::~HYDROData_Stream() { } -QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_Stream::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aName = GetObjPyName(); Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis(); - setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" ); HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles(); for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i ) { const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i ); - setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" ); } // Set bottom polyline if exists const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline(); if ( !aBottomPolyline.IsNull() ) { - setPythonReferenceObject( theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" ); + setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" ); } aResList << QString( "" ); diff --git a/src/HYDROData/HYDROData_Stream.h b/src/HYDROData/HYDROData_Stream.h index cfcd6a11..73691575 100644 --- a/src/HYDROData/HYDROData_Stream.h +++ b/src/HYDROData/HYDROData_Stream.h @@ -100,7 +100,8 @@ public: /** * Dump object to Python script representation. */ - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns the list of all reference objects of this object. diff --git a/src/HYDROData/HYDROData_StricklerTable.cxx b/src/HYDROData/HYDROData_StricklerTable.cxx index b2901ef5..e5c2c347 100644 --- a/src/HYDROData/HYDROData_StricklerTable.cxx +++ b/src/HYDROData/HYDROData_StricklerTable.cxx @@ -203,7 +203,8 @@ void HYDROData_StricklerTable::Clear() aMap->ChangeReals( TDataStd_DataMapOfStringReal() ); } -QStringList HYDROData_StricklerTable::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +QStringList HYDROData_StricklerTable::DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const { QStringList aResList = dumpObjectCreation( theTreatedObjects ); QString aPyName = GetObjPyName(); diff --git a/src/HYDROData/HYDROData_StricklerTable.h b/src/HYDROData/HYDROData_StricklerTable.h index 6c081e1b..f50f4546 100644 --- a/src/HYDROData/HYDROData_StricklerTable.h +++ b/src/HYDROData/HYDROData_StricklerTable.h @@ -59,7 +59,8 @@ public: HYDRODATA_EXPORT void Clear(); - HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; + HYDRODATA_EXPORT virtual QStringList DumpToPython( const QString& thePyScriptPath, + MapOfTreatedObjects& theTreatedObjects ) const; HYDRODATA_EXPORT QString GetAttrName() const; HYDRODATA_EXPORT bool SetAttrName( const QString& ) const; diff --git a/src/HYDROPy/HYDROData_Document.sip b/src/HYDROPy/HYDROData_Document.sip index 584b11dd..2ff3c604 100644 --- a/src/HYDROPy/HYDROData_Document.sip +++ b/src/HYDROPy/HYDROData_Document.sip @@ -168,6 +168,11 @@ class HYDROData_Document aRes = new HYDROData_StricklerTable( *dynamic_cast( theObject ) ); break; } + case KIND_LAND_COVER_MAP: + { + aRes = new HYDROData_LandCoverMap( *dynamic_cast( theObject ) ); + break; + } } return aRes; diff --git a/src/HYDROPy/HYDROData_Entity.sip b/src/HYDROPy/HYDROData_Entity.sip index ee4e4841..52a84635 100644 --- a/src/HYDROPy/HYDROData_Entity.sip +++ b/src/HYDROPy/HYDROData_Entity.sip @@ -44,6 +44,7 @@ const ObjectKind KIND_SHAPES_GROUP; const ObjectKind KIND_SPLITTED_GROUP; const ObjectKind KIND_OBSTACLE_ALTITUDE; const ObjectKind KIND_STRICKLER_TABLE; +const ObjectKind KIND_LAND_COVER_MAP; class HYDROData_Entity { @@ -143,6 +144,10 @@ class HYDROData_Entity sipClass = sipClass_HYDROData_StricklerTable; break; + case KIND_LAND_COVER_MAP: + sipClass = sipClass_HYDROData_LandCoverMap; + break; + case KIND_UNKNOWN: sipClass = sipClass_HYDROData_Entity; break; diff --git a/src/HYDROPy/HYDROData_LandCoverMap.sip b/src/HYDROPy/HYDROData_LandCoverMap.sip index 734565ea..cd0ed5b8 100644 --- a/src/HYDROPy/HYDROData_LandCoverMap.sip +++ b/src/HYDROPy/HYDROData_LandCoverMap.sip @@ -55,8 +55,7 @@ public: DBFStatus ImportDBF( const QString& theDBFFileName, const QString& theFieldName, const QStringList& DBFValues, - const QStringList& StricklerTypes, - const QList& theIndices ); + const QStringList& StricklerTypes ); void ExportDBF( const QString& theDBFFileName, const QString& theFieldName, diff --git a/src/HYDRO_tests/reference_data/lc_dump.dbf b/src/HYDRO_tests/reference_data/lc_dump.dbf new file mode 100644 index 0000000000000000000000000000000000000000..2766ee85b4494e93bb9c7beee07150fc1f645681 GIT binary patch literal 65 ncmZRMXP06C0!Ic>5QPfD85o@XU0mZ0%s}GKAVLI0AOT(gf35>{ literal 0 HcmV?d00001 diff --git a/src/HYDRO_tests/reference_data/lc_dump.py b/src/HYDRO_tests/reference_data/lc_dump.py new file mode 100644 index 00000000..3b145eab --- /dev/null +++ b/src/HYDRO_tests/reference_data/lc_dump.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- + +### +### This file is generated automatically by SALOME v7.6.0 with dump python functionality +### + +import sys +import salome + +salome.salome_init() +theStudy = salome.myStudy + +import salome_notebook +notebook = salome_notebook.NoteBook(theStudy) +sys.path.insert( 0, r'D:/asl/hydro/studies') + +### +### HYDRO component +### + +from HYDROPy import * +from PyQt4.QtCore import * +from PyQt4.QtGui import * + +hydro_doc = HYDROData_Document.Document( theStudy._get_StudyId() ); + +hydro_doc.SetLocalCS( 0, 0 ) + +DefStr = hydro_doc.CreateObject( KIND_STRICKLER_TABLE ); +DefStr.SetName( "DefStr" ); + +DefStr.SetAttrName( "CODE_06" ); + +DefStr.Set( u"Zones de champs, prairies, sans cultures", 20 ); +DefStr.SetAttrValue( u"Zones de champs, prairies, sans cultures", "511" ); +DefStr.SetColor( u"Zones de champs, prairies, sans cultures", QColor( 255, 0, 0 ) ); + +DefStr.Set( u"Zones à faible urbanization (bourg)", 9 ); +DefStr.SetAttrValue( u"Zones à faible urbanization (bourg)", "" ); +DefStr.SetColor( u"Zones à faible urbanization (bourg)", QColor( 0, 0, 255 ) ); + +DefStr.Set( u"Zones de champs cultivé à végétation haute", 12.5 ); +DefStr.SetAttrValue( u"Zones de champs cultivé à végétation haute", "" ); +DefStr.SetColor( u"Zones de champs cultivé à végétation haute", QColor( 0, 255, 0 ) ); + +DefStr.Set( u"Canaux artificiels en béton", 65 ); +DefStr.SetAttrValue( u"Canaux artificiels en béton", "" ); +DefStr.SetColor( u"Canaux artificiels en béton", QColor( 136, 136, 136 ) ); + +DefStr.Set( u"Canaux naturels", 35 ); +DefStr.SetAttrValue( u"Canaux naturels", "" ); +DefStr.SetColor( u"Canaux naturels", QColor( 255, 0, 255 ) ); + +DefStr.Set( u"Zones à forte urbanization (agglomération)", 9 ); +DefStr.SetAttrValue( u"Zones à forte urbanization (agglomération)", "" ); +DefStr.SetColor( u"Zones à forte urbanization (agglomération)", QColor( 18, 52, 86 ) ); + +DefStr.Set( u"Zones de champs cultivé à végétation basse", 17.5 ); +DefStr.SetAttrValue( u"Zones de champs cultivé à végétation basse", "512" ); +DefStr.SetColor( u"Zones de champs cultivé à végétation basse", QColor( 255, 255, 0 ) ); + +DefStr.Set( u"Zones d'arbustes, de sous-bois", 10 ); +DefStr.SetAttrValue( u"Zones d'arbustes, de sous-bois", "" ); +DefStr.SetColor( u"Zones d'arbustes, de sous-bois", QColor( 0, 255, 255 ) ); + + +DefStr.Update(); + +test_LCM = hydro_doc.CreateObject( KIND_LAND_COVER_MAP ); +test_LCM.SetName( "test_LCM" ); + +attr_values = QStringList() +attr_values.append( u"" ) +attr_values.append( u"" ) +attr_values.append( u"" ) +attr_values.append( u"512" ) +attr_values.append( u"" ) +attr_values.append( u"511" ) +attr_values.append( u"" ) +attr_values.append( u"" ) +types = QStringList() +types.append( u"Canaux artificiels en béton" ) +types.append( u"Canaux naturels" ) +types.append( u"Zones d'arbustes, de sous-bois" ) +types.append( u"Zones de champs cultivé à végétation basse" ) +types.append( u"Zones de champs cultivé à végétation haute" ) +types.append( u"Zones de champs, prairies, sans cultures" ) +types.append( u"Zones à faible urbanization (bourg)" ) +types.append( u"Zones à forte urbanization (agglomération)" ) +test_LCM.ImportDBF( 'C:/tmp/lc_dump.dbf', 'CODE_06', attr_values, types ) + diff --git a/src/HYDRO_tests/reference_data/test_LCM.dbf b/src/HYDRO_tests/reference_data/test_LCM.dbf new file mode 100644 index 0000000000000000000000000000000000000000..2766ee85b4494e93bb9c7beee07150fc1f645681 GIT binary patch literal 65 ncmZRMXP06C0!Ic>5QPfD85o@XU0mZ0%s}GKAVLI0AOT(gf35>{ literal 0 HcmV?d00001 diff --git a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx index 0d52d3e6..4976d7e6 100644 --- a/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx +++ b/src/HYDRO_tests/test_HYDROData_LandCoverMap.cxx @@ -531,6 +531,11 @@ void test_HYDROData_LandCoverMap::test_dump_python() { Handle(HYDROData_Document) aDoc = HYDROData_Document::Document(1); + Handle(HYDROData_StricklerTable) aTable = + Handle(HYDROData_StricklerTable)::DownCast( aDoc->CreateObject( KIND_STRICKLER_TABLE ) ); + CPPUNIT_ASSERT_EQUAL( true, aTable->Import( DEF_STR_PATH ) ); + aTable->SetName( "DefStr" ); + Handle(HYDROData_LandCoverMap) aMap = Handle(HYDROData_LandCoverMap)::DownCast( aDoc->CreateObject( KIND_LAND_COVER_MAP ) ); aMap->SetName( "test_LCM" ); @@ -551,10 +556,15 @@ void test_HYDROData_LandCoverMap::test_dump_python() 127 << 42 << 145 << 43 << 148 << 60 << 90 << 65 ); CPPUNIT_ASSERT_EQUAL( true, aMap->LocalPartition( aLC3, "test3" ) ); - QString aTmpPath = QDir::tempPath() + "/lc_dump.py"; + QString aBaseName = "lc_dump.py"; + QString aBaseShp = "lc_dump.shp"; + QString aBaseDbf = "lc_dump.dbf"; + QString aTmpPath = QDir::tempPath() + "/" + aBaseName; CPPUNIT_ASSERT_EQUAL( true, aDoc->DumpToPython( aTmpPath, false ) ); - //TODO: compare files + CPPUNIT_ASSERT_SCRIPTS_EQUAL( aBaseName, true, false, 20 ); + //TODO: CPPUNIT_ASSERT_FILES_EQUAL( aBaseShp ); + //TODO: CPPUNIT_ASSERT_FILES_EQUAL( aBaseDbf ); aDoc->Close(); } -- 2.39.2