0026619: Tolerances of operands are modified using bop
[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];
3510db62 69 Standard_Boolean bRunParallel, bNonDestructive, bShowTime;
a942f2da 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();
3510db62 84 bNonDestructive = BOPTest_Objects::NonDestructive();
85 aTol = BOPTest_Objects::FuzzyValue();
49b0c452 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);
3510db62 111 aPF.SetNonDestructive(bNonDestructive);
b1d15f53 112 aPF.SetFuzzyValue(aTol);
a942f2da 113 //
c7b59798 114 OSD_Timer aTimer;
115 aTimer.Start();
4e57c75e 116 //
117 aPF.Perform();
118 iErr=aPF.ErrorStatus();
119 if (iErr) {
120 Sprintf(buf, " error: %d\n", iErr);
121 di << buf;
122 return 0;
123 }
124 //
c7b59798 125 aTimer.Stop();
a942f2da 126 //
c7b59798 127 if (bShowTime)
128 {
129 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
a942f2da 130 di << buf;
131 }
132 //
4e57c75e 133 return 0;
134}
4e57c75e 135//=======================================================================
136//function : bbuild
137//purpose :
138//=======================================================================
a942f2da 139Standard_Integer bbuild(Draw_Interpretor& di,
140 Standard_Integer n,
141 const char** a)
4e57c75e 142{
796a784d 143 if (n<2) {
43cb0011 144 di << " use bbuild r [-t]\n";
4e57c75e 145 return 0;
146 }
147 //
148 BOPDS_PDS pDS=BOPTest_Objects::PDS();
149 if (!pDS) {
150 di << " prepare PaveFiller first\n";
151 return 0;
152 }
153 //
796a784d 154 char buf[128];
155 Standard_Boolean bRunParallel, bShowTime;
156 Standard_Integer i, iErr;
c7b59798 157
4e57c75e 158 BOPCol_ListIteratorOfListOfShape aIt;
159 //
160 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
161 //
a493b4a1 162 BOPTest_Objects::SetBuilderDefault();
4e57c75e 163 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
164 aBuilder.Clear();
165 //
166 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
167 aIt.Initialize(aLSObj);
168 for (; aIt.More(); aIt.Next()) {
169 const TopoDS_Shape& aS=aIt.Value();
170 aBuilder.AddArgument(aS);
171 }
172 //
173 BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
174 aIt.Initialize(aLSTool);
175 for (; aIt.More(); aIt.Next()) {
176 const TopoDS_Shape& aS=aIt.Value();
177 aBuilder.AddArgument(aS);
178 }
179 //
796a784d 180 bShowTime=Standard_False;
49b0c452 181 bRunParallel=BOPTest_Objects::RunParallel();
796a784d 182 for (i=2; i<n; ++i) {
43cb0011 183 if (!strcmp(a[i], "-t")) {
796a784d 184 bShowTime=Standard_True;
185 }
186 }
187 aBuilder.SetRunParallel(bRunParallel);
188 //
189 //
c7b59798 190 OSD_Timer aTimer;
191 aTimer.Start();
796a784d 192 //
193 aBuilder.PerformWithFiller(aPF);
4e57c75e 194 iErr=aBuilder.ErrorStatus();
195 if (iErr) {
196 Sprintf(buf, " error: %d\n", iErr);
197 di << buf;
198 return 0;
199 }
200 //
c7b59798 201 aTimer.Stop();
796a784d 202 //
c7b59798 203 if (bShowTime)
204 {
205 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
796a784d 206 di << buf;
207 }
208 //
4e57c75e 209 const TopoDS_Shape& aR=aBuilder.Shape();
210 if (aR.IsNull()) {
211 di << " null shape\n";
212 return 0;
213 }
214 //
215 DBRep::Set(a[1], aR);
216 return 0;
217}
4e57c75e 218//=======================================================================
219//function : bbop
220//purpose :
221//=======================================================================
a942f2da 222Standard_Integer bbop(Draw_Interpretor& di,
223 Standard_Integer n,
224 const char** a)
4e57c75e 225{
8620e18d 226 if (n<3) {
43cb0011 227 di << " use bbop r op [-t]\n";
4e57c75e 228 return 0;
229 }
230 //
231 BOPDS_PDS pDS=BOPTest_Objects::PDS();
232 if (!pDS) {
233 di << " prepare PaveFiller first\n";
234 return 0;
235 }
236 //
237 char buf[32];
8620e18d 238 Standard_Boolean bRunParallel, bShowTime;
239 Standard_Integer iErr, iOp, i;
4e57c75e 240 BOPAlgo_Operation aOp;
8620e18d 241 BOPCol_ListIteratorOfListOfShape aIt;
4e57c75e 242 //
243 iOp=Draw::Atoi(a[2]);
244 if (iOp<0 || iOp>4) {
245 di << " invalid operation type\n";
8620e18d 246 return 0;
4e57c75e 247 }
248 aOp=(BOPAlgo_Operation)iOp;
249 //
8620e18d 250 bShowTime=Standard_False;
49b0c452 251 bRunParallel=BOPTest_Objects::RunParallel();
8620e18d 252 for (i=3; i<n; ++i) {
43cb0011 253 if (!strcmp(a[i], "-t")) {
8620e18d 254 bShowTime=Standard_True;
255 }
256 }
257 //
4e57c75e 258 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
259 //
85915310 260 BOPAlgo_Builder *pBuilder=NULL;
261
262 if (aOp!=BOPAlgo_SECTION) {
263 pBuilder=&BOPTest_Objects::BOP();
264 }
265 else {
266 pBuilder=&BOPTest_Objects::Section();
267 }
268 //
269 pBuilder->Clear();
4e57c75e 270 //
271 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
272 aIt.Initialize(aLSObj);
273 for (; aIt.More(); aIt.Next()) {
274 const TopoDS_Shape& aS=aIt.Value();
85915310 275 pBuilder->AddArgument(aS);
4e57c75e 276 }
277 //
85915310 278 if (aOp!=BOPAlgo_SECTION) {
279 BOPAlgo_BOP *pBOP=(BOPAlgo_BOP *)pBuilder;
280 //
281 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
282 aIt.Initialize(aLSTools);
283 for (; aIt.More(); aIt.Next()) {
284 const TopoDS_Shape& aS=aIt.Value();
285 pBOP->AddTool(aS);
286 }
287 //
288 pBOP->SetOperation(aOp);
4e57c75e 289 }
b1d15f53 290 else {
291 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
292 aIt.Initialize(aLSTools);
293 for (; aIt.More(); aIt.Next()) {
294 const TopoDS_Shape& aS=aIt.Value();
295 pBuilder->AddArgument(aS);
296 }
297 }
4e57c75e 298 //
85915310 299 pBuilder->SetRunParallel(bRunParallel);
8620e18d 300 //
c7b59798 301 OSD_Timer aTimer;
302 aTimer.Start();
4e57c75e 303 //
85915310 304 pBuilder->PerformWithFiller(aPF);
305 iErr=pBuilder->ErrorStatus();
4e57c75e 306 if (iErr) {
307 Sprintf(buf, " error: %d\n", iErr);
308 di << buf;
309 return 0;
310 }
311 //
c7b59798 312 aTimer.Stop();
8620e18d 313 //
314 if (bShowTime) {
c7b59798 315 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
8620e18d 316 di << buf;
317 }
318 //
85915310 319 const TopoDS_Shape& aR=pBuilder->Shape();
4e57c75e 320 if (aR.IsNull()) {
321 di << " null shape\n";
322 return 0;
323 }
324 //
a493b4a1 325 BOPTest_Objects::SetBuilder(pBuilder);
326 //
4e57c75e 327 DBRep::Set(a[1], aR);
328 return 0;
329}
330