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