Salome HOME
Invalidate method added.
[modules/hydro.git] / src / HYDROData / HYDROData_ProfileUZ.cxx
1
2 #include "HYDROData_ProfileUZ.h"
3
4 #include "HYDROData_Tool.h"
5
6 #include <gp_XY.hxx>
7
8 #include <TColStd_ListIteratorOfListOfReal.hxx>
9
10 #include <TDataStd_RealList.hxx>
11
12 #include <TopoDS_Shape.hxx>
13
14
15 IMPLEMENT_STANDARD_HANDLE(HYDROData_ProfileUZ, HYDROData_IPolyline)
16 IMPLEMENT_STANDARD_RTTIEXT(HYDROData_ProfileUZ, HYDROData_IPolyline)
17
18 HYDROData_ProfileUZ::HYDROData_ProfileUZ()
19 : HYDROData_IPolyline()
20 {
21 }
22
23 HYDROData_ProfileUZ::~HYDROData_ProfileUZ()
24 {
25 }
26
27 TopoDS_Shape HYDROData_ProfileUZ::GetShape()
28 {
29   // TODO
30   return TopoDS_Shape();
31 }
32
33 int HYDROData_ProfileUZ::NbSections() const
34 {
35   return 1;
36 }
37
38 void HYDROData_ProfileUZ::AddSection( const TCollection_AsciiString& /*theSectName*/,
39                                       const SectionType              /*theSectionType*/,
40                                       const bool                     /*theIsClosed*/ )
41 {
42 }
43
44 TCollection_AsciiString HYDROData_ProfileUZ::GetSectionName( const int /*theSectionIndex*/ ) const
45 {
46   return "Section_1";
47 }
48
49 void HYDROData_ProfileUZ::SetSectionName( const int                      /*theSectionIndex*/, 
50                                           const TCollection_AsciiString& /*theSectionName*/ )
51 {
52 }
53
54 HYDROData_ProfileUZ::SectionType HYDROData_ProfileUZ::GetSectionType( const int /*theSectionIndex*/ ) const
55 {
56   return SECTION_POLYLINE;
57 }
58
59 void HYDROData_ProfileUZ::SetSectionType( const int         /*theSectionIndex*/, 
60                                           const SectionType /*theSectionType*/ )
61 {
62 }
63
64 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
65 {
66   return false;
67 }
68
69 void HYDROData_ProfileUZ::SetSectionClosed( const int  /*theSectionIndex*/, 
70                                             const bool /*theIsClosed*/ )
71 {
72 }
73
74 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
75 {
76   RemoveSections();
77 }
78
79 void HYDROData_ProfileUZ::RemoveSections()
80 {
81   removePointsLists( 0 );
82 }
83
84 void HYDROData_ProfileUZ::AddPoint( const int    /*theSectionIndex*/,
85                                     const Point& thePoint,
86                                     const int    thePointIndex )
87 {
88   double aNewCoordU = thePoint.X();
89   double aNewCoordZ = thePoint.Y();
90
91   Handle(TDataStd_RealList) aListU, aListZ;
92   getPointsLists( 0, aListU, aListZ );
93
94   if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
95   {
96     aListU->Append( aNewCoordU );
97     aListZ->Append( aNewCoordZ );
98     return;
99   }
100   else if ( aNewCoordU < aListU->First() )
101   {
102     aListU->Prepend( aNewCoordU );
103     aListZ->Prepend( aNewCoordZ );
104     return;
105   }
106
107   TColStd_ListOfReal anOldListU;
108   anOldListU = aListU->List();
109
110   TColStd_ListOfReal anOldListZ;
111   anOldListZ = aListZ->List();
112
113   // Crsat new lists
114   removePointsLists( 0 );
115   getPointsLists( 0, aListU, aListZ );
116
117   bool anIsInserted = false;
118   TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
119   TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
120   for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
121   {
122     double aCoordU = anIterU.Value();
123     double aCoordZ = anIterZ.Value();
124
125     if ( !anIsInserted )
126     {
127       if ( ValuesEquals( aNewCoordU, aCoordU ) )
128       {
129         // Just update Z value
130         aCoordZ = aNewCoordZ;
131         anIsInserted = true;
132       }
133       else if ( aNewCoordU < aCoordU )
134       {
135         // Insert new point
136         aListU->Append( aNewCoordU );
137         aListZ->Append( aNewCoordZ );
138         anIsInserted = true;
139       }
140     }
141
142     aListU->Append( aCoordU );
143     aListZ->Append( aCoordZ );
144   }
145 }
146
147 void HYDROData_ProfileUZ::SetPoint( const int    theSectionIndex,
148                                     const Point& thePoint,
149                                     const int    /*thePointIndex*/ )
150 {
151   AddPoint( theSectionIndex, thePoint );
152 }
153
154 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
155                                        const int thePointIndex )
156 {
157   Handle(TDataStd_RealList) aListU, aListZ;
158   getPointsLists( 0, aListU, aListZ, false );
159   if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
160     return;
161
162   TColStd_ListOfReal anOldListU;
163   anOldListU = aListU->List();
164
165   TColStd_ListOfReal anOldListZ;
166   anOldListZ = aListZ->List();
167
168   // Creat new lists
169   removePointsLists( 0 );
170   getPointsLists( 0, aListU, aListZ );
171
172   bool anIsInserted = false;
173   TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
174   TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
175   for ( int i = 0; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next(), ++i )
176   {
177     if ( i == thePointIndex )
178       continue; // skip index to remove
179
180     aListU->Append( anIterU.Value() );
181     aListZ->Append( anIterZ.Value() );
182   }
183 }
184
185 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
186 {
187   PointsList aResList;
188
189   Handle(TDataStd_RealList) aListU, aListZ;
190   getPointsLists( 0, aListU, aListZ, false );
191   if ( aListU.IsNull() || aListZ.IsNull() )
192     return aResList;
193
194   TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
195   TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
196   for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
197   {
198     Point aPoint( anIterU.Value(), anIterZ.Value() );
199     aResList.Append( aPoint );
200   }
201
202   return aResList;
203 }
204
205