Salome HOME
0016756: EDF 545 GEOM : Extrusion, give the coordinates of the vector as input
[modules/geom.git] / src / NMTDS / NMTDS_PassKey.cxx
1 // Copyright (C) 2005  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
3 // 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either 
7 // version 2.1 of the License.
8 // 
9 // This library is distributed in the hope that it will be useful 
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
12 // Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public  
15 // License along with this library; if not, write to the Free Software 
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
17 //
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
19 //
20 //
21 // File:        NMTDS_Algo.cxx
22 // Created:     Sat Dec 04 12:39:47 2004
23 // Author:      Peter KURNEV
24 //              <peter@PREFEX>
25
26
27 #include <NMTDS_PassKey.ixx>
28
29 #include <stdio.h>
30 #include <string.h>
31 #include <TColStd_ListIteratorOfListOfInteger.hxx>
32 #include <TColStd_ListOfInteger.hxx>
33
34 #ifdef WNT
35 #pragma warning( disable : 4101) 
36 #endif
37
38 static
39   Standard_Integer NormalizedId(const Standard_Integer aId,
40                                 const Standard_Integer aDiv);
41
42 //=======================================================================
43 //function :
44 //purpose  : 
45 //=======================================================================
46   NMTDS_PassKey::NMTDS_PassKey()
47 {
48  Clear(); 
49 }
50 //=======================================================================
51 //function :
52 //purpose  : 
53 //=======================================================================
54   NMTDS_PassKey::NMTDS_PassKey(const NMTDS_PassKey& aOther)
55 {
56   myNbIds=aOther.myNbIds;
57   mySum=aOther.mySum;
58   myMap=aOther.myMap;
59 }
60 //=======================================================================
61 //function :operator =
62 //purpose  : 
63 //=======================================================================
64   NMTDS_PassKey& NMTDS_PassKey::operator =(const NMTDS_PassKey& aOther)
65 {
66   myNbIds=aOther.myNbIds;
67   mySum=aOther.mySum;
68   myMap=aOther.myMap;
69   return *this;
70 }
71 //=======================================================================
72 //function :~
73 //purpose  : 
74 //=======================================================================
75   NMTDS_PassKey::~NMTDS_PassKey()
76 {
77 }
78 //=======================================================================
79 //function :Clear
80 //purpose  : 
81 //=======================================================================
82   void NMTDS_PassKey::Clear()
83 {
84   myNbIds=0;
85   mySum=0;
86   myMap.Clear();
87 }
88 //=======================================================================
89 //function :SetIds
90 //purpose  : 
91 //=======================================================================
92   void NMTDS_PassKey::SetIds(const Standard_Integer aId1)
93                                
94 {
95   Clear();
96   myNbIds=1;
97   myMap.Add(aId1);
98   mySum=NormalizedId(aId1, myNbIds);
99 }
100 //=======================================================================
101 //function :SetIds
102 //purpose  : 
103 //=======================================================================
104   void NMTDS_PassKey::SetIds(const Standard_Integer aId1,
105                              const Standard_Integer aId2)
106 {
107   TColStd_ListOfInteger aLI;
108   //
109   aLI.Append(aId1);
110   aLI.Append(aId2);
111   SetIds(aLI);
112 }
113 //=======================================================================
114 //function :SetIds
115 //purpose  : 
116 //=======================================================================
117   void NMTDS_PassKey::SetIds(const Standard_Integer aId1,
118                              const Standard_Integer aId2,
119                              const Standard_Integer aId3)
120 {
121   TColStd_ListOfInteger aLI;
122   //
123   aLI.Append(aId1);
124   aLI.Append(aId2);
125   aLI.Append(aId3);
126   SetIds(aLI);
127 }
128 //=======================================================================
129 //function :SetIds
130 //purpose  : 
131 //=======================================================================
132   void NMTDS_PassKey::SetIds(const Standard_Integer aId1,
133                              const Standard_Integer aId2,
134                              const Standard_Integer aId3,
135                              const Standard_Integer aId4)
136
137   TColStd_ListOfInteger aLI;
138   //
139   aLI.Append(aId1);
140   aLI.Append(aId2);
141   aLI.Append(aId3);
142   aLI.Append(aId4);
143   SetIds(aLI);
144 }
145 //=======================================================================
146 //function :SetIds
147 //purpose  : 
148 //=======================================================================
149   void NMTDS_PassKey::SetIds(const TColStd_ListOfInteger& aLI)
150 {
151   Standard_Integer i, aId, aIdN;
152   TColStd_ListIteratorOfListOfInteger aIt;
153   //
154   Clear();
155   aIt.Initialize(aLI);
156   for (; aIt.More(); aIt.Next()) {
157     aId=aIt.Value();
158     myMap.Add(aId);
159   }
160   myNbIds=myMap.Extent();
161   for(i=1; i<=myNbIds; ++i) {
162     aId=myMap(i);
163     aIdN=NormalizedId(aId, myNbIds);
164     mySum+=aIdN;
165   }
166 }
167
168 //=======================================================================
169 //function :NbIds
170 //purpose  : 
171 //=======================================================================
172   Standard_Integer NMTDS_PassKey::NbIds()const
173 {
174   return myNbIds;
175 }
176 //=======================================================================
177 //function :Id
178 //purpose  : 
179 //=======================================================================
180   Standard_Integer NMTDS_PassKey::Id(const Standard_Integer aIndex) const
181 {
182   if (aIndex<1 || aIndex>myNbIds) {
183     return -1;
184   }
185   return myMap(aIndex);
186 }
187 //=======================================================================
188 //function :Ids
189 //purpose  : 
190 //=======================================================================
191   void NMTDS_PassKey::Ids(Standard_Integer& aId1,
192                           Standard_Integer& aId2) const
193 {
194   aId1=0;
195   aId2=0;
196   if (myNbIds>1) {
197     aId1=myMap(1);
198     aId2=myMap(2);
199   }
200 }
201 //=======================================================================
202 //function :IsEqual
203 //purpose  : 
204 //=======================================================================
205   Standard_Boolean NMTDS_PassKey::IsEqual(const NMTDS_PassKey& aOther) const
206 {
207   Standard_Boolean bRet;
208   Standard_Integer i, aId;
209   //
210   bRet=Standard_False;
211   //
212   if (myNbIds!=aOther.myNbIds) {
213     return bRet;
214   }
215   for (i=1; i<=myNbIds; ++i) {
216     aId=myMap(i);
217     if (!aOther.myMap.Contains(aId)) {
218       return bRet;
219     }
220   }
221   return !bRet;
222 }
223 //=======================================================================
224 //function : HashCode
225 //purpose  : 
226 //=======================================================================
227   Standard_Integer NMTDS_PassKey::HashCode(const Standard_Integer aUpper) const
228 {
229   return ::HashCode(mySum, aUpper);
230 }
231 //=======================================================================
232 //function : Dump
233 //purpose  : 
234 //=======================================================================
235   void NMTDS_PassKey::Dump(const Standard_Integer )const
236 {
237 }
238
239 //=======================================================================
240 // function: NormalizedId
241 // purpose : 
242 //=======================================================================
243 Standard_Integer NormalizedId(const Standard_Integer aId,
244                               const Standard_Integer aDiv)
245 {
246   Standard_Integer aMax, aTresh, aIdRet;
247   //
248   aIdRet=aId;
249   aMax=::IntegerLast();
250   aTresh=aMax/aDiv;
251   if (aId>aTresh) {
252     aIdRet=aId%aTresh;
253   }
254   return aIdRet;
255 }
256 /*
257 //=========
258 //=======================================================================
259 //function : Contains
260 //purpose  : 
261 //=======================================================================
262   Standard_Boolean NMTDS_PassKey::Contains(const Standard_Integer aId) const
263 {
264   return myMap.Contains(aId);
265 }
266 //=======================================================================
267 //function :Contains
268 //purpose  : 
269 //=======================================================================
270   Standard_Boolean NMTDS_PassKey::Contains(const NMTDS_PassKey& aOther) const
271 {
272   Standard_Boolean bRet;
273   Standard_Integer i, aId;
274   //
275   bRet=Standard_False;
276   //
277   if (myNbIds<aOther.myNbIds) {
278     return bRet;
279   }
280   for (i=1; i<=aOther.myNbIds; ++i) {
281     aId=aOther.myMap(i);
282     if (!myMap.Contains(aId)) {
283       return bRet;
284     }
285   }
286   return !bRet;
287 }
288 //=======================================================================
289 //function :Intersected
290 //purpose  : 
291 //=======================================================================
292   Standard_Boolean NMTDS_PassKey::Intersected(const NMTDS_PassKey& aOther) const
293 {
294   Standard_Boolean bRet;
295   Standard_Integer i, aId;
296   //
297   bRet=Standard_False;
298   //
299   for (i=1; i<=myNbIds; ++i) {
300     aId=myMap(i);
301     if (aOther.Contains(aId)) {
302       return !bRet;
303     }
304   }
305   return bRet;
306 }
307 //=======================================================================
308 //function : Add
309 //purpose  : 
310 //=======================================================================
311   void NMTDS_PassKey::Add(const Standard_Integer aId)
312 {
313   TColStd_ListOfInteger aLI;
314   aLI.Append(aId);
315   //
316   Add(aLI);
317 }
318 //=======================================================================
319 //function : Add
320 //purpose  : 
321 //=======================================================================
322   void NMTDS_PassKey::Add(const NMTDS_PassKey& aOther) 
323 {
324   Standard_Integer i, aId;
325   TColStd_ListOfInteger aLS;
326   //
327   for(i=1; i<=myNbIds; ++i) {
328     aId=myMap(i);
329     aLS.Append(aId);
330   }
331   for(i=1; i<=aOther.myNbIds; ++i) {
332     aId=aOther.myMap(i);
333     aLS.Append(aId);
334   }
335   //
336   Add(aLS);
337 }
338 //=======================================================================
339 //function : Add
340 //purpose  : 
341 //=======================================================================
342   void NMTDS_PassKey::Add(const TColStd_ListOfInteger& aLI)
343 {
344   Standard_Integer i, aId;
345   TColStd_ListOfInteger aLS;
346   TColStd_ListIteratorOfListOfInteger aIt;
347   //
348   for(i=1; i<=myNbIds; ++i) {
349     aId=myMap(i);
350     aLS.Append(aId);
351   }
352   aIt.Initialize(aLI);
353   for (; aIt.More(); aIt.Next()) {
354     aId=aIt.Value();
355     aLS.Append(aId);
356   }
357   //
358   SetIds(aLS);
359 }
360 //=========
361 */