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