b311480e |
1 | // Created on: 1994-02-18 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1994-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
973c2be1 |
8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public version 2.1 as published |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // modified by Michael KLOKOV Wed Mar 6 15:01:25 2002 |
4e57c75e |
18 | // modified by Eugeny MALTCHIKOV Wed Jul 04 11:13:01 2012 |
7fd59977 |
19 | |
20 | #include <BRepAlgoAPI_Section.ixx> |
21 | |
22 | |
23 | #include <BRepBuilderAPI_MakeFace.hxx> |
24 | #include <BRepBuilderAPI_MakeShell.hxx> |
25 | #include <Geom_Plane.hxx> |
26 | #include <Geom2d_TrimmedCurve.hxx> |
4e57c75e |
27 | |
7fd59977 |
28 | #include <TopExp.hxx> |
29 | #include <TopTools_IndexedMapOfShape.hxx> |
30 | #include <TopTools_MapOfShape.hxx> |
31 | #include <TopoDS.hxx> |
32 | #include <TopoDS_Face.hxx> |
33 | #include <BRep_Tool.hxx> |
34 | |
4e57c75e |
35 | #include <BOPAlgo_PaveFiller.hxx> |
36 | #include <BOPAlgo_BOP.hxx> |
37 | #include <BOPDS_DS.hxx> |
7fd59977 |
38 | |
39 | static TopoDS_Shape MakeShape(const Handle(Geom_Surface)& S) |
40 | { |
41 | GeomAbs_Shape c = S->Continuity(); |
1c72dff6 |
42 | if (c >= GeomAbs_C2) return BRepBuilderAPI_MakeFace(S, Precision::Confusion()); |
7fd59977 |
43 | else return BRepBuilderAPI_MakeShell(S); |
44 | } |
45 | |
4e57c75e |
46 | static Standard_Boolean HasAncestorFaces(const BOPAlgo_PPaveFiller& theDSFiller, |
47 | const TopoDS_Shape& E, |
48 | TopoDS_Shape& F1, |
49 | TopoDS_Shape& F2); |
7fd59977 |
50 | |
51 | //======================================================================= |
52 | //function : Constructor |
53 | //purpose : |
54 | //======================================================================= |
55 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh1, |
4e57c75e |
56 | const TopoDS_Shape& Sh2, |
57 | const Standard_Boolean PerformNow) |
58 | : BRepAlgoAPI_BooleanOperation(Sh1, Sh2, BOPAlgo_SECTION) |
7fd59977 |
59 | { |
60 | InitParameters(); |
61 | myparameterschanged = Standard_True; |
62 | |
63 | if(myS1.IsNull() || myS2.IsNull()) { |
64 | // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL"); |
65 | myshapeisnull = Standard_True; |
66 | } |
4e57c75e |
67 | if (PerformNow) { |
7fd59977 |
68 | Build(); |
4e57c75e |
69 | } |
7fd59977 |
70 | } |
71 | |
72 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& aS1, |
4e57c75e |
73 | const TopoDS_Shape& aS2, |
74 | const BOPAlgo_PaveFiller& aDSF, |
75 | const Standard_Boolean PerformNow) |
76 | : BRepAlgoAPI_BooleanOperation(aS1, aS2, aDSF, BOPAlgo_SECTION) |
7fd59977 |
77 | { |
78 | InitParameters(); |
79 | myparameterschanged = Standard_True; |
80 | |
81 | if(myS1.IsNull() || myS2.IsNull()) { |
82 | // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL"); |
83 | myshapeisnull = Standard_True; |
84 | } |
85 | |
4e57c75e |
86 | if (PerformNow) { |
7fd59977 |
87 | Build(); |
88 | } |
89 | } |
90 | |
91 | |
92 | //======================================================================= |
93 | //function : Constructor |
94 | //purpose : |
95 | //======================================================================= |
96 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh, |
4e57c75e |
97 | const gp_Pln& Pl, |
98 | const Standard_Boolean PerformNow) |
99 | : BRepAlgoAPI_BooleanOperation(Sh, MakeShape(new Geom_Plane(Pl)), BOPAlgo_SECTION) |
7fd59977 |
100 | { |
101 | InitParameters(); |
102 | myparameterschanged = Standard_True; |
103 | |
104 | if(Sh.IsNull() || myS2.IsNull()) { |
105 | // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL"); |
106 | myshapeisnull = Standard_True; |
107 | } |
4e57c75e |
108 | if (PerformNow) { |
7fd59977 |
109 | Build(); |
4e57c75e |
110 | } |
7fd59977 |
111 | } |
112 | |
113 | //======================================================================= |
114 | //function : Constructor |
115 | //purpose : |
116 | //======================================================================= |
117 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh, |
4e57c75e |
118 | const Handle(Geom_Surface)& Sf, |
119 | const Standard_Boolean PerformNow) |
120 | : BRepAlgoAPI_BooleanOperation(Sh, MakeShape(Sf), BOPAlgo_SECTION) |
7fd59977 |
121 | { |
122 | InitParameters(); |
123 | myparameterschanged = Standard_True; |
124 | |
125 | if(Sh.IsNull() || myS2.IsNull()) { |
126 | // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL"); |
127 | myshapeisnull = Standard_True; |
128 | } |
4e57c75e |
129 | if (PerformNow) { |
7fd59977 |
130 | Build(); |
4e57c75e |
131 | } |
7fd59977 |
132 | } |
133 | |
134 | //======================================================================= |
135 | //function : Constructor |
136 | //purpose : |
137 | //======================================================================= |
138 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const Handle(Geom_Surface)& Sf, |
4e57c75e |
139 | const TopoDS_Shape& Sh, |
140 | const Standard_Boolean PerformNow) |
141 | : BRepAlgoAPI_BooleanOperation(MakeShape(Sf), Sh, BOPAlgo_SECTION) |
7fd59977 |
142 | { |
143 | InitParameters(); |
144 | myparameterschanged = Standard_True; |
145 | |
146 | if(myS1.IsNull() || Sh.IsNull()) { |
147 | // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL"); |
148 | myshapeisnull = Standard_True; |
149 | } |
4e57c75e |
150 | if (PerformNow) { |
7fd59977 |
151 | Build(); |
4e57c75e |
152 | } |
7fd59977 |
153 | } |
154 | |
155 | //======================================================================= |
156 | //function : Constructor |
157 | //purpose : |
158 | //======================================================================= |
159 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const Handle(Geom_Surface)& Sf1, |
4e57c75e |
160 | const Handle(Geom_Surface)& Sf2, |
161 | const Standard_Boolean PerformNow) |
162 | : BRepAlgoAPI_BooleanOperation(MakeShape(Sf1), MakeShape(Sf2), BOPAlgo_SECTION) |
7fd59977 |
163 | { |
164 | InitParameters(); |
165 | myparameterschanged = Standard_True; |
166 | |
167 | if(myS1.IsNull() || myS2.IsNull()) { |
168 | // StdFail_NotDone::Raise("BRepAlgoAPI_Section : Shape NULL"); |
169 | myshapeisnull = Standard_True; |
170 | } |
171 | |
4e57c75e |
172 | if (PerformNow) { |
7fd59977 |
173 | Build(); |
4e57c75e |
174 | } |
7fd59977 |
175 | } |
176 | |
177 | //======================================================================= |
178 | //function : Init1 |
179 | //purpose : |
180 | //======================================================================= |
181 | void BRepAlgoAPI_Section::Init1(const TopoDS_Shape& S1) |
182 | { |
183 | if(!S1.IsNull()) { |
184 | if (!S1.IsEqual(myS1)) { |
185 | myS1 = S1; |
186 | |
187 | if(!myS2.IsNull()) { |
4e57c75e |
188 | myshapeisnull = Standard_False; |
7fd59977 |
189 | } |
190 | myparameterschanged = Standard_True; |
191 | } |
192 | } |
193 | else { |
194 | if(!myS1.IsNull()) { |
195 | myS1 = S1; |
196 | myshapeisnull = Standard_True; |
197 | myparameterschanged = Standard_True; |
198 | } |
199 | } |
200 | |
201 | if(myparameterschanged) |
202 | NotDone(); |
203 | } |
204 | |
205 | //======================================================================= |
206 | //function : Init1 |
207 | //purpose : |
208 | //======================================================================= |
209 | void BRepAlgoAPI_Section::Init1(const gp_Pln& Pl) |
210 | { |
211 | Init1(MakeShape(new Geom_Plane(Pl))); |
212 | } |
213 | |
214 | //======================================================================= |
215 | //function : Init1 |
216 | //purpose : |
217 | //======================================================================= |
218 | void BRepAlgoAPI_Section::Init1(const Handle(Geom_Surface)& Sf) |
219 | { |
220 | Init1(MakeShape(Sf)); |
221 | } |
222 | |
223 | //======================================================================= |
224 | //function : Init2 |
225 | //purpose : |
226 | //======================================================================= |
227 | void BRepAlgoAPI_Section::Init2(const TopoDS_Shape& S2) |
228 | { |
229 | if(!S2.IsNull()) { |
230 | if (!S2.IsEqual(myS2)) { |
231 | myS2 = S2; |
232 | |
233 | if(!myS1.IsNull()) { |
4e57c75e |
234 | myshapeisnull = Standard_False; |
7fd59977 |
235 | } |
236 | myparameterschanged = Standard_True; |
237 | } |
238 | } |
239 | else { |
240 | if(!myS2.IsNull()) { |
241 | myS2 = S2; |
242 | myshapeisnull = Standard_True; |
243 | myparameterschanged = Standard_True; |
244 | } |
245 | } |
246 | |
247 | if(myparameterschanged) { |
248 | NotDone(); |
249 | } |
250 | } |
251 | |
252 | //======================================================================= |
253 | //function : Init2 |
254 | //purpose : |
255 | //======================================================================= |
256 | void BRepAlgoAPI_Section::Init2(const gp_Pln& Pl) |
257 | { |
258 | Init2(MakeShape(new Geom_Plane(Pl))); |
259 | } |
260 | |
261 | //======================================================================= |
262 | //function : Init2 |
263 | //purpose : |
264 | //======================================================================= |
265 | void BRepAlgoAPI_Section::Init2(const Handle(Geom_Surface)& Sf) |
266 | { |
267 | Init2(MakeShape(Sf)); |
268 | } |
269 | |
270 | //======================================================================= |
271 | //function : Approximation |
272 | //purpose : |
273 | //======================================================================= |
274 | void BRepAlgoAPI_Section::Approximation(const Standard_Boolean B) |
275 | { |
276 | if(myApprox != B) { |
277 | myApprox = B; |
278 | myparameterschanged = Standard_True; |
279 | } |
280 | } |
281 | |
282 | //======================================================================= |
283 | //function : ComputePCurveOn1 |
284 | //purpose : |
285 | //======================================================================= |
286 | void BRepAlgoAPI_Section::ComputePCurveOn1(const Standard_Boolean B) |
287 | { |
288 | if(myComputePCurve1 != B) { |
289 | myComputePCurve1 = B; |
290 | myparameterschanged = Standard_True; |
291 | } |
292 | } |
293 | |
294 | //======================================================================= |
295 | //function : ComputePCurveOn2 |
296 | //purpose : |
297 | //======================================================================= |
298 | void BRepAlgoAPI_Section::ComputePCurveOn2(const Standard_Boolean B) |
299 | { |
300 | if(myComputePCurve2 != B) { |
301 | myComputePCurve2 = B; |
302 | myparameterschanged = Standard_True; |
303 | } |
304 | } |
305 | |
306 | //======================================================================= |
307 | //function : Build |
308 | //purpose : |
309 | //======================================================================= |
310 | void BRepAlgoAPI_Section::Build() |
311 | { |
312 | if(myshapeisnull) { |
313 | myErrorStatus = 2; |
314 | NotDone(); |
315 | return; |
316 | } |
317 | |
318 | if(myparameterschanged) { |
7fd59977 |
319 | Standard_Boolean bIsNewFiller = PrepareFiller(); |
320 | // |
321 | if (myErrorStatus!=1) { |
322 | NotDone(); |
323 | // there were errors during the preparation |
324 | return; |
325 | } |
326 | // |
327 | if (bIsNewFiller) { |
4e57c75e |
328 | BOPAlgo_SectionAttribute theSecAttr(myApprox, myComputePCurve1, myComputePCurve2); |
329 | myDSFiller->SetSectionAttribute(theSecAttr); |
330 | myDSFiller->Perform(); |
7fd59977 |
331 | } |
4e57c75e |
332 | // |
333 | BRepAlgoAPI_BooleanOperation::Build(); |
334 | // |
7fd59977 |
335 | myparameterschanged = Standard_False; |
336 | } |
337 | } |
338 | |
339 | //======================================================================= |
340 | //function : HasAncestorFaceOn1 |
341 | //purpose : |
342 | //======================================================================= |
343 | Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn1(const TopoDS_Shape& E, TopoDS_Shape& F) const |
344 | { |
345 | Standard_Boolean aResult = Standard_False; |
346 | if(E.IsNull()) { |
347 | return aResult; |
348 | } |
349 | |
350 | if(E.ShapeType() != TopAbs_EDGE) { |
351 | return aResult; |
352 | } |
353 | TopoDS_Shape F1, F2; |
4e57c75e |
354 | aResult = HasAncestorFaces(myDSFiller, E, F1, F2); |
7fd59977 |
355 | |
356 | if(F1.IsNull()) { |
357 | return Standard_False; |
358 | } |
359 | F = F1; |
360 | return aResult; |
361 | } |
362 | |
363 | //======================================================================= |
364 | //function : HasAncestorFaceOn2 |
365 | //purpose : |
366 | //======================================================================= |
367 | Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn2(const TopoDS_Shape& E,TopoDS_Shape& F) const |
368 | { |
369 | Standard_Boolean aResult = Standard_False; |
370 | if(E.IsNull()) { |
371 | return aResult; |
372 | } |
373 | |
374 | if(E.ShapeType() != TopAbs_EDGE) { |
375 | return aResult; |
376 | } |
377 | TopoDS_Shape F1, F2; |
4e57c75e |
378 | aResult = HasAncestorFaces(myDSFiller, E, F1, F2); |
7fd59977 |
379 | |
380 | if(F2.IsNull()) { |
381 | return Standard_False; |
382 | } |
383 | F = F2; |
384 | return aResult; |
385 | } |
386 | |
7fd59977 |
387 | //======================================================================= |
388 | //function : InitParameters |
389 | //purpose : |
390 | //======================================================================= |
391 | void BRepAlgoAPI_Section::InitParameters() |
392 | { |
393 | myparameterschanged = Standard_False; |
394 | myshapeisnull = Standard_False; |
395 | myApprox = Standard_False; |
396 | myComputePCurve1 = Standard_False; |
397 | myComputePCurve2 = Standard_False; |
398 | } |
399 | |
400 | // ------------------------------------------------------------------------ |
401 | // static function : HasAncestorFaces |
402 | // purpose : |
403 | // ------------------------------------------------------------------------ |
4e57c75e |
404 | static Standard_Boolean HasAncestorFaces(const BOPAlgo_PPaveFiller& theDSFiller, |
405 | const TopoDS_Shape& E, |
406 | TopoDS_Shape& F1, |
407 | TopoDS_Shape& F2) { |
408 | |
7a9d451a |
409 | Standard_Integer aNb, i, j, nE, nF1, nF2, aNbCurves; |
4e57c75e |
410 | // |
411 | const BOPDS_PDS& pDS = theDSFiller->PDS(); |
412 | BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF(); |
413 | // |
414 | aNb=aFFs.Extent(); |
7a9d451a |
415 | //section edges |
4e57c75e |
416 | for (i = 0; i < aNb; i++) { |
417 | BOPDS_InterfFF& aFFi=aFFs(i); |
418 | aFFi.Indices(nF1, nF2); |
419 | // |
4e57c75e |
420 | const BOPDS_VectorOfCurve& aSeqOfCurve=aFFi.Curves(); |
421 | aNbCurves=aSeqOfCurve.Extent(); |
422 | for (j=0; j<aNbCurves; j++) { |
423 | const BOPDS_Curve& aCurve=aSeqOfCurve(j); |
424 | |
425 | const BOPDS_ListOfPaveBlock& aSectEdges = aCurve.PaveBlocks(); |
426 | |
427 | BOPDS_ListIteratorOfListOfPaveBlock anIt; |
428 | anIt.Initialize(aSectEdges); |
7fd59977 |
429 | |
430 | for(; anIt.More(); anIt.Next()) { |
4e57c75e |
431 | const Handle(BOPDS_PaveBlock)& aPB = anIt.Value(); |
432 | nE = aPB->Edge(); |
433 | if(nE < 0) continue; |
434 | // |
435 | if(E.IsSame(pDS->Shape(nE))) { |
436 | F1 = pDS->Shape(nF1); |
437 | F2 = pDS->Shape(nF2); |
438 | return Standard_True; |
439 | } |
7fd59977 |
440 | } |
441 | } |
7fd59977 |
442 | } |
443 | return Standard_False; |
444 | } |