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"
32 #include <TDataStd_RealArray.hxx>
34 #include <Precision.hxx>
36 #include <NCollection_DataMap.hxx>
38 #include <TColStd_Array1OfReal.hxx>
39 #include <TColStd_ListOfReal.hxx>
40 #include <TColStd_ListIteratorOfListOfReal.hxx>
41 #include <TCollection_CompareOfReal.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>
79 #include <SortTools_QuickSortOfReal.hxx>
82 #include <QStringList>
84 //#define DEB_STREAM 1
86 //#define DEB_HASINT 1
87 //#define DEB_UPDATE 1
88 #include <BRepTools.hxx>
89 #include <TCollection_AsciiString.hxx>
92 typedef NCollection_DataMap<Standard_Real, Handle(HYDROData_Profile)> HYDROData_DataMapOfRealOfHDProfile;
94 IMPLEMENT_STANDARD_HANDLE(HYDROData_Stream,HYDROData_NaturalObject)
95 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Stream,HYDROData_NaturalObject)
98 HYDROData_Stream::HYDROData_Stream()
99 : HYDROData_NaturalObject( Geom_3d )
103 HYDROData_Stream::~HYDROData_Stream()
107 QStringList HYDROData_Stream::DumpToPython( const QString& thePyScriptPath,
108 MapOfTreatedObjects& theTreatedObjects ) const
110 QStringList aResList = dumpObjectCreation( theTreatedObjects );
111 QString aName = GetObjPyName();
113 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
114 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
116 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
117 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
119 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
120 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
123 // Set bottom polyline if exists
124 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
125 if ( !aBottomPolyline.IsNull() ) {
126 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
129 QString aDDZs = QString::number( GetDDZ(), 'f', 3 );
130 QString aSSteps = QString::number( GetSpatialStep(), 'f', 3 );
131 aResList << QString( "%1.SetDDZ( %2 )" ).arg( aName ).arg( aDDZs );
132 aResList << QString( "%1.SetSpatialStep( %2 )" ).arg( aName ).arg( aSSteps );
134 aResList << QString( "" );
135 aResList << QString( "%1.Update()" ).arg( aName );
136 aResList << QString( "" );
141 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
143 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
145 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
146 if ( !aHydAxis.IsNull() )
147 aResSeq.Append( aHydAxis );
149 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
150 aResSeq.Append( aSeqOfProfiles );
155 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
156 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
158 Handle(Geom_BSplineCurve) aBSpline;
159 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
160 anInterpolator.Perform() ;
161 if (anInterpolator.IsDone())
162 aBSpline = anInterpolator.Curve();
166 void HYDROData_Stream::Update()
168 updateProfilesOrder();
170 // Update bottom polyline if exists
171 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
172 if ( !aBottomPolyline.IsNull() ) {
173 if ( GenerateBottomPolyline() ) {
174 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
175 if ( !aPolylineXY.IsNull() ) {
176 aPolylineXY->Update();
178 aBottomPolyline->Update();
182 Handle_HYDROData_DTM dtm = DTM();
187 bool HYDROData_Stream::IsHas2dPrs() const
192 bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM,
193 PrsDefinition& thePrs )
195 if ( theDTM.IsNull() )
198 HYDROData_SequenceOfObjects profiles = theDTM->GetProfiles();
199 if( profiles.Length() < 2 )
202 TopTools_ListOfShape profiles3d;
205 HYDROData_SequenceOfObjects::Iterator anIter( profiles );
206 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
208 Handle(HYDROData_Profile) aProfile =
209 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
211 if ( aProfile.IsNull() )
214 const TopoDS_Shape& aProfileShape = aProfile->GetShape3D();
215 profiles3d.Append( aProfileShape );
218 TopoDS_Edge aLeftBank, aRightBank;
219 theDTM->CreateBankShapes( aLeftBank, aRightBank );
220 return CreatePresentations( aLeftBank, aRightBank, profiles3d, thePrs );
223 void HYDROData_Stream::UpdatePrs( const Handle_HYDROData_DTM& theDTM )
225 HYDROData_NaturalObject::Update();
227 PrsDefinition aResultPrs;
228 if ( !CreatePresentations( theDTM, aResultPrs ) )
231 SetShape3D( aResultPrs.myPrs3D );
232 SetTopShape( aResultPrs.myPrs2D );
234 // Create the stream groups
235 QString aLeftGroupName = GetName() + "_Left_Bank";
237 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
238 aLeftGroup->SetName( aLeftGroupName );
239 aLeftGroup->AddShape( aResultPrs.myLeftBank );
241 QString aRightGroupName = GetName() + "_Right_Bank";
243 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
244 aRightGroup->SetName( aRightGroupName );
245 aRightGroup->AddShape( aResultPrs.myRightBank );
247 QString anInGroupName = GetName() + "_Inlet";
249 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
250 anInGroup->SetName( anInGroupName );
251 anInGroup->AddShape( aResultPrs.myInlet );
253 QString anOutGroupName = GetName() + "_Outlet";
255 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
256 anOutGroup->SetName( anOutGroupName );
257 anOutGroup->AddShape( aResultPrs.myOutlet );
260 QColor HYDROData_Stream::DefaultFillingColor() const
262 return QColor( Qt::green );
265 QColor HYDROData_Stream::DefaultBorderColor() const
267 return QColor( Qt::transparent );
270 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
272 if ( theHydAxis.IsNull() )
275 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
276 if ( aHydraulicShape.IsNull() ||
277 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
278 BRep_Tool::IsClosed( aHydraulicShape ) )
279 return false; // The polyline must be a single not closed wire
284 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
286 HYDROData_SequenceOfObjects aGroups = GetGroups();
287 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
290 TopoDS_Shape HYDROData_Stream::GetRightShape() const
292 HYDROData_SequenceOfObjects aGroups = GetGroups();
293 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
296 TopoDS_Shape HYDROData_Stream::GetInletShape() const
298 HYDROData_SequenceOfObjects aGroups = GetGroups();
299 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
302 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
304 HYDROData_SequenceOfObjects aGroups = GetGroups();
305 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
308 Handle_HYDROData_DTM HYDROData_Stream::DTM() const
310 const_cast<HYDROData_Stream*>( this )->checkAndSetAltitudeObject();
311 return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() );
314 double HYDROData_Stream::GetDDZ() const
316 return DTM()->GetDDZ();
319 void HYDROData_Stream::SetDDZ( double theDDZ )
321 DTM()->SetDDZ( theDDZ );
324 double HYDROData_Stream::GetSpatialStep() const
326 return DTM()->GetSpatialStep();
329 void HYDROData_Stream::SetSpatialStep( double theSpatialStep )
331 DTM()->SetSpatialStep( theSpatialStep );
334 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
336 if ( !IsValidAsAxis( theAxis ) )
339 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
340 if ( IsEqual( aPrevAxis, theAxis ) )
343 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
345 // Update the order of profiles
346 updateProfilesOrder();
348 // Indicate model of the need to update the stream presentation
354 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
356 return Handle(HYDROData_PolylineXY)::DownCast(
357 GetReferenceObject( DataTag_HydraulicAxis ) );
360 void HYDROData_Stream::RemoveHydraulicAxis()
362 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
363 if ( aPrevAxis.IsNull() )
366 ClearReferenceObjects( DataTag_HydraulicAxis );
368 // We remove the reference profiles
371 // Indicate model of the need to update the stream presentation
375 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
376 const TopoDS_Face& thePlane,
377 Standard_Real& theOutPar ) const
379 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
380 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
383 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
384 const Handle(HYDROData_Profile)& theProfile,
385 const TopoDS_Face& thePlane,
386 Standard_Real& theOutPar )
388 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
391 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
392 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
393 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
396 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
397 if(!aProjector.IsDone())
399 TopoDS_Shape aPrjProfile = aProjector.Shape();
400 if(aPrjProfile.IsNull())
402 TopoDS_Vertex aV1, aV2;
403 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
404 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
405 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
406 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
407 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
408 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
410 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
412 anExp.Init(aPrjProfile, TopAbs_EDGE);
414 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
418 if(aV1.IsNull() || aV2.IsNull())
420 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
421 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
424 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
427 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
428 Standard_Integer aNum(0);
430 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
431 for(;anExplo.More();anExplo.Next()) aNum++;
432 // check for self-intersection
433 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
434 Standard_Boolean hasInt(false);
435 Standard_Real aSqDist(DBL_MAX);
436 Standard_Integer anIndx(0);
437 BRepExtrema_ExtCC aCC;
438 aCC.Initialize(anEdg2);
440 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
441 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
442 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
445 Standard_Boolean hasSol(false);
449 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
450 if(aCC.SquareDistance(i) < aSqDist) {
451 aSqDist = aCC.SquareDistance(i);
457 if(aSqDist <= SquareTolerance) { // hasInt
458 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
460 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
461 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
463 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
471 TopExp::Vertices(anEdg1, aV1, aV2);
472 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
475 } else if(aNum > 1) {
476 TopExp::Vertices(anEdg1, aV1, aV2);
477 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
485 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
487 if ( theProfile.IsNull() )
490 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
491 if ( aHydAxis.IsNull() )
495 if(!BuildFace(aHydAxis, aPlane))
498 Standard_Real aPar(.0);
499 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
500 return false; // Object is already in reference list or it has no intersection
502 int aProfileIndex = insertParameter( aPar );
503 insertProfileInToOrder( theProfile, aProfileIndex );
505 // Indicate model of the need to update the stream presentation
511 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
512 const bool& theIsToOrder )
516 for ( int i = 1; i <= theProfiles.Length(); ++i )
518 Handle(HYDROData_Profile) aProfile =
519 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
520 if ( aProfile.IsNull() )
523 if ( !AddProfile( aProfile ) )
525 DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
530 else // Just store the sequence of objects as is
532 bool anIsToUpdate = true;
534 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
535 if ( anOldProfiles.Length() == theProfiles.Length() )
537 anIsToUpdate = false;
539 for ( int i = 1; i <= theProfiles.Length(); ++i )
541 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
542 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
543 if ( !IsEqual( anOldProfile, aNewProfile ) )
551 SetReferenceObjects( theProfiles, DataTag_Profile );
557 DTM()->SetProfiles( GetProfiles() );
561 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
563 return GetReferenceObjects( DataTag_Profile );
566 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
568 if ( theProfile.IsNull() )
571 int aProfileIndex = -1;
573 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
574 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
575 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
577 Handle(HYDROData_Profile) aProfile =
578 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
579 if ( aProfile.IsNull() )
582 if ( IsEqual( theProfile, aProfile ) )
589 if ( aProfileIndex == -1 )
592 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
594 // Remove parameter for removed profile
595 removeParameter( aProfileIndex );
597 // Indicate model of the need to update the stream presentation
603 void HYDROData_Stream::RemoveProfiles()
605 ClearReferenceObjects( DataTag_Profile );
607 // Remove the parameters array
608 removeParametersArray();
610 // Indicate model of the need to update the stream presentation
614 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
615 const int theBeforeIndex )
617 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
618 if ( theProfile.IsNull() || aHydAxis.IsNull() )
621 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
622 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
623 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
626 if ( theBeforeIndex == -1 )
627 AddReferenceObject( theProfile, DataTag_Profile );
629 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
632 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
633 TopoDS_Face& thePlane )
635 if ( !IsValidAsAxis( theHydAxis ) )
638 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
640 gp_Ax2 aX2(gp::XOY());
644 BRepBndLib::Add(aHydraulicWire,B);
645 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
646 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
647 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
648 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
649 thePlane = TopoDS::Face(aMkr.Shape());
653 void HYDROData_Stream::updateProfilesOrder()
655 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
656 if ( aRefProfiles.IsEmpty() )
659 // At first we remove all profiles from order
662 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
663 if ( aHydAxis.IsNull() )
667 if ( !BuildFace( aHydAxis, aPlane ) )
670 Standard_Real aPar( .0 );
674 TopoDS_Compound aCmp;
675 aBB.MakeCompound(aCmp);
678 HYDROData_DataMapOfRealOfHDProfile aDM;
679 TColStd_ListOfReal aList;
680 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
681 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
683 Handle(HYDROData_Profile) aProfile =
684 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
686 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
687 aBB.Add( aCmp, aProfileWire );
689 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
692 aDM.Bind( aPar, aProfile );
693 aList.Append( aPar );
696 if ( aList.IsEmpty() )
699 TColStd_Array1OfReal anArr( 1, aList.Extent() );
701 TColStd_ListIteratorOfListOfReal it( aList );
702 for ( int j = 1; it.More(); it.Next(), j++ )
703 anArr( j ) = it.Value();
706 if ( aList.Extent() > 1 )
708 TCollection_CompareOfReal Compar;
709 SortTools_QuickSortOfReal::Sort( anArr, Compar );
711 for (int j = 1; j <= anArr.Length(); j++) {
712 const Standard_Real aKey = anArr(j);
713 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
714 insertProfileInToOrder( aProfile );
716 } else if ( aList.Extent() == 1 ) {
717 const Standard_Real aKey = aList.Last();
718 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
719 insertProfileInToOrder( aProfile );
722 setParametersArray( anArr );
725 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
726 BRepTools::Write(aHydraulicWire, "Path.brep");
727 BRepTools::Write(aCmp, "Prof.brep");
731 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
736 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
738 if ( theArray.Length() == 0 )
740 removeParametersArray();
744 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
746 Handle(TDataStd_RealArray) aParamsArray =
747 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
749 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
751 const Standard_Real& aParam = theArray( i );
752 aParamsArray->SetValue( i, aParam );
756 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
758 TColStd_Array1OfReal* anArray = NULL;
760 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
761 if ( !aLabel.IsNull() )
763 Handle(TDataStd_RealArray) aParamsArray;
764 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
766 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
767 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
769 const Standard_Real& aParam = aParamsArray->Value( i );
770 anArray->SetValue( i, aParam );
778 void HYDROData_Stream::removeParametersArray()
780 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
781 if ( !aLabel.IsNull() )
782 aLabel.ForgetAllAttributes();
785 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
789 TColStd_Array1OfReal* anArr = getParametersArray();
794 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
796 bool isInserted = false;
797 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
799 const Standard_Real& aStoredParam = anArr->Value( i );
802 if ( theParam > aStoredParam )
808 aNewArr( j ) = theParam;
814 aNewArr( j ) = aStoredParam;
820 aNewArr( aNewArr.Upper() ) = theParam;
823 setParametersArray( aNewArr );
828 TColStd_Array1OfReal aNewArr( 1, 1 );
829 aNewArr.SetValue( 1, theParam );
830 setParametersArray( aNewArr );
836 void HYDROData_Stream::removeParameter( const int& theIndex )
838 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
839 if ( aLabel.IsNull() )
842 Handle(TDataStd_RealArray) aParamsArray;
843 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
846 if ( aParamsArray->Length() == 1 )
848 removeParametersArray();
852 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
854 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
856 const Standard_Real& aStoredParam = aParamsArray->Value( i );
860 aNewArr.SetValue( j, aStoredParam );
864 setParametersArray( aNewArr );
867 bool HYDROData_Stream::GenerateBottomPolyline()
870 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
871 if ( aDocument.IsNull() ) {
875 // Collect bottom points ( one bottom point from each profile of the stream )
876 HYDROData_Profile::ProfilePoints aBottomPoints;
878 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
879 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
880 const Handle(HYDROData_Profile) aProfile =
881 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
882 if ( aProfile.IsNull() ) {
886 aBottomPoints.Append( aProfile->GetBottomPoint() );
889 int aNbBottomPoints = aBottomPoints.Size();
891 if ( aNbBottomPoints < 2 ) {
895 // Create bottom polyline object if the stream doesn't contain it yet
896 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
897 if ( aBottom.IsNull() ) {
898 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
899 QString aBaseName = GetName() + "_bottom";
900 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
901 aBottom->SetName( aName );
903 SetReferenceObject( aBottom, DataTag_BottomPolyline );
906 // Create 2D polyline if the bottom polyline doesn't contain it yet
907 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
908 if ( aPolylineXY.IsNull() ) {
909 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
910 QString aBaseName = GetName() + "_bottom_2d";
911 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
912 aPolylineXY->SetName( aName );
913 aBottom->SetPolylineXY( aPolylineXY, false );
916 aPolylineXY->RemoveSections();
917 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
919 // Create profile if the bottom polyline doesn't contain it yet
920 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
921 if ( aProfileUZ.IsNull() ) {
922 Handle(HYDROData_Profile) aProfile =
923 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
924 QString aBaseName = GetName() + "_bottom_profile";
925 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
926 aProfile->SetName( aName );
927 aProfileUZ = aProfile->GetProfileUZ( true );
928 aBottom->SetProfileUZ( aProfileUZ );
931 aProfileUZ->RemoveSection( 0 );
933 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
938 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
940 return Handle(HYDROData_Polyline3D)::DownCast(
941 GetReferenceObject( DataTag_BottomPolyline ) );
944 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
946 if ( theBottom.IsNull() ) {
950 SetReferenceObject( theBottom, DataTag_BottomPolyline );
955 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
958 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
959 if ( aDocument.IsNull() ) {
963 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
964 theInterpolator->Calculate();
967 if ( theInterpolator->GetErrorCode() != OK ) {
973 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
974 // Get calculated point coordinates
975 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
976 if ( aResultPoints.IsEmpty() ) {
981 // Create profile object
982 Handle(HYDROData_Profile) aProfile =
983 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
984 QString aBaseName = GetName() + "_interp_profile";
985 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
986 aProfile->SetName( aName );
988 // Fill the profile with points
989 aProfile->SetProfilePoints( aResultPoints );
991 // Add profile to the stream
992 bool isAdded = AddProfile( aProfile );
1006 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1007 bool isGenerateNewName ) const
1010 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1011 if ( aDocument.IsNull() ) {
1016 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1018 Handle(HYDROData_Stream) aStreamCopy =
1019 Handle(HYDROData_Stream)::DownCast( theDestination );
1021 // Copy bottom polyline if exists
1022 if ( !aStreamCopy.IsNull() ) {
1023 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1024 if ( !aBottom.IsNull() ) {
1025 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1026 aStreamCopy->GenerateBottomPolyline();
1027 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1028 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1029 aBottomCopy->GetPolylineXY()->Update();
1030 aBottomCopy->Update();
1035 #include <GeomProjLib.hxx>
1036 #include <Geom_TrimmedCurve.hxx>
1037 #include <Geom_Plane.hxx>
1038 #include <BRepTools.hxx>
1039 static void ProjEdgeOnPlane(const TopoDS_Edge& inpEdge, const Handle_Geom_Plane& RefPlane, TopoDS_Edge& outSh, TopoDS_Vertex V1, TopoDS_Vertex V2)
1042 Handle(Geom_Curve) C3d = BRep_Tool::Curve(inpEdge, f, l);
1043 Handle(Geom_Curve) ProjectedCurve = GeomProjLib::ProjectOnPlane(new Geom_TrimmedCurve(C3d, f, l), RefPlane, RefPlane->Position().Direction(), Standard_True);
1044 if (V1.IsNull() || V2.IsNull())
1045 outSh = BRepLib_MakeEdge(ProjectedCurve); //create new vertices
1047 outSh = BRepLib_MakeEdge(ProjectedCurve, V1, V2);
1051 bool HYDROData_Stream::CreatePresentations( const TopoDS_Edge& theLeftBank,
1052 const TopoDS_Edge& theRightBank,
1053 const std::vector<TopoDS_Edge>& theProfiles3d,
1054 PrsDefinition& thePrs )
1056 thePrs.myLeftBank = theLeftBank;
1057 thePrs.myRightBank = theRightBank;
1060 TopoDS_Compound aCmp;
1061 aBB.MakeCompound(aCmp);
1062 for (size_t i = 0; i < theProfiles3d.size(); i++ )
1063 aBB.Add(aCmp, theProfiles3d[i]);
1065 aBB.Add(aCmp, theLeftBank);
1066 aBB.Add(aCmp, theRightBank);
1068 thePrs.myPrs3D = aCmp; //3d pres
1071 Handle_Geom_Plane RefPlane = new Geom_Plane(gp_Pnt(0,0,0), gp_Dir(0,0,1));
1072 std::vector<TopoDS_Edge> internProf;
1073 internProf.reserve(theProfiles3d.size() - 2);
1075 //project internal edges/profiles
1076 for (size_t i = 1; i < theProfiles3d.size() - 1; i++ )
1078 TopoDS_Edge ProjEdge;
1079 ProjEdgeOnPlane(theProfiles3d[i], RefPlane, ProjEdge, TopoDS_Vertex(), TopoDS_Vertex());
1080 internProf.push_back (TopoDS::Edge(ProjEdge.Oriented(TopAbs_INTERNAL)));
1083 TopoDS_Edge ProjEdgeIn, ProjEdgeOut;
1084 TopoDS_Vertex V1In, V2In, V1Out, V2Out;
1086 ProjEdgeOnPlane(theProfiles3d.front(), RefPlane, ProjEdgeIn, TopoDS_Vertex(), TopoDS_Vertex());
1087 TopExp::Vertices(ProjEdgeIn, V1In, V2In);
1089 ProjEdgeOnPlane(theProfiles3d.back(), RefPlane, ProjEdgeOut, TopoDS_Vertex(), TopoDS_Vertex());
1090 TopExp::Vertices(ProjEdgeOut, V1Out, V2Out);
1092 TopoDS_Edge ProjEdgeLeftB, ProjEdgeRightB;
1093 ProjEdgeOnPlane(theLeftBank, RefPlane, ProjEdgeLeftB, V1In, V1Out);
1094 ProjEdgeOnPlane(theRightBank, RefPlane, ProjEdgeRightB, V2In, V2Out);
1096 BRepLib_MakeWire WM(ProjEdgeIn, ProjEdgeOut, ProjEdgeLeftB, ProjEdgeRightB);
1097 for (size_t i = 0; i < internProf.size(); i++ )
1098 WM.Add(internProf[i]);
1100 TopoDS_Face outF = BRepLib_MakeFace(RefPlane, WM.Wire()).Face();
1101 thePrs.myPrs2D = outF;
1104 /*if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) {
1108 if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) {
1112 // Construct of the 3D presentation
1113 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt);
1114 if(aBSpline.IsNull())
1117 TopoDS_Edge anEdgLeft, anEdgRight;
1119 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
1120 if(aMakeEdge.IsDone())
1121 anEdgLeft = aMakeEdge.Edge();
1123 if(anEdgLeft.IsNull())
1127 aBSpline = buildInterpolationCurve (theArrayOfLPnt);
1128 if(aBSpline.IsNull())
1131 aMakeEdge.Init(aBSpline);
1132 if(aMakeEdge.IsDone())
1133 anEdgRight = aMakeEdge.Edge();
1135 if(anEdgRight.IsNull())
1139 TopoDS_Compound aCmp;
1140 aBB.MakeCompound(aCmp);
1141 for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ )
1142 aBB.Add(aCmp, theArrOfProfiles->Value(i));
1144 aBB.Add(aCmp,anEdgLeft);
1145 aBB.Add(aCmp,anEdgRight);
1146 BRepCheck_Analyzer aCh(aCmp);
1148 thePrs.myPrs3D = aCmp;
1151 BRepTools::Write(aCmp, "str3d.brep");
1152 thePrs.myPrs3D = aCmp;
1156 // Construct the top presentation
1157 int aNbPoints = theArrayOfFPnt->Length();
1158 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1159 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1160 for( int i=1; i <= aNbPoints; i++ ) {
1161 gp_Pnt aPnt = theArrayOfFPnt->Value(i);
1162 aPnt.SetZ(.0); // make 2d
1163 anArrayOfFPnt->SetValue(i, aPnt);
1164 aPnt = theArrayOfLPnt->Value(i);
1166 anArrayOfLPnt->SetValue(i, aPnt);
1170 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
1171 if(aBSpline.IsNull())
1174 aMakeEdge.Init(aBSpline);
1175 if(aMakeEdge.IsDone())
1176 anEdgLeft = aMakeEdge.Edge();
1179 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
1180 if(aBSpline.IsNull())
1183 aMakeEdge.Init(aBSpline);
1184 if(aMakeEdge.IsDone())
1185 anEdgRight = aMakeEdge.Edge();
1186 if(anEdgRight.IsNull())
1189 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
1190 TopoDS_Edge aBotEdge, aTopEdge;
1191 if(aMakeEdge2.IsDone())
1192 aBotEdge = aMakeEdge2.Edge();
1194 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
1195 if(aMakeEdge3.IsDone())
1196 aTopEdge = aMakeEdge3.Edge();
1198 // Make wire for 2D presentation with updating of corresponding edges
1199 BRepBuilderAPI_MakeWire aMakeWire;
1201 aMakeWire.Add( aBotEdge );
1202 thePrs.myInlet = aMakeWire.Edge();
1204 aMakeWire.Add( anEdgLeft );
1205 thePrs.myLeftBank = aMakeWire.Edge();
1207 aMakeWire.Add( aTopEdge );
1208 thePrs.myOutlet = aMakeWire.Edge();
1210 aMakeWire.Add( anEdgRight );
1211 thePrs.myRightBank = aMakeWire.Edge();
1213 TopoDS_Wire aSectProfileWire;
1214 if(aMakeWire.IsDone())
1215 aSectProfileWire = aMakeWire.Wire();
1217 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
1220 if( aMakeFace.IsDone() )
1221 aFace = aMakeFace.Face();
1223 TopoDS_Shape aPrs2D;
1225 if ( !theArrOf2DProfiles.IsNull() ) {
1227 aBB.MakeCompound(aCmp);
1228 aBB.Add(aCmp,aFace);
1229 for(int i=1;i <= theArrOf2DProfiles->Length(); i++)
1230 aBB.Add(aCmp, theArrOf2DProfiles->Value(i));
1239 thePrs.myPrs2D = aPrs2D;
1242 BRepTools::Write(aPrs2D, "str2d.brep");
1243 thePrs.myPrs2D = aPrs2D;