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 void HYDROData_Stream::SetLabel( const TDF_Label& theLabel )
109 HYDROData_NaturalObject::SetLabel( theLabel );
111 if( GetAltitudeObject().IsNull() )
113 Handle(HYDROData_Document) aDoc = HYDROData_Document::Document( myLab );
114 Handle(HYDROData_DTM) aDTM =
115 Handle(HYDROData_DTM)::DownCast( aDoc->CreateObject( KIND_DTM ) );
116 SetAltitudeObject( aDTM );
120 QStringList HYDROData_Stream::DumpToPython( const QString& thePyScriptPath,
121 MapOfTreatedObjects& theTreatedObjects ) const
123 QStringList aResList = dumpObjectCreation( theTreatedObjects );
124 QString aName = GetObjPyName();
126 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
127 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aHydAxis, "SetHydraulicAxis" );
129 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
130 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; ++i )
132 const Handle(HYDROData_Entity) aProfile = aSeqOfProfiles.Value( i );
133 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aProfile, "AddProfile" );
136 // Set bottom polyline if exists
137 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
138 if ( !aBottomPolyline.IsNull() ) {
139 setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aBottomPolyline, "SetBottomPolyline" );
142 QString aDDZs = QString::number( GetDDZ(), 'f', 3 );
143 QString aSSteps = QString::number( GetSpatialStep(), 'f', 3 );
144 aResList << QString( "%1.SetDDZ( %2 )" ).arg( aName ).arg( aDDZs );
145 aResList << QString( "%1.SetSpatialStep( %2 )" ).arg( aName ).arg( aSSteps );
147 aResList << QString( "" );
148 aResList << QString( "%1.Update()" ).arg( aName );
149 aResList << QString( "" );
154 HYDROData_SequenceOfObjects HYDROData_Stream::GetAllReferenceObjects() const
156 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
158 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
159 if ( !aHydAxis.IsNull() )
160 aResSeq.Append( aHydAxis );
162 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
163 aResSeq.Append( aSeqOfProfiles );
168 Handle(Geom_BSplineCurve) HYDROData_Stream::buildInterpolationCurve(
169 const Handle(TColgp_HArray1OfPnt)& theArrayOfPnt )
171 Handle(Geom_BSplineCurve) aBSpline;
172 GeomAPI_Interpolate anInterpolator (theArrayOfPnt, Standard_False, 1.0e-5);
173 anInterpolator.Perform() ;
174 if (anInterpolator.IsDone())
175 aBSpline = anInterpolator.Curve();
179 void HYDROData_Stream::Update()
181 updateProfilesOrder();
183 // Update bottom polyline if exists
184 const Handle(HYDROData_Polyline3D) aBottomPolyline = GetBottomPolyline();
185 if ( !aBottomPolyline.IsNull() ) {
186 if ( GenerateBottomPolyline() ) {
187 Handle(HYDROData_PolylineXY) aPolylineXY = aBottomPolyline->GetPolylineXY();
188 if ( !aPolylineXY.IsNull() ) {
189 aPolylineXY->Update();
191 aBottomPolyline->Update();
199 bool HYDROData_Stream::IsHas2dPrs() const
204 bool HYDROData_Stream::CreatePresentations( const Handle_HYDROData_DTM& theDTM,
205 PrsDefinition& thePrs )
207 if ( theDTM.IsNull() )
210 HYDROData_SequenceOfObjects profiles = theDTM->GetProfiles();
211 if( profiles.Length() < 2 )
214 TopTools_ListOfShape profiles3d;
217 HYDROData_SequenceOfObjects::Iterator anIter( profiles );
218 for (int i=1 ; anIter.More(); anIter.Next(),i++ )
220 Handle(HYDROData_Profile) aProfile =
221 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
223 if ( aProfile.IsNull() )
226 const TopoDS_Shape& aProfileShape = aProfile->GetShape3D();
227 profiles3d.Append( aProfileShape );
230 TopoDS_Edge aLeftBank, aRightBank;
231 theDTM->CreateBankShapes( aLeftBank, aRightBank );
232 return CreatePresentations( aLeftBank, aRightBank, profiles3d, thePrs );
235 void HYDROData_Stream::UpdatePrs()
237 HYDROData_NaturalObject::Update();
239 PrsDefinition aResultPrs;
240 if ( !CreatePresentations( DTM(), aResultPrs ) )
243 SetShape3D( aResultPrs.myPrs3D );
244 SetTopShape( aResultPrs.myPrs2D );
246 // Create the stream groups
247 QString aLeftGroupName = GetName() + "_Left_Bank";
249 Handle(HYDROData_ShapesGroup) aLeftGroup = createGroupObject();
250 aLeftGroup->SetName( aLeftGroupName );
251 aLeftGroup->AddShape( aResultPrs.myLeftBank );
253 QString aRightGroupName = GetName() + "_Right_Bank";
255 Handle(HYDROData_ShapesGroup) aRightGroup = createGroupObject();
256 aRightGroup->SetName( aRightGroupName );
257 aRightGroup->AddShape( aResultPrs.myRightBank );
259 QString anInGroupName = GetName() + "_Inlet";
261 Handle(HYDROData_ShapesGroup) anInGroup = createGroupObject();
262 anInGroup->SetName( anInGroupName );
263 anInGroup->AddShape( aResultPrs.myInlet );
265 QString anOutGroupName = GetName() + "_Outlet";
267 Handle(HYDROData_ShapesGroup) anOutGroup = createGroupObject();
268 anOutGroup->SetName( anOutGroupName );
269 anOutGroup->AddShape( aResultPrs.myOutlet );
272 QColor HYDROData_Stream::DefaultFillingColor() const
274 return QColor( Qt::green );
277 QColor HYDROData_Stream::DefaultBorderColor() const
279 return QColor( Qt::transparent );
282 bool HYDROData_Stream::IsValidAsAxis( const Handle(HYDROData_PolylineXY)& theHydAxis )
284 if ( theHydAxis.IsNull() )
287 TopoDS_Shape aHydraulicShape = theHydAxis->GetShape();
288 if ( aHydraulicShape.IsNull() ||
289 aHydraulicShape.ShapeType() != TopAbs_WIRE ||
290 BRep_Tool::IsClosed( aHydraulicShape ) )
291 return false; // The polyline must be a single not closed wire
296 TopoDS_Shape HYDROData_Stream::GetLeftShape() const
298 HYDROData_SequenceOfObjects aGroups = GetGroups();
299 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 1);
302 TopoDS_Shape HYDROData_Stream::GetRightShape() const
304 HYDROData_SequenceOfObjects aGroups = GetGroups();
305 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 2);
308 TopoDS_Shape HYDROData_Stream::GetInletShape() const
310 HYDROData_SequenceOfObjects aGroups = GetGroups();
311 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 3);
314 TopoDS_Shape HYDROData_Stream::GetOutletShape() const
316 HYDROData_SequenceOfObjects aGroups = GetGroups();
317 return HYDROData_Tool::getFirstShapeFromGroup( aGroups, 4);
320 Handle_HYDROData_DTM HYDROData_Stream::DTM() const
322 return Handle(HYDROData_DTM)::DownCast( GetAltitudeObject() );
325 double HYDROData_Stream::GetDDZ() const
327 return DTM()->GetDDZ();
330 void HYDROData_Stream::SetDDZ( double theDDZ )
332 DTM()->SetDDZ( theDDZ );
335 double HYDROData_Stream::GetSpatialStep() const
337 return DTM()->GetSpatialStep();
340 void HYDROData_Stream::SetSpatialStep( double theSpatialStep )
342 DTM()->SetSpatialStep( theSpatialStep );
345 bool HYDROData_Stream::SetHydraulicAxis( const Handle(HYDROData_PolylineXY)& theAxis )
347 if ( !IsValidAsAxis( theAxis ) )
350 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
351 if ( IsEqual( aPrevAxis, theAxis ) )
354 SetReferenceObject( theAxis, DataTag_HydraulicAxis );
356 // Update the order of profiles
357 updateProfilesOrder();
359 // Indicate model of the need to update the stream presentation
365 Handle(HYDROData_PolylineXY) HYDROData_Stream::GetHydraulicAxis() const
367 return Handle(HYDROData_PolylineXY)::DownCast(
368 GetReferenceObject( DataTag_HydraulicAxis ) );
371 void HYDROData_Stream::RemoveHydraulicAxis()
373 Handle(HYDROData_PolylineXY) aPrevAxis = GetHydraulicAxis();
374 if ( aPrevAxis.IsNull() )
377 ClearReferenceObjects( DataTag_HydraulicAxis );
379 // We remove the reference profiles
382 // Indicate model of the need to update the stream presentation
386 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_Profile)& theProfile,
387 const TopoDS_Face& thePlane,
388 Standard_Real& theOutPar ) const
390 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
391 return HasIntersection( aHydAxis, theProfile, thePlane, theOutPar );
394 bool HYDROData_Stream::HasIntersection( const Handle(HYDROData_PolylineXY)& theHydAxis,
395 const Handle(HYDROData_Profile)& theProfile,
396 const TopoDS_Face& thePlane,
397 Standard_Real& theOutPar )
399 if ( theProfile.IsNull() || !IsValidAsAxis( theHydAxis ) )
402 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() ); //guide line
403 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
404 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
407 BRepProj_Projection aProjector (aProfileWire, thePlane, gp::OZ().Direction());
408 if(!aProjector.IsDone())
410 TopoDS_Shape aPrjProfile = aProjector.Shape();
411 if(aPrjProfile.IsNull())
413 TopoDS_Vertex aV1, aV2;
414 if(aPrjProfile.ShapeType() == TopAbs_EDGE)
415 TopExp::Vertices(TopoDS::Edge(aPrjProfile), aV1, aV2);
416 else if(aPrjProfile.ShapeType() == TopAbs_WIRE)
417 TopExp::Vertices(TopoDS::Wire(aPrjProfile), aV1, aV2);
418 else if(aPrjProfile.ShapeType() == TopAbs_COMPOUND){
419 TopExp_Explorer anExp(aPrjProfile, TopAbs_WIRE);
421 TopExp::Vertices(TopoDS::Wire(anExp.Current()), aV1, aV2);
423 anExp.Init(aPrjProfile, TopAbs_EDGE);
425 TopExp::Vertices(TopoDS::Edge(anExp.Current()), aV1, aV2);
429 if(aV1.IsNull() || aV2.IsNull())
431 gp_Pnt aPnt1 = BRep_Tool::Pnt(aV1);
432 gp_Pnt aPnt2 = BRep_Tool::Pnt(aV2);
435 BRepBuilderAPI_MakeEdge aMk(aPnt1, aPnt2);
438 const TopoDS_Edge& anEdg2 = aMk.Edge();//Section edge
439 Standard_Integer aNum(0);
441 TopExp_Explorer anExplo(aHydraulicWire, TopAbs_EDGE);
442 for(;anExplo.More();anExplo.Next()) aNum++;
443 // check for self-intersection
444 const Standard_Real SquareTolerance = Precision::Confusion()*Precision::Confusion();
445 Standard_Boolean hasInt(false);
446 Standard_Real aSqDist(DBL_MAX);
447 Standard_Integer anIndx(0);
448 BRepExtrema_ExtCC aCC;
449 aCC.Initialize(anEdg2);
451 anExplo.Init(aHydraulicWire, TopAbs_EDGE);
452 for(Standard_Integer j=1;anExplo.More();anExplo.Next(),j++) {
453 const TopoDS_Edge& anEdg1 = TopoDS::Edge(anExplo.Current());
456 Standard_Boolean hasSol(false);
460 for(Standard_Integer i=1; i<= aCC.NbExt();i++)
461 if(aCC.SquareDistance(i) < aSqDist) {
462 aSqDist = aCC.SquareDistance(i);
468 if(aSqDist <= SquareTolerance) { // hasInt
469 const gp_Pnt& aPnt = aCC.PointOnE1(anIndx);
471 TopExp::Vertices(anEdg1, aV1, aV2, Standard_True);
472 theOutPar += BRep_Tool::Pnt(aV1).Distance(aPnt);
474 Standard_Real aPar = aCC.ParameterOnE1(anIndx);
482 TopExp::Vertices(anEdg1, aV1, aV2);
483 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
486 } else if(aNum > 1) {
487 TopExp::Vertices(anEdg1, aV1, aV2);
488 theOutPar += BRep_Tool::Pnt(aV1).Distance(BRep_Tool::Pnt(aV2));
496 bool HYDROData_Stream::AddProfile( const Handle(HYDROData_Profile)& theProfile )
498 if ( theProfile.IsNull() )
501 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
502 if ( aHydAxis.IsNull() )
506 if(!BuildFace(aHydAxis, aPlane))
509 Standard_Real aPar(.0);
510 if ( HasReference( theProfile, DataTag_Profile ) || !HasIntersection( theProfile, aPlane, aPar ) )
511 return false; // Object is already in reference list or it has no intersection
513 int aProfileIndex = insertParameter( aPar );
514 insertProfileInToOrder( theProfile, aProfileIndex );
516 // Indicate model of the need to update the stream presentation
522 bool HYDROData_Stream::SetProfiles( const HYDROData_SequenceOfObjects& theProfiles,
523 const bool& theIsToOrder )
527 for ( int i = 1; i <= theProfiles.Length(); ++i )
529 Handle(HYDROData_Profile) aProfile =
530 Handle(HYDROData_Profile)::DownCast( theProfiles.Value( i ) );
531 if ( aProfile.IsNull() )
534 if ( !AddProfile( aProfile ) )
536 DTM()->SetProfiles( HYDROData_SequenceOfObjects() );
541 else // Just store the sequence of objects as is
543 bool anIsToUpdate = true;
545 HYDROData_SequenceOfObjects anOldProfiles = GetProfiles();
546 if ( anOldProfiles.Length() == theProfiles.Length() )
548 anIsToUpdate = false;
550 for ( int i = 1; i <= theProfiles.Length(); ++i )
552 Handle(HYDROData_Entity) anOldProfile = anOldProfiles.Value( i );
553 Handle(HYDROData_Entity) aNewProfile = theProfiles.Value( i );
554 if ( !IsEqual( anOldProfile, aNewProfile ) )
562 SetReferenceObjects( theProfiles, DataTag_Profile );
568 DTM()->SetProfiles( GetProfiles() );
572 HYDROData_SequenceOfObjects HYDROData_Stream::GetProfiles() const
574 return GetReferenceObjects( DataTag_Profile );
577 bool HYDROData_Stream::RemoveProfile( const Handle(HYDROData_Profile)& theProfile )
579 if ( theProfile.IsNull() )
582 int aProfileIndex = -1;
584 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
585 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
586 for ( int i = 0 ; anIter.More(); anIter.Next(), ++i )
588 Handle(HYDROData_Profile) aProfile =
589 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
590 if ( aProfile.IsNull() )
593 if ( IsEqual( theProfile, aProfile ) )
600 if ( aProfileIndex == -1 )
603 RemoveReferenceObject( theProfile->Label(), DataTag_Profile );
605 // Remove parameter for removed profile
606 removeParameter( aProfileIndex );
608 // Indicate model of the need to update the stream presentation
614 void HYDROData_Stream::RemoveProfiles()
616 ClearReferenceObjects( DataTag_Profile );
618 // Remove the parameters array
619 removeParametersArray();
621 // Indicate model of the need to update the stream presentation
625 void HYDROData_Stream::insertProfileInToOrder( const Handle(HYDROData_Profile)& theProfile,
626 const int theBeforeIndex )
628 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
629 if ( theProfile.IsNull() || aHydAxis.IsNull() )
632 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
633 TopoDS_Wire aProfileWire = TopoDS::Wire( theProfile->GetTopShape() );
634 if ( aHydraulicWire.IsNull() || aProfileWire.IsNull() )
637 if ( theBeforeIndex == -1 )
638 AddReferenceObject( theProfile, DataTag_Profile );
640 InsertReferenceObject( theProfile, DataTag_Profile, theBeforeIndex );
643 bool HYDROData_Stream::BuildFace( const Handle(HYDROData_PolylineXY)& theHydAxis,
644 TopoDS_Face& thePlane )
646 if ( !IsValidAsAxis( theHydAxis ) )
649 TopoDS_Wire aHydraulicWire = TopoDS::Wire( theHydAxis->GetShape() );
651 gp_Ax2 aX2(gp::XOY());
655 BRepBndLib::Add(aHydraulicWire,B);
656 Standard_Real axmin,aymin,azmin,axmax,aymax,azmax;
657 B.Get(axmin,aymin,azmin,axmax,aymax,azmax);
658 BRepBuilderAPI_MakeFace aMkr(aPln, axmin-500., axmax+500., aymin-500., aymax+500.); // to be tuned later according max/ Profile deviation
659 if(!aMkr.IsDone() || aMkr.Shape().IsNull()) return false;
660 thePlane = TopoDS::Face(aMkr.Shape());
664 void HYDROData_Stream::updateProfilesOrder()
666 HYDROData_SequenceOfObjects aRefProfiles = GetProfiles();
667 if ( aRefProfiles.IsEmpty() )
670 // At first we remove all profiles from order
673 Handle(HYDROData_PolylineXY) aHydAxis = GetHydraulicAxis();
674 if ( aHydAxis.IsNull() )
678 if ( !BuildFace( aHydAxis, aPlane ) )
681 Standard_Real aPar( .0 );
685 TopoDS_Compound aCmp;
686 aBB.MakeCompound(aCmp);
689 HYDROData_DataMapOfRealOfHDProfile aDM;
690 TColStd_ListOfReal aList;
691 HYDROData_SequenceOfObjects::Iterator anIter( aRefProfiles );
692 for (int i = 1 ; anIter.More(); anIter.Next(), i++ )
694 Handle(HYDROData_Profile) aProfile =
695 Handle(HYDROData_Profile)::DownCast( anIter.Value() );
697 TopoDS_Wire aProfileWire = TopoDS::Wire( aProfile->GetTopShape() );
698 aBB.Add( aCmp, aProfileWire );
700 if ( aProfile.IsNull() || !HasIntersection( aProfile, aPlane, aPar ) )
703 aDM.Bind( aPar, aProfile );
704 aList.Append( aPar );
707 if ( aList.IsEmpty() )
710 TColStd_Array1OfReal anArr( 1, aList.Extent() );
712 TColStd_ListIteratorOfListOfReal it( aList );
713 for ( int j = 1; it.More(); it.Next(), j++ )
714 anArr( j ) = it.Value();
717 if ( aList.Extent() > 1 )
719 TCollection_CompareOfReal Compar;
720 SortTools_QuickSortOfReal::Sort( anArr, Compar );
722 for (int j = 1; j <= anArr.Length(); j++) {
723 const Standard_Real aKey = anArr(j);
724 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
725 insertProfileInToOrder( aProfile );
727 } else if ( aList.Extent() == 1 ) {
728 const Standard_Real aKey = aList.Last();
729 const Handle(HYDROData_Profile)& aProfile = aDM.Find(aKey);
730 insertProfileInToOrder( aProfile );
733 setParametersArray( anArr );
736 TopoDS_Wire aHydraulicWire = TopoDS::Wire( aHydAxis->GetShape() );
737 BRepTools::Write(aHydraulicWire, "Path.brep");
738 BRepTools::Write(aCmp, "Prof.brep");
742 ObjectKind HYDROData_Stream::getAltitudeObjectType() const
747 void HYDROData_Stream::setParametersArray( const TColStd_Array1OfReal& theArray )
749 if ( theArray.Length() == 0 )
751 removeParametersArray();
755 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray );
757 Handle(TDataStd_RealArray) aParamsArray =
758 TDataStd_RealArray::Set( aLabel, theArray.Lower(), theArray.Upper() );
760 for ( int i = theArray.Lower(), n = theArray.Upper(); i <= n; ++i )
762 const Standard_Real& aParam = theArray( i );
763 aParamsArray->SetValue( i, aParam );
767 TColStd_Array1OfReal* HYDROData_Stream::getParametersArray() const
769 TColStd_Array1OfReal* anArray = NULL;
771 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
772 if ( !aLabel.IsNull() )
774 Handle(TDataStd_RealArray) aParamsArray;
775 if ( aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
777 anArray = new TColStd_Array1OfReal( aParamsArray->Lower(), aParamsArray->Upper() );
778 for ( int i = aParamsArray->Lower(), n = aParamsArray->Upper(); i <= n; ++i )
780 const Standard_Real& aParam = aParamsArray->Value( i );
781 anArray->SetValue( i, aParam );
789 void HYDROData_Stream::removeParametersArray()
791 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
792 if ( !aLabel.IsNull() )
793 aLabel.ForgetAllAttributes();
796 int HYDROData_Stream::insertParameter( const Standard_Real& theParam )
800 TColStd_Array1OfReal* anArr = getParametersArray();
805 TColStd_Array1OfReal aNewArr( anArr->Lower(), anArr->Upper() + 1 );
807 bool isInserted = false;
808 for ( int i = anArr->Lower(), j = i, n = anArr->Upper(); i <= n; ++i, ++j )
810 const Standard_Real& aStoredParam = anArr->Value( i );
813 if ( theParam > aStoredParam )
819 aNewArr( j ) = theParam;
825 aNewArr( j ) = aStoredParam;
831 aNewArr( aNewArr.Upper() ) = theParam;
834 setParametersArray( aNewArr );
839 TColStd_Array1OfReal aNewArr( 1, 1 );
840 aNewArr.SetValue( 1, theParam );
841 setParametersArray( aNewArr );
847 void HYDROData_Stream::removeParameter( const int& theIndex )
849 TDF_Label aLabel = myLab.FindChild( DataTag_ParamsArray, false );
850 if ( aLabel.IsNull() )
853 Handle(TDataStd_RealArray) aParamsArray;
854 if ( !aLabel.FindAttribute( TDataStd_RealArray::GetID(), aParamsArray ) )
857 if ( aParamsArray->Length() == 1 )
859 removeParametersArray();
863 TColStd_Array1OfReal aNewArr( aParamsArray->Lower(), aParamsArray->Upper() - 1 );
865 for ( int i = aParamsArray->Lower(), j = i, k = 0, n = aParamsArray->Upper(); i <= n; ++i, ++k )
867 const Standard_Real& aStoredParam = aParamsArray->Value( i );
871 aNewArr.SetValue( j, aStoredParam );
875 setParametersArray( aNewArr );
878 bool HYDROData_Stream::GenerateBottomPolyline()
881 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
882 if ( aDocument.IsNull() ) {
886 // Collect bottom points ( one bottom point from each profile of the stream )
887 HYDROData_Profile::ProfilePoints aBottomPoints;
889 HYDROData_SequenceOfObjects aSeqOfProfiles = GetProfiles();
890 for ( int i = 1, aNb = aSeqOfProfiles.Size(); i <= aNb; i++ ) {
891 const Handle(HYDROData_Profile) aProfile =
892 Handle(HYDROData_Profile)::DownCast( aSeqOfProfiles.Value( i ) );
893 if ( aProfile.IsNull() ) {
897 aBottomPoints.Append( aProfile->GetBottomPoint() );
900 int aNbBottomPoints = aBottomPoints.Size();
902 if ( aNbBottomPoints < 2 ) {
906 // Create bottom polyline object if the stream doesn't contain it yet
907 Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
908 if ( aBottom.IsNull() ) {
909 aBottom = Handle(HYDROData_Polyline3D)::DownCast( aDocument->CreateObject( KIND_POLYLINE ) );
910 QString aBaseName = GetName() + "_bottom";
911 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
912 aBottom->SetName( aName );
914 SetReferenceObject( aBottom, DataTag_BottomPolyline );
917 // Create 2D polyline if the bottom polyline doesn't contain it yet
918 Handle(HYDROData_PolylineXY) aPolylineXY = aBottom->GetPolylineXY();
919 if ( aPolylineXY.IsNull() ) {
920 aPolylineXY = Handle(HYDROData_PolylineXY)::DownCast( aDocument->CreateObject( KIND_POLYLINEXY ) );
921 QString aBaseName = GetName() + "_bottom_2d";
922 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
923 aPolylineXY->SetName( aName );
924 aBottom->SetPolylineXY( aPolylineXY, false );
927 aPolylineXY->RemoveSections();
928 aPolylineXY->AddSection( "", HYDROData_PolylineXY::SECTION_SPLINE, false );
930 // Create profile if the bottom polyline doesn't contain it yet
931 Handle(HYDROData_ProfileUZ) aProfileUZ = aBottom->GetProfileUZ();
932 if ( aProfileUZ.IsNull() ) {
933 Handle(HYDROData_Profile) aProfile =
934 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
935 QString aBaseName = GetName() + "_bottom_profile";
936 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName, QStringList(), true );
937 aProfile->SetName( aName );
938 aProfileUZ = aProfile->GetProfileUZ( true );
939 aBottom->SetProfileUZ( aProfileUZ );
942 aProfileUZ->RemoveSection( 0 );
944 aProfileUZ->CalculateAndAddPoints(aBottomPoints, aPolylineXY);
949 Handle(HYDROData_Polyline3D) HYDROData_Stream::GetBottomPolyline() const
951 return Handle(HYDROData_Polyline3D)::DownCast(
952 GetReferenceObject( DataTag_BottomPolyline ) );
955 bool HYDROData_Stream::SetBottomPolyline( const Handle(HYDROData_Polyline3D)& theBottom )
957 if ( theBottom.IsNull() ) {
961 SetReferenceObject( theBottom, DataTag_BottomPolyline );
966 bool HYDROData_Stream::Interpolate( HYDROData_IProfilesInterpolator* theInterpolator )
969 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
970 if ( aDocument.IsNull() ) {
974 if ( theInterpolator->GetCalculatedProfilesNumber() < 1 ) {
975 theInterpolator->Calculate();
978 if ( theInterpolator->GetErrorCode() != OK ) {
984 for ( int aProfileInd = 0; aProfileInd < theInterpolator->GetCalculatedProfilesNumber(); aProfileInd++ ) {
985 // Get calculated point coordinates
986 HYDROData_Profile::ProfilePoints aResultPoints = theInterpolator->GetResultProfilePoints( aProfileInd );
987 if ( aResultPoints.IsEmpty() ) {
992 // Create profile object
993 Handle(HYDROData_Profile) aProfile =
994 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
995 QString aBaseName = GetName() + "_interp_profile";
996 QString aName = HYDROData_Tool::GenerateObjectName( aDocument, aBaseName );
997 aProfile->SetName( aName );
999 // Fill the profile with points
1000 aProfile->SetProfilePoints( aResultPoints );
1002 // Add profile to the stream
1003 bool isAdded = AddProfile( aProfile );
1017 void HYDROData_Stream::CopyTo( const Handle(HYDROData_Entity)& theDestination,
1018 bool isGenerateNewName ) const
1021 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
1022 if ( aDocument.IsNull() ) {
1027 HYDROData_Entity::CopyTo( theDestination, isGenerateNewName );
1029 Handle(HYDROData_Stream) aStreamCopy =
1030 Handle(HYDROData_Stream)::DownCast( theDestination );
1032 // Copy bottom polyline if exists
1033 if ( !aStreamCopy.IsNull() ) {
1034 const Handle(HYDROData_Polyline3D) aBottom = GetBottomPolyline();
1035 if ( !aBottom.IsNull() ) {
1036 aStreamCopy->ClearReferenceObjects( DataTag_BottomPolyline );
1037 aStreamCopy->GenerateBottomPolyline();
1038 const Handle(HYDROData_Polyline3D) aBottomCopy = aStreamCopy->GetBottomPolyline();
1039 if ( !aBottomCopy.IsNull() && !aBottomCopy->GetPolylineXY().IsNull() ) {
1040 aBottomCopy->GetPolylineXY()->Update();
1041 aBottomCopy->Update();
1047 bool HYDROData_Stream::CreatePresentations( const TopoDS_Edge& theLeftBank,
1048 const TopoDS_Edge& theRightBank,
1049 const TopTools_ListOfShape& theProfiles3d,
1050 PrsDefinition& thePrs )
1053 /*if ( theArrayOfFPnt.IsNull() || theArrayOfLPnt.IsNull() || theArrOfProfiles.IsNull() ) {
1057 if ( theArrayOfFPnt->Length() != theArrayOfLPnt->Length() ) {
1061 // Construct of the 3D presentation
1062 Handle(Geom_BSplineCurve) aBSpline = buildInterpolationCurve (theArrayOfFPnt);
1063 if(aBSpline.IsNull())
1066 TopoDS_Edge anEdgLeft, anEdgRight;
1068 BRepBuilderAPI_MakeEdge aMakeEdge(aBSpline);
1069 if(aMakeEdge.IsDone())
1070 anEdgLeft = aMakeEdge.Edge();
1072 if(anEdgLeft.IsNull())
1076 aBSpline = buildInterpolationCurve (theArrayOfLPnt);
1077 if(aBSpline.IsNull())
1080 aMakeEdge.Init(aBSpline);
1081 if(aMakeEdge.IsDone())
1082 anEdgRight = aMakeEdge.Edge();
1084 if(anEdgRight.IsNull())
1088 TopoDS_Compound aCmp;
1089 aBB.MakeCompound(aCmp);
1090 for (int i=1 ; i < theArrOfProfiles->Length() +1; i++ )
1091 aBB.Add(aCmp, theArrOfProfiles->Value(i));
1093 aBB.Add(aCmp,anEdgLeft);
1094 aBB.Add(aCmp,anEdgRight);
1095 BRepCheck_Analyzer aCh(aCmp);
1097 thePrs.myPrs3D = aCmp;
1100 BRepTools::Write(aCmp, "str3d.brep");
1101 thePrs.myPrs3D = aCmp;
1105 // Construct the top presentation
1106 int aNbPoints = theArrayOfFPnt->Length();
1107 Handle(TColgp_HArray1OfPnt) anArrayOfFPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1108 Handle(TColgp_HArray1OfPnt) anArrayOfLPnt = new TColgp_HArray1OfPnt(1, aNbPoints);
1109 for( int i=1; i <= aNbPoints; i++ ) {
1110 gp_Pnt aPnt = theArrayOfFPnt->Value(i);
1111 aPnt.SetZ(.0); // make 2d
1112 anArrayOfFPnt->SetValue(i, aPnt);
1113 aPnt = theArrayOfLPnt->Value(i);
1115 anArrayOfLPnt->SetValue(i, aPnt);
1119 aBSpline = buildInterpolationCurve (anArrayOfFPnt);
1120 if(aBSpline.IsNull())
1123 aMakeEdge.Init(aBSpline);
1124 if(aMakeEdge.IsDone())
1125 anEdgLeft = aMakeEdge.Edge();
1128 aBSpline = buildInterpolationCurve (anArrayOfLPnt);
1129 if(aBSpline.IsNull())
1132 aMakeEdge.Init(aBSpline);
1133 if(aMakeEdge.IsDone())
1134 anEdgRight = aMakeEdge.Edge();
1135 if(anEdgRight.IsNull())
1138 BRepBuilderAPI_MakeEdge aMakeEdge2(anArrayOfFPnt->Value(1),anArrayOfLPnt->Value(1));
1139 TopoDS_Edge aBotEdge, aTopEdge;
1140 if(aMakeEdge2.IsDone())
1141 aBotEdge = aMakeEdge2.Edge();
1143 BRepBuilderAPI_MakeEdge aMakeEdge3(anArrayOfFPnt->Value(anArrayOfFPnt->Length()),anArrayOfLPnt->Value(anArrayOfLPnt->Length()));
1144 if(aMakeEdge3.IsDone())
1145 aTopEdge = aMakeEdge3.Edge();
1147 // Make wire for 2D presentation with updating of corresponding edges
1148 BRepBuilderAPI_MakeWire aMakeWire;
1150 aMakeWire.Add( aBotEdge );
1151 thePrs.myInlet = aMakeWire.Edge();
1153 aMakeWire.Add( anEdgLeft );
1154 thePrs.myLeftBank = aMakeWire.Edge();
1156 aMakeWire.Add( aTopEdge );
1157 thePrs.myOutlet = aMakeWire.Edge();
1159 aMakeWire.Add( anEdgRight );
1160 thePrs.myRightBank = aMakeWire.Edge();
1162 TopoDS_Wire aSectProfileWire;
1163 if(aMakeWire.IsDone())
1164 aSectProfileWire = aMakeWire.Wire();
1166 BRepBuilderAPI_MakeFace aMakeFace( aSectProfileWire, Standard_True );
1169 if( aMakeFace.IsDone() )
1170 aFace = aMakeFace.Face();
1172 TopoDS_Shape aPrs2D;
1174 if ( !theArrOf2DProfiles.IsNull() ) {
1176 aBB.MakeCompound(aCmp);
1177 aBB.Add(aCmp,aFace);
1178 for(int i=1;i <= theArrOf2DProfiles->Length(); i++)
1179 aBB.Add(aCmp, theArrOf2DProfiles->Value(i));
1188 thePrs.myPrs2D = aPrs2D;
1191 BRepTools::Write(aPrs2D, "str2d.brep");
1192 thePrs.myPrs2D = aPrs2D;