Salome HOME
#refs 522 (very draft) //import only
[modules/hydro.git] / src / HYDROData / HYDROData_ProfileUZ.cxx
index d8ccba4e236cad9d0652b775da8e489342ec95bc..a91549c5ce3ab85fdc25116e05330bcd4019b916 100755 (executable)
@@ -1,12 +1,37 @@
+// 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
+//
+// 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
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
 
 #include "HYDROData_ProfileUZ.h"
 
 #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 +49,47 @@ HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
 {
 }
 
-TopoDS_Shape HYDROData_ProfileUZ::GetShape()
+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 +113,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