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( const QString& thePyScriptPath,
107 MapOfTreatedObjects& theTreatedObjects ) const
109 QStringList aResList = dumpObjectCreation( theTreatedObjects );
110 QString aName = GetObjPyName();
112 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
113 setPythonReferenceObject( thePyScriptPath, 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( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
122 // Set bottom polyline if exists
123 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
124 if ( !aBottomPolyline.IsNull() ) {
125 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
128 aResList << QString( "" );
129 aResList << QString( "%1.Update()" ).arg( aName );
130 aResList << QString( "" );
135 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
137 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
139 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
140 if ( !aHydAxis.IsNull() )
141 aResSeq.Append( aHydAxis );
143 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
144 aResSeq.Append( aSeqOfProfiles );
149 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
150 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
152 Handle(Geom_BSplineCurve) aBSpline;
153 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
154 anInterpolator.Perform() ;
155 if (anInterpolator.IsDone())
156 aBSpline = anInterpolator.Curve();
160 void HYDROData_Stream::Update()
162 updateProfilesOrder();
164 // Update bottom polyline if exists
165 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
166 if ( !aBottomPolyline.IsNull() ) {
167 if ( GenerateBottomPolyline() ) {
168 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
169 if ( !aPolylineXY.IsNull() ) {
170 aPolylineXY->Update();
172 aBottomPolyline->Update();
179 bool HYDROData_Stream::IsHas2dPrs() const
184 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_PolylineXY)& theHydAxis,
185 const HYDROData_SequenceOfObjects& theProfiles,
186 PrsDefinition& thePrs )
188 if ( theHydAxis.IsNull() || theProfiles.Length() < 2 )
191 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
192 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, theProfiles.Length());
193 Handle(TopTools_HArray1OfShape) anArrOfProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
194 Handle(TopTools_HArray1OfShape) anArrOf2DProfiles = new TopTools_HArray1OfShape(1, theProfiles.Length());
197 HYDROData_SequenceOfObjects::Iterator anIter( theProfiles );
198 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
200 Handle(HYDROData_Profile) aProfile =
201 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
202 if ( aProfile.IsNull() )
205 const TopoDS_Shape& aProf3d = aProfile->GetShape3D();
207 if ( !aProfile->GetLeftPoint( aPnt1, false ) || !aProfile->GetRightPoint( aPnt2, false ) )
210 anArrOfProfiles->SetValue(i,aProfile->GetShape3D());//aProfile->GetTopShape();
211 anArrOf2DProfiles->SetValue(i,aProfile->GetTopShape());
213 gp_Pnt aCurFP, aCurLP;
214 TopoDS_Vertex aV1, aV2;
215 TopExp::Vertices(TopoDS::Wire(aProf3d), aV1, aV2);
216 gp_Pnt aP1 = BRep_Tool::Pnt(aV1);
217 if(aP1.X() == aPnt1.X() && aP1.Y() == aPnt1.Y())
221 aP1 = BRep_Tool::Pnt(aV2);
222 if(aP1.X() == aPnt2.X() && aP1.Y() == aPnt2.Y())
226 anArrayOfFPnt->SetValue(i,aCurFP);
227 anArrayOfLPnt->SetValue(i,aCurLP);
230 return CreatePresentations( anArrayOfFPnt, anArrayOfLPnt, anArrOfProfiles, anArrOf2DProfiles, thePrs );
233 void HYDROData_Stream::UpdatePrs()
235 HYDROData_NaturalObject::Update();
237 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
238 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
240 PrsDefinition aResultPrs;
241 if ( !CreatePresentations( aHydAxis, aRefProfiles, aResultPrs ) )
244 SetShape3D( aResultPrs.myPrs3D );
245 SetTopShape( aResultPrs.myPrs2D );
247 // Create the stream groups
248 QString aLeftGroupName = GetName() + "_Left_Bank";
250 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
251 aLeftGroup->SetName( aLeftGroupName );
252 aLeftGroup->AddShape( aResultPrs.myLeftBank );
254 QString aRightGroupName = GetName() + "_Right_Bank";
256 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
257 aRightGroup->SetName( aRightGroupName );
258 aRightGroup->AddShape( aResultPrs.myRightBank );
260 QString anInGroupName = GetName() + "_Inlet";
262 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
263 anInGroup->SetName( anInGroupName );
264 anInGroup->AddShape( aResultPrs.myInlet );
266 QString anOutGroupName = GetName() + "_Outlet";
268 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
269 anOutGroup->SetName( anOutGroupName );
270 anOutGroup->AddShape( aResultPrs.myOutlet );
273 QColor HYDROData_Stream::DefaultFillingColor() const
275 return QColor( Qt::green );
278 QColor HYDROData_Stream::DefaultBorderColor() const
280 return QColor( Qt::transparent );
283 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
285 if ( theHydAxis.IsNull() )
288 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
289 if ( aHydraulicShape.IsNull() ||
290 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
291 BRep_Tool::IsClosed( aHydraulicShape ) )
292 return false; // The polyline must be a single not closed wire
297 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
299 HYDROData_SequenceOfObjects aGroups = GetGroups();
300 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
303 TopoDS_Shape HYDROData_Stream::GetRightShape() const
305 HYDROData_SequenceOfObjects aGroups = GetGroups();
306 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
309 TopoDS_Shape HYDROData_Stream::GetInletShape() const
311 HYDROData_SequenceOfObjects aGroups = GetGroups();
312 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
315 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
317 HYDROData_SequenceOfObjects aGroups = GetGroups();
318 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
321 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
323 if ( !IsValidAsAxis( theAxis ) )
326 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
327 if ( IsEqual( aPrevAxis, theAxis ) )
330 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
332 // Update the order of profiles
333 updateProfilesOrder();
335 // Indicate model of the need to update the stream presentation
341 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
343 return Handle(HYDROData_PolylineXY)::DownCast(
344 GetReferenceObject( DataTag_HydraulicAxis ) );
347 void HYDROData_Stream::RemoveHydraulicAxis()
349 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
350 if ( aPrevAxis.IsNull() )
353 ClearReferenceObjects( DataTag_HydraulicAxis );
355 // We remove the reference profiles
358 // Indicate model of the need to update the stream presentation
362 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
363 const TopoDS_Face& thePlane,
364 Standard_Real& theOutPar ) const
366 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
367 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
370 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
371 const Handle(HYDROData_Profile)& theProfile,
372 const TopoDS_Face& thePlane,
373 Standard_Real& theOutPar )
375 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
378 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
379 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
380 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
383 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
384 if(!aProjector.IsDone())
386 TopoDS_Shape aPrjProfile = aProjector.Shape();
387 if(aPrjProfile.IsNull())
389 TopoDS_Vertex aV1, aV2;
390 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
391 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
392 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
393 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
394 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
395 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
397 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
399 anExp.Init(aPrjProfile, TopAbs_EDGE);
401 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
405 if(aV1.IsNull() || aV2.IsNull())
407 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
408 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
411 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
414 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
415 Standard_Integer aNum(0);
417 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
418 for(;anExplo.More();anExplo.Next()) aNum++;
419 // check for self-intersection
420 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
421 Standard_Boolean hasInt(false);
422 Standard_Real aSqDist(DBL_MAX);
423 Standard_Integer anIndx(0);
424 BRepExtrema_ExtCC aCC;
425 aCC.Initialize(anEdg2);
427 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
428 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
429 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
432 Standard_Boolean hasSol(false);
436 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
437 if(aCC.SquareDistance(i) < aSqDist) {
438 aSqDist = aCC.SquareDistance(i);
444 if(aSqDist <= SquareTolerance) { // hasInt
445 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
447 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
448 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
450 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
458 TopExp::Vertices(anEdg1, aV1, aV2);
459 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
462 } else if(aNum > 1) {
463 TopExp::Vertices(anEdg1, aV1, aV2);
464 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
472 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
474 if ( theProfile.IsNull() )
477 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
478 if ( aHydAxis.IsNull() )
482 if(!BuildFace(aHydAxis, aPlane))
485 Standard_Real aPar(.0);
486 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
487 return false; // Object is already in reference list or it has no intersection
489 int aProfileIndex = insertParameter( aPar );
490 insertProfileInToOrder( theProfile, aProfileIndex );
492 // Indicate model of the need to update the stream presentation
498 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
499 const bool& theIsToOrder )
503 for ( int i = 1; i <= theProfiles.Length(); ++i )
505 Handle(HYDROData_Profile) aProfile =
506 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
507 if ( aProfile.IsNull() )
510 if ( !AddProfile( aProfile ) )
514 else // Just store the sequence of objects as is
516 bool anIsToUpdate = true;
518 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
519 if ( anOldProfiles.Length() == theProfiles.Length() )
521 anIsToUpdate = false;
523 for ( int i = 1; i <= theProfiles.Length(); ++i )
525 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
526 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
527 if ( !IsEqual( anOldProfile, aNewProfile ) )
535 SetReferenceObjects( theProfiles, DataTag_Profile );
544 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
546 return GetReferenceObjects( DataTag_Profile );
549 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
551 if ( theProfile.IsNull() )
554 int aProfileIndex = -1;
556 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
557 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
558 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
560 Handle(HYDROData_Profile) aProfile =
561 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
562 if ( aProfile.IsNull() )
565 if ( IsEqual( theProfile, aProfile ) )
572 if ( aProfileIndex == -1 )
575 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
577 // Remove parameter for removed profile
578 removeParameter( aProfileIndex );
580 // Indicate model of the need to update the stream presentation
586 void HYDROData_Stream::RemoveProfiles()
588 ClearReferenceObjects( DataTag_Profile );
590 // Remove the parameters array
591 removeParametersArray();
593 // Indicate model of the need to update the stream presentation
597 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
598 const int theBeforeIndex )
600 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
601 if ( theProfile.IsNull() || aHydAxis.IsNull() )
604 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
605 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
606 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
609 if ( theBeforeIndex == -1 )
610 AddReferenceObject( theProfile, DataTag_Profile );
612 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
615 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
616 TopoDS_Face& thePlane )
618 if ( !IsValidAsAxis( theHydAxis ) )
621 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
623 gp_Ax2 aX2(gp::XOY());
627 BRepBndLib::Add(aHydraulicWire,B);
628 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
629 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
630 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
631 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
632 thePlane = TopoDS::Face(aMkr.Shape());
636 void HYDROData_Stream::updateProfilesOrder()
638 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
639 if ( aRefProfiles.IsEmpty() )
642 // At first we remove all profiles from order
645 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
646 if ( aHydAxis.IsNull() )
650 if ( !BuildFace( aHydAxis, aPlane ) )
653 Standard_Real aPar( .0 );
657 TopoDS_Compound aCmp;
658 aBB.MakeCompound(aCmp);
661 HYDROData_DataMapOfRealOfHDProfile aDM;
662 TColStd_ListOfReal aList;
663 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
664 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
666 Handle(HYDROData_Profile) aProfile =
667 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
669 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
670 aBB.Add( aCmp, aProfileWire );
672 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
675 aDM.Bind( aPar, aProfile );
676 aList.Append( aPar );
679 if ( aList.IsEmpty() )
682 TColStd_Array1OfReal anArr( 1, aList.Extent() );
684 TColStd_ListIteratorOfListOfReal it( aList );
685 for ( int j = 1; it.More(); it.Next(), j++ )
686 anArr( j ) = it.Value();
689 if ( aList.Extent() > 1 )
691 TCollection_CompareOfReal Compar;
692 SortTools_QuickSortOfReal::Sort( anArr, Compar );
694 for (int j = 1; j <= anArr.Length(); j++) {
695 const Standard_Real aKey = anArr(j);
696 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
697 insertProfileInToOrder( aProfile );
699 } else if ( aList.Extent() == 1 ) {
700 const Standard_Real aKey = aList.Last();
701 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
702 insertProfileInToOrder( aProfile );
705 setParametersArray( anArr );
708 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
709 BRepTools::Write(aHydraulicWire, "Path.brep");
710 BRepTools::Write(aCmp, "Prof.brep");
714 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
716 return KIND_STREAM_ALTITUDE;
719 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
721 if ( theArray.Length() == 0 )
723 removeParametersArray();
727 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
729 Handle(TDataStd_RealArray) aParamsArray =
730 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
732 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
734 const Standard_Real& aParam = theArray( i );
735 aParamsArray->SetValue( i, aParam );
739 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
741 TColStd_Array1OfReal* anArray = NULL;
743 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
744 if ( !aLabel.IsNull() )
746 Handle(TDataStd_RealArray) aParamsArray;
747 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
749 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
750 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
752 const Standard_Real& aParam = aParamsArray->Value( i );
753 anArray->SetValue( i, aParam );
761 void HYDROData_Stream::removeParametersArray()
763 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
764 if ( !aLabel.IsNull() )
765 aLabel.ForgetAllAttributes();
768 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
772 TColStd_Array1OfReal* anArr = getParametersArray();
777 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
779 bool isInserted = false;
780 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
782 const Standard_Real& aStoredParam = anArr->Value( i );
785 if ( theParam > aStoredParam )
791 aNewArr( j ) = theParam;
797 aNewArr( j ) = aStoredParam;
803 aNewArr( aNewArr.Upper() ) = theParam;
806 setParametersArray( aNewArr );
811 TColStd_Array1OfReal aNewArr( 1, 1 );
812 aNewArr.SetValue( 1, theParam );
813 setParametersArray( aNewArr );
819 void HYDROData_Stream::removeParameter( const int& theIndex )
821 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
822 if ( aLabel.IsNull() )
825 Handle(TDataStd_RealArray) aParamsArray;
826 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
829 if ( aParamsArray->Length() == 1 )
831 removeParametersArray();
835 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
837 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
839 const Standard_Real& aStoredParam = aParamsArray->Value( i );
843 aNewArr.SetValue( j, aStoredParam );
847 setParametersArray( aNewArr );
850 bool HYDROData_Stream::GenerateBottomPolyline()
853 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
854 if ( aDocument.IsNull() ) {
858 // Collect bottom points ( one bottom point from each profile of the stream )
859 HYDROData_Profile::ProfilePoints aBottomPoints;
861 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
862 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
863 const Handle(HYDROData_Profile) aProfile =
864 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
865 if ( aProfile.IsNull() ) {
869 aBottomPoints.Append( aProfile->GetBottomPoint() );
872 int aNbBottomPoints = aBottomPoints.Size();
874 if ( aNbBottomPoints < 2 ) {
878 // Create bottom polyline object if the stream doesn't contain it yet
879 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
880 if ( aBottom.IsNull() ) {
881 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
882 QString aBaseName = GetName() + "_bottom";
883 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
884 aBottom->SetName( aName );
886 SetReferenceObject( aBottom, DataTag_BottomPolyline );
889 // Create 2D polyline if the bottom polyline doesn't contain it yet
890 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
891 if ( aPolylineXY.IsNull() ) {
892 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
893 QString aBaseName = GetName() + "_bottom_2d";
894 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
895 aPolylineXY->SetName( aName );
896 aBottom->SetPolylineXY( aPolylineXY, false );
899 aPolylineXY->RemoveSections();
900 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
902 // Create profile if the bottom polyline doesn't contain it yet
903 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
904 if ( aProfileUZ.IsNull() ) {
905 Handle(HYDROData_Profile) aProfile =
906 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
907 QString aBaseName = GetName() + "_bottom_profile";
908 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
909 aProfile->SetName( aName );
910 aProfileUZ = aProfile->GetProfileUZ( true );
911 aBottom->SetProfileUZ( aProfileUZ );
914 aProfileUZ->RemoveSection( 0 );
916 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
921 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
923 return Handle(HYDROData_Polyline3D)::DownCast(
924 GetReferenceObject( DataTag_BottomPolyline ) );
927 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
929 if ( theBottom.IsNull() ) {
933 SetReferenceObject( theBottom, DataTag_BottomPolyline );
938 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
941 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
942 if ( aDocument.IsNull() ) {
946 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
947 theInterpolator->Calculate();
950 if ( theInterpolator->GetErrorCode() != OK ) {
956 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
957 // Get calculated point coordinates
958 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
959 if ( aResultPoints.IsEmpty() ) {
964 // Create profile object
965 Handle(HYDROData_Profile) aProfile =
966 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
967 QString aBaseName = GetName() + "_interp_profile";
968 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
969 aProfile->SetName( aName );
971 // Fill the profile with points
972 aProfile->SetProfilePoints( aResultPoints );
974 // Add profile to the stream
975 bool isAdded = AddProfile( aProfile );
989 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
990 bool isGenerateNewName ) const
993 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
994 if ( aDocument.IsNull() ) {
999 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1001 Handle(HYDROData_Stream) aStreamCopy =
1002 Handle(HYDROData_Stream)::DownCast( theDestination );
1004 // Copy bottom polyline if exists
1005 if ( !aStreamCopy.IsNull() ) {
1006 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1007 if ( !aBottom.IsNull() ) {
1008 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1009 aStreamCopy->GenerateBottomPolyline();
1010 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1011 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1012 aBottomCopy->GetPolylineXY()->Update();
1013 aBottomCopy->Update();
1019 bool HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1020 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1021 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1022 const Handle(TopTools_HArray1OfShape) theArrOf2DProfiles,
1023 PrsDefinition& thePrs )
1025 if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) {
1029 if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) {
1033 // Construct of the 3D presentation
1034 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt);
1035 if(aBSpline.IsNull())
1038 TopoDS_Edge anEdgLeft, anEdgRight;
1040 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
1041 if(aMakeEdge.IsDone())
1042 anEdgLeft = aMakeEdge.Edge();
1044 if(anEdgLeft.IsNull())
1048 aBSpline = buildInterpolationCurve (theArrayOfLPnt);
1049 if(aBSpline.IsNull())
1052 aMakeEdge.Init(aBSpline);
1053 if(aMakeEdge.IsDone())
1054 anEdgRight = aMakeEdge.Edge();
1056 if(anEdgRight.IsNull())
1060 TopoDS_Compound aCmp;
1061 aBB.MakeCompound(aCmp);
1062 for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ )
1063 aBB.Add(aCmp, theArrOfProfiles->Value(i));
1065 aBB.Add(aCmp,anEdgLeft);
1066 aBB.Add(aCmp,anEdgRight);
1067 BRepCheck_Analyzer aCh(aCmp);
1069 thePrs.myPrs3D = aCmp;
1072 BRepTools::Write(aCmp, "str3d.brep");
1073 thePrs.myPrs3D = aCmp;
1077 // Construct the top presentation
1078 int aNbPoints = theArrayOfFPnt->Length();
1079 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1080 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1081 for( int i=1; i <= aNbPoints; i++ ) {
1082 gp_Pnt aPnt = theArrayOfFPnt->Value(i);
1083 aPnt.SetZ(.0); // make 2d
1084 anArrayOfFPnt->SetValue(i, aPnt);
1085 aPnt = theArrayOfLPnt->Value(i);
1087 anArrayOfLPnt->SetValue(i, aPnt);
1091 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
1092 if(aBSpline.IsNull())
1095 aMakeEdge.Init(aBSpline);
1096 if(aMakeEdge.IsDone())
1097 anEdgLeft = aMakeEdge.Edge();
1100 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
1101 if(aBSpline.IsNull())
1104 aMakeEdge.Init(aBSpline);
1105 if(aMakeEdge.IsDone())
1106 anEdgRight = aMakeEdge.Edge();
1107 if(anEdgRight.IsNull())
1110 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
1111 TopoDS_Edge aBotEdge, aTopEdge;
1112 if(aMakeEdge2.IsDone())
1113 aBotEdge = aMakeEdge2.Edge();
1115 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
1116 if(aMakeEdge3.IsDone())
1117 aTopEdge = aMakeEdge3.Edge();
1119 // Make wire for 2D presentation with updating of corresponding edges
1120 BRepBuilderAPI_MakeWire aMakeWire;
1122 aMakeWire.Add( aBotEdge );
1123 thePrs.myInlet = aMakeWire.Edge();
1125 aMakeWire.Add( anEdgLeft );
1126 thePrs.myLeftBank = aMakeWire.Edge();
1128 aMakeWire.Add( aTopEdge );
1129 thePrs.myOutlet = aMakeWire.Edge();
1131 aMakeWire.Add( anEdgRight );
1132 thePrs.myRightBank = aMakeWire.Edge();
1134 TopoDS_Wire aSectProfileWire;
1135 if(aMakeWire.IsDone())
1136 aSectProfileWire = aMakeWire.Wire();
1138 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
1141 if( aMakeFace.IsDone() )
1142 aFace = aMakeFace.Face();
1144 TopoDS_Shape aPrs2D;
1146 if ( !theArrOf2DProfiles.IsNull() ) {
1148 aBB.MakeCompound(aCmp);
1149 aBB.Add(aCmp,aFace);
1150 for(int i=1;i <= theArrOf2DProfiles->Length(); i++)
1151 aBB.Add(aCmp, theArrOf2DProfiles->Value(i));
1160 thePrs.myPrs2D = aPrs2D;
1163 BRepTools::Write(aPrs2D, "str2d.brep");
1164 thePrs.myPrs2D = aPrs2D;