0024002: Overall code and build procedure refactoring -- automatic
[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>
28#include <NCollection_IncAllocator.hxx>
c7b59798 29#include <OSD_Timer.hxx>
42cf5bc1 30#include <TopoDS_Shape.hxx>
796a784d 31
42cf5bc1 32#include <stdio.h>
33#include <string.h>
34//
35//
4e57c75e 36static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
37static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
38static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
a942f2da 39
4e57c75e 40//=======================================================================
41//function : PartitionCommands
42//purpose :
43//=======================================================================
a942f2da 44void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
4e57c75e 45{
46 static Standard_Boolean done = Standard_False;
47 if (done) return;
48 done = Standard_True;
49 // Chapter's name
43cb0011 50 const char* g = "BOPTest commands";
4e57c75e 51 // Commands
43cb0011 52 theCommands.Add("bfillds", "use bfillds [-t]" , __FILE__, bfillds, g);
53 theCommands.Add("bbuild" , "use bbuild r [-t]" , __FILE__, bbuild, g);
54 theCommands.Add("bbop" , "use bbop r op [-t]", __FILE__, bbop, g);
4e57c75e 55}
56//=======================================================================
57//function : bfillds
58//purpose :
59//=======================================================================
a942f2da 60Standard_Integer bfillds(Draw_Interpretor& di,
61 Standard_Integer n,
62 const char** a)
4e57c75e 63{
43cb0011 64 if (n > 2) {
65 di << " use bfillds [-t]\n";
4e57c75e 66 return 0;
67 }
68 //
69 char buf[32];
a942f2da 70 Standard_Boolean bRunParallel, bShowTime;
71 Standard_Integer i, aNbS, iErr;
b1d15f53 72 Standard_Real aTol;
4e57c75e 73 BOPCol_ListIteratorOfListOfShape aIt;
74 BOPCol_ListOfShape aLC;
4e57c75e 75 BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
76 aNbS=aLS.Extent();
77 if (!aNbS) {
78 di << " no objects to process\n";
79 return 0;
80 }
81 //
b1d15f53 82 bShowTime = Standard_False;
49b0c452 83 //
84 bRunParallel=BOPTest_Objects::RunParallel();
85 aTol=BOPTest_Objects::FuzzyValue();
86 //
a942f2da 87 for (i=1; i<n; ++i) {
43cb0011 88 if (!strcmp(a[i], "-t")) {
a942f2da 89 bShowTime=Standard_True;
90 }
c7b59798 91 }
a942f2da 92 //
4e57c75e 93 BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
4e57c75e 94 //
95 aIt.Initialize(aLS);
96 for (; aIt.More(); aIt.Next()) {
97 const TopoDS_Shape& aS=aIt.Value();
98 aLC.Append(aS);
99 }
100 //
101 aIt.Initialize(aLT);
102 for (; aIt.More(); aIt.Next()) {
103 const TopoDS_Shape& aS=aIt.Value();
c7b59798 104 aLC.Append(aS);
4e57c75e 105 }
106 //
107 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
108 //
109 aPF.SetArguments(aLC);
a942f2da 110 aPF.SetRunParallel(bRunParallel);
b1d15f53 111 aPF.SetFuzzyValue(aTol);
a942f2da 112 //
c7b59798 113 OSD_Timer aTimer;
114 aTimer.Start();
4e57c75e 115 //
116 aPF.Perform();
117 iErr=aPF.ErrorStatus();
118 if (iErr) {
119 Sprintf(buf, " error: %d\n", iErr);
120 di << buf;
121 return 0;
122 }
123 //
c7b59798 124 aTimer.Stop();
a942f2da 125 //
c7b59798 126 if (bShowTime)
127 {
128 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
a942f2da 129 di << buf;
130 }
131 //
4e57c75e 132 return 0;
133}
4e57c75e 134//=======================================================================
135//function : bbuild
136//purpose :
137//=======================================================================
a942f2da 138Standard_Integer bbuild(Draw_Interpretor& di,
139 Standard_Integer n,
140 const char** a)
4e57c75e 141{
796a784d 142 if (n<2) {
43cb0011 143 di << " use bbuild r [-t]\n";
4e57c75e 144 return 0;
145 }
146 //
147 BOPDS_PDS pDS=BOPTest_Objects::PDS();
148 if (!pDS) {
149 di << " prepare PaveFiller first\n";
150 return 0;
151 }
152 //
796a784d 153 char buf[128];
154 Standard_Boolean bRunParallel, bShowTime;
155 Standard_Integer i, iErr;
c7b59798 156
4e57c75e 157 BOPCol_ListIteratorOfListOfShape aIt;
158 //
159 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
160 //
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 //
323 DBRep::Set(a[1], aR);
324 return 0;
325}
326