4e57c75e |
1 | // Created by: Peter KURNEV |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
4e57c75e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
4e57c75e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
4e57c75e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
4e57c75e |
14 | |
4e57c75e |
15 | |
42cf5bc1 |
16 | #include <BOPAlgo_BOP.hxx> |
17 | #include <BOPAlgo_Builder.hxx> |
18 | #include <BOPAlgo_PaveFiller.hxx> |
19 | #include <BOPAlgo_Section.hxx> |
20 | #include <BOPTest_Objects.hxx> |
338434c7 |
21 | #include <BOPAlgo_CellsBuilder.hxx> |
c58055ad |
22 | #include <BOPAlgo_Splitter.hxx> |
4e57c75e |
23 | #include <NCollection_BaseAllocator.hxx> |
944768d2 |
24 | #include <Precision.hxx> |
4e57c75e |
25 | |
26 | static Handle(NCollection_BaseAllocator)& Allocator1(); |
27 | |
28 | //======================================================================= |
29 | //function : BOPTest_Session |
30 | //purpose : |
31 | //======================================================================= |
32 | class BOPTest_Session { |
33 | public: |
34 | // |
35 | BOPTest_Session() { |
36 | Init(); |
37 | }; |
38 | // |
39 | ~BOPTest_Session(){ |
40 | Clear(); |
41 | }; |
42 | // |
43 | // Init |
44 | void Init() { |
45 | Handle(NCollection_BaseAllocator) pA1, pA2; |
46 | // |
488e5b9d |
47 | pA1=NCollection_BaseAllocator::CommonBaseAllocator(); |
48 | pA2=NCollection_BaseAllocator::CommonBaseAllocator(); |
4e57c75e |
49 | // |
50 | myPaveFiller=new BOPAlgo_PaveFiller(pA1); |
51 | myBuilderDefault=new BOPAlgo_Builder(pA2); |
52 | // |
53 | myBuilder=myBuilderDefault; |
948fe6ca |
54 | SetDefaultOptions(); |
4e57c75e |
55 | }; |
56 | // |
57 | // Clear |
58 | void Clear() { |
59 | if (myPaveFiller) { |
60 | delete myPaveFiller; |
61 | myPaveFiller=NULL; |
62 | } |
63 | // |
64 | if (myBuilderDefault) { |
65 | delete myBuilderDefault; |
66 | myBuilderDefault=NULL; |
67 | } |
68 | }; |
69 | // |
70 | // IsValid |
71 | Standard_Boolean IsValid() const { |
72 | return (myPaveFiller!=NULL); |
73 | } |
74 | // PaveFiller |
75 | BOPAlgo_PaveFiller& PaveFiller() { |
76 | return *myPaveFiller; |
77 | }; |
78 | // |
79 | // Builder |
80 | BOPAlgo_Builder& Builder() { |
81 | return *myBuilder; |
82 | }; |
83 | // |
84 | // SetBuilder |
85 | void SetBuilder(BOPAlgo_Builder* pBuilder) { |
86 | myBuilder=pBuilder; |
87 | }; |
88 | // |
89 | // SetBuilderDef |
90 | void SetBuilderDefault() { |
91 | myBuilder=myBuilderDefault; |
92 | }; |
93 | // |
1155d05a |
94 | TopTools_ListOfShape& Shapes() { |
49b0c452 |
95 | return myShapes; |
96 | } |
97 | // |
1155d05a |
98 | TopTools_ListOfShape& Tools() { |
49b0c452 |
99 | return myTools; |
100 | } |
948fe6ca |
101 | // Resets all options to default values |
102 | void SetDefaultOptions() |
103 | { |
104 | myRunParallel = Standard_False; |
105 | myNonDestructive = Standard_False; |
106 | myFuzzyValue = Precision::Confusion(); |
107 | myGlue = BOPAlgo_GlueOff; |
108 | myDrawWarnShapes = Standard_False; |
109 | myCheckInverted = Standard_True; |
110 | myUseOBB = Standard_False; |
111 | myUnifyEdges = Standard_False; |
112 | myUnifyFaces = Standard_False; |
113 | myAngTol = Precision::Angular(); |
114 | } |
49b0c452 |
115 | // |
116 | void SetRunParallel(const Standard_Boolean bFlag) { |
117 | myRunParallel=bFlag; |
118 | }; |
119 | // |
120 | Standard_Boolean RunParallel()const { |
121 | return myRunParallel; |
122 | }; |
123 | // |
124 | void SetFuzzyValue(const Standard_Real aValue) { |
125 | myFuzzyValue=aValue; |
126 | }; |
127 | // |
128 | Standard_Real FuzzyValue()const { |
129 | return myFuzzyValue; |
130 | }; |
131 | // |
3510db62 |
132 | void SetNonDestructive(const Standard_Boolean theFlag) { |
133 | myNonDestructive = theFlag; |
134 | }; |
135 | // |
136 | Standard_Boolean NonDestructive()const { |
137 | return myNonDestructive; |
138 | }; |
139 | // |
483ce1bd |
140 | void SetGlue(const BOPAlgo_GlueEnum theGlue) { |
141 | myGlue = theGlue; |
142 | }; |
143 | // |
144 | BOPAlgo_GlueEnum Glue() const { |
145 | return myGlue; |
146 | }; |
147 | // |
33ba8565 |
148 | void SetDrawWarnShapes(const Standard_Boolean bDraw) { |
149 | myDrawWarnShapes = bDraw; |
150 | }; |
151 | // |
152 | Standard_Boolean DrawWarnShapes() const { |
153 | return myDrawWarnShapes; |
154 | }; |
155 | // |
98b37659 |
156 | void SetCheckInverted(const Standard_Boolean bCheck) { |
157 | myCheckInverted = bCheck; |
158 | }; |
159 | // |
160 | Standard_Boolean CheckInverted() const { |
161 | return myCheckInverted; |
162 | }; |
163 | // |
944768d2 |
164 | void SetUseOBB(const Standard_Boolean bUse) { |
165 | myUseOBB = bUse; |
166 | }; |
167 | // |
168 | Standard_Boolean UseOBB() const { |
169 | return myUseOBB; |
170 | }; |
948fe6ca |
171 | |
172 | // Controls the Unification of Edges after BOP |
173 | void SetUnifyEdges(const Standard_Boolean bUE) { myUnifyEdges = bUE; } |
174 | // Returns flag of Edges unification |
175 | Standard_Boolean UnifyEdges() const { return myUnifyEdges; } |
176 | |
177 | // Controls the Unification of Faces after BOP |
178 | void SetUnifyFaces(const Standard_Boolean bUF) { myUnifyFaces = bUF; } |
179 | // Returns flag of Faces unification |
180 | Standard_Boolean UnifyFaces() const { return myUnifyFaces; } |
181 | |
182 | // Sets angular tolerance for Edges and Faces unification |
183 | void SetAngular(const Standard_Real theAngTol) { myAngTol = theAngTol; } |
184 | // Returns angular tolerance |
185 | Standard_Real Angular() const { return myAngTol; } |
186 | |
96f3bacc |
187 | protected: |
188 | // |
189 | BOPTest_Session(const BOPTest_Session&); |
190 | BOPTest_Session& operator=(const BOPTest_Session&); |
191 | // |
192 | protected: |
4e57c75e |
193 | // |
194 | BOPAlgo_PaveFiller* myPaveFiller; |
195 | BOPAlgo_Builder* myBuilder; |
196 | BOPAlgo_Builder* myBuilderDefault; |
49b0c452 |
197 | // |
1155d05a |
198 | TopTools_ListOfShape myShapes; |
199 | TopTools_ListOfShape myTools; |
49b0c452 |
200 | Standard_Boolean myRunParallel; |
3510db62 |
201 | Standard_Boolean myNonDestructive; |
49b0c452 |
202 | Standard_Real myFuzzyValue; |
483ce1bd |
203 | BOPAlgo_GlueEnum myGlue; |
33ba8565 |
204 | Standard_Boolean myDrawWarnShapes; |
98b37659 |
205 | Standard_Boolean myCheckInverted; |
944768d2 |
206 | Standard_Boolean myUseOBB; |
948fe6ca |
207 | Standard_Boolean myUnifyEdges; |
208 | Standard_Boolean myUnifyFaces; |
209 | Standard_Real myAngTol; |
4e57c75e |
210 | }; |
211 | // |
212 | //======================================================================= |
213 | //function : GetSession |
214 | //purpose : |
215 | //======================================================================= |
216 | static BOPTest_Session& GetSession() |
217 | { |
218 | static BOPTest_Session* pSession=new BOPTest_Session; |
219 | // |
220 | if (!pSession->IsValid()) { |
221 | pSession->Init(); |
222 | } |
223 | return *pSession; |
224 | } |
225 | // |
226 | //======================================================================= |
227 | //function : Init |
228 | //purpose : |
229 | //======================================================================= |
230 | void BOPTest_Objects::Init() |
231 | { |
232 | GetSession().Init(); |
233 | } |
234 | //======================================================================= |
235 | //function : Clear |
236 | //purpose : |
237 | //======================================================================= |
238 | void BOPTest_Objects::Clear() |
239 | { |
240 | GetSession().Clear(); |
2bc5e8f1 |
241 | Shapes().Clear(); |
242 | Tools().Clear(); |
4e57c75e |
243 | } |
244 | //======================================================================= |
245 | //function : PaveFiller |
246 | //purpose : |
247 | //======================================================================= |
248 | BOPAlgo_PaveFiller& BOPTest_Objects::PaveFiller() |
249 | { |
250 | return GetSession().PaveFiller(); |
251 | } |
252 | //======================================================================= |
253 | //function : PDS |
254 | //purpose : |
255 | //======================================================================= |
256 | BOPDS_PDS BOPTest_Objects::PDS() |
257 | { |
258 | return BOPTest_Objects::PaveFiller().PDS(); |
259 | } |
260 | //======================================================================= |
261 | //function : Builder |
262 | //purpose : |
263 | //======================================================================= |
264 | BOPAlgo_Builder& BOPTest_Objects::Builder() |
265 | { |
266 | return GetSession().Builder(); |
267 | } |
268 | //======================================================================= |
269 | //function : SetBuilder |
270 | //purpose : |
271 | //======================================================================= |
272 | void BOPTest_Objects::SetBuilder(const BOPAlgo_PBuilder& theBuilder) |
273 | { |
274 | BOPAlgo_Builder* pB; |
275 | // |
276 | pB=(BOPAlgo_Builder*)theBuilder; |
277 | GetSession().SetBuilder(pB); |
278 | } |
279 | //======================================================================= |
280 | //function : SetBuilderDefault |
281 | //purpose : |
282 | //======================================================================= |
283 | void BOPTest_Objects::SetBuilderDefault() |
284 | { |
285 | GetSession().SetBuilderDefault(); |
286 | } |
287 | //======================================================================= |
288 | //function : BOP |
289 | //purpose : |
290 | //======================================================================= |
291 | BOPAlgo_BOP& BOPTest_Objects::BOP() |
292 | { |
293 | static BOPAlgo_BOP sBOP(Allocator1()); |
294 | return sBOP; |
295 | } |
296 | //======================================================================= |
85915310 |
297 | //function : Section |
298 | //purpose : |
299 | //======================================================================= |
300 | BOPAlgo_Section& BOPTest_Objects::Section() |
301 | { |
302 | static BOPAlgo_Section sSection(Allocator1()); |
303 | return sSection; |
304 | } |
305 | //======================================================================= |
338434c7 |
306 | //function : CellsBuilder |
307 | //purpose : |
308 | //======================================================================= |
309 | BOPAlgo_CellsBuilder& BOPTest_Objects::CellsBuilder() |
310 | { |
311 | static BOPAlgo_CellsBuilder sCBuilder(Allocator1()); |
312 | return sCBuilder; |
313 | } |
314 | //======================================================================= |
c58055ad |
315 | //function : Splitter |
316 | //purpose : |
317 | //======================================================================= |
318 | BOPAlgo_Splitter& BOPTest_Objects::Splitter() |
319 | { |
320 | static BOPAlgo_Splitter aSplitter(Allocator1()); |
321 | return aSplitter; |
322 | } |
323 | //======================================================================= |
4e57c75e |
324 | //function : Shapes |
325 | //purpose : |
326 | //======================================================================= |
1155d05a |
327 | TopTools_ListOfShape& BOPTest_Objects::Shapes() |
4e57c75e |
328 | { |
49b0c452 |
329 | return GetSession().Shapes(); |
4e57c75e |
330 | } |
331 | //======================================================================= |
332 | //function : Tools |
333 | //purpose : |
334 | //======================================================================= |
1155d05a |
335 | TopTools_ListOfShape& BOPTest_Objects::Tools() |
4e57c75e |
336 | { |
49b0c452 |
337 | return GetSession().Tools(); |
338 | } |
339 | //======================================================================= |
948fe6ca |
340 | //function : SetDefaultOptions |
341 | //purpose : |
342 | //======================================================================= |
343 | void BOPTest_Objects::SetDefaultOptions() |
344 | { |
345 | GetSession().SetDefaultOptions(); |
346 | } |
347 | //======================================================================= |
49b0c452 |
348 | //function : SetRunParallel |
349 | //purpose : |
350 | //======================================================================= |
351 | void BOPTest_Objects::SetRunParallel(const Standard_Boolean bFlag) |
352 | { |
353 | GetSession().SetRunParallel(bFlag); |
354 | } |
355 | //======================================================================= |
356 | //function : RunParallel |
357 | //purpose : |
358 | //======================================================================= |
359 | Standard_Boolean BOPTest_Objects::RunParallel() |
360 | { |
361 | return GetSession().RunParallel(); |
362 | } |
363 | //======================================================================= |
364 | //function : SetFuzzyValue |
365 | //purpose : |
366 | //======================================================================= |
367 | void BOPTest_Objects::SetFuzzyValue(const Standard_Real aValue) |
368 | { |
369 | GetSession().SetFuzzyValue(aValue); |
370 | } |
371 | //======================================================================= |
372 | //function : FuzzyValue |
373 | //purpose : |
374 | //======================================================================= |
375 | Standard_Real BOPTest_Objects::FuzzyValue() |
376 | { |
377 | return GetSession().FuzzyValue(); |
4e57c75e |
378 | } |
379 | //======================================================================= |
3510db62 |
380 | //function : SetNonDestructive |
381 | //purpose : |
382 | //======================================================================= |
383 | void BOPTest_Objects::SetNonDestructive(const Standard_Boolean theFlag) |
384 | { |
385 | GetSession().SetNonDestructive(theFlag); |
386 | } |
387 | //======================================================================= |
388 | //function : NonDestructive |
389 | //purpose : |
390 | //======================================================================= |
391 | Standard_Boolean BOPTest_Objects::NonDestructive() |
392 | { |
393 | return GetSession().NonDestructive(); |
394 | } |
395 | //======================================================================= |
483ce1bd |
396 | //function : SetGlue |
397 | //purpose : |
398 | //======================================================================= |
399 | void BOPTest_Objects::SetGlue(const BOPAlgo_GlueEnum theGlue) |
400 | { |
401 | GetSession().SetGlue(theGlue); |
402 | } |
403 | //======================================================================= |
404 | //function : Glue |
405 | //purpose : |
406 | //======================================================================= |
407 | BOPAlgo_GlueEnum BOPTest_Objects::Glue() |
408 | { |
409 | return GetSession().Glue(); |
410 | } |
411 | //======================================================================= |
33ba8565 |
412 | //function : SetDrawWarnShapes |
413 | //purpose : |
414 | //======================================================================= |
415 | void BOPTest_Objects::SetDrawWarnShapes(const Standard_Boolean bDraw) |
416 | { |
417 | GetSession().SetDrawWarnShapes(bDraw); |
418 | } |
419 | //======================================================================= |
420 | //function : DrawWarnShapes |
421 | //purpose : |
422 | //======================================================================= |
423 | Standard_Boolean BOPTest_Objects::DrawWarnShapes() |
424 | { |
425 | return GetSession().DrawWarnShapes(); |
426 | } |
427 | //======================================================================= |
98b37659 |
428 | //function : SetCheckInverted |
429 | //purpose : |
430 | //======================================================================= |
431 | void BOPTest_Objects::SetCheckInverted(const Standard_Boolean bCheck) |
432 | { |
433 | GetSession().SetCheckInverted(bCheck); |
434 | } |
435 | //======================================================================= |
436 | //function : CheckInverted |
437 | //purpose : |
438 | //======================================================================= |
439 | Standard_Boolean BOPTest_Objects::CheckInverted() |
440 | { |
441 | return GetSession().CheckInverted(); |
442 | } |
443 | //======================================================================= |
944768d2 |
444 | //function : SetUseOBB |
445 | //purpose : |
446 | //======================================================================= |
447 | void BOPTest_Objects::SetUseOBB(const Standard_Boolean bUseOBB) |
448 | { |
449 | GetSession().SetUseOBB(bUseOBB); |
450 | } |
451 | //======================================================================= |
452 | //function : UseOBB |
453 | //purpose : |
454 | //======================================================================= |
455 | Standard_Boolean BOPTest_Objects::UseOBB() |
456 | { |
457 | return GetSession().UseOBB(); |
458 | } |
459 | //======================================================================= |
948fe6ca |
460 | //function : SetUnifyEdges |
461 | //purpose : |
462 | //======================================================================= |
463 | void BOPTest_Objects::SetUnifyEdges(const Standard_Boolean bUE) |
464 | { |
465 | GetSession().SetUnifyEdges(bUE); |
466 | } |
467 | //======================================================================= |
468 | //function : UnifyEdges |
469 | //purpose : |
470 | //======================================================================= |
471 | Standard_Boolean BOPTest_Objects::UnifyEdges() |
472 | { |
473 | return GetSession().UnifyEdges(); |
474 | } |
475 | //======================================================================= |
476 | //function : SetUnifyFaces |
477 | //purpose : |
478 | //======================================================================= |
479 | void BOPTest_Objects::SetUnifyFaces(const Standard_Boolean bUF) |
480 | { |
481 | GetSession().SetUnifyFaces(bUF); |
482 | } |
483 | //======================================================================= |
484 | //function : UnifyFaces |
485 | //purpose : |
486 | //======================================================================= |
487 | Standard_Boolean BOPTest_Objects::UnifyFaces() |
488 | { |
489 | return GetSession().UnifyFaces(); |
490 | } |
491 | //======================================================================= |
492 | //function : SetAngular |
493 | //purpose : |
494 | //======================================================================= |
495 | void BOPTest_Objects::SetAngular(const Standard_Real theAngTol) |
496 | { |
497 | GetSession().SetAngular(theAngTol); |
498 | } |
499 | //======================================================================= |
500 | //function : Angular |
501 | //purpose : |
502 | //======================================================================= |
503 | Standard_Real BOPTest_Objects::Angular() |
504 | { |
505 | return GetSession().Angular(); |
506 | } |
507 | //======================================================================= |
4e57c75e |
508 | //function : Allocator1 |
509 | //purpose : |
510 | //======================================================================= |
511 | Handle(NCollection_BaseAllocator)& Allocator1() |
512 | { |
513 | static Handle(NCollection_BaseAllocator) sAL1= |
488e5b9d |
514 | NCollection_BaseAllocator::CommonBaseAllocator(); |
4e57c75e |
515 | return sAL1; |
516 | } |