b311480e |
1 | // Created on: 2000-03-16 |
2 | // Created by: Peter KURNEV |
973c2be1 |
3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
7fd59977 |
16 | |
4e57c75e |
17 | #include <BOPAlgo_BOP.hxx> |
92ae0f2f |
18 | #include <BOPAlgo_MakerVolume.hxx> |
42cf5bc1 |
19 | #include <BOPAlgo_Operation.hxx> |
20 | #include <BOPAlgo_PaveFiller.hxx> |
49b0c452 |
21 | #include <BOPAlgo_Section.hxx> |
42cf5bc1 |
22 | #include <BOPCol_ListOfShape.hxx> |
23 | #include <BOPDS_DS.hxx> |
24 | #include <BOPTest.hxx> |
42cf5bc1 |
25 | #include <BOPTest_Objects.hxx> |
26 | #include <BRep_Builder.hxx> |
da219023 |
27 | #include <BRepAlgoAPI_BooleanOperation.hxx> |
28 | #include <BRepAlgoAPI_Common.hxx> |
da219023 |
29 | #include <BRepAlgoAPI_Cut.hxx> |
42cf5bc1 |
30 | #include <BRepAlgoAPI_Fuse.hxx> |
da219023 |
31 | #include <BRepAlgoAPI_Section.hxx> |
42cf5bc1 |
32 | #include <DBRep.hxx> |
33 | #include <Draw.hxx> |
42cf5bc1 |
34 | #include <DrawTrSurf.hxx> |
543a9964 |
35 | #include <Geom2d_Curve.hxx> |
42cf5bc1 |
36 | #include <Geom_Curve.hxx> |
37 | #include <IntTools_Curve.hxx> |
38 | #include <IntTools_FaceFace.hxx> |
39 | #include <IntTools_PntOn2Faces.hxx> |
40 | #include <NCollection_BaseAllocator.hxx> |
42cf5bc1 |
41 | #include <TCollection_AsciiString.hxx> |
42 | #include <TopoDS_Compound.hxx> |
43 | #include <TopoDS_Iterator.hxx> |
44 | #include <TopoDS_Shape.hxx> |
543a9964 |
45 | |
42cf5bc1 |
46 | #include <stdio.h> |
47 | // |
7fd59977 |
48 | // |
4e57c75e |
49 | static BOPAlgo_PaveFiller* pPF=NULL; |
7fd59977 |
50 | // |
7fd59977 |
51 | |
4e57c75e |
52 | static |
53 | Standard_Integer bopsmt(Draw_Interpretor& di, |
54 | Standard_Integer n, |
55 | const char** a, |
56 | const BOPAlgo_Operation aOp); |
43cb0011 |
57 | // |
4e57c75e |
58 | static |
59 | Standard_Integer bsmt (Draw_Interpretor& di, |
60 | Standard_Integer n, |
61 | const char** a, |
62 | const BOPAlgo_Operation aOp); |
7fd59977 |
63 | // |
4e57c75e |
64 | static Standard_Integer bop (Draw_Interpretor&, Standard_Integer, const char**); |
65 | static Standard_Integer bopsection(Draw_Interpretor&, Standard_Integer, const char**); |
66 | static Standard_Integer boptuc (Draw_Interpretor&, Standard_Integer, const char**); |
67 | static Standard_Integer bopcut (Draw_Interpretor&, Standard_Integer, const char**); |
68 | static Standard_Integer bopfuse (Draw_Interpretor&, Standard_Integer, const char**); |
69 | static Standard_Integer bopcommon (Draw_Interpretor&, Standard_Integer, const char**); |
7fd59977 |
70 | // |
4e57c75e |
71 | static Standard_Integer bsection (Draw_Interpretor&, Standard_Integer, const char**); |
72 | static Standard_Integer btuc (Draw_Interpretor&, Standard_Integer, const char**); |
73 | static Standard_Integer bcut (Draw_Interpretor&, Standard_Integer, const char**); |
74 | static Standard_Integer bfuse (Draw_Interpretor&, Standard_Integer, const char**); |
75 | static Standard_Integer bcommon (Draw_Interpretor&, Standard_Integer, const char**); |
7fd59977 |
76 | // |
4e57c75e |
77 | static Standard_Integer bopcurves (Draw_Interpretor&, Standard_Integer, const char**); |
92ae0f2f |
78 | static Standard_Integer mkvolume (Draw_Interpretor&, Standard_Integer, const char**); |
7fd59977 |
79 | |
7fd59977 |
80 | //======================================================================= |
81 | //function : BOPCommands |
82 | //purpose : |
83 | //======================================================================= |
4e57c75e |
84 | void BOPTest::BOPCommands(Draw_Interpretor& theCommands) |
7fd59977 |
85 | { |
86 | static Standard_Boolean done = Standard_False; |
4e57c75e |
87 | if (done) return; |
7fd59977 |
88 | done = Standard_True; |
89 | // Chapter's name |
43cb0011 |
90 | const char* g = "BOPTest commands"; |
4e57c75e |
91 | // Commands |
92 | |
43cb0011 |
93 | theCommands.Add("bop" , "use bop s1 s2" , __FILE__, bop, g); |
b1d15f53 |
94 | theCommands.Add("bopcommon" , "use bopcommon r" , __FILE__, bopcommon, g); |
95 | theCommands.Add("bopfuse" , "use bopfuse r" , __FILE__,bopfuse, g); |
96 | theCommands.Add("bopcut" , "use bopcut r" , __FILE__,bopcut, g); |
97 | theCommands.Add("boptuc" , "use boptuc r" , __FILE__,boptuc, g); |
98 | theCommands.Add("bopsection", "use bopsection r" , __FILE__,bopsection, g); |
99 | // |
43cb0011 |
100 | theCommands.Add("bcommon" , "use bcommon r s1 s2" , __FILE__,bcommon, g); |
101 | theCommands.Add("bfuse" , "use bfuse r s1 s2" , __FILE__,bfuse, g); |
102 | theCommands.Add("bcut" , "use bcut r s1 s2" , __FILE__,bcut, g); |
103 | theCommands.Add("btuc" , "use btuc r s1 s2" , __FILE__,btuc, g); |
104 | theCommands.Add("bsection", "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na]", |
4e57c75e |
105 | __FILE__, bsection, g); |
7fd59977 |
106 | // |
5652dc62 |
107 | theCommands.Add("bopcurves", "use bopcurves F1 F2 [-2d/-2d1/-2d2] " |
108 | "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]", |
99c5f9f0 |
109 | __FILE__, bopcurves, g); |
291fced1 |
110 | theCommands.Add("mkvolume", "make solids from set of shapes.\nmkvolume r b1 b2 ... [-c] [-ni] [-ai]", |
b1d15f53 |
111 | __FILE__, mkvolume , g); |
7fd59977 |
112 | } |
4e57c75e |
113 | |
7fd59977 |
114 | //======================================================================= |
115 | //function : bop |
116 | //purpose : |
117 | //======================================================================= |
43cb0011 |
118 | Standard_Integer bop(Draw_Interpretor& di, |
119 | Standard_Integer n, |
120 | const char** a) |
7fd59977 |
121 | { |
3510db62 |
122 | Standard_Boolean bRunParallel, bNonDestructive; |
b1d15f53 |
123 | Standard_Real aTol; |
4e57c75e |
124 | TopoDS_Shape aS1, aS2; |
125 | BOPCol_ListOfShape aLC; |
126 | // |
43cb0011 |
127 | if (n != 3) { |
128 | di << " use bop s1 s2 \n"; |
49b0c452 |
129 | return 0; |
7fd59977 |
130 | } |
4e57c75e |
131 | // |
132 | aS1=DBRep::Get(a[1]); |
133 | aS2=DBRep::Get(a[2]); |
134 | // |
135 | if (aS1.IsNull() || aS2.IsNull()) { |
136 | di << " null shapes are not allowed \n"; |
49b0c452 |
137 | return 0; |
7fd59977 |
138 | } |
4e57c75e |
139 | // |
49b0c452 |
140 | aTol=BOPTest_Objects::FuzzyValue(); |
49b0c452 |
141 | bRunParallel=BOPTest_Objects::RunParallel(); |
3510db62 |
142 | bNonDestructive = BOPTest_Objects::NonDestructive(); |
483ce1bd |
143 | BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue(); |
49b0c452 |
144 | // |
4e57c75e |
145 | aLC.Append(aS1); |
146 | aLC.Append(aS2); |
147 | // |
5d05cf31 |
148 | if (pPF!=NULL) { |
4e57c75e |
149 | delete pPF; |
5d05cf31 |
150 | pPF=NULL; |
7fd59977 |
151 | } |
488e5b9d |
152 | Handle(NCollection_BaseAllocator)aAL= |
153 | NCollection_BaseAllocator::CommonBaseAllocator(); |
5d05cf31 |
154 | pPF=new BOPAlgo_PaveFiller(aAL); |
4e57c75e |
155 | // |
156 | pPF->SetArguments(aLC); |
b1d15f53 |
157 | pPF->SetFuzzyValue(aTol); |
49b0c452 |
158 | pPF->SetRunParallel(bRunParallel); |
3510db62 |
159 | pPF->SetNonDestructive(bNonDestructive); |
483ce1bd |
160 | pPF->SetGlue(aGlue); |
4e57c75e |
161 | // |
162 | pPF->Perform(); |
33ba8565 |
163 | BOPTest::ReportAlerts(*pPF); |
4e57c75e |
164 | // |
7fd59977 |
165 | return 0; |
166 | } |
7fd59977 |
167 | //======================================================================= |
4e57c75e |
168 | //function : bopcommon |
7fd59977 |
169 | //purpose : |
170 | //======================================================================= |
43cb0011 |
171 | Standard_Integer bopcommon (Draw_Interpretor& di, |
172 | Standard_Integer n, |
173 | const char** a) |
7fd59977 |
174 | { |
4e57c75e |
175 | return bopsmt(di, n, a, BOPAlgo_COMMON); |
176 | } |
177 | //======================================================================= |
178 | //function : bopfuse |
179 | //purpose : |
180 | //======================================================================= |
43cb0011 |
181 | Standard_Integer bopfuse(Draw_Interpretor& di, |
182 | Standard_Integer n, |
183 | const char** a) |
4e57c75e |
184 | { |
185 | return bopsmt(di, n, a, BOPAlgo_FUSE); |
186 | } |
187 | //======================================================================= |
188 | //function : bopcut |
189 | //purpose : |
190 | //======================================================================= |
43cb0011 |
191 | Standard_Integer bopcut(Draw_Interpretor& di, |
192 | Standard_Integer n, |
193 | const char** a) |
4e57c75e |
194 | { |
195 | return bopsmt(di, n, a, BOPAlgo_CUT); |
196 | } |
197 | //======================================================================= |
198 | //function : boptuc |
199 | //purpose : |
200 | //======================================================================= |
43cb0011 |
201 | Standard_Integer boptuc(Draw_Interpretor& di, |
202 | Standard_Integer n, |
203 | const char** a) |
4e57c75e |
204 | { |
205 | return bopsmt(di, n, a, BOPAlgo_CUT21); |
206 | } |
207 | //======================================================================= |
4e57c75e |
208 | //function : bopsmt |
209 | //purpose : |
210 | //======================================================================= |
211 | Standard_Integer bopsmt(Draw_Interpretor& di, |
212 | Standard_Integer n, |
213 | const char** a, |
214 | const BOPAlgo_Operation aOp) |
215 | { |
216 | if (n<2) { |
43cb0011 |
217 | di << " use bopsmt r\n"; |
4e57c75e |
218 | return 0; |
7fd59977 |
219 | } |
4e57c75e |
220 | // |
221 | if (!pPF) { |
222 | di << " prepare PaveFiller first\n"; |
223 | return 0; |
224 | } |
225 | // |
33ba8565 |
226 | if (pPF->HasErrors()) { |
4e57c75e |
227 | di << " PaveFiller has not been done\n"; |
228 | return 0; |
229 | } |
230 | // |
231 | char buf[64]; |
49b0c452 |
232 | Standard_Boolean bRunParallel; |
33ba8565 |
233 | Standard_Integer aNb; |
4e57c75e |
234 | BOPAlgo_BOP aBOP; |
235 | // |
236 | const BOPCol_ListOfShape& aLC=pPF->Arguments(); |
237 | aNb=aLC.Extent(); |
238 | if (aNb!=2) { |
239 | Sprintf (buf, " wrong number of arguments %s\n", aNb); |
240 | di << buf; |
241 | return 0; |
242 | } |
49b0c452 |
243 | // |
244 | bRunParallel=BOPTest_Objects::RunParallel(); |
4e57c75e |
245 | // |
246 | const TopoDS_Shape& aS1=aLC.First(); |
247 | const TopoDS_Shape& aS2=aLC.Last(); |
248 | // |
249 | aBOP.AddArgument(aS1); |
250 | aBOP.AddTool(aS2); |
251 | aBOP.SetOperation(aOp); |
49b0c452 |
252 | aBOP.SetRunParallel (bRunParallel); |
4e57c75e |
253 | // |
254 | aBOP.PerformWithFiller(*pPF); |
33ba8565 |
255 | BOPTest::ReportAlerts(aBOP); |
256 | if (aBOP.HasErrors()) { |
4e57c75e |
257 | return 0; |
258 | } |
259 | // |
260 | const TopoDS_Shape& aR=aBOP.Shape(); |
261 | if (aR.IsNull()) { |
262 | di << " null shape\n"; |
263 | return 0; |
264 | } |
265 | // |
266 | DBRep::Set(a[1], aR); |
267 | return 0; |
7fd59977 |
268 | } |
7fd59977 |
269 | //======================================================================= |
85915310 |
270 | //function : bopsection |
271 | //purpose : |
272 | //======================================================================= |
43cb0011 |
273 | Standard_Integer bopsection(Draw_Interpretor& di, |
274 | Standard_Integer n, |
275 | const char** a) |
85915310 |
276 | { |
277 | if (n<2) { |
43cb0011 |
278 | di << " use bopsection r\n"; |
85915310 |
279 | return 0; |
280 | } |
281 | // |
282 | if (!pPF) { |
283 | di << " prepare PaveFiller first\n"; |
284 | return 0; |
285 | } |
286 | // |
33ba8565 |
287 | if (pPF->HasErrors()) { |
85915310 |
288 | di << " PaveFiller has not been done\n"; |
289 | return 0; |
290 | } |
291 | // |
292 | char buf[64]; |
49b0c452 |
293 | Standard_Boolean bRunParallel; |
33ba8565 |
294 | Standard_Integer aNb; |
85915310 |
295 | BOPAlgo_Section aBOP; |
296 | // |
297 | const BOPCol_ListOfShape& aLC=pPF->Arguments(); |
298 | aNb=aLC.Extent(); |
299 | if (aNb!=2) { |
300 | Sprintf (buf, " wrong number of arguments %s\n", aNb); |
301 | di << buf; |
302 | return 0; |
303 | } |
304 | // |
49b0c452 |
305 | bRunParallel=BOPTest_Objects::RunParallel(); |
306 | // |
85915310 |
307 | const TopoDS_Shape& aS1=aLC.First(); |
308 | const TopoDS_Shape& aS2=aLC.Last(); |
309 | // |
310 | aBOP.AddArgument(aS1); |
311 | aBOP.AddArgument(aS2); |
49b0c452 |
312 | aBOP.SetRunParallel (bRunParallel); |
85915310 |
313 | // |
314 | aBOP.PerformWithFiller(*pPF); |
33ba8565 |
315 | BOPTest::ReportAlerts(aBOP); |
316 | if (aBOP.HasErrors()) { |
85915310 |
317 | return 0; |
318 | } |
319 | // |
320 | const TopoDS_Shape& aR=aBOP.Shape(); |
321 | if (aR.IsNull()) { |
322 | di << " null shape\n"; |
323 | return 0; |
324 | } |
325 | // |
326 | DBRep::Set(a[1], aR); |
327 | return 0; |
328 | } |
329 | //======================================================================= |
7fd59977 |
330 | //function : bcommon |
331 | //purpose : |
332 | //======================================================================= |
43cb0011 |
333 | Standard_Integer bcommon (Draw_Interpretor& di, |
334 | Standard_Integer n, |
335 | const char** a) |
7fd59977 |
336 | { |
4e57c75e |
337 | return bsmt(di, n, a, BOPAlgo_COMMON); |
7fd59977 |
338 | } |
339 | //======================================================================= |
340 | //function : bfuse |
341 | //purpose : |
342 | //======================================================================= |
43cb0011 |
343 | Standard_Integer bfuse (Draw_Interpretor& di, |
344 | Standard_Integer n, |
345 | const char** a) |
7fd59977 |
346 | { |
4e57c75e |
347 | return bsmt(di, n, a, BOPAlgo_FUSE); |
7fd59977 |
348 | } |
7fd59977 |
349 | //======================================================================= |
350 | //function : bcut |
351 | //purpose : |
352 | //======================================================================= |
43cb0011 |
353 | Standard_Integer bcut (Draw_Interpretor& di, |
354 | Standard_Integer n, |
355 | const char** a) |
7fd59977 |
356 | { |
4e57c75e |
357 | return bsmt(di, n, a, BOPAlgo_CUT); |
358 | } |
359 | //======================================================================= |
360 | //function : btuc |
361 | //purpose : |
362 | //======================================================================= |
43cb0011 |
363 | Standard_Integer btuc (Draw_Interpretor& di, |
364 | Standard_Integer n, |
365 | const char** a) |
4e57c75e |
366 | { |
367 | return bsmt(di, n, a, BOPAlgo_CUT21); |
7fd59977 |
368 | } |
369 | //======================================================================= |
370 | //function : bsection |
371 | //purpose : |
372 | //======================================================================= |
373 | Standard_Integer bsection(Draw_Interpretor& di, |
4e57c75e |
374 | Standard_Integer n, |
375 | const char** a) |
7fd59977 |
376 | { |
7fd59977 |
377 | if (n < 4) { |
43cb0011 |
378 | di << "use bsection r s1 s2 [-n2d/-n2d1/-n2d2] [-na] [tol]\n"; |
49b0c452 |
379 | return 0; |
7fd59977 |
380 | } |
b1d15f53 |
381 | // |
43cb0011 |
382 | TopoDS_Shape aS1, aS2; |
b1d15f53 |
383 | // |
43cb0011 |
384 | aS1=DBRep::Get(a[2]); |
385 | aS2=DBRep::Get(a[3]); |
4e57c75e |
386 | if (aS1.IsNull() || aS2.IsNull()) { |
7fd59977 |
387 | di << " Null shapes are not allowed \n"; |
49b0c452 |
388 | return 0; |
7fd59977 |
389 | } |
49b0c452 |
390 | // |
3510db62 |
391 | Standard_Boolean bRunParallel, bNonDestructive, bApp, bPC1, bPC2; |
b1d15f53 |
392 | Standard_Real aTol; |
da219023 |
393 | // |
394 | bApp = Standard_True; |
395 | bPC1 = Standard_True; |
396 | bPC2 = Standard_True; |
49b0c452 |
397 | aTol = BOPTest_Objects::FuzzyValue(); |
398 | bRunParallel = BOPTest_Objects::RunParallel(); |
3510db62 |
399 | bNonDestructive = BOPTest_Objects::NonDestructive(); |
483ce1bd |
400 | BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue(); |
b1d15f53 |
401 | // |
33ba8565 |
402 | for (Standard_Integer i = 4; i < n; ++i) { |
b1d15f53 |
403 | if (!strcmp(a[i], "-n2d")) { |
404 | bPC1 = Standard_False; |
405 | bPC2 = Standard_False; |
7fd59977 |
406 | } |
b1d15f53 |
407 | else if (!strcmp(a[i], "-n2d1")) { |
408 | bPC1 = Standard_False; |
7fd59977 |
409 | } |
b1d15f53 |
410 | else if (!strcmp(a[i], "-n2d2")) { |
411 | bPC2 = Standard_False; |
7fd59977 |
412 | } |
b1d15f53 |
413 | else if (!strcmp(a[i], "-na")) { |
414 | bApp = Standard_False; |
7fd59977 |
415 | } |
b1d15f53 |
416 | } |
417 | // |
b1d15f53 |
418 | BRepAlgoAPI_Section aSec(aS1, aS2, Standard_False); |
49b0c452 |
419 | // |
b1d15f53 |
420 | aSec.Approximation(bApp); |
421 | aSec.ComputePCurveOn1(bPC1); |
422 | aSec.ComputePCurveOn2(bPC2); |
43cb0011 |
423 | // |
b1d15f53 |
424 | aSec.SetFuzzyValue(aTol); |
49b0c452 |
425 | aSec.SetRunParallel(bRunParallel); |
3510db62 |
426 | aSec.SetNonDestructive(bNonDestructive); |
483ce1bd |
427 | aSec.SetGlue(aGlue); |
b1d15f53 |
428 | // |
429 | aSec.Build(); |
33ba8565 |
430 | // |
431 | if (aSec.HasWarnings()) { |
432 | Standard_SStream aSStream; |
433 | aSec.DumpWarnings(aSStream); |
434 | di << aSStream; |
435 | } |
436 | // |
b1d15f53 |
437 | if (!aSec.IsDone()) { |
33ba8565 |
438 | Standard_SStream aSStream; |
439 | aSec.DumpErrors(aSStream); |
440 | di << aSStream; |
4e57c75e |
441 | return 0; |
7fd59977 |
442 | } |
b1d15f53 |
443 | // |
444 | const TopoDS_Shape& aR=aSec.Shape(); |
445 | if (aR.IsNull()) { |
446 | di << " null shape\n"; |
447 | return 0; |
7fd59977 |
448 | } |
b1d15f53 |
449 | DBRep::Set(a[1], aR); |
450 | return 0; |
7fd59977 |
451 | } |
7fd59977 |
452 | //======================================================================= |
4e57c75e |
453 | //function : bsmt |
7fd59977 |
454 | //purpose : |
455 | //======================================================================= |
4e57c75e |
456 | Standard_Integer bsmt (Draw_Interpretor& di, |
457 | Standard_Integer n, |
458 | const char** a, |
459 | const BOPAlgo_Operation aOp) |
7fd59977 |
460 | { |
3510db62 |
461 | Standard_Boolean bRunParallel, bNonDestructive; |
4e57c75e |
462 | TopoDS_Shape aS1, aS2; |
463 | BOPCol_ListOfShape aLC; |
b1d15f53 |
464 | Standard_Real aTol; |
4e57c75e |
465 | // |
43cb0011 |
466 | if (n != 4) { |
467 | di << " use bx r s1 s2\n"; |
49b0c452 |
468 | return 0; |
7fd59977 |
469 | } |
4e57c75e |
470 | // |
471 | aS1=DBRep::Get(a[2]); |
472 | aS2=DBRep::Get(a[3]); |
473 | // |
474 | if (aS1.IsNull() || aS2.IsNull()) { |
475 | di << " null shapes are not allowed \n"; |
49b0c452 |
476 | return 0; |
7fd59977 |
477 | } |
49b0c452 |
478 | aLC.Append(aS1); |
479 | aLC.Append(aS2); |
480 | // |
481 | aTol=BOPTest_Objects::FuzzyValue(); |
49b0c452 |
482 | bRunParallel = BOPTest_Objects::RunParallel(); |
3510db62 |
483 | bNonDestructive = BOPTest_Objects::NonDestructive(); |
483ce1bd |
484 | BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue(); |
4e57c75e |
485 | // |
488e5b9d |
486 | Handle(NCollection_BaseAllocator)aAL= |
487 | NCollection_BaseAllocator::CommonBaseAllocator(); |
49b0c452 |
488 | // |
489 | //--------------------------------------------------------------- |
4e57c75e |
490 | BOPAlgo_PaveFiller aPF(aAL); |
491 | // |
492 | aPF.SetArguments(aLC); |
49b0c452 |
493 | aPF.SetFuzzyValue(aTol); |
494 | aPF.SetRunParallel(bRunParallel); |
3510db62 |
495 | aPF.SetNonDestructive(bNonDestructive); |
483ce1bd |
496 | aPF.SetGlue(aGlue); |
4e57c75e |
497 | // |
498 | aPF.Perform(); |
33ba8565 |
499 | BOPTest::ReportAlerts(aPF); |
500 | if (aPF.HasErrors()) { |
4e57c75e |
501 | return 0; |
7fd59977 |
502 | } |
503 | // |
49b0c452 |
504 | //--------------------------------------------------------------- |
505 | BOPAlgo_BOP aBOP(aAL); |
506 | // |
507 | aBOP.AddArgument(aS1); |
508 | aBOP.AddTool(aS2); |
509 | aBOP.SetOperation(aOp); |
510 | aBOP.SetRunParallel(bRunParallel); |
da219023 |
511 | // |
49b0c452 |
512 | aBOP.PerformWithFiller(aPF); |
33ba8565 |
513 | BOPTest::ReportAlerts(aBOP); |
514 | if (aBOP.HasErrors()) { |
4e57c75e |
515 | return 0; |
7fd59977 |
516 | } |
49b0c452 |
517 | const TopoDS_Shape& aR=aBOP.Shape(); |
4e57c75e |
518 | if (aR.IsNull()) { |
519 | di << " null shape\n"; |
520 | return 0; |
7fd59977 |
521 | } |
49b0c452 |
522 | // |
4e57c75e |
523 | DBRep::Set(a[1], aR); |
7fd59977 |
524 | return 0; |
525 | } |
7fd59977 |
526 | //======================================================================= |
4e57c75e |
527 | //function : bopcurves |
7fd59977 |
528 | //purpose : |
529 | //======================================================================= |
4e57c75e |
530 | Standard_Integer bopcurves (Draw_Interpretor& di, |
531 | Standard_Integer n, |
532 | const char** a) |
7fd59977 |
533 | { |
4e57c75e |
534 | if (n<3) { |
5652dc62 |
535 | di << "Usage: bopcurves F1 F2 [-2d/-2d1/-2d2] " |
536 | "[-p u1 v1 u2 v2 (to add start points] [-v (for extended output)]\n"; |
4e57c75e |
537 | return 1; |
7fd59977 |
538 | } |
99c5f9f0 |
539 | // |
4e57c75e |
540 | TopoDS_Shape S1 = DBRep::Get(a[1]); |
541 | TopoDS_Shape S2 = DBRep::Get(a[2]); |
542 | TopAbs_ShapeEnum aType; |
99c5f9f0 |
543 | // |
4e57c75e |
544 | if (S1.IsNull() || S2.IsNull()) { |
5652dc62 |
545 | di << " Null shapes are not allowed \n"; |
4e57c75e |
546 | return 1; |
7fd59977 |
547 | } |
99c5f9f0 |
548 | // |
4e57c75e |
549 | aType=S1.ShapeType(); |
550 | if (aType != TopAbs_FACE) { |
551 | di << " Type mismatch F1\n"; |
552 | return 1; |
7fd59977 |
553 | } |
4e57c75e |
554 | aType=S2.ShapeType(); |
555 | if (aType != TopAbs_FACE) { |
556 | di << " Type mismatch F2\n"; |
557 | return 1; |
7fd59977 |
558 | } |
99c5f9f0 |
559 | // |
4e57c75e |
560 | const TopoDS_Face& aF1=*(TopoDS_Face*)(&S1); |
561 | const TopoDS_Face& aF2=*(TopoDS_Face*)(&S2); |
99c5f9f0 |
562 | // |
563 | Standard_Boolean aToApproxC3d, aToApproxC2dOnS1, aToApproxC2dOnS2, anIsDone; |
d677b214 |
564 | Standard_Integer aNbCurves, aNbPoints; |
5652dc62 |
565 | Standard_Real anAppTol; |
47e3009d |
566 | IntSurf_ListOfPntOn2S aListOfPnts; |
e9e644ed |
567 | TCollection_AsciiString aNm("c_"), aNp("p_"); |
99c5f9f0 |
568 | // |
569 | anAppTol = 0.0000001; |
570 | aToApproxC3d = Standard_True; |
571 | aToApproxC2dOnS1 = Standard_False; |
572 | aToApproxC2dOnS2 = Standard_False; |
47e3009d |
573 | |
99c5f9f0 |
574 | // |
5652dc62 |
575 | Standard_Boolean bExtOut = Standard_False; |
47e3009d |
576 | for(Standard_Integer i = 3; i < n; i++) |
577 | { |
578 | if (!strcasecmp(a[i],"-2d")) { |
99c5f9f0 |
579 | aToApproxC2dOnS1 = Standard_True; |
580 | aToApproxC2dOnS2 = Standard_True; |
581 | } |
47e3009d |
582 | else if (!strcasecmp(a[i],"-2d1")) { |
99c5f9f0 |
583 | aToApproxC2dOnS1 = Standard_True; |
584 | } |
47e3009d |
585 | else if (!strcasecmp(a[i],"-2d2")) { |
99c5f9f0 |
586 | aToApproxC2dOnS2 = Standard_True; |
587 | } |
47e3009d |
588 | else if (!strcasecmp(a[i],"-p")) { |
589 | IntSurf_PntOn2S aPt; |
590 | const Standard_Real aU1 = Draw::Atof(a[++i]); |
591 | const Standard_Real aV1 = Draw::Atof(a[++i]); |
592 | const Standard_Real aU2 = Draw::Atof(a[++i]); |
593 | const Standard_Real aV2 = Draw::Atof(a[++i]); |
594 | |
595 | aPt.SetValue(aU1, aV1, aU2, aV2); |
596 | aListOfPnts.Append(aPt); |
597 | } |
5652dc62 |
598 | else if (!strcasecmp(a[i],"-v")) { |
599 | bExtOut = Standard_True; |
600 | } |
99c5f9f0 |
601 | else { |
5652dc62 |
602 | di << "Wrong key.\n"; |
603 | di << "To build 2d curves use one of the following keys: -2d/-2d1/-2d2\n"; |
604 | di << "To add start points use the following key: -p u1 v1 u2 v2\n"; |
605 | di << "For extended output use the following key: -v\n"; |
c2c2f2b6 |
606 | return 1; |
607 | } |
608 | } |
609 | // |
4e57c75e |
610 | IntTools_FaceFace aFF; |
99c5f9f0 |
611 | // |
4e57c75e |
612 | aFF.SetParameters (aToApproxC3d, |
613 | aToApproxC2dOnS1, |
614 | aToApproxC2dOnS2, |
615 | anAppTol); |
47e3009d |
616 | aFF.SetList(aListOfPnts); |
99c5f9f0 |
617 | // |
4e57c75e |
618 | aFF.Perform (aF1, aF2); |
99c5f9f0 |
619 | // |
4e57c75e |
620 | anIsDone=aFF.IsDone(); |
621 | if (!anIsDone) { |
5652dc62 |
622 | di << "Error: Intersection failed\n"; |
d0820f2e |
623 | return 0; |
7fd59977 |
624 | } |
99c5f9f0 |
625 | // |
c2c2f2b6 |
626 | aFF.PrepareLines3D(Standard_False); |
4e57c75e |
627 | const IntTools_SequenceOfCurves& aSCs=aFF.Lines(); |
e9e644ed |
628 | const IntTools_SequenceOfPntOn2Faces& aSPs = aFF.Points(); |
4e57c75e |
629 | // |
e9e644ed |
630 | aNbCurves = aSCs.Length(); |
631 | aNbPoints = aSPs.Length(); |
632 | if (!aNbCurves && !aNbPoints) { |
633 | di << " has no 3d curves\n"; |
634 | di << " has no 3d points\n"; |
d0820f2e |
635 | return 0; |
7fd59977 |
636 | } |
e9e644ed |
637 | // |
e9e644ed |
638 | // curves |
639 | if (aNbCurves) { |
5652dc62 |
640 | Standard_Real aTolR = 0.; |
641 | if (!bExtOut) { |
642 | // find maximal tolerance |
643 | for (Standard_Integer i = 1; i <= aNbCurves; i++) { |
644 | const IntTools_Curve& anIC = aSCs(i); |
645 | if (aTolR < anIC.Tolerance()) { |
646 | aTolR = anIC.Tolerance(); |
647 | } |
648 | } |
649 | di << "Tolerance Reached=" << aTolR << "\n"; |
650 | } |
651 | // |
c2c2f2b6 |
652 | di << aNbCurves << " curve(s) found.\n"; |
e9e644ed |
653 | // |
d677b214 |
654 | for (Standard_Integer i=1; i<=aNbCurves; i++) { |
e9e644ed |
655 | const IntTools_Curve& anIC=aSCs(i); |
7fd59977 |
656 | |
e9e644ed |
657 | Handle (Geom_Curve) aC3D = anIC.Curve(); |
7fd59977 |
658 | |
e9e644ed |
659 | if (aC3D.IsNull()) { |
660 | di << " has Null 3d curve# " << i << "\n"; |
661 | continue; |
662 | } |
7fd59977 |
663 | |
e9e644ed |
664 | TCollection_AsciiString anIndx(i), aNmx; |
665 | aNmx = aNm + anIndx; |
c2c2f2b6 |
666 | |
e9e644ed |
667 | Standard_CString nameC = aNmx.ToCString(); |
c2c2f2b6 |
668 | |
e9e644ed |
669 | DrawTrSurf::Set(nameC, aC3D); |
670 | di << nameC << " "; |
c2c2f2b6 |
671 | // |
e9e644ed |
672 | Handle(Geom2d_Curve) aPC1 = anIC.FirstCurve2d(); |
673 | Handle(Geom2d_Curve) aPC2 = anIC.SecondCurve2d(); |
c2c2f2b6 |
674 | // |
e9e644ed |
675 | if (!aPC1.IsNull() || !aPC2.IsNull()) { |
676 | di << "("; |
99c5f9f0 |
677 | // |
678 | if (!aPC1.IsNull()) { |
e9e644ed |
679 | TCollection_AsciiString pc1N("c2d1_"), pc1Nx; |
680 | pc1Nx = pc1N + anIndx; |
681 | Standard_CString nameC2d1 = pc1Nx.ToCString(); |
682 | // |
683 | DrawTrSurf::Set(nameC2d1, aPC1); |
684 | di << nameC2d1; |
99c5f9f0 |
685 | } |
e9e644ed |
686 | // |
687 | if (!aPC2.IsNull()) { |
688 | TCollection_AsciiString pc2N("c2d2_"), pc2Nx; |
689 | pc2Nx = pc2N + anIndx; |
690 | Standard_CString nameC2d2 = pc2Nx.ToCString(); |
691 | // |
692 | DrawTrSurf::Set(nameC2d2, aPC2); |
693 | // |
694 | if (!aPC1.IsNull()) { |
695 | di << ", "; |
696 | } |
697 | di << nameC2d2; |
698 | } |
699 | di << ") "; |
c2c2f2b6 |
700 | } |
5652dc62 |
701 | // |
702 | if (bExtOut) { |
703 | di << "\nTolerance: " << anIC.Tolerance() << "\n"; |
704 | di << "Tangential tolerance: " << anIC.TangentialTolerance() << "\n"; |
705 | di << "\n"; |
706 | } |
707 | } |
708 | if (!bExtOut) { |
709 | di << "\n"; |
c2c2f2b6 |
710 | } |
e9e644ed |
711 | } |
712 | // |
713 | // points |
714 | if (aNbPoints) { |
715 | di << aNbPoints << " point(s) found.\n"; |
716 | // |
d677b214 |
717 | for (Standard_Integer i = 1; i <= aNbPoints; i++) { |
e9e644ed |
718 | const IntTools_PntOn2Faces& aPi = aSPs(i); |
719 | const gp_Pnt& aP = aPi.P1().Pnt(); |
720 | // |
721 | TCollection_AsciiString anIndx(i), aNmx; |
722 | aNmx = aNp + anIndx; |
723 | Standard_CString nameP = aNmx.ToCString(); |
724 | // |
725 | DrawTrSurf::Set(nameP, aP); |
726 | di << nameP << " "; |
727 | } |
728 | di << "\n"; |
7fd59977 |
729 | } |
99c5f9f0 |
730 | // |
4e57c75e |
731 | return 0; |
7fd59977 |
732 | } |
92ae0f2f |
733 | //======================================================================= |
734 | //function : mkvolume |
735 | //purpose : |
736 | //======================================================================= |
737 | Standard_Integer mkvolume(Draw_Interpretor& di, Standard_Integer n, const char** a) |
738 | { |
92ae0f2f |
739 | if (n < 3) { |
291fced1 |
740 | di << "Usage: mkvolume r b1 b2 ... [-c] [-ni] [-ai]\n"; |
b1d15f53 |
741 | di << "Options:\n"; |
742 | di << " -c - use this option if the arguments are compounds\n"; |
743 | di << " containing shapes that should be interfered;\n"; |
744 | di << " -ni - use this option if the arguments should not be interfered;\n"; |
291fced1 |
745 | di << " -ai - use this option to avoid internal for solids shapes in the result.\n"; |
92ae0f2f |
746 | return 1; |
747 | } |
748 | // |
b1d15f53 |
749 | const char* usage = "Type mkvolume without arguments for the usage of the command.\n"; |
750 | // |
291fced1 |
751 | Standard_Boolean bToIntersect, bRunParallel, bNonDestructive; |
752 | Standard_Boolean bCompounds, bAvoidInternal; |
b1d15f53 |
753 | Standard_Integer i; |
754 | Standard_Real aTol; |
755 | TopoDS_Shape aS; |
756 | BOPCol_ListOfShape aLS; |
92ae0f2f |
757 | // |
49b0c452 |
758 | aTol = BOPTest_Objects::FuzzyValue(); |
49b0c452 |
759 | bRunParallel = BOPTest_Objects::RunParallel(); |
3510db62 |
760 | bNonDestructive = BOPTest_Objects::NonDestructive(); |
483ce1bd |
761 | BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue(); |
43cb0011 |
762 | // |
763 | bToIntersect = Standard_True; |
b1d15f53 |
764 | bCompounds = Standard_False; |
291fced1 |
765 | bAvoidInternal = Standard_False; |
92ae0f2f |
766 | // |
b1d15f53 |
767 | for (i = 2; i < n; ++i) { |
92ae0f2f |
768 | aS = DBRep::Get(a[i]); |
769 | if (!aS.IsNull()) { |
770 | aLS.Append(aS); |
771 | } |
b1d15f53 |
772 | else { |
773 | if (!strcmp(a[i], "-c")) { |
774 | bCompounds = Standard_True; |
775 | } |
776 | else if (!strcmp(a[i], "-ni")) { |
777 | bToIntersect = Standard_False; |
778 | } |
291fced1 |
779 | else if (!strcmp(a[i], "-ai")) { |
780 | bAvoidInternal = Standard_True; |
781 | } |
b1d15f53 |
782 | } |
92ae0f2f |
783 | } |
784 | // |
785 | if (aLS.IsEmpty()) { |
b1d15f53 |
786 | di << "No shapes to process.\n"; |
92ae0f2f |
787 | di << usage; |
788 | return 1; |
789 | } |
790 | // |
b1d15f53 |
791 | // treat list of arguments for the case of compounds |
792 | if (bToIntersect && bCompounds) { |
793 | BOPCol_ListOfShape aLSx; |
794 | BOPCol_ListIteratorOfListOfShape aItLS; |
795 | // |
796 | aItLS.Initialize(aLS); |
797 | for (; aItLS.More(); aItLS.Next()) { |
798 | const TopoDS_Shape& aSx = aItLS.Value(); |
799 | TopoDS_Iterator aItS(aSx); |
800 | for (; aItS.More(); aItS.Next()) { |
801 | const TopoDS_Shape& aSxS = aItS.Value(); |
802 | aLSx.Append(aSxS); |
803 | } |
804 | } |
805 | // |
806 | aLS.Clear(); |
807 | aLS.Assign(aLSx); |
808 | } |
809 | // |
92ae0f2f |
810 | BOPAlgo_MakerVolume aMV; |
811 | aMV.SetArguments(aLS); |
812 | aMV.SetIntersect(bToIntersect); |
813 | aMV.SetRunParallel(bRunParallel); |
b1d15f53 |
814 | aMV.SetFuzzyValue(aTol); |
3510db62 |
815 | aMV.SetNonDestructive(bNonDestructive); |
291fced1 |
816 | aMV.SetAvoidInternalShapes(bAvoidInternal); |
483ce1bd |
817 | aMV.SetGlue(aGlue); |
92ae0f2f |
818 | // |
819 | aMV.Perform(); |
33ba8565 |
820 | BOPTest::ReportAlerts(aMV); |
821 | if (aMV.HasErrors()) { |
822 | return 0; |
92ae0f2f |
823 | } |
824 | // |
825 | const TopoDS_Shape& aR = aMV.Shape(); |
826 | // |
827 | DBRep::Set(a[1], aR); |
828 | // |
829 | return 0; |
830 | } |