+
+#include "HYDROData_Polyline3D.h"
+
+#include "HYDROData_Document.h"
+#include "HYDROData_PolylineXY.h"
+#include "HYDROData_ProfileUZ.h"
+
+#include <gp_Pnt2d.hxx>
+#include <gp_XY.hxx>
+#include <gp_XYZ.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Wire.hxx>
+
+#include <QStringList>
+
+#define PYTHON_POLYLINE_ID "KIND_POLYLINE"
+
+IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object)
+IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object)
+
+
+HYDROData_Polyline3D::HYDROData_Polyline3D()
+: HYDROData_Object()
+{
+}
+
+HYDROData_Polyline3D::~HYDROData_Polyline3D()
+{
+}
+
+QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+ QStringList aResList;
+
+ Handle(HYDROData_Document) aDocument = HYDROData_Document::Document( myLab );
+ if ( aDocument.IsNull() )
+ return aResList;
+
+ QString aDocName = aDocument->GetDocPyName();
+ QString aPolylineName = GetName();
+
+ aResList << QString( "%1 = %2.CreateObject( %3 );" )
+ .arg( aPolylineName ).arg( aDocName ).arg( PYTHON_POLYLINE_ID );
+ aResList << QString( "%1.SetName( \"%1\" );" ).arg( aPolylineName );
+ aResList << QString( "" );
+
+ // TODO
+
+ return aResList;
+}
+
+TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
+{
+ return getTopShape();
+}
+
+TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
+{
+ return getShape3D();
+}
+
+void HYDROData_Polyline3D::Update()
+{
+ removeTopShape();
+ removeShape3D();
+
+ Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
+ Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
+ if ( aPolylineXY.IsNull() || aProfileUZ.IsNull() )
+ return;
+
+ bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
+ HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
+ HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
+ HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
+ if ( aPolylinePoints.IsEmpty() || aProfilePoints.IsEmpty() )
+ return;
+
+ const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
+ const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
+
+ const HYDROData_IPolyline::Point& aFirstParPoint = aProfilePoints.First();
+ const HYDROData_IPolyline::Point& aLastParPoint = aProfilePoints.Last();
+
+ double aPolylineCommonDist = aPolylineXY->GetDistance( 0, aPolylinePoints.Size() - 1 );
+ double aParCommonDist = gp_Pnt2d( aFirstParPoint.X(), 0 ).Distance( gp_Pnt2d( aLastParPoint.X(), 0 ) );
+
+ NCollection_Sequence<Polyline3DPoint> aResPoints;
+
+ // Add first point as is
+ aResPoints.Append( Polyline3DPoint( aFirstPoint.X(), aFirstPoint.Y(), aFirstParPoint.Y() ) );
+
+ for ( int i = 2, aNbPoints = aPolylinePoints.Size(); i < aNbPoints; ++i )
+ {
+ const HYDROData_IPolyline::Point& aPolylinePoint = aPolylinePoints.Value( i );
+
+ double aDistance = aPolylineXY->GetDistance( 0, i - 1 );
+
+ double aParLen = ( aDistance / aPolylineCommonDist ) * aParCommonDist;
+ double aDepth = aProfileUZ->GetDepthFromDistance( aParLen );
+
+ Polyline3DPoint aCompPoint( aPolylinePoint.X(), aPolylinePoint.Y(), aDepth );
+ aResPoints.Append( aCompPoint );
+ }
+
+ // Add last point as is
+ aResPoints.Append( Polyline3DPoint( aLastPoint.X(), aLastPoint.Y(), aLastParPoint.Y() ) );
+
+ TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
+ SetTopShape( aResWire );
+ SetShape3D( aResWire );
+}
+
+bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& thePolyline )
+{
+ if ( thePolyline.IsNull() )
+ return false;
+
+ Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
+ if ( IsEqual( aPrevPolyline, thePolyline ) )
+ return true;
+
+ SetReferenceObject( thePolyline, DataTag_PolylineXY );
+
+ // Indicate model of the need to update the polyline presentation
+ SetToUpdate( true );
+
+ return true;
+}
+
+Handle(HYDROData_PolylineXY) HYDROData_Polyline3D::GetPolylineXY() const
+{
+ return Handle(HYDROData_PolylineXY)::DownCast(
+ GetReferenceObject( DataTag_PolylineXY ) );
+}
+
+void HYDROData_Polyline3D::RemovePolylineXY()
+{
+ Handle(HYDROData_PolylineXY) aPrevPolyline = GetPolylineXY();
+ if ( aPrevPolyline.IsNull() )
+ return;
+
+ ClearReferenceObjects( DataTag_PolylineXY );
+
+ // Indicate model of the need to update the polyline presentation
+ SetToUpdate( true );
+}
+
+bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
+{
+ if ( theProfile.IsNull() )
+ return false;
+
+ Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
+ if ( IsEqual( aPrevProfile, theProfile ) )
+ return true;
+
+ SetReferenceObject( theProfile, DataTag_ProfileUZ );
+
+ // Indicate model of the need to update the polyline presentation
+ SetToUpdate( true );
+
+ return true;
+}
+
+Handle(HYDROData_ProfileUZ) HYDROData_Polyline3D::GetProfileUZ() const
+{
+ return Handle(HYDROData_ProfileUZ)::DownCast(
+ GetReferenceObject( DataTag_ProfileUZ ) );
+}
+
+void HYDROData_Polyline3D::RemoveProfileUZ()
+{
+ Handle(HYDROData_ProfileUZ) aPrevProfile = GetProfileUZ();
+ if ( aPrevProfile.IsNull() )
+ return;
+
+ ClearReferenceObjects( DataTag_ProfileUZ );
+
+ // Indicate model of the need to update the polyline presentation
+ SetToUpdate( true );
+}
+