1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <BOPAlgo_BOP.hxx>
17 #include <BOPAlgo_Builder.hxx>
18 #include <BOPAlgo_Operation.hxx>
19 #include <BOPAlgo_PaveFiller.hxx>
20 #include <BOPAlgo_Section.hxx>
21 #include <BOPAlgo_Splitter.hxx>
22 #include <BOPTest.hxx>
23 #include <BOPTest_DrawableShape.hxx>
24 #include <BOPTest_Objects.hxx>
25 #include <BRepTest_Objects.hxx>
28 #include <Draw_Color.hxx>
29 #include <DrawTrSurf.hxx>
30 #include <OSD_Timer.hxx>
31 #include <TopoDS_Shape.hxx>
37 static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
38 static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
39 static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
40 static Standard_Integer bsplit (Draw_Interpretor&, Standard_Integer, const char**);
42 //=======================================================================
43 //function : PartitionCommands
45 //=======================================================================
46 void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
48 static Standard_Boolean done = Standard_False;
52 const char* g = "BOPTest commands";
54 theCommands.Add("bfillds", "use bfillds [-t]" , __FILE__, bfillds, g);
55 theCommands.Add("bbuild" , "use bbuild r [-t]" , __FILE__, bbuild, g);
56 theCommands.Add("bbop" , "use bbop r op [-t]", __FILE__, bbop, g);
57 theCommands.Add("bsplit" , "use bsplit r [-t]" , __FILE__, bsplit, g);
59 //=======================================================================
62 //=======================================================================
63 Standard_Integer bfillds(Draw_Interpretor& di,
68 di << " use bfillds [-t]\n";
73 Standard_Boolean bRunParallel, bNonDestructive, bShowTime;
74 Standard_Integer i, aNbS;
76 TopTools_ListIteratorOfListOfShape aIt;
77 TopTools_ListOfShape aLC;
78 TopTools_ListOfShape& aLS=BOPTest_Objects::Shapes();
81 di << " no objects to process\n";
85 bShowTime = Standard_False;
87 bRunParallel=BOPTest_Objects::RunParallel();
88 bNonDestructive = BOPTest_Objects::NonDestructive();
89 aTol = BOPTest_Objects::FuzzyValue();
90 BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
93 if (!strcmp(a[i], "-t")) {
94 bShowTime=Standard_True;
98 TopTools_ListOfShape& aLT=BOPTest_Objects::Tools();
101 for (; aIt.More(); aIt.Next()) {
102 const TopoDS_Shape& aS=aIt.Value();
107 for (; aIt.More(); aIt.Next()) {
108 const TopoDS_Shape& aS=aIt.Value();
112 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
114 aPF.SetArguments(aLC);
115 aPF.SetRunParallel(bRunParallel);
116 aPF.SetNonDestructive(bNonDestructive);
117 aPF.SetFuzzyValue(aTol);
119 aPF.SetUseOBB(BOPTest_Objects::UseOBB());
125 BOPTest::ReportAlerts(aPF.GetReport());
126 if (aPF.HasErrors()) {
134 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
140 //=======================================================================
143 //=======================================================================
144 Standard_Integer bbuild(Draw_Interpretor& di,
149 di << " use bbuild r [-t]\n";
153 BOPDS_PDS pDS=BOPTest_Objects::PDS();
155 di << " prepare PaveFiller first\n";
160 Standard_Boolean bRunParallel, bShowTime;
163 TopTools_ListIteratorOfListOfShape aIt;
165 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
167 BOPTest_Objects::SetBuilderDefault();
168 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
171 TopTools_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
172 aIt.Initialize(aLSObj);
173 for (; aIt.More(); aIt.Next()) {
174 const TopoDS_Shape& aS=aIt.Value();
175 aBuilder.AddArgument(aS);
178 TopTools_ListOfShape& aLSTool=BOPTest_Objects::Tools();
179 aIt.Initialize(aLSTool);
180 for (; aIt.More(); aIt.Next()) {
181 const TopoDS_Shape& aS=aIt.Value();
182 aBuilder.AddArgument(aS);
185 bShowTime=Standard_False;
186 bRunParallel=BOPTest_Objects::RunParallel();
187 for (i=2; i<n; ++i) {
188 if (!strcmp(a[i], "-t")) {
189 bShowTime=Standard_True;
192 aBuilder.SetRunParallel(bRunParallel);
193 aBuilder.SetCheckInverted(BOPTest_Objects::CheckInverted());
199 aBuilder.PerformWithFiller(aPF);
200 BOPTest::ReportAlerts(aBuilder.GetReport());
202 // Set history of GF operation into the session
203 BRepTest_Objects::SetHistory(aPF.Arguments(), aBuilder);
205 if (aBuilder.HasErrors()) {
213 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
217 const TopoDS_Shape& aR=aBuilder.Shape();
219 di << " null shape\n";
223 DBRep::Set(a[1], aR);
226 //=======================================================================
229 //=======================================================================
230 Standard_Integer bbop(Draw_Interpretor& di,
235 di << " use bbop r op [-t]\n";
239 BOPDS_PDS pDS=BOPTest_Objects::PDS();
241 di << " prepare PaveFiller first\n";
246 Standard_Boolean bRunParallel, bShowTime;
247 Standard_Integer iOp, i;
248 BOPAlgo_Operation aOp;
249 TopTools_ListIteratorOfListOfShape aIt;
251 iOp=Draw::Atoi(a[2]);
252 if (iOp<0 || iOp>4) {
253 di << " invalid operation type\n";
256 aOp=(BOPAlgo_Operation)iOp;
258 bShowTime=Standard_False;
259 bRunParallel=BOPTest_Objects::RunParallel();
260 for (i=3; i<n; ++i) {
261 if (!strcmp(a[i], "-t")) {
262 bShowTime=Standard_True;
266 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
268 BOPAlgo_Builder *pBuilder=NULL;
270 if (aOp!=BOPAlgo_SECTION) {
271 pBuilder=&BOPTest_Objects::BOP();
274 pBuilder=&BOPTest_Objects::Section();
279 TopTools_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
280 aIt.Initialize(aLSObj);
281 for (; aIt.More(); aIt.Next()) {
282 const TopoDS_Shape& aS=aIt.Value();
283 pBuilder->AddArgument(aS);
286 if (aOp!=BOPAlgo_SECTION) {
287 BOPAlgo_BOP *pBOP=(BOPAlgo_BOP *)pBuilder;
289 TopTools_ListOfShape& aLSTools=BOPTest_Objects::Tools();
290 aIt.Initialize(aLSTools);
291 for (; aIt.More(); aIt.Next()) {
292 const TopoDS_Shape& aS=aIt.Value();
296 pBOP->SetOperation(aOp);
299 TopTools_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);
307 pBuilder->SetRunParallel(bRunParallel);
308 pBuilder->SetCheckInverted(BOPTest_Objects::CheckInverted());
313 pBuilder->PerformWithFiller(aPF);
314 BOPTest::ReportAlerts(pBuilder->GetReport());
316 // Set history of Boolean operation into the session
317 BRepTest_Objects::SetHistory(aPF.Arguments(), *pBuilder);
319 if (pBuilder->HasErrors()) {
326 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
330 const TopoDS_Shape& aR=pBuilder->Shape();
332 di << " null shape\n";
336 BOPTest_Objects::SetBuilder(pBuilder);
338 DBRep::Set(a[1], aR);
342 //=======================================================================
345 //=======================================================================
346 Standard_Integer bsplit(Draw_Interpretor& di,
351 di << " use bsplit r [-t (show time)]\n";
355 BOPDS_PDS pDS = BOPTest_Objects::PDS();
357 di << " prepare PaveFiller first\n";
361 BOPAlgo_PaveFiller& aPF = BOPTest_Objects::PaveFiller();
363 BOPAlgo_Splitter* pSplitter = &BOPTest_Objects::Splitter();
367 const TopTools_ListOfShape& aLSObjects = BOPTest_Objects::Shapes();
368 pSplitter->SetArguments(aLSObjects);
371 TopTools_ListOfShape& aLSTools = BOPTest_Objects::Tools();
372 pSplitter->SetTools(aLSTools);
375 pSplitter->SetRunParallel(BOPTest_Objects::RunParallel());
376 pSplitter->SetNonDestructive(BOPTest_Objects::NonDestructive());
377 pSplitter->SetFuzzyValue(BOPTest_Objects::FuzzyValue());
378 pSplitter->SetCheckInverted(BOPTest_Objects::CheckInverted());
380 // measure the time of the operation
384 // perform the operation
385 pSplitter->PerformWithFiller(aPF);
388 BOPTest::ReportAlerts(pSplitter->GetReport());
390 // Set history of Split operation into the session
391 BRepTest_Objects::SetHistory(aPF.Arguments(), *pSplitter);
393 if (pSplitter->HasErrors()) {
397 // show time if necessary
398 if (n == 3 && !strcmp(a[2], "-t")) {
400 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
404 // Debug commands support
405 BOPTest_Objects::SetBuilder(pSplitter);
407 const TopoDS_Shape& aR = pSplitter->Shape();
409 di << " null shape\n";
413 DBRep::Set(a[1], aR);