1 // Created on: 1997-09-17
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1997-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Standard_ProgramError.hxx>
19 #include <TopOpeBRepDS.hxx>
20 #include <TopOpeBRepDS_DataMapIteratorOfDataMapOfIntegerListOfInterference.hxx>
21 #include <TopOpeBRepDS_EXPORT.hxx>
22 #include <TopOpeBRepDS_Interference.hxx>
23 #include <TopOpeBRepDS_TKI.hxx>
26 #define MDSdmoiloi TopOpeBRepDS_DataMapOfIntegerListOfInterference
27 #define MDSdmiodmoiloi TopOpeBRepDS_DataMapIteratorOfDataMapOfIntegerListOfInterference
28 #define MDShaodmoiloi TopOpeBRepDS_HArray1OfDataMapOfIntegerListOfInterference
30 //=======================================================================
31 //function : TopOpeBRepDS_TKI
33 //=======================================================================
34 TopOpeBRepDS_TKI::TopOpeBRepDS_TKI()
39 //=======================================================================
42 //=======================================================================
43 void TopOpeBRepDS_TKI::Reset()
45 Standard_Integer ip = (Standard_Integer)TopOpeBRepDS_POINT;
46 Standard_Integer is = (Standard_Integer)TopOpeBRepDS_SOLID;
48 throw Standard_ProgramError("TopOpeBRepDS_TKI : enumeration badly ordered");
51 Standard_Integer f = 1; // first index of table
52 Standard_Integer l = f + (is-ip); // last index of table
54 // k + mydelta = i in [f,l]; TopOpeBRepDS_POINT,SOLID + mydelta = f,l
55 if (myT.IsNull()) myT = new MDShaodmoiloi(f,l);
57 myK = TopOpeBRepDS_UNKNOWN;
61 //=======================================================================
64 //=======================================================================
65 void TopOpeBRepDS_TKI::Clear()
67 Standard_Integer i=myT->Lower(), n=myT->Upper();
68 for (; i<=n; i++) myT->ChangeValue(i).Clear();
71 //=======================================================================
72 //function : FillOnGeometry
74 //=======================================================================
75 void TopOpeBRepDS_TKI::FillOnGeometry(const TopOpeBRepDS_ListOfInterference& L)
77 for(TopOpeBRepDS_ListIteratorOfListOfInterference it(L);it.More();it.Next()) {
78 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
79 TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S;
80 FDS_data(I,GT,G,ST,S);
85 //=======================================================================
86 //function : FillOnSupport
88 //=======================================================================
89 void TopOpeBRepDS_TKI::FillOnSupport(const TopOpeBRepDS_ListOfInterference& L)
91 for(TopOpeBRepDS_ListIteratorOfListOfInterference it(L);it.More();it.Next()) {
92 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
93 TopOpeBRepDS_Kind GT,ST; Standard_Integer G,S;
94 FDS_data(I,GT,G,ST,S);
99 //=======================================================================
102 //=======================================================================
103 Standard_Boolean TopOpeBRepDS_TKI::IsBound(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
105 if (!IsValidKG(K,G)) return Standard_False;
106 Standard_Integer TI = KindToTableIndex(K);
107 Standard_Boolean in = myT->Value(TI).IsBound(G);
111 //=======================================================================
112 //function : Interferences
114 //=======================================================================
115 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::Interferences
116 (const TopOpeBRepDS_Kind K,const Standard_Integer G) const
118 Standard_Boolean in = IsBound(K,G);
119 Standard_Integer TI = KindToTableIndex(K);
120 if ( in ) return myT->Value(TI).Find(G);
124 //=======================================================================
125 //function : ChangeInterferences
127 //=======================================================================
128 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::ChangeInterferences(const TopOpeBRepDS_Kind K,const Standard_Integer G)
130 Standard_Boolean in = IsBound(K,G);
131 Standard_Integer TI = KindToTableIndex(K);
132 if ( in ) return myT->ChangeValue(TI).ChangeFind(G);
136 //=======================================================================
137 //function : HasInterferences
139 //=======================================================================
140 Standard_Boolean TopOpeBRepDS_TKI::HasInterferences(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
142 Standard_Boolean has = IsBound(K,G);
144 const TopOpeBRepDS_ListOfInterference& loi = Interferences(K,G);
145 Standard_Integer l = loi.Extent();
151 //=======================================================================
154 //=======================================================================
155 void TopOpeBRepDS_TKI::Add(const TopOpeBRepDS_Kind K,const Standard_Integer G)
157 Standard_Boolean ok = IsValidKG(K,G);
159 throw Standard_ProgramError("TopOpeBRepDS_TKI : Add K G");
163 Standard_Boolean in = IsBound(K,G);
164 Standard_Integer TI = KindToTableIndex(K);
165 TopOpeBRepDS_ListOfInterference thelist;
167 myT->ChangeValue(TI).Bind(G, thelist);
170 //=======================================================================
173 //=======================================================================
174 void TopOpeBRepDS_TKI::Add(const TopOpeBRepDS_Kind K,const Standard_Integer G,const Handle(TopOpeBRepDS_Interference)& HI)
176 Standard_Boolean ok = IsValidKG(K,G);
177 if (!ok) throw Standard_ProgramError("TopOpeBRepDS_TKI : Add K G HI");
180 ChangeInterferences(K,G).Append(HI);
183 //=======================================================================
184 //function : DumpTKIIterator
186 //=======================================================================
187 void TopOpeBRepDS_TKI::DumpTKIIterator(const TCollection_AsciiString& s1,const TCollection_AsciiString& s2)
192 TopOpeBRepDS_Kind K;Standard_Integer G;
200 //=======================================================================
203 //=======================================================================
204 void TopOpeBRepDS_TKI::Init()
206 myK = TopOpeBRepDS_UNKNOWN;
208 if (myT.IsNull()) return;
209 myTI = myT->Lower(); myK = TableIndexToKind(myTI);
210 myITM.Initialize(myT->Value(myTI));
214 //=======================================================================
217 //=======================================================================
218 Standard_Boolean TopOpeBRepDS_TKI::More() const
220 Standard_Boolean b = IsValidKG(myK,myG);
224 //=======================================================================
227 //=======================================================================
228 void TopOpeBRepDS_TKI::Next()
234 else if ( MoreTI() ) {
237 myITM.Initialize(myT->Value(myTI));
243 //=======================================================================
246 //=======================================================================
247 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::Value(TopOpeBRepDS_Kind& K,Standard_Integer& G) const
249 if ( !More() ) return myEmptyLOI;
251 return Interferences(K,G);
254 //=======================================================================
255 //function : ChangeValue
257 //=======================================================================
258 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::ChangeValue(TopOpeBRepDS_Kind& K,Standard_Integer& G)
260 if ( !More() ) return myEmptyLOI;
262 return ChangeInterferences(K,G);
265 //=======================================================================
268 //=======================================================================
269 Standard_Boolean TopOpeBRepDS_TKI::MoreTI() const
271 Standard_Boolean b = IsValidTI(myTI);
275 //=======================================================================
278 //=======================================================================
279 void TopOpeBRepDS_TKI::NextTI()
281 myTI = myTI + 1; myK = TableIndexToKind(myTI);
284 //=======================================================================
287 //=======================================================================
288 Standard_Boolean TopOpeBRepDS_TKI::MoreITM() const
290 Standard_Boolean b = myITM.More();
294 //=======================================================================
297 //=======================================================================
298 void TopOpeBRepDS_TKI::FindITM()
300 Standard_Boolean f = Standard_False;
303 f = HasInterferences(myK,myG);
309 //=======================================================================
312 //=======================================================================
313 void TopOpeBRepDS_TKI::NextITM()
315 if ( !MoreITM() ) return;
320 //=======================================================================
323 //=======================================================================
324 void TopOpeBRepDS_TKI::Find()
326 Standard_Boolean f = Standard_False;
330 f = HasInterferences(myK,myG);
337 myITM.Initialize(myT->Value(myTI));
343 //=======================================================================
344 //function : KindToTableIndex
346 //=======================================================================
347 Standard_Integer TopOpeBRepDS_TKI::KindToTableIndex(const TopOpeBRepDS_Kind K) const
349 // K(Kind) + mydelta = TI(integer) = index in myT
350 Standard_Integer TI = (Standard_Integer)K + mydelta;
354 //=======================================================================
355 //function : TableIndexToKind
357 //=======================================================================
358 TopOpeBRepDS_Kind TopOpeBRepDS_TKI::TableIndexToKind(const Standard_Integer TI) const
360 // K(Kind) + mydelta = TI(integer) = index in myT
361 TopOpeBRepDS_Kind K = (TopOpeBRepDS_Kind)(TI - mydelta);
365 //=======================================================================
366 //function : IsValidTI
368 //=======================================================================
369 Standard_Boolean TopOpeBRepDS_TKI::IsValidTI(const Standard_Integer TI) const
371 if ( myT.IsNull() ) return Standard_False;
372 Standard_Boolean nok = ( TI < myT->Lower() || TI > myT->Upper() );
376 //=======================================================================
377 //function : IsValidK
379 //=======================================================================
380 Standard_Boolean TopOpeBRepDS_TKI::IsValidK(const TopOpeBRepDS_Kind K) const
382 Standard_Boolean nok = ( K < TopOpeBRepDS_POINT || K > TopOpeBRepDS_SOLID );
386 //=======================================================================
387 //function : IsValidG
389 //=======================================================================
390 Standard_Boolean TopOpeBRepDS_TKI::IsValidG(const Standard_Integer G) const
392 Standard_Boolean nok = (G <= 0);
396 //=======================================================================
397 //function : IsValidKG
399 //=======================================================================
400 Standard_Boolean TopOpeBRepDS_TKI::IsValidKG(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
402 Standard_Boolean nok = (!IsValidK(K) || !IsValidG(G));