4e57c75e |
1 | // Created by: Peter KURNEV |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
19 | |
20 | #include <BOPTest.ixx> |
21 | |
22 | #include <stdio.h> |
796a784d |
23 | #include <string.h> |
4e57c75e |
24 | |
25 | #include <NCollection_IncAllocator.hxx> |
26 | |
27 | #include <DBRep.hxx> |
28 | #include <Draw.hxx> |
29 | #include <Draw_Color.hxx> |
30 | #include <DrawTrSurf.hxx> |
31 | |
32 | #include <TopoDS_Shape.hxx> |
33 | // |
34 | #include <BOPAlgo_Builder.hxx> |
35 | #include <BOPAlgo_PaveFiller.hxx> |
36 | #include <BOPAlgo_Operation.hxx> |
37 | #include <BOPAlgo_BOP.hxx> |
38 | // |
39 | #include <BOPTest_DrawableShape.hxx> |
40 | #include <BOPTest_Objects.hxx> |
41 | |
42 | // |
796a784d |
43 | #ifdef HAVE_TBB |
44 | #include <BOPCol_TBB.hxx> |
45 | //======================================================================= |
46 | //class : BOPTime_Chronometer |
47 | //purpose : |
48 | //======================================================================= |
49 | class BOPTime_Chronometer { |
50 | public: |
51 | BOPTime_Chronometer() { |
52 | } |
53 | // |
54 | ~BOPTime_Chronometer() { |
55 | } |
56 | // |
57 | void Start() { |
58 | myT0 = tick_count::now(); |
59 | } |
60 | // |
61 | void Stop() { |
62 | myTime=(tick_count::now() - myT0).seconds(); |
63 | } |
64 | // |
65 | double Time() const{ |
66 | return myTime; |
67 | }; |
68 | // |
69 | protected: |
70 | tick_count myT0; |
71 | double myTime; |
72 | }; |
73 | //////////////////////////////////////////////////////////////////////// |
74 | #else |
75 | #include <OSD_Chronometer.hxx> |
76 | //======================================================================= |
77 | //class : BOPTime_Chronometer |
78 | //purpose : |
79 | //======================================================================= |
80 | class BOPTime_Chronometer { |
81 | public: |
82 | BOPTime_Chronometer() { |
83 | } |
84 | // |
85 | ~BOPTime_Chronometer() { |
86 | } |
87 | // |
88 | void Start() { |
89 | myChronometer.Reset(); |
90 | myChronometer.Start(); |
91 | } |
92 | // |
93 | void Stop() { |
94 | myChronometer.Stop(); |
95 | myChronometer.Show(myTime); |
96 | } |
97 | // |
98 | double Time() const{ |
99 | return myTime; |
100 | }; |
101 | // |
102 | protected: |
103 | OSD_Chronometer myChronometer; |
104 | double myTime; |
105 | }; |
106 | #endif |
107 | |
108 | |
109 | |
4e57c75e |
110 | static Standard_Integer bfillds (Draw_Interpretor&, Standard_Integer, const char**); |
111 | static Standard_Integer bbuild (Draw_Interpretor&, Standard_Integer, const char**); |
112 | static Standard_Integer bbop (Draw_Interpretor&, Standard_Integer, const char**); |
113 | static Standard_Integer bclear (Draw_Interpretor&, Standard_Integer, const char**); |
114 | //======================================================================= |
115 | //function : PartitionCommands |
116 | //purpose : |
117 | //======================================================================= |
118 | void BOPTest::PartitionCommands(Draw_Interpretor& theCommands) |
119 | { |
120 | static Standard_Boolean done = Standard_False; |
121 | if (done) return; |
122 | done = Standard_True; |
123 | // Chapter's name |
124 | const char* g = "Partition commands"; |
125 | // Commands |
126 | theCommands.Add("bfillds" , "use bfillds" , __FILE__, bfillds , g); |
796a784d |
127 | theCommands.Add("bbuild" , " use bbuild r [-s -t]" , __FILE__, bbuild, g); |
4e57c75e |
128 | theCommands.Add("bbop" , "use bbop r op" , __FILE__, bbop, g); |
129 | theCommands.Add("bclear" , "use bclear" , __FILE__, bclear, g); |
130 | } |
131 | |
132 | //======================================================================= |
133 | //function : bclear |
134 | //purpose : |
135 | //======================================================================= |
136 | Standard_Integer bclear(Draw_Interpretor& di, Standard_Integer n, const char** ) |
137 | { |
138 | if (n!=1) { |
139 | di << " use bclear\n"; |
140 | return 0; |
141 | } |
142 | // |
143 | BOPTest_Objects::Clear(); |
144 | return 0; |
145 | } |
146 | //======================================================================= |
147 | //function : bfillds |
148 | //purpose : |
149 | //======================================================================= |
150 | Standard_Integer bfillds(Draw_Interpretor& di, Standard_Integer n, const char** ) |
151 | { |
152 | if (n!=1) { |
153 | di << " Use bfillds\n"; |
154 | return 0; |
155 | } |
156 | // |
157 | char buf[32]; |
158 | Standard_Integer aNbS, aNbT, iErr; |
159 | BOPCol_ListIteratorOfListOfShape aIt; |
160 | BOPCol_ListOfShape aLC; |
161 | |
162 | BOPCol_ListOfShape& aLS=BOPTest_Objects::Shapes(); |
163 | aNbS=aLS.Extent(); |
164 | if (!aNbS) { |
165 | di << " no objects to process\n"; |
166 | return 0; |
167 | } |
168 | // |
169 | BOPCol_ListOfShape& aLT=BOPTest_Objects::Tools(); |
170 | aNbT=aLT.Extent(); |
171 | // |
172 | aIt.Initialize(aLS); |
173 | for (; aIt.More(); aIt.Next()) { |
174 | const TopoDS_Shape& aS=aIt.Value(); |
175 | aLC.Append(aS); |
176 | } |
177 | // |
178 | aIt.Initialize(aLT); |
179 | for (; aIt.More(); aIt.Next()) { |
180 | const TopoDS_Shape& aS=aIt.Value(); |
181 | aLC.Append(aS); |
182 | } |
183 | // |
184 | BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); |
185 | // |
186 | aPF.SetArguments(aLC); |
187 | // |
188 | aPF.Perform(); |
189 | iErr=aPF.ErrorStatus(); |
190 | if (iErr) { |
191 | Sprintf(buf, " error: %d\n", iErr); |
192 | di << buf; |
193 | return 0; |
194 | } |
195 | // |
196 | return 0; |
197 | } |
4e57c75e |
198 | //======================================================================= |
199 | //function : bbuild |
200 | //purpose : |
201 | //======================================================================= |
202 | Standard_Integer bbuild(Draw_Interpretor& di, Standard_Integer n, const char** a) |
203 | { |
796a784d |
204 | if (n<2) { |
205 | di << " use bbuild r [-s -t]\n"; |
4e57c75e |
206 | return 0; |
207 | } |
208 | // |
209 | BOPDS_PDS pDS=BOPTest_Objects::PDS(); |
210 | if (!pDS) { |
211 | di << " prepare PaveFiller first\n"; |
212 | return 0; |
213 | } |
214 | // |
796a784d |
215 | char buf[128]; |
216 | Standard_Boolean bRunParallel, bShowTime; |
217 | Standard_Integer i, iErr; |
218 | |
219 | BOPTime_Chronometer aChrono; |
4e57c75e |
220 | BOPCol_ListIteratorOfListOfShape aIt; |
796a784d |
221 | // |
222 | |
4e57c75e |
223 | // |
224 | BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); |
225 | // |
226 | BOPAlgo_Builder& aBuilder=BOPTest_Objects::Builder(); |
227 | aBuilder.Clear(); |
228 | // |
229 | BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes(); |
230 | aIt.Initialize(aLSObj); |
231 | for (; aIt.More(); aIt.Next()) { |
232 | const TopoDS_Shape& aS=aIt.Value(); |
233 | aBuilder.AddArgument(aS); |
234 | } |
235 | // |
236 | BOPCol_ListOfShape& aLSTool=BOPTest_Objects::Tools(); |
237 | aIt.Initialize(aLSTool); |
238 | for (; aIt.More(); aIt.Next()) { |
239 | const TopoDS_Shape& aS=aIt.Value(); |
240 | aBuilder.AddArgument(aS); |
241 | } |
242 | // |
796a784d |
243 | bShowTime=Standard_False; |
244 | bRunParallel=Standard_True; |
245 | for (i=2; i<n; ++i) { |
246 | if (!strcmp(a[i], "-s")) { |
247 | bRunParallel=Standard_False; |
248 | } |
249 | else if (!strcmp(a[i], "-t")) { |
250 | bShowTime=Standard_True; |
251 | } |
252 | } |
253 | aBuilder.SetRunParallel(bRunParallel); |
254 | // |
255 | // |
256 | aChrono.Start(); |
257 | // |
258 | aBuilder.PerformWithFiller(aPF); |
4e57c75e |
259 | iErr=aBuilder.ErrorStatus(); |
260 | if (iErr) { |
261 | Sprintf(buf, " error: %d\n", iErr); |
262 | di << buf; |
263 | return 0; |
264 | } |
265 | // |
796a784d |
266 | aChrono.Stop(); |
267 | // |
268 | if (bShowTime) { |
269 | Standard_Real aTime; |
270 | // |
271 | aTime=aChrono.Time(); |
272 | Sprintf(buf, " Tps: %7.2lf\n", aTime); |
273 | di << buf; |
274 | } |
275 | // |
4e57c75e |
276 | const TopoDS_Shape& aR=aBuilder.Shape(); |
277 | if (aR.IsNull()) { |
278 | di << " null shape\n"; |
279 | return 0; |
280 | } |
281 | // |
282 | DBRep::Set(a[1], aR); |
283 | return 0; |
284 | } |
285 | |
286 | //======================================================================= |
287 | //function : bbop |
288 | //purpose : |
289 | //======================================================================= |
290 | Standard_Integer bbop(Draw_Interpretor& di, Standard_Integer n, const char** a) |
291 | { |
292 | if (n!=3) { |
293 | di << " use bbop r op\n"; |
294 | return 0; |
295 | } |
296 | // |
297 | BOPDS_PDS pDS=BOPTest_Objects::PDS(); |
298 | if (!pDS) { |
299 | di << " prepare PaveFiller first\n"; |
300 | return 0; |
301 | } |
302 | // |
303 | char buf[32]; |
304 | Standard_Integer iErr, iOp; |
305 | BOPAlgo_Operation aOp; |
306 | BOPCol_ListIteratorOfListOfShape aIt; |
307 | // |
308 | iOp=Draw::Atoi(a[2]); |
309 | if (iOp<0 || iOp>4) { |
310 | di << " invalid operation type\n"; |
311 | } |
312 | aOp=(BOPAlgo_Operation)iOp; |
313 | // |
314 | BOPAlgo_PaveFiller& aPF=BOPTest_Objects::PaveFiller(); |
315 | // |
316 | BOPAlgo_BOP& aBOP=BOPTest_Objects::BOP(); |
317 | aBOP.Clear(); |
318 | // |
319 | BOPCol_ListOfShape& aLSObj=BOPTest_Objects::Shapes(); |
320 | aIt.Initialize(aLSObj); |
321 | for (; aIt.More(); aIt.Next()) { |
322 | const TopoDS_Shape& aS=aIt.Value(); |
323 | aBOP.AddArgument(aS); |
324 | } |
325 | // |
326 | BOPCol_ListOfShape& aLSTools=BOPTest_Objects::Tools(); |
327 | aIt.Initialize(aLSTools); |
328 | for (; aIt.More(); aIt.Next()) { |
329 | const TopoDS_Shape& aS=aIt.Value(); |
330 | aBOP.AddTool(aS); |
331 | } |
332 | // |
333 | aBOP.SetOperation(aOp); |
334 | // |
335 | aBOP.PerformWithFiller(aPF); |
336 | iErr=aBOP.ErrorStatus(); |
337 | if (iErr) { |
338 | Sprintf(buf, " error: %d\n", iErr); |
339 | di << buf; |
340 | return 0; |
341 | } |
342 | // |
343 | const TopoDS_Shape& aR=aBOP.Shape(); |
344 | if (aR.IsNull()) { |
345 | di << " null shape\n"; |
346 | return 0; |
347 | } |
348 | // |
349 | DBRep::Set(a[1], aR); |
350 | return 0; |
351 | } |
352 | |