Salome HOME
Refs #279 - Copy for the view position coordinates
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
index 93640008ad700a057b8bf0efa676829a29c66818..9aa3d2354deeac809724251d2732cfea92240dea 100644 (file)
@@ -6,6 +6,7 @@
 #include "HYDROData_Profile.h"
 #include "HYDROData_ShapesGroup.h"
 #include "HYDROData_ShapesTool.h"
+#include "HYDROData_IAltitudeObject.h"
 
 #include <TDataStd_RealArray.hxx>
 
@@ -142,6 +143,12 @@ Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
 }
 
 void HYDROData_Stream::Update()
+{
+  updateProfilesOrder();
+  UpdatePrs();
+}
+
+void HYDROData_Stream::UpdatePrs()
 {
   HYDROData_NaturalObject::Update();
 
@@ -286,6 +293,14 @@ void HYDROData_Stream::Update()
 
   // Create the stream groups
   createGroupObjects();
+
+  // This peace of code is for testing of functionality of altitude,
+  // will be removed by adv when testing will be finished
+  Handle(HYDROData_IAltitudeObject) anAltObj = GetAltitudeObject();
+  gp_XY aTestPnt( 5, 0 );
+  anAltObj->GetAltitudeForPoint( aTestPnt );
+  // End of test code
+
 }
 
 QColor HYDROData_Stream::DefaultFillingColor()
@@ -298,6 +313,65 @@ QColor HYDROData_Stream::DefaultBorderColor()
   return QColor( Qt::transparent );
 }
 
+bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
+{
+  if ( theHydAxis.IsNull() )
+    return false;
+
+  TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
+  if ( aHydraulicShape.IsNull() || 
+       aHydraulicShape.ShapeType() != TopAbs_WIRE ||
+       BRep_Tool::IsClosed( aHydraulicShape ) )
+    return false; // The polyline must be a single not closed wire
+
+  return true;
+}
+
+TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
+                                const int                          theGroupId )
+{
+  TopoDS_Shape aResShape;
+  if ( theGroups.Length() != 4 )
+    return aResShape;
+
+  Handle(HYDROData_ShapesGroup) aGroup =
+    Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
+  if ( aGroup.IsNull() )
+    return aResShape;
+
+  TopTools_SequenceOfShape aGroupShapes;
+  aGroup->GetShapes( aGroupShapes );
+
+  if ( !aGroupShapes.IsEmpty() )
+    aResShape = aGroupShapes.First();
+
+  return aResShape;
+}
+
+TopoDS_Shape HYDROData_Stream::GetLeftShape() const
+{
+  HYDROData_SequenceOfObjects aGroups = GetGroups();
+  return getShapeFromGroup( aGroups, 1 );
+}
+
+TopoDS_Shape HYDROData_Stream::GetRightShape() const
+{
+  HYDROData_SequenceOfObjects aGroups = GetGroups();
+  return getShapeFromGroup( aGroups, 2 );
+}
+
+TopoDS_Shape HYDROData_Stream::GetInletShape() const
+{
+  HYDROData_SequenceOfObjects aGroups = GetGroups();
+  return getShapeFromGroup( aGroups, 3 );
+}
+
+TopoDS_Shape HYDROData_Stream::GetOutletShape() const
+{
+  HYDROData_SequenceOfObjects aGroups = GetGroups();
+  return getShapeFromGroup( aGroups, 4 );
+}
+
 QColor HYDROData_Stream::getDefaultFillingColor() const
 {
   return DefaultFillingColor();
@@ -310,20 +384,12 @@ QColor HYDROData_Stream::getDefaultBorderColor() const
 
 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
 {
-  Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
-
-  if ( theAxis.IsNull() )
-  {
-    RemoveHydraulicAxis();
-    return !aPrevAxis.IsNull();
-  }
-
-  if ( IsEqual( aPrevAxis, theAxis ) )
+  if ( !IsValidAsAxis( theAxis ) )
     return false;
 
-  TopoDS_Wire aHydraulicWire = TopoDS::Wire( theAxis->GetShape() );
-  if ( aHydraulicWire.IsNull() )
-    return false; // The polyline must be a single wire
+  Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
+  if ( IsEqual( aPrevAxis, theAxis ) )
+    return true;
 
   SetReferenceObject( theAxis, DataTag_HydraulicAxis );
 
@@ -362,7 +428,7 @@ bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theH
                                         const TopoDS_Face& thePlane,
                                                               Standard_Real& outPar)
 {
-  if ( theProfile.IsNull() || theHydAxis.IsNull() )
+  if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
     return false; 
 
   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
@@ -567,11 +633,14 @@ void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)&
     InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
 }
 
-bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, TopoDS_Face& thePlane) const
+bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
+                                  TopoDS_Face&                        thePlane ) const
 {
-  if ( theHydAxis.IsNull() ) return false;
+  if ( !IsValidAsAxis( theHydAxis ) )
+    return false;
+
   TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
-  if(aHydraulicWire.IsNull()) return false;
+
   gp_Ax2 aX2(gp::XOY());
   gp_Ax3 aX3(aX2);
   gp_Pln aPln(aX3);   
@@ -771,6 +840,11 @@ void HYDROData_Stream::createGroupObjects()
   anOutGroup->AddShape( aTopEdge );
 }
 
+ObjectKind HYDROData_Stream::getAltitudeObjectType() const
+{
+  return KIND_STREAM_ALTITUDE;
+}
+
 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
 {
   if ( theArray.Length() == 0 )