338434c7 |
1 | // Created by: Eugeny MALTCHIKOV |
2 | // Copyright (c) 2015 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 | #include <BOPTest.hxx> |
16 | #include <BOPTest_Objects.hxx> |
17 | |
18 | #include <Draw.hxx> |
19 | #include <TopoDS_Shape.hxx> |
20 | #include <DBRep.hxx> |
21 | |
22 | #include <BOPDS_DS.hxx> |
23 | #include <BOPAlgo_PaveFiller.hxx> |
24 | #include <BOPAlgo_CellsBuilder.hxx> |
25 | |
26 | |
27 | static Standard_Integer bcbuild (Draw_Interpretor&, Standard_Integer, const char**); |
28 | static Standard_Integer bcaddall (Draw_Interpretor&, Standard_Integer, const char**); |
29 | static Standard_Integer bcremoveall (Draw_Interpretor&, Standard_Integer, const char**); |
30 | static Standard_Integer bcadd (Draw_Interpretor&, Standard_Integer, const char**); |
31 | static Standard_Integer bcremove (Draw_Interpretor&, Standard_Integer, const char**); |
32 | static Standard_Integer bcremoveint (Draw_Interpretor&, Standard_Integer, const char**); |
33 | static Standard_Integer bcmakecontainers (Draw_Interpretor&, Standard_Integer, const char**); |
34 | |
35 | //======================================================================= |
36 | //function : CellsCommands |
37 | //purpose : |
38 | //======================================================================= |
39 | void BOPTest::CellsCommands(Draw_Interpretor& theCommands) |
40 | { |
41 | static Standard_Boolean done = Standard_False; |
42 | if (done) return; |
43 | done = Standard_True; |
44 | // Chapter's name |
45 | const char* g = "BOPTest commands"; |
46 | // Commands |
47 | |
48 | theCommands.Add("bcbuild", "Cells builder. Use: bcbuild r", |
49 | __FILE__, bcbuild, g); |
50 | theCommands.Add("bcaddall", "Add all parts to result. Use: bcaddall r [-m material [-u]]", |
51 | __FILE__, bcaddall, g); |
52 | theCommands.Add("bcremoveall", "Remove all parts from result. Use: bcremoveall", |
53 | __FILE__, bcremoveall, g); |
54 | theCommands.Add("bcadd", "Add parts to result. Use: bcadd r s1 (0,1) s2 (0,1) ... [-m material [-u]]", |
55 | __FILE__, bcadd, g); |
56 | theCommands.Add("bcremove", "Remove parts from result. Use: bcremove r s1 (0,1) s2 (0,1) ...", |
57 | __FILE__, bcremove, g); |
58 | theCommands.Add("bcremoveint", "Remove internal boundaries. Use: bcremoveint r", |
59 | __FILE__, bcremoveint, g); |
60 | theCommands.Add("bcmakecontainers", "Make containers from the parts added to result. Use: bcmakecontainers r", |
61 | __FILE__, bcmakecontainers, g); |
62 | } |
63 | |
64 | //======================================================================= |
65 | //function : bcbuild |
66 | //purpose : |
67 | //======================================================================= |
68 | Standard_Integer bcbuild(Draw_Interpretor& di, |
69 | Standard_Integer n, |
70 | const char** a) |
71 | { |
72 | if (n != 2) { |
73 | di << "Cells builder. Use: bcbuild r\n"; |
74 | return 1; |
75 | } |
76 | // |
77 | BOPDS_PDS pDS = BOPTest_Objects::PDS(); |
78 | if (!pDS) { |
79 | di << " prepare PaveFiller first\n"; |
80 | return 1; |
81 | } |
82 | // |
338434c7 |
83 | BOPCol_ListIteratorOfListOfShape aIt; |
84 | // |
85 | BOPAlgo_PaveFiller& aPF = BOPTest_Objects::PaveFiller(); |
86 | // |
87 | BOPAlgo_CellsBuilder& aCBuilder = BOPTest_Objects::CellsBuilder(); |
88 | aCBuilder.Clear(); |
89 | // |
90 | BOPCol_ListOfShape& aLSObj = BOPTest_Objects::Shapes(); |
91 | aIt.Initialize(aLSObj); |
92 | for (; aIt.More(); aIt.Next()) { |
93 | const TopoDS_Shape& aS = aIt.Value(); |
94 | aCBuilder.AddArgument(aS); |
95 | } |
96 | // |
97 | BOPCol_ListOfShape& aLSTool = BOPTest_Objects::Tools(); |
98 | aIt.Initialize(aLSTool); |
99 | for (; aIt.More(); aIt.Next()) { |
100 | const TopoDS_Shape& aS = aIt.Value(); |
101 | aCBuilder.AddArgument(aS); |
102 | } |
103 | // |
483ce1bd |
104 | // set the options to the algorithm |
105 | Standard_Boolean bRunParallel = BOPTest_Objects::RunParallel(); |
106 | Standard_Real aTol = BOPTest_Objects::FuzzyValue(); |
107 | Standard_Boolean bNonDestructive = BOPTest_Objects::NonDestructive(); |
108 | BOPAlgo_GlueEnum aGlue = BOPTest_Objects::Glue(); |
109 | // |
338434c7 |
110 | aCBuilder.SetRunParallel(bRunParallel); |
483ce1bd |
111 | aCBuilder.SetFuzzyValue(aTol); |
112 | aCBuilder.SetNonDestructive(bNonDestructive); |
113 | aCBuilder.SetGlue(aGlue); |
338434c7 |
114 | // |
115 | aCBuilder.PerformWithFiller(aPF); |
33ba8565 |
116 | BOPTest::ReportAlerts(aCBuilder); |
117 | if (aCBuilder.HasErrors()) { |
118 | return 0; |
338434c7 |
119 | } |
120 | // |
121 | BOPTest_Objects::SetBuilder(&aCBuilder); |
122 | // |
123 | const TopoDS_Shape& aR = aCBuilder.GetAllParts(); |
124 | if (aR.IsNull()) { |
125 | di << "no parts were built\n"; |
126 | return 0; |
127 | } |
128 | // |
129 | DBRep::Set(a[1], aR); |
130 | return 0; |
131 | } |
132 | |
133 | //======================================================================= |
134 | //function : bcaddall |
135 | //purpose : |
136 | //======================================================================= |
137 | Standard_Integer bcaddall(Draw_Interpretor& di, |
e8b9db57 |
138 | Standard_Integer n, |
338434c7 |
139 | const char** a) |
140 | { |
141 | if (n < 2 || n > 5) { |
142 | di << "Add all parts to result. Use: bcaddall r [-m material [-u]]\n"; |
143 | return 1; |
144 | } |
145 | // |
146 | Standard_Integer iMaterial = 0; |
147 | Standard_Boolean bUpdate = Standard_False; |
148 | // |
149 | if (n > 3) { |
150 | if (!strcmp(a[2], "-m")) { |
151 | iMaterial = Draw::Atoi(a[3]); |
152 | } |
153 | // |
154 | if (n == 5) { |
155 | bUpdate = !strcmp(a[4], "-u"); |
156 | } |
157 | } |
158 | // |
159 | BOPAlgo_CellsBuilder& aCBuilder = BOPTest_Objects::CellsBuilder(); |
160 | // |
33ba8565 |
161 | aCBuilder.ClearWarnings(); |
338434c7 |
162 | aCBuilder.AddAllToResult(iMaterial, bUpdate); |
33ba8565 |
163 | BOPTest::ReportAlerts(aCBuilder); |
e8b9db57 |
164 | // |
338434c7 |
165 | const TopoDS_Shape& aR = aCBuilder.Shape(); |
166 | // |
167 | DBRep::Set(a[1], aR); |
168 | return 0; |
169 | } |
170 | |
171 | //======================================================================= |
172 | //function : bcremoveall |
173 | //purpose : |
174 | //======================================================================= |
175 | Standard_Integer bcremoveall(Draw_Interpretor& di, |
176 | Standard_Integer n, |
177 | const char**) |
178 | { |
179 | if (n != 1) { |
180 | di << "Remove all parts from result. Use: bcremoveall\n"; |
181 | return 1; |
182 | } |
183 | // |
184 | BOPAlgo_CellsBuilder& aCBuilder = BOPTest_Objects::CellsBuilder(); |
185 | // |
186 | aCBuilder.RemoveAllFromResult(); |
187 | // |
188 | return 0; |
189 | } |
190 | |
191 | //======================================================================= |
192 | //function : bcadd |
193 | //purpose : |
194 | //======================================================================= |
195 | Standard_Integer bcadd(Draw_Interpretor& di, |
196 | Standard_Integer n, |
197 | const char** a) |
198 | { |
199 | if (n < 4) { |
200 | di << "Add parts to result. Use: bcadd r s1 (0,1) s2 (0,1) ... [-m material [-u]]\n"; |
201 | return 1; |
202 | } |
203 | // |
204 | BOPCol_ListOfShape aLSToTake, aLSToAvoid; |
205 | Standard_Integer i, iMaterial, iTake, n1; |
206 | Standard_Boolean bUpdate; |
207 | // |
208 | iMaterial = 0; |
209 | bUpdate = Standard_False; |
210 | n1 = n; |
211 | // |
212 | if (!strcmp(a[n-3], "-m")) { |
213 | iMaterial = Draw::Atoi(a[n-2]); |
214 | bUpdate = !strcmp(a[n-1], "-u"); |
215 | n1 = n - 3; |
216 | } |
217 | else if (!strcmp(a[n-2], "-m")) { |
218 | iMaterial = Draw::Atoi(a[n-1]); |
219 | n1 = n - 2; |
220 | } |
221 | // |
222 | for (i = 2; i < n1; i += 2) { |
223 | const TopoDS_Shape& aS = DBRep::Get(a[i]); |
224 | if (aS.IsNull()) { |
225 | di << a[i] << " is a null shape\n"; |
226 | continue; |
227 | } |
228 | iTake = Draw::Atoi(a[i+1]); |
229 | // |
230 | if (iTake) { |
231 | aLSToTake.Append(aS); |
232 | } |
233 | else { |
234 | aLSToAvoid.Append(aS); |
235 | } |
236 | } |
237 | // |
238 | if (aLSToTake.IsEmpty()) { |
239 | di << "No shapes from which to add the parts\n"; |
240 | return 1; |
241 | } |
242 | // |
243 | BOPAlgo_CellsBuilder& aCBuilder = BOPTest_Objects::CellsBuilder(); |
338434c7 |
244 | // |
33ba8565 |
245 | aCBuilder.ClearWarnings(); |
246 | aCBuilder.AddToResult(aLSToTake, aLSToAvoid, iMaterial, bUpdate); |
247 | BOPTest::ReportAlerts(aCBuilder); |
e8b9db57 |
248 | // |
338434c7 |
249 | const TopoDS_Shape& aR = aCBuilder.Shape(); |
250 | // |
251 | DBRep::Set(a[1], aR); |
252 | return 0; |
253 | } |
254 | |
255 | //======================================================================= |
256 | //function : bcremove |
257 | //purpose : |
258 | //======================================================================= |
259 | Standard_Integer bcremove(Draw_Interpretor& di, |
260 | Standard_Integer n, |
261 | const char** a) |
262 | { |
263 | if (n < 4 || ((n % 2) != 0)) { |
264 | di << "Remove parts from result. Use: bcremove r s1 (0,1) s2 (0,1) ...\n"; |
265 | return 1; |
266 | } |
267 | // |
268 | BOPCol_ListOfShape aLSToTake, aLSToAvoid; |
269 | Standard_Integer i, iTake; |
270 | // |
271 | for (i = 2; i < n; i += 2) { |
272 | const TopoDS_Shape& aS = DBRep::Get(a[i]); |
273 | if (aS.IsNull()) { |
274 | di << a[i] << " is a null shape\n"; |
275 | return 1; |
276 | } |
277 | iTake = Draw::Atoi(a[i+1]); |
278 | // |
279 | if (iTake) { |
280 | aLSToTake.Append(aS); |
281 | } |
282 | else { |
283 | aLSToAvoid.Append(aS); |
284 | } |
285 | } |
286 | // |
287 | if (aLSToTake.IsEmpty()) { |
288 | di << "No shapes from which to remove the parts\n"; |
289 | return 1; |
290 | } |
291 | // |
292 | BOPAlgo_CellsBuilder& aCBuilder = BOPTest_Objects::CellsBuilder(); |
293 | aCBuilder.RemoveFromResult(aLSToTake, aLSToAvoid); |
294 | // |
295 | const TopoDS_Shape& aR = aCBuilder.Shape(); |
296 | // |
297 | DBRep::Set(a[1], aR); |
298 | return 0; |
299 | } |
300 | |
301 | //======================================================================= |
302 | //function : bcremoveint |
303 | //purpose : |
304 | //======================================================================= |
305 | Standard_Integer bcremoveint(Draw_Interpretor& di, |
306 | Standard_Integer n, |
307 | const char** a) |
308 | { |
309 | if (n != 2) { |
310 | di << "Remove internal boundaries. Use: bcremoveint r\n"; |
311 | return 1; |
312 | } |
313 | // |
314 | BOPAlgo_CellsBuilder& aCBuilder = BOPTest_Objects::CellsBuilder(); |
338434c7 |
315 | // |
33ba8565 |
316 | aCBuilder.ClearWarnings(); |
317 | aCBuilder.RemoveInternalBoundaries(); |
318 | BOPTest::ReportAlerts(aCBuilder); |
e8b9db57 |
319 | // |
338434c7 |
320 | const TopoDS_Shape& aR = aCBuilder.Shape(); |
321 | // |
322 | DBRep::Set(a[1], aR); |
323 | return 0; |
324 | } |
325 | |
326 | //======================================================================= |
327 | //function : bcmakecontainers |
328 | //purpose : |
329 | //======================================================================= |
330 | Standard_Integer bcmakecontainers(Draw_Interpretor& di, |
331 | Standard_Integer n, |
332 | const char** a) |
333 | { |
334 | if (n != 2) { |
335 | di << "Make containers from the parts added to result. Use: bcmakecontainers r\n"; |
336 | return 1; |
337 | } |
338 | // |
339 | BOPAlgo_CellsBuilder& aCBuilder = BOPTest_Objects::CellsBuilder(); |
340 | aCBuilder.MakeContainers(); |
341 | // |
342 | const TopoDS_Shape& aR = aCBuilder.Shape(); |
343 | // |
344 | DBRep::Set(a[1], aR); |
345 | return 0; |
346 | } |