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 = TopoDS::Wire(OutInlet);
219 thePrs.myOutlet = TopoDS::Wire(OutOutlet);
220 thePrs.myLeftBank = TopoDS::Wire(OutLeftB);
221 thePrs.myRightBank = TopoDS::Wire(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 // Indicate model of the need to update the stream presentation
543 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
544 const bool& theIsToOrder )
548 for ( int i = 1; i <= theProfiles.Length(); ++i )
550 Handle(HYDROData_Profile) aProfile =
551 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
552 if ( aProfile.IsNull() )
555 if ( !AddProfile( aProfile ) )
557 DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
562 else // Just store the sequence of objects as is
564 bool anIsToUpdate = true;
566 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
567 if ( anOldProfiles.Length() == theProfiles.Length() )
569 anIsToUpdate = false;
571 for ( int i = 1; i <= theProfiles.Length(); ++i )
573 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
574 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
575 if ( !IsEqual( anOldProfile, aNewProfile ) )
583 SetReferenceObjects( theProfiles, DataTag_Profile );
589 DTM()->SetProfiles( GetProfiles() );
593 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
595 return GetReferenceObjects( DataTag_Profile );
598 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
600 if ( theProfile.IsNull() )
603 int aProfileIndex = -1;
605 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
606 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
607 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
609 Handle(HYDROData_Profile) aProfile =
610 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
611 if ( aProfile.IsNull() )
614 if ( IsEqual( theProfile, aProfile ) )
621 if ( aProfileIndex == -1 )
624 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
626 // Remove parameter for removed profile
627 removeParameter( aProfileIndex );
629 // Indicate model of the need to update the stream presentation
635 void HYDROData_Stream::RemoveProfiles()
637 ClearReferenceObjects( DataTag_Profile );
639 // Remove the parameters array
640 removeParametersArray();
642 // Indicate model of the need to update the stream presentation
646 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
647 const int theBeforeIndex )
649 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
650 if ( theProfile.IsNull() )
653 //TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
654 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
655 if ( aProfileWire.IsNull() )
658 if ( theBeforeIndex == -1 )
659 AddReferenceObject( theProfile, DataTag_Profile );
661 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
664 void HYDROData_Stream::BuildRefFace( TopoDS_Face& thePlane )
666 thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face();
669 void HYDROData_Stream::updateProfilesOrder()
671 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
672 if ( aRefProfiles.IsEmpty() )
675 // At first we remove all profiles from order
678 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
679 if ( aHydAxis.IsNull() )
683 BuildRefFace( aPlane );
685 Standard_Real aPar( .0 );
689 TopoDS_Compound aCmp;
690 aBB.MakeCompound(aCmp);
693 HYDROData_DataMapOfRealOfHDProfile aDM;
694 TColStd_ListOfReal aList;
695 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
696 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
698 Handle(HYDROData_Profile) aProfile =
699 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
701 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
702 aBB.Add( aCmp, aProfileWire );
704 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
707 aDM.Bind( aPar, aProfile );
708 aList.Append( aPar );
711 if ( aList.IsEmpty() )
714 QVector<double> anArr( aList.Extent() );
716 TColStd_ListIteratorOfListOfReal it( aList );
717 for ( int j = 1; it.More(); it.Next(), j++ )
718 anArr[j-1] = it.Value();
721 if ( aList.Extent() > 1 )
723 //TCollection_CompareOfReal Compar;
724 //SortTools_QuickSortOfReal::Sort( anArr, Compar );
725 std::sort( anArr.begin(), anArr.end() );
727 for (int j = 1; j <= anArr.size(); j++) {
728 const Standard_Real aKey = anArr[j-1];
729 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
730 insertProfileInToOrder( aProfile );
732 } else if ( aList.Extent() == 1 ) {
733 const Standard_Real aKey = aList.Last();
734 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
735 insertProfileInToOrder( aProfile );
738 setParametersArray( anArr );
741 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
742 BRepTools::Write(aHydraulicWire, "Path.brep");
743 BRepTools::Write(aCmp, "Prof.brep");
747 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
752 void HYDROData_Stream::setParametersArray( const QVector<double>& theArray )
754 if ( theArray.size() == 0 )
756 removeParametersArray();
760 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
762 int n = theArray.size();
763 Handle(TDataStd_RealArray) aParamsArray =
764 TDataStd_RealArray::Set( aLabel, 1, n );
765 for ( int i = 0; i < n; ++i )
767 const Standard_Real& aParam = theArray[i];
768 aParamsArray->SetValue( i+1, aParam );
772 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
774 TColStd_Array1OfReal* anArray = NULL;
776 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
777 if ( !aLabel.IsNull() )
779 Handle(TDataStd_RealArray) aParamsArray;
780 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
782 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
783 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
785 const Standard_Real& aParam = aParamsArray->Value( i );
786 anArray->SetValue( i, aParam );
794 void HYDROData_Stream::removeParametersArray()
796 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
797 if ( !aLabel.IsNull() )
798 aLabel.ForgetAllAttributes();
801 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
805 TColStd_Array1OfReal* anArr = getParametersArray();
810 QVector<double> aNewArr( anArr->Upper() );
812 bool isInserted = false;
813 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
815 const Standard_Real& aStoredParam = anArr->Value( i );
818 if ( theParam > aStoredParam )
824 aNewArr[j-1] = theParam;
830 aNewArr[j-1] = aStoredParam;
836 aNewArr[aNewArr.size()-1] = theParam;
839 setParametersArray( aNewArr );
844 QVector<double> aNewArr( 1 );
845 aNewArr[0] = theParam;
846 setParametersArray( aNewArr );
852 void HYDROData_Stream::removeParameter( const int& theIndex )
854 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
855 if ( aLabel.IsNull() )
858 Handle(TDataStd_RealArray) aParamsArray;
859 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
862 if ( aParamsArray->Length() == 1 )
864 removeParametersArray();
868 QVector<double> aNewArr( aParamsArray->Upper() - 2 );
870 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
872 const Standard_Real& aStoredParam = aParamsArray->Value( i );
876 aNewArr[j-1] = aStoredParam;
880 setParametersArray( aNewArr );
883 bool HYDROData_Stream::GenerateBottomPolyline()
886 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
887 if ( aDocument.IsNull() ) {
891 // Collect bottom points ( one bottom point from each profile of the stream )
892 HYDROData_Profile::ProfilePoints aBottomPoints;
894 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
895 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
896 const Handle(HYDROData_Profile) aProfile =
897 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
898 if ( aProfile.IsNull() ) {
902 aBottomPoints.Append( aProfile->GetBottomPoint() );
905 int aNbBottomPoints = aBottomPoints.Size();
907 if ( aNbBottomPoints < 2 ) {
911 // Create bottom polyline object if the stream doesn't contain it yet
912 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
913 if ( aBottom.IsNull() ) {
914 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
915 QString aBaseName = GetName() + "_bottom";
916 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
917 aBottom->SetName( aName );
919 SetReferenceObject( aBottom, DataTag_BottomPolyline );
922 // Create 2D polyline if the bottom polyline doesn't contain it yet
923 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
924 if ( aPolylineXY.IsNull() ) {
925 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
926 QString aBaseName = GetName() + "_bottom_2d";
927 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
928 aPolylineXY->SetName( aName );
929 aBottom->SetPolylineXY( aPolylineXY, false );
932 aPolylineXY->RemoveSections();
933 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
935 // Create profile if the bottom polyline doesn't contain it yet
936 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
937 if ( aProfileUZ.IsNull() ) {
938 Handle(HYDROData_Profile) aProfile =
939 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
940 QString aBaseName = GetName() + "_bottom_profile";
941 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
942 aProfile->SetName( aName );
943 aProfileUZ = aProfile->GetProfileUZ( true );
944 aBottom->SetProfileUZ( aProfileUZ );
947 aProfileUZ->RemoveSection( 0 );
949 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
954 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
956 return Handle(HYDROData_Polyline3D)::DownCast(
957 GetReferenceObject( DataTag_BottomPolyline ) );
960 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
962 if ( theBottom.IsNull() ) {
966 SetReferenceObject( theBottom, DataTag_BottomPolyline );
971 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
974 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
975 if ( aDocument.IsNull() ) {
979 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
980 theInterpolator->Calculate();
983 if ( theInterpolator->GetErrorCode() != OK ) {
989 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
990 // Get calculated point coordinates
991 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
992 if ( aResultPoints.IsEmpty() ) {
997 // Create profile object
998 Handle(HYDROData_Profile) aProfile =
999 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1000 QString aBaseName = GetName() + "_interp_profile";
1001 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
1002 aProfile->SetName( aName );
1004 // Fill the profile with points
1005 aProfile->SetProfilePoints( aResultPoints );
1007 // Add profile to the stream
1008 bool isAdded = AddProfile( aProfile );
1022 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1023 bool isGenerateNewName ) const
1026 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1027 if ( aDocument.IsNull() ) {
1032 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1034 Handle(HYDROData_Stream) aStreamCopy =
1035 Handle(HYDROData_Stream)::DownCast( theDestination );
1037 // Copy bottom polyline if exists
1038 if ( !aStreamCopy.IsNull() ) {
1039 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1040 if ( !aBottom.IsNull() ) {
1041 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1042 aStreamCopy->GenerateBottomPolyline();
1043 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1044 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1045 aBottomCopy->GetPolylineXY()->Update();
1046 aBottomCopy->Update();
1051 void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1052 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1053 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1054 PrsDefinition& thePrs )
1057 HYDROData_Bathymetry::AltitudePoints left;
1058 for (int i = theArrayOfLPnt->Lower(); i <= theArrayOfLPnt->Upper(); i++)
1060 left.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfLPnt->Value(i).X(),
1061 theArrayOfLPnt->Value(i).Y(),
1062 theArrayOfLPnt->Value(i).Z()));
1065 HYDROData_Bathymetry::AltitudePoints right;
1066 for (int i = theArrayOfFPnt->Lower(); i <= theArrayOfFPnt->Upper(); i++)
1068 right.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfFPnt->Value(i).X(),
1069 theArrayOfFPnt->Value(i).Y(),
1070 theArrayOfFPnt->Value(i).Z()));
1073 std::vector<HYDROData_Bathymetry::AltitudePoints> dummy;
1074 TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy);
1076 TopoDS_Shape LB, RB, IL, OL;
1080 LB = TopoDS::Wire(ll(1));
1081 RB = TopoDS::Wire(ll(2));
1084 IL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
1085 OL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
1087 //make new compound so it's shapes will be in known order to build correct projection
1089 TopoDS_Compound newCmp;
1090 BB.MakeCompound(newCmp);
1096 thePrs.myPrs3D = newCmp;
1098 ind.insert(1); //inlet ind
1099 ind.insert(2); //outlet ind
1101 TopTools_SequenceOfShape LS;
1102 HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D), &LS, ind );
1105 TopTools_IndexedMapOfShape EE;
1106 TopExp::MapShapes(thePrs.myPrs2D, TopAbs_EDGE, EE);
1108 for (int i = 1; i <= 4; i++)
1110 TopoDS_Shape W = LS(i);
1111 TopTools_IndexedMapOfShape EW;
1112 TopExp::MapShapes(W, TopAbs_EDGE, EW);
1113 for (int k = 1; k <= EW.Extent(); k++)
1114 noncontNb += !EE.Contains(EW(k));
1116 //noncontNb > 0 => some problem with edge history
1117 assert(noncontNb == 0);
1120 thePrs.myLeftBank = TopoDS::Wire(LS(1));
1121 thePrs.myInlet = TopoDS::Wire(LS(2));
1122 thePrs.myOutlet = TopoDS::Wire(LS(3));
1123 thePrs.myRightBank = TopoDS::Wire(LS(4));