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.
15 #include <BOPTest.ixx>
20 #include <NCollection_IncAllocator.hxx>
24 #include <Draw_Color.hxx>
25 #include <DrawTrSurf.hxx>
27 #include <TopoDS_Shape.hxx>
29 #include <BOPAlgo_Builder.hxx>
30 #include <BOPAlgo_PaveFiller.hxx>
31 #include <BOPAlgo_Operation.hxx>
32 #include <BOPAlgo_BOP.hxx>
33 #include <BOPAlgo_Section.hxx>
35 #include <BOPTest_DrawableShape.hxx>
36 #include <BOPTest_Objects.hxx>
38 #include <BOPTest_Chronometer.hxx>
40 static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
41 static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
42 static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
44 //=======================================================================
45 //function : PartitionCommands
47 //=======================================================================
48 void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
50 static Standard_Boolean done = Standard_False;
54 const char* g = "BOPTest commands";
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);
60 //=======================================================================
63 //=======================================================================
64 Standard_Integer bfillds(Draw_Interpretor& di,
69 di << " use bfillds [-t]\n";
74 Standard_Boolean bRunParallel, bShowTime;
75 Standard_Integer i, aNbS, iErr;
77 BOPCol_ListIteratorOfListOfShape aIt;
78 BOPCol_ListOfShape aLC;
79 BOPTest_Chronometer aChrono;
81 BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
84 di << " no objects to process\n";
88 bShowTime = Standard_False;
90 bRunParallel=BOPTest_Objects::RunParallel();
91 aTol=BOPTest_Objects::FuzzyValue();
94 if (!strcmp(a[i], "-t")) {
95 bShowTime=Standard_True;
99 BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
102 for (; aIt.More(); aIt.Next()) {
103 const TopoDS_Shape& aS=aIt.Value();
108 for (; aIt.More(); aIt.Next()) {
109 const TopoDS_Shape& aS=aIt.Value();
113 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
115 aPF.SetArguments(aLC);
116 aPF.SetRunParallel(bRunParallel);
117 aPF.SetFuzzyValue(aTol);
122 iErr=aPF.ErrorStatus();
124 Sprintf(buf, " error: %d\n", iErr);
134 aTime=aChrono.Time();
135 Sprintf(buf, " Tps: %7.2lf\n", aTime);
141 //=======================================================================
144 //=======================================================================
145 Standard_Integer bbuild(Draw_Interpretor& di,
150 di << " use bbuild r [-t]\n";
154 BOPDS_PDS pDS=BOPTest_Objects::PDS();
156 di << " prepare PaveFiller first\n";
161 Standard_Boolean bRunParallel, bShowTime;
162 Standard_Integer i, iErr;
164 BOPTest_Chronometer aChrono;
165 BOPCol_ListIteratorOfListOfShape aIt;
167 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
169 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
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);
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);
186 bShowTime=Standard_False;
187 bRunParallel=BOPTest_Objects::RunParallel();
188 for (i=2; i<n; ++i) {
189 if (!strcmp(a[i], "-t")) {
190 bShowTime=Standard_True;
193 aBuilder.SetRunParallel(bRunParallel);
198 aBuilder.PerformWithFiller(aPF);
199 iErr=aBuilder.ErrorStatus();
201 Sprintf(buf, " error: %d\n", iErr);
211 aTime=aChrono.Time();
212 Sprintf(buf, " Tps: %7.2lf\n", aTime);
216 const TopoDS_Shape& aR=aBuilder.Shape();
218 di << " null shape\n";
222 DBRep::Set(a[1], aR);
225 //=======================================================================
228 //=======================================================================
229 Standard_Integer bbop(Draw_Interpretor& di,
234 di << " use bbop r op [-t]\n";
238 BOPDS_PDS pDS=BOPTest_Objects::PDS();
240 di << " prepare PaveFiller first\n";
245 Standard_Boolean bRunParallel, bShowTime;
246 Standard_Integer iErr, iOp, i;
247 BOPAlgo_Operation aOp;
248 BOPCol_ListIteratorOfListOfShape aIt;
249 BOPTest_Chronometer aChrono;
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 BOPCol_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 BOPCol_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 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);
307 pBuilder->SetRunParallel(bRunParallel);
311 pBuilder->PerformWithFiller(aPF);
312 iErr=pBuilder->ErrorStatus();
314 Sprintf(buf, " error: %d\n", iErr);
324 aTime=aChrono.Time();
325 Sprintf(buf, " Tps: %7.2lf\n", aTime);
329 const TopoDS_Shape& aR=pBuilder->Shape();
331 di << " null shape\n";
335 DBRep::Set(a[1], aR);