2 #include "HYDROData_Stream.h"
4 #include "HYDROData_Document.h"
5 #include "HYDROData_PolylineXY.h"
6 #include "HYDROData_Profile.h"
7 #include "HYDROData_ShapesGroup.h"
8 #include "HYDROData_ShapesTool.h"
10 #include <TDataStd_RealArray.hxx>
12 #include <Precision.hxx>
14 #include <NCollection_DataMap.hxx>
16 #include <TColStd_Array1OfReal.hxx>
17 #include <TColStd_ListOfReal.hxx>
18 #include <TColStd_ListIteratorOfListOfReal.hxx>
19 #include <TCollection_CompareOfReal.hxx>
20 #include <TColgp_Array1OfPnt.hxx>
21 #include <TColgp_HArray1OfPnt.hxx>
24 #include <TopoDS_Wire.hxx>
25 #include <TopoDS_Shell.hxx>
26 #include <TopoDS_Face.hxx>
27 #include <TopoDS_Edge.hxx>
28 #include <TopoDS_Vertex.hxx>
30 #include <TopExp_Explorer.hxx>
32 #include <Bnd_Box.hxx>
34 #include <BRep_Builder.hxx>
35 #include <BRepBuilderAPI_MakeEdge.hxx>
36 #include <BRepBuilderAPI_MakeWire.hxx>
37 #include <BRepBuilderAPI_MakeFace.hxx>
39 #include <BRepBndLib.hxx>
40 #include <BRepProj_Projection.hxx>
41 #include <BRepExtrema_ExtCC.hxx>
42 #include <BRepCheck_Analyzer.hxx>
52 #include <GeomAPI_Interpolate.hxx>
53 #include <Geom_BSplineCurve.hxx>
55 #include <TopTools_Array1OfShape.hxx>
57 #include <SortTools_QuickSortOfReal.hxx>
60 #include <QStringList>
62 //#define DEB_STREAM 1
64 //#define DEB_HASINT 1
65 //#define DEB_UPDATE 1
66 #include <BRepTools.hxx>
67 #include <TCollection_AsciiString.hxx>
70 #define PYTHON_STREAM_ID "KIND_STREAM"
72 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
74 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
75 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
78 HYDROData_Stream::HYDROData_Stream()
79 : HYDROData_NaturalObject()
83 HYDROData_Stream::~HYDROData_Stream()
87 QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
91 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
92 if ( aDocument.IsNull() )
95 QString aDocName = aDocument->GetDocPyName();
96 QString aStreamName = GetName();
98 aResList << QString( "%1 = %2.CreateObject( %3 );" )
99 .arg( aStreamName ).arg( aDocName ).arg( PYTHON_STREAM_ID );
100 aResList << QString( "%1.SetName( \"%2\" );" )
101 .arg( aStreamName ).arg( aStreamName );
102 aResList << QString( "" );
109 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
111 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
113 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
114 if ( !aHydAxis.IsNull() )
115 aResSeq.Append( aHydAxis );
117 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
118 aResSeq.Append( aSeqOfProfiles );
123 TopoDS_Shape HYDROData_Stream::GetTopShape() const
125 return getTopShape();
128 TopoDS_Shape HYDROData_Stream::GetShape3D() const
133 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
134 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
136 Handle(Geom_BSplineCurve) aBSpline;
137 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
138 anInterpolator.Perform() ;
139 if (anInterpolator.IsDone())
140 aBSpline = anInterpolator.Curve();
144 void HYDROData_Stream::Update()
146 HYDROData_NaturalObject::Update();
148 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
149 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
150 if ( aHydAxis.IsNull() || aRefProfiles.Length() < 2 )
153 bool anIsFirst = true;
154 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
155 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
156 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
157 TopTools_Array1OfShape anArrOfProfiles(1, aRefProfiles.Length());
158 TopTools_Array1OfShape anArrOf2DProfiles(1, aRefProfiles.Length());
161 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
162 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
164 Handle(HYDROData_Profile) aProfile =
165 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
166 if ( aProfile.IsNull() )
168 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
170 if ( !aProfile->GetLeftPoint( aPnt1 ) || !aProfile->GetRightPoint( aPnt2 ) )
172 anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
173 anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
175 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
176 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
177 TopoDS_Vertex aV1, aV2;
178 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
179 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
180 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
184 aP1 = BRep_Tool::Pnt(aV2);
185 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
189 anArrayOfFPnt->SetValue(i,aCurFP);
190 anArrayOfLPnt->SetValue(i,aCurLP);
193 // Construct of the 3D presentation
194 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
195 if(aBSpline.IsNull())
197 TopoDS_Edge anEdgLeft, anEdgRight;
198 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
199 if(aMakeEdge.IsDone())
200 anEdgLeft = aMakeEdge.Edge();
201 if(anEdgLeft.IsNull())
204 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
205 if(aBSpline.IsNull())
207 aMakeEdge.Init(aBSpline);
208 if(aMakeEdge.IsDone())
209 anEdgRight = aMakeEdge.Edge();
210 if(anEdgRight.IsNull())
213 TopoDS_Compound aCmp;
214 aBB.MakeCompound(aCmp);
215 anIter.Init( aRefProfiles );
216 for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )
217 aBB.Add(aCmp, anArrOfProfiles.Value(i));
218 aBB.Add(aCmp,anEdgLeft);
219 aBB.Add(aCmp,anEdgRight);
220 BRepCheck_Analyzer aCh(aCmp);
225 BRepTools::Write(aCmp, "str3d.brep");
230 // Construct the top presentation
231 for(int i=1;i<= anArrayOfLPnt->Length();i++) {
232 gp_Pnt aPnt = anArrayOfFPnt->Value(i);
233 aPnt.SetZ(.0); // make 2d
234 anArrayOfFPnt->SetValue(i, aPnt);
235 aPnt = anArrayOfLPnt->Value(i);
237 anArrayOfLPnt->SetValue(i, aPnt);
240 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
241 if(aBSpline.IsNull())
243 aMakeEdge.Init(aBSpline);
244 if(aMakeEdge.IsDone())
245 anEdgLeft = aMakeEdge.Edge();
247 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
248 if(aBSpline.IsNull())
250 aMakeEdge.Init(aBSpline);
251 if(aMakeEdge.IsDone())
252 anEdgRight = aMakeEdge.Edge();
253 if(anEdgRight.IsNull())
255 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
256 TopoDS_Edge aBotEdge, aTopEdge;
257 if(aMakeEdge2.IsDone())
258 aBotEdge = aMakeEdge2.Edge();
259 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
260 if(aMakeEdge3.IsDone())
261 aTopEdge = aMakeEdge3.Edge();
263 BRepBuilderAPI_MakeWire aMakeWire( aBotEdge, anEdgLeft, aTopEdge,anEdgRight);
264 TopoDS_Wire aSectProfileWire;
265 if(aMakeWire.IsDone())
266 aSectProfileWire = aMakeWire.Wire();
267 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
270 if( aMakeFace.IsDone() )
271 aFace = aMakeFace.Face();
273 aBB.MakeCompound(aCmp);
275 for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
276 aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
282 BRepTools::Write(aCmp, "str2d.brep");
287 // Create the stream groups
288 createGroupObjects();
291 QColor HYDROData_Stream::DefaultFillingColor()
293 return QColor( Qt::green );
296 QColor HYDROData_Stream::DefaultBorderColor()
298 return QColor( Qt::transparent );
301 QColor HYDROData_Stream::getDefaultFillingColor() const
303 return DefaultFillingColor();
306 QColor HYDROData_Stream::getDefaultBorderColor() const
308 return DefaultBorderColor();
311 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
313 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
315 if ( theAxis.IsNull() )
317 RemoveHydraulicAxis();
318 return !aPrevAxis.IsNull();
321 if ( IsEqual( aPrevAxis, theAxis ) )
324 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theAxis->GetShape() );
325 if ( aHydraulicWire.IsNull() )
326 return false; // The polyline must be a single wire
328 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
330 // Update the order of profiles
331 updateProfilesOrder();
333 // Indicate model of the need to update the stream presentation
339 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
341 return Handle(HYDROData_PolylineXY)::DownCast(
342 GetReferenceObject( DataTag_HydraulicAxis ) );
345 void HYDROData_Stream::RemoveHydraulicAxis()
347 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
348 if ( aPrevAxis.IsNull() )
351 ClearReferenceObjects( DataTag_HydraulicAxis );
353 // We remove the reference profiles
356 // Indicate model of the need to update the stream presentation
360 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
361 const Handle(HYDROData_Profile)& theProfile,
362 const TopoDS_Face& thePlane,
363 Standard_Real& outPar)
365 if ( theProfile.IsNull() || theHydAxis.IsNull() )
368 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
369 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
370 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
373 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
374 if(!aProjector.IsDone())
376 TopoDS_Shape aPrjProfile = aProjector.Shape();
377 if(aPrjProfile.IsNull())
379 TopoDS_Vertex aV1, aV2;
380 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
381 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
382 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
383 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
384 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
385 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
387 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
389 anExp.Init(aPrjProfile, TopAbs_EDGE);
391 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
395 if(aV1.IsNull() || aV2.IsNull())
397 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
398 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
401 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
404 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
405 Standard_Integer aNum(0);
407 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
408 for(;anExplo.More();anExplo.Next()) aNum++;
409 // check for self-intersection
410 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
411 Standard_Boolean hasInt(false);
412 Standard_Real aSqDist(DBL_MAX);
413 Standard_Integer anIndx(0);
414 BRepExtrema_ExtCC aCC;
415 aCC.Initialize(anEdg2);
417 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
418 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
419 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
422 Standard_Boolean hasSol(false);
426 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
427 if(aCC.SquareDistance(i) < aSqDist) {
428 aSqDist = aCC.SquareDistance(i);
434 if(aSqDist <= SquareTolerance) { // hasInt
435 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
437 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
438 outPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
440 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
448 TopExp::Vertices(anEdg1, aV1, aV2);
449 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
452 } else if(aNum > 1) {
453 TopExp::Vertices(anEdg1, aV1, aV2);
454 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
462 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
463 Standard_Real& outPar ) const
465 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
467 return HasIntersection( aHydAxis, theProfile, thePlane, outPar );
471 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
473 if ( theProfile.IsNull() )
476 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
477 if ( aHydAxis.IsNull() )
481 if(!BuildFace(aHydAxis, aPlane))
484 Standard_Real aPar(.0);
485 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
486 return false; // Object is already in reference list or it has no intersection
488 int aProfileIndex = insertParameter( aPar );
489 insertProfileInToOrder( theProfile, aProfileIndex );
491 // Indicate model of the need to update the stream presentation
497 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
499 return GetReferenceObjects( DataTag_Profile );
502 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
504 if ( theProfile.IsNull() )
507 int aProfileIndex = -1;
509 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
510 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
511 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
513 Handle(HYDROData_Profile) aProfile =
514 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
515 if ( aProfile.IsNull() )
518 if ( IsEqual( theProfile, aProfile ) )
525 if ( aProfileIndex == -1 )
528 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
530 // Remove parameter for removed profile
531 removeParameter( aProfileIndex );
533 // Indicate model of the need to update the stream presentation
539 void HYDROData_Stream::RemoveProfiles()
541 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
543 ClearReferenceObjects( DataTag_Profile );
545 // Remove the parameters array
546 removeParametersArray();
548 // Indicate model of the need to update the stream presentation
549 SetToUpdate( anIsToUpdate );
552 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
553 const int theBeforeIndex )
555 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
556 if ( theProfile.IsNull() || aHydAxis.IsNull() )
559 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
560 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
561 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
564 if ( theBeforeIndex == -1 )
565 AddReferenceObject( theProfile, DataTag_Profile );
567 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
570 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis, TopoDS_Face& thePlane) const
572 if ( theHydAxis.IsNull() ) return false;
573 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
574 if(aHydraulicWire.IsNull()) return false;
575 gp_Ax2 aX2(gp::XOY());
579 BRepBndLib::Add(aHydraulicWire,B);
580 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
581 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
582 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
583 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
584 thePlane = TopoDS::Face(aMkr.Shape());
588 void HYDROData_Stream::updateProfilesOrder()
590 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
591 if ( aRefProfiles.IsEmpty() )
594 // At first we remove all profiles from order
597 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
598 if ( aHydAxis.IsNull() )
602 if ( !BuildFace( aHydAxis, aPlane ) )
605 Standard_Real aPar( .0 );
609 TopoDS_Compound aCmp;
610 aBB.MakeCompound(aCmp);
613 HYDROData_DataMapOfRealOfHDProfile aDM;
614 TColStd_ListOfReal aList;
615 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
616 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
618 Handle(HYDROData_Profile) aProfile =
619 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
621 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
622 aBB.Add( aCmp, aProfileWire );
624 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
627 aDM.Bind( aPar, aProfile );
628 aList.Append( aPar );
631 if ( aList.IsEmpty() )
634 TColStd_Array1OfReal anArr( 1, aList.Extent() );
636 TColStd_ListIteratorOfListOfReal it( aList );
637 for ( int j = 1; it.More(); it.Next(), j++ )
638 anArr( j ) = it.Value();
641 if ( aList.Extent() > 1 )
643 TCollection_CompareOfReal Compar;
644 SortTools_QuickSortOfReal::Sort( anArr, Compar );
646 for (int j = 1; j <= anArr.Length(); j++) {
647 const Standard_Real aKey = anArr(j);
648 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
649 insertProfileInToOrder( aProfile );
651 } else if ( aList.Extent() == 1 ) {
652 const Standard_Real aKey = aList.Last();
653 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
654 insertProfileInToOrder( aProfile );
657 setParametersArray( anArr );
660 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
661 BRepTools::Write(aHydraulicWire, "Path.brep");
662 BRepTools::Write(aCmp, "Prof.brep");
666 void HYDROData_Stream::createGroupObjects()
668 TopoDS_Shape aStreamShape = GetTopShape();
669 if ( aStreamShape.IsNull() )
672 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
673 if ( aRefProfiles.Length() < 2 )
676 Handle(HYDROData_Profile) aFirstProfile =
677 Handle(HYDROData_Profile)::DownCast( aRefProfiles.First() );
678 Handle(HYDROData_Profile) aLastProfile =
679 Handle(HYDROData_Profile)::DownCast( aRefProfiles.Last() );
680 if ( aFirstProfile.IsNull() || aLastProfile.IsNull() )
683 TopoDS_Shape aBotEdgeShape = aFirstProfile->GetTopShape();
684 TopoDS_Shape aTopEdgeShape = aLastProfile->GetTopShape();
685 if ( aBotEdgeShape.IsNull() || aBotEdgeShape.ShapeType() != TopAbs_WIRE ||
686 aTopEdgeShape.IsNull() || aTopEdgeShape.ShapeType() != TopAbs_WIRE )
689 TopExp_Explorer aBotEdgeShapeExp( aBotEdgeShape, TopAbs_EDGE );
690 TopExp_Explorer aTopEdgeShapeExp( aTopEdgeShape, TopAbs_EDGE );
691 if ( !aBotEdgeShapeExp.More() || !aTopEdgeShapeExp.More() )
694 TopoDS_Edge aBotEdge = TopoDS::Edge( aBotEdgeShapeExp.Current() );
695 TopoDS_Edge aTopEdge = TopoDS::Edge( aTopEdgeShapeExp.Current() );
697 TopoDS_Vertex aBotFirstVert, aBotLastVert, aTopFirstVert, aTopLastVert;
698 TopExp::Vertices( aBotEdge, aBotFirstVert, aBotLastVert, true );
699 TopExp::Vertices( aTopEdge, aTopFirstVert, aTopLastVert, true );
701 TopExp_Explorer aStreamFaceExp( aStreamShape, TopAbs_FACE );
702 if ( !aStreamFaceExp.More() )
705 // Get only face because of 2d profile wires is in compound
706 TopoDS_Face aStreamFace = TopoDS::Face( aStreamFaceExp.Current() );
708 TopTools_SequenceOfShape aStreamWires;
709 HYDROData_ShapesTool::ExploreShapeToShapes( aStreamFace, TopAbs_EDGE, aStreamWires );
711 bool anIsLeft = false;
712 bool anIsRight = false;
714 TopTools_SequenceOfShape aLeftEdges, aRightEdges;
715 for ( int i = 1, n = aStreamWires.Length(); i <= n; ++i )
717 TopoDS_Edge anEdge = TopoDS::Edge( aStreamWires.Value( i ) );
718 if ( HYDROData_ShapesTool::IsEdgesEquals( anEdge, aBotEdge ) ||
719 HYDROData_ShapesTool::IsEdgesEquals( anEdge, aTopEdge ) )
726 if ( !anIsLeft && !anIsRight )
728 TopoDS_Vertex anEdgeFirstVert, anEdgeLastVert;
729 TopExp::Vertices( anEdge, anEdgeFirstVert, anEdgeLastVert, true );
731 anIsLeft = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aBotFirstVert ) ||
732 HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aTopFirstVert );
734 anIsRight = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aTopLastVert ) ||
735 HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aBotLastVert );
740 aLeftEdges.Append( anEdge );
742 else if ( anIsRight )
744 aRightEdges.Append( anEdge );
748 // Create edges groups
749 QString aLeftGroupName = GetName() + "_Left_Bank";
751 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
752 aLeftGroup->SetName( aLeftGroupName );
753 aLeftGroup->SetShapes( aLeftEdges );
755 QString aRightGroupName = GetName() + "_Right_Bank";
757 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
758 aRightGroup->SetName( aRightGroupName );
759 aRightGroup->SetShapes( aRightEdges );
761 QString anInGroupName = GetName() + "_Inlet";
763 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
764 anInGroup->SetName( anInGroupName );
765 anInGroup->AddShape( aBotEdge );
767 QString anOutGroupName = GetName() + "_Outlet";
769 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
770 anOutGroup->SetName( anOutGroupName );
771 anOutGroup->AddShape( aTopEdge );
774 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
776 return KIND_STREAM_ALTITUDE;
779 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
781 if ( theArray.Length() == 0 )
783 removeParametersArray();
787 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
789 Handle(TDataStd_RealArray) aParamsArray =
790 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
792 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
794 const Standard_Real& aParam = theArray( i );
795 aParamsArray->SetValue( i, aParam );
799 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
801 TColStd_Array1OfReal* anArray = NULL;
803 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
804 if ( !aLabel.IsNull() )
806 Handle(TDataStd_RealArray) aParamsArray;
807 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
809 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
810 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
812 const Standard_Real& aParam = aParamsArray->Value( i );
813 anArray->SetValue( i, aParam );
821 void HYDROData_Stream::removeParametersArray()
823 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
824 if ( !aLabel.IsNull() )
825 aLabel.ForgetAllAttributes();
828 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
832 TColStd_Array1OfReal* anArr = getParametersArray();
837 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
839 bool isInserted = false;
840 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
842 const Standard_Real& aStoredParam = anArr->Value( i );
845 if ( theParam > aStoredParam )
851 aNewArr( j ) = theParam;
857 aNewArr( j ) = aStoredParam;
863 aNewArr( aNewArr.Upper() ) = theParam;
866 setParametersArray( aNewArr );
871 TColStd_Array1OfReal aNewArr( 1, 1 );
872 aNewArr.SetValue( 1, theParam );
873 setParametersArray( aNewArr );
879 void HYDROData_Stream::removeParameter( const int& theIndex )
881 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
882 if ( aLabel.IsNull() )
885 Handle(TDataStd_RealArray) aParamsArray;
886 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
889 if ( aParamsArray->Length() == 1 )
891 removeParametersArray();
895 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
897 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
899 const Standard_Real& aStoredParam = aParamsArray->Value( i );
903 aNewArr.SetValue( j, aStoredParam );
907 setParametersArray( aNewArr );