1 #include <BOP_ShellSolidHistoryCollector.ixx>
4 #include <TopExp_Explorer.hxx>
5 #include <BooleanOperations_ShapesDataStructure.hxx>
6 #include <BooleanOperations_IndexedDataMapOfShapeInteger.hxx>
7 #include <BOPTools_SSInterference.hxx>
8 #include <BOPTools_InterferencePool.hxx>
9 #include <BOPTools_CArray1OfSSInterference.hxx>
10 #include <BOPTools_ListIteratorOfListOfPaveBlock.hxx>
11 #include <BOPTools_Curve.hxx>
12 #include <BOPTools_PaveBlock.hxx>
13 #include <BOPTools_DSFiller.hxx>
14 #include <BOPTools_PaveFiller.hxx>
15 #include <BOPTools_CommonBlock.hxx>
16 #include <BOPTools_ListOfCommonBlock.hxx>
17 #include <BOPTools_ListIteratorOfListOfCommonBlock.hxx>
18 #include <BOPTools_ListIteratorOfListOfPave.hxx>
19 #include <BOP_BuilderTools.hxx>
20 #include <TopTools_IndexedMapOfShape.hxx>
21 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
23 #include <TColStd_ListIteratorOfListOfInteger.hxx>
24 #include <TopTools_ListIteratorOfListOfShape.hxx>
26 // ====================================================================================================
27 // function: Constructor
29 // ====================================================================================================
30 BOP_ShellSolidHistoryCollector::BOP_ShellSolidHistoryCollector(const TopoDS_Shape& theShape1,
31 const TopoDS_Shape& theShape2,
32 const BOP_Operation theOperation) :
33 BOP_HistoryCollector(theShape1, theShape2, theOperation)
37 // ====================================================================================================
38 // function: AddNewFace
40 // ====================================================================================================
41 void BOP_ShellSolidHistoryCollector::AddNewFace(const TopoDS_Shape& theOldShape,
42 const TopoDS_Shape& theNewShape,
43 const BOPTools_PDSFiller& theDSFiller)
45 Standard_Boolean bAddAsGenerated = Standard_True;
47 if(theOldShape.ShapeType() != theNewShape.ShapeType())
50 const BooleanOperations_IndexedDataMapOfShapeInteger& aMap = theDSFiller->DS().ShapeIndexMap(1);
51 Standard_Boolean bIsObject = (myS1.ShapeType() == TopAbs_SHELL) ? aMap.Contains(theOldShape) : !aMap.Contains(theOldShape);
54 bAddAsGenerated = Standard_False;
57 TopTools_DataMapOfShapeListOfShape& aHistoryMap = (bAddAsGenerated) ? myGenMap : myModifMap;
59 if(aHistoryMap.IsBound(theOldShape)) {
60 aHistoryMap.ChangeFind(theOldShape).Append(theNewShape);
63 TopTools_ListOfShape aShapeList;
64 aShapeList.Append(theNewShape);
65 aHistoryMap.Bind(theOldShape, aShapeList);
69 // ====================================================================================================
70 // function: SetResult
72 // ====================================================================================================
73 void BOP_ShellSolidHistoryCollector::SetResult(const TopoDS_Shape& theResult,
74 const BOPTools_PDSFiller& theDSFiller)
77 FillSection(theDSFiller);
78 FillEdgeHistory(theDSFiller);
80 myHasDeleted = Standard_False;
81 Standard_Integer i = 0;
83 TopTools_IndexedMapOfShape aFreeBoundaryMap;
84 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
86 if(myS1.ShapeType() == TopAbs_SHELL) {
87 TopExp::MapShapesAndAncestors(myS1, TopAbs_EDGE, TopAbs_FACE, aEFMap);
90 TopExp::MapShapesAndAncestors(myS2, TopAbs_EDGE, TopAbs_FACE, aEFMap);
93 for(i = 1; i <= aEFMap.Extent(); i++) {
94 if(aEFMap.FindFromIndex(i).Extent() < 2)
95 aFreeBoundaryMap.Add(aEFMap.FindKey(i));
99 for(i = (Standard_Integer)TopAbs_FACE; !myHasDeleted && (i < (Standard_Integer)TopAbs_EDGE); i++) {
100 if(i == (Standard_Integer)TopAbs_WIRE)
103 TopAbs_ShapeEnum aType = (TopAbs_ShapeEnum) i;
104 TopTools_IndexedMapOfShape aMap;
105 TopExp::MapShapes(myResult, aType, aMap);
107 TopExp_Explorer anExpObj(myS1, aType);
109 for(; anExpObj.More(); anExpObj.Next()) {
110 const TopoDS_Shape& aS = anExpObj.Current();
112 if((i == (Standard_Integer)TopAbs_EDGE) && !aFreeBoundaryMap.Contains(aS))
115 if(!aMap.Contains(aS)) {
117 if((!myModifMap.IsBound(aS) || myModifMap(aS).IsEmpty()) &&
118 (!myGenMap.IsBound(aS) || myGenMap(aS).IsEmpty())) {
119 myHasDeleted = Standard_True;
124 TopExp_Explorer anExpTool(myS2, aType);
126 for(; anExpTool.More(); anExpTool.Next()) {
127 const TopoDS_Shape& aS = anExpTool.Current();
129 if(!aMap.Contains(aS)) {
130 if((!myModifMap.IsBound(aS) || myModifMap(aS).IsEmpty()) &&
131 (!myGenMap.IsBound(aS) || myGenMap(aS).IsEmpty())) {
132 myHasDeleted = Standard_True;
140 // ====================================================================================================
141 // function: FillSection
143 // ====================================================================================================
144 void BOP_ShellSolidHistoryCollector::FillSection(const BOPTools_PDSFiller& theDSFiller)
146 BOPTools_InterferencePool* pIntrPool = (BOPTools_InterferencePool*)&theDSFiller->InterfPool();
147 BOPTools_CArray1OfSSInterference& aFFs = pIntrPool->SSInterferences();
148 Standard_Integer i = 0;
149 TopTools_IndexedDataMapOfShapeListOfShape aResultMap;
151 if(!myResult.IsNull()) {
152 TopExp::MapShapesAndAncestors(myResult, TopAbs_EDGE, TopAbs_FACE, aResultMap);
155 for(i = 1; i <= aFFs.Extent(); i++) {
156 BOPTools_SSInterference& aFF = aFFs(i);
157 Standard_Integer nF1 = aFF.Index1();
158 Standard_Integer nF2 = aFF.Index2();
160 if(aFF.IsTangentFaces())
162 TopoDS_Shape aF1 = theDSFiller->DS().Shape(nF1);
163 TopoDS_Shape aF2 = theDSFiller->DS().Shape(nF2);
166 BOPTools_SequenceOfCurves& aSeqOfCurves = aFF.Curves();
167 Standard_Integer j = 0;
169 for(j = 1; j <= aSeqOfCurves.Length(); j++) {
170 const BOPTools_Curve& aCurve = aSeqOfCurves.Value(j);
172 const BOPTools_ListOfPaveBlock& aPBList = aCurve.NewPaveBlocks();
173 BOPTools_ListIteratorOfListOfPaveBlock anIt(aPBList);
175 for (; anIt.More();anIt.Next()) {
176 const BOPTools_PaveBlock& aPB = anIt.Value();
177 Standard_Integer anindex = aPB.Edge();
178 const TopoDS_Shape& aS = theDSFiller->DS().GetShape(anindex);
180 if(aResultMap.Contains(aS)) {
181 TopTools_ListOfShape thelist;
182 if(!myGenMap.IsBound(aF1))
183 myGenMap.Bind(aF1, thelist);
184 myGenMap.ChangeFind(aF1).Append(aS);
186 if(!myGenMap.IsBound(aF2))
187 myGenMap.Bind(aF2, thelist);
188 myGenMap.ChangeFind(aF2).Append(aS);
194 const BOPTools_ListOfPaveBlock& aSectList = aFF.PaveBlocks();
195 BOPTools_ListIteratorOfListOfPaveBlock anIt(aSectList);
197 for (; anIt.More();anIt.Next()) {
198 const BOPTools_PaveBlock& aPB=anIt.Value();
199 Standard_Integer nSect = aPB.Edge();
200 const TopoDS_Shape& aS = theDSFiller->DS().GetShape(nSect);
202 if(aResultMap.Contains(aS)) {
203 if(aResultMap.FindFromKey(aS).Extent() >= 2)
206 Standard_Boolean add1 = Standard_True;
207 TopTools_ListOfShape thelist1;
208 if(!myGenMap.IsBound(aF1))
209 myGenMap.Bind(aF1, thelist1);
211 TopTools_ListOfShape& aList = myGenMap.ChangeFind(aF1);
212 TopTools_ListIteratorOfListOfShape anItF1(aList);
214 for(; anItF1.More(); anItF1.Next()) {
215 if(aS.IsSame(anItF1.Value())) {
216 add1 = Standard_False;
223 myGenMap.ChangeFind(aF1).Append(aS);
225 Standard_Boolean add2 = Standard_True;
226 TopTools_ListOfShape thelist2;
227 if(!myGenMap.IsBound(aF2))
228 myGenMap.Bind(aF2, thelist2);
230 TopTools_ListOfShape& aList = myGenMap.ChangeFind(aF2);
231 TopTools_ListIteratorOfListOfShape anItF2(aList);
233 for(; anItF2.More(); anItF2.Next()) {
234 if(aS.IsSame(anItF2.Value())) {
235 add2 = Standard_False;
242 myGenMap.ChangeFind(aF2).Append(aS);
248 TopTools_IndexedMapOfShape aResultMapV;
250 if(!myResult.IsNull()) {
251 TopExp::MapShapes(myResult, TopAbs_VERTEX, aResultMapV);
254 for(i = 1; i <= aFFs.Extent(); i++) {
255 BOPTools_SSInterference& aFF = aFFs(i);
256 Standard_Integer nF1 = aFF.Index1();
257 Standard_Integer nF2 = aFF.Index2();
259 if(aFF.IsTangentFaces())
261 TopoDS_Shape aF1 = theDSFiller->DS().Shape(nF1);
262 TopoDS_Shape aF2 = theDSFiller->DS().Shape(nF2);
264 TColStd_ListIteratorOfListOfInteger anIt(aFF.AloneVertices());
266 for(; anIt.More(); anIt.Next()) {
267 TopoDS_Shape aNewVertex = theDSFiller->DS().Shape(anIt.Value());
269 if(aResultMapV.Contains(aNewVertex)) {
270 TopTools_ListOfShape thelist3;
271 if(!myGenMap.IsBound(aF1))
272 myGenMap.Bind(aF1, thelist3);
273 myGenMap.ChangeFind(aF1).Append(aNewVertex);
275 if(!myGenMap.IsBound(aF2))
276 myGenMap.Bind(aF2, thelist3);
277 myGenMap.ChangeFind(aF2).Append(aNewVertex);
283 // ====================================================================================================
284 // function: FillEdgeHistory
286 // ====================================================================================================
287 void BOP_ShellSolidHistoryCollector::FillEdgeHistory(const BOPTools_PDSFiller& theDSFiller)
289 const BooleanOperations_ShapesDataStructure& aDS = theDSFiller->DS();
290 const BOPTools_PaveFiller& aPaveFiller = theDSFiller->PaveFiller();
291 const BOPTools_SplitShapesPool& aSplitShapesPool = aPaveFiller.SplitShapesPool();
292 TopTools_IndexedMapOfShape aResultMap, aFreeBoundaryMap;
294 if(!myResult.IsNull()) {
295 TopExp::MapShapes(myResult, TopAbs_EDGE, aResultMap);
297 TopTools_IndexedDataMapOfShapeListOfShape aEFMap;
299 if(myS1.ShapeType() == TopAbs_SHELL) {
300 TopExp::MapShapesAndAncestors(myS1, TopAbs_EDGE, TopAbs_FACE, aEFMap);
303 TopExp::MapShapesAndAncestors(myS2, TopAbs_EDGE, TopAbs_FACE, aEFMap);
305 Standard_Integer i = 0;
307 for(i = 1; i <= aEFMap.Extent(); i++) {
308 if(aEFMap.FindFromIndex(i).Extent() < 2)
309 aFreeBoundaryMap.Add(aEFMap.FindKey(i));
313 Standard_Integer iRank = 1;
315 for(; iRank <= 2; iRank++) {
316 BooleanOperations_StateOfShape aStateCmp, aState;
317 aStateCmp = BOP_BuilderTools::StateToCompare(iRank, myOp);
318 Standard_Integer i = 0;
319 Standard_Integer nb = aDS.NumberOfShapesOfTheObject();
320 nb = (iRank == 1) ? nb : (nb + aDS.NumberOfShapesOfTheTool());
321 Standard_Integer startindex = (iRank == 1) ? 1 : (aDS.NumberOfShapesOfTheObject() + 1);
323 for(i = startindex; i <= nb; i++) {
324 if(aDS.GetShapeType(i) != TopAbs_EDGE)
326 const BOPTools_ListOfPaveBlock& aLPB = aSplitShapesPool(aDS.RefEdge(i));
327 const TopoDS_Shape& anOldShape = aDS.Shape(i);
329 if(!aFreeBoundaryMap.Contains(anOldShape)) {
333 if(!aLPB.IsEmpty()) {
334 BOPTools_ListIteratorOfListOfPaveBlock aPBIt(aLPB);
336 for(; aPBIt.More(); aPBIt.Next()) {
337 const BOPTools_PaveBlock& aPB = aPBIt.Value();
338 Standard_Integer nSp = aPB.Edge();
342 aState=aDS.GetState(nSp);
344 if (aState == aStateCmp) {
345 const TopoDS_Shape& aNewShape = aDS.Shape(nSp);
347 if(aResultMap.Contains(aNewShape)) {
348 TopTools_DataMapOfShapeListOfShape& aHistoryMap = myModifMap;
350 if(aHistoryMap.IsBound(anOldShape)) {
351 aHistoryMap.ChangeFind(anOldShape).Append(aNewShape);
354 TopTools_ListOfShape aShapeList;
355 aShapeList.Append(aNewShape);
356 aHistoryMap.Bind(anOldShape, aShapeList);
362 //end if(!aLPB.IsEmpty...
364 const BOPTools_CommonBlockPool& aCBPool = aPaveFiller.CommonBlockPool();
365 const BOPTools_ListOfCommonBlock& aLCB = aCBPool(aDS.RefEdge(i));
366 BOPTools_ListIteratorOfListOfCommonBlock anItCB(aLCB);
368 for (; anItCB.More(); anItCB.Next()) {
369 const BOPTools_CommonBlock& aCB = anItCB.Value();
370 const BOPTools_PaveBlock& aPB = aCB.PaveBlock1();
371 Standard_Integer nSp = aPB.Edge();
372 TopoDS_Shape aNewShape = aDS.Shape(nSp);
374 if(aResultMap.Contains(aNewShape)) {
375 TopTools_DataMapOfShapeListOfShape& aHistoryMap = myModifMap;
377 if(aHistoryMap.IsBound(anOldShape)) {
378 aHistoryMap.ChangeFind(anOldShape).Append(aNewShape);
381 TopTools_ListOfShape aShapeList;
382 aShapeList.Append(aNewShape);
383 aHistoryMap.Bind(anOldShape, aShapeList);
387 // end for (; anItCB.More...