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 <TCollection_CompareOfReal.hxx>
43 #include <TColgp_Array1OfPnt.hxx>
44 #include <TColgp_HArray1OfPnt.hxx>
47 #include <TopoDS_Wire.hxx>
48 #include <TopoDS_Shell.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Vertex.hxx>
53 #include <TopExp_Explorer.hxx>
55 #include <Bnd_Box.hxx>
57 #include <BRep_Builder.hxx>
58 #include <BRepBuilderAPI_MakeEdge.hxx>
59 #include <BRepBuilderAPI_MakeWire.hxx>
60 #include <BRepBuilderAPI_MakeFace.hxx>
62 #include <BRepBndLib.hxx>
63 #include <BRepProj_Projection.hxx>
64 #include <BRepExtrema_ExtCC.hxx>
65 #include <BRepCheck_Analyzer.hxx>
75 #include <GeomAPI_Interpolate.hxx>
76 #include <Geom_BSplineCurve.hxx>
78 #include <TopTools_HArray1OfShape.hxx>
79 #include <TopTools_IndexedMapOfOrientedShape.hxx>
80 #include <TopTools_ListIteratorOfListOfShape.hxx>
81 #include <TopTools_SequenceOfShape.hxx>
82 #include <TopTools_IndexedMapOfShape.hxx>
84 #include <SortTools_QuickSortOfReal.hxx>
87 #include <QStringList>
89 //#define DEB_STREAM 1
91 //#define DEB_HASINT 1
92 //#define DEB_UPDATE 1
93 #include <BRepTools.hxx>
94 #include <TCollection_AsciiString.hxx>
99 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
101 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
102 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
105 HYDROData_Stream::HYDROData_Stream()
106 : HYDROData_NaturalObject( Geom_3d )
110 HYDROData_Stream::~HYDROData_Stream()
114 QStringList HYDROData_Stream::DumpToPython( const QString& thePyScriptPath,
115 MapOfTreatedObjects& theTreatedObjects ) const
117 QStringList aResList = dumpObjectCreation( theTreatedObjects );
118 QString aName = GetObjPyName();
120 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
121 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
123 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
124 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
126 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
127 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
130 // Set bottom polyline if exists
131 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
132 if ( !aBottomPolyline.IsNull() ) {
133 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
136 QString aDDZs = QString::number( GetDDZ(), 'f', 3 );
137 QString aSSteps = QString::number( GetSpatialStep(), 'f', 3 );
138 aResList << QString( "%1.SetDDZ( %2 )" ).arg( aName ).arg( aDDZs );
139 aResList << QString( "%1.SetSpatialStep( %2 )" ).arg( aName ).arg( aSSteps );
141 aResList << QString( "" );
142 aResList << QString( "%1.Update()" ).arg( aName );
143 aResList << QString( "" );
148 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
150 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
152 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
153 if ( !aHydAxis.IsNull() )
154 aResSeq.Append( aHydAxis );
156 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
157 aResSeq.Append( aSeqOfProfiles );
162 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
163 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
165 Handle(Geom_BSplineCurve) aBSpline;
166 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
167 anInterpolator.Perform() ;
168 if (anInterpolator.IsDone())
169 aBSpline = anInterpolator.Curve();
173 void HYDROData_Stream::Update()
175 if (!GetHydraulicAxis().IsNull())
176 updateProfilesOrder();
178 // Update bottom polyline if exists
179 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
180 if ( !aBottomPolyline.IsNull() ) {
181 if ( GenerateBottomPolyline() ) {
182 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
183 if ( !aPolylineXY.IsNull() ) {
184 aPolylineXY->Update();
186 aBottomPolyline->Update();
190 Handle_HYDROData_DTM dtm = DTM();
194 HYDROData_NaturalObject::Update();
197 bool HYDROData_Stream::IsHas2dPrs() const
202 bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM,
203 PrsDefinition& thePrs )
205 if ( theDTM.IsNull() )
208 HYDROData_SequenceOfObjects profiles = theDTM->GetProfiles();
209 if( profiles.Length() < 2 )
212 TopoDS_Shape Out3dPres;
213 TopoDS_Shape Out2dPres;
214 TopoDS_Shape OutLeftB;
215 TopoDS_Shape OutRightB;
216 TopoDS_Shape OutInlet;
217 TopoDS_Shape OutOutlet;
219 theDTM->GetPresentationShapes(Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet);
221 thePrs.myInlet = OutInlet;
222 thePrs.myOutlet = OutOutlet;
223 thePrs.myLeftBank = OutLeftB;
224 thePrs.myRightBank = OutRightB;
225 thePrs.myPrs2D = Out2dPres;
226 thePrs.myPrs3D = Out3dPres;
227 /*std::vector<TopoDS_Wire> profiles3d;
228 profiles3d.reserve(profiles.Length());
231 HYDROData_SequenceOfObjects::Iterator anIter( profiles );
232 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
234 Handle(HYDROData_Profile) aProfile =
235 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
237 if ( aProfile.IsNull() )
240 const TopoDS_Shape& aProfileShape = aProfile->GetShape3D();
241 //TopExp_Explorer exp(aProfileShape, TopAbs_EDGE);
242 profiles3d.push_back( TopoDS::Wire(aProfileShape) );
248 void HYDROData_Stream::UpdatePrs( const Handle_HYDROData_DTM& theDTM )
250 HYDROData_NaturalObject::Update();
252 PrsDefinition aResultPrs;
253 if ( !CreatePresentations( theDTM, aResultPrs ) )
256 SetShape3D( aResultPrs.myPrs3D );
257 SetTopShape( aResultPrs.myPrs2D );
259 // Create the stream groups
260 QString aLeftGroupName = GetName() + "_Left_Bank";
262 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
263 aLeftGroup->SetName( aLeftGroupName );
264 aLeftGroup->AddShape( aResultPrs.myLeftBank );
266 QString aRightGroupName = GetName() + "_Right_Bank";
268 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
269 aRightGroup->SetName( aRightGroupName );
270 aRightGroup->AddShape( aResultPrs.myRightBank );
272 QString anInGroupName = GetName() + "_Inlet";
274 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
275 anInGroup->SetName( anInGroupName );
276 anInGroup->AddShape( aResultPrs.myInlet );
278 QString anOutGroupName = GetName() + "_Outlet";
280 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
281 anOutGroup->SetName( anOutGroupName );
282 anOutGroup->AddShape( aResultPrs.myOutlet );
285 QColor HYDROData_Stream::DefaultFillingColor() const
287 return QColor( Qt::green );
290 QColor HYDROData_Stream::DefaultBorderColor() const
292 return QColor( Qt::transparent );
295 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
297 if ( theHydAxis.IsNull() )
300 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
301 if ( aHydraulicShape.IsNull() ||
302 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
303 BRep_Tool::IsClosed( aHydraulicShape ) )
304 return false; // The polyline must be a single not closed wire
309 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
311 HYDROData_SequenceOfObjects aGroups = GetGroups();
312 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
315 TopoDS_Shape HYDROData_Stream::GetRightShape() const
317 HYDROData_SequenceOfObjects aGroups = GetGroups();
318 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
321 TopoDS_Shape HYDROData_Stream::GetInletShape() const
323 HYDROData_SequenceOfObjects aGroups = GetGroups();
324 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
327 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
329 HYDROData_SequenceOfObjects aGroups = GetGroups();
330 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
333 Handle_HYDROData_DTM HYDROData_Stream::DTM() const
335 const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
336 return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() );
339 double HYDROData_Stream::GetDDZ() const
341 return DTM()->GetDDZ();
344 void HYDROData_Stream::SetDDZ( double theDDZ )
346 DTM()->SetDDZ( theDDZ );
350 double HYDROData_Stream::GetSpatialStep() const
352 return DTM()->GetSpatialStep();
355 void HYDROData_Stream::SetSpatialStep( double theSpatialStep )
357 DTM()->SetSpatialStep( theSpatialStep );
361 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
363 if ( !IsValidAsAxis( theAxis ) )
366 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
367 if ( IsEqual( aPrevAxis, theAxis ) )
370 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
372 // Update the order of profiles
373 updateProfilesOrder();
375 // Indicate model of the need to update the stream presentation
381 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
383 return Handle(HYDROData_PolylineXY)::DownCast(
384 GetReferenceObject( DataTag_HydraulicAxis ) );
387 void HYDROData_Stream::RemoveHydraulicAxis()
389 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
390 if ( aPrevAxis.IsNull() )
393 ClearReferenceObjects( DataTag_HydraulicAxis );
395 // We remove the reference profiles
398 // Indicate model of the need to update the stream presentation
402 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
403 const TopoDS_Face& thePlane,
404 Standard_Real& theOutPar ) const
406 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
407 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
410 #include <BRepAlgo_NormalProjection.hxx>
412 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
413 const Handle(HYDROData_Profile)& theProfile,
414 const TopoDS_Face& thePlane,
415 Standard_Real& theOutPar )
417 if ( theProfile.IsNull() /*|| !IsValidAsAxis( theHydAxis )*/ )
420 if (theHydAxis.IsNull())
421 return true; //empty h_axis; its's OK
423 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
424 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
425 if ( aProfileWire.IsNull() )
428 //BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
429 BRepAlgo_NormalProjection nproj(thePlane);
430 nproj.Add(aProfileWire);
431 nproj.SetDefaultParams();
435 TopoDS_Shape aPrjProfile = nproj.Projection();
436 if(aPrjProfile.IsNull())
438 TopoDS_Vertex aV1, aV2;
439 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
440 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
441 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
442 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
443 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
444 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
446 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
448 anExp.Init(aPrjProfile, TopAbs_EDGE);
450 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
454 if(aV1.IsNull() || aV2.IsNull())
456 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
457 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
460 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
463 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
464 Standard_Integer aNum(0);
466 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
467 for(;anExplo.More();anExplo.Next()) aNum++;
468 // check for self-intersection
469 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
470 Standard_Boolean hasInt(false);
471 Standard_Real aSqDist(DBL_MAX);
472 Standard_Integer anIndx(0);
473 BRepExtrema_ExtCC aCC;
474 aCC.Initialize(anEdg2);
476 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
477 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
478 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
481 Standard_Boolean hasSol(false);
485 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
486 if(aCC.SquareDistance(i) < aSqDist) {
487 aSqDist = aCC.SquareDistance(i);
493 if(aSqDist <= SquareTolerance) { // hasInt
494 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
496 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
497 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
499 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
507 TopExp::Vertices(anEdg1, aV1, aV2);
508 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
511 } else if(aNum > 1) {
512 TopExp::Vertices(anEdg1, aV1, aV2);
513 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
521 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
523 if ( theProfile.IsNull() )
526 // Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
527 // if ( aHydAxis.IsNull() )
531 BuildRefFace( aPlane );
533 Standard_Real aPar(.0);
534 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
535 return false; // Object is already in reference list or it has no intersection
537 int aProfileIndex = insertParameter( aPar );
538 insertProfileInToOrder( theProfile, aProfileIndex );
540 DTM()->SetProfiles( GetProfiles() );
542 // Indicate model of the need to update the stream presentation
548 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
549 const bool& theIsToOrder )
553 for ( int i = 1; i <= theProfiles.Length(); ++i )
555 Handle(HYDROData_Profile) aProfile =
556 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
557 if ( aProfile.IsNull() )
560 if ( !AddProfile( aProfile ) )
562 DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
567 else // Just store the sequence of objects as is
569 bool anIsToUpdate = true;
571 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
572 if ( anOldProfiles.Length() == theProfiles.Length() )
574 anIsToUpdate = false;
576 for ( int i = 1; i <= theProfiles.Length(); ++i )
578 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
579 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
580 if ( !IsEqual( anOldProfile, aNewProfile ) )
588 SetReferenceObjects( theProfiles, DataTag_Profile );
594 DTM()->SetProfiles( GetProfiles() );
598 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
600 return GetReferenceObjects( DataTag_Profile );
603 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
605 if ( theProfile.IsNull() )
608 int aProfileIndex = -1;
610 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
611 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
612 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
614 Handle(HYDROData_Profile) aProfile =
615 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
616 if ( aProfile.IsNull() )
619 if ( IsEqual( theProfile, aProfile ) )
626 if ( aProfileIndex == -1 )
629 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
631 // Remove parameter for removed profile
632 removeParameter( aProfileIndex );
634 // Indicate model of the need to update the stream presentation
640 void HYDROData_Stream::RemoveProfiles()
642 ClearReferenceObjects( DataTag_Profile );
644 // Remove the parameters array
645 removeParametersArray();
647 // Indicate model of the need to update the stream presentation
651 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
652 const int theBeforeIndex )
654 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
655 if ( theProfile.IsNull() )
658 //TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
659 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
660 if ( aProfileWire.IsNull() )
663 if ( theBeforeIndex == -1 )
664 AddReferenceObject( theProfile, DataTag_Profile );
666 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
669 void HYDROData_Stream::BuildRefFace( TopoDS_Face& thePlane )
671 thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face();
674 void HYDROData_Stream::updateProfilesOrder()
676 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
677 if ( aRefProfiles.IsEmpty() )
680 // At first we remove all profiles from order
683 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
684 if ( aHydAxis.IsNull() )
688 BuildRefFace( aPlane );
690 Standard_Real aPar( .0 );
694 TopoDS_Compound aCmp;
695 aBB.MakeCompound(aCmp);
698 HYDROData_DataMapOfRealOfHDProfile aDM;
699 TColStd_ListOfReal aList;
700 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
701 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
703 Handle(HYDROData_Profile) aProfile =
704 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
706 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
707 aBB.Add( aCmp, aProfileWire );
709 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
712 aDM.Bind( aPar, aProfile );
713 aList.Append( aPar );
716 if ( aList.IsEmpty() )
719 TColStd_Array1OfReal anArr( 1, aList.Extent() );
721 TColStd_ListIteratorOfListOfReal it( aList );
722 for ( int j = 1; it.More(); it.Next(), j++ )
723 anArr( j ) = it.Value();
726 if ( aList.Extent() > 1 )
728 TCollection_CompareOfReal Compar;
729 SortTools_QuickSortOfReal::Sort( anArr, Compar );
731 for (int j = 1; j <= anArr.Length(); j++) {
732 const Standard_Real aKey = anArr(j);
733 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
734 insertProfileInToOrder( aProfile );
736 } else if ( aList.Extent() == 1 ) {
737 const Standard_Real aKey = aList.Last();
738 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
739 insertProfileInToOrder( aProfile );
742 setParametersArray( anArr );
745 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
746 BRepTools::Write(aHydraulicWire, "Path.brep");
747 BRepTools::Write(aCmp, "Prof.brep");
751 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
756 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
758 if ( theArray.Length() == 0 )
760 removeParametersArray();
764 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
766 Handle(TDataStd_RealArray) aParamsArray =
767 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
769 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
771 const Standard_Real& aParam = theArray( i );
772 aParamsArray->SetValue( i, aParam );
776 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
778 TColStd_Array1OfReal* anArray = NULL;
780 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
781 if ( !aLabel.IsNull() )
783 Handle(TDataStd_RealArray) aParamsArray;
784 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
786 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
787 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
789 const Standard_Real& aParam = aParamsArray->Value( i );
790 anArray->SetValue( i, aParam );
798 void HYDROData_Stream::removeParametersArray()
800 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
801 if ( !aLabel.IsNull() )
802 aLabel.ForgetAllAttributes();
805 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
809 TColStd_Array1OfReal* anArr = getParametersArray();
814 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
816 bool isInserted = false;
817 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
819 const Standard_Real& aStoredParam = anArr->Value( i );
822 if ( theParam > aStoredParam )
828 aNewArr( j ) = theParam;
834 aNewArr( j ) = aStoredParam;
840 aNewArr( aNewArr.Upper() ) = theParam;
843 setParametersArray( aNewArr );
848 TColStd_Array1OfReal aNewArr( 1, 1 );
849 aNewArr.SetValue( 1, theParam );
850 setParametersArray( aNewArr );
856 void HYDROData_Stream::removeParameter( const int& theIndex )
858 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
859 if ( aLabel.IsNull() )
862 Handle(TDataStd_RealArray) aParamsArray;
863 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
866 if ( aParamsArray->Length() == 1 )
868 removeParametersArray();
872 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
874 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
876 const Standard_Real& aStoredParam = aParamsArray->Value( i );
880 aNewArr.SetValue( j, aStoredParam );
884 setParametersArray( aNewArr );
887 bool HYDROData_Stream::GenerateBottomPolyline()
890 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
891 if ( aDocument.IsNull() ) {
895 // Collect bottom points ( one bottom point from each profile of the stream )
896 HYDROData_Profile::ProfilePoints aBottomPoints;
898 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
899 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
900 const Handle(HYDROData_Profile) aProfile =
901 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
902 if ( aProfile.IsNull() ) {
906 aBottomPoints.Append( aProfile->GetBottomPoint() );
909 int aNbBottomPoints = aBottomPoints.Size();
911 if ( aNbBottomPoints < 2 ) {
915 // Create bottom polyline object if the stream doesn't contain it yet
916 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
917 if ( aBottom.IsNull() ) {
918 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
919 QString aBaseName = GetName() + "_bottom";
920 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
921 aBottom->SetName( aName );
923 SetReferenceObject( aBottom, DataTag_BottomPolyline );
926 // Create 2D polyline if the bottom polyline doesn't contain it yet
927 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
928 if ( aPolylineXY.IsNull() ) {
929 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
930 QString aBaseName = GetName() + "_bottom_2d";
931 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
932 aPolylineXY->SetName( aName );
933 aBottom->SetPolylineXY( aPolylineXY, false );
936 aPolylineXY->RemoveSections();
937 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
939 // Create profile if the bottom polyline doesn't contain it yet
940 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
941 if ( aProfileUZ.IsNull() ) {
942 Handle(HYDROData_Profile) aProfile =
943 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
944 QString aBaseName = GetName() + "_bottom_profile";
945 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
946 aProfile->SetName( aName );
947 aProfileUZ = aProfile->GetProfileUZ( true );
948 aBottom->SetProfileUZ( aProfileUZ );
951 aProfileUZ->RemoveSection( 0 );
953 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
958 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
960 return Handle(HYDROData_Polyline3D)::DownCast(
961 GetReferenceObject( DataTag_BottomPolyline ) );
964 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
966 if ( theBottom.IsNull() ) {
970 SetReferenceObject( theBottom, DataTag_BottomPolyline );
975 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
978 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
979 if ( aDocument.IsNull() ) {
983 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
984 theInterpolator->Calculate();
987 if ( theInterpolator->GetErrorCode() != OK ) {
993 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
994 // Get calculated point coordinates
995 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
996 if ( aResultPoints.IsEmpty() ) {
1001 // Create profile object
1002 Handle(HYDROData_Profile) aProfile =
1003 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1004 QString aBaseName = GetName() + "_interp_profile";
1005 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
1006 aProfile->SetName( aName );
1008 // Fill the profile with points
1009 aProfile->SetProfilePoints( aResultPoints );
1011 // Add profile to the stream
1012 bool isAdded = AddProfile( aProfile );
1026 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1027 bool isGenerateNewName ) const
1030 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1031 if ( aDocument.IsNull() ) {
1036 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1038 Handle(HYDROData_Stream) aStreamCopy =
1039 Handle(HYDROData_Stream)::DownCast( theDestination );
1041 // Copy bottom polyline if exists
1042 if ( !aStreamCopy.IsNull() ) {
1043 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1044 if ( !aBottom.IsNull() ) {
1045 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1046 aStreamCopy->GenerateBottomPolyline();
1047 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1048 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1049 aBottomCopy->GetPolylineXY()->Update();
1050 aBottomCopy->Update();
1055 void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1056 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1057 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1058 PrsDefinition& thePrs )
1061 HYDROData_Bathymetry::AltitudePoints left;
1062 for (int i = theArrayOfLPnt->Lower(); i <= theArrayOfLPnt->Upper(); i++)
1064 left.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfLPnt->Value(i).X(),
1065 theArrayOfLPnt->Value(i).Y(),
1066 theArrayOfLPnt->Value(i).Z()));
1069 HYDROData_Bathymetry::AltitudePoints right;
1070 for (int i = theArrayOfFPnt->Lower(); i <= theArrayOfFPnt->Upper(); i++)
1072 right.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfFPnt->Value(i).X(),
1073 theArrayOfFPnt->Value(i).Y(),
1074 theArrayOfFPnt->Value(i).Z()));
1077 std::vector<HYDROData_Bathymetry::AltitudePoints> dummy;
1078 TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy);
1080 TopoDS_Shape LB, RB, IL, OL;
1084 TopAbs_ShapeEnum ll1_sht = ll(1).ShapeType();
1085 TopAbs_ShapeEnum ll2_sht = ll(2).ShapeType();
1086 if ((ll1_sht == TopAbs_WIRE || ll1_sht == TopAbs_EDGE) &&
1087 (ll2_sht == TopAbs_WIRE || ll2_sht == TopAbs_EDGE))
1094 IL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
1095 OL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
1097 //make new compound so it's shapes will be in known order to build correct projection
1099 TopoDS_Compound newCmp;
1100 BB.MakeCompound(newCmp);
1106 thePrs.myPrs3D = newCmp;
1108 TopTools_SequenceOfShape LS;
1109 //HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D), &LS, ind );
1111 HYDROData_DTM::GetPlanarFaceFromBanks(TopoDS::Edge(LB), TopoDS::Edge(RB), TopoDS::Face(thePrs.myPrs2D), &LS);
1114 TopTools_IndexedMapOfShape EE;
1115 TopExp::MapShapes(thePrs.myPrs2D, TopAbs_EDGE, EE);
1117 for (int i = 1; i <= 4; i++)
1119 TopoDS_Shape W = LS(i);
1120 TopTools_IndexedMapOfShape EW;
1121 TopExp::MapShapes(W, TopAbs_EDGE, EW);
1122 for (int k = 1; k <= EW.Extent(); k++)
1123 noncontNb += !EE.Contains(EW(k));
1125 //noncontNb > 0 => some problem with edge history
1126 assert(noncontNb == 0);
1129 thePrs.myLeftBank = LS(1);
1130 thePrs.myInlet = LS(2);
1131 thePrs.myOutlet = LS(3);
1132 thePrs.myRightBank = LS(4);