Salome HOME
Temporary workaround for python.
[modules/hydro.git] / src / HYDROData / HYDROData_Stream.cxx
index 93640008ad700a057b8bf0efa676829a29c66818..fbe9212b3b94d89cb156c23d547c3acd52d87759 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>
 
@@ -67,8 +68,6 @@
 #include <TCollection_AsciiString.hxx>
 #endif
 
-#define PYTHON_STREAM_ID "KIND_STREAM"
-
 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
 
 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
@@ -86,22 +85,14 @@ HYDROData_Stream::~HYDROData_Stream()
 
 QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
 {
-  QStringList aResList;
-
-  Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
-  if ( aDocument.IsNull() )
-    return aResList;
+  QStringList aResList = dumpObjectCreation( theTreatedObjects );
+  QString aName = GetObjPyName();
 
-  QString aDocName = aDocument->GetDocPyName();
-  QString aStreamName = GetName();
+  // TODO
 
-  aResList << QString( "%1 = %2.CreateObject( %3 );" )
-              .arg( aStreamName ).arg( aDocName ).arg( PYTHON_STREAM_ID );
-  aResList << QString( "%1.SetName( \"%2\" );" )
-              .arg( aStreamName ).arg( aStreamName );
   aResList << QString( "" );
-
-  // TODO
+  aResList << QString( "%1.Update();" ).arg( aName );
+  aResList << QString( "" );
 
   return aResList;
 }
@@ -142,6 +133,12 @@ Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
 }
 
 void HYDROData_Stream::Update()
+{
+  updateProfilesOrder();
+  UpdatePrs();
+}
+
+void HYDROData_Stream::UpdatePrs()
 {
   HYDROData_NaturalObject::Update();
 
@@ -260,15 +257,31 @@ void HYDROData_Stream::Update()
   if(aMakeEdge3.IsDone()) 
     aTopEdge = aMakeEdge3.Edge();
 
-  BRepBuilderAPI_MakeWire aMakeWire( aBotEdge, anEdgLeft, aTopEdge,anEdgRight);
+  // Make wire for 2D presentation with updating of corresponding edges
+  BRepBuilderAPI_MakeWire aMakeWire;
+  
+  aMakeWire.Add( aBotEdge );
+  aBotEdge = aMakeWire.Edge();
+
+  aMakeWire.Add( anEdgLeft );
+  anEdgLeft = aMakeWire.Edge();
+
+  aMakeWire.Add( aTopEdge );
+  aTopEdge = aMakeWire.Edge();
+
+  aMakeWire.Add( anEdgRight );
+  anEdgRight = aMakeWire.Edge();
+
   TopoDS_Wire aSectProfileWire;
   if(aMakeWire.IsDone())
     aSectProfileWire = aMakeWire.Wire();
+
   BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
   TopoDS_Face aFace;
   aMakeFace.Build();
   if( aMakeFace.IsDone() )
     aFace = aMakeFace.Face();
+
   aCmp.Nullify();
   aBB.MakeCompound(aCmp);
   aBB.Add(aCmp,aFace);
@@ -285,7 +298,37 @@ void HYDROData_Stream::Update()
 #endif 
 
   // Create the stream groups
-  createGroupObjects();
+  QString aLeftGroupName = GetName() + "_Left_Bank";
+
+  Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
+  aLeftGroup->SetName( aLeftGroupName );
+  aLeftGroup->AddShape( anEdgLeft );
+
+  QString aRightGroupName = GetName() + "_Right_Bank";
+
+  Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
+  aRightGroup->SetName( aRightGroupName );
+  aRightGroup->AddShape( anEdgRight );
+
+  QString anInGroupName = GetName() + "_Inlet";
+
+  Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
+  anInGroup->SetName( anInGroupName );
+  anInGroup->AddShape( aBotEdge );
+
+  QString anOutGroupName = GetName() + "_Outlet";
+
+  Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
+  anOutGroup->SetName( anOutGroupName );
+  anOutGroup->AddShape( aTopEdge );
+
+  // 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 +341,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 +412,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 +456,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 +661,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);   
@@ -663,112 +760,9 @@ void HYDROData_Stream::updateProfilesOrder()
 #endif
 }
 
-void HYDROData_Stream::createGroupObjects()
+ObjectKind HYDROData_Stream::getAltitudeObjectType() const
 {
-  TopoDS_Shape aStreamShape = GetTopShape();
-  if ( aStreamShape.IsNull() )
-    return;
-
-  HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
-  if ( aRefProfiles.Length() < 2 )
-    return;
-
-  Handle(HYDROData_Profile) aFirstProfile =
-    Handle(HYDROData_Profile)::DownCast( aRefProfiles.First() );
-  Handle(HYDROData_Profile) aLastProfile =
-    Handle(HYDROData_Profile)::DownCast( aRefProfiles.Last() );
-  if ( aFirstProfile.IsNull() || aLastProfile.IsNull() )
-    return;
-
-  TopoDS_Shape aBotEdgeShape = aFirstProfile->GetTopShape();
-  TopoDS_Shape aTopEdgeShape = aLastProfile->GetTopShape();
-  if ( aBotEdgeShape.IsNull() || aBotEdgeShape.ShapeType() != TopAbs_WIRE ||
-       aTopEdgeShape.IsNull() || aTopEdgeShape.ShapeType() != TopAbs_WIRE )
-    return;
-
-  TopExp_Explorer aBotEdgeShapeExp( aBotEdgeShape, TopAbs_EDGE );
-  TopExp_Explorer aTopEdgeShapeExp( aTopEdgeShape, TopAbs_EDGE );
-  if ( !aBotEdgeShapeExp.More() || !aTopEdgeShapeExp.More() )
-    return;
-
-  TopoDS_Edge aBotEdge = TopoDS::Edge( aBotEdgeShapeExp.Current() );
-  TopoDS_Edge aTopEdge = TopoDS::Edge( aTopEdgeShapeExp.Current() );
-
-  TopoDS_Vertex aBotFirstVert, aBotLastVert, aTopFirstVert, aTopLastVert;
-  TopExp::Vertices( aBotEdge, aBotFirstVert, aBotLastVert, true );
-  TopExp::Vertices( aTopEdge, aTopFirstVert, aTopLastVert, true );
-
-  TopExp_Explorer aStreamFaceExp( aStreamShape, TopAbs_FACE );
-  if ( !aStreamFaceExp.More() )
-    return;
-
-  // Get only face because of 2d profile wires is in compound
-  TopoDS_Face aStreamFace = TopoDS::Face( aStreamFaceExp.Current() );
-  
-  TopTools_SequenceOfShape aStreamWires;
-  HYDROData_ShapesTool::ExploreShapeToShapes( aStreamFace, TopAbs_EDGE, aStreamWires );
-
-  bool anIsLeft = false;
-  bool anIsRight = false;
-
-  TopTools_SequenceOfShape aLeftEdges, aRightEdges;
-  for ( int i = 1, n = aStreamWires.Length(); i <= n; ++i )
-  {
-    TopoDS_Edge anEdge = TopoDS::Edge( aStreamWires.Value( i ) );
-    if ( HYDROData_ShapesTool::IsEdgesEquals( anEdge, aBotEdge ) || 
-         HYDROData_ShapesTool::IsEdgesEquals( anEdge, aTopEdge ) )
-    {
-      anIsLeft = false;
-      anIsRight = false;
-      continue;
-    }
-
-    if ( !anIsLeft && !anIsRight )
-    {
-      TopoDS_Vertex anEdgeFirstVert, anEdgeLastVert;
-      TopExp::Vertices( anEdge, anEdgeFirstVert, anEdgeLastVert, true );
-
-      anIsLeft = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aBotFirstVert ) ||
-                 HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aTopFirstVert );
-      
-      anIsRight = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aTopLastVert ) ||
-                  HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aBotLastVert );
-    }
-
-    if ( anIsLeft )
-    {
-      aLeftEdges.Append( anEdge );
-    }
-    else if ( anIsRight )
-    {
-      aRightEdges.Append( anEdge );
-    }
-  }
-
-  // Create edges groups
-  QString aLeftGroupName = GetName() + "_Left_Bank";
-
-  Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
-  aLeftGroup->SetName( aLeftGroupName );
-  aLeftGroup->SetShapes( aLeftEdges );
-
-  QString aRightGroupName = GetName() + "_Right_Bank";
-
-  Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
-  aRightGroup->SetName( aRightGroupName );
-  aRightGroup->SetShapes( aRightEdges );
-
-  QString anInGroupName = GetName() + "_Inlet";
-
-  Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
-  anInGroup->SetName( anInGroupName );
-  anInGroup->AddShape( aBotEdge );
-
-  QString anOutGroupName = GetName() + "_Outlet";
-
-  Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
-  anOutGroup->SetName( anOutGroupName );
-  anOutGroup->AddShape( aTopEdge );
+  return KIND_STREAM_ALTITUDE;
 }
 
 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )