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 <BOPTest.hxx>
22 #include <BOPTest_DrawableShape.hxx>
23 #include <BOPTest_Objects.hxx>
26 #include <Draw_Color.hxx>
27 #include <DrawTrSurf.hxx>
28 #include <NCollection_IncAllocator.hxx>
29 #include <OSD_Timer.hxx>
30 #include <TopoDS_Shape.hxx>
36 static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
37 static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
38 static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
40 //=======================================================================
41 //function : PartitionCommands
43 //=======================================================================
44 void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
46 static Standard_Boolean done = Standard_False;
50 const char* g = "BOPTest commands";
52 theCommands.Add("bfillds", "use bfillds [-t]" , __FILE__, bfillds, g);
53 theCommands.Add("bbuild" , "use bbuild r [-t]" , __FILE__, bbuild, g);
54 theCommands.Add("bbop" , "use bbop r op [-t]", __FILE__, bbop, g);
56 //=======================================================================
59 //=======================================================================
60 Standard_Integer bfillds(Draw_Interpretor& di,
65 di << " use bfillds [-t]\n";
70 Standard_Boolean bRunParallel, bShowTime;
71 Standard_Integer i, aNbS, iErr;
73 BOPCol_ListIteratorOfListOfShape aIt;
74 BOPCol_ListOfShape aLC;
75 BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
78 di << " no objects to process\n";
82 bShowTime = Standard_False;
84 bRunParallel=BOPTest_Objects::RunParallel();
85 aTol=BOPTest_Objects::FuzzyValue();
88 if (!strcmp(a[i], "-t")) {
89 bShowTime=Standard_True;
93 BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
96 for (; aIt.More(); aIt.Next()) {
97 const TopoDS_Shape& aS=aIt.Value();
102 for (; aIt.More(); aIt.Next()) {
103 const TopoDS_Shape& aS=aIt.Value();
107 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
109 aPF.SetArguments(aLC);
110 aPF.SetRunParallel(bRunParallel);
111 aPF.SetFuzzyValue(aTol);
117 iErr=aPF.ErrorStatus();
119 Sprintf(buf, " error: %d\n", iErr);
128 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
134 //=======================================================================
137 //=======================================================================
138 Standard_Integer bbuild(Draw_Interpretor& di,
143 di << " use bbuild r [-t]\n";
147 BOPDS_PDS pDS=BOPTest_Objects::PDS();
149 di << " prepare PaveFiller first\n";
154 Standard_Boolean bRunParallel, bShowTime;
155 Standard_Integer i, iErr;
157 BOPCol_ListIteratorOfListOfShape aIt;
159 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
161 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
164 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
165 aIt.Initialize(aLSObj);
166 for (; aIt.More(); aIt.Next()) {
167 const TopoDS_Shape& aS=aIt.Value();
168 aBuilder.AddArgument(aS);
171 BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
172 aIt.Initialize(aLSTool);
173 for (; aIt.More(); aIt.Next()) {
174 const TopoDS_Shape& aS=aIt.Value();
175 aBuilder.AddArgument(aS);
178 bShowTime=Standard_False;
179 bRunParallel=BOPTest_Objects::RunParallel();
180 for (i=2; i<n; ++i) {
181 if (!strcmp(a[i], "-t")) {
182 bShowTime=Standard_True;
185 aBuilder.SetRunParallel(bRunParallel);
191 aBuilder.PerformWithFiller(aPF);
192 iErr=aBuilder.ErrorStatus();
194 Sprintf(buf, " error: %d\n", iErr);
203 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
207 const TopoDS_Shape& aR=aBuilder.Shape();
209 di << " null shape\n";
213 DBRep::Set(a[1], aR);
216 //=======================================================================
219 //=======================================================================
220 Standard_Integer bbop(Draw_Interpretor& di,
225 di << " use bbop r op [-t]\n";
229 BOPDS_PDS pDS=BOPTest_Objects::PDS();
231 di << " prepare PaveFiller first\n";
236 Standard_Boolean bRunParallel, bShowTime;
237 Standard_Integer iErr, iOp, i;
238 BOPAlgo_Operation aOp;
239 BOPCol_ListIteratorOfListOfShape aIt;
241 iOp=Draw::Atoi(a[2]);
242 if (iOp<0 || iOp>4) {
243 di << " invalid operation type\n";
246 aOp=(BOPAlgo_Operation)iOp;
248 bShowTime=Standard_False;
249 bRunParallel=BOPTest_Objects::RunParallel();
250 for (i=3; i<n; ++i) {
251 if (!strcmp(a[i], "-t")) {
252 bShowTime=Standard_True;
256 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
258 BOPAlgo_Builder *pBuilder=NULL;
260 if (aOp!=BOPAlgo_SECTION) {
261 pBuilder=&BOPTest_Objects::BOP();
264 pBuilder=&BOPTest_Objects::Section();
269 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
270 aIt.Initialize(aLSObj);
271 for (; aIt.More(); aIt.Next()) {
272 const TopoDS_Shape& aS=aIt.Value();
273 pBuilder->AddArgument(aS);
276 if (aOp!=BOPAlgo_SECTION) {
277 BOPAlgo_BOP *pBOP=(BOPAlgo_BOP *)pBuilder;
279 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
280 aIt.Initialize(aLSTools);
281 for (; aIt.More(); aIt.Next()) {
282 const TopoDS_Shape& aS=aIt.Value();
286 pBOP->SetOperation(aOp);
289 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
290 aIt.Initialize(aLSTools);
291 for (; aIt.More(); aIt.Next()) {
292 const TopoDS_Shape& aS=aIt.Value();
293 pBuilder->AddArgument(aS);
297 pBuilder->SetRunParallel(bRunParallel);
302 pBuilder->PerformWithFiller(aPF);
303 iErr=pBuilder->ErrorStatus();
305 Sprintf(buf, " error: %d\n", iErr);
313 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
317 const TopoDS_Shape& aR=pBuilder->Shape();
319 di << " null shape\n";
323 DBRep::Set(a[1], aR);