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