0027031: Samples - fix compilation issues in java/jniviewer sample
[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
21 #include <stdio.h>
22 #include <string.h>
23 static Standard_Integer boptions (Draw_Interpretor&, Standard_Integer, const char**); 
24 static Standard_Integer brunparallel (Draw_Interpretor&, Standard_Integer, const char**); 
25 static Standard_Integer bfuzzyvalue (Draw_Interpretor&, Standard_Integer, const char**); 
26 static Standard_Integer bparallelmode(Draw_Interpretor&, Standard_Integer, const char**);
27
28 //=======================================================================
29 //function : OptionCommands
30 //purpose  : 
31 //=======================================================================
32 void BOPTest::OptionCommands(Draw_Interpretor& theCommands)
33 {
34   static Standard_Boolean done = Standard_False;
35   if (done) return;
36   done = Standard_True;
37   // Chapter's name
38   const char* g = "BOPTest commands";
39   // Commands  
40   theCommands.Add("boptions", "use boptions" , __FILE__, boptions, g);
41   theCommands.Add("brunparallel", "use brunparallel [0/1]" , __FILE__, brunparallel, g);
42   theCommands.Add("bfuzzyvalue", "use bfuzzyvalue value" , __FILE__, bfuzzyvalue, g);
43   theCommands.Add("bparallelmode", 
44     "bparallelmode [1/0] : show / set parallel mode for boolean operations", 
45                   __FILE__, bparallelmode, g);
46
47 }
48 //=======================================================================
49 //function : boptions
50 //purpose  : 
51 //=======================================================================
52 Standard_Integer boptions(Draw_Interpretor& di,
53                           Standard_Integer n, 
54                           const char** ) 
55
56   if (n!=1) {
57     di << " use boptions\n";
58     return 0;
59   }
60   //
61   char buf[128];
62   Standard_Boolean bRunParallel;
63   Standard_Real aFuzzyValue;
64   //
65   bRunParallel=BOPTest_Objects::RunParallel();
66   aFuzzyValue=BOPTest_Objects::FuzzyValue();
67   
68   Sprintf(buf, " RunParallel: %d\n",  bRunParallel);
69   di << buf;
70   Sprintf(buf, " FuzzyValue : %lf\n", aFuzzyValue);
71   di << buf;
72   //
73   return 0;
74 }
75 //=======================================================================
76 //function : bfuzzyvalue
77 //purpose  : 
78 //=======================================================================
79 Standard_Integer bfuzzyvalue(Draw_Interpretor& di,
80                              Standard_Integer n, 
81                              const char** a) 
82
83   if (n!=2) {
84     di << " use bfuzzyvalue value\n";
85     return 0;
86   }
87   //
88   Standard_Real aFuzzyValue;
89   //
90   aFuzzyValue=Draw::Atof(a[1]);
91   if (aFuzzyValue<0.) {
92     di << " Wrong value.\n"; 
93     return 0;  
94   }
95   //
96   BOPTest_Objects::SetFuzzyValue(aFuzzyValue);
97   //
98   return 0;
99 }
100 //=======================================================================
101 //function : brunparallel
102 //purpose  : 
103 //=======================================================================
104 Standard_Integer brunparallel(Draw_Interpretor& di,
105                               Standard_Integer n, 
106                               const char** a) 
107
108   if (n!=2) {
109     di << " use brunparallel [0/1]\n";
110     return 0;
111   }
112   //
113   Standard_Integer iX;
114   Standard_Boolean bRunParallel;
115   //
116   iX=Draw::Atoi(a[1]);
117   if (iX<0 || iX>1) {
118     di << " Wrong value.\n"; 
119     return 0;  
120   }
121   //
122   bRunParallel=(Standard_Boolean)(iX);
123   BOPTest_Objects::SetRunParallel(bRunParallel);
124   //
125   return 0;
126 }
127 //=======================================================================
128 //function : bparallelmode
129 //purpose  : 
130 //=======================================================================
131 Standard_Integer bparallelmode(Draw_Interpretor& di, 
132                                Standard_Integer n, 
133                                const char** a)
134 {
135   Standard_Boolean bRunParallel;
136   //
137   if (n == 2)  {
138     bRunParallel=(Standard_Boolean)Draw::Atoi(a[1]);
139     BOPTest_Objects::SetRunParallel(bRunParallel);
140     if (bRunParallel) {
141       di << "Parallel mode for boolean operations has been enabled";
142     }
143     else  {
144       di << "Parallel mode for boolean operations has been disabled";
145     }
146   }
147   else  {
148     bRunParallel=BOPTest_Objects::RunParallel();
149     di << "Parallel mode state for boolean operations: " 
150       << (bRunParallel? "enabled" : "disabled");
151   }
152   return 0;
153 }