Salome HOME
New calculation case dialog layout is implemented. Two lists of geometry objects...
[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_Wire.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_Wire HYDROData_ProfileUZ::GetWire() const
28 {
29   // TODO
30   return TopoDS_Wire();
31 }
32
33 int HYDROData_ProfileUZ::NbSections() const
34 {
35   return 1;
36 }
37
38 void HYDROData_ProfileUZ::AddSection( const bool /*theIsClosed*/ )
39 {
40 }
41
42 bool HYDROData_ProfileUZ::IsClosedSection( const int /*theSectionIndex*/ ) const
43 {
44   return false;
45 }
46
47 void HYDROData_ProfileUZ::RemoveSection( const int /*theSectionIndex*/ )
48 {
49   RemoveSections();
50 }
51
52 void HYDROData_ProfileUZ::RemoveSections()
53 {
54   removePointsLists( 0 );
55 }
56
57 void HYDROData_ProfileUZ::AddPoint( const int    /*theSectionIndex*/,
58                                     const Point& thePoint,
59                                     const int    thePointIndex )
60 {
61   double aNewCoordU = thePoint.X();
62   double aNewCoordZ = thePoint.Y();
63
64   Handle(TDataStd_RealList) aListU, aListZ;
65   getPointsLists( 0, aListU, aListZ );
66
67   if ( aListU->IsEmpty() || aNewCoordU > aListU->Last() )
68   {
69     aListU->Append( aNewCoordU );
70     aListZ->Append( aNewCoordZ );
71     return;
72   }
73   else if ( aNewCoordU < aListU->First() )
74   {
75     aListU->Prepend( aNewCoordU );
76     aListZ->Prepend( aNewCoordZ );
77     return;
78   }
79
80   TColStd_ListOfReal anOldListU;
81   anOldListU = aListU->List();
82
83   TColStd_ListOfReal anOldListZ;
84   anOldListZ = aListZ->List();
85
86   // Crsat new lists
87   removePointsLists( 0 );
88   getPointsLists( 0, aListU, aListZ );
89
90   bool anIsInserted = false;
91   TColStd_ListIteratorOfListOfReal anIterU( anOldListU );
92   TColStd_ListIteratorOfListOfReal anIterZ( anOldListZ );
93   for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
94   {
95     double aCoordU = anIterU.Value();
96     double aCoordZ = anIterZ.Value();
97
98     if ( !anIsInserted )
99     {
100       if ( ValuesEquals( aNewCoordU, aCoordU ) )
101       {
102         // Just update Z value
103         aCoordZ = aNewCoordZ;
104         anIsInserted = true;
105       }
106       else if ( aNewCoordU < aCoordU )
107       {
108         // Insert new point
109         aListU->Append( aNewCoordU );
110         aListZ->Append( aNewCoordZ );
111         anIsInserted = true;
112       }
113     }
114
115     aListU->Append( aCoordU );
116     aListZ->Append( aCoordZ );
117   }
118 }
119
120 void HYDROData_ProfileUZ::SetPoint( const int    theSectionIndex,
121                                     const int    /*thePointIndex*/,
122                                     const Point& thePoint )
123 {
124   AddPoint( theSectionIndex, thePoint );
125 }
126
127 void HYDROData_ProfileUZ::RemovePoint( const int /*theSectionIndex*/,
128                                        const int thePointIndex )
129 {
130   Handle(TDataStd_RealList) aListU, aListZ;
131   getPointsLists( 0, aListU, aListZ, false );
132   if ( aListU.IsNull() || aListZ.IsNull() || aListU->IsEmpty() )
133     return;
134
135   TColStd_ListOfReal anOldListU;
136   anOldListU = aListU->List();
137
138   TColStd_ListOfReal anOldListZ;
139   anOldListZ = aListZ->List();
140
141   // Creat new lists
142   removePointsLists( 0 );
143   getPointsLists( 0, aListU, aListZ );
144
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 )
149   {
150     if ( i == thePointIndex )
151       continue; // skip index to remove
152
153     aListU->Append( anIterU.Value() );
154     aListZ->Append( anIterZ.Value() );
155   }
156 }
157
158 HYDROData_ProfileUZ::PointsList HYDROData_ProfileUZ::GetPoints( const int /*theSectionIndex*/ ) const
159 {
160   PointsList aResList;
161
162   Handle(TDataStd_RealList) aListU, aListZ;
163   getPointsLists( 0, aListU, aListZ, false );
164   if ( aListU.IsNull() || aListZ.IsNull() )
165     return aResList;
166
167   TColStd_ListIteratorOfListOfReal anIterU( aListU->List() );
168   TColStd_ListIteratorOfListOfReal anIterZ( aListZ->List() );
169   for ( ; anIterU.More() && anIterZ.More(); anIterU.Next(), anIterZ.Next() )
170   {
171     Point aPoint( anIterU.Value(), anIterZ.Value() );
172     aResList.Append( aPoint );
173   }
174
175   return aResList;
176 }
177
178