0026377: Passing Handle objects as arguments to functions as non-const reference...
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_TKI.cxx
CommitLineData
b311480e 1// Created on: 1997-09-17
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1997-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 8// This library is free software; you can redistribute it and/or modify it under
9// the terms of the GNU Lesser General Public License version 2.1 as published
973c2be1 10// by the Free Software Foundation, with special exception defined in the file
11// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12// distribution for complete text of the license and disclaimer of any warranty.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
42cf5bc1 17
18#include <Standard_ProgramError.hxx>
19#include <TopOpeBRepDS.hxx>
20#include <TopOpeBRepDS_DataMapIteratorOfDataMapOfIntegerListOfInterference.hxx>
21#include <TopOpeBRepDS_DataMapOfIntegerListOfInterference.hxx>
7fd59977 22#include <TopOpeBRepDS_define.hxx>
23#include <TopOpeBRepDS_EXPORT.hxx>
42cf5bc1 24#include <TopOpeBRepDS_Interference.hxx>
25#include <TopOpeBRepDS_TKI.hxx>
7fd59977 26
27// extras define
7fd59977 28#define MDSdmoiloi TopOpeBRepDS_DataMapOfIntegerListOfInterference
29#define MDSdmiodmoiloi TopOpeBRepDS_DataMapIteratorOfDataMapOfIntegerListOfInterference
30#define MDShaodmoiloi TopOpeBRepDS_HArray1OfDataMapOfIntegerListOfInterference
31
32//=======================================================================
33//function : TopOpeBRepDS_TKI
34//purpose :
35//=======================================================================
36TopOpeBRepDS_TKI::TopOpeBRepDS_TKI()
37{
38 Reset();
39}
40
41//=======================================================================
42//function : Reset
43//purpose : private
44//=======================================================================
45void TopOpeBRepDS_TKI::Reset()
46{
47 Standard_Integer ip = (Standard_Integer)TopOpeBRepDS_POINT;
48 Standard_Integer is = (Standard_Integer)TopOpeBRepDS_SOLID;
49 if (ip > is ) {
50 Standard_ProgramError::Raise("TopOpeBRepDS_TKI : enumeration badly ordered");
51 return;
52 }
53 Standard_Integer f = 1; // first index of table
54 Standard_Integer l = f + (is-ip); // last index of table
55 mydelta = f - ip;
56 // k + mydelta = i in [f,l]; TopOpeBRepDS_POINT,SOLID + mydelta = f,l
57 if (myT.IsNull()) myT = new MDShaodmoiloi(f,l);
58 Clear();
59 myK = TopOpeBRepDS_UNKNOWN;
60 myG = 0;
61}
62
63//=======================================================================
64//function : Clear
65//purpose :
66//=======================================================================
67void TopOpeBRepDS_TKI::Clear()
68{
69 Standard_Integer i=myT->Lower(), n=myT->Upper();
70 for (; i<=n; i++) myT->ChangeValue(i).Clear();
71}
72
73//=======================================================================
74//function : FillOnGeometry
75//purpose :
76//=======================================================================
77void TopOpeBRepDS_TKI::FillOnGeometry(const TopOpeBRepDS_ListOfInterference& L)
78{
79 for(TopOpeBRepDS_ListIteratorOfListOfInterference it(L);it.More();it.Next()) {
80 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
81 TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S;
82 FDS_data(I,GT,G,ST,S);
83 Add(GT,G,I);
84 }
85}
86
87//=======================================================================
88//function : FillOnSupport
89//purpose :
90//=======================================================================
91void TopOpeBRepDS_TKI::FillOnSupport(const TopOpeBRepDS_ListOfInterference& L)
92{
93 for(TopOpeBRepDS_ListIteratorOfListOfInterference it(L);it.More();it.Next()) {
94 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
95 TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S;
96 FDS_data(I,GT,G,ST,S);
97 Add(ST,S,I);
98 }
99}
100
101//=======================================================================
102//function : IsBound
103//purpose :
104//=======================================================================
105Standard_Boolean TopOpeBRepDS_TKI::IsBound(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
106{
107 if (!IsValidKG(K,G)) return Standard_False;
108 Standard_Integer TI = KindToTableIndex(K);
109 Standard_Boolean in = myT->Value(TI).IsBound(G);
110 return in;
111}
112
113//=======================================================================
114//function : Interferences
115//purpose :
116//=======================================================================
117const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::Interferences
118(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
119{
120 Standard_Boolean in = IsBound(K,G);
121 Standard_Integer TI = KindToTableIndex(K);
122 if ( in ) return myT->Value(TI).Find(G);
123 return myEmptyLOI;
124}
125
126//=======================================================================
127//function : ChangeInterferences
128//purpose :
129//=======================================================================
130TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::ChangeInterferences(const TopOpeBRepDS_Kind K,const Standard_Integer G)
131{
132 Standard_Boolean in = IsBound(K,G);
133 Standard_Integer TI = KindToTableIndex(K);
134 if ( in ) return myT->ChangeValue(TI).ChangeFind(G);
135 return myEmptyLOI;
136}
137
138//=======================================================================
139//function : HasInterferences
140//purpose :
141//=======================================================================
142Standard_Boolean TopOpeBRepDS_TKI::HasInterferences(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
143{
144 Standard_Boolean has = IsBound(K,G);
145 if ( has ) {
146 const TopOpeBRepDS_ListOfInterference& loi = Interferences(K,G);
147 Standard_Integer l = loi.Extent();
148 has = (l != 0 ) ;
149 }
150 return has;
151}
152
153//=======================================================================
154//function : Add
155//purpose :
156//=======================================================================
157void TopOpeBRepDS_TKI::Add(const TopOpeBRepDS_Kind K,const Standard_Integer G)
158{
159 Standard_Boolean ok = IsValidKG(K,G);
160 if (!ok) {
161 Standard_ProgramError::Raise("TopOpeBRepDS_TKI : Add K G");
162 return;
163 }
164
165 Standard_Boolean in = IsBound(K,G);
166 Standard_Integer TI = KindToTableIndex(K);
167 TopOpeBRepDS_ListOfInterference thelist;
168 if ( !in )
169 myT->ChangeValue(TI).Bind(G, thelist);
170}
171
172//=======================================================================
173//function : Add
174//purpose :
175//=======================================================================
176void TopOpeBRepDS_TKI::Add(const TopOpeBRepDS_Kind K,const Standard_Integer G,const Handle(TopOpeBRepDS_Interference)& HI)
177{
178 Standard_Boolean ok = IsValidKG(K,G);
179 if (!ok) Standard_ProgramError::Raise("TopOpeBRepDS_TKI : Add K G HI");
180
181 Add(K,G);
182 ChangeInterferences(K,G).Append(HI);
183}
184
185//=======================================================================
186//function : DumpTKI
187//purpose :
188//=======================================================================
189void TopOpeBRepDS_TKI::DumpTKI
190(const TCollection_AsciiString& s1,const TCollection_AsciiString& s2) const
191{
192 if (myT.IsNull()) return;
193 cout<<s1;
194 for (Standard_Integer i=myT->Lower();i<=myT->Upper();i++) {
195 TopOpeBRepDS_Kind k = TableIndexToKind(i);
196 DumpTKI(k);
197 }
198 cout<<s2;
199 cout.flush();
200}
201
202//=======================================================================
203//function : DumpTKI
204//purpose :
205//=======================================================================
206void TopOpeBRepDS_TKI::DumpTKI
207(const TopOpeBRepDS_Kind K,const TCollection_AsciiString&,const TCollection_AsciiString&) const
208{
209 if (myT.IsNull()) return;
210 Standard_Integer TI = KindToTableIndex(K);
211 const MDSdmoiloi& M = myT->Value(TI);
212 for (MDSdmiodmoiloi it(M);it.More();it.Next()) {
213 Standard_Integer G = it.Key();
214 DumpTKI(K,G,"","\n");
215 }
216}
217
218//=======================================================================
219//function : DumpTKI
220//purpose :
221//=======================================================================
222void TopOpeBRepDS_TKI::DumpTKI
223(const TopOpeBRepDS_Kind K,const Standard_Integer G,const TCollection_AsciiString& s1,const TCollection_AsciiString& s2) const
224{
225 if (!HasInterferences(K,G)) return;
226 const TopOpeBRepDS_ListOfInterference& loi = Interferences(K,G);
227 DumpTKI(K,G,loi,s1,s2);
228}
229
230//=======================================================================
231//function : DumpTKI
232//purpose :
233//=======================================================================
234void TopOpeBRepDS_TKI::DumpTKI
235(const TopOpeBRepDS_Kind K,const Standard_Integer G,const TopOpeBRepDS_ListOfInterference& L,const TCollection_AsciiString& s1,const TCollection_AsciiString& s2) const
236{
237 if (!HasInterferences(K,G)) return;
238 TCollection_AsciiString s;
239 if (s1.Length()) s = s1;
240 else s = TopOpeBRepDS::SPrint(K,G,"at "," : ");
241 TCollection_AsciiString sb(s.Length(),' ');
242 Standard_Integer i=0;
243 for (TopOpeBRepDS_ListIteratorOfListOfInterference it(L);it.More();it.Next(),i++) {
244 if (i) it.Value()->Dump(cout,sb,s2);
245 else it.Value()->Dump(cout,s,s2);
246 }
247}
248
249//=======================================================================
250//function : DumpTKIIterator
251//purpose :
252//=======================================================================
253void TopOpeBRepDS_TKI::DumpTKIIterator(const TCollection_AsciiString& s1,const TCollection_AsciiString& s2)
254{
255 cout<<s1;
256 Init();
257 while (More()) {
258 TopOpeBRepDS_Kind K;Standard_Integer G; const TopOpeBRepDS_ListOfInterference& L = Value(K,G);
259 DumpTKI(K,G,L,"","\n");
260 Next();
261 }
262 cout<<s2;
263 cout.flush();
264}
265
266//=======================================================================
267//function : Init
268//purpose :
269//=======================================================================
270void TopOpeBRepDS_TKI::Init()
271{
272 myK = TopOpeBRepDS_UNKNOWN;
273 myG = 0;
274 if (myT.IsNull()) return;
275 myTI = myT->Lower(); myK = TableIndexToKind(myTI);
276 myITM.Initialize(myT->Value(myTI));
277 Find();
278}
279
280//=======================================================================
281//function : More
282//purpose :
283//=======================================================================
284Standard_Boolean TopOpeBRepDS_TKI::More() const
285{
286 Standard_Boolean b = IsValidKG(myK,myG);
287 return b;
288}
289
290//=======================================================================
291//function : Next
292//purpose :
293//=======================================================================
294void TopOpeBRepDS_TKI::Next()
295{
296 if ( MoreITM() ) {
297 NextITM();
298 Find();
299 }
300 else if ( MoreTI() ) {
301 NextTI();
302 if (MoreTI()) {
303 myITM.Initialize(myT->Value(myTI));
304 }
305 Find();
306 }
307}
308
309//=======================================================================
310//function : Value
311//purpose :
312//=======================================================================
313const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::Value(TopOpeBRepDS_Kind& K,Standard_Integer& G) const
314{
315 if ( !More() ) return myEmptyLOI;
316 K = myK; G = myG;
317 return Interferences(K,G);
318}
319
320//=======================================================================
321//function : ChangeValue
322//purpose :
323//=======================================================================
324TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::ChangeValue(TopOpeBRepDS_Kind& K,Standard_Integer& G)
325{
326 if ( !More() ) return myEmptyLOI;
327 K = myK; G = myG;
328 return ChangeInterferences(K,G);
329}
330
331//=======================================================================
332//function : MoreTI
333//purpose :
334//=======================================================================
335Standard_Boolean TopOpeBRepDS_TKI::MoreTI() const
336{
337 Standard_Boolean b = IsValidTI(myTI);
338 return b;
339}
340
341//=======================================================================
342//function : NextTI
343//purpose :
344//=======================================================================
345void TopOpeBRepDS_TKI::NextTI()
346{
347 myTI = myTI + 1; myK = TableIndexToKind(myTI);
348}
349
350//=======================================================================
351//function : MoreITM
352//purpose :
353//=======================================================================
354Standard_Boolean TopOpeBRepDS_TKI::MoreITM() const
355{
356 Standard_Boolean b = myITM.More();
357 return b;
358}
359
360//=======================================================================
361//function : FindITM
362//purpose :
363//=======================================================================
364void TopOpeBRepDS_TKI::FindITM()
365{
366 Standard_Boolean f = Standard_False;
367 while (MoreITM()) {
368 myG = myITM.Key();
369 f = HasInterferences(myK,myG);
370 if (f) break;
371 else myITM.Next();
372 }
373}
374
375//=======================================================================
376//function : NextITM
377//purpose :
378//=======================================================================
379void TopOpeBRepDS_TKI::NextITM()
380{
381 if ( !MoreITM() ) return;
382 myITM.Next();
383 FindITM();
384}
385
386//=======================================================================
387//function : Find
388//purpose :
389//=======================================================================
390void TopOpeBRepDS_TKI::Find()
391{
392 Standard_Boolean f = Standard_False;
393 while (MoreTI()) {
394 while (MoreITM()) {
395 FindITM();
396 f = HasInterferences(myK,myG);
397 if (f) break;
398 }
399 if (f) break;
400 else {
401 NextTI();
402 if (MoreTI()) {
403 myITM.Initialize(myT->Value(myTI));
404 }
405 }
406 }
407}
408
409//=======================================================================
410//function : KindToTableIndex
411//purpose : private
412//=======================================================================
413Standard_Integer TopOpeBRepDS_TKI::KindToTableIndex(const TopOpeBRepDS_Kind K) const
414{
415 // K(Kind) + mydelta = TI(integer) = index in myT
416 Standard_Integer TI = (Standard_Integer)K + mydelta;
417 return TI;
418}
419
420//=======================================================================
421//function : TableIndexToKind
422//purpose : private
423//=======================================================================
424TopOpeBRepDS_Kind TopOpeBRepDS_TKI::TableIndexToKind(const Standard_Integer TI) const
425{
426 // K(Kind) + mydelta = TI(integer) = index in myT
427 TopOpeBRepDS_Kind K = (TopOpeBRepDS_Kind)(TI - mydelta);
428 return K;
429}
430
431//=======================================================================
432//function : IsValidTI
433//purpose : private
434//=======================================================================
435Standard_Boolean TopOpeBRepDS_TKI::IsValidTI(const Standard_Integer TI) const
436{
437 if ( myT.IsNull() ) return Standard_False;
438 Standard_Boolean nok = ( TI < myT->Lower() || TI > myT->Upper() );
439 return !nok;
440}
441
442//=======================================================================
443//function : IsValidK
444//purpose : private
445//=======================================================================
446Standard_Boolean TopOpeBRepDS_TKI::IsValidK(const TopOpeBRepDS_Kind K) const
447{
448 Standard_Boolean nok = ( K < TopOpeBRepDS_POINT || K > TopOpeBRepDS_SOLID );
449 return !nok;
450}
451
452//=======================================================================
453//function : IsValidG
454//purpose : private
455//=======================================================================
456Standard_Boolean TopOpeBRepDS_TKI::IsValidG(const Standard_Integer G) const
457{
458 Standard_Boolean nok = (G <= 0);
459 return !nok;
460}
461
462//=======================================================================
463//function : IsValidKG
464//purpose : private
465//=======================================================================
466Standard_Boolean TopOpeBRepDS_TKI::IsValidKG(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
467{
468 Standard_Boolean nok = (!IsValidK(K) || !IsValidG(G));
469 return !nok;
470}