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