b311480e |
1 | // Created on: 2001-05-06 |
2 | // Created by: Igor FEOKTISTOV |
3 | // Copyright (c) 2001-2012 OPEN CASCADE SAS |
4 | // |
5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file |
7 | // except in compliance with the License. Please obtain a copy of the License |
8 | // at http://www.opencascade.org and read it completely before using this file. |
9 | // |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
12 | // |
13 | // The Original Code and all software distributed under the License is |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
15 | // Initial Developer hereby disclaims all such warranties, including without |
16 | // limitation, any warranties of merchantability, fitness for a particular |
17 | // purpose or non-infringement. Please see the License for the specific terms |
18 | // and conditions governing the rights and limitations under the License. |
7fd59977 |
19 | |
20 | #include <QANewModTopOpe_Limitation.ixx> |
21 | |
22 | #include <BRep_Builder.hxx> |
23 | #include <TopExp_Explorer.hxx> |
24 | #include <TopoDS.hxx> |
25 | #include <TopoDS_Iterator.hxx> |
26 | #include <TopAbs.hxx> |
27 | #include <TopTools_ListOfShape.hxx> |
28 | #include <BRepAlgoAPI_Cut.hxx> |
29 | #include <BRepAlgoAPI_Common.hxx> |
30 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
31 | #include <Standard_ConstructionError.hxx> |
32 | #include <TopTools_MapOfShape.hxx> |
33 | |
34 | |
35 | static TopoDS_Shape MakeCutTool(const TopoDS_Shape& theS2) |
36 | { |
37 | TopoDS_Shape aRealCutTool, aSh; |
38 | BRep_Builder aBB; |
39 | |
40 | aBB.MakeSolid(TopoDS::Solid(aRealCutTool)); |
41 | aBB.MakeShell(TopoDS::Shell(aSh)); |
42 | |
43 | TopExp_Explorer anExp; |
44 | |
45 | anExp.Init(theS2,TopAbs_FACE); |
46 | |
47 | for(; anExp.More(); anExp.Next()) aBB.Add(aSh, anExp.Current()); |
48 | aBB.Add(aRealCutTool, aSh); |
49 | |
50 | return aRealCutTool; |
51 | } |
52 | |
53 | |
54 | QANewModTopOpe_Limitation::QANewModTopOpe_Limitation(const TopoDS_Shape& theObjectToCut, |
55 | const TopoDS_Shape& theCutTool, |
56 | const QANewModTopOpe_ModeOfLimitation theMode) : |
57 | myObjectToCut(theObjectToCut), |
58 | myFwdIsDone(Standard_False), |
59 | myRevIsDone(Standard_False), |
60 | myMode(theMode), |
61 | myCut(NULL), |
62 | myCommon(NULL) |
63 | { |
64 | |
65 | TopExp_Explorer anExp; |
66 | anExp.Init(theCutTool,TopAbs_FACE); |
67 | |
68 | if(!anExp.More()) return; |
69 | |
70 | myCutTool = MakeCutTool(theCutTool); |
71 | |
72 | Cut(); |
73 | |
74 | } |
75 | |
76 | void QANewModTopOpe_Limitation::Cut() |
77 | { |
78 | |
79 | NotDone(); |
80 | |
81 | if(myMode == QANewModTopOpe_Forward) { |
82 | if(!myFwdIsDone) { |
83 | myCut = new BRepAlgoAPI_Cut(myObjectToCut, myCutTool); |
84 | if(myCut->IsDone()) { |
85 | myResultFwd = myCut->Shape(); |
86 | myFwdIsDone = Standard_True; |
87 | } |
88 | } |
89 | if(myFwdIsDone) { |
90 | myShape = myResultFwd; |
91 | Done(); |
92 | } |
93 | } |
94 | else if (myMode == QANewModTopOpe_Reversed) { |
95 | if(!myRevIsDone) { |
96 | myCommon = new BRepAlgoAPI_Common(myObjectToCut, myCutTool); |
97 | if(myCommon->IsDone()) { |
98 | myResultRvs = myCommon->Shape(); |
99 | myRevIsDone = Standard_True; |
100 | } |
101 | } |
102 | if(myRevIsDone) { |
103 | myShape = myResultRvs; |
104 | Done(); |
105 | } |
106 | } |
107 | else if (myMode == QANewModTopOpe_BothParts) { |
108 | if(!myFwdIsDone) { |
109 | myCut = new BRepAlgoAPI_Cut(myObjectToCut, myCutTool); |
110 | if(myCut->IsDone()) { |
111 | myResultFwd = myCut->Shape(); |
112 | myFwdIsDone = Standard_True; |
113 | } |
114 | } |
115 | |
116 | if(!myRevIsDone) { |
117 | myCommon = new BRepAlgoAPI_Common(myObjectToCut, myCutTool); |
118 | if(myCommon->IsDone()) { |
119 | myResultRvs = myCommon->Shape(); |
120 | myRevIsDone = Standard_True; |
121 | } |
122 | } |
123 | |
124 | if(myFwdIsDone && myRevIsDone) { |
125 | myShape.Nullify(); |
126 | BRep_Builder aBB; |
127 | aBB.MakeCompound(TopoDS::Compound(myShape)); |
128 | TopoDS_Iterator aItr; |
129 | aItr.Initialize(myResultFwd, Standard_False, Standard_False); |
130 | for(; aItr.More(); aItr.Next()) aBB.Add(myShape, aItr.Value()); |
131 | |
132 | aItr.Initialize(myResultRvs, Standard_False, Standard_False); |
133 | for(; aItr.More(); aItr.Next()) aBB.Add(myShape, aItr.Value()); |
134 | |
135 | Done(); |
136 | } |
137 | |
138 | } |
139 | else { |
140 | Standard_ConstructionError::Raise("QANewModTopOpe_Limitation : wrong mode"); |
141 | } |
142 | |
143 | |
144 | } |
145 | |
146 | void QANewModTopOpe_Limitation::SetMode(const QANewModTopOpe_ModeOfLimitation theMode) |
147 | { |
148 | myMode = theMode; |
149 | } |
150 | |
151 | QANewModTopOpe_ModeOfLimitation QANewModTopOpe_Limitation::GetMode() const |
152 | { |
153 | return myMode; |
154 | } |
155 | |
156 | const TopoDS_Shape& QANewModTopOpe_Limitation::Shape1() const |
157 | { |
158 | return myObjectToCut; |
159 | } |
160 | |
161 | const TopoDS_Shape& QANewModTopOpe_Limitation::Shape2() const |
162 | { |
163 | return myCutTool; |
164 | } |
165 | |
166 | |
167 | //======================================================================= |
168 | //function : Modified |
169 | //purpose : |
170 | //======================================================================= |
171 | |
172 | const TopTools_ListOfShape& QANewModTopOpe_Limitation::Modified(const TopoDS_Shape& S) |
173 | { |
174 | Check(); |
175 | myGenerated.Clear(); |
176 | if(myMode == QANewModTopOpe_Forward) { |
177 | myGenerated = myCut->Modified(S); |
178 | } |
179 | else if(myMode == QANewModTopOpe_Reversed) { |
180 | myGenerated = myCommon->Modified(S); |
181 | } |
182 | else { |
183 | myGenerated = myCut->Modified(S); |
184 | |
185 | TopTools_MapOfShape aMap; // to check if shape can be added in list more then one time |
186 | TopTools_ListIteratorOfListOfShape It(myGenerated); |
187 | for(;It.More();It.Next()) { |
188 | aMap.Add(It.Value()); |
189 | } |
190 | |
191 | It.Initialize(myCommon->Modified(S)); |
192 | for(;It.More();It.Next()) { |
193 | if(aMap.Add(It.Value())) myGenerated.Append(It.Value()); |
194 | } |
195 | } |
196 | |
197 | return myGenerated; |
198 | } |
199 | |
200 | // ================================================================================================ |
201 | // function: Modified2 |
202 | // purpose: |
203 | // ================================================================================================ |
204 | const TopTools_ListOfShape& QANewModTopOpe_Limitation::Modified2(const TopoDS_Shape& aS) |
205 | { |
206 | Check(); |
207 | myGenerated.Clear(); |
208 | if(myMode == QANewModTopOpe_Forward) { |
209 | myGenerated = myCut->Modified2(aS); |
210 | } |
211 | else if(myMode == QANewModTopOpe_Reversed) { |
212 | myGenerated = myCommon->Modified2(aS); |
213 | } |
214 | else { |
215 | myGenerated = myCut->Modified2(aS); |
216 | |
217 | TopTools_MapOfShape aMap; // to check if shape can be added in list more then one time |
218 | TopTools_ListIteratorOfListOfShape It(myGenerated); |
219 | for(;It.More();It.Next()) { |
220 | aMap.Add(It.Value()); |
221 | } |
222 | |
223 | It.Initialize(myCommon->Modified2(aS)); |
224 | for(;It.More();It.Next()) { |
225 | if(aMap.Add(It.Value())) myGenerated.Append(It.Value()); |
226 | } |
227 | } |
228 | |
229 | return myGenerated; |
230 | } |
231 | |
232 | // ================================================================================================ |
233 | // function: Generated |
234 | // purpose: |
235 | // ================================================================================================ |
236 | const TopTools_ListOfShape& QANewModTopOpe_Limitation::Generated(const TopoDS_Shape& S) |
237 | { |
238 | Check(); |
239 | myGenerated.Clear(); |
240 | if(myMode == QANewModTopOpe_Forward) { |
241 | myGenerated = myCut->Generated(S); |
242 | } |
243 | else if(myMode == QANewModTopOpe_Reversed) { |
244 | myGenerated = myCommon->Generated(S); |
245 | } |
246 | else { |
247 | myGenerated = myCut->Generated(S); |
248 | |
249 | TopTools_MapOfShape aMap; // to check if shape can be added in list more then one time |
250 | TopTools_ListIteratorOfListOfShape It(myGenerated); |
251 | for(;It.More();It.Next()) { |
252 | aMap.Add(It.Value()); |
253 | } |
254 | |
255 | It.Initialize(myCommon->Generated(S)); |
256 | for(;It.More();It.Next()) { |
257 | if(aMap.Add(It.Value())) myGenerated.Append(It.Value()); |
258 | } |
259 | } |
260 | |
261 | return myGenerated; |
262 | } |
263 | |
264 | // ================================================================================================ |
265 | // function: HasModified |
266 | // purpose: |
267 | // ================================================================================================ |
268 | Standard_Boolean QANewModTopOpe_Limitation::HasModified() const |
269 | { |
270 | Check(); |
271 | if(myMode == QANewModTopOpe_Forward) { |
272 | return myCut->HasModified(); |
273 | } |
274 | else if(myMode == QANewModTopOpe_Reversed) { |
275 | return myCommon->HasModified(); |
276 | } |
277 | else { |
278 | return myCut->HasModified() || myCommon->HasModified(); |
279 | } |
280 | } |
281 | |
282 | // ================================================================================================ |
283 | // function: HasGenerated |
284 | // purpose: |
285 | // ================================================================================================ |
286 | Standard_Boolean QANewModTopOpe_Limitation::HasGenerated() const |
287 | { |
288 | Check(); |
289 | if(myMode == QANewModTopOpe_Forward) { |
290 | return myCut->HasGenerated(); |
291 | } |
292 | else if(myMode == QANewModTopOpe_Reversed) { |
293 | return myCommon->HasGenerated(); |
294 | } |
295 | else { |
296 | return myCut->HasGenerated() || myCommon->HasGenerated(); |
297 | } |
298 | } |
299 | |
300 | // ================================================================================================ |
301 | // function: HasDeleted |
302 | // purpose: |
303 | // ================================================================================================ |
304 | Standard_Boolean QANewModTopOpe_Limitation::HasDeleted() const |
305 | { |
306 | Check(); |
307 | if(myMode == QANewModTopOpe_Forward) { |
308 | return myCut->HasDeleted(); |
309 | } |
310 | else if(myMode == QANewModTopOpe_Reversed) { |
311 | return myCommon->HasDeleted(); |
312 | } |
313 | else { |
314 | return myCut->HasDeleted() || myCommon->HasDeleted(); |
315 | } |
316 | } |
317 | |
318 | Standard_Boolean QANewModTopOpe_Limitation::IsDeleted(const TopoDS_Shape& S) |
319 | { |
320 | |
321 | Check(); |
322 | if(myMode == QANewModTopOpe_Forward) { |
323 | return myCut->IsDeleted(S); |
324 | } |
325 | else if(myMode == QANewModTopOpe_Reversed) { |
326 | return myCommon->IsDeleted(S); |
327 | } |
328 | else { |
329 | return myCut->IsDeleted(S) && myCommon->IsDeleted(S); |
330 | } |
331 | |
332 | } |
333 | |
334 | void QANewModTopOpe_Limitation::Delete() |
335 | { |
336 | delete myCut; |
337 | delete myCommon; |
338 | } |