Salome HOME
Bathymetry points has been changed from QList to NCollection_Sequence.
[modules/hydro.git] / src / HYDROData / HYDROData_CalculationCase.cxx
index 04163f3a4e7eaf06242cb7d4ecaefc646b2ef442..198222ab62a76428d734c9c6163ba39374c9eb0f 100644 (file)
@@ -2,7 +2,7 @@
 #include "HYDROData_CalculationCase.h"
 
 #include "HYDROData_ArtificialObject.h"
-#include "HYDROData_Bathymetry.h"
+#include "HYDROData_IAltitudeObject.h"
 #include "HYDROData_Document.h"
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_Iterator.h"
@@ -70,12 +70,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName )
       if ( aRegion.IsNull() )
         continue;
 
-      QString aRegionName = aRegion->GetName();
-      if ( aRegionName.startsWith( anOldCaseName ) )
-      {
-        aRegionName.replace( anOldCaseName, theName );
-        aRegion->SetName( aRegionName );
-      }
+      HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegion );
 
       HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
       HYDROData_SequenceOfObjects::Iterator anIter( aZones );
@@ -86,12 +81,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName )
         if ( aRegZone.IsNull() )
           continue;
 
-        QString aRegionZoneName = aRegZone->GetName();
-        if ( aRegionZoneName.startsWith( anOldCaseName ) )
-        {
-          aRegionZoneName.replace( anOldCaseName, theName );
-          aRegZone->SetName( aRegionZoneName );
-        }
+        HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aRegZone );
       }
     }
 
@@ -105,12 +95,7 @@ void HYDROData_CalculationCase::SetName( const QString& theName )
       if ( aGroup.IsNull() )
         continue;
 
-      QString aGroupName = aGroup->GetName();
-      if ( aGroupName.startsWith( anOldCaseName ) )
-      {
-        aGroupName.replace( anOldCaseName, theName );
-        aGroup->SetName( aGroupName );
-      }
+      HYDROData_Tool::UpdateChildObjectName( anOldCaseName, theName, aGroup );
     }
   }
 
@@ -501,13 +486,13 @@ void HYDROData_CalculationCase::RemoveSplittedGroups()
 
 double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
 {
-  double aResAltitude = HYDROData_Bathymetry::GetInvalidAltitude();
+  double aResAltitude = HYDROData_IAltitudeObject::GetInvalidAltitude();
 
   Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
   if ( aZone.IsNull() )
     return aResAltitude;
 
-  HYDROData_Zone::MergeBathymetriesType aZoneMergeType = aZone->GetMergeType();
+  HYDROData_Zone::MergeAltitudesType aZoneMergeType = aZone->GetMergeType();
   if ( !aZone->IsMergingNeed() )
   {
     aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
@@ -519,9 +504,9 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) c
 
   if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
   {
-    Handle(HYDROData_Bathymetry) aMergeBathymetry = aZone->GetMergeBathymetry();
-    if ( !aMergeBathymetry.IsNull() )
-      aResAltitude = aMergeBathymetry->GetAltitudeForPoint( thePoint );
+    Handle(HYDROData_IAltitudeObject) aMergeAltitude = aZone->GetMergeAltitude();
+    if ( !aMergeAltitude.IsNull() )
+      aResAltitude = aMergeAltitude->GetAltitudeForPoint( thePoint );
   }
   else
   {
@@ -534,12 +519,12 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) c
       if ( aZoneObj.IsNull() )
         continue;
 
-      Handle(HYDROData_Bathymetry) anObjBathymetry = aZoneObj->GetBathymetry();
-      if ( anObjBathymetry.IsNull() )
+      Handle(HYDROData_IAltitudeObject) anObjAltitude = aZoneObj->GetAltitudeObject();
+      if ( anObjAltitude.IsNull() )
         continue;
 
-      double aPointAltitude = anObjBathymetry->GetAltitudeForPoint( thePoint );
-      if ( ValuesEquals( aPointAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) )
+      double aPointAltitude = anObjAltitude->GetAltitudeForPoint( thePoint );
+      if ( ValuesEquals( aPointAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) )
         continue;
 
       if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
@@ -549,7 +534,7 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) c
       }
       else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
       {
-        if ( ValuesEquals( aResAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ||
+        if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
              aResAltitude > aPointAltitude )
         {
           aResAltitude = aPointAltitude;
@@ -557,7 +542,7 @@ double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) c
       }
       else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
       {
-        if ( ValuesEquals( aResAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ||
+        if ( ValuesEquals( aResAltitude, HYDROData_IAltitudeObject::GetInvalidAltitude() ) ||
              aResAltitude < aPointAltitude )
         {
           aResAltitude = aPointAltitude;
@@ -651,7 +636,6 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
                                         SALOMEDS::Study_ptr theStudy )
 {
   // Get faces
-  // TODO to be revised
   TopTools_ListOfShape aFaces;
   HYDROData_SequenceOfObjects aCaseRegions = GetRegions();
   HYDROData_SequenceOfObjects::Iterator aRegionIter( aCaseRegions );
@@ -667,7 +651,6 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
   }
 
   // Get groups
-  // TODO to be revised
   HYDROData_SequenceOfObjects aSplittedGroups = GetSplittedGroups();
 
   return Export( theGeomEngine, theStudy, aFaces, aSplittedGroups );
@@ -722,7 +705,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
   TopTools_IndexedMapOfShape aMapOfSubShapes;
   TopExp::MapShapes( aSewedShape, aMapOfSubShapes );
 
-  QHash<QString, QSet<int>> aGroupsData;
+  QHash<QString, QSet<int> > aGroupsData;
 
   HYDROData_SequenceOfObjects::Iterator anIter( theSplittedGroups );
   for ( ; anIter.More(); anIter.Next() ) {
@@ -737,7 +720,7 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
 
     // Get shapes of the group
     TopTools_SequenceOfShape aShapes;
-    aGroup->GeShapes( aShapes );
+    aGroup->GetShapes( aShapes );
     for( int i = 1, aNbShapes = aShapes.Length(); i <= aNbShapes; i++ ) {
       const TopoDS_Shape& aShape = aShapes.Value( i );
       const TopoDS_Shape ModifiedShape = aSewing.Modified( aShape );
@@ -754,24 +737,27 @@ bool HYDROData_CalculationCase::Export( GEOM::GEOM_Gen_var theGeomEngine,
     }
   }
   
-  GEOM::GEOM_IGroupOperations_var aGroupOp = 
-    theGeomEngine->GetIGroupOperations( theStudy->StudyId() );  
-
-  foreach ( const QString& aGroupName, aGroupsData.keys() ) {
-    QSet<int> aGroupIndexes = aGroupsData.value( aGroupName );
-
-    GEOM::GEOM_Object_var aGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
-    if ( !CORBA::is_nil(aGroup) && aGroupOp->IsDone() ) {
-      GEOM::ListOfLong_var anIndexes = new GEOM::ListOfLong;
-      int aListIndex = 0;
-      foreach ( const int anIndex, aGroupIndexes ) {
-        anIndexes[aListIndex++] = anIndex;
-      }
+  if ( !aGroupsData.isEmpty() ) {
+    GEOM::GEOM_IGroupOperations_var aGroupOp = 
+      theGeomEngine->GetIGroupOperations( theStudy->StudyId() );  
+
+    foreach ( const QString& aGroupName, aGroupsData.keys() ) {
+      QSet<int> aGroupIndexes = aGroupsData.value( aGroupName );
+
+      GEOM::GEOM_Object_var aGroup = aGroupOp->CreateGroup( aMainShape, TopAbs_EDGE );
+      if ( !CORBA::is_nil(aGroup) && aGroupOp->IsDone() ) {
+        GEOM::ListOfLong_var anIndexes = new GEOM::ListOfLong;
+        anIndexes->length( aGroupIndexes.count() );
+        int aListIndex = 0;
+        foreach ( const int anIndex, aGroupIndexes ) {
+          anIndexes[aListIndex++] = anIndex;
+        }
 
-      aGroupOp->UnionIDs( aGroup, anIndexes );
-      if ( aGroupOp->IsDone() ) {
-        SALOMEDS::SObject_var aGroupSO = 
-          theGeomEngine->AddInStudy( theStudy, aGroup, qPrintable( aName ), aMainShape );
+        aGroupOp->UnionIDs( aGroup, anIndexes );
+        if ( aGroupOp->IsDone() ) {
+          SALOMEDS::SObject_var aGroupSO = 
+            theGeomEngine->AddInStudy( theStudy, aGroup, qPrintable( aGroupName ), aMainShape );
+        }
       }
     }
   }
@@ -785,8 +771,6 @@ GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
 {
   GEOM::GEOM_Object_var aGeomObj;
 
-  bool isNil = aGeomObj->_is_nil(); ///@MZN
-
   if ( theGeomEngine->_is_nil() || theStudy->_is_nil() ||
        theShape.IsNull() ) {
     return aGeomObj._retn();
@@ -814,11 +798,11 @@ GEOM::GEOM_Object_ptr HYDROData_CalculationCase::publishShapeInGEOM(
 
     SALOMEDS::SObject_var aResultSO = 
       theGeomEngine->PublishInStudy( theStudy, SALOMEDS::SObject::_nil(), 
-                                     aGeomObj, qPrintable( theName ) );
+                                     aGeomObj, qPrintable( aName ) );
     if ( aResultSO->_is_nil() ) {
       aGeomObj = GEOM::GEOM_Object::_nil();
     }
   }
 
   return aGeomObj._retn();
- }
\ No newline at end of file
+ }