0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_KPart.cxx
CommitLineData
b311480e 1// Created on: 1994-08-30
2// Created by: Jean Yves LEBEY
3// Copyright (c) 1994-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
7fd59977 17
2f0109b7 18#include <BRepClass3d.hxx>
7fd59977 19#include <BRepClass3d_SolidExplorer.hxx>
42cf5bc1 20#include <BRepTools.hxx>
21#include <gp_Pnt.hxx>
42cf5bc1 22#include <TopAbs.hxx>
23#include <TopExp.hxx>
24#include <TopExp_Explorer.hxx>
25#include <TopoDS.hxx>
26#include <TopoDS_Edge.hxx>
27#include <TopoDS_Face.hxx>
28#include <TopoDS_Shape.hxx>
42cf5bc1 29#include <TopoDS_Vertex.hxx>
42cf5bc1 30#include <TopOpeBRepBuild_GTool.hxx>
31#include <TopOpeBRepBuild_GTopo.hxx>
32#include <TopOpeBRepBuild_HBuilder.hxx>
7fd59977 33#include <TopOpeBRepBuild_kpresu.hxx>
42cf5bc1 34#include <TopOpeBRepDS_BuildTool.hxx>
35#include <TopOpeBRepDS_connex.hxx>
36#include <TopOpeBRepDS_CurveIterator.hxx>
37#include <TopOpeBRepDS_EXPORT.hxx>
38#include <TopOpeBRepDS_HDataStructure.hxx>
ec357c5c 39#include <TopOpeBRepDS_ShapeShapeInterference.hxx>
42cf5bc1 40#include <TopOpeBRepTool.hxx>
41#include <TopOpeBRepTool_EXPORT.hxx>
42#include <TopOpeBRepTool_SC.hxx>
43#include <TopOpeBRepTool_ShapeExplorer.hxx>
7fd59977 44
0797d9d3 45#ifdef OCCT_DEBUG
1d0a9d4d 46extern Standard_Boolean TopOpeBRepBuild_GettraceKPB();
7fd59977 47#endif
48
49static void FUN_Raise() {
0797d9d3 50#ifdef OCCT_DEBUG
04232180 51 std::cout<<"******************************ERROR"<<std::endl;
9775fa61 52 throw Standard_ProgramError("KPart.cxx");
7fd59977 53#endif
54}
55
56#define M_REVERSED(st) (st == TopAbs_REVERSED)
57
58Standard_EXPORT Standard_Boolean FUNKP_KPiskolesh(const TopOpeBRepBuild_Builder& BU,const TopOpeBRepDS_DataStructure& BDS,const TopoDS_Shape& Sarg,TopTools_ListOfShape& lShsd,TopTools_ListOfShape& lfhsd);
59
60
61//modified by NIZHNY-MKK Fri May 19 17:03:59 2000.BEGIN
62enum TopOpeBRepBuild_KPart_Operation {TopOpeBRepBuild_KPart_Operation_Fuse, TopOpeBRepBuild_KPart_Operation_Common, TopOpeBRepBuild_KPart_Operation_Cut12, TopOpeBRepBuild_KPart_Operation_Cut21};
63
64static void LocalKPisdisjanalyse(const TopAbs_State Stsol1, const TopAbs_State Stsol2,
65 const TopOpeBRepBuild_KPart_Operation& theOperation,
66 Standard_Integer& ires, Standard_Integer& icla1, Standard_Integer& icla2);
67
68static TopoDS_Solid BuildNewSolid(const TopoDS_Solid& sol1,
69 const TopoDS_Solid& sol2,
70 const TopAbs_State stsol1,
71 const TopAbs_State stsol2,
72 const Standard_Integer ires,
73 const Standard_Integer icla1,
74 const Standard_Integer icla2,
75 const TopAbs_State theState1,
76 const TopAbs_State theState2);
77
78static Standard_Boolean disjPerformFuse(const TopTools_IndexedMapOfShape& theMapOfSolid1,
79 const TopTools_IndexedMapOfShape& theMapOfSolid2,
80 TopTools_IndexedMapOfShape& theMapOfResult);
81
82static Standard_Boolean disjPerformCommon(const TopTools_IndexedMapOfShape& theMapOfSolid1,
83 const TopTools_IndexedMapOfShape& theMapOfSolid2,
84 TopTools_IndexedMapOfShape& theMapOfResult);
85
86static Standard_Boolean disjPerformCut(const TopTools_IndexedMapOfShape& theMapOfSolid1,
87 const TopTools_IndexedMapOfShape& theMapOfSolid2,
88 TopTools_IndexedMapOfShape& theMapOfResult);
89//modified by NIZHNY-MKK Fri May 19 17:04:07 2000.END
90
91
92//=======================================================================
93//function : FindIsKPart
94//purpose :
95//=======================================================================
96
97Standard_Integer TopOpeBRepBuild_Builder::FindIsKPart()
98{
99 KPClearMaps();
100
0797d9d3 101#ifdef OCCT_DEBUG
7fd59977 102 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
04232180 103 if(TKPB){std::cout<<std::endl<<"--- IsKPart ? ---"<<std::endl;}
7fd59977 104#endif
105
106 Standard_Integer isfafa = KPisfafa();
107 // face,face SameDomain
108 if (isfafa) {
109 myIsKPart = 3;
110 return KPreturn(myIsKPart);
111 }
112
113 Standard_Integer isdisj = KPisdisj();
114 // shape,shape sans aucune interference geometrique
115 if (isdisj) {
116 myIsKPart = 2;
117 return KPreturn(myIsKPart);
118 }
119
120 Standard_Integer iskole = KPiskole();
121 // solide,solide colles par faces tangentes sans aretes tangentes
122 if (iskole) {
123 myIsKPart = 1;
124 return KPreturn(myIsKPart);
125 }
126
127 Standard_Integer iskoletge = KPiskoletge();
128 // solide,solide par faces tangentes avec aretes tangentes
129 if (iskoletge) {
130 myIsKPart = 5;
131 return KPreturn(myIsKPart);
132 }
133
134 Standard_Integer issoso = KPissoso();
135 // solide,solide quelconques
136 if (issoso) {
137 myIsKPart = 4;
138 return KPreturn(myIsKPart);
139 }
140
141 myIsKPart = 0;
142 return KPreturn(myIsKPart);
143}
144
145//=======================================================================
146//function : IsKPart
147//purpose :
148//=======================================================================
149
150Standard_Integer TopOpeBRepBuild_Builder::IsKPart() const
151{
152 return myIsKPart;
153}
154
155
156//=======================================================================
157//function : MergeKPart
158//purpose :
159//=======================================================================
160
161void TopOpeBRepBuild_Builder::MergeKPart(const TopAbs_State TB1,
162 const TopAbs_State TB2)
163{
164 myState1 = TB1;
165 myState2 = TB2;
166 MergeKPart();
167}
168
169//=======================================================================
170//function : MergeKPart
171//purpose :
172//=======================================================================
173
174void TopOpeBRepBuild_Builder::MergeKPart()
175{
176 if ( myIsKPart == 1 ) { // iskole
177 MergeKPartiskole();
178 }
179 else if ( myIsKPart == 5 ) { // iskoletge
180 MergeKPartiskoletge();
181 }
182 else if (myIsKPart == 2) { // isdisj
183 MergeKPartisdisj();
184 }
185 else if ( myIsKPart == 3 ) { // isfafa
186 MergeKPartisfafa();
187 }
188 else if ( myIsKPart == 4 ) { // issoso
189 MergeKPartissoso();
190 }
191 End();
192}
193
194static void FUN_sortplcy(const TopTools_ListOfShape& lof, TopTools_ListOfShape& lopl, TopTools_ListOfShape& locy)
195{
196 TopTools_ListIteratorOfListOfShape it(lof);
197 for (; it.More(); it.Next()){
198 const TopoDS_Face& ff = TopoDS::Face(it.Value());
199 Standard_Boolean plane = FUN_tool_plane(ff);
200 if (plane) {lopl.Append(ff);}
201 Standard_Boolean cylinder = FUN_tool_cylinder(ff);
202 if (cylinder){locy.Append(ff);}
203 }
204}
205
206/*static Standard_Boolean FUN_proj2(const TopOpeBRepBuild_Builder& BU, const Handle(TopOpeBRepDS_HDataStructure)& HDS,
207 const TopoDS_Shape& Fa2, TopTools_DataMapOfShapeListOfShape& EnewE)
208{
209 const TopoDS_Face& F2 = TopoDS::Face(Fa2);
210 TopoDS_Wire Ow2 = BRepTools::OuterWire(TopoDS::Face(F2));
211 TopExp_Explorer exe(Ow2, TopAbs_EDGE);
212 for (; exe.More(); exe.Next()){
213 const TopoDS_Shape& ed = exe.Current();
214 Standard_Boolean issplit = BU.IsSplit(ed,TopAbs_ON);
215 if (!issplit) return Standard_False;
216 const TopTools_ListOfShape& speds = BU.Splits(ed,TopAbs_ON);
217 TopTools_ListOfShape lfcF2; // faces of shapei connexed to ed
218 FDSCNX_FaceEdgeConnexFaces(TopoDS::Face(F2),ed,HDS,lfcF2);
219 // prequesitory : ed in {edges of Ow2}
220 // ed's faces ancestor = {F2,fofj}
221 if (lfcF2.Extent() != 1) return Standard_False;
222 const TopoDS_Face& fcF2 = TopoDS::Face(lfcF2.First());
223
224 // projecting sp(ed) on faces F2 and fofj
225 TopTools_ListOfShape newesp;
226 TopTools_ListIteratorOfListOfShape itspe(speds);
227 for (; itspe.More(); itspe.Next()){
228 TopoDS_Edge esp = TopoDS::Edge(itspe.Value());
229 Standard_Boolean ok = FUN_tool_pcurveonF(F2,esp);
230 if (!ok) return Standard_False;
231 ok = FUN_tool_pcurveonF(fcF2,esp);
232 if (!ok) return Standard_False;
233// EnewE.Add(esp,newesp);
234 newesp.Append(esp);
235 }
236 EnewE.Bind(ed,newesp);
237 }
238 return Standard_True;
239}*/
240
241static void FUN_addf(const TopAbs_State sta, const TopoDS_Shape& ftoadd, TopTools_DataMapOfShapeShape& map)
242{
0797d9d3 243#ifdef OCCT_DEBUG
7fd59977 244// Standard_Boolean isadded = map.IsBound(ftoadd);
245#endif
246 TopoDS_Shape fori = ftoadd;
247 if (sta == TopAbs_IN) fori.Complement();
248 map.Bind(fori,fori);
249}
250
251static Standard_Integer FUN_comparekoletgesh(TopOpeBRepTool_ShapeClassifier& SC,
252 const TopoDS_Shape& sh1, const TopoDS_Shape& sh2,
253 const TopoDS_Shape& fkole1, const TopoDS_Shape& )
254// purpose: <sh1> and <sh2> are kpkoletge on faces <fkole1>,<fkole2>
255// with <fkole1> same oriented with <fkole2>
256// returns k=1,2 if shi is contained in shk
257// else returns 0
258{
259 SC.SetReference(sh2);
260 TopExp_Explorer exf(sh1,TopAbs_FACE);
261 for (; exf.More(); exf.Next()){
262 const TopoDS_Face& f1 = TopoDS::Face(exf.Current());
263 if (f1.IsSame(fkole1)) continue;
264 gp_Pnt pnt1;
265 BRepClass3d_SolidExplorer::FindAPointInTheFace(f1,pnt1);
266 SC.StateP3DReference(pnt1);
267 TopAbs_State stpnt1 = SC.State();
268 if (stpnt1 == TopAbs_IN) return 2;
269 if (stpnt1 == TopAbs_OUT) return 1;
270 }
271 return 0;
272}
273
274static Standard_Boolean FUN_changev(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Shape& v)
275{
276 Standard_Boolean changev = HDS->HasShape(v);
277 if (!changev) return Standard_False;
278 changev = HDS->HasSameDomain(v);
279 if (!changev) return Standard_False;
dde68833 280 Standard_Integer rankv = HDS->DS().AncestorRank(v);
7fd59977 281 changev = (rankv == 2);
282 return changev;
283}
284static Standard_Boolean FUN_updatev
285(const Handle(TopOpeBRepDS_HDataStructure)& HDS, TopoDS_Edge& newed,
286 const TopoDS_Vertex& v, const TopAbs_Orientation oriv, const Standard_Real parv, const Standard_Boolean changev)
287{
288 TopOpeBRepDS_BuildTool BT;
289 BRep_Builder BB;
290 if (changev) {
291 TopoDS_Shape oov; Standard_Boolean ok = FUN_ds_getoov(v,HDS,oov);
292 if(!ok) return Standard_False;
293 oov.Orientation(oriv);
294 BB.Add(newed,oov);
295 BT.Parameter(newed,oov,parv);
296 }
297 else {
298 TopoDS_Shape aLocalShape = v.Oriented(oriv);
299 TopoDS_Vertex ov = TopoDS::Vertex(aLocalShape);
300// TopoDS_Vertex ov = TopoDS::Vertex(v.Oriented(oriv));
301 BB.Add(newed,ov);
302 BT.Parameter(newed,ov,parv);
303 }
304 return Standard_True;
305}
306
307static Standard_Boolean FUN_makefaces(const TopOpeBRepBuild_Builder& BU, const Handle(TopOpeBRepDS_HDataStructure)& HDS, TopTools_DataMapOfShapeListOfShape& EnewE,
308 const TopoDS_Shape& f, const TopoDS_Shape& , TopTools_ListOfShape& newfaces)
309//prequesitory : <outerwi>=<f>'s outer wire
310//purpose : <outerwi>={edow},
311// edow=(vf,vl), if(rank(vj)=2 && vj sdm vj1), replace vj by vj1
312// <f> gives <newf>
313
314{
315 TopOpeBRepDS_BuildTool BT;
316 BRep_Builder BB;
317 TopoDS_Shape aLocalShape = f.Oriented(TopAbs_FORWARD);
318 TopoDS_Face F = TopoDS::Face(aLocalShape); // working on FORWARD face
319// TopoDS_Face F = TopoDS::Face(f.Oriented(TopAbs_FORWARD)); // working on FORWARD face
320 TopAbs_Orientation of = f.Orientation();
321
322 //the new outer wire :
323 // -------------------
324 TopTools_ListOfShape loe;
325 // -------
326 TopoDS_Wire outerwf = BRepTools::OuterWire(F);
327 TopExp_Explorer ex(outerwf, TopAbs_EDGE);
328 for (; ex.More(); ex.Next()){
329 const TopoDS_Edge& ed = TopoDS::Edge(ex.Current());
330 TopAbs_Orientation oe = ed.Orientation();
331 Standard_Boolean issplit = BU.IsSplit(ed,TopAbs_ON);
332 Standard_Boolean isbound = EnewE.IsBound(ed);
333
334 if (!isbound && !issplit) {
335 // new edge
336 TopoDS_Vertex vf,vl; TopExp::Vertices(ed,vf,vl);
337 Standard_Boolean changevf = ::FUN_changev(HDS,vf);
338 Standard_Boolean changevl = ::FUN_changev(HDS,vl);
339 Standard_Boolean changee = changevf || changevl;
340 if (changee) {
341 Standard_Real ff = BRep_Tool::Parameter(vf, ed);
342 Standard_Real l = BRep_Tool::Parameter(vl, ed);
343
344 TopoDS_Edge newed; BT.CopyEdge(ed.Oriented(TopAbs_FORWARD),newed);
345 Standard_Boolean ok = ::FUN_updatev(HDS,newed,vf,TopAbs_FORWARD,ff,changevf);
346 if (!ok) return Standard_False;
347 ok = ::FUN_updatev(HDS,newed,vl,TopAbs_REVERSED,l,changevl);
348 if (!ok) return Standard_False;
349 newed.Orientation(oe);
350 TopTools_ListOfShape led; led.Append(newed); EnewE.Bind(ed,led);
351 isbound = Standard_True;
352 }
353 }
354
355 if (issplit) {
356 const TopTools_ListOfShape& speds = BU.Splits(ed,TopAbs_ON);
357 if (speds.Extent() == 0) return Standard_False;
358 const TopoDS_Edge& spe = TopoDS::Edge(speds.First());
359 Standard_Boolean sameori = FUN_tool_SameOri(ed,spe);
360 TopAbs_Orientation orisp = spe.Orientation();
361 if (!sameori) orisp = TopAbs::Complement(orisp);
362
363 TopTools_ListIteratorOfListOfShape it(speds);
364 for (; it.More(); it.Next()) {
365 TopoDS_Edge esp = TopoDS::Edge(it.Value());
366 Standard_Boolean ok = FUN_tool_pcurveonF(TopoDS::Face(f),esp);
367 if (!ok) return Standard_False;
368 TopoDS_Shape ee = esp.Oriented(orisp);
369 loe.Append(ee);
370 }
371 }
372 else if (isbound) {
373 const TopTools_ListOfShape& neweds = EnewE.ChangeFind(ed);
374 TopTools_ListIteratorOfListOfShape itnes(neweds);
375 for (; itnes.More(); itnes.Next()) loe.Append(itnes.Value().Oriented(oe));
376 }
377 else
378 loe.Append(ed);
379 }
380
381 TopoDS_Wire newW;
382 //---------------
383 BB.MakeWire(newW);
384 for (TopTools_ListIteratorOfListOfShape itee(loe); itee.More(); itee.Next())
385 BB.Add(newW,itee.Value());
386
387 // the new face :
388 // --------------
389 aLocalShape = F.EmptyCopied();
390 TopoDS_Face newf = TopoDS::Face(aLocalShape);
391// TopoDS_Face newf = TopoDS::Face(F.EmptyCopied());
392 BB.Add(newf,newW);
393
394 // other wires of <f> :
395 TopExp_Explorer exw(F, TopAbs_WIRE);
396 for (; exw.More(); exw.Next()){
397 const TopoDS_Wire OOw = TopoDS::Wire(exw.Current());
398 if (OOw.IsSame(outerwf)) continue;
399 BB.Add(newf,OOw);
400 }
401
402 if (M_REVERSED(of)) newf.Orientation(TopAbs_REVERSED);
403
404 // xpu140898 : CTS21251
405 TopoDS_Face Newf = newf;
406 Standard_Boolean ok = TopOpeBRepTool::CorrectONUVISO(TopoDS::Face(f),Newf);
407 if (ok) newfaces.Append(Newf);
408 else newfaces.Append(newf);
409
410 return Standard_True;
411}
412
413static Standard_Boolean FUN_rebuildfc(const TopOpeBRepBuild_Builder& BU, const Handle(TopOpeBRepDS_HDataStructure)& HDS,
414 const TopAbs_State , const TopoDS_Shape& Fk,
415 TopTools_DataMapOfShapeListOfShape& EnewE, TopTools_IndexedDataMapOfShapeListOfShape& fcnewfc)
416// Owk = <Fk>'s outer wire
417//prequesitory: Owk = {edk}, Splits(edk,Stk) = spedk
418//purpose: fills up <fcnewfc> = {(fcFk,newfcFk)}
419// with {fcFk} = faces of shape k connexed to Owk
420// fcFk has edges {edk}
421{
0797d9d3 422#ifdef OCCT_DEBUG
7fd59977 423// const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
424// Standard_Integer rFk = BDS.AncestorRank(Fk);
425#endif
426 TopoDS_Wire Owk = BRepTools::OuterWire(TopoDS::Face(Fk));
427 TopTools_ListOfShape eds; FUN_tool_shapes(Owk,TopAbs_EDGE,eds);
428 TopTools_ListIteratorOfListOfShape ite(eds);
429
430 ite.Initialize(eds);
431 for (; ite.More(); ite.Next()){
432 const TopoDS_Shape& ed = ite.Value();
433 TopTools_ListOfShape lfcFk; // faces of shapei connexed to ed
434 FDSCNX_FaceEdgeConnexFaces(TopoDS::Face(Fk),ed,HDS,lfcFk);
435 // prequesitory : ed in {edges of Owk}
436 // ed's faces ancestor = {Fk,fofj}
437 if (lfcFk.Extent() != 1) return Standard_False;
438
439 // purpose : Building up new topologies on connexed faces
440 // attached to outer wire's edges.
441 const TopoDS_Shape& fcFk = lfcFk.First();
442 TopTools_ListOfShape newfcFk; Standard_Boolean ok = FUN_makefaces(BU,HDS,EnewE,fcFk,Owk,newfcFk);
443 if (!ok) return Standard_False;
444 fcnewfc.Add(fcFk,newfcFk);
445 }
446 return Standard_True;
447} // FUN_rebuildfc
448
0797d9d3 449#ifdef OCCT_DEBUG
7fd59977 450Standard_EXPORT void debiskoletge() {}
451#endif
452
453//=======================================================================
454//function : MergeKPartiskoletge
455//purpose :
456//=======================================================================
457
458void TopOpeBRepBuild_Builder::MergeKPartiskoletge()
459{
0797d9d3 460#ifdef OCCT_DEBUG
7fd59977 461 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
462 if (TKPB) KPreturn(myIsKPart);
463 debiskoletge();
464#endif
465
466 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
467// Standard_Integer ibid;
468
469 if ( myIsKPart != 5 ) {FUN_Raise(); return;}
470
471 GMapShapes(myShape1,myShape2);
472 // NYI : on doit pouvoir faire l'economie du mapping GMapShapes(...)
473 // NYI en allant chercher l'indice 1,2 retourne par GShapeRank(S)
474 // NYI dans la DS. l'index est defini pour tous les shapes HasSameDomain
475
476 TopTools_ListOfShape& lmergesha1 = ChangeMerged(myShape1,myState1);
477 ChangeMerged(myShape2,myState2);
478
479 TopTools_ListOfShape lShsd1,lShsd2; // liste de solides HasSameDomain
480 TopTools_ListOfShape lfhsd1,lfhsd2; // liste de faces HasSameDomain
481 KPiskoletgesh(myShape1,lShsd1,lfhsd1);
482 KPiskoletgesh(myShape2,lShsd2,lfhsd2);
483
484 // traitement de tous les solides NYI
485 TopoDS_Shape sol1 = lShsd1.First();
486 TopoDS_Shape sol2 = lShsd2.First();
487
488 ChangeMerged(sol1,myState1);
489 ChangeMerged(sol2,myState2);
490
491 TopTools_ListOfShape lplhsd1, lcyhsd1; ::FUN_sortplcy(lfhsd1,lplhsd1,lcyhsd1);
492 TopTools_ListOfShape lplhsd2, lcyhsd2; ::FUN_sortplcy(lfhsd2,lplhsd2,lcyhsd2);
493 const TopoDS_Face& fac1 = TopoDS::Face(lplhsd1.First());
494 const TopoDS_Face& fac2 = TopoDS::Face(lplhsd2.First());
0797d9d3 495#ifdef OCCT_DEBUG
7fd59977 496 Standard_Integer iF1 =
497#endif
498 myDataStructure->Shape(fac1); //DEB
0797d9d3 499#ifdef OCCT_DEBUG
7fd59977 500 Standard_Integer iF2 =
501#endif
502 myDataStructure->Shape(fac2); //DEB
503
0797d9d3 504#ifdef OCCT_DEBUG
04232180 505 if (TKPB) {std::cout<<""<<std::endl;std::cout<<"face "<<iF1<<" : ";std::cout<<iF2<<std::endl;}
7fd59977 506#endif
507
508 TopOpeBRepDS_Config config2 = BDS.SameDomainOri(fac2);
509
510 Standard_Boolean SameOriented = (config2 == TopOpeBRepDS_SAMEORIENTED);
511
512 const TopoDS_Shape* pfGRE = NULL;
513 const TopoDS_Shape* pfSMA = NULL;
514
515 Standard_Integer rgre = 1;
516 if (SameOriented) {
517 // getting greater
518 rgre = ::FUN_comparekoletgesh(myShapeClassifier,
519 myShape1,myShape2,fac1,fac2);
520 if (rgre == 0) rgre = FUN_tool_comparebndkole(myShape1,myShape2);
521 }
522 if (rgre == 0) {FUN_Raise(); return;}
523
524 // ires :
525 //-------
526 Standard_Integer rsma = (rgre == 1)? 2: 1;
527 pfSMA = (rsma == 1)? &fac1: &fac2;
528 pfGRE = (rgre == 1)? &fac1: &fac2;
529 TopAbs_State staSMA = (rsma == 1)? myState1: myState2;
530 TopAbs_State staGRE = (rgre == 1)? myState1: myState2;
531
532 TopoDS_Shape shaSMA = (rsma == 1)? myShape1: myShape2;
533 TopoDS_Shape shaGRE = (rgre == 1)? myShape1: myShape2;
534
535 Standard_Integer ires = 0; KPiskoletgeanalyse(config2,staSMA,staGRE,ires);
536
537 // merge :
538 //-------
539 TopoDS_Shape sheSMA; // sheSMA = shell accedant facSMA
540 TopTools_IndexedDataMapOfShapeListOfShape MfacsheSMA;
541 TopExp::MapShapesAndAncestors(shaSMA,TopAbs_FACE,TopAbs_SHELL,MfacsheSMA);
542 const TopTools_ListOfShape& lsheSMA = MfacsheSMA.FindFromKey(*pfSMA);
543 TopTools_ListIteratorOfListOfShape itlsheSMA(lsheSMA);
544 sheSMA = itlsheSMA.Value();
545
546 TopoDS_Shape sheGRE; // sheGRE = shell accedant facGRE
547 TopTools_IndexedDataMapOfShapeListOfShape MfacsheGRE;
548 TopExp::MapShapesAndAncestors(shaGRE,TopAbs_FACE,TopAbs_SHELL,MfacsheGRE);
549 const TopTools_ListOfShape& lsheGRE = MfacsheGRE.FindFromKey(*pfGRE);
550 TopTools_ListIteratorOfListOfShape itlsheGRE(lsheGRE);
551 sheGRE = itlsheGRE.Value();
552
553 ChangeMerged(sheSMA, staSMA);
554 ChangeMerged(sheGRE, staGRE);
555
556 TopoDS_Shell newshe;
557 if (ires == RESNULL) {
558 return;
559 }
560 else if (ires == RESSHAPE1) {
561 myBuildTool.MakeShell(newshe);
562 newshe = TopoDS::Shell(sheSMA);
563 }
564 else if (ires == RESSHAPE2) {
565 myBuildTool.MakeShell(newshe);
566 newshe = TopoDS::Shell(sheGRE);
567 }
568 else if (ires == RESNEWSOL) {
569
570 TopTools_DataMapOfShapeShape addedfaces;
571 // As splits of outer wire's edges have 2drep only on shape1,
572 // we have to project them on the connexed faces of shape2
573 TopTools_DataMapOfShapeListOfShape EnewE;
574// Standard_Boolean ok = ::FUN_proj2((*this),myDataStructure,fac2,EnewE);
575// if (!ok) {FUN_Raise(); return;}
576
577 // new topologies :
578 TopTools_IndexedDataMapOfShapeListOfShape fcnewfcSMA;// faces connexed to fSMA built up with the split of outerwSMA
579 TopTools_IndexedDataMapOfShapeListOfShape fcnewfcGRE;// faces connexed to fGRE built up with the split of outerwGRE
580 Standard_Boolean ok = ::FUN_rebuildfc((*this),myDataStructure,staSMA,*pfSMA,EnewE,fcnewfcSMA);
581 if (!ok) {FUN_Raise(); return;}
582 Standard_Integer nfcSMA = fcnewfcSMA.Extent();
583// for (Standard_Integer i=1; i<=nfcSMA; i++) {
584 Standard_Integer i ;
585 for ( i=1; i<=nfcSMA; i++) {
586 const TopoDS_Shape& f = fcnewfcSMA.FindKey(i);
587 const TopTools_ListOfShape& newlf = fcnewfcSMA.FindFromIndex(i);
588
589 TopTools_ListIteratorOfListOfShape it(newlf);
590 for (; it.More(); it.Next()){
591 const TopoDS_Shape& ff = it.Value();
592 ::FUN_addf(staSMA,ff,addedfaces);
593 ChangeMerged(f,staSMA).Append(ff);
594 }
595 } // fcnewfcSMA
596 ok = ::FUN_rebuildfc((*this),myDataStructure,staGRE,*pfGRE,EnewE,fcnewfcGRE);
597 if (!ok) {FUN_Raise(); return;}
598 Standard_Integer nfcGRE = fcnewfcGRE.Extent();
599 for (i=1; i<=nfcGRE; i++) {
600 const TopoDS_Shape& f = fcnewfcGRE.FindKey(i);
601 const TopTools_ListOfShape& newlf = fcnewfcGRE.FindFromIndex(i);
602
603 TopTools_ListIteratorOfListOfShape it(newlf);
604 for (; it.More(); it.Next()){
605 const TopoDS_Shape& ff = it.Value();
606 ::FUN_addf(staGRE,ff,addedfaces);
607 ChangeMerged(f,staGRE).Append(ff);
608 }
609 } // fcnewfcGRE
610
611 // old topologies :
612 TopTools_ListOfShape lOOfSMA; // DEB : faces of SMA non connexed to fSMA
613 TopTools_ListOfShape lOOfGRE; // DEB : faces of GRE non connexed to fGRE
614 TopExp_Explorer exSMA(shaSMA, TopAbs_FACE);
615 for (; exSMA.More(); exSMA.Next()){
616 const TopoDS_Shape& ff = exSMA.Current();
617 if (fcnewfcSMA.Contains(ff)) continue;
618 if (ff.IsSame(*pfSMA)) continue;
619 lOOfSMA.Append(ff); // DEB
620 ::FUN_addf(staSMA,ff,addedfaces);
621 }
622 TopExp_Explorer exGRE(shaGRE, TopAbs_FACE);
623 for (; exGRE.More(); exGRE.Next()){
624 const TopoDS_Shape& ff = exGRE.Current();
625 if (fcnewfcGRE.Contains(ff)) continue;
626 if (ff.IsSame(*pfGRE)) continue;
627 lOOfGRE.Append(ff); // DEB
628 ::FUN_addf(staGRE,ff,addedfaces);
629 }
630
631 // newshell :
632 TopTools_DataMapIteratorOfDataMapOfShapeShape itadd(addedfaces);
633 Standard_Boolean yauadd = itadd.More();
634 if (yauadd) {
635 myBuildTool.MakeShell(newshe);
636 myBuildTool.Closed(newshe,Standard_True); // NYI : check exact du caractere closed du shell
637 }
638 for (; itadd.More(); itadd.Next() ) {
639 const TopoDS_Shape& ftoadd = itadd.Key();
640 myBuildTool.AddShellFace(newshe,ftoadd);
641 }
642
643 } // RESNEWSOL
644
645 TopoDS_Solid newsol;
646 if ( !newshe.IsNull() ) {
647 myBuildTool.MakeSolid(newsol);
648 myBuildTool.AddSolidShell(newsol,newshe);
649 }
650
651 // le solide final
652 if ( !newsol.IsNull() ) {
653 lmergesha1.Append(newsol);
654 }
655
656} // MergeKPartiskoletge
657
658//=======================================================================
659//function : MergeKPartisdisj
660//purpose :
661//=======================================================================
662
663void TopOpeBRepBuild_Builder::MergeKPartisdisj()
664{
0797d9d3 665#ifdef OCCT_DEBUG
7fd59977 666 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
667 if (TKPB) KPreturn(myIsKPart);
668#endif
669
670 if (myIsKPart != 2) return; // isdisj
671
672 TopTools_ListOfShape& lmergesha1 = ChangeMerged(myShape1,myState1);
673/* TopTools_ListOfShape& lmergesha2 =*/ ChangeMerged(myShape2,myState2);
674
7fd59977 675 Standard_Boolean soldisj = Standard_False;
676 TopOpeBRepTool_ShapeExplorer exsol1(myShape1,TopAbs_SOLID);
677 Standard_Boolean hassol1 = exsol1.More();
678 TopOpeBRepTool_ShapeExplorer exsol2(myShape2,TopAbs_SOLID);
679 Standard_Boolean hassol2 = exsol2.More();
680 soldisj = (hassol1 && hassol2);
7fd59977 681
682//modified by NIZHNY-MKK Fri May 19 16:18:12 2000.BEGIN
683 Standard_Boolean hasnotsol1=Standard_False;
684 Standard_Boolean hasnotsol2=Standard_False;
685 TopExp_Explorer anExp(myShape1, TopAbs_SHELL, TopAbs_SOLID);
686 for(Standard_Integer i=TopAbs_SHELL; i <= TopAbs_VERTEX && !hasnotsol1 && !hasnotsol2; i++) {
687 anExp.Init(myShape1, (TopAbs_ShapeEnum)i, TopAbs_SOLID);
688 if(anExp.More())
689 hasnotsol1 = Standard_True;
690 anExp.Init(myShape2, (TopAbs_ShapeEnum)i, TopAbs_SOLID);
691 if(anExp.More())
692 hasnotsol2 = Standard_True;
693 }
694 soldisj = !(hasnotsol1 || hasnotsol2);
7fd59977 695//modified by NIZHNY-MKK Fri May 19 16:18:16 2000.END
696
697 TopoDS_Solid sol1; TopoDS_Shell outsha1;
698 TopoDS_Solid sol2; TopoDS_Shell outsha2;
699
700 if ( soldisj ) {
701//modified by NIZHNY-MKK Fri May 19 16:47:19 2000.BEGIN
702 TopTools_IndexedMapOfShape aMapOfSolid1, aMapOfSolid2;
703 TopExp::MapShapes(myShape1, TopAbs_SOLID, aMapOfSolid1);
704 TopExp::MapShapes(myShape2, TopAbs_SOLID, aMapOfSolid2);
705
706 if(aMapOfSolid1.Extent() > 1 || aMapOfSolid2.Extent() > 1) {
707 TopTools_IndexedMapOfShape aMapOfResult;
708 if(Opefus()) {
709 if(!disjPerformFuse(aMapOfSolid1, aMapOfSolid2, aMapOfResult))
710 return;
711 }
712 else if(Opec12()) {
713 if(!disjPerformCut(aMapOfSolid1, aMapOfSolid2, aMapOfResult))
714 return;
715 }
716 else if(Opec21()) {
717 if(!disjPerformCut(aMapOfSolid2, aMapOfSolid1, aMapOfResult))
718 return;
719 }
720 else if(Opecom()) {
721 if(!disjPerformCommon(aMapOfSolid1, aMapOfSolid2, aMapOfResult))
722 return;
723 }
724 for(Standard_Integer ii=1; ii<=aMapOfResult.Extent(); ii++) {
725 lmergesha1.Append(aMapOfResult(ii));
726 }
727 return;
728 } //end if(aMapOfSolid1.Extent() > 1 || aMapOfSolid2.Extent() > 1)
729 else {
730//modified by NIZHNY-MKK Fri May 19 16:47:23 2000.END
731 sol1 = TopoDS::Solid(exsol1.Current());
732 ChangeMerged(sol1,myState1);
2f0109b7 733 outsha1 = BRepClass3d::OuterShell(sol1);
7fd59977 734
735 sol2 = TopoDS::Solid(exsol2.Current());
736 ChangeMerged(sol2,myState2);
2f0109b7 737 outsha2 = BRepClass3d::OuterShell(sol2);
7fd59977 738
739 TopAbs_State stsol1 = KPclasSS(outsha1,sol2);
740 TopAbs_State stsol2 = KPclasSS(outsha2,sol1);
741
742 Standard_Integer ires,icla1,icla2;
743 KPisdisjanalyse(stsol1,stsol2,ires,icla1,icla2);
744
745 if (ires == RESUNDEF) {
746 return;
747 }
748
749 else if (icla1 == SHEUNDEF || icla2 == SHEUNDEF) {
750 return;
751 }
752
753 else if (ires == RESNULL) {
754 return;
755 }
756
757 else if (ires == RESSHAPE12) {
758 lmergesha1.Append(myShape1);
759 lmergesha1.Append(myShape2);
760 return;
761 }
762
763 else if (ires == RESSHAPE1) {
764 lmergesha1.Append(myShape1);
765 return;
766 }
767
768 else if (ires == RESSHAPE2) {
769 lmergesha1.Append(myShape2);
770 return;
771 }
772
773 else if (ires == RESNEWSHA1 ||
774 ires == RESNEWSHA2) {
775 //modified by NIZHNY-MKK Tue May 23 11:36:33 2000.BEGIN
776 TopoDS_Solid newsol = BuildNewSolid(sol1, sol2, stsol1, stsol2, ires, icla1, icla2, myState1, myState2);
777 //modified by NIZHNY-MKK Tue May 23 11:36:39 2000.END
778 lmergesha1.Append(newsol);
779 return;
780 }
781 else {
0797d9d3 782#ifdef OCCT_DEBUG
04232180 783 std::cout<<"TopOpeBRepBuild_MergeKPart soldisj : ires = "<<ires<<std::endl;
7fd59977 784#endif
785 return;
786 }
787//modified by NIZHNY-MKK Tue May 23 11:37:15 2000
788 } //end else of if(aMapOfSolid1.Extent() > 1 || aMapOfSolid2.Extent() > 1)
789
790 } // if (soldisj)
791 else { //
792
793 if (Opec12()) {
794 lmergesha1.Append(myShape1);
795 }
796 else if (Opec21()) {
797 lmergesha1.Append(myShape2);
798 }
799 else if (Opecom()) {
800 lmergesha1.Clear();
801 }
802 else if (Opefus()) {
803 lmergesha1.Append(myShape1);
804 lmergesha1.Append(myShape2);
805 }
806 else return;
807
808 } // ( !soldisj )
809
810 return;
811
812} // MergeKPartisdisj
813
814//=======================================================================
815//function : MergeKPartisfafa
816//purpose :
817//=======================================================================
818
819void TopOpeBRepBuild_Builder::MergeKPartisfafa()
820{
0797d9d3 821#ifdef OCCT_DEBUG
7fd59977 822 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
823 if (TKPB) KPreturn(myIsKPart);
824#endif
825
826 if ( myIsKPart == 3 ) { // isfafa
827
828 TopExp_Explorer ex;
829 ex.Init(myShape1,TopAbs_FACE); if (! ex.More() ) return;
830 TopoDS_Shape F1 = ex.Current();
831 ex.Init(myShape2,TopAbs_FACE); if (! ex.More() ) return;
832 TopoDS_Shape F2 = ex.Current();
833
834 TopTools_ListOfShape LF1,LF2;
835 GFindSamDom(F1,LF1,LF2);
836
837 TopAbs_ShapeEnum tf = TopAbs_FACE;
838 TopOpeBRepBuild_GTopo G;
839 if (Opec12()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf);
840 else if (Opec21()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf).CopyPermuted();
841 else if (Opecom()) G=TopOpeBRepBuild_GTool::GComSame(tf,tf);
842 else if (Opefus()) G=TopOpeBRepBuild_GTool::GFusSame(tf,tf);
843 else return;
844
845 GMapShapes(myShape1,myShape2);
846 GMergeFaces(LF1,LF2,G);
847
848 if (myShape1.ShapeType() == TopAbs_COMPOUND) {
849 TopTools_ListOfShape& L1 = ChangeMerged(myShape1,myState1);
850 L1 = ChangeMerged(F1,myState1);
851 }
852
853 if (myShape2.ShapeType() == TopAbs_COMPOUND) {
854 TopTools_ListOfShape& L2 = ChangeMerged(myShape2,myState2);
855 L2 = ChangeMerged(F2,myState2);
856 }
857
858 }
859
860} // MergeKPartisfafa
861
862//=======================================================================
863//function : MergeKPartissoso
864//purpose :
865//=======================================================================
866
867void TopOpeBRepBuild_Builder::MergeKPartissoso()
868{
0797d9d3 869#ifdef OCCT_DEBUG
7fd59977 870 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
871 if (TKPB) KPreturn(myIsKPart);
872#endif
873
874 if ( myIsKPart == 4 ) { // issoso
875
876 TopExp_Explorer ex;
877
878 TopoDS_Shape SO1;
879 if (!myShape1.IsNull()) {
880 ex.Init(myShape1,TopAbs_SOLID);
881 if (! ex.More() ) return;
882 SO1 = ex.Current();
883 }
884
885 TopoDS_Shape SO2;
886 if (!myShape2.IsNull()) {
887 ex.Init(myShape2,TopAbs_SOLID);
888 if (! ex.More() ) return;
889 SO2 = ex.Current();
890 }
891
892 if (SO1.IsNull()) return;
893
894 TopTools_ListOfShape LSO1,LSO2;
895 GFindSamDom(SO1,LSO1,LSO2);
896
897 TopAbs_ShapeEnum tf = TopAbs_FACE; // NYI TopAbs_SOLID
898 TopOpeBRepBuild_GTopo G;
899 if (Opec12()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf);
900 else if (Opec21()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf).CopyPermuted();
901 else if (Opecom()) G=TopOpeBRepBuild_GTool::GComSame(tf,tf);
902 else if (Opefus()) G=TopOpeBRepBuild_GTool::GFusSame(tf,tf);
903 else return;
904
905 GMapShapes(myShape1,myShape2);
906 GMergeSolids(LSO1,LSO2,G);
907
908 if (!myShape1.IsNull()) {
909 if (myShape1.ShapeType() == TopAbs_COMPOUND) {
910 TopTools_ListOfShape& L1 = ChangeMerged(myShape1,myState1);
911 L1 = ChangeMerged(SO1,myState1);
912 }
913 }
914
915 if (!myShape2.IsNull()) {
916 if (myShape2.ShapeType() == TopAbs_COMPOUND) {
917 TopTools_ListOfShape& L2 = ChangeMerged(myShape2,myState2);
918 L2 = ChangeMerged(SO2,myState2);
919 }
920 }
921
922 }
923
924} // MergeKPartissoso
925
926static Standard_Boolean sectionedgesON(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Shape& outerw1,
927 const TopTools_IndexedMapOfShape& mape2)
928// prequesitory : all edges of <outerw1> are section edges
929{
930 TopExp_Explorer ex1(outerw1, TopAbs_EDGE);
931 for (; ex1.More(); ex1.Next()){
932 const TopoDS_Shape& e1 = ex1.Current();
933 TopTools_ListIteratorOfListOfShape it2 = HDS->SameDomain(e1);
934 if (!it2.More()) return Standard_False; // xpu231098 : cto904C7 : e1 !hsd
935 for (; it2.More(); it2.Next()){
936 const TopoDS_Shape& e2 = it2.Value();
937 Standard_Boolean isbound = mape2.Contains(e2);
938 if (!isbound) return Standard_False;
939 }
940 }
941 return Standard_True;
942}
943
944static Standard_Boolean allIonsectionedges(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Shape& f1,
945 const TopTools_IndexedMapOfShape& mape1,
946 const TopTools_IndexedMapOfShape& mape2)
947// prequesitory : all interferences attached to <f1> are SSI
948{
949 TopOpeBRepDS_ListIteratorOfListOfInterference it1(HDS->DS().ShapeInterferences(f1));
950 for (; it1.More(); it1.Next()){
c5f3a425 951 Handle(TopOpeBRepDS_ShapeShapeInterference) SSI1 (Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(it1.Value()));
7fd59977 952 Standard_Integer G1 = SSI1->Geometry();
953 Standard_Boolean isgbound = SSI1->GBound();
954 const TopoDS_Shape& e1 = HDS->Shape(G1);
955 Standard_Boolean isbound = isgbound? mape1.Contains(e1): mape2.Contains(e1);
956 if (!isbound) return Standard_False;
957 }
958 return Standard_True;
959}
960
961//=======================================================================
962//function : KPiskoletge
963//purpose : detection faces collees tangentes sur wire exterieur
964//=======================================================================
965
966Standard_Integer TopOpeBRepBuild_Builder::KPiskoletge()
967{
0797d9d3 968/*#ifdef OCCT_DEBUG
7fd59977 969 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
970#endif*/
971
972 TopTools_ListOfShape lShsd1,lShsd2; // liste de solides HasSameDomain
973 TopTools_ListOfShape lfhsd1,lfhsd2; // liste de faces HasSameDomain
974
975 Standard_Boolean iskp1 = KPiskoletgesh(myShape1,lShsd1,lfhsd1);
976 if ( !iskp1 ) return 0;
977 TopTools_ListOfShape lplhsd1, lcyhsd1; ::FUN_sortplcy(lfhsd1,lplhsd1, lcyhsd1);
978 Standard_Integer nplhsd1 = lplhsd1.Extent(); Standard_Integer ncyhsd1 = lcyhsd1.Extent();
979 if ( nplhsd1 != 1 ) return 0;
980 if ( ncyhsd1 > 1 ) return 0;
981
982 Standard_Boolean iskp2 = KPiskoletgesh(myShape2,lShsd2,lfhsd2);
983 if ( !iskp2 ) return 0;
984 TopTools_ListOfShape lplhsd2, lcyhsd2; ::FUN_sortplcy(lfhsd2,lplhsd2, lcyhsd2);
985 Standard_Integer nplhsd2 = lplhsd2.Extent(); Standard_Integer ncyhsd2 = lcyhsd2.Extent();
986 if ( nplhsd2 != 1 ) return 0;
987
988 // Si l'un des objets est constitue de plusieurs solides on passe
989 // dans le cas general.
990 Standard_Integer nshsd1 = lShsd1.Extent();
991 Standard_Integer nshsd2 = lShsd2.Extent();
992 if ( nshsd1>1 || nshsd2>1 ) return 0;
993
994
995 // NYI : (nplhsd1 > 1) || (nplhsd2 > 1)
996 // ------------------------------------
997
998 const TopoDS_Face& f1 = TopoDS::Face(lplhsd1.First());
0797d9d3 999#ifdef OCCT_DEBUG
7fd59977 1000// Standard_Boolean isb1 = myKPMAPf1f2.IsBound(f1); // DEB
1001#endif
1002
1003 const TopoDS_Face& f2 = TopoDS::Face(lplhsd2.First());
0797d9d3 1004#ifdef OCCT_DEBUG
7fd59977 1005// Standard_Boolean isb2 = myKPMAPf1f2.IsBound(f2); // DEB
1006#endif
1007
0797d9d3 1008#ifdef OCCT_DEBUG
7fd59977 1009 Standard_Integer iF1,iF2;
1010 Standard_Boolean tSPS1 = GtraceSPS(f1,iF1);
1011 Standard_Boolean tSPS2 = GtraceSPS(f2,iF2);
1012 if(tSPS1 || tSPS2)
1013 {GdumpSHA( f1, (char *) "KPiskoletge ");
04232180 1014 std::cout<<std::endl;
7fd59977 1015 GdumpSHA( f2, (char *)"KPiskoletge ");
04232180 1016 std::cout<<std::endl;}
7fd59977 1017#endif
1018
1019 TopoDS_Wire outerw1 = BRepTools::OuterWire(f1);
1020 TopoDS_Wire outerw2 = BRepTools::OuterWire(f2);
1021
1022 TopTools_IndexedMapOfShape mape1; TopExp::MapShapes(outerw1, TopAbs_EDGE, mape1);
1023 TopTools_IndexedMapOfShape mape2; TopExp::MapShapes(outerw2, TopAbs_EDGE, mape2);
1024
1025 Standard_Boolean se1ONouterw2 = ::sectionedgesON(myDataStructure,outerw1,mape2);
1026 if (!se1ONouterw2) return 0;
1027 Standard_Boolean se2ONouterw1 = ::sectionedgesON(myDataStructure,outerw2,mape1);
1028 if (!se2ONouterw1) return 0;
1029
1030 // NYI : <fi> interfers with faces of <Sj> on edges different from outerw's edges
1031 // ------------------------------------------------------------------------------
1032 Standard_Boolean allI1onseouterw = ::allIonsectionedges(myDataStructure,f1,mape1,mape2);
1033 if (!allI1onseouterw) return 0;
1034 Standard_Boolean allI2onseouterw = ::allIonsectionedges(myDataStructure,f2,mape2,mape1);
1035 if (!allI2onseouterw) return 0;
1036
1037
1038 // NYI : (ncyhsd1 > 1) || (ncyhsd2 > 1)
1039 // ------------------------------------
1040 // KPcycy :
1041 if (ncyhsd1 > 0) {
1042 Standard_Boolean cycy = ( ncyhsd1 == 1 ) && ( ncyhsd2 == 1 );
1043 if (!cycy) return 0;
1044
1045 Standard_Boolean isbound1 = FUN_tool_inS(outerw1,f1);
1046 if (!isbound1) return 0;
1047 Standard_Boolean isbound2 = FUN_tool_inS(outerw2,f2);
1048 if (!isbound2) return 0;
1049 }
1050
1051 return 1;
1052}
1053
1054//=======================================================================
1055//function : KPisdisj
1056//purpose : detection shapes disjoints
1057//=======================================================================
1058
1059Standard_Integer TopOpeBRepBuild_Builder::KPisdisj()
1060{
0797d9d3 1061#ifdef OCCT_DEBUG
7fd59977 1062 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1063#endif
1064
1065 // myShape1 et myShape2 : aucune interference
1066 const TopOpeBRepDS_DataStructure& DS = myDataStructure->DS();
1067 // Standard_Integer nsh = DS.NbShapes();
1068 // if (nsh != 2) return 0;
1069
1070 if (!DS.HasShape(myShape1)) return 0;
1071 if (!DS.HasShape(myShape2)) return 0;
1072
1073 Standard_Integer isdisj1 = KPisdisjsh(myShape1);
1074 Standard_Integer isdisj2 = KPisdisjsh(myShape2);
1075
0797d9d3 1076#ifdef OCCT_DEBUG
7fd59977 1077 if (TKPB) {
04232180 1078 std::cout<<"isdisj : "<<isdisj1<<" "<<isdisj2<<std::endl;
7fd59977 1079 }
1080#endif
1081
1082 Standard_Integer isdisj = (isdisj1 && isdisj2) ? 1 : 0;
1083 return isdisj;
1084}
1085
1086//=======================================================================
1087//function : KPisfafa
1088//purpose : detection {face} / {face} toutes HasSameDomain
1089//=======================================================================
1090
1091Standard_Integer TopOpeBRepBuild_Builder::KPisfafa()
1092{
0797d9d3 1093/*#ifdef OCCT_DEBUG
7fd59977 1094 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1095#endif*/
dde68833 1096
1097 return KPisfafash(myShape1) != 0
1098 && KPisfafash(myShape2) != 0
1099 ? 1
1100 : 0;
7fd59977 1101}
1102
1103//=======================================================================
1104//function : KPissoso
1105//purpose : detection {solide} / {solide} tous HasSameDomain
1106//=======================================================================
1107
1108Standard_Integer TopOpeBRepBuild_Builder::KPissoso()
1109{
0797d9d3 1110/*#ifdef OCCT_DEBUG
7fd59977 1111 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1112#endif*/
dde68833 1113
1114 return KPissososh(myShape1) != 0
1115 && KPissososh(myShape2) != 0
1116 ? 1
1117 : 0;
7fd59977 1118}
1119
1120//=======================================================================
1121//function : KPClearMaps
1122//purpose :
1123//=======================================================================
1124
1125void TopOpeBRepBuild_Builder::KPClearMaps()
1126{
1127 myKPMAPf1f2.Clear();
1128}
1129
1130//=======================================================================
1131//function : KPlhg
1132//purpose : --> nb des subsshapes <T> de <S> qui sont HasGeometry()
1133//=======================================================================
1134
1135Standard_Integer TopOpeBRepBuild_Builder::KPlhg(const TopoDS_Shape& S,const TopAbs_ShapeEnum T) const
1136{
1137 TopTools_ListOfShape L;
1138 Standard_Integer n = KPlhg(S,T,L);
1139 return n;
1140}
1141
1142//=======================================================================
1143//function : KPlhg
1144//purpose : --> nb +liste des subsshapes <T> de <S> qui sont HasGeometry()
1145//=======================================================================
1146
1147Standard_Integer TopOpeBRepBuild_Builder::KPlhg(const TopoDS_Shape& S,const TopAbs_ShapeEnum T,TopTools_ListOfShape& L) const
1148{
1149 Standard_Integer n = 0;
1150 L.Clear();
1151
1152 TopExp_Explorer ex;
1153 for (ex.Init(S,T); ex.More(); ex.Next()) {
1154// for (TopExp_Explorer ex(S,T); ex.More(); ex.Next()) {
1155 const TopoDS_Shape& s = ex.Current();
1156 Standard_Boolean hg = myDataStructure->HasGeometry(s);
1157 if (hg) {
1158 n++;
1159 L.Append(s);
1160 }
1161 }
1162
1163 return n;
1164}
1165
1166//=======================================================================
1167//function : KPlhsd
1168//purpose :
1169// KPlhsd --> nb des subsshapes <T> de <S> qui sont HasSameDomain()
1170//=======================================================================
1171
1172Standard_Integer TopOpeBRepBuild_Builder::KPlhsd(const TopoDS_Shape& S,const TopAbs_ShapeEnum T) const
1173{
1174 TopTools_ListOfShape L;
1175 Standard_Integer n = KPlhsd(S,T,L);
1176 return n;
1177}
1178
1179//=======================================================================
1180//function : KPlhsd
1181//purpose :
1182// KPlhsd --> nb + liste des subsshapes <T> de <S> qui sont HasSameDomain()
1183//=======================================================================
1184
1185Standard_Integer TopOpeBRepBuild_Builder::KPlhsd(const TopoDS_Shape& S,const TopAbs_ShapeEnum T,TopTools_ListOfShape& L) const
1186{
1187 Standard_Integer n = 0;
1188 L.Clear();
1189
1190 TopExp_Explorer ex;
1191 for (ex.Init(S,T); ex.More(); ex.Next()) {
1192// for (TopExp_Explorer ex(S,T); ex.More(); ex.Next()) {
1193 const TopoDS_Shape& s = ex.Current();
1194 Standard_Boolean hsd = myDataStructure->HasSameDomain(s);
1195 if (hsd) {
1196 n++;
1197 L.Append(s);
1198 }
1199 }
1200
1201 return n;
1202}
1203
1204//=======================================================================
1205//function : KPclasSS
1206//purpose :
1207// classifie le shape S1 par rapport a S2 en evitant de prendre
1208// les shape exLS1 de S1 comme element de classification.
1209// exS1 peut etre IsNull().
1210// S1,S2 = SOLID | SHELL
1211//=======================================================================
1212
1213TopAbs_State TopOpeBRepBuild_Builder::KPclasSS(const TopoDS_Shape& S1,const TopTools_ListOfShape& exLS1,const TopoDS_Shape& S2)
1214{
1215 TopAbs_State state = TopAbs_UNKNOWN;
1216 state = myShapeClassifier.StateShapeShape(S1,exLS1,S2);
1217
0797d9d3 1218#ifdef OCCT_DEBUG
7fd59977 1219 if (TopOpeBRepBuild_GettraceKPB()) {
1220 const gp_Pnt& P1 = myShapeClassifier.P3D();
04232180 1221 std::cout<<"point P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z();
1222 std::cout<<" "; TopAbs::Print(state,std::cout);std::cout<<std::endl;
7fd59977 1223 }
1224#endif
1225
1226 return state;
1227}
1228
1229//=======================================================================
1230//function : KPclasSS
1231//purpose :
1232// classifie le shape S1 par rapport a S2 en evitant de prendre
1233// le shape exS1 de S1 comme element de classification.
1234// exS1 peut etre IsNull().
1235// S1,S2 = SOLID | SHELL
1236//=======================================================================
1237
1238TopAbs_State TopOpeBRepBuild_Builder::KPclasSS(const TopoDS_Shape& S1,const TopoDS_Shape& exS1,const TopoDS_Shape& S2)
1239{
1240 TopAbs_State state = myShapeClassifier.StateShapeShape(S1,exS1,S2);
1241
0797d9d3 1242#ifdef OCCT_DEBUG
7fd59977 1243 if (TopOpeBRepBuild_GettraceKPB()) {
1244 const gp_Pnt& P1 = myShapeClassifier.P3D();
04232180 1245 std::cout<<"point P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z();
1246 std::cout<<" "; TopAbs::Print(state,std::cout);std::cout<<std::endl;
7fd59977 1247 }
1248#endif
1249
1250 return state;
1251}
1252
1253//=======================================================================
1254//function : KPclasSS
1255//purpose : classifie le shape S1 par rapport a S2 sans evitement de shape
1256// S1,S2 = SOLID | SHELL
1257//=======================================================================
1258
1259TopAbs_State TopOpeBRepBuild_Builder::KPclasSS(const TopoDS_Shape& S1,const TopoDS_Shape& S2)
1260{
1261 TopoDS_Shape Snull;
1262 TopAbs_State state = KPclasSS(S1,Snull,S2);
1263 return state;
1264}
1265
1266//=======================================================================
1267//function : KPiskoletgesh
1268//purpose :
1269// KPiskoletgesh :
1270// S est il un shape traite par le cas particulier de koletge?
1271// si oui : retourne un solide et une liste de faces de collage
1272//=======================================================================
1273
1274Standard_Boolean TopOpeBRepBuild_Builder::KPiskoletgesh(const TopoDS_Shape& Sarg,TopTools_ListOfShape& lShsd,TopTools_ListOfShape& lfhsd) const
1275{
0797d9d3 1276#ifdef OCCT_DEBUG
7fd59977 1277 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1278#endif
1279 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
1280 Standard_Boolean iskolesh = FUNKP_KPiskolesh((*this),BDS,Sarg,lShsd,lfhsd);
1281 if (!iskolesh) return Standard_False;
1282
0797d9d3 1283#ifdef OCCT_DEBUG
7fd59977 1284 Standard_Integer nfhsd =
1285#endif
1286 KPlhsd(Sarg,TopAbs_FACE,lfhsd);
1287 TopTools_ListIteratorOfListOfShape it(lfhsd);
1288 for (; it.More(); it.Next() ) {
1289 const TopoDS_Face& fac = TopoDS::Face(it.Value());
1290 Standard_Boolean isplan = FUN_tool_plane(fac);
1291 Standard_Boolean iscylinder = FUN_tool_cylinder(fac);
1292 if (iscylinder) continue;
1293 if (!isplan) return Standard_False;
1294
1295 TopoDS_Wire outerw = BRepTools::OuterWire(fac);
1296 if (outerw.IsNull()) return Standard_False;
1297
1298 TopExp_Explorer exe(outerw, TopAbs_EDGE);
1299// Standard_Integer ne = 0;
1300 for (; exe.More(); exe.Next()){
1301 const TopoDS_Edge& ed = TopoDS::Edge(exe.Current());
1302 Standard_Boolean isse = BDS.IsSectionEdge(ed);
1303 const TopTools_ListOfShape& sp = (*this).Splits(ed,TopAbs_ON);
1304 if (sp.Extent() == 0) return Standard_False;
1305 if (!isse) return Standard_False;
1306// ne++;
1307 }
1308// if (ne > 1) return Standard_False;
1309
0797d9d3 1310#ifdef OCCT_DEBUG
7fd59977 1311 Standard_Integer isol = myDataStructure->Shape(Sarg); Standard_Integer ifac = myDataStructure->Shape(fac);
04232180 1312 if(TKPB){std::cout<<"isol "<<isol<<std::endl;}
1313 if(TKPB){std::cout<<"nfhsd "<<nfhsd<<std::endl;}
1314 if(TKPB){std::cout<<"ifac "<<ifac<<std::endl;}
1315 if(TKPB){std::cout<<"isplan "<<isplan<<std::endl;}
1316 if(TKPB){std::cout<<"iscylinder "<<iscylinder<<std::endl;}
1317 if(TKPB){std::cout<<std::endl;}
7fd59977 1318#endif
1319 }
1320
1321 return Standard_True;
1322}
1323
1324//=======================================================================
1325//function : KPSameDomain
1326//purpose : complete the lists L1,L2 with the shapes of the DS
1327// having same domain :
1328// L1 = shapes sharing the same domain of L2 shapes
1329// L2 = shapes sharing the same domain of L1 shapes
1330// (L1 contains a face)
1331//=======================================================================
1332
1333void TopOpeBRepBuild_Builder::KPSameDomain(TopTools_ListOfShape& L1, TopTools_ListOfShape& L2) const
1334{
1335 Standard_Integer i;
1336 Standard_Integer nl1 = L1.Extent(), nl2 = L2.Extent();
1337
1338 while ( nl1 > 0 || nl2 > 0 ) {
1339
1340 TopTools_ListIteratorOfListOfShape it1(L1);
1341 for (i=1 ; i<=nl1; i++) {
1342 const TopoDS_Shape& S1 = it1.Value();
0797d9d3 1343#ifdef OCCT_DEBUG
7fd59977 1344// Standard_Integer iS1 = myDataStructure->Shape(S1);
1345#endif
1346 TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S1));
1347 for (; itsd.More(); itsd.Next() ) {
1348 const TopoDS_Shape& S2 = itsd.Value();
0797d9d3 1349#ifdef OCCT_DEBUG
7fd59977 1350// Standard_Integer iS2 = myDataStructure->Shape(S2);
1351#endif
1352 Standard_Boolean found = KPContains(S2,L2);
1353 if ( ! found ) {
1354 L2.Prepend(S2);
1355 nl2++;
1356 }
1357 }
1358 it1.Next();
1359 }
1360 nl1 = 0;
1361
1362 TopTools_ListIteratorOfListOfShape it2(L2);
1363 for (i=1 ; i<=nl2; i++) {
1364 const TopoDS_Shape& S2 = it2.Value();
0797d9d3 1365#ifdef OCCT_DEBUG
7fd59977 1366// Standard_Integer iS2 = myDataStructure->Shape(S2);
1367#endif
1368 TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S2));
1369 for (; itsd.More(); itsd.Next() ) {
1370 const TopoDS_Shape& S1 = itsd.Value();
0797d9d3 1371#ifdef OCCT_DEBUG
7fd59977 1372// Standard_Integer iS1 = myDataStructure->Shape(S1);
1373#endif
1374 Standard_Boolean found = KPContains(S1,L1);
1375 if ( ! found ) {
1376 L1.Prepend(S1);
1377 nl1++;
1378 }
1379 }
1380 it2.Next();
1381 }
1382 nl2 = 0;
1383 }
1384}
1385
1386//=======================================================================
1387//function : KPisdisjsh
1388//purpose : S est il un shape traite par le cas particulier "disjoint"
1389//=======================================================================
1390
1391Standard_Integer TopOpeBRepBuild_Builder::KPisdisjsh(const TopoDS_Shape& Sarg) const
1392{
1393 if ( Sarg.IsNull() ) return 0;
1394
1395 TopExp_Explorer ex;
1396 Standard_Integer nhg;
1397
1398 nhg = KPlhg(Sarg,TopAbs_SOLID);
1399 if ( nhg != 0 ) return 0;
1400
1401 nhg = KPlhg(Sarg,TopAbs_FACE);
1402 if ( nhg != 0 ) return 0;
1403
1404 nhg = KPlhg(Sarg,TopAbs_EDGE);
1405 if ( nhg != 0 ) return 0;
1406
1407 // un seul niveau de HasSameDomain
1408 Standard_Integer n1,n2;
1409 TopTools_ListOfShape lshsd;
1410
1411 n1 = KPlhsd(Sarg,TopAbs_SOLID,lshsd);
1412 if ( n1 ) {
1413 TopTools_ListIteratorOfListOfShape it(lshsd);
1414 for(;it.More();it.Next()) {
1415 const TopoDS_Shape& s = it.Value();
1416 n2 = KPlhsd(s,TopAbs_FACE);
1417 if (n2 != 0 ) return 0;
1418 }
1419 }
1420
1421 n1 = KPlhsd(Sarg,TopAbs_FACE,lshsd);
1422 if ( n1 ) {
1423 TopTools_ListIteratorOfListOfShape it(lshsd);
1424 for(;it.More();it.Next()) {
1425 const TopoDS_Shape& s = it.Value();
1426 n2 = KPlhsd(s,TopAbs_EDGE);
1427 if (n2 != 0 ) return 0;
1428 }
1429 }
1430
1431 return 1;
1432}
1433
1434//=======================================================================
1435//function : KPissososh
1436//purpose : detection S = {solid} tous HasSameDomain
1437//=======================================================================
1438
1439Standard_Integer TopOpeBRepBuild_Builder::KPissososh(const TopoDS_Shape& Sarg) const
1440{
1441 // que des solides volants (nb total de solides = nb de solides volants)
1442 Standard_Integer nsol1 = 0;
1443 TopExp_Explorer ex1(Sarg,TopAbs_SOLID);
1444 for(; ex1.More(); ex1.Next()) nsol1++;
1445
1446 Standard_Integer nsol2 = 0;
1447 TopExp_Explorer ex2(Sarg,TopAbs_SOLID,TopAbs_COMPSOLID);
1448 for(; ex2.More(); ex2.Next()) nsol2++;
1449
1450 if (nsol1 && (nsol1 != nsol2)) return 0;
1451
1452 // toutes les solides sont HasSameDomain()
1453 Standard_Integer nhsd = KPlhsd(Sarg,TopAbs_SOLID);
1454 if (nhsd != nsol1) return 0;
1455
1456 Standard_Integer n; TopExp_Explorer ex;
1457
1458 // pas de shell volant
1459 n = 0;
1460 for (ex.Init(Sarg,TopAbs_SHELL,TopAbs_SOLID); ex.More(); ex.Next()) n++;
1461 if (n) return 0;
1462
1463 // pas de face volant
1464 n = 0;
1465 for (ex.Init(Sarg,TopAbs_FACE,TopAbs_SHELL); ex.More(); ex.Next()) n++;
1466 if (n) return 0;
1467
1468 // pas d'edge volant
1469 n = 0;
1470 for (ex.Init(Sarg,TopAbs_EDGE,TopAbs_WIRE); ex.More(); ex.Next()) n++;
1471 if (n) return 0;
1472
1473 // pas de vertex volant
1474 n = 0;
1475 for (ex.Init(Sarg,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) n++;
1476 if (n) return 0;
1477
1478 return 1;
1479}
1480
1481//=======================================================================
1482//function : KPisfafash
1483//purpose : detection S = {face} toutes HasSameDomain
1484//=======================================================================
1485
1486Standard_Integer TopOpeBRepBuild_Builder::KPisfafash(const TopoDS_Shape& Sarg) const
1487{
1488 // il n'y a que des faces volantes (nb total de faces = nb de faces volantes)
1489 Standard_Integer nfac1 = 0;
1490 TopExp_Explorer ex1(Sarg,TopAbs_FACE);
1491 for(; ex1.More(); ex1.Next()) nfac1++;
1492
1493 Standard_Integer nfac2 = 0;
1494 TopExp_Explorer ex2(Sarg,TopAbs_FACE,TopAbs_SHELL);
1495 for(; ex2.More(); ex2.Next()) nfac2++;
1496
1497 if (nfac1 && (nfac1 != nfac2)) return 0;
1498
1499 // toutes les faces sont HasSameDomain()
1500 Standard_Integer nhsd = KPlhsd(Sarg,TopAbs_FACE);
1501 if (nhsd != nfac1) return 0;
1502
1503 Standard_Integer n; TopExp_Explorer ex;
1504
1505 // pas de wire volant
1506 n = 0;
1507 for (ex.Init(Sarg,TopAbs_WIRE,TopAbs_FACE); ex.More(); ex.Next()) n++;
1508 if (n) return 0;
1509
1510 // pas d'edge volant
1511 n = 0;
1512 for (ex.Init(Sarg,TopAbs_EDGE,TopAbs_WIRE); ex.More(); ex.Next()) n++;
1513 if (n) return 0;
1514
1515 // pas de vertex volant
1516 n = 0;
1517 for (ex.Init(Sarg,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) n++;
1518 if (n) return 0;
1519
1520 return 1;
1521}
1522
1523//=======================================================================
1524//function : KPiskoletgeanalyse
1525//purpose :
1526//=======================================================================
1527
1528void TopOpeBRepBuild_Builder::KPiskoletgeanalyse(const TopOpeBRepDS_Config config2,
1529 const TopAbs_State Stsol1, const TopAbs_State Stsol2,
1530 Standard_Integer& ires) const
1531{
1532 // -----------------------------------------------------------------------------
1533 // prequesitory : (nplhsd1 == 1) || (nplhsd2 == 1)
1534 // ------------- <plsdmi> has all interferences Ii = (T, G=edge of outerw1
1535 // ||edge of outerw2, S)
1536 // -----------------------------------------------------------------------------
1537
1538 ires = RESUNDEF;
1539
1540 Standard_Boolean SameOriented = (config2 == TopOpeBRepDS_SAMEORIENTED);
1541 Standard_Boolean DiffOriented = (config2 == TopOpeBRepDS_DIFFORIENTED);
1542
1543// Standard_Boolean com = Opecom();
1544// Standard_Boolean c12 = Opec12();
1545// Standard_Boolean c21 = Opec21();
1546// Standard_Boolean fus = Opefus();
1547
1548 if (DiffOriented) {
1549 if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_IN)
1550// if (com) ires = RESNULL;
1551 ires = RESNULL;
1552
1553 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN) {
1554// if (c12) ires = RESSHAPE1; // rank(sol1) == 1 && rank(sol2) == 2
1555// if (c21) ires = RESSHAPE2; // rank(sol1) == 2 && rank(sol2) == 1
1556 ires = RESSHAPE1;
1557 }
1558
1559 if (Stsol2 == TopAbs_OUT && Stsol1 == TopAbs_IN) {
1560// if (c12) ires = RESSHAPE2; // rank(sol2) == 1 && rank(sol1) == 2
1561// if (c21) ires = RESSHAPE1; // rank(sol2) == 2 && rank(sol1) == 1
1562 ires = RESSHAPE2;
1563 }
1564
1565 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT)
1566// if (fus) ires = RESNEWSOL;
1567 ires = RESNEWSOL;
1568 } // DiffOriented
1569
1570 if (SameOriented) {
1571 // ==============================
1572 // PREQUESITORY :sol1 is IN sol2
1573 // ==============================
1574
1575 if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_IN)
1576// if (com) ires = RESSHAPE1;
1577 ires = RESSHAPE1;
1578
1579 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN) {
1580// if (c12) ires = RESNULL; // rank(sol1) == 1 && rank(sol2) == 2
1581// if (c21) ires = RESNEWSOL; // rank(sol1) == 2 && rank(sol2) == 1
1582 ires = RESNULL;
1583 }
1584
1585 if (Stsol2 == TopAbs_OUT && Stsol1 == TopAbs_IN) {
1586// if (c12) ires = RESNULL; // rank(sol2) == 1 && rank(sol1) == 2
1587// if (c21) ires = RESNEWSOL; // rank(sol2) == 2 && rank(sol1) == 1
1588 ires = RESNEWSOL;
1589 }
1590
1591 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT)
1592// if (fus) ires = RESSHAPE2;
1593 ires = RESSHAPE2;
1594 } // SameOriented
1595
0797d9d3 1596#ifdef OCCT_DEBUG
7fd59977 1597 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
04232180 1598 if (TKPB) std::cout<<"ires = "<<ires<<std::endl;
7fd59977 1599#endif
1600}
1601
1602
1603//=======================================================================
1604//function : KPisdisjanalyse
1605//purpose :
1606//=======================================================================
1607
1608void TopOpeBRepBuild_Builder::KPisdisjanalyse(const TopAbs_State Stsol1, const TopAbs_State Stsol2,
1609 Standard_Integer& ires,Standard_Integer& icla1,Standard_Integer& icla2) const
1610{
1611 ires = RESUNDEF; icla1 = icla2 = SHEUNDEF;
1612
1613 if (Opefus()) {
1614 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1615 ires = RESSHAPE12; icla1 = icla2 = SHEAUCU; //--
1616 }
1617 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1618 ires = RESNEWSHA1; icla1 = icla2 = SHECLASAUTR; //--
1619 }
1620 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1621 ires = RESNEWSHA2; icla1 = icla2 = SHECLASAUTR; //--
1622 }
1623 }
1624 else if (Opec12()) {
1625 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1626 ires = RESSHAPE1; icla1 = SHEGARDTOUS; icla2 = SHEAUCU; //--
1627 }
1628 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1629 ires = RESNEWSHA1; icla1 = SHECLASAUTR; icla2 = SHEGARDCOUR; //--
1630 }
1631 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1632 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1633 }
1634 }
1635 else if (Opec21()) {
1636 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1637 ires = RESSHAPE2; icla1 = SHEAUCU; icla2 = SHEGARDTOUS; //--
1638 }
1639 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1640 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1641 }
1642 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1643 ires = RESNEWSHA2; icla1 = SHEGARDCOUR; icla2 = SHECLASAUTR; //--
1644 }
1645 }
1646 else if (Opecom()) {
1647 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1648 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1649 }
1650 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1651 ires = RESNEWSHA2; icla1 = SHECLASAUTR; icla2 = SHEGARDAUTR; //--
1652 }
1653 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1654 ires = RESNEWSHA1; icla1 = SHEGARDAUTR; icla2 = SHECLASAUTR; //--
1655 }
1656 }
1657
0797d9d3 1658#ifdef OCCT_DEBUG
7fd59977 1659 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
04232180 1660 if (TKPB) std::cout<<"ires = "<<ires<<" icla1 "<<icla1<<" icla2 "<<icla2<<std::endl;
7fd59977 1661#endif
1662}
1663
1664//=======================================================================
1665//function : KPls (class method)
1666//purpose :
1667// KPls --> nb des subsshapes <T> de <S>
1668//=======================================================================
1669
1670Standard_Integer TopOpeBRepBuild_Builder::KPls(const TopoDS_Shape& S,const TopAbs_ShapeEnum T)
1671{
1672 TopTools_ListOfShape L;
1673 Standard_Integer n = KPls(S,T,L);
1674 return n;
1675}
1676
1677//=======================================================================
1678//function : KPls (class method)
1679//purpose :
1680// KPls --> nb + liste des subsshapes <T> de <S>
1681//=======================================================================
1682
1683Standard_Integer TopOpeBRepBuild_Builder::KPls(const TopoDS_Shape& S, const TopAbs_ShapeEnum T, TopTools_ListOfShape& L)
1684{
1685 Standard_Integer n = 0;
1686 L.Clear();
1687
1688 TopExp_Explorer ex;
1689 for (ex.Init(S,T); ex.More(); ex.Next()) {
1690// for (TopExp_Explorer ex(S,T); ex.More(); ex.Next()) {
1691 const TopoDS_Shape& s = ex.Current();
1692 n++;
1693 L.Append(s);
1694 }
1695
1696 return n;
1697}
1698
1699//=======================================================================
1700//function : KPclassF (class method)
1701//purpose :
1702// KPclassF : classification F1 par rapport a F2
1703// F1 et F2 ne partagent aucune arete
1704// F1 et F2 sont SameDomain
1705//=======================================================================
1706
1707TopAbs_State TopOpeBRepBuild_Builder::KPclassF(const TopoDS_Shape& F1,const TopoDS_Shape& F2)
1708{
1709 if (F1.IsNull()) return TopAbs_UNKNOWN;
1710 if (F2.IsNull()) return TopAbs_UNKNOWN;
1711
1712 TopoDS_Face F1F = TopoDS::Face(F1); F1F.Orientation(TopAbs_FORWARD);
1713 TopoDS_Face F2F = TopoDS::Face(F2); F2F.Orientation(TopAbs_FORWARD);
1714
1715 TopTools_ListOfShape le1;
1716 Standard_Integer ne1 = KPls(F1F,TopAbs_EDGE,le1);
1717 if ( ne1 == 0 ) return TopAbs_UNKNOWN;
1718 const TopoDS_Edge& e1 = TopoDS::Edge(le1.First());
1719
1720 Standard_Integer isamdom = 1;
1721 TopAbs_State St1 = TopAbs_UNKNOWN;
1722 St1 = myShapeClassifier.StateShapeShape(e1,F2F,isamdom);
1723 return St1;
1724}
1725
1726//=======================================================================
1727//function : KPclassFF (class method)
1728//purpose :
1729// classifie F1/F2 --> etats des faces l'une par rapport a l'autre
1730//=======================================================================
1731
1732void TopOpeBRepBuild_Builder::KPclassFF(const TopoDS_Shape& F1,const TopoDS_Shape& F2,TopAbs_State& St1,TopAbs_State& St2)
1733{
1734 St1 = KPclassF(F1,F2);
1735 St2 = KPclassF(F2,F1);
1736
0797d9d3 1737#ifdef OCCT_DEBUG
7fd59977 1738 if (TopOpeBRepBuild_GettraceKPB()) {
04232180 1739 std::cout<<"Stf1 ";TopAbs::Print(St1,std::cout); std::cout<<" ";
1740 std::cout<<"Stf2 ";TopAbs::Print(St2,std::cout); std::cout<<std::endl;
7fd59977 1741 }
1742#endif
1743}
1744
1745//=======================================================================
1746//function : KPiskoleFF
1747//purpose :
1748// classifie F1/F2 --> etats des faces l'une par rapport a l'autre
1749// --> True si la configutration topologique correspond au cas "iskole".
1750//=======================================================================
1751
1752Standard_Boolean TopOpeBRepBuild_Builder::KPiskoleFF(const TopoDS_Shape& F1,const TopoDS_Shape& F2,TopAbs_State& St1,TopAbs_State& St2)
1753{
0797d9d3 1754#ifdef OCCT_DEBUG
7fd59977 1755 Standard_Integer iF1;
1756 Standard_Boolean tSPS1 = GtraceSPS(F1,iF1);
1757 Standard_Integer iF2;
1758 Standard_Boolean tSPS2 = GtraceSPS(F2,iF2);
04232180 1759 if(tSPS1) { GdumpSHA(F1, (char *) "KPiskoleFF ");std::cout<<std::endl; }
1760 if(tSPS2) { GdumpSHA(F2, (char *) "KPiskoleFF ");std::cout<<std::endl; }
7fd59977 1761#endif
1762
1763 KPclassFF(F1,F2,St1,St2);
1764 Standard_Boolean st1ok = (St1 == TopAbs_OUT || St1 == TopAbs_IN);
1765 Standard_Boolean st2ok = (St2 == TopAbs_OUT || St2 == TopAbs_IN);
1766
1767 if ( !st1ok ) return Standard_False;
1768 if ( !st2ok ) return Standard_False;
1769 Standard_Boolean stok = (St1 != St2);
1770 if ( !stok ) return Standard_False;
1771 return Standard_True;
1772}
1773
1774//=======================================================================
1775//function : KPContains (class method)
1776//purpose : returns True if S is in the list L.
1777//=======================================================================
1778
1779Standard_Boolean TopOpeBRepBuild_Builder::KPContains(const TopoDS_Shape& S,const TopTools_ListOfShape& L)
1780{
1781 for (TopTools_ListIteratorOfListOfShape it(L); it.More(); it.Next() ) {
1782 const TopoDS_Shape& SL = it.Value();
1783 Standard_Boolean issame = SL.IsSame(S);
1784 if ( issame ) return Standard_True;
1785 }
1786 return Standard_False;
1787} // KPContains
1788
1789//=======================================================================
1790//function : KPreturn (class method)
1791//purpose :
1792//=======================================================================
1793
1794Standard_Integer TopOpeBRepBuild_Builder::KPreturn(const Standard_Integer b)
1795{
0797d9d3 1796#ifdef OCCT_DEBUG
7fd59977 1797 if (TopOpeBRepBuild_GettraceKPB()) {
04232180 1798 std::cout<<"--- IsKPart "<<b;
1799 if ( b == 1 ) std::cout<<" iskole";
1800 if ( b == 2 ) std::cout<<" isdisj";
1801 if ( b == 3 ) std::cout<<" isfafa";
1802 std::cout<<" ---"<<std::endl;
7fd59977 1803 }
1804#endif
1805 return b;
1806}
1807
1808//modified by NIZHNY-MKK Tue May 23 09:48:47 2000.BEGIN
1809//======================================================================================================
1810// static function : LocalKPisdisjanalyse
1811// purpose:
1812//======================================================================================================
1813static void LocalKPisdisjanalyse(const TopAbs_State Stsol1, const TopAbs_State Stsol2,
1814 const TopOpeBRepBuild_KPart_Operation& theOperation,
1815 Standard_Integer& ires, Standard_Integer& icla1, Standard_Integer& icla2) {
1816 ires = RESUNDEF; icla1 = icla2 = SHEUNDEF;
1817
1818 switch(theOperation) {
1819 case TopOpeBRepBuild_KPart_Operation_Fuse: {
1820 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1821 ires = RESSHAPE12; icla1 = icla2 = SHEAUCU; //--
1822 }
1823 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1824 ires = RESNEWSHA1; icla1 = icla2 = SHECLASAUTR; //--
1825 }
1826 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1827 ires = RESNEWSHA2; icla1 = icla2 = SHECLASAUTR; //--
1828 }
1829 break;
1830 }
1831 case TopOpeBRepBuild_KPart_Operation_Cut12: {
1832 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1833 ires = RESSHAPE1; icla1 = SHEGARDTOUS; icla2 = SHEAUCU; //--
1834 }
1835 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1836 ires = RESNEWSHA1; icla1 = SHECLASAUTR; icla2 = SHEGARDCOUR; //--
1837 }
1838 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1839 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1840 }
1841 break;
1842 }
1843 case TopOpeBRepBuild_KPart_Operation_Cut21: {
1844 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1845 ires = RESSHAPE2; icla1 = SHEAUCU; icla2 = SHEGARDTOUS; //--
1846 }
1847 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1848 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1849 }
1850 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1851 ires = RESNEWSHA2; icla1 = SHEGARDCOUR; icla2 = SHECLASAUTR; //--
1852 }
1853 break;
1854 }
1855 case TopOpeBRepBuild_KPart_Operation_Common: {
1856 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1857 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1858 }
1859 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1860 ires = RESNEWSHA2; icla1 = SHECLASAUTR; icla2 = SHEGARDAUTR; //--
1861 }
1862 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1863 ires = RESNEWSHA1; icla1 = SHEGARDAUTR; icla2 = SHECLASAUTR; //--
1864 }
1865 break;
1866 }
1867 default: {
04232180 1868 std::cout << "Warning: given operation is unknown" << std::endl;
7fd59977 1869 break;
1870 }
1871 } //end switch
1872
1873}
1874
1875//======================================================================================================
1876// static function : BuildNewSolid
1877// purpose: Build new solid based on sol1 and sol2 according to the states
1878//======================================================================================================
1879static TopoDS_Solid BuildNewSolid(const TopoDS_Solid& sol1,
1880 const TopoDS_Solid& sol2,
1881 const TopAbs_State stsol1,
1882 const TopAbs_State stsol2,
1883 const Standard_Integer ires,
1884 const Standard_Integer icla1,
1885 const Standard_Integer icla2,
1886 const TopAbs_State theState1,
1887 const TopAbs_State theState2) {
1888
1889 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
1890 TopoDS_Shape Snull;
1891 TopTools_MapOfShape isdisjmap;
1892 TopOpeBRepDS_BuildTool aBuildTool;
1893 TopoDS_Solid sol;
1894 TopAbs_State solstate,shastatetoadd;
1895 TopoDS_Shell outsha;
1896 Standard_Integer icla;
1897 TopoDS_Solid othersol;
2f0109b7 1898 TopoDS_Shell outsha1 = BRepClass3d::OuterShell(sol1);
1899 TopoDS_Shell outsha2 = BRepClass3d::OuterShell(sol2);
7fd59977 1900
1901
1902 TopoDS_Solid newsol;
1903 aBuildTool.MakeSolid(newsol);
1904 if (ires == RESNEWSHA1) {
1905 if ( ! isdisjmap.Contains(outsha1) ) {
1906 isdisjmap.Add(outsha1);
1907 aBuildTool.AddSolidShell(newsol,outsha1);
1908 }
1909 }
1910 else if (ires == RESNEWSHA2) {
1911 if ( ! isdisjmap.Contains(outsha2) ) {
1912 isdisjmap.Add(outsha2);
1913 aBuildTool.AddSolidShell(newsol,outsha2);
1914 }
1915 }
1916
1917 sol = sol1;
1918 solstate = stsol1;
1919 shastatetoadd = theState1;
1920 outsha = outsha1;
1921 icla = icla1;
1922 othersol = sol2;
1923
1924 {
1925 TopOpeBRepTool_ShapeExplorer exsha;
1926 for (exsha.Init(sol,TopAbs_SHELL); exsha.More(); exsha.Next()) {
1927 const TopoDS_Shell& shacur = TopoDS::Shell(exsha.Current());
1928 Standard_Boolean isoutsha = shacur.IsEqual(outsha);
1929
1930 Standard_Boolean garde = Standard_True;
1931 if (icla==SHEAUCU) garde = Standard_False;
1932 else if (icla==SHEGARDAUTR || icla==SHECLASAUTR) garde = ! isoutsha;
1933 if (!garde) continue;
1934
1935 Standard_Boolean add = Standard_False;
1936 if ( icla==SHEGARDCOUR ) add = Standard_True;
1937 else if ( icla==SHEGARDAUTR ) add = Standard_True;
1938 else if ( icla==SHEGARDTOUS ) add = Standard_True;
1939 else if ( icla==SHECLASAUTR ) {
1940 TopAbs_State state = aShapeClassifier.StateShapeShape(shacur,Snull,othersol);
1941 add = (state == shastatetoadd);
1942 }
1943 if (add) {
1944 TopoDS_Shell shaori = shacur;
1945 Standard_Boolean r = (solstate == TopAbs_IN);
1946 if (r) shaori.Complement();
1947 if ( ! isdisjmap.Contains(shaori) ) {
1948 isdisjmap.Add(shaori);
1949 aBuildTool.AddSolidShell(newsol,shaori);
1950 }
1951 }
1952 }
1953 } //end block1
1954
1955 sol = sol2;
1956 solstate = stsol2;
1957 shastatetoadd = theState2;
1958 outsha = outsha2;
1959 icla = icla2;
1960 othersol = sol1;
1961
1962 {
1963 TopOpeBRepTool_ShapeExplorer exsha;
1964 for (exsha.Init(sol,TopAbs_SHELL); exsha.More(); exsha.Next()) {
1965 const TopoDS_Shell& shacur = TopoDS::Shell(exsha.Current());
1966 Standard_Boolean isoutsha = shacur.IsEqual(outsha);
1967
1968 Standard_Boolean garde = Standard_True;
1969 if (icla==SHEAUCU) garde = Standard_False;
1970 else if (icla==SHEGARDAUTR || icla==SHECLASAUTR) garde = ! isoutsha;
1971 if (!garde) continue;
1972
1973 Standard_Boolean add = Standard_False;
1974 if ( icla==SHEGARDCOUR ) add = Standard_True;
1975 else if ( icla==SHEGARDAUTR ) add = Standard_True;
1976 else if ( icla==SHEGARDTOUS ) add = Standard_True;
1977 else if ( icla==SHECLASAUTR ) {
1978 TopAbs_State state = aShapeClassifier.StateShapeShape(shacur,Snull,othersol);
1979 add = (state == shastatetoadd);
1980 }
1981 if (add) {
1982 TopoDS_Shell shaori = shacur;
1983 Standard_Boolean r = (solstate == TopAbs_IN);
1984 if (r) shaori.Complement();
1985 aBuildTool.AddSolidShell(newsol,shaori);
1986 }
1987 }
1988 } //end block2
1989 return newsol;
1990}
1991
1992
1993//======================================================================================================
1994// static function : disjPerformFuse
1995// purpose: is needed in case of KPart==2
1996// attention: theMapOfResult is cleared before computations
1997//======================================================================================================
1998static Standard_Boolean disjPerformFuse(const TopTools_IndexedMapOfShape& theMapOfSolid1,
1999 const TopTools_IndexedMapOfShape& theMapOfSolid2,
2000 TopTools_IndexedMapOfShape& theMapOfResult) {
2001
2002 theMapOfResult.Clear();
2003
2004 TopTools_IndexedMapOfShape aMapOfSolid;
2005 aMapOfSolid = theMapOfSolid1;
2006 Standard_Integer i=1;
2007 for(i=1; i<=theMapOfSolid2.Extent(); i++) {
2008 aMapOfSolid.Add(theMapOfSolid2(i));
2009 }
2010
2011 TopoDS_Solid sol1; TopoDS_Shell outsha1;
2012 TopoDS_Solid sol2; TopoDS_Shell outsha2;
2013 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
2014 TopoDS_Shape Snull;
2015 TopTools_MapOfShape aMapOfUsedSolids;
2016 TopoDS_Solid acurrentsolid;
2017 Standard_Integer aMaxNumberOfIterations = aMapOfSolid.Extent()*aMapOfSolid.Extent();
2018
2019 for(i=1; i <=aMapOfSolid.Extent(); i++) {
2020 const TopoDS_Shape& localshape1 = aMapOfSolid(i);
2021 if(localshape1.ShapeType()!=TopAbs_SOLID)
2022 return Standard_False;
2023
2024 sol1 = TopoDS::Solid(localshape1);
2025 acurrentsolid = sol1;
2026 if(aMapOfUsedSolids.Contains(localshape1))
2027 continue;
2028
2029 Standard_Integer j=1, acheckiterator=0;
2030 while(j<=aMapOfSolid.Extent() && (acheckiterator <= aMaxNumberOfIterations)) {
2031 acheckiterator++;
2032 if(j==i) {
2033 j++;
2034 continue;
2035 }
2036 const TopoDS_Shape& localshape2 = aMapOfSolid(j);
2037 if(localshape2.ShapeType()!=TopAbs_SOLID)
2038 return Standard_False;
2039
2040 j++; // increase iterator
2041
2042 if(aMapOfUsedSolids.Contains(localshape2)) {
2043 continue;
2044 }
2045 sol2 = TopoDS::Solid(localshape2);
2f0109b7 2046 outsha2 = BRepClass3d::OuterShell(sol2);
7fd59977 2047
2f0109b7 2048 outsha1 = BRepClass3d::OuterShell(acurrentsolid);
7fd59977 2049 TopAbs_State stsol1 = aShapeClassifier.StateShapeShape(outsha1,Snull,sol2);
2050 TopAbs_State stsol2 = aShapeClassifier.StateShapeShape(outsha2,Snull,acurrentsolid);
2051 Standard_Integer ires=RESUNDEF, icla1=SHEUNDEF, icla2=SHEUNDEF;
2052 LocalKPisdisjanalyse(stsol1, stsol2, TopOpeBRepBuild_KPart_Operation_Fuse, ires, icla1, icla2);
2053 if (ires == RESUNDEF || icla1 == SHEUNDEF || icla2 == SHEUNDEF || ires == RESNULL) {
04232180 2054 std::cout << "Warning: disjPerformFuse: can not determine solid's states" << std::endl;
7fd59977 2055 continue;
2056 }
2057 if(ires == RESSHAPE12)
2058 continue;
2059
2060 if(ires==RESNEWSHA1 || ires==RESNEWSHA2) {
2061 TopoDS_Solid newsol = BuildNewSolid(acurrentsolid, sol2, stsol1, stsol2, ires, icla1, icla2, TopAbs_OUT, TopAbs_OUT);
2062 j=1; // iterate on all solids again except already used (very dengerous method)
2063 acurrentsolid = newsol;
2064 aMapOfUsedSolids.Add(localshape2);
2065 if(acurrentsolid.IsNull())
2066 return Standard_False;
2067 }
2068 } //end while(j)
2069 if(acheckiterator > aMaxNumberOfIterations) {
04232180 2070 std::cout << "disjPerformFuse: programming error" << std::endl;
7fd59977 2071 return Standard_False;
2072 }
2073 theMapOfResult.Add(acurrentsolid);
2074 } //end for(i)
2075
2076 return Standard_True;
2077}
2078
2079//======================================================================================================
2080// static function : disjPerformCommon
2081// purpose: is needed in case of KPart==2
2082// attention: theMapOfResult is cleared before computations
2083//======================================================================================================
2084static Standard_Boolean disjPerformCommon(const TopTools_IndexedMapOfShape& theMapOfSolid1,
2085 const TopTools_IndexedMapOfShape& theMapOfSolid2,
2086 TopTools_IndexedMapOfShape& theMapOfResult) {
2087
2088 TopoDS_Solid sol1; TopoDS_Shell outsha1;
2089 TopoDS_Solid sol2; TopoDS_Shell outsha2;
2090 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
2091 TopoDS_Shape Snull;
2092 TopTools_IndexedMapOfShape aMapOfSeparatedSolid1, aMapOfSeparatedSolid2, aMapOfCommonOfCouple;
2093 theMapOfResult.Clear();
2094
2095 disjPerformFuse(theMapOfSolid1, theMapOfSolid1, aMapOfSeparatedSolid1);
2096 disjPerformFuse(theMapOfSolid2, theMapOfSolid2, aMapOfSeparatedSolid2);
2097 // Now common parts of all couples of solids are different
2098 for(Standard_Integer i=1; i <=aMapOfSeparatedSolid1.Extent(); i++) {
2099 const TopoDS_Shape& localshape1 = aMapOfSeparatedSolid1(i);
2100 if(localshape1.ShapeType()!=TopAbs_SOLID)
2101 return Standard_False;
2102 sol1 = TopoDS::Solid(localshape1);
2f0109b7 2103 outsha1 = BRepClass3d::OuterShell(sol1);
7fd59977 2104
2105 for(Standard_Integer j=1; j<=aMapOfSeparatedSolid2.Extent(); j++) {
2106 const TopoDS_Shape& localshape2 = aMapOfSeparatedSolid2(j);
2107 if(localshape2.ShapeType()!=TopAbs_SOLID)
2108 return Standard_False;
2109
2110 sol2 = TopoDS::Solid(localshape2);
2f0109b7 2111 outsha2 = BRepClass3d::OuterShell(sol2);
7fd59977 2112 TopAbs_State stsol1 = aShapeClassifier.StateShapeShape(outsha1,Snull,sol2);
2113 TopAbs_State stsol2 = aShapeClassifier.StateShapeShape(outsha2,Snull,sol1);
2114 Standard_Integer ires=RESUNDEF, icla1=SHEUNDEF, icla2=SHEUNDEF;
2115
2116 LocalKPisdisjanalyse(stsol1, stsol2, TopOpeBRepBuild_KPart_Operation_Common, ires, icla1, icla2);
2117 if (ires == RESUNDEF || icla1 == SHEUNDEF || icla2 == SHEUNDEF) {
04232180 2118 std::cout << "Warning: disjPerformCommon: can not determine solid's states" << std::endl;
7fd59977 2119 continue;
2120 }
2121 switch (ires) {
2122 case RESNULL: {
2123 continue;
7fd59977 2124 }
2125 case RESSHAPE12 : {
2126 aMapOfCommonOfCouple.Add(sol1);
2127 aMapOfCommonOfCouple.Add(sol2);
2128 continue;
7fd59977 2129 }
2130 case RESSHAPE1 : {
2131 aMapOfCommonOfCouple.Add(sol1);
2132 continue;
7fd59977 2133 }
2134 case RESSHAPE2 : {
2135 aMapOfCommonOfCouple.Add(sol2);
2136 break;
2137 }
2138 case RESNEWSHA1:
2139 case RESNEWSHA2: {
2140 TopoDS_Solid newsol = BuildNewSolid(sol1, sol2, stsol1, stsol2, ires, icla1, icla2, TopAbs_IN, TopAbs_IN);
2141 aMapOfCommonOfCouple.Add(newsol);
2142 break;
2143 }
2144 default: continue;
2145 }//end switch
2146 } //end for(j)
2147 } //end for(i)
2148
2149 disjPerformFuse(aMapOfCommonOfCouple, aMapOfCommonOfCouple, theMapOfResult);
2150 return Standard_True;
2151}
2152
2153//======================================================================================================
2154// static function : disjPerformCut
2155// purpose: is needed in case of KPart==2
2156// attention: theMapOfResult is cleared before computations
2157//======================================================================================================
2158static Standard_Boolean disjPerformCut(const TopTools_IndexedMapOfShape& theMapOfSolid1,
2159 const TopTools_IndexedMapOfShape& theMapOfSolid2,
2160 TopTools_IndexedMapOfShape& theMapOfResult) {
2161 TopoDS_Solid sol1; TopoDS_Shell outsha1;
2162 TopoDS_Solid sol2; TopoDS_Shell outsha2;
2163 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
2164 TopoDS_Shape Snull;
2165 TopoDS_Solid acurrentsolid;
2166 TopTools_IndexedMapOfShape aMapOfSeparatedSolid1, aMapOfSeparatedSolid2;
2167
2168 theMapOfResult.Clear();
2169
2170 disjPerformFuse(theMapOfSolid1, theMapOfSolid1, aMapOfSeparatedSolid1);
2171 disjPerformFuse(theMapOfSolid2, theMapOfSolid2, aMapOfSeparatedSolid2);
2172
2173 for(Standard_Integer i=1; i<= aMapOfSeparatedSolid1.Extent(); i++) {
2174 const TopoDS_Shape& localshape1 = aMapOfSeparatedSolid1(i);
2175 if(localshape1.ShapeType()!=TopAbs_SOLID)
2176 return Standard_False;
2177 sol1 = TopoDS::Solid(localshape1);
2178 acurrentsolid = sol1;
2179
2180 Standard_Boolean NullResult = Standard_False;
2181
2182 for(Standard_Integer j=1; j<=aMapOfSeparatedSolid2.Extent() && !NullResult; j++) {
2183 const TopoDS_Shape& localshape2 = aMapOfSeparatedSolid2(j);
2184 if(localshape2.ShapeType()!=TopAbs_SOLID)
2185 return Standard_False;
2186 sol2 = TopoDS::Solid(localshape2);
2f0109b7 2187 outsha2 = BRepClass3d::OuterShell(sol2);
2188 outsha1 = BRepClass3d::OuterShell(acurrentsolid);
7fd59977 2189 TopAbs_State stsol1 = aShapeClassifier.StateShapeShape(outsha1,Snull,sol2);
2190 TopAbs_State stsol2 = aShapeClassifier.StateShapeShape(outsha2,Snull,acurrentsolid);
2191 Standard_Integer ires=RESUNDEF, icla1=SHEUNDEF, icla2=SHEUNDEF;
2192
2193 LocalKPisdisjanalyse(stsol1, stsol2, TopOpeBRepBuild_KPart_Operation_Cut12, ires, icla1, icla2);
2194 if (ires == RESUNDEF || icla1 == SHEUNDEF || icla2 == SHEUNDEF) {
04232180 2195 std::cout << "Warning: disjPerformCut: can not determine solid's states" << std::endl;
7fd59977 2196 continue;
2197 }
2198 switch (ires) {
2199 case RESNULL: {
2200 NullResult=Standard_True;
2201 break;
2202 }
2203 case RESSHAPE12 : {
2204 NullResult=Standard_True;
2205 break;
2206 }
2207 case RESSHAPE1 : {
2208 NullResult=Standard_False;
2209 break;
2210 }
2211 case RESSHAPE2 : {
2212 NullResult=Standard_True;
2213 break;
2214 }
2215 case RESNEWSHA1:
2216 case RESNEWSHA2: {
2217 TopoDS_Solid newsol = BuildNewSolid(acurrentsolid, sol2, stsol1, stsol2, ires, icla1, icla2, TopAbs_OUT, TopAbs_IN);
2218 acurrentsolid = newsol;
2219 break;
2220 }
2221 default: continue;
2222 }//end switch
2223 } //end for(j)
2224 if(!NullResult) {
2225 if(acurrentsolid.IsNull())
2226 return Standard_False;
2227 theMapOfResult.Add(acurrentsolid);
2228 }
2229 } //end for(i)
2230 return Standard_True;
2231}
2232//modified by NIZHNY-MKK Tue May 23 09:49:03 2000.END