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 );
43 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
45 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
47 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
48 if ( !aPolylineXY.IsNull() )
49 aResSeq.Append( aPolylineXY );
51 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
52 if ( !aProfileUZ.IsNull() )
53 aResSeq.Append( aProfileUZ );
55 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
56 if ( !aChildProfileUZ.IsNull() )
57 aResSeq.Append( aChildProfileUZ );
62 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
67 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
72 void HYDROData_Polyline3D::Update()
74 HYDROData_Object::Update();
76 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
77 if ( aPolylineXY.IsNull() )
80 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
81 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
82 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
83 if ( aPolylinePoints.IsEmpty() )
86 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
88 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
89 if ( !anAltitude.IsNull() )
90 aProfileUZ = GetChildProfileUZ();
92 if ( aProfileUZ.IsNull() )
95 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
96 if ( aProfilePoints.IsEmpty() )
99 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
100 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
102 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
103 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
105 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
106 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
108 NCollection_Sequence<Polyline3DPoint> aResPoints;
110 // Add first point as is
111 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
113 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
115 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
117 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
119 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
120 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
122 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
123 aResPoints.Append( aCompPoint );
126 // Add last point as is
127 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
129 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
130 SetTopShape( aResWire );
131 SetShape3D( aResWire );
134 QColor HYDROData_Polyline3D::DefaultFillingColor()
136 return QColor( Qt::transparent );
139 QColor HYDROData_Polyline3D::DefaultBorderColor()
141 return QColor( Qt::red );
144 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
146 return DefaultFillingColor();
149 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
151 return DefaultBorderColor();
154 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
155 const bool theIsUpdateProfile )
157 if ( thePolyline.IsNull() )
160 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
161 if ( IsEqual( aPrevPolyline, thePolyline ) )
164 SetReferenceObject( thePolyline, DataTag_PolylineXY );
166 // Update the child profile object
167 if ( theIsUpdateProfile )
168 updateChildProfilePoints();
170 // Indicate model of the need to update the polyline presentation
176 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
178 return Handle(HYDROData_PolylineXY)::DownCast(
179 GetReferenceObject( DataTag_PolylineXY ) );
182 void HYDROData_Polyline3D::RemovePolylineXY()
184 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
185 if ( aPrevPolyline.IsNull() )
188 ClearReferenceObjects( DataTag_PolylineXY );
190 // Indicate model of the need to update the polyline presentation
194 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
196 if ( theProfile.IsNull() )
199 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
200 if ( IsEqual( aPrevProfile, theProfile ) )
203 SetReferenceObject( theProfile, DataTag_ProfileUZ );
205 // Remove the bathymetry, because one altitude object can be presented at time
206 RemoveAltitudeObject();
208 // Indicate model of the need to update the polyline presentation
214 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
216 return Handle(HYDROData_ProfileUZ)::DownCast(
217 GetReferenceObject( DataTag_ProfileUZ ) );
220 void HYDROData_Polyline3D::RemoveProfileUZ()
222 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
223 if ( aPrevProfile.IsNull() )
226 ClearReferenceObjects( DataTag_ProfileUZ );
228 // Indicate model of the need to update the polyline presentation
232 bool HYDROData_Polyline3D::SetAltitudeObject(
233 const Handle(HYDROData_IAltitudeObject)& theAltitude )
235 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
237 if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
240 if ( IsEqual( aPrevAltitude, theAltitude ) )
243 // Remove the u,z profile, because one altitude object can be presented at time
246 // Create the child profile object
247 updateChildProfilePoints();
253 void HYDROData_Polyline3D::RemoveAltitudeObject()
255 HYDROData_Object::RemoveAltitudeObject();
257 // Remove the child profile object
258 removeChildProfileUZ();
261 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
263 Handle(HYDROData_ProfileUZ) aProfileUZ =
264 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
265 if ( !theIsCreate || !aProfileUZ.IsNull() )
268 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
269 if ( aDocument.IsNull() )
272 Handle(HYDROData_Profile) aProfile =
273 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
275 QString aProfilePref = GetName() + "_Profile";
276 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
278 aProfile->SetName( aProfileName );
280 aProfileUZ = aProfile->GetProfileUZ();
282 Handle(HYDROData_Polyline3D) me = this;
283 me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
288 HYDROData_IPolyline::PointsList generateProfileUZPoints(
289 const Handle(HYDROData_PolylineXY)& thePolyline,
290 const Handle(HYDROData_IAltitudeObject)& theAltitude )
292 HYDROData_IPolyline::PointsList aPointsList;
293 if ( thePolyline.IsNull() || theAltitude.IsNull() )
296 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
297 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
298 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
299 if ( aPolylinePoints.IsEmpty() )
302 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
304 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
306 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
307 double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
308 if( aPointDepth == theAltitude->GetInvalidAltitude() )
311 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
312 aPointsList.Append( anAltitudePoint );
318 void HYDROData_Polyline3D::updateChildProfilePoints()
320 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
321 if ( anAltitude.IsNull() )
324 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
325 if ( aChildProfileUZ.IsNull() )
328 Handle(HYDROData_Profile) aProfile =
329 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
330 if ( aProfile.IsNull() )
333 HYDROData_IPolyline::PointsList aProfilePoints =
334 generateProfileUZPoints( GetPolylineXY(), anAltitude );
335 aProfile->SetParametricPoints( aProfilePoints );
340 void HYDROData_Polyline3D::removeChildProfileUZ()
342 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
343 if ( aChildProfileUZ.IsNull() )
346 ClearReferenceObjects( DataTag_ChildProfileUZ );
348 /* Uncomment if removing is requested
349 Handle(HYDROData_Profile) aProfile =
350 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
351 if ( !aProfile.IsNull() )