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"
30 #include "HYDROData_DTM.h"
31 #include <HYDROData_Bathymetry.h>
33 #include <TDataStd_RealArray.hxx>
35 #include <Precision.hxx>
37 #include <NCollection_DataMap.hxx>
39 #include <TColStd_Array1OfReal.hxx>
40 #include <TColStd_ListOfReal.hxx>
41 #include <TColStd_ListIteratorOfListOfReal.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_HArray1OfShape.hxx>
78 #include <TopTools_IndexedMapOfOrientedShape.hxx>
79 #include <TopTools_ListIteratorOfListOfShape.hxx>
80 #include <TopTools_SequenceOfShape.hxx>
81 #include <TopTools_IndexedMapOfShape.hxx>
84 #include <QStringList>
87 //#define DEB_STREAM 1
89 //#define DEB_HASINT 1
90 //#define DEB_UPDATE 1
91 #include <BRepTools.hxx>
92 #include <TCollection_AsciiString.hxx>
97 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
99 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
102 HYDROData_Stream::HYDROData_Stream()
103 : HYDROData_NaturalObject( Geom_3d )
107 HYDROData_Stream::~HYDROData_Stream()
111 QStringList HYDROData_Stream::DumpToPython( const QString& thePyScriptPath,
112 MapOfTreatedObjects& theTreatedObjects ) const
114 QStringList aResList = dumpObjectCreation( theTreatedObjects );
115 QString aName = GetObjPyName();
117 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
118 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
120 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
121 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
123 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
124 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
127 // Set bottom polyline if exists
128 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
129 if ( !aBottomPolyline.IsNull() ) {
130 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
133 QString aDDZs = QString::number( GetDDZ(), 'f', 3 );
134 QString aSSteps = QString::number( GetSpatialStep(), 'f', 3 );
135 aResList << QString( "%1.SetDDZ( %2 )" ).arg( aName ).arg( aDDZs );
136 aResList << QString( "%1.SetSpatialStep( %2 )" ).arg( aName ).arg( aSSteps );
138 aResList << QString( "" );
139 aResList << QString( "%1.Update()" ).arg( aName );
140 aResList << QString( "" );
145 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
147 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
149 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
150 if ( !aHydAxis.IsNull() )
151 aResSeq.Append( aHydAxis );
153 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
154 aResSeq.Append( aSeqOfProfiles );
159 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
160 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
162 Handle(Geom_BSplineCurve) aBSpline;
163 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
164 anInterpolator.Perform() ;
165 if (anInterpolator.IsDone())
166 aBSpline = anInterpolator.Curve();
170 void HYDROData_Stream::Update()
172 if (!GetHydraulicAxis().IsNull())
173 updateProfilesOrder();
175 // Update bottom polyline if exists
176 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
177 if ( !aBottomPolyline.IsNull() ) {
178 if ( GenerateBottomPolyline() ) {
179 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
180 if ( !aPolylineXY.IsNull() ) {
181 aPolylineXY->Update();
183 aBottomPolyline->Update();
187 Handle(HYDROData_DTM) dtm = DTM();
191 HYDROData_NaturalObject::Update();
194 bool HYDROData_Stream::IsHas2dPrs() const
199 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_DTM)& theDTM,
200 PrsDefinition& thePrs )
202 if ( theDTM.IsNull() )
205 HYDROData_SequenceOfObjects profiles = theDTM->GetProfiles();
206 if( profiles.Length() < 2 )
209 TopoDS_Shape Out3dPres;
210 TopoDS_Shape Out2dPres;
211 TopoDS_Shape OutLeftB;
212 TopoDS_Shape OutRightB;
213 TopoDS_Shape OutInlet;
214 TopoDS_Shape OutOutlet;
216 theDTM->GetPresentationShapes(Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet);
218 thePrs.myInlet = OutInlet;
219 thePrs.myOutlet = OutOutlet;
220 thePrs.myLeftBank = OutLeftB;
221 thePrs.myRightBank = OutRightB;
222 thePrs.myPrs2D = Out2dPres;
223 thePrs.myPrs3D = Out3dPres;
224 /*std::vector<TopoDS_Wire> profiles3d;
225 profiles3d.reserve(profiles.Length());
228 HYDROData_SequenceOfObjects::Iterator anIter( profiles );
229 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
231 Handle(HYDROData_Profile) aProfile =
232 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
234 if ( aProfile.IsNull() )
237 const TopoDS_Shape& aProfileShape = aProfile->GetShape3D();
238 //TopExp_Explorer exp(aProfileShape, TopAbs_EDGE);
239 profiles3d.push_back( TopoDS::Wire(aProfileShape) );
245 void HYDROData_Stream::UpdatePrs( const Handle(HYDROData_DTM)& theDTM )
247 HYDROData_NaturalObject::Update();
249 PrsDefinition aResultPrs;
250 if ( !CreatePresentations( theDTM, 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() const
284 return QColor( Qt::green );
287 QColor HYDROData_Stream::DefaultBorderColor() const
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 Handle(HYDROData_DTM) HYDROData_Stream::DTM() const
332 const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
333 return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() );
336 double HYDROData_Stream::GetDDZ() const
338 return DTM()->GetDDZ();
341 void HYDROData_Stream::SetDDZ( double theDDZ )
343 DTM()->SetDDZ( theDDZ );
347 double HYDROData_Stream::GetSpatialStep() const
349 return DTM()->GetSpatialStep();
352 void HYDROData_Stream::SetSpatialStep( double theSpatialStep )
354 DTM()->SetSpatialStep( theSpatialStep );
358 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
360 if ( !IsValidAsAxis( theAxis ) )
363 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
364 if ( IsEqual( aPrevAxis, theAxis ) )
367 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
369 // Update the order of profiles
370 updateProfilesOrder();
372 // Indicate model of the need to update the stream presentation
378 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
380 return Handle(HYDROData_PolylineXY)::DownCast(
381 GetReferenceObject( DataTag_HydraulicAxis ) );
384 void HYDROData_Stream::RemoveHydraulicAxis()
386 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
387 if ( aPrevAxis.IsNull() )
390 ClearReferenceObjects( DataTag_HydraulicAxis );
392 // We remove the reference profiles
395 // Indicate model of the need to update the stream presentation
399 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
400 const TopoDS_Face& thePlane,
401 Standard_Real& theOutPar ) const
403 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
404 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
407 #include <BRepAlgo_NormalProjection.hxx>
409 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
410 const Handle(HYDROData_Profile)& theProfile,
411 const TopoDS_Face& thePlane,
412 Standard_Real& theOutPar )
414 if ( theProfile.IsNull() /*|| !IsValidAsAxis( theHydAxis )*/ )
417 if (theHydAxis.IsNull())
418 return true; //empty h_axis; its's OK
420 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
421 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
422 if ( aProfileWire.IsNull() )
425 //BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
426 BRepAlgo_NormalProjection nproj(thePlane);
427 nproj.Add(aProfileWire);
428 nproj.SetDefaultParams();
432 TopoDS_Shape aPrjProfile = nproj.Projection();
433 if(aPrjProfile.IsNull())
435 TopoDS_Vertex aV1, aV2;
436 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
437 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
438 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
439 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
440 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
441 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
443 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
445 anExp.Init(aPrjProfile, TopAbs_EDGE);
447 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
451 if(aV1.IsNull() || aV2.IsNull())
453 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
454 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
457 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
460 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
461 Standard_Integer aNum(0);
463 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
464 for(;anExplo.More();anExplo.Next()) aNum++;
465 // check for self-intersection
466 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
467 Standard_Boolean hasInt(false);
468 Standard_Real aSqDist(DBL_MAX);
469 Standard_Integer anIndx(0);
470 BRepExtrema_ExtCC aCC;
471 aCC.Initialize(anEdg2);
473 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
474 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
475 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
478 Standard_Boolean hasSol(false);
482 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
483 if(aCC.SquareDistance(i) < aSqDist) {
484 aSqDist = aCC.SquareDistance(i);
490 if(aSqDist <= SquareTolerance) { // hasInt
491 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
493 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
494 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
496 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
504 TopExp::Vertices(anEdg1, aV1, aV2);
505 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
508 } else if(aNum > 1) {
509 TopExp::Vertices(anEdg1, aV1, aV2);
510 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
518 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
520 if ( theProfile.IsNull() )
523 // Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
524 // if ( aHydAxis.IsNull() )
528 BuildRefFace( aPlane );
530 Standard_Real aPar(.0);
531 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
532 return false; // Object is already in reference list or it has no intersection
534 int aProfileIndex = insertParameter( aPar );
535 insertProfileInToOrder( theProfile, aProfileIndex );
537 DTM()->SetProfiles( GetProfiles() );
539 // Indicate model of the need to update the stream presentation
545 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
546 const bool& theIsToOrder )
550 for ( int i = 1; i <= theProfiles.Length(); ++i )
552 Handle(HYDROData_Profile) aProfile =
553 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
554 if ( aProfile.IsNull() )
557 if ( !AddProfile( aProfile ) )
559 DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
564 else // Just store the sequence of objects as is
566 bool anIsToUpdate = true;
568 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
569 if ( anOldProfiles.Length() == theProfiles.Length() )
571 anIsToUpdate = false;
573 for ( int i = 1; i <= theProfiles.Length(); ++i )
575 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
576 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
577 if ( !IsEqual( anOldProfile, aNewProfile ) )
585 SetReferenceObjects( theProfiles, DataTag_Profile );
591 DTM()->SetProfiles( GetProfiles() );
595 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
597 return GetReferenceObjects( DataTag_Profile );
600 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
602 if ( theProfile.IsNull() )
605 int aProfileIndex = -1;
607 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
608 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
609 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
611 Handle(HYDROData_Profile) aProfile =
612 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
613 if ( aProfile.IsNull() )
616 if ( IsEqual( theProfile, aProfile ) )
623 if ( aProfileIndex == -1 )
626 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
628 // Remove parameter for removed profile
629 removeParameter( aProfileIndex );
631 // Indicate model of the need to update the stream presentation
637 void HYDROData_Stream::RemoveProfiles()
639 ClearReferenceObjects( DataTag_Profile );
641 // Remove the parameters array
642 removeParametersArray();
644 // Indicate model of the need to update the stream presentation
648 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
649 const int theBeforeIndex )
651 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
652 if ( theProfile.IsNull() )
655 //TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
656 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
657 if ( aProfileWire.IsNull() )
660 if ( theBeforeIndex == -1 )
661 AddReferenceObject( theProfile, DataTag_Profile );
663 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
666 void HYDROData_Stream::BuildRefFace( TopoDS_Face& thePlane )
668 thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face();
671 void HYDROData_Stream::updateProfilesOrder()
673 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
674 if ( aRefProfiles.IsEmpty() )
677 // At first we remove all profiles from order
680 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
681 if ( aHydAxis.IsNull() )
685 BuildRefFace( aPlane );
687 Standard_Real aPar( .0 );
691 TopoDS_Compound aCmp;
692 aBB.MakeCompound(aCmp);
695 HYDROData_DataMapOfRealOfHDProfile aDM;
696 TColStd_ListOfReal aList;
697 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
698 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
700 Handle(HYDROData_Profile) aProfile =
701 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
703 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
704 aBB.Add( aCmp, aProfileWire );
706 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
709 aDM.Bind( aPar, aProfile );
710 aList.Append( aPar );
713 if ( aList.IsEmpty() )
716 QVector<double> anArr( aList.Extent() );
718 TColStd_ListIteratorOfListOfReal it( aList );
719 for ( int j = 1; it.More(); it.Next(), j++ )
720 anArr[j-1] = it.Value();
723 if ( aList.Extent() > 1 )
725 //TCollection_CompareOfReal Compar;
726 //SortTools_QuickSortOfReal::Sort( anArr, Compar );
727 std::sort( anArr.begin(), anArr.end() );
729 for (int j = 1; j <= anArr.size(); j++) {
730 const Standard_Real aKey = anArr[j-1];
731 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
732 insertProfileInToOrder( aProfile );
734 } else if ( aList.Extent() == 1 ) {
735 const Standard_Real aKey = aList.Last();
736 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
737 insertProfileInToOrder( aProfile );
740 setParametersArray( anArr );
743 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
744 BRepTools::Write(aHydraulicWire, "Path.brep");
745 BRepTools::Write(aCmp, "Prof.brep");
749 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
754 void HYDROData_Stream::setParametersArray( const QVector<double>& theArray )
756 if ( theArray.size() == 0 )
758 removeParametersArray();
762 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
764 int n = theArray.size();
765 Handle(TDataStd_RealArray) aParamsArray =
766 TDataStd_RealArray::Set( aLabel, 1, n );
767 for ( int i = 0; i < n; ++i )
769 const Standard_Real& aParam = theArray[i];
770 aParamsArray->SetValue( i+1, aParam );
774 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
776 TColStd_Array1OfReal* anArray = NULL;
778 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
779 if ( !aLabel.IsNull() )
781 Handle(TDataStd_RealArray) aParamsArray;
782 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
784 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
785 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
787 const Standard_Real& aParam = aParamsArray->Value( i );
788 anArray->SetValue( i, aParam );
796 void HYDROData_Stream::removeParametersArray()
798 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
799 if ( !aLabel.IsNull() )
800 aLabel.ForgetAllAttributes();
803 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
807 TColStd_Array1OfReal* anArr = getParametersArray();
812 QVector<double> aNewArr( anArr->Upper() );
814 bool isInserted = false;
815 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
817 const Standard_Real& aStoredParam = anArr->Value( i );
820 if ( theParam > aStoredParam )
826 aNewArr[j-1] = theParam;
832 aNewArr[j-1] = aStoredParam;
838 aNewArr[aNewArr.size()-1] = theParam;
841 setParametersArray( aNewArr );
846 QVector<double> aNewArr( 1 );
847 aNewArr[0] = theParam;
848 setParametersArray( aNewArr );
854 void HYDROData_Stream::removeParameter( const int& theIndex )
856 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
857 if ( aLabel.IsNull() )
860 Handle(TDataStd_RealArray) aParamsArray;
861 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
864 if ( aParamsArray->Length() == 1 )
866 removeParametersArray();
870 QVector<double> aNewArr( aParamsArray->Upper() - 2 );
872 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
874 const Standard_Real& aStoredParam = aParamsArray->Value( i );
878 aNewArr[j-1] = aStoredParam;
882 setParametersArray( aNewArr );
885 bool HYDROData_Stream::GenerateBottomPolyline()
888 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
889 if ( aDocument.IsNull() ) {
893 // Collect bottom points ( one bottom point from each profile of the stream )
894 HYDROData_Profile::ProfilePoints aBottomPoints;
896 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
897 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
898 const Handle(HYDROData_Profile) aProfile =
899 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
900 if ( aProfile.IsNull() ) {
904 aBottomPoints.Append( aProfile->GetBottomPoint() );
907 int aNbBottomPoints = aBottomPoints.Size();
909 if ( aNbBottomPoints < 2 ) {
913 // Create bottom polyline object if the stream doesn't contain it yet
914 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
915 if ( aBottom.IsNull() ) {
916 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
917 QString aBaseName = GetName() + "_bottom";
918 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
919 aBottom->SetName( aName );
921 SetReferenceObject( aBottom, DataTag_BottomPolyline );
924 // Create 2D polyline if the bottom polyline doesn't contain it yet
925 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
926 if ( aPolylineXY.IsNull() ) {
927 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
928 QString aBaseName = GetName() + "_bottom_2d";
929 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
930 aPolylineXY->SetName( aName );
931 aBottom->SetPolylineXY( aPolylineXY, false );
934 aPolylineXY->RemoveSections();
935 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
937 // Create profile if the bottom polyline doesn't contain it yet
938 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
939 if ( aProfileUZ.IsNull() ) {
940 Handle(HYDROData_Profile) aProfile =
941 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
942 QString aBaseName = GetName() + "_bottom_profile";
943 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
944 aProfile->SetName( aName );
945 aProfileUZ = aProfile->GetProfileUZ( true );
946 aBottom->SetProfileUZ( aProfileUZ );
949 aProfileUZ->RemoveSection( 0 );
951 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
956 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
958 return Handle(HYDROData_Polyline3D)::DownCast(
959 GetReferenceObject( DataTag_BottomPolyline ) );
962 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
964 if ( theBottom.IsNull() ) {
968 SetReferenceObject( theBottom, DataTag_BottomPolyline );
973 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
976 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
977 if ( aDocument.IsNull() ) {
981 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
982 theInterpolator->Calculate();
985 if ( theInterpolator->GetErrorCode() != OK ) {
991 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
992 // Get calculated point coordinates
993 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
994 if ( aResultPoints.IsEmpty() ) {
999 // Create profile object
1000 Handle(HYDROData_Profile) aProfile =
1001 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1002 QString aBaseName = GetName() + "_interp_profile";
1003 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
1004 aProfile->SetName( aName );
1006 // Fill the profile with points
1007 aProfile->SetProfilePoints( aResultPoints );
1009 // Add profile to the stream
1010 bool isAdded = AddProfile( aProfile );
1024 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1025 bool isGenerateNewName ) const
1028 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1029 if ( aDocument.IsNull() ) {
1034 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1036 Handle(HYDROData_Stream) aStreamCopy =
1037 Handle(HYDROData_Stream)::DownCast( theDestination );
1039 // Copy bottom polyline if exists
1040 if ( !aStreamCopy.IsNull() ) {
1041 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1042 if ( !aBottom.IsNull() ) {
1043 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1044 aStreamCopy->GenerateBottomPolyline();
1045 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1046 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1047 aBottomCopy->GetPolylineXY()->Update();
1048 aBottomCopy->Update();
1053 void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1054 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1055 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1056 PrsDefinition& thePrs )
1059 HYDROData_Bathymetry::AltitudePoints left;
1060 for (int i = theArrayOfLPnt->Lower(); i <= theArrayOfLPnt->Upper(); i++)
1062 left.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfLPnt->Value(i).X(),
1063 theArrayOfLPnt->Value(i).Y(),
1064 theArrayOfLPnt->Value(i).Z()));
1067 HYDROData_Bathymetry::AltitudePoints right;
1068 for (int i = theArrayOfFPnt->Lower(); i <= theArrayOfFPnt->Upper(); i++)
1070 right.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfFPnt->Value(i).X(),
1071 theArrayOfFPnt->Value(i).Y(),
1072 theArrayOfFPnt->Value(i).Z()));
1075 std::vector<HYDROData_Bathymetry::AltitudePoints> dummy;
1076 TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy);
1078 TopoDS_Shape LB, RB, IL, OL;
1082 TopAbs_ShapeEnum ll1_sht = ll(1).ShapeType();
1083 TopAbs_ShapeEnum ll2_sht = ll(2).ShapeType();
1084 if ((ll1_sht == TopAbs_WIRE || ll1_sht == TopAbs_EDGE) &&
1085 (ll2_sht == TopAbs_WIRE || ll2_sht == TopAbs_EDGE))
1092 IL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
1093 OL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
1095 //make new compound so it's shapes will be in known order to build correct projection
1097 TopoDS_Compound newCmp;
1098 BB.MakeCompound(newCmp);
1104 thePrs.myPrs3D = newCmp;
1106 TopTools_SequenceOfShape LS;
1107 //HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D), &LS, ind );
1109 HYDROData_DTM::GetPlanarFaceFromBanks(TopoDS::Edge(LB), TopoDS::Edge(RB), TopoDS::Face(thePrs.myPrs2D), &LS);
1112 TopTools_IndexedMapOfShape EE;
1113 TopExp::MapShapes(thePrs.myPrs2D, TopAbs_EDGE, EE);
1115 for (int i = 1; i <= 4; i++)
1117 TopoDS_Shape W = LS(i);
1118 TopTools_IndexedMapOfShape EW;
1119 TopExp::MapShapes(W, TopAbs_EDGE, EW);
1120 for (int k = 1; k <= EW.Extent(); k++)
1121 noncontNb += !EE.Contains(EW(k));
1123 //noncontNb > 0 => some problem with edge history
1124 assert(noncontNb == 0);
1127 thePrs.myLeftBank = LS(1);
1128 thePrs.myInlet = LS(2);
1129 thePrs.myOutlet = LS(3);
1130 thePrs.myRightBank = LS(4);