Salome HOME
temporary fix to allow compliation, gcc 4.8, not used ?
[modules/hydro.git] / src / HYDROData / HYDROData_Polyline3D.cxx
index b2650b635d77f1ee52c2c5046f281dc6e5626875..15959d971f698ca5499aa347c7d7f3dc604470af 100644 (file)
@@ -1,8 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
-//
-// Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
-// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
-//
+// Copyright (C) 2014-2015  EDF-R&D
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
 #include "HYDROData_PolylineXY.h"
 #include "HYDROData_Profile.h"
 #include "HYDROData_ProfileUZ.h"
+#include "HYDROData_ShapesTool.h"
 #include "HYDROData_Tool.h"
 
+#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 <gp_XYZ.hxx>
 
+#include <TColStd_Array1OfReal.hxx>
+
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS_Vertex.hxx>
 #include <TopoDS_Wire.hxx>
 
+#include <TopExp.hxx>
+
+#include <TopExp_Explorer.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)
 
 
 HYDROData_Polyline3D::HYDROData_Polyline3D()
-: HYDROData_Object()
+: HYDROData_Object( Geom_3d )
 {
 }
 
@@ -52,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 );
       }
     }
@@ -85,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;
@@ -126,16 +143,6 @@ HYDROData_SequenceOfObjects HYDROData_Polyline3D::GetAllReferenceObjects() const
   return aResSeq;
 }
 
-TopoDS_Shape HYDROData_Polyline3D::GetTopShape() const
-{
-  return getTopShape();
-}
-
-TopoDS_Shape HYDROData_Polyline3D::GetShape3D() const
-{
-  return getShape3D();
-}
-
 void HYDROData_Polyline3D::Update()
 {
   HYDROData_Object::Update();
@@ -198,26 +205,16 @@ void HYDROData_Polyline3D::Update()
   SetShape3D( aResWire );
 } 
 
-QColor HYDROData_Polyline3D::DefaultFillingColor()
+QColor HYDROData_Polyline3D::DefaultFillingColor() const
 {
   return QColor( Qt::transparent );
 }
 
-QColor HYDROData_Polyline3D::DefaultBorderColor()
+QColor HYDROData_Polyline3D::DefaultBorderColor() const
 {
   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 )
 {
@@ -235,7 +232,7 @@ bool HYDROData_Polyline3D::SetPolylineXY( const Handle(HYDROData_PolylineXY)& th
     updateChildProfilePoints();
 
   // Indicate model of the need to update the polyline presentation
-  SetToUpdate( true );
+  Changed( Geom_2d );
 
   return true;
 }
@@ -255,7 +252,7 @@ void HYDROData_Polyline3D::RemovePolylineXY()
   ClearReferenceObjects( DataTag_PolylineXY );
 
   // Indicate model of the need to update the polyline presentation
-  SetToUpdate( true );
+  Changed( Geom_2d );
 }
 
 bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theProfile )
@@ -273,7 +270,7 @@ bool HYDROData_Polyline3D::SetProfileUZ( const Handle(HYDROData_ProfileUZ)& theP
   RemoveAltitudeObject();
 
   // Indicate model of the need to update the polyline presentation
-  SetToUpdate( true );
+  Changed( Geom_Z );
 
   return true;
 }
@@ -293,7 +290,7 @@ void HYDROData_Polyline3D::RemoveProfileUZ()
   ClearReferenceObjects( DataTag_ProfileUZ );
 
   // Indicate model of the need to update the polyline presentation
-  SetToUpdate( true );
+  Changed( Geom_Z );
 }
 
 bool HYDROData_Polyline3D::SetAltitudeObject( 
@@ -425,4 +422,98 @@ void HYDROData_Polyline3D::removeChildProfileUZ()
   */
 }
 
+HYDROData_Polyline3D::Polyline3DPoints HYDROData_Polyline3D::GetPoints( double theEqDistance ) const
+{
+  Polyline3DPoints aPoints;
+
+  Handle(HYDROData_PolylineXY) aPolylineXY = GetPolylineXY();
+  TopoDS_Wire aWire = TopoDS::Wire( GetShape3D() );
+  if ( aPolylineXY.IsNull() || aWire.IsNull() ) {
+    return aPoints; 
+  }
+
+  // Explode polyline on edges
+  TopTools_SequenceOfShape anEdges;
+  HYDROData_ShapesTool::ExploreShapeToShapes( aWire, TopAbs_EDGE, anEdges );
+
+  // Get points
+  if ( !anEdges.IsEmpty() ) {
+    HYDROData_IPolyline::SectionType aSectionType = aPolylineXY->GetSectionType( 0 );
+    
+    if ( aSectionType == HYDROData_IPolyline::SECTION_POLYLINE ) {
+      // Get points from wire
+      /* Seems that intermediate vertices are duplicated
+      TopExp_Explorer anExp( aWire, TopAbs_VERTEX );
+      for ( ; anExp.More(); anExp.Next() ) {
+        TopoDS_Vertex aVertex = TopoDS::Vertex( anExp.Current() );
+        if ( !aVertex.IsNull() ) {
+          gp_Pnt aPnt = BRep_Tool::Pnt( aVertex );
+          aPoints.Append( aPnt.XYZ() );
+        }
+      }
+      */
+      TopExp_Explorer anExp( aWire, TopAbs_EDGE );
+      bool isFirst = true;
+      for ( ; anExp.More(); anExp.Next() ) {
+        TopoDS_Edge anEdge = TopoDS::Edge( anExp.Current() );
+        if ( !anEdge.IsNull() ) {
+          TopoDS_Vertex aV1, aV2;
+          TopExp::Vertices( anEdge, aV1, aV2 );
+          if ( isFirst ) {
+            gp_Pnt aPnt1 = BRep_Tool::Pnt( aV1 );
+            aPoints.Append( aPnt1.XYZ() );
+          }
+
+          gp_Pnt aPnt2 = BRep_Tool::Pnt( aV2 );
+          aPoints.Append( aPnt2.XYZ() );
+
+          isFirst = false;
+        }
+      }
+    } else {
+      // Get points from spline curve
+      Standard_Real 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() ) {
+        int aNbKnots = aGeomSpline->NbKnots();
+
+        TColStd_Array1OfReal aSplineKnots( 1, aNbKnots );
+        aGeomSpline->Knots( aSplineKnots );
+
+        for ( int i = 1; i <= aNbKnots; ++i ) {
+          const Standard_Real& aKnot = aSplineKnots.Value( i );
+          gp_Pnt aPnt;
+          aGeomSpline->D0( aKnot, aPnt );
+          aPoints.Append( aPnt.XYZ() );
+        }
+      }
+    }
+  }
+
+  return aPoints; 
+}