2 #include "HYDROData_Polyline3D.h"
4 #include "HYDROData_Document.h"
5 #include "HYDROData_PolylineXY.h"
6 #include "HYDROData_ProfileUZ.h"
8 #include <gp_Pnt2d.hxx>
13 #include <TopoDS_Wire.hxx>
15 #include <QStringList>
17 #define PYTHON_POLYLINE_ID "KIND_POLYLINE"
19 IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object)
20 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object)
23 HYDROData_Polyline3D::HYDROData_Polyline3D()
28 HYDROData_Polyline3D::~HYDROData_Polyline3D()
32 QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
36 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
37 if ( aDocument.IsNull() )
40 QString aDocName = aDocument->GetDocPyName();
41 QString aPolylineName = GetName();
43 aResList << QString( "%1 = %2.CreateObject( %3 );" )
44 .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINE_ID );
45 aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
46 aResList << QString( "" );
53 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
55 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
57 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
58 if ( !aPolylineXY.IsNull() )
59 aResSeq.Append( aPolylineXY );
61 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
62 if ( !aProfileUZ.IsNull() )
63 aResSeq.Append( aProfileUZ );
68 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
73 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
78 void HYDROData_Polyline3D::Update()
80 HYDROData_Object::Update();
82 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
83 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
84 if ( aPolylineXY.IsNull() || aProfileUZ.IsNull() )
87 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
88 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
89 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
90 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
91 if ( aPolylinePoints.IsEmpty() || aProfilePoints.IsEmpty() )
94 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
95 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
97 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
98 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
100 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
101 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
103 NCollection_Sequence<Polyline3DPoint> aResPoints;
105 // Add first point as is
106 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
108 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
110 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
112 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
114 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
115 double aDepth = aProfileUZ->GetDepthFromDistance( aParLen );
117 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
118 aResPoints.Append( aCompPoint );
121 // Add last point as is
122 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
124 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
125 SetTopShape( aResWire );
126 SetShape3D( aResWire );
129 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline )
131 if ( thePolyline.IsNull() )
134 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
135 if ( IsEqual( aPrevPolyline, thePolyline ) )
138 SetReferenceObject( thePolyline, DataTag_PolylineXY );
140 // Indicate model of the need to update the polyline presentation
146 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
148 return Handle(HYDROData_PolylineXY)::DownCast(
149 GetReferenceObject( DataTag_PolylineXY ) );
152 void HYDROData_Polyline3D::RemovePolylineXY()
154 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
155 if ( aPrevPolyline.IsNull() )
158 ClearReferenceObjects( DataTag_PolylineXY );
160 // Indicate model of the need to update the polyline presentation
164 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
166 if ( theProfile.IsNull() )
169 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
170 if ( IsEqual( aPrevProfile, theProfile ) )
173 SetReferenceObject( theProfile, DataTag_ProfileUZ );
175 // Indicate model of the need to update the polyline presentation
181 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
183 return Handle(HYDROData_ProfileUZ)::DownCast(
184 GetReferenceObject( DataTag_ProfileUZ ) );
187 void HYDROData_Polyline3D::RemoveProfileUZ()
189 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
190 if ( aPrevProfile.IsNull() )
193 ClearReferenceObjects( DataTag_ProfileUZ );
195 // Indicate model of the need to update the polyline presentation