Salome HOME
export of 3D poly to SHP (lot 5)
[modules/hydro.git] / src / HYDROData / HYDROData_Polyline3D.cxx
index d11aaf9348ed2d334017edeec9783dea8c97f520..858a0a6c7b73641ecef7d6b5231707b8c1488308 100644 (file)
@@ -29,6 +29,9 @@
 #include <BRep_Tool.hxx>
 
 #include <Geom_BSplineCurve.hxx>
+#include <GeomAdaptor_Curve.hxx>
+#include <GCPnts_QuasiUniformAbscissa.hxx>
+#include <GCPnts_AbscissaPoint.hxx>
 
 #include <gp_Pnt2d.hxx>
 #include <gp_XY.hxx>
 
 #include <TopTools_SequenceOfShape.hxx>
 
+#define _DEVDEBUG_
+#include "HYDRO_trace.hxx"
+
 #include <QColor>
 #include <QStringList>
 
-IMPLEMENT_STANDARD_HANDLE(HYDROData_Polyline3D,HYDROData_Object)
 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_Polyline3D,HYDROData_Object)
 
 
@@ -63,25 +68,26 @@ HYDROData_Polyline3D::~HYDROData_Polyline3D()
 {
 }
 
-QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+QStringList HYDROData_Polyline3D::DumpToPython( const QString& thePyScriptPath,
+                                                MapOfTreatedObjects& theTreatedObjects ) const
 {
   QStringList aResList = dumpObjectCreation( theTreatedObjects );
   QString aPolylineName = GetObjPyName();
 
   Handle(HYDROData_PolylineXY) aRefPolyline = GetPolylineXY();
-  setPythonReferenceObject( theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" );
+  setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefPolyline, "SetPolylineXY" );
 
   Handle(HYDROData_ProfileUZ) aRefProfileUZ = GetProfileUZ();
   if ( !aRefProfileUZ.IsNull() )
   {
     Handle(HYDROData_Profile) aProfile = 
       Handle(HYDROData_Profile)::DownCast( aRefProfileUZ->GetFatherObject() );
-    if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) )
+    if ( checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, aResList, aProfile ) )
     {
       QString aProfileName = aProfile->GetObjPyName();
       if ( !aProfileName.isEmpty() )
       {
-        aResList << QString( "%1.SetProfileUZ( %2.GetProfileUZ() );" )
+        aResList << QString( "%1.SetProfileUZ( %2.GetProfileUZ() )" )
                      .arg( aPolylineName ).arg( aProfileName );
       }
     }
@@ -96,23 +102,23 @@ QStringList HYDROData_Polyline3D::DumpToPython( MapOfTreatedObjects& theTreatedO
       {
         Handle(HYDROData_Profile) aProfile = 
           Handle(HYDROData_Profile)::DownCast( aChildProfileUZ->GetFatherObject() );
-        if ( checkObjectPythonDefinition( theTreatedObjects, aResList, aProfile ) )
+        if ( checkObjectPythonDefinition( thePyScriptPath, theTreatedObjects, aResList, aProfile ) )
         {
           QString aProfileName = aProfile->GetObjPyName();
           if ( !aProfileName.isEmpty() )
           {
-            aResList << QString( "%1.SetChildProfileUZ( %2.GetProfileUZ() );" )
+            aResList << QString( "%1.SetChildProfileUZ( %2.GetProfileUZ() )" )
                          .arg( aPolylineName ).arg( aProfileName );
           }
         }
       }
 
-      setPythonReferenceObject( theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" );
+      setPythonReferenceObject( thePyScriptPath, theTreatedObjects, aResList, aRefBathymetry, "SetAltitudeObject" );
     }
   }
 
   aResList << QString( "" );
-  aResList << QString( "%1.Update();" ).arg( aPolylineName );
+  aResList << QString( "%1.Update()" ).arg( aPolylineName );
   aResList << QString( "" );
 
   return aResList;
@@ -147,9 +153,22 @@ void HYDROData_Polyline3D::Update()
 
   bool anIsSectionClosed = aPolylineXY->IsClosedSection( 0 );
   HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
+  NCollection_Sequence<Polyline3DPoint> aResPoints = GetProfilePoints3D();
+
+  TopoDS_Wire aResWire = HYDROData_PolylineXY::BuildWire( aSectionType, anIsSectionClosed, aResPoints );
+  SetTopShape( aResWire );
+  SetShape3D( aResWire );
+} 
+
+HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetProfilePoints3D()
+{
+  Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
+  if ( aPolylineXY.IsNull() )
+    return Polyline3DPoints();
+
   HYDROData_IPolyline::PointsList aPolylinePoints = aPolylineXY->GetPoints( 0 );
   if ( aPolylinePoints.IsEmpty() )
-    return;
+    return Polyline3DPoints();
 
   Handle(HYDROData_ProfileUZ) aProfileUZ = GetProfileUZ();
 
@@ -158,11 +177,11 @@ void HYDROData_Polyline3D::Update()
     aProfileUZ = GetChildProfileUZ();
 
   if ( aProfileUZ.IsNull() )
-    return;
+    return Polyline3DPoints();
 
   HYDROData_IPolyline::PointsList aProfilePoints = aProfileUZ->GetPoints();
   if ( aProfilePoints.IsEmpty() )
-    return;
+    return NCollection_Sequence<HYDROData_Polyline3D::Polyline3DPoint>();
 
   const HYDROData_IPolyline::Point& aFirstPoint = aPolylinePoints.First();
   const HYDROData_IPolyline::Point& aLastPoint = aPolylinePoints.Last();
@@ -194,10 +213,8 @@ void HYDROData_Polyline3D::Update()
   // 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 );
-} 
+  return aResPoints;
+}
 
 QColor HYDROData_Polyline3D::DefaultFillingColor() const
 {
@@ -416,7 +433,7 @@ void HYDROData_Polyline3D::removeChildProfileUZ()
   */
 }
 
-HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetPoints() const
+HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetPoints( double theEqDistance ) const
 {
   Polyline3DPoints aPoints;
 
@@ -467,7 +484,29 @@ HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetPoints() const
     } else {
       // Get points from spline curve
       Standard_Real aStart, anEnd;
-      Handle(Geom_Curve) aCurve = BRep_Tool::Curve( TopoDS::Edge( anEdges.First() ), aStart, anEnd );
+      TopoDS_Edge anEdge = TopoDS::Edge( anEdges.First() );
+      Handle(Geom_Curve) aCurve = BRep_Tool::Curve( anEdge, aStart, anEnd );
+
+      if( theEqDistance > 0 )
+      {
+        GeomAdaptor_Curve anAdaptorCurve( aCurve );
+        double aLength = GCPnts_AbscissaPoint::Length( anAdaptorCurve );
+        int aNbPoints = ceil( aLength / theEqDistance );
+        GCPnts_QuasiUniformAbscissa aDist( anAdaptorCurve, aNbPoints );
+        if( aDist.IsDone() )
+        {
+          aNbPoints = aDist.NbPoints();
+          for( int i=1; i<=aNbPoints; i++ )
+          {
+            double p = aDist.Parameter( i );
+            gp_Pnt aPnt;
+            aCurve->D0( p, aPnt );
+            aPoints.Append( aPnt.XYZ() );
+          }
+          return aPoints;
+        }
+      }
+
       Handle(Geom_BSplineCurve) aGeomSpline = Handle(Geom_BSplineCurve)::DownCast( aCurve );
 
       if ( !aGeomSpline.IsNull() ) {