Adding of testing cases from subgroups 937 940 and 941 of CHL group
[occt.git] / src / BOP / BOP_WireSolidHistoryCollector.cxx
CommitLineData
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_WireSolidHistoryCollector.ixx>
19
20#include <TopExp_Explorer.hxx>
21#include <TopAbs.hxx>
22#include <BooleanOperations_ShapesDataStructure.hxx>
23#include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
24#include <BOPTools_SSInterference.hxx>
25#include <BOPTools_InterferencePool.hxx>
26#include <BOPTools_CArray1OfSSInterference.hxx>
27#include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
28#include <BOPTools_Curve.hxx>
29#include <BOPTools_PaveBlock.hxx>
30#include <BOPTools_DSFiller.hxx>
31#include <BOPTools_PaveFiller.hxx>
32#include <BOPTools_CommonBlock.hxx>
33#include <BOPTools_ListOfCommonBlock.hxx>
34#include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
35#include <BOPTools_ListIteratorOfListOfPave.hxx>
36#include <BOPTools_PShapeShapeInterference.hxx>
37#include <BOPTools_VVInterference.hxx>
38
39#include <BOP_BuilderTools.hxx>
40#include <TopTools_IndexedMapOfShape.hxx>
41#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
42#include <TopTools_ListIteratorOfListOfShape.hxx>
43#include <TopExp.hxx>
44
45static Standard_Boolean AddNewShape(const TopoDS_Shape& theKey,
46 const TopoDS_Shape& theItem,
47 TopTools_DataMapOfShapeListOfShape& theMap);
48
49static void GetAncestorFaces(const Standard_Integer theShapeIndex,
50 const BooleanOperations_ShapesDataStructure& theDS,
51 TopTools_IndexedMapOfShape& theFaces);
52
53static Standard_Integer GetShapeWire(const BooleanOperations_ShapesDataStructure& theDS,
54 const TopoDS_Shape& S1,
55 const TopoDS_Shape& S2,
56 TopoDS_Shape& WS);
57
58// ====================================================================================================
59// function: Constructor
60// purpose:
61// ====================================================================================================
62BOP_WireSolidHistoryCollector::BOP_WireSolidHistoryCollector(const TopoDS_Shape& theShape1,
63 const TopoDS_Shape& theShape2,
64 const BOP_Operation theOperation) :
65BOP_HistoryCollector(theShape1, theShape2, theOperation)
66{
67}
68
69// ====================================================================================================
70// function: SetResult
71// purpose:
72// ====================================================================================================
73void BOP_WireSolidHistoryCollector::SetResult(const TopoDS_Shape& theResult,
74 const BOPTools_PDSFiller& theDSFiller)
75{
76 myResult = theResult;
77
78 FillSection(theDSFiller);
79 FillEdgeHistory(theDSFiller);
80
81 myHasDeleted = Standard_False;
82
83 TopExp_Explorer anExp(myS1, TopAbs_FACE);
84
85 if(!anExp.More()) {
86 anExp.Init(myS2, TopAbs_FACE);
87
88 if(anExp.More()) {
89 myHasDeleted = Standard_True;
90 return;
91 }
92 }
93 else {
94 myHasDeleted = Standard_True;
95 return;
96 }
97
98 Standard_Integer i = 0;
99
100 for(i = (Standard_Integer)TopAbs_EDGE; !myHasDeleted && (i < (Standard_Integer)TopAbs_VERTEX); i++) {
101 TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum) i;
102 TopTools_IndexedMapOfShape aMap;
103 TopExp::MapShapes(myResult, aType, aMap);
104
105 TopExp_Explorer anExpObj(myS1, aType);
106
107 for(; anExpObj.More(); anExpObj.Next()) {
108 const TopoDS_Shape& aS = anExpObj.Current();
109
110 if(!aMap.Contains(aS)) {
111
112 if((!myModifMap.IsBound(aS) || myModifMap(aS).IsEmpty()) &&
113 (!myGenMap.IsBound(aS) || myGenMap(aS).IsEmpty())) {
114 myHasDeleted = Standard_True;
115 break;
116 }
117 }
118 }
119 TopExp_Explorer anExpTool(myS2, aType);
120
121 for(; anExpTool.More(); anExpTool.Next()) {
122 const TopoDS_Shape& aS = anExpTool.Current();
123
124 if(!aMap.Contains(aS)) {
125 if((!myModifMap.IsBound(aS) || myModifMap(aS).IsEmpty()) &&
126 (!myGenMap.IsBound(aS) || myGenMap(aS).IsEmpty())) {
127 myHasDeleted = Standard_True;
128 break;
129 }
130 }
131 }
132 }
133}
134
135// ====================================================================================================
136// function: FillSection
137// purpose:
138// ====================================================================================================
139void BOP_WireSolidHistoryCollector::FillSection(const BOPTools_PDSFiller& theDSFiller)
140{
141 // for edges
142 BOPTools_InterferencePool* pIntrPool = (BOPTools_InterferencePool*)&theDSFiller->InterfPool();
143 const BOPTools_PavePool& aPavePool = theDSFiller->PaveFiller().PavePool();
144 const BooleanOperations_ShapesDataStructure& aDS = theDSFiller->DS();
145 Standard_Integer nb = aDS.NumberOfShapesOfTheObject() + aDS.NumberOfShapesOfTheTool();
146 Standard_Integer i = 0;
147 TopTools_IndexedMapOfShape aResultMap;
148
149 if(!myResult.IsNull()) {
150 TopExp::MapShapes(myResult, TopAbs_VERTEX, aResultMap);
151 }
152
153 for(i = 1; i <= nb; i++) {
154 if(aDS.GetShapeType(i) != TopAbs_EDGE)
155 continue;
156 const BOPTools_PaveSet& aPaveSet = aPavePool.Value(aDS.RefEdge(i));
157 const BOPTools_ListOfPave& aListOfPave = aPaveSet.Set();
158 BOPTools_ListIteratorOfListOfPave anIt(aListOfPave);
159 TopTools_IndexedMapOfShape aMapOfVertex;
160
161 for(; anIt.More(); anIt.Next()) {
162 const BOPTools_Pave& aPave = anIt.Value();
163
164 if((aPave.Type() == BooleanOperations_EdgeSurface) ||
165 (aPave.Type() == BooleanOperations_EdgeEdge) ||
166 (aPave.Type() == BooleanOperations_VertexEdge)) {
167 BOPTools_PShapeShapeInterference anInter = pIntrPool->GetInterference(aPave.Interference(), aPave.Type());
168
169 if(anInter != NULL) {
170 const TopoDS_Shape& aS1 = aDS.Shape(anInter->Index1());
171 const TopoDS_Shape& aS2 = aDS.Shape(anInter->Index2());
172 const TopoDS_Shape& aNewShape = aDS.Shape(anInter->NewShape());
173
174 if(aNewShape.ShapeType() != TopAbs_VERTEX)
175 continue;
176
177 Standard_Boolean addfirst = Standard_False;
178 Standard_Boolean addsecond = Standard_False;
179
180 if(aResultMap.Contains(aNewShape)) {
181 if(i == anInter->Index1()) {
182 addfirst = Standard_True;
183
184 if(aS1.IsSame(aNewShape)) {
185 aMapOfVertex.Add(aNewShape);
186 continue;
187 }
188
189 if(aPave.Type() != BooleanOperations_EdgeEdge) {
190 addsecond = Standard_True;
191
192 if(aS2.IsSame(aNewShape)) {
193 aMapOfVertex.Add(aNewShape);
194 continue;
195 }
196 }
197 }
198 else {
199 addsecond = Standard_True;
200
201 if(aS2.IsSame(aNewShape)) {
202 aMapOfVertex.Add(aNewShape);
203 continue;
204 }
205
206 if(aPave.Type() != BooleanOperations_EdgeEdge) {
207 addfirst = Standard_True;
208
209 if(aS1.IsSame(aNewShape)) {
210 aMapOfVertex.Add(aNewShape);
211 continue;
212 }
213 }
214 }
215 TopTools_ListOfShape thelist;
216 if(addfirst) {
217 // modified by NIZHNY-3643 Thu Nov 13 17:33:38 2003 .b
218 if( aPave.Type() == BooleanOperations_EdgeEdge) {
219 TopTools_IndexedMapOfShape aSharedFaces;
220 aSharedFaces.Clear();
221 GetAncestorFaces(i,aDS,aSharedFaces);
222 Standard_Integer anbFaces = aSharedFaces.Extent();
223 if( anbFaces != 0 ) {
224 Standard_Integer iFace = 0;
225 for( iFace = 1; iFace <= anbFaces; iFace++ ) {
226 if(!myGenMap.IsBound(aSharedFaces.FindKey(iFace)))
227 myGenMap.Bind(aSharedFaces.FindKey(iFace), thelist);
228 myGenMap.ChangeFind(aSharedFaces.FindKey(iFace)).Append(aNewShape);
229 }
230 }
231 else {
232 if(!myGenMap.IsBound(aS1))
233 myGenMap.Bind(aS1, thelist);
234 myGenMap.ChangeFind(aS1).Append(aNewShape);
235 }
236 }
237 else {
238 if(!myGenMap.IsBound(aS1))
239 myGenMap.Bind(aS1, thelist);
240 myGenMap.ChangeFind(aS1).Append(aNewShape);
241 }
242 // modified by NIZHNY-3643 Thu Nov 13 17:34:45 2003 .e
243 }
244
245 if(addsecond) {
246 // modified by NIZHNY-3643 Thu Nov 13 17:33:38 2003 .b
247 if( aPave.Type() == BooleanOperations_EdgeEdge) {
248 TopTools_IndexedMapOfShape aSharedFaces;
249 aSharedFaces.Clear();
250 GetAncestorFaces(i,aDS,aSharedFaces);
251 Standard_Integer anbFaces = aSharedFaces.Extent();
252 if( anbFaces != 0 ) {
253 Standard_Integer iFace = 0;
254 for( iFace = 1; iFace <= anbFaces; iFace++ ) {
255 if(!myGenMap.IsBound(aSharedFaces.FindKey(iFace)))
256 myGenMap.Bind(aSharedFaces.FindKey(iFace), thelist);
257 myGenMap.ChangeFind(aSharedFaces.FindKey(iFace)).Append(aNewShape);
258 }
259 }
260 else {
261 if(!myGenMap.IsBound(aS2))
262 myGenMap.Bind(aS2, thelist);
263 myGenMap.ChangeFind(aS2).Append(aNewShape);
264 }
265 }
266 else {
267 if(!myGenMap.IsBound(aS2))
268 myGenMap.Bind(aS2, thelist);
269 myGenMap.ChangeFind(aS2).Append(aNewShape);
270 }
271 // modified by NIZHNY-3643 Thu Nov 13 19:01:19 2003 .e
272 }
273 }
274 }
275 }
276 }
277 // end for(; anIt.More...
278
279 // fill history for edges which vertices are on other shape.begin
280 TopTools_IndexedDataMapOfShapeListOfShape aMapOfOldNewVertex, aVEMap;
281 TopExp::MapShapesAndAncestors(myResult, TopAbs_VERTEX, TopAbs_EDGE, aVEMap);
282 Standard_Integer j = 0, k = 0;
283 TopTools_ListOfShape thelist1;
284 for(j = 1; j <= aDS.NumberOfSuccessors(i); j++) {
285 Standard_Integer avindex = aDS.GetSuccessor(i, j);
286
287 BOPTools_CArray1OfVVInterference& VVs = pIntrPool->VVInterferences();
288 Standard_Integer aNb = VVs.Extent();
289
290 for (k = 1; k <= aNb; k++) {
291 BOPTools_VVInterference& VV=VVs(k);
292 Standard_Integer anIndex1 = VV.Index1();
293 Standard_Integer anIndex2 = VV.Index2();
294
295 if((avindex == anIndex1) || (avindex == anIndex2)) {
296 Standard_Integer aNewShapeIndex = VV.NewShape();
297 TopoDS_Shape aNewShape = aDS.Shape(aNewShapeIndex);
298
299 if(!aVEMap.Contains(aNewShape))
300 continue;
301
302 if(aVEMap.FindFromKey(aNewShape).Extent() >= 2)
303 continue;
304
305 for(Standard_Integer vit = 0; vit < 2; vit++) {
306 TopoDS_Shape aShape = (vit == 0) ? aDS.Shape(anIndex1) : aDS.Shape(anIndex2);
307
308 if(!aMapOfOldNewVertex.Contains(aShape))
309 aMapOfOldNewVertex.Add(aShape, thelist1);
310 aMapOfOldNewVertex.ChangeFromKey(aShape).Append(aNewShape);
311 }
312 break;
313 }
314 }
315
316 for(Standard_Integer aninterit = 0; aninterit < 2; aninterit++) {
317
318 if(aninterit == 0)
319 aNb = pIntrPool->VEInterferences().Extent();
320 else
321 aNb = pIntrPool->VSInterferences().Extent();
322
323 for (k = 1; k <= aNb; k++) {
324 BOPTools_ShapeShapeInterference* anInterference = NULL;
325
326 if(aninterit == 0)
327 anInterference = (BOPTools_ShapeShapeInterference*)(&pIntrPool->VEInterferences().Value(k));
328 else
329 anInterference = (BOPTools_ShapeShapeInterference*)(&pIntrPool->VSInterferences().Value(k));
330 Standard_Integer anIndex1 = anInterference->Index1();
331 Standard_Integer anIndex2 = anInterference->Index2();
332
333 if((avindex == anIndex1) || (avindex == anIndex2)) {
334 Standard_Integer aNewShapeIndex = anInterference->NewShape();
335 TopoDS_Shape aNewShape = aDS.Shape(aNewShapeIndex);
336
337 if(!aVEMap.Contains(aNewShape))
338 continue;
339
340 if(aVEMap.FindFromKey(aNewShape).Extent() >= 2)
341 continue;
342 TopoDS_Shape aShape1 = aDS.Shape(avindex);
343 TopoDS_Shape aShape2 = (avindex == anIndex1) ? aDS.Shape(anIndex2) : aDS.Shape(anIndex1);
344
345 if(!aMapOfOldNewVertex.Contains(aShape1))
346 aMapOfOldNewVertex.Add(aShape1, thelist1);
347 aMapOfOldNewVertex.ChangeFromKey(aShape1).Append(aNewShape);
348
349 AddNewShape(aShape2, aNewShape, myGenMap);
350 }
351 }
352 }
353 }
354
355 // modified by NIZHNY-3643 Fri Nov 14 09:59:47 2003 .b
356 TopoDS_Shape WShape;
357 Standard_Integer wRank = GetShapeWire(aDS,myS1,myS2,WShape);
358 // modified by NIZHNY-3643 Fri Nov 14 09:59:53 2003 .e
359
360 if(!aMapOfOldNewVertex.IsEmpty()) {
361 TopTools_IndexedDataMapOfShapeListOfShape aMapVE;
362
363 // modified by NIZHNY-3643 Fri Nov 14 10:01:32 2003 .b
364 Standard_Integer iSh = 0;
365 TopoDS_Shape aCShape;
366 for( iSh = 1; iSh <= 2; iSh ++ ) {
367
368 if( iSh == 1 ) {
369 TopExp::MapShapesAndAncestors(myS1, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
370 aCShape = myS1;
371 }
372 else {
373 aMapVE.Clear();
374 TopExp::MapShapesAndAncestors(myS2, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
375 aCShape = myS2;
376 }
377
378 Standard_Integer vit = 0;
379
380 for(vit = 1; vit <= aMapOfOldNewVertex.Extent(); vit++) {
381 const TopoDS_Shape& aV = aMapOfOldNewVertex.FindKey(vit);
382
383 if(!aMapVE.Contains(aV))
384 continue;
385 TopTools_ListIteratorOfListOfShape aEIt(aMapVE.FindFromKey(aV));
386 const TopTools_ListOfShape& aNewVList = aMapOfOldNewVertex.FindFromIndex(vit);
387
388 if(aNewVList.IsEmpty())
389 continue;
390 TopoDS_Shape aNewShape = aNewVList.First();
391
392 // for wire old
393 if( aCShape.IsSame(WShape) ) {
394 for(; aEIt.More(); aEIt.Next()) {
395 const TopoDS_Shape& aE = aEIt.Value();
396 AddNewShape(aE, aNewShape, myGenMap);
397 }
398 // avoid shared edges from solids here
399 Standard_Integer eRank = aDS.Rank(i);
400 if( eRank != wRank ) {
401 TopTools_IndexedMapOfShape aSharedFaces;
402 aSharedFaces.Clear();
403 GetAncestorFaces(i,aDS,aSharedFaces);
404 if( aSharedFaces.Extent() == 1 ) {
405 TopoDS_Shape aE = aDS.Shape(i);
406 AddNewShape(aE, aNewShape, myGenMap);
407 }
408 }
409 else {
410 TopoDS_Shape aE = aDS.Shape(i);
411 AddNewShape(aE, aNewShape, myGenMap);
412 }
413 }
414 else {
415 // for solid new
416 TopTools_IndexedMapOfShape aSharedFaces;
417 aSharedFaces.Clear();
418 Standard_Integer sRank = (wRank == 1) ? 2 : 1;
419 for(; aEIt.More(); aEIt.Next()) {
420 const TopoDS_Shape& aE = aEIt.Value();
421 Standard_Integer iE = aDS.ShapeIndex(aE,sRank);
422 if( iE != 0 )
423 GetAncestorFaces(iE,aDS,aSharedFaces);
424 }
425 TopoDS_Shape aE = aDS.Shape(i);
426 Standard_Integer iE = aDS.ShapeIndex(aE,sRank);
427 if( iE != 0 )
428 GetAncestorFaces(iE,aDS,aSharedFaces);
429 if( aSharedFaces.Extent() != 0 ) {
430 Standard_Integer anbFaces = aSharedFaces.Extent();
431 Standard_Integer iFace = 0;
432 for( iFace = 1; iFace <= anbFaces; iFace++ ) {
433 AddNewShape(aSharedFaces.FindKey(iFace), aNewShape, myGenMap);
434 }
435 }
436 }
437 }
438 }
439 // modified by NIZHNY-3643 Fri Nov 14 10:02:19 2003 .e
440 }
441 // fill history for edges which vertices are on other shape.end
442
443 if(!aMapOfVertex.IsEmpty()) {
444 if(!myResult.IsNull()) {
445 TopTools_IndexedDataMapOfShapeListOfShape aMapVE;
446 TopExp::MapShapesAndAncestors(myS1, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
447 TopExp::MapShapesAndAncestors(myS2, TopAbs_VERTEX, TopAbs_EDGE, aMapVE);
448 Standard_Integer vit = 0;
449
450 for(vit = 1; vit <= aMapOfVertex.Extent(); vit++) {
451 const TopoDS_Shape& aV = aMapOfVertex(vit);
452
453 if(!aMapVE.Contains(aV))
454 continue;
455 TopTools_ListIteratorOfListOfShape aEIt(aMapVE.FindFromKey(aV));
456
457 for(; aEIt.More(); aEIt.Next()) {
458 const TopoDS_Shape& aE = aEIt.Value();
459 AddNewShape(aE, aV, myGenMap);
460 }
461 TopoDS_Shape aE = aDS.Shape(i);
462 AddNewShape(aE, aV, myGenMap);
463 }
464 }
465 }
466 }
467}
468
469// ====================================================================================================
470// function: FillEdgeHistory
471// purpose: Fills modified map for edges,
472// fills generated map for edges (vertex type of intersection, edge type of intersection)
473// ====================================================================================================
474void BOP_WireSolidHistoryCollector::FillEdgeHistory(const BOPTools_PDSFiller& theDSFiller)
475{
476 const BooleanOperations_ShapesDataStructure& aDS = theDSFiller->DS();
477 const BOPTools_PaveFiller& aPaveFiller = theDSFiller->PaveFiller();
478 const BOPTools_SplitShapesPool& aSplitShapesPool = aPaveFiller.SplitShapesPool();
479 TopTools_IndexedMapOfShape aResultMap;
480
481 if(!myResult.IsNull()) {
482 TopExp::MapShapes(myResult, TopAbs_EDGE, aResultMap);
483 }
484
485 Standard_Integer iRank = 1;
486
487 for(; iRank <= 2; iRank++) {
488 BooleanOperations_StateOfShape aStateCmp, aState;
489 aStateCmp = BOP_BuilderTools::StateToCompare(iRank, myOp);
490 Standard_Integer i = 0;
491 Standard_Integer nb = aDS.NumberOfShapesOfTheObject();
492 nb = (iRank == 1) ? nb : (nb + aDS.NumberOfShapesOfTheTool());
493 Standard_Integer startindex = (iRank == 1) ? 1 : (aDS.NumberOfShapesOfTheObject() + 1);
494
495 for(i = startindex; i <= nb; i++) {
496 if(aDS.GetShapeType(i) != TopAbs_EDGE)
497 continue;
498 const BOPTools_ListOfPaveBlock& aLPB = aSplitShapesPool(aDS.RefEdge(i));
499 const TopoDS_Shape& anOldShape = aDS.Shape(i);
500
501 if(!aLPB.IsEmpty()) {
502 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aLPB);
503
504 for(; aPBIt.More(); aPBIt.Next()) {
505 const BOPTools_PaveBlock& aPB = aPBIt.Value();
506 Standard_Integer nSp = aPB.Edge();
507
508 if(nSp == i)
509 continue;
510 aState=aDS.GetState(nSp);
511
512 if ((aState == aStateCmp) || (myOp==BOP_COMMON && (aState == BooleanOperations_ON))) {
513 const TopoDS_Shape& aNewShape = aDS.Shape(nSp);
514
515 if(aResultMap.Contains(aNewShape)) {
516 Standard_Integer bIsGenerated = Standard_True;
517
518 if((myOp == BOP_CUT) || (myOp == BOP_FUSE)) {
519 bIsGenerated = (iRank == 2);
520 }
521 else {
522 if(myOp == BOP_CUT21) {
523 bIsGenerated = (iRank == 1);
524 }
525 else if(myOp == BOP_COMMON) {
526 bIsGenerated = Standard_False;
527 }
528 }
529 TopTools_DataMapOfShapeListOfShape& aHistoryMap = (bIsGenerated) ? myGenMap : myModifMap;
530
531 if(aHistoryMap.IsBound(anOldShape)) {
532 aHistoryMap.ChangeFind(anOldShape).Append(aNewShape);
533 }
534 else {
535 TopTools_ListOfShape aShapeList;
536 aShapeList.Append(aNewShape);
537 aHistoryMap.Bind(anOldShape, aShapeList);
538 }
539 }
540 }
541 }
542 }
543 //end if(!aLPB.IsEmpty...
544
545 const BOPTools_CommonBlockPool& aCBPool = aPaveFiller.CommonBlockPool();
546 const BOPTools_ListOfCommonBlock& aLCB = aCBPool(aDS.RefEdge(i));
547 BOPTools_ListIteratorOfListOfCommonBlock anItCB(aLCB);
548 Standard_Boolean bWireIsObject = (myS1.ShapeType() == TopAbs_WIRE);
549 Standard_Boolean bFillWithCommonPart = bWireIsObject ? (iRank == 1) : (iRank == 2);
550
551 for (; bFillWithCommonPart && anItCB.More(); anItCB.Next()) {
552 const BOPTools_CommonBlock& aCB = anItCB.Value();
553 const BOPTools_PaveBlock& aPB = aCB.PaveBlock1();
554 Standard_Integer nSp = aPB.Edge();
555 TopoDS_Shape aNewShape = aDS.Shape(nSp);
556
557 Standard_Boolean found = Standard_True;
558
559 if(!aResultMap.Contains(aNewShape)) {
560 nSp = aCB.PaveBlock2().Edge();
561 found = Standard_False;
562
563 if(nSp) {
564 aNewShape = aDS.Shape(nSp);
565 found = aResultMap.Contains(aNewShape);
566 }
567 }
568
569 if(found) {
570 TopTools_DataMapOfShapeListOfShape& aHistoryMap = myModifMap;
571
572 if(aHistoryMap.IsBound(anOldShape)) {
573 aHistoryMap.ChangeFind(anOldShape).Append(aNewShape);
574 }
575 else {
576 TopTools_ListOfShape aShapeList;
577 aShapeList.Append(aNewShape);
578 aHistoryMap.Bind(anOldShape, aShapeList);
579 }
580 }
581 }
582 }
583 // end for(i = startindex...
584 }
585}
586
587// --------------------------------------------------------------------------------
588// static function: AddNewShape
589// purpose:
590// --------------------------------------------------------------------------------
591Standard_Boolean AddNewShape(const TopoDS_Shape& theKey,
592 const TopoDS_Shape& theItem,
593 TopTools_DataMapOfShapeListOfShape& theMap) {
594
595
596 if(!theMap.IsBound(theKey)) {
597 TopTools_ListOfShape aList;
598 aList.Append(theItem);
599 theMap.Bind(theKey, aList);
600 return Standard_True;
601 }
602
603 Standard_Boolean found = Standard_False;
604 TopTools_ListOfShape& aList = theMap.ChangeFind(theKey);
605 TopTools_ListIteratorOfListOfShape aVIt(aList);
606
607 for(; aVIt.More(); aVIt.Next()) {
608 if(theItem.IsSame(aVIt.Value())) {
609 found = Standard_True;
610 break;
611 }
612 }
613
614 if(!found) {
615 aList.Append(theItem);
616 }
617 return !found;
618}
619
620void GetAncestorFaces(const Standard_Integer theShapeIndex,
621 const BooleanOperations_ShapesDataStructure& theDS,
622 TopTools_IndexedMapOfShape& theFaces)
623{
624 // find ancestors for the edge
625 Standard_Integer nbeA = theDS.NumberOfAncestors(theShapeIndex);
626 if( nbeA == 0 ) return;
627 Standard_Integer ieA = 0;
628 for( ieA = 1; ieA <= nbeA; ieA++ ) {
629 Standard_Integer indxA = theDS.GetAncestor(theShapeIndex,ieA);
630 TopAbs_ShapeEnum aShapeType = theDS.GetShapeType(indxA);
631 if( aShapeType == TopAbs_FACE ) {
632 theFaces.Add(theDS.Shape(indxA));
633 }
634 else if( aShapeType == TopAbs_WIRE ) {
635 GetAncestorFaces(indxA,theDS,theFaces);
636 }
637 else {
638 return;
639 }
640 }
641}
642
643Standard_Integer GetShapeWire(const BooleanOperations_ShapesDataStructure& theDS,
644 const TopoDS_Shape& S1,
645 const TopoDS_Shape& S2,
646 TopoDS_Shape& WS)
647{
648 Standard_Integer wRank = 0;
649 if( S1.ShapeType() == TopAbs_WIRE ) {
650 if( S1.IsSame(theDS.Object()) )
651 wRank = 1;
652 else
653 wRank = 2;
654 WS = S1;
655 }
656 else {
657 if( S2.IsSame(theDS.Object()) )
658 wRank = 1;
659 else
660 wRank = 2;
661 WS = S2;
662 }
663 return wRank;
664}