0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BOPTest / BOPTest_OptionCommands.cxx
CommitLineData
49b0c452 1// Created by: Peter KURNEV
2// Copyright (c) 2014 OPEN CASCADE SAS
3//
4// This file is part of Open CASCADE Technology software library.
5//
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
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.
11//
12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
14
49b0c452 15
42cf5bc1 16#include <BOPTest.hxx>
17#include <BOPTest_Objects.hxx>
49b0c452 18#include <DBRep.hxx>
19#include <Draw.hxx>
483ce1bd 20#include <BOPAlgo_GlueEnum.hxx>
49b0c452 21
42cf5bc1 22#include <stdio.h>
23#include <string.h>
49b0c452 24static Standard_Integer boptions (Draw_Interpretor&, Standard_Integer, const char**);
25static Standard_Integer brunparallel (Draw_Interpretor&, Standard_Integer, const char**);
3510db62 26static Standard_Integer bnondestructive(Draw_Interpretor&, Standard_Integer, const char**);
27static Standard_Integer bfuzzyvalue(Draw_Interpretor&, Standard_Integer, const char**);
483ce1bd 28static Standard_Integer bGlue(Draw_Interpretor&, Standard_Integer, const char**);
33ba8565 29static Standard_Integer bdrawwarnshapes(Draw_Interpretor&, Standard_Integer, const char**);
98b37659 30static Standard_Integer bcheckinverted(Draw_Interpretor&, Standard_Integer, const char**);
944768d2 31static Standard_Integer buseobb(Draw_Interpretor&, Standard_Integer, const char**);
948fe6ca 32static Standard_Integer bsimplify(Draw_Interpretor&, Standard_Integer, const char**);
49b0c452 33
34//=======================================================================
35//function : OptionCommands
36//purpose :
37//=======================================================================
38void BOPTest::OptionCommands(Draw_Interpretor& theCommands)
39{
40 static Standard_Boolean done = Standard_False;
41 if (done) return;
42 done = Standard_True;
43 // Chapter's name
43cb0011 44 const char* g = "BOPTest commands";
49b0c452 45 // Commands
948fe6ca 46 theCommands.Add("boptions", "Usage: boptions [-default]\n"
47 "\t\tw/o arguments shows current value of BOP options\n"
48 "\t\t-default - allows setting all options to default values",
49 __FILE__, boptions, g);
50
51 theCommands.Add("brunparallel", "Enables/Disables parallel processing mode.\n"
52 "\t\tUsage: brunparallel 0/1",
53 __FILE__, brunparallel, g);
54
55 theCommands.Add("bnondestructive", "Enables/Disables the safe processing mode.\n"
56 "\t\tUsage: bnondestructive 0/1",
57 __FILE__, bnondestructive, g);
58
59 theCommands.Add("bfuzzyvalue", "Sets the additional tolerance for BOP algorithms.\n"
60 "\t\tUsage: bfuzzyvalue value",
61 __FILE__, bfuzzyvalue, g);
62
63 theCommands.Add("bglue", "Sets the gluing mode for the BOP algorithms.\n"
64 "\t\tUsage: bglue [0 (off) / 1 (shift) / 2 (full)]",
65 __FILE__, bGlue, g);
66
67 theCommands.Add("bdrawwarnshapes", "Enables/Disables drawing of waring shapes of BOP algorithms.\n"
68 "\t\tUsage: bdrawwarnshapes 0 (do not draw) / 1 (draw warning shapes)",
33ba8565 69 __FILE__, bdrawwarnshapes, g);
948fe6ca 70
71 theCommands.Add("bcheckinverted", "Enables/Disables the check of the input solids on inverted status in BOP algorithms\n"
72 "\t\tUsage: bcheckinverted 0 (off) / 1 (on)",
73 __FILE__, bcheckinverted, g);
74
75 theCommands.Add("buseobb", "Enables/disables the usage of OBB in BOP algorithms\n"
76 "\t\tUsage: buseobb 0 (off) / 1 (on)",
77 __FILE__, buseobb, g);
78
79 theCommands.Add("bsimplify", "Enables/Disables the result simplification after BOP\n"
80 "\t\tUsage: bsimplify [-e 0/1] [-f 0/1] [-a tol]\n"
81 "\t\t-e 0/1 - enables/disables edges unification\n"
82 "\t\t-f 0/1 - enables/disables faces unification\n"
83 "\t\t-a tol - changes default angular tolerance of unification algo (accepts value in degrees).",
84 __FILE__, bsimplify, g);
49b0c452 85}
86//=======================================================================
87//function : boptions
88//purpose :
89//=======================================================================
90Standard_Integer boptions(Draw_Interpretor& di,
91 Standard_Integer n,
948fe6ca 92 const char** a)
49b0c452 93{
948fe6ca 94 if (n > 2)
95 {
96 di.PrintHelp(a[0]);
97 return 1;
98 }
99
100 if (n == 2)
101 {
102 if (strcmp(a[1], "-default"))
103 {
104 di.PrintHelp(a[0]);
105 return 1;
106 }
107
108 // Set all options to default values
109 BOPTest_Objects::SetDefaultOptions();
49b0c452 110 return 0;
111 }
112 //
113 char buf[128];
948fe6ca 114 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
49b0c452 115 //
948fe6ca 116 Sprintf(buf, " RunParallel: %s \t\t(%s)\n", BOPTest_Objects::RunParallel() ? "Yes" : "No",
117 "use \"brunparallel\" command to change");
118 di << buf;
119 Sprintf(buf, " NonDestructive: %s \t\t(%s)\n", BOPTest_Objects::NonDestructive() ? "Yes" : "No",
120 "use \"bnondestructive\" command to change");
121 di << buf;
122 Sprintf(buf, " FuzzyValue: %g \t\t(%s)\n", BOPTest_Objects::FuzzyValue(),
123 "use \"bfuzzyvalue\" command to change");
49b0c452 124 di << buf;
948fe6ca 125 Sprintf(buf, " GlueOption: %s \t\t(%s)\n", ((aGlue == BOPAlgo_GlueOff) ? "Off" :
126 ((aGlue == BOPAlgo_GlueFull) ? "Full" : "Shift")),
127 "use \"bglue\" command to change");
3510db62 128 di << buf;
948fe6ca 129 Sprintf(buf, " Draw Warning Shapes: %s \t(%s)\n", BOPTest_Objects::DrawWarnShapes() ? "Yes" : "No",
130 "use \"bdrawwarnshapes\" command to change");
483ce1bd 131 di << buf;
948fe6ca 132 Sprintf(buf, " Check for invert solids: %s \t(%s)\n", BOPTest_Objects::CheckInverted() ? "Yes" : "No",
133 "use \"bcheckinverted\" command to change");
49b0c452 134 di << buf;
948fe6ca 135 Sprintf(buf, " Use OBB: %s \t\t\t(%s)\n", BOPTest_Objects::UseOBB() ? "Yes" : "No",
136 "use \"buseobb\" command to change");
33ba8565 137 di << buf;
948fe6ca 138 Sprintf(buf, " Unify Edges: %s \t\t(%s)\n", BOPTest_Objects::UnifyEdges() ? "Yes" : "No",
139 "use \"bsimplify -e\" command to change");
98b37659 140 di << buf;
948fe6ca 141 Sprintf(buf, " Unify Faces: %s \t\t(%s)\n", BOPTest_Objects::UnifyFaces() ? "Yes" : "No",
142 "use \"bsimplify -f\" command to change");
143 di << buf;
144 Sprintf(buf, " Angular: %g \t\t(%s)\n", BOPTest_Objects::Angular(),
145 "use \"bsimplify -a\" command to change");
944768d2 146 di << buf;
49b0c452 147 //
148 return 0;
149}
150//=======================================================================
151//function : bfuzzyvalue
152//purpose :
153//=======================================================================
154Standard_Integer bfuzzyvalue(Draw_Interpretor& di,
155 Standard_Integer n,
156 const char** a)
948fe6ca 157{
158 if (n != 2)
159 {
160 di.PrintHelp(a[0]);
161 return 1;
49b0c452 162 }
948fe6ca 163
164 Standard_Real aFuzzyValue = Draw::Atof(a[1]);
49b0c452 165 BOPTest_Objects::SetFuzzyValue(aFuzzyValue);
49b0c452 166 return 0;
167}
168//=======================================================================
169//function : brunparallel
170//purpose :
171//=======================================================================
172Standard_Integer brunparallel(Draw_Interpretor& di,
948fe6ca 173 Standard_Integer n,
174 const char** a)
175{
176 if (n != 2)
177 {
178 di.PrintHelp(a[0]);
179 return 1;
49b0c452 180 }
948fe6ca 181
182 Standard_Integer iRunParallel = Draw::Atoi(a[1]);
183 BOPTest_Objects::SetRunParallel(iRunParallel != 0);
49b0c452 184 return 0;
185}
43cb0011 186//=======================================================================
3510db62 187//function : bnondestructive
43cb0011 188//purpose :
189//=======================================================================
3510db62 190Standard_Integer bnondestructive(Draw_Interpretor& di,
948fe6ca 191 Standard_Integer n,
192 const char** a)
43cb0011 193{
948fe6ca 194 if (n != 2)
195 {
196 di.PrintHelp(a[0]);
197 return 1;
43cb0011 198 }
948fe6ca 199
200 Standard_Integer iNonDestructive = Draw::Atoi(a[1]);
201 BOPTest_Objects::SetNonDestructive(iNonDestructive != 0);
43cb0011 202 return 0;
203}
483ce1bd 204
205//=======================================================================
206//function : bglue
207//purpose :
208//=======================================================================
209Standard_Integer bGlue(Draw_Interpretor& di,
948fe6ca 210 Standard_Integer n,
211 const char** a)
483ce1bd 212{
948fe6ca 213 if (n != 2)
214 {
215 di.PrintHelp(a[0]);
483ce1bd 216 return 1;
217 }
948fe6ca 218
483ce1bd 219 Standard_Integer iGlue = Draw::Atoi(a[1]);
948fe6ca 220 if (iGlue < 0 || iGlue > 2)
221 {
222 di << "Wrong value.\n";
223 di.PrintHelp(a[0]);
483ce1bd 224 return 1;
225 }
948fe6ca 226
483ce1bd 227 BOPAlgo_GlueEnum aGlue = BOPAlgo_GlueEnum(iGlue);
228 BOPTest_Objects::SetGlue(aGlue);
483ce1bd 229 return 0;
230}
33ba8565 231
232//=======================================================================
233//function : bdrawwarnshapes
234//purpose :
235//=======================================================================
236Standard_Integer bdrawwarnshapes(Draw_Interpretor& di,
948fe6ca 237 Standard_Integer n,
238 const char** a)
33ba8565 239{
948fe6ca 240 if (n != 2)
241 {
242 di.PrintHelp(a[0]);
33ba8565 243 return 1;
244 }
948fe6ca 245
33ba8565 246 Standard_Integer iDraw = Draw::Atoi(a[1]);
247 BOPTest_Objects::SetDrawWarnShapes(iDraw != 0);
248 return 0;
249}
98b37659 250
251//=======================================================================
252//function : bcheckinverted
253//purpose :
254//=======================================================================
255Standard_Integer bcheckinverted(Draw_Interpretor& di,
256 Standard_Integer n,
257 const char** a)
258{
948fe6ca 259 if (n != 2)
260 {
98b37659 261 di.PrintHelp(a[0]);
262 return 1;
263 }
948fe6ca 264
98b37659 265 Standard_Integer iCheck = Draw::Atoi(a[1]);
266 BOPTest_Objects::SetCheckInverted(iCheck != 0);
267 return 0;
268}
944768d2 269
270//=======================================================================
271//function : buseobb
272//purpose :
273//=======================================================================
274Standard_Integer buseobb(Draw_Interpretor& di,
275 Standard_Integer n,
276 const char** a)
277{
278 if (n != 2)
279 {
280 di.PrintHelp(a[0]);
281 return 1;
282 }
948fe6ca 283
944768d2 284 Standard_Integer iUse = Draw::Atoi(a[1]);
285 BOPTest_Objects::SetUseOBB(iUse != 0);
286 return 0;
287}
948fe6ca 288
289//=======================================================================
290//function : bsimplify
291//purpose :
292//=======================================================================
293Standard_Integer bsimplify(Draw_Interpretor& di,
294 Standard_Integer n,
295 const char** a)
296{
297 if (n == 1 || n%2 == 0)
298 {
299 di.PrintHelp(a[0]);
300 return 1;
301 }
302
303 for (Standard_Integer i = 1; i < n - 1; ++i)
304 {
305 if (!strcmp(a[i], "-e"))
306 {
307 Standard_Integer iUnifyEdges = Draw::Atoi(a[++i]);
308 BOPTest_Objects::SetUnifyEdges(iUnifyEdges != 0);
309 }
310 else if (!strcmp(a[i], "-f"))
311 {
312 Standard_Integer iUnifyFaces = Draw::Atoi(a[++i]);
313 BOPTest_Objects::SetUnifyFaces(iUnifyFaces != 0);
314 }
315 else if (!strcmp(a[i], "-a"))
316 {
317 Standard_Real anAngTol = Draw::Atof(a[++i]) * (M_PI / 180.0);
318 BOPTest_Objects::SetAngular(anAngTol);
319 }
320 else
321 {
322 di << "Wrong key option.\n";
323 di.PrintHelp(a[0]);
324 return 1;
325 }
326 }
327 return 0;
328}