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