Salome HOME
Dump of profile is implemented.
[modules/hydro.git] / src / HYDROData / HYDROData_ProfileUZ.cxx
index d8ccba4e236cad9d0652b775da8e489342ec95bc..09fc5234de188ee49bcd28eb8e02cc8cac57873c 100755 (executable)
@@ -4,9 +4,13 @@
 #include "HYDROData_Tool.h"
 
 #include <gp_XY.hxx>
+#include <gp_Pnt2d.hxx>
 
 #include <TColStd_ListIteratorOfListOfReal.hxx>
 
+#include <TDataStd_BooleanList.hxx>
+#include <TDataStd_ExtStringList.hxx>
+#include <TDataStd_IntegerList.hxx>
 #include <TDataStd_RealList.hxx>
 
 #include <TopoDS_Shape.hxx>
@@ -24,12 +28,77 @@ HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
 {
 }
 
-TopoDS_Shape HYDROData_ProfileUZ::GetShape()
+QStringList HYDROData_ProfileUZ::DumpToPython( MapOfTreatedObjects& theTreatedObjects ) const
+{
+  QStringList aResList = dumpObjectCreation( theTreatedObjects );
+  QString aName = GetName();
+
+  // Set polilyne data
+  const TCollection_AsciiString& aSectName = GetSectionName( 0 );
+  const SectionType& aSectType = GetSectionType( 0 );
+  bool aSectClosure = IsClosedSection( 0 );
+
+  aResList << QString( "%1.AddSection( \"%2\", %3, %4 );" ).arg( aName )
+              .arg( aSectName.ToCString() ).arg( aSectType ).arg( aSectClosure );
+
+  HYDROData_IPolyline::PointsList aSectPointsList = GetPoints( 0 );
+  for ( int k = 1, aNbPoints = aSectPointsList.Size(); k <= aNbPoints; ++k )
+  {
+    const Point& aSectPoint = aSectPointsList.Value( k );
+
+    aResList << QString( "%1.AddPoint( 0, QPointF( %2, %3 ) );" ).arg( aName )
+      .arg( aSectPoint.X() ).arg( aSectPoint.Y() );
+  }
+
+  aResList << QString( "" );
+  aResList << QString( "%1.Update();" ).arg( aName );
+  aResList << QString( "" );
+
+  return aResList;
+}
+
+TopoDS_Shape HYDROData_ProfileUZ::GetShape() const
 {
   // TODO
   return TopoDS_Shape();
 }
 
+double HYDROData_ProfileUZ::GetDepthFromDistance( const PointsList& thePoints,
+                                                  const double&     theDistance )
+{
+  double aResDepth = 0.0;
+
+  int aNbPoints = thePoints.Size();
+  if ( aNbPoints < 2 )
+    return aResDepth;
+
+  double aCompDist = 0.0;
+  HYDROData_IPolyline::Point aPrevPoint = thePoints.First();
+  for ( int i = 2; i <= aNbPoints; ++i )
+  {
+    const Point& aCurPoint = thePoints.Value( i );
+
+    double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) );
+
+    aCompDist += aPntDist;
+
+    if ( theDistance < aCompDist )
+    {
+      double aComPntDist = gp_Pnt2d( thePoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) );
+
+      double aFindDist = theDistance - aComPntDist;
+      double aRatio = aFindDist / ( aPntDist - aFindDist );
+
+      aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio );
+      break;
+    }
+
+    aPrevPoint = aCurPoint;
+  }
+
+  return aResDepth;
+}
+
 int HYDROData_ProfileUZ::NbSections() const
 {
   return 1;
@@ -53,12 +122,29 @@ void HYDROData_ProfileUZ::SetSectionName( const int                      /*theSe
 
 HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const
 {
-  return SECTION_POLYLINE;
+  Handle(TDataStd_ExtStringList) aNamesList;
+  Handle(TDataStd_IntegerList) aTypesList;
+  Handle(TDataStd_BooleanList) aClosuresList;
+  getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
+  if ( aTypesList.IsNull() || aTypesList->IsEmpty() )
+    return SECTION_POLYLINE;
+
+  return (SectionType)aTypesList->First();
 }
 
 void HYDROData_ProfileUZ::SetSectionType( const int         /*theSectionIndex*/, 
-                                          const SectionType /*theSectionType*/ )
+                                          const SectionType theSectionType )
 {
+  Handle(TDataStd_ExtStringList) aNamesList;
+  Handle(TDataStd_IntegerList) aTypesList;
+  Handle(TDataStd_BooleanList) aClosuresList;
+  getSectionsLists( aNamesList, aTypesList, aClosuresList );
+  if ( aTypesList.IsNull()  )
+    return;
+
+  // Refill the existing list
+  aTypesList->Clear();
+  aTypesList->Append( theSectionType );
 }
 
 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const