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