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 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
303 if ( theHydAxis.IsNull() )
306 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
307 if ( aHydraulicShape.IsNull() ||
308 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
309 BRep_Tool::IsClosed( aHydraulicShape ) )
310 return false; // The polyline must be a single not closed wire
315 QColor HYDROData_Stream::getDefaultFillingColor() const
317 return DefaultFillingColor();
320 QColor HYDROData_Stream::getDefaultBorderColor() const
322 return DefaultBorderColor();
325 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
327 if ( !IsValidAsAxis( theAxis ) )
330 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
331 if ( IsEqual( aPrevAxis, theAxis ) )
334 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
336 // Update the order of profiles
337 updateProfilesOrder();
339 // Indicate model of the need to update the stream presentation
345 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
347 return Handle(HYDROData_PolylineXY)::DownCast(
348 GetReferenceObject( DataTag_HydraulicAxis ) );
351 void HYDROData_Stream::RemoveHydraulicAxis()
353 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
354 if ( aPrevAxis.IsNull() )
357 ClearReferenceObjects( DataTag_HydraulicAxis );
359 // We remove the reference profiles
362 // Indicate model of the need to update the stream presentation
366 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
367 const Handle(HYDROData_Profile)& theProfile,
368 const TopoDS_Face& thePlane,
369 Standard_Real& outPar)
371 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
374 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
375 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
376 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
379 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
380 if(!aProjector.IsDone())
382 TopoDS_Shape aPrjProfile = aProjector.Shape();
383 if(aPrjProfile.IsNull())
385 TopoDS_Vertex aV1, aV2;
386 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
387 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
388 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
389 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
390 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
391 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
393 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
395 anExp.Init(aPrjProfile, TopAbs_EDGE);
397 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
401 if(aV1.IsNull() || aV2.IsNull())
403 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
404 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
407 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
410 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
411 Standard_Integer aNum(0);
413 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
414 for(;anExplo.More();anExplo.Next()) aNum++;
415 // check for self-intersection
416 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
417 Standard_Boolean hasInt(false);
418 Standard_Real aSqDist(DBL_MAX);
419 Standard_Integer anIndx(0);
420 BRepExtrema_ExtCC aCC;
421 aCC.Initialize(anEdg2);
423 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
424 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
425 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
428 Standard_Boolean hasSol(false);
432 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
433 if(aCC.SquareDistance(i) < aSqDist) {
434 aSqDist = aCC.SquareDistance(i);
440 if(aSqDist <= SquareTolerance) { // hasInt
441 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
443 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
444 outPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
446 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
454 TopExp::Vertices(anEdg1, aV1, aV2);
455 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
458 } else if(aNum > 1) {
459 TopExp::Vertices(anEdg1, aV1, aV2);
460 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
468 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
469 Standard_Real& outPar ) const
471 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
473 return HasIntersection( aHydAxis, theProfile, thePlane, outPar );
477 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
479 if ( theProfile.IsNull() )
482 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
483 if ( aHydAxis.IsNull() )
487 if(!BuildFace(aHydAxis, aPlane))
490 Standard_Real aPar(.0);
491 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
492 return false; // Object is already in reference list or it has no intersection
494 int aProfileIndex = insertParameter( aPar );
495 insertProfileInToOrder( theProfile, aProfileIndex );
497 // Indicate model of the need to update the stream presentation
503 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
505 return GetReferenceObjects( DataTag_Profile );
508 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
510 if ( theProfile.IsNull() )
513 int aProfileIndex = -1;
515 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
516 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
517 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
519 Handle(HYDROData_Profile) aProfile =
520 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
521 if ( aProfile.IsNull() )
524 if ( IsEqual( theProfile, aProfile ) )
531 if ( aProfileIndex == -1 )
534 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
536 // Remove parameter for removed profile
537 removeParameter( aProfileIndex );
539 // Indicate model of the need to update the stream presentation
545 void HYDROData_Stream::RemoveProfiles()
547 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
549 ClearReferenceObjects( DataTag_Profile );
551 // Remove the parameters array
552 removeParametersArray();
554 // Indicate model of the need to update the stream presentation
555 SetToUpdate( anIsToUpdate );
558 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
559 const int theBeforeIndex )
561 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
562 if ( theProfile.IsNull() || aHydAxis.IsNull() )
565 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
566 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
567 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
570 if ( theBeforeIndex == -1 )
571 AddReferenceObject( theProfile, DataTag_Profile );
573 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
576 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
577 TopoDS_Face& thePlane ) const
579 if ( !IsValidAsAxis( theHydAxis ) )
582 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
584 gp_Ax2 aX2(gp::XOY());
588 BRepBndLib::Add(aHydraulicWire,B);
589 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
590 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
591 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
592 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
593 thePlane = TopoDS::Face(aMkr.Shape());
597 void HYDROData_Stream::updateProfilesOrder()
599 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
600 if ( aRefProfiles.IsEmpty() )
603 // At first we remove all profiles from order
606 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
607 if ( aHydAxis.IsNull() )
611 if ( !BuildFace( aHydAxis, aPlane ) )
614 Standard_Real aPar( .0 );
618 TopoDS_Compound aCmp;
619 aBB.MakeCompound(aCmp);
622 HYDROData_DataMapOfRealOfHDProfile aDM;
623 TColStd_ListOfReal aList;
624 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
625 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
627 Handle(HYDROData_Profile) aProfile =
628 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
630 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
631 aBB.Add( aCmp, aProfileWire );
633 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
636 aDM.Bind( aPar, aProfile );
637 aList.Append( aPar );
640 if ( aList.IsEmpty() )
643 TColStd_Array1OfReal anArr( 1, aList.Extent() );
645 TColStd_ListIteratorOfListOfReal it( aList );
646 for ( int j = 1; it.More(); it.Next(), j++ )
647 anArr( j ) = it.Value();
650 if ( aList.Extent() > 1 )
652 TCollection_CompareOfReal Compar;
653 SortTools_QuickSortOfReal::Sort( anArr, Compar );
655 for (int j = 1; j <= anArr.Length(); j++) {
656 const Standard_Real aKey = anArr(j);
657 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
658 insertProfileInToOrder( aProfile );
660 } else if ( aList.Extent() == 1 ) {
661 const Standard_Real aKey = aList.Last();
662 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
663 insertProfileInToOrder( aProfile );
666 setParametersArray( anArr );
669 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
670 BRepTools::Write(aHydraulicWire, "Path.brep");
671 BRepTools::Write(aCmp, "Prof.brep");
675 void HYDROData_Stream::createGroupObjects()
677 TopoDS_Shape aStreamShape = GetTopShape();
678 if ( aStreamShape.IsNull() )
681 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
682 if ( aRefProfiles.Length() < 2 )
685 Handle(HYDROData_Profile) aFirstProfile =
686 Handle(HYDROData_Profile)::DownCast( aRefProfiles.First() );
687 Handle(HYDROData_Profile) aLastProfile =
688 Handle(HYDROData_Profile)::DownCast( aRefProfiles.Last() );
689 if ( aFirstProfile.IsNull() || aLastProfile.IsNull() )
692 TopoDS_Shape aBotEdgeShape = aFirstProfile->GetTopShape();
693 TopoDS_Shape aTopEdgeShape = aLastProfile->GetTopShape();
694 if ( aBotEdgeShape.IsNull() || aBotEdgeShape.ShapeType() != TopAbs_WIRE ||
695 aTopEdgeShape.IsNull() || aTopEdgeShape.ShapeType() != TopAbs_WIRE )
698 TopExp_Explorer aBotEdgeShapeExp( aBotEdgeShape, TopAbs_EDGE );
699 TopExp_Explorer aTopEdgeShapeExp( aTopEdgeShape, TopAbs_EDGE );
700 if ( !aBotEdgeShapeExp.More() || !aTopEdgeShapeExp.More() )
703 TopoDS_Edge aBotEdge = TopoDS::Edge( aBotEdgeShapeExp.Current() );
704 TopoDS_Edge aTopEdge = TopoDS::Edge( aTopEdgeShapeExp.Current() );
706 TopoDS_Vertex aBotFirstVert, aBotLastVert, aTopFirstVert, aTopLastVert;
707 TopExp::Vertices( aBotEdge, aBotFirstVert, aBotLastVert, true );
708 TopExp::Vertices( aTopEdge, aTopFirstVert, aTopLastVert, true );
710 TopExp_Explorer aStreamFaceExp( aStreamShape, TopAbs_FACE );
711 if ( !aStreamFaceExp.More() )
714 // Get only face because of 2d profile wires is in compound
715 TopoDS_Face aStreamFace = TopoDS::Face( aStreamFaceExp.Current() );
717 TopTools_SequenceOfShape aStreamWires;
718 HYDROData_ShapesTool::ExploreShapeToShapes( aStreamFace, TopAbs_EDGE, aStreamWires );
720 bool anIsLeft = false;
721 bool anIsRight = false;
723 TopTools_SequenceOfShape aLeftEdges, aRightEdges;
724 for ( int i = 1, n = aStreamWires.Length(); i <= n; ++i )
726 TopoDS_Edge anEdge = TopoDS::Edge( aStreamWires.Value( i ) );
727 if ( HYDROData_ShapesTool::IsEdgesEquals( anEdge, aBotEdge ) ||
728 HYDROData_ShapesTool::IsEdgesEquals( anEdge, aTopEdge ) )
735 if ( !anIsLeft && !anIsRight )
737 TopoDS_Vertex anEdgeFirstVert, anEdgeLastVert;
738 TopExp::Vertices( anEdge, anEdgeFirstVert, anEdgeLastVert, true );
740 anIsLeft = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aBotFirstVert ) ||
741 HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aTopFirstVert );
743 anIsRight = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aTopLastVert ) ||
744 HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aBotLastVert );
749 aLeftEdges.Append( anEdge );
751 else if ( anIsRight )
753 aRightEdges.Append( anEdge );
757 // Create edges groups
758 QString aLeftGroupName = GetName() + "_Left_Bank";
760 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
761 aLeftGroup->SetName( aLeftGroupName );
762 aLeftGroup->SetShapes( aLeftEdges );
764 QString aRightGroupName = GetName() + "_Right_Bank";
766 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
767 aRightGroup->SetName( aRightGroupName );
768 aRightGroup->SetShapes( aRightEdges );
770 QString anInGroupName = GetName() + "_Inlet";
772 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
773 anInGroup->SetName( anInGroupName );
774 anInGroup->AddShape( aBotEdge );
776 QString anOutGroupName = GetName() + "_Outlet";
778 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
779 anOutGroup->SetName( anOutGroupName );
780 anOutGroup->AddShape( aTopEdge );
783 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
785 return KIND_STREAM_ALTITUDE;
788 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
790 if ( theArray.Length() == 0 )
792 removeParametersArray();
796 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
798 Handle(TDataStd_RealArray) aParamsArray =
799 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
801 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
803 const Standard_Real& aParam = theArray( i );
804 aParamsArray->SetValue( i, aParam );
808 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
810 TColStd_Array1OfReal* anArray = NULL;
812 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
813 if ( !aLabel.IsNull() )
815 Handle(TDataStd_RealArray) aParamsArray;
816 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
818 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
819 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
821 const Standard_Real& aParam = aParamsArray->Value( i );
822 anArray->SetValue( i, aParam );
830 void HYDROData_Stream::removeParametersArray()
832 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
833 if ( !aLabel.IsNull() )
834 aLabel.ForgetAllAttributes();
837 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
841 TColStd_Array1OfReal* anArr = getParametersArray();
846 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
848 bool isInserted = false;
849 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
851 const Standard_Real& aStoredParam = anArr->Value( i );
854 if ( theParam > aStoredParam )
860 aNewArr( j ) = theParam;
866 aNewArr( j ) = aStoredParam;
872 aNewArr( aNewArr.Upper() ) = theParam;
875 setParametersArray( aNewArr );
880 TColStd_Array1OfReal aNewArr( 1, 1 );
881 aNewArr.SetValue( 1, theParam );
882 setParametersArray( aNewArr );
888 void HYDROData_Stream::removeParameter( const int& theIndex )
890 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
891 if ( aLabel.IsNull() )
894 Handle(TDataStd_RealArray) aParamsArray;
895 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
898 if ( aParamsArray->Length() == 1 )
900 removeParametersArray();
904 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
906 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
908 const Standard_Real& aStoredParam = aParamsArray->Value( i );
912 aNewArr.SetValue( j, aStoredParam );
916 setParametersArray( aNewArr );