0024428: Implementation of LGPL license
[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//
973c2be1 6// This library is free software; you can redistribute it and / or modify it
7// under the terms of the GNU Lesser General Public 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.
4e57c75e 11//
973c2be1 12// Alternatively, this file may be used under the terms of Open CASCADE
13// commercial license or contractual agreement.
4e57c75e 14
15#include <BOPTest.ixx>
16
17#include <stdio.h>
796a784d 18#include <string.h>
4e57c75e 19
20#include <NCollection_IncAllocator.hxx>
21
22#include <DBRep.hxx>
23#include <Draw.hxx>
24#include <Draw_Color.hxx>
25#include <DrawTrSurf.hxx>
26
27#include <TopoDS_Shape.hxx>
28//
29#include <BOPAlgo_Builder.hxx>
30#include <BOPAlgo_PaveFiller.hxx>
31#include <BOPAlgo_Operation.hxx>
32#include <BOPAlgo_BOP.hxx>
33//
34#include <BOPTest_DrawableShape.hxx>
35#include <BOPTest_Objects.hxx>
36
37//
796a784d 38#ifdef HAVE_TBB
39#include <BOPCol_TBB.hxx>
40//=======================================================================
41//class : BOPTime_Chronometer
42//purpose :
43//=======================================================================
44class BOPTime_Chronometer {
45 public:
46 BOPTime_Chronometer() {
47 }
48 //
49 ~BOPTime_Chronometer() {
50 }
51 //
52 void Start() {
53 myT0 = tick_count::now();
54 }
55 //
56 void Stop() {
57 myTime=(tick_count::now() - myT0).seconds();
58 }
59 //
60 double Time() const{
61 return myTime;
62 };
63 //
64 protected:
65 tick_count myT0;
66 double myTime;
67};
68////////////////////////////////////////////////////////////////////////
69#else
70#include <OSD_Chronometer.hxx>
71//=======================================================================
72//class : BOPTime_Chronometer
73//purpose :
74//=======================================================================
75class BOPTime_Chronometer {
76 public:
77 BOPTime_Chronometer() {
78 }
79 //
80 ~BOPTime_Chronometer() {
81 }
82 //
83 void Start() {
84 myChronometer.Reset();
85 myChronometer.Start();
86 }
87 //
88 void Stop() {
89 myChronometer.Stop();
90 myChronometer.Show(myTime);
91 }
92 //
93 double Time() const{
94 return myTime;
95 };
96 //
97 protected:
98 OSD_Chronometer myChronometer;
99 double myTime;
100};
101#endif
102
103
104
4e57c75e 105static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
106static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
107static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
108static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const char**);
109//=======================================================================
110//function : PartitionCommands
111//purpose :
112//=======================================================================
113 void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
114{
115 static Standard_Boolean done = Standard_False;
116 if (done) return;
117 done = Standard_True;
118 // Chapter's name
119 const char* g = "Partition commands";
120 // Commands
121 theCommands.Add("bfillds" , "use bfillds" , __FILE__, bfillds , g);
796a784d 122 theCommands.Add("bbuild" , " use bbuild r [-s -t]" , __FILE__, bbuild, g);
4e57c75e 123 theCommands.Add("bbop" , "use bbop r op" , __FILE__, bbop, g);
124 theCommands.Add("bclear" , "use bclear" , __FILE__, bclear, g);
125}
126
127//=======================================================================
128//function : bclear
129//purpose :
130//=======================================================================
131Standard_Integer bclear(Draw_Interpretor& di, Standard_Integer n, const char** )
132{
133 if (n!=1) {
134 di << " use bclear\n";
135 return 0;
136 }
137 //
138 BOPTest_Objects::Clear();
139 return 0;
140}
141//=======================================================================
142//function : bfillds
143//purpose :
144//=======================================================================
145Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char** )
146{
147 if (n!=1) {
148 di << " Use bfillds\n";
149 return 0;
150 }
151 //
152 char buf[32];
153 Standard_Integer aNbS, aNbT, iErr;
154 BOPCol_ListIteratorOfListOfShape aIt;
155 BOPCol_ListOfShape aLC;
156
157 BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
158 aNbS=aLS.Extent();
159 if (!aNbS) {
160 di << " no objects to process\n";
161 return 0;
162 }
163 //
164 BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
165 aNbT=aLT.Extent();
166 //
167 aIt.Initialize(aLS);
168 for (; aIt.More(); aIt.Next()) {
169 const TopoDS_Shape& aS=aIt.Value();
170 aLC.Append(aS);
171 }
172 //
173 aIt.Initialize(aLT);
174 for (; aIt.More(); aIt.Next()) {
175 const TopoDS_Shape& aS=aIt.Value();
176 aLC.Append(aS);
177 }
178 //
179 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
180 //
181 aPF.SetArguments(aLC);
182 //
183 aPF.Perform();
184 iErr=aPF.ErrorStatus();
185 if (iErr) {
186 Sprintf(buf, " error: %d\n", iErr);
187 di << buf;
188 return 0;
189 }
190 //
191 return 0;
192}
4e57c75e 193//=======================================================================
194//function : bbuild
195//purpose :
196//=======================================================================
197Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a)
198{
796a784d 199 if (n<2) {
200 di << " use bbuild r [-s -t]\n";
4e57c75e 201 return 0;
202 }
203 //
204 BOPDS_PDS pDS=BOPTest_Objects::PDS();
205 if (!pDS) {
206 di << " prepare PaveFiller first\n";
207 return 0;
208 }
209 //
796a784d 210 char buf[128];
211 Standard_Boolean bRunParallel, bShowTime;
212 Standard_Integer i, iErr;
213
214 BOPTime_Chronometer aChrono;
4e57c75e 215 BOPCol_ListIteratorOfListOfShape aIt;
796a784d 216 //
217
4e57c75e 218 //
219 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
220 //
221 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
222 aBuilder.Clear();
223 //
224 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
225 aIt.Initialize(aLSObj);
226 for (; aIt.More(); aIt.Next()) {
227 const TopoDS_Shape& aS=aIt.Value();
228 aBuilder.AddArgument(aS);
229 }
230 //
231 BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
232 aIt.Initialize(aLSTool);
233 for (; aIt.More(); aIt.Next()) {
234 const TopoDS_Shape& aS=aIt.Value();
235 aBuilder.AddArgument(aS);
236 }
237 //
796a784d 238 bShowTime=Standard_False;
239 bRunParallel=Standard_True;
240 for (i=2; i<n; ++i) {
241 if (!strcmp(a[i], "-s")) {
242 bRunParallel=Standard_False;
243 }
244 else if (!strcmp(a[i], "-t")) {
245 bShowTime=Standard_True;
246 }
247 }
248 aBuilder.SetRunParallel(bRunParallel);
249 //
250 //
251 aChrono.Start();
252 //
253 aBuilder.PerformWithFiller(aPF);
4e57c75e 254 iErr=aBuilder.ErrorStatus();
255 if (iErr) {
256 Sprintf(buf, " error: %d\n", iErr);
257 di << buf;
258 return 0;
259 }
260 //
796a784d 261 aChrono.Stop();
262 //
263 if (bShowTime) {
264 Standard_Real aTime;
265 //
266 aTime=aChrono.Time();
267 Sprintf(buf, " Tps: %7.2lf\n", aTime);
268 di << buf;
269 }
270 //
4e57c75e 271 const TopoDS_Shape& aR=aBuilder.Shape();
272 if (aR.IsNull()) {
273 di << " null shape\n";
274 return 0;
275 }
276 //
277 DBRep::Set(a[1], aR);
278 return 0;
279}
280
281//=======================================================================
282//function : bbop
283//purpose :
284//=======================================================================
285Standard_Integer bbop(Draw_Interpretor& di, Standard_Integer n, const char** a)
286{
287 if (n!=3) {
288 di << " use bbop r op\n";
289 return 0;
290 }
291 //
292 BOPDS_PDS pDS=BOPTest_Objects::PDS();
293 if (!pDS) {
294 di << " prepare PaveFiller first\n";
295 return 0;
296 }
297 //
298 char buf[32];
299 Standard_Integer iErr, iOp;
300 BOPAlgo_Operation aOp;
301 BOPCol_ListIteratorOfListOfShape aIt;
302 //
303 iOp=Draw::Atoi(a[2]);
304 if (iOp<0 || iOp>4) {
305 di << " invalid operation type\n";
306 }
307 aOp=(BOPAlgo_Operation)iOp;
308 //
309 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
310 //
311 BOPAlgo_BOP& aBOP=BOPTest_Objects::BOP();
312 aBOP.Clear();
313 //
314 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
315 aIt.Initialize(aLSObj);
316 for (; aIt.More(); aIt.Next()) {
317 const TopoDS_Shape& aS=aIt.Value();
318 aBOP.AddArgument(aS);
319 }
320 //
321 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
322 aIt.Initialize(aLSTools);
323 for (; aIt.More(); aIt.Next()) {
324 const TopoDS_Shape& aS=aIt.Value();
325 aBOP.AddTool(aS);
326 }
327 //
328 aBOP.SetOperation(aOp);
329 //
330 aBOP.PerformWithFiller(aPF);
331 iErr=aBOP.ErrorStatus();
332 if (iErr) {
333 Sprintf(buf, " error: %d\n", iErr);
334 di << buf;
335 return 0;
336 }
337 //
338 const TopoDS_Shape& aR=aBOP.Shape();
339 if (aR.IsNull()) {
340 di << " null shape\n";
341 return 0;
342 }
343 //
344 DBRep::Set(a[1], aR);
345 return 0;
346}
347