]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Bug #480: implement regions dump to Python.
authormzn <mzn@opencascade.com>
Tue, 28 Oct 2014 12:58:59 +0000 (12:58 +0000)
committermzn <mzn@opencascade.com>
Tue, 28 Oct 2014 12:58:59 +0000 (12:58 +0000)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_Entity.cxx
src/HYDROData/HYDROData_Entity.h
src/HYDROData/HYDROData_Region.cxx
src/HYDROData/HYDROData_Region.h

index 5e0ce79ec10159a36f052a1b24c417a36676baee..3c139f1793e39f57b225b6dd5c16b64cdd99245e 100644 (file)
@@ -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;
     }
   }
 
index fc5fe6c2d82493c5dc07de427a120fdc2e67090f..30c2aa948705b81736dcf7e8183868795fbe6e36 100644 (file)
@@ -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() );
+}
index d639c4a7c976cf18704e605e112e34fb6a4a69b0..dcc6912b96d7717a7f5d05a4feaad9eab5c93c72 100644 (file)
@@ -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:
 
   /**
index aad021e74f81fa9feae5bd5af3aff69549abb288..aca81aeb2bdb2f868ba126a69d391e01015bb63a 100644 (file)
@@ -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
index a0714da1dfaf92183225c89c5a2175339575e672..45fd385c0847f5e58108c2c7b30f49a1f968e4eb 100644 (file)
@@ -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.