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 TopoDS_Shape HYDROData_Stream::GetTopShape() const
150 return getTopShape();
153 TopoDS_Shape HYDROData_Stream::GetShape3D() const
158 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
159 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
161 Handle(Geom_BSplineCurve) aBSpline;
162 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
163 anInterpolator.Perform() ;
164 if (anInterpolator.IsDone())
165 aBSpline = anInterpolator.Curve();
169 void HYDROData_Stream::Update()
171 updateProfilesOrder();
173 // Update bottom polyline if exists
174 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
175 if ( !aBottomPolyline.IsNull() ) {
176 if ( GenerateBottomPolyline() ) {
177 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
178 if ( !aPolylineXY.IsNull() ) {
179 aPolylineXY->Update();
181 aBottomPolyline->Update();
188 bool HYDROData_Stream::IsHas2dPrs() const
193 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis,
194 const HYDROData_SequenceOfObjects& theProfiles,
195 PrsDefinition& thePrs )
197 if ( theHydAxis.IsNull() || theProfiles.Length() < 2 )
200 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
201 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
202 Handle(TopTools_HArray1OfShape) anArrOfProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
203 Handle(TopTools_HArray1OfShape) anArrOf2DProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
206 HYDROData_SequenceOfObjects::Iterator anIter( theProfiles );
207 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
209 Handle(HYDROData_Profile) aProfile =
210 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
211 if ( aProfile.IsNull() )
214 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
216 if ( !aProfile->GetLeftPoint( aPnt1, false ) || !aProfile->GetRightPoint( aPnt2, false ) )
219 anArrOfProfiles->SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
220 anArrOf2DProfiles->SetValue(i,aProfile->GetTopShape());
222 gp_Pnt aCurFP, aCurLP;
223 TopoDS_Vertex aV1, aV2;
224 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
225 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
226 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
230 aP1 = BRep_Tool::Pnt(aV2);
231 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
235 anArrayOfFPnt->SetValue(i,aCurFP);
236 anArrayOfLPnt->SetValue(i,aCurLP);
239 return CreatePresentations( anArrayOfFPnt, anArrayOfLPnt, anArrOfProfiles, anArrOf2DProfiles, thePrs );
242 void HYDROData_Stream::UpdatePrs()
244 HYDROData_NaturalObject::Update();
246 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
247 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
249 PrsDefinition aResultPrs;
250 if ( !CreatePresentations( aHydAxis, aRefProfiles, aResultPrs ) )
253 SetShape3D( aResultPrs.myPrs3D );
254 SetTopShape( aResultPrs.myPrs2D );
256 // Create the stream groups
257 QString aLeftGroupName = GetName() + "_Left_Bank";
259 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
260 aLeftGroup->SetName( aLeftGroupName );
261 aLeftGroup->AddShape( aResultPrs.myLeftBank );
263 QString aRightGroupName = GetName() + "_Right_Bank";
265 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
266 aRightGroup->SetName( aRightGroupName );
267 aRightGroup->AddShape( aResultPrs.myRightBank );
269 QString anInGroupName = GetName() + "_Inlet";
271 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
272 anInGroup->SetName( anInGroupName );
273 anInGroup->AddShape( aResultPrs.myInlet );
275 QString anOutGroupName = GetName() + "_Outlet";
277 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
278 anOutGroup->SetName( anOutGroupName );
279 anOutGroup->AddShape( aResultPrs.myOutlet );
282 QColor HYDROData_Stream::DefaultFillingColor()
284 return QColor( Qt::green );
287 QColor HYDROData_Stream::DefaultBorderColor()
289 return QColor( Qt::transparent );
292 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
294 if ( theHydAxis.IsNull() )
297 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
298 if ( aHydraulicShape.IsNull() ||
299 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
300 BRep_Tool::IsClosed( aHydraulicShape ) )
301 return false; // The polyline must be a single not closed wire
306 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
308 HYDROData_SequenceOfObjects aGroups = GetGroups();
309 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
312 TopoDS_Shape HYDROData_Stream::GetRightShape() const
314 HYDROData_SequenceOfObjects aGroups = GetGroups();
315 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
318 TopoDS_Shape HYDROData_Stream::GetInletShape() const
320 HYDROData_SequenceOfObjects aGroups = GetGroups();
321 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
324 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
326 HYDROData_SequenceOfObjects aGroups = GetGroups();
327 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
330 QColor HYDROData_Stream::getDefaultFillingColor() const
332 return DefaultFillingColor();
335 QColor HYDROData_Stream::getDefaultBorderColor() const
337 return DefaultBorderColor();
340 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
342 if ( !IsValidAsAxis( theAxis ) )
345 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
346 if ( IsEqual( aPrevAxis, theAxis ) )
349 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
351 // Update the order of profiles
352 updateProfilesOrder();
354 // Indicate model of the need to update the stream presentation
360 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
362 return Handle(HYDROData_PolylineXY)::DownCast(
363 GetReferenceObject( DataTag_HydraulicAxis ) );
366 void HYDROData_Stream::RemoveHydraulicAxis()
368 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
369 if ( aPrevAxis.IsNull() )
372 ClearReferenceObjects( DataTag_HydraulicAxis );
374 // We remove the reference profiles
377 // Indicate model of the need to update the stream presentation
381 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
382 const TopoDS_Face& thePlane,
383 Standard_Real& theOutPar ) const
385 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
386 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
389 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
390 const Handle(HYDROData_Profile)& theProfile,
391 const TopoDS_Face& thePlane,
392 Standard_Real& theOutPar )
394 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
397 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
398 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
399 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
402 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
403 if(!aProjector.IsDone())
405 TopoDS_Shape aPrjProfile = aProjector.Shape();
406 if(aPrjProfile.IsNull())
408 TopoDS_Vertex aV1, aV2;
409 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
410 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
411 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
412 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
413 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
414 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
416 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
418 anExp.Init(aPrjProfile, TopAbs_EDGE);
420 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
424 if(aV1.IsNull() || aV2.IsNull())
426 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
427 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
430 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
433 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
434 Standard_Integer aNum(0);
436 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
437 for(;anExplo.More();anExplo.Next()) aNum++;
438 // check for self-intersection
439 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
440 Standard_Boolean hasInt(false);
441 Standard_Real aSqDist(DBL_MAX);
442 Standard_Integer anIndx(0);
443 BRepExtrema_ExtCC aCC;
444 aCC.Initialize(anEdg2);
446 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
447 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
448 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
451 Standard_Boolean hasSol(false);
455 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
456 if(aCC.SquareDistance(i) < aSqDist) {
457 aSqDist = aCC.SquareDistance(i);
463 if(aSqDist <= SquareTolerance) { // hasInt
464 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
466 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
467 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
469 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
477 TopExp::Vertices(anEdg1, aV1, aV2);
478 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
481 } else if(aNum > 1) {
482 TopExp::Vertices(anEdg1, aV1, aV2);
483 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
491 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
493 if ( theProfile.IsNull() )
496 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
497 if ( aHydAxis.IsNull() )
501 if(!BuildFace(aHydAxis, aPlane))
504 Standard_Real aPar(.0);
505 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
506 return false; // Object is already in reference list or it has no intersection
508 int aProfileIndex = insertParameter( aPar );
509 insertProfileInToOrder( theProfile, aProfileIndex );
511 // Indicate model of the need to update the stream presentation
517 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
518 const bool& theIsToOrder )
522 for ( int i = 1; i <= theProfiles.Length(); ++i )
524 Handle(HYDROData_Profile) aProfile =
525 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
526 if ( aProfile.IsNull() )
529 if ( !AddProfile( aProfile ) )
533 else // Just store the sequence of objects as is
535 bool anIsToUpdate = true;
537 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
538 if ( anOldProfiles.Length() == theProfiles.Length() )
540 anIsToUpdate = false;
542 for ( int i = 1; i <= theProfiles.Length(); ++i )
544 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
545 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
546 if ( !IsEqual( anOldProfile, aNewProfile ) )
554 SetReferenceObjects( theProfiles, DataTag_Profile );
563 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
565 return GetReferenceObjects( DataTag_Profile );
568 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
570 if ( theProfile.IsNull() )
573 int aProfileIndex = -1;
575 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
576 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
577 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
579 Handle(HYDROData_Profile) aProfile =
580 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
581 if ( aProfile.IsNull() )
584 if ( IsEqual( theProfile, aProfile ) )
591 if ( aProfileIndex == -1 )
594 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
596 // Remove parameter for removed profile
597 removeParameter( aProfileIndex );
599 // Indicate model of the need to update the stream presentation
605 void HYDROData_Stream::RemoveProfiles()
607 ClearReferenceObjects( DataTag_Profile );
609 // Remove the parameters array
610 removeParametersArray();
612 // Indicate model of the need to update the stream presentation
616 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
617 const int theBeforeIndex )
619 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
620 if ( theProfile.IsNull() || aHydAxis.IsNull() )
623 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
624 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
625 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
628 if ( theBeforeIndex == -1 )
629 AddReferenceObject( theProfile, DataTag_Profile );
631 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
634 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
635 TopoDS_Face& thePlane )
637 if ( !IsValidAsAxis( theHydAxis ) )
640 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
642 gp_Ax2 aX2(gp::XOY());
646 BRepBndLib::Add(aHydraulicWire,B);
647 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
648 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
649 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
650 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
651 thePlane = TopoDS::Face(aMkr.Shape());
655 void HYDROData_Stream::updateProfilesOrder()
657 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
658 if ( aRefProfiles.IsEmpty() )
661 // At first we remove all profiles from order
664 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
665 if ( aHydAxis.IsNull() )
669 if ( !BuildFace( aHydAxis, aPlane ) )
672 Standard_Real aPar( .0 );
676 TopoDS_Compound aCmp;
677 aBB.MakeCompound(aCmp);
680 HYDROData_DataMapOfRealOfHDProfile aDM;
681 TColStd_ListOfReal aList;
682 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
683 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
685 Handle(HYDROData_Profile) aProfile =
686 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
688 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
689 aBB.Add( aCmp, aProfileWire );
691 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
694 aDM.Bind( aPar, aProfile );
695 aList.Append( aPar );
698 if ( aList.IsEmpty() )
701 TColStd_Array1OfReal anArr( 1, aList.Extent() );
703 TColStd_ListIteratorOfListOfReal it( aList );
704 for ( int j = 1; it.More(); it.Next(), j++ )
705 anArr( j ) = it.Value();
708 if ( aList.Extent() > 1 )
710 TCollection_CompareOfReal Compar;
711 SortTools_QuickSortOfReal::Sort( anArr, Compar );
713 for (int j = 1; j <= anArr.Length(); j++) {
714 const Standard_Real aKey = anArr(j);
715 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
716 insertProfileInToOrder( aProfile );
718 } else if ( aList.Extent() == 1 ) {
719 const Standard_Real aKey = aList.Last();
720 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
721 insertProfileInToOrder( aProfile );
724 setParametersArray( anArr );
727 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
728 BRepTools::Write(aHydraulicWire, "Path.brep");
729 BRepTools::Write(aCmp, "Prof.brep");
733 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
735 return KIND_STREAM_ALTITUDE;
738 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
740 if ( theArray.Length() == 0 )
742 removeParametersArray();
746 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
748 Handle(TDataStd_RealArray) aParamsArray =
749 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
751 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
753 const Standard_Real& aParam = theArray( i );
754 aParamsArray->SetValue( i, aParam );
758 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
760 TColStd_Array1OfReal* anArray = NULL;
762 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
763 if ( !aLabel.IsNull() )
765 Handle(TDataStd_RealArray) aParamsArray;
766 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
768 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
769 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
771 const Standard_Real& aParam = aParamsArray->Value( i );
772 anArray->SetValue( i, aParam );
780 void HYDROData_Stream::removeParametersArray()
782 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
783 if ( !aLabel.IsNull() )
784 aLabel.ForgetAllAttributes();
787 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
791 TColStd_Array1OfReal* anArr = getParametersArray();
796 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
798 bool isInserted = false;
799 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
801 const Standard_Real& aStoredParam = anArr->Value( i );
804 if ( theParam > aStoredParam )
810 aNewArr( j ) = theParam;
816 aNewArr( j ) = aStoredParam;
822 aNewArr( aNewArr.Upper() ) = theParam;
825 setParametersArray( aNewArr );
830 TColStd_Array1OfReal aNewArr( 1, 1 );
831 aNewArr.SetValue( 1, theParam );
832 setParametersArray( aNewArr );
838 void HYDROData_Stream::removeParameter( const int& theIndex )
840 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
841 if ( aLabel.IsNull() )
844 Handle(TDataStd_RealArray) aParamsArray;
845 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
848 if ( aParamsArray->Length() == 1 )
850 removeParametersArray();
854 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
856 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
858 const Standard_Real& aStoredParam = aParamsArray->Value( i );
862 aNewArr.SetValue( j, aStoredParam );
866 setParametersArray( aNewArr );
869 bool HYDROData_Stream::GenerateBottomPolyline()
872 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
873 if ( aDocument.IsNull() ) {
877 // Collect bottom points ( one bottom point from each profile of the stream )
878 HYDROData_Profile::ProfilePoints aBottomPoints;
880 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
881 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
882 const Handle(HYDROData_Profile) aProfile =
883 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
884 if ( aProfile.IsNull() ) {
888 aBottomPoints.Append( aProfile->GetBottomPoint() );
891 int aNbBottomPoints = aBottomPoints.Size();
893 if ( aNbBottomPoints < 2 ) {
897 // Create bottom polyline object if the stream doesn't contain it yet
898 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
899 if ( aBottom.IsNull() ) {
900 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
901 QString aBaseName = GetName() + "_bottom";
902 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
903 aBottom->SetName( aName );
905 SetReferenceObject( aBottom, DataTag_BottomPolyline );
908 // Create 2D polyline if the bottom polyline doesn't contain it yet
909 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
910 if ( aPolylineXY.IsNull() ) {
911 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
912 QString aBaseName = GetName() + "_bottom_2d";
913 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
914 aPolylineXY->SetName( aName );
915 aBottom->SetPolylineXY( aPolylineXY, false );
918 aPolylineXY->RemoveSections();
919 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
921 // Create profile if the bottom polyline doesn't contain it yet
922 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
923 if ( aProfileUZ.IsNull() ) {
924 Handle(HYDROData_Profile) aProfile =
925 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
926 QString aBaseName = GetName() + "_bottom_profile";
927 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
928 aProfile->SetName( aName );
929 aProfileUZ = aProfile->GetProfileUZ( true );
930 aBottom->SetProfileUZ( aProfileUZ );
933 aProfileUZ->RemoveSection( 0 );
935 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
940 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
942 return Handle(HYDROData_Polyline3D)::DownCast(
943 GetReferenceObject( DataTag_BottomPolyline ) );
946 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
948 if ( theBottom.IsNull() ) {
952 SetReferenceObject( theBottom, DataTag_BottomPolyline );
957 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
960 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
961 if ( aDocument.IsNull() ) {
965 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
966 theInterpolator->Calculate();
969 if ( theInterpolator->GetErrorCode() != OK ) {
975 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
976 // Get calculated point coordinates
977 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
978 if ( aResultPoints.IsEmpty() ) {
983 // Create profile object
984 Handle(HYDROData_Profile) aProfile =
985 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
986 QString aBaseName = GetName() + "_interp_profile";
987 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
988 aProfile->SetName( aName );
990 // Fill the profile with points
991 aProfile->SetProfilePoints( aResultPoints );
993 // Add profile to the stream
994 bool isAdded = AddProfile( aProfile );
1008 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1009 bool isGenerateNewName ) const
1012 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1013 if ( aDocument.IsNull() ) {
1018 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1020 Handle(HYDROData_Stream) aStreamCopy =
1021 Handle(HYDROData_Stream)::DownCast( theDestination );
1023 // Copy bottom polyline if exists
1024 if ( !aStreamCopy.IsNull() ) {
1025 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1026 if ( !aBottom.IsNull() ) {
1027 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1028 aStreamCopy->GenerateBottomPolyline();
1029 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1030 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1031 aBottomCopy->GetPolylineXY()->Update();
1032 aBottomCopy->Update();
1038 bool HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1039 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1040 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1041 const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles,
1042 PrsDefinition& thePrs )
1044 if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) {
1048 if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) {
1052 // Construct of the 3D presentation
1053 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt);
1054 if(aBSpline.IsNull())
1057 TopoDS_Edge anEdgLeft, anEdgRight;
1059 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
1060 if(aMakeEdge.IsDone())
1061 anEdgLeft = aMakeEdge.Edge();
1063 if(anEdgLeft.IsNull())
1067 aBSpline = buildInterpolationCurve (theArrayOfLPnt);
1068 if(aBSpline.IsNull())
1071 aMakeEdge.Init(aBSpline);
1072 if(aMakeEdge.IsDone())
1073 anEdgRight = aMakeEdge.Edge();
1075 if(anEdgRight.IsNull())
1079 TopoDS_Compound aCmp;
1080 aBB.MakeCompound(aCmp);
1081 for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ )
1082 aBB.Add(aCmp, theArrOfProfiles->Value(i));
1084 aBB.Add(aCmp,anEdgLeft);
1085 aBB.Add(aCmp,anEdgRight);
1086 BRepCheck_Analyzer aCh(aCmp);
1088 thePrs.myPrs3D = aCmp;
1091 BRepTools::Write(aCmp, "str3d.brep");
1092 thePrs.myPrs3D = aCmp;
1096 // Construct the top presentation
1097 int aNbPoints = theArrayOfFPnt->Length();
1098 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1099 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1100 for( int i=1; i <= aNbPoints; i++ ) {
1101 gp_Pnt aPnt = theArrayOfFPnt->Value(i);
1102 aPnt.SetZ(.0); // make 2d
1103 anArrayOfFPnt->SetValue(i, aPnt);
1104 aPnt = theArrayOfLPnt->Value(i);
1106 anArrayOfLPnt->SetValue(i, aPnt);
1110 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
1111 if(aBSpline.IsNull())
1114 aMakeEdge.Init(aBSpline);
1115 if(aMakeEdge.IsDone())
1116 anEdgLeft = aMakeEdge.Edge();
1119 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
1120 if(aBSpline.IsNull())
1123 aMakeEdge.Init(aBSpline);
1124 if(aMakeEdge.IsDone())
1125 anEdgRight = aMakeEdge.Edge();
1126 if(anEdgRight.IsNull())
1129 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
1130 TopoDS_Edge aBotEdge, aTopEdge;
1131 if(aMakeEdge2.IsDone())
1132 aBotEdge = aMakeEdge2.Edge();
1134 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
1135 if(aMakeEdge3.IsDone())
1136 aTopEdge = aMakeEdge3.Edge();
1138 // Make wire for 2D presentation with updating of corresponding edges
1139 BRepBuilderAPI_MakeWire aMakeWire;
1141 aMakeWire.Add( aBotEdge );
1142 thePrs.myInlet = aMakeWire.Edge();
1144 aMakeWire.Add( anEdgLeft );
1145 thePrs.myLeftBank = aMakeWire.Edge();
1147 aMakeWire.Add( aTopEdge );
1148 thePrs.myOutlet = aMakeWire.Edge();
1150 aMakeWire.Add( anEdgRight );
1151 thePrs.myRightBank = aMakeWire.Edge();
1153 TopoDS_Wire aSectProfileWire;
1154 if(aMakeWire.IsDone())
1155 aSectProfileWire = aMakeWire.Wire();
1157 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
1160 if( aMakeFace.IsDone() )
1161 aFace = aMakeFace.Face();
1163 TopoDS_Shape aPrs2D;
1165 if ( !theArrOf2DProfiles.IsNull() ) {
1167 aBB.MakeCompound(aCmp);
1168 aBB.Add(aCmp,aFace);
1169 for(int i=1;i <= theArrOf2DProfiles->Length(); i++)
1170 aBB.Add(aCmp, theArrOf2DProfiles->Value(i));
1179 thePrs.myPrs2D = aPrs2D;
1182 BRepTools::Write(aPrs2D, "str2d.brep");
1183 thePrs.myPrs2D = aPrs2D;