0028786: Refactoring of the Warning/Error reporting system of Boolean Operations...
[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**);
49b0c452 30
31//=======================================================================
32//function : OptionCommands
33//purpose :
34//=======================================================================
35void BOPTest::OptionCommands(Draw_Interpretor& theCommands)
36{
37 static Standard_Boolean done = Standard_False;
38 if (done) return;
39 done = Standard_True;
40 // Chapter's name
43cb0011 41 const char* g = "BOPTest commands";
49b0c452 42 // Commands
3510db62 43 theCommands.Add("boptions", "use boptions, shows current value of BOP options" , __FILE__, boptions, g);
49b0c452 44 theCommands.Add("brunparallel", "use brunparallel [0/1]" , __FILE__, brunparallel, g);
3510db62 45 theCommands.Add("bnondestructive", "use bnondestructive [0/1]", __FILE__, bnondestructive, g);
46 theCommands.Add("bfuzzyvalue", "use bfuzzyvalue value", __FILE__, bfuzzyvalue, g);
483ce1bd 47 theCommands.Add("bglue", "use bglue [0 (off) / 1 (shift) / 2 (full)]", __FILE__, bGlue, g);
33ba8565 48 theCommands.Add("bdrawwarnshapes", "Defines whether to draw warning shapes or not\n"
49 "Usage: bdrawwarnshapes [0 (do not draw) / 1 (draw warning shapes)",
50 __FILE__, bdrawwarnshapes, g);
49b0c452 51}
52//=======================================================================
53//function : boptions
54//purpose :
55//=======================================================================
56Standard_Integer boptions(Draw_Interpretor& di,
57 Standard_Integer n,
58 const char** )
59{
60 if (n!=1) {
61 di << " use boptions\n";
62 return 0;
63 }
64 //
65 char buf[128];
3510db62 66 Standard_Boolean bRunParallel, bNonDestructive;
49b0c452 67 Standard_Real aFuzzyValue;
483ce1bd 68 BOPAlgo_GlueEnum aGlue;
49b0c452 69 //
70 bRunParallel=BOPTest_Objects::RunParallel();
3510db62 71 bNonDestructive = BOPTest_Objects::NonDestructive();
72 aFuzzyValue = BOPTest_Objects::FuzzyValue();
483ce1bd 73 aGlue = BOPTest_Objects::Glue();
33ba8565 74 Standard_Boolean bDrawWarnShapes = BOPTest_Objects::DrawWarnShapes();
483ce1bd 75 //
49b0c452 76 Sprintf(buf, " RunParallel: %d\n", bRunParallel);
77 di << buf;
3510db62 78 Sprintf(buf, " NonDestructive: %d\n", bNonDestructive);
79 di << buf;
483ce1bd 80 Sprintf(buf, " FuzzyValue: %lf\n", aFuzzyValue);
81 di << buf;
82 Sprintf(buf, " GlueOption: %s\n", ((aGlue == BOPAlgo_GlueOff) ? "Off" :
83 ((aGlue == BOPAlgo_GlueFull) ? "Full" : "Shift")));
49b0c452 84 di << buf;
33ba8565 85 Sprintf(buf, " Draw Warning Shapes: %s\n", bDrawWarnShapes ? "Yes" : "No");
86 di << buf;
49b0c452 87 //
88 return 0;
89}
90//=======================================================================
91//function : bfuzzyvalue
92//purpose :
93//=======================================================================
94Standard_Integer bfuzzyvalue(Draw_Interpretor& di,
95 Standard_Integer n,
96 const char** a)
97{
98 if (n!=2) {
99 di << " use bfuzzyvalue value\n";
100 return 0;
101 }
102 //
103 Standard_Real aFuzzyValue;
104 //
105 aFuzzyValue=Draw::Atof(a[1]);
106 if (aFuzzyValue<0.) {
107 di << " Wrong value.\n";
108 return 0;
109 }
110 //
111 BOPTest_Objects::SetFuzzyValue(aFuzzyValue);
112 //
113 return 0;
114}
115//=======================================================================
116//function : brunparallel
117//purpose :
118//=======================================================================
119Standard_Integer brunparallel(Draw_Interpretor& di,
120 Standard_Integer n,
121 const char** a)
122{
123 if (n!=2) {
124 di << " use brunparallel [0/1]\n";
125 return 0;
126 }
127 //
128 Standard_Integer iX;
129 Standard_Boolean bRunParallel;
130 //
131 iX=Draw::Atoi(a[1]);
132 if (iX<0 || iX>1) {
133 di << " Wrong value.\n";
134 return 0;
135 }
136 //
dde68833 137 bRunParallel = (iX != 0);
49b0c452 138 BOPTest_Objects::SetRunParallel(bRunParallel);
139 //
140 return 0;
141}
43cb0011 142//=======================================================================
3510db62 143//function : bnondestructive
43cb0011 144//purpose :
145//=======================================================================
3510db62 146Standard_Integer bnondestructive(Draw_Interpretor& di,
147 Standard_Integer n,
148 const char** a)
43cb0011 149{
3510db62 150 if (n != 2) {
151 di << " use bnondestructive [0/1]\n";
152 return 0;
43cb0011 153 }
3510db62 154 //
155 Standard_Integer iX;
156 Standard_Boolean bNonDestructive;
157 //
158 iX = Draw::Atoi(a[1]);
159 if (iX<0 || iX>1) {
160 di << " Wrong value.\n";
161 return 0;
43cb0011 162 }
3510db62 163 //
dde68833 164 bNonDestructive = (iX != 0);
3510db62 165 BOPTest_Objects::SetNonDestructive(bNonDestructive);
166 //
43cb0011 167 return 0;
168}
483ce1bd 169
170//=======================================================================
171//function : bglue
172//purpose :
173//=======================================================================
174Standard_Integer bGlue(Draw_Interpretor& di,
175 Standard_Integer n,
176 const char** a)
177{
178 if (n != 2) {
179 di << " use bglue [0 (off) / 1 (shift) / 2 (full)]\n";
180 return 1;
181 }
182 //
183 Standard_Integer iGlue = Draw::Atoi(a[1]);
184 if (iGlue < 0 || iGlue > 2) {
185 di << " Wrong value. Use bglue [0 (off) / 1 (shift) / 2 (full)]\n";
186 return 1;
187 }
188 //
189 BOPAlgo_GlueEnum aGlue = BOPAlgo_GlueEnum(iGlue);
190 BOPTest_Objects::SetGlue(aGlue);
191 //
192 return 0;
193}
33ba8565 194
195//=======================================================================
196//function : bdrawwarnshapes
197//purpose :
198//=======================================================================
199Standard_Integer bdrawwarnshapes(Draw_Interpretor& di,
200 Standard_Integer n,
201 const char** a)
202{
203 if (n != 2) {
204 di << " use bdrawwarnshapes [0 (do not draw) / 1 (draw warning shapes)\n";
205 return 1;
206 }
207 //
208 Standard_Integer iDraw = Draw::Atoi(a[1]);
209 BOPTest_Objects::SetDrawWarnShapes(iDraw != 0);
210 return 0;
211}