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 updateProfilesOrder();
150 QColor HYDROData_Stream::DefaultFillingColor()
152 return QColor( Qt::green );
155 QColor HYDROData_Stream::DefaultBorderColor()
157 return QColor( Qt::transparent );
160 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
162 if ( theHydAxis.IsNull() )
165 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
166 if ( aHydraulicShape.IsNull() ||
167 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
168 BRep_Tool::IsClosed( aHydraulicShape ) )
169 return false; // The polyline must be a single not closed wire
174 QColor HYDROData_Stream::getDefaultFillingColor() const
176 return DefaultFillingColor();
179 QColor HYDROData_Stream::getDefaultBorderColor() const
181 return DefaultBorderColor();
184 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
186 if ( !IsValidAsAxis( theAxis ) )
189 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
190 if ( IsEqual( aPrevAxis, theAxis ) )
193 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
195 // Update the order of profiles
196 updateProfilesOrder();
198 // Indicate model of the need to update the stream presentation
204 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
206 return Handle(HYDROData_PolylineXY)::DownCast(
207 GetReferenceObject( DataTag_HydraulicAxis ) );
210 void HYDROData_Stream::RemoveHydraulicAxis()
212 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
213 if ( aPrevAxis.IsNull() )
216 ClearReferenceObjects( DataTag_HydraulicAxis );
218 // We remove the reference profiles
221 // Indicate model of the need to update the stream presentation
225 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
226 const Handle(HYDROData_Profile)& theProfile,
227 const TopoDS_Face& thePlane,
228 Standard_Real& outPar)
230 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
233 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
234 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
235 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
238 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
239 if(!aProjector.IsDone())
241 TopoDS_Shape aPrjProfile = aProjector.Shape();
242 if(aPrjProfile.IsNull())
244 TopoDS_Vertex aV1, aV2;
245 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
246 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
247 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
248 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
249 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
250 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
252 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
254 anExp.Init(aPrjProfile, TopAbs_EDGE);
256 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
260 if(aV1.IsNull() || aV2.IsNull())
262 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
263 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
266 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
269 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
270 Standard_Integer aNum(0);
272 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
273 for(;anExplo.More();anExplo.Next()) aNum++;
274 // check for self-intersection
275 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
276 Standard_Boolean hasInt(false);
277 Standard_Real aSqDist(DBL_MAX);
278 Standard_Integer anIndx(0);
279 BRepExtrema_ExtCC aCC;
280 aCC.Initialize(anEdg2);
282 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
283 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
284 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
287 Standard_Boolean hasSol(false);
291 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
292 if(aCC.SquareDistance(i) < aSqDist) {
293 aSqDist = aCC.SquareDistance(i);
299 if(aSqDist <= SquareTolerance) { // hasInt
300 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
302 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
303 outPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
305 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
313 TopExp::Vertices(anEdg1, aV1, aV2);
314 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
317 } else if(aNum > 1) {
318 TopExp::Vertices(anEdg1, aV1, aV2);
319 outPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
327 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile, const TopoDS_Face& thePlane,
328 Standard_Real& outPar ) const
330 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
332 return HasIntersection( aHydAxis, theProfile, thePlane, outPar );
336 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
338 if ( theProfile.IsNull() )
341 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
342 if ( aHydAxis.IsNull() )
346 if(!BuildFace(aHydAxis, aPlane))
349 Standard_Real aPar(.0);
350 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
351 return false; // Object is already in reference list or it has no intersection
353 int aProfileIndex = insertParameter( aPar );
354 insertProfileInToOrder( theProfile, aProfileIndex );
356 // Indicate model of the need to update the stream presentation
362 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
364 return GetReferenceObjects( DataTag_Profile );
367 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
369 if ( theProfile.IsNull() )
372 int aProfileIndex = -1;
374 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
375 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
376 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
378 Handle(HYDROData_Profile) aProfile =
379 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
380 if ( aProfile.IsNull() )
383 if ( IsEqual( theProfile, aProfile ) )
390 if ( aProfileIndex == -1 )
393 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
395 // Remove parameter for removed profile
396 removeParameter( aProfileIndex );
398 // Indicate model of the need to update the stream presentation
404 void HYDROData_Stream::RemoveProfiles()
406 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
408 ClearReferenceObjects( DataTag_Profile );
410 // Remove the parameters array
411 removeParametersArray();
413 // Indicate model of the need to update the stream presentation
414 SetToUpdate( anIsToUpdate );
417 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
418 const int theBeforeIndex )
420 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
421 if ( theProfile.IsNull() || aHydAxis.IsNull() )
424 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
425 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
426 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
429 if ( theBeforeIndex == -1 )
430 AddReferenceObject( theProfile, DataTag_Profile );
432 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
435 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
436 TopoDS_Face& thePlane ) const
438 if ( !IsValidAsAxis( theHydAxis ) )
441 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
443 gp_Ax2 aX2(gp::XOY());
447 BRepBndLib::Add(aHydraulicWire,B);
448 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
449 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
450 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
451 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
452 thePlane = TopoDS::Face(aMkr.Shape());
456 void HYDROData_Stream::updateProfilesOrder()
458 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
459 if ( aRefProfiles.IsEmpty() )
462 // At first we remove all profiles from order
465 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
466 if ( aHydAxis.IsNull() )
470 if ( !BuildFace( aHydAxis, aPlane ) )
473 Standard_Real aPar( .0 );
477 TopoDS_Compound aCmp;
478 aBB.MakeCompound(aCmp);
481 HYDROData_DataMapOfRealOfHDProfile aDM;
482 TColStd_ListOfReal aList;
483 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
484 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
486 Handle(HYDROData_Profile) aProfile =
487 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
489 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
490 aBB.Add( aCmp, aProfileWire );
492 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
495 aDM.Bind( aPar, aProfile );
496 aList.Append( aPar );
499 if ( aList.IsEmpty() )
502 TColStd_Array1OfReal anArr( 1, aList.Extent() );
504 TColStd_ListIteratorOfListOfReal it( aList );
505 for ( int j = 1; it.More(); it.Next(), j++ )
506 anArr( j ) = it.Value();
509 if ( aList.Extent() > 1 )
511 TCollection_CompareOfReal Compar;
512 SortTools_QuickSortOfReal::Sort( anArr, Compar );
514 for (int j = 1; j <= anArr.Length(); j++) {
515 const Standard_Real aKey = anArr(j);
516 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
517 insertProfileInToOrder( aProfile );
519 } else if ( aList.Extent() == 1 ) {
520 const Standard_Real aKey = aList.Last();
521 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
522 insertProfileInToOrder( aProfile );
525 setParametersArray( anArr );
528 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
529 BRepTools::Write(aHydraulicWire, "Path.brep");
530 BRepTools::Write(aCmp, "Prof.brep");
534 void HYDROData_Stream::createGroupObjects()
536 TopoDS_Shape aStreamShape = GetTopShape();
537 if ( aStreamShape.IsNull() )
540 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
541 if ( aRefProfiles.Length() < 2 )
544 Handle(HYDROData_Profile) aFirstProfile =
545 Handle(HYDROData_Profile)::DownCast( aRefProfiles.First() );
546 Handle(HYDROData_Profile) aLastProfile =
547 Handle(HYDROData_Profile)::DownCast( aRefProfiles.Last() );
548 if ( aFirstProfile.IsNull() || aLastProfile.IsNull() )
551 TopoDS_Shape aBotEdgeShape = aFirstProfile->GetTopShape();
552 TopoDS_Shape aTopEdgeShape = aLastProfile->GetTopShape();
553 if ( aBotEdgeShape.IsNull() || aBotEdgeShape.ShapeType() != TopAbs_WIRE ||
554 aTopEdgeShape.IsNull() || aTopEdgeShape.ShapeType() != TopAbs_WIRE )
557 TopExp_Explorer aBotEdgeShapeExp( aBotEdgeShape, TopAbs_EDGE );
558 TopExp_Explorer aTopEdgeShapeExp( aTopEdgeShape, TopAbs_EDGE );
559 if ( !aBotEdgeShapeExp.More() || !aTopEdgeShapeExp.More() )
562 TopoDS_Edge aBotEdge = TopoDS::Edge( aBotEdgeShapeExp.Current() );
563 TopoDS_Edge aTopEdge = TopoDS::Edge( aTopEdgeShapeExp.Current() );
565 TopoDS_Vertex aBotFirstVert, aBotLastVert, aTopFirstVert, aTopLastVert;
566 TopExp::Vertices( aBotEdge, aBotFirstVert, aBotLastVert, true );
567 TopExp::Vertices( aTopEdge, aTopFirstVert, aTopLastVert, true );
569 TopExp_Explorer aStreamFaceExp( aStreamShape, TopAbs_FACE );
570 if ( !aStreamFaceExp.More() )
573 // Get only face because of 2d profile wires is in compound
574 TopoDS_Face aStreamFace = TopoDS::Face( aStreamFaceExp.Current() );
576 TopTools_SequenceOfShape aStreamWires;
577 HYDROData_ShapesTool::ExploreShapeToShapes( aStreamFace, TopAbs_EDGE, aStreamWires );
579 bool anIsLeft = false;
580 bool anIsRight = false;
582 TopTools_SequenceOfShape aLeftEdges, aRightEdges;
583 for ( int i = 1, n = aStreamWires.Length(); i <= n; ++i )
585 TopoDS_Edge anEdge = TopoDS::Edge( aStreamWires.Value( i ) );
586 if ( HYDROData_ShapesTool::IsEdgesEquals( anEdge, aBotEdge ) ||
587 HYDROData_ShapesTool::IsEdgesEquals( anEdge, aTopEdge ) )
594 if ( !anIsLeft && !anIsRight )
596 TopoDS_Vertex anEdgeFirstVert, anEdgeLastVert;
597 TopExp::Vertices( anEdge, anEdgeFirstVert, anEdgeLastVert, true );
599 anIsLeft = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aBotFirstVert ) ||
600 HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aTopFirstVert );
602 anIsRight = HYDROData_ShapesTool::IsVerticesEquals( anEdgeFirstVert, aTopLastVert ) ||
603 HYDROData_ShapesTool::IsVerticesEquals( anEdgeLastVert, aBotLastVert );
608 aLeftEdges.Append( anEdge );
610 else if ( anIsRight )
612 aRightEdges.Append( anEdge );
616 // Create edges groups
617 QString aLeftGroupName = GetName() + "_Left_Bank";
619 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
620 aLeftGroup->SetName( aLeftGroupName );
621 aLeftGroup->SetShapes( aLeftEdges );
623 QString aRightGroupName = GetName() + "_Right_Bank";
625 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
626 aRightGroup->SetName( aRightGroupName );
627 aRightGroup->SetShapes( aRightEdges );
629 QString anInGroupName = GetName() + "_Inlet";
631 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
632 anInGroup->SetName( anInGroupName );
633 anInGroup->AddShape( aBotEdge );
635 QString anOutGroupName = GetName() + "_Outlet";
637 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
638 anOutGroup->SetName( anOutGroupName );
639 anOutGroup->AddShape( aTopEdge );
642 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
644 return KIND_STREAM_ALTITUDE;
647 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
649 if ( theArray.Length() == 0 )
651 removeParametersArray();
655 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
657 Handle(TDataStd_RealArray) aParamsArray =
658 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
660 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
662 const Standard_Real& aParam = theArray( i );
663 aParamsArray->SetValue( i, aParam );
667 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
669 TColStd_Array1OfReal* anArray = NULL;
671 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
672 if ( !aLabel.IsNull() )
674 Handle(TDataStd_RealArray) aParamsArray;
675 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
677 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
678 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
680 const Standard_Real& aParam = aParamsArray->Value( i );
681 anArray->SetValue( i, aParam );
689 void HYDROData_Stream::removeParametersArray()
691 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
692 if ( !aLabel.IsNull() )
693 aLabel.ForgetAllAttributes();
696 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
700 TColStd_Array1OfReal* anArr = getParametersArray();
705 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
707 bool isInserted = false;
708 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
710 const Standard_Real& aStoredParam = anArr->Value( i );
713 if ( theParam > aStoredParam )
719 aNewArr( j ) = theParam;
725 aNewArr( j ) = aStoredParam;
731 aNewArr( aNewArr.Upper() ) = theParam;
734 setParametersArray( aNewArr );
739 TColStd_Array1OfReal aNewArr( 1, 1 );
740 aNewArr.SetValue( 1, theParam );
741 setParametersArray( aNewArr );
747 void HYDROData_Stream::removeParameter( const int& theIndex )
749 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
750 if ( aLabel.IsNull() )
753 Handle(TDataStd_RealArray) aParamsArray;
754 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
757 if ( aParamsArray->Length() == 1 )
759 removeParametersArray();
763 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
765 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
767 const Standard_Real& aStoredParam = aParamsArray->Value( i );
771 aNewArr.SetValue( j, aStoredParam );
775 setParametersArray( aNewArr );
778 void HYDROData_Stream::UpdatePrs()
780 HYDROData_NaturalObject::Update();
782 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
783 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
784 if ( aHydAxis.IsNull() || aRefProfiles.Length() < 2 )
787 bool anIsFirst = true;
788 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
789 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
790 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aRefProfiles.Length());
791 TopTools_Array1OfShape anArrOfProfiles(1, aRefProfiles.Length());
792 TopTools_Array1OfShape anArrOf2DProfiles(1, aRefProfiles.Length());
795 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
796 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
798 Handle(HYDROData_Profile) aProfile =
799 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
800 if ( aProfile.IsNull() )
802 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
804 if ( !aProfile->GetLeftPoint( aPnt1 ) || !aProfile->GetRightPoint( aPnt2 ) )
806 anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
807 anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
809 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
810 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
811 TopoDS_Vertex aV1, aV2;
812 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
813 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
814 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
818 aP1 = BRep_Tool::Pnt(aV2);
819 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
823 anArrayOfFPnt->SetValue(i,aCurFP);
824 anArrayOfLPnt->SetValue(i,aCurLP);
827 // Construct of the 3D presentation
828 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
829 if(aBSpline.IsNull())
831 TopoDS_Edge anEdgLeft, anEdgRight;
832 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
833 if(aMakeEdge.IsDone())
834 anEdgLeft = aMakeEdge.Edge();
835 if(anEdgLeft.IsNull())
838 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
839 if(aBSpline.IsNull())
841 aMakeEdge.Init(aBSpline);
842 if(aMakeEdge.IsDone())
843 anEdgRight = aMakeEdge.Edge();
844 if(anEdgRight.IsNull())
847 TopoDS_Compound aCmp;
848 aBB.MakeCompound(aCmp);
849 anIter.Init( aRefProfiles );
850 for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )
851 aBB.Add(aCmp, anArrOfProfiles.Value(i));
852 aBB.Add(aCmp,anEdgLeft);
853 aBB.Add(aCmp,anEdgRight);
854 BRepCheck_Analyzer aCh(aCmp);
859 BRepTools::Write(aCmp, "str3d.brep");
864 // Construct the top presentation
865 for(int i=1;i<= anArrayOfLPnt->Length();i++) {
866 gp_Pnt aPnt = anArrayOfFPnt->Value(i);
867 aPnt.SetZ(.0); // make 2d
868 anArrayOfFPnt->SetValue(i, aPnt);
869 aPnt = anArrayOfLPnt->Value(i);
871 anArrayOfLPnt->SetValue(i, aPnt);
874 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
875 if(aBSpline.IsNull())
877 aMakeEdge.Init(aBSpline);
878 if(aMakeEdge.IsDone())
879 anEdgLeft = aMakeEdge.Edge();
881 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
882 if(aBSpline.IsNull())
884 aMakeEdge.Init(aBSpline);
885 if(aMakeEdge.IsDone())
886 anEdgRight = aMakeEdge.Edge();
887 if(anEdgRight.IsNull())
889 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
890 TopoDS_Edge aBotEdge, aTopEdge;
891 if(aMakeEdge2.IsDone())
892 aBotEdge = aMakeEdge2.Edge();
893 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
894 if(aMakeEdge3.IsDone())
895 aTopEdge = aMakeEdge3.Edge();
897 BRepBuilderAPI_MakeWire aMakeWire( aBotEdge, anEdgLeft, aTopEdge,anEdgRight);
898 TopoDS_Wire aSectProfileWire;
899 if(aMakeWire.IsDone())
900 aSectProfileWire = aMakeWire.Wire();
901 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
904 if( aMakeFace.IsDone() )
905 aFace = aMakeFace.Face();
907 aBB.MakeCompound(aCmp);
909 for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
910 aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
916 BRepTools::Write(aCmp, "str2d.brep");
921 // Create the stream groups
922 createGroupObjects();