b311480e |
1 | // Created on: 1993-07-22 |
2 | // Created by: Remi LEQUETTE |
3 | // Copyright (c) 1993-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
17 | #include <BRepTest.hxx> |
4f7d41ea |
18 | |
19 | #include <BRepTest_Objects.hxx> |
20 | |
7fd59977 |
21 | #include <DBRep.hxx> |
22 | #include <Draw_Interpretor.hxx> |
23 | #include <Draw_Appli.hxx> |
24 | |
25 | #include <BRepFill.hxx> |
26 | #include <BRepBuilderAPI_PipeError.hxx> |
27 | #include <BRepFill_Generator.hxx> |
28 | #include <BRepPrimAPI_MakePrism.hxx> |
29 | #include <BRepPrimAPI_MakeRevol.hxx> |
30 | #include <BRepOffsetAPI_MakePipe.hxx> |
31 | #include <BRepOffsetAPI_MakeEvolved.hxx> |
32 | #include <BRepOffsetAPI_ThruSections.hxx> |
33 | #include <BRepOffsetAPI_MakePipeShell.hxx> |
2277323d |
34 | #include <BRepOffsetAPI_MiddlePath.hxx> |
7fd59977 |
35 | |
36 | #include <BRepLib_MakeWire.hxx> |
37 | #include <TopoDS.hxx> |
38 | #include <TopTools_ListIteratorOfListOfShape.hxx> |
39 | #include <TopExp_Explorer.hxx> |
40 | |
41 | #include <Precision.hxx> |
42 | #include <Law_Interpol.hxx> |
43 | #include <gp_Ax1.hxx> |
44 | #include <gp_Ax2.hxx> |
45 | #include <gp_Pnt2d.hxx> |
46 | #include <TColgp_Array1OfPnt2d.hxx> |
47 | |
80eeb3ce |
48 | static BRepOffsetAPI_MakePipeShell* Sweep = 0; |
50258e77 |
49 | static BRepOffsetAPI_ThruSections* Generator = 0; |
7fd59977 |
50 | |
7fd59977 |
51 | #include <stdio.h> |
52 | #include <Geom_Curve.hxx> |
53 | #include <GeomAdaptor_HCurve.hxx> |
54 | #include <GeomFill_Pipe.hxx> |
55 | #include <Geom_Surface.hxx> |
56 | #include <BRepBuilderAPI_MakeFace.hxx> |
57 | #include <BRep_Tool.hxx> |
58 | #include <gp_Pnt.hxx> |
7fd59977 |
59 | #include <gp_Vec.hxx> |
60 | #include <Geom_Circle.hxx> |
61 | #include <gp_Ax2.hxx> |
d99f0355 |
62 | #include <Message.hxx> |
f9032cf2 |
63 | |
7fd59977 |
64 | //======================================================================= |
65 | // prism |
66 | //======================================================================= |
67 | |
80eeb3ce |
68 | static Standard_Integer prism(Draw_Interpretor&, Standard_Integer n, const char** a) |
7fd59977 |
69 | { |
70 | if (n < 6) return 1; |
71 | |
72 | TopoDS_Shape base = DBRep::Get(a[2]); |
73 | if (base.IsNull()) return 1; |
74 | |
80eeb3ce |
75 | gp_Vec V(Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5])); |
76 | |
7fd59977 |
77 | Standard_Boolean copy = Standard_False; |
80eeb3ce |
78 | Standard_Boolean inf = Standard_False; |
7fd59977 |
79 | Standard_Boolean sinf = Standard_False; |
80 | |
81 | if (n > 6) { |
82 | copy = (*a[6] == 'c') || (*a[6] == 'C'); |
80eeb3ce |
83 | inf = (*a[6] == 'i') || (*a[6] == 'I'); |
7fd59977 |
84 | sinf = (*a[6] == 's') || (*a[6] == 'S'); |
85 | } |
86 | |
87 | TopoDS_Shape res; |
88 | |
80eeb3ce |
89 | BRepPrimAPI_MakePrism* Prism; |
90 | if (inf || sinf) |
91 | { |
92 | Prism = new BRepPrimAPI_MakePrism(base, gp_Dir(V), inf); |
93 | } |
7fd59977 |
94 | else |
80eeb3ce |
95 | { |
96 | Prism = new BRepPrimAPI_MakePrism(base, V, copy); |
97 | } |
7fd59977 |
98 | |
80eeb3ce |
99 | res = Prism->Shape(); |
100 | |
101 | DBRep::Set(a[1], res); |
102 | |
103 | //History |
104 | TopTools_ListOfShape anArgs; |
105 | anArgs.Append(base); |
106 | BRepTest_Objects::SetHistory(anArgs, *Prism); |
107 | |
108 | delete Prism; |
7fd59977 |
109 | |
110 | return 0; |
111 | } |
112 | |
113 | |
114 | //======================================================================= |
115 | // revol |
116 | //======================================================================= |
6f241137 |
117 | static Standard_Integer revol(Draw_Interpretor& di, |
80eeb3ce |
118 | Standard_Integer n, const char** a) |
7fd59977 |
119 | { |
80eeb3ce |
120 | if (n < 10) return 1; |
7fd59977 |
121 | |
122 | TopoDS_Shape base = DBRep::Get(a[2]); |
123 | if (base.IsNull()) return 1; |
124 | |
80eeb3ce |
125 | gp_Pnt P(Draw::Atof(a[3]), Draw::Atof(a[4]), Draw::Atof(a[5])); |
126 | gp_Dir D(Draw::Atof(a[6]), Draw::Atof(a[7]), Draw::Atof(a[8])); |
127 | gp_Ax1 A(P, D); |
7fd59977 |
128 | |
91322f44 |
129 | Standard_Real angle = Draw::Atof(a[9]) * (M_PI / 180.0); |
80eeb3ce |
130 | |
7fd59977 |
131 | Standard_Boolean copy = n > 10; |
132 | |
7e4ff648 |
133 | |
134 | BRepPrimAPI_MakeRevol Revol(base, A, angle, copy); |
135 | |
6f241137 |
136 | if (Revol.IsDone()) |
137 | { |
138 | TopoDS_Shape res = Revol.Shape(); |
7fd59977 |
139 | |
6f241137 |
140 | DBRep::Set(a[1], res); |
7fd59977 |
141 | |
6f241137 |
142 | //History |
143 | TopTools_ListOfShape anArgs; |
144 | anArgs.Append(base); |
145 | BRepTest_Objects::SetHistory(anArgs, Revol); |
146 | } |
147 | else |
148 | { |
149 | di << "Revol not done \n"; |
150 | } |
7e4ff648 |
151 | |
7fd59977 |
152 | return 0; |
153 | } |
154 | |
155 | |
156 | //======================================================================= |
157 | // pipe |
158 | //======================================================================= |
159 | |
471ce736 |
160 | static Standard_Integer pipe(Draw_Interpretor& di, |
80eeb3ce |
161 | Standard_Integer n, const char** a) |
7fd59977 |
162 | { |
471ce736 |
163 | if (n == 1) |
164 | { |
586db386 |
165 | di << "pipe result Wire_spine Profile [Mode [Approx]]\n"; |
166 | di << "Mode = 0 - CorrectedFrenet,\n"; |
167 | di << " = 1 - Frenet,\n"; |
168 | di << " = 2 - DiscreteTrihedron\n"; |
169 | di << "Approx - force C1-approximation if result is C0\n"; |
471ce736 |
170 | return 0; |
171 | } |
80eeb3ce |
172 | |
471ce736 |
173 | if (n > 1 && n < 4) return 1; |
7fd59977 |
174 | |
80eeb3ce |
175 | TopoDS_Shape Spine = DBRep::Get(a[2], TopAbs_WIRE); |
176 | if (Spine.IsNull()) return 1; |
7fd59977 |
177 | |
178 | TopoDS_Shape Profile = DBRep::Get(a[3]); |
80eeb3ce |
179 | if (Profile.IsNull()) return 1; |
471ce736 |
180 | |
181 | GeomFill_Trihedron Mode = GeomFill_IsCorrectedFrenet; |
182 | if (n >= 5) |
183 | { |
184 | Standard_Integer iMode = atoi(a[4]); |
185 | if (iMode == 1) |
186 | Mode = GeomFill_IsFrenet; |
187 | else if (iMode == 2) |
188 | Mode = GeomFill_IsDiscreteTrihedron; |
189 | } |
190 | |
191 | Standard_Boolean ForceApproxC1 = Standard_False; |
192 | if (n >= 6) |
193 | ForceApproxC1 = Standard_True; |
80eeb3ce |
194 | |
cab49d68 |
195 | BRepOffsetAPI_MakePipe PipeBuilder(TopoDS::Wire(Spine), |
80eeb3ce |
196 | Profile, |
197 | Mode, |
198 | ForceApproxC1); |
cab49d68 |
199 | TopoDS_Shape S = PipeBuilder.Shape(); |
7fd59977 |
200 | |
80eeb3ce |
201 | DBRep::Set(a[1], S); |
202 | |
cab49d68 |
203 | // Save history of pipe |
204 | if (BRepTest_Objects::IsHistoryNeeded()) |
205 | { |
206 | TopTools_ListOfShape aList; |
207 | aList.Append(Profile); |
208 | aList.Append(Spine); |
209 | BRepTest_Objects::SetHistory(aList, PipeBuilder); |
210 | } |
80eeb3ce |
211 | |
7fd59977 |
212 | return 0; |
213 | } |
471ce736 |
214 | |
7fd59977 |
215 | //======================================================================= |
216 | |
80eeb3ce |
217 | static Standard_Integer geompipe(Draw_Interpretor&, |
218 | Standard_Integer n, const char** a) |
7fd59977 |
219 | { |
80eeb3ce |
220 | TopoDS_Shape Spine = DBRep::Get(a[2], TopAbs_EDGE); |
221 | if (Spine.IsNull()) return 1; |
222 | if (n < 5) return 1; |
223 | TopoDS_Shape Profile = DBRep::Get(a[3], TopAbs_EDGE); |
224 | if (Profile.IsNull()) return 1; |
225 | Standard_Real aSpFirst, aSpLast, aPrFirst, aPrLast; |
226 | Handle(Geom_Curve) SpineCurve = BRep_Tool::Curve(TopoDS::Edge(Spine), aSpFirst, aSpLast); |
227 | Handle(Geom_Curve) ProfileCurve = BRep_Tool::Curve(TopoDS::Edge(Profile), aPrFirst, aPrLast); |
228 | Handle(GeomAdaptor_HCurve) aAdaptCurve = new GeomAdaptor_HCurve(SpineCurve, aSpFirst, aSpLast); |
7fd59977 |
229 | Standard_Boolean ByACR = Standard_False; |
230 | Standard_Boolean rotate = Standard_False; |
91322f44 |
231 | Standard_Real Radius = Draw::Atof(a[4]); |
7fd59977 |
232 | gp_Pnt ctr; |
233 | gp_Vec norm; |
80eeb3ce |
234 | ProfileCurve->D1(aSpFirst, ctr, norm); |
235 | gp_Vec xAxisStart(ctr, SpineCurve->Value(aSpFirst)); |
236 | gp_Ax2 aAx2Start(ctr, norm, xAxisStart); |
237 | Handle(Geom_Circle) cStart = new Geom_Circle(aAx2Start, Radius); |
238 | Standard_Integer k = 5; |
239 | if (n > k) |
240 | ByACR = (Draw::Atoi(a[k++]) == 1); |
241 | if (n > k) |
242 | rotate = (Draw::Atoi(a[k++]) == 1); |
243 | GeomFill_Pipe aPipe(ProfileCurve, aAdaptCurve, cStart, ByACR, rotate); |
7fd59977 |
244 | aPipe.Perform(Standard_True); |
a8b52677 |
245 | if (!aPipe.IsDone()) |
246 | { |
d99f0355 |
247 | Message::SendFail() << "GeomFill_Pipe cannot make a surface"; |
a8b52677 |
248 | return 1; |
249 | } |
bf327822 |
250 | |
251 | Standard_Real Accuracy = aPipe.ErrorOnSurf(); |
252 | std::cout << "Accuracy of approximation = " << Accuracy << std::endl; |
253 | |
80eeb3ce |
254 | Handle(Geom_Surface) Sur = aPipe.Surface(); |
7fd59977 |
255 | TopoDS_Face F; |
80eeb3ce |
256 | if (!Sur.IsNull()) |
1c72dff6 |
257 | F = BRepBuilderAPI_MakeFace(Sur, Precision::Confusion()); |
80eeb3ce |
258 | DBRep::Set(a[1], F); |
7fd59977 |
259 | return 0; |
260 | } |
261 | |
262 | //======================================================================= |
263 | //function : evolved |
264 | //purpose : |
265 | //======================================================================= |
266 | |
267 | Standard_Integer evolved(Draw_Interpretor& di, Standard_Integer n, const char** a) |
268 | { |
80eeb3ce |
269 | if (n == 1) { |
85843588 |
270 | di << " evolved result -s spine -p profile [-solid] [-v] [-a] [-t toler] [-parallel] : \n"; |
271 | di << " Make evolved profile on spine.\n"; |
272 | di << " -solid means make closed solid.\n"; |
273 | di << " -v means use alternative algorithm (volume mode).\n"; |
274 | di << " -a means referencial CS is automatically computed, otherwise global CS is used. \n"; |
275 | di << " -t sets the tolerance.\n"; |
276 | di << " -parallel turns on parallel execution.\n"; |
7fd59977 |
277 | return 0; |
278 | } |
279 | |
80eeb3ce |
280 | if (n < 4) return 1; |
85843588 |
281 | Standard_Boolean Solid = Standard_False; |
282 | Standard_Boolean isVolume = Standard_False; |
283 | Standard_Boolean hasToComputeAxes = Standard_False; |
284 | Standard_Real aTolerance = 0.0; |
285 | TopoDS_Shape Base; |
286 | TopoDS_Wire Prof; |
287 | Standard_Boolean isParallel = Standard_True; |
288 | |
289 | for (Standard_Integer i = 2; i < n; i++) |
290 | { |
291 | if (a[i][0] != '-') |
292 | { |
293 | di << "Error: wrong option!\n"; |
294 | return 1; |
295 | } |
296 | |
297 | if (!Solid && !strcmp(a[i], "-solid")) |
298 | { |
299 | Solid = Standard_True; |
300 | continue; |
301 | } |
7fd59977 |
302 | |
85843588 |
303 | if (!strcmp(a[i], "-stm")) |
304 | { |
305 | isParallel = Standard_False; |
306 | continue; |
307 | } |
7fd59977 |
308 | |
85843588 |
309 | switch (a[i][1]) |
310 | { |
311 | case 's': |
312 | { |
313 | Base = DBRep::Get(a[++i], TopAbs_WIRE, Standard_False); |
314 | if (Base.IsNull()) |
315 | { |
316 | Base = DBRep::Get(a[i], TopAbs_FACE, Standard_False); |
317 | } |
318 | } |
319 | break; |
80eeb3ce |
320 | |
85843588 |
321 | case 'p': |
322 | { |
323 | Prof = TopoDS::Wire(DBRep::Get(a[++i], TopAbs_WIRE, Standard_False)); |
324 | } |
325 | break; |
7fd59977 |
326 | |
85843588 |
327 | case 'v': |
328 | { |
329 | isVolume = Standard_True; |
330 | } |
331 | break; |
332 | |
333 | case 'a': |
334 | { |
335 | hasToComputeAxes = Standard_True; |
336 | } |
337 | break; |
7fd59977 |
338 | |
85843588 |
339 | case 't': |
340 | { |
341 | aTolerance = Draw::Atof(a[++i]); |
342 | } |
343 | break; |
344 | |
345 | default: |
346 | di << "Error: Unknown option!\n"; |
347 | break; |
348 | } |
7fd59977 |
349 | } |
85843588 |
350 | |
351 | if (Base.IsNull() || Prof.IsNull()) |
352 | { |
353 | di << "spine (face or wire) and profile (wire) are expected\n"; |
354 | return 1; |
7fd59977 |
355 | } |
356 | |
85843588 |
357 | TopoDS_Shape Volevo = BRepOffsetAPI_MakeEvolved(Base, Prof, GeomAbs_Arc, !hasToComputeAxes, |
358 | Solid, Standard_False, |
359 | aTolerance, isVolume, isParallel); |
360 | |
361 | DBRep::Set(a[1],Volevo); |
362 | |
7fd59977 |
363 | return 0; |
364 | } |
365 | |
366 | |
367 | //======================================================================= |
368 | //function : pruled |
369 | //purpose : |
370 | //======================================================================= |
371 | |
80eeb3ce |
372 | static Standard_Integer pruled(Draw_Interpretor&, |
373 | Standard_Integer n, const char** a) |
7fd59977 |
374 | { |
80eeb3ce |
375 | if (n != 4) return 1; |
7fd59977 |
376 | |
377 | Standard_Boolean YaWIRE = Standard_False; |
80eeb3ce |
378 | TopoDS_Shape S1 = DBRep::Get(a[2], TopAbs_EDGE); |
379 | if (S1.IsNull()) { |
380 | S1 = DBRep::Get(a[2], TopAbs_WIRE); |
7fd59977 |
381 | if (S1.IsNull()) return 1; |
382 | YaWIRE = Standard_True; |
383 | } |
384 | |
80eeb3ce |
385 | TopoDS_Shape S2 = DBRep::Get(a[3], TopAbs_EDGE); |
386 | if (S2.IsNull()) { |
387 | S2 = DBRep::Get(a[3], TopAbs_WIRE); |
388 | if (S2.IsNull()) return 1; |
7fd59977 |
389 | if (!YaWIRE) { |
390 | S1 = BRepLib_MakeWire(TopoDS::Edge(S1)); |
391 | YaWIRE = Standard_True; |
392 | } |
393 | } |
80eeb3ce |
394 | else if (YaWIRE) { |
7fd59977 |
395 | S2 = BRepLib_MakeWire(TopoDS::Edge(S2)); |
396 | } |
397 | |
398 | TopoDS_Shape Result; |
80eeb3ce |
399 | if (YaWIRE) { |
400 | Result = BRepFill::Shell(TopoDS::Wire(S1), TopoDS::Wire(S2)); |
7fd59977 |
401 | } |
402 | else { |
80eeb3ce |
403 | Result = BRepFill::Face(TopoDS::Edge(S1), TopoDS::Edge(S2)); |
7fd59977 |
404 | } |
405 | |
80eeb3ce |
406 | DBRep::Set(a[1], Result); |
7fd59977 |
407 | return 0; |
408 | } |
409 | |
410 | |
411 | //======================================================================= |
412 | //function : gener |
413 | //purpose : Create a surface between generating wires |
414 | //======================================================================= |
415 | |
416 | Standard_Integer gener(Draw_Interpretor&, Standard_Integer n, const char** a) |
417 | { |
80eeb3ce |
418 | if (n < 4) return 1; |
7fd59977 |
419 | |
80eeb3ce |
420 | TopoDS_Shape Shape; |
7fd59977 |
421 | |
50258e77 |
422 | BRepFill_Generator aGenerator; |
80eeb3ce |
423 | |
424 | for (Standard_Integer i = 2; i <= n - 1; i++) { |
425 | Shape = DBRep::Get(a[i], TopAbs_WIRE); |
426 | if (Shape.IsNull()) |
7fd59977 |
427 | return 1; |
428 | |
50258e77 |
429 | aGenerator.AddWire(TopoDS::Wire(Shape)); |
7fd59977 |
430 | } |
431 | |
50258e77 |
432 | aGenerator.Perform(); |
7fd59977 |
433 | |
50258e77 |
434 | TopoDS_Shell Shell = aGenerator.Shell(); |
80eeb3ce |
435 | |
7fd59977 |
436 | DBRep::Set(a[1], Shell); |
437 | |
438 | |
439 | return 0; |
440 | } |
441 | |
442 | |
443 | //======================================================================= |
444 | //function : thrusections |
445 | //purpose : |
446 | //======================================================================= |
447 | |
448 | Standard_Integer thrusections(Draw_Interpretor&, Standard_Integer n, const char** a) |
449 | { |
80eeb3ce |
450 | if (n < 6) return 1; |
7fd59977 |
451 | |
452 | Standard_Boolean check = Standard_True; |
453 | Standard_Boolean samenumber = Standard_True; |
454 | Standard_Integer index = 2; |
80eeb3ce |
455 | // Lecture option |
456 | if (!strcmp(a[1], "-N")) { |
457 | if (n < 7) return 1; |
7fd59977 |
458 | check = Standard_False; |
459 | index++; |
460 | } |
461 | |
80eeb3ce |
462 | TopoDS_Shape Shape; |
7fd59977 |
463 | |
80eeb3ce |
464 | Standard_Boolean issolid = (Draw::Atoi(a[index]) == 1); |
465 | Standard_Boolean isruled = (Draw::Atoi(a[index + 1]) == 1); |
7fd59977 |
466 | |
50258e77 |
467 | if (Generator != 0) |
468 | { |
80eeb3ce |
469 | delete Generator; |
50258e77 |
470 | Generator = 0; |
471 | } |
80eeb3ce |
472 | Generator = new BRepOffsetAPI_ThruSections(issolid, isruled); |
473 | |
7fd59977 |
474 | Standard_Integer NbEdges = 0; |
475 | Standard_Boolean IsFirstWire = Standard_False; |
80eeb3ce |
476 | for (Standard_Integer i = index + 2; i <= n - 1; i++) { |
7fd59977 |
477 | Standard_Boolean IsWire = Standard_True; |
478 | Shape = DBRep::Get(a[i], TopAbs_WIRE); |
479 | if (!Shape.IsNull()) |
80eeb3ce |
480 | { |
481 | Generator->AddWire(TopoDS::Wire(Shape)); |
482 | if (!IsFirstWire) |
483 | IsFirstWire = Standard_True; |
484 | else |
485 | IsFirstWire = Standard_False; |
486 | } |
7fd59977 |
487 | else |
80eeb3ce |
488 | { |
489 | Shape = DBRep::Get(a[i], TopAbs_VERTEX); |
490 | IsWire = Standard_False; |
491 | if (!Shape.IsNull()) |
492 | Generator->AddVertex(TopoDS::Vertex(Shape)); |
493 | else |
494 | return 1; |
495 | } |
7fd59977 |
496 | |
497 | Standard_Integer cpt = 0; |
498 | TopExp_Explorer PE; |
499 | for (PE.Init(Shape, TopAbs_EDGE); PE.More(); PE.Next()) { |
500 | cpt++; |
501 | } |
80eeb3ce |
502 | if (IsFirstWire) |
7fd59977 |
503 | NbEdges = cpt; |
504 | else |
505 | if (IsWire && cpt != NbEdges) |
80eeb3ce |
506 | samenumber = Standard_False; |
507 | |
7fd59977 |
508 | } |
509 | |
510 | check = (check || !samenumber); |
50258e77 |
511 | Generator->CheckCompatibility(check); |
7fd59977 |
512 | |
50258e77 |
513 | Generator->Build(); |
7fd59977 |
514 | |
50258e77 |
515 | if (Generator->IsDone()) { |
516 | TopoDS_Shape Shell = Generator->Shape(); |
80eeb3ce |
517 | DBRep::Set(a[index - 1], Shell); |
4f7d41ea |
518 | // Save history of the lofting |
948fe6ca |
519 | if (BRepTest_Objects::IsHistoryNeeded()) |
520 | BRepTest_Objects::SetHistory(Generator->Wires(), *Generator); |
a4bb1420 |
521 | } |
522 | else { |
04232180 |
523 | std::cout << "Algorithm is not done" << std::endl; |
a4bb1420 |
524 | } |
50258e77 |
525 | |
50258e77 |
526 | return 0; |
527 | } |
528 | |
7fd59977 |
529 | //======================================================================= |
530 | // mksweep |
531 | //======================================================================= |
80eeb3ce |
532 | static Standard_Integer mksweep(Draw_Interpretor&, |
533 | Standard_Integer n, const char** a) |
7fd59977 |
534 | { |
80eeb3ce |
535 | if (n != 2) return 1; |
536 | TopoDS_Shape Spine = DBRep::Get(a[1], TopAbs_WIRE); |
537 | if (Spine.IsNull()) return 1; |
538 | if (Sweep != 0) { |
539 | delete Sweep; |
7fd59977 |
540 | Sweep = 0; |
541 | } |
542 | Sweep = new BRepOffsetAPI_MakePipeShell(TopoDS::Wire(Spine)); |
543 | return 0; |
544 | } |
545 | |
546 | //======================================================================= |
547 | // setsweep |
548 | //======================================================================= |
549 | static Standard_Integer setsweep(Draw_Interpretor& di, |
80eeb3ce |
550 | Standard_Integer n, const char** a) |
7fd59977 |
551 | { |
80eeb3ce |
552 | if (n == 1) { |
586db386 |
553 | di << "setsweep options [arg1 [arg2 [...]]] : options are :\n"; |
554 | di << " -FR : Tangent and Normal are given by Frenet trihedron\n"; |
555 | di << " -CF : Tangente is given by Frenet,\n"; |
556 | di << " the Normal is computed to minimize the torsion \n"; |
557 | di << " -DT : discrete trihedron\n"; |
80eeb3ce |
558 | di << " -DX Surf : Tangent and Normal are given by Darboux trihedron,\n"; |
586db386 |
559 | di << " Surf have to be a shell or a face\n"; |
560 | di << " -CN dx dy dz : BiNormal is given by dx dy dz\n"; |
561 | di << " -FX Tx Ty TZ [Nx Ny Nz] : Tangent and Normal are fixed\n"; |
562 | di << " -G guide 0|1(Plan|ACR) 0|1|2(no contact|contact|contact on border) : with guide\n"; |
7fd59977 |
563 | return 0; |
564 | } |
565 | |
80eeb3ce |
566 | if (Sweep == 0) { |
80eeb3ce |
567 | di << "You have forgotten the <<mksweep>> command !\n"; |
568 | return 1; |
569 | } |
570 | if (!strcmp(a[1], "-FR")) { |
7fd59977 |
571 | Sweep->SetMode(Standard_True); |
572 | } |
80eeb3ce |
573 | else if (!strcmp(a[1], "-CF")) { |
7fd59977 |
574 | Sweep->SetMode(Standard_False); |
575 | } |
80eeb3ce |
576 | else if (!strcmp(a[1], "-DT")) { |
a31abc03 |
577 | Sweep->SetDiscreteMode(); |
578 | } |
80eeb3ce |
579 | else if (!strcmp(a[1], "-DX")) { |
580 | if (n != 3) { |
586db386 |
581 | di << "bad arguments !\n"; |
7fd59977 |
582 | return 1; |
583 | } |
584 | TopoDS_Shape Surf; |
80eeb3ce |
585 | Surf = DBRep::Get(a[2], TopAbs_SHAPE); |
7fd59977 |
586 | if (Surf.IsNull()) { |
80eeb3ce |
587 | di << a[2] << "is not a shape !\n"; |
7fd59977 |
588 | return 1; |
589 | } |
590 | Sweep->SetMode(Surf); |
591 | } |
80eeb3ce |
592 | else if (!strcmp(a[1], "-CN")) { |
593 | if (n != 5) { |
586db386 |
594 | di << "bad arguments !\n"; |
7fd59977 |
595 | return 1; |
596 | } |
91322f44 |
597 | gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4])); |
8c2d3314 |
598 | Sweep->SetMode(D); |
7fd59977 |
599 | } |
80eeb3ce |
600 | else if (!strcmp(a[1], "-FX")) { |
601 | if ((n != 5) && (n != 8)) { |
586db386 |
602 | di << "bad arguments !\n"; |
7fd59977 |
603 | return 1; |
604 | } |
91322f44 |
605 | gp_Dir D(Draw::Atof(a[2]), Draw::Atof(a[3]), Draw::Atof(a[4])); |
80eeb3ce |
606 | if (n == 8) { |
91322f44 |
607 | gp_Dir DN(Draw::Atof(a[5]), Draw::Atof(a[6]), Draw::Atof(a[7])); |
7fd59977 |
608 | gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D, DN); |
609 | Sweep->SetMode(Axe); |
610 | } |
611 | else { |
612 | gp_Ax2 Axe(gp_Pnt(0., 0., 0.), D); |
613 | Sweep->SetMode(Axe); |
614 | } |
615 | } |
80eeb3ce |
616 | else if (!strcmp(a[1], "-G")) // contour guide |
617 | { |
618 | if (n != 5) |
619 | { |
80eeb3ce |
620 | di << "bad arguments !\n"; |
621 | return 1; |
622 | } |
623 | else |
7fd59977 |
624 | { |
80eeb3ce |
625 | TopoDS_Shape Guide = DBRep::Get(a[2], TopAbs_WIRE); |
626 | Standard_Boolean CurvilinearEquivalence = Draw::Atoi(a[3]) != 0; |
627 | Standard_Integer KeepContact = Draw::Atoi(a[4]); |
628 | Sweep->SetMode(TopoDS::Wire(Guide), |
629 | CurvilinearEquivalence, |
630 | (BRepFill_TypeOfContact)KeepContact); |
7fd59977 |
631 | } |
80eeb3ce |
632 | } |
633 | |
7fd59977 |
634 | else { |
80eeb3ce |
635 | di << "The option " << a[1] << " is unknown !\n"; |
7fd59977 |
636 | return 1; |
637 | } |
638 | return 0; |
639 | } |
640 | |
641 | |
642 | //======================================================================= |
643 | // addsweep |
644 | //======================================================================= |
645 | static Standard_Integer addsweep(Draw_Interpretor& di, |
80eeb3ce |
646 | Standard_Integer n, const char** a) |
7fd59977 |
647 | { |
80eeb3ce |
648 | if (n == 1) { |
586db386 |
649 | di << "addsweep wire/vertex [Vertex] [-T] [-R] [u0 v0 u1 v1 [...[uN vN]]] : options are :\n"; |
650 | di << " -T : the wire/vertex have to be translated to assume contact\n"; |
651 | di << " with the spine\n"; |
652 | di << " -R : the wire have to be rotated to assume orthogonality\n"; |
653 | di << " with the spine's tangent\n"; |
7fd59977 |
654 | return 0; |
655 | } |
656 | |
80eeb3ce |
657 | if (Sweep == 0) { |
586db386 |
658 | di << "You have forgotten the <<mksweep>> command !\n"; |
7fd59977 |
659 | return 1; |
660 | } |
661 | |
662 | TopoDS_Shape Section; |
663 | TopoDS_Vertex Vertex; |
664 | Handle(Law_Interpol) thelaw; |
665 | |
666 | Section = DBRep::Get(a[1], TopAbs_SHAPE); |
8878d0ec |
667 | if (Section.IsNull() || |
80eeb3ce |
668 | (Section.ShapeType() != TopAbs_WIRE && |
669 | Section.ShapeType() != TopAbs_VERTEX)) |
670 | { |
80eeb3ce |
671 | di << a[1] << " is not a wire and is not a vertex!\n"; |
672 | return 1; |
673 | } |
7fd59977 |
674 | |
80eeb3ce |
675 | Standard_Boolean HasVertex = Standard_False, |
676 | isT = Standard_False, |
677 | isR = Standard_False; |
7fd59977 |
678 | |
80eeb3ce |
679 | if (n > 2) { |
7fd59977 |
680 | Standard_Integer cur = 2; |
0d969553 |
681 | // Reading of Vertex |
80eeb3ce |
682 | TopoDS_Shape InputVertex(DBRep::Get(a[cur], TopAbs_VERTEX)); |
7fd59977 |
683 | Vertex = TopoDS::Vertex(InputVertex); |
7fd59977 |
684 | if (!Vertex.IsNull()) { |
685 | cur++; |
686 | HasVertex = Standard_True; |
687 | } |
80eeb3ce |
688 | |
0d969553 |
689 | // Reading of the translation option |
80eeb3ce |
690 | if ((n > cur) && !strcmp(a[cur], "-T")) { |
7fd59977 |
691 | cur++; |
692 | isT = Standard_True; |
693 | } |
694 | |
0d969553 |
695 | // Reading of the rotation option |
80eeb3ce |
696 | if ((n > cur) && !strcmp(a[cur], "-R")) { |
7fd59977 |
697 | cur++; |
698 | isR = Standard_True; |
699 | } |
700 | |
0d969553 |
701 | // law ? |
80eeb3ce |
702 | if (n > cur) { |
703 | Standard_Integer nbreal = n - cur; |
704 | if ((nbreal < 4) || (nbreal % 2 != 0)) { |
04232180 |
705 | //std::cout << "bad arguments ! :" <<a[cur] << std::endl; |
80eeb3ce |
706 | di << "bad arguments ! :" << a[cur] << "\n"; |
707 | } |
708 | else { //law of interpolation |
709 | Standard_Integer ii, L = nbreal / 2; |
710 | TColgp_Array1OfPnt2d ParAndRad(1, L); |
711 | for (ii = 1; ii <= L; ii++, cur += 2) { |
f9032cf2 |
712 | ParAndRad(ii).SetX(Draw::Atof(a[cur])); |
80eeb3ce |
713 | ParAndRad(ii).SetY(Draw::Atof(a[cur + 1])); |
f9032cf2 |
714 | } |
80eeb3ce |
715 | thelaw = new (Law_Interpol)(); |
716 | thelaw->Set(ParAndRad, |
717 | Abs(ParAndRad(1).Y() - ParAndRad(L).Y()) < Precision::Confusion()); |
7fd59977 |
718 | } |
719 | } |
720 | } |
721 | |
722 | if (thelaw.IsNull()) { |
723 | if (HasVertex) Sweep->Add(Section, Vertex, isT, isR); |
724 | else Sweep->Add(Section, isT, isR); |
725 | } |
726 | else { |
727 | if (HasVertex) Sweep->SetLaw(Section, thelaw, Vertex, isT, isR); |
728 | else Sweep->SetLaw(Section, thelaw, isT, isR); |
729 | } |
730 | |
731 | return 0; |
732 | } |
733 | |
734 | //======================================================================= |
735 | // deletesweep |
736 | //======================================================================= |
737 | static Standard_Integer deletesweep(Draw_Interpretor& di, |
80eeb3ce |
738 | Standard_Integer n, const char** a) |
7fd59977 |
739 | { |
80eeb3ce |
740 | if (n != 2) { |
7fd59977 |
741 | return 1; |
742 | } |
743 | TopoDS_Wire Section; |
80eeb3ce |
744 | TopoDS_Shape InputShape(DBRep::Get(a[1], TopAbs_SHAPE)); |
7fd59977 |
745 | Section = TopoDS::Wire(InputShape); |
7fd59977 |
746 | if (Section.IsNull()) { |
80eeb3ce |
747 | di << a[1] << "is not a wire !\n"; |
7fd59977 |
748 | return 1; |
80eeb3ce |
749 | } |
7fd59977 |
750 | |
751 | Sweep->Delete(Section); |
7fd59977 |
752 | return 0; |
753 | } |
754 | |
755 | //======================================================================= |
756 | // buildsweep |
757 | //======================================================================= |
758 | static Standard_Integer buildsweep(Draw_Interpretor& di, |
80eeb3ce |
759 | Standard_Integer n, const char** a) |
7fd59977 |
760 | { |
80eeb3ce |
761 | if (n == 1) { |
586db386 |
762 | di << "build sweep result [-M/-C/-R] [-S] [tol] : options are\n"; |
80eeb3ce |
763 | di << " -M : Discontinuities are treated by Modfication of\n"; |
586db386 |
764 | di << " the sweeping mode : it is the default\n"; |
765 | di << " -C : Discontinuities are treated like Right Corner\n"; |
766 | di << " Treatement is Extent && Intersect\n"; |
767 | di << " -R : Discontinuities are treated like Round Corner\n"; |
768 | di << " Treatement is Intersect and Fill\n"; |
769 | di << " -S : To build a Solid\n"; |
7fd59977 |
770 | return 0; |
771 | } |
772 | |
773 | Standard_Boolean mksolid = Standard_False; |
80eeb3ce |
774 | if (Sweep == 0) { |
586db386 |
775 | di << "You have forgotten the <<mksweep>> command !\n"; |
7fd59977 |
776 | return 1; |
777 | } |
778 | |
779 | if (!Sweep->IsReady()) { |
586db386 |
780 | di << "You have forgotten the <<addsweep>> command !\n"; |
7fd59977 |
781 | return 1; |
782 | } |
783 | |
784 | TopoDS_Shape result; |
80eeb3ce |
785 | Standard_Integer cur = 2; |
786 | if (n > cur) { |
7fd59977 |
787 | BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed; |
788 | |
0d969553 |
789 | // Reading Transition |
80eeb3ce |
790 | if (!strcmp(a[cur], "-C")) { |
7fd59977 |
791 | Transition = BRepBuilderAPI_RightCorner; |
792 | cur++; |
793 | } |
80eeb3ce |
794 | else if (!strcmp(a[cur], "-R")) { |
7fd59977 |
795 | Transition = BRepBuilderAPI_RoundCorner; |
796 | cur++; |
797 | } |
798 | Sweep->SetTransitionMode(Transition); |
799 | } |
0d969553 |
800 | // Reading solid ? |
80eeb3ce |
801 | if ((n > cur) && (!strcmp(a[cur], "-S"))) mksolid = Standard_True; |
7fd59977 |
802 | |
803 | // Calcul le resultat |
804 | Sweep->Build(); |
805 | if (!Sweep->IsDone()) { |
586db386 |
806 | di << "Buildsweep : Not Done\n"; |
80eeb3ce |
807 | BRepBuilderAPI_PipeError Stat = Sweep->GetStatus(); |
7fd59977 |
808 | if (Stat == BRepBuilderAPI_PlaneNotIntersectGuide) { |
586db386 |
809 | di << "Buildsweep : One Plane not intersect the guide\n"; |
7fd59977 |
810 | } |
811 | if (Stat == BRepBuilderAPI_ImpossibleContact) { |
586db386 |
812 | di << "BuildSweep : One section can not be in contact with the guide\n"; |
7fd59977 |
813 | } |
7fd59977 |
814 | } |
815 | else { |
816 | if (mksolid) { |
817 | Standard_Boolean B; |
818 | B = Sweep->MakeSolid(); |
586db386 |
819 | if (!B) di << " BuildSweep : It is impossible to make a solid !\n"; |
7fd59977 |
820 | } |
821 | result = Sweep->Shape(); |
80eeb3ce |
822 | DBRep::Set(a[1], result); |
4f7d41ea |
823 | // Save history of sweep |
948fe6ca |
824 | if (BRepTest_Objects::IsHistoryNeeded()) |
825 | { |
a922aab5 |
826 | TopTools_ListOfShape aList; |
827 | Sweep->Profiles(aList); |
828 | TopoDS_Shape aSpine = Sweep->Spine(); |
829 | aList.Append(aSpine); |
830 | BRepTest_Objects::SetHistory(aList, *Sweep); |
948fe6ca |
831 | } |
7fd59977 |
832 | } |
833 | |
834 | return 0; |
835 | } |
836 | |
107f794f |
837 | //======================================================================= |
838 | //function : errorsweep |
839 | //purpose : returns the summary error on resulting surfaces |
840 | // reached by Sweep |
841 | //======================================================================= |
842 | static Standard_Integer errorsweep(Draw_Interpretor& di, |
80eeb3ce |
843 | Standard_Integer, const char**) |
107f794f |
844 | { |
845 | if (!Sweep->IsDone()) |
846 | { |
847 | di << "Sweep is not done\n"; |
848 | return 1; |
849 | } |
850 | Standard_Real ErrorOnSurfaces = Sweep->ErrorOnSurface(); |
851 | di << "Tolerance on surfaces = " << ErrorOnSurfaces << "\n"; |
852 | return 0; |
853 | } |
854 | |
7fd59977 |
855 | //======================================================================= |
856 | // simulsweep |
857 | //======================================================================= |
858 | static Standard_Integer simulsweep(Draw_Interpretor& di, |
80eeb3ce |
859 | Standard_Integer n, const char** a) |
7fd59977 |
860 | { |
80eeb3ce |
861 | if ((n != 3) && (n != 4)) return 1; |
862 | |
863 | if (Sweep == 0) { |
586db386 |
864 | di << "You have forgotten the <<mksweep>> command !\n"; |
7fd59977 |
865 | return 1; |
866 | } |
80eeb3ce |
867 | |
7fd59977 |
868 | if (!Sweep->IsReady()) { |
586db386 |
869 | di << "You have forgotten the <<addsweep>> command !\n"; |
7fd59977 |
870 | return 1; |
871 | } |
80eeb3ce |
872 | |
7fd59977 |
873 | char name[100]; |
874 | TopTools_ListOfShape List; |
875 | TopTools_ListIteratorOfListOfShape it; |
876 | Standard_Integer N, ii; |
91322f44 |
877 | N = Draw::Atoi(a[2]); |
7fd59977 |
878 | |
80eeb3ce |
879 | if (n > 3) { |
7fd59977 |
880 | BRepBuilderAPI_TransitionMode Transition = BRepBuilderAPI_Transformed; |
881 | // Lecture Transition |
80eeb3ce |
882 | if (!strcmp(a[3], "-C")) { |
7fd59977 |
883 | Transition = BRepBuilderAPI_RightCorner; |
884 | } |
80eeb3ce |
885 | else if (!strcmp(a[3], "-R")) { |
7fd59977 |
886 | Transition = BRepBuilderAPI_RoundCorner; |
887 | } |
888 | Sweep->SetTransitionMode(Transition); |
889 | } |
890 | |
0d969553 |
891 | // Calculate the result |
7fd59977 |
892 | Sweep->Simulate(N, List); |
80eeb3ce |
893 | for (ii = 1, it.Initialize(List); it.More(); it.Next(), ii++) { |
894 | Sprintf(name, "%s_%d", a[1], ii); |
7fd59977 |
895 | DBRep::Set(name, it.Value()); |
896 | } |
897 | |
898 | return 0; |
899 | } |
900 | |
2277323d |
901 | //======================================================================= |
902 | // middlepath |
903 | //======================================================================= |
35e08fe8 |
904 | static Standard_Integer middlepath(Draw_Interpretor& /*di*/, |
80eeb3ce |
905 | Standard_Integer n, const char** a) |
2277323d |
906 | { |
907 | if (n < 5) return 1; |
908 | |
909 | TopoDS_Shape aShape = DBRep::Get(a[2]); |
910 | if (aShape.IsNull()) return 1; |
911 | |
912 | TopoDS_Shape StartShape = DBRep::Get(a[3]); |
913 | if (StartShape.IsNull()) return 1; |
80eeb3ce |
914 | |
915 | TopoDS_Shape EndShape = DBRep::Get(a[4]); |
2277323d |
916 | if (EndShape.IsNull()) return 1; |
917 | |
918 | BRepOffsetAPI_MiddlePath Builder(aShape, StartShape, EndShape); |
919 | Builder.Build(); |
920 | |
921 | TopoDS_Shape Result = Builder.Shape(); |
922 | DBRep::Set(a[1], Result); |
923 | |
924 | return 0; |
925 | } |
926 | |
7fd59977 |
927 | //======================================================================= |
928 | //function : SweepCommands |
929 | //purpose : |
930 | //======================================================================= |
931 | |
932 | void BRepTest::SweepCommands(Draw_Interpretor& theCommands) |
933 | { |
934 | static Standard_Boolean done = Standard_False; |
935 | if (done) return; |
936 | done = Standard_True; |
937 | |
938 | DBRep::BasicCommands(theCommands); |
939 | |
940 | const char* g = "Sweep commands"; |
80eeb3ce |
941 | |
7fd59977 |
942 | theCommands.Add("prism", |
80eeb3ce |
943 | "prism result base dx dy dz [Copy | Inf | Seminf]", |
944 | __FILE__, prism, g); |
945 | |
7fd59977 |
946 | theCommands.Add("revol", |
80eeb3ce |
947 | "revol result base px py pz dx dy dz angle [Copy]", |
948 | __FILE__, revol, g); |
949 | |
7fd59977 |
950 | theCommands.Add("pipe", |
80eeb3ce |
951 | "pipe result Wire_spine Profile [Mode [Approx]], no args to get help", |
952 | __FILE__, pipe, g); |
953 | |
7fd59977 |
954 | theCommands.Add("evolved", |
80eeb3ce |
955 | "evolved , no args to get help", |
956 | __FILE__, evolved, g); |
7fd59977 |
957 | |
7fd59977 |
958 | theCommands.Add("pruled", |
80eeb3ce |
959 | "pruled result Edge1/Wire1 Edge2/Wire2", |
960 | __FILE__, pruled, g); |
7fd59977 |
961 | |
962 | theCommands.Add("gener", "gener result wire1 wire2 [..wire..]", |
80eeb3ce |
963 | __FILE__, gener, g); |
7fd59977 |
964 | |
965 | theCommands.Add("thrusections", "thrusections [-N] result issolid isruled shape1 shape2 [..shape..], the option -N means no check on wires, shapes must be wires or vertices (only first or last)", |
80eeb3ce |
966 | __FILE__, thrusections, g); |
967 | |
7fd59977 |
968 | theCommands.Add("mksweep", "mksweep wire", |
80eeb3ce |
969 | __FILE__, mksweep, g); |
7fd59977 |
970 | |
971 | theCommands.Add("setsweep", "setsweep no args to get help", |
80eeb3ce |
972 | __FILE__, setsweep, g); |
7fd59977 |
973 | |
80eeb3ce |
974 | theCommands.Add("addsweep", |
975 | "addsweep wire [vertex] [-M ] [-C] [auxiilaryshape]:no args to get help", |
976 | __FILE__, addsweep, g); |
7fd59977 |
977 | |
80eeb3ce |
978 | theCommands.Add("deletesweep", |
979 | "deletesweep wire, To delete a section", |
980 | __FILE__, deletesweep, g); |
7fd59977 |
981 | |
80eeb3ce |
982 | theCommands.Add("buildsweep", "builsweep [r] [option] [Tol] , no args to get help", |
983 | __FILE__, buildsweep, g); |
984 | |
985 | theCommands.Add("errorsweep", "errorsweep: returns the summary error on resulting surfaces reached by Sweep", |
986 | __FILE__, errorsweep, g); |
107f794f |
987 | |
7fd59977 |
988 | theCommands.Add("simulsweep", "simulsweep r [n] [option]" |
80eeb3ce |
989 | __FILE__, simulsweep, g); |
7fd59977 |
990 | theCommands.Add("geompipe", "geompipe r spineedge profileedge radius [byACR [byrotate]]" |
80eeb3ce |
991 | __FILE__, geompipe, g); |
992 | |
2277323d |
993 | theCommands.Add("middlepath", "middlepath res shape startshape endshape", |
80eeb3ce |
994 | __FILE__, middlepath, g); |
7fd59977 |
995 | } |
996 | |