2 #include "HYDROData_ProfileUZ.h"
4 #include "HYDROData_Tool.h"
8 #include <TColStd_ListIteratorOfListOfReal.hxx>
10 #include <TDataStd_RealList.hxx>
12 #include <TopoDS_Wire.hxx>
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ProfileUZ, HYDROData_IPolyline)
18 HYDROData_ProfileUZ::HYDROData_ProfileUZ()
19 : HYDROData_IPolyline()
23 HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
27 TopoDS_Wire HYDROData_ProfileUZ::GetWire() const
33 int HYDROData_ProfileUZ::NbSections() const
38 void HYDROData_ProfileUZ::AddSection( const bool /*theIsClosed*/ )
42 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
47 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
52 void HYDROData_ProfileUZ::RemoveSections()
54 removePointsLists( 0 );
57 void HYDROData_ProfileUZ::AddPoint( const int /*theSectionIndex*/,
58 const Point& thePoint,
59 const int thePointIndex )
61 double aNewCoordU = thePoint.X();
62 double aNewCoordZ = thePoint.Y();
64 Handle(TDataStd_RealList) aListU, aListZ;
65 getPointsLists( 0, aListU, aListZ );
67 if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
69 aListU->Append( aNewCoordU );
70 aListZ->Append( aNewCoordZ );
73 else if ( aNewCoordU < aListU->First() )
75 aListU->Prepend( aNewCoordU );
76 aListZ->Prepend( aNewCoordZ );
80 TColStd_ListOfReal anOldListU;
81 anOldListU = aListU->List();
83 TColStd_ListOfReal anOldListZ;
84 anOldListZ = aListZ->List();
87 removePointsLists( 0 );
88 getPointsLists( 0, aListU, aListZ );
90 bool anIsInserted = false;
91 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
92 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
93 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
95 double aCoordU = anIterU.Value();
96 double aCoordZ = anIterZ.Value();
100 if ( ValuesEquals( aNewCoordU, aCoordU ) )
102 // Just update Z value
103 aCoordZ = aNewCoordZ;
106 else if ( aNewCoordU < aCoordU )
109 aListU->Append( aNewCoordU );
110 aListZ->Append( aNewCoordZ );
115 aListU->Append( aCoordU );
116 aListZ->Append( aCoordZ );
120 void HYDROData_ProfileUZ::SetPoint( const int theSectionIndex,
121 const int /*thePointIndex*/,
122 const Point& thePoint )
124 AddPoint( theSectionIndex, thePoint );
127 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
128 const int thePointIndex )
130 Handle(TDataStd_RealList) aListU, aListZ;
131 getPointsLists( 0, aListU, aListZ, false );
132 if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
135 TColStd_ListOfReal anOldListU;
136 anOldListU = aListU->List();
138 TColStd_ListOfReal anOldListZ;
139 anOldListZ = aListZ->List();
142 removePointsLists( 0 );
143 getPointsLists( 0, aListU, aListZ );
145 bool anIsInserted = false;
146 TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
147 TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
148 for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
150 if ( i == thePointIndex )
151 continue; // skip index to remove
153 aListU->Append( anIterU.Value() );
154 aListZ->Append( anIterZ.Value() );
158 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
162 Handle(TDataStd_RealList) aListU, aListZ;
163 getPointsLists( 0, aListU, aListZ, false );
164 if ( aListU.IsNull() || aListZ.IsNull() )
167 TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
168 TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
169 for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
171 Point aPoint( anIterU.Value(), anIterZ.Value() );
172 aResList.Append( aPoint );