1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <BOPTest.ixx>
20 #include <NCollection_IncAllocator.hxx>
24 #include <Draw_Color.hxx>
25 #include <DrawTrSurf.hxx>
27 #include <TopoDS_Shape.hxx>
29 #include <BOPAlgo_Builder.hxx>
30 #include <BOPAlgo_PaveFiller.hxx>
31 #include <BOPAlgo_Operation.hxx>
32 #include <BOPAlgo_BOP.hxx>
34 #include <BOPTest_DrawableShape.hxx>
35 #include <BOPTest_Objects.hxx>
39 #include <BOPCol_TBB.hxx>
40 //=======================================================================
41 //class : BOPTime_Chronometer
43 //=======================================================================
44 class BOPTime_Chronometer {
46 BOPTime_Chronometer() {
49 ~BOPTime_Chronometer() {
53 myT0 = tick_count::now();
57 myTime=(tick_count::now() - myT0).seconds();
68 ////////////////////////////////////////////////////////////////////////
70 #include <OSD_Chronometer.hxx>
71 //=======================================================================
72 //class : BOPTime_Chronometer
74 //=======================================================================
75 class BOPTime_Chronometer {
77 BOPTime_Chronometer() {
80 ~BOPTime_Chronometer() {
84 myChronometer.Reset();
85 myChronometer.Start();
90 myChronometer.Show(myTime);
98 OSD_Chronometer myChronometer;
103 static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
104 static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
105 static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
106 static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const char**);
108 //=======================================================================
109 //function : PartitionCommands
111 //=======================================================================
112 void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
114 static Standard_Boolean done = Standard_False;
116 done = Standard_True;
118 const char* g = "Partition commands";
120 theCommands.Add("bfillds" , "use bfillds [-s -t]" , __FILE__, bfillds, g);
121 theCommands.Add("bbuild" , "use bbuild r [-s -t]", __FILE__, bbuild, g);
122 theCommands.Add("bbop" , "use bbop r op" , __FILE__, bbop, g);
123 theCommands.Add("bclear" , "use bclear" , __FILE__, bclear, g);
126 //=======================================================================
129 //=======================================================================
130 Standard_Integer bclear(Draw_Interpretor& di,
135 di << " use bclear\n";
139 BOPTest_Objects::Clear();
142 //=======================================================================
145 //=======================================================================
146 Standard_Integer bfillds(Draw_Interpretor& di,
151 di << " use bfillds [-s -t]\n";
156 Standard_Boolean bRunParallel, bShowTime;
157 Standard_Integer i, aNbS, iErr;
158 BOPCol_ListIteratorOfListOfShape aIt;
159 BOPCol_ListOfShape aLC;
160 BOPTime_Chronometer aChrono;
162 BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
165 di << " no objects to process\n";
169 bShowTime=Standard_False;
170 bRunParallel=Standard_True;
171 for (i=1; i<n; ++i) {
172 if (!strcmp(a[i], "-s")) {
173 bRunParallel=Standard_False;
175 else if (!strcmp(a[i], "-t")) {
176 bShowTime=Standard_True;
180 BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
183 for (; aIt.More(); aIt.Next()) {
184 const TopoDS_Shape& aS=aIt.Value();
189 for (; aIt.More(); aIt.Next()) {
190 const TopoDS_Shape& aS=aIt.Value();
194 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
196 aPF.SetArguments(aLC);
197 aPF.SetRunParallel(bRunParallel);
202 iErr=aPF.ErrorStatus();
204 Sprintf(buf, " error: %d\n", iErr);
214 aTime=aChrono.Time();
215 Sprintf(buf, " Tps: %7.2lf\n", aTime);
221 //=======================================================================
224 //=======================================================================
225 Standard_Integer bbuild(Draw_Interpretor& di,
230 di << " use bbuild r [-s -t]\n";
234 BOPDS_PDS pDS=BOPTest_Objects::PDS();
236 di << " prepare PaveFiller first\n";
241 Standard_Boolean bRunParallel, bShowTime;
242 Standard_Integer i, iErr;
244 BOPTime_Chronometer aChrono;
245 BOPCol_ListIteratorOfListOfShape aIt;
247 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
249 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
252 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
253 aIt.Initialize(aLSObj);
254 for (; aIt.More(); aIt.Next()) {
255 const TopoDS_Shape& aS=aIt.Value();
256 aBuilder.AddArgument(aS);
259 BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
260 aIt.Initialize(aLSTool);
261 for (; aIt.More(); aIt.Next()) {
262 const TopoDS_Shape& aS=aIt.Value();
263 aBuilder.AddArgument(aS);
266 bShowTime=Standard_False;
267 bRunParallel=Standard_True;
268 for (i=2; i<n; ++i) {
269 if (!strcmp(a[i], "-s")) {
270 bRunParallel=Standard_False;
272 else if (!strcmp(a[i], "-t")) {
273 bShowTime=Standard_True;
276 aBuilder.SetRunParallel(bRunParallel);
281 aBuilder.PerformWithFiller(aPF);
282 iErr=aBuilder.ErrorStatus();
284 Sprintf(buf, " error: %d\n", iErr);
294 aTime=aChrono.Time();
295 Sprintf(buf, " Tps: %7.2lf\n", aTime);
299 const TopoDS_Shape& aR=aBuilder.Shape();
301 di << " null shape\n";
305 DBRep::Set(a[1], aR);
309 //=======================================================================
312 //=======================================================================
313 Standard_Integer bbop(Draw_Interpretor& di,
318 di << " use bbop r op\n";
322 BOPDS_PDS pDS=BOPTest_Objects::PDS();
324 di << " prepare PaveFiller first\n";
329 Standard_Integer iErr, iOp;
330 BOPAlgo_Operation aOp;
331 BOPCol_ListIteratorOfListOfShape aIt;
333 iOp=Draw::Atoi(a[2]);
334 if (iOp<0 || iOp>4) {
335 di << " invalid operation type\n";
337 aOp=(BOPAlgo_Operation)iOp;
339 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
341 BOPAlgo_BOP& aBOP=BOPTest_Objects::BOP();
344 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
345 aIt.Initialize(aLSObj);
346 for (; aIt.More(); aIt.Next()) {
347 const TopoDS_Shape& aS=aIt.Value();
348 aBOP.AddArgument(aS);
351 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
352 aIt.Initialize(aLSTools);
353 for (; aIt.More(); aIt.Next()) {
354 const TopoDS_Shape& aS=aIt.Value();
358 aBOP.SetOperation(aOp);
360 aBOP.PerformWithFiller(aPF);
361 iErr=aBOP.ErrorStatus();
363 Sprintf(buf, " error: %d\n", iErr);
368 const TopoDS_Shape& aR=aBOP.Shape();
370 di << " null shape\n";
374 DBRep::Set(a[1], aR);