2 #include "HYDROData_ProfileUZ.h"
4 #include "HYDROData_Tool.h"
7 #include <gp_Pnt2d.hxx>
9 #include <TColStd_ListIteratorOfListOfReal.hxx>
11 #include <TDataStd_BooleanList.hxx>
12 #include <TDataStd_ExtStringList.hxx>
13 #include <TDataStd_IntegerList.hxx>
14 #include <TDataStd_RealList.hxx>
16 #include <TopoDS_Shape.hxx>
19 IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline)
20 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ProfileUZ, HYDROData_IPolyline)
22 HYDROData_ProfileUZ::HYDROData_ProfileUZ()
23 : HYDROData_IPolyline()
27 HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
31 TopoDS_Shape HYDROData_ProfileUZ::GetShape() const
34 return TopoDS_Shape();
37 double HYDROData_ProfileUZ::GetDepthFromDistance( const PointsList& thePoints,
38 const double& theDistance )
40 double aResDepth = 0.0;
42 int aNbPoints = thePoints.Size();
46 double aCompDist = 0.0;
47 HYDROData_IPolyline::Point aPrevPoint = thePoints.First();
48 for ( int i = 2; i <= aNbPoints; ++i )
50 const Point& aCurPoint = thePoints.Value( i );
52 double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) );
54 aCompDist += aPntDist;
56 if ( theDistance < aCompDist )
58 double aComPntDist = gp_Pnt2d( thePoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) );
60 double aFindDist = theDistance - aComPntDist;
61 double aRatio = aFindDist / ( aPntDist - aFindDist );
63 aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio );
67 aPrevPoint = aCurPoint;
73 int HYDROData_ProfileUZ::NbSections() const
78 void HYDROData_ProfileUZ::AddSection( const TCollection_AsciiString& /*theSectName*/,
79 const SectionType /*theSectionType*/,
80 const bool /*theIsClosed*/ )
84 TCollection_AsciiString HYDROData_ProfileUZ::GetSectionName( const int /*theSectionIndex*/ ) const
89 void HYDROData_ProfileUZ::SetSectionName( const int /*theSectionIndex*/,
90 const TCollection_AsciiString& /*theSectionName*/ )
94 HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const
96 Handle(TDataStd_ExtStringList) aNamesList;
97 Handle(TDataStd_IntegerList) aTypesList;
98 Handle(TDataStd_BooleanList) aClosuresList;
99 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
100 if ( aTypesList.IsNull() || aTypesList->IsEmpty() )
101 return SECTION_POLYLINE;
103 return (SectionType)aTypesList->First();
106 void HYDROData_ProfileUZ::SetSectionType( const int /*theSectionIndex*/,
107 const SectionType theSectionType )
109 Handle(TDataStd_ExtStringList) aNamesList;
110 Handle(TDataStd_IntegerList) aTypesList;
111 Handle(TDataStd_BooleanList) aClosuresList;
112 getSectionsLists( aNamesList, aTypesList, aClosuresList );
113 if ( aTypesList.IsNull() )
116 // Refill the existing list
118 aTypesList->Append( theSectionType );
121 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
126 void HYDROData_ProfileUZ::SetSectionClosed( const int /*theSectionIndex*/,
127 const bool /*theIsClosed*/ )
131 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
136 void HYDROData_ProfileUZ::RemoveSections()
138 removePointsLists( 0 );
141 void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/,
142 const Point& thePoint,
143 const int thePointIndex )
145 double aNewCoordU = thePoint.X();
146 double aNewCoordZ = thePoint.Y();
148 Handle(TDataStd_RealList) aListU, aListZ;
149 getPointsLists( 0, aListU, aListZ );
151 if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
153 aListU->Append( aNewCoordU );
154 aListZ->Append( aNewCoordZ );
157 else if ( aNewCoordU < aListU->First() )
159 aListU->Prepend( aNewCoordU );
160 aListZ->Prepend( aNewCoordZ );
164 TColStd_ListOfReal anOldListU;
165 anOldListU = aListU->List();
167 TColStd_ListOfReal anOldListZ;
168 anOldListZ = aListZ->List();
171 removePointsLists( 0 );
172 getPointsLists( 0, aListU, aListZ );
174 bool anIsInserted = false;
175 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
176 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
177 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
179 double aCoordU = anIterU.Value();
180 double aCoordZ = anIterZ.Value();
184 if ( ValuesEquals( aNewCoordU, aCoordU ) )
186 // Just update Z value
187 aCoordZ = aNewCoordZ;
190 else if ( aNewCoordU < aCoordU )
193 aListU->Append( aNewCoordU );
194 aListZ->Append( aNewCoordZ );
199 aListU->Append( aCoordU );
200 aListZ->Append( aCoordZ );
204 void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex,
205 const Point& thePoint,
206 const int /*thePointIndex*/ )
208 AddPoint( theSectionIndex, thePoint );
211 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
212 const int thePointIndex )
214 Handle(TDataStd_RealList) aListU, aListZ;
215 getPointsLists( 0, aListU, aListZ, false );
216 if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
219 TColStd_ListOfReal anOldListU;
220 anOldListU = aListU->List();
222 TColStd_ListOfReal anOldListZ;
223 anOldListZ = aListZ->List();
226 removePointsLists( 0 );
227 getPointsLists( 0, aListU, aListZ );
229 bool anIsInserted = false;
230 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
231 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
232 for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
234 if ( i == thePointIndex )
235 continue; // skip index to remove
237 aListU->Append( anIterU.Value() );
238 aListZ->Append( anIterZ.Value() );
242 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
246 Handle(TDataStd_RealList) aListU, aListZ;
247 getPointsLists( 0, aListU, aListZ, false );
248 if ( aListU.IsNull() || aListZ.IsNull() )
251 TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
252 TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
253 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
255 Point aPoint( anIterU.Value(), anIterZ.Value() );
256 aResList.Append( aPoint );