0025418: Debug output to be limited to OCC development environment
[occt.git] / src / TopOpeBRepDS / TopOpeBRepDS_ProcessInterferencesTool.cxx
CommitLineData
b311480e 1// Created on: 1997-02-14
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
17#include <TopOpeBRepDS_InterferenceTool.hxx>
18#include <TopOpeBRepDS_ProcessInterferencesTool.hxx>
19#include <TopOpeBRepDS_EdgeVertexInterference.hxx>
20#include <TopOpeBRepDS_InterferenceIterator.hxx>
21#include <TopOpeBRepDS_TKI.hxx>
22#include <TopoDS.hxx>
23#include <BRepLProp_SLProps.hxx>
24#include <BRepAdaptor_Surface.hxx>
25//#include <BRepAdaptor_Curve2d.hxx>
26#include <BRep_Tool.hxx>
27#include <gp_Pnt2d.hxx>
28#include <gp_Vec.hxx>
29#include <gp_Dir.hxx>
30#include <Precision.hxx>
31#include <TColStd_MapOfInteger.hxx>
32#include <Standard_ProgramError.hxx>
33#include <TopOpeBRepDS_define.hxx>
34#include <TopOpeBRepTool_TOOL.hxx>
35#include <TopOpeBRepTool_EXPORT.hxx>
36#include <TopOpeBRepDS_EXPORT.hxx>
37
0797d9d3 38#ifdef OCCT_DEBUG
1d0a9d4d 39extern Standard_Boolean TopOpeBRepDS_GettracePEI();
40extern Standard_Boolean TopOpeBRepDS_GettracePI();
41extern Standard_Boolean TopOpeBRepDS_GettraceSPSX(const Standard_Integer);
7fd59977 42static Standard_Boolean TRCE(const Standard_Integer EIX) {
43 Standard_Boolean b1 = TopOpeBRepDS_GettracePEI();
44 Standard_Boolean b2 = TopOpeBRepDS_GettracePI();
45 Standard_Boolean b3 = TopOpeBRepDS_GettraceSPSX(EIX);
46 return (b1 || b2 || b3);
47}
48Standard_EXPORT void debredudoub(const Standard_Integer /*i*/) {}
49Standard_EXPORT void debredudoub1(const Standard_Integer /*i*/) {}
50Standard_EXPORT void debredudoub2(const Standard_Integer /*i*/) {}
51Standard_EXPORT void debredunk(const Standard_Integer /*i*/) {}
52#endif
53
54//-----------------------------------------------------------------------
55Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeCPVInterference
56(const TopOpeBRepDS_Transition& T, // transition
57 const Standard_Integer SI, // curve/edge index
58 const Standard_Integer GI, // point/vertex index
59 const Standard_Real P, // parameter of G on S
60 const TopOpeBRepDS_Kind GK) // POINT/VERTEX
61//-----------------------------------------------------------------------
62{
63 Handle(TopOpeBRepDS_Interference) I;
64 TopOpeBRepDS_Kind SK = TopOpeBRepDS_CURVE;
65 I = TopOpeBRepDS_InterferenceTool::MakeCurveInterference(T,SK,SI,GK,GI,P);
66 return I;
67}
68
69//-----------------------------------------------------------------------
70Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
71(const TopOpeBRepDS_Transition& T, // transition
72 const Standard_Integer SI, // curve/edge index
73 const Standard_Integer GI, // point/vertex index
74 const Standard_Real P, // parameter of G on S
75 const TopOpeBRepDS_Kind GK,
76 const Standard_Boolean B) // G is a vertex (or not) of the interference master
77//-----------------------------------------------------------------------
78{
79 Handle(TopOpeBRepDS_Interference) I;
80 TopOpeBRepDS_Kind SK = TopOpeBRepDS_EDGE;
81 if ( GK == TopOpeBRepDS_POINT ) {
82 I = TopOpeBRepDS_InterferenceTool::MakeEdgeInterference(T,SK,SI,GK,GI,P);
83 }
84 else if ( GK == TopOpeBRepDS_VERTEX ) {
85 I = TopOpeBRepDS_InterferenceTool::MakeEdgeVertexInterference(T,SI,GI,B,TopOpeBRepDS_UNSHGEOMETRY,P);
86 I->GeometryType(GK);
87 }
88 return I;
89}
90
91//-----------------------------------------------------------------------
92Standard_EXPORT Handle(TopOpeBRepDS_Interference) MakeEPVInterference
93(const TopOpeBRepDS_Transition& T, // transition
94 const Standard_Integer S, // curve/edge index
95 const Standard_Integer G, // point/vertex index
96 const Standard_Real P, // parameter of G on S
97 const TopOpeBRepDS_Kind GK, // POINT/VERTEX
98 const TopOpeBRepDS_Kind SK,
99 const Standard_Boolean B) // G is a vertex (or not) of the interference master
100//-----------------------------------------------------------------------
101{
102 Handle(TopOpeBRepDS_Interference) I = ::MakeEPVInterference(T,S,G,P,GK,B);
103 I->SupportType(SK);
104 return I;
105}
106
107//------------------------------------------------------
108Standard_EXPORT Standard_Boolean FUN_hasStateShape
109//------------------------------------------------------
110// FUN_hasStateShape : True if transition T is (state,shape) before or after
111(const TopOpeBRepDS_Transition& T,
112 const TopAbs_State state,
113 const TopAbs_ShapeEnum shape)
114{
115 TopAbs_State staB = T.Before(), staA = T.After();
116 TopAbs_ShapeEnum shaB = T.ShapeBefore(), shaA = T.ShapeAfter();
117 Standard_Boolean B = ( staB == state ) && ( shaB == shape);
118 Standard_Boolean A = ( staA == state ) && ( shaA == shape);
119 Standard_Boolean result = B || A;
120 return result;
121}
122
123//------------------------------------------------------
124Standard_EXPORT Standard_Integer FUN_selectTRASHAinterference
125//------------------------------------------------------
126// selection des interf (sha2) de L1 dans L2. retourne leur nombre.
127(TopOpeBRepDS_ListOfInterference& L1,const TopAbs_ShapeEnum sha2, TopOpeBRepDS_ListOfInterference& L2)
128{
129 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
130 while (it1.More()) {
131 Handle(TopOpeBRepDS_Interference) I1 = it1.Value();
132 const TopOpeBRepDS_Transition& T1 = I1->Transition();
133
134 TopAbs_ShapeEnum shab = T1.ShapeBefore(), shaa = T1.ShapeAfter();
135 Standard_Boolean sel=((shab==sha2)||(shaa==sha2));
136 if (sel) {
137 L2.Append(I1);
138 L1.Remove(it1);
139 }
140 else it1.Next();
141 }
142 Standard_Integer n2 = L2.Extent();
143 return n2;
144}
145
146//------------------------------------------------------
147Standard_EXPORT Standard_Integer FUN_selectITRASHAinterference
148//------------------------------------------------------
149// selection des interf (sha2) de L1 dans L2. retourne leur nombre.
150(TopOpeBRepDS_ListOfInterference& L1,const Standard_Integer Index, TopOpeBRepDS_ListOfInterference& L2)
151{
152 if (Index == 0) return 0;
153 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
154 while (it1.More()) {
155 Handle(TopOpeBRepDS_Interference) I1 = it1.Value();
156 const TopOpeBRepDS_Transition& T1 = I1->Transition();
157 Standard_Integer Ind = T1.Index();
158 if (Ind == Index) {
159 L2.Append(I1);
160 L1.Remove(it1);
161 }
162 else it1.Next();
163 }
164 Standard_Integer n2 = L2.Extent();
165 return n2;
166}
167
168//------------------------------------------------------
169Standard_EXPORT Standard_Integer FUN_selectTRAUNKinterference
170//------------------------------------------------------
171// selection des interf de transition (UNK,UNK) de L1 dans L2. retourne leur nombre.
172(TopOpeBRepDS_ListOfInterference& L1,TopOpeBRepDS_ListOfInterference& L2)
173{
174 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
175 while (it1.More()) {
176 Handle(TopOpeBRepDS_Interference) I1 = it1.Value();
177 const TopOpeBRepDS_Transition& T1 = I1->Transition();
178 Standard_Boolean sel = T1.IsUnknown();
179 if (sel) {
180 L2.Append(I1);
181 L1.Remove(it1);
182 }
183 else it1.Next();
184 }
185 Standard_Integer n2 = L2.Extent();
186 return n2;
187}
188
189//------------------------------------------------------
190Standard_EXPORT Standard_Integer FUN_selectTRAORIinterference
191//------------------------------------------------------
192// selection des interf d'orientation donnee O de L1 dans L2. retourne leur nombre.
193(TopOpeBRepDS_ListOfInterference& L1, const TopAbs_Orientation O, TopOpeBRepDS_ListOfInterference& L2)
194{
195 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
196 while (it1.More()) {
197 Handle(TopOpeBRepDS_Interference) I1 = it1.Value();
198 const TopOpeBRepDS_Transition& T1 = I1->Transition();
199 TopAbs_Orientation ori = T1.Orientation(TopAbs_IN);
200 Standard_Boolean sel = (ori ==O);
201 if (sel) {
202 L2.Append(I1);
203 L1.Remove(it1);
204 }
205 else it1.Next();
206 }
207 Standard_Integer n2 = L2.Extent();
208 return n2;
209}
210
211//------------------------------------------------------
212Standard_EXPORT Standard_Integer FUN_selectGKinterference
213//------------------------------------------------------
214(TopOpeBRepDS_ListOfInterference& L1,const TopOpeBRepDS_Kind GK,TopOpeBRepDS_ListOfInterference& L2)
215{
216 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
217 while (it1.More()) {
218 TopOpeBRepDS_Kind gki = it1.Value()->GeometryType();
219 if (gki == GK) {
220 L2.Append(it1.Value());
221 L1.Remove(it1);
222 }
223 else it1.Next();
224 }
225 Standard_Integer n2 = L2.Extent();
226 return n2;
227}
228
229//------------------------------------------------------
230Standard_EXPORT Standard_Integer FUN_selectSKinterference
231//------------------------------------------------------
232// selection des interf de type de support SK de L1 dans L2. retourne leur nombre.
233(TopOpeBRepDS_ListOfInterference& L1,const TopOpeBRepDS_Kind SK,TopOpeBRepDS_ListOfInterference& L2)
234{
235 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
236 while (it1.More()) {
237 TopOpeBRepDS_Kind ski = it1.Value()->SupportType();
238 if (ski == SK) {
239 L2.Append(it1.Value());
240 L1.Remove(it1);
241 }
242 else it1.Next();
243 }
244 Standard_Integer n2 = L2.Extent();
245 return n2;
246}
247
248//------------------------------------------------------
249Standard_EXPORT Standard_Integer FUN_selectGIinterference
250//------------------------------------------------------
251// selection des interf d' index de geometrie GI de L1 dans L2. retourne leur nombre.
252(TopOpeBRepDS_ListOfInterference& L1,const Standard_Integer GI,TopOpeBRepDS_ListOfInterference& L2)
253{
254 if (GI == 0) return 0;
255 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
256 while (it1.More()) {
257 Standard_Integer gi = it1.Value()->Geometry();
258 if (gi == GI) {
259 L2.Append(it1.Value());
260 L1.Remove(it1);
261 }
262 else it1.Next();
263 }
264 Standard_Integer n2 = L2.Extent();
265 return n2;
266}
267
268//------------------------------------------------------
269Standard_EXPORT Standard_Integer FUN_selectSIinterference
270//------------------------------------------------------
271// selection des interf d' index de support SI de L1 dans L2. retourne leur nombre.
272(TopOpeBRepDS_ListOfInterference& L1,const Standard_Integer SI,TopOpeBRepDS_ListOfInterference& L2)
273{
274 if (SI == 0) return 0;
275 TopOpeBRepDS_ListIteratorOfListOfInterference it1(L1);
276 while (it1.More()) {
277 Standard_Integer si = it1.Value()->Support();
278 if (si == SI) {
279 L2.Append(it1.Value());
280 L1.Remove(it1);
281 }
282 else it1.Next();
283 }
284 Standard_Integer n2 = L2.Extent();
285 return n2;
286}
287
288//------------------------------------------------------
289Standard_EXPORT Standard_Boolean FUN_interfhassupport
290//------------------------------------------------------
291// FUN_interfhassupport : True si shape support de l 'interf I est IsSame(S).
292(const TopOpeBRepDS_DataStructure& DS,const Handle(TopOpeBRepDS_Interference)& I,const TopoDS_Shape& S)
293{
294 Standard_Boolean h = Standard_True;
295 const Standard_Integer index = I->Support();
296 const TopoDS_Shape& SofI = DS.Shape(index);
297 if ( SofI.IsSame(S) ) h = Standard_True;
298 else h = Standard_False;
299 return h;
300}
301
302//------------------------------------------------------
303Standard_EXPORT Standard_Boolean FUN_transitionEQUAL
304//------------------------------------------------------
305(const TopOpeBRepDS_Transition& T1,const TopOpeBRepDS_Transition& T2)
306{
307 Standard_Boolean id1 = FUN_transitionSTATEEQUAL(T1,T2);
308 Standard_Boolean id2 = FUN_transitionSHAPEEQUAL(T1,T2);
309 Standard_Boolean id3 = FUN_transitionINDEXEQUAL(T1,T2);
310 Standard_Boolean id = id1 && id2 && id3;
311 return id;
312}
313
314//------------------------------------------------------
315Standard_EXPORT Standard_Boolean FUN_transitionSTATEEQUAL
316//------------------------------------------------------
317(const TopOpeBRepDS_Transition& T1,const TopOpeBRepDS_Transition& T2)
318{
319 Standard_Boolean id = T1.Before()==T2.Before() && T1.After()==T2.After();
320 return id;
321}
322
323//------------------------------------------------------
324Standard_EXPORT Standard_Boolean FUN_transitionSHAPEEQUAL
325//------------------------------------------------------
326(const TopOpeBRepDS_Transition& T1,const TopOpeBRepDS_Transition& T2)
327{
328 Standard_Boolean id = T1.ShapeBefore()==T2.ShapeBefore() && T1.ShapeAfter()==T2.ShapeAfter();
329 return id;
330}
331
332//------------------------------------------------------
333Standard_EXPORT Standard_Boolean FUN_transitionINDEXEQUAL
334//------------------------------------------------------
335(const TopOpeBRepDS_Transition& T1,const TopOpeBRepDS_Transition& T2)
336{
337 Standard_Boolean id = T1.IndexBefore()==T2.IndexBefore() && T1.IndexAfter()==T2.IndexAfter();
338 return id;
339}
340
341//------------------------------------------------------
342Standard_EXPORT void FUN_reducedoublons
343//------------------------------------------------------
344(TopOpeBRepDS_ListOfInterference& LI,const TopOpeBRepDS_DataStructure& BDS,const Standard_Integer SIX)
345{
0797d9d3 346#ifdef OCCT_DEBUG
7fd59977 347 Standard_Boolean TRC=TRCE(SIX); if (TRC) debredudoub(SIX);
348 Standard_Boolean modif = Standard_False;
349#endif
350 const TopoDS_Shape& E = BDS.Shape(SIX);
351 TopOpeBRepDS_ListIteratorOfListOfInterference it1;
352
353 // process interferences of LI with VERTEX geometry
354
355 it1.Initialize(LI);
356 while (it1.More() ) {
357 Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
358 const TopOpeBRepDS_Transition& T1 = I1->Transition();
359 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_data(I1,GT1,G1,ST1,S1);
360 TopAbs_ShapeEnum tsb1,tsa1; Standard_Integer isb1,isa1;
361 FDS_Tdata(I1,tsb1,isb1,tsa1,isa1);
362
0797d9d3 363#ifdef OCCT_DEBUG
7fd59977 364 if (TRC) debredudoub1(SIX);
365#endif
366
367 TopOpeBRepDS_ListIteratorOfListOfInterference it2(it1); it2.Next();
368 while ( it2.More() ) {
369
370 const Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
371 const TopOpeBRepDS_Transition& T2 = I2->Transition();
372 TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; FDS_data(I2,GT2,G2,ST2,S2);
373 TopAbs_ShapeEnum tsb2,tsa2; Standard_Integer isb2,isa2;
374 FDS_Tdata(I2,tsb2,isb2,tsa2,isa2);
375
0797d9d3 376#ifdef OCCT_DEBUG
7fd59977 377 if (TRC) debredudoub2(SIX);
378#endif
379
380 Standard_Boolean idGS = (GT2 == GT1 && G2 == G1 && ST2 == ST1 && S2 == S1);
381 if (idGS) {
382
383 Standard_Boolean id1 = FUN_transitionSTATEEQUAL(T1,T2);
384 Standard_Boolean id2 = FUN_transitionSHAPEEQUAL(T1,T2);
385 Standard_Boolean id3 = FUN_transitionINDEXEQUAL(T1,T2);
386 Standard_Boolean idT = id1 && id2 && id3;
387
388 if ( idT ) {
389 const Handle(TopOpeBRepDS_EdgeVertexInterference) EVI1 = Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I1);
390 const Handle(TopOpeBRepDS_EdgeVertexInterference) EVI2 = Handle(TopOpeBRepDS_EdgeVertexInterference)::DownCast(I2);
391 Standard_Boolean evi = (!EVI1.IsNull()) && (!EVI2.IsNull());
392 if (evi) {
393 //xpu130898 : if vG is on E's closing vertex -> filter
394 const TopoDS_Vertex& vG = TopoDS::Vertex(BDS.Shape(G1));
395 TopoDS_Vertex OOv; Standard_Boolean hasOO = FUN_ds_getoov(vG,BDS,OOv);
396 TopoDS_Vertex vclo; Standard_Boolean Eclosed = TopOpeBRepTool_TOOL::ClosedE(TopoDS::Edge(E),vclo);
397 Standard_Boolean onvclo = Standard_False;
398 if (Eclosed) {
399 onvclo = vG.IsSame(vG);
400 if (hasOO && !onvclo) onvclo = vG.IsSame(OOv);
401 }
402 if (onvclo) idT = Standard_True;
403 else {
404 //xpu100697 : if interf are EVI compare parameters
405 Standard_Real tolE = FUN_tool_maxtol(E); Standard_Real t = Precision::Parametric(tolE);
406 Standard_Real t1 = EVI1->Parameter(); Standard_Real t2 = EVI2->Parameter();
407 Standard_Real dd = t1-t2;
408 Standard_Boolean samepar = (Abs(dd) <= t);
409 idT = samepar;
410 }
411 } // evi
412 }
413 if (idT) {
414 // les 2 interferences I1 et I2 sont identiques : on supprime I2
0797d9d3 415#ifdef OCCT_DEBUG
7fd59977 416 if(TRC){cout<<"shape "<<SIX<<" : doublon ";I1->Dump(cout);cout<<endl;}
417 modif = Standard_True;
418#endif
419 LI.Remove(it2);
420 }
421 else it2.Next();
422 }
423 else it2.Next();
424 }
425 it1.Next();
426 } // it1.More()
427
0797d9d3 428#ifdef OCCT_DEBUG
7fd59977 429 if(TRC && !modif){ FDS_dumpLI(LI,"sans doublon : "); }
430#endif
431} // reducedoublons
432
433//------------------------------------------------------
434Standard_EXPORT void FUN_unkeepUNKNOWN
435//------------------------------------------------------
436 (TopOpeBRepDS_ListOfInterference& LI,
437 TopOpeBRepDS_DataStructure& /*BDS*/,
0797d9d3 438#ifdef OCCT_DEBUG
7fd59977 439 const Standard_Integer SIX)
440#else
441 const Standard_Integer)
442#endif
443{
0797d9d3 444#ifdef OCCT_DEBUG
7fd59977 445 Standard_Boolean TRC=TRCE(SIX); if (TRC) debredunk(SIX);
446 Standard_Boolean modif = Standard_False;
447#endif
448// BDS.Shape(SIX);
449 TopOpeBRepDS_ListIteratorOfListOfInterference it1;
450
451 // process interferences of LI with UNKNOWN transition
452
453 it1.Initialize(LI);
454 while (it1.More() ) {
455 Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
456 const TopOpeBRepDS_Transition& T1 = I1->Transition();
457 Standard_Boolean isunk = T1.IsUnknown();
458
459 if (isunk) {
0797d9d3 460#ifdef OCCT_DEBUG
7fd59977 461 if(TRC) {
462 if (isunk) debredunk(SIX);
463 cout<<"shape "<<SIX<<" : UNKNOWN transition ";I1->Dump(cout);cout<<endl;
464 }
465#endif
466 LI.Remove(it1);
467 }
468 else it1.Next();
469 } // it1.More()
470
0797d9d3 471#ifdef OCCT_DEBUG
7fd59977 472 if(TRC && !modif){ FDS_dumpLI(LI,"sans UNKNOWN : "); }
473#endif
474} // unkeepUNKNOWN
475
476// -----------------------------------------------------------
477static Standard_Integer FUN_select3dI(const Standard_Integer SIX, TopOpeBRepDS_DataStructure& BDS,
478 TopOpeBRepDS_ListOfInterference& lFE, TopOpeBRepDS_ListOfInterference& lFEresi, TopOpeBRepDS_ListOfInterference& l3dFE)
479//------------------------------------------------------
480{
481 l3dFE.Clear();
482 lFEresi.Clear();
483 Standard_Integer n3d = 0;
0797d9d3 484#ifdef OCCT_DEBUG
7fd59977 485 Standard_Boolean TRC=TRCE(SIX);
486#endif
487
488 Standard_Integer nFE = lFE.Extent();
489 if (nFE <= 1) return n3d;
490
491 const TopoDS_Edge& E = TopoDS::Edge(BDS.Shape(SIX));
492 Standard_Integer rankE = BDS.AncestorRank(E);
493 TopoDS_Shape OOv; Standard_Integer OOG = 0, Gsta = 0;
494
495 // attached to a given edge :
496 // <lFE> = {I=(T(face),G=POINT,S=EDGE)}/ {I=(T(face),G=VERTEX,S=EDGE)}
497 // = set of interferences of same geometry kind.
498 // -> <l3dFE> + <lFE>
499 // <l3dFE> = sets of interferences with same geometry,
500 // describing 3d complex transitions.
501
502 TopOpeBRepDS_ListIteratorOfListOfInterference it1(lFE);
503 while (it1.More()) {
504
505 Standard_Boolean complex3d=Standard_False;
506 const Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
507 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_data(I1,GT1,G1,ST1,S1);
508 TopAbs_ShapeEnum SB1,SA1; Standard_Integer IB1,IA1; FDS_Tdata(I1,SB1,IB1,SA1,IA1);
509 Standard_Boolean vertex1 = (GT1 == TopOpeBRepDS_VERTEX);
510
511 TopOpeBRepDS_ListIteratorOfListOfInterference it2(it1);
512 if (it2.More()) it2.Next();
513 else break;
514
515 // <Gsta>, <OOv>
516 if (vertex1) {
517 TopoDS_Vertex vG1 = TopoDS::Vertex(BDS.Shape(G1)); Standard_Integer rankvG1 = BDS.AncestorRank(vG1);
518 Standard_Boolean G1hsd = FUN_ds_getVsdm(BDS,G1,OOG);
519 if (rankvG1 != rankE) // vG1 not on E
520 {OOv = vG1; Gsta = G1hsd? 3: 2;}
521 else // vG on E
522 {if (G1hsd) OOv = BDS.Shape(OOG); Gsta = G1hsd? 3: 1;}
523 }
524
525 while (it2.More()){
526 const Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
527 TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; FDS_data(I2,GT2,G2,ST2,S2);
528 TopAbs_ShapeEnum SB2,SA2; Standard_Integer IB2,IA2; FDS_Tdata(I2,SB2,IB2,SA2,IA2);
529
530 Standard_Boolean sameG = (GT2 == GT1);
531 if (!sameG) break;
532 sameG = (G2 == G1) || (G2 == OOG);
533
534 const TopoDS_Face& F1 = TopoDS::Face(BDS.Shape(IB1));
535 const TopoDS_Face& F2 = TopoDS::Face(BDS.Shape(IB2));
536
537 // same domain faces, -> 2d interferences
538 Standard_Boolean sdmFT = (IB1==IB2) || FUN_ds_sdm(BDS,F1,F2);
539// if (sdmFT) {it2.Next(); continue;}
540 if (sdmFT) {lFEresi.Append(I2); lFE.Remove(it2); continue;}
541
542 // a. if (S2 == S1) ->ok
543 // b. else :
544 // if (G is POINT on Fi i = 1,2) ->continue
545 // else : look for E1(edge S1) on F1(IB1) shared by F2(IB2)
546 // with bound G.
547 Standard_Boolean sameS = (ST2 == ST1) && (S2 == S1);
548
549 Standard_Boolean sameSorsharedEbyTRASHA = sameS;
550 Standard_Boolean hasOOv = (Gsta > 1);
551 if (!sameSorsharedEbyTRASHA && hasOOv) {
552 TopoDS_Shape Eshared; Standard_Boolean foundsh = FUN_tool_Eshared(OOv,F1,F2,Eshared);
553 if (!foundsh) {it2.Next(); continue;}
554
555 sameSorsharedEbyTRASHA = Standard_True;
556 if (!BDS.HasShape(Eshared))
557 {Standard_Integer OOrank = BDS.AncestorRank(OOv); BDS.AddShape(Eshared,OOrank);}
558 S1 = BDS.Shape(Eshared); S2 = S1;
0797d9d3 559#ifdef OCCT_DEBUG
7fd59977 560 if (TRC) {cout<<" finding out E shared by F"<<IB1<<" and F"<<IB2;
561 cout<<" new support is E"<<S1<<endl;}
562#endif
563 }
564
565 if (sameSorsharedEbyTRASHA) { // xpu : 09-03-98
566 Standard_Boolean sdm = FUN_ds_sdm(BDS,BDS.Shape(SIX),BDS.Shape(S1));
567 if (sdm) {
0797d9d3 568#ifdef OCCT_DEBUG
7fd59977 569 if (TRC) cout<<" NO I3d : e"<<SIX<<" same domain with e"<<S1<<endl;
570#endif
571 it2.Next(); continue;
572 }
573 } // xpu : 09-03-98
574
575 if (sameSorsharedEbyTRASHA) {l3dFE.Append(I2); lFE.Remove(it2); complex3d=Standard_True;}
576 else it2.Next();
577 } // it2(it1);
578
579 if (complex3d) {l3dFE.Append(I1); lFE.Remove(it1);}
580 else it1.Next();
581 } // it1(lFE);
582
583 // xpu170898 : cto009H1 (I1(T1(F),G,S1),I1'(T2(F),G,S2), I2)
584 // (I1,I2) -> to reduce => I1' to delete
585 n3d = l3dFE.Extent();
586 Standard_Integer nresi = lFEresi.Extent();
587 if (nresi == 0) return n3d;
588
589 if (n3d != 0) {
590 TopOpeBRepDS_ListIteratorOfListOfInterference it(lFEresi);
591 while (it.More()){
592 const Handle(TopOpeBRepDS_Interference)& I = it.Value();
593 Standard_Integer TRA = I->Transition().Index();
594 TopOpeBRepDS_ListOfInterference lcopy; FDS_assign(l3dFE,lcopy);
595 TopOpeBRepDS_ListOfInterference lfound; Standard_Integer nfound = FUN_selectITRASHAinterference(lcopy,TRA,lfound);
596 if (nfound == 0) lFE.Remove(it);
597 else it.Next();
598 }
599 }
600 else lFE.Append(lFEresi);
601 return n3d;
602}
603
604static Standard_Boolean FUN_find3dISEsameISF(const Handle(TopOpeBRepDS_Interference)& I1, TopOpeBRepDS_ListIteratorOfListOfInterference& it2)
605// I1 = (T0,G0,S)
606// looking among interferences of <it2> for I2/
607// I2 = (T0,G0,S')
608{
609 TopAbs_Orientation O1 = I1->Transition().Orientation(TopAbs_IN);
610 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_data(I1,GT1,G1,ST1,S1);
611 TopAbs_ShapeEnum SB1,SA1; Standard_Integer IB1,IA1; FDS_Tdata(I1,SB1,IB1,SA1,IA1);
612
613 while ( it2.More()){
614 Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
615 TopAbs_Orientation O2 = I2->Transition().Orientation(TopAbs_IN);
616 TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; FDS_data(I2,GT2,G2,ST2,S2);
617 TopAbs_ShapeEnum SB2,SA2; Standard_Integer IB2,IA2; FDS_Tdata(I2,SB2,IB2,SA2,IA2);
618 Standard_Boolean sameT = (SB1 == SB2) && (IB1 == IB2) && (O1 == O2);
619 Standard_Boolean sameG = (GT1 == GT2) && (G1 == G2);
620 if (sameT && sameG) return Standard_True;
621 else it2.Next();
622 } // it2
623 return Standard_False;
624}
625
626// ------------------------------------------------------------
627static Standard_Integer FUN_select3dISEsameISF
628(TopOpeBRepDS_ListOfInterference& lFE, TopOpeBRepDS_ListOfInterference& l3dFE, TopOpeBRepDS_ListOfInterference& l3dFEresi,
629 TopOpeBRepDS_ListOfInterference& lF, TopOpeBRepDS_ListOfInterference& l3dF)
630//-------------------------------------------------------------
631{
632 // I3d in <l3dFE>, I3d = (T(face),G=POINT/VERTEX,S=EDGE)
633 // <->I3d' in <l3dF>, I3d'= (T(face),G=POINT/VERTEX,S=FACE)
634
635 // <l3dFEold> -> {I3d} + <l3dFEnew>
636 // <lFEold> -> <lFE> + (<l3dFEold> - <l3dFEnew>)
637 // <lFold> -> {I3d'}+ <lFnew>; {I3d'}=<l3dF>
638
639 TopOpeBRepDS_ListIteratorOfListOfInterference it1(l3dFE);
640 while (it1.More()) {
641 const Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
642// TopAbs_Orientation O1 = I1->Transition().Orientation(TopAbs_IN);
643// TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_data(I1,GT1,G1,ST1,S1);
644// TopAbs_ShapeEnum SB1,SA1; Standard_Integer IB1,IA1; FDS_Tdata(I1,SB1,IB1,SA1,IA1);
645
646// Standard_Boolean found = Standard_False;
647// TopOpeBRepDS_ListIteratorOfListOfInterference it2(lF);
648// while ( it2.More()){
649// Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
650// TopAbs_Orientation O2 = I2->Transition().Orientation(TopAbs_IN);
651// TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; FDS_data(I2,GT2,G2,ST2,S2);
652// TopAbs_ShapeEnum SB2,SA2; Standard_Integer IB2,IA2; FDS_Tdata(I2,SB2,IB2,SA2,IA2);
653// Standard_Boolean sameT = (SB1 == SB2) && (IB1 == IB2) && (O1 == O2);
654// Standard_Boolean sameG = (GT1 == GT2) && (G1 == G2);
655// if (sameT && sameG) {found = Standard_True; l3dF.Append(I2); lF.Remove(it2);break;}
656// else it2.Next();
657// } // it2
658// if (found) it1.Next();
659// else {lFE.Append(I1); l3dFE.Remove(it1);}
660
661 // {IFE = (T0,G0,Sedge); IFF = (T0,G0,Sface)}
662 // => l3dFE += IFE, l3dF += iFF
663 TopOpeBRepDS_ListIteratorOfListOfInterference it2(lF);
664 Standard_Boolean found = FUN_find3dISEsameISF(I1,it2);
665
666 if (found) {
667 l3dF.Append(it2.Value());
668 lF.Remove(it2);
669 it1.Next();
670 }
671 else {
672 // xpu : 16-02-98 :
673 // IFE1 = (T0,G0,Sedge1), IFE2 = (T0,G0,Sedge2)
674 // IFF = (T0,G0,Sface)
675 // => l3dFE += IFE1, l3dF += iFF,
676 // l3dFEresi += IFE2
677 TopOpeBRepDS_ListIteratorOfListOfInterference it3(l3dF);
678 found = FUN_find3dISEsameISF(I1,it3);
679
680 if (found) l3dFEresi.Append(I1);
681 else lFE.Append(I1);
682 l3dFE.Remove(it1);
683
684 }
685 } // it1
686 return l3dF.Extent();
687}
688
689//------------------------------------------------------
690Standard_EXPORT Standard_Integer FUN_select2dI
691(const Standard_Integer SIX, TopOpeBRepDS_DataStructure& BDS,const TopAbs_ShapeEnum TRASHAk,TopOpeBRepDS_ListOfInterference& lI,TopOpeBRepDS_ListOfInterference& l2dI)
692//------------------------------------------------------
693// <lI> -> <l2dI> + <lI>
694// TRASHAk = TopAbs_FACE : <l2dI> = {I2d = (T on same domain faces, G,S)}
695// TRASHAk = TopAbs_EDGE : <l2dI> = {I2d = (T on same edge, G,S)}
696{
697 l2dI.Clear();
698 Standard_Integer n2d = 0;
699 Standard_Integer nFE = lI.Extent();
700 if (nFE <=1) return n2d;
701
702 Standard_Boolean TonFace = (TRASHAk == TopAbs_FACE);
703
704 // xpu201098 : check FEI is not 3dFEI (cto904F6,SIX10,G6)
705 TColStd_MapOfInteger mapftra;
706 TopOpeBRepDS_ListOfInterference lIE; FDS_copy(BDS.ShapeInterferences(SIX),lIE);
707 TopOpeBRepDS_ListOfInterference l3dF;
0797d9d3 708#ifdef OCCT_DEBUG
7fd59977 709// Standard_Integer n3d =
710#endif
711 FUN_selectSKinterference(lIE,TopOpeBRepDS_FACE,l3dF);
712 for (TopOpeBRepDS_ListIteratorOfListOfInterference itt(l3dF); itt.More(); itt.Next()) mapftra.Add(itt.Value()->Support());
713 TopOpeBRepDS_ListOfInterference lII; TopOpeBRepDS_ListIteratorOfListOfInterference it1(lI);
714 while (it1.More()) {
715 const Handle(TopOpeBRepDS_Interference)& I = it1.Value();
716 Standard_Integer ITRASHA = I->Transition().Index();
717 if (mapftra.Contains(ITRASHA)) {it1.Next();}
718 else {lII.Append(I);lI.Remove(it1);}
719 }
720
721 it1.Initialize(lII);
722 while (it1.More()) {
723 const Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
724 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_data(I1,GT1,G1,ST1,S1);
725 TopAbs_ShapeEnum SB1,SA1; Standard_Integer IB1,IA1; FDS_Tdata(I1,SB1,IB1,SA1,IA1);
726
727 if (SB1 != TRASHAk) {it1.Next(); continue;}
728
729 Standard_Boolean complex2d = Standard_False;
730 TopOpeBRepDS_ListIteratorOfListOfInterference it2(it1);
731 if (it2.More()) it2.Next();
732 else break;
733 while (it2.More()){
734 const Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
735 TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; FDS_data(I2,GT2,G2,ST2,S2);
736 TopAbs_ShapeEnum SB2,SA2; Standard_Integer IB2,IA2; FDS_Tdata(I2,SB2,IB2,SA2,IA2);
737
738 Standard_Boolean cond = (SB1 == SB2) && (IB1 == IB2) && (IA1 == IA2);
739 if (!cond) {it2.Next(); continue;}
740
741 Standard_Boolean sameG = (GT2 == GT1) && (G2 == G1);
742 Standard_Boolean sameST = (ST2 == ST1);
743 cond = sameG && sameST;
744 if (!cond) {it2.Next(); continue;}
745
746 complex2d = (IB1==IB2);
747 if (TonFace) {
748 const TopoDS_Face& F1 = TopoDS::Face(BDS.Shape(IB1));
749 const TopoDS_Face& F2 = TopoDS::Face(BDS.Shape(IB2));
750 complex2d = complex2d || FUN_ds_sdm(BDS,F1,F2);
751 }
752 if (complex2d) {l2dI.Append(I2); lII.Remove(it2);}
753 else it2.Next();
754 } // it2
755 if (complex2d) {l2dI.Append(I1); lII.Remove(it1);}
756 else it1.Next();
757 } // it1
758 lI.Append(lII);
759 n2d = l2dI.Extent();
760 return n2d;
761}
762
763//------------------------------------------------------
764Standard_EXPORT Standard_Integer FUN_selectpure2dI
765(const TopOpeBRepDS_ListOfInterference& lF, TopOpeBRepDS_ListOfInterference& lFE, TopOpeBRepDS_ListOfInterference& l2dFE)
766//------------------------------------------------------
767// <lFE> -> <lFE> + <l2dFE>
768// <l2dFE> = {I2dFE = (T(face),G,S=edge) / we cannot find (T(face),G,face)}
769{
770 l2dFE.Clear();
771 TopOpeBRepDS_ListIteratorOfListOfInterference itFE(lFE);
772 while (itFE.More()) {
773 const Handle(TopOpeBRepDS_Interference)& IFE = itFE.Value();
774 const TopOpeBRepDS_Transition& TFE = IFE->Transition();
775 Standard_Integer IB = TFE.IndexBefore(), IA = TFE.IndexAfter();
776 if (IB != IA) {itFE.Next(); continue;}
777
778 Standard_Boolean foundIF = Standard_False;
779 for (TopOpeBRepDS_ListIteratorOfListOfInterference itF(lF); itF.More(); itF.Next()){
780 const Handle(TopOpeBRepDS_Interference)& IF = itF.Value();
781 Standard_Integer S = IF->Support();
782 if (S == IB) {foundIF = Standard_True; break;}
783 }
784 if (foundIF) {itFE.Next(); continue;}
785
786 l2dFE.Append(IFE); lFE.Remove(itFE);
787 }
788 Standard_Integer n2dFE = l2dFE.Extent();
789 return n2dFE;
790} // selectpure2dI
791
792//------------------------------------------------------
793Standard_EXPORT Standard_Integer FUN_select1dI(const Standard_Integer SIX, TopOpeBRepDS_DataStructure& BDS,TopOpeBRepDS_ListOfInterference& LI,TopOpeBRepDS_ListOfInterference& l1dI)
794//------------------------------------------------------
795// attached to edge E : <lI>={I=(T(ES),G,ES)} -> <l1dI> + <lI>
796// l1dI contains {(I1,I2) / I1=(T1(ES1),VG,ES1), I2=(T2(ES2),VG,ES2),
797// E sdm ES1, ES2}
798{
799 l1dI.Clear();
800 Standard_Integer n1d = 0;
801 Standard_Integer nFE = LI.Extent();
802 if (nFE <=1) return n1d;
803
804 TopOpeBRepDS_ListOfInterference newLI;
805 const TopoDS_Shape& EIX = BDS.Shape(SIX);
806 TopOpeBRepDS_TKI tki; tki.FillOnGeometry(LI);
807 for (tki.Init(); tki.More(); tki.Next()) {
808 TopOpeBRepDS_Kind K; Standard_Integer G; tki.Value(K,G);
809 TopOpeBRepDS_ListOfInterference& loi = tki.ChangeValue(K,G); TopOpeBRepDS_ListOfInterference Rloi;
810 Standard_Integer nloi = loi.Extent();
811
812 Standard_Boolean ok = (K == TopOpeBRepDS_VERTEX);
813 ok = ok && (nloi > 1);
814 if (!ok) {newLI.Append(loi); continue;}
815
816 TopOpeBRepDS_ListIteratorOfListOfInterference it1(loi);
817 while (it1.More()) {
818 const Handle(TopOpeBRepDS_Interference)& I1 = it1.Value();
819 TopOpeBRepDS_Kind GT1,ST1; Standard_Integer G1,S1; FDS_data(I1,GT1,G1,ST1,S1);
820 TopAbs_ShapeEnum SB1,SA1; Standard_Integer IB1,IA1; FDS_Tdata(I1,SB1,IB1,SA1,IA1);
821
822 Standard_Boolean cond1 = (SB1 == TopAbs_EDGE) && (IB1 == IA1);
823 if (!cond1) {newLI.Append(I1); it1.Next(); continue;}
824 cond1 = FUN_ds_sdm(BDS,EIX,BDS.Shape(S1));
825 if (!cond1) {newLI.Append(I1); it1.Next(); continue;}
826
827 Standard_Boolean complex1d = Standard_False;
828 TopOpeBRepDS_ListIteratorOfListOfInterference it2(it1);
829 if (it2.More()) it2.Next();
830 else break;
831 while (it2.More()){
832 const Handle(TopOpeBRepDS_Interference)& I2 = it2.Value();
833 TopOpeBRepDS_Kind GT2,ST2; Standard_Integer G2,S2; FDS_data(I2,GT2,G2,ST2,S2);
834 TopAbs_ShapeEnum SB2,SA2; Standard_Integer IB2,IA2; FDS_Tdata(I2,SB2,IB2,SA2,IA2);
835
836 Standard_Boolean cond2 = (SB1 == SB2) && (IB2 == IA2);
837 if (!cond2) {newLI.Append(I2); it2.Next(); continue;}
838 complex1d = FUN_ds_sdm(BDS,EIX,BDS.Shape(S2));
839 if (!complex1d) {newLI.Append(I2); it2.Next(); continue;}
840// LI.Extent(); //deb
841 l1dI.Append(I2); it2.Next();
842 } // it2
843 if (complex1d) {l1dI.Append(I1); it1.Next();}
844 else it1.Next();
845 } // it1
846 } // tki
847 LI.Clear(); LI.Append(newLI);
848 n1d = l1dI.Extent();
849 return n1d;
850} // select1dI
851
852//------------------------------------------------------
853Standard_EXPORT void FUN_select3dinterference
854(const Standard_Integer SIX, TopOpeBRepDS_DataStructure& BDS,
855 TopOpeBRepDS_ListOfInterference& lF, TopOpeBRepDS_ListOfInterference& l3dF,
856 TopOpeBRepDS_ListOfInterference& lFE, TopOpeBRepDS_ListOfInterference& lFEresi, TopOpeBRepDS_ListOfInterference& l3dFE, TopOpeBRepDS_ListOfInterference& l3dFEresi,
857 TopOpeBRepDS_ListOfInterference& l2dFE)
858//------------------------------------------------------
859{
860 const TopoDS_Edge& E = TopoDS::Edge(BDS.Shape(SIX));
861 Standard_Boolean isdg = BRep_Tool::Degenerated(E);
862 if (isdg) return;
863
864 l3dF.Clear(); l3dFE.Clear();
865 // attached to an edge the list of interferences :
866 // IN : <lF> = {I=(T(face),G=POINT/VERTEX,S=FACE)}
867 // <lFE> = {I=(T(face),G=POINT/VERTEX,S=EDGE)}
868
869 // OUT : <lFE> -> <l3dFE> = {I describing 3d interferences on S=EDGE}
870 // is the list of 3d interferences to reduce
871 // +<lFE> +lFEresi
872 // <lF> -> <l3dF> = {I describing 3d interferences on S=FACE}
873 // +<lF>
874 // I = (T(face),G=POINT/VERTEX,S=EDGE) in <l3dFE>
875 // <-> I' = (T(face),G=POINT/VERTEX,S=FACE) in <l3dF>
876
0797d9d3 877#ifdef OCCT_DEBUG
7fd59977 878// Standard_Integer n3dFE =
879#endif
880 ::FUN_select3dI(SIX,BDS,lFE,lFEresi,l3dFE);
0797d9d3 881#ifdef OCCT_DEBUG
7fd59977 882// Standard_Integer n3dFF =
883#endif
884 ::FUN_select3dISEsameISF(lFE,l3dFE,l3dFEresi,lF,l3dF);
0797d9d3 885#ifdef OCCT_DEBUG
7fd59977 886// Standard_Integer n2dFE =
887#endif
888 FUN_select2dI(SIX,BDS,TopAbs_FACE,lFE,l2dFE);
889}