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 #define PYTHON_POLYLINE_ID "KIND_POLYLINE"
23 IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object)
24 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object)
27 HYDROData_Polyline3D::HYDROData_Polyline3D()
32 HYDROData_Polyline3D::~HYDROData_Polyline3D()
36 QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
40 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
41 if ( aDocument.IsNull() )
44 QString aDocName = aDocument->GetDocPyName();
45 QString aPolylineName = GetName();
47 aResList << QString( "%1 = %2.CreateObject( %3 );" )
48 .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINE_ID );
49 aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
50 aResList << QString( "" );
57 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
59 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
61 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
62 if ( !aPolylineXY.IsNull() )
63 aResSeq.Append( aPolylineXY );
65 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
66 if ( !aProfileUZ.IsNull() )
67 aResSeq.Append( aProfileUZ );
69 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
70 if ( !aChildProfileUZ.IsNull() )
71 aResSeq.Append( aChildProfileUZ );
76 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
81 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
86 void HYDROData_Polyline3D::Update()
88 HYDROData_Object::Update();
90 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
91 if ( aPolylineXY.IsNull() )
94 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
95 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
96 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
97 if ( aPolylinePoints.IsEmpty() )
100 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
102 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
103 if ( !anAltitude.IsNull() )
104 aProfileUZ = GetChildProfileUZ();
106 if ( aProfileUZ.IsNull() )
109 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
110 if ( aProfilePoints.IsEmpty() )
113 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
114 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
116 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
117 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
119 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
120 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
122 NCollection_Sequence<Polyline3DPoint> aResPoints;
124 // Add first point as is
125 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
127 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
129 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
131 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
133 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
134 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
136 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
137 aResPoints.Append( aCompPoint );
140 // Add last point as is
141 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
143 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
144 SetTopShape( aResWire );
145 SetShape3D( aResWire );
148 QColor HYDROData_Polyline3D::DefaultFillingColor()
150 return QColor( Qt::transparent );
153 QColor HYDROData_Polyline3D::DefaultBorderColor()
155 return QColor( Qt::red );
158 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
160 return DefaultFillingColor();
163 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
165 return DefaultBorderColor();
168 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
169 const bool theIsUpdateProfile )
171 if ( thePolyline.IsNull() )
174 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
175 if ( IsEqual( aPrevPolyline, thePolyline ) )
178 SetReferenceObject( thePolyline, DataTag_PolylineXY );
180 // Update the child profile object
181 if ( theIsUpdateProfile )
182 updateChildProfilePoints();
184 // Indicate model of the need to update the polyline presentation
190 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
192 return Handle(HYDROData_PolylineXY)::DownCast(
193 GetReferenceObject( DataTag_PolylineXY ) );
196 void HYDROData_Polyline3D::RemovePolylineXY()
198 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
199 if ( aPrevPolyline.IsNull() )
202 ClearReferenceObjects( DataTag_PolylineXY );
204 // Indicate model of the need to update the polyline presentation
208 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
210 if ( theProfile.IsNull() )
213 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
214 if ( IsEqual( aPrevProfile, theProfile ) )
217 SetReferenceObject( theProfile, DataTag_ProfileUZ );
219 // Remove the bathymetry, because one altitude object can be presented at time
220 RemoveAltitudeObject();
222 // Indicate model of the need to update the polyline presentation
228 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
230 return Handle(HYDROData_ProfileUZ)::DownCast(
231 GetReferenceObject( DataTag_ProfileUZ ) );
234 void HYDROData_Polyline3D::RemoveProfileUZ()
236 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
237 if ( aPrevProfile.IsNull() )
240 ClearReferenceObjects( DataTag_ProfileUZ );
242 // Indicate model of the need to update the polyline presentation
246 bool HYDROData_Polyline3D::SetAltitudeObject(
247 const Handle(HYDROData_IAltitudeObject)& theAltitude )
249 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
251 if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
254 if ( IsEqual( aPrevAltitude, theAltitude ) )
257 // Remove the u,z profile, because one altitude object can be presented at time
260 // Create the child profile object
261 updateChildProfilePoints();
267 void HYDROData_Polyline3D::RemoveAltitudeObject()
269 HYDROData_Object::RemoveAltitudeObject();
271 // Remove the child profile object
272 removeChildProfileUZ();
275 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
277 Handle(HYDROData_ProfileUZ) aProfileUZ =
278 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
279 if ( !theIsCreate || !aProfileUZ.IsNull() )
282 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
283 if ( aDocument.IsNull() )
286 Handle(HYDROData_Profile) aProfile =
287 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
289 QString aProfilePref = GetName() + "_Profile";
290 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
292 aProfile->SetName( aProfileName );
294 aProfileUZ = aProfile->GetProfileUZ();
296 Handle(HYDROData_Polyline3D) me = this;
297 me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
302 HYDROData_IPolyline::PointsList generateProfileUZPoints(
303 const Handle(HYDROData_PolylineXY)& thePolyline,
304 const Handle(HYDROData_IAltitudeObject)& theAltitude )
306 HYDROData_IPolyline::PointsList aPointsList;
307 if ( thePolyline.IsNull() || theAltitude.IsNull() )
310 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
311 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
312 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
313 if ( aPolylinePoints.IsEmpty() )
316 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
318 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
320 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
321 double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
322 if( aPointDepth == theAltitude->GetInvalidAltitude() )
325 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
326 aPointsList.Append( anAltitudePoint );
332 void HYDROData_Polyline3D::updateChildProfilePoints()
334 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
335 if ( anAltitude.IsNull() )
338 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
339 if ( aChildProfileUZ.IsNull() )
342 Handle(HYDROData_Profile) aProfile =
343 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
344 if ( aProfile.IsNull() )
347 HYDROData_IPolyline::PointsList aProfilePoints =
348 generateProfileUZPoints( GetPolylineXY(), anAltitude );
349 aProfile->SetParametricPoints( aProfilePoints );
354 void HYDROData_Polyline3D::removeChildProfileUZ()
356 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
357 if ( aChildProfileUZ.IsNull() )
360 ClearReferenceObjects( DataTag_ChildProfileUZ );
362 /* Uncomment if removing is requested
363 Handle(HYDROData_Profile) aProfile =
364 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
365 if ( !aProfile.IsNull() )