b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #include <BOP_SectionHistoryCollector.ixx> |
19 | |
20 | #include <TopExp.hxx> |
21 | #include <TopExp_Explorer.hxx> |
22 | #include <TopTools_IndexedMapOfShape.hxx> |
23 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
24 | #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx> |
25 | #include <BooleanOperations_ShapesDataStructure.hxx> |
26 | #include <BOPTools_DSFiller.hxx> |
27 | #include <BOPTools_InterferencePool.hxx> |
28 | #include <BOPTools_SSInterference.hxx> |
29 | #include <BOPTools_ListOfPaveBlock.hxx> |
30 | #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx> |
31 | #include <BOPTools_ListIteratorOfListOfPave.hxx> |
32 | #include <BOPTools_PaveBlock.hxx> |
33 | #include <BOPTools_Curve.hxx> |
34 | #include <BOPTools_PavePool.hxx> |
35 | #include <BOPTools_PaveFiller.hxx> |
36 | #include <BOPTools_VVInterference.hxx> |
37 | #include <BOPTools_VEInterference.hxx> |
38 | #include <BOPTools_VSInterference.hxx> |
39 | #include <TopoDS.hxx> |
40 | #include <TopTools_MapOfShape.hxx> |
41 | |
42 | static Standard_Boolean AddNewShape(const TopoDS_Shape& theKey, |
43 | const TopoDS_Shape& theItem, |
44 | TopTools_DataMapOfShapeListOfShape& theMap); |
45 | |
46 | // ============================================================================================ |
47 | // function: Constructor |
48 | // purpose: |
49 | // ============================================================================================ |
50 | BOP_SectionHistoryCollector::BOP_SectionHistoryCollector(const TopoDS_Shape& theShape1, |
51 | const TopoDS_Shape& theShape2) : |
52 | BOP_HistoryCollector(theShape1,theShape2, BOP_SECTION) |
53 | { |
54 | } |
55 | |
56 | // ============================================================================================ |
57 | // function: SetResult |
58 | // purpose: |
59 | // ============================================================================================ |
60 | void BOP_SectionHistoryCollector::SetResult(const TopoDS_Shape& theResult, |
61 | const BOPTools_PDSFiller& theDSFiller) |
62 | { |
63 | myResult = theResult; |
64 | |
65 | if(myResult.IsNull()) |
66 | return; |
67 | |
68 | TopAbs_ShapeEnum aResultType = TopAbs_EDGE; |
69 | Standard_Boolean bcontainsface1 = Standard_False; |
70 | Standard_Boolean bcontainsface2 = Standard_False; |
71 | |
72 | Standard_Boolean bcontainsedge1 = Standard_False; |
73 | Standard_Boolean bcontainsedge2 = Standard_False; |
74 | |
75 | TopExp_Explorer anExp(myS1, TopAbs_FACE); |
76 | |
77 | if(anExp.More()) { |
78 | bcontainsface1 = Standard_True; |
79 | bcontainsedge1 = Standard_True; |
80 | } |
81 | else { |
82 | anExp.Init(myS1, TopAbs_EDGE); |
83 | |
84 | if(anExp.More()) { |
85 | bcontainsedge1 = Standard_True; |
86 | } |
87 | } |
88 | anExp.Init(myS2, TopAbs_FACE); |
89 | |
90 | if(anExp.More()) { |
91 | bcontainsface2 = Standard_True; |
92 | bcontainsedge2 = Standard_True; |
93 | } |
94 | else { |
95 | anExp.Init(myS2, TopAbs_EDGE); |
96 | |
97 | if(anExp.More()) { |
98 | bcontainsedge2 = Standard_True; |
99 | } |
100 | } |
101 | |
102 | if(bcontainsface1 && bcontainsface2) |
103 | aResultType = TopAbs_EDGE; |
104 | else if(bcontainsedge1 && bcontainsedge2) |
105 | aResultType = TopAbs_VERTEX; |
106 | else |
107 | return; |
108 | |
109 | myHasDeleted = Standard_True; |
110 | |
111 | |
112 | TopTools_IndexedMapOfShape aMap; |
113 | TopExp::MapShapes(myResult, aResultType, aMap); |
114 | |
115 | if(aResultType == TopAbs_EDGE) { |
116 | FillFaceSection(theDSFiller, aMap); |
117 | |
118 | TopTools_IndexedDataMapOfShapeListOfShape aEFMap; |
119 | TopTools_IndexedDataMapOfShapeListOfShape aVEMap; |
120 | |
121 | TopExp::MapShapesAndAncestors(myResult, TopAbs_VERTEX, TopAbs_EDGE, aVEMap); |
122 | TopExp::MapShapesAndAncestors(myS1, TopAbs_EDGE, TopAbs_FACE, aEFMap); |
123 | TopExp::MapShapesAndAncestors(myS2, TopAbs_EDGE, TopAbs_FACE, aEFMap); |
124 | |
125 | TopTools_IndexedMapOfShape aResultMap, aFreeBoundaryMap; |
126 | Standard_Integer i = 0; |
127 | |
128 | for(i = 1; i <= aEFMap.Extent(); i++) { |
129 | if(aEFMap.FindFromIndex(i).Extent() < 2) |
130 | aFreeBoundaryMap.Add(aEFMap.FindKey(i)); |
131 | } |
132 | |
133 | for(i = 1; i <= aFreeBoundaryMap.Extent(); i++) { |
134 | const TopoDS_Shape& anEdge = aFreeBoundaryMap.FindKey(i); |
135 | FillEdgeSection(anEdge, theDSFiller, aMap, aVEMap, aEFMap); |
136 | } |
137 | } |
138 | } |
139 | |
140 | // ============================================================================================ |
141 | // function: FillFaceSection |
142 | // purpose: |
143 | // ============================================================================================ |
144 | void BOP_SectionHistoryCollector::FillFaceSection(const BOPTools_PDSFiller& theDSFiller, |
145 | const TopTools_IndexedMapOfShape& theResultMap) |
146 | { |
147 | const BooleanOperations_ShapesDataStructure& aDS = theDSFiller->DS(); |
148 | const BOPTools_InterferencePool& anInterfPool = theDSFiller->InterfPool(); |
149 | BOPTools_InterferencePool* pInterfPool = (BOPTools_InterferencePool*) &anInterfPool; |
150 | BOPTools_CArray1OfSSInterference& aFFs = pInterfPool->SSInterferences(); |
151 | // |
152 | TopTools_IndexedMapOfShape aMap; |
153 | Standard_Integer aNbFFs = aFFs.Extent(); |
154 | Standard_Integer i = 0, j = 0; |
155 | |
156 | for (i=1; i<=aNbFFs; ++i) { |
157 | BOPTools_SSInterference& aFFi = aFFs(i); |
158 | // |
159 | Standard_Integer nF1 = aFFi.Index1(); |
160 | Standard_Integer nF2 = aFFi.Index2(); |
161 | TopoDS_Shape aF1 = aDS.Shape(nF1); |
162 | TopoDS_Shape aF2 = aDS.Shape(nF2); |
163 | Standard_Integer nSect = 0; |
164 | |
165 | // Old Section Edges |
166 | const BOPTools_ListOfPaveBlock& aSectList = aFFi.PaveBlocks(); |
167 | BOPTools_ListIteratorOfListOfPaveBlock anIt(aSectList); |
168 | |
169 | for (; anIt.More();anIt.Next()) { |
170 | const BOPTools_PaveBlock& aPB=anIt.Value(); |
171 | nSect = aPB.Edge(); |
172 | const TopoDS_Shape& aS = aDS.GetShape(nSect); |
173 | |
174 | if(theResultMap.Contains(aS)) { |
175 | TopTools_ListOfShape thelist; |
176 | if(!myGenMap.IsBound(aF1)) |
177 | myGenMap.Bind(aF1, thelist ); |
178 | |
179 | if(!myGenMap.IsBound(aF2)) |
180 | myGenMap.Bind(aF2, thelist); |
181 | |
182 | for(Standard_Integer fit = 0; fit < 2; fit++) { |
183 | if(fit == 0) |
184 | AddNewShape(aF1, aS, myGenMap); |
185 | else |
186 | AddNewShape(aF2, aS, myGenMap); |
187 | } |
188 | } |
189 | } |
190 | |
191 | // New Section Edges |
192 | BOPTools_SequenceOfCurves& aBCurves = aFFi.Curves(); |
193 | Standard_Integer aNbCurves = aBCurves.Length(); |
194 | |
195 | for (j = 1; j <= aNbCurves; j++) { |
196 | BOPTools_Curve& aBC = aBCurves(j); |
197 | const BOPTools_ListOfPaveBlock& aSectEdges = aBC.NewPaveBlocks(); |
198 | |
199 | BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aSectEdges); |
200 | |
201 | for (; aPBIt.More(); aPBIt.Next()) { |
202 | BOPTools_PaveBlock& aPB = aPBIt.Value(); |
203 | nSect = aPB.Edge(); |
204 | const TopoDS_Shape& aS = aDS.GetShape(nSect); |
205 | |
206 | if(theResultMap.Contains(aS) && !aMap.Contains(aS)) { |
207 | TopTools_ListOfShape thelist1; |
208 | |
209 | if(!myGenMap.IsBound(aF1)) { |
210 | myGenMap.Bind(aF1, thelist1); |
211 | } |
212 | myGenMap.ChangeFind(aF1).Append(aS); |
213 | |
214 | if(!myGenMap.IsBound(aF2)) |
215 | myGenMap.Bind(aF2, thelist1); |
216 | myGenMap.ChangeFind(aF2).Append(aS); |
217 | aMap.Add(aS); |
218 | } |
219 | } |
220 | } |
221 | } |
222 | } |
223 | |
224 | // Modified by skv - Wed Nov 5 15:52:48 2003 OCC3644 Begin |
225 | // ============================================================================================ |
226 | // function: IsEdgeToAdd |
227 | // purpose: |
228 | // ============================================================================================ |
229 | |
230 | static Standard_Boolean IsEdgeToAdd |
231 | (const TopoDS_Shape &theEdge, |
232 | const TopTools_IndexedMapOfShape &theResultMap, |
233 | const TopTools_IndexedDataMapOfShapeListOfShape &theVEMapRes, |
234 | const BOPTools_PDSFiller &theDSFiller) |
235 | { |
236 | if (theEdge.ShapeType() != TopAbs_EDGE) |
237 | return Standard_True; |
238 | |
239 | const BooleanOperations_ShapesDataStructure &aDS=theDSFiller->DS(); |
240 | const BOPTools_PaveFiller &aPvFiller=theDSFiller->PaveFiller(); |
241 | const BOPTools_SplitShapesPool &aSplitShapesPool=aPvFiller.SplitShapesPool(); |
242 | Standard_Integer aNbE1 = aDS.ShapeIndex(theEdge, 1); |
243 | Standard_Integer aNbE2 = aDS.ShapeIndex(theEdge, 2); |
244 | Standard_Integer aNbE = (aNbE1 == 0) ? aNbE2 : aNbE1; |
245 | |
246 | if (aNbE == 0) |
247 | return Standard_False; |
248 | |
249 | const BOPTools_ListOfPaveBlock &aLPB=aSplitShapesPool(aDS.RefEdge(aNbE)); |
250 | BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aLPB); |
251 | |
252 | for (; aPBIt.More(); aPBIt.Next()) { |
253 | const BOPTools_PaveBlock& aPB = aPBIt.Value(); |
254 | Standard_Integer aSplitNb = aPB.Edge(); |
255 | const TopoDS_Shape& aSplit = aDS.Shape(aSplitNb); |
256 | |
257 | if (theResultMap.Contains(aSplit)) { |
258 | TopoDS_Vertex aVf; |
259 | TopoDS_Vertex aVl; |
260 | TopoDS_Edge anEdge = TopoDS::Edge(aSplit); |
261 | |
262 | TopExp::Vertices(anEdge, aVf, aVl); |
263 | |
264 | if (theVEMapRes.FindFromKey(aVf).Extent() < 2 || |
265 | theVEMapRes.FindFromKey(aVl).Extent() < 2) |
266 | return Standard_False; |
267 | } |
268 | } |
269 | |
270 | return Standard_True; |
271 | } |
272 | // Modified by skv - Wed Nov 5 15:52:50 2003 OCC3644 End |
273 | |
274 | // ============================================================================================ |
275 | // function: FillEdgeSection |
276 | // purpose: |
277 | // ============================================================================================ |
278 | void BOP_SectionHistoryCollector::FillEdgeSection |
279 | (const TopoDS_Shape &theEdge, |
280 | const BOPTools_PDSFiller &theDSFiller, |
281 | const TopTools_IndexedMapOfShape &theResultMap, |
282 | const TopTools_IndexedDataMapOfShapeListOfShape &theVEMapRes, |
283 | const TopTools_IndexedDataMapOfShapeListOfShape &theEFMap) |
284 | { |
285 | if(myResult.IsNull()) |
286 | return; |
287 | |
288 | TopTools_IndexedDataMapOfShapeListOfShape aMapOfOldNewVertex; |
289 | |
290 | BOPTools_InterferencePool* pIntrPool = (BOPTools_InterferencePool*)&theDSFiller->InterfPool(); |
291 | const BOPTools_PavePool& aPavePool = theDSFiller->PaveFiller().PavePool(); |
292 | const BooleanOperations_ShapesDataStructure& aDS = theDSFiller->DS(); |
293 | |
294 | Standard_Integer anIndex = 0; |
295 | const BooleanOperations_IndexedDataMapOfShapeInteger& aMap1 = theDSFiller->DS().ShapeIndexMap(1); |
296 | const BooleanOperations_IndexedDataMapOfShapeInteger& aMap2 = theDSFiller->DS().ShapeIndexMap(2); |
297 | |
298 | if(aMap1.Contains(theEdge)) |
299 | anIndex = aMap1.FindFromKey(theEdge); |
300 | else if(aMap2.Contains(theEdge)) |
301 | anIndex = aMap2.FindFromKey(theEdge); |
302 | else |
303 | return; |
304 | |
305 | const BOPTools_PaveSet& aPaveSet = aPavePool.Value(aDS.RefEdge(anIndex)); |
306 | const BOPTools_ListOfPave& aListOfPave = aPaveSet.Set(); |
307 | BOPTools_ListIteratorOfListOfPave anIt(aListOfPave); |
308 | |
309 | for(; anIt.More(); anIt.Next()) { |
310 | const BOPTools_Pave& aPave = anIt.Value(); |
311 | const BooleanOperations_KindOfInterference aPaveType = aPave.Type(); |
312 | |
313 | if((aPaveType == BooleanOperations_EdgeSurface)) { |
314 | BOPTools_PShapeShapeInterference anInter = pIntrPool->GetInterference(aPave.Interference(), aPaveType); |
315 | |
316 | if(anInter == NULL) |
317 | continue; |
318 | |
319 | const TopoDS_Shape& aS1 = aDS.Shape(anInter->Index1()); |
320 | const TopoDS_Shape& aS2 = aDS.Shape(anInter->Index2()); |
321 | const TopoDS_Shape& aNewShape = aDS.Shape(anInter->NewShape()); |
322 | |
323 | if((aNewShape.ShapeType() != TopAbs_VERTEX) || |
324 | (!theVEMapRes.Contains(aNewShape))) |
325 | continue; |
326 | |
327 | if(theVEMapRes.FindFromKey(aNewShape).Extent() >= 2) |
328 | continue; |
329 | |
330 | if(aS1.IsSame(aNewShape) || aS2.IsSame(aNewShape)) { |
331 | TopTools_ListOfShape thelist; |
332 | if(!aMapOfOldNewVertex.Contains(aNewShape)) |
333 | aMapOfOldNewVertex.Add(aNewShape, thelist); |
334 | aMapOfOldNewVertex.ChangeFromKey(aNewShape).Append(aNewShape); |
335 | continue; |
336 | } |
337 | Standard_Boolean addfirst = Standard_True; |
338 | Standard_Boolean addsecond = Standard_True; |
339 | |
340 | for(Standard_Integer sit = 0; sit < 2; sit++) { |
341 | if(((sit == 0) && !addfirst) || ((sit != 0) && !addsecond)) |
342 | continue; |
343 | const TopoDS_Shape& aS = (sit == 0) ? aS1 : aS2; |
344 | // Modified by skv - Wed Nov 5 17:11:41 2003 OCC3644 Begin |
345 | // AddNewShape(aS, aNewShape, myGenMap); |
346 | if (IsEdgeToAdd(aS, theResultMap, theVEMapRes, theDSFiller)) |
347 | AddNewShape(aS, aNewShape, myGenMap); |
348 | // Modified by skv - Wed Nov 5 17:11:49 2003 OCC3644 End |
349 | } |
350 | } else if (aPaveType == BooleanOperations_EdgeEdge || |
351 | aPaveType == BooleanOperations_VertexEdge) { |
352 | // Special treatment of case Edge-Edge and Edge-Vertex interference. |
353 | BOPTools_PShapeShapeInterference anInter = pIntrPool->GetInterference(aPave.Interference(), aPaveType); |
354 | |
355 | if(anInter == NULL) |
356 | continue; |
357 | |
358 | const TopoDS_Shape& aS1 = aDS.Shape(anInter->Index1()); |
359 | const TopoDS_Shape& aS2 = aDS.Shape(anInter->Index2()); |
360 | const TopoDS_Shape& aNewShape = aDS.Shape(anInter->NewShape()); |
361 | |
362 | if((aNewShape.ShapeType() != TopAbs_VERTEX) || |
363 | (!theVEMapRes.Contains(aNewShape))) |
364 | continue; |
365 | |
366 | if(theVEMapRes.FindFromKey(aNewShape).Extent() >= 2) |
367 | continue; |
368 | |
369 | Standard_Boolean isAddObj = IsEdgeToAdd(aS1, theResultMap, theVEMapRes, theDSFiller); |
370 | Standard_Boolean isAddTool = IsEdgeToAdd(aS2, theResultMap, theVEMapRes, theDSFiller); |
371 | |
372 | if (!isAddObj) { |
373 | if (!theEFMap.Contains(aS1)) |
374 | continue; |
375 | |
376 | AddNewShape(aS2, aNewShape, myGenMap); |
377 | |
378 | const TopTools_ListOfShape &aFaces = theEFMap.FindFromKey(aS1); |
379 | TopTools_ListIteratorOfListOfShape aFIter(aFaces); |
380 | |
381 | for (; aFIter.More(); aFIter.Next()) { |
382 | const TopoDS_Shape &anAncFace = aFIter.Value(); |
383 | |
384 | AddNewShape(anAncFace, aNewShape, myGenMap); |
385 | } |
386 | } else if (!isAddTool) { |
387 | if (!theEFMap.Contains(aS2)) |
388 | continue; |
389 | |
390 | AddNewShape(aS1, aNewShape, myGenMap); |
391 | |
392 | const TopTools_ListOfShape &aFaces = theEFMap.FindFromKey(aS2); |
393 | TopTools_ListIteratorOfListOfShape aFIter(aFaces); |
394 | |
395 | for (; aFIter.More(); aFIter.Next()) { |
396 | const TopoDS_Shape &anAncFace = aFIter.Value(); |
397 | |
398 | AddNewShape(anAncFace, aNewShape, myGenMap); |
399 | } |
400 | } else { |
401 | if (!theEFMap.Contains(aS1) || !theEFMap.Contains(aS2)) |
402 | continue; |
403 | |
404 | AddNewShape(aS1, aNewShape, myGenMap); |
405 | AddNewShape(aS2, aNewShape, myGenMap); |
406 | |
407 | const TopTools_ListOfShape &aFaces1 = theEFMap.FindFromKey(aS1); |
408 | const TopTools_ListOfShape &aFaces2 = theEFMap.FindFromKey(aS1); |
409 | TopTools_ListIteratorOfListOfShape aFIter(aFaces1); |
410 | |
411 | for (; aFIter.More(); aFIter.Next()) { |
412 | const TopoDS_Shape &anAncFace = aFIter.Value(); |
413 | |
414 | AddNewShape(anAncFace, aNewShape, myGenMap); |
415 | } |
416 | |
417 | for (aFIter.Initialize(aFaces2); aFIter.More(); aFIter.Next()) { |
418 | const TopoDS_Shape &anAncFace = aFIter.Value(); |
419 | |
420 | AddNewShape(anAncFace, aNewShape, myGenMap); |
421 | } |
422 | } |
423 | } |
424 | } |
425 | |
426 | Standard_Integer i = 0, j = 0; |
427 | |
428 | for(j = 1; j <= aDS.NumberOfSuccessors(anIndex); j++) { |
429 | Standard_Integer avindex = aDS.GetSuccessor(anIndex, j); |
430 | |
431 | BOPTools_CArray1OfVVInterference& VVs = pIntrPool->VVInterferences(); |
432 | Standard_Integer aNb = VVs.Extent(); |
433 | |
434 | for (i = 1; i <= aNb; i++) { |
435 | BOPTools_VVInterference& VV=VVs(i); |
436 | Standard_Integer anIndex1 = VV.Index1(); |
437 | Standard_Integer anIndex2 = VV.Index2(); |
438 | |
439 | if((avindex == anIndex1) || (avindex == anIndex2)) { |
440 | Standard_Integer aNewShapeIndex = VV.NewShape(); |
441 | TopoDS_Shape aNewShape = aDS.Shape(aNewShapeIndex); |
442 | |
443 | if(!theVEMapRes.Contains(aNewShape)) |
444 | continue; |
445 | |
446 | if(theVEMapRes.FindFromKey(aNewShape).Extent() >= 2) |
447 | continue; |
448 | |
449 | for(Standard_Integer vit = 0; vit < 2; vit++) { |
450 | TopoDS_Shape aShape = (vit == 0) ? aDS.Shape(anIndex1) : aDS.Shape(anIndex2); |
451 | TopTools_ListOfShape thelist1; |
452 | if(!aMapOfOldNewVertex.Contains(aShape)) |
453 | aMapOfOldNewVertex.Add(aShape, thelist1); |
454 | aMapOfOldNewVertex.ChangeFromKey(aShape).Append(aNewShape); |
455 | } |
456 | break; |
457 | } |
458 | } |
459 | |
460 | for(Standard_Integer aninterit = 0; aninterit < 2; aninterit++) { |
461 | |
462 | if(aninterit == 0) |
463 | aNb = pIntrPool->VEInterferences().Extent(); |
464 | else |
465 | aNb = pIntrPool->VSInterferences().Extent(); |
466 | |
467 | for (i = 1; i <= aNb; i++) { |
468 | BOPTools_ShapeShapeInterference* anInterference = NULL; |
469 | |
470 | if(aninterit == 0) |
471 | anInterference = (BOPTools_ShapeShapeInterference*)(&pIntrPool->VEInterferences().Value(i)); |
472 | else |
473 | anInterference = (BOPTools_ShapeShapeInterference*)(&pIntrPool->VSInterferences().Value(i)); |
474 | Standard_Integer anIndex1 = anInterference->Index1(); |
475 | Standard_Integer anIndex2 = anInterference->Index2(); |
476 | |
477 | if((avindex == anIndex1) || (avindex == anIndex2)) { |
478 | Standard_Integer aNewShapeIndex = anInterference->NewShape(); |
479 | TopoDS_Shape aNewShape = aDS.Shape(aNewShapeIndex); |
480 | |
481 | if(!theVEMapRes.Contains(aNewShape)) |
482 | continue; |
483 | |
484 | if(theVEMapRes.FindFromKey(aNewShape).Extent() >= 2) |
485 | continue; |
486 | TopoDS_Shape aShape1 = aDS.Shape(avindex); |
487 | TopoDS_Shape aShape2 = (avindex == anIndex1) ? aDS.Shape(anIndex2) : aDS.Shape(anIndex1); |
488 | |
489 | if(aninterit == 0) { |
490 | TopTools_ListOfShape thelist2; |
491 | if(!aMapOfOldNewVertex.Contains(aShape1)) |
492 | aMapOfOldNewVertex.Add(aShape1, thelist2); |
493 | aMapOfOldNewVertex.ChangeFromKey(aShape1).Append(aNewShape); |
494 | } else { |
495 | Standard_Integer aRank = 1; |
496 | Standard_Integer aVtxIndex = aDS.ShapeIndex(aShape1, aRank); |
497 | |
498 | if (aVtxIndex == 0) { |
499 | aRank = 2; |
500 | aVtxIndex = aDS.ShapeIndex(aShape1, aRank); |
501 | } |
502 | |
503 | if (aVtxIndex != 0) { |
504 | Standard_Integer aNbEdges = aDS.NumberOfAncestors(aVtxIndex); |
505 | Standard_Integer anEdgeInd; |
506 | TopTools_MapOfShape anAddedFaces; |
507 | |
508 | for (anEdgeInd = 1; anEdgeInd <= aNbEdges; anEdgeInd++) { |
509 | Standard_Integer anEdgeId = aDS.GetAncestor(aVtxIndex, anEdgeInd); |
510 | const TopoDS_Shape &anEdge = aDS.GetShape(anEdgeId); |
511 | |
512 | if (IsEdgeToAdd(anEdge, theResultMap, theVEMapRes, theDSFiller)) |
513 | AddNewShape(anEdge, aNewShape, myGenMap); |
514 | } |
515 | } |
516 | } |
517 | |
518 | // Modified by skv - Wed Nov 5 17:11:41 2003 OCC3644 Begin |
519 | // AddNewShape(aShape2, aNewShape, myGenMap); |
520 | if (IsEdgeToAdd(aShape2, theResultMap, theVEMapRes, theDSFiller)) |
521 | AddNewShape(aShape2, aNewShape, myGenMap); |
522 | // Modified by skv - Wed Nov 5 17:11:49 2003 OCC3644 End |
523 | } |
524 | } |
525 | } |
526 | } |
527 | |
528 | if(!aMapOfOldNewVertex.IsEmpty()) { |
529 | Standard_Integer vit = 0; |
530 | |
531 | for(vit = 1; vit <= aMapOfOldNewVertex.Extent(); vit++) { |
532 | const TopoDS_Shape& aV = aMapOfOldNewVertex.FindKey(vit); |
533 | Standard_Integer aRank = 1; |
534 | Standard_Integer aVtxIndex = aDS.ShapeIndex(aV, aRank); |
535 | |
536 | if (aVtxIndex == 0) { |
537 | aRank = 2; |
538 | aVtxIndex = aDS.ShapeIndex(aV, aRank); |
539 | } |
540 | |
541 | if (aVtxIndex == 0) |
542 | continue; |
543 | |
544 | Standard_Integer aNbEdges = aDS.NumberOfAncestors(aVtxIndex); |
545 | Standard_Integer anEdgeInd; |
546 | TopTools_MapOfShape anAddedFaces; |
547 | const TopTools_ListOfShape& aNewVList = aMapOfOldNewVertex.FindFromIndex(vit); |
548 | |
549 | if(aNewVList.IsEmpty()) |
550 | continue; |
551 | |
552 | TopoDS_Shape aNewShape = aNewVList.First(); |
553 | |
554 | for (anEdgeInd = 1; anEdgeInd <= aNbEdges; anEdgeInd++) { |
555 | Standard_Integer anEdgeId = aDS.GetAncestor(aVtxIndex, anEdgeInd); |
556 | const TopoDS_Shape &anEdge = aDS.GetShape(anEdgeId); |
557 | const TopTools_ListOfShape &aFaces = theEFMap.FindFromKey(anEdge); |
558 | |
559 | TopTools_ListIteratorOfListOfShape aFaceIter(aFaces); |
560 | |
561 | for (; aFaceIter.More(); aFaceIter.Next()) { |
562 | const TopoDS_Shape &aFace = aFaceIter.Value(); |
563 | |
564 | if (!anAddedFaces.Add(aFace)) |
565 | continue; |
566 | |
567 | AddNewShape(aFace, aNewShape, myGenMap); |
568 | } |
569 | } |
570 | } |
571 | } |
572 | } |
573 | |
574 | // -------------------------------------------------------------------------------- |
575 | // static function: AddNewShape |
576 | // purpose: |
577 | // -------------------------------------------------------------------------------- |
578 | Standard_Boolean AddNewShape(const TopoDS_Shape& theKey, |
579 | const TopoDS_Shape& theItem, |
580 | TopTools_DataMapOfShapeListOfShape& theMap) { |
581 | |
582 | |
583 | if(!theMap.IsBound(theKey)) { |
584 | TopTools_ListOfShape aList; |
585 | aList.Append(theItem); |
586 | theMap.Bind(theKey, aList); |
587 | return Standard_True; |
588 | } |
589 | |
590 | Standard_Boolean found = Standard_False; |
591 | TopTools_ListOfShape& aList = theMap.ChangeFind(theKey); |
592 | TopTools_ListIteratorOfListOfShape aVIt(aList); |
593 | |
594 | for(; aVIt.More(); aVIt.Next()) { |
595 | if(theItem.IsSame(aVIt.Value())) { |
596 | found = Standard_True; |
597 | break; |
598 | } |
599 | } |
600 | |
601 | if(!found) { |
602 | aList.Append(theItem); |
603 | } |
604 | return !found; |
605 | } |