2 #include "HYDROData_Polyline3D.h"
4 #include "HYDROData_IAltitudeObject.h"
5 #include "HYDROData_Document.h"
6 #include "HYDROData_PolylineXY.h"
7 #include "HYDROData_Profile.h"
8 #include "HYDROData_ProfileUZ.h"
9 #include "HYDROData_Tool.h"
11 #include <gp_Pnt2d.hxx>
16 #include <TopoDS_Wire.hxx>
19 #include <QStringList>
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
36 QStringList aResList = dumpObjectCreation( theTreatedObjects );
37 QString aName = GetObjPyName();
39 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolylineXY();
40 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" );
42 Handle(HYDROData_ProfileUZ) aRefProfile = GetProfileUZ();
43 setPythonReferenceObject( theTreatedObjects, aResList, aRefProfile, "SetProfileUZ" );
45 Handle(HYDROData_IAltitudeObject) aRefBathymetry = GetAltitudeObject();
46 setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" );
48 aResList << QString( "" );
49 aResList << QString( "%1.Update();" ).arg( aName );
50 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 );
67 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
68 if ( !aChildProfileUZ.IsNull() )
69 aResSeq.Append( aChildProfileUZ );
74 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
79 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
84 void HYDROData_Polyline3D::Update()
86 HYDROData_Object::Update();
88 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
89 if ( aPolylineXY.IsNull() )
92 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
93 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
94 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
95 if ( aPolylinePoints.IsEmpty() )
98 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
100 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
101 if ( !anAltitude.IsNull() )
102 aProfileUZ = GetChildProfileUZ();
104 if ( aProfileUZ.IsNull() )
107 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
108 if ( aProfilePoints.IsEmpty() )
111 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
112 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
114 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
115 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
117 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
118 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
120 NCollection_Sequence<Polyline3DPoint> aResPoints;
122 // Add first point as is
123 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
125 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
127 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
129 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
131 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
132 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
134 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
135 aResPoints.Append( aCompPoint );
138 // Add last point as is
139 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
141 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
142 SetTopShape( aResWire );
143 SetShape3D( aResWire );
146 QColor HYDROData_Polyline3D::DefaultFillingColor()
148 return QColor( Qt::transparent );
151 QColor HYDROData_Polyline3D::DefaultBorderColor()
153 return QColor( Qt::red );
156 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
158 return DefaultFillingColor();
161 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
163 return DefaultBorderColor();
166 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
167 const bool theIsUpdateProfile )
169 if ( thePolyline.IsNull() )
172 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
173 if ( IsEqual( aPrevPolyline, thePolyline ) )
176 SetReferenceObject( thePolyline, DataTag_PolylineXY );
178 // Update the child profile object
179 if ( theIsUpdateProfile )
180 updateChildProfilePoints();
182 // Indicate model of the need to update the polyline presentation
188 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
190 return Handle(HYDROData_PolylineXY)::DownCast(
191 GetReferenceObject( DataTag_PolylineXY ) );
194 void HYDROData_Polyline3D::RemovePolylineXY()
196 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
197 if ( aPrevPolyline.IsNull() )
200 ClearReferenceObjects( DataTag_PolylineXY );
202 // Indicate model of the need to update the polyline presentation
206 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
208 if ( theProfile.IsNull() )
211 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
212 if ( IsEqual( aPrevProfile, theProfile ) )
215 SetReferenceObject( theProfile, DataTag_ProfileUZ );
217 // Remove the bathymetry, because one altitude object can be presented at time
218 RemoveAltitudeObject();
220 // Indicate model of the need to update the polyline presentation
226 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
228 return Handle(HYDROData_ProfileUZ)::DownCast(
229 GetReferenceObject( DataTag_ProfileUZ ) );
232 void HYDROData_Polyline3D::RemoveProfileUZ()
234 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
235 if ( aPrevProfile.IsNull() )
238 ClearReferenceObjects( DataTag_ProfileUZ );
240 // Indicate model of the need to update the polyline presentation
244 bool HYDROData_Polyline3D::SetAltitudeObject(
245 const Handle(HYDROData_IAltitudeObject)& theAltitude )
247 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
249 if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
252 if ( IsEqual( aPrevAltitude, theAltitude ) )
255 // Remove the u,z profile, because one altitude object can be presented at time
258 // Create the child profile object
259 updateChildProfilePoints();
265 void HYDROData_Polyline3D::RemoveAltitudeObject()
267 HYDROData_Object::RemoveAltitudeObject();
269 // Remove the child profile object
270 removeChildProfileUZ();
273 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
275 Handle(HYDROData_ProfileUZ) aProfileUZ =
276 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
277 if ( !theIsCreate || !aProfileUZ.IsNull() )
280 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
281 if ( aDocument.IsNull() )
284 Handle(HYDROData_Profile) aProfile =
285 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
287 QString aProfilePref = GetName() + "_Profile";
288 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
290 aProfile->SetName( aProfileName );
292 aProfileUZ = aProfile->GetProfileUZ();
294 Handle(HYDROData_Polyline3D) me = this;
295 me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
300 HYDROData_IPolyline::PointsList generateProfileUZPoints(
301 const Handle(HYDROData_PolylineXY)& thePolyline,
302 const Handle(HYDROData_IAltitudeObject)& theAltitude )
304 HYDROData_IPolyline::PointsList aPointsList;
305 if ( thePolyline.IsNull() || theAltitude.IsNull() )
308 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
309 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
310 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
311 if ( aPolylinePoints.IsEmpty() )
314 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
316 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
318 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
319 double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
320 if( aPointDepth == theAltitude->GetInvalidAltitude() )
323 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
324 aPointsList.Append( anAltitudePoint );
330 void HYDROData_Polyline3D::updateChildProfilePoints()
332 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
333 if ( anAltitude.IsNull() )
336 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
337 if ( aChildProfileUZ.IsNull() )
340 Handle(HYDROData_Profile) aProfile =
341 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
342 if ( aProfile.IsNull() )
345 HYDROData_IPolyline::PointsList aProfilePoints =
346 generateProfileUZPoints( GetPolylineXY(), anAltitude );
347 aProfile->SetParametricPoints( aProfilePoints );
352 void HYDROData_Polyline3D::removeChildProfileUZ()
354 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
355 if ( aChildProfileUZ.IsNull() )
358 ClearReferenceObjects( DataTag_ChildProfileUZ );
360 /* Uncomment if removing is requested
361 Handle(HYDROData_Profile) aProfile =
362 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
363 if ( !aProfile.IsNull() )