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