1 // Copyright (C) 2014-2015 EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 // Lesser General Public License for more details.
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 #include "HYDROData_ProfileUZ.h"
21 #include "HYDROData_Tool.h"
24 #include <gp_Pnt2d.hxx>
26 #include <TColStd_ListIteratorOfListOfReal.hxx>
28 #include <TDataStd_BooleanList.hxx>
29 #include <TDataStd_ExtStringList.hxx>
30 #include <TDataStd_IntegerList.hxx>
31 #include <TDataStd_RealList.hxx>
33 #include <TopoDS_Shape.hxx>
36 IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline)
37 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ProfileUZ, HYDROData_IPolyline)
39 HYDROData_ProfileUZ::HYDROData_ProfileUZ()
40 : HYDROData_IPolyline()
44 HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
48 TopoDS_Shape HYDROData_ProfileUZ::GetShape() const
50 return TopoDS_Shape();
53 double HYDROData_ProfileUZ::GetDepthFromDistance( const PointsList& thePoints,
54 const double& theDistance )
56 double aResDepth = 0.0;
58 int aNbPoints = thePoints.Size();
62 double aCompDist = 0.0;
63 HYDROData_IPolyline::Point aPrevPoint = thePoints.First();
64 for ( int i = 2; i <= aNbPoints; ++i )
66 const Point& aCurPoint = thePoints.Value( i );
68 double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) );
70 aCompDist += aPntDist;
72 if ( theDistance < aCompDist )
74 double aComPntDist = gp_Pnt2d( thePoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) );
76 double aFindDist = theDistance - aComPntDist;
77 double aRatio = aFindDist / ( aPntDist - aFindDist );
79 aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio );
83 aPrevPoint = aCurPoint;
89 int HYDROData_ProfileUZ::NbSections() const
94 void HYDROData_ProfileUZ::AddSection( const TCollection_AsciiString& /*theSectName*/,
95 const SectionType /*theSectionType*/,
96 const bool /*theIsClosed*/ )
100 TCollection_AsciiString HYDROData_ProfileUZ::GetSectionName( const int /*theSectionIndex*/ ) const
105 void HYDROData_ProfileUZ::SetSectionName( const int /*theSectionIndex*/,
106 const TCollection_AsciiString& /*theSectionName*/ )
110 HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const
112 Handle(TDataStd_ExtStringList) aNamesList;
113 Handle(TDataStd_IntegerList) aTypesList;
114 Handle(TDataStd_BooleanList) aClosuresList;
115 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
116 if ( aTypesList.IsNull() || aTypesList->IsEmpty() )
117 return SECTION_POLYLINE;
119 return (SectionType)aTypesList->First();
122 void HYDROData_ProfileUZ::SetSectionType( const int /*theSectionIndex*/,
123 const SectionType theSectionType )
125 Handle(TDataStd_ExtStringList) aNamesList;
126 Handle(TDataStd_IntegerList) aTypesList;
127 Handle(TDataStd_BooleanList) aClosuresList;
128 getSectionsLists( aNamesList, aTypesList, aClosuresList );
129 if ( aTypesList.IsNull() )
132 // Refill the existing list
134 aTypesList->Append( theSectionType );
137 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
142 void HYDROData_ProfileUZ::SetSectionClosed( const int /*theSectionIndex*/,
143 const bool /*theIsClosed*/ )
147 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
152 void HYDROData_ProfileUZ::RemoveSections()
154 removePointsLists( 0 );
157 void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/,
158 const Point& thePoint,
159 const int thePointIndex )
161 double aNewCoordU = thePoint.X();
162 double aNewCoordZ = thePoint.Y();
164 Handle(TDataStd_RealList) aListU, aListZ;
165 getPointsLists( 0, aListU, aListZ );
167 if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
169 aListU->Append( aNewCoordU );
170 aListZ->Append( aNewCoordZ );
173 else if ( aNewCoordU < aListU->First() )
175 aListU->Prepend( aNewCoordU );
176 aListZ->Prepend( aNewCoordZ );
180 TColStd_ListOfReal anOldListU;
181 anOldListU = aListU->List();
183 TColStd_ListOfReal anOldListZ;
184 anOldListZ = aListZ->List();
187 removePointsLists( 0 );
188 getPointsLists( 0, aListU, aListZ );
190 bool anIsInserted = false;
191 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
192 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
193 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
195 double aCoordU = anIterU.Value();
196 double aCoordZ = anIterZ.Value();
200 if ( ValuesEquals( aNewCoordU, aCoordU ) )
202 // Just update Z value
203 aCoordZ = aNewCoordZ;
206 else if ( aNewCoordU < aCoordU )
209 aListU->Append( aNewCoordU );
210 aListZ->Append( aNewCoordZ );
215 aListU->Append( aCoordU );
216 aListZ->Append( aCoordZ );
220 void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex,
221 const Point& thePoint,
222 const int /*thePointIndex*/ )
224 AddPoint( theSectionIndex, thePoint );
227 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
228 const int thePointIndex )
230 Handle(TDataStd_RealList) aListU, aListZ;
231 getPointsLists( 0, aListU, aListZ, false );
232 if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
235 TColStd_ListOfReal anOldListU;
236 anOldListU = aListU->List();
238 TColStd_ListOfReal anOldListZ;
239 anOldListZ = aListZ->List();
242 removePointsLists( 0 );
243 getPointsLists( 0, aListU, aListZ );
245 bool anIsInserted = false;
246 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
247 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
248 for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
250 if ( i == thePointIndex )
251 continue; // skip index to remove
253 aListU->Append( anIterU.Value() );
254 aListZ->Append( anIterZ.Value() );
258 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
262 Handle(TDataStd_RealList) aListU, aListZ;
263 getPointsLists( 0, aListU, aListZ, false );
264 if ( aListU.IsNull() || aListZ.IsNull() )
267 TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
268 TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
269 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
271 Point aPoint( anIterU.Value(), anIterZ.Value() );
272 aResList.Append( aPoint );