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());
194 aBuilder.SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
200 aBuilder.PerformWithFiller(aPF);
201 BOPTest::ReportAlerts(aBuilder.GetReport());
203 // Set history of GF operation into the session
204 if (BRepTest_Objects::IsHistoryNeeded())
205 BRepTest_Objects::SetHistory(aPF.Arguments(), aBuilder);
207 if (aBuilder.HasErrors()) {
215 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
219 const TopoDS_Shape& aR=aBuilder.Shape();
221 di << " null shape\n";
225 DBRep::Set(a[1], aR);
228 //=======================================================================
231 //=======================================================================
232 Standard_Integer bbop(Draw_Interpretor& di,
237 di << " use bbop r op [-t]\n";
241 BOPDS_PDS pDS=BOPTest_Objects::PDS();
243 di << " prepare PaveFiller first\n";
248 Standard_Boolean bRunParallel, bShowTime;
249 Standard_Integer iOp, i;
250 BOPAlgo_Operation aOp;
251 TopTools_ListIteratorOfListOfShape aIt;
253 iOp=Draw::Atoi(a[2]);
254 if (iOp<0 || iOp>4) {
255 di << " invalid operation type\n";
258 aOp=(BOPAlgo_Operation)iOp;
260 bShowTime=Standard_False;
261 bRunParallel=BOPTest_Objects::RunParallel();
262 for (i=3; i<n; ++i) {
263 if (!strcmp(a[i], "-t")) {
264 bShowTime=Standard_True;
268 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
270 BOPAlgo_Builder *pBuilder=NULL;
272 if (aOp!=BOPAlgo_SECTION) {
273 pBuilder=&BOPTest_Objects::BOP();
276 pBuilder=&BOPTest_Objects::Section();
281 TopTools_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
282 aIt.Initialize(aLSObj);
283 for (; aIt.More(); aIt.Next()) {
284 const TopoDS_Shape& aS=aIt.Value();
285 pBuilder->AddArgument(aS);
288 if (aOp!=BOPAlgo_SECTION) {
289 BOPAlgo_BOP *pBOP=(BOPAlgo_BOP *)pBuilder;
291 TopTools_ListOfShape& aLSTools=BOPTest_Objects::Tools();
292 aIt.Initialize(aLSTools);
293 for (; aIt.More(); aIt.Next()) {
294 const TopoDS_Shape& aS=aIt.Value();
298 pBOP->SetOperation(aOp);
301 TopTools_ListOfShape& aLSTools=BOPTest_Objects::Tools();
302 aIt.Initialize(aLSTools);
303 for (; aIt.More(); aIt.Next()) {
304 const TopoDS_Shape& aS=aIt.Value();
305 pBuilder->AddArgument(aS);
309 pBuilder->SetRunParallel(bRunParallel);
310 pBuilder->SetCheckInverted(BOPTest_Objects::CheckInverted());
311 pBuilder->SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
316 pBuilder->PerformWithFiller(aPF);
317 BOPTest::ReportAlerts(pBuilder->GetReport());
319 // Set history of Boolean operation into the session
320 if (BRepTest_Objects::IsHistoryNeeded())
321 BRepTest_Objects::SetHistory(aPF.Arguments(), *pBuilder);
323 if (pBuilder->HasErrors()) {
330 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
334 const TopoDS_Shape& aR=pBuilder->Shape();
336 di << " null shape\n";
340 BOPTest_Objects::SetBuilder(pBuilder);
342 DBRep::Set(a[1], aR);
346 //=======================================================================
349 //=======================================================================
350 Standard_Integer bsplit(Draw_Interpretor& di,
355 di << " use bsplit r [-t (show time)]\n";
359 BOPDS_PDS pDS = BOPTest_Objects::PDS();
361 di << " prepare PaveFiller first\n";
365 BOPAlgo_PaveFiller& aPF = BOPTest_Objects::PaveFiller();
367 BOPAlgo_Splitter* pSplitter = &BOPTest_Objects::Splitter();
371 const TopTools_ListOfShape& aLSObjects = BOPTest_Objects::Shapes();
372 pSplitter->SetArguments(aLSObjects);
375 TopTools_ListOfShape& aLSTools = BOPTest_Objects::Tools();
376 pSplitter->SetTools(aLSTools);
379 pSplitter->SetRunParallel(BOPTest_Objects::RunParallel());
380 pSplitter->SetNonDestructive(BOPTest_Objects::NonDestructive());
381 pSplitter->SetFuzzyValue(BOPTest_Objects::FuzzyValue());
382 pSplitter->SetCheckInverted(BOPTest_Objects::CheckInverted());
383 pSplitter->SetToFillHistory(BRepTest_Objects::IsHistoryNeeded());
385 // measure the time of the operation
389 // perform the operation
390 pSplitter->PerformWithFiller(aPF);
393 BOPTest::ReportAlerts(pSplitter->GetReport());
395 // Set history of Split operation into the session
396 if (BRepTest_Objects::IsHistoryNeeded())
397 BRepTest_Objects::SetHistory(aPF.Arguments(), *pSplitter);
399 if (pSplitter->HasErrors()) {
403 // show time if necessary
404 if (n == 3 && !strcmp(a[2], "-t")) {
406 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
410 // Debug commands support
411 BOPTest_Objects::SetBuilder(pSplitter);
413 const TopoDS_Shape& aR = pSplitter->Shape();
415 di << " null shape\n";
419 DBRep::Set(a[1], aR);