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 | // |
d5f74e42 |
9 | // This library is free software; you can redistribute it and/or modify it under |
10 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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 | |
4e57c75e |
18 | |
42cf5bc1 |
19 | #include <BOPAlgo_Builder.hxx> |
20 | #include <BOPAlgo_PaveFiller.hxx> |
4e57c75e |
21 | #include <BOPCol_ListOfShape.hxx> |
22 | #include <BOPCol_MapOfShape.hxx> |
8620e18d |
23 | #include <BOPDS_DS.hxx> |
4e57c75e |
24 | #include <BOPTools.hxx> |
42cf5bc1 |
25 | #include <BOPTools_AlgoTools.hxx> |
26 | #include <IntTools_Context.hxx> |
27 | #include <TopoDS_Iterator.hxx> |
28 | #include <TopoDS_Shape.hxx> |
8620e18d |
29 | |
4e57c75e |
30 | //======================================================================= |
31 | //function : Generated |
32 | //purpose : |
33 | //======================================================================= |
8620e18d |
34 | const TopTools_ListOfShape& BOPAlgo_Builder::Generated |
35 | (const TopoDS_Shape&) |
4e57c75e |
36 | { |
4e57c75e |
37 | myHistShapes.Clear(); |
4e57c75e |
38 | return myHistShapes; |
39 | } |
40 | //======================================================================= |
41 | //function : Modified |
42 | //purpose : |
43 | //======================================================================= |
8620e18d |
44 | const TopTools_ListOfShape& BOPAlgo_Builder::Modified |
45 | (const TopoDS_Shape& theS) |
4e57c75e |
46 | { |
47 | Standard_Boolean bHasImage, bToReverse; |
48 | TopAbs_ShapeEnum aType; |
49 | BOPCol_ListIteratorOfListOfShape aIt; |
50 | // |
51 | myHistShapes.Clear(); |
52 | // |
53 | if (theS.IsNull()) { |
54 | return myHistShapes; |
55 | } |
56 | // |
57 | bHasImage=myImages.IsBound(theS); |
58 | if (!bHasImage) { |
59 | return myHistShapes; |
60 | } |
61 | // |
62 | aType=theS.ShapeType(); |
63 | // |
64 | if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE || |
65 | aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) { |
66 | return myHistShapes; |
67 | } |
68 | // |
69 | //PrepareHistory(); |
70 | // |
71 | const BOPCol_ListOfShape& aLSp=myImages.Find(theS); |
72 | aIt.Initialize(aLSp); |
73 | for (; aIt.More(); aIt.Next()) { |
74 | TopoDS_Shape aSp=aIt.Value(); |
b24ac892 |
75 | if (myShapesSD.IsBound(aSp)) { |
76 | aSp = myShapesSD.Find(aSp); |
77 | } |
78 | // |
79 | if (myMapShape.Contains(aSp)) { |
80 | // |
81 | if (aType==TopAbs_VERTEX || aType==TopAbs_SOLID) { |
82 | aSp.Orientation(theS.Orientation()); |
83 | } |
84 | else { |
8620e18d |
85 | bToReverse= |
86 | BOPTools_AlgoTools::IsSplitToReverse(aSp, theS, myContext); |
b24ac892 |
87 | if (bToReverse) { |
88 | aSp.Reverse(); |
89 | } |
4e57c75e |
90 | } |
b24ac892 |
91 | // |
92 | myHistShapes.Append(aSp); |
4e57c75e |
93 | } |
94 | } |
95 | // |
96 | return myHistShapes; |
97 | } |
98 | //======================================================================= |
99 | //function : IsDeleted |
100 | //purpose : |
101 | //======================================================================= |
8620e18d |
102 | Standard_Boolean BOPAlgo_Builder::IsDeleted |
103 | (const TopoDS_Shape& theS) |
4e57c75e |
104 | { |
c088aa93 |
105 | Standard_Boolean bRet; |
4e57c75e |
106 | TopAbs_ShapeEnum aType; |
107 | BOPCol_ListIteratorOfListOfShape aIt; |
108 | // |
c088aa93 |
109 | bRet = Standard_True; |
4e57c75e |
110 | // |
111 | if (theS.IsNull()) { |
c088aa93 |
112 | return bRet; |
4e57c75e |
113 | } |
114 | // |
c088aa93 |
115 | aType = theS.ShapeType(); |
4e57c75e |
116 | if (!(aType==TopAbs_EDGE || aType==TopAbs_FACE || |
117 | aType==TopAbs_VERTEX || aType==TopAbs_SOLID)) { |
c088aa93 |
118 | return bRet; |
4e57c75e |
119 | } |
120 | // |
c088aa93 |
121 | if (!myImages.IsBound(theS)) { |
122 | bRet = !myMapShape.Contains(theS); |
123 | return bRet; |
4e57c75e |
124 | } |
125 | // |
c088aa93 |
126 | const BOPCol_ListOfShape& aLSp = myImages.Find(theS); |
4e57c75e |
127 | aIt.Initialize(aLSp); |
128 | for (; aIt.More(); aIt.Next()) { |
c088aa93 |
129 | const TopoDS_Shape& aSp = aIt.Value(); |
130 | const TopoDS_Shape& aSpR = myShapesSD.IsBound(aSp) ? |
131 | myShapesSD.Find(aSp) : aSp; |
4e57c75e |
132 | // |
c088aa93 |
133 | if (myMapShape.Contains(aSpR)) { |
134 | bRet = Standard_False; |
135 | break; |
4e57c75e |
136 | } |
137 | } |
c088aa93 |
138 | // |
139 | return bRet; |
4e57c75e |
140 | } |
141 | //======================================================================= |
142 | //function : PrepareHistory |
143 | //purpose : |
144 | //======================================================================= |
8620e18d |
145 | void BOPAlgo_Builder::PrepareHistory() |
4e57c75e |
146 | { |
147 | if (!myFlagHistory) { |
148 | return; |
149 | } |
150 | // |
151 | if(myShape.IsNull()) { |
152 | return; |
153 | } |
154 | // |
b24ac892 |
155 | Standard_Boolean bHasImage; |
4e57c75e |
156 | TopAbs_ShapeEnum aType; |
157 | BOPCol_MapOfShape aMS; |
158 | BOPCol_ListIteratorOfListOfShape aIt; |
159 | BOPCol_MapIteratorOfMapOfShape aItM; |
160 | // |
161 | // 1. Clearing |
162 | BOPAlgo_BuilderShape::PrepareHistory(); |
163 | // |
164 | // 2. myMapShape - all shapes of result with theirs sub-shapes |
165 | BOPTools::MapShapes(myShape, myMapShape); |
166 | // |
167 | // 3. MS - all argument shapes with theirs sub-shapes |
8620e18d |
168 | const BOPCol_ListOfShape& aArguments=myDS->Arguments(); |
169 | aIt.Initialize(aArguments); |
4e57c75e |
170 | for (; aIt.More(); aIt.Next()) { |
171 | const TopoDS_Shape& aSx=aIt.Value(); |
172 | BOPTools::MapShapes(aSx, aMS); |
173 | } |
174 | // |
175 | // 4. Treatment |
176 | aItM.Initialize(aMS); |
177 | for (; aItM.More(); aItM.Next()) { |
178 | const TopoDS_Shape& aSx=aItM.Key(); |
ecf4f17c |
179 | aType = aSx.ShapeType(); |
180 | if (!(aType == TopAbs_VERTEX || aType == TopAbs_EDGE || |
181 | aType == TopAbs_FACE || aType == TopAbs_SOLID)) { |
182 | continue; |
183 | } |
4e57c75e |
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 | } |