6ade617d11e92195089e6903ef557efdbf265863
[occt.git] / src / TopOpeBRepBuild / TopOpeBRepBuild_kpkole.cxx
1 // Created on: 1994-08-30
2 // Created by: Jean Yves LEBEY
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
8 // This library is free software; you can redistribute it and / or modify it
9 // under the terms of the GNU Lesser General Public version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <TopOpeBRepBuild_Builder.jxx>
18
19 #include <TopAbs.hxx>
20 #include <TopoDS_Solid.hxx>
21 #include <TopoDS_Shell.hxx>
22 #include <TopoDS_Wire.hxx>
23 #include <TopoDS.hxx>
24 #include <TopExp.hxx>
25 #include <BRep_Builder.hxx>
26 #include <TopOpeBRepTool_ShapeExplorer.hxx>
27 #include <TopOpeBRepTool_EXPORT.hxx>
28 #include <TopOpeBRepDS_EXPORT.hxx>
29 #include <TopOpeBRepDS_connex.hxx>
30 #include <TopOpeBRepBuild_define.hxx>
31 #include <TopOpeBRepBuild_WireToFace.hxx>
32 #include <TopOpeBRepBuild_kpresu.hxx>
33 #include <Standard_ProgramError.hxx>
34
35 #ifdef DEB
36 extern Standard_Boolean TopOpeBRepBuild_GettraceKPB();
37 void debiskole() {}
38 #endif
39
40 Standard_EXPORT Standard_Boolean FUNKP_KPiskolesh(const TopOpeBRepBuild_Builder& BU,const TopOpeBRepDS_DataStructure& BDS,const TopoDS_Shape& Sarg,TopTools_ListOfShape& lShsd,TopTools_ListOfShape& lfhsd);
41 Standard_EXPORT void FUNKP_KPmakefaces(const TopOpeBRepBuild_Builder& BU, const TopoDS_Shape& Fac1, const TopTools_ListOfShape& LF2,
42                                        const TopAbs_State Stfac1, const TopAbs_State Stfac2,
43                                        const Standard_Boolean R1, const Standard_Boolean R2,TopTools_ListOfShape& Lres);
44
45
46 //=======================================================================
47 //function : MergeKPartiskole
48 //purpose  : 
49 //=======================================================================
50
51 void TopOpeBRepBuild_Builder::MergeKPartiskole()
52 {
53 #ifdef DEB
54   Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
55   if (TKPB) KPreturn(myIsKPart);
56   debiskole();
57 #endif
58   
59   Standard_Integer ibid;
60   
61   if ( myIsKPart != 1 ) return;
62   
63   GMapShapes(myShape1,myShape2);
64   // NYI : on doit pouvoir faire l'economie du mapping GMapShapes(...)
65   // NYI en allant chercher l'indice 1,2 retourne par GShapeRank(S)
66   // NYI dans la DS. l'index est defini pour tous les shapes HasSameDomain
67   
68   TopTools_ListOfShape& lmergesha1 = ChangeMerged(myShape1,myState1);
69   ChangeMerged(myShape2,myState2);
70   
71   TopTools_ListOfShape lShsd1,lShsd2; // liste de solides HasSameDomain
72   TopTools_ListOfShape lfhsd1,lfhsd2; // liste de faces HasSameDomain
73   KPiskolesh(myShape1,lShsd1,lfhsd1);
74   KPiskolesh(myShape2,lShsd2,lfhsd2);
75   // traitement de tous les solides NYI
76   TopoDS_Shape sol1 = lShsd1.First();
77   TopoDS_Shape sol2 = lShsd2.First();
78   
79   ChangeMerged(sol1,myState1); 
80   ChangeMerged(sol2,myState2);
81   
82   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm1;
83   itm1.Initialize(myKPMAPf1f2);
84   if ( ! itm1.More() ) return;
85   
86 #ifdef DEB
87   if (TKPB) {
88     cout<<""<<endl;
89     for (; itm1.More();itm1.Next()) {
90       const TopoDS_Shape& f = itm1.Key();
91       Standard_Integer fi = myDataStructure->Shape(f);
92       cout<<"face "<<fi<<" : ";
93       const TopTools_ListOfShape& l = itm1.Value();
94       TopTools_ListIteratorOfListOfShape it(l);
95       for(; it.More(); it.Next()) {
96         const TopoDS_Shape& ff = it.Value();      
97         Standard_Integer ffi = myDataStructure->Shape(ff);
98         cout<<ffi<<" ";
99       }
100       cout<<endl;
101     }
102     itm1.Initialize(myKPMAPf1f2);
103   }
104 #endif
105   
106   TopTools_ListOfShape  LFIN;
107   TopTools_ListOfShape* plfIN = NULL;
108   const TopoDS_Shape* pfOU = NULL;
109   const TopoDS_Shape* pfIN = NULL;
110   
111   for (; itm1.More();itm1.Next()) {
112 //    const TopoDS_Shape& f = itm1.Key();
113 //   myDataStructure->Shape(f); //DEB
114     const TopTools_ListOfShape& los = itm1.Value();
115     Standard_Boolean emp = los.IsEmpty();
116     if (!emp) {
117       if (plfIN == NULL) plfIN = (TopTools_ListOfShape*)&itm1.Value();
118       if (pfOU == NULL) pfOU = &itm1.Key();
119       if (pfIN == NULL) pfIN = &plfIN->First();
120       for (TopTools_ListIteratorOfListOfShape it(los);it.More();it.Next()) LFIN.Append(it.Value());
121     }
122   }
123   
124   if ( plfIN==NULL) return;
125   if ( pfOU==NULL) return;
126   if ( pfIN==NULL) return;
127   
128 #ifdef DEB
129   Standard_Integer ifOU; Standard_Boolean tSPS = GtraceSPS(*pfOU,ifOU);
130   if(tSPS || TKPB) { 
131 //    Standard_Integer iOU = myDataStructure->Shape(*pfOU);
132 //    Standard_Integer iIN = myDataStructure->Shape(*pfIN);
133     GdumpSHA(*pfOU, (char *) "MergeKPartiskole pfOU ");cout<<endl;
134     GdumpSAMDOM(LFIN, (char *) "LFIN : ");
135     debiskole();
136   }
137 #endif
138   
139   Standard_Integer rankpfOU = GShapeRank(*pfOU);
140   Standard_Integer rankpfIN = GShapeRank(*pfIN);
141   if ( rankpfOU != 1 && rankpfOU != 2 ) return;
142   if ( rankpfIN != 1 && rankpfIN != 2 ) return;
143   
144   // solfOU = solide dont la face *pfOU est OUT / faces LFIN
145   // solfIN = solide dont les faces *plfIN sont IN / face *pfOU
146   TopoDS_Shape solfOU;
147   if (rankpfOU == 1) solfOU = sol1;
148   else               solfOU = sol2; 
149   TopoDS_Shape solfIN;
150   if (rankpfIN == 1) solfIN = sol1;
151   else               solfIN = sol2; 
152   TopAbs_State stsolfOU = KPclasSS(solfOU,*pfOU, solfIN);
153   TopAbs_State stsolfIN = KPclasSS(solfIN,LFIN,solfOU);
154   TopAbs_State stfOU = TopAbs_OUT;
155   TopAbs_State stfIN = TopAbs_IN;
156   
157   TopAbs_State stsol1=TopAbs_UNKNOWN,stsol2=TopAbs_UNKNOWN;
158   TopAbs_State stfac1=TopAbs_UNKNOWN,stfac2=TopAbs_UNKNOWN;
159   TopoDS_Shape fac1,fac2;
160   if      (rankpfOU == 1 ) {
161     stsol1 = stsolfOU; stfac1 = stfOU; fac1 = *pfOU;
162     stsol2 = stsolfIN; stfac2 = stfIN; fac2 = *pfIN;
163   }
164   else if (rankpfOU == 2 ) {
165     stsol1 = stsolfIN; stfac1 = stfIN; fac1 = *pfIN;
166     stsol2 = stsolfOU; stfac2 = stfOU; fac2 = *pfOU;
167   }
168   
169   Standard_Integer ires,icla1,icla2;
170   KPiskoleanalyse(stfac1,stfac2,stsol1,stsol2,ires,icla1,icla2);
171   if (ires == RESUNDEF) return;
172   if (icla1 == SHEUNDEF || icla2 == SHEUNDEF) return;
173   
174   TopoDS_Shape she1; // she1 = shell accedant fac1
175   TopTools_IndexedDataMapOfShapeListOfShape Mfacshe1;
176   TopExp::MapShapesAndAncestors(sol1,TopAbs_FACE,TopAbs_SHELL,Mfacshe1);
177   const TopTools_ListOfShape& lshe1 = Mfacshe1.FindFromKey(fac1);
178   TopTools_ListIteratorOfListOfShape itlshe1(lshe1);
179   she1 = itlshe1.Value(); 
180   
181   TopoDS_Shape she2; // she2 = shell accedant fac2
182   TopTools_IndexedDataMapOfShapeListOfShape Mfacshe2;
183   TopExp::MapShapesAndAncestors(sol2,TopAbs_FACE,TopAbs_SHELL,Mfacshe2);
184   const TopTools_ListOfShape& lshe2 = Mfacshe2.FindFromKey(fac2);
185   TopTools_ListIteratorOfListOfShape itlshe2(lshe2);
186   she2 = itlshe2.Value();
187   
188   ChangeMerged(she1,myState1);
189   ChangeMerged(she2,myState2);
190   
191 #ifdef DEB
192   if (TKPB) { cout<<"stsol1 ";TopAbs::Print(stsol1,cout); cout<<" "; }
193   if (TKPB) { cout<<"stsol2 ";TopAbs::Print(stsol2,cout); cout<<endl; }
194   debiskole();
195 #endif
196   
197   TopoDS_Shell newshe;
198   
199   if      ( ires == RESNULL ) {
200     return;
201   }
202   
203   else if (ires == RESSHAPE1) {
204     myBuildTool.MakeShell(newshe);
205     newshe = TopoDS::Shell(she1);
206   }
207   
208   else if (ires == RESSHAPE2) {
209     myBuildTool.MakeShell(newshe);
210     newshe = TopoDS::Shell(she2);
211   }
212   
213   else if ( ires == RESFACE1 ) {
214     if      (rankpfOU == 1) {
215       // resultat = face de rang 1 et face de rang 1 = face OUT
216       lmergesha1.Append(*pfOU);
217       ChangeMerged(fac2,myState2).Append(*pfOU);
218     }
219     else if (rankpfOU == 2) {
220       // resultat = face de rang 1 et face de rang 1 = faces IN
221       GCopyList(*plfIN,lmergesha1);
222       GCopyList(*plfIN,ChangeMerged(fac2,myState2));
223     }
224     return;
225   }
226   
227   else if ( ires == RESFACE2 ) {
228     if      (rankpfOU == 2) {
229       // resultat = face de rang 2 et face de rang 2 = face OUT
230       lmergesha1.Append(*pfOU);
231       ChangeMerged(fac1,myState1).Append(*pfOU);
232     }
233     else if (rankpfOU == 1) {
234       // resultat = face de rang 2 et face de rang 2 = faces IN
235       GCopyList(*plfIN,lmergesha1);
236       GCopyList(*plfIN,ChangeMerged(fac1,myState1));
237     }
238     return;
239   }
240   
241   else if (ires == RESNEWSHE) {
242     
243     itm1.Initialize(myKPMAPf1f2);
244     if (! itm1.More() ) return;
245     
246     TopTools_DataMapOfShapeShape addedfaces;
247     for (; itm1.More();itm1.Next()) {
248       
249       const TopoDS_Shape& f1 = itm1.Key();      
250       const TopTools_ListOfShape& lf2 = itm1.Value();
251       if (lf2.IsEmpty()) continue;
252       
253       TopTools_ListIteratorOfListOfShape it2;
254       it2.Initialize(lf2);
255       const TopoDS_Shape& f2 = it2.Value();
256       
257 /*#ifdef DEB
258       Standard_Integer ii1 = myDataStructure->Shape(f1);
259       Standard_Integer ii2 = myDataStructure->Shape(f2);
260 #endif*/
261       Standard_Integer rankf1 = GShapeRank(f1);
262       Standard_Integer rankf2 = GShapeRank(f2);
263       if (rankf1 == 0) continue;
264       if (rankf2 == 0) continue;
265       
266       TopAbs_State stf1,stf2; KPclassFF(f1,f2,stf1,stf2);
267       if ( rankf1 == 1 ) KPiskoleanalyse(stf1,stf2,stsol1,stsol2,ires,ibid,ibid);
268       if ( rankf1 == 2 ) KPiskoleanalyse(stf2,stf1,stsol2,stsol1,ires,ibid,ibid);
269       if (ires == RESUNDEF) continue;
270       
271       Standard_Boolean r1 = (stsol1 == TopAbs_IN);
272       Standard_Boolean r2 = (stsol2 == TopAbs_IN);
273       TopoDS_Shape fac;
274       if ( rankf1 == 1 ) fac = KPmakeface(f1,lf2,stf1,stf2,r1,r2);
275       if ( rankf1 == 2 ) fac = KPmakeface(f1,lf2,stf1,stf2,r2,r1);
276       if ( fac.IsNull() ) continue;
277       if ( ! fac.IsNull() ) addedfaces.Bind(fac,fac);
278       
279       TopAbs_State statemergef1 = (rankf1 == 1) ? myState1 : myState2;
280       TopAbs_State statemergef2 = (rankf2 == 2) ? myState2 : myState1;
281       ChangeMerged(f1,statemergef1).Append(fac);
282       it2.Initialize(lf2);
283       for (;it2.More();it2.Next()) 
284         ChangeMerged(it2.Value(),statemergef2).Append(fac);
285       
286       // les faces de she1 sauf les tangentes et celles deja ajoutees
287       TopOpeBRepTool_ShapeExplorer fex1;
288       for (fex1.Init(she1,TopAbs_FACE); fex1.More(); fex1.Next()) {
289         const TopoDS_Shape& facur = fex1.Current();
290         
291         Standard_Boolean isfsd   = myKPMAPf1f2.IsBound(facur);
292         Standard_Boolean isadded = addedfaces.IsBound(facur);
293         Standard_Boolean toadd =  (!isfsd) && (!isadded) ;
294         
295         if ( toadd ) {
296           TopoDS_Shape fori = facur;
297           if (stsol1 == TopAbs_IN) fori.Complement();
298           addedfaces.Bind(fori,fori);
299         }
300       }
301       
302       // les faces de she2 sauf les tangentes et celles deja ajoutees
303       TopOpeBRepTool_ShapeExplorer fex2;
304       for (fex2.Init(she2,TopAbs_FACE); fex2.More(); fex2.Next()) {
305         const TopoDS_Shape& facur = fex2.Current();
306         
307         Standard_Boolean isfsd   = myKPMAPf1f2.IsBound(facur);
308         Standard_Boolean isadded = addedfaces.IsBound(facur);
309         Standard_Boolean toadd =  (!isfsd) && (!isadded) ;
310         
311         if ( toadd ) {
312           TopoDS_Shape fori = facur;
313           if (stsol2 == TopAbs_IN) fori.Complement();
314           addedfaces.Bind(fori,fori);
315         }
316       }
317     }  // === fin iteration fac1,fac2
318     
319     TopTools_DataMapIteratorOfDataMapOfShapeShape itadd(addedfaces);
320     Standard_Boolean yauadd = itadd.More();
321     if (yauadd) {
322       myBuildTool.MakeShell(newshe);
323       myBuildTool.Closed(newshe,Standard_True);  // NYI : check exact du caractere closed du shell
324     }
325     for (; itadd.More(); itadd.Next() ) {
326       const TopoDS_Shape& ftoadd = itadd.Key();
327       myBuildTool.AddShellFace(newshe,ftoadd);
328     }
329     
330   } // === fin RESNEWSHE 
331   
332   else {
333 #ifdef DEB
334     cout<<"MergeKPartiskole : ires = "<<ires<<endl;
335 #endif
336   }
337   
338   TopoDS_Solid newsol;
339   if ( !newshe.IsNull() ) {
340     myBuildTool.MakeSolid(newsol);
341     myBuildTool.AddSolidShell(newsol,newshe);
342   }
343   
344   if ( icla1 == SHECLASAUTR || icla1 == SHEGARDAUTR ) {
345     // n.b. : ne pas prendre she1 accedant f1
346     TopTools_ListOfShape loshe1;
347     TopOpeBRepTool_ShapeExplorer ex1;
348     for (ex1.Init(sol1,TopAbs_SHELL); ex1.More(); ex1.Next()) {
349       const TopoDS_Shape& shecur = ex1.Current();
350       if (she1.IsEqual(shecur)) continue;
351       if (icla1 == SHECLASAUTR) {
352         TopAbs_State state1 = KPclasSS(shecur,fac1,sol2);
353         if (state1 == myState1) loshe1.Append(shecur);
354       }
355       else if (icla1 == SHEGARDAUTR) {
356         loshe1.Append(shecur);
357       }
358     }
359 #ifdef DEB
360 //    Standard_Integer nshe1 = loshe1.Extent();
361 #endif
362     TopTools_ListIteratorOfListOfShape itloshe1;
363     for( itloshe1.Initialize(loshe1); itloshe1.More(); itloshe1.Next() ) {
364       const TopoDS_Shape& shecur = itloshe1.Value();
365       myBuildTool.AddSolidShell(newsol,shecur);
366     }
367   }
368   
369   if ( icla2 == SHECLASAUTR || icla2 == SHEGARDAUTR ) {
370     // n.b. : ne pas prendre she2 accedant f2
371     TopTools_ListOfShape loshe2;
372     TopOpeBRepTool_ShapeExplorer ex2;
373     for (ex2.Init(sol2,TopAbs_SHELL); ex2.More(); ex2.Next()) {
374       const TopoDS_Shape& shecur = ex2.Current();
375       if (she2.IsEqual(shecur)) continue;
376       if      (icla2 == SHECLASAUTR) {
377         TopAbs_State state2 = KPclasSS(shecur,fac2,sol1);
378         if (state2 == myState2) loshe2.Append(shecur);
379       }
380       else if (icla2 == SHEGARDAUTR) {
381         loshe2.Append(shecur);
382       }
383     }
384 #ifdef DEB
385 //    Standard_Integer nshe2 = loshe2.Extent();
386 #endif
387     TopTools_ListIteratorOfListOfShape itloshe2;
388     for( itloshe2.Initialize(loshe2); itloshe2.More(); itloshe2.Next() ) {
389       const TopoDS_Shape& shecur = itloshe2.Value();
390       myBuildTool.AddSolidShell(newsol,shecur);
391     }
392   }
393   
394   // le solide final
395   if ( !newsol.IsNull() ) {
396     lmergesha1.Append(newsol);
397   }
398   
399 } // MergeKPartiskole
400
401
402 //=======================================================================
403 //function : KPiskole
404 //purpose  : detection faces collees
405 //=======================================================================
406
407 Standard_Integer TopOpeBRepBuild_Builder::KPiskole()
408 {  
409   
410   TopTools_ListOfShape lShsd1,lShsd2; // liste de solides HasSameDomain
411   TopTools_ListOfShape lfhsd1,lfhsd2; // liste de faces HasSameDomain
412   
413   Standard_Boolean iskp1 = KPiskolesh(myShape1,lShsd1,lfhsd1);
414   if ( !iskp1 ) return 0;
415   Standard_Integer nfhsd1 = lfhsd1.Extent();
416   if ( nfhsd1 == 0 ) return 0;
417   
418   Standard_Boolean iskp2 = KPiskolesh(myShape2,lShsd2,lfhsd2);
419   if ( !iskp2 ) return 0;
420   Standard_Integer nfhsd2 = lfhsd2.Extent();
421   if ( nfhsd2 == 0 ) return 0;
422   
423   // Si l'un des objets est constitue de plusieur solides on passe
424   // dans le cas general , sinon on obtient
425   //** Exception ** Standard_OutOfRange: TCollection_IndexedDataMap::FindFromKey at
426   // TopOpeBRepBuild_Builder::MergeKPartiskole(this = 0xf7988), 
427   // line 397 in "/adv_21/MDL/k1deb/ref/prod/TopOpeBRepBuild/src/TopOpeBRepBuild_KPart.cxx"
428   // DPF le 10/07/1997
429   Standard_Integer nshsd1 = lShsd1.Extent();
430   Standard_Integer nshsd2 = lShsd2.Extent();
431   if (nshsd1>1 || nshsd2>1) return 0;
432   
433   TopTools_ListOfShape lf1,lf2;
434   TopTools_ListOfShape les; //section
435   
436   for (TopTools_ListIteratorOfListOfShape itlf1(lfhsd1);
437        itlf1.More();itlf1.Next()) {
438     
439     const TopoDS_Shape& f1 = itlf1.Value();
440 #ifdef DEB
441 //    Standard_Boolean isb1 = myKPMAPf1f2.IsBound(f1); // DEB
442 #endif
443     lf1.Clear(); lf1.Append(f1);
444     lf2.Clear(); KPSameDomain(lf1,lf2);
445 #ifdef DEB
446 //    Standard_Integer n1 = lf1.Extent();
447 //    Standard_Integer n2 = lf2.Extent();
448 #endif
449     
450 #ifdef DEB
451     Standard_Integer iF1; Standard_Boolean tSPS1 = GtraceSPS(f1,iF1);
452     if(tSPS1) { 
453       GdumpSHA(f1, (char *) "KPiskole ");cout<<endl;
454       GdumpSAMDOM(lf2, (char *) "lf2 : ");
455     }
456 #endif
457     
458     for (TopTools_ListIteratorOfListOfShape itlf2(lf2); 
459          itlf2.More(); itlf2.Next() ) {
460       
461       const TopoDS_Shape& f2 = itlf2.Value();
462 #ifdef DEB
463 //      Standard_Boolean isb2 = myKPMAPf1f2.IsBound(f2); // DEB
464 #endif
465       TopAbs_State state1,state2;
466       Standard_Boolean classok = KPiskoleFF(f1,f2,state1,state2);
467       if ( ! classok ) return 0;
468       
469       // on va reconstuire la face OUT
470       if ( state1 == TopAbs_OUT && state2 == TopAbs_IN) {
471         Standard_Boolean isb1 = myKPMAPf1f2.IsBound(f1);
472         if ( ! isb1 ) { TopTools_ListOfShape los; myKPMAPf1f2.Bind(f1,los); }
473         TopTools_ListOfShape& los = myKPMAPf1f2.ChangeFind(f1);
474         los.Append(f2);
475         
476         Standard_Boolean isb2 = myKPMAPf1f2.IsBound(f2);
477         if ( ! isb2 ) { TopTools_ListOfShape los1; myKPMAPf1f2.Bind(f2,los1); }
478       }
479       else if ( state2 == TopAbs_OUT && state1 == TopAbs_IN) {
480         Standard_Boolean isb2 = myKPMAPf1f2.IsBound(f2);
481         if ( ! isb2 ) { TopTools_ListOfShape los; myKPMAPf1f2.Bind(f2,los); }
482         TopTools_ListOfShape& los = myKPMAPf1f2.ChangeFind(f2);
483         los.Append(f1);
484         
485         Standard_Boolean isb1 = myKPMAPf1f2.IsBound(f1);
486         if ( ! isb1 ) { TopTools_ListOfShape los1; myKPMAPf1f2.Bind(f1,los1); }
487       }
488       
489       // les aretes de la face IN sont des aretes de section
490       TopoDS_Shape fw;
491       if      (state1 == TopAbs_IN) fw = f1;
492       else if (state2 == TopAbs_IN) fw = f2;
493       if (fw.IsNull()) continue;
494       
495       TopOpeBRepTool_ShapeExplorer ex(fw,TopAbs_EDGE);
496       for (;ex.More();ex.Next()) les.Append(ex.Current());
497     } 
498   }
499   
500   // aretes de section iskole
501   TopOpeBRepDS_DataStructure& DS = myDataStructure->ChangeDS();
502   DS.InitSectionEdges(); TopTools_ListIteratorOfListOfShape it(les);
503   for (;it.More();it.Next()) DS.AddSectionEdge(TopoDS::Edge(it.Value()));
504   
505   return 1;
506 } // TopOpeBRepBuild_Builder::KPiskole
507
508 //=======================================================================
509 //function : KPiskoleanalyse
510 //purpose  : 
511 //=======================================================================
512
513 void TopOpeBRepBuild_Builder::KPiskoleanalyse(const TopAbs_State Stfac1, const TopAbs_State Stfac2,
514                            const TopAbs_State Stsol1, const TopAbs_State Stsol2,
515                            Standard_Integer& ires,Standard_Integer& icla1,Standard_Integer& icla2) const 
516 {
517   ires = RESUNDEF; icla1 = icla2 = SHEUNDEF;
518   
519   if      (Opefus())  {
520     if      (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
521       ires = RESNEWSHE; icla1 = SHEGARDAUTR; icla2 = SHEGARDAUTR;
522     }
523     else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
524       ires = RESSHAPE1; icla1 = SHECLASAUTR; icla2 = SHEAUCU;
525     }
526     else if (Stsol1 == TopAbs_IN  && Stsol2 == TopAbs_OUT) {
527       ires = RESSHAPE2; icla1 = SHEAUCU; icla2 = SHECLASAUTR;
528     }
529   }
530   else if (Opec12()) {
531     if      (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
532       ires = RESSHAPE1; icla1 = SHEGARDAUTR; icla2 = SHEAUCU;
533     }
534     else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
535       ires = RESNEWSHE; icla1 = SHECLASAUTR; icla2 = SHEAUCU;
536     }
537     else if (Stsol1 == TopAbs_IN  && Stsol2 == TopAbs_OUT) {
538       ires = RESNULL; icla1 = icla2 = SHEAUCU;
539     }
540   }
541   else if (Opec21()) {
542     if      (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) {
543       ires = RESSHAPE2; icla1 = SHEAUCU; icla2 = SHEGARDAUTR;
544     }
545     else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
546       ires = RESNULL; icla1 = icla2 = SHEAUCU;
547     }
548     else if (Stsol1 == TopAbs_IN  && Stsol2 == TopAbs_OUT) {
549       ires = RESNEWSHE; icla1 = SHEAUCU; icla2 = SHECLASAUTR;
550     }
551   }
552   else if (Opecom()) {
553     if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_OUT) { 
554       if (Stfac1 == TopAbs_IN) {
555         ires = RESFACE1; icla1 = icla2 = SHEAUCU;
556       }
557       if (Stfac2 == TopAbs_IN) {
558         ires = RESFACE2; icla1 = icla2 = SHEAUCU;
559       }
560     }
561     else if (Stsol1 == TopAbs_OUT && Stsol2 == TopAbs_IN ) {
562       ires = RESSHAPE2; icla1 = SHECLASAUTR; icla2 = SHEGARDAUTR;
563     }
564     else if (Stsol1 == TopAbs_IN  && Stsol2 == TopAbs_OUT) {
565       ires = RESSHAPE1; icla1 = SHEGARDAUTR; icla2 = SHECLASAUTR;
566     }
567   }
568   
569 #ifdef DEB
570   Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
571   if (TKPB) cout<<"ires = "<<ires<<" icla1 "<<icla1<<" icla2 "<<icla2<<endl;
572 #endif
573 } // TopOpeBRepBuild_Builder::KPiskoleanalyse
574
575 Standard_EXPORT void FUNKP_KPmakefaces(const TopOpeBRepBuild_Builder& BU,
576                                        const TopoDS_Shape& Fac1,
577                                        const TopTools_ListOfShape& LF2,
578                                        const TopAbs_State Stfac1,
579                                        const TopAbs_State /*Stfac2*/,
580                                        const Standard_Boolean R1,
581                                        const Standard_Boolean R2,
582                                        TopTools_ListOfShape& Lres)
583 {
584   // reconstruisons la face qui contient les autres
585   BRep_Builder BB;
586   TopoDS_Face fac; BB.MakeFace(fac);
587   
588   Standard_Integer rankIN = 0;
589   TopTools_ListOfShape LFSO,LFDO;
590   
591 #ifdef DEB
592   Standard_Integer iF1; Standard_Boolean tSPS = BU.GtraceSPS(Fac1,iF1);
593   if(tSPS) { BU.GdumpSHA(Fac1, (char *) "KPmakeFace ");cout<<endl; }
594 #endif
595   
596   if (Stfac1 == TopAbs_OUT) {
597     TopoDS_Shape aLocalShape = Fac1.EmptyCopied();
598     fac = TopoDS::Face(aLocalShape);
599 //    fac = TopoDS::Face(Fac1.EmptyCopied());
600     Standard_Integer rankF = BU.GShapeRank(Fac1);
601     rankIN = (rankF) ? ( (rankF==1) ? 2 : 1) : 0;
602     BU.GFindSamDomSODO(Fac1,LFSO,LFDO);
603   }
604   else {
605     Standard_ProgramError::Raise("KPmakeface Stfac1 != OUT");
606   }
607   
608   if (rankIN == 0) {
609     Standard_ProgramError::Raise("KPmakeface rankIN = 0");
610   }
611   
612   TopTools_ListOfShape LFIN;
613   BU.GFindSameRank(LFSO,rankIN,LFIN);
614   BU.GFindSameRank(LFDO,rankIN,LFIN);
615   
616 #ifdef DEB
617   if(tSPS) { 
618     BU.GdumpSAMDOM(LFSO, (char *) "LESO : ");
619     BU.GdumpSAMDOM(LFDO, (char *) "LEDO : ");
620     BU.GdumpSAMDOM(LFIN, (char *) "LFIN : ");
621   }
622 #endif
623   
624   TopOpeBRepBuild_WireToFace wtof;
625   
626   TopOpeBRepTool_ShapeExplorer wex1;
627   for (wex1.Init(Fac1,TopAbs_WIRE); wex1.More(); wex1.Next()) {
628     const TopoDS_Shape& wicur = wex1.Current();
629     TopoDS_Wire wori = TopoDS::Wire(wicur);
630     if (R1) wori.Complement();
631     wtof.AddWire(wori);
632     //myBuildTool.AddFaceWire(fac,wori);
633   }
634   
635   TopOpeBRepTool_ShapeExplorer wex2;
636   for (TopTools_ListIteratorOfListOfShape it2(LF2);it2.More();it2.Next()) {
637     const TopoDS_Shape& Fac2 = it2.Value();
638     for (wex2.Init(Fac2,TopAbs_WIRE); wex2.More(); wex2.Next()) {
639       const TopoDS_Shape& wicur = wex2.Current();
640       TopoDS_Wire wori = TopoDS::Wire(wicur);
641       if (R2) wori.Complement();
642       wtof.AddWire(wori);
643       //myBuildTool.AddFaceWire(fac,wori);
644     }
645   }
646   
647   const TopoDS_Face& F1 = TopoDS::Face(Fac1);
648   wtof.MakeFaces(F1,Lres);
649 #ifdef DEB
650 //  Standard_Integer nlres = Lres.Extent(); // DEB
651 #endif
652   
653   return;
654 } // FUNKP_KPmakefaces
655
656 //=======================================================================
657 //function : KPmakeface
658 //purpose  : 
659 //=======================================================================
660
661 TopoDS_Shape TopOpeBRepBuild_Builder::KPmakeface(const TopoDS_Shape& Fac1,
662                                                  const TopTools_ListOfShape& LF2,
663                                                  const TopAbs_State Stfac1,
664                                                  const TopAbs_State /*Stfac2*/,
665                                                  const Standard_Boolean R1,
666                                                  const Standard_Boolean R2)
667 {
668   // reconstruisons la face qui contient l'autre
669   BRep_Builder BB;
670   TopoDS_Face fac; BB.MakeFace(fac);
671   
672   Standard_Integer rankIN = 0;
673   TopTools_ListOfShape LFSO,LFDO;
674   
675 #ifdef DEB
676   Standard_Integer iF1;
677   Standard_Boolean tSPS = GtraceSPS(Fac1,iF1);
678   if(tSPS) {
679     GdumpSHA(Fac1, (char *) "KPmakeFace ");
680     cout<<endl;
681   }
682 #endif
683   
684   if (Stfac1 == TopAbs_OUT) {
685     TopoDS_Shape aLocalShape = Fac1.EmptyCopied();
686     fac = TopoDS::Face(aLocalShape);
687 //    fac = TopoDS::Face(Fac1.EmptyCopied());
688     Standard_Integer rankF = GShapeRank(Fac1);
689     rankIN = (rankF) ? ( (rankF==1) ? 2 : 1) : 0;
690     GFindSamDomSODO(Fac1,LFSO,LFDO);
691   }
692   else {
693     Standard_ProgramError::Raise("KPmakeface Stfac1 != OUT");
694     return myFaceReference; //Dummy
695   }
696   
697   if (rankIN == 0) {
698     Standard_ProgramError::Raise("KPmakeface rankIN = 0");
699     return myFaceReference; //Dummy
700   }
701   
702   TopTools_ListOfShape LFIN;
703   GFindSameRank(LFSO,rankIN,LFIN);
704   GFindSameRank(LFDO,rankIN,LFIN);
705   
706 #ifdef DEB
707   if(tSPS) { 
708     GdumpSAMDOM(LFSO, (char *) "LESO : ");
709     GdumpSAMDOM(LFDO, (char *) "LEDO : ");
710     GdumpSAMDOM(LFIN, (char *) "LFIN : ");
711   }
712 #endif
713   
714   
715   TopOpeBRepTool_ShapeExplorer wex1;
716   for (wex1.Init(Fac1,TopAbs_WIRE); wex1.More(); wex1.Next()) {
717     const TopoDS_Shape& wicur = wex1.Current();
718     TopoDS_Shape wori = wicur;
719     if (R1) wori.Complement();
720     myBuildTool.AddFaceWire(fac,wori);
721   }
722   
723   TopOpeBRepTool_ShapeExplorer wex2;
724   for (TopTools_ListIteratorOfListOfShape it2(LF2);it2.More();it2.Next()) {
725     const TopoDS_Shape& Fac2 = it2.Value();
726     for (wex2.Init(Fac2,TopAbs_WIRE); wex2.More(); wex2.Next()) {
727       const TopoDS_Shape& wicur = wex2.Current();
728       TopoDS_Shape wori = wicur;
729       if (R2) wori.Complement();
730       myBuildTool.AddFaceWire(fac,wori);
731     }
732   }
733   
734   return fac;
735 } // TopOpeBRepBuild_Builder::KPmakeface
736
737 Standard_EXPORT Standard_Boolean FUNKP_KPiskolesh(const TopOpeBRepBuild_Builder& BU,
738                                                   const TopOpeBRepDS_DataStructure& BDS,
739                                                   const TopoDS_Shape& Sarg,
740                                                   TopTools_ListOfShape& lShsd,
741                                                   TopTools_ListOfShape& /*lfhsd*/)
742      // <lShsd> : the list of solids same domain with <Sarg>
743      // sol is  <lShsd>'s first solid      
744      // <lfhsd> : the list of <sol>'s same domain faces, none of the list carries geometric interf
745 {
746   if ( Sarg.IsNull() ) return Standard_False;
747   
748   Standard_Integer nsol = BU.KPlhsd(Sarg,TopAbs_SOLID,lShsd);
749   if ( nsol == 0 ) return Standard_False;
750   const TopoDS_Shape& sol = lShsd.First();
751   
752   TopTools_ListOfShape lfhg; 
753   Standard_Integer nfhg = BU.KPlhg(sol,TopAbs_FACE,lfhg);
754   if ( nfhg != 0 ) {
755     TopTools_ListIteratorOfListOfShape its(lfhg);
756     for(; its.More(); its.Next()) {
757       TopOpeBRepDS_ListIteratorOfListOfInterference iti(BDS.ShapeInterferences(its.Value()));
758       for (;iti.More();iti.Next()) {
759         Handle(TopOpeBRepDS_ShapeShapeInterference) ssi;
760         ssi = Handle(TopOpeBRepDS_ShapeShapeInterference)::DownCast(iti.Value());
761         if (ssi.IsNull()) {
762           return Standard_False;
763         }
764       }
765     }  
766   }
767   return Standard_True;
768 } // FUNKP_KPiskolesh
769
770 //=======================================================================
771 //function : KPiskolesh
772 //purpose  : 
773 // KPiskolesh : 
774 // S est il un shape traite par le cas particulier du collage ?
775 // si oui : retourne un solide et une liste de faces de collage
776 //=======================================================================
777
778 Standard_Boolean TopOpeBRepBuild_Builder::KPiskolesh(const TopoDS_Shape& Sarg,
779                                                      TopTools_ListOfShape& lShsd,
780                                                      TopTools_ListOfShape& lfhsd) const 
781 {
782 #ifdef DEB
783   Standard_Boolean TKPB = TopOpeBRepBuild_GettraceKPB();
784 #endif
785   const TopOpeBRepDS_DataStructure& BDS = myDataStructure->DS();
786   Standard_Boolean iskolesh = FUNKP_KPiskolesh(*this,BDS,Sarg,lShsd,lfhsd);
787   if (!iskolesh) return Standard_False;
788   
789 #ifdef DEB
790   Standard_Integer nfhsd =
791 #endif
792               KPlhsd(Sarg,TopAbs_FACE,lfhsd);
793   TopTools_ListIteratorOfListOfShape it(lfhsd);
794   for (; it.More(); it.Next() ) {
795     const TopoDS_Shape& fac = it.Value();    
796     Standard_Boolean isplan = FUN_tool_plane(fac); //pro7993 BUG
797     if ( !isplan ) return Standard_False;
798
799     Standard_Integer nw = KPls(fac,TopAbs_WIRE);
800     if (nw > 1) return Standard_False; 
801
802     TopTools_ListOfShape lehg;
803     Standard_Integer nehg = KPlhg(fac,TopAbs_EDGE,lehg);
804     if ( nehg != 0 ) return Standard_False;
805     
806 #ifdef DEB
807     Standard_Integer isol = myDataStructure->Shape(Sarg);
808     Standard_Integer ifac = myDataStructure->Shape(fac); 
809     if(TKPB){cout<<"isol "<<isol<<endl;}
810     if(TKPB){cout<<"nfhsd  "<<nfhsd<<endl;}
811     if(TKPB){cout<<"ifac "<<ifac<<endl;}
812     if(TKPB){cout<<"isplan "<<isplan<<endl;}
813     if(TKPB){cout<<"nehg "<<nehg<<endl;}
814     if(TKPB){cout<<endl;}
815 #endif
816   }
817   
818   return Standard_True;
819 } // TopOpeBRepBuild_Builder::KPiskolesh