#include "HYDROData_Polyline3D.h"
+#include "HYDROData_Bathymetry.h"
#include "HYDROData_Document.h"
#include "HYDROData_PolylineXY.h"
+#include "HYDROData_Profile.h"
#include "HYDROData_ProfileUZ.h"
+#include "HYDROData_Tool.h"
#include <gp_Pnt2d.hxx>
#include <gp_XY.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Wire.hxx>
+#include <QColor>
#include <QStringList>
#define PYTHON_POLYLINE_ID "KIND_POLYLINE"
if ( !aProfileUZ.IsNull() )
aResSeq.Append( aProfileUZ );
+ Handle(HYDROData_ProfileUZ) aChildProfileUZ = GetChildProfileUZ( false );
+ if ( !aChildProfileUZ.IsNull() )
+ aResSeq.Append( aChildProfileUZ );
+
return aResSeq;
}
HYDROData_Object::Update();
Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
- Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
- if ( aPolylineXY.IsNull() || aProfileUZ.IsNull() )
+ if ( aPolylineXY.IsNull() )
return;
bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
+ if ( aPolylinePoints.IsEmpty() )
+ return;
+
+ Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
+
+ Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry();
+ if ( !aBathymetry.IsNull() )
+ aProfileUZ = GetChildProfileUZ();
+
+ if ( aProfileUZ.IsNull() )
+ return;
+
HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
- if ( aPolylinePoints.IsEmpty() || aProfilePoints.IsEmpty() )
+ if ( aProfilePoints.IsEmpty() )
return;
const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
- double aDepth = aProfileUZ->GetDepthFromDistance( aParLen );
+ double aDepth = HYDROData_ProfileUZ::GetDepthFromDistance( aProfilePoints, aParLen );
Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
aResPoints.Append( aCompPoint );
SetShape3D( aResWire );
}
-bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline )
+QColor HYDROData_Polyline3D::DefaultFillingColor()
+{
+ return QColor( Qt::transparent );
+}
+
+QColor HYDROData_Polyline3D::DefaultBorderColor()
+{
+ return QColor( Qt::red );
+}
+
+QColor HYDROData_Polyline3D::getDefaultFillingColor() const
+{
+ return DefaultFillingColor();
+}
+
+QColor HYDROData_Polyline3D::getDefaultBorderColor() const
+{
+ return DefaultBorderColor();
+}
+
+bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline,
+ const bool theIsUpdateProfile )
{
if ( thePolyline.IsNull() )
return false;
SetReferenceObject( thePolyline, DataTag_PolylineXY );
+ // Update the child profile object
+ if ( theIsUpdateProfile )
+ updateChildProfilePoints();
+
// Indicate model of the need to update the polyline presentation
SetToUpdate( true );
SetReferenceObject( theProfile, DataTag_ProfileUZ );
+ // Remove the bathymetry, because one altitude object can be presented at time
+ RemoveBathymetry();
+
// Indicate model of the need to update the polyline presentation
SetToUpdate( true );
SetToUpdate( true );
}
+bool HYDROData_Polyline3D::SetBathymetry( const Handle(HYDROData_Bathymetry)& theBathymetry )
+{
+ Handle(HYDROData_Bathymetry) aPrevBathymetry = GetBathymetry();
+
+ if ( !HYDROData_Object::SetBathymetry( theBathymetry ) )
+ return false;
+
+ if ( IsEqual( aPrevBathymetry, theBathymetry ) )
+ 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::RemoveBathymetry()
+{
+ HYDROData_Object::RemoveBathymetry();
+
+ // 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();
+
+ Handle(HYDROData_Polyline3D) me = this;
+ me->SetReferenceObject( aProfileUZ, DataTag_ChildProfileUZ );
+
+ return aProfileUZ;
+}
+
+HYDROData_IPolyline::PointsList generateProfileUZPoints(
+ const Handle(HYDROData_PolylineXY)& thePolyline,
+ const Handle(HYDROData_Bathymetry)& theBathymetry )
+{
+ HYDROData_IPolyline::PointsList aPointsList;
+ if ( thePolyline.IsNull() || theBathymetry.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 = theBathymetry->GetAltitudeForPoint( aSectPoint );
+ if( aPointDepth==theBathymetry->GetInvalidAltitude() )
+ aPointDepth = 0.0;
+
+ HYDROData_IPolyline::Point anAltitudePoint( aPointDistance, aPointDepth );
+ aPointsList.Append( anAltitudePoint );
+ }
+
+ return aPointsList;
+}
+
+void HYDROData_Polyline3D::updateChildProfilePoints()
+{
+ Handle(HYDROData_Bathymetry) aBathymetry = GetBathymetry();
+ if ( aBathymetry.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(), GetBathymetry() );
+ 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();
+ */
+}
+
+