1 // Created by: Peter KURNEV
2 // Copyright (c) 2010-2012 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 // The content of this file is subject to the Open CASCADE Technology Public
8 // License Version 6.5 (the "License"). You may not use the content of this file
9 // except in compliance with the License. Please obtain a copy of the License
10 // at http://www.opencascade.org and read it completely before using this file.
12 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
13 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
15 // The Original Code and all software distributed under the License is
16 // distributed on an "AS IS" basis, without warranty of any kind, and the
17 // Initial Developer hereby disclaims all such warranties, including without
18 // limitation, any warranties of merchantability, fitness for a particular
19 // purpose or non-infringement. Please see the License for the specific terms
20 // and conditions governing the rights and limitations under the License.
23 #include <BOPAlgo_Builder.ixx>
25 #include <TopoDS_Iterator.hxx>
27 #include <BOPCol_ListOfShape.hxx>
28 #include <BOPCol_MapOfShape.hxx>
30 #include <BOPTools_AlgoTools.hxx>
31 #include <BOPTools.hxx>
33 //=======================================================================
34 //function : Generated
36 //=======================================================================
37 const TopTools_ListOfShape& BOPAlgo_Builder::Generated(const TopoDS_Shape& theS)
39 Standard_Boolean bHasImage, bToReverse;
40 TopAbs_ShapeEnum aType;
41 BOPCol_ListIteratorOfListOfShape aIt;
49 bHasImage=myImages.IsBound(theS);
54 aType=theS.ShapeType();
56 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
57 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
63 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
65 for (; aIt.More(); aIt.Next()) {
66 const TopoDS_Shape& aSp=aIt.Value();
67 if (myShapesSD.IsBound(aSp)) {
68 if (myMapShape.Contains(aSp)) {
69 TopoDS_Shape aSpR=myShapesSD.Find(aSp);
71 if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
72 aSpR.Orientation(theS.Orientation());
75 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSpR, theS, myContext);
81 myHistShapes.Append(aSpR);
88 //=======================================================================
91 //=======================================================================
92 const TopTools_ListOfShape& BOPAlgo_Builder::Modified(const TopoDS_Shape& theS)
94 Standard_Boolean bHasImage, bToReverse;
95 TopAbs_ShapeEnum aType;
96 BOPCol_ListIteratorOfListOfShape aIt;
104 bHasImage=myImages.IsBound(theS);
109 aType=theS.ShapeType();
111 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
112 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
118 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
119 aIt.Initialize(aLSp);
120 for (; aIt.More(); aIt.Next()) {
121 TopoDS_Shape aSp=aIt.Value();
122 if (!myShapesSD.IsBound(aSp)) {
123 if (myMapShape.Contains(aSp)) {
125 if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
126 aSp.Orientation(theS.Orientation());
129 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSp, theS, myContext);
135 myHistShapes.Append(aSp);
142 //=======================================================================
143 //function : IsDeleted
145 //=======================================================================
146 Standard_Boolean BOPAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
148 Standard_Boolean bRet, bHasImage, bContains;
149 TopAbs_ShapeEnum aType;
150 BOPCol_ListIteratorOfListOfShape aIt;
158 aType=theS.ShapeType();
159 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
160 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
164 bHasImage=myImages.IsBound(theS);
171 bContains=myMapShape.Contains(theS);
176 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
177 aIt.Initialize(aLSp);
178 for (; aIt.More(); aIt.Next()) {
179 TopoDS_Shape aSp=aIt.Value();
181 if (!myShapesSD.IsBound(aSp)) {
182 if (myMapShape.Contains(aSp)) {
187 TopoDS_Shape aSpR=myShapesSD.Find(aSp);
188 if (myMapShape.Contains(aSpR)) {
193 return !bRet; // true
195 //=======================================================================
196 //function : PrepareHistory
198 //=======================================================================
199 void BOPAlgo_Builder::PrepareHistory()
201 if (!myFlagHistory) {
205 if(myShape.IsNull()) {
209 Standard_Boolean bHasImage, bContainsSD;
210 TopAbs_ShapeEnum aType;
211 BOPCol_MapOfShape aMS;
212 BOPCol_ListIteratorOfListOfShape aIt;
213 BOPCol_MapIteratorOfMapOfShape aItM;
216 BOPAlgo_BuilderShape::PrepareHistory();
218 // 2. myMapShape - all shapes of result with theirs sub-shapes
219 BOPTools::MapShapes(myShape, myMapShape);
221 // 3. MS - all argument shapes with theirs sub-shapes
222 aIt.Initialize(myArguments);
223 for (; aIt.More(); aIt.Next()) {
224 const TopoDS_Shape& aSx=aIt.Value();
225 BOPTools::MapShapes(aSx, aMS);
229 aItM.Initialize(aMS);
230 for (; aItM.More(); aItM.Next()) {
231 const TopoDS_Shape& aSx=aItM.Key();
232 aType=aSx.ShapeType();
234 // 4.1 .myImagesResult
235 bHasImage=myImages.IsBound(aSx);
237 BOPCol_ListOfShape aLSx;
239 if (myMapShape.Contains(aSx)) {
241 myImagesResult.Add(aSx, aLSx);
245 const BOPCol_ListOfShape& aLSp=myImages.Find(aSx);
246 aIt.Initialize(aLSp);
247 for (; aIt.More(); aIt.Next()) {
248 const TopoDS_Shape& aSp=aIt.Value();
249 if (myMapShape.Contains(aSp)) {
253 myImagesResult.Add(aSx, aLSx);
259 myHasDeleted=IsDeleted(aSx);
262 if (!myHasGenerated || !myHasModified) {
263 if (aType==TopAbs_EDGE || aType==TopAbs_FACE ||
264 aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
266 const BOPCol_ListOfShape& aLSp=myImages.Find(aSx);
267 aIt.Initialize(aLSp);
268 for (; aIt.More(); aIt.Next()) {
269 const TopoDS_Shape& aSp=aIt.Value();
271 if (myMapShape.Contains(aSp)) {
272 bContainsSD=myShapesSD.IsBound(aSp);
274 if (!myHasGenerated) {
276 myHasGenerated=Standard_True;
279 if (!myHasModified) {
281 myHasModified=Standard_True;
284 } // if (myMapShape.Contains(aSp))
290 myFlagHistory=Standard_True;
295 BOPCol_ListOfShape aLSx;
297 if (myMapShape.Contains(aSx)) {
299 myImagesResult.Add(aSx, aLSx);
303 const BOPCol_ListOfShape& aLSp=myImages.Find(aSx);
304 aIt.Initialize(aLSp);
305 for (; aIt.More(); aIt.Next()) {
306 const TopoDS_Shape& aSp=aIt.Value();
307 if (myMapShape.Contains(aSp)) {
311 myImagesResult.Add(aSx, aLSx);