0028501: Incomplete result of offset operation in mode Complete with Join type inters...
[occt.git] / src / BOPTest / BOPTest_PartitionCommands.cxx
1 // Created by: Peter KURNEV
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
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>
24 #include <DBRep.hxx>
25 #include <Draw.hxx>
26 #include <Draw_Color.hxx>
27 #include <DrawTrSurf.hxx>
28 #include <OSD_Timer.hxx>
29 #include <TopoDS_Shape.hxx>
30
31 #include <stdio.h>
32 #include <string.h>
33 //
34 //
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**);
38
39 //=======================================================================
40 //function : PartitionCommands
41 //purpose  : 
42 //=======================================================================
43 void BOPTest::PartitionCommands(Draw_Interpretor& theCommands)
44 {
45   static Standard_Boolean done = Standard_False;
46   if (done) return;
47   done = Standard_True;
48   // Chapter's name
49   const char* g = "BOPTest commands";
50   // 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);
54 }
55 //=======================================================================
56 //function : bfillds
57 //purpose  : 
58 //=======================================================================
59 Standard_Integer bfillds(Draw_Interpretor& di, 
60                          Standard_Integer n, 
61                          const char** a) 
62
63   if (n > 2) {
64     di << " use bfillds [-t]\n";
65     return 0;
66   }
67   //
68   char buf[32];
69   Standard_Boolean bRunParallel, bNonDestructive, bShowTime;
70   Standard_Integer i, aNbS, iErr;
71   Standard_Real aTol;
72   BOPCol_ListIteratorOfListOfShape aIt;
73   BOPCol_ListOfShape aLC;
74   BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes();
75   aNbS=aLS.Extent();
76   if (!aNbS) {
77     di << " no objects to process\n";
78     return 0;
79   }
80   //
81   bShowTime = Standard_False;
82   //
83   bRunParallel=BOPTest_Objects::RunParallel();
84   bNonDestructive = BOPTest_Objects::NonDestructive();
85   aTol = BOPTest_Objects::FuzzyValue();
86   BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue();
87   //
88   for (i=1; i<n; ++i) {
89     if (!strcmp(a[i], "-t")) {
90       bShowTime=Standard_True;
91     }
92   }
93   //
94   BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools();
95   //
96   aIt.Initialize(aLS);
97   for (; aIt.More(); aIt.Next()) {
98     const TopoDS_Shape& aS=aIt.Value();
99     aLC.Append(aS);
100   }
101   //
102   aIt.Initialize(aLT);
103   for (; aIt.More(); aIt.Next()) {
104     const TopoDS_Shape& aS=aIt.Value();
105      aLC.Append(aS);
106   }
107   //
108   BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
109   //
110   aPF.SetArguments(aLC);
111   aPF.SetRunParallel(bRunParallel);
112   aPF.SetNonDestructive(bNonDestructive);
113   aPF.SetFuzzyValue(aTol);
114   aPF.SetGlue(aGlue);
115   //
116   OSD_Timer aTimer;
117   aTimer.Start();
118   //
119   aPF.Perform();
120   iErr=aPF.ErrorStatus();
121   if (iErr) {
122     Sprintf(buf, " error: %d\n",  iErr);
123     di << buf;
124     return 0;
125   }
126   //
127   aTimer.Stop();
128   //
129   if (bShowTime)
130   {
131     Sprintf(buf, "  Tps: %7.2lf\n", aTimer.ElapsedTime());
132     di << buf;
133   }
134   //
135   return 0;
136 }
137 //=======================================================================
138 //function : bbuild
139 //purpose  : 
140 //=======================================================================
141 Standard_Integer bbuild(Draw_Interpretor& di,
142                         Standard_Integer n, 
143                         const char** a) 
144
145   if (n<2) {
146     di << " use bbuild r [-t]\n";
147     return 0;
148   }
149   //
150   BOPDS_PDS pDS=BOPTest_Objects::PDS();
151   if (!pDS) {
152     di << " prepare PaveFiller first\n";
153     return 0;
154   }
155   //
156   char buf[128];
157   Standard_Boolean bRunParallel, bShowTime;
158   Standard_Integer i, iErr;
159
160   BOPCol_ListIteratorOfListOfShape aIt;
161   //
162   BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
163   //
164   BOPTest_Objects::SetBuilderDefault();
165   BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder();
166   aBuilder.Clear();
167   //
168   BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
169   aIt.Initialize(aLSObj);
170   for (; aIt.More(); aIt.Next()) {
171     const TopoDS_Shape& aS=aIt.Value();
172     aBuilder.AddArgument(aS);
173   }
174   //
175   BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools();
176   aIt.Initialize(aLSTool);
177   for (; aIt.More(); aIt.Next()) {
178     const TopoDS_Shape& aS=aIt.Value();
179     aBuilder.AddArgument(aS);
180   }
181   //
182   bShowTime=Standard_False;
183   bRunParallel=BOPTest_Objects::RunParallel();
184   for (i=2; i<n; ++i) {
185     if (!strcmp(a[i], "-t")) {
186       bShowTime=Standard_True;
187     }
188   }
189   aBuilder.SetRunParallel(bRunParallel);
190   //
191   //
192   OSD_Timer aTimer;
193   aTimer.Start();
194   //
195   aBuilder.PerformWithFiller(aPF); 
196   iErr=aBuilder.ErrorStatus();
197   if (iErr) {
198     Sprintf(buf, " error: %d\n",  iErr);
199     di << buf;
200     return 0;
201   }
202   //
203   aTimer.Stop();
204   //
205   if (bShowTime)
206   {
207     Sprintf(buf, "  Tps: %7.2lf\n", aTimer.ElapsedTime());
208     di << buf;
209   }
210   //
211   const TopoDS_Shape& aR=aBuilder.Shape();
212   if (aR.IsNull()) {
213     di << " null shape\n";
214     return 0;
215   }
216   //
217   DBRep::Set(a[1], aR);
218   return 0;
219 }
220 //=======================================================================
221 //function : bbop
222 //purpose  : 
223 //=======================================================================
224 Standard_Integer bbop(Draw_Interpretor& di, 
225                       Standard_Integer n, 
226                       const char** a) 
227
228   if (n<3) {
229     di << " use bbop r op [-t]\n";
230     return 0;
231   }
232   //
233   BOPDS_PDS pDS=BOPTest_Objects::PDS();
234   if (!pDS) {
235     di << " prepare PaveFiller first\n";
236     return 0;
237   }
238   //
239   char buf[32];
240   Standard_Boolean bRunParallel, bShowTime;
241   Standard_Integer iErr, iOp, i;
242   BOPAlgo_Operation aOp;
243   BOPCol_ListIteratorOfListOfShape aIt; 
244   //
245   iOp=Draw::Atoi(a[2]);
246   if (iOp<0 || iOp>4) {
247     di << " invalid operation type\n";
248     return 0;
249   }
250   aOp=(BOPAlgo_Operation)iOp;
251   //
252   bShowTime=Standard_False;
253   bRunParallel=BOPTest_Objects::RunParallel();
254   for (i=3; i<n; ++i) {
255     if (!strcmp(a[i], "-t")) {
256       bShowTime=Standard_True;
257     }
258   }
259   //
260   BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller();
261   //
262   BOPAlgo_Builder *pBuilder=NULL;
263   
264   if (aOp!=BOPAlgo_SECTION) { 
265     pBuilder=&BOPTest_Objects::BOP();
266   } 
267   else {
268     pBuilder=&BOPTest_Objects::Section();
269   }
270   //
271   pBuilder->Clear();
272   //
273   BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes();
274   aIt.Initialize(aLSObj);
275   for (; aIt.More(); aIt.Next()) {
276     const TopoDS_Shape& aS=aIt.Value();
277     pBuilder->AddArgument(aS);
278   }
279   //
280   if (aOp!=BOPAlgo_SECTION) {
281     BOPAlgo_BOP *pBOP=(BOPAlgo_BOP *)pBuilder;
282     //
283     BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
284     aIt.Initialize(aLSTools);
285     for (; aIt.More(); aIt.Next()) {
286       const TopoDS_Shape& aS=aIt.Value();
287       pBOP->AddTool(aS);
288     }
289     //
290     pBOP->SetOperation(aOp);
291   }
292   else {
293     BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools();
294     aIt.Initialize(aLSTools);
295     for (; aIt.More(); aIt.Next()) {
296       const TopoDS_Shape& aS=aIt.Value();
297       pBuilder->AddArgument(aS);
298     }
299   }
300   //
301   pBuilder->SetRunParallel(bRunParallel);
302   //
303   OSD_Timer aTimer;
304   aTimer.Start();
305   //
306   pBuilder->PerformWithFiller(aPF);
307   iErr=pBuilder->ErrorStatus();
308   if (iErr) {
309     Sprintf(buf, " error: %d\n",  iErr);
310     di << buf;
311     return 0;
312   }
313   //
314   aTimer.Stop();
315   //
316   if (bShowTime) {
317     Sprintf(buf, "  Tps: %7.2lf\n", aTimer.ElapsedTime());
318     di << buf;
319   }
320   //
321   const TopoDS_Shape& aR=pBuilder->Shape();
322   if (aR.IsNull()) {
323     di << " null shape\n";
324     return 0;
325   }
326   //
327   BOPTest_Objects::SetBuilder(pBuilder);
328   //
329   DBRep::Set(a[1], aR);
330   return 0;
331 }
332