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>
96 #include "HYDRO_trace.hxx"
100 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
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() )
427 DEBTRACE("aProfileWire.IsNull");
431 //BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
432 BRepAlgo_NormalProjection nproj(thePlane);
433 nproj.Add(aProfileWire);
434 nproj.SetDefaultParams();
438 DEBTRACE("!nproj.IsDone");
441 TopoDS_Shape aPrjProfile = nproj.Projection();
442 if(aPrjProfile.IsNull())
444 DEBTRACE("aPrjProfile.IsNull");
447 TopoDS_Vertex aV1, aV2;
448 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
449 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
450 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
451 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
452 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
453 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
455 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
457 anExp.Init(aPrjProfile, TopAbs_EDGE);
459 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
463 if(aV1.IsNull() || aV2.IsNull())
465 DEBTRACE("aV1.IsNull() || aV2.IsNull()");
468 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
469 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
472 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
475 DEBTRACE("!aMk.IsDone()");
478 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
479 Standard_Integer aNum(0);
481 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
482 for(;anExplo.More();anExplo.Next()) aNum++;
483 // check for self-intersection
484 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
485 Standard_Boolean hasInt(false);
486 Standard_Real aSqDist(DBL_MAX);
487 Standard_Integer anIndx(0);
488 BRepExtrema_ExtCC aCC;
489 aCC.Initialize(anEdg2);
491 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
492 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
493 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
496 Standard_Boolean hasSol(false);
500 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
501 if(aCC.SquareDistance(i) < aSqDist) {
502 aSqDist = aCC.SquareDistance(i);
508 if(aSqDist <= SquareTolerance) { // hasInt
509 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
511 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
512 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
514 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
522 TopExp::Vertices(anEdg1, aV1, aV2);
523 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
526 } else if(aNum > 1) {
527 TopExp::Vertices(anEdg1, aV1, aV2);
528 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
533 DEBTRACE("!hasInt " << aPnt1.X() << " " << aPnt1.Y() << " " << aPnt2.X() << " " << aPnt2.Y() << " --- " << aSqDist);
537 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
539 if ( theProfile.IsNull() )
542 // Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
543 // if ( aHydAxis.IsNull() )
547 BuildRefFace( aPlane );
549 Standard_Real aPar(.0);
550 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
551 return false; // Object is already in reference list or it has no intersection
552 //DEBTRACE("AddProfile - insertParameter " << aPar);
553 int aProfileIndex = insertParameter( aPar );
554 insertProfileInToOrder( theProfile, aProfileIndex );
556 DTM()->SetProfiles( GetProfiles() );
558 // Indicate model of the need to update the stream presentation
564 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
565 const bool& theIsToOrder )
567 DEBTRACE(" --- SetProfiles " <<theIsToOrder );
570 for ( int i = 1; i <= theProfiles.Length(); ++i )
572 Handle(HYDROData_Profile) aProfile =
573 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
574 if ( aProfile.IsNull() )
577 if ( !AddProfile( aProfile ) )
579 DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
584 else // Just store the sequence of objects as is
586 bool anIsToUpdate = true;
588 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
589 if ( anOldProfiles.Length() == theProfiles.Length() )
591 anIsToUpdate = false;
593 for ( int i = 1; i <= theProfiles.Length(); ++i )
595 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
596 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
597 if ( !IsEqual( anOldProfile, aNewProfile ) )
605 SetReferenceObjects( theProfiles, DataTag_Profile );
611 DTM()->SetProfiles( GetProfiles() );
615 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
617 return GetReferenceObjects( DataTag_Profile );
620 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
622 if ( theProfile.IsNull() )
625 int aProfileIndex = -1;
627 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
628 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
629 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
631 Handle(HYDROData_Profile) aProfile =
632 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
633 if ( aProfile.IsNull() )
636 if ( IsEqual( theProfile, aProfile ) )
643 if ( aProfileIndex == -1 )
646 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
648 // Remove parameter for removed profile
649 removeParameter( aProfileIndex );
651 // Indicate model of the need to update the stream presentation
657 void HYDROData_Stream::RemoveProfiles()
659 ClearReferenceObjects( DataTag_Profile );
661 // Remove the parameters array
662 removeParametersArray();
664 // Indicate model of the need to update the stream presentation
668 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
669 const int theBeforeIndex )
671 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
672 if ( theProfile.IsNull() )
675 //TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
676 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
677 if ( aProfileWire.IsNull() )
680 if ( theBeforeIndex == -1 )
681 AddReferenceObject( theProfile, DataTag_Profile );
683 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
686 void HYDROData_Stream::BuildRefFace( TopoDS_Face& thePlane )
688 thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face();
691 void HYDROData_Stream::updateProfilesOrder()
693 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
694 if ( aRefProfiles.IsEmpty() )
697 // At first we remove all profiles from order
700 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
701 if ( aHydAxis.IsNull() )
705 BuildRefFace( aPlane );
707 Standard_Real aPar( .0 );
711 TopoDS_Compound aCmp;
712 aBB.MakeCompound(aCmp);
715 HYDROData_DataMapOfRealOfHDProfile aDM;
716 TColStd_ListOfReal aList;
717 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
718 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
720 Handle(HYDROData_Profile) aProfile =
721 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
723 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
724 aBB.Add( aCmp, aProfileWire );
726 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
729 aDM.Bind( aPar, aProfile );
730 aList.Append( aPar );
733 if ( aList.IsEmpty() )
736 QVector<double> anArr( aList.Extent() );
738 TColStd_ListIteratorOfListOfReal it( aList );
739 for ( int j = 1; it.More(); it.Next(), j++ )
740 anArr[j-1] = it.Value();
743 if ( aList.Extent() > 1 )
745 //TCollection_CompareOfReal Compar;
746 //SortTools_QuickSortOfReal::Sort( anArr, Compar );
747 std::sort( anArr.begin(), anArr.end() );
749 for (int j = 1; j <= anArr.size(); j++) {
750 const Standard_Real aKey = anArr[j-1];
751 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
752 insertProfileInToOrder( aProfile );
754 } else if ( aList.Extent() == 1 ) {
755 const Standard_Real aKey = aList.Last();
756 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
757 insertProfileInToOrder( aProfile );
760 setParametersArray( anArr );
763 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
764 BRepTools::Write(aHydraulicWire, "Path.brep");
765 BRepTools::Write(aCmp, "Prof.brep");
769 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
774 void HYDROData_Stream::setParametersArray( const QVector<double>& theArray )
776 if ( theArray.size() == 0 )
778 removeParametersArray();
782 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
784 int n = theArray.size();
785 Handle(TDataStd_RealArray) aParamsArray =
786 TDataStd_RealArray::Set( aLabel, 1, n );
787 for ( int i = 0; i < n; ++i )
789 const Standard_Real& aParam = theArray[i];
790 aParamsArray->SetValue( i+1, aParam );
794 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
796 TColStd_Array1OfReal* anArray = NULL;
798 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
799 if ( !aLabel.IsNull() )
801 Handle(TDataStd_RealArray) aParamsArray;
802 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
804 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
805 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
807 const Standard_Real& aParam = aParamsArray->Value( i );
808 anArray->SetValue( i, aParam );
816 void HYDROData_Stream::removeParametersArray()
818 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
819 if ( !aLabel.IsNull() )
820 aLabel.ForgetAllAttributes();
823 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
827 TColStd_Array1OfReal* anArr = getParametersArray();
832 QVector<double> aNewArr( anArr->Upper() +1 );
833 bool isInserted = false;
834 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
836 const Standard_Real& aStoredParam = anArr->Value( i );
839 if ( theParam > aStoredParam )
846 aNewArr[j-1] = theParam;
852 aNewArr[j-1] = aStoredParam;
858 aNewArr[aNewArr.size()-1] = theParam;
861 setParametersArray( aNewArr );
866 QVector<double> aNewArr( 1 );
867 aNewArr[0] = theParam;
868 setParametersArray( aNewArr );
874 void HYDROData_Stream::removeParameter( const int& theIndex )
876 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
877 if ( aLabel.IsNull() )
880 Handle(TDataStd_RealArray) aParamsArray;
881 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
884 if ( aParamsArray->Length() == 1 )
886 removeParametersArray();
890 QVector<double> aNewArr( aParamsArray->Upper() - 2 );
892 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
894 const Standard_Real& aStoredParam = aParamsArray->Value( i );
898 aNewArr[j-1] = aStoredParam;
902 setParametersArray( aNewArr );
905 bool HYDROData_Stream::GenerateBottomPolyline()
908 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
909 if ( aDocument.IsNull() ) {
913 // Collect bottom points ( one bottom point from each profile of the stream )
914 HYDROData_Profile::ProfilePoints aBottomPoints;
916 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
917 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
918 const Handle(HYDROData_Profile) aProfile =
919 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
920 if ( aProfile.IsNull() ) {
924 aBottomPoints.Append( aProfile->GetBottomPoint() );
927 int aNbBottomPoints = aBottomPoints.Size();
929 if ( aNbBottomPoints < 2 ) {
933 // Create bottom polyline object if the stream doesn't contain it yet
934 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
935 if ( aBottom.IsNull() ) {
936 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
937 QString aBaseName = GetName() + "_bottom";
938 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
939 aBottom->SetName( aName );
941 SetReferenceObject( aBottom, DataTag_BottomPolyline );
944 // Create 2D polyline if the bottom polyline doesn't contain it yet
945 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
946 if ( aPolylineXY.IsNull() ) {
947 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
948 QString aBaseName = GetName() + "_bottom_2d";
949 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
950 aPolylineXY->SetName( aName );
951 aBottom->SetPolylineXY( aPolylineXY, false );
954 aPolylineXY->RemoveSections();
955 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
957 // Create profile if the bottom polyline doesn't contain it yet
958 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
959 if ( aProfileUZ.IsNull() ) {
960 Handle(HYDROData_Profile) aProfile =
961 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
962 QString aBaseName = GetName() + "_bottom_profile";
963 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
964 aProfile->SetName( aName );
965 aProfileUZ = aProfile->GetProfileUZ( true );
966 aBottom->SetProfileUZ( aProfileUZ );
969 aProfileUZ->RemoveSection( 0 );
971 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
976 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
978 return Handle(HYDROData_Polyline3D)::DownCast(
979 GetReferenceObject( DataTag_BottomPolyline ) );
982 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
984 if ( theBottom.IsNull() ) {
988 SetReferenceObject( theBottom, DataTag_BottomPolyline );
993 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
996 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
997 if ( aDocument.IsNull() ) {
1001 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
1002 theInterpolator->Calculate();
1005 if ( theInterpolator->GetErrorCode() != OK ) {
1011 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
1012 // Get calculated point coordinates
1013 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
1014 if ( aResultPoints.IsEmpty() ) {
1019 // Create profile object
1020 Handle(HYDROData_Profile) aProfile =
1021 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1022 QString aBaseName = GetName() + "_interp_profile";
1023 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
1024 aProfile->SetName( aName );
1026 // Fill the profile with points
1027 aProfile->SetProfilePoints( aResultPoints );
1029 // Add profile to the stream
1030 bool isAdded = AddProfile( aProfile );
1044 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1045 bool isGenerateNewName ) const
1048 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1049 if ( aDocument.IsNull() ) {
1054 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1056 Handle(HYDROData_Stream) aStreamCopy =
1057 Handle(HYDROData_Stream)::DownCast( theDestination );
1059 // Copy bottom polyline if exists
1060 if ( !aStreamCopy.IsNull() ) {
1061 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1062 if ( !aBottom.IsNull() ) {
1063 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1064 aStreamCopy->GenerateBottomPolyline();
1065 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1066 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1067 aBottomCopy->GetPolylineXY()->Update();
1068 aBottomCopy->Update();
1073 void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1074 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1075 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1076 PrsDefinition& thePrs )
1079 HYDROData_Bathymetry::AltitudePoints left;
1080 for (int i = theArrayOfLPnt->Lower(); i <= theArrayOfLPnt->Upper(); i++)
1082 left.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfLPnt->Value(i).X(),
1083 theArrayOfLPnt->Value(i).Y(),
1084 theArrayOfLPnt->Value(i).Z()));
1087 HYDROData_Bathymetry::AltitudePoints right;
1088 for (int i = theArrayOfFPnt->Lower(); i <= theArrayOfFPnt->Upper(); i++)
1090 right.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfFPnt->Value(i).X(),
1091 theArrayOfFPnt->Value(i).Y(),
1092 theArrayOfFPnt->Value(i).Z()));
1095 std::vector<HYDROData_Bathymetry::AltitudePoints> dummy;
1096 TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy);
1098 TopoDS_Shape LB, RB, IL, OL;
1102 TopAbs_ShapeEnum ll1_sht = ll(1).ShapeType();
1103 TopAbs_ShapeEnum ll2_sht = ll(2).ShapeType();
1104 if ((ll1_sht == TopAbs_WIRE || ll1_sht == TopAbs_EDGE) &&
1105 (ll2_sht == TopAbs_WIRE || ll2_sht == TopAbs_EDGE))
1112 IL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
1113 OL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
1115 //make new compound so it's shapes will be in known order to build correct projection
1117 TopoDS_Compound newCmp;
1118 BB.MakeCompound(newCmp);
1124 thePrs.myPrs3D = newCmp;
1126 TopTools_SequenceOfShape LS;
1127 //HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D), &LS, ind );
1129 HYDROData_DTM::GetPlanarFaceFromBanks(TopoDS::Edge(LB), TopoDS::Edge(RB), TopoDS::Face(thePrs.myPrs2D), &LS);
1132 TopTools_IndexedMapOfShape EE;
1133 TopExp::MapShapes(thePrs.myPrs2D, TopAbs_EDGE, EE);
1135 for (int i = 1; i <= 4; i++)
1137 TopoDS_Shape W = LS(i);
1138 TopTools_IndexedMapOfShape EW;
1139 TopExp::MapShapes(W, TopAbs_EDGE, EW);
1140 for (int k = 1; k <= EW.Extent(); k++)
1141 noncontNb += !EE.Contains(EW(k));
1143 //noncontNb > 0 => some problem with edge history
1144 assert(noncontNb == 0);
1147 thePrs.myLeftBank = LS(1);
1148 thePrs.myInlet = LS(2);
1149 thePrs.myOutlet = LS(3);
1150 thePrs.myRightBank = LS(4);