From: mzn Date: Tue, 28 Oct 2014 12:58:59 +0000 (+0000) Subject: Bug #480: implement regions dump to Python. X-Git-Tag: BR_hydro_v_1_0_4~7 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=78fa91f995f3518a77ba3fd4608ecf8b772de9a4;p=modules%2Fhydro.git Bug #480: implement regions dump to Python. --- diff --git a/src/HYDROData/HYDROData_CalculationCase.cxx b/src/HYDROData/HYDROData_CalculationCase.cxx index 5e0ce79e..3c139f17 100644 --- a/src/HYDROData/HYDROData_CalculationCase.cxx +++ b/src/HYDROData/HYDROData_CalculationCase.cxx @@ -180,19 +180,9 @@ QStringList HYDROData_CalculationCase::DumpToPython( MapOfTreatedObjects& theTre if ( aRegion.IsNull() ) continue; - QString aRegionName = aRegion->GetName(); - - HYDROData_SequenceOfObjects aZones = aRegion->GetZones(); - HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones ); - for ( ; aZonesIter.More(); aZonesIter.Next() ) - { - Handle(HYDROData_Zone) aRegZone = - Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() ); - if ( aRegZone.IsNull() ) - continue; - - // TODO - } + theTreatedObjects.insert( aRegion->GetName(), aRegion ); + QStringList aRegDump = aRegion->DumpToPython( theTreatedObjects ); + aResList << aRegDump; } } diff --git a/src/HYDROData/HYDROData_Entity.cxx b/src/HYDROData/HYDROData_Entity.cxx index fc5fe6c2..30c2aa94 100644 --- a/src/HYDROData/HYDROData_Entity.cxx +++ b/src/HYDROData/HYDROData_Entity.cxx @@ -620,4 +620,14 @@ void HYDROData_Entity::setPythonObjectColor( QStringList& theScript, .arg( theColor.blue() ).arg( theColor.alpha() ); } - +void HYDROData_Entity::findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, + QStringList& theScript ) const +{ + Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab ); + if ( aDocument.IsNull() ) + return; + + theScript << QString( "%1 = %2.FindObjectByName( \"%3\" );" ).arg( GetObjPyName() ) + .arg( aDocument->GetDocPyName() ) + .arg( GetName() ); +} diff --git a/src/HYDROData/HYDROData_Entity.h b/src/HYDROData/HYDROData_Entity.h index d639c4a7..dcc6912b 100644 --- a/src/HYDROData/HYDROData_Entity.h +++ b/src/HYDROData/HYDROData_Entity.h @@ -213,7 +213,14 @@ public: */ HYDRODATA_EXPORT virtual void RemoveZLevel(); - + /** + Find the Python object in the document by the object name. + @param theTreatedObjects the map of treated objects + @param theScript the script + */ + void findPythonReferenceObject( MapOfTreatedObjects& theTreatedObjects, + QStringList& theScript ) const; + protected: friend class HYDROData_Iterator; @@ -355,8 +362,7 @@ protected: * \param theDefColor default color to return if attribute has not been set before */ QColor GetColor( const QColor& theDefColor, const int theTag = 0 ) const; - - + protected: /** diff --git a/src/HYDROData/HYDROData_Region.cxx b/src/HYDROData/HYDROData_Region.cxx index aad021e7..aca81aeb 100644 --- a/src/HYDROData/HYDROData_Region.cxx +++ b/src/HYDROData/HYDROData_Region.cxx @@ -371,3 +371,52 @@ TopoDS_Shape HYDROData_Region::GetShape( HYDROData_ShapesGroup::SeqOfGroupsDefs* return aResShape; } + +QStringList HYDROData_Region::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const +{ + QStringList aResList; + + // Find region + findPythonReferenceObject( theTreatedObjects, aResList ); + + // Add zones + HYDROData_SequenceOfObjects aZones = GetZones(); + HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones ); + for ( ; aZonesIter.More(); aZonesIter.Next() ) { + Handle(HYDROData_Zone) aZone = + Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() ); + if ( aZone.IsNull() ) { + continue; + } + + // find zone + aZone->findPythonReferenceObject( theTreatedObjects, aResList ); + theTreatedObjects.insert( aZone->GetName(), aZone ); + // add zone + setPythonReferenceObject( theTreatedObjects, aResList, aZone, "AddZone" ); + // set zone merge type + QString aMergeTypeStr; + HYDROData_Zone::MergeAltitudesType aMergeType = aZone->GetMergeType(); + if ( aMergeType == HYDROData_Zone::Merge_ZMIN ) { + aMergeTypeStr = "HYDROData_Zone.Merge_ZMIN"; + } else if ( aMergeType == HYDROData_Zone::Merge_ZMAX ) { + aMergeTypeStr = "HYDROData_Zone.Merge_ZMAX"; + } else if ( aMergeType == HYDROData_Zone::Merge_Object ) { + aMergeTypeStr = "HYDROData_Zone.Merge_Object"; + } + + if ( !aMergeTypeStr.isEmpty() ) { + aResList << QString( "%1.SetMergeType( %2 )" ).arg( aZone->GetObjPyName() ).arg( aMergeTypeStr ); + } + if ( aMergeType == HYDROData_Zone::Merge_Object ) { + Handle(HYDROData_IAltitudeObject) aMergeAltitude = aZone->GetMergeAltitude(); + if ( !aMergeAltitude.IsNull() ) { + aMergeAltitude->findPythonReferenceObject( theTreatedObjects, aResList ); + aResList << QString( "%1.SetMergeAltitude( %2 )" ).arg( aZone->GetObjPyName() ) + .arg( aMergeAltitude->GetObjPyName() ); + } + } + } + + return aResList; +} \ No newline at end of file diff --git a/src/HYDROData/HYDROData_Region.h b/src/HYDROData/HYDROData_Region.h index a0714da1..45fd385c 100644 --- a/src/HYDROData/HYDROData_Region.h +++ b/src/HYDROData/HYDROData_Region.h @@ -39,6 +39,10 @@ public: */ HYDRODATA_EXPORT virtual const ObjectKind GetKind() const { return KIND_REGION; } + /** + * Dump object to Python script representation. + */ + HYDRODATA_EXPORT virtual QStringList DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const; /** * Returns flag indicating that object is updateble or not.