]> SALOME platform Git repositories - modules/hydro.git/commitdiff
Salome HOME
Calculation case services implementation (Feature #11).
authoradv <adv@opencascade.com>
Wed, 11 Dec 2013 15:22:29 +0000 (15:22 +0000)
committeradv <adv@opencascade.com>
Wed, 11 Dec 2013 15:22:29 +0000 (15:22 +0000)
src/HYDROData/HYDROData_CalculationCase.cxx
src/HYDROData/HYDROData_CalculationCase.h

index 9d6b58f460957305786c6056ca4d85439d3c886c..5d910ddca6701e293900deee7e314af596ca6afa 100644 (file)
@@ -2,6 +2,7 @@
 #include "HYDROData_CalculationCase.h"
 
 #include "HYDROData_ArtificialObject.h"
+#include "HYDROData_Bathymetry.h"
 #include "HYDROData_Document.h"
 #include "HYDROData_Iterator.h"
 #include "HYDROData_NaturalObject.h"
@@ -518,4 +519,124 @@ TopoDS_Shell HYDROData_CalculationCase::GetShell()
   return aShell;
 }
 
+double HYDROData_CalculationCase::GetAltitudeForPoint( const gp_XY& thePoint ) const
+{
+  double aResAltitude = HYDROData_Bathymetry::GetInvalidAltitude();
+
+  Handle(HYDROData_Zone) aZone = GetZoneFromPoint( thePoint );
+  if ( aZone.IsNull() )
+    return aResAltitude;
+
+  HYDROData_Zone::MergeBathymetriesType aZoneMergeType = aZone->GetMergeType();
+  if ( !aZone->IsMergingNeed() )
+  {
+    aZoneMergeType = HYDROData_Zone::Merge_UNKNOWN;
+  }
+  else if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
+  {
+    return aResAltitude;
+  }
+
+  if ( aZoneMergeType == HYDROData_Zone::Merge_Object )
+  {
+    Handle(HYDROData_Bathymetry) aMergeBathymetry = aZone->GetMergeBathymetry();
+    if ( !aMergeBathymetry.IsNull() )
+      aResAltitude = aMergeBathymetry->GetAltitudeForPoint( thePoint );
+  }
+  else
+  {
+    HYDROData_SequenceOfObjects aZoneObjects = aZone->GetGeometryObjects();
+    HYDROData_SequenceOfObjects::Iterator anIter( aZoneObjects );
+    for ( ; anIter.More(); anIter.Next() )
+    {
+      Handle(HYDROData_Object) aZoneObj =
+        Handle(HYDROData_Object)::DownCast( anIter.Value() );
+      if ( aZoneObj.IsNull() )
+        continue;
+
+      Handle(HYDROData_Bathymetry) anObjBathymetry = aZoneObj->GetBathymetry();
+      if ( anObjBathymetry.IsNull() )
+        continue;
+
+      double aPointAltitude = anObjBathymetry->GetAltitudeForPoint( thePoint );
+      if ( ValuesEquals( aPointAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) )
+        continue;
+
+      if ( aZoneMergeType == HYDROData_Zone::Merge_UNKNOWN )
+      {
+        aResAltitude = aPointAltitude;
+        break;
+      }
+      else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMIN )
+      {
+        if ( ValuesEquals( aResAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ||
+             aResAltitude > aPointAltitude )
+        {
+          aResAltitude = aPointAltitude;
+        }
+      }
+      else if ( aZoneMergeType == HYDROData_Zone::Merge_ZMAX )
+      {
+        if ( ValuesEquals( aResAltitude, HYDROData_Bathymetry::GetInvalidAltitude() ) ||
+             aResAltitude < aPointAltitude )
+        {
+          aResAltitude = aPointAltitude;
+        }
+      }
+    }
+  }
+
+  return aResAltitude;
+}
+
+Handle(HYDROData_Zone) HYDROData_CalculationCase::GetZoneFromPoint( const gp_XY& thePoint ) const
+{
+  Handle(HYDROData_Zone) aResZone;
 
+  HYDROData_SequenceOfObjects aRegions = GetRegions();
+
+  HYDROData_SequenceOfObjects::Iterator anIter( aRegions );
+  for ( ; anIter.More() && aResZone.IsNull(); anIter.Next() )
+  {
+    Handle(HYDROData_Region) aRegion =
+      Handle(HYDROData_Region)::DownCast( anIter.Value() );
+    if ( aRegion.IsNull() )
+      continue;
+
+    HYDROData_SequenceOfObjects aZones = aRegion->GetZones();
+    HYDROData_SequenceOfObjects::Iterator aZonesIter( aZones );
+    for ( ; aZonesIter.More() && aResZone.IsNull(); aZonesIter.Next() )
+    {
+      Handle(HYDROData_Zone) aRegZone =
+        Handle(HYDROData_Zone)::DownCast( aZonesIter.Value() );
+      if ( aRegZone.IsNull() )
+        continue;
+
+      PointClassification aPointRelation = GetPointClassification( thePoint, aRegZone );
+      if ( aPointRelation != POINT_OUT )
+        aResZone = aRegZone; // We found the desired zone
+    }
+  }
+
+  return aResZone;
+}
+
+HYDROData_CalculationCase::PointClassification HYDROData_CalculationCase::GetPointClassification(
+  const gp_XY&                  thePoint,
+  const Handle(HYDROData_Zone)& theZone ) const
+{
+  PointClassification aRes = POINT_OUT;
+  if ( theZone.IsNull() )
+    return aRes;
+
+  TopoDS_Face aZoneFace = TopoDS::Face( theZone->GetShape() );
+  if ( aZoneFace.IsNull() )
+    return aRes;
+
+  // TODO: classify the point position relative to zone
+  // POINT_OUT - point is out of zone face
+  // POINT_IN  - point is inside of zone face
+  // POINT_ON  - point is on the edge of zone face
+
+  return aRes;
+}
index f6787a2790e790d0c8d0f21e43b2c08427c36bd6..b4a8261db2045b8b8c7c88b89fb14af15dfd4f30 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <HYDROData_Entity.h>
 
+class gp_XY;
+
 class TopoDS_Shell;
 
 class Handle(HYDROData_Object);
@@ -21,6 +23,14 @@ DEFINE_STANDARD_HANDLE(HYDROData_CalculationCase, HYDROData_Entity)
  */
 class HYDROData_CalculationCase : public HYDROData_Entity
 {
+public:
+
+  enum PointClassification
+  {
+    POINT_OUT,
+    POINT_IN,
+    POINT_ON
+  };
 
 protected:
 
@@ -148,6 +158,34 @@ public:
    */
   HYDRODATA_EXPORT virtual TopoDS_Shell GetShell();
 
+
+public:      
+  // Public methods to work with Calculation services
+
+  /**
+   * Returns altitude for given point.
+   * \param thePoint the point to examine
+   * \return result altitude value
+   */
+  HYDRODATA_EXPORT virtual double GetAltitudeForPoint( const gp_XY& thePoint ) const;
+
+  /**
+   * Returns zone to which the point is belongs.
+   * \param thePoint the point to examine
+   * \return result zone
+   */
+  HYDRODATA_EXPORT virtual Handle(HYDROData_Zone) GetZoneFromPoint( const gp_XY& thePoint ) const;
+
+  /**
+   * Returns classification of point for given zone.
+   * \param thePoint the point to examine
+   * \param theZone the zone to examine
+   * \return result classification
+   */
+  HYDRODATA_EXPORT virtual PointClassification GetPointClassification(
+    const gp_XY&                  thePoint,
+    const Handle(HYDROData_Zone)& theZone ) const;
+
 private:
 
   /**