2 #include "HYDROData_Polyline3D.h"
4 #include "HYDROData_Bathymetry.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_PolylineXY.h"
7 #include "HYDROData_ProfileUZ.h"
9 #include <gp_Pnt2d.hxx>
14 #include <TopoDS_Wire.hxx>
17 #include <QStringList>
19 #define PYTHON_POLYLINE_ID "KIND_POLYLINE"
21 IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object)
22 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object)
25 HYDROData_Polyline3D::HYDROData_Polyline3D()
30 HYDROData_Polyline3D::~HYDROData_Polyline3D()
34 QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
38 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
39 if ( aDocument.IsNull() )
42 QString aDocName = aDocument->GetDocPyName();
43 QString aPolylineName = GetName();
45 aResList << QString( "%1 = %2.CreateObject( %3 );" )
46 .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINE_ID );
47 aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
48 aResList << QString( "" );
55 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
57 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
59 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
60 if ( !aPolylineXY.IsNull() )
61 aResSeq.Append( aPolylineXY );
63 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
64 if ( !aProfileUZ.IsNull() )
65 aResSeq.Append( aProfileUZ );
70 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
75 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
80 HYDROData_IPolyline::PointsList generateProfileUZPoints(
81 const Handle(HYDROData_PolylineXY)& thePolyline,
82 const Handle(HYDROData_Bathymetry)& theBathymetry )
84 HYDROData_IPolyline::PointsList aPointsList;
85 if ( thePolyline.IsNull() || theBathymetry.IsNull() )
88 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
89 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
90 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
91 if ( aPolylinePoints.IsEmpty() )
94 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
96 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
98 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
99 double aPointDepth = theBathymetry->GetAltitudeForPoint( aSectPoint );
101 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
102 aPointsList.Append( anAltitudePoint );
108 void HYDROData_Polyline3D::Update()
110 HYDROData_Object::Update();
112 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
113 if ( aPolylineXY.IsNull() )
116 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
117 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
118 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
119 if ( aPolylinePoints.IsEmpty() )
122 HYDROData_IPolyline::PointsList aProfilePoints;
124 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
125 Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry();
127 if ( !aProfileUZ.IsNull() )
129 aProfilePoints = aProfileUZ->GetPoints();
131 else if ( !aBathymetry.IsNull() )
133 aProfilePoints = generateProfileUZPoints( aPolylineXY, aBathymetry );
136 if ( aProfilePoints.IsEmpty() )
139 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
140 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
142 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
143 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
145 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
146 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
148 NCollection_Sequence<Polyline3DPoint> aResPoints;
150 // Add first point as is
151 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
153 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
155 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
157 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
159 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
160 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
162 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
163 aResPoints.Append( aCompPoint );
166 // Add last point as is
167 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
169 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
170 SetTopShape( aResWire );
171 SetShape3D( aResWire );
174 QColor HYDROData_Polyline3D::DefaultFillingColor()
176 return QColor( Qt::transparent );
179 QColor HYDROData_Polyline3D::DefaultBorderColor()
181 return QColor( Qt::red );
184 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
186 return DefaultFillingColor();
189 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
191 return DefaultBorderColor();
194 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline )
196 if ( thePolyline.IsNull() )
199 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
200 if ( IsEqual( aPrevPolyline, thePolyline ) )
203 SetReferenceObject( thePolyline, DataTag_PolylineXY );
205 // Indicate model of the need to update the polyline presentation
211 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
213 return Handle(HYDROData_PolylineXY)::DownCast(
214 GetReferenceObject( DataTag_PolylineXY ) );
217 void HYDROData_Polyline3D::RemovePolylineXY()
219 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
220 if ( aPrevPolyline.IsNull() )
223 ClearReferenceObjects( DataTag_PolylineXY );
225 // Indicate model of the need to update the polyline presentation
229 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
231 if ( theProfile.IsNull() )
234 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
235 if ( IsEqual( aPrevProfile, theProfile ) )
238 SetReferenceObject( theProfile, DataTag_ProfileUZ );
240 // Remove the bathymetry, because one altitude object can be presented at time
243 // Indicate model of the need to update the polyline presentation
249 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
251 return Handle(HYDROData_ProfileUZ)::DownCast(
252 GetReferenceObject( DataTag_ProfileUZ ) );
255 void HYDROData_Polyline3D::RemoveProfileUZ()
257 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
258 if ( aPrevProfile.IsNull() )
261 ClearReferenceObjects( DataTag_ProfileUZ );
263 // Indicate model of the need to update the polyline presentation
268 bool HYDROData_Polyline3D::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
270 if ( !HYDROData_Object::SetBathymetry( theBathymetry ) )
273 // Remove the u,z profile, because one altitude object can be presented at time