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
33 return TopoDS_Shape();
36 double HYDROData_ProfileUZ::GetDepthFromDistance( const PointsList& thePoints,
37 const double& theDistance )
39 double aResDepth = 0.0;
41 int aNbPoints = thePoints.Size();
45 double aCompDist = 0.0;
46 HYDROData_IPolyline::Point aPrevPoint = thePoints.First();
47 for ( int i = 2; i <= aNbPoints; ++i )
49 const Point& aCurPoint = thePoints.Value( i );
51 double aPntDist = gp_Pnt2d( aPrevPoint.X(), 0 ).Distance( gp_Pnt2d( aCurPoint.X(), 0 ) );
53 aCompDist += aPntDist;
55 if ( theDistance < aCompDist )
57 double aComPntDist = gp_Pnt2d( thePoints.First().X(), 0 ).Distance( gp_Pnt2d( aPrevPoint.X(), 0 ) );
59 double aFindDist = theDistance - aComPntDist;
60 double aRatio = aFindDist / ( aPntDist - aFindDist );
62 aResDepth = ( aPrevPoint.Y() + aRatio * aCurPoint.Y() ) / ( 1 + aRatio );
66 aPrevPoint = aCurPoint;
72 int HYDROData_ProfileUZ::NbSections() const
77 void HYDROData_ProfileUZ::AddSection( const TCollection_AsciiString& /*theSectName*/,
78 const SectionType /*theSectionType*/,
79 const bool /*theIsClosed*/ )
83 TCollection_AsciiString HYDROData_ProfileUZ::GetSectionName( const int /*theSectionIndex*/ ) const
88 void HYDROData_ProfileUZ::SetSectionName( const int /*theSectionIndex*/,
89 const TCollection_AsciiString& /*theSectionName*/ )
93 HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const
95 Handle(TDataStd_ExtStringList) aNamesList;
96 Handle(TDataStd_IntegerList) aTypesList;
97 Handle(TDataStd_BooleanList) aClosuresList;
98 getSectionsLists( aNamesList, aTypesList, aClosuresList, false );
99 if ( aTypesList.IsNull() || aTypesList->IsEmpty() )
100 return SECTION_POLYLINE;
102 return (SectionType)aTypesList->First();
105 void HYDROData_ProfileUZ::SetSectionType( const int /*theSectionIndex*/,
106 const SectionType theSectionType )
108 Handle(TDataStd_ExtStringList) aNamesList;
109 Handle(TDataStd_IntegerList) aTypesList;
110 Handle(TDataStd_BooleanList) aClosuresList;
111 getSectionsLists( aNamesList, aTypesList, aClosuresList );
112 if ( aTypesList.IsNull() )
115 // Refill the existing list
117 aTypesList->Append( theSectionType );
120 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
125 void HYDROData_ProfileUZ::SetSectionClosed( const int /*theSectionIndex*/,
126 const bool /*theIsClosed*/ )
130 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
135 void HYDROData_ProfileUZ::RemoveSections()
137 removePointsLists( 0 );
140 void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/,
141 const Point& thePoint,
142 const int thePointIndex )
144 double aNewCoordU = thePoint.X();
145 double aNewCoordZ = thePoint.Y();
147 Handle(TDataStd_RealList) aListU, aListZ;
148 getPointsLists( 0, aListU, aListZ );
150 if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
152 aListU->Append( aNewCoordU );
153 aListZ->Append( aNewCoordZ );
156 else if ( aNewCoordU < aListU->First() )
158 aListU->Prepend( aNewCoordU );
159 aListZ->Prepend( aNewCoordZ );
163 TColStd_ListOfReal anOldListU;
164 anOldListU = aListU->List();
166 TColStd_ListOfReal anOldListZ;
167 anOldListZ = aListZ->List();
170 removePointsLists( 0 );
171 getPointsLists( 0, aListU, aListZ );
173 bool anIsInserted = false;
174 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
175 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
176 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
178 double aCoordU = anIterU.Value();
179 double aCoordZ = anIterZ.Value();
183 if ( ValuesEquals( aNewCoordU, aCoordU ) )
185 // Just update Z value
186 aCoordZ = aNewCoordZ;
189 else if ( aNewCoordU < aCoordU )
192 aListU->Append( aNewCoordU );
193 aListZ->Append( aNewCoordZ );
198 aListU->Append( aCoordU );
199 aListZ->Append( aCoordZ );
203 void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex,
204 const Point& thePoint,
205 const int /*thePointIndex*/ )
207 AddPoint( theSectionIndex, thePoint );
210 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
211 const int thePointIndex )
213 Handle(TDataStd_RealList) aListU, aListZ;
214 getPointsLists( 0, aListU, aListZ, false );
215 if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
218 TColStd_ListOfReal anOldListU;
219 anOldListU = aListU->List();
221 TColStd_ListOfReal anOldListZ;
222 anOldListZ = aListZ->List();
225 removePointsLists( 0 );
226 getPointsLists( 0, aListU, aListZ );
228 bool anIsInserted = false;
229 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
230 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
231 for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
233 if ( i == thePointIndex )
234 continue; // skip index to remove
236 aListU->Append( anIterU.Value() );
237 aListZ->Append( anIterZ.Value() );
241 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
245 Handle(TDataStd_RealList) aListU, aListZ;
246 getPointsLists( 0, aListU, aListZ, false );
247 if ( aListU.IsNull() || aListZ.IsNull() )
250 TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
251 TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
252 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
254 Point aPoint( anIterU.Value(), anIterZ.Value() );
255 aResList.Append( aPoint );