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"
9 #include "HYDROData_IAltitudeObject.h"
11 #include <TDataStd_RealArray.hxx>
13 #include <Precision.hxx>
15 #include <NCollection_DataMap.hxx>
17 #include <TColStd_Array1OfReal.hxx>
18 #include <TColStd_ListOfReal.hxx>
19 #include <TColStd_ListIteratorOfListOfReal.hxx>
20 #include <TCollection_CompareOfReal.hxx>
21 #include <TColgp_Array1OfPnt.hxx>
22 #include <TColgp_HArray1OfPnt.hxx>
25 #include <TopoDS_Wire.hxx>
26 #include <TopoDS_Shell.hxx>
27 #include <TopoDS_Face.hxx>
28 #include <TopoDS_Edge.hxx>
29 #include <TopoDS_Vertex.hxx>
31 #include <TopExp_Explorer.hxx>
33 #include <Bnd_Box.hxx>
35 #include <BRep_Builder.hxx>
36 #include <BRepBuilderAPI_MakeEdge.hxx>
37 #include <BRepBuilderAPI_MakeWire.hxx>
38 #include <BRepBuilderAPI_MakeFace.hxx>
40 #include <BRepBndLib.hxx>
41 #include <BRepProj_Projection.hxx>
42 #include <BRepExtrema_ExtCC.hxx>
43 #include <BRepCheck_Analyzer.hxx>
53 #include <GeomAPI_Interpolate.hxx>
54 #include <Geom_BSplineCurve.hxx>
56 #include <TopTools_Array1OfShape.hxx>
58 #include <SortTools_QuickSortOfReal.hxx>
61 #include <QStringList>
63 //#define DEB_STREAM 1
65 //#define DEB_HASINT 1
66 //#define DEB_UPDATE 1
67 #include <BRepTools.hxx>
68 #include <TCollection_AsciiString.hxx>
71 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
73 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
74 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
77 HYDROData_Stream::HYDROData_Stream()
78 : HYDROData_NaturalObject()
82 HYDROData_Stream::~HYDROData_Stream()
86 QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
88 QStringList aResList = dumpObjectCreation( theTreatedObjects );
89 QString aName = GetObjPyName();
93 aResList << QString( "" );
94 aResList << QString( "%1.Update();" ).arg( aName );
95 aResList << QString( "" );
100 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
102 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
104 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
105 if ( !aHydAxis.IsNull() )
106 aResSeq.Append( aHydAxis );
108 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
109 aResSeq.Append( aSeqOfProfiles );
114 TopoDS_Shape HYDROData_Stream::GetTopShape() const
116 return getTopShape();
119 TopoDS_Shape HYDROData_Stream::GetShape3D() const
124 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
125 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
127 Handle(Geom_BSplineCurve) aBSpline;
128 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
129 anInterpolator.Perform() ;
130 if (anInterpolator.IsDone())
131 aBSpline = anInterpolator.Curve();
135 void HYDROData_Stream::Update()
137 updateProfilesOrder();
141 void HYDROData_Stream::UpdatePrs()
143 HYDROData_NaturalObject::Update();
145 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
146 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
147 if ( aHydAxis.IsNull() || aRefProfiles.Length() < 2 )
150 bool anIsFirst = true;
151 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
152 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
153 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
154 TopTools_Array1OfShape anArrOfProfiles(1, aRefProfiles.Length());
155 TopTools_Array1OfShape anArrOf2DProfiles(1, aRefProfiles.Length());
158 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
159 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
161 Handle(HYDROData_Profile) aProfile =
162 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
163 if ( aProfile.IsNull() )
165 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
167 if ( !aProfile->GetLeftPoint( aPnt1 ) || !aProfile->GetRightPoint( aPnt2 ) )
169 anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
170 anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
172 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
173 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
174 TopoDS_Vertex aV1, aV2;
175 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
176 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
177 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
181 aP1 = BRep_Tool::Pnt(aV2);
182 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
186 anArrayOfFPnt->SetValue(i,aCurFP);
187 anArrayOfLPnt->SetValue(i,aCurLP);
190 // Construct of the 3D presentation
191 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
192 if(aBSpline.IsNull())
194 TopoDS_Edge anEdgLeft, anEdgRight;
195 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
196 if(aMakeEdge.IsDone())
197 anEdgLeft = aMakeEdge.Edge();
198 if(anEdgLeft.IsNull())
201 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
202 if(aBSpline.IsNull())
204 aMakeEdge.Init(aBSpline);
205 if(aMakeEdge.IsDone())
206 anEdgRight = aMakeEdge.Edge();
207 if(anEdgRight.IsNull())
210 TopoDS_Compound aCmp;
211 aBB.MakeCompound(aCmp);
212 anIter.Init( aRefProfiles );
213 for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )
214 aBB.Add(aCmp, anArrOfProfiles.Value(i));
215 aBB.Add(aCmp,anEdgLeft);
216 aBB.Add(aCmp,anEdgRight);
217 BRepCheck_Analyzer aCh(aCmp);
222 BRepTools::Write(aCmp, "str3d.brep");
227 // Construct the top presentation
228 for(int i=1;i<= anArrayOfLPnt->Length();i++) {
229 gp_Pnt aPnt = anArrayOfFPnt->Value(i);
230 aPnt.SetZ(.0); // make 2d
231 anArrayOfFPnt->SetValue(i, aPnt);
232 aPnt = anArrayOfLPnt->Value(i);
234 anArrayOfLPnt->SetValue(i, aPnt);
237 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
238 if(aBSpline.IsNull())
240 aMakeEdge.Init(aBSpline);
241 if(aMakeEdge.IsDone())
242 anEdgLeft = aMakeEdge.Edge();
244 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
245 if(aBSpline.IsNull())
247 aMakeEdge.Init(aBSpline);
248 if(aMakeEdge.IsDone())
249 anEdgRight = aMakeEdge.Edge();
250 if(anEdgRight.IsNull())
252 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
253 TopoDS_Edge aBotEdge, aTopEdge;
254 if(aMakeEdge2.IsDone())
255 aBotEdge = aMakeEdge2.Edge();
256 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
257 if(aMakeEdge3.IsDone())
258 aTopEdge = aMakeEdge3.Edge();
260 // Make wire for 2D presentation with updating of corresponding edges
261 BRepBuilderAPI_MakeWire aMakeWire;
263 aMakeWire.Add( aBotEdge );
264 aBotEdge = aMakeWire.Edge();
266 aMakeWire.Add( anEdgLeft );
267 anEdgLeft = aMakeWire.Edge();
269 aMakeWire.Add( aTopEdge );
270 aTopEdge = aMakeWire.Edge();
272 aMakeWire.Add( anEdgRight );
273 anEdgRight = aMakeWire.Edge();
275 TopoDS_Wire aSectProfileWire;
276 if(aMakeWire.IsDone())
277 aSectProfileWire = aMakeWire.Wire();
279 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
282 if( aMakeFace.IsDone() )
283 aFace = aMakeFace.Face();
286 aBB.MakeCompound(aCmp);
288 for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
289 aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
295 BRepTools::Write(aCmp, "str2d.brep");
300 // Create the stream groups
301 QString aLeftGroupName = GetName() + "_Left_Bank";
303 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
304 aLeftGroup->SetName( aLeftGroupName );
305 aLeftGroup->AddShape( anEdgLeft );
307 QString aRightGroupName = GetName() + "_Right_Bank";
309 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
310 aRightGroup->SetName( aRightGroupName );
311 aRightGroup->AddShape( anEdgRight );
313 QString anInGroupName = GetName() + "_Inlet";
315 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
316 anInGroup->SetName( anInGroupName );
317 anInGroup->AddShape( aBotEdge );
319 QString anOutGroupName = GetName() + "_Outlet";
321 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
322 anOutGroup->SetName( anOutGroupName );
323 anOutGroup->AddShape( aTopEdge );
325 // This peace of code is for testing of functionality of altitude,
326 // will be removed by adv when testing will be finished
327 Handle(HYDROData_IAltitudeObject) anAltObj = GetAltitudeObject();
328 gp_XY aTestPnt( 5, 0 );
329 anAltObj->GetAltitudeForPoint( aTestPnt );
334 QColor HYDROData_Stream::DefaultFillingColor()
336 return QColor( Qt::green );
339 QColor HYDROData_Stream::DefaultBorderColor()
341 return QColor( Qt::transparent );
344 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
346 if ( theHydAxis.IsNull() )
349 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
350 if ( aHydraulicShape.IsNull() ||
351 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
352 BRep_Tool::IsClosed( aHydraulicShape ) )
353 return false; // The polyline must be a single not closed wire
358 TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
359 const int theGroupId )
361 TopoDS_Shape aResShape;
362 if ( theGroups.Length() != 4 )
365 Handle(HYDROData_ShapesGroup) aGroup =
366 Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
367 if ( aGroup.IsNull() )
370 TopTools_SequenceOfShape aGroupShapes;
371 aGroup->GetShapes( aGroupShapes );
373 if ( !aGroupShapes.IsEmpty() )
374 aResShape = aGroupShapes.First();
379 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
381 HYDROData_SequenceOfObjects aGroups = GetGroups();
382 return getShapeFromGroup( aGroups, 1 );
385 TopoDS_Shape HYDROData_Stream::GetRightShape() const
387 HYDROData_SequenceOfObjects aGroups = GetGroups();
388 return getShapeFromGroup( aGroups, 2 );
391 TopoDS_Shape HYDROData_Stream::GetInletShape() const
393 HYDROData_SequenceOfObjects aGroups = GetGroups();
394 return getShapeFromGroup( aGroups, 3 );
397 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
399 HYDROData_SequenceOfObjects aGroups = GetGroups();
400 return getShapeFromGroup( aGroups, 4 );
403 QColor HYDROData_Stream::getDefaultFillingColor() const
405 return DefaultFillingColor();
408 QColor HYDROData_Stream::getDefaultBorderColor() const
410 return DefaultBorderColor();
413 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
415 if ( !IsValidAsAxis( theAxis ) )
418 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
419 if ( IsEqual( aPrevAxis, theAxis ) )
422 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
424 // Update the order of profiles
425 updateProfilesOrder();
427 // Indicate model of the need to update the stream presentation
433 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
435 return Handle(HYDROData_PolylineXY)::DownCast(
436 GetReferenceObject( DataTag_HydraulicAxis ) );
439 void HYDROData_Stream::RemoveHydraulicAxis()
441 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
442 if ( aPrevAxis.IsNull() )
445 ClearReferenceObjects( DataTag_HydraulicAxis );
447 // We remove the reference profiles
450 // Indicate model of the need to update the stream presentation
454 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
455 const Handle(HYDROData_Profile)& theProfile,
456 const TopoDS_Face& thePlane,
457 Standard_Real& outPar)
459 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
462 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
463 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
464 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
467 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
468 if(!aProjector.IsDone())
470 TopoDS_Shape aPrjProfile = aProjector.Shape();
471 if(aPrjProfile.IsNull())
473 TopoDS_Vertex aV1, aV2;
474 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
475 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
476 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
477 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
478 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
479 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
481 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
483 anExp.Init(aPrjProfile, TopAbs_EDGE);
485 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
489 if(aV1.IsNull() || aV2.IsNull())
491 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
492 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
495 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
498 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
499 Standard_Integer aNum(0);
501 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
502 for(;anExplo.More();anExplo.Next()) aNum++;
503 // check for self-intersection
504 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
505 Standard_Boolean hasInt(false);
506 Standard_Real aSqDist(DBL_MAX);
507 Standard_Integer anIndx(0);
508 BRepExtrema_ExtCC aCC;
509 aCC.Initialize(anEdg2);
511 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
512 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
513 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
516 Standard_Boolean hasSol(false);
520 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
521 if(aCC.SquareDistance(i) < aSqDist) {
522 aSqDist = aCC.SquareDistance(i);
528 if(aSqDist <= SquareTolerance) { // hasInt
529 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
531 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
532 outPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
534 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
542 TopExp::Vertices(anEdg1, aV1, aV2);
543 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
546 } else if(aNum > 1) {
547 TopExp::Vertices(anEdg1, aV1, aV2);
548 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
556 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
557 Standard_Real& outPar ) const
559 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
561 return HasIntersection( aHydAxis, theProfile, thePlane, outPar );
565 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
567 if ( theProfile.IsNull() )
570 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
571 if ( aHydAxis.IsNull() )
575 if(!BuildFace(aHydAxis, aPlane))
578 Standard_Real aPar(.0);
579 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
580 return false; // Object is already in reference list or it has no intersection
582 int aProfileIndex = insertParameter( aPar );
583 insertProfileInToOrder( theProfile, aProfileIndex );
585 // Indicate model of the need to update the stream presentation
591 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
593 return GetReferenceObjects( DataTag_Profile );
596 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
598 if ( theProfile.IsNull() )
601 int aProfileIndex = -1;
603 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
604 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
605 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
607 Handle(HYDROData_Profile) aProfile =
608 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
609 if ( aProfile.IsNull() )
612 if ( IsEqual( theProfile, aProfile ) )
619 if ( aProfileIndex == -1 )
622 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
624 // Remove parameter for removed profile
625 removeParameter( aProfileIndex );
627 // Indicate model of the need to update the stream presentation
633 void HYDROData_Stream::RemoveProfiles()
635 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
637 ClearReferenceObjects( DataTag_Profile );
639 // Remove the parameters array
640 removeParametersArray();
642 // Indicate model of the need to update the stream presentation
643 SetToUpdate( anIsToUpdate );
646 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
647 const int theBeforeIndex )
649 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
650 if ( theProfile.IsNull() || aHydAxis.IsNull() )
653 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
654 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
655 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
658 if ( theBeforeIndex == -1 )
659 AddReferenceObject( theProfile, DataTag_Profile );
661 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
664 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
665 TopoDS_Face& thePlane ) const
667 if ( !IsValidAsAxis( theHydAxis ) )
670 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
672 gp_Ax2 aX2(gp::XOY());
676 BRepBndLib::Add(aHydraulicWire,B);
677 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
678 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
679 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
680 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
681 thePlane = TopoDS::Face(aMkr.Shape());
685 void HYDROData_Stream::updateProfilesOrder()
687 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
688 if ( aRefProfiles.IsEmpty() )
691 // At first we remove all profiles from order
694 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
695 if ( aHydAxis.IsNull() )
699 if ( !BuildFace( aHydAxis, aPlane ) )
702 Standard_Real aPar( .0 );
706 TopoDS_Compound aCmp;
707 aBB.MakeCompound(aCmp);
710 HYDROData_DataMapOfRealOfHDProfile aDM;
711 TColStd_ListOfReal aList;
712 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
713 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
715 Handle(HYDROData_Profile) aProfile =
716 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
718 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
719 aBB.Add( aCmp, aProfileWire );
721 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
724 aDM.Bind( aPar, aProfile );
725 aList.Append( aPar );
728 if ( aList.IsEmpty() )
731 TColStd_Array1OfReal anArr( 1, aList.Extent() );
733 TColStd_ListIteratorOfListOfReal it( aList );
734 for ( int j = 1; it.More(); it.Next(), j++ )
735 anArr( j ) = it.Value();
738 if ( aList.Extent() > 1 )
740 TCollection_CompareOfReal Compar;
741 SortTools_QuickSortOfReal::Sort( anArr, Compar );
743 for (int j = 1; j <= anArr.Length(); j++) {
744 const Standard_Real aKey = anArr(j);
745 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
746 insertProfileInToOrder( aProfile );
748 } else if ( aList.Extent() == 1 ) {
749 const Standard_Real aKey = aList.Last();
750 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
751 insertProfileInToOrder( aProfile );
754 setParametersArray( anArr );
757 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
758 BRepTools::Write(aHydraulicWire, "Path.brep");
759 BRepTools::Write(aCmp, "Prof.brep");
763 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
765 return KIND_STREAM_ALTITUDE;
768 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
770 if ( theArray.Length() == 0 )
772 removeParametersArray();
776 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
778 Handle(TDataStd_RealArray) aParamsArray =
779 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
781 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
783 const Standard_Real& aParam = theArray( i );
784 aParamsArray->SetValue( i, aParam );
788 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
790 TColStd_Array1OfReal* anArray = NULL;
792 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
793 if ( !aLabel.IsNull() )
795 Handle(TDataStd_RealArray) aParamsArray;
796 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
798 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
799 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
801 const Standard_Real& aParam = aParamsArray->Value( i );
802 anArray->SetValue( i, aParam );
810 void HYDROData_Stream::removeParametersArray()
812 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
813 if ( !aLabel.IsNull() )
814 aLabel.ForgetAllAttributes();
817 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
821 TColStd_Array1OfReal* anArr = getParametersArray();
826 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
828 bool isInserted = false;
829 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
831 const Standard_Real& aStoredParam = anArr->Value( i );
834 if ( theParam > aStoredParam )
840 aNewArr( j ) = theParam;
846 aNewArr( j ) = aStoredParam;
852 aNewArr( aNewArr.Upper() ) = theParam;
855 setParametersArray( aNewArr );
860 TColStd_Array1OfReal aNewArr( 1, 1 );
861 aNewArr.SetValue( 1, theParam );
862 setParametersArray( aNewArr );
868 void HYDROData_Stream::removeParameter( const int& theIndex )
870 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
871 if ( aLabel.IsNull() )
874 Handle(TDataStd_RealArray) aParamsArray;
875 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
878 if ( aParamsArray->Length() == 1 )
880 removeParametersArray();
884 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
886 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
888 const Standard_Real& aStoredParam = aParamsArray->Value( i );
892 aNewArr.SetValue( j, aStoredParam );
896 setParametersArray( aNewArr );