1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2014 OPEN CASCADE SAS
3 // Copyright (c) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
4 // Copyright (c) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT,
5 // EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
7 // This file is part of Open CASCADE Technology software library.
9 // This library is free software; you can redistribute it and / or modify it
10 // under the terms of the GNU Lesser General Public version 2.1 as published
11 // by the Free Software Foundation, with special exception defined in the file
12 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
13 // distribution for complete text of the license and disclaimer of any warranty.
15 // Alternatively, this file may be used under the terms of Open CASCADE
16 // commercial license or contractual agreement.
18 #include <BOPAlgo_Builder.ixx>
20 #include <TopoDS_Iterator.hxx>
22 #include <BOPCol_ListOfShape.hxx>
23 #include <BOPCol_MapOfShape.hxx>
25 #include <BOPTools_AlgoTools.hxx>
26 #include <BOPTools.hxx>
28 //=======================================================================
29 //function : Generated
31 //=======================================================================
32 const TopTools_ListOfShape& BOPAlgo_Builder::Generated(const TopoDS_Shape& theS)
34 Standard_Boolean bHasImage, bToReverse;
35 TopAbs_ShapeEnum aType;
36 BOPCol_ListIteratorOfListOfShape aIt;
44 bHasImage=myImages.IsBound(theS);
49 aType=theS.ShapeType();
51 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
52 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
58 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
60 for (; aIt.More(); aIt.Next()) {
61 const TopoDS_Shape& aSp=aIt.Value();
62 if (myShapesSD.IsBound(aSp)) {
63 if (myMapShape.Contains(aSp)) {
64 TopoDS_Shape aSpR=myShapesSD.Find(aSp);
66 if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
67 aSpR.Orientation(theS.Orientation());
70 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSpR, theS, myContext);
76 myHistShapes.Append(aSpR);
83 //=======================================================================
86 //=======================================================================
87 const TopTools_ListOfShape& BOPAlgo_Builder::Modified(const TopoDS_Shape& theS)
89 Standard_Boolean bHasImage, bToReverse;
90 TopAbs_ShapeEnum aType;
91 BOPCol_ListIteratorOfListOfShape aIt;
99 bHasImage=myImages.IsBound(theS);
104 aType=theS.ShapeType();
106 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
107 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
113 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
114 aIt.Initialize(aLSp);
115 for (; aIt.More(); aIt.Next()) {
116 TopoDS_Shape aSp=aIt.Value();
117 if (!myShapesSD.IsBound(aSp)) {
118 if (myMapShape.Contains(aSp)) {
120 if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
121 aSp.Orientation(theS.Orientation());
124 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSp, theS, myContext);
130 myHistShapes.Append(aSp);
137 //=======================================================================
138 //function : IsDeleted
140 //=======================================================================
141 Standard_Boolean BOPAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
143 Standard_Boolean bRet, bHasImage, bContains;
144 TopAbs_ShapeEnum aType;
145 BOPCol_ListIteratorOfListOfShape aIt;
153 aType=theS.ShapeType();
154 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
155 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
159 bHasImage=myImages.IsBound(theS);
166 bContains=myMapShape.Contains(theS);
171 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
172 aIt.Initialize(aLSp);
173 for (; aIt.More(); aIt.Next()) {
174 TopoDS_Shape aSp=aIt.Value();
176 if (!myShapesSD.IsBound(aSp)) {
177 if (myMapShape.Contains(aSp)) {
182 TopoDS_Shape aSpR=myShapesSD.Find(aSp);
183 if (myMapShape.Contains(aSpR)) {
188 return !bRet; // true
190 //=======================================================================
191 //function : PrepareHistory
193 //=======================================================================
194 void BOPAlgo_Builder::PrepareHistory()
196 if (!myFlagHistory) {
200 if(myShape.IsNull()) {
204 Standard_Boolean bHasImage, bContainsSD;
205 TopAbs_ShapeEnum aType;
206 BOPCol_MapOfShape aMS;
207 BOPCol_ListIteratorOfListOfShape aIt;
208 BOPCol_MapIteratorOfMapOfShape aItM;
211 BOPAlgo_BuilderShape::PrepareHistory();
213 // 2. myMapShape - all shapes of result with theirs sub-shapes
214 BOPTools::MapShapes(myShape, myMapShape);
216 // 3. MS - all argument shapes with theirs sub-shapes
217 aIt.Initialize(myArguments);
218 for (; aIt.More(); aIt.Next()) {
219 const TopoDS_Shape& aSx=aIt.Value();
220 BOPTools::MapShapes(aSx, aMS);
224 aItM.Initialize(aMS);
225 for (; aItM.More(); aItM.Next()) {
226 const TopoDS_Shape& aSx=aItM.Key();
227 aType=aSx.ShapeType();
229 // 4.1 .myImagesResult
230 bHasImage=myImages.IsBound(aSx);
232 BOPCol_ListOfShape aLSx;
234 if (myMapShape.Contains(aSx)) {
236 myImagesResult.Add(aSx, aLSx);
240 const BOPCol_ListOfShape& aLSp=myImages.Find(aSx);
241 aIt.Initialize(aLSp);
242 for (; aIt.More(); aIt.Next()) {
243 const TopoDS_Shape& aSp=aIt.Value();
244 if (myMapShape.Contains(aSp)) {
248 myImagesResult.Add(aSx, aLSx);
254 myHasDeleted=IsDeleted(aSx);
257 if (!myHasGenerated || !myHasModified) {
258 if (aType==TopAbs_EDGE || aType==TopAbs_FACE ||
259 aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
261 const BOPCol_ListOfShape& aLSp=myImages.Find(aSx);
262 aIt.Initialize(aLSp);
263 for (; aIt.More(); aIt.Next()) {
264 const TopoDS_Shape& aSp=aIt.Value();
266 if (myMapShape.Contains(aSp)) {
267 bContainsSD=myShapesSD.IsBound(aSp);
269 if (!myHasGenerated) {
271 myHasGenerated=Standard_True;
274 if (!myHasModified) {
276 myHasModified=Standard_True;
279 } // if (myMapShape.Contains(aSp))
285 myFlagHistory=Standard_True;
290 BOPCol_ListOfShape aLSx;
292 if (myMapShape.Contains(aSx)) {
294 myImagesResult.Add(aSx, aLSx);
298 const BOPCol_ListOfShape& aLSp=myImages.Find(aSx);
299 aIt.Initialize(aLSp);
300 for (; aIt.More(); aIt.Next()) {
301 const TopoDS_Shape& aSp=aIt.Value();
302 if (myMapShape.Contains(aSp)) {
306 myImagesResult.Add(aSx, aLSx);