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_LISM.h"
33 #include <HYDROData_Bathymetry.h>
35 #include <TDataStd_RealArray.hxx>
37 #include <Precision.hxx>
39 #include <NCollection_DataMap.hxx>
41 #include <TColStd_Array1OfReal.hxx>
42 #include <TColStd_ListOfReal.hxx>
43 #include <TColStd_ListIteratorOfListOfReal.hxx>
44 #include <TColgp_Array1OfPnt.hxx>
45 #include <TColgp_HArray1OfPnt.hxx>
48 #include <TopoDS_Wire.hxx>
49 #include <TopoDS_Shell.hxx>
50 #include <TopoDS_Face.hxx>
51 #include <TopoDS_Edge.hxx>
52 #include <TopoDS_Vertex.hxx>
54 #include <TopExp_Explorer.hxx>
56 #include <Bnd_Box.hxx>
58 #include <BRep_Builder.hxx>
59 #include <BRepBuilderAPI_MakeEdge.hxx>
60 #include <BRepBuilderAPI_MakeWire.hxx>
61 #include <BRepBuilderAPI_MakeFace.hxx>
63 #include <BRepBndLib.hxx>
64 #include <BRepProj_Projection.hxx>
65 #include <BRepExtrema_ExtCC.hxx>
66 #include <BRepCheck_Analyzer.hxx>
76 #include <GeomAPI_Interpolate.hxx>
77 #include <Geom_BSplineCurve.hxx>
79 #include <TopTools_HArray1OfShape.hxx>
80 #include <TopTools_IndexedMapOfOrientedShape.hxx>
81 #include <TopTools_ListIteratorOfListOfShape.hxx>
82 #include <TopTools_SequenceOfShape.hxx>
83 #include <TopTools_IndexedMapOfShape.hxx>
86 #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>
98 #include "HYDRO_trace.hxx"
102 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
104 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
107 HYDROData_Stream::HYDROData_Stream()
108 : HYDROData_NaturalObject( Geom_3d )
112 HYDROData_Stream::~HYDROData_Stream()
116 QStringList HYDROData_Stream::DumpToPython( const QString& thePyScriptPath,
117 MapOfTreatedObjects& theTreatedObjects ) const
119 QStringList aResList = dumpObjectCreation( theTreatedObjects );
120 QString aName = GetObjPyName();
122 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
123 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
125 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
126 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
128 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
129 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
132 // Set bottom polyline if exists
133 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
134 if ( !aBottomPolyline.IsNull() ) {
135 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
138 QString aDDZs = QString::number( GetDDZ(), 'f', 3 );
139 QString aSSteps = QString::number( GetSpatialStep(), 'f', 3 );
140 aResList << QString( "%1.SetDDZ( %2 )" ).arg( aName ).arg( aDDZs );
141 aResList << QString( "%1.SetSpatialStep( %2 )" ).arg( aName ).arg( aSSteps );
143 aResList << QString( "" );
144 aResList << QString( "%1.Update()" ).arg( aName );
145 aResList << QString( "" );
150 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
152 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
154 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
155 if ( !aHydAxis.IsNull() )
156 aResSeq.Append( aHydAxis );
158 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
159 aResSeq.Append( aSeqOfProfiles );
164 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
165 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
167 Handle(Geom_BSplineCurve) aBSpline;
168 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
169 anInterpolator.Perform() ;
170 if (anInterpolator.IsDone())
171 aBSpline = anInterpolator.Curve();
175 void HYDROData_Stream::GetWarnings(NCollection_DataMap<Handle(HYDROData_Profile), QSet<QString>>& warnings)
177 warnings = myWarnings;
180 void HYDROData_Stream::Update()
182 if (GetInterpolationMethod() == 0)
184 if (!GetHydraulicAxis().IsNull())
185 updateProfilesOrder();
187 // Update bottom polyline if exists
188 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
189 if ( !aBottomPolyline.IsNull() ) {
190 if ( GenerateBottomPolyline() ) {
191 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
192 if ( !aPolylineXY.IsNull() ) {
193 aPolylineXY->Update();
195 aBottomPolyline->Update();
199 Handle(HYDROData_DTM) dtm = DTM();
204 dtm->GetWarnings(myWarnings);
208 Handle(HYDROData_LISM) lism = LISM();
213 //lism->GetWarnings(myWarnings);
217 HYDROData_NaturalObject::Update();
220 bool HYDROData_Stream::IsHas2dPrs() const
225 bool HYDROData_Stream::CreatePresentations( const Handle(HYDROData_DTM)& theDTM,
226 PrsDefinition& thePrs )
228 if ( theDTM.IsNull() )
231 HYDROData_SequenceOfObjects profiles = theDTM->GetProfiles();
232 if( profiles.Length() < 2 )
235 TopoDS_Shape Out3dPres;
236 TopoDS_Shape Out2dPres;
237 TopoDS_Shape OutLeftB;
238 TopoDS_Shape OutRightB;
239 TopoDS_Shape OutInlet;
240 TopoDS_Shape OutOutlet;
242 theDTM->GetPresentationShapes(Out3dPres, Out2dPres, OutLeftB, OutRightB, OutInlet, OutOutlet);
244 thePrs.myInlet = OutInlet;
245 thePrs.myOutlet = OutOutlet;
246 thePrs.myLeftBank = OutLeftB;
247 thePrs.myRightBank = OutRightB;
248 thePrs.myPrs2D = Out2dPres;
249 thePrs.myPrs3D = Out3dPres;
250 /*std::vector<TopoDS_Wire> profiles3d;
251 profiles3d.reserve(profiles.Length());
254 HYDROData_SequenceOfObjects::Iterator anIter( profiles );
255 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
257 Handle(HYDROData_Profile) aProfile =
258 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
260 if ( aProfile.IsNull() )
263 const TopoDS_Shape& aProfileShape = aProfile->GetShape3D();
264 //TopExp_Explorer exp(aProfileShape, TopAbs_EDGE);
265 profiles3d.push_back( TopoDS::Wire(aProfileShape) );
271 void HYDROData_Stream::internalUpdatePrs( const PrsDefinition& aResultPrs )
273 SetShape3D( aResultPrs.myPrs3D );
274 SetTopShape( aResultPrs.myPrs2D );
276 // Create the stream groups
277 QString aLeftGroupName = GetName() + "_Left_Bank";
279 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
280 aLeftGroup->SetName( aLeftGroupName );
281 aLeftGroup->AddShape( aResultPrs.myLeftBank );
283 QString aRightGroupName = GetName() + "_Right_Bank";
285 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
286 aRightGroup->SetName( aRightGroupName );
287 aRightGroup->AddShape( aResultPrs.myRightBank );
289 QString anInGroupName = GetName() + "_Inlet";
291 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
292 anInGroup->SetName( anInGroupName );
293 anInGroup->AddShape( aResultPrs.myInlet );
295 QString anOutGroupName = GetName() + "_Outlet";
297 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
298 anOutGroup->SetName( anOutGroupName );
299 anOutGroup->AddShape( aResultPrs.myOutlet );
303 void HYDROData_Stream::UpdatePrs( const Handle(HYDROData_DTM)& theDTM )
305 HYDROData_NaturalObject::Update();
307 PrsDefinition aResultPrs;
308 if ( !CreatePresentations( theDTM, aResultPrs ) )
311 internalUpdatePrs(aResultPrs);
314 void HYDROData_Stream::UpdatePrs( const Handle(HYDROData_LISM)& theLISM )
316 HYDROData_NaturalObject::Update();
317 PrsDefinition prsDef;
318 theLISM->GetShapePresentations(prsDef);
320 internalUpdatePrs(prsDef);
323 QColor HYDROData_Stream::DefaultFillingColor() const
325 return QColor( Qt::green );
328 QColor HYDROData_Stream::DefaultBorderColor() const
330 return QColor( Qt::transparent );
333 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
335 if ( theHydAxis.IsNull() )
338 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
339 if ( aHydraulicShape.IsNull() ||
340 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
341 BRep_Tool::IsClosed( aHydraulicShape ) )
342 return false; // The polyline must be a single not closed wire
347 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
349 HYDROData_SequenceOfObjects aGroups = GetGroups();
350 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
353 TopoDS_Shape HYDROData_Stream::GetRightShape() const
355 HYDROData_SequenceOfObjects aGroups = GetGroups();
356 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
359 TopoDS_Shape HYDROData_Stream::GetInletShape() const
361 HYDROData_SequenceOfObjects aGroups = GetGroups();
362 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
365 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
367 HYDROData_SequenceOfObjects aGroups = GetGroups();
368 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
371 Handle(HYDROData_DTM) HYDROData_Stream::DTM() const
373 const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
374 return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() );
377 Handle(HYDROData_LISM) HYDROData_Stream::LISM() const
379 const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
380 return Handle(HYDROData_LISM)::DownCast( GetAltitudeObject() );
383 double HYDROData_Stream::GetDDZ() const
385 return DTM()->GetDDZ();
388 void HYDROData_Stream::SetDDZ( double theDDZ )
390 DTM()->SetDDZ( theDDZ );
394 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetLeftBank() const
396 return LISM()->GetLeftBank();
399 void HYDROData_Stream::SetLeftBank( const Handle(HYDROData_PolylineXY)& theBank )
401 LISM()->SetLeftBank( theBank );
405 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetRightBank() const
407 return LISM()->GetRightBank();
410 void HYDROData_Stream::SetRightBank( const Handle(HYDROData_PolylineXY)& theBank )
412 LISM()->SetRightBank( theBank );
417 double HYDROData_Stream::GetHaxStep() const
419 return LISM()->GetHaxStep();
422 void HYDROData_Stream::SetHaxStep( double theHaxStep )
424 LISM()->SetHaxStep( theHaxStep );
428 int HYDROData_Stream::GetNbProfilePoints() const
430 return LISM()->GetNbProfilePoints();
433 void HYDROData_Stream::SetNbProfilePoints( int theNbPoints )
435 LISM()->SetNbProfilePoints( theNbPoints );
439 double HYDROData_Stream::GetSpatialStep() const
441 if (GetInterpolationMethod() == 0)
442 return DTM()->GetSpatialStep();
444 return LISM()->GetHaxStep();
447 void HYDROData_Stream::SetSpatialStep( double theSpatialStep )
449 if (GetInterpolationMethod() == 0 )
450 DTM()->SetSpatialStep( theSpatialStep );
452 LISM()->SetHaxStep( theSpatialStep );
456 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
458 if (GetInterpolationMethod() == 0)
460 if ( !IsValidAsAxis( theAxis ) )
463 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
464 if ( IsEqual( aPrevAxis, theAxis ) )
467 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
469 // Update the order of profiles
470 updateProfilesOrder();
472 // Indicate model of the need to update the stream presentation
477 LISM()->SetHydraulicAxis( theAxis );
484 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
486 if (GetInterpolationMethod() == 0)
487 return Handle(HYDROData_PolylineXY)::DownCast( GetReferenceObject( DataTag_HydraulicAxis ) );
489 return LISM()->GetHydraulicAxis();
492 void HYDROData_Stream::RemoveHydraulicAxis()
494 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
495 if ( aPrevAxis.IsNull() )
498 ClearReferenceObjects( DataTag_HydraulicAxis );
500 // We remove the reference profiles
503 // Indicate model of the need to update the stream presentation
507 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
508 const TopoDS_Face& thePlane,
509 Standard_Real& theOutPar ) const
511 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
512 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
515 #include <BRepAlgo_NormalProjection.hxx>
517 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
518 const Handle(HYDROData_Profile)& theProfile,
519 const TopoDS_Face& thePlane,
520 Standard_Real& theOutPar )
522 if ( theProfile.IsNull() /*|| !IsValidAsAxis( theHydAxis )*/ )
525 if (theHydAxis.IsNull())
526 return true; //empty h_axis; its's OK
528 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
529 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
530 if ( aProfileWire.IsNull() )
532 DEBTRACE("aProfileWire.IsNull");
536 //BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
537 BRepAlgo_NormalProjection nproj(thePlane);
538 nproj.Add(aProfileWire);
539 nproj.SetDefaultParams();
543 DEBTRACE("!nproj.IsDone");
546 TopoDS_Shape aPrjProfile = nproj.Projection();
547 if(aPrjProfile.IsNull())
549 DEBTRACE("aPrjProfile.IsNull");
552 TopoDS_Vertex aV1, aV2;
553 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
554 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
555 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
556 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
557 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
558 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
560 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
562 anExp.Init(aPrjProfile, TopAbs_EDGE);
564 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
568 if(aV1.IsNull() || aV2.IsNull())
570 DEBTRACE("aV1.IsNull() || aV2.IsNull()");
573 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
574 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
577 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
580 DEBTRACE("!aMk.IsDone()");
583 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
584 Standard_Integer aNum(0);
586 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
587 for(;anExplo.More();anExplo.Next()) aNum++;
588 // check for self-intersection
589 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
590 Standard_Boolean hasInt(false);
591 Standard_Real aSqDist(DBL_MAX);
592 Standard_Integer anIndx(0);
593 BRepExtrema_ExtCC aCC;
594 aCC.Initialize(anEdg2);
596 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
597 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
598 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
601 Standard_Boolean hasSol(false);
605 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
606 if(aCC.SquareDistance(i) < aSqDist) {
607 aSqDist = aCC.SquareDistance(i);
613 if(aSqDist <= SquareTolerance) { // hasInt
614 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
616 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
617 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
619 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
627 TopExp::Vertices(anEdg1, aV1, aV2);
628 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
631 } else if(aNum > 1) {
632 TopExp::Vertices(anEdg1, aV1, aV2);
633 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
638 DEBTRACE("!hasInt " << aPnt1.X() << " " << aPnt1.Y() << " " << aPnt2.X() << " " << aPnt2.Y() << " --- " << aSqDist);
642 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
644 if ( theProfile.IsNull() )
647 // Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
648 // if ( aHydAxis.IsNull() )
652 BuildRefFace( aPlane );
654 Standard_Real aPar(.0);
655 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
656 return false; // Object is already in reference list or it has no intersection
657 //DEBTRACE("AddProfile - insertParameter " << aPar);
658 int aProfileIndex = insertParameter( aPar );
659 insertProfileInToOrder( theProfile, aProfileIndex );
661 if (GetInterpolationMethod()==0)
662 DTM()->SetProfiles( GetProfiles() );
664 LISM()->SetProfiles( GetProfiles() );
666 // Indicate model of the need to update the stream presentation
672 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
673 const bool& theIsToOrder )
675 DEBTRACE(" --- SetProfiles " <<theIsToOrder );
678 for ( int i = 1; i <= theProfiles.Length(); ++i )
680 Handle(HYDROData_Profile) aProfile =
681 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
682 if ( aProfile.IsNull() )
685 if ( !AddProfile( aProfile ) )
687 DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
692 else // Just store the sequence of objects as is
694 bool anIsToUpdate = true;
696 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
697 if ( anOldProfiles.Length() == theProfiles.Length() )
699 anIsToUpdate = false;
701 for ( int i = 1; i <= theProfiles.Length(); ++i )
703 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
704 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
705 if ( !IsEqual( anOldProfile, aNewProfile ) )
713 SetReferenceObjects( theProfiles, DataTag_Profile );
719 if (GetInterpolationMethod()==0)
720 DTM()->SetProfiles( GetProfiles() );
722 LISM()->SetProfiles( GetProfiles() );
726 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
728 return GetReferenceObjects( DataTag_Profile );
731 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
733 if ( theProfile.IsNull() )
736 int aProfileIndex = -1;
738 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
739 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
740 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
742 Handle(HYDROData_Profile) aProfile =
743 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
744 if ( aProfile.IsNull() )
747 if ( IsEqual( theProfile, aProfile ) )
754 if ( aProfileIndex == -1 )
757 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
759 // Remove parameter for removed profile
760 removeParameter( aProfileIndex );
762 // Indicate model of the need to update the stream presentation
768 void HYDROData_Stream::RemoveProfiles()
770 ClearReferenceObjects( DataTag_Profile );
772 // Remove the parameters array
773 removeParametersArray();
775 // Indicate model of the need to update the stream presentation
780 int HYDROData_Stream::GetInterpolationMethod() const
782 return GetInteger( DataTag_InterpMethod );
785 void HYDROData_Stream::SetInterpolationMethod( int theMethod ) //if DTM => 0 ; if LISM => 1
787 SetInteger( DataTag_InterpMethod, theMethod );
792 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
793 const int theBeforeIndex )
795 //Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
796 if ( theProfile.IsNull() )
799 //TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
800 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
801 if ( aProfileWire.IsNull() )
804 if ( theBeforeIndex == -1 )
805 AddReferenceObject( theProfile, DataTag_Profile );
807 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
810 void HYDROData_Stream::BuildRefFace( TopoDS_Face& thePlane )
812 thePlane = BRepBuilderAPI_MakeFace(gp_Pln(gp_Pnt(0,0,0),gp_Dir(0,0,1))).Face();
815 void HYDROData_Stream::updateProfilesOrder()
817 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
818 if ( aRefProfiles.IsEmpty() )
821 // At first we remove all profiles from order
824 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
825 if ( aHydAxis.IsNull() )
829 BuildRefFace( aPlane );
831 Standard_Real aPar( .0 );
835 TopoDS_Compound aCmp;
836 aBB.MakeCompound(aCmp);
839 HYDROData_DataMapOfRealOfHDProfile aDM;
840 TColStd_ListOfReal aList;
841 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
842 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
844 Handle(HYDROData_Profile) aProfile =
845 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
847 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
848 aBB.Add( aCmp, aProfileWire );
850 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
853 aDM.Bind( aPar, aProfile );
854 aList.Append( aPar );
857 if ( aList.IsEmpty() )
860 QVector<double> anArr( aList.Extent() );
862 TColStd_ListIteratorOfListOfReal it( aList );
863 for ( int j = 1; it.More(); it.Next(), j++ )
864 anArr[j-1] = it.Value();
867 if ( aList.Extent() > 1 )
869 //TCollection_CompareOfReal Compar;
870 //SortTools_QuickSortOfReal::Sort( anArr, Compar );
871 std::sort( anArr.begin(), anArr.end() );
873 for (int j = 1; j <= anArr.size(); j++) {
874 const Standard_Real aKey = anArr[j-1];
875 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
876 insertProfileInToOrder( aProfile );
878 } else if ( aList.Extent() == 1 ) {
879 const Standard_Real aKey = aList.Last();
880 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
881 insertProfileInToOrder( aProfile );
884 setParametersArray( anArr );
887 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
888 BRepTools::Write(aHydraulicWire, "Path.brep");
889 BRepTools::Write(aCmp, "Prof.brep");
893 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
895 int InterpMethod = GetInterpolationMethod();
896 if (InterpMethod == 1)
902 void HYDROData_Stream::setParametersArray( const QVector<double>& theArray )
904 if ( theArray.size() == 0 )
906 removeParametersArray();
910 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
912 int n = theArray.size();
913 Handle(TDataStd_RealArray) aParamsArray =
914 TDataStd_RealArray::Set( aLabel, 1, n );
915 aParamsArray->SetID(TDataStd_RealArray::GetID());
916 for ( int i = 0; i < n; ++i )
918 const Standard_Real& aParam = theArray[i];
919 aParamsArray->SetValue( i+1, aParam );
923 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
925 TColStd_Array1OfReal* anArray = NULL;
927 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
928 if ( !aLabel.IsNull() )
930 Handle(TDataStd_RealArray) aParamsArray;
931 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
933 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
934 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
936 const Standard_Real& aParam = aParamsArray->Value( i );
937 anArray->SetValue( i, aParam );
945 void HYDROData_Stream::removeParametersArray()
947 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
948 if ( !aLabel.IsNull() )
949 aLabel.ForgetAllAttributes();
952 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
956 TColStd_Array1OfReal* anArr = getParametersArray();
961 QVector<double> aNewArr( anArr->Upper() +1 );
962 bool isInserted = false;
963 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
965 const Standard_Real& aStoredParam = anArr->Value( i );
968 if ( theParam > aStoredParam )
975 aNewArr[j-1] = theParam;
981 aNewArr[j-1] = aStoredParam;
987 aNewArr[aNewArr.size()-1] = theParam;
990 setParametersArray( aNewArr );
995 QVector<double> aNewArr( 1 );
996 aNewArr[0] = theParam;
997 setParametersArray( aNewArr );
1003 void HYDROData_Stream::removeParameter( const int& theIndex )
1005 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
1006 if ( aLabel.IsNull() )
1009 Handle(TDataStd_RealArray) aParamsArray;
1010 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
1013 if ( aParamsArray->Length() == 1 )
1015 removeParametersArray();
1019 QVector<double> aNewArr( aParamsArray->Upper() - 2 );
1021 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
1023 const Standard_Real& aStoredParam = aParamsArray->Value( i );
1024 if ( k == theIndex )
1027 aNewArr[j-1] = aStoredParam;
1031 setParametersArray( aNewArr );
1034 bool HYDROData_Stream::GenerateBottomPolyline()
1037 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1038 if ( aDocument.IsNull() ) {
1042 // Collect bottom points ( one bottom point from each profile of the stream )
1043 HYDROData_Profile::ProfilePoints aBottomPoints;
1045 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
1046 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
1047 const Handle(HYDROData_Profile) aProfile =
1048 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
1049 if ( aProfile.IsNull() ) {
1053 aBottomPoints.Append( aProfile->GetBottomPoint() );
1056 int aNbBottomPoints = aBottomPoints.Size();
1058 if ( aNbBottomPoints < 2 ) {
1062 // Create bottom polyline object if the stream doesn't contain it yet
1063 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1064 if ( aBottom.IsNull() ) {
1065 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
1066 QString aBaseName = GetName() + "_bottom";
1067 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
1068 aBottom->SetName( aName );
1070 SetReferenceObject( aBottom, DataTag_BottomPolyline );
1073 // Create 2D polyline if the bottom polyline doesn't contain it yet
1074 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
1075 if ( aPolylineXY.IsNull() ) {
1076 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
1077 QString aBaseName = GetName() + "_bottom_2d";
1078 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
1079 aPolylineXY->SetName( aName );
1080 aBottom->SetPolylineXY( aPolylineXY, false );
1083 aPolylineXY->RemoveSections();
1084 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
1086 // Create profile if the bottom polyline doesn't contain it yet
1087 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
1088 if ( aProfileUZ.IsNull() ) {
1089 Handle(HYDROData_Profile) aProfile =
1090 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1091 QString aBaseName = GetName() + "_bottom_profile";
1092 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
1093 aProfile->SetName( aName );
1094 aProfileUZ = aProfile->GetProfileUZ( true );
1095 aBottom->SetProfileUZ( aProfileUZ );
1098 aProfileUZ->RemoveSection( 0 );
1100 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY, true);
1105 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
1107 return Handle(HYDROData_Polyline3D)::DownCast(
1108 GetReferenceObject( DataTag_BottomPolyline ) );
1111 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
1113 if ( theBottom.IsNull() ) {
1117 SetReferenceObject( theBottom, DataTag_BottomPolyline );
1122 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
1125 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1126 if ( aDocument.IsNull() ) {
1130 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
1131 theInterpolator->Calculate();
1134 if ( theInterpolator->GetErrorCode() != OK ) {
1140 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
1141 // Get calculated point coordinates
1142 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
1143 if ( aResultPoints.IsEmpty() ) {
1148 // Create profile object
1149 Handle(HYDROData_Profile) aProfile =
1150 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
1151 QString aBaseName = GetName() + "_interp_profile";
1152 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
1153 aProfile->SetName( aName );
1155 // Fill the profile with points
1156 aProfile->SetProfilePoints( aResultPoints );
1158 // Add profile to the stream
1159 bool isAdded = AddProfile( aProfile );
1173 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1174 bool isGenerateNewName ) const
1177 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1178 if ( aDocument.IsNull() ) {
1183 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1185 Handle(HYDROData_Stream) aStreamCopy =
1186 Handle(HYDROData_Stream)::DownCast( theDestination );
1188 // Copy bottom polyline if exists
1189 if ( !aStreamCopy.IsNull() ) {
1190 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1191 if ( !aBottom.IsNull() ) {
1192 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1193 aStreamCopy->GenerateBottomPolyline();
1194 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1195 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1196 aBottomCopy->GetPolylineXY()->Update();
1197 aBottomCopy->Update();
1202 void HYDROData_Stream::CreatePresentations( const Handle(TColgp_HArray1OfPnt) theArrayOfFPnt,
1203 const Handle(TColgp_HArray1OfPnt) theArrayOfLPnt,
1204 const Handle(TopTools_HArray1OfShape) theArrOfProfiles,
1205 PrsDefinition& thePrs )
1208 HYDROData_Bathymetry::AltitudePoints left;
1209 for (int i = theArrayOfLPnt->Lower(); i <= theArrayOfLPnt->Upper(); i++)
1211 left.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfLPnt->Value(i).X(),
1212 theArrayOfLPnt->Value(i).Y(),
1213 theArrayOfLPnt->Value(i).Z()));
1216 HYDROData_Bathymetry::AltitudePoints right;
1217 for (int i = theArrayOfFPnt->Lower(); i <= theArrayOfFPnt->Upper(); i++)
1219 right.push_back(HYDROData_Bathymetry::AltitudePoint(theArrayOfFPnt->Value(i).X(),
1220 theArrayOfFPnt->Value(i).Y(),
1221 theArrayOfFPnt->Value(i).Z()));
1224 std::vector<HYDROData_Bathymetry::AltitudePoints> dummy;
1225 TopTools_IndexedMapOfOrientedShape ll = HYDROData_DTM::Create3DShape(left, right, dummy);
1227 TopoDS_Shape LB, RB, IL, OL;
1231 TopAbs_ShapeEnum ll1_sht = ll(1).ShapeType();
1232 TopAbs_ShapeEnum ll2_sht = ll(2).ShapeType();
1233 if ((ll1_sht == TopAbs_WIRE || ll1_sht == TopAbs_EDGE) &&
1234 (ll2_sht == TopAbs_WIRE || ll2_sht == TopAbs_EDGE))
1241 IL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Lower())); //TODO check that
1242 OL = TopoDS::Wire(theArrOfProfiles->Value(theArrOfProfiles->Upper()));
1244 //make new compound so it's shapes will be in known order to build correct projection
1246 TopoDS_Compound newCmp;
1247 BB.MakeCompound(newCmp);
1253 thePrs.myPrs3D = newCmp;
1255 TopTools_SequenceOfShape LS;
1256 //HYDROData_DTM::Get2dFaceFrom3dPres( newCmp, TopoDS::Face(thePrs.myPrs2D), &LS, ind );
1258 HYDROData_DTM::GetPlanarFaceFromBanks(TopoDS::Edge(LB), TopoDS::Edge(RB), TopoDS::Face(thePrs.myPrs2D), &LS);
1261 TopTools_IndexedMapOfShape EE;
1262 TopExp::MapShapes(thePrs.myPrs2D, TopAbs_EDGE, EE);
1264 for (int i = 1; i <= 4; i++)
1266 TopoDS_Shape W = LS(i);
1267 TopTools_IndexedMapOfShape EW;
1268 TopExp::MapShapes(W, TopAbs_EDGE, EW);
1269 for (int k = 1; k <= EW.Extent(); k++)
1270 noncontNb += !EE.Contains(EW(k));
1272 //noncontNb > 0 => some problem with edge history
1273 assert(noncontNb == 0);
1276 thePrs.myLeftBank = LS(1);
1277 thePrs.myInlet = LS(2);
1278 thePrs.myOutlet = LS(3);
1279 thePrs.myRightBank = LS(4);