1 // Created on: 1994-08-30
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 #include <TopOpeBRepBuild_Builder.jxx>
24 #include <TopOpeBRepBuild_GTool.hxx>
25 #include <TopOpeBRepTool.hxx>
26 #include <TopOpeBRepTool_ShapeExplorer.hxx>
27 #include <TopOpeBRepDS_BuildTool.hxx>
29 #include <TopoDS_Solid.hxx>
30 #include <TopoDS_Shell.hxx>
31 #include <TopoDS_Wire.hxx>
33 #include <Precision.hxx>
34 #include <TopExp_Explorer.hxx>
37 #include <BRep_Tool.hxx>
38 #include <BRep_Builder.hxx>
39 #include <BRepTools.hxx>
40 #include <BRepClass3d.hxx>
41 #include <BRepClass3d_SolidExplorer.hxx>
42 #include <TopOpeBRepTool_EXPORT.hxx>
43 #include <TopOpeBRepTool_SC.hxx>
44 #include <TopOpeBRepDS_EXPORT.hxx>
45 #include <TopOpeBRepDS_connex.hxx>
46 #include <TopOpeBRepBuild_define.hxx>
47 #include <TopOpeBRepBuild_kpresu.hxx>
48 #include <Standard_ProgramError.hxx>
51 Standard_EXPORT Standard_Boolean TopOpeBRepBuild_GettraceKPB();
54 static void FUN_Raise() {
56 cout<<"******************************ERROR"<<endl;
57 Standard_ProgramError::Raise("KPart.cxx");
61 #define M_REVERSED(st) (st == TopAbs_REVERSED)
63 Standard_EXPORT Standard_Boolean FUNKP_KPiskolesh(const TopOpeBRepBuild_Builder& BU,const TopOpeBRepDS_DataStructure& BDS,const TopoDS_Shape& Sarg,TopTools_ListOfShape& lShsd,TopTools_ListOfShape& lfhsd);
66 //modified by NIZHNY-MKK Fri May 19 17:03:59 2000.BEGIN
67 enum TopOpeBRepBuild_KPart_Operation {TopOpeBRepBuild_KPart_Operation_Fuse, TopOpeBRepBuild_KPart_Operation_Common, TopOpeBRepBuild_KPart_Operation_Cut12, TopOpeBRepBuild_KPart_Operation_Cut21};
69 static void LocalKPisdisjanalyse(const TopAbs_State Stsol1, const TopAbs_State Stsol2,
70 const TopOpeBRepBuild_KPart_Operation& theOperation,
71 Standard_Integer& ires, Standard_Integer& icla1, Standard_Integer& icla2);
73 static TopoDS_Solid BuildNewSolid(const TopoDS_Solid& sol1,
74 const TopoDS_Solid& sol2,
75 const TopAbs_State stsol1,
76 const TopAbs_State stsol2,
77 const Standard_Integer ires,
78 const Standard_Integer icla1,
79 const Standard_Integer icla2,
80 const TopAbs_State theState1,
81 const TopAbs_State theState2);
83 static Standard_Boolean disjPerformFuse(const TopTools_IndexedMapOfShape& theMapOfSolid1,
84 const TopTools_IndexedMapOfShape& theMapOfSolid2,
85 TopTools_IndexedMapOfShape& theMapOfResult);
87 static Standard_Boolean disjPerformCommon(const TopTools_IndexedMapOfShape& theMapOfSolid1,
88 const TopTools_IndexedMapOfShape& theMapOfSolid2,
89 TopTools_IndexedMapOfShape& theMapOfResult);
91 static Standard_Boolean disjPerformCut(const TopTools_IndexedMapOfShape& theMapOfSolid1,
92 const TopTools_IndexedMapOfShape& theMapOfSolid2,
93 TopTools_IndexedMapOfShape& theMapOfResult);
94 //modified by NIZHNY-MKK Fri May 19 17:04:07 2000.END
97 //=======================================================================
98 //function : FindIsKPart
100 //=======================================================================
102 Standard_Integer TopOpeBRepBuild_Builder::FindIsKPart()
107 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
108 if(TKPB){cout<<endl<<"--- IsKPart ? ---"<<endl;}
111 Standard_Integer isfafa = KPisfafa();
112 // face,face SameDomain
115 return KPreturn(myIsKPart);
118 Standard_Integer isdisj = KPisdisj();
119 // shape,shape sans aucune interference geometrique
122 return KPreturn(myIsKPart);
125 Standard_Integer iskole = KPiskole();
126 // solide,solide colles par faces tangentes sans aretes tangentes
129 return KPreturn(myIsKPart);
132 Standard_Integer iskoletge = KPiskoletge();
133 // solide,solide par faces tangentes avec aretes tangentes
136 return KPreturn(myIsKPart);
139 Standard_Integer issoso = KPissoso();
140 // solide,solide quelconques
143 return KPreturn(myIsKPart);
147 return KPreturn(myIsKPart);
150 //=======================================================================
153 //=======================================================================
155 Standard_Integer TopOpeBRepBuild_Builder::IsKPart() const
161 //=======================================================================
162 //function : MergeKPart
164 //=======================================================================
166 void TopOpeBRepBuild_Builder::MergeKPart(const TopAbs_State TB1,
167 const TopAbs_State TB2)
174 //=======================================================================
175 //function : MergeKPart
177 //=======================================================================
179 void TopOpeBRepBuild_Builder::MergeKPart()
181 if ( myIsKPart == 1 ) { // iskole
184 else if ( myIsKPart == 5 ) { // iskoletge
185 MergeKPartiskoletge();
187 else if (myIsKPart == 2) { // isdisj
190 else if ( myIsKPart == 3 ) { // isfafa
193 else if ( myIsKPart == 4 ) { // issoso
199 static void FUN_sortplcy(const TopTools_ListOfShape& lof, TopTools_ListOfShape& lopl, TopTools_ListOfShape& locy)
201 TopTools_ListIteratorOfListOfShape it(lof);
202 for (; it.More(); it.Next()){
203 const TopoDS_Face& ff = TopoDS::Face(it.Value());
204 Standard_Boolean plane = FUN_tool_plane(ff);
205 if (plane) {lopl.Append(ff);}
206 Standard_Boolean cylinder = FUN_tool_cylinder(ff);
207 if (cylinder){locy.Append(ff);}
211 /*static Standard_Boolean FUN_proj2(const TopOpeBRepBuild_Builder& BU, const Handle(TopOpeBRepDS_HDataStructure)& HDS,
212 const TopoDS_Shape& Fa2, TopTools_DataMapOfShapeListOfShape& EnewE)
214 const TopoDS_Face& F2 = TopoDS::Face(Fa2);
215 TopoDS_Wire Ow2 = BRepTools::OuterWire(TopoDS::Face(F2));
216 TopExp_Explorer exe(Ow2, TopAbs_EDGE);
217 for (; exe.More(); exe.Next()){
218 const TopoDS_Shape& ed = exe.Current();
219 Standard_Boolean issplit = BU.IsSplit(ed,TopAbs_ON);
220 if (!issplit) return Standard_False;
221 const TopTools_ListOfShape& speds = BU.Splits(ed,TopAbs_ON);
222 TopTools_ListOfShape lfcF2; // faces of shapei connexed to ed
223 FDSCNX_FaceEdgeConnexFaces(TopoDS::Face(F2),ed,HDS,lfcF2);
224 // prequesitory : ed in {edges of Ow2}
225 // ed's faces ancestor = {F2,fofj}
226 if (lfcF2.Extent() != 1) return Standard_False;
227 const TopoDS_Face& fcF2 = TopoDS::Face(lfcF2.First());
229 // projecting sp(ed) on faces F2 and fofj
230 TopTools_ListOfShape newesp;
231 TopTools_ListIteratorOfListOfShape itspe(speds);
232 for (; itspe.More(); itspe.Next()){
233 TopoDS_Edge esp = TopoDS::Edge(itspe.Value());
234 Standard_Boolean ok = FUN_tool_pcurveonF(F2,esp);
235 if (!ok) return Standard_False;
236 ok = FUN_tool_pcurveonF(fcF2,esp);
237 if (!ok) return Standard_False;
238 // EnewE.Add(esp,newesp);
241 EnewE.Bind(ed,newesp);
243 return Standard_True;
246 static void FUN_addf(const TopAbs_State sta, const TopoDS_Shape& ftoadd, TopTools_DataMapOfShapeShape& map)
249 // Standard_Boolean isadded = map.IsBound(ftoadd);
251 TopoDS_Shape fori = ftoadd;
252 if (sta == TopAbs_IN) fori.Complement();
256 static Standard_Integer FUN_comparekoletgesh(TopOpeBRepTool_ShapeClassifier& SC,
257 const TopoDS_Shape& sh1, const TopoDS_Shape& sh2,
258 const TopoDS_Shape& fkole1, const TopoDS_Shape& )
259 // purpose: <sh1> and <sh2> are kpkoletge on faces <fkole1>,<fkole2>
260 // with <fkole1> same oriented with <fkole2>
261 // returns k=1,2 if shi is contained in shk
264 SC.SetReference(sh2);
265 TopExp_Explorer exf(sh1,TopAbs_FACE);
266 for (; exf.More(); exf.Next()){
267 const TopoDS_Face& f1 = TopoDS::Face(exf.Current());
268 if (f1.IsSame(fkole1)) continue;
270 BRepClass3d_SolidExplorer::FindAPointInTheFace(f1,pnt1);
271 SC.StateP3DReference(pnt1);
272 TopAbs_State stpnt1 = SC.State();
273 if (stpnt1 == TopAbs_IN) return 2;
274 if (stpnt1 == TopAbs_OUT) return 1;
279 static Standard_Boolean FUN_changev(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Shape& v)
281 Standard_Boolean changev = HDS->HasShape(v);
282 if (!changev) return Standard_False;
283 changev = HDS->HasSameDomain(v);
284 if (!changev) return Standard_False;
285 Standard_Boolean rankv = HDS->DS().AncestorRank(v);
286 changev = (rankv == 2);
289 static Standard_Boolean FUN_updatev
290 (const Handle(TopOpeBRepDS_HDataStructure)& HDS, TopoDS_Edge& newed,
291 const TopoDS_Vertex& v, const TopAbs_Orientation oriv, const Standard_Real parv, const Standard_Boolean changev)
293 TopOpeBRepDS_BuildTool BT;
296 TopoDS_Shape oov; Standard_Boolean ok = FUN_ds_getoov(v,HDS,oov);
297 if(!ok) return Standard_False;
298 oov.Orientation(oriv);
300 BT.Parameter(newed,oov,parv);
303 TopoDS_Shape aLocalShape = v.Oriented(oriv);
304 TopoDS_Vertex ov = TopoDS::Vertex(aLocalShape);
305 // TopoDS_Vertex ov = TopoDS::Vertex(v.Oriented(oriv));
307 BT.Parameter(newed,ov,parv);
309 return Standard_True;
312 static Standard_Boolean FUN_makefaces(const TopOpeBRepBuild_Builder& BU, const Handle(TopOpeBRepDS_HDataStructure)& HDS, TopTools_DataMapOfShapeListOfShape& EnewE,
313 const TopoDS_Shape& f, const TopoDS_Shape& , TopTools_ListOfShape& newfaces)
314 //prequesitory : <outerwi>=<f>'s outer wire
315 //purpose : <outerwi>={edow},
316 // edow=(vf,vl), if(rank(vj)=2 && vj sdm vj1), replace vj by vj1
320 TopOpeBRepDS_BuildTool BT;
322 TopoDS_Shape aLocalShape = f.Oriented(TopAbs_FORWARD);
323 TopoDS_Face F = TopoDS::Face(aLocalShape); // working on FORWARD face
324 // TopoDS_Face F = TopoDS::Face(f.Oriented(TopAbs_FORWARD)); // working on FORWARD face
325 TopAbs_Orientation of = f.Orientation();
327 //the new outer wire :
328 // -------------------
329 TopTools_ListOfShape loe;
331 TopoDS_Wire outerwf = BRepTools::OuterWire(F);
332 TopExp_Explorer ex(outerwf, TopAbs_EDGE);
333 for (; ex.More(); ex.Next()){
334 const TopoDS_Edge& ed = TopoDS::Edge(ex.Current());
335 TopAbs_Orientation oe = ed.Orientation();
336 Standard_Boolean issplit = BU.IsSplit(ed,TopAbs_ON);
337 Standard_Boolean isbound = EnewE.IsBound(ed);
339 if (!isbound && !issplit) {
341 TopoDS_Vertex vf,vl; TopExp::Vertices(ed,vf,vl);
342 Standard_Boolean changevf = ::FUN_changev(HDS,vf);
343 Standard_Boolean changevl = ::FUN_changev(HDS,vl);
344 Standard_Boolean changee = changevf || changevl;
346 Standard_Real ff = BRep_Tool::Parameter(vf, ed);
347 Standard_Real l = BRep_Tool::Parameter(vl, ed);
349 TopoDS_Edge newed; BT.CopyEdge(ed.Oriented(TopAbs_FORWARD),newed);
350 Standard_Boolean ok = ::FUN_updatev(HDS,newed,vf,TopAbs_FORWARD,ff,changevf);
351 if (!ok) return Standard_False;
352 ok = ::FUN_updatev(HDS,newed,vl,TopAbs_REVERSED,l,changevl);
353 if (!ok) return Standard_False;
354 newed.Orientation(oe);
355 TopTools_ListOfShape led; led.Append(newed); EnewE.Bind(ed,led);
356 isbound = Standard_True;
361 const TopTools_ListOfShape& speds = BU.Splits(ed,TopAbs_ON);
362 if (speds.Extent() == 0) return Standard_False;
363 const TopoDS_Edge& spe = TopoDS::Edge(speds.First());
364 Standard_Boolean sameori = FUN_tool_SameOri(ed,spe);
365 TopAbs_Orientation orisp = spe.Orientation();
366 if (!sameori) orisp = TopAbs::Complement(orisp);
368 TopTools_ListIteratorOfListOfShape it(speds);
369 for (; it.More(); it.Next()) {
370 TopoDS_Edge esp = TopoDS::Edge(it.Value());
371 Standard_Boolean ok = FUN_tool_pcurveonF(TopoDS::Face(f),esp);
372 if (!ok) return Standard_False;
373 TopoDS_Shape ee = esp.Oriented(orisp);
378 const TopTools_ListOfShape& neweds = EnewE.ChangeFind(ed);
379 TopTools_ListIteratorOfListOfShape itnes(neweds);
380 for (; itnes.More(); itnes.Next()) loe.Append(itnes.Value().Oriented(oe));
389 for (TopTools_ListIteratorOfListOfShape itee(loe); itee.More(); itee.Next())
390 BB.Add(newW,itee.Value());
394 aLocalShape = F.EmptyCopied();
395 TopoDS_Face newf = TopoDS::Face(aLocalShape);
396 // TopoDS_Face newf = TopoDS::Face(F.EmptyCopied());
399 // other wires of <f> :
400 TopExp_Explorer exw(F, TopAbs_WIRE);
401 for (; exw.More(); exw.Next()){
402 const TopoDS_Wire OOw = TopoDS::Wire(exw.Current());
403 if (OOw.IsSame(outerwf)) continue;
407 if (M_REVERSED(of)) newf.Orientation(TopAbs_REVERSED);
409 // xpu140898 : CTS21251
410 TopoDS_Face Newf = newf;
411 Standard_Boolean ok = TopOpeBRepTool::CorrectONUVISO(TopoDS::Face(f),Newf);
412 if (ok) newfaces.Append(Newf);
413 else newfaces.Append(newf);
415 return Standard_True;
418 static Standard_Boolean FUN_rebuildfc(const TopOpeBRepBuild_Builder& BU, const Handle(TopOpeBRepDS_HDataStructure)& HDS,
419 const TopAbs_State , const TopoDS_Shape& Fk,
420 TopTools_DataMapOfShapeListOfShape& EnewE, TopTools_IndexedDataMapOfShapeListOfShape& fcnewfc)
421 // Owk = <Fk>'s outer wire
422 //prequesitory: Owk = {edk}, Splits(edk,Stk) = spedk
423 //purpose: fills up <fcnewfc> = {(fcFk,newfcFk)}
424 // with {fcFk} = faces of shape k connexed to Owk
425 // fcFk has edges {edk}
428 // const TopOpeBRepDS_DataStructure& BDS = HDS->DS();
429 // Standard_Integer rFk = BDS.AncestorRank(Fk);
431 TopoDS_Wire Owk = BRepTools::OuterWire(TopoDS::Face(Fk));
432 TopTools_ListOfShape eds; FUN_tool_shapes(Owk,TopAbs_EDGE,eds);
433 TopTools_ListIteratorOfListOfShape ite(eds);
436 for (; ite.More(); ite.Next()){
437 const TopoDS_Shape& ed = ite.Value();
438 TopTools_ListOfShape lfcFk; // faces of shapei connexed to ed
439 FDSCNX_FaceEdgeConnexFaces(TopoDS::Face(Fk),ed,HDS,lfcFk);
440 // prequesitory : ed in {edges of Owk}
441 // ed's faces ancestor = {Fk,fofj}
442 if (lfcFk.Extent() != 1) return Standard_False;
444 // purpose : Building up new topologies on connexed faces
445 // attached to outer wire's edges.
446 const TopoDS_Shape& fcFk = lfcFk.First();
447 TopTools_ListOfShape newfcFk; Standard_Boolean ok = FUN_makefaces(BU,HDS,EnewE,fcFk,Owk,newfcFk);
448 if (!ok) return Standard_False;
449 fcnewfc.Add(fcFk,newfcFk);
451 return Standard_True;
455 Standard_EXPORT void debiskoletge() {}
458 //=======================================================================
459 //function : MergeKPartiskoletge
461 //=======================================================================
463 void TopOpeBRepBuild_Builder::MergeKPartiskoletge()
466 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
467 if (TKPB) KPreturn(myIsKPart);
471 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
472 // Standard_Integer ibid;
474 if ( myIsKPart != 5 ) {FUN_Raise(); return;}
476 GMapShapes(myShape1,myShape2);
477 // NYI : on doit pouvoir faire l'economie du mapping GMapShapes(...)
478 // NYI en allant chercher l'indice 1,2 retourne par GShapeRank(S)
479 // NYI dans la DS. l'index est defini pour tous les shapes HasSameDomain
481 TopTools_ListOfShape& lmergesha1 = ChangeMerged(myShape1,myState1);
482 ChangeMerged(myShape2,myState2);
484 TopTools_ListOfShape lShsd1,lShsd2; // liste de solides HasSameDomain
485 TopTools_ListOfShape lfhsd1,lfhsd2; // liste de faces HasSameDomain
486 KPiskoletgesh(myShape1,lShsd1,lfhsd1);
487 KPiskoletgesh(myShape2,lShsd2,lfhsd2);
489 // traitement de tous les solides NYI
490 TopoDS_Shape sol1 = lShsd1.First();
491 TopoDS_Shape sol2 = lShsd2.First();
493 ChangeMerged(sol1,myState1);
494 ChangeMerged(sol2,myState2);
496 TopTools_ListOfShape lplhsd1, lcyhsd1; ::FUN_sortplcy(lfhsd1,lplhsd1,lcyhsd1);
497 TopTools_ListOfShape lplhsd2, lcyhsd2; ::FUN_sortplcy(lfhsd2,lplhsd2,lcyhsd2);
498 const TopoDS_Face& fac1 = TopoDS::Face(lplhsd1.First());
499 const TopoDS_Face& fac2 = TopoDS::Face(lplhsd2.First());
501 Standard_Integer iF1 =
503 myDataStructure->Shape(fac1); //DEB
505 Standard_Integer iF2 =
507 myDataStructure->Shape(fac2); //DEB
510 if (TKPB) {cout<<""<<endl;cout<<"face "<<iF1<<" : ";cout<<iF2<<endl;}
513 TopOpeBRepDS_Config config2 = BDS.SameDomainOri(fac2);
515 Standard_Boolean SameOriented = (config2 == TopOpeBRepDS_SAMEORIENTED);
517 const TopoDS_Shape* pfGRE = NULL;
518 const TopoDS_Shape* pfSMA = NULL;
520 Standard_Integer rgre = 1;
523 rgre = ::FUN_comparekoletgesh(myShapeClassifier,
524 myShape1,myShape2,fac1,fac2);
525 if (rgre == 0) rgre = FUN_tool_comparebndkole(myShape1,myShape2);
527 if (rgre == 0) {FUN_Raise(); return;}
531 Standard_Integer rsma = (rgre == 1)? 2: 1;
532 pfSMA = (rsma == 1)? &fac1: &fac2;
533 pfGRE = (rgre == 1)? &fac1: &fac2;
534 TopAbs_State staSMA = (rsma == 1)? myState1: myState2;
535 TopAbs_State staGRE = (rgre == 1)? myState1: myState2;
537 TopoDS_Shape shaSMA = (rsma == 1)? myShape1: myShape2;
538 TopoDS_Shape shaGRE = (rgre == 1)? myShape1: myShape2;
540 Standard_Integer ires = 0; KPiskoletgeanalyse(config2,staSMA,staGRE,ires);
544 TopoDS_Shape sheSMA; // sheSMA = shell accedant facSMA
545 TopTools_IndexedDataMapOfShapeListOfShape MfacsheSMA;
546 TopExp::MapShapesAndAncestors(shaSMA,TopAbs_FACE,TopAbs_SHELL,MfacsheSMA);
547 const TopTools_ListOfShape& lsheSMA = MfacsheSMA.FindFromKey(*pfSMA);
548 TopTools_ListIteratorOfListOfShape itlsheSMA(lsheSMA);
549 sheSMA = itlsheSMA.Value();
551 TopoDS_Shape sheGRE; // sheGRE = shell accedant facGRE
552 TopTools_IndexedDataMapOfShapeListOfShape MfacsheGRE;
553 TopExp::MapShapesAndAncestors(shaGRE,TopAbs_FACE,TopAbs_SHELL,MfacsheGRE);
554 const TopTools_ListOfShape& lsheGRE = MfacsheGRE.FindFromKey(*pfGRE);
555 TopTools_ListIteratorOfListOfShape itlsheGRE(lsheGRE);
556 sheGRE = itlsheGRE.Value();
558 ChangeMerged(sheSMA, staSMA);
559 ChangeMerged(sheGRE, staGRE);
562 if (ires == RESNULL) {
565 else if (ires == RESSHAPE1) {
566 myBuildTool.MakeShell(newshe);
567 newshe = TopoDS::Shell(sheSMA);
569 else if (ires == RESSHAPE2) {
570 myBuildTool.MakeShell(newshe);
571 newshe = TopoDS::Shell(sheGRE);
573 else if (ires == RESNEWSOL) {
575 TopTools_DataMapOfShapeShape addedfaces;
576 // As splits of outer wire's edges have 2drep only on shape1,
577 // we have to project them on the connexed faces of shape2
578 TopTools_DataMapOfShapeListOfShape EnewE;
579 // Standard_Boolean ok = ::FUN_proj2((*this),myDataStructure,fac2,EnewE);
580 // if (!ok) {FUN_Raise(); return;}
583 TopTools_IndexedDataMapOfShapeListOfShape fcnewfcSMA;// faces connexed to fSMA built up with the split of outerwSMA
584 TopTools_IndexedDataMapOfShapeListOfShape fcnewfcGRE;// faces connexed to fGRE built up with the split of outerwGRE
585 Standard_Boolean ok = ::FUN_rebuildfc((*this),myDataStructure,staSMA,*pfSMA,EnewE,fcnewfcSMA);
586 if (!ok) {FUN_Raise(); return;}
587 Standard_Integer nfcSMA = fcnewfcSMA.Extent();
588 // for (Standard_Integer i=1; i<=nfcSMA; i++) {
590 for ( i=1; i<=nfcSMA; i++) {
591 const TopoDS_Shape& f = fcnewfcSMA.FindKey(i);
592 const TopTools_ListOfShape& newlf = fcnewfcSMA.FindFromIndex(i);
594 TopTools_ListIteratorOfListOfShape it(newlf);
595 for (; it.More(); it.Next()){
596 const TopoDS_Shape& ff = it.Value();
597 ::FUN_addf(staSMA,ff,addedfaces);
598 ChangeMerged(f,staSMA).Append(ff);
601 ok = ::FUN_rebuildfc((*this),myDataStructure,staGRE,*pfGRE,EnewE,fcnewfcGRE);
602 if (!ok) {FUN_Raise(); return;}
603 Standard_Integer nfcGRE = fcnewfcGRE.Extent();
604 for (i=1; i<=nfcGRE; i++) {
605 const TopoDS_Shape& f = fcnewfcGRE.FindKey(i);
606 const TopTools_ListOfShape& newlf = fcnewfcGRE.FindFromIndex(i);
608 TopTools_ListIteratorOfListOfShape it(newlf);
609 for (; it.More(); it.Next()){
610 const TopoDS_Shape& ff = it.Value();
611 ::FUN_addf(staGRE,ff,addedfaces);
612 ChangeMerged(f,staGRE).Append(ff);
617 TopTools_ListOfShape lOOfSMA; // DEB : faces of SMA non connexed to fSMA
618 TopTools_ListOfShape lOOfGRE; // DEB : faces of GRE non connexed to fGRE
619 TopExp_Explorer exSMA(shaSMA, TopAbs_FACE);
620 for (; exSMA.More(); exSMA.Next()){
621 const TopoDS_Shape& ff = exSMA.Current();
622 if (fcnewfcSMA.Contains(ff)) continue;
623 if (ff.IsSame(*pfSMA)) continue;
624 lOOfSMA.Append(ff); // DEB
625 ::FUN_addf(staSMA,ff,addedfaces);
627 TopExp_Explorer exGRE(shaGRE, TopAbs_FACE);
628 for (; exGRE.More(); exGRE.Next()){
629 const TopoDS_Shape& ff = exGRE.Current();
630 if (fcnewfcGRE.Contains(ff)) continue;
631 if (ff.IsSame(*pfGRE)) continue;
632 lOOfGRE.Append(ff); // DEB
633 ::FUN_addf(staGRE,ff,addedfaces);
637 TopTools_DataMapIteratorOfDataMapOfShapeShape itadd(addedfaces);
638 Standard_Boolean yauadd = itadd.More();
640 myBuildTool.MakeShell(newshe);
641 myBuildTool.Closed(newshe,Standard_True); // NYI : check exact du caractere closed du shell
643 for (; itadd.More(); itadd.Next() ) {
644 const TopoDS_Shape& ftoadd = itadd.Key();
645 myBuildTool.AddShellFace(newshe,ftoadd);
651 if ( !newshe.IsNull() ) {
652 myBuildTool.MakeSolid(newsol);
653 myBuildTool.AddSolidShell(newsol,newshe);
657 if ( !newsol.IsNull() ) {
658 lmergesha1.Append(newsol);
661 } // MergeKPartiskoletge
663 //=======================================================================
664 //function : MergeKPartisdisj
666 //=======================================================================
668 void TopOpeBRepBuild_Builder::MergeKPartisdisj()
671 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
672 if (TKPB) KPreturn(myIsKPart);
675 if (myIsKPart != 2) return; // isdisj
677 TopTools_ListOfShape& lmergesha1 = ChangeMerged(myShape1,myState1);
678 /* TopTools_ListOfShape& lmergesha2 =*/ ChangeMerged(myShape2,myState2);
680 Standard_Boolean traite = Standard_True;
682 Standard_Boolean soldisj = Standard_False;
683 TopOpeBRepTool_ShapeExplorer exsol1(myShape1,TopAbs_SOLID);
684 Standard_Boolean hassol1 = exsol1.More();
685 TopOpeBRepTool_ShapeExplorer exsol2(myShape2,TopAbs_SOLID);
686 Standard_Boolean hassol2 = exsol2.More();
687 soldisj = (hassol1 && hassol2);
690 //modified by NIZHNY-MKK Fri May 19 16:18:12 2000.BEGIN
691 Standard_Boolean hasnotsol1=Standard_False;
692 Standard_Boolean hasnotsol2=Standard_False;
693 TopExp_Explorer anExp(myShape1, TopAbs_SHELL, TopAbs_SOLID);
694 for(Standard_Integer i=TopAbs_SHELL; i <= TopAbs_VERTEX && !hasnotsol1 && !hasnotsol2; i++) {
695 anExp.Init(myShape1, (TopAbs_ShapeEnum)i, TopAbs_SOLID);
697 hasnotsol1 = Standard_True;
698 anExp.Init(myShape2, (TopAbs_ShapeEnum)i, TopAbs_SOLID);
700 hasnotsol2 = Standard_True;
702 soldisj = !(hasnotsol1 || hasnotsol2);
704 //modified by NIZHNY-MKK Fri May 19 16:18:16 2000.END
706 TopoDS_Solid sol1; TopoDS_Shell outsha1;
707 TopoDS_Solid sol2; TopoDS_Shell outsha2;
710 //modified by NIZHNY-MKK Fri May 19 16:47:19 2000.BEGIN
711 TopTools_IndexedMapOfShape aMapOfSolid1, aMapOfSolid2;
712 TopExp::MapShapes(myShape1, TopAbs_SOLID, aMapOfSolid1);
713 TopExp::MapShapes(myShape2, TopAbs_SOLID, aMapOfSolid2);
715 if(aMapOfSolid1.Extent() > 1 || aMapOfSolid2.Extent() > 1) {
716 TopTools_IndexedMapOfShape aMapOfResult;
718 if(!disjPerformFuse(aMapOfSolid1, aMapOfSolid2, aMapOfResult))
722 if(!disjPerformCut(aMapOfSolid1, aMapOfSolid2, aMapOfResult))
726 if(!disjPerformCut(aMapOfSolid2, aMapOfSolid1, aMapOfResult))
730 if(!disjPerformCommon(aMapOfSolid1, aMapOfSolid2, aMapOfResult))
733 for(Standard_Integer ii=1; ii<=aMapOfResult.Extent(); ii++) {
734 lmergesha1.Append(aMapOfResult(ii));
737 } //end if(aMapOfSolid1.Extent() > 1 || aMapOfSolid2.Extent() > 1)
739 //modified by NIZHNY-MKK Fri May 19 16:47:23 2000.END
740 sol1 = TopoDS::Solid(exsol1.Current());
741 ChangeMerged(sol1,myState1);
742 outsha1 = BRepClass3d::OuterShell(sol1);
744 sol2 = TopoDS::Solid(exsol2.Current());
745 ChangeMerged(sol2,myState2);
746 outsha2 = BRepClass3d::OuterShell(sol2);
748 TopAbs_State stsol1 = KPclasSS(outsha1,sol2);
749 TopAbs_State stsol2 = KPclasSS(outsha2,sol1);
751 Standard_Integer ires,icla1,icla2;
752 KPisdisjanalyse(stsol1,stsol2,ires,icla1,icla2);
754 if (ires == RESUNDEF) {
758 else if (icla1 == SHEUNDEF || icla2 == SHEUNDEF) {
762 else if (ires == RESNULL) {
766 else if (ires == RESSHAPE12) {
767 lmergesha1.Append(myShape1);
768 lmergesha1.Append(myShape2);
772 else if (ires == RESSHAPE1) {
773 lmergesha1.Append(myShape1);
777 else if (ires == RESSHAPE2) {
778 lmergesha1.Append(myShape2);
782 else if (ires == RESNEWSHA1 ||
783 ires == RESNEWSHA2) {
784 //modified by NIZHNY-MKK Tue May 23 11:36:33 2000.BEGIN
785 TopoDS_Solid newsol = BuildNewSolid(sol1, sol2, stsol1, stsol2, ires, icla1, icla2, myState1, myState2);
786 //modified by NIZHNY-MKK Tue May 23 11:36:39 2000.END
787 lmergesha1.Append(newsol);
792 cout<<"TopOpeBRepBuild_MergeKPart soldisj : ires = "<<ires<<endl;
796 //modified by NIZHNY-MKK Tue May 23 11:37:15 2000
797 } //end else of if(aMapOfSolid1.Extent() > 1 || aMapOfSolid2.Extent() > 1)
803 lmergesha1.Append(myShape1);
806 lmergesha1.Append(myShape2);
812 lmergesha1.Append(myShape1);
813 lmergesha1.Append(myShape2);
821 } // MergeKPartisdisj
823 //=======================================================================
824 //function : MergeKPartisfafa
826 //=======================================================================
828 void TopOpeBRepBuild_Builder::MergeKPartisfafa()
831 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
832 if (TKPB) KPreturn(myIsKPart);
835 if ( myIsKPart == 3 ) { // isfafa
838 ex.Init(myShape1,TopAbs_FACE); if (! ex.More() ) return;
839 TopoDS_Shape F1 = ex.Current();
840 ex.Init(myShape2,TopAbs_FACE); if (! ex.More() ) return;
841 TopoDS_Shape F2 = ex.Current();
843 TopTools_ListOfShape LF1,LF2;
844 GFindSamDom(F1,LF1,LF2);
846 TopAbs_ShapeEnum tf = TopAbs_FACE;
847 TopOpeBRepBuild_GTopo G;
848 if (Opec12()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf);
849 else if (Opec21()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf).CopyPermuted();
850 else if (Opecom()) G=TopOpeBRepBuild_GTool::GComSame(tf,tf);
851 else if (Opefus()) G=TopOpeBRepBuild_GTool::GFusSame(tf,tf);
854 GMapShapes(myShape1,myShape2);
855 GMergeFaces(LF1,LF2,G);
857 if (myShape1.ShapeType() == TopAbs_COMPOUND) {
858 TopTools_ListOfShape& L1 = ChangeMerged(myShape1,myState1);
859 L1 = ChangeMerged(F1,myState1);
862 if (myShape2.ShapeType() == TopAbs_COMPOUND) {
863 TopTools_ListOfShape& L2 = ChangeMerged(myShape2,myState2);
864 L2 = ChangeMerged(F2,myState2);
869 } // MergeKPartisfafa
871 //=======================================================================
872 //function : MergeKPartissoso
874 //=======================================================================
876 void TopOpeBRepBuild_Builder::MergeKPartissoso()
879 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
880 if (TKPB) KPreturn(myIsKPart);
883 if ( myIsKPart == 4 ) { // issoso
888 if (!myShape1.IsNull()) {
889 ex.Init(myShape1,TopAbs_SOLID);
890 if (! ex.More() ) return;
895 if (!myShape2.IsNull()) {
896 ex.Init(myShape2,TopAbs_SOLID);
897 if (! ex.More() ) return;
901 if (SO1.IsNull()) return;
903 TopTools_ListOfShape LSO1,LSO2;
904 GFindSamDom(SO1,LSO1,LSO2);
906 TopAbs_ShapeEnum tf = TopAbs_FACE; // NYI TopAbs_SOLID
907 TopOpeBRepBuild_GTopo G;
908 if (Opec12()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf);
909 else if (Opec21()) G=TopOpeBRepBuild_GTool::GCutSame(tf,tf).CopyPermuted();
910 else if (Opecom()) G=TopOpeBRepBuild_GTool::GComSame(tf,tf);
911 else if (Opefus()) G=TopOpeBRepBuild_GTool::GFusSame(tf,tf);
914 GMapShapes(myShape1,myShape2);
915 GMergeSolids(LSO1,LSO2,G);
917 if (!myShape1.IsNull()) {
918 if (myShape1.ShapeType() == TopAbs_COMPOUND) {
919 TopTools_ListOfShape& L1 = ChangeMerged(myShape1,myState1);
920 L1 = ChangeMerged(SO1,myState1);
924 if (!myShape2.IsNull()) {
925 if (myShape2.ShapeType() == TopAbs_COMPOUND) {
926 TopTools_ListOfShape& L2 = ChangeMerged(myShape2,myState2);
927 L2 = ChangeMerged(SO2,myState2);
933 } // MergeKPartissoso
935 static Standard_Boolean sectionedgesON(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Shape& outerw1,
936 const TopTools_IndexedMapOfShape& mape2)
937 // prequesitory : all edges of <outerw1> are section edges
939 TopExp_Explorer ex1(outerw1, TopAbs_EDGE);
940 for (; ex1.More(); ex1.Next()){
941 const TopoDS_Shape& e1 = ex1.Current();
942 TopTools_ListIteratorOfListOfShape it2 = HDS->SameDomain(e1);
943 if (!it2.More()) return Standard_False; // xpu231098 : cto904C7 : e1 !hsd
944 for (; it2.More(); it2.Next()){
945 const TopoDS_Shape& e2 = it2.Value();
946 Standard_Boolean isbound = mape2.Contains(e2);
947 if (!isbound) return Standard_False;
950 return Standard_True;
953 static Standard_Boolean allIonsectionedges(const Handle(TopOpeBRepDS_HDataStructure)& HDS, const TopoDS_Shape& f1,
954 const TopTools_IndexedMapOfShape& mape1,
955 const TopTools_IndexedMapOfShape& mape2)
956 // prequesitory : all interferences attached to <f1> are SSI
958 TopOpeBRepDS_ListIteratorOfListOfInterference it1(HDS->DS().ShapeInterferences(f1));
959 for (; it1.More(); it1.Next()){
960 const Handle(TopOpeBRepDS_ShapeShapeInterference)& SSI1 = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(it1.Value());
961 Standard_Integer G1 = SSI1->Geometry();
962 Standard_Boolean isgbound = SSI1->GBound();
963 const TopoDS_Shape& e1 = HDS->Shape(G1);
964 Standard_Boolean isbound = isgbound? mape1.Contains(e1): mape2.Contains(e1);
965 if (!isbound) return Standard_False;
967 return Standard_True;
970 //=======================================================================
971 //function : KPiskoletge
972 //purpose : detection faces collees tangentes sur wire exterieur
973 //=======================================================================
975 Standard_Integer TopOpeBRepBuild_Builder::KPiskoletge()
978 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
981 TopTools_ListOfShape lShsd1,lShsd2; // liste de solides HasSameDomain
982 TopTools_ListOfShape lfhsd1,lfhsd2; // liste de faces HasSameDomain
984 Standard_Boolean iskp1 = KPiskoletgesh(myShape1,lShsd1,lfhsd1);
985 if ( !iskp1 ) return 0;
986 TopTools_ListOfShape lplhsd1, lcyhsd1; ::FUN_sortplcy(lfhsd1,lplhsd1, lcyhsd1);
987 Standard_Integer nplhsd1 = lplhsd1.Extent(); Standard_Integer ncyhsd1 = lcyhsd1.Extent();
988 if ( nplhsd1 != 1 ) return 0;
989 if ( ncyhsd1 > 1 ) return 0;
991 Standard_Boolean iskp2 = KPiskoletgesh(myShape2,lShsd2,lfhsd2);
992 if ( !iskp2 ) return 0;
993 TopTools_ListOfShape lplhsd2, lcyhsd2; ::FUN_sortplcy(lfhsd2,lplhsd2, lcyhsd2);
994 Standard_Integer nplhsd2 = lplhsd2.Extent(); Standard_Integer ncyhsd2 = lcyhsd2.Extent();
995 if ( nplhsd2 != 1 ) return 0;
997 // Si l'un des objets est constitue de plusieurs solides on passe
998 // dans le cas general.
999 Standard_Integer nshsd1 = lShsd1.Extent();
1000 Standard_Integer nshsd2 = lShsd2.Extent();
1001 if ( nshsd1>1 || nshsd2>1 ) return 0;
1004 // NYI : (nplhsd1 > 1) || (nplhsd2 > 1)
1005 // ------------------------------------
1007 const TopoDS_Face& f1 = TopoDS::Face(lplhsd1.First());
1009 // Standard_Boolean isb1 = myKPMAPf1f2.IsBound(f1); // DEB
1012 const TopoDS_Face& f2 = TopoDS::Face(lplhsd2.First());
1014 // Standard_Boolean isb2 = myKPMAPf1f2.IsBound(f2); // DEB
1018 Standard_Integer iF1,iF2;
1019 Standard_Boolean tSPS1 = GtraceSPS(f1,iF1);
1020 Standard_Boolean tSPS2 = GtraceSPS(f2,iF2);
1022 {GdumpSHA( f1, (char *) "KPiskoletge ");
1024 GdumpSHA( f2, (char *)"KPiskoletge ");
1028 TopoDS_Wire outerw1 = BRepTools::OuterWire(f1);
1029 TopoDS_Wire outerw2 = BRepTools::OuterWire(f2);
1031 TopTools_IndexedMapOfShape mape1; TopExp::MapShapes(outerw1, TopAbs_EDGE, mape1);
1032 TopTools_IndexedMapOfShape mape2; TopExp::MapShapes(outerw2, TopAbs_EDGE, mape2);
1034 Standard_Boolean se1ONouterw2 = ::sectionedgesON(myDataStructure,outerw1,mape2);
1035 if (!se1ONouterw2) return 0;
1036 Standard_Boolean se2ONouterw1 = ::sectionedgesON(myDataStructure,outerw2,mape1);
1037 if (!se2ONouterw1) return 0;
1039 // NYI : <fi> interfers with faces of <Sj> on edges different from outerw's edges
1040 // ------------------------------------------------------------------------------
1041 Standard_Boolean allI1onseouterw = ::allIonsectionedges(myDataStructure,f1,mape1,mape2);
1042 if (!allI1onseouterw) return 0;
1043 Standard_Boolean allI2onseouterw = ::allIonsectionedges(myDataStructure,f2,mape2,mape1);
1044 if (!allI2onseouterw) return 0;
1047 // NYI : (ncyhsd1 > 1) || (ncyhsd2 > 1)
1048 // ------------------------------------
1051 Standard_Boolean cycy = ( ncyhsd1 == 1 ) && ( ncyhsd2 == 1 );
1052 if (!cycy) return 0;
1054 Standard_Boolean isbound1 = FUN_tool_inS(outerw1,f1);
1055 if (!isbound1) return 0;
1056 Standard_Boolean isbound2 = FUN_tool_inS(outerw2,f2);
1057 if (!isbound2) return 0;
1063 //=======================================================================
1064 //function : KPisdisj
1065 //purpose : detection shapes disjoints
1066 //=======================================================================
1068 Standard_Integer TopOpeBRepBuild_Builder::KPisdisj()
1071 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1074 // myShape1 et myShape2 : aucune interference
1075 const TopOpeBRepDS_DataStructure& DS = myDataStructure->DS();
1076 // Standard_Integer nsh = DS.NbShapes();
1077 // if (nsh != 2) return 0;
1079 if (!DS.HasShape(myShape1)) return 0;
1080 if (!DS.HasShape(myShape2)) return 0;
1082 Standard_Integer isdisj1 = KPisdisjsh(myShape1);
1083 Standard_Integer isdisj2 = KPisdisjsh(myShape2);
1087 cout<<"isdisj : "<<isdisj1<<" "<<isdisj2<<endl;
1091 Standard_Integer isdisj = (isdisj1 && isdisj2) ? 1 : 0;
1095 //=======================================================================
1096 //function : KPisfafa
1097 //purpose : detection {face} / {face} toutes HasSameDomain
1098 //=======================================================================
1100 Standard_Integer TopOpeBRepBuild_Builder::KPisfafa()
1103 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1106 Standard_Boolean iskp1 = KPisfafash(myShape1);
1107 if ( !iskp1 ) return 0;
1109 Standard_Boolean iskp2 = KPisfafash(myShape2);
1110 if ( !iskp2 ) return 0;
1115 //=======================================================================
1116 //function : KPissoso
1117 //purpose : detection {solide} / {solide} tous HasSameDomain
1118 //=======================================================================
1120 Standard_Integer TopOpeBRepBuild_Builder::KPissoso()
1123 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1126 Standard_Boolean iskp1 = KPissososh(myShape1);
1127 if ( !iskp1 ) return 0;
1129 Standard_Boolean iskp2 = KPissososh(myShape2);
1130 if ( !iskp2 ) return 0;
1135 //=======================================================================
1136 //function : KPClearMaps
1138 //=======================================================================
1140 void TopOpeBRepBuild_Builder::KPClearMaps()
1142 myKPMAPf1f2.Clear();
1145 //=======================================================================
1147 //purpose : --> nb des subsshapes <T> de <S> qui sont HasGeometry()
1148 //=======================================================================
1150 Standard_Integer TopOpeBRepBuild_Builder::KPlhg(const TopoDS_Shape& S,const TopAbs_ShapeEnum T) const
1152 TopTools_ListOfShape L;
1153 Standard_Integer n = KPlhg(S,T,L);
1157 //=======================================================================
1159 //purpose : --> nb +liste des subsshapes <T> de <S> qui sont HasGeometry()
1160 //=======================================================================
1162 Standard_Integer TopOpeBRepBuild_Builder::KPlhg(const TopoDS_Shape& S,const TopAbs_ShapeEnum T,TopTools_ListOfShape& L) const
1164 Standard_Integer n = 0;
1168 for (ex.Init(S,T); ex.More(); ex.Next()) {
1169 // for (TopExp_Explorer ex(S,T); ex.More(); ex.Next()) {
1170 const TopoDS_Shape& s = ex.Current();
1171 Standard_Boolean hg = myDataStructure->HasGeometry(s);
1181 //=======================================================================
1184 // KPlhsd --> nb des subsshapes <T> de <S> qui sont HasSameDomain()
1185 //=======================================================================
1187 Standard_Integer TopOpeBRepBuild_Builder::KPlhsd(const TopoDS_Shape& S,const TopAbs_ShapeEnum T) const
1189 TopTools_ListOfShape L;
1190 Standard_Integer n = KPlhsd(S,T,L);
1194 //=======================================================================
1197 // KPlhsd --> nb + liste des subsshapes <T> de <S> qui sont HasSameDomain()
1198 //=======================================================================
1200 Standard_Integer TopOpeBRepBuild_Builder::KPlhsd(const TopoDS_Shape& S,const TopAbs_ShapeEnum T,TopTools_ListOfShape& L) const
1202 Standard_Integer n = 0;
1206 for (ex.Init(S,T); ex.More(); ex.Next()) {
1207 // for (TopExp_Explorer ex(S,T); ex.More(); ex.Next()) {
1208 const TopoDS_Shape& s = ex.Current();
1209 Standard_Boolean hsd = myDataStructure->HasSameDomain(s);
1219 //=======================================================================
1220 //function : KPclasSS
1222 // classifie le shape S1 par rapport a S2 en evitant de prendre
1223 // les shape exLS1 de S1 comme element de classification.
1224 // exS1 peut etre IsNull().
1225 // S1,S2 = SOLID | SHELL
1226 //=======================================================================
1228 TopAbs_State TopOpeBRepBuild_Builder::KPclasSS(const TopoDS_Shape& S1,const TopTools_ListOfShape& exLS1,const TopoDS_Shape& S2)
1230 TopAbs_State state = TopAbs_UNKNOWN;
1231 state = myShapeClassifier.StateShapeShape(S1,exLS1,S2);
1234 if (TopOpeBRepBuild_GettraceKPB()) {
1235 const gp_Pnt& P1 = myShapeClassifier.P3D();
1236 cout<<"point P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z();
1237 cout<<" "; TopAbs::Print(state,cout);cout<<endl;
1244 //=======================================================================
1245 //function : KPclasSS
1247 // classifie le shape S1 par rapport a S2 en evitant de prendre
1248 // le shape exS1 de S1 comme element de classification.
1249 // exS1 peut etre IsNull().
1250 // S1,S2 = SOLID | SHELL
1251 //=======================================================================
1253 TopAbs_State TopOpeBRepBuild_Builder::KPclasSS(const TopoDS_Shape& S1,const TopoDS_Shape& exS1,const TopoDS_Shape& S2)
1255 TopAbs_State state = myShapeClassifier.StateShapeShape(S1,exS1,S2);
1258 if (TopOpeBRepBuild_GettraceKPB()) {
1259 const gp_Pnt& P1 = myShapeClassifier.P3D();
1260 cout<<"point P1 "<<P1.X()<<" "<<P1.Y()<<" "<<P1.Z();
1261 cout<<" "; TopAbs::Print(state,cout);cout<<endl;
1268 //=======================================================================
1269 //function : KPclasSS
1270 //purpose : classifie le shape S1 par rapport a S2 sans evitement de shape
1271 // S1,S2 = SOLID | SHELL
1272 //=======================================================================
1274 TopAbs_State TopOpeBRepBuild_Builder::KPclasSS(const TopoDS_Shape& S1,const TopoDS_Shape& S2)
1277 TopAbs_State state = KPclasSS(S1,Snull,S2);
1281 //=======================================================================
1282 //function : KPiskoletgesh
1285 // S est il un shape traite par le cas particulier de koletge?
1286 // si oui : retourne un solide et une liste de faces de collage
1287 //=======================================================================
1289 Standard_Boolean TopOpeBRepBuild_Builder::KPiskoletgesh(const TopoDS_Shape& Sarg,TopTools_ListOfShape& lShsd,TopTools_ListOfShape& lfhsd) const
1292 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1294 const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
1295 Standard_Boolean iskolesh = FUNKP_KPiskolesh((*this),BDS,Sarg,lShsd,lfhsd);
1296 if (!iskolesh) return Standard_False;
1299 Standard_Integer nfhsd =
1301 KPlhsd(Sarg,TopAbs_FACE,lfhsd);
1302 TopTools_ListIteratorOfListOfShape it(lfhsd);
1303 for (; it.More(); it.Next() ) {
1304 const TopoDS_Face& fac = TopoDS::Face(it.Value());
1305 Standard_Boolean isplan = FUN_tool_plane(fac);
1306 Standard_Boolean iscylinder = FUN_tool_cylinder(fac);
1307 if (iscylinder) continue;
1308 if (!isplan) return Standard_False;
1310 TopoDS_Wire outerw = BRepTools::OuterWire(fac);
1311 if (outerw.IsNull()) return Standard_False;
1313 TopExp_Explorer exe(outerw, TopAbs_EDGE);
1314 // Standard_Integer ne = 0;
1315 for (; exe.More(); exe.Next()){
1316 const TopoDS_Edge& ed = TopoDS::Edge(exe.Current());
1317 Standard_Boolean isse = BDS.IsSectionEdge(ed);
1318 const TopTools_ListOfShape& sp = (*this).Splits(ed,TopAbs_ON);
1319 if (sp.Extent() == 0) return Standard_False;
1320 if (!isse) return Standard_False;
1323 // if (ne > 1) return Standard_False;
1326 Standard_Integer isol = myDataStructure->Shape(Sarg); Standard_Integer ifac = myDataStructure->Shape(fac);
1327 if(TKPB){cout<<"isol "<<isol<<endl;}
1328 if(TKPB){cout<<"nfhsd "<<nfhsd<<endl;}
1329 if(TKPB){cout<<"ifac "<<ifac<<endl;}
1330 if(TKPB){cout<<"isplan "<<isplan<<endl;}
1331 if(TKPB){cout<<"iscylinder "<<iscylinder<<endl;}
1332 if(TKPB){cout<<endl;}
1336 return Standard_True;
1339 //=======================================================================
1340 //function : KPSameDomain
1341 //purpose : complete the lists L1,L2 with the shapes of the DS
1342 // having same domain :
1343 // L1 = shapes sharing the same domain of L2 shapes
1344 // L2 = shapes sharing the same domain of L1 shapes
1345 // (L1 contains a face)
1346 //=======================================================================
1348 void TopOpeBRepBuild_Builder::KPSameDomain(TopTools_ListOfShape& L1, TopTools_ListOfShape& L2) const
1351 Standard_Integer nl1 = L1.Extent(), nl2 = L2.Extent();
1353 while ( nl1 > 0 || nl2 > 0 ) {
1355 TopTools_ListIteratorOfListOfShape it1(L1);
1356 for (i=1 ; i<=nl1; i++) {
1357 const TopoDS_Shape& S1 = it1.Value();
1359 // Standard_Integer iS1 = myDataStructure->Shape(S1);
1361 TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S1));
1362 for (; itsd.More(); itsd.Next() ) {
1363 const TopoDS_Shape& S2 = itsd.Value();
1365 // Standard_Integer iS2 = myDataStructure->Shape(S2);
1367 Standard_Boolean found = KPContains(S2,L2);
1377 TopTools_ListIteratorOfListOfShape it2(L2);
1378 for (i=1 ; i<=nl2; i++) {
1379 const TopoDS_Shape& S2 = it2.Value();
1381 // Standard_Integer iS2 = myDataStructure->Shape(S2);
1383 TopTools_ListIteratorOfListOfShape itsd(myDataStructure->SameDomain(S2));
1384 for (; itsd.More(); itsd.Next() ) {
1385 const TopoDS_Shape& S1 = itsd.Value();
1387 // Standard_Integer iS1 = myDataStructure->Shape(S1);
1389 Standard_Boolean found = KPContains(S1,L1);
1401 //=======================================================================
1402 //function : KPisdisjsh
1403 //purpose : S est il un shape traite par le cas particulier "disjoint"
1404 //=======================================================================
1406 Standard_Integer TopOpeBRepBuild_Builder::KPisdisjsh(const TopoDS_Shape& Sarg) const
1408 if ( Sarg.IsNull() ) return 0;
1411 Standard_Integer nhg;
1413 nhg = KPlhg(Sarg,TopAbs_SOLID);
1414 if ( nhg != 0 ) return 0;
1416 nhg = KPlhg(Sarg,TopAbs_FACE);
1417 if ( nhg != 0 ) return 0;
1419 nhg = KPlhg(Sarg,TopAbs_EDGE);
1420 if ( nhg != 0 ) return 0;
1422 // un seul niveau de HasSameDomain
1423 Standard_Integer n1,n2;
1424 TopTools_ListOfShape lshsd;
1426 n1 = KPlhsd(Sarg,TopAbs_SOLID,lshsd);
1428 TopTools_ListIteratorOfListOfShape it(lshsd);
1429 for(;it.More();it.Next()) {
1430 const TopoDS_Shape& s = it.Value();
1431 n2 = KPlhsd(s,TopAbs_FACE);
1432 if (n2 != 0 ) return 0;
1436 n1 = KPlhsd(Sarg,TopAbs_FACE,lshsd);
1438 TopTools_ListIteratorOfListOfShape it(lshsd);
1439 for(;it.More();it.Next()) {
1440 const TopoDS_Shape& s = it.Value();
1441 n2 = KPlhsd(s,TopAbs_EDGE);
1442 if (n2 != 0 ) return 0;
1449 //=======================================================================
1450 //function : KPissososh
1451 //purpose : detection S = {solid} tous HasSameDomain
1452 //=======================================================================
1454 Standard_Integer TopOpeBRepBuild_Builder::KPissososh(const TopoDS_Shape& Sarg) const
1456 // que des solides volants (nb total de solides = nb de solides volants)
1457 Standard_Integer nsol1 = 0;
1458 TopExp_Explorer ex1(Sarg,TopAbs_SOLID);
1459 for(; ex1.More(); ex1.Next()) nsol1++;
1461 Standard_Integer nsol2 = 0;
1462 TopExp_Explorer ex2(Sarg,TopAbs_SOLID,TopAbs_COMPSOLID);
1463 for(; ex2.More(); ex2.Next()) nsol2++;
1465 if (nsol1 && (nsol1 != nsol2)) return 0;
1467 // toutes les solides sont HasSameDomain()
1468 Standard_Integer nhsd = KPlhsd(Sarg,TopAbs_SOLID);
1469 if (nhsd != nsol1) return 0;
1471 Standard_Integer n; TopExp_Explorer ex;
1473 // pas de shell volant
1475 for (ex.Init(Sarg,TopAbs_SHELL,TopAbs_SOLID); ex.More(); ex.Next()) n++;
1478 // pas de face volant
1480 for (ex.Init(Sarg,TopAbs_FACE,TopAbs_SHELL); ex.More(); ex.Next()) n++;
1483 // pas d'edge volant
1485 for (ex.Init(Sarg,TopAbs_EDGE,TopAbs_WIRE); ex.More(); ex.Next()) n++;
1488 // pas de vertex volant
1490 for (ex.Init(Sarg,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) n++;
1496 //=======================================================================
1497 //function : KPisfafash
1498 //purpose : detection S = {face} toutes HasSameDomain
1499 //=======================================================================
1501 Standard_Integer TopOpeBRepBuild_Builder::KPisfafash(const TopoDS_Shape& Sarg) const
1503 // il n'y a que des faces volantes (nb total de faces = nb de faces volantes)
1504 Standard_Integer nfac1 = 0;
1505 TopExp_Explorer ex1(Sarg,TopAbs_FACE);
1506 for(; ex1.More(); ex1.Next()) nfac1++;
1508 Standard_Integer nfac2 = 0;
1509 TopExp_Explorer ex2(Sarg,TopAbs_FACE,TopAbs_SHELL);
1510 for(; ex2.More(); ex2.Next()) nfac2++;
1512 if (nfac1 && (nfac1 != nfac2)) return 0;
1514 // toutes les faces sont HasSameDomain()
1515 Standard_Integer nhsd = KPlhsd(Sarg,TopAbs_FACE);
1516 if (nhsd != nfac1) return 0;
1518 Standard_Integer n; TopExp_Explorer ex;
1520 // pas de wire volant
1522 for (ex.Init(Sarg,TopAbs_WIRE,TopAbs_FACE); ex.More(); ex.Next()) n++;
1525 // pas d'edge volant
1527 for (ex.Init(Sarg,TopAbs_EDGE,TopAbs_WIRE); ex.More(); ex.Next()) n++;
1530 // pas de vertex volant
1532 for (ex.Init(Sarg,TopAbs_VERTEX,TopAbs_EDGE); ex.More(); ex.Next()) n++;
1538 //=======================================================================
1539 //function : KPiskoletgeanalyse
1541 //=======================================================================
1543 void TopOpeBRepBuild_Builder::KPiskoletgeanalyse(const TopOpeBRepDS_Config config2,
1544 const TopAbs_State Stsol1, const TopAbs_State Stsol2,
1545 Standard_Integer& ires) const
1547 // -----------------------------------------------------------------------------
1548 // prequesitory : (nplhsd1 == 1) || (nplhsd2 == 1)
1549 // ------------- <plsdmi> has all interferences Ii = (T, G=edge of outerw1
1550 // ||edge of outerw2, S)
1551 // -----------------------------------------------------------------------------
1555 Standard_Boolean SameOriented = (config2 == TopOpeBRepDS_SAMEORIENTED);
1556 Standard_Boolean DiffOriented = (config2 == TopOpeBRepDS_DIFFORIENTED);
1558 // Standard_Boolean com = Opecom();
1559 // Standard_Boolean c12 = Opec12();
1560 // Standard_Boolean c21 = Opec21();
1561 // Standard_Boolean fus = Opefus();
1564 if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_IN)
1565 // if (com) ires = RESNULL;
1568 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN) {
1569 // if (c12) ires = RESSHAPE1; // rank(sol1) == 1 && rank(sol2) == 2
1570 // if (c21) ires = RESSHAPE2; // rank(sol1) == 2 && rank(sol2) == 1
1574 if (Stsol2 == TopAbs_OUT && Stsol1 == TopAbs_IN) {
1575 // if (c12) ires = RESSHAPE2; // rank(sol2) == 1 && rank(sol1) == 2
1576 // if (c21) ires = RESSHAPE1; // rank(sol2) == 2 && rank(sol1) == 1
1580 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT)
1581 // if (fus) ires = RESNEWSOL;
1586 // ==============================
1587 // PREQUESITORY :sol1 is IN sol2
1588 // ==============================
1590 if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_IN)
1591 // if (com) ires = RESSHAPE1;
1594 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN) {
1595 // if (c12) ires = RESNULL; // rank(sol1) == 1 && rank(sol2) == 2
1596 // if (c21) ires = RESNEWSOL; // rank(sol1) == 2 && rank(sol2) == 1
1600 if (Stsol2 == TopAbs_OUT && Stsol1 == TopAbs_IN) {
1601 // if (c12) ires = RESNULL; // rank(sol2) == 1 && rank(sol1) == 2
1602 // if (c21) ires = RESNEWSOL; // rank(sol2) == 2 && rank(sol1) == 1
1606 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT)
1607 // if (fus) ires = RESSHAPE2;
1612 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1613 if (TKPB) cout<<"ires = "<<ires<<endl;
1618 //=======================================================================
1619 //function : KPisdisjanalyse
1621 //=======================================================================
1623 void TopOpeBRepBuild_Builder::KPisdisjanalyse(const TopAbs_State Stsol1, const TopAbs_State Stsol2,
1624 Standard_Integer& ires,Standard_Integer& icla1,Standard_Integer& icla2) const
1626 ires = RESUNDEF; icla1 = icla2 = SHEUNDEF;
1629 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1630 ires = RESSHAPE12; icla1 = icla2 = SHEAUCU; //--
1632 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1633 ires = RESNEWSHA1; icla1 = icla2 = SHECLASAUTR; //--
1635 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1636 ires = RESNEWSHA2; icla1 = icla2 = SHECLASAUTR; //--
1639 else if (Opec12()) {
1640 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1641 ires = RESSHAPE1; icla1 = SHEGARDTOUS; icla2 = SHEAUCU; //--
1643 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1644 ires = RESNEWSHA1; icla1 = SHECLASAUTR; icla2 = SHEGARDCOUR; //--
1646 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1647 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1650 else if (Opec21()) {
1651 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1652 ires = RESSHAPE2; icla1 = SHEAUCU; icla2 = SHEGARDTOUS; //--
1654 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1655 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1657 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1658 ires = RESNEWSHA2; icla1 = SHEGARDCOUR; icla2 = SHECLASAUTR; //--
1661 else if (Opecom()) {
1662 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1663 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1665 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1666 ires = RESNEWSHA2; icla1 = SHECLASAUTR; icla2 = SHEGARDAUTR; //--
1668 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1669 ires = RESNEWSHA1; icla1 = SHEGARDAUTR; icla2 = SHECLASAUTR; //--
1674 Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
1675 if (TKPB) cout<<"ires = "<<ires<<" icla1 "<<icla1<<" icla2 "<<icla2<<endl;
1679 //=======================================================================
1680 //function : KPls (class method)
1682 // KPls --> nb des subsshapes <T> de <S>
1683 //=======================================================================
1685 Standard_Integer TopOpeBRepBuild_Builder::KPls(const TopoDS_Shape& S,const TopAbs_ShapeEnum T)
1687 TopTools_ListOfShape L;
1688 Standard_Integer n = KPls(S,T,L);
1692 //=======================================================================
1693 //function : KPls (class method)
1695 // KPls --> nb + liste des subsshapes <T> de <S>
1696 //=======================================================================
1698 Standard_Integer TopOpeBRepBuild_Builder::KPls(const TopoDS_Shape& S, const TopAbs_ShapeEnum T, TopTools_ListOfShape& L)
1700 Standard_Integer n = 0;
1704 for (ex.Init(S,T); ex.More(); ex.Next()) {
1705 // for (TopExp_Explorer ex(S,T); ex.More(); ex.Next()) {
1706 const TopoDS_Shape& s = ex.Current();
1714 //=======================================================================
1715 //function : KPclassF (class method)
1717 // KPclassF : classification F1 par rapport a F2
1718 // F1 et F2 ne partagent aucune arete
1719 // F1 et F2 sont SameDomain
1720 //=======================================================================
1722 TopAbs_State TopOpeBRepBuild_Builder::KPclassF(const TopoDS_Shape& F1,const TopoDS_Shape& F2)
1724 if (F1.IsNull()) return TopAbs_UNKNOWN;
1725 if (F2.IsNull()) return TopAbs_UNKNOWN;
1727 TopoDS_Face F1F = TopoDS::Face(F1); F1F.Orientation(TopAbs_FORWARD);
1728 TopoDS_Face F2F = TopoDS::Face(F2); F2F.Orientation(TopAbs_FORWARD);
1730 TopTools_ListOfShape le1;
1731 Standard_Integer ne1 = KPls(F1F,TopAbs_EDGE,le1);
1732 if ( ne1 == 0 ) return TopAbs_UNKNOWN;
1733 const TopoDS_Edge& e1 = TopoDS::Edge(le1.First());
1735 Standard_Integer isamdom = 1;
1736 TopAbs_State St1 = TopAbs_UNKNOWN;
1737 St1 = myShapeClassifier.StateShapeShape(e1,F2F,isamdom);
1741 //=======================================================================
1742 //function : KPclassFF (class method)
1744 // classifie F1/F2 --> etats des faces l'une par rapport a l'autre
1745 //=======================================================================
1747 void TopOpeBRepBuild_Builder::KPclassFF(const TopoDS_Shape& F1,const TopoDS_Shape& F2,TopAbs_State& St1,TopAbs_State& St2)
1749 St1 = KPclassF(F1,F2);
1750 St2 = KPclassF(F2,F1);
1753 if (TopOpeBRepBuild_GettraceKPB()) {
1754 cout<<"Stf1 ";TopAbs::Print(St1,cout); cout<<" ";
1755 cout<<"Stf2 ";TopAbs::Print(St2,cout); cout<<endl;
1760 //=======================================================================
1761 //function : KPiskoleFF
1763 // classifie F1/F2 --> etats des faces l'une par rapport a l'autre
1764 // --> True si la configutration topologique correspond au cas "iskole".
1765 //=======================================================================
1767 Standard_Boolean TopOpeBRepBuild_Builder::KPiskoleFF(const TopoDS_Shape& F1,const TopoDS_Shape& F2,TopAbs_State& St1,TopAbs_State& St2)
1770 Standard_Integer iF1;
1771 Standard_Boolean tSPS1 = GtraceSPS(F1,iF1);
1772 Standard_Integer iF2;
1773 Standard_Boolean tSPS2 = GtraceSPS(F2,iF2);
1774 if(tSPS1) { GdumpSHA(F1, (char *) "KPiskoleFF ");cout<<endl; }
1775 if(tSPS2) { GdumpSHA(F2, (char *) "KPiskoleFF ");cout<<endl; }
1778 KPclassFF(F1,F2,St1,St2);
1779 Standard_Boolean st1ok = (St1 == TopAbs_OUT || St1 == TopAbs_IN);
1780 Standard_Boolean st2ok = (St2 == TopAbs_OUT || St2 == TopAbs_IN);
1782 if ( !st1ok ) return Standard_False;
1783 if ( !st2ok ) return Standard_False;
1784 Standard_Boolean stok = (St1 != St2);
1785 if ( !stok ) return Standard_False;
1786 return Standard_True;
1789 //=======================================================================
1790 //function : KPContains (class method)
1791 //purpose : returns True if S is in the list L.
1792 //=======================================================================
1794 Standard_Boolean TopOpeBRepBuild_Builder::KPContains(const TopoDS_Shape& S,const TopTools_ListOfShape& L)
1796 for (TopTools_ListIteratorOfListOfShape it(L); it.More(); it.Next() ) {
1797 const TopoDS_Shape& SL = it.Value();
1798 Standard_Boolean issame = SL.IsSame(S);
1799 if ( issame ) return Standard_True;
1801 return Standard_False;
1804 //=======================================================================
1805 //function : KPreturn (class method)
1807 //=======================================================================
1809 Standard_Integer TopOpeBRepBuild_Builder::KPreturn(const Standard_Integer b)
1812 if (TopOpeBRepBuild_GettraceKPB()) {
1813 cout<<"--- IsKPart "<<b;
1814 if ( b == 1 ) cout<<" iskole";
1815 if ( b == 2 ) cout<<" isdisj";
1816 if ( b == 3 ) cout<<" isfafa";
1823 //modified by NIZHNY-MKK Tue May 23 09:48:47 2000.BEGIN
1824 //======================================================================================================
1825 // static function : LocalKPisdisjanalyse
1827 //======================================================================================================
1828 static void LocalKPisdisjanalyse(const TopAbs_State Stsol1, const TopAbs_State Stsol2,
1829 const TopOpeBRepBuild_KPart_Operation& theOperation,
1830 Standard_Integer& ires, Standard_Integer& icla1, Standard_Integer& icla2) {
1831 ires = RESUNDEF; icla1 = icla2 = SHEUNDEF;
1833 switch(theOperation) {
1834 case TopOpeBRepBuild_KPart_Operation_Fuse: {
1835 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1836 ires = RESSHAPE12; icla1 = icla2 = SHEAUCU; //--
1838 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1839 ires = RESNEWSHA1; icla1 = icla2 = SHECLASAUTR; //--
1841 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1842 ires = RESNEWSHA2; icla1 = icla2 = SHECLASAUTR; //--
1846 case TopOpeBRepBuild_KPart_Operation_Cut12: {
1847 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1848 ires = RESSHAPE1; icla1 = SHEGARDTOUS; icla2 = SHEAUCU; //--
1850 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1851 ires = RESNEWSHA1; icla1 = SHECLASAUTR; icla2 = SHEGARDCOUR; //--
1853 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1854 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1858 case TopOpeBRepBuild_KPart_Operation_Cut21: {
1859 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1860 ires = RESSHAPE2; icla1 = SHEAUCU; icla2 = SHEGARDTOUS; //--
1862 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1863 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1865 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1866 ires = RESNEWSHA2; icla1 = SHEGARDCOUR; icla2 = SHECLASAUTR; //--
1870 case TopOpeBRepBuild_KPart_Operation_Common: {
1871 if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
1872 ires = RESNULL; icla1 = icla2 = SHEAUCU; //--
1874 else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
1875 ires = RESNEWSHA2; icla1 = SHECLASAUTR; icla2 = SHEGARDAUTR; //--
1877 else if (Stsol1 == TopAbs_IN && Stsol2 == TopAbs_OUT) {
1878 ires = RESNEWSHA1; icla1 = SHEGARDAUTR; icla2 = SHECLASAUTR; //--
1883 cout << "Warning: given operation is unknown" << endl;
1890 //======================================================================================================
1891 // static function : BuildNewSolid
1892 // purpose: Build new solid based on sol1 and sol2 according to the states
1893 //======================================================================================================
1894 static TopoDS_Solid BuildNewSolid(const TopoDS_Solid& sol1,
1895 const TopoDS_Solid& sol2,
1896 const TopAbs_State stsol1,
1897 const TopAbs_State stsol2,
1898 const Standard_Integer ires,
1899 const Standard_Integer icla1,
1900 const Standard_Integer icla2,
1901 const TopAbs_State theState1,
1902 const TopAbs_State theState2) {
1904 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
1906 TopTools_MapOfShape isdisjmap;
1907 TopOpeBRepDS_BuildTool aBuildTool;
1909 TopAbs_State solstate,shastatetoadd;
1910 TopoDS_Shell outsha;
1911 Standard_Integer icla;
1912 TopoDS_Solid othersol;
1913 TopoDS_Shell outsha1 = BRepClass3d::OuterShell(sol1);
1914 TopoDS_Shell outsha2 = BRepClass3d::OuterShell(sol2);
1917 TopoDS_Solid newsol;
1918 aBuildTool.MakeSolid(newsol);
1919 if (ires == RESNEWSHA1) {
1920 if ( ! isdisjmap.Contains(outsha1) ) {
1921 isdisjmap.Add(outsha1);
1922 aBuildTool.AddSolidShell(newsol,outsha1);
1925 else if (ires == RESNEWSHA2) {
1926 if ( ! isdisjmap.Contains(outsha2) ) {
1927 isdisjmap.Add(outsha2);
1928 aBuildTool.AddSolidShell(newsol,outsha2);
1934 shastatetoadd = theState1;
1940 TopOpeBRepTool_ShapeExplorer exsha;
1941 for (exsha.Init(sol,TopAbs_SHELL); exsha.More(); exsha.Next()) {
1942 const TopoDS_Shell& shacur = TopoDS::Shell(exsha.Current());
1943 Standard_Boolean isoutsha = shacur.IsEqual(outsha);
1945 Standard_Boolean garde = Standard_True;
1946 if (icla==SHEAUCU) garde = Standard_False;
1947 else if (icla==SHEGARDAUTR || icla==SHECLASAUTR) garde = ! isoutsha;
1948 if (!garde) continue;
1950 Standard_Boolean add = Standard_False;
1951 if ( icla==SHEGARDCOUR ) add = Standard_True;
1952 else if ( icla==SHEGARDAUTR ) add = Standard_True;
1953 else if ( icla==SHEGARDTOUS ) add = Standard_True;
1954 else if ( icla==SHECLASAUTR ) {
1955 TopAbs_State state = aShapeClassifier.StateShapeShape(shacur,Snull,othersol);
1956 add = (state == shastatetoadd);
1959 TopoDS_Shell shaori = shacur;
1960 Standard_Boolean r = (solstate == TopAbs_IN);
1961 if (r) shaori.Complement();
1962 if ( ! isdisjmap.Contains(shaori) ) {
1963 isdisjmap.Add(shaori);
1964 aBuildTool.AddSolidShell(newsol,shaori);
1972 shastatetoadd = theState2;
1978 TopOpeBRepTool_ShapeExplorer exsha;
1979 for (exsha.Init(sol,TopAbs_SHELL); exsha.More(); exsha.Next()) {
1980 const TopoDS_Shell& shacur = TopoDS::Shell(exsha.Current());
1981 Standard_Boolean isoutsha = shacur.IsEqual(outsha);
1983 Standard_Boolean garde = Standard_True;
1984 if (icla==SHEAUCU) garde = Standard_False;
1985 else if (icla==SHEGARDAUTR || icla==SHECLASAUTR) garde = ! isoutsha;
1986 if (!garde) continue;
1988 Standard_Boolean add = Standard_False;
1989 if ( icla==SHEGARDCOUR ) add = Standard_True;
1990 else if ( icla==SHEGARDAUTR ) add = Standard_True;
1991 else if ( icla==SHEGARDTOUS ) add = Standard_True;
1992 else if ( icla==SHECLASAUTR ) {
1993 TopAbs_State state = aShapeClassifier.StateShapeShape(shacur,Snull,othersol);
1994 add = (state == shastatetoadd);
1997 TopoDS_Shell shaori = shacur;
1998 Standard_Boolean r = (solstate == TopAbs_IN);
1999 if (r) shaori.Complement();
2000 aBuildTool.AddSolidShell(newsol,shaori);
2008 //======================================================================================================
2009 // static function : disjPerformFuse
2010 // purpose: is needed in case of KPart==2
2011 // attention: theMapOfResult is cleared before computations
2012 //======================================================================================================
2013 static Standard_Boolean disjPerformFuse(const TopTools_IndexedMapOfShape& theMapOfSolid1,
2014 const TopTools_IndexedMapOfShape& theMapOfSolid2,
2015 TopTools_IndexedMapOfShape& theMapOfResult) {
2017 theMapOfResult.Clear();
2019 TopTools_IndexedMapOfShape aMapOfSolid;
2020 aMapOfSolid = theMapOfSolid1;
2021 Standard_Integer i=1;
2022 for(i=1; i<=theMapOfSolid2.Extent(); i++) {
2023 aMapOfSolid.Add(theMapOfSolid2(i));
2026 TopoDS_Solid sol1; TopoDS_Shell outsha1;
2027 TopoDS_Solid sol2; TopoDS_Shell outsha2;
2028 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
2030 TopTools_MapOfShape aMapOfUsedSolids;
2031 TopoDS_Solid acurrentsolid;
2032 Standard_Integer aMaxNumberOfIterations = aMapOfSolid.Extent()*aMapOfSolid.Extent();
2034 for(i=1; i <=aMapOfSolid.Extent(); i++) {
2035 const TopoDS_Shape& localshape1 = aMapOfSolid(i);
2036 if(localshape1.ShapeType()!=TopAbs_SOLID)
2037 return Standard_False;
2039 sol1 = TopoDS::Solid(localshape1);
2040 acurrentsolid = sol1;
2041 if(aMapOfUsedSolids.Contains(localshape1))
2044 Standard_Integer j=1, acheckiterator=0;
2045 while(j<=aMapOfSolid.Extent() && (acheckiterator <= aMaxNumberOfIterations)) {
2051 const TopoDS_Shape& localshape2 = aMapOfSolid(j);
2052 if(localshape2.ShapeType()!=TopAbs_SOLID)
2053 return Standard_False;
2055 j++; // increase iterator
2057 if(aMapOfUsedSolids.Contains(localshape2)) {
2060 sol2 = TopoDS::Solid(localshape2);
2061 outsha2 = BRepClass3d::OuterShell(sol2);
2063 outsha1 = BRepClass3d::OuterShell(acurrentsolid);
2064 TopAbs_State stsol1 = aShapeClassifier.StateShapeShape(outsha1,Snull,sol2);
2065 TopAbs_State stsol2 = aShapeClassifier.StateShapeShape(outsha2,Snull,acurrentsolid);
2066 Standard_Integer ires=RESUNDEF, icla1=SHEUNDEF, icla2=SHEUNDEF;
2067 LocalKPisdisjanalyse(stsol1, stsol2, TopOpeBRepBuild_KPart_Operation_Fuse, ires, icla1, icla2);
2068 if (ires == RESUNDEF || icla1 == SHEUNDEF || icla2 == SHEUNDEF || ires == RESNULL) {
2069 cout << "Warning: disjPerformFuse: can not determine solid's states" << endl;
2072 if(ires == RESSHAPE12)
2075 if(ires==RESNEWSHA1 || ires==RESNEWSHA2) {
2076 TopoDS_Solid newsol = BuildNewSolid(acurrentsolid, sol2, stsol1, stsol2, ires, icla1, icla2, TopAbs_OUT, TopAbs_OUT);
2077 j=1; // iterate on all solids again except already used (very dengerous method)
2078 acurrentsolid = newsol;
2079 aMapOfUsedSolids.Add(localshape2);
2080 if(acurrentsolid.IsNull())
2081 return Standard_False;
2084 if(acheckiterator > aMaxNumberOfIterations) {
2085 cout << "disjPerformFuse: programming error" << endl;
2086 return Standard_False;
2088 theMapOfResult.Add(acurrentsolid);
2091 return Standard_True;
2094 //======================================================================================================
2095 // static function : disjPerformCommon
2096 // purpose: is needed in case of KPart==2
2097 // attention: theMapOfResult is cleared before computations
2098 //======================================================================================================
2099 static Standard_Boolean disjPerformCommon(const TopTools_IndexedMapOfShape& theMapOfSolid1,
2100 const TopTools_IndexedMapOfShape& theMapOfSolid2,
2101 TopTools_IndexedMapOfShape& theMapOfResult) {
2103 TopoDS_Solid sol1; TopoDS_Shell outsha1;
2104 TopoDS_Solid sol2; TopoDS_Shell outsha2;
2105 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
2107 TopTools_IndexedMapOfShape aMapOfSeparatedSolid1, aMapOfSeparatedSolid2, aMapOfCommonOfCouple;
2108 theMapOfResult.Clear();
2110 disjPerformFuse(theMapOfSolid1, theMapOfSolid1, aMapOfSeparatedSolid1);
2111 disjPerformFuse(theMapOfSolid2, theMapOfSolid2, aMapOfSeparatedSolid2);
2112 // Now common parts of all couples of solids are different
2113 for(Standard_Integer i=1; i <=aMapOfSeparatedSolid1.Extent(); i++) {
2114 const TopoDS_Shape& localshape1 = aMapOfSeparatedSolid1(i);
2115 if(localshape1.ShapeType()!=TopAbs_SOLID)
2116 return Standard_False;
2117 sol1 = TopoDS::Solid(localshape1);
2118 outsha1 = BRepClass3d::OuterShell(sol1);
2120 for(Standard_Integer j=1; j<=aMapOfSeparatedSolid2.Extent(); j++) {
2121 const TopoDS_Shape& localshape2 = aMapOfSeparatedSolid2(j);
2122 if(localshape2.ShapeType()!=TopAbs_SOLID)
2123 return Standard_False;
2125 sol2 = TopoDS::Solid(localshape2);
2126 outsha2 = BRepClass3d::OuterShell(sol2);
2127 TopAbs_State stsol1 = aShapeClassifier.StateShapeShape(outsha1,Snull,sol2);
2128 TopAbs_State stsol2 = aShapeClassifier.StateShapeShape(outsha2,Snull,sol1);
2129 Standard_Integer ires=RESUNDEF, icla1=SHEUNDEF, icla2=SHEUNDEF;
2131 LocalKPisdisjanalyse(stsol1, stsol2, TopOpeBRepBuild_KPart_Operation_Common, ires, icla1, icla2);
2132 if (ires == RESUNDEF || icla1 == SHEUNDEF || icla2 == SHEUNDEF) {
2133 cout << "Warning: disjPerformCommon: can not determine solid's states" << endl;
2142 aMapOfCommonOfCouple.Add(sol1);
2143 aMapOfCommonOfCouple.Add(sol2);
2148 aMapOfCommonOfCouple.Add(sol1);
2153 aMapOfCommonOfCouple.Add(sol2);
2158 TopoDS_Solid newsol = BuildNewSolid(sol1, sol2, stsol1, stsol2, ires, icla1, icla2, TopAbs_IN, TopAbs_IN);
2159 aMapOfCommonOfCouple.Add(newsol);
2167 disjPerformFuse(aMapOfCommonOfCouple, aMapOfCommonOfCouple, theMapOfResult);
2168 return Standard_True;
2171 //======================================================================================================
2172 // static function : disjPerformCut
2173 // purpose: is needed in case of KPart==2
2174 // attention: theMapOfResult is cleared before computations
2175 //======================================================================================================
2176 static Standard_Boolean disjPerformCut(const TopTools_IndexedMapOfShape& theMapOfSolid1,
2177 const TopTools_IndexedMapOfShape& theMapOfSolid2,
2178 TopTools_IndexedMapOfShape& theMapOfResult) {
2179 TopoDS_Solid sol1; TopoDS_Shell outsha1;
2180 TopoDS_Solid sol2; TopoDS_Shell outsha2;
2181 TopOpeBRepTool_ShapeClassifier aShapeClassifier;
2183 TopoDS_Solid acurrentsolid;
2184 TopTools_IndexedMapOfShape aMapOfSeparatedSolid1, aMapOfSeparatedSolid2;
2186 theMapOfResult.Clear();
2188 disjPerformFuse(theMapOfSolid1, theMapOfSolid1, aMapOfSeparatedSolid1);
2189 disjPerformFuse(theMapOfSolid2, theMapOfSolid2, aMapOfSeparatedSolid2);
2191 for(Standard_Integer i=1; i<= aMapOfSeparatedSolid1.Extent(); i++) {
2192 const TopoDS_Shape& localshape1 = aMapOfSeparatedSolid1(i);
2193 if(localshape1.ShapeType()!=TopAbs_SOLID)
2194 return Standard_False;
2195 sol1 = TopoDS::Solid(localshape1);
2196 acurrentsolid = sol1;
2198 Standard_Boolean NullResult = Standard_False;
2200 for(Standard_Integer j=1; j<=aMapOfSeparatedSolid2.Extent() && !NullResult; j++) {
2201 const TopoDS_Shape& localshape2 = aMapOfSeparatedSolid2(j);
2202 if(localshape2.ShapeType()!=TopAbs_SOLID)
2203 return Standard_False;
2204 sol2 = TopoDS::Solid(localshape2);
2205 outsha2 = BRepClass3d::OuterShell(sol2);
2206 outsha1 = BRepClass3d::OuterShell(acurrentsolid);
2207 TopAbs_State stsol1 = aShapeClassifier.StateShapeShape(outsha1,Snull,sol2);
2208 TopAbs_State stsol2 = aShapeClassifier.StateShapeShape(outsha2,Snull,acurrentsolid);
2209 Standard_Integer ires=RESUNDEF, icla1=SHEUNDEF, icla2=SHEUNDEF;
2211 LocalKPisdisjanalyse(stsol1, stsol2, TopOpeBRepBuild_KPart_Operation_Cut12, ires, icla1, icla2);
2212 if (ires == RESUNDEF || icla1 == SHEUNDEF || icla2 == SHEUNDEF) {
2213 cout << "Warning: disjPerformCut: can not determine solid's states" << endl;
2218 NullResult=Standard_True;
2222 NullResult=Standard_True;
2226 NullResult=Standard_False;
2230 NullResult=Standard_True;
2235 TopoDS_Solid newsol = BuildNewSolid(acurrentsolid, sol2, stsol1, stsol2, ires, icla1, icla2, TopAbs_OUT, TopAbs_IN);
2236 acurrentsolid = newsol;
2243 if(acurrentsolid.IsNull())
2244 return Standard_False;
2245 theMapOfResult.Add(acurrentsolid);
2248 return Standard_True;
2250 //modified by NIZHNY-MKK Tue May 23 09:49:03 2000.END