+bool HYDROData_Polyline3D::SetAltitudeObject(
+ const Handle(HYDROData_IAltitudeObject)& theAltitude )
+{
+ Handle(HYDROData_IAltitudeObject) aPrevAltitude = GetAltitudeObject();
+
+ if ( !HYDROData_Object::SetAltitudeObject( theAltitude ) )
+ return false;
+
+ if ( IsEqual( aPrevAltitude, theAltitude ) )
+ return true;
+
+ // Remove the u,z profile, because one altitude object can be presented at time
+ RemoveProfileUZ();
+
+ // Create the child profile object
+ updateChildProfilePoints();
+
+ return true;
+}
+
+
+void HYDROData_Polyline3D::RemoveAltitudeObject()
+{
+ HYDROData_Object::RemoveAltitudeObject();
+
+ // Remove the child profile object
+ removeChildProfileUZ();
+}
+
+Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetChildProfileUZ( const bool theIsCreate ) const
+{
+ Handle(HYDROData_ProfileUZ) aProfileUZ =
+ Handle(HYDROData_ProfileUZ)::DownCast( GetReferenceObject( DataTag_ChildProfileUZ ) );
+ if ( !theIsCreate || !aProfileUZ.IsNull() )
+ return aProfileUZ;
+
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+ if ( aDocument.IsNull() )
+ return aProfileUZ;
+
+ Handle(HYDROData_Profile) aProfile =
+ Handle(HYDROData_Profile)::DownCast( aDocument->CreateObject( KIND_PROFILE ) );
+
+ QString aProfilePref = GetName() + "_Profile";
+ QString aProfileName = HYDROData_Tool::GenerateObjectName( aDocument, aProfilePref );
+
+ aProfile->SetName( aProfileName );
+
+ aProfileUZ = aProfile->GetProfileUZ();
+
+ HYDROData_Polyline3D* me = const_cast<HYDROData_Polyline3D*>( this ); // Temporary to be revised
+ me->SetChildProfileUZ( aProfileUZ );
+
+ return aProfileUZ;
+}
+
+void HYDROData_Polyline3D::SetChildProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
+{
+ SetReferenceObject( theProfile, DataTag_ChildProfileUZ );
+}
+
+HYDROData_IPolyline::PointsList generateProfileUZPoints(
+ const Handle(HYDROData_PolylineXY)& thePolyline,
+ const Handle(HYDROData_IAltitudeObject)& theAltitude )
+{
+ HYDROData_IPolyline::PointsList aPointsList;
+ if ( thePolyline.IsNull() || theAltitude.IsNull() )
+ return aPointsList;
+
+ bool anIsSectionClosed = thePolyline->IsClosedSection( 0 );
+ HYDROData_IPolyline::SectionType aSectionType = thePolyline->GetSectionType( 0 );
+ HYDROData_IPolyline::PointsList aPolylinePoints = thePolyline->GetPoints( 0 );
+ if ( aPolylinePoints.IsEmpty() )
+ return aPointsList;
+
+ for ( int i = 1, aNbPoints = aPolylinePoints.Size(); i <= aNbPoints; ++i )
+ {
+ const HYDROData_PolylineXY::Point& aSectPoint = aPolylinePoints.Value( i );
+
+ double aPointDistance = thePolyline->GetDistance( 0, i - 1 );
+ double aPointDepth = theAltitude->GetAltitudeForPoint( aSectPoint );
+ if( aPointDepth == theAltitude->GetInvalidAltitude() )
+ aPointDepth = 0.0;
+
+ HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
+ aPointsList.Append( anAltitudePoint );
+ }
+
+ return aPointsList;
+}
+
+void HYDROData_Polyline3D::updateChildProfilePoints()
+{
+ Handle(HYDROData_IAltitudeObject) anAltitude = GetAltitudeObject();
+ if ( anAltitude.IsNull() )
+ return;
+
+ Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ();
+ if ( aChildProfileUZ.IsNull() )
+ return;
+
+ Handle(HYDROData_Profile) aProfile =
+ Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
+ if ( aProfile.IsNull() )
+ return;
+
+ HYDROData_IPolyline::PointsList aProfilePoints =
+ generateProfileUZPoints( GetPolylineXY(), anAltitude );
+ aProfile->SetParametricPoints( aProfilePoints );
+
+ aProfile->Update();
+}
+
+void HYDROData_Polyline3D::removeChildProfileUZ()
+{
+ Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
+ if ( aChildProfileUZ.IsNull() )
+ return;
+
+ ClearReferenceObjects( DataTag_ChildProfileUZ );
+
+ /* Uncomment if removing is requested
+ Handle(HYDROData_Profile) aProfile =
+ Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
+ if ( !aProfile.IsNull() )
+ aProfile->Remove();
+ */
+}
+
+