0027031: Samples - fix compilation issues in java/jniviewer sample
[occt.git] / src / BOPTest / BOPTest_PartitionCommands.cxx
CommitLineData
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//
0a36ca0a 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>
4e57c75e 17#include <BOPAlgo_Builder.hxx>
4e57c75e 18#include <BOPAlgo_Operation.hxx>
42cf5bc1 19#include <BOPAlgo_PaveFiller.hxx>
85915310 20#include <BOPAlgo_Section.hxx>
42cf5bc1 21#include <BOPTest.hxx>
4e57c75e 22#include <BOPTest_DrawableShape.hxx>
23#include <BOPTest_Objects.hxx>
42cf5bc1 24#include <DBRep.hxx>
25#include <Draw.hxx>
26#include <Draw_Color.hxx>
27#include <DrawTrSurf.hxx>
c7b59798 28#include <OSD_Timer.hxx>
42cf5bc1 29#include <TopoDS_Shape.hxx>
796a784d 30
42cf5bc1 31#include <stdio.h>
32#include <string.h>
33//
34//
4e57c75e 35static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
36static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
37static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
a942f2da 38
4e57c75e 39//=======================================================================
40//function : PartitionCommands
41//purpose :
42//=======================================================================
a942f2da 43void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
4e57c75e 44{
45 static Standard_Boolean done = Standard_False;
46 if (done) return;
47 done = Standard_True;
48 // Chapter's name
43cb0011 49 const char* g = "BOPTest commands";
4e57c75e 50 // Commands
43cb0011 51 theCommands.Add("bfillds", "use bfillds [-t]" , __FILE__, bfillds, g);
52 theCommands.Add("bbuild" , "use bbuild r [-t]" , __FILE__, bbuild, g);
53 theCommands.Add("bbop" , "use bbop r op [-t]", __FILE__, bbop, g);
4e57c75e 54}
55//=======================================================================
56//function : bfillds
57//purpose :
58//=======================================================================
a942f2da 59Standard_Integer bfillds(Draw_Interpretor& di,
60 Standard_Integer n,
61 const char** a)
4e57c75e 62{
43cb0011 63 if (n > 2) {
64 di << " use bfillds [-t]\n";
4e57c75e 65 return 0;
66 }
67 //
68 char buf[32];
a942f2da 69 Standard_Boolean bRunParallel, bShowTime;
70 Standard_Integer i, aNbS, iErr;
b1d15f53 71 Standard_Real aTol;
4e57c75e 72 BOPCol_ListIteratorOfListOfShape aIt;
73 BOPCol_ListOfShape aLC;
4e57c75e 74 BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
75 aNbS=aLS.Extent();
76 if (!aNbS) {
77 di << " no objects to process\n";
78 return 0;
79 }
80 //
b1d15f53 81 bShowTime = Standard_False;
49b0c452 82 //
83 bRunParallel=BOPTest_Objects::RunParallel();
84 aTol=BOPTest_Objects::FuzzyValue();
85 //
a942f2da 86 for (i=1; i<n; ++i) {
43cb0011 87 if (!strcmp(a[i], "-t")) {
a942f2da 88 bShowTime=Standard_True;
89 }
c7b59798 90 }
a942f2da 91 //
4e57c75e 92 BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
4e57c75e 93 //
94 aIt.Initialize(aLS);
95 for (; aIt.More(); aIt.Next()) {
96 const TopoDS_Shape& aS=aIt.Value();
97 aLC.Append(aS);
98 }
99 //
100 aIt.Initialize(aLT);
101 for (; aIt.More(); aIt.Next()) {
102 const TopoDS_Shape& aS=aIt.Value();
c7b59798 103 aLC.Append(aS);
4e57c75e 104 }
105 //
106 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
107 //
108 aPF.SetArguments(aLC);
a942f2da 109 aPF.SetRunParallel(bRunParallel);
b1d15f53 110 aPF.SetFuzzyValue(aTol);
a942f2da 111 //
c7b59798 112 OSD_Timer aTimer;
113 aTimer.Start();
4e57c75e 114 //
115 aPF.Perform();
116 iErr=aPF.ErrorStatus();
117 if (iErr) {
118 Sprintf(buf, " error: %d\n", iErr);
119 di << buf;
120 return 0;
121 }
122 //
c7b59798 123 aTimer.Stop();
a942f2da 124 //
c7b59798 125 if (bShowTime)
126 {
127 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
a942f2da 128 di << buf;
129 }
130 //
4e57c75e 131 return 0;
132}
4e57c75e 133//=======================================================================
134//function : bbuild
135//purpose :
136//=======================================================================
a942f2da 137Standard_Integer bbuild(Draw_Interpretor& di,
138 Standard_Integer n,
139 const char** a)
4e57c75e 140{
796a784d 141 if (n<2) {
43cb0011 142 di << " use bbuild r [-t]\n";
4e57c75e 143 return 0;
144 }
145 //
146 BOPDS_PDS pDS=BOPTest_Objects::PDS();
147 if (!pDS) {
148 di << " prepare PaveFiller first\n";
149 return 0;
150 }
151 //
796a784d 152 char buf[128];
153 Standard_Boolean bRunParallel, bShowTime;
154 Standard_Integer i, iErr;
c7b59798 155
4e57c75e 156 BOPCol_ListIteratorOfListOfShape aIt;
157 //
158 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
159 //
a493b4a1 160 BOPTest_Objects::SetBuilderDefault();
4e57c75e 161 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
162 aBuilder.Clear();
163 //
164 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
165 aIt.Initialize(aLSObj);
166 for (; aIt.More(); aIt.Next()) {
167 const TopoDS_Shape& aS=aIt.Value();
168 aBuilder.AddArgument(aS);
169 }
170 //
171 BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
172 aIt.Initialize(aLSTool);
173 for (; aIt.More(); aIt.Next()) {
174 const TopoDS_Shape& aS=aIt.Value();
175 aBuilder.AddArgument(aS);
176 }
177 //
796a784d 178 bShowTime=Standard_False;
49b0c452 179 bRunParallel=BOPTest_Objects::RunParallel();
796a784d 180 for (i=2; i<n; ++i) {
43cb0011 181 if (!strcmp(a[i], "-t")) {
796a784d 182 bShowTime=Standard_True;
183 }
184 }
185 aBuilder.SetRunParallel(bRunParallel);
186 //
187 //
c7b59798 188 OSD_Timer aTimer;
189 aTimer.Start();
796a784d 190 //
191 aBuilder.PerformWithFiller(aPF);
4e57c75e 192 iErr=aBuilder.ErrorStatus();
193 if (iErr) {
194 Sprintf(buf, " error: %d\n", iErr);
195 di << buf;
196 return 0;
197 }
198 //
c7b59798 199 aTimer.Stop();
796a784d 200 //
c7b59798 201 if (bShowTime)
202 {
203 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
796a784d 204 di << buf;
205 }
206 //
4e57c75e 207 const TopoDS_Shape& aR=aBuilder.Shape();
208 if (aR.IsNull()) {
209 di << " null shape\n";
210 return 0;
211 }
212 //
213 DBRep::Set(a[1], aR);
214 return 0;
215}
4e57c75e 216//=======================================================================
217//function : bbop
218//purpose :
219//=======================================================================
a942f2da 220Standard_Integer bbop(Draw_Interpretor& di,
221 Standard_Integer n,
222 const char** a)
4e57c75e 223{
8620e18d 224 if (n<3) {
43cb0011 225 di << " use bbop r op [-t]\n";
4e57c75e 226 return 0;
227 }
228 //
229 BOPDS_PDS pDS=BOPTest_Objects::PDS();
230 if (!pDS) {
231 di << " prepare PaveFiller first\n";
232 return 0;
233 }
234 //
235 char buf[32];
8620e18d 236 Standard_Boolean bRunParallel, bShowTime;
237 Standard_Integer iErr, iOp, i;
4e57c75e 238 BOPAlgo_Operation aOp;
8620e18d 239 BOPCol_ListIteratorOfListOfShape aIt;
4e57c75e 240 //
241 iOp=Draw::Atoi(a[2]);
242 if (iOp<0 || iOp>4) {
243 di << " invalid operation type\n";
8620e18d 244 return 0;
4e57c75e 245 }
246 aOp=(BOPAlgo_Operation)iOp;
247 //
8620e18d 248 bShowTime=Standard_False;
49b0c452 249 bRunParallel=BOPTest_Objects::RunParallel();
8620e18d 250 for (i=3; i<n; ++i) {
43cb0011 251 if (!strcmp(a[i], "-t")) {
8620e18d 252 bShowTime=Standard_True;
253 }
254 }
255 //
4e57c75e 256 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
257 //
85915310 258 BOPAlgo_Builder *pBuilder=NULL;
259
260 if (aOp!=BOPAlgo_SECTION) {
261 pBuilder=&BOPTest_Objects::BOP();
262 }
263 else {
264 pBuilder=&BOPTest_Objects::Section();
265 }
266 //
267 pBuilder->Clear();
4e57c75e 268 //
269 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
270 aIt.Initialize(aLSObj);
271 for (; aIt.More(); aIt.Next()) {
272 const TopoDS_Shape& aS=aIt.Value();
85915310 273 pBuilder->AddArgument(aS);
4e57c75e 274 }
275 //
85915310 276 if (aOp!=BOPAlgo_SECTION) {
277 BOPAlgo_BOP *pBOP=(BOPAlgo_BOP *)pBuilder;
278 //
279 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
280 aIt.Initialize(aLSTools);
281 for (; aIt.More(); aIt.Next()) {
282 const TopoDS_Shape& aS=aIt.Value();
283 pBOP->AddTool(aS);
284 }
285 //
286 pBOP->SetOperation(aOp);
4e57c75e 287 }
b1d15f53 288 else {
289 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
290 aIt.Initialize(aLSTools);
291 for (; aIt.More(); aIt.Next()) {
292 const TopoDS_Shape& aS=aIt.Value();
293 pBuilder->AddArgument(aS);
294 }
295 }
4e57c75e 296 //
85915310 297 pBuilder->SetRunParallel(bRunParallel);
8620e18d 298 //
c7b59798 299 OSD_Timer aTimer;
300 aTimer.Start();
4e57c75e 301 //
85915310 302 pBuilder->PerformWithFiller(aPF);
303 iErr=pBuilder->ErrorStatus();
4e57c75e 304 if (iErr) {
305 Sprintf(buf, " error: %d\n", iErr);
306 di << buf;
307 return 0;
308 }
309 //
c7b59798 310 aTimer.Stop();
8620e18d 311 //
312 if (bShowTime) {
c7b59798 313 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
8620e18d 314 di << buf;
315 }
316 //
85915310 317 const TopoDS_Shape& aR=pBuilder->Shape();
4e57c75e 318 if (aR.IsNull()) {
319 di << " null shape\n";
320 return 0;
321 }
322 //
a493b4a1 323 BOPTest_Objects::SetBuilder(pBuilder);
324 //
4e57c75e 325 DBRep::Set(a[1], aR);
326 return 0;
327}
328