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 = GetName();
41 aResList << QString( "" );
42 aResList << QString( "%1.Update();" ).arg( aName );
43 aResList << QString( "" );
48 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
50 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
52 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
53 if ( !aPolylineXY.IsNull() )
54 aResSeq.Append( aPolylineXY );
56 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
57 if ( !aProfileUZ.IsNull() )
58 aResSeq.Append( aProfileUZ );
60 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
61 if ( !aChildProfileUZ.IsNull() )
62 aResSeq.Append( aChildProfileUZ );
67 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
72 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
77 void HYDROData_Polyline3D::Update()
79 HYDROData_Object::Update();
81 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
82 if ( aPolylineXY.IsNull() )
85 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
86 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
87 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
88 if ( aPolylinePoints.IsEmpty() )
91 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
93 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
94 if ( !anAltitude.IsNull() )
95 aProfileUZ = GetChildProfileUZ();
97 if ( aProfileUZ.IsNull() )
100 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
101 if ( aProfilePoints.IsEmpty() )
104 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
105 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
107 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
108 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
110 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
111 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
113 NCollection_Sequence<Polyline3DPoint> aResPoints;
115 // Add first point as is
116 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
118 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
120 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
122 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
124 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
125 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
127 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
128 aResPoints.Append( aCompPoint );
131 // Add last point as is
132 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
134 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
135 SetTopShape( aResWire );
136 SetShape3D( aResWire );
139 QColor HYDROData_Polyline3D::DefaultFillingColor()
141 return QColor( Qt::transparent );
144 QColor HYDROData_Polyline3D::DefaultBorderColor()
146 return QColor( Qt::red );
149 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
151 return DefaultFillingColor();
154 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
156 return DefaultBorderColor();
159 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
160 const bool theIsUpdateProfile )
162 if ( thePolyline.IsNull() )
165 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
166 if ( IsEqual( aPrevPolyline, thePolyline ) )
169 SetReferenceObject( thePolyline, DataTag_PolylineXY );
171 // Update the child profile object
172 if ( theIsUpdateProfile )
173 updateChildProfilePoints();
175 // Indicate model of the need to update the polyline presentation
181 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
183 return Handle(HYDROData_PolylineXY)::DownCast(
184 GetReferenceObject( DataTag_PolylineXY ) );
187 void HYDROData_Polyline3D::RemovePolylineXY()
189 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
190 if ( aPrevPolyline.IsNull() )
193 ClearReferenceObjects( DataTag_PolylineXY );
195 // Indicate model of the need to update the polyline presentation
199 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
201 if ( theProfile.IsNull() )
204 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
205 if ( IsEqual( aPrevProfile, theProfile ) )
208 SetReferenceObject( theProfile, DataTag_ProfileUZ );
210 // Remove the bathymetry, because one altitude object can be presented at time
211 RemoveAltitudeObject();
213 // Indicate model of the need to update the polyline presentation
219 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
221 return Handle(HYDROData_ProfileUZ)::DownCast(
222 GetReferenceObject( DataTag_ProfileUZ ) );
225 void HYDROData_Polyline3D::RemoveProfileUZ()
227 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
228 if ( aPrevProfile.IsNull() )
231 ClearReferenceObjects( DataTag_ProfileUZ );
233 // Indicate model of the need to update the polyline presentation
237 bool HYDROData_Polyline3D::SetAltitudeObject(
238 const Handle(HYDROData_IAltitudeObject)& theAltitude )
240 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
242 if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
245 if ( IsEqual( aPrevAltitude, theAltitude ) )
248 // Remove the u,z profile, because one altitude object can be presented at time
251 // Create the child profile object
252 updateChildProfilePoints();
258 void HYDROData_Polyline3D::RemoveAltitudeObject()
260 HYDROData_Object::RemoveAltitudeObject();
262 // Remove the child profile object
263 removeChildProfileUZ();
266 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
268 Handle(HYDROData_ProfileUZ) aProfileUZ =
269 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
270 if ( !theIsCreate || !aProfileUZ.IsNull() )
273 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
274 if ( aDocument.IsNull() )
277 Handle(HYDROData_Profile) aProfile =
278 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
280 QString aProfilePref = GetName() + "_Profile";
281 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
283 aProfile->SetName( aProfileName );
285 aProfileUZ = aProfile->GetProfileUZ();
287 Handle(HYDROData_Polyline3D) me = this;
288 me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
293 HYDROData_IPolyline::PointsList generateProfileUZPoints(
294 const Handle(HYDROData_PolylineXY)& thePolyline,
295 const Handle(HYDROData_IAltitudeObject)& theAltitude )
297 HYDROData_IPolyline::PointsList aPointsList;
298 if ( thePolyline.IsNull() || theAltitude.IsNull() )
301 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
302 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
303 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
304 if ( aPolylinePoints.IsEmpty() )
307 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
309 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
311 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
312 double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
313 if( aPointDepth == theAltitude->GetInvalidAltitude() )
316 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
317 aPointsList.Append( anAltitudePoint );
323 void HYDROData_Polyline3D::updateChildProfilePoints()
325 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
326 if ( anAltitude.IsNull() )
329 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
330 if ( aChildProfileUZ.IsNull() )
333 Handle(HYDROData_Profile) aProfile =
334 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
335 if ( aProfile.IsNull() )
338 HYDROData_IPolyline::PointsList aProfilePoints =
339 generateProfileUZPoints( GetPolylineXY(), anAltitude );
340 aProfile->SetParametricPoints( aProfilePoints );
345 void HYDROData_Polyline3D::removeChildProfileUZ()
347 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
348 if ( aChildProfileUZ.IsNull() )
351 ClearReferenceObjects( DataTag_ChildProfileUZ );
353 /* Uncomment if removing is requested
354 Handle(HYDROData_Profile) aProfile =
355 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
356 if ( !aProfile.IsNull() )