Adding of testing cases from subgroups 937 940 and 941 of CHL group
[occt.git] / src / BOP / BOP_ShellSolidHistoryCollector.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_ShellSolidHistoryCollector.ixx>
19
20#include <TopAbs.hxx>
21#include <TopExp_Explorer.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 <BOP_BuilderTools.hxx>
37#include <TopTools_IndexedMapOfShape.hxx>
38#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
39#include <TopExp.hxx>
40#include <TColStd_ListIteratorOfListOfInteger.hxx>
41#include <TopTools_ListIteratorOfListOfShape.hxx>
42
43// ====================================================================================================
44// function: Constructor
45// purpose:
46// ====================================================================================================
47BOP_ShellSolidHistoryCollector::BOP_ShellSolidHistoryCollector(const TopoDS_Shape& theShape1,
48 const TopoDS_Shape& theShape2,
49 const BOP_Operation theOperation) :
50BOP_HistoryCollector(theShape1, theShape2, theOperation)
51{
52}
53
54// ====================================================================================================
55// function: AddNewFace
56// purpose:
57// ====================================================================================================
58void BOP_ShellSolidHistoryCollector::AddNewFace(const TopoDS_Shape& theOldShape,
59 const TopoDS_Shape& theNewShape,
60 const BOPTools_PDSFiller& theDSFiller)
61{
62 Standard_Boolean bAddAsGenerated = Standard_True;
63
64 if(theOldShape.ShapeType() != theNewShape.ShapeType())
65 return;
66
67 const BooleanOperations_IndexedDataMapOfShapeInteger& aMap = theDSFiller->DS().ShapeIndexMap(1);
68 Standard_Boolean bIsObject = (myS1.ShapeType() == TopAbs_SHELL) ? aMap.Contains(theOldShape) : !aMap.Contains(theOldShape);
69
70 if(bIsObject) {
71 bAddAsGenerated = Standard_False;
72 }
73
74 TopTools_DataMapOfShapeListOfShape& aHistoryMap = (bAddAsGenerated) ? myGenMap : myModifMap;
75
76 if(aHistoryMap.IsBound(theOldShape)) {
77 aHistoryMap.ChangeFind(theOldShape).Append(theNewShape);
78 }
79 else {
80 TopTools_ListOfShape aShapeList;
81 aShapeList.Append(theNewShape);
82 aHistoryMap.Bind(theOldShape, aShapeList);
83 }
84}
85
86// ====================================================================================================
87// function: SetResult
88// purpose:
89// ====================================================================================================
90void BOP_ShellSolidHistoryCollector::SetResult(const TopoDS_Shape& theResult,
91 const BOPTools_PDSFiller& theDSFiller)
92{
93 myResult = theResult;
94 FillSection(theDSFiller);
95 FillEdgeHistory(theDSFiller);
96
97 myHasDeleted = Standard_False;
98 Standard_Integer i = 0;
99
100 TopTools_IndexedMapOfShape aFreeBoundaryMap;
101 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
102
103 if(myS1.ShapeType() == TopAbs_SHELL) {
104 TopExp::MapShapesAndAncestors(myS1, TopAbs_EDGE, TopAbs_FACE, aEFMap);
105 }
106 else {
107 TopExp::MapShapesAndAncestors(myS2, TopAbs_EDGE, TopAbs_FACE, aEFMap);
108 }
109
110 for(i = 1; i <= aEFMap.Extent(); i++) {
111 if(aEFMap.FindFromIndex(i).Extent() < 2)
112 aFreeBoundaryMap.Add(aEFMap.FindKey(i));
113 }
114 aEFMap.Clear();
115
116 for(i = (Standard_Integer)TopAbs_FACE; !myHasDeleted && (i < (Standard_Integer)TopAbs_EDGE); i++) {
117 if(i == (Standard_Integer)TopAbs_WIRE)
118 continue;
119
120 TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum) i;
121 TopTools_IndexedMapOfShape aMap;
122 TopExp::MapShapes(myResult, aType, aMap);
123
124 TopExp_Explorer anExpObj(myS1, aType);
125
126 for(; anExpObj.More(); anExpObj.Next()) {
127 const TopoDS_Shape& aS = anExpObj.Current();
128
129 if((i == (Standard_Integer)TopAbs_EDGE) && !aFreeBoundaryMap.Contains(aS))
130 continue;
131
132 if(!aMap.Contains(aS)) {
133
134 if((!myModifMap.IsBound(aS) || myModifMap(aS).IsEmpty()) &&
135 (!myGenMap.IsBound(aS) || myGenMap(aS).IsEmpty())) {
136 myHasDeleted = Standard_True;
137 break;
138 }
139 }
140 }
141 TopExp_Explorer anExpTool(myS2, aType);
142
143 for(; anExpTool.More(); anExpTool.Next()) {
144 const TopoDS_Shape& aS = anExpTool.Current();
145
146 if(!aMap.Contains(aS)) {
147 if((!myModifMap.IsBound(aS) || myModifMap(aS).IsEmpty()) &&
148 (!myGenMap.IsBound(aS) || myGenMap(aS).IsEmpty())) {
149 myHasDeleted = Standard_True;
150 break;
151 }
152 }
153 }
154 }
155}
156
157// ====================================================================================================
158// function: FillSection
159// purpose:
160// ====================================================================================================
161void BOP_ShellSolidHistoryCollector::FillSection(const BOPTools_PDSFiller& theDSFiller)
162{
163 BOPTools_InterferencePool* pIntrPool = (BOPTools_InterferencePool*)&theDSFiller->InterfPool();
164 BOPTools_CArray1OfSSInterference& aFFs = pIntrPool->SSInterferences();
165 Standard_Integer i = 0;
166 TopTools_IndexedDataMapOfShapeListOfShape aResultMap;
167
168 if(!myResult.IsNull()) {
169 TopExp::MapShapesAndAncestors(myResult, TopAbs_EDGE, TopAbs_FACE, aResultMap);
170 }
171
172 for(i = 1; i <= aFFs.Extent(); i++) {
173 BOPTools_SSInterference& aFF = aFFs(i);
174 Standard_Integer nF1 = aFF.Index1();
175 Standard_Integer nF2 = aFF.Index2();
176
177 if(aFF.IsTangentFaces())
178 continue;
179 TopoDS_Shape aF1 = theDSFiller->DS().Shape(nF1);
180 TopoDS_Shape aF2 = theDSFiller->DS().Shape(nF2);
181
182
183 BOPTools_SequenceOfCurves& aSeqOfCurves = aFF.Curves();
184 Standard_Integer j = 0;
185
186 for(j = 1; j <= aSeqOfCurves.Length(); j++) {
187 const BOPTools_Curve& aCurve = aSeqOfCurves.Value(j);
188
189 const BOPTools_ListOfPaveBlock& aPBList = aCurve.NewPaveBlocks();
190 BOPTools_ListIteratorOfListOfPaveBlock anIt(aPBList);
191
192 for (; anIt.More();anIt.Next()) {
193 const BOPTools_PaveBlock& aPB = anIt.Value();
194 Standard_Integer anindex = aPB.Edge();
195 const TopoDS_Shape& aS = theDSFiller->DS().GetShape(anindex);
196
197 if(aResultMap.Contains(aS)) {
198 TopTools_ListOfShape thelist;
199 if(!myGenMap.IsBound(aF1))
200 myGenMap.Bind(aF1, thelist);
201 myGenMap.ChangeFind(aF1).Append(aS);
202
203 if(!myGenMap.IsBound(aF2))
204 myGenMap.Bind(aF2, thelist);
205 myGenMap.ChangeFind(aF2).Append(aS);
206 }
207 }
208 }
209
210 // Old Section Edges
211 const BOPTools_ListOfPaveBlock& aSectList = aFF.PaveBlocks();
212 BOPTools_ListIteratorOfListOfPaveBlock anIt(aSectList);
213
214 for (; anIt.More();anIt.Next()) {
215 const BOPTools_PaveBlock& aPB=anIt.Value();
216 Standard_Integer nSect = aPB.Edge();
217 const TopoDS_Shape& aS = theDSFiller->DS().GetShape(nSect);
218
219 if(aResultMap.Contains(aS)) {
220 if(aResultMap.FindFromKey(aS).Extent() >= 2)
221 continue;
222
223 Standard_Boolean add1 = Standard_True;
224 TopTools_ListOfShape thelist1;
225 if(!myGenMap.IsBound(aF1))
226 myGenMap.Bind(aF1, thelist1);
227 else {
228 TopTools_ListOfShape& aList = myGenMap.ChangeFind(aF1);
229 TopTools_ListIteratorOfListOfShape anItF1(aList);
230
231 for(; anItF1.More(); anItF1.Next()) {
232 if(aS.IsSame(anItF1.Value())) {
233 add1 = Standard_False;
234 break;
235 }
236 }
237 }
238
239 if(add1) {
240 myGenMap.ChangeFind(aF1).Append(aS);
241 }
242 Standard_Boolean add2 = Standard_True;
243 TopTools_ListOfShape thelist2;
244 if(!myGenMap.IsBound(aF2))
245 myGenMap.Bind(aF2, thelist2);
246 else {
247 TopTools_ListOfShape& aList = myGenMap.ChangeFind(aF2);
248 TopTools_ListIteratorOfListOfShape anItF2(aList);
249
250 for(; anItF2.More(); anItF2.Next()) {
251 if(aS.IsSame(anItF2.Value())) {
252 add2 = Standard_False;
253 break;
254 }
255 }
256 }
257
258 if(add2) {
259 myGenMap.ChangeFind(aF2).Append(aS);
260 }
261 }
262 }
263 }
264 aResultMap.Clear();
265 TopTools_IndexedMapOfShape aResultMapV;
266
267 if(!myResult.IsNull()) {
268 TopExp::MapShapes(myResult, TopAbs_VERTEX, aResultMapV);
269 }
270
271 for(i = 1; i <= aFFs.Extent(); i++) {
272 BOPTools_SSInterference& aFF = aFFs(i);
273 Standard_Integer nF1 = aFF.Index1();
274 Standard_Integer nF2 = aFF.Index2();
275
276 if(aFF.IsTangentFaces())
277 continue;
278 TopoDS_Shape aF1 = theDSFiller->DS().Shape(nF1);
279 TopoDS_Shape aF2 = theDSFiller->DS().Shape(nF2);
280
281 TColStd_ListIteratorOfListOfInteger anIt(aFF.AloneVertices());
282
283 for(; anIt.More(); anIt.Next()) {
284 TopoDS_Shape aNewVertex = theDSFiller->DS().Shape(anIt.Value());
285
286 if(aResultMapV.Contains(aNewVertex)) {
287 TopTools_ListOfShape thelist3;
288 if(!myGenMap.IsBound(aF1))
289 myGenMap.Bind(aF1, thelist3);
290 myGenMap.ChangeFind(aF1).Append(aNewVertex);
291
292 if(!myGenMap.IsBound(aF2))
293 myGenMap.Bind(aF2, thelist3);
294 myGenMap.ChangeFind(aF2).Append(aNewVertex);
295 }
296 }
297 }
298}
299
300// ====================================================================================================
301// function: FillEdgeHistory
302// purpose:
303// ====================================================================================================
304void BOP_ShellSolidHistoryCollector::FillEdgeHistory(const BOPTools_PDSFiller& theDSFiller)
305{
306 const BooleanOperations_ShapesDataStructure& aDS = theDSFiller->DS();
307 const BOPTools_PaveFiller& aPaveFiller = theDSFiller->PaveFiller();
308 const BOPTools_SplitShapesPool& aSplitShapesPool = aPaveFiller.SplitShapesPool();
309 TopTools_IndexedMapOfShape aResultMap, aFreeBoundaryMap;
310
311 if(!myResult.IsNull()) {
312 TopExp::MapShapes(myResult, TopAbs_EDGE, aResultMap);
313
314 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
315
316 if(myS1.ShapeType() == TopAbs_SHELL) {
317 TopExp::MapShapesAndAncestors(myS1, TopAbs_EDGE, TopAbs_FACE, aEFMap);
318 }
319 else {
320 TopExp::MapShapesAndAncestors(myS2, TopAbs_EDGE, TopAbs_FACE, aEFMap);
321 }
322 Standard_Integer i = 0;
323
324 for(i = 1; i <= aEFMap.Extent(); i++) {
325 if(aEFMap.FindFromIndex(i).Extent() < 2)
326 aFreeBoundaryMap.Add(aEFMap.FindKey(i));
327 }
328 }
329
330 Standard_Integer iRank = 1;
331
332 for(; iRank <= 2; iRank++) {
333 BooleanOperations_StateOfShape aStateCmp, aState;
334 aStateCmp = BOP_BuilderTools::StateToCompare(iRank, myOp);
335 Standard_Integer i = 0;
336 Standard_Integer nb = aDS.NumberOfShapesOfTheObject();
337 nb = (iRank == 1) ? nb : (nb + aDS.NumberOfShapesOfTheTool());
338 Standard_Integer startindex = (iRank == 1) ? 1 : (aDS.NumberOfShapesOfTheObject() + 1);
339
340 for(i = startindex; i <= nb; i++) {
341 if(aDS.GetShapeType(i) != TopAbs_EDGE)
342 continue;
343 const BOPTools_ListOfPaveBlock& aLPB = aSplitShapesPool(aDS.RefEdge(i));
344 const TopoDS_Shape& anOldShape = aDS.Shape(i);
345
346 if(!aFreeBoundaryMap.Contains(anOldShape)) {
347 continue;
348 }
349
350 if(!aLPB.IsEmpty()) {
351 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aLPB);
352
353 for(; aPBIt.More(); aPBIt.Next()) {
354 const BOPTools_PaveBlock& aPB = aPBIt.Value();
355 Standard_Integer nSp = aPB.Edge();
356
357 if(nSp == i)
358 continue;
359 aState=aDS.GetState(nSp);
360
361 if (aState == aStateCmp) {
362 const TopoDS_Shape& aNewShape = aDS.Shape(nSp);
363
364 if(aResultMap.Contains(aNewShape)) {
365 TopTools_DataMapOfShapeListOfShape& aHistoryMap = myModifMap;
366
367 if(aHistoryMap.IsBound(anOldShape)) {
368 aHistoryMap.ChangeFind(anOldShape).Append(aNewShape);
369 }
370 else {
371 TopTools_ListOfShape aShapeList;
372 aShapeList.Append(aNewShape);
373 aHistoryMap.Bind(anOldShape, aShapeList);
374 }
375 }
376 }
377 }
378 }
379 //end if(!aLPB.IsEmpty...
380
381 const BOPTools_CommonBlockPool& aCBPool = aPaveFiller.CommonBlockPool();
382 const BOPTools_ListOfCommonBlock& aLCB = aCBPool(aDS.RefEdge(i));
383 BOPTools_ListIteratorOfListOfCommonBlock anItCB(aLCB);
384
385 for (; anItCB.More(); anItCB.Next()) {
386 const BOPTools_CommonBlock& aCB = anItCB.Value();
387 const BOPTools_PaveBlock& aPB = aCB.PaveBlock1();
388 Standard_Integer nSp = aPB.Edge();
389 TopoDS_Shape aNewShape = aDS.Shape(nSp);
390
391 if(aResultMap.Contains(aNewShape)) {
392 TopTools_DataMapOfShapeListOfShape& aHistoryMap = myModifMap;
393
394 if(aHistoryMap.IsBound(anOldShape)) {
395 aHistoryMap.ChangeFind(anOldShape).Append(aNewShape);
396 }
397 else {
398 TopTools_ListOfShape aShapeList;
399 aShapeList.Append(aNewShape);
400 aHistoryMap.Bind(anOldShape, aShapeList);
401 }
402 }
403 }
404 // end for (; anItCB.More...
405 }
406 }
407}
408