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 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
58 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
63 void HYDROData_Polyline3D::Update()
65 HYDROData_Object::Update();
67 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
68 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
69 if ( aPolylineXY.IsNull() || aProfileUZ.IsNull() )
72 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
73 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
74 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
75 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
76 if ( aPolylinePoints.IsEmpty() || aProfilePoints.IsEmpty() )
79 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
80 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
82 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
83 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
85 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
86 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
88 NCollection_Sequence<Polyline3DPoint> aResPoints;
90 // Add first point as is
91 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
93 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
95 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
97 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
99 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
100 double aDepth = aProfileUZ->GetDepthFromDistance( aParLen );
102 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
103 aResPoints.Append( aCompPoint );
106 // Add last point as is
107 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
109 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
110 SetTopShape( aResWire );
111 SetShape3D( aResWire );
114 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline )
116 if ( thePolyline.IsNull() )
119 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
120 if ( IsEqual( aPrevPolyline, thePolyline ) )
123 SetReferenceObject( thePolyline, DataTag_PolylineXY );
125 // Indicate model of the need to update the polyline presentation
131 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
133 return Handle(HYDROData_PolylineXY)::DownCast(
134 GetReferenceObject( DataTag_PolylineXY ) );
137 void HYDROData_Polyline3D::RemovePolylineXY()
139 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
140 if ( aPrevPolyline.IsNull() )
143 ClearReferenceObjects( DataTag_PolylineXY );
145 // Indicate model of the need to update the polyline presentation
149 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
151 if ( theProfile.IsNull() )
154 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
155 if ( IsEqual( aPrevProfile, theProfile ) )
158 SetReferenceObject( theProfile, DataTag_ProfileUZ );
160 // Indicate model of the need to update the polyline presentation
166 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
168 return Handle(HYDROData_ProfileUZ)::DownCast(
169 GetReferenceObject( DataTag_ProfileUZ ) );
172 void HYDROData_Polyline3D::RemoveProfileUZ()
174 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
175 if ( aPrevProfile.IsNull() )
178 ClearReferenceObjects( DataTag_ProfileUZ );
180 // Indicate model of the need to update the polyline presentation