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 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
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 | |
03cca6f7 |
20 | #include <BRepAlgoAPI_Section.hxx> |
21 | |
42cf5bc1 |
22 | #include <BOPAlgo_PaveFiller.hxx> |
03cca6f7 |
23 | |
42cf5bc1 |
24 | #include <BOPDS_DS.hxx> |
03cca6f7 |
25 | |
7fd59977 |
26 | #include <BRepBuilderAPI_MakeFace.hxx> |
27 | #include <BRepBuilderAPI_MakeShell.hxx> |
03cca6f7 |
28 | |
42cf5bc1 |
29 | #include <Geom_Plane.hxx> |
30 | #include <Geom_Surface.hxx> |
03cca6f7 |
31 | |
42cf5bc1 |
32 | #include <gp_Pln.hxx> |
03cca6f7 |
33 | |
42cf5bc1 |
34 | #include <TopoDS_Shape.hxx> |
7fd59977 |
35 | |
b1d15f53 |
36 | // |
37 | static |
38 | TopoDS_Shape MakeShape(const Handle(Geom_Surface)& ); |
7fd59977 |
39 | |
b1d15f53 |
40 | static |
41 | Standard_Boolean HasAncestorFaces(const BOPAlgo_PPaveFiller&, |
42 | const TopoDS_Shape&, |
43 | TopoDS_Shape&, |
44 | TopoDS_Shape&); |
49b0c452 |
45 | static |
46 | Standard_Boolean HasAncestorFace (const BOPAlgo_PPaveFiller& , |
47 | Standard_Integer , |
48 | const TopoDS_Shape& , |
49 | TopoDS_Shape& ); |
50 | // |
b1d15f53 |
51 | //======================================================================= |
52 | //function : BRepAlgoAPI_Section |
53 | //purpose : |
54 | //======================================================================= |
55 | BRepAlgoAPI_Section::BRepAlgoAPI_Section() |
56 | : |
57 | BRepAlgoAPI_BooleanOperation() |
58 | { |
49b0c452 |
59 | Init(Standard_False); |
b1d15f53 |
60 | } |
61 | //======================================================================= |
49b0c452 |
62 | //function : BRepAlgoAPI_Section |
b1d15f53 |
63 | //purpose : |
64 | //======================================================================= |
49b0c452 |
65 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const BOPAlgo_PaveFiller& aPF) |
66 | : |
67 | BRepAlgoAPI_BooleanOperation(aPF) |
b1d15f53 |
68 | { |
49b0c452 |
69 | Init(Standard_False); |
b1d15f53 |
70 | } |
7fd59977 |
71 | //======================================================================= |
72 | //function : Constructor |
73 | //purpose : |
74 | //======================================================================= |
75 | BRepAlgoAPI_Section::BRepAlgoAPI_Section(const TopoDS_Shape& Sh1, |
4e57c75e |
76 | const TopoDS_Shape& Sh2, |
77 | const Standard_Boolean PerformNow) |
b1d15f53 |
78 | : |
49b0c452 |
79 | BRepAlgoAPI_BooleanOperation(Sh1, |
80 | Sh2, |
81 | BOPAlgo_SECTION) |
7fd59977 |
82 | { |
49b0c452 |
83 | Init(PerformNow); |
7fd59977 |
84 | } |
b1d15f53 |
85 | //======================================================================= |
86 | //function : BRepAlgoAPI_Section |
87 | //purpose : |
88 | //======================================================================= |
89 | BRepAlgoAPI_Section::BRepAlgoAPI_Section |
90 | (const TopoDS_Shape& aS1, |
91 | const TopoDS_Shape& aS2, |
92 | const BOPAlgo_PaveFiller& aDSF, |
93 | const Standard_Boolean PerformNow) |
94 | : |
49b0c452 |
95 | BRepAlgoAPI_BooleanOperation(aS1, |
96 | aS2, |
97 | aDSF, |
98 | BOPAlgo_SECTION) |
7fd59977 |
99 | { |
49b0c452 |
100 | Init(PerformNow); |
7fd59977 |
101 | } |
7fd59977 |
102 | //======================================================================= |
103 | //function : Constructor |
104 | //purpose : |
105 | //======================================================================= |
b1d15f53 |
106 | BRepAlgoAPI_Section::BRepAlgoAPI_Section |
107 | (const TopoDS_Shape& Sh, |
108 | const gp_Pln& Pl, |
109 | const Standard_Boolean PerformNow) |
110 | : |
49b0c452 |
111 | BRepAlgoAPI_BooleanOperation(Sh, |
112 | MakeShape(new Geom_Plane(Pl)), |
b1d15f53 |
113 | BOPAlgo_SECTION) |
7fd59977 |
114 | { |
49b0c452 |
115 | Init(PerformNow); |
7fd59977 |
116 | } |
7fd59977 |
117 | //======================================================================= |
118 | //function : Constructor |
119 | //purpose : |
120 | //======================================================================= |
b1d15f53 |
121 | BRepAlgoAPI_Section::BRepAlgoAPI_Section |
122 | (const TopoDS_Shape& Sh, |
123 | const Handle(Geom_Surface)& Sf, |
124 | const Standard_Boolean PerformNow) |
125 | : |
49b0c452 |
126 | BRepAlgoAPI_BooleanOperation(Sh, |
127 | MakeShape(Sf), |
128 | BOPAlgo_SECTION) |
7fd59977 |
129 | { |
49b0c452 |
130 | Init(PerformNow); |
7fd59977 |
131 | } |
7fd59977 |
132 | //======================================================================= |
133 | //function : Constructor |
134 | //purpose : |
135 | //======================================================================= |
b1d15f53 |
136 | BRepAlgoAPI_Section::BRepAlgoAPI_Section |
137 | (const Handle(Geom_Surface)& Sf, |
138 | const TopoDS_Shape& Sh, |
139 | const Standard_Boolean PerformNow) |
140 | : |
49b0c452 |
141 | BRepAlgoAPI_BooleanOperation(MakeShape(Sf), |
142 | Sh, |
143 | BOPAlgo_SECTION) |
7fd59977 |
144 | { |
49b0c452 |
145 | Init(PerformNow); |
7fd59977 |
146 | } |
7fd59977 |
147 | //======================================================================= |
148 | //function : Constructor |
149 | //purpose : |
150 | //======================================================================= |
b1d15f53 |
151 | BRepAlgoAPI_Section::BRepAlgoAPI_Section |
152 | (const Handle(Geom_Surface)& Sf1, |
153 | const Handle(Geom_Surface)& Sf2, |
154 | const Standard_Boolean PerformNow) |
155 | : |
156 | BRepAlgoAPI_BooleanOperation(MakeShape(Sf1), |
157 | MakeShape(Sf2), |
158 | BOPAlgo_SECTION) |
7fd59977 |
159 | { |
49b0c452 |
160 | Init(PerformNow); |
161 | } |
162 | //======================================================================= |
163 | //function : ~BRepAlgoAPI_Section |
164 | //purpose : |
165 | //======================================================================= |
166 | BRepAlgoAPI_Section::~BRepAlgoAPI_Section() |
167 | { |
168 | } |
169 | //======================================================================= |
170 | //function : Init |
171 | //purpose : |
172 | //======================================================================= |
173 | void BRepAlgoAPI_Section::Init(const Standard_Boolean bFlag) |
174 | { |
175 | myOperation=BOPAlgo_SECTION; |
49b0c452 |
176 | myApprox = Standard_False; |
177 | myComputePCurve1 = Standard_False; |
178 | myComputePCurve2 = Standard_False; |
49b0c452 |
179 | // |
180 | if (bFlag) { |
7fd59977 |
181 | Build(); |
4e57c75e |
182 | } |
7fd59977 |
183 | } |
7fd59977 |
184 | //======================================================================= |
185 | //function : Init1 |
186 | //purpose : |
187 | //======================================================================= |
188 | void BRepAlgoAPI_Section::Init1(const TopoDS_Shape& S1) |
189 | { |
49b0c452 |
190 | myArguments.Clear(); |
191 | myArguments.Append(S1); |
7fd59977 |
192 | } |
7fd59977 |
193 | //======================================================================= |
194 | //function : Init1 |
195 | //purpose : |
196 | //======================================================================= |
197 | void BRepAlgoAPI_Section::Init1(const gp_Pln& Pl) |
198 | { |
199 | Init1(MakeShape(new Geom_Plane(Pl))); |
200 | } |
7fd59977 |
201 | //======================================================================= |
202 | //function : Init1 |
203 | //purpose : |
204 | //======================================================================= |
205 | void BRepAlgoAPI_Section::Init1(const Handle(Geom_Surface)& Sf) |
206 | { |
207 | Init1(MakeShape(Sf)); |
208 | } |
7fd59977 |
209 | //======================================================================= |
210 | //function : Init2 |
211 | //purpose : |
212 | //======================================================================= |
213 | void BRepAlgoAPI_Section::Init2(const TopoDS_Shape& S2) |
214 | { |
49b0c452 |
215 | myTools.Clear(); |
216 | myTools.Append(S2); |
7fd59977 |
217 | } |
7fd59977 |
218 | //======================================================================= |
219 | //function : Init2 |
220 | //purpose : |
221 | //======================================================================= |
222 | void BRepAlgoAPI_Section::Init2(const gp_Pln& Pl) |
223 | { |
224 | Init2(MakeShape(new Geom_Plane(Pl))); |
225 | } |
7fd59977 |
226 | //======================================================================= |
227 | //function : Init2 |
228 | //purpose : |
229 | //======================================================================= |
230 | void BRepAlgoAPI_Section::Init2(const Handle(Geom_Surface)& Sf) |
231 | { |
232 | Init2(MakeShape(Sf)); |
233 | } |
7fd59977 |
234 | //======================================================================= |
235 | //function : Approximation |
236 | //purpose : |
237 | //======================================================================= |
238 | void BRepAlgoAPI_Section::Approximation(const Standard_Boolean B) |
239 | { |
03cca6f7 |
240 | myApprox = B; |
7fd59977 |
241 | } |
7fd59977 |
242 | //======================================================================= |
243 | //function : ComputePCurveOn1 |
244 | //purpose : |
245 | //======================================================================= |
246 | void BRepAlgoAPI_Section::ComputePCurveOn1(const Standard_Boolean B) |
247 | { |
03cca6f7 |
248 | myComputePCurve1 = B; |
7fd59977 |
249 | } |
7fd59977 |
250 | //======================================================================= |
251 | //function : ComputePCurveOn2 |
252 | //purpose : |
253 | //======================================================================= |
254 | void BRepAlgoAPI_Section::ComputePCurveOn2(const Standard_Boolean B) |
255 | { |
03cca6f7 |
256 | myComputePCurve2 = B; |
7fd59977 |
257 | } |
7fd59977 |
258 | //======================================================================= |
49b0c452 |
259 | //function : SetAttributes |
260 | //purpose : |
261 | //======================================================================= |
262 | void BRepAlgoAPI_Section::SetAttributes() |
263 | { |
03cca6f7 |
264 | BOPAlgo_SectionAttribute theSecAttr(myApprox, |
265 | myComputePCurve1, |
266 | myComputePCurve2); |
49b0c452 |
267 | myDSFiller->SetSectionAttribute(theSecAttr); |
268 | } |
269 | //======================================================================= |
7fd59977 |
270 | //function : Build |
271 | //purpose : |
272 | //======================================================================= |
d03c0898 |
273 | void BRepAlgoAPI_Section::Build(const Message_ProgressRange& theRange) |
7fd59977 |
274 | { |
d03c0898 |
275 | BRepAlgoAPI_BooleanOperation::Build(theRange); |
7fd59977 |
276 | } |
7fd59977 |
277 | //======================================================================= |
278 | //function : HasAncestorFaceOn1 |
279 | //purpose : |
280 | //======================================================================= |
b1d15f53 |
281 | Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn1 |
49b0c452 |
282 | (const TopoDS_Shape& aE, |
283 | TopoDS_Shape& aF) const |
7fd59977 |
284 | { |
49b0c452 |
285 | Standard_Boolean bRes; |
286 | // |
287 | bRes = HasAncestorFace(myDSFiller,1 , aE, aF); |
288 | return bRes; |
7fd59977 |
289 | } |
7fd59977 |
290 | //======================================================================= |
291 | //function : HasAncestorFaceOn2 |
292 | //purpose : |
293 | //======================================================================= |
b1d15f53 |
294 | Standard_Boolean BRepAlgoAPI_Section::HasAncestorFaceOn2 |
49b0c452 |
295 | (const TopoDS_Shape& aE, |
296 | TopoDS_Shape& aF) const |
297 | { |
298 | Standard_Boolean bRes; |
299 | // |
300 | bRes = HasAncestorFace(myDSFiller, 2, aE, aF); |
301 | return bRes; |
302 | } |
303 | //======================================================================= |
304 | //function : HasAncestorFace |
305 | //purpose : |
306 | //======================================================================= |
307 | Standard_Boolean HasAncestorFace (const BOPAlgo_PPaveFiller& pPF, |
308 | Standard_Integer aIndex, |
309 | const TopoDS_Shape& aE, |
310 | TopoDS_Shape& aF) |
7fd59977 |
311 | { |
49b0c452 |
312 | Standard_Boolean bRes; |
313 | // |
314 | bRes = Standard_False; |
315 | if(aE.IsNull()) { |
316 | return bRes; |
7fd59977 |
317 | } |
49b0c452 |
318 | if(aE.ShapeType() != TopAbs_EDGE) { |
319 | return bRes; |
7fd59977 |
320 | } |
49b0c452 |
321 | // |
322 | TopoDS_Shape aF1, aF2; |
323 | // |
324 | bRes=HasAncestorFaces(pPF, aE, aF1, aF2); |
325 | if (!bRes) { |
326 | return bRes; |
7fd59977 |
327 | } |
49b0c452 |
328 | // |
329 | aF=(aIndex==1) ? aF1 : aF2; |
330 | return bRes; |
7fd59977 |
331 | } |
332 | |
7fd59977 |
333 | //======================================================================= |
b1d15f53 |
334 | //function : HasAncestorFaces |
7fd59977 |
335 | //purpose : |
336 | //======================================================================= |
49b0c452 |
337 | Standard_Boolean HasAncestorFaces (const BOPAlgo_PPaveFiller& pPF, |
338 | const TopoDS_Shape& aEx, |
339 | TopoDS_Shape& aF1, |
340 | TopoDS_Shape& aF2) |
7fd59977 |
341 | { |
b1d15f53 |
342 | |
49b0c452 |
343 | Standard_Integer aNbFF, i, j, nE, nF1, nF2, aNbVC; |
344 | BOPDS_ListIteratorOfListOfPaveBlock aItLPB; |
4e57c75e |
345 | // |
49b0c452 |
346 | const BOPDS_PDS& pDS = pPF->PDS(); |
4e57c75e |
347 | BOPDS_VectorOfInterfFF& aFFs=pDS->InterfFF(); |
348 | // |
7a9d451a |
349 | //section edges |
1155d05a |
350 | aNbFF=aFFs.Length(); |
49b0c452 |
351 | for (i = 0; i<aNbFF; ++i) { |
4e57c75e |
352 | BOPDS_InterfFF& aFFi=aFFs(i); |
353 | aFFi.Indices(nF1, nF2); |
354 | // |
49b0c452 |
355 | const BOPDS_VectorOfCurve& aVC=aFFi.Curves(); |
1155d05a |
356 | aNbVC=aVC.Length(); |
49b0c452 |
357 | for (j=0; j<aNbVC; j++) { |
358 | const BOPDS_Curve& aBC=aVC(j); |
359 | // |
360 | const BOPDS_ListOfPaveBlock& aLPB = aBC.PaveBlocks(); |
361 | // |
362 | aItLPB.Initialize(aLPB); |
363 | for(; aItLPB.More(); aItLPB.Next()) { |
364 | const Handle(BOPDS_PaveBlock)& aPB = aItLPB.Value(); |
4e57c75e |
365 | nE = aPB->Edge(); |
49b0c452 |
366 | if(nE < 0) { |
367 | continue; |
368 | } |
4e57c75e |
369 | // |
49b0c452 |
370 | const TopoDS_Shape aE=pDS->Shape(nE); |
371 | if(aEx.IsSame(aE)) { |
372 | aF1 = pDS->Shape(nF1); |
373 | aF2 = pDS->Shape(nF2); |
4e57c75e |
374 | return Standard_True; |
375 | } |
7fd59977 |
376 | } |
377 | } |
7fd59977 |
378 | } |
379 | return Standard_False; |
380 | } |
b1d15f53 |
381 | //======================================================================= |
382 | //function : MakeShape |
383 | //purpose : |
384 | //======================================================================= |
385 | TopoDS_Shape MakeShape(const Handle(Geom_Surface)& S) |
386 | { |
387 | GeomAbs_Shape c = S->Continuity(); |
388 | if (c >= GeomAbs_C2) { |
389 | return BRepBuilderAPI_MakeFace(S, Precision::Confusion()); |
390 | } |
391 | return BRepBuilderAPI_MakeShell(S); |
392 | } |