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