1 // Copyright (C) 2007-2015 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "HYDROData_Stream.h"
25 #include "HYDROData_Document.h"
26 #include "HYDROData_PolylineXY.h"
27 #include "HYDROData_Profile.h"
28 #include "HYDROData_ShapesGroup.h"
29 #include "HYDROData_ShapesTool.h"
30 #include "HYDROData_IAltitudeObject.h"
32 #include <TDataStd_RealArray.hxx>
34 #include <Precision.hxx>
36 #include <NCollection_DataMap.hxx>
38 #include <TColStd_Array1OfReal.hxx>
39 #include <TColStd_ListOfReal.hxx>
40 #include <TColStd_ListIteratorOfListOfReal.hxx>
41 #include <TCollection_CompareOfReal.hxx>
42 #include <TColgp_Array1OfPnt.hxx>
43 #include <TColgp_HArray1OfPnt.hxx>
46 #include <TopoDS_Wire.hxx>
47 #include <TopoDS_Shell.hxx>
48 #include <TopoDS_Face.hxx>
49 #include <TopoDS_Edge.hxx>
50 #include <TopoDS_Vertex.hxx>
52 #include <TopExp_Explorer.hxx>
54 #include <Bnd_Box.hxx>
56 #include <BRep_Builder.hxx>
57 #include <BRepBuilderAPI_MakeEdge.hxx>
58 #include <BRepBuilderAPI_MakeWire.hxx>
59 #include <BRepBuilderAPI_MakeFace.hxx>
61 #include <BRepBndLib.hxx>
62 #include <BRepProj_Projection.hxx>
63 #include <BRepExtrema_ExtCC.hxx>
64 #include <BRepCheck_Analyzer.hxx>
74 #include <GeomAPI_Interpolate.hxx>
75 #include <Geom_BSplineCurve.hxx>
77 #include <TopTools_Array1OfShape.hxx>
79 #include <SortTools_QuickSortOfReal.hxx>
82 #include <QStringList>
84 //#define DEB_STREAM 1
86 //#define DEB_HASINT 1
87 //#define DEB_UPDATE 1
88 #include <BRepTools.hxx>
89 #include <TCollection_AsciiString.hxx>
92 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
94 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
95 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
98 HYDROData_Stream::HYDROData_Stream()
99 : HYDROData_NaturalObject()
103 HYDROData_Stream::~HYDROData_Stream()
107 QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
109 QStringList aResList = dumpObjectCreation( theTreatedObjects );
110 QString aName = GetObjPyName();
112 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
113 setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
115 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
116 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
118 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
119 setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
122 aResList << QString( "" );
123 aResList << QString( "%1.Update();" ).arg( aName );
124 aResList << QString( "" );
129 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
131 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
133 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
134 if ( !aHydAxis.IsNull() )
135 aResSeq.Append( aHydAxis );
137 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
138 aResSeq.Append( aSeqOfProfiles );
143 TopoDS_Shape HYDROData_Stream::GetTopShape() const
145 return getTopShape();
148 TopoDS_Shape HYDROData_Stream::GetShape3D() const
153 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
154 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
156 Handle(Geom_BSplineCurve) aBSpline;
157 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
158 anInterpolator.Perform() ;
159 if (anInterpolator.IsDone())
160 aBSpline = anInterpolator.Curve();
164 void HYDROData_Stream::Update()
166 updateProfilesOrder();
170 bool HYDROData_Stream::IsHas2dPrs() const
175 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis,
176 const HYDROData_SequenceOfObjects& theProfiles,
177 PrsDefinition& thePrs )
179 if ( theHydAxis.IsNull() || theProfiles.Length() < 2 )
182 gp_Pnt aPrevFirstPoint, aPrevLastPoint;
183 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
184 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
185 TopTools_Array1OfShape anArrOfProfiles(1, theProfiles.Length());
186 TopTools_Array1OfShape anArrOf2DProfiles(1, theProfiles.Length());
189 HYDROData_SequenceOfObjects::Iterator anIter( theProfiles );
190 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
192 Handle(HYDROData_Profile) aProfile =
193 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
194 if ( aProfile.IsNull() )
197 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
199 if ( !aProfile->GetLeftPoint( aPnt1, false ) || !aProfile->GetRightPoint( aPnt2, false ) )
202 anArrOfProfiles.SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
203 anArrOf2DProfiles.SetValue(i,aProfile->GetTopShape());
205 gp_Pnt aCurFirstPoint( aPnt1.X(), aPnt1.Y(), 0 ), aCurFP;
206 gp_Pnt aCurLastPoint( aPnt2.X(), aPnt2.Y(), 0 ), aCurLP;
207 TopoDS_Vertex aV1, aV2;
208 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
209 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
210 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
214 aP1 = BRep_Tool::Pnt(aV2);
215 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
219 anArrayOfFPnt->SetValue(i,aCurFP);
220 anArrayOfLPnt->SetValue(i,aCurLP);
223 // Construct of the 3D presentation
224 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (anArrayOfFPnt);
225 if(aBSpline.IsNull())
228 TopoDS_Edge anEdgLeft, anEdgRight;
230 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
231 if(aMakeEdge.IsDone())
232 anEdgLeft = aMakeEdge.Edge();
234 if(anEdgLeft.IsNull())
238 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
239 if(aBSpline.IsNull())
242 aMakeEdge.Init(aBSpline);
243 if(aMakeEdge.IsDone())
244 anEdgRight = aMakeEdge.Edge();
246 if(anEdgRight.IsNull())
250 TopoDS_Compound aCmp;
251 aBB.MakeCompound(aCmp);
252 anIter.Init( theProfiles );
253 for (int i=1 ; i < anArrOfProfiles.Length() +1; i++ )
254 aBB.Add(aCmp, anArrOfProfiles.Value(i));
256 aBB.Add(aCmp,anEdgLeft);
257 aBB.Add(aCmp,anEdgRight);
258 BRepCheck_Analyzer aCh(aCmp);
260 thePrs.myPrs3D = aCmp;
263 BRepTools::Write(aCmp, "str3d.brep");
264 thePrs.myPrs3D = aCmp;
268 // Construct the top presentation
269 for(int i=1;i<= anArrayOfLPnt->Length();i++) {
270 gp_Pnt aPnt = anArrayOfFPnt->Value(i);
271 aPnt.SetZ(.0); // make 2d
272 anArrayOfFPnt->SetValue(i, aPnt);
273 aPnt = anArrayOfLPnt->Value(i);
275 anArrayOfLPnt->SetValue(i, aPnt);
279 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
280 if(aBSpline.IsNull())
283 aMakeEdge.Init(aBSpline);
284 if(aMakeEdge.IsDone())
285 anEdgLeft = aMakeEdge.Edge();
288 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
289 if(aBSpline.IsNull())
292 aMakeEdge.Init(aBSpline);
293 if(aMakeEdge.IsDone())
294 anEdgRight = aMakeEdge.Edge();
295 if(anEdgRight.IsNull())
298 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
299 TopoDS_Edge aBotEdge, aTopEdge;
300 if(aMakeEdge2.IsDone())
301 aBotEdge = aMakeEdge2.Edge();
303 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
304 if(aMakeEdge3.IsDone())
305 aTopEdge = aMakeEdge3.Edge();
307 // Make wire for 2D presentation with updating of corresponding edges
308 BRepBuilderAPI_MakeWire aMakeWire;
310 aMakeWire.Add( aBotEdge );
311 thePrs.myInlet = aMakeWire.Edge();
313 aMakeWire.Add( anEdgLeft );
314 thePrs.myLeftBank = aMakeWire.Edge();
316 aMakeWire.Add( aTopEdge );
317 thePrs.myOutlet = aMakeWire.Edge();
319 aMakeWire.Add( anEdgRight );
320 thePrs.myRightBank = aMakeWire.Edge();
322 TopoDS_Wire aSectProfileWire;
323 if(aMakeWire.IsDone())
324 aSectProfileWire = aMakeWire.Wire();
326 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
329 if( aMakeFace.IsDone() )
330 aFace = aMakeFace.Face();
333 aBB.MakeCompound(aCmp);
335 for(int i=1;i <= anArrOf2DProfiles.Length(); i++)
336 aBB.Add(aCmp,anArrOf2DProfiles.Value(i));
340 thePrs.myPrs2D = aCmp;
343 BRepTools::Write(aCmp, "str2d.brep");
344 thePrs.myPrs2D = aCmp;
351 void HYDROData_Stream::UpdatePrs()
353 HYDROData_NaturalObject::Update();
355 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
356 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
358 PrsDefinition aResultPrs;
359 if ( !CreatePresentations( aHydAxis, aRefProfiles, aResultPrs ) )
362 SetShape3D( aResultPrs.myPrs3D );
363 SetTopShape( aResultPrs.myPrs2D );
365 // Create the stream groups
366 QString aLeftGroupName = GetName() + "_Left_Bank";
368 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
369 aLeftGroup->SetName( aLeftGroupName );
370 aLeftGroup->AddShape( aResultPrs.myLeftBank );
372 QString aRightGroupName = GetName() + "_Right_Bank";
374 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
375 aRightGroup->SetName( aRightGroupName );
376 aRightGroup->AddShape( aResultPrs.myRightBank );
378 QString anInGroupName = GetName() + "_Inlet";
380 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
381 anInGroup->SetName( anInGroupName );
382 anInGroup->AddShape( aResultPrs.myInlet );
384 QString anOutGroupName = GetName() + "_Outlet";
386 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
387 anOutGroup->SetName( anOutGroupName );
388 anOutGroup->AddShape( aResultPrs.myOutlet );
391 QColor HYDROData_Stream::DefaultFillingColor()
393 return QColor( Qt::green );
396 QColor HYDROData_Stream::DefaultBorderColor()
398 return QColor( Qt::transparent );
401 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
403 if ( theHydAxis.IsNull() )
406 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
407 if ( aHydraulicShape.IsNull() ||
408 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
409 BRep_Tool::IsClosed( aHydraulicShape ) )
410 return false; // The polyline must be a single not closed wire
415 TopoDS_Shape getShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
416 const int theGroupId )
418 TopoDS_Shape aResShape;
419 if ( theGroups.Length() != 4 )
422 Handle(HYDROData_ShapesGroup) aGroup =
423 Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
424 if ( aGroup.IsNull() )
427 TopTools_SequenceOfShape aGroupShapes;
428 aGroup->GetShapes( aGroupShapes );
430 if ( !aGroupShapes.IsEmpty() )
431 aResShape = aGroupShapes.First();
436 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
438 HYDROData_SequenceOfObjects aGroups = GetGroups();
439 return getShapeFromGroup( aGroups, 1 );
442 TopoDS_Shape HYDROData_Stream::GetRightShape() const
444 HYDROData_SequenceOfObjects aGroups = GetGroups();
445 return getShapeFromGroup( aGroups, 2 );
448 TopoDS_Shape HYDROData_Stream::GetInletShape() const
450 HYDROData_SequenceOfObjects aGroups = GetGroups();
451 return getShapeFromGroup( aGroups, 3 );
454 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
456 HYDROData_SequenceOfObjects aGroups = GetGroups();
457 return getShapeFromGroup( aGroups, 4 );
460 QColor HYDROData_Stream::getDefaultFillingColor() const
462 return DefaultFillingColor();
465 QColor HYDROData_Stream::getDefaultBorderColor() const
467 return DefaultBorderColor();
470 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
472 if ( !IsValidAsAxis( theAxis ) )
475 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
476 if ( IsEqual( aPrevAxis, theAxis ) )
479 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
481 // Update the order of profiles
482 updateProfilesOrder();
484 // Indicate model of the need to update the stream presentation
490 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
492 return Handle(HYDROData_PolylineXY)::DownCast(
493 GetReferenceObject( DataTag_HydraulicAxis ) );
496 void HYDROData_Stream::RemoveHydraulicAxis()
498 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
499 if ( aPrevAxis.IsNull() )
502 ClearReferenceObjects( DataTag_HydraulicAxis );
504 // We remove the reference profiles
507 // Indicate model of the need to update the stream presentation
511 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
512 const TopoDS_Face& thePlane,
513 Standard_Real& theOutPar ) const
515 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
516 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
519 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
520 const Handle(HYDROData_Profile)& theProfile,
521 const TopoDS_Face& thePlane,
522 Standard_Real& theOutPar )
524 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
527 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
528 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
529 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
532 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
533 if(!aProjector.IsDone())
535 TopoDS_Shape aPrjProfile = aProjector.Shape();
536 if(aPrjProfile.IsNull())
538 TopoDS_Vertex aV1, aV2;
539 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
540 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
541 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
542 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
543 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
544 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
546 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
548 anExp.Init(aPrjProfile, TopAbs_EDGE);
550 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
554 if(aV1.IsNull() || aV2.IsNull())
556 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
557 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
560 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
563 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
564 Standard_Integer aNum(0);
566 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
567 for(;anExplo.More();anExplo.Next()) aNum++;
568 // check for self-intersection
569 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
570 Standard_Boolean hasInt(false);
571 Standard_Real aSqDist(DBL_MAX);
572 Standard_Integer anIndx(0);
573 BRepExtrema_ExtCC aCC;
574 aCC.Initialize(anEdg2);
576 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
577 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
578 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
581 Standard_Boolean hasSol(false);
585 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
586 if(aCC.SquareDistance(i) < aSqDist) {
587 aSqDist = aCC.SquareDistance(i);
593 if(aSqDist <= SquareTolerance) { // hasInt
594 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
596 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
597 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
599 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
607 TopExp::Vertices(anEdg1, aV1, aV2);
608 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
611 } else if(aNum > 1) {
612 TopExp::Vertices(anEdg1, aV1, aV2);
613 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
621 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
623 if ( theProfile.IsNull() )
626 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
627 if ( aHydAxis.IsNull() )
631 if(!BuildFace(aHydAxis, aPlane))
634 Standard_Real aPar(.0);
635 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
636 return false; // Object is already in reference list or it has no intersection
638 int aProfileIndex = insertParameter( aPar );
639 insertProfileInToOrder( theProfile, aProfileIndex );
641 // Indicate model of the need to update the stream presentation
647 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
648 const bool& theIsToOrder )
652 for ( int i = 1; i <= theProfiles.Length(); ++i )
654 Handle(HYDROData_Profile) aProfile =
655 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
656 if ( aProfile.IsNull() )
659 if ( !AddProfile( aProfile ) )
663 else // Just store the sequence of objects as is
665 bool anIsToUpdate = true;
667 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
668 if ( anOldProfiles.Length() == theProfiles.Length() )
670 anIsToUpdate = false;
672 for ( int i = 1; i <= theProfiles.Length(); ++i )
674 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
675 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
676 if ( !IsEqual( anOldProfile, aNewProfile ) )
684 SetReferenceObjects( theProfiles, DataTag_Profile );
693 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
695 return GetReferenceObjects( DataTag_Profile );
698 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
700 if ( theProfile.IsNull() )
703 int aProfileIndex = -1;
705 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
706 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
707 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
709 Handle(HYDROData_Profile) aProfile =
710 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
711 if ( aProfile.IsNull() )
714 if ( IsEqual( theProfile, aProfile ) )
721 if ( aProfileIndex == -1 )
724 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
726 // Remove parameter for removed profile
727 removeParameter( aProfileIndex );
729 // Indicate model of the need to update the stream presentation
735 void HYDROData_Stream::RemoveProfiles()
737 bool anIsToUpdate = IsMustBeUpdated() || NbReferenceObjects( DataTag_Profile ) > 0;
739 ClearReferenceObjects( DataTag_Profile );
741 // Remove the parameters array
742 removeParametersArray();
744 // Indicate model of the need to update the stream presentation
745 SetToUpdate( anIsToUpdate );
748 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
749 const int theBeforeIndex )
751 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
752 if ( theProfile.IsNull() || aHydAxis.IsNull() )
755 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
756 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
757 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
760 if ( theBeforeIndex == -1 )
761 AddReferenceObject( theProfile, DataTag_Profile );
763 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
766 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
767 TopoDS_Face& thePlane )
769 if ( !IsValidAsAxis( theHydAxis ) )
772 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
774 gp_Ax2 aX2(gp::XOY());
778 BRepBndLib::Add(aHydraulicWire,B);
779 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
780 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
781 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
782 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
783 thePlane = TopoDS::Face(aMkr.Shape());
787 void HYDROData_Stream::updateProfilesOrder()
789 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
790 if ( aRefProfiles.IsEmpty() )
793 // At first we remove all profiles from order
796 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
797 if ( aHydAxis.IsNull() )
801 if ( !BuildFace( aHydAxis, aPlane ) )
804 Standard_Real aPar( .0 );
808 TopoDS_Compound aCmp;
809 aBB.MakeCompound(aCmp);
812 HYDROData_DataMapOfRealOfHDProfile aDM;
813 TColStd_ListOfReal aList;
814 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
815 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
817 Handle(HYDROData_Profile) aProfile =
818 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
820 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
821 aBB.Add( aCmp, aProfileWire );
823 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
826 aDM.Bind( aPar, aProfile );
827 aList.Append( aPar );
830 if ( aList.IsEmpty() )
833 TColStd_Array1OfReal anArr( 1, aList.Extent() );
835 TColStd_ListIteratorOfListOfReal it( aList );
836 for ( int j = 1; it.More(); it.Next(), j++ )
837 anArr( j ) = it.Value();
840 if ( aList.Extent() > 1 )
842 TCollection_CompareOfReal Compar;
843 SortTools_QuickSortOfReal::Sort( anArr, Compar );
845 for (int j = 1; j <= anArr.Length(); j++) {
846 const Standard_Real aKey = anArr(j);
847 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
848 insertProfileInToOrder( aProfile );
850 } else if ( aList.Extent() == 1 ) {
851 const Standard_Real aKey = aList.Last();
852 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
853 insertProfileInToOrder( aProfile );
856 setParametersArray( anArr );
859 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
860 BRepTools::Write(aHydraulicWire, "Path.brep");
861 BRepTools::Write(aCmp, "Prof.brep");
865 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
867 return KIND_STREAM_ALTITUDE;
870 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
872 if ( theArray.Length() == 0 )
874 removeParametersArray();
878 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
880 Handle(TDataStd_RealArray) aParamsArray =
881 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
883 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
885 const Standard_Real& aParam = theArray( i );
886 aParamsArray->SetValue( i, aParam );
890 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
892 TColStd_Array1OfReal* anArray = NULL;
894 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
895 if ( !aLabel.IsNull() )
897 Handle(TDataStd_RealArray) aParamsArray;
898 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
900 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
901 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
903 const Standard_Real& aParam = aParamsArray->Value( i );
904 anArray->SetValue( i, aParam );
912 void HYDROData_Stream::removeParametersArray()
914 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
915 if ( !aLabel.IsNull() )
916 aLabel.ForgetAllAttributes();
919 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
923 TColStd_Array1OfReal* anArr = getParametersArray();
928 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
930 bool isInserted = false;
931 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
933 const Standard_Real& aStoredParam = anArr->Value( i );
936 if ( theParam > aStoredParam )
942 aNewArr( j ) = theParam;
948 aNewArr( j ) = aStoredParam;
954 aNewArr( aNewArr.Upper() ) = theParam;
957 setParametersArray( aNewArr );
962 TColStd_Array1OfReal aNewArr( 1, 1 );
963 aNewArr.SetValue( 1, theParam );
964 setParametersArray( aNewArr );
970 void HYDROData_Stream::removeParameter( const int& theIndex )
972 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
973 if ( aLabel.IsNull() )
976 Handle(TDataStd_RealArray) aParamsArray;
977 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
980 if ( aParamsArray->Length() == 1 )
982 removeParametersArray();
986 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
988 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
990 const Standard_Real& aStoredParam = aParamsArray->Value( i );
994 aNewArr.SetValue( j, aStoredParam );
998 setParametersArray( aNewArr );