0031642: Visualization - crash in Graphic3d_Structure::SetVisual() on redisplaying...
[occt.git] / src / BOPTest / BOPTest_OptionCommands.cxx
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
15
16 #include <BOPTest.hxx>
17 #include <BOPTest_Objects.hxx>
18 #include <DBRep.hxx>
19 #include <Draw.hxx>
20 #include <BOPAlgo_GlueEnum.hxx>
21
22 #include <stdio.h>
23 #include <string.h>
24 static Standard_Integer boptions (Draw_Interpretor&, Standard_Integer, const char**); 
25 static Standard_Integer brunparallel (Draw_Interpretor&, Standard_Integer, const char**); 
26 static Standard_Integer bnondestructive(Draw_Interpretor&, Standard_Integer, const char**);
27 static Standard_Integer bfuzzyvalue(Draw_Interpretor&, Standard_Integer, const char**);
28 static Standard_Integer bGlue(Draw_Interpretor&, Standard_Integer, const char**);
29 static Standard_Integer bdrawwarnshapes(Draw_Interpretor&, Standard_Integer, const char**);
30 static Standard_Integer bcheckinverted(Draw_Interpretor&, Standard_Integer, const char**);
31 static Standard_Integer buseobb(Draw_Interpretor&, Standard_Integer, const char**);
32 static Standard_Integer bsimplify(Draw_Interpretor&, Standard_Integer, const char**);
33
34 //=======================================================================
35 //function : OptionCommands
36 //purpose  : 
37 //=======================================================================
38 void 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
44   const char* g = "BOPTest commands";
45   // Commands  
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)",
69                   __FILE__, bdrawwarnshapes, g);
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);
85 }
86 //=======================================================================
87 //function : boptions
88 //purpose  : 
89 //=======================================================================
90 Standard_Integer boptions(Draw_Interpretor& di,
91                           Standard_Integer n, 
92                           const char** a) 
93
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();
110     return 0;
111   }
112   //
113   char buf[128];
114   BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
115   //
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");
124   di << buf;
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");
128   di << buf;
129   Sprintf(buf, " Draw Warning Shapes: %s \t(%s)\n", BOPTest_Objects::DrawWarnShapes() ? "Yes" : "No",
130                "use \"bdrawwarnshapes\" command to change");
131   di << buf;
132   Sprintf(buf, " Check for invert solids: %s \t(%s)\n", BOPTest_Objects::CheckInverted() ? "Yes" : "No",
133                "use \"bcheckinverted\" command to change");
134   di << buf;
135   Sprintf(buf, " Use OBB: %s \t\t\t(%s)\n", BOPTest_Objects::UseOBB() ? "Yes" : "No",
136                "use \"buseobb\" command to change");
137   di << buf;
138   Sprintf(buf, " Unify Edges: %s \t\t(%s)\n", BOPTest_Objects::UnifyEdges() ? "Yes" : "No",
139                "use \"bsimplify -e\" command to change");
140   di << buf;
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");
146   di << buf;
147   //
148   return 0;
149 }
150 //=======================================================================
151 //function : bfuzzyvalue
152 //purpose  : 
153 //=======================================================================
154 Standard_Integer bfuzzyvalue(Draw_Interpretor& di,
155                              Standard_Integer n, 
156                              const char** a) 
157 {
158   if (n != 2)
159   {
160     di.PrintHelp(a[0]);
161     return 1;
162   }
163
164   Standard_Real aFuzzyValue = Draw::Atof(a[1]);
165   BOPTest_Objects::SetFuzzyValue(aFuzzyValue);
166   return 0;
167 }
168 //=======================================================================
169 //function : brunparallel
170 //purpose  : 
171 //=======================================================================
172 Standard_Integer brunparallel(Draw_Interpretor& di,
173                               Standard_Integer n,
174                               const char** a)
175 {
176   if (n != 2)
177   {
178     di.PrintHelp(a[0]);
179     return 1;
180   }
181
182   Standard_Integer iRunParallel = Draw::Atoi(a[1]);
183   BOPTest_Objects::SetRunParallel(iRunParallel != 0);
184   return 0;
185 }
186 //=======================================================================
187 //function : bnondestructive
188 //purpose  : 
189 //=======================================================================
190 Standard_Integer bnondestructive(Draw_Interpretor& di,
191                                  Standard_Integer n,
192                                  const char** a)
193 {
194   if (n != 2)
195   {
196     di.PrintHelp(a[0]);
197     return 1;
198   }
199
200   Standard_Integer iNonDestructive = Draw::Atoi(a[1]);
201   BOPTest_Objects::SetNonDestructive(iNonDestructive != 0);
202   return 0;
203 }
204
205 //=======================================================================
206 //function : bglue
207 //purpose  : 
208 //=======================================================================
209 Standard_Integer bGlue(Draw_Interpretor& di,
210                        Standard_Integer n,
211                        const char** a)
212 {
213   if (n != 2)
214   {
215     di.PrintHelp(a[0]);
216     return 1;
217   }
218
219   Standard_Integer iGlue = Draw::Atoi(a[1]);
220   if (iGlue < 0 || iGlue > 2)
221   {
222     di << "Wrong value.\n";
223     di.PrintHelp(a[0]);
224     return 1;
225   }
226
227   BOPAlgo_GlueEnum aGlue = BOPAlgo_GlueEnum(iGlue);
228   BOPTest_Objects::SetGlue(aGlue);
229   return 0;
230 }
231
232 //=======================================================================
233 //function : bdrawwarnshapes
234 //purpose  : 
235 //=======================================================================
236 Standard_Integer bdrawwarnshapes(Draw_Interpretor& di,
237                               Standard_Integer n,
238                               const char** a)
239
240   if (n != 2)
241   {
242     di.PrintHelp(a[0]);
243     return 1;
244   }
245
246   Standard_Integer iDraw = Draw::Atoi(a[1]);
247   BOPTest_Objects::SetDrawWarnShapes(iDraw != 0);
248   return 0;
249 }
250
251 //=======================================================================
252 //function : bcheckinverted
253 //purpose  : 
254 //=======================================================================
255 Standard_Integer bcheckinverted(Draw_Interpretor& di,
256                                 Standard_Integer n,
257                                 const char** a)
258 {
259   if (n != 2)
260   {
261     di.PrintHelp(a[0]);
262     return 1;
263   }
264
265   Standard_Integer iCheck = Draw::Atoi(a[1]);
266   BOPTest_Objects::SetCheckInverted(iCheck != 0);
267   return 0;
268 }
269
270 //=======================================================================
271 //function : buseobb
272 //purpose  : 
273 //=======================================================================
274 Standard_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   }
283
284   Standard_Integer iUse = Draw::Atoi(a[1]);
285   BOPTest_Objects::SetUseOBB(iUse != 0);
286   return 0;
287 }
288
289 //=======================================================================
290 //function : bsimplify
291 //purpose  : 
292 //=======================================================================
293 Standard_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 }