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 ( !aProfile.IsNull() )
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 setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" );
63 aResList << QString( "" );
64 aResList << QString( "%1.Update();" ).arg( aPolylineName );
65 aResList << QString( "" );
70 HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
72 HYDROData_SequenceOfObjects aResSeq = HYDROData_Object::GetAllReferenceObjects();
74 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
75 if ( !aPolylineXY.IsNull() )
76 aResSeq.Append( aPolylineXY );
78 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
79 if ( !aProfileUZ.IsNull() )
80 aResSeq.Append( aProfileUZ );
82 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
83 if ( !aChildProfileUZ.IsNull() )
84 aResSeq.Append( aChildProfileUZ );
89 TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
94 TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
99 void HYDROData_Polyline3D::Update()
101 HYDROData_Object::Update();
103 Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
104 if ( aPolylineXY.IsNull() )
107 bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
108 HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
109 HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
110 if ( aPolylinePoints.IsEmpty() )
113 Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
115 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
116 if ( !anAltitude.IsNull() )
117 aProfileUZ = GetChildProfileUZ();
119 if ( aProfileUZ.IsNull() )
122 HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
123 if ( aProfilePoints.IsEmpty() )
126 const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
127 const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
129 const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
130 const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
132 double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
133 double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
135 NCollection_Sequence<Polyline3DPoint> aResPoints;
137 // Add first point as is
138 aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
140 for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
142 const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
144 double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
146 double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
147 double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
149 Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
150 aResPoints.Append( aCompPoint );
153 // Add last point as is
154 aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
156 TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
157 SetTopShape( aResWire );
158 SetShape3D( aResWire );
161 QColor HYDROData_Polyline3D::DefaultFillingColor()
163 return QColor( Qt::transparent );
166 QColor HYDROData_Polyline3D::DefaultBorderColor()
168 return QColor( Qt::red );
171 QColor HYDROData_Polyline3D::getDefaultFillingColor() const
173 return DefaultFillingColor();
176 QColor HYDROData_Polyline3D::getDefaultBorderColor() const
178 return DefaultBorderColor();
181 bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
182 const bool theIsUpdateProfile )
184 if ( thePolyline.IsNull() )
187 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
188 if ( IsEqual( aPrevPolyline, thePolyline ) )
191 SetReferenceObject( thePolyline, DataTag_PolylineXY );
193 // Update the child profile object
194 if ( theIsUpdateProfile )
195 updateChildProfilePoints();
197 // Indicate model of the need to update the polyline presentation
203 Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
205 return Handle(HYDROData_PolylineXY)::DownCast(
206 GetReferenceObject( DataTag_PolylineXY ) );
209 void HYDROData_Polyline3D::RemovePolylineXY()
211 Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
212 if ( aPrevPolyline.IsNull() )
215 ClearReferenceObjects( DataTag_PolylineXY );
217 // Indicate model of the need to update the polyline presentation
221 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
223 if ( theProfile.IsNull() )
226 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
227 if ( IsEqual( aPrevProfile, theProfile ) )
230 SetReferenceObject( theProfile, DataTag_ProfileUZ );
232 // Remove the bathymetry, because one altitude object can be presented at time
233 RemoveAltitudeObject();
235 // Indicate model of the need to update the polyline presentation
241 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
243 return Handle(HYDROData_ProfileUZ)::DownCast(
244 GetReferenceObject( DataTag_ProfileUZ ) );
247 void HYDROData_Polyline3D::RemoveProfileUZ()
249 Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
250 if ( aPrevProfile.IsNull() )
253 ClearReferenceObjects( DataTag_ProfileUZ );
255 // Indicate model of the need to update the polyline presentation
259 bool HYDROData_Polyline3D::SetAltitudeObject(
260 const Handle(HYDROData_IAltitudeObject)& theAltitude )
262 Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
264 if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
267 if ( IsEqual( aPrevAltitude, theAltitude ) )
270 // Remove the u,z profile, because one altitude object can be presented at time
273 // Create the child profile object
274 updateChildProfilePoints();
280 void HYDROData_Polyline3D::RemoveAltitudeObject()
282 HYDROData_Object::RemoveAltitudeObject();
284 // Remove the child profile object
285 removeChildProfileUZ();
288 Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
290 Handle(HYDROData_ProfileUZ) aProfileUZ =
291 Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
292 if ( !theIsCreate || !aProfileUZ.IsNull() )
295 Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
296 if ( aDocument.IsNull() )
299 Handle(HYDROData_Profile) aProfile =
300 Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
302 QString aProfilePref = GetName() + "_Profile";
303 QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
305 aProfile->SetName( aProfileName );
307 aProfileUZ = aProfile->GetProfileUZ();
309 HYDROData_Polyline3D* me = const_cast<HYDROData_Polyline3D*>( this ); // Temporary to be revised
310 me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
315 HYDROData_IPolyline::PointsList generateProfileUZPoints(
316 const Handle(HYDROData_PolylineXY)& thePolyline,
317 const Handle(HYDROData_IAltitudeObject)& theAltitude )
319 HYDROData_IPolyline::PointsList aPointsList;
320 if ( thePolyline.IsNull() || theAltitude.IsNull() )
323 bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
324 HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
325 HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
326 if ( aPolylinePoints.IsEmpty() )
329 for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
331 const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
333 double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
334 double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
335 if( aPointDepth == theAltitude->GetInvalidAltitude() )
338 HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
339 aPointsList.Append( anAltitudePoint );
345 void HYDROData_Polyline3D::updateChildProfilePoints()
347 Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
348 if ( anAltitude.IsNull() )
351 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
352 if ( aChildProfileUZ.IsNull() )
355 Handle(HYDROData_Profile) aProfile =
356 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
357 if ( aProfile.IsNull() )
360 HYDROData_IPolyline::PointsList aProfilePoints =
361 generateProfileUZPoints( GetPolylineXY(), anAltitude );
362 aProfile->SetParametricPoints( aProfilePoints );
367 void HYDROData_Polyline3D::removeChildProfileUZ()
369 Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
370 if ( aChildProfileUZ.IsNull() )
373 ClearReferenceObjects( DataTag_ChildProfileUZ );
375 /* Uncomment if removing is requested
376 Handle(HYDROData_Profile) aProfile =
377 Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
378 if ( !aProfile.IsNull() )