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 bool HYDROData_Stream::IsHas2dPrs() const
154 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis,
155 const HYDROData_SequenceOfObjects& theProfiles,
156 PrsDefinition& thePrs )
158 if ( theHydAxis.IsNull() || theProfiles.Length() < 2 )
161 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
162 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
163 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
164 TopTools_Array1OfShape anArrOfProfiles(1, theProfiles.Length());
165 TopTools_Array1OfShape anArrOf2DProfiles(1, theProfiles.Length());
168 HYDROData_SequenceOfObjects::Iterator anIter( theProfiles );
169 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
171 Handle(HYDROData_Profile) aProfile =
172 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
173 if ( aProfile.IsNull() )
176 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
178 if ( !aProfile->GetLeftPoint( aPnt1, false ) || !aProfile->GetRightPoint( aPnt2, false ) )
181 anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
182 anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
184 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
185 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
186 TopoDS_Vertex aV1, aV2;
187 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
188 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
189 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
193 aP1 = BRep_Tool::Pnt(aV2);
194 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
198 anArrayOfFPnt->SetValue(i,aCurFP);
199 anArrayOfLPnt->SetValue(i,aCurLP);
202 // Construct of the 3D presentation
203 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
204 if(aBSpline.IsNull())
207 TopoDS_Edge anEdgLeft, anEdgRight;
209 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
210 if(aMakeEdge.IsDone())
211 anEdgLeft = aMakeEdge.Edge();
213 if(anEdgLeft.IsNull())
217 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
218 if(aBSpline.IsNull())
221 aMakeEdge.Init(aBSpline);
222 if(aMakeEdge.IsDone())
223 anEdgRight = aMakeEdge.Edge();
225 if(anEdgRight.IsNull())
229 TopoDS_Compound aCmp;
230 aBB.MakeCompound(aCmp);
231 anIter.Init( theProfiles );
232 for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )
233 aBB.Add(aCmp, anArrOfProfiles.Value(i));
235 aBB.Add(aCmp,anEdgLeft);
236 aBB.Add(aCmp,anEdgRight);
237 BRepCheck_Analyzer aCh(aCmp);
239 thePrs.myPrs3D = aCmp;
242 BRepTools::Write(aCmp, "str3d.brep");
243 thePrs.myPrs3D = aCmp;
247 // Construct the top presentation
248 for(int i=1;i<= anArrayOfLPnt->Length();i++) {
249 gp_Pnt aPnt = anArrayOfFPnt->Value(i);
250 aPnt.SetZ(.0); // make 2d
251 anArrayOfFPnt->SetValue(i, aPnt);
252 aPnt = anArrayOfLPnt->Value(i);
254 anArrayOfLPnt->SetValue(i, aPnt);
258 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
259 if(aBSpline.IsNull())
262 aMakeEdge.Init(aBSpline);
263 if(aMakeEdge.IsDone())
264 anEdgLeft = aMakeEdge.Edge();
267 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
268 if(aBSpline.IsNull())
271 aMakeEdge.Init(aBSpline);
272 if(aMakeEdge.IsDone())
273 anEdgRight = aMakeEdge.Edge();
274 if(anEdgRight.IsNull())
277 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
278 TopoDS_Edge aBotEdge, aTopEdge;
279 if(aMakeEdge2.IsDone())
280 aBotEdge = aMakeEdge2.Edge();
282 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
283 if(aMakeEdge3.IsDone())
284 aTopEdge = aMakeEdge3.Edge();
286 // Make wire for 2D presentation with updating of corresponding edges
287 BRepBuilderAPI_MakeWire aMakeWire;
289 aMakeWire.Add( aBotEdge );
290 thePrs.myInlet = aMakeWire.Edge();
292 aMakeWire.Add( anEdgLeft );
293 thePrs.myLeftBank = aMakeWire.Edge();
295 aMakeWire.Add( aTopEdge );
296 thePrs.myOutlet = aMakeWire.Edge();
298 aMakeWire.Add( anEdgRight );
299 thePrs.myRightBank = aMakeWire.Edge();
301 TopoDS_Wire aSectProfileWire;
302 if(aMakeWire.IsDone())
303 aSectProfileWire = aMakeWire.Wire();
305 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
308 if( aMakeFace.IsDone() )
309 aFace = aMakeFace.Face();
312 aBB.MakeCompound(aCmp);
314 for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
315 aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
319 thePrs.myPrs2D = aCmp;
322 BRepTools::Write(aCmp, "str2d.brep");
323 thePrs.myPrs2D = aCmp;
330 void HYDROData_Stream::UpdatePrs()
332 HYDROData_NaturalObject::Update();
334 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
335 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
337 PrsDefinition aResultPrs;
338 if ( !CreatePresentations( aHydAxis, aRefProfiles, aResultPrs ) )
341 SetShape3D( aResultPrs.myPrs3D );
342 SetTopShape( aResultPrs.myPrs2D );
344 // Create the stream groups
345 QString aLeftGroupName = GetName() + "_Left_Bank";
347 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
348 aLeftGroup->SetName( aLeftGroupName );
349 aLeftGroup->AddShape( aResultPrs.myLeftBank );
351 QString aRightGroupName = GetName() + "_Right_Bank";
353 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
354 aRightGroup->SetName( aRightGroupName );
355 aRightGroup->AddShape( aResultPrs.myRightBank );
357 QString anInGroupName = GetName() + "_Inlet";
359 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
360 anInGroup->SetName( anInGroupName );
361 anInGroup->AddShape( aResultPrs.myInlet );
363 QString anOutGroupName = GetName() + "_Outlet";
365 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
366 anOutGroup->SetName( anOutGroupName );
367 anOutGroup->AddShape( aResultPrs.myOutlet );
370 QColor HYDROData_Stream::DefaultFillingColor()
372 return QColor( Qt::green );
375 QColor HYDROData_Stream::DefaultBorderColor()
377 return QColor( Qt::transparent );
380 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
382 if ( theHydAxis.IsNull() )
385 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
386 if ( aHydraulicShape.IsNull() ||
387 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
388 BRep_Tool::IsClosed( aHydraulicShape ) )
389 return false; // The polyline must be a single not closed wire
394 TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
395 const int theGroupId )
397 TopoDS_Shape aResShape;
398 if ( theGroups.Length() != 4 )
401 Handle(HYDROData_ShapesGroup) aGroup =
402 Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
403 if ( aGroup.IsNull() )
406 TopTools_SequenceOfShape aGroupShapes;
407 aGroup->GetShapes( aGroupShapes );
409 if ( !aGroupShapes.IsEmpty() )
410 aResShape = aGroupShapes.First();
415 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
417 HYDROData_SequenceOfObjects aGroups = GetGroups();
418 return getShapeFromGroup( aGroups, 1 );
421 TopoDS_Shape HYDROData_Stream::GetRightShape() const
423 HYDROData_SequenceOfObjects aGroups = GetGroups();
424 return getShapeFromGroup( aGroups, 2 );
427 TopoDS_Shape HYDROData_Stream::GetInletShape() const
429 HYDROData_SequenceOfObjects aGroups = GetGroups();
430 return getShapeFromGroup( aGroups, 3 );
433 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
435 HYDROData_SequenceOfObjects aGroups = GetGroups();
436 return getShapeFromGroup( aGroups, 4 );
439 QColor HYDROData_Stream::getDefaultFillingColor() const
441 return DefaultFillingColor();
444 QColor HYDROData_Stream::getDefaultBorderColor() const
446 return DefaultBorderColor();
449 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
451 if ( !IsValidAsAxis( theAxis ) )
454 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
455 if ( IsEqual( aPrevAxis, theAxis ) )
458 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
460 // Update the order of profiles
461 updateProfilesOrder();
463 // Indicate model of the need to update the stream presentation
469 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
471 return Handle(HYDROData_PolylineXY)::DownCast(
472 GetReferenceObject( DataTag_HydraulicAxis ) );
475 void HYDROData_Stream::RemoveHydraulicAxis()
477 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
478 if ( aPrevAxis.IsNull() )
481 ClearReferenceObjects( DataTag_HydraulicAxis );
483 // We remove the reference profiles
486 // Indicate model of the need to update the stream presentation
490 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
491 const TopoDS_Face& thePlane,
492 Standard_Real& theOutPar ) const
494 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
495 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
498 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
499 const Handle(HYDROData_Profile)& theProfile,
500 const TopoDS_Face& thePlane,
501 Standard_Real& theOutPar )
503 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
506 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
507 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
508 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
511 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
512 if(!aProjector.IsDone())
514 TopoDS_Shape aPrjProfile = aProjector.Shape();
515 if(aPrjProfile.IsNull())
517 TopoDS_Vertex aV1, aV2;
518 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
519 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
520 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
521 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
522 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
523 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
525 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
527 anExp.Init(aPrjProfile, TopAbs_EDGE);
529 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
533 if(aV1.IsNull() || aV2.IsNull())
535 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
536 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
539 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
542 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
543 Standard_Integer aNum(0);
545 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
546 for(;anExplo.More();anExplo.Next()) aNum++;
547 // check for self-intersection
548 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
549 Standard_Boolean hasInt(false);
550 Standard_Real aSqDist(DBL_MAX);
551 Standard_Integer anIndx(0);
552 BRepExtrema_ExtCC aCC;
553 aCC.Initialize(anEdg2);
555 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
556 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
557 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
560 Standard_Boolean hasSol(false);
564 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
565 if(aCC.SquareDistance(i) < aSqDist) {
566 aSqDist = aCC.SquareDistance(i);
572 if(aSqDist <= SquareTolerance) { // hasInt
573 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
575 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
576 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
578 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
586 TopExp::Vertices(anEdg1, aV1, aV2);
587 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
590 } else if(aNum > 1) {
591 TopExp::Vertices(anEdg1, aV1, aV2);
592 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
600 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
602 if ( theProfile.IsNull() )
605 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
606 if ( aHydAxis.IsNull() )
610 if(!BuildFace(aHydAxis, aPlane))
613 Standard_Real aPar(.0);
614 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
615 return false; // Object is already in reference list or it has no intersection
617 int aProfileIndex = insertParameter( aPar );
618 insertProfileInToOrder( theProfile, aProfileIndex );
620 // Indicate model of the need to update the stream presentation
626 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
627 const bool& theIsToOrder )
631 for ( int i = 1; i <= theProfiles.Length(); ++i )
633 Handle(HYDROData_Profile) aProfile =
634 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
635 if ( aProfile.IsNull() )
638 if ( !AddProfile( aProfile ) )
642 else // Just store the sequence of objects as is
644 bool anIsToUpdate = true;
646 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
647 if ( anOldProfiles.Length() == theProfiles.Length() )
649 anIsToUpdate = false;
651 for ( int i = 1; i <= theProfiles.Length(); ++i )
653 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
654 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
655 if ( !IsEqual( anOldProfile, aNewProfile ) )
663 SetReferenceObjects( theProfiles, DataTag_Profile );
672 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
674 return GetReferenceObjects( DataTag_Profile );
677 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
679 if ( theProfile.IsNull() )
682 int aProfileIndex = -1;
684 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
685 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
686 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
688 Handle(HYDROData_Profile) aProfile =
689 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
690 if ( aProfile.IsNull() )
693 if ( IsEqual( theProfile, aProfile ) )
700 if ( aProfileIndex == -1 )
703 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
705 // Remove parameter for removed profile
706 removeParameter( aProfileIndex );
708 // Indicate model of the need to update the stream presentation
714 void HYDROData_Stream::RemoveProfiles()
716 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
718 ClearReferenceObjects( DataTag_Profile );
720 // Remove the parameters array
721 removeParametersArray();
723 // Indicate model of the need to update the stream presentation
724 SetToUpdate( anIsToUpdate );
727 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
728 const int theBeforeIndex )
730 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
731 if ( theProfile.IsNull() || aHydAxis.IsNull() )
734 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
735 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
736 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
739 if ( theBeforeIndex == -1 )
740 AddReferenceObject( theProfile, DataTag_Profile );
742 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
745 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
746 TopoDS_Face& thePlane )
748 if ( !IsValidAsAxis( theHydAxis ) )
751 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
753 gp_Ax2 aX2(gp::XOY());
757 BRepBndLib::Add(aHydraulicWire,B);
758 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
759 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
760 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
761 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
762 thePlane = TopoDS::Face(aMkr.Shape());
766 void HYDROData_Stream::updateProfilesOrder()
768 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
769 if ( aRefProfiles.IsEmpty() )
772 // At first we remove all profiles from order
775 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
776 if ( aHydAxis.IsNull() )
780 if ( !BuildFace( aHydAxis, aPlane ) )
783 Standard_Real aPar( .0 );
787 TopoDS_Compound aCmp;
788 aBB.MakeCompound(aCmp);
791 HYDROData_DataMapOfRealOfHDProfile aDM;
792 TColStd_ListOfReal aList;
793 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
794 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
796 Handle(HYDROData_Profile) aProfile =
797 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
799 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
800 aBB.Add( aCmp, aProfileWire );
802 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
805 aDM.Bind( aPar, aProfile );
806 aList.Append( aPar );
809 if ( aList.IsEmpty() )
812 TColStd_Array1OfReal anArr( 1, aList.Extent() );
814 TColStd_ListIteratorOfListOfReal it( aList );
815 for ( int j = 1; it.More(); it.Next(), j++ )
816 anArr( j ) = it.Value();
819 if ( aList.Extent() > 1 )
821 TCollection_CompareOfReal Compar;
822 SortTools_QuickSortOfReal::Sort( anArr, Compar );
824 for (int j = 1; j <= anArr.Length(); j++) {
825 const Standard_Real aKey = anArr(j);
826 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
827 insertProfileInToOrder( aProfile );
829 } else if ( aList.Extent() == 1 ) {
830 const Standard_Real aKey = aList.Last();
831 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
832 insertProfileInToOrder( aProfile );
835 setParametersArray( anArr );
838 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
839 BRepTools::Write(aHydraulicWire, "Path.brep");
840 BRepTools::Write(aCmp, "Prof.brep");
844 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
846 return KIND_STREAM_ALTITUDE;
849 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
851 if ( theArray.Length() == 0 )
853 removeParametersArray();
857 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
859 Handle(TDataStd_RealArray) aParamsArray =
860 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
862 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
864 const Standard_Real& aParam = theArray( i );
865 aParamsArray->SetValue( i, aParam );
869 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
871 TColStd_Array1OfReal* anArray = NULL;
873 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
874 if ( !aLabel.IsNull() )
876 Handle(TDataStd_RealArray) aParamsArray;
877 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
879 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
880 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
882 const Standard_Real& aParam = aParamsArray->Value( i );
883 anArray->SetValue( i, aParam );
891 void HYDROData_Stream::removeParametersArray()
893 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
894 if ( !aLabel.IsNull() )
895 aLabel.ForgetAllAttributes();
898 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
902 TColStd_Array1OfReal* anArr = getParametersArray();
907 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
909 bool isInserted = false;
910 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
912 const Standard_Real& aStoredParam = anArr->Value( i );
915 if ( theParam > aStoredParam )
921 aNewArr( j ) = theParam;
927 aNewArr( j ) = aStoredParam;
933 aNewArr( aNewArr.Upper() ) = theParam;
936 setParametersArray( aNewArr );
941 TColStd_Array1OfReal aNewArr( 1, 1 );
942 aNewArr.SetValue( 1, theParam );
943 setParametersArray( aNewArr );
949 void HYDROData_Stream::removeParameter( const int& theIndex )
951 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
952 if ( aLabel.IsNull() )
955 Handle(TDataStd_RealArray) aParamsArray;
956 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
959 if ( aParamsArray->Length() == 1 )
961 removeParametersArray();
965 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
967 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
969 const Standard_Real& aStoredParam = aParamsArray->Value( i );
973 aNewArr.SetValue( j, aStoredParam );
977 setParametersArray( aNewArr );