2 #include "HYDROData_Polyline3D.h"
4 #include "HYDROData_Bathymetry.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_Bathymetry) aBathymetry = GetBathymetry();
103 if ( !aBathymetry.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
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::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
248 Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
250 if ( !HYDROData_Object::SetBathymetry( theBathymetry ) )
253 if ( IsEqual( aPrevBathymetry, theBathymetry ) )
256 // Remove the u,z profile, because one altitude object can be presented at time
259 // Create the child profile object
260 updateChildProfilePoints();
266 void HYDROData_Polyline3D::RemoveBathymetry()
268 HYDROData_Object::RemoveBathymetry();
270 // Remove the child profile object
271 removeChildProfileUZ();
274 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
276 Handle(HYDROData_ProfileUZ) aProfileUZ =
277 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
278 if ( !theIsCreate || !aProfileUZ.IsNull() )
281 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
282 if ( aDocument.IsNull() )
285 Handle(HYDROData_Profile) aProfile =
286 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
288 QString aProfilePref = GetName() + "_Profile";
289 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
291 aProfile->SetName( aProfileName );
293 aProfileUZ = aProfile->GetProfileUZ();
295 Handle(HYDROData_Polyline3D) me = this;
296 me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
301 HYDROData_IPolyline::PointsList generateProfileUZPoints(
302 const Handle(HYDROData_PolylineXY)& thePolyline,
303 const Handle(HYDROData_Bathymetry)& theBathymetry )
305 HYDROData_IPolyline::PointsList aPointsList;
306 if ( thePolyline.IsNull() || theBathymetry.IsNull() )
309 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
310 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
311 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
312 if ( aPolylinePoints.IsEmpty() )
315 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
317 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
319 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
320 double aPointDepth = theBathymetry->GetAltitudeForPoint( aSectPoint );
321 if( aPointDepth==theBathymetry->GetInvalidAltitude() )
324 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
325 aPointsList.Append( anAltitudePoint );
331 void HYDROData_Polyline3D::updateChildProfilePoints()
333 Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry();
334 if ( aBathymetry.IsNull() )
337 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
338 if ( aChildProfileUZ.IsNull() )
341 Handle(HYDROData_Profile) aProfile =
342 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
343 if ( aProfile.IsNull() )
346 HYDROData_IPolyline::PointsList aProfilePoints =
347 generateProfileUZPoints( GetPolylineXY(), GetBathymetry() );
348 aProfile->SetParametricPoints( aProfilePoints );
353 void HYDROData_Polyline3D::removeChildProfileUZ()
355 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
356 if ( aChildProfileUZ.IsNull() )
359 ClearReferenceObjects( DataTag_ChildProfileUZ );
361 /* Uncomment if removing is requested
362 Handle(HYDROData_Profile) aProfile =
363 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
364 if ( !aProfile.IsNull() )