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