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 aPolylineName = GetObjPyName();
39 Handle(HYDROData_PolylineXY) aRefPolyline = GetPolylineXY();
40 setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" );
42 Handle(HYDROData_ProfileUZ) aRefProfileUZ = GetProfileUZ();
43 if ( !aRefProfileUZ.IsNull() )
45 Handle(HYDROData_Profile) aProfile =
46 Handle(HYDROData_Profile)::DownCast( aRefProfileUZ->GetFatherObject() );
47 if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) )
49 QString aProfileName = aProfile->GetObjPyName();
50 if ( !aProfileName.isEmpty() )
52 aResList << QString( "%1.SetProfileUZ( %2.GetProfileUZ() );" )
53 .arg( aPolylineName ).arg( aProfileName );
59 Handle(HYDROData_IAltitudeObject) aRefBathymetry = GetAltitudeObject();
60 if ( !aRefBathymetry.IsNull() )
62 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
63 if ( !aChildProfileUZ.IsNull() )
65 Handle(HYDROData_Profile) aProfile =
66 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
67 if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) )
69 QString aProfileName = aProfile->GetObjPyName();
70 if ( !aProfileName.isEmpty() )
72 aResList << QString( "%1.SetChildProfileUZ( %2.GetProfileUZ() );" )
73 .arg( aPolylineName ).arg( aProfileName );
78 setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" );
82 aResList << QString( "" );
83 aResList << QString( "%1.Update();" ).arg( aPolylineName );
84 aResList << QString( "" );
89 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
91 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
93 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
94 if ( !aPolylineXY.IsNull() )
95 aResSeq.Append( aPolylineXY );
97 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
98 if ( !aProfileUZ.IsNull() )
99 aResSeq.Append( aProfileUZ );
101 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
102 if ( !aChildProfileUZ.IsNull() )
103 aResSeq.Append( aChildProfileUZ );
108 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
110 return getTopShape();
113 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
118 void HYDROData_Polyline3D::Update()
120 HYDROData_Object::Update();
122 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
123 if ( aPolylineXY.IsNull() )
126 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
127 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
128 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
129 if ( aPolylinePoints.IsEmpty() )
132 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
134 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
135 if ( !anAltitude.IsNull() )
136 aProfileUZ = GetChildProfileUZ();
138 if ( aProfileUZ.IsNull() )
141 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
142 if ( aProfilePoints.IsEmpty() )
145 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
146 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
148 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
149 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
151 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
152 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
154 NCollection_Sequence<Polyline3DPoint> aResPoints;
156 // Add first point as is
157 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
159 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
161 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
163 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
165 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
166 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
168 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
169 aResPoints.Append( aCompPoint );
172 // Add last point as is
173 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
175 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
176 SetTopShape( aResWire );
177 SetShape3D( aResWire );
180 QColor HYDROData_Polyline3D::DefaultFillingColor()
182 return QColor( Qt::transparent );
185 QColor HYDROData_Polyline3D::DefaultBorderColor()
187 return QColor( Qt::red );
190 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
192 return DefaultFillingColor();
195 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
197 return DefaultBorderColor();
200 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
201 const bool theIsUpdateProfile )
203 if ( thePolyline.IsNull() )
206 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
207 if ( IsEqual( aPrevPolyline, thePolyline ) )
210 SetReferenceObject( thePolyline, DataTag_PolylineXY );
212 // Update the child profile object
213 if ( theIsUpdateProfile )
214 updateChildProfilePoints();
216 // Indicate model of the need to update the polyline presentation
222 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
224 return Handle(HYDROData_PolylineXY)::DownCast(
225 GetReferenceObject( DataTag_PolylineXY ) );
228 void HYDROData_Polyline3D::RemovePolylineXY()
230 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
231 if ( aPrevPolyline.IsNull() )
234 ClearReferenceObjects( DataTag_PolylineXY );
236 // Indicate model of the need to update the polyline presentation
240 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
242 if ( theProfile.IsNull() )
245 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
246 if ( IsEqual( aPrevProfile, theProfile ) )
249 SetReferenceObject( theProfile, DataTag_ProfileUZ );
251 // Remove the bathymetry, because one altitude object can be presented at time
252 RemoveAltitudeObject();
254 // Indicate model of the need to update the polyline presentation
260 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
262 return Handle(HYDROData_ProfileUZ)::DownCast(
263 GetReferenceObject( DataTag_ProfileUZ ) );
266 void HYDROData_Polyline3D::RemoveProfileUZ()
268 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
269 if ( aPrevProfile.IsNull() )
272 ClearReferenceObjects( DataTag_ProfileUZ );
274 // Indicate model of the need to update the polyline presentation
278 bool HYDROData_Polyline3D::SetAltitudeObject(
279 const Handle(HYDROData_IAltitudeObject)& theAltitude )
281 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
283 if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
286 if ( IsEqual( aPrevAltitude, theAltitude ) )
289 // Remove the u,z profile, because one altitude object can be presented at time
292 // Create the child profile object
293 updateChildProfilePoints();
299 void HYDROData_Polyline3D::RemoveAltitudeObject()
301 HYDROData_Object::RemoveAltitudeObject();
303 // Remove the child profile object
304 removeChildProfileUZ();
307 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
309 Handle(HYDROData_ProfileUZ) aProfileUZ =
310 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
311 if ( !theIsCreate || !aProfileUZ.IsNull() )
314 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
315 if ( aDocument.IsNull() )
318 Handle(HYDROData_Profile) aProfile =
319 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
321 QString aProfilePref = GetName() + "_Profile";
322 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
324 aProfile->SetName( aProfileName );
326 aProfileUZ = aProfile->GetProfileUZ();
328 HYDROData_Polyline3D* me = const_cast<HYDROData_Polyline3D*>( this ); // Temporary to be revised
329 me->SetChildProfileUZ( aProfileUZ );
334 void HYDROData_Polyline3D::SetChildProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
336 SetReferenceObject( theProfile, DataTag_ChildProfileUZ );
339 HYDROData_IPolyline::PointsList generateProfileUZPoints(
340 const Handle(HYDROData_PolylineXY)& thePolyline,
341 const Handle(HYDROData_IAltitudeObject)& theAltitude )
343 HYDROData_IPolyline::PointsList aPointsList;
344 if ( thePolyline.IsNull() || theAltitude.IsNull() )
347 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
348 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
349 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
350 if ( aPolylinePoints.IsEmpty() )
353 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
355 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
357 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
358 double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
359 if( aPointDepth == theAltitude->GetInvalidAltitude() )
362 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
363 aPointsList.Append( anAltitudePoint );
369 void HYDROData_Polyline3D::updateChildProfilePoints()
371 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
372 if ( anAltitude.IsNull() )
375 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
376 if ( aChildProfileUZ.IsNull() )
379 Handle(HYDROData_Profile) aProfile =
380 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
381 if ( aProfile.IsNull() )
384 HYDROData_IPolyline::PointsList aProfilePoints =
385 generateProfileUZPoints( GetPolylineXY(), anAltitude );
386 aProfile->SetParametricPoints( aProfilePoints );
391 void HYDROData_Polyline3D::removeChildProfileUZ()
393 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
394 if ( aChildProfileUZ.IsNull() )
397 ClearReferenceObjects( DataTag_ChildProfileUZ );
399 /* Uncomment if removing is requested
400 Handle(HYDROData_Profile) aProfile =
401 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
402 if ( !aProfile.IsNull() )