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 <OSD_Timer.hxx>
29 #include <TopoDS_Shape.hxx>
35 static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**);
36 static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**);
37 static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**);
39 //=======================================================================
40 //function : PartitionCommands
42 //=======================================================================
43 void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
45 static Standard_Boolean done = Standard_False;
49 const char* g = "BOPTest commands";
51 theCommands.Add("bfillds", "use bfillds [-t]" , __FILE__, bfillds, g);
52 theCommands.Add("bbuild" , "use bbuild r [-t]" , __FILE__, bbuild, g);
53 theCommands.Add("bbop" , "use bbop r op [-t]", __FILE__, bbop, g);
55 //=======================================================================
58 //=======================================================================
59 Standard_Integer bfillds(Draw_Interpretor& di,
64 di << " use bfillds [-t]\n";
69 Standard_Boolean bRunParallel, bNonDestructive, bShowTime;
70 Standard_Integer i, aNbS, iErr;
72 BOPCol_ListIteratorOfListOfShape aIt;
73 BOPCol_ListOfShape aLC;
74 BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
77 di << " no objects to process\n";
81 bShowTime = Standard_False;
83 bRunParallel=BOPTest_Objects::RunParallel();
84 bNonDestructive = BOPTest_Objects::NonDestructive();
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.SetNonDestructive(bNonDestructive);
112 aPF.SetFuzzyValue(aTol);
118 iErr=aPF.ErrorStatus();
120 Sprintf(buf, " error: %d\n", iErr);
129 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
135 //=======================================================================
138 //=======================================================================
139 Standard_Integer bbuild(Draw_Interpretor& di,
144 di << " use bbuild r [-t]\n";
148 BOPDS_PDS pDS=BOPTest_Objects::PDS();
150 di << " prepare PaveFiller first\n";
155 Standard_Boolean bRunParallel, bShowTime;
156 Standard_Integer i, iErr;
158 BOPCol_ListIteratorOfListOfShape aIt;
160 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
162 BOPTest_Objects::SetBuilderDefault();
163 BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
166 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
167 aIt.Initialize(aLSObj);
168 for (; aIt.More(); aIt.Next()) {
169 const TopoDS_Shape& aS=aIt.Value();
170 aBuilder.AddArgument(aS);
173 BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
174 aIt.Initialize(aLSTool);
175 for (; aIt.More(); aIt.Next()) {
176 const TopoDS_Shape& aS=aIt.Value();
177 aBuilder.AddArgument(aS);
180 bShowTime=Standard_False;
181 bRunParallel=BOPTest_Objects::RunParallel();
182 for (i=2; i<n; ++i) {
183 if (!strcmp(a[i], "-t")) {
184 bShowTime=Standard_True;
187 aBuilder.SetRunParallel(bRunParallel);
193 aBuilder.PerformWithFiller(aPF);
194 iErr=aBuilder.ErrorStatus();
196 Sprintf(buf, " error: %d\n", iErr);
205 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
209 const TopoDS_Shape& aR=aBuilder.Shape();
211 di << " null shape\n";
215 DBRep::Set(a[1], aR);
218 //=======================================================================
221 //=======================================================================
222 Standard_Integer bbop(Draw_Interpretor& di,
227 di << " use bbop r op [-t]\n";
231 BOPDS_PDS pDS=BOPTest_Objects::PDS();
233 di << " prepare PaveFiller first\n";
238 Standard_Boolean bRunParallel, bShowTime;
239 Standard_Integer iErr, iOp, i;
240 BOPAlgo_Operation aOp;
241 BOPCol_ListIteratorOfListOfShape aIt;
243 iOp=Draw::Atoi(a[2]);
244 if (iOp<0 || iOp>4) {
245 di << " invalid operation type\n";
248 aOp=(BOPAlgo_Operation)iOp;
250 bShowTime=Standard_False;
251 bRunParallel=BOPTest_Objects::RunParallel();
252 for (i=3; i<n; ++i) {
253 if (!strcmp(a[i], "-t")) {
254 bShowTime=Standard_True;
258 BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
260 BOPAlgo_Builder *pBuilder=NULL;
262 if (aOp!=BOPAlgo_SECTION) {
263 pBuilder=&BOPTest_Objects::BOP();
266 pBuilder=&BOPTest_Objects::Section();
271 BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
272 aIt.Initialize(aLSObj);
273 for (; aIt.More(); aIt.Next()) {
274 const TopoDS_Shape& aS=aIt.Value();
275 pBuilder->AddArgument(aS);
278 if (aOp!=BOPAlgo_SECTION) {
279 BOPAlgo_BOP *pBOP=(BOPAlgo_BOP *)pBuilder;
281 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
282 aIt.Initialize(aLSTools);
283 for (; aIt.More(); aIt.Next()) {
284 const TopoDS_Shape& aS=aIt.Value();
288 pBOP->SetOperation(aOp);
291 BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
292 aIt.Initialize(aLSTools);
293 for (; aIt.More(); aIt.Next()) {
294 const TopoDS_Shape& aS=aIt.Value();
295 pBuilder->AddArgument(aS);
299 pBuilder->SetRunParallel(bRunParallel);
304 pBuilder->PerformWithFiller(aPF);
305 iErr=pBuilder->ErrorStatus();
307 Sprintf(buf, " error: %d\n", iErr);
315 Sprintf(buf, " Tps: %7.2lf\n", aTimer.ElapsedTime());
319 const TopoDS_Shape& aR=pBuilder->Shape();
321 di << " null shape\n";
325 BOPTest_Objects::SetBuilder(pBuilder);
327 DBRep::Set(a[1], aR);