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_DataMapOfIntegerListOfInterference.hxx>
22 #include <TopOpeBRepDS_define.hxx>
23 #include <TopOpeBRepDS_EXPORT.hxx>
24 #include <TopOpeBRepDS_Interference.hxx>
25 #include <TopOpeBRepDS_TKI.hxx>
28 #define MDSdmoiloi TopOpeBRepDS_DataMapOfIntegerListOfInterference
29 #define MDSdmiodmoiloi TopOpeBRepDS_DataMapIteratorOfDataMapOfIntegerListOfInterference
30 #define MDShaodmoiloi TopOpeBRepDS_HArray1OfDataMapOfIntegerListOfInterference
32 //=======================================================================
33 //function : TopOpeBRepDS_TKI
35 //=======================================================================
36 TopOpeBRepDS_TKI::TopOpeBRepDS_TKI()
41 //=======================================================================
44 //=======================================================================
45 void TopOpeBRepDS_TKI::Reset()
47 Standard_Integer ip = (Standard_Integer)TopOpeBRepDS_POINT;
48 Standard_Integer is = (Standard_Integer)TopOpeBRepDS_SOLID;
50 throw Standard_ProgramError("TopOpeBRepDS_TKI : enumeration badly ordered");
53 Standard_Integer f = 1; // first index of table
54 Standard_Integer l = f + (is-ip); // last index of table
56 // k + mydelta = i in [f,l]; TopOpeBRepDS_POINT,SOLID + mydelta = f,l
57 if (myT.IsNull()) myT = new MDShaodmoiloi(f,l);
59 myK = TopOpeBRepDS_UNKNOWN;
63 //=======================================================================
66 //=======================================================================
67 void TopOpeBRepDS_TKI::Clear()
69 Standard_Integer i=myT->Lower(), n=myT->Upper();
70 for (; i<=n; i++) myT->ChangeValue(i).Clear();
73 //=======================================================================
74 //function : FillOnGeometry
76 //=======================================================================
77 void TopOpeBRepDS_TKI::FillOnGeometry(const TopOpeBRepDS_ListOfInterference& L)
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);
87 //=======================================================================
88 //function : FillOnSupport
90 //=======================================================================
91 void TopOpeBRepDS_TKI::FillOnSupport(const TopOpeBRepDS_ListOfInterference& L)
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);
101 //=======================================================================
104 //=======================================================================
105 Standard_Boolean TopOpeBRepDS_TKI::IsBound(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
107 if (!IsValidKG(K,G)) return Standard_False;
108 Standard_Integer TI = KindToTableIndex(K);
109 Standard_Boolean in = myT->Value(TI).IsBound(G);
113 //=======================================================================
114 //function : Interferences
116 //=======================================================================
117 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::Interferences
118 (const TopOpeBRepDS_Kind K,const Standard_Integer G) const
120 Standard_Boolean in = IsBound(K,G);
121 Standard_Integer TI = KindToTableIndex(K);
122 if ( in ) return myT->Value(TI).Find(G);
126 //=======================================================================
127 //function : ChangeInterferences
129 //=======================================================================
130 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::ChangeInterferences(const TopOpeBRepDS_Kind K,const Standard_Integer G)
132 Standard_Boolean in = IsBound(K,G);
133 Standard_Integer TI = KindToTableIndex(K);
134 if ( in ) return myT->ChangeValue(TI).ChangeFind(G);
138 //=======================================================================
139 //function : HasInterferences
141 //=======================================================================
142 Standard_Boolean TopOpeBRepDS_TKI::HasInterferences(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
144 Standard_Boolean has = IsBound(K,G);
146 const TopOpeBRepDS_ListOfInterference& loi = Interferences(K,G);
147 Standard_Integer l = loi.Extent();
153 //=======================================================================
156 //=======================================================================
157 void TopOpeBRepDS_TKI::Add(const TopOpeBRepDS_Kind K,const Standard_Integer G)
159 Standard_Boolean ok = IsValidKG(K,G);
161 throw Standard_ProgramError("TopOpeBRepDS_TKI : Add K G");
165 Standard_Boolean in = IsBound(K,G);
166 Standard_Integer TI = KindToTableIndex(K);
167 TopOpeBRepDS_ListOfInterference thelist;
169 myT->ChangeValue(TI).Bind(G, thelist);
172 //=======================================================================
175 //=======================================================================
176 void TopOpeBRepDS_TKI::Add(const TopOpeBRepDS_Kind K,const Standard_Integer G,const Handle(TopOpeBRepDS_Interference)& HI)
178 Standard_Boolean ok = IsValidKG(K,G);
179 if (!ok) throw Standard_ProgramError("TopOpeBRepDS_TKI : Add K G HI");
182 ChangeInterferences(K,G).Append(HI);
185 //=======================================================================
186 //function : DumpTKIIterator
188 //=======================================================================
189 void TopOpeBRepDS_TKI::DumpTKIIterator(const TCollection_AsciiString& s1,const TCollection_AsciiString& s2)
194 TopOpeBRepDS_Kind K;Standard_Integer G;
202 //=======================================================================
205 //=======================================================================
206 void TopOpeBRepDS_TKI::Init()
208 myK = TopOpeBRepDS_UNKNOWN;
210 if (myT.IsNull()) return;
211 myTI = myT->Lower(); myK = TableIndexToKind(myTI);
212 myITM.Initialize(myT->Value(myTI));
216 //=======================================================================
219 //=======================================================================
220 Standard_Boolean TopOpeBRepDS_TKI::More() const
222 Standard_Boolean b = IsValidKG(myK,myG);
226 //=======================================================================
229 //=======================================================================
230 void TopOpeBRepDS_TKI::Next()
236 else if ( MoreTI() ) {
239 myITM.Initialize(myT->Value(myTI));
245 //=======================================================================
248 //=======================================================================
249 const TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::Value(TopOpeBRepDS_Kind& K,Standard_Integer& G) const
251 if ( !More() ) return myEmptyLOI;
253 return Interferences(K,G);
256 //=======================================================================
257 //function : ChangeValue
259 //=======================================================================
260 TopOpeBRepDS_ListOfInterference& TopOpeBRepDS_TKI::ChangeValue(TopOpeBRepDS_Kind& K,Standard_Integer& G)
262 if ( !More() ) return myEmptyLOI;
264 return ChangeInterferences(K,G);
267 //=======================================================================
270 //=======================================================================
271 Standard_Boolean TopOpeBRepDS_TKI::MoreTI() const
273 Standard_Boolean b = IsValidTI(myTI);
277 //=======================================================================
280 //=======================================================================
281 void TopOpeBRepDS_TKI::NextTI()
283 myTI = myTI + 1; myK = TableIndexToKind(myTI);
286 //=======================================================================
289 //=======================================================================
290 Standard_Boolean TopOpeBRepDS_TKI::MoreITM() const
292 Standard_Boolean b = myITM.More();
296 //=======================================================================
299 //=======================================================================
300 void TopOpeBRepDS_TKI::FindITM()
302 Standard_Boolean f = Standard_False;
305 f = HasInterferences(myK,myG);
311 //=======================================================================
314 //=======================================================================
315 void TopOpeBRepDS_TKI::NextITM()
317 if ( !MoreITM() ) return;
322 //=======================================================================
325 //=======================================================================
326 void TopOpeBRepDS_TKI::Find()
328 Standard_Boolean f = Standard_False;
332 f = HasInterferences(myK,myG);
339 myITM.Initialize(myT->Value(myTI));
345 //=======================================================================
346 //function : KindToTableIndex
348 //=======================================================================
349 Standard_Integer TopOpeBRepDS_TKI::KindToTableIndex(const TopOpeBRepDS_Kind K) const
351 // K(Kind) + mydelta = TI(integer) = index in myT
352 Standard_Integer TI = (Standard_Integer)K + mydelta;
356 //=======================================================================
357 //function : TableIndexToKind
359 //=======================================================================
360 TopOpeBRepDS_Kind TopOpeBRepDS_TKI::TableIndexToKind(const Standard_Integer TI) const
362 // K(Kind) + mydelta = TI(integer) = index in myT
363 TopOpeBRepDS_Kind K = (TopOpeBRepDS_Kind)(TI - mydelta);
367 //=======================================================================
368 //function : IsValidTI
370 //=======================================================================
371 Standard_Boolean TopOpeBRepDS_TKI::IsValidTI(const Standard_Integer TI) const
373 if ( myT.IsNull() ) return Standard_False;
374 Standard_Boolean nok = ( TI < myT->Lower() || TI > myT->Upper() );
378 //=======================================================================
379 //function : IsValidK
381 //=======================================================================
382 Standard_Boolean TopOpeBRepDS_TKI::IsValidK(const TopOpeBRepDS_Kind K) const
384 Standard_Boolean nok = ( K < TopOpeBRepDS_POINT || K > TopOpeBRepDS_SOLID );
388 //=======================================================================
389 //function : IsValidG
391 //=======================================================================
392 Standard_Boolean TopOpeBRepDS_TKI::IsValidG(const Standard_Integer G) const
394 Standard_Boolean nok = (G <= 0);
398 //=======================================================================
399 //function : IsValidKG
401 //=======================================================================
402 Standard_Boolean TopOpeBRepDS_TKI::IsValidKG(const TopOpeBRepDS_Kind K,const Standard_Integer G) const
404 Standard_Boolean nok = (!IsValidK(K) || !IsValidG(G));