2 #include "HYDROData_ProfileUZ.h"
4 #include "HYDROData_Tool.h"
7 #include <gp_Pnt2d.hxx>
9 #include <TColStd_ListIteratorOfListOfReal.hxx>
11 #include <TDataStd_RealList.hxx>
13 #include <TopoDS_Shape.hxx>
16 IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline)
17 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ProfileUZ, HYDROData_IPolyline)
19 HYDROData_ProfileUZ::HYDROData_ProfileUZ()
20 : HYDROData_IPolyline()
24 HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
28 TopoDS_Shape HYDROData_ProfileUZ::GetShape()
31 return TopoDS_Shape();
34 double HYDROData_ProfileUZ::GetDepthFromDistance( const double& theDistance ) const
36 double aResDepth = 0.0;
38 HYDROData_IPolyline::PointsList aPoints = GetPoints();
39 int aNbPoints = aPoints.Size();
43 double aCompDist = 0.0;
44 HYDROData_IPolyline::Point aPrevPoint = aPoints.First();
45 for ( int i = 2; i <= aNbPoints; ++i )
47 const Point& aCurPoint = aPoints.Value( i );
49 double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) );
51 aCompDist += aPntDist;
53 if ( theDistance < aCompDist )
55 double aComPntDist = gp_Pnt2d( aPoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) );
57 double aFindDist = theDistance - aComPntDist;
58 double aRatio = aFindDist / ( aPntDist - aFindDist );
60 aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio );
64 aPrevPoint = aCurPoint;
70 int HYDROData_ProfileUZ::NbSections() const
75 void HYDROData_ProfileUZ::AddSection( const TCollection_AsciiString& /*theSectName*/,
76 const SectionType /*theSectionType*/,
77 const bool /*theIsClosed*/ )
81 TCollection_AsciiString HYDROData_ProfileUZ::GetSectionName( const int /*theSectionIndex*/ ) const
86 void HYDROData_ProfileUZ::SetSectionName( const int /*theSectionIndex*/,
87 const TCollection_AsciiString& /*theSectionName*/ )
91 HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const
93 return SECTION_POLYLINE;
96 void HYDROData_ProfileUZ::SetSectionType( const int /*theSectionIndex*/,
97 const SectionType /*theSectionType*/ )
101 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
106 void HYDROData_ProfileUZ::SetSectionClosed( const int /*theSectionIndex*/,
107 const bool /*theIsClosed*/ )
111 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
116 void HYDROData_ProfileUZ::RemoveSections()
118 removePointsLists( 0 );
121 void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/,
122 const Point& thePoint,
123 const int thePointIndex )
125 double aNewCoordU = thePoint.X();
126 double aNewCoordZ = thePoint.Y();
128 Handle(TDataStd_RealList) aListU, aListZ;
129 getPointsLists( 0, aListU, aListZ );
131 if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
133 aListU->Append( aNewCoordU );
134 aListZ->Append( aNewCoordZ );
137 else if ( aNewCoordU < aListU->First() )
139 aListU->Prepend( aNewCoordU );
140 aListZ->Prepend( aNewCoordZ );
144 TColStd_ListOfReal anOldListU;
145 anOldListU = aListU->List();
147 TColStd_ListOfReal anOldListZ;
148 anOldListZ = aListZ->List();
151 removePointsLists( 0 );
152 getPointsLists( 0, aListU, aListZ );
154 bool anIsInserted = false;
155 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
156 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
157 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
159 double aCoordU = anIterU.Value();
160 double aCoordZ = anIterZ.Value();
164 if ( ValuesEquals( aNewCoordU, aCoordU ) )
166 // Just update Z value
167 aCoordZ = aNewCoordZ;
170 else if ( aNewCoordU < aCoordU )
173 aListU->Append( aNewCoordU );
174 aListZ->Append( aNewCoordZ );
179 aListU->Append( aCoordU );
180 aListZ->Append( aCoordZ );
184 void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex,
185 const Point& thePoint,
186 const int /*thePointIndex*/ )
188 AddPoint( theSectionIndex, thePoint );
191 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
192 const int thePointIndex )
194 Handle(TDataStd_RealList) aListU, aListZ;
195 getPointsLists( 0, aListU, aListZ, false );
196 if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
199 TColStd_ListOfReal anOldListU;
200 anOldListU = aListU->List();
202 TColStd_ListOfReal anOldListZ;
203 anOldListZ = aListZ->List();
206 removePointsLists( 0 );
207 getPointsLists( 0, aListU, aListZ );
209 bool anIsInserted = false;
210 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
211 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
212 for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
214 if ( i == thePointIndex )
215 continue; // skip index to remove
217 aListU->Append( anIterU.Value() );
218 aListZ->Append( anIterZ.Value() );
222 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
226 Handle(TDataStd_RealList) aListU, aListZ;
227 getPointsLists( 0, aListU, aListZ, false );
228 if ( aListU.IsNull() || aListZ.IsNull() )
231 TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
232 TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
233 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
235 Point aPoint( anIterU.Value(), anIterZ.Value() );
236 aResList.Append( aPoint );