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