0024491: Partition algorithm history bug (faces).
[occt.git] / src / BOPAlgo / BOPAlgo_Builder_4.cxx
CommitLineData
4e57c75e 1// Created by: Peter KURNEV
973c2be1 2// Copyright (c) 2010-2014 OPEN CASCADE SAS
4e57c75e 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
6//
973c2be1 7// This file is part of Open CASCADE Technology software library.
4e57c75e 8//
973c2be1 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.
4e57c75e 14//
973c2be1 15// Alternatively, this file may be used under the terms of Open CASCADE
16// commercial license or contractual agreement.
4e57c75e 17
18#include <BOPAlgo_Builder.ixx>
19
20#include <TopoDS_Iterator.hxx>
21
22#include <BOPCol_ListOfShape.hxx>
23#include <BOPCol_MapOfShape.hxx>
24
25#include <BOPTools_AlgoTools.hxx>
26#include <BOPTools.hxx>
27
28//=======================================================================
29//function : Generated
30//purpose :
31//=======================================================================
b24ac892 32 const TopTools_ListOfShape& BOPAlgo_Builder::Generated(const TopoDS_Shape&)
4e57c75e 33{
4e57c75e 34 myHistShapes.Clear();
4e57c75e 35 return myHistShapes;
36}
37//=======================================================================
38//function : Modified
39//purpose :
40//=======================================================================
41 const TopTools_ListOfShape& BOPAlgo_Builder::Modified(const TopoDS_Shape& theS)
42{
43 Standard_Boolean bHasImage, bToReverse;
44 TopAbs_ShapeEnum aType;
45 BOPCol_ListIteratorOfListOfShape aIt;
46 //
47 myHistShapes.Clear();
48 //
49 if (theS.IsNull()) {
50 return myHistShapes;
51 }
52 //
53 bHasImage=myImages.IsBound(theS);
54 if (!bHasImage) {
55 return myHistShapes;
56 }
57 //
58 aType=theS.ShapeType();
59 //
60 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
61 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
62 return myHistShapes;
63 }
64 //
65 //PrepareHistory();
66 //
67 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
68 aIt.Initialize(aLSp);
69 for (; aIt.More(); aIt.Next()) {
70 TopoDS_Shape aSp=aIt.Value();
b24ac892 71 if (myShapesSD.IsBound(aSp)) {
72 aSp = myShapesSD.Find(aSp);
73 }
74 //
75 if (myMapShape.Contains(aSp)) {
76 //
77 if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
78 aSp.Orientation(theS.Orientation());
79 }
80 else {
81 bToReverse=BOPTools_AlgoTools::IsSplitToReverse(aSp, theS, myContext);
82 if (bToReverse) {
83 aSp.Reverse();
84 }
4e57c75e 85 }
b24ac892 86 //
87 myHistShapes.Append(aSp);
4e57c75e 88 }
89 }
90 //
91 return myHistShapes;
92}
93//=======================================================================
94//function : IsDeleted
95//purpose :
96//=======================================================================
97 Standard_Boolean BOPAlgo_Builder::IsDeleted(const TopoDS_Shape& theS)
98{
99 Standard_Boolean bRet, bHasImage, bContains;
100 TopAbs_ShapeEnum aType;
101 BOPCol_ListIteratorOfListOfShape aIt;
102 //
103 bRet=Standard_False;
104 //
105 if (theS.IsNull()) {
106 return !bRet; //true
107 }
108 //
109 aType=theS.ShapeType();
110 if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE ||
111 aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) {
112 return !bRet;
113 }
114 //
115 bHasImage=myImages.IsBound(theS);
116 if (!bHasImage) {
117 return !bRet; //true
118 }
119 //
120 //PrepareHistory();
121 //
122 bContains=myMapShape.Contains(theS);
123 if (bContains) {
124 return bRet; //false
125 }
126 //
127 const BOPCol_ListOfShape& aLSp=myImages.Find(theS);
128 aIt.Initialize(aLSp);
129 for (; aIt.More(); aIt.Next()) {
130 TopoDS_Shape aSp=aIt.Value();
131 //
132 if (!myShapesSD.IsBound(aSp)) {
133 if (myMapShape.Contains(aSp)) {
b24ac892 134 return bRet; //false
4e57c75e 135 }
136 }
137 else {
138 TopoDS_Shape aSpR=myShapesSD.Find(aSp);
139 if (myMapShape.Contains(aSpR)) {
b24ac892 140 return bRet; //false
4e57c75e 141 }
142 }
143 }
144 return !bRet; // true
145}
146//=======================================================================
147//function : PrepareHistory
148//purpose :
149//=======================================================================
150 void BOPAlgo_Builder::PrepareHistory()
151{
152 if (!myFlagHistory) {
153 return;
154 }
155 //
156 if(myShape.IsNull()) {
157 return;
158 }
159 //
b24ac892 160 Standard_Boolean bHasImage;
4e57c75e 161 TopAbs_ShapeEnum aType;
162 BOPCol_MapOfShape aMS;
163 BOPCol_ListIteratorOfListOfShape aIt;
164 BOPCol_MapIteratorOfMapOfShape aItM;
165 //
166 // 1. Clearing
167 BOPAlgo_BuilderShape::PrepareHistory();
168 //
169 // 2. myMapShape - all shapes of result with theirs sub-shapes
170 BOPTools::MapShapes(myShape, myMapShape);
171 //
172 // 3. MS - all argument shapes with theirs sub-shapes
173 aIt.Initialize(myArguments);
174 for (; aIt.More(); aIt.Next()) {
175 const TopoDS_Shape& aSx=aIt.Value();
176 BOPTools::MapShapes(aSx, aMS);
177 }
178 //
179 // 4. Treatment
180 aItM.Initialize(aMS);
181 for (; aItM.More(); aItM.Next()) {
182 const TopoDS_Shape& aSx=aItM.Key();
183 aType=aSx.ShapeType();
184 //
185 // 4.1 .myImagesResult
186 bHasImage=myImages.IsBound(aSx);
187 //
188 BOPCol_ListOfShape aLSx;
189 if (!bHasImage) {
190 if (myMapShape.Contains(aSx)) {
b24ac892 191 aLSx.Append(aSx);
192 myImagesResult.Add(aSx, aLSx);
4e57c75e 193 }
194 }
195 else {
196 const BOPCol_ListOfShape& aLSp=myImages.Find(aSx);
197 aIt.Initialize(aLSp);
198 for (; aIt.More(); aIt.Next()) {
b24ac892 199 const TopoDS_Shape& aSp=aIt.Value();
200 if (myMapShape.Contains(aSp)) {
201 aLSx.Append(aSp);
202 }
4e57c75e 203 }
204 myImagesResult.Add(aSx, aLSx);
205 }
206 // <- A
207 //
208 // 4.2 As it was
209 if (!myHasDeleted) {
210 myHasDeleted=IsDeleted(aSx);
211 }
212 //
b24ac892 213 if (!myHasModified && bHasImage) {
4e57c75e 214 if (aType==TopAbs_EDGE || aType==TopAbs_FACE ||
b24ac892 215 aType==TopAbs_VERTEX || aType==TopAbs_SOLID) {
216 myHasModified = Standard_True;
4e57c75e 217 }
218 }
b24ac892 219 //
220 if (!myHasGenerated) {
221 if (aType==TopAbs_FACE) {
222 const TopTools_ListOfShape& aLG = Generated(aSx);
223 myHasGenerated = aLG.Extent() > 0;
224 }
225 }
4e57c75e 226 }
227 myFlagHistory=Standard_True;
228}