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();
91 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
92 setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
94 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
95 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
97 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
98 setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
101 aResList << QString( "" );
102 aResList << QString( "%1.Update();" ).arg( aName );
103 aResList << QString( "" );
108 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
110 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
112 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
113 if ( !aHydAxis.IsNull() )
114 aResSeq.Append( aHydAxis );
116 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
117 aResSeq.Append( aSeqOfProfiles );
122 TopoDS_Shape HYDROData_Stream::GetTopShape() const
124 return getTopShape();
127 TopoDS_Shape HYDROData_Stream::GetShape3D() const
132 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
133 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
135 Handle(Geom_BSplineCurve) aBSpline;
136 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
137 anInterpolator.Perform() ;
138 if (anInterpolator.IsDone())
139 aBSpline = anInterpolator.Curve();
143 void HYDROData_Stream::Update()
145 updateProfilesOrder();
149 void HYDROData_Stream::UpdatePrs()
151 HYDROData_NaturalObject::Update();
153 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
154 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
155 if ( aHydAxis.IsNull() || aRefProfiles.Length() < 2 )
158 bool anIsFirst = true;
159 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
160 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
161 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
162 TopTools_Array1OfShape anArrOfProfiles(1, aRefProfiles.Length());
163 TopTools_Array1OfShape anArrOf2DProfiles(1, aRefProfiles.Length());
166 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
167 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
169 Handle(HYDROData_Profile) aProfile =
170 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
171 if ( aProfile.IsNull() )
173 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
175 if ( !aProfile->GetLeftPoint( aPnt1 ) || !aProfile->GetRightPoint( aPnt2 ) )
177 anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
178 anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
180 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
181 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
182 TopoDS_Vertex aV1, aV2;
183 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
184 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
185 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
189 aP1 = BRep_Tool::Pnt(aV2);
190 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
194 anArrayOfFPnt->SetValue(i,aCurFP);
195 anArrayOfLPnt->SetValue(i,aCurLP);
198 // Construct of the 3D presentation
199 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
200 if(aBSpline.IsNull())
202 TopoDS_Edge anEdgLeft, anEdgRight;
203 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
204 if(aMakeEdge.IsDone())
205 anEdgLeft = aMakeEdge.Edge();
206 if(anEdgLeft.IsNull())
209 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
210 if(aBSpline.IsNull())
212 aMakeEdge.Init(aBSpline);
213 if(aMakeEdge.IsDone())
214 anEdgRight = aMakeEdge.Edge();
215 if(anEdgRight.IsNull())
218 TopoDS_Compound aCmp;
219 aBB.MakeCompound(aCmp);
220 anIter.Init( aRefProfiles );
221 for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )
222 aBB.Add(aCmp, anArrOfProfiles.Value(i));
223 aBB.Add(aCmp,anEdgLeft);
224 aBB.Add(aCmp,anEdgRight);
225 BRepCheck_Analyzer aCh(aCmp);
230 BRepTools::Write(aCmp, "str3d.brep");
235 // Construct the top presentation
236 for(int i=1;i<= anArrayOfLPnt->Length();i++) {
237 gp_Pnt aPnt = anArrayOfFPnt->Value(i);
238 aPnt.SetZ(.0); // make 2d
239 anArrayOfFPnt->SetValue(i, aPnt);
240 aPnt = anArrayOfLPnt->Value(i);
242 anArrayOfLPnt->SetValue(i, aPnt);
245 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
246 if(aBSpline.IsNull())
248 aMakeEdge.Init(aBSpline);
249 if(aMakeEdge.IsDone())
250 anEdgLeft = aMakeEdge.Edge();
252 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
253 if(aBSpline.IsNull())
255 aMakeEdge.Init(aBSpline);
256 if(aMakeEdge.IsDone())
257 anEdgRight = aMakeEdge.Edge();
258 if(anEdgRight.IsNull())
260 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
261 TopoDS_Edge aBotEdge, aTopEdge;
262 if(aMakeEdge2.IsDone())
263 aBotEdge = aMakeEdge2.Edge();
264 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
265 if(aMakeEdge3.IsDone())
266 aTopEdge = aMakeEdge3.Edge();
268 // Make wire for 2D presentation with updating of corresponding edges
269 BRepBuilderAPI_MakeWire aMakeWire;
271 aMakeWire.Add( aBotEdge );
272 aBotEdge = aMakeWire.Edge();
274 aMakeWire.Add( anEdgLeft );
275 anEdgLeft = aMakeWire.Edge();
277 aMakeWire.Add( aTopEdge );
278 aTopEdge = aMakeWire.Edge();
280 aMakeWire.Add( anEdgRight );
281 anEdgRight = aMakeWire.Edge();
283 TopoDS_Wire aSectProfileWire;
284 if(aMakeWire.IsDone())
285 aSectProfileWire = aMakeWire.Wire();
287 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
290 if( aMakeFace.IsDone() )
291 aFace = aMakeFace.Face();
294 aBB.MakeCompound(aCmp);
296 for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
297 aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
303 BRepTools::Write(aCmp, "str2d.brep");
308 // Create the stream groups
309 QString aLeftGroupName = GetName() + "_Left_Bank";
311 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
312 aLeftGroup->SetName( aLeftGroupName );
313 aLeftGroup->AddShape( anEdgLeft );
315 QString aRightGroupName = GetName() + "_Right_Bank";
317 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
318 aRightGroup->SetName( aRightGroupName );
319 aRightGroup->AddShape( anEdgRight );
321 QString anInGroupName = GetName() + "_Inlet";
323 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
324 anInGroup->SetName( anInGroupName );
325 anInGroup->AddShape( aBotEdge );
327 QString anOutGroupName = GetName() + "_Outlet";
329 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
330 anOutGroup->SetName( anOutGroupName );
331 anOutGroup->AddShape( aTopEdge );
333 // This peace of code is for testing of functionality of altitude,
334 // will be removed by adv when testing will be finished
335 Handle(HYDROData_IAltitudeObject) anAltObj = GetAltitudeObject();
336 gp_XY aTestPnt( 5, 0 );
337 anAltObj->GetAltitudeForPoint( aTestPnt );
342 QColor HYDROData_Stream::DefaultFillingColor()
344 return QColor( Qt::green );
347 QColor HYDROData_Stream::DefaultBorderColor()
349 return QColor( Qt::transparent );
352 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
354 if ( theHydAxis.IsNull() )
357 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
358 if ( aHydraulicShape.IsNull() ||
359 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
360 BRep_Tool::IsClosed( aHydraulicShape ) )
361 return false; // The polyline must be a single not closed wire
366 TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
367 const int theGroupId )
369 TopoDS_Shape aResShape;
370 if ( theGroups.Length() != 4 )
373 Handle(HYDROData_ShapesGroup) aGroup =
374 Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
375 if ( aGroup.IsNull() )
378 TopTools_SequenceOfShape aGroupShapes;
379 aGroup->GetShapes( aGroupShapes );
381 if ( !aGroupShapes.IsEmpty() )
382 aResShape = aGroupShapes.First();
387 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
389 HYDROData_SequenceOfObjects aGroups = GetGroups();
390 return getShapeFromGroup( aGroups, 1 );
393 TopoDS_Shape HYDROData_Stream::GetRightShape() const
395 HYDROData_SequenceOfObjects aGroups = GetGroups();
396 return getShapeFromGroup( aGroups, 2 );
399 TopoDS_Shape HYDROData_Stream::GetInletShape() const
401 HYDROData_SequenceOfObjects aGroups = GetGroups();
402 return getShapeFromGroup( aGroups, 3 );
405 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
407 HYDROData_SequenceOfObjects aGroups = GetGroups();
408 return getShapeFromGroup( aGroups, 4 );
411 QColor HYDROData_Stream::getDefaultFillingColor() const
413 return DefaultFillingColor();
416 QColor HYDROData_Stream::getDefaultBorderColor() const
418 return DefaultBorderColor();
421 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
423 if ( !IsValidAsAxis( theAxis ) )
426 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
427 if ( IsEqual( aPrevAxis, theAxis ) )
430 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
432 // Update the order of profiles
433 updateProfilesOrder();
435 // Indicate model of the need to update the stream presentation
441 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
443 return Handle(HYDROData_PolylineXY)::DownCast(
444 GetReferenceObject( DataTag_HydraulicAxis ) );
447 void HYDROData_Stream::RemoveHydraulicAxis()
449 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
450 if ( aPrevAxis.IsNull() )
453 ClearReferenceObjects( DataTag_HydraulicAxis );
455 // We remove the reference profiles
458 // Indicate model of the need to update the stream presentation
462 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
463 const Handle(HYDROData_Profile)& theProfile,
464 const TopoDS_Face& thePlane,
465 Standard_Real& outPar)
467 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
470 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
471 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
472 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
475 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
476 if(!aProjector.IsDone())
478 TopoDS_Shape aPrjProfile = aProjector.Shape();
479 if(aPrjProfile.IsNull())
481 TopoDS_Vertex aV1, aV2;
482 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
483 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
484 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
485 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
486 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
487 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
489 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
491 anExp.Init(aPrjProfile, TopAbs_EDGE);
493 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
497 if(aV1.IsNull() || aV2.IsNull())
499 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
500 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
503 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
506 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
507 Standard_Integer aNum(0);
509 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
510 for(;anExplo.More();anExplo.Next()) aNum++;
511 // check for self-intersection
512 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
513 Standard_Boolean hasInt(false);
514 Standard_Real aSqDist(DBL_MAX);
515 Standard_Integer anIndx(0);
516 BRepExtrema_ExtCC aCC;
517 aCC.Initialize(anEdg2);
519 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
520 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
521 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
524 Standard_Boolean hasSol(false);
528 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
529 if(aCC.SquareDistance(i) < aSqDist) {
530 aSqDist = aCC.SquareDistance(i);
536 if(aSqDist <= SquareTolerance) { // hasInt
537 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
539 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
540 outPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
542 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
550 TopExp::Vertices(anEdg1, aV1, aV2);
551 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
554 } else if(aNum > 1) {
555 TopExp::Vertices(anEdg1, aV1, aV2);
556 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
564 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
565 Standard_Real& outPar ) const
567 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
569 return HasIntersection( aHydAxis, theProfile, thePlane, outPar );
573 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
575 if ( theProfile.IsNull() )
578 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
579 if ( aHydAxis.IsNull() )
583 if(!BuildFace(aHydAxis, aPlane))
586 Standard_Real aPar(.0);
587 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
588 return false; // Object is already in reference list or it has no intersection
590 int aProfileIndex = insertParameter( aPar );
591 insertProfileInToOrder( theProfile, aProfileIndex );
593 // Indicate model of the need to update the stream presentation
599 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
601 return GetReferenceObjects( DataTag_Profile );
604 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
606 if ( theProfile.IsNull() )
609 int aProfileIndex = -1;
611 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
612 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
613 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
615 Handle(HYDROData_Profile) aProfile =
616 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
617 if ( aProfile.IsNull() )
620 if ( IsEqual( theProfile, aProfile ) )
627 if ( aProfileIndex == -1 )
630 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
632 // Remove parameter for removed profile
633 removeParameter( aProfileIndex );
635 // Indicate model of the need to update the stream presentation
641 void HYDROData_Stream::RemoveProfiles()
643 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
645 ClearReferenceObjects( DataTag_Profile );
647 // Remove the parameters array
648 removeParametersArray();
650 // Indicate model of the need to update the stream presentation
651 SetToUpdate( anIsToUpdate );
654 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
655 const int theBeforeIndex )
657 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
658 if ( theProfile.IsNull() || aHydAxis.IsNull() )
661 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
662 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
663 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
666 if ( theBeforeIndex == -1 )
667 AddReferenceObject( theProfile, DataTag_Profile );
669 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
672 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
673 TopoDS_Face& thePlane ) const
675 if ( !IsValidAsAxis( theHydAxis ) )
678 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
680 gp_Ax2 aX2(gp::XOY());
684 BRepBndLib::Add(aHydraulicWire,B);
685 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
686 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
687 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
688 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
689 thePlane = TopoDS::Face(aMkr.Shape());
693 void HYDROData_Stream::updateProfilesOrder()
695 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
696 if ( aRefProfiles.IsEmpty() )
699 // At first we remove all profiles from order
702 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
703 if ( aHydAxis.IsNull() )
707 if ( !BuildFace( aHydAxis, aPlane ) )
710 Standard_Real aPar( .0 );
714 TopoDS_Compound aCmp;
715 aBB.MakeCompound(aCmp);
718 HYDROData_DataMapOfRealOfHDProfile aDM;
719 TColStd_ListOfReal aList;
720 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
721 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
723 Handle(HYDROData_Profile) aProfile =
724 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
726 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
727 aBB.Add( aCmp, aProfileWire );
729 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
732 aDM.Bind( aPar, aProfile );
733 aList.Append( aPar );
736 if ( aList.IsEmpty() )
739 TColStd_Array1OfReal anArr( 1, aList.Extent() );
741 TColStd_ListIteratorOfListOfReal it( aList );
742 for ( int j = 1; it.More(); it.Next(), j++ )
743 anArr( j ) = it.Value();
746 if ( aList.Extent() > 1 )
748 TCollection_CompareOfReal Compar;
749 SortTools_QuickSortOfReal::Sort( anArr, Compar );
751 for (int j = 1; j <= anArr.Length(); j++) {
752 const Standard_Real aKey = anArr(j);
753 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
754 insertProfileInToOrder( aProfile );
756 } else if ( aList.Extent() == 1 ) {
757 const Standard_Real aKey = aList.Last();
758 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
759 insertProfileInToOrder( aProfile );
762 setParametersArray( anArr );
765 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
766 BRepTools::Write(aHydraulicWire, "Path.brep");
767 BRepTools::Write(aCmp, "Prof.brep");
771 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
773 return KIND_STREAM_ALTITUDE;
776 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
778 if ( theArray.Length() == 0 )
780 removeParametersArray();
784 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
786 Handle(TDataStd_RealArray) aParamsArray =
787 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
789 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
791 const Standard_Real& aParam = theArray( i );
792 aParamsArray->SetValue( i, aParam );
796 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
798 TColStd_Array1OfReal* anArray = NULL;
800 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
801 if ( !aLabel.IsNull() )
803 Handle(TDataStd_RealArray) aParamsArray;
804 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
806 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
807 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
809 const Standard_Real& aParam = aParamsArray->Value( i );
810 anArray->SetValue( i, aParam );
818 void HYDROData_Stream::removeParametersArray()
820 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
821 if ( !aLabel.IsNull() )
822 aLabel.ForgetAllAttributes();
825 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
829 TColStd_Array1OfReal* anArr = getParametersArray();
834 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
836 bool isInserted = false;
837 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
839 const Standard_Real& aStoredParam = anArr->Value( i );
842 if ( theParam > aStoredParam )
848 aNewArr( j ) = theParam;
854 aNewArr( j ) = aStoredParam;
860 aNewArr( aNewArr.Upper() ) = theParam;
863 setParametersArray( aNewArr );
868 TColStd_Array1OfReal aNewArr( 1, 1 );
869 aNewArr.SetValue( 1, theParam );
870 setParametersArray( aNewArr );
876 void HYDROData_Stream::removeParameter( const int& theIndex )
878 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
879 if ( aLabel.IsNull() )
882 Handle(TDataStd_RealArray) aParamsArray;
883 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
886 if ( aParamsArray->Length() == 1 )
888 removeParametersArray();
892 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
894 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
896 const Standard_Real& aStoredParam = aParamsArray->Value( i );
900 aNewArr.SetValue( j, aStoredParam );
904 setParametersArray( aNewArr );