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 );
95 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
97 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
99 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
100 if ( !aHydAxis.IsNull() )
101 aResSeq.Append( aHydAxis );
103 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
104 aResSeq.Append( aSeqOfProfiles );
109 TopoDS_Shape HYDROData_Stream::GetTopShape() const
111 return getTopShape();
114 TopoDS_Shape HYDROData_Stream::GetShape3D() const
119 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
120 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
122 Handle(Geom_BSplineCurve) aBSpline;
123 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
124 anInterpolator.Perform() ;
125 if (anInterpolator.IsDone())
126 aBSpline = anInterpolator.Curve();
130 void HYDROData_Stream::Update()
132 updateProfilesOrder();
136 void HYDROData_Stream::UpdatePrs()
138 HYDROData_NaturalObject::Update();
140 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
141 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
142 if ( aHydAxis.IsNull() || aRefProfiles.Length() < 2 )
145 bool anIsFirst = true;
146 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
147 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
148 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
149 TopTools_Array1OfShape anArrOfProfiles(1, aRefProfiles.Length());
150 TopTools_Array1OfShape anArrOf2DProfiles(1, aRefProfiles.Length());
153 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
154 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
156 Handle(HYDROData_Profile) aProfile =
157 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
158 if ( aProfile.IsNull() )
160 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
162 if ( !aProfile->GetLeftPoint( aPnt1 ) || !aProfile->GetRightPoint( aPnt2 ) )
164 anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
165 anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
167 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
168 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
169 TopoDS_Vertex aV1, aV2;
170 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
171 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
172 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
176 aP1 = BRep_Tool::Pnt(aV2);
177 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
181 anArrayOfFPnt->SetValue(i,aCurFP);
182 anArrayOfLPnt->SetValue(i,aCurLP);
185 // Construct of the 3D presentation
186 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
187 if(aBSpline.IsNull())
189 TopoDS_Edge anEdgLeft, anEdgRight;
190 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
191 if(aMakeEdge.IsDone())
192 anEdgLeft = aMakeEdge.Edge();
193 if(anEdgLeft.IsNull())
196 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
197 if(aBSpline.IsNull())
199 aMakeEdge.Init(aBSpline);
200 if(aMakeEdge.IsDone())
201 anEdgRight = aMakeEdge.Edge();
202 if(anEdgRight.IsNull())
205 TopoDS_Compound aCmp;
206 aBB.MakeCompound(aCmp);
207 anIter.Init( aRefProfiles );
208 for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )
209 aBB.Add(aCmp, anArrOfProfiles.Value(i));
210 aBB.Add(aCmp,anEdgLeft);
211 aBB.Add(aCmp,anEdgRight);
212 BRepCheck_Analyzer aCh(aCmp);
217 BRepTools::Write(aCmp, "str3d.brep");
222 // Construct the top presentation
223 for(int i=1;i<= anArrayOfLPnt->Length();i++) {
224 gp_Pnt aPnt = anArrayOfFPnt->Value(i);
225 aPnt.SetZ(.0); // make 2d
226 anArrayOfFPnt->SetValue(i, aPnt);
227 aPnt = anArrayOfLPnt->Value(i);
229 anArrayOfLPnt->SetValue(i, aPnt);
232 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
233 if(aBSpline.IsNull())
235 aMakeEdge.Init(aBSpline);
236 if(aMakeEdge.IsDone())
237 anEdgLeft = aMakeEdge.Edge();
239 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
240 if(aBSpline.IsNull())
242 aMakeEdge.Init(aBSpline);
243 if(aMakeEdge.IsDone())
244 anEdgRight = aMakeEdge.Edge();
245 if(anEdgRight.IsNull())
247 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
248 TopoDS_Edge aBotEdge, aTopEdge;
249 if(aMakeEdge2.IsDone())
250 aBotEdge = aMakeEdge2.Edge();
251 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
252 if(aMakeEdge3.IsDone())
253 aTopEdge = aMakeEdge3.Edge();
255 // Make wire for 2D presentation with updating of corresponding edges
256 BRepBuilderAPI_MakeWire aMakeWire;
258 aMakeWire.Add( aBotEdge );
259 aBotEdge = aMakeWire.Edge();
261 aMakeWire.Add( anEdgLeft );
262 anEdgLeft = aMakeWire.Edge();
264 aMakeWire.Add( aTopEdge );
265 aTopEdge = aMakeWire.Edge();
267 aMakeWire.Add( anEdgRight );
268 anEdgRight = aMakeWire.Edge();
270 TopoDS_Wire aSectProfileWire;
271 if(aMakeWire.IsDone())
272 aSectProfileWire = aMakeWire.Wire();
274 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
277 if( aMakeFace.IsDone() )
278 aFace = aMakeFace.Face();
281 aBB.MakeCompound(aCmp);
283 for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
284 aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
290 BRepTools::Write(aCmp, "str2d.brep");
295 // Create the stream groups
296 QString aLeftGroupName = GetName() + "_Left_Bank";
298 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
299 aLeftGroup->SetName( aLeftGroupName );
300 aLeftGroup->AddShape( anEdgLeft );
302 QString aRightGroupName = GetName() + "_Right_Bank";
304 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
305 aRightGroup->SetName( aRightGroupName );
306 aRightGroup->AddShape( anEdgRight );
308 QString anInGroupName = GetName() + "_Inlet";
310 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
311 anInGroup->SetName( anInGroupName );
312 anInGroup->AddShape( aBotEdge );
314 QString anOutGroupName = GetName() + "_Outlet";
316 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
317 anOutGroup->SetName( anOutGroupName );
318 anOutGroup->AddShape( aTopEdge );
320 // This peace of code is for testing of functionality of altitude,
321 // will be removed by adv when testing will be finished
322 Handle(HYDROData_IAltitudeObject) anAltObj = GetAltitudeObject();
323 gp_XY aTestPnt( 5, 0 );
324 anAltObj->GetAltitudeForPoint( aTestPnt );
329 QColor HYDROData_Stream::DefaultFillingColor()
331 return QColor( Qt::green );
334 QColor HYDROData_Stream::DefaultBorderColor()
336 return QColor( Qt::transparent );
339 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
341 if ( theHydAxis.IsNull() )
344 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
345 if ( aHydraulicShape.IsNull() ||
346 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
347 BRep_Tool::IsClosed( aHydraulicShape ) )
348 return false; // The polyline must be a single not closed wire
353 TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
354 const int theGroupId )
356 TopoDS_Shape aResShape;
357 if ( theGroups.Length() != 4 )
360 Handle(HYDROData_ShapesGroup) aGroup =
361 Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
362 if ( aGroup.IsNull() )
365 TopTools_SequenceOfShape aGroupShapes;
366 aGroup->GetShapes( aGroupShapes );
368 if ( !aGroupShapes.IsEmpty() )
369 aResShape = aGroupShapes.First();
374 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
376 HYDROData_SequenceOfObjects aGroups = GetGroups();
377 return getShapeFromGroup( aGroups, 1 );
380 TopoDS_Shape HYDROData_Stream::GetRightShape() const
382 HYDROData_SequenceOfObjects aGroups = GetGroups();
383 return getShapeFromGroup( aGroups, 2 );
386 TopoDS_Shape HYDROData_Stream::GetInletShape() const
388 HYDROData_SequenceOfObjects aGroups = GetGroups();
389 return getShapeFromGroup( aGroups, 3 );
392 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
394 HYDROData_SequenceOfObjects aGroups = GetGroups();
395 return getShapeFromGroup( aGroups, 4 );
398 QColor HYDROData_Stream::getDefaultFillingColor() const
400 return DefaultFillingColor();
403 QColor HYDROData_Stream::getDefaultBorderColor() const
405 return DefaultBorderColor();
408 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
410 if ( !IsValidAsAxis( theAxis ) )
413 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
414 if ( IsEqual( aPrevAxis, theAxis ) )
417 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
419 // Update the order of profiles
420 updateProfilesOrder();
422 // Indicate model of the need to update the stream presentation
428 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
430 return Handle(HYDROData_PolylineXY)::DownCast(
431 GetReferenceObject( DataTag_HydraulicAxis ) );
434 void HYDROData_Stream::RemoveHydraulicAxis()
436 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
437 if ( aPrevAxis.IsNull() )
440 ClearReferenceObjects( DataTag_HydraulicAxis );
442 // We remove the reference profiles
445 // Indicate model of the need to update the stream presentation
449 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
450 const Handle(HYDROData_Profile)& theProfile,
451 const TopoDS_Face& thePlane,
452 Standard_Real& outPar)
454 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
457 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
458 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
459 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
462 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
463 if(!aProjector.IsDone())
465 TopoDS_Shape aPrjProfile = aProjector.Shape();
466 if(aPrjProfile.IsNull())
468 TopoDS_Vertex aV1, aV2;
469 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
470 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
471 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
472 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
473 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
474 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
476 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
478 anExp.Init(aPrjProfile, TopAbs_EDGE);
480 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
484 if(aV1.IsNull() || aV2.IsNull())
486 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
487 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
490 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
493 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
494 Standard_Integer aNum(0);
496 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
497 for(;anExplo.More();anExplo.Next()) aNum++;
498 // check for self-intersection
499 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
500 Standard_Boolean hasInt(false);
501 Standard_Real aSqDist(DBL_MAX);
502 Standard_Integer anIndx(0);
503 BRepExtrema_ExtCC aCC;
504 aCC.Initialize(anEdg2);
506 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
507 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
508 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
511 Standard_Boolean hasSol(false);
515 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
516 if(aCC.SquareDistance(i) < aSqDist) {
517 aSqDist = aCC.SquareDistance(i);
523 if(aSqDist <= SquareTolerance) { // hasInt
524 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
526 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
527 outPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
529 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
537 TopExp::Vertices(anEdg1, aV1, aV2);
538 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
541 } else if(aNum > 1) {
542 TopExp::Vertices(anEdg1, aV1, aV2);
543 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
551 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
552 Standard_Real& outPar ) const
554 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
556 return HasIntersection( aHydAxis, theProfile, thePlane, outPar );
560 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
562 if ( theProfile.IsNull() )
565 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
566 if ( aHydAxis.IsNull() )
570 if(!BuildFace(aHydAxis, aPlane))
573 Standard_Real aPar(.0);
574 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
575 return false; // Object is already in reference list or it has no intersection
577 int aProfileIndex = insertParameter( aPar );
578 insertProfileInToOrder( theProfile, aProfileIndex );
580 // Indicate model of the need to update the stream presentation
586 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
588 return GetReferenceObjects( DataTag_Profile );
591 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
593 if ( theProfile.IsNull() )
596 int aProfileIndex = -1;
598 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
599 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
600 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
602 Handle(HYDROData_Profile) aProfile =
603 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
604 if ( aProfile.IsNull() )
607 if ( IsEqual( theProfile, aProfile ) )
614 if ( aProfileIndex == -1 )
617 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
619 // Remove parameter for removed profile
620 removeParameter( aProfileIndex );
622 // Indicate model of the need to update the stream presentation
628 void HYDROData_Stream::RemoveProfiles()
630 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
632 ClearReferenceObjects( DataTag_Profile );
634 // Remove the parameters array
635 removeParametersArray();
637 // Indicate model of the need to update the stream presentation
638 SetToUpdate( anIsToUpdate );
641 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
642 const int theBeforeIndex )
644 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
645 if ( theProfile.IsNull() || aHydAxis.IsNull() )
648 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
649 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
650 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
653 if ( theBeforeIndex == -1 )
654 AddReferenceObject( theProfile, DataTag_Profile );
656 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
659 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
660 TopoDS_Face& thePlane ) const
662 if ( !IsValidAsAxis( theHydAxis ) )
665 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
667 gp_Ax2 aX2(gp::XOY());
671 BRepBndLib::Add(aHydraulicWire,B);
672 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
673 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
674 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
675 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
676 thePlane = TopoDS::Face(aMkr.Shape());
680 void HYDROData_Stream::updateProfilesOrder()
682 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
683 if ( aRefProfiles.IsEmpty() )
686 // At first we remove all profiles from order
689 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
690 if ( aHydAxis.IsNull() )
694 if ( !BuildFace( aHydAxis, aPlane ) )
697 Standard_Real aPar( .0 );
701 TopoDS_Compound aCmp;
702 aBB.MakeCompound(aCmp);
705 HYDROData_DataMapOfRealOfHDProfile aDM;
706 TColStd_ListOfReal aList;
707 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
708 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
710 Handle(HYDROData_Profile) aProfile =
711 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
713 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
714 aBB.Add( aCmp, aProfileWire );
716 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
719 aDM.Bind( aPar, aProfile );
720 aList.Append( aPar );
723 if ( aList.IsEmpty() )
726 TColStd_Array1OfReal anArr( 1, aList.Extent() );
728 TColStd_ListIteratorOfListOfReal it( aList );
729 for ( int j = 1; it.More(); it.Next(), j++ )
730 anArr( j ) = it.Value();
733 if ( aList.Extent() > 1 )
735 TCollection_CompareOfReal Compar;
736 SortTools_QuickSortOfReal::Sort( anArr, Compar );
738 for (int j = 1; j <= anArr.Length(); j++) {
739 const Standard_Real aKey = anArr(j);
740 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
741 insertProfileInToOrder( aProfile );
743 } else if ( aList.Extent() == 1 ) {
744 const Standard_Real aKey = aList.Last();
745 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
746 insertProfileInToOrder( aProfile );
749 setParametersArray( anArr );
752 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
753 BRepTools::Write(aHydraulicWire, "Path.brep");
754 BRepTools::Write(aCmp, "Prof.brep");
758 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
760 return KIND_STREAM_ALTITUDE;
763 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
765 if ( theArray.Length() == 0 )
767 removeParametersArray();
771 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
773 Handle(TDataStd_RealArray) aParamsArray =
774 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
776 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
778 const Standard_Real& aParam = theArray( i );
779 aParamsArray->SetValue( i, aParam );
783 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
785 TColStd_Array1OfReal* anArray = NULL;
787 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
788 if ( !aLabel.IsNull() )
790 Handle(TDataStd_RealArray) aParamsArray;
791 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
793 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
794 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
796 const Standard_Real& aParam = aParamsArray->Value( i );
797 anArray->SetValue( i, aParam );
805 void HYDROData_Stream::removeParametersArray()
807 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
808 if ( !aLabel.IsNull() )
809 aLabel.ForgetAllAttributes();
812 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
816 TColStd_Array1OfReal* anArr = getParametersArray();
821 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
823 bool isInserted = false;
824 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
826 const Standard_Real& aStoredParam = anArr->Value( i );
829 if ( theParam > aStoredParam )
835 aNewArr( j ) = theParam;
841 aNewArr( j ) = aStoredParam;
847 aNewArr( aNewArr.Upper() ) = theParam;
850 setParametersArray( aNewArr );
855 TColStd_Array1OfReal aNewArr( 1, 1 );
856 aNewArr.SetValue( 1, theParam );
857 setParametersArray( aNewArr );
863 void HYDROData_Stream::removeParameter( const int& theIndex )
865 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
866 if ( aLabel.IsNull() )
869 Handle(TDataStd_RealArray) aParamsArray;
870 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
873 if ( aParamsArray->Length() == 1 )
875 removeParametersArray();
879 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
881 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
883 const Standard_Real& aStoredParam = aParamsArray->Value( i );
887 aNewArr.SetValue( j, aStoredParam );
891 setParametersArray( aNewArr );