1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_Stream.h"
21 #include "HYDROData_Document.h"
22 #include "HYDROData_PolylineXY.h"
23 #include "HYDROData_Polyline3D.h"
24 #include "HYDROData_Profile.h"
25 #include "HYDROData_ShapesGroup.h"
26 #include "HYDROData_ShapesTool.h"
27 #include "HYDROData_IAltitudeObject.h"
28 #include "HYDROData_IProfilesInterpolator.h"
29 #include "HYDROData_Tool.h"
31 #include <TDataStd_RealArray.hxx>
33 #include <Precision.hxx>
35 #include <NCollection_DataMap.hxx>
37 #include <TColStd_Array1OfReal.hxx>
38 #include <TColStd_ListOfReal.hxx>
39 #include <TColStd_ListIteratorOfListOfReal.hxx>
40 #include <TCollection_CompareOfReal.hxx>
41 #include <TColgp_Array1OfPnt.hxx>
42 #include <TColgp_HArray1OfPnt.hxx>
45 #include <TopoDS_Wire.hxx>
46 #include <TopoDS_Shell.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Vertex.hxx>
51 #include <TopExp_Explorer.hxx>
53 #include <Bnd_Box.hxx>
55 #include <BRep_Builder.hxx>
56 #include <BRepBuilderAPI_MakeEdge.hxx>
57 #include <BRepBuilderAPI_MakeWire.hxx>
58 #include <BRepBuilderAPI_MakeFace.hxx>
60 #include <BRepBndLib.hxx>
61 #include <BRepProj_Projection.hxx>
62 #include <BRepExtrema_ExtCC.hxx>
63 #include <BRepCheck_Analyzer.hxx>
73 #include <GeomAPI_Interpolate.hxx>
74 #include <Geom_BSplineCurve.hxx>
76 #include <TopTools_HArray1OfShape.hxx>
78 #include <SortTools_QuickSortOfReal.hxx>
81 #include <QStringList>
83 //#define DEB_STREAM 1
85 //#define DEB_HASINT 1
86 //#define DEB_UPDATE 1
87 #include <BRepTools.hxx>
88 #include <TCollection_AsciiString.hxx>
91 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
93 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
94 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
97 HYDROData_Stream::HYDROData_Stream()
98 : HYDROData_NaturalObject( Geom_3d )
102 HYDROData_Stream::~HYDROData_Stream()
106 QStringList HYDROData_Stream::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
108 QStringList aResList = dumpObjectCreation( theTreatedObjects );
109 QString aName = GetObjPyName();
111 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
112 setPythonReferenceObject( theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
114 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
115 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
117 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
118 setPythonReferenceObject( theTreatedObjects, aResList, aProfile, "AddProfile" );
121 // Set bottom polyline if exists
122 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
123 if ( !aBottomPolyline.IsNull() ) {
124 setPythonReferenceObject( theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
127 aResList << QString( "" );
128 aResList << QString( "%1.Update();" ).arg( aName );
129 aResList << QString( "" );
134 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
136 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
138 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
139 if ( !aHydAxis.IsNull() )
140 aResSeq.Append( aHydAxis );
142 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
143 aResSeq.Append( aSeqOfProfiles );
148 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
149 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
151 Handle(Geom_BSplineCurve) aBSpline;
152 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
153 anInterpolator.Perform() ;
154 if (anInterpolator.IsDone())
155 aBSpline = anInterpolator.Curve();
159 void HYDROData_Stream::Update()
161 updateProfilesOrder();
163 // Update bottom polyline if exists
164 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
165 if ( !aBottomPolyline.IsNull() ) {
166 if ( GenerateBottomPolyline() ) {
167 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
168 if ( !aPolylineXY.IsNull() ) {
169 aPolylineXY->Update();
171 aBottomPolyline->Update();
178 bool HYDROData_Stream::IsHas2dPrs() const
183 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis,
184 const HYDROData_SequenceOfObjects& theProfiles,
185 PrsDefinition& thePrs )
187 if ( theHydAxis.IsNull() || theProfiles.Length() < 2 )
190 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
191 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
192 Handle(TopTools_HArray1OfShape) anArrOfProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
193 Handle(TopTools_HArray1OfShape) anArrOf2DProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
196 HYDROData_SequenceOfObjects::Iterator anIter( theProfiles );
197 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
199 Handle(HYDROData_Profile) aProfile =
200 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
201 if ( aProfile.IsNull() )
204 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
206 if ( !aProfile->GetLeftPoint( aPnt1, false ) || !aProfile->GetRightPoint( aPnt2, false ) )
209 anArrOfProfiles->SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
210 anArrOf2DProfiles->SetValue(i,aProfile->GetTopShape());
212 gp_Pnt aCurFP, aCurLP;
213 TopoDS_Vertex aV1, aV2;
214 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
215 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
216 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
220 aP1 = BRep_Tool::Pnt(aV2);
221 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
225 anArrayOfFPnt->SetValue(i,aCurFP);
226 anArrayOfLPnt->SetValue(i,aCurLP);
229 return CreatePresentations( anArrayOfFPnt, anArrayOfLPnt, anArrOfProfiles, anArrOf2DProfiles, thePrs );
232 void HYDROData_Stream::UpdatePrs()
234 HYDROData_NaturalObject::Update();
236 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
237 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
239 PrsDefinition aResultPrs;
240 if ( !CreatePresentations( aHydAxis, aRefProfiles, aResultPrs ) )
243 SetShape3D( aResultPrs.myPrs3D );
244 SetTopShape( aResultPrs.myPrs2D );
246 // Create the stream groups
247 QString aLeftGroupName = GetName() + "_Left_Bank";
249 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
250 aLeftGroup->SetName( aLeftGroupName );
251 aLeftGroup->AddShape( aResultPrs.myLeftBank );
253 QString aRightGroupName = GetName() + "_Right_Bank";
255 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
256 aRightGroup->SetName( aRightGroupName );
257 aRightGroup->AddShape( aResultPrs.myRightBank );
259 QString anInGroupName = GetName() + "_Inlet";
261 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
262 anInGroup->SetName( anInGroupName );
263 anInGroup->AddShape( aResultPrs.myInlet );
265 QString anOutGroupName = GetName() + "_Outlet";
267 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
268 anOutGroup->SetName( anOutGroupName );
269 anOutGroup->AddShape( aResultPrs.myOutlet );
272 QColor HYDROData_Stream::DefaultFillingColor() const
274 return QColor( Qt::green );
277 QColor HYDROData_Stream::DefaultBorderColor() const
279 return QColor( Qt::transparent );
282 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
284 if ( theHydAxis.IsNull() )
287 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
288 if ( aHydraulicShape.IsNull() ||
289 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
290 BRep_Tool::IsClosed( aHydraulicShape ) )
291 return false; // The polyline must be a single not closed wire
296 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
298 HYDROData_SequenceOfObjects aGroups = GetGroups();
299 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
302 TopoDS_Shape HYDROData_Stream::GetRightShape() const
304 HYDROData_SequenceOfObjects aGroups = GetGroups();
305 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
308 TopoDS_Shape HYDROData_Stream::GetInletShape() const
310 HYDROData_SequenceOfObjects aGroups = GetGroups();
311 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
314 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
316 HYDROData_SequenceOfObjects aGroups = GetGroups();
317 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
320 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
322 if ( !IsValidAsAxis( theAxis ) )
325 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
326 if ( IsEqual( aPrevAxis, theAxis ) )
329 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
331 // Update the order of profiles
332 updateProfilesOrder();
334 // Indicate model of the need to update the stream presentation
340 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
342 return Handle(HYDROData_PolylineXY)::DownCast(
343 GetReferenceObject( DataTag_HydraulicAxis ) );
346 void HYDROData_Stream::RemoveHydraulicAxis()
348 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
349 if ( aPrevAxis.IsNull() )
352 ClearReferenceObjects( DataTag_HydraulicAxis );
354 // We remove the reference profiles
357 // Indicate model of the need to update the stream presentation
361 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
362 const TopoDS_Face& thePlane,
363 Standard_Real& theOutPar ) const
365 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
366 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
369 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
370 const Handle(HYDROData_Profile)& theProfile,
371 const TopoDS_Face& thePlane,
372 Standard_Real& theOutPar )
374 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
377 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
378 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
379 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
382 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
383 if(!aProjector.IsDone())
385 TopoDS_Shape aPrjProfile = aProjector.Shape();
386 if(aPrjProfile.IsNull())
388 TopoDS_Vertex aV1, aV2;
389 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
390 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
391 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
392 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
393 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
394 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
396 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
398 anExp.Init(aPrjProfile, TopAbs_EDGE);
400 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
404 if(aV1.IsNull() || aV2.IsNull())
406 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
407 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
410 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
413 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
414 Standard_Integer aNum(0);
416 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
417 for(;anExplo.More();anExplo.Next()) aNum++;
418 // check for self-intersection
419 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
420 Standard_Boolean hasInt(false);
421 Standard_Real aSqDist(DBL_MAX);
422 Standard_Integer anIndx(0);
423 BRepExtrema_ExtCC aCC;
424 aCC.Initialize(anEdg2);
426 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
427 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
428 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
431 Standard_Boolean hasSol(false);
435 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
436 if(aCC.SquareDistance(i) < aSqDist) {
437 aSqDist = aCC.SquareDistance(i);
443 if(aSqDist <= SquareTolerance) { // hasInt
444 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
446 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
447 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
449 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
457 TopExp::Vertices(anEdg1, aV1, aV2);
458 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
461 } else if(aNum > 1) {
462 TopExp::Vertices(anEdg1, aV1, aV2);
463 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
471 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
473 if ( theProfile.IsNull() )
476 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
477 if ( aHydAxis.IsNull() )
481 if(!BuildFace(aHydAxis, aPlane))
484 Standard_Real aPar(.0);
485 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
486 return false; // Object is already in reference list or it has no intersection
488 int aProfileIndex = insertParameter( aPar );
489 insertProfileInToOrder( theProfile, aProfileIndex );
491 // Indicate model of the need to update the stream presentation
497 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
498 const bool& theIsToOrder )
502 for ( int i = 1; i <= theProfiles.Length(); ++i )
504 Handle(HYDROData_Profile) aProfile =
505 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
506 if ( aProfile.IsNull() )
509 if ( !AddProfile( aProfile ) )
513 else // Just store the sequence of objects as is
515 bool anIsToUpdate = true;
517 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
518 if ( anOldProfiles.Length() == theProfiles.Length() )
520 anIsToUpdate = false;
522 for ( int i = 1; i <= theProfiles.Length(); ++i )
524 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
525 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
526 if ( !IsEqual( anOldProfile, aNewProfile ) )
534 SetReferenceObjects( theProfiles, DataTag_Profile );
543 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
545 return GetReferenceObjects( DataTag_Profile );
548 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
550 if ( theProfile.IsNull() )
553 int aProfileIndex = -1;
555 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
556 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
557 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
559 Handle(HYDROData_Profile) aProfile =
560 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
561 if ( aProfile.IsNull() )
564 if ( IsEqual( theProfile, aProfile ) )
571 if ( aProfileIndex == -1 )
574 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
576 // Remove parameter for removed profile
577 removeParameter( aProfileIndex );
579 // Indicate model of the need to update the stream presentation
585 void HYDROData_Stream::RemoveProfiles()
587 ClearReferenceObjects( DataTag_Profile );
589 // Remove the parameters array
590 removeParametersArray();
592 // Indicate model of the need to update the stream presentation
596 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
597 const int theBeforeIndex )
599 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
600 if ( theProfile.IsNull() || aHydAxis.IsNull() )
603 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
604 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
605 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
608 if ( theBeforeIndex == -1 )
609 AddReferenceObject( theProfile, DataTag_Profile );
611 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
614 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
615 TopoDS_Face& thePlane )
617 if ( !IsValidAsAxis( theHydAxis ) )
620 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
622 gp_Ax2 aX2(gp::XOY());
626 BRepBndLib::Add(aHydraulicWire,B);
627 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
628 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
629 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
630 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
631 thePlane = TopoDS::Face(aMkr.Shape());
635 void HYDROData_Stream::updateProfilesOrder()
637 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
638 if ( aRefProfiles.IsEmpty() )
641 // At first we remove all profiles from order
644 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
645 if ( aHydAxis.IsNull() )
649 if ( !BuildFace( aHydAxis, aPlane ) )
652 Standard_Real aPar( .0 );
656 TopoDS_Compound aCmp;
657 aBB.MakeCompound(aCmp);
660 HYDROData_DataMapOfRealOfHDProfile aDM;
661 TColStd_ListOfReal aList;
662 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
663 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
665 Handle(HYDROData_Profile) aProfile =
666 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
668 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
669 aBB.Add( aCmp, aProfileWire );
671 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
674 aDM.Bind( aPar, aProfile );
675 aList.Append( aPar );
678 if ( aList.IsEmpty() )
681 TColStd_Array1OfReal anArr( 1, aList.Extent() );
683 TColStd_ListIteratorOfListOfReal it( aList );
684 for ( int j = 1; it.More(); it.Next(), j++ )
685 anArr( j ) = it.Value();
688 if ( aList.Extent() > 1 )
690 TCollection_CompareOfReal Compar;
691 SortTools_QuickSortOfReal::Sort( anArr, Compar );
693 for (int j = 1; j <= anArr.Length(); j++) {
694 const Standard_Real aKey = anArr(j);
695 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
696 insertProfileInToOrder( aProfile );
698 } else if ( aList.Extent() == 1 ) {
699 const Standard_Real aKey = aList.Last();
700 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
701 insertProfileInToOrder( aProfile );
704 setParametersArray( anArr );
707 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
708 BRepTools::Write(aHydraulicWire, "Path.brep");
709 BRepTools::Write(aCmp, "Prof.brep");
713 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
715 return KIND_STREAM_ALTITUDE;
718 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
720 if ( theArray.Length() == 0 )
722 removeParametersArray();
726 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
728 Handle(TDataStd_RealArray) aParamsArray =
729 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
731 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
733 const Standard_Real& aParam = theArray( i );
734 aParamsArray->SetValue( i, aParam );
738 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
740 TColStd_Array1OfReal* anArray = NULL;
742 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
743 if ( !aLabel.IsNull() )
745 Handle(TDataStd_RealArray) aParamsArray;
746 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
748 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
749 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
751 const Standard_Real& aParam = aParamsArray->Value( i );
752 anArray->SetValue( i, aParam );
760 void HYDROData_Stream::removeParametersArray()
762 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
763 if ( !aLabel.IsNull() )
764 aLabel.ForgetAllAttributes();
767 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
771 TColStd_Array1OfReal* anArr = getParametersArray();
776 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
778 bool isInserted = false;
779 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
781 const Standard_Real& aStoredParam = anArr->Value( i );
784 if ( theParam > aStoredParam )
790 aNewArr( j ) = theParam;
796 aNewArr( j ) = aStoredParam;
802 aNewArr( aNewArr.Upper() ) = theParam;
805 setParametersArray( aNewArr );
810 TColStd_Array1OfReal aNewArr( 1, 1 );
811 aNewArr.SetValue( 1, theParam );
812 setParametersArray( aNewArr );
818 void HYDROData_Stream::removeParameter( const int& theIndex )
820 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
821 if ( aLabel.IsNull() )
824 Handle(TDataStd_RealArray) aParamsArray;
825 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
828 if ( aParamsArray->Length() == 1 )
830 removeParametersArray();
834 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
836 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
838 const Standard_Real& aStoredParam = aParamsArray->Value( i );
842 aNewArr.SetValue( j, aStoredParam );
846 setParametersArray( aNewArr );
849 bool HYDROData_Stream::GenerateBottomPolyline()
852 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
853 if ( aDocument.IsNull() ) {
857 // Collect bottom points ( one bottom point from each profile of the stream )
858 HYDROData_Profile::ProfilePoints aBottomPoints;
860 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
861 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
862 const Handle(HYDROData_Profile) aProfile =
863 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
864 if ( aProfile.IsNull() ) {
868 aBottomPoints.Append( aProfile->GetBottomPoint() );
871 int aNbBottomPoints = aBottomPoints.Size();
873 if ( aNbBottomPoints < 2 ) {
877 // Create bottom polyline object if the stream doesn't contain it yet
878 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
879 if ( aBottom.IsNull() ) {
880 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
881 QString aBaseName = GetName() + "_bottom";
882 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
883 aBottom->SetName( aName );
885 SetReferenceObject( aBottom, DataTag_BottomPolyline );
888 // Create 2D polyline if the bottom polyline doesn't contain it yet
889 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
890 if ( aPolylineXY.IsNull() ) {
891 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
892 QString aBaseName = GetName() + "_bottom_2d";
893 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
894 aPolylineXY->SetName( aName );
895 aBottom->SetPolylineXY( aPolylineXY, false );
898 aPolylineXY->RemoveSections();
899 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
901 // Create profile if the bottom polyline doesn't contain it yet
902 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
903 if ( aProfileUZ.IsNull() ) {
904 Handle(HYDROData_Profile) aProfile =
905 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
906 QString aBaseName = GetName() + "_bottom_profile";
907 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
908 aProfile->SetName( aName );
909 aProfileUZ = aProfile->GetProfileUZ( true );
910 aBottom->SetProfileUZ( aProfileUZ );
913 aProfileUZ->RemoveSection( 0 );
915 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
920 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
922 return Handle(HYDROData_Polyline3D)::DownCast(
923 GetReferenceObject( DataTag_BottomPolyline ) );
926 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
928 if ( theBottom.IsNull() ) {
932 SetReferenceObject( theBottom, DataTag_BottomPolyline );
937 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
940 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
941 if ( aDocument.IsNull() ) {
945 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
946 theInterpolator->Calculate();
949 if ( theInterpolator->GetErrorCode() != OK ) {
955 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
956 // Get calculated point coordinates
957 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
958 if ( aResultPoints.IsEmpty() ) {
963 // Create profile object
964 Handle(HYDROData_Profile) aProfile =
965 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
966 QString aBaseName = GetName() + "_interp_profile";
967 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
968 aProfile->SetName( aName );
970 // Fill the profile with points
971 aProfile->SetProfilePoints( aResultPoints );
973 // Add profile to the stream
974 bool isAdded = AddProfile( aProfile );
988 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
989 bool isGenerateNewName ) const
992 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
993 if ( aDocument.IsNull() ) {
998 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1000 Handle(HYDROData_Stream) aStreamCopy =
1001 Handle(HYDROData_Stream)::DownCast( theDestination );
1003 // Copy bottom polyline if exists
1004 if ( !aStreamCopy.IsNull() ) {
1005 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1006 if ( !aBottom.IsNull() ) {
1007 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1008 aStreamCopy->GenerateBottomPolyline();
1009 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1010 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1011 aBottomCopy->GetPolylineXY()->Update();
1012 aBottomCopy->Update();
1018 bool HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1019 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1020 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1021 const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles,
1022 PrsDefinition& thePrs )
1024 if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) {
1028 if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) {
1032 // Construct of the 3D presentation
1033 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt);
1034 if(aBSpline.IsNull())
1037 TopoDS_Edge anEdgLeft, anEdgRight;
1039 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
1040 if(aMakeEdge.IsDone())
1041 anEdgLeft = aMakeEdge.Edge();
1043 if(anEdgLeft.IsNull())
1047 aBSpline = buildInterpolationCurve (theArrayOfLPnt);
1048 if(aBSpline.IsNull())
1051 aMakeEdge.Init(aBSpline);
1052 if(aMakeEdge.IsDone())
1053 anEdgRight = aMakeEdge.Edge();
1055 if(anEdgRight.IsNull())
1059 TopoDS_Compound aCmp;
1060 aBB.MakeCompound(aCmp);
1061 for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ )
1062 aBB.Add(aCmp, theArrOfProfiles->Value(i));
1064 aBB.Add(aCmp,anEdgLeft);
1065 aBB.Add(aCmp,anEdgRight);
1066 BRepCheck_Analyzer aCh(aCmp);
1068 thePrs.myPrs3D = aCmp;
1071 BRepTools::Write(aCmp, "str3d.brep");
1072 thePrs.myPrs3D = aCmp;
1076 // Construct the top presentation
1077 int aNbPoints = theArrayOfFPnt->Length();
1078 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1079 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1080 for( int i=1; i <= aNbPoints; i++ ) {
1081 gp_Pnt aPnt = theArrayOfFPnt->Value(i);
1082 aPnt.SetZ(.0); // make 2d
1083 anArrayOfFPnt->SetValue(i, aPnt);
1084 aPnt = theArrayOfLPnt->Value(i);
1086 anArrayOfLPnt->SetValue(i, aPnt);
1090 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
1091 if(aBSpline.IsNull())
1094 aMakeEdge.Init(aBSpline);
1095 if(aMakeEdge.IsDone())
1096 anEdgLeft = aMakeEdge.Edge();
1099 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
1100 if(aBSpline.IsNull())
1103 aMakeEdge.Init(aBSpline);
1104 if(aMakeEdge.IsDone())
1105 anEdgRight = aMakeEdge.Edge();
1106 if(anEdgRight.IsNull())
1109 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
1110 TopoDS_Edge aBotEdge, aTopEdge;
1111 if(aMakeEdge2.IsDone())
1112 aBotEdge = aMakeEdge2.Edge();
1114 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
1115 if(aMakeEdge3.IsDone())
1116 aTopEdge = aMakeEdge3.Edge();
1118 // Make wire for 2D presentation with updating of corresponding edges
1119 BRepBuilderAPI_MakeWire aMakeWire;
1121 aMakeWire.Add( aBotEdge );
1122 thePrs.myInlet = aMakeWire.Edge();
1124 aMakeWire.Add( anEdgLeft );
1125 thePrs.myLeftBank = aMakeWire.Edge();
1127 aMakeWire.Add( aTopEdge );
1128 thePrs.myOutlet = aMakeWire.Edge();
1130 aMakeWire.Add( anEdgRight );
1131 thePrs.myRightBank = aMakeWire.Edge();
1133 TopoDS_Wire aSectProfileWire;
1134 if(aMakeWire.IsDone())
1135 aSectProfileWire = aMakeWire.Wire();
1137 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
1140 if( aMakeFace.IsDone() )
1141 aFace = aMakeFace.Face();
1143 TopoDS_Shape aPrs2D;
1145 if ( !theArrOf2DProfiles.IsNull() ) {
1147 aBB.MakeCompound(aCmp);
1148 aBB.Add(aCmp,aFace);
1149 for(int i=1;i <= theArrOf2DProfiles->Length(); i++)
1150 aBB.Add(aCmp, theArrOf2DProfiles->Value(i));
1159 thePrs.myPrs2D = aPrs2D;
1162 BRepTools::Write(aPrs2D, "str2d.brep");
1163 thePrs.myPrs2D = aPrs2D;