Commit | Line | Data |
---|---|---|
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 | // |
973c2be1 | 8 | // This library is free software; you can redistribute it and / or modify it |
9 | // under the terms of the GNU Lesser General Public version 2.1 as published | |
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 <GeometryTest.hxx> | |
19 | #include <gp_Pnt2d.hxx> | |
20 | #include <gp_Pln.hxx> | |
21 | #include <gp_Ax2.hxx> | |
22 | #include <gp_Vec.hxx> | |
23 | #include <gp_Vec2d.hxx> | |
24 | #include <TColgp_HArray1OfPnt2d.hxx> | |
25 | #include <TColgp_Array1OfPnt2d.hxx> | |
26 | #include <BRepBuilderAPI.hxx> | |
27 | #include <BRepBuilderAPI_MakeVertex.hxx> | |
28 | #include <BRepBuilderAPI_MakeEdge.hxx> | |
29 | #include <BRepBuilderAPI_MakeEdge2d.hxx> | |
30 | #include <BRepBuilderAPI_MakeFace.hxx> | |
31 | #include <BRepBuilderAPI_MakeWire.hxx> | |
32 | #include <BRepBuilderAPI_MakePolygon.hxx> | |
33 | #include <BRepOffsetAPI_MakeOffset.hxx> | |
34 | #include <BRepLib.hxx> | |
35 | #include <BRepAlgo.hxx> | |
36 | #include <BRepAdaptor_Curve.hxx> | |
37 | #include <BRep_Builder.hxx> | |
38 | #include <BRep_Tool.hxx> | |
39 | #include <BRepTools.hxx> | |
40 | #include <Geom_Curve.hxx> | |
41 | #include <Geom_TrimmedCurve.hxx> | |
42 | #include <Geom2d_BSplineCurve.hxx> | |
43 | #include <Geom_Surface.hxx> | |
44 | #include <Geom_RectangularTrimmedSurface.hxx> | |
45 | #include <Geom_Plane.hxx> | |
46 | #include <Geom2d_Line.hxx> | |
47 | #include <Geom2d_Circle.hxx> | |
48 | #include <Geom2dAPI_Interpolate.hxx> | |
49 | #include <Geom2d_TrimmedCurve.hxx> | |
50 | #include <TopoDS.hxx> | |
51 | #include <TopoDS_Shape.hxx> | |
52 | #include <TopoDS_Wire.hxx> | |
53 | ||
54 | #include <DBRep.hxx> | |
55 | #include <DBRep_DrawableShape.hxx> | |
56 | #include <Draw_Interpretor.hxx> | |
57 | #include <Draw_Appli.hxx> | |
58 | #include <DrawTrSurf.hxx> | |
59 | #include <DrawTrSurf_BSplineCurve2d.hxx> | |
60 | ||
61 | #include <gp.hxx> | |
62 | #include <Precision.hxx> | |
63 | #include <GeomAPI.hxx> | |
64 | #include <TopAbs_Orientation.hxx> | |
65 | #include <TopExp_Explorer.hxx> | |
66 | #include <TopOpeBRep_EdgesIntersector.hxx> | |
67 | #include <TopOpeBRep_Point2d.hxx> | |
68 | #include <TopOpeBRepDS_Transition.hxx> | |
69 | ||
7fd59977 | 70 | #include <stdio.h> |
71 | #ifdef WNT | |
72 | Standard_IMPORT Draw_Viewer dout; | |
73 | #endif | |
74 | ||
75 | //======================================================================= | |
76 | // vertex | |
77 | //======================================================================= | |
78 | ||
79 | static Standard_Integer vertex(Draw_Interpretor& , Standard_Integer n, const char** a) | |
80 | { | |
81 | if (n < 4) return 1; | |
82 | if (n >= 5) { | |
83 | DBRep::Set(a[1], | |
73cd8a8a | 84 | BRepBuilderAPI_MakeVertex(gp_Pnt(Draw::Atof(a[2]),Draw::Atof(a[3]),Draw::Atof(a[4])))); |
85 | } | |
7fd59977 | 86 | else { |
87 | TopoDS_Shape S = DBRep::Get(a[3]); | |
88 | if (S.IsNull()) return 0; | |
89 | if (S.ShapeType() != TopAbs_EDGE) return 0; | |
90 | BRepAdaptor_Curve C(TopoDS::Edge(S)); | |
91 | gp_Pnt P; | |
91322f44 | 92 | C.D0(Draw::Atof(a[2]),P); |
7fd59977 | 93 | DBRep::Set(a[1], BRepBuilderAPI_MakeVertex(P)); |
94 | } | |
95 | return 0; | |
96 | } | |
97 | ||
98 | //======================================================================= | |
99 | // range | |
100 | //======================================================================= | |
101 | ||
102 | static Standard_Integer range(Draw_Interpretor& , Standard_Integer n, const char** a) | |
103 | { | |
104 | if (n < 4) return 1; | |
105 | TopoDS_Shape aLocalShape(DBRep::Get(a[1],TopAbs_EDGE)); | |
106 | TopoDS_Edge E = TopoDS::Edge(aLocalShape); | |
107 | // TopoDS_Edge E = TopoDS::Edge(DBRep::Get(a[1],TopAbs_EDGE)); | |
108 | if (E.IsNull()) return 1; | |
91322f44 | 109 | Standard_Real f = Draw::Atof(a[n-2]); |
110 | Standard_Real l = Draw::Atof(a[n-1]); | |
7fd59977 | 111 | BRep_Builder B; |
112 | if (n == 4) | |
113 | B.Range(E,f,l); | |
114 | else { | |
115 | aLocalShape = DBRep::Get(a[2],TopAbs_FACE); | |
116 | TopoDS_Face F = TopoDS::Face(aLocalShape); | |
117 | // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[2],TopAbs_FACE)); | |
118 | if (F.IsNull()) return 1; | |
119 | B.Range(E,F,f,l); | |
120 | } | |
121 | return 0; | |
122 | } | |
123 | ||
124 | //======================================================================= | |
125 | // trim | |
126 | //======================================================================= | |
127 | ||
128 | static Standard_Integer trim(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
129 | { | |
130 | if (n < 3) return 1; | |
131 | TopoDS_Shape e = DBRep::Get(a[1]); | |
132 | if (e.IsNull()) return 1; | |
133 | if (e.ShapeType() != TopAbs_EDGE) return 1; | |
134 | TopoDS_Shape v1 = DBRep::Get(a[2]); | |
135 | if (v1.IsNull()) return 1; | |
136 | if (v1.ShapeType() != TopAbs_VERTEX) return 1; | |
137 | TopoDS_Shape v2; | |
138 | if (n > 3) { | |
139 | v2 = DBRep::Get(a[3]); | |
140 | if (v2.IsNull()) return 1; | |
141 | if (v2.ShapeType() != TopAbs_VERTEX) return 1; | |
142 | } | |
143 | TopLoc_Location L; | |
144 | Standard_Real f,l; | |
145 | const Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(e),L,f,l); | |
146 | TopLoc_Location LI = L.Inverted(); | |
147 | e.Orientation(TopAbs_FORWARD); | |
148 | e.Move(LI); | |
149 | v1.Move(LI); | |
150 | v2.Move(LI); | |
151 | TopoDS_Edge ne; | |
152 | if (v2.IsNull()) { | |
153 | if (v1.Orientation() == TopAbs_REVERSED) { | |
154 | v2 = v1; | |
155 | v1 = TopoDS_Shape(); | |
156 | } | |
157 | } | |
158 | BRepBuilderAPI_MakeEdge ME(C,TopoDS::Vertex(v1),TopoDS::Vertex(v2)); | |
159 | if (ME.IsDone()) { | |
160 | ne = ME; | |
161 | ne.Move(L); | |
162 | DBRep::Set(a[1],ne); | |
163 | } | |
164 | else { | |
165 | //cout <<"Error creating edge"<<endl; | |
166 | di <<"Error creating edge"<<"\n"; | |
167 | } | |
168 | return 0; | |
169 | } | |
170 | ||
171 | ||
172 | //======================================================================= | |
173 | // polyline | |
174 | //======================================================================= | |
175 | ||
176 | static Standard_Integer polyline(Draw_Interpretor& , Standard_Integer n, const char** a) | |
177 | { | |
178 | if (n < 8) return 1; | |
179 | if (((n-2) % 3) != 0) return 1; | |
180 | Standard_Integer i, j, np = (n-2) / 3; | |
181 | BRepBuilderAPI_MakePolygon W; | |
182 | j = 2; | |
183 | for (i = 1; i <= np; i ++) { | |
91322f44 | 184 | W.Add(gp_Pnt(Draw::Atof(a[j]),Draw::Atof(a[j+1]),Draw::Atof(a[j+2]))); |
7fd59977 | 185 | j += 3; |
186 | } | |
187 | DBRep::Set(a[1],W.Wire()); | |
188 | return 0; | |
189 | } | |
190 | ||
191 | //======================================================================= | |
192 | // polyvertex | |
193 | //======================================================================= | |
194 | ||
195 | static Standard_Integer polyvertex(Draw_Interpretor& , Standard_Integer n, const char** a) | |
196 | { | |
197 | if (n < 4) return 1; | |
198 | Standard_Integer i; | |
199 | BRepBuilderAPI_MakePolygon W; | |
200 | for (i = 2; i < n; i ++) { | |
201 | TopoDS_Shape S = DBRep::Get(a[i]); | |
202 | if (S.IsNull()) return 1; | |
203 | if (S.ShapeType() != TopAbs_VERTEX) return 1; | |
204 | W.Add(TopoDS::Vertex(S)); | |
205 | } | |
206 | DBRep::Set(a[1],W.Wire()); | |
207 | return 0; | |
208 | } | |
209 | ||
210 | //======================================================================= | |
211 | // wire | |
212 | //======================================================================= | |
213 | ||
214 | static Standard_Integer wire(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
215 | { | |
216 | if (n < 3) return 1; | |
217 | Standard_Integer i; | |
218 | BRepBuilderAPI_MakeWire MW; | |
219 | for (i = 2; i < n; i ++) { | |
220 | TopoDS_Shape S = DBRep::Get(a[i]); | |
221 | if (S.IsNull()) continue; | |
222 | if (S.ShapeType() == TopAbs_EDGE) | |
223 | MW.Add(TopoDS::Edge(S)); | |
224 | else if (S.ShapeType() == TopAbs_WIRE) | |
225 | MW.Add(TopoDS::Wire(S)); | |
226 | else | |
227 | continue; | |
228 | } | |
229 | if (!MW.IsDone()) { | |
230 | //cout << "Wire not done" << endl; | |
231 | di << "Wire not done" << "\n"; | |
232 | return 0; | |
233 | } | |
234 | DBRep::Set(a[1],MW); | |
235 | return 0; | |
236 | } | |
237 | ||
238 | //======================================================================= | |
239 | // mkedge | |
240 | //======================================================================= | |
241 | ||
242 | static Standard_Integer mkedge(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
243 | { | |
244 | if (n < 3) return 1; | |
73cd8a8a | 245 | |
7fd59977 | 246 | Handle(Geom_Curve) C = DrawTrSurf::GetCurve(a[2]); |
247 | Handle(Geom2d_Curve) C2d = DrawTrSurf::GetCurve2d(a[2]); | |
248 | if (C.IsNull() && C2d.IsNull()) { | |
249 | //cout << a[2] << " is not a curve" << endl; | |
250 | di << a[2] << " is not a curve" << "\n"; | |
251 | return 1; | |
252 | } | |
73cd8a8a | 253 | |
7fd59977 | 254 | TopoDS_Edge edge; |
255 | ||
256 | if (n == 3) { | |
257 | if (!C.IsNull()) edge = BRepBuilderAPI_MakeEdge(C); | |
258 | else edge = BRepBuilderAPI_MakeEdge2d(C2d); | |
259 | } | |
260 | else { | |
261 | Handle(Geom_Surface) S; | |
262 | Standard_Integer i = 0; | |
263 | if (!C2d.IsNull()) { | |
264 | S = DrawTrSurf::GetSurface(a[3]); | |
265 | if (!S.IsNull()) i = 1; | |
266 | } | |
267 | TopoDS_Shape aLocalShape(DBRep::Get(a[3+i],TopAbs_VERTEX)); | |
268 | TopoDS_Vertex V1 = TopoDS::Vertex(aLocalShape); | |
269 | // TopoDS_Vertex V1 = TopoDS::Vertex(DBRep::Get(a[3+i],TopAbs_VERTEX)); | |
270 | if (n == 5+i) { | |
271 | if (V1.IsNull()) { | |
73cd8a8a | 272 | if (!C.IsNull()) |
273 | edge = BRepBuilderAPI_MakeEdge(C,Draw::Atof(a[3]),Draw::Atof(a[4])); | |
274 | else if (S.IsNull()) | |
275 | edge = BRepBuilderAPI_MakeEdge2d(C2d,Draw::Atof(a[3]),Draw::Atof(a[4])); | |
276 | else | |
277 | edge = BRepBuilderAPI_MakeEdge(C2d,S,Draw::Atof(a[4]),Draw::Atof(a[5])); | |
7fd59977 | 278 | } |
279 | else { | |
73cd8a8a | 280 | aLocalShape = DBRep::Get(a[4+i],TopAbs_VERTEX); |
281 | TopoDS_Vertex V2 = TopoDS::Vertex(aLocalShape); | |
282 | // TopoDS_Vertex V2 = TopoDS::Vertex(DBRep::Get(a[4+i],TopAbs_VERTEX)); | |
283 | if (!C.IsNull()) | |
284 | edge = BRepBuilderAPI_MakeEdge(C,V1,V2); | |
285 | else if (S.IsNull()) | |
286 | edge = BRepBuilderAPI_MakeEdge2d(C2d,V1,V2); | |
287 | else | |
288 | edge = BRepBuilderAPI_MakeEdge(C2d,S,V1,V2); | |
7fd59977 | 289 | } |
290 | } | |
291 | else if (n == 7+i) { | |
292 | aLocalShape = DBRep::Get(a[5+i],TopAbs_VERTEX); | |
293 | TopoDS_Vertex V2 = TopoDS::Vertex(aLocalShape); | |
294 | // TopoDS_Vertex V2 = TopoDS::Vertex(DBRep::Get(a[5+i],TopAbs_VERTEX)); | |
295 | if (!C.IsNull()) | |
73cd8a8a | 296 | edge = BRepBuilderAPI_MakeEdge(C,V1,V2,Draw::Atof(a[4]),Draw::Atof(a[6])); |
7fd59977 | 297 | else if (S.IsNull()) |
73cd8a8a | 298 | edge = BRepBuilderAPI_MakeEdge2d(C2d,V1,V2,Draw::Atof(a[4]),Draw::Atof(a[6])); |
7fd59977 | 299 | else |
73cd8a8a | 300 | edge = BRepBuilderAPI_MakeEdge(C2d,S,V1,V2,Draw::Atof(a[5]),Draw::Atof(a[7])); |
7fd59977 | 301 | } |
302 | else | |
303 | return 1; | |
304 | } | |
305 | ||
306 | DBRep::Set(a[1],edge); | |
307 | return 0; | |
308 | } | |
309 | ||
310 | //======================================================================= | |
311 | // mkcurve | |
312 | //======================================================================= | |
313 | Standard_IMPORT Draw_Color DrawTrSurf_CurveColor(const Draw_Color col); | |
314 | Standard_IMPORT void DBRep_WriteColorOrientation (); | |
315 | Standard_IMPORT Draw_Color DBRep_ColorOrientation (const TopAbs_Orientation Or); | |
316 | ||
317 | static Standard_Integer mkcurve(Draw_Interpretor& di, Standard_Integer n, const char** a) | |
318 | { | |
319 | if (n < 3) return 1; | |
320 | ||
321 | Standard_Boolean DispOrientation = !strcmp(a[0],"mkoricurve"); | |
322 | ||
323 | TopoDS_Shape S = DBRep::Get(a[2],TopAbs_EDGE); | |
324 | if (S.IsNull()) return 1; | |
325 | TopLoc_Location L; | |
326 | Standard_Real f,l; | |
327 | ||
328 | Handle(Geom_Curve) C = BRep_Tool::Curve(TopoDS::Edge(S),L,f,l); | |
329 | if (C.IsNull()) { | |
330 | //cout << a[2] << " has no 3d curve" << endl; | |
331 | di << a[2] << " has no 3d curve" << "\n"; | |
332 | return 1; | |
333 | } | |
334 | C = new Geom_TrimmedCurve(C,f,l); | |
73cd8a8a | 335 | |
7fd59977 | 336 | Draw_Color col,savecol; |
73cd8a8a | 337 | |
7fd59977 | 338 | if ( DispOrientation) { |
339 | DBRep_WriteColorOrientation (); | |
340 | col = DBRep_ColorOrientation(TopoDS::Edge(S).Orientation()); | |
341 | savecol = DrawTrSurf_CurveColor(col); | |
342 | } | |
343 | DrawTrSurf::Set(a[1],C->Transformed(L.Transformation())); | |
344 | if ( DispOrientation) { | |
345 | DrawTrSurf_CurveColor(savecol); | |
346 | } | |
347 | ||
348 | return 0; | |
349 | } | |
350 | ||
351 | //======================================================================= | |
352 | //function : mkpoint | |
353 | //purpose : | |
354 | //======================================================================= | |
355 | ||
356 | static Standard_Integer mkpoint(Draw_Interpretor& , | |
73cd8a8a | 357 | Standard_Integer n, const char** a) |
7fd59977 | 358 | { |
359 | if (n < 3) return 1; | |
360 | ||
361 | TopoDS_Shape S = DBRep::Get(a[2],TopAbs_VERTEX); | |
362 | if ( S.IsNull()) return 1; | |
363 | ||
364 | TopoDS_Vertex V = TopoDS::Vertex(S); | |
73cd8a8a | 365 | |
7fd59977 | 366 | gp_Pnt P = BRep_Tool::Pnt(V); |
367 | DrawTrSurf::Set(a[1],P); | |
368 | ||
369 | return 0; | |
370 | } | |
371 | ||
372 | //======================================================================= | |
373 | // mk2dcurve | |
374 | //======================================================================= | |
375 | ||
376 | static Standard_Integer mk2dcurve(Draw_Interpretor& di, | |
73cd8a8a | 377 | Standard_Integer na, const char** a) |
7fd59977 | 378 | { |
379 | if (na < 3) return 1; | |
380 | ||
381 | TopoDS_Shape S; | |
382 | S = DBRep::Get(a[2],TopAbs_EDGE); if (S.IsNull()) return 1; | |
383 | TopoDS_Edge E = TopoDS::Edge(S); | |
384 | ||
385 | TopLoc_Location L; | |
1d47d8d0 | 386 | Standard_Real f = 0., l = 0.; |
7fd59977 | 387 | Handle(Geom2d_Curve) C; |
388 | Handle(Geom_Surface) Surf; | |
73cd8a8a | 389 | |
7fd59977 | 390 | if ( na == 3 ) { |
391 | // get the first PCurve connected to edge E | |
392 | BRep_Tool::CurveOnSurface(E,C,Surf,L,f,l); | |
393 | } | |
394 | else if ( na == 4 ) { | |
395 | S = DBRep::Get(a[3],TopAbs_FACE); if (S.IsNull()) return 1; | |
396 | TopoDS_Face F = TopoDS::Face(S); | |
397 | C = BRep_Tool::CurveOnSurface(E,F,f,l); | |
398 | } | |
399 | ||
400 | if (C.IsNull()) { | |
401 | //cout << a[2] << " has no 2d curve"; if (na == 4) cout << " on " << a[3]; | |
402 | //cout << endl; | |
403 | di << a[2] << " has no 2d curve"; if (na == 4) di << " on " << a[3]; | |
404 | di << "\n"; | |
405 | return 1; | |
406 | } | |
407 | C = new Geom2d_TrimmedCurve(C,f,l); | |
408 | DrawTrSurf::Set(a[1],C); | |
409 | ||
410 | return 0; | |
411 | } | |
412 | ||
413 | //======================================================================= | |
414 | // edge | |
415 | //======================================================================= | |
416 | ||
417 | static Standard_Integer edge(Draw_Interpretor& , Standard_Integer n, const char** a) | |
418 | { | |
419 | if (n < 4) return 1; | |
420 | TopoDS_Shape V1 = DBRep::Get(a[2],TopAbs_VERTEX); | |
421 | TopoDS_Shape V2 = DBRep::Get(a[3],TopAbs_VERTEX); | |
422 | if (V1.IsNull() || V2.IsNull()) return 1; | |
423 | TopoDS_Edge E = BRepBuilderAPI_MakeEdge(TopoDS::Vertex(V1), | |
73cd8a8a | 424 | TopoDS::Vertex(V2)); |
7fd59977 | 425 | DBRep::Set(a[1],E); |
426 | return 0; | |
427 | } | |
428 | ||
429 | //======================================================================= | |
430 | // isoedge | |
431 | //======================================================================= | |
432 | ||
433 | static Standard_Integer isoedge(Draw_Interpretor& , Standard_Integer n, const char** a) | |
434 | { | |
435 | if (n < 6) return 1; | |
436 | ||
437 | Standard_Boolean uiso = *a[0] == 'u'; | |
91322f44 | 438 | Standard_Real p = Draw::Atof(a[3]); |
439 | Standard_Real p1 = Draw::Atof(a[4]); | |
440 | Standard_Real p2 = Draw::Atof(a[5]); | |
7fd59977 | 441 | TopoDS_Shape Sh = DBRep::Get(a[2],TopAbs_FACE); |
442 | if (Sh.IsNull()) return 1; | |
443 | TopLoc_Location Loc; | |
444 | const Handle(Geom_Surface)& S = BRep_Tool::Surface(TopoDS::Face(Sh),Loc); | |
445 | Standard_Real UMin,UMax,VMin,VMax; | |
446 | BRepTools::UVBounds(TopoDS::Face(Sh),UMin,UMax,VMin,VMax); | |
447 | if (uiso) { | |
73cd8a8a | 448 | VMin = Min (VMin , Min (p1,p2)); |
449 | VMax = Max (VMax , Max (p1,p2)); | |
450 | } | |
7fd59977 | 451 | else{ |
73cd8a8a | 452 | UMin = Min (UMin , Min (p1,p2)); |
453 | UMax = Max (VMax , Max (p1,p2)); | |
454 | } | |
455 | ||
7fd59977 | 456 | Handle(Geom_RectangularTrimmedSurface) TS = new Geom_RectangularTrimmedSurface(S,UMin,UMax,VMin,VMax); |
457 | Handle(Geom_Curve) C; | |
458 | Handle(Geom2d_Line) L; | |
459 | if (uiso) { | |
460 | C = TS->UIso(p); | |
461 | L = new Geom2d_Line(gp_Pnt2d(p,0),gp_Dir2d(0,1)); | |
462 | } | |
463 | else { | |
464 | C = TS->VIso(p); | |
465 | L = new Geom2d_Line(gp_Pnt2d(0,p),gp_Dir2d(1,0)); | |
466 | } | |
467 | ||
468 | TopoDS_Edge E = BRepBuilderAPI_MakeEdge(C,p1,p2); | |
469 | E.Location(Loc); | |
470 | BRep_Builder B; | |
471 | B.UpdateEdge(E,L,TopoDS::Face(Sh),0.); | |
472 | ||
473 | DBRep::Set(a[1],E); | |
474 | return 0; | |
475 | } | |
476 | ||
477 | //======================================================================= | |
478 | // transfert | |
479 | //======================================================================= | |
480 | ||
481 | static Standard_Integer transfert(Draw_Interpretor& , Standard_Integer n, const char** a) | |
482 | { | |
483 | if (n < 3) return 1; | |
484 | ||
485 | TopoDS_Shape E1 = DBRep::Get(a[1],TopAbs_EDGE); | |
486 | TopoDS_Shape E2 = DBRep::Get(a[2],TopAbs_EDGE); | |
487 | if (E1.IsNull() || E2.IsNull()) return 1; | |
73cd8a8a | 488 | |
7fd59977 | 489 | BRep_Builder B; |
490 | B.Transfert(TopoDS::Edge(E1),TopoDS::Edge(E2)); | |
491 | return 0; | |
492 | } | |
493 | ||
494 | //======================================================================= | |
495 | // profile | |
496 | // command to build a profile | |
497 | //======================================================================= | |
498 | ||
499 | static Standard_Integer profile(Draw_Interpretor& di, | |
73cd8a8a | 500 | Standard_Integer n, |
501 | const char** a) | |
7fd59977 | 502 | { |
503 | // this command build a profile | |
504 | // from a moving point | |
505 | ||
506 | if (n == 1) { | |
507 | // print help | |
508 | ||
509 | //cout << "profile name [code values] [code values] ...\n"; | |
510 | //cout << " Build a profile in the XY plane from a moving point and direction\n"; | |
511 | //cout << " The original point and direction are 0 0 and 1 0\n"; | |
512 | //cout << " Codes and values describe the point or direction change\n"; | |
513 | //cout << " When the point change the direction becomes the tangent\n"; | |
514 | //cout << " All angles are in degree (may be negative)\n"; | |
515 | //cout << " By default the profile is closed and a face is built\n"; | |
516 | //cout << "\n"; | |
517 | //cout << " Instruction Parameters Action\n"; | |
518 | //cout << " O X Y Z Set the origin of the plane\n"; | |
519 | //cout << " P DX DY DZ UX UY UZ Set the normal and X of the plane\n"; | |
520 | //cout << " S Face Set the Plane (Face must be a Face)\n"; | |
521 | //cout << " F X Y Set the first point\n"; | |
522 | //cout << " X DX Translate point along X\n"; | |
523 | //cout << " Y DY Translate point along Y\n"; | |
524 | //cout << " L DL Translate point along direction\n"; | |
525 | //cout << " XX X Set point X coordinate\n"; | |
526 | //cout << " YY Y Set point Y coordinate\n"; | |
527 | //cout << " T DX DY Translate point\n"; | |
528 | //cout << " TT X Y Set point\n"; | |
529 | //cout << " R Angle Rotate direction\n"; | |
530 | //cout << " RR Angle Set direction\n"; | |
531 | //cout << " D DX DY Set direction\n"; | |
532 | //cout << " IX X Intersect with vertical\n"; | |
533 | //cout << " IY Y Intersect with horizontal\n"; | |
534 | //cout << " C Radius Angle Arc of circle tangent to direction\n"; | |
535 | //cout << " W Make a closed wire\n"; | |
536 | //cout << " WW Make an open wire\n"; | |
537 | //cout << endl; | |
538 | di << "profile name [code values] [code values] ...\n"; | |
539 | di << " Build a profile in the XY plane from a moving point and direction\n"; | |
540 | di << " The original point and direction are 0 0 and 1 0\n"; | |
541 | di << " Codes and values describe the point or direction change\n"; | |
542 | di << " When the point change the direction becomes the tangent\n"; | |
543 | di << " All angles are in degree (may be negative)\n"; | |
544 | di << " By default the profile is closed and a face is built\n"; | |
545 | di << "\n"; | |
546 | di << " Instruction Parameters Action\n"; | |
547 | di << " O X Y Z Set the origin of the plane\n"; | |
548 | di << " P DX DY DZ UX UY UZ Set the normal and X of the plane\n"; | |
549 | di << " S Face Set the Plane (Face must be a Face)\n"; | |
550 | di << " F X Y Set the first point\n"; | |
551 | di << " X DX Translate point along X\n"; | |
552 | di << " Y DY Translate point along Y\n"; | |
553 | di << " L DL Translate point along direction\n"; | |
554 | di << " XX X Set point X coordinate\n"; | |
555 | di << " YY Y Set point Y coordinate\n"; | |
556 | di << " T DX DY Translate point\n"; | |
557 | di << " TT X Y Set point\n"; | |
558 | di << " R Angle Rotate direction\n"; | |
559 | di << " RR Angle Set direction\n"; | |
560 | di << " D DX DY Set direction\n"; | |
561 | di << " IX X Intersect with vertical\n"; | |
562 | di << " IY Y Intersect with horizontal\n"; | |
563 | di << " C Radius Angle Arc of circle tangent to direction\n"; | |
564 | di << " W Make a closed wire\n"; | |
565 | di << " WW Make an open wire\n"; | |
566 | di << "\n"; | |
567 | return 0; | |
568 | } | |
569 | ||
570 | Standard_Integer i = 2; | |
571 | Standard_Real x0 = 0, y0 = 0, x = 0, y = 0, dx = 1, dy = 0; | |
572 | BRepBuilderAPI_MakeWire MW; | |
573 | gp_Ax3 DummyHP(gp::XOY()); | |
574 | gp_Pln P(DummyHP); | |
575 | enum {line , circle, none} move; | |
576 | Standard_Boolean face = Standard_True; | |
577 | Standard_Boolean close = Standard_True; | |
578 | Standard_Boolean first = Standard_True; | |
579 | Standard_Boolean stayfirst = Standard_False; | |
580 | Standard_Boolean isplanar = Standard_True; | |
581 | TopoDS_Shape S; | |
582 | TopLoc_Location TheLocation; | |
583 | Handle(Geom_Surface) Surface; | |
584 | while (i < n) { | |
585 | ||
586 | Standard_Real length=0,radius=0,angle=0; | |
587 | move = none; | |
588 | ||
589 | switch (a[i][0]) { | |
590 | ||
591 | case 'F': | |
592 | case 'f': | |
593 | i += 2; | |
594 | if (i >= n) goto badargs; | |
595 | if (!first) { | |
73cd8a8a | 596 | di << "profile: The F instruction must precede all moves"; |
597 | return 1; | |
7fd59977 | 598 | } |
91322f44 | 599 | x0 = x = Draw::Atof(a[i-1]); |
600 | y0 = y = Draw::Atof(a[i]); | |
7fd59977 | 601 | stayfirst = Standard_True; |
602 | break; | |
603 | ||
604 | case 'O': | |
605 | case 'o': | |
606 | i += 3; | |
607 | if (i >= n) goto badargs; | |
91322f44 | 608 | P.SetLocation(gp_Pnt(Draw::Atof(a[i-2]),Draw::Atof(a[i-1]),Draw::Atof(a[i]))); |
7fd59977 | 609 | stayfirst = Standard_True; |
610 | break; | |
611 | ||
612 | case 'P': | |
613 | case 'p': | |
614 | i += 6; | |
615 | if (i >= n) goto badargs; | |
616 | { | |
73cd8a8a | 617 | gp_Vec vn(Draw::Atof(a[i-5]),Draw::Atof(a[i-4]),Draw::Atof(a[i-3])); |
618 | gp_Vec vx(Draw::Atof(a[i-2]),Draw::Atof(a[i-1]),Draw::Atof(a[i])); | |
619 | if (vn.Magnitude() <= Precision::Confusion()) { | |
620 | di << "profile : null direction"; | |
621 | return 1; | |
622 | } | |
623 | if (vx.Magnitude() <= Precision::Confusion()) { | |
624 | di << "profile : null direction"; | |
625 | return 1; | |
626 | } | |
627 | gp_Ax2 ax(P.Location(),vn,vx); | |
628 | P.SetPosition(ax); | |
7fd59977 | 629 | } |
630 | stayfirst = Standard_True; | |
631 | break; | |
632 | ||
633 | case 'S': | |
634 | case 's': | |
635 | i += 1; | |
636 | if (i >= n) goto badargs; | |
637 | { | |
73cd8a8a | 638 | TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE)); |
639 | TopoDS_Face Face = TopoDS::Face(aLocalShape); | |
640 | // TopoDS_Face Face = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)); | |
641 | if (Face.IsNull()) { | |
642 | di << "profile : no face found"; | |
643 | return 1; | |
644 | } | |
645 | Surface = BRep_Tool::Surface(Face,TheLocation); | |
646 | Handle(Geom_Plane) Plane = Handle(Geom_Plane)::DownCast(Surface); | |
647 | if ( Plane.IsNull()) { | |
648 | isplanar = Standard_False; | |
649 | } | |
650 | else | |
651 | P = Plane->Pln(); | |
7fd59977 | 652 | } |
653 | stayfirst = Standard_True; | |
654 | break; | |
655 | ||
656 | case 'X': | |
657 | case 'x': | |
658 | i++; | |
659 | if (i >= n) goto badargs; | |
91322f44 | 660 | length = Draw::Atof(a[i]); |
7fd59977 | 661 | if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) { |
73cd8a8a | 662 | length -= x; |
7fd59977 | 663 | } |
664 | dx = 1; dy = 0; | |
665 | move = line; | |
666 | break; | |
73cd8a8a | 667 | |
7fd59977 | 668 | case 'Y': |
669 | case 'y': | |
670 | i++; | |
671 | if (i >= n) goto badargs; | |
91322f44 | 672 | length = Draw::Atof(a[i]); |
7fd59977 | 673 | if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) { |
73cd8a8a | 674 | length -= y; |
7fd59977 | 675 | } |
676 | dx = 0; dy = 1; | |
677 | move = line; | |
678 | break; | |
73cd8a8a | 679 | |
7fd59977 | 680 | case 'L': |
681 | case 'l': | |
682 | i++; | |
683 | if (i >= n) goto badargs; | |
91322f44 | 684 | length = Draw::Atof(a[i]); |
7fd59977 | 685 | move = line; |
686 | break; | |
687 | ||
688 | case 'T': | |
689 | case 't': | |
690 | i += 2; | |
691 | if (i >= n) goto badargs; | |
692 | { | |
73cd8a8a | 693 | Standard_Real vx = Draw::Atof(a[i-1]); |
694 | Standard_Real vy = Draw::Atof(a[i]); | |
695 | if ((a[i-2][1] == 'T') || (a[i-2][1] == 't')) { | |
696 | vx -= x; | |
697 | vy -= y; | |
698 | } | |
699 | length = Sqrt(vx*vx+vy*vy); | |
700 | if (length > Precision::Confusion()) { | |
701 | move = line; | |
702 | dx = vx / length; | |
703 | dy = vy / length; | |
704 | } | |
7fd59977 | 705 | } |
706 | break; | |
707 | ||
708 | case 'R': | |
709 | case 'r': | |
710 | i++; | |
711 | if (i >= n) goto badargs; | |
91322f44 | 712 | angle = Draw::Atof(a[i]) * (M_PI / 180.0); |
7fd59977 | 713 | if ((a[i-1][1] == 'R') || (a[i-1][1] == 'r')) { |
73cd8a8a | 714 | dx = Cos(angle); |
715 | dy = Sin(angle); | |
7fd59977 | 716 | } |
717 | else { | |
73cd8a8a | 718 | Standard_Real c = Cos(angle); |
719 | Standard_Real s = Sin(angle); | |
720 | Standard_Real t = c * dx - s * dy; | |
721 | dy = s * dx + c * dy; | |
722 | dx = t; | |
7fd59977 | 723 | } |
724 | break; | |
725 | ||
726 | case 'D': | |
727 | case 'd': | |
728 | i += 2; | |
729 | if (i >= n) goto badargs; | |
730 | { | |
73cd8a8a | 731 | Standard_Real vx = Draw::Atof(a[i-1]); |
732 | Standard_Real vy = Draw::Atof(a[i]); | |
733 | length = Sqrt(vx*vx+vy*vy); | |
734 | if (length > Precision::Confusion()) { | |
735 | // move = line; DUB | |
736 | dx = vx / length; | |
737 | dy = vy / length; | |
738 | } | |
7fd59977 | 739 | } |
740 | break; | |
741 | ||
742 | case 'C': | |
743 | case 'c': | |
744 | i += 2; | |
745 | if (i >= n) goto badargs; | |
91322f44 | 746 | radius = Draw::Atof(a[i-1]); |
7fd59977 | 747 | if (Abs(radius) > Precision::Confusion()) { |
73cd8a8a | 748 | angle = Draw::Atof(a[i]) * (M_PI / 180.0); |
749 | move = circle; | |
7fd59977 | 750 | } |
751 | break; | |
752 | ||
753 | case 'I': | |
754 | case 'i': | |
755 | i++; | |
756 | if (i >= n) goto badargs; | |
91322f44 | 757 | length = Draw::Atof(a[i]); |
7fd59977 | 758 | if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) { |
73cd8a8a | 759 | if (Abs(dx) < Precision::Confusion()) { |
760 | di << "Profile : cannot intersect, arg " << i-1; | |
761 | return 1; | |
762 | } | |
763 | length = (length - x) / dx; | |
764 | move = line; | |
7fd59977 | 765 | } |
766 | else if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) { | |
73cd8a8a | 767 | if (Abs(dy) < Precision::Confusion()) { |
768 | di << "Profile : cannot intersect, arg " << i-1; | |
769 | return 1; | |
770 | } | |
771 | length = (length - y) / dy; | |
772 | move = line; | |
7fd59977 | 773 | } |
73cd8a8a | 774 | |
7fd59977 | 775 | break; |
776 | ||
777 | case 'W': | |
778 | case 'w': | |
779 | face = Standard_False; | |
780 | if ((a[i][1] == 'W') || (a[i][1] == 'w')) { | |
73cd8a8a | 781 | close = Standard_False; |
7fd59977 | 782 | } |
783 | i = n-1; | |
784 | break; | |
785 | ||
786 | default: | |
787 | di <<"profile : unknown code " << a[i]; | |
788 | return 1; | |
789 | } | |
790 | ||
73cd8a8a | 791 | again: |
7fd59977 | 792 | |
793 | switch (move) { | |
73cd8a8a | 794 | |
7fd59977 | 795 | case line : |
796 | { | |
73cd8a8a | 797 | if (length < 0) { |
798 | length = -length; | |
799 | dx = -dx; | |
800 | dy = -dy; | |
801 | } | |
802 | Handle(Geom2d_Line) l = | |
803 | new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy)); | |
804 | if (isplanar) | |
805 | MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(l,P),0,length)); | |
806 | else | |
807 | MW.Add(BRepBuilderAPI_MakeEdge(l,Surface,0,length)); | |
808 | x += length*dx; | |
809 | y += length*dy; | |
7fd59977 | 810 | } |
811 | break; | |
812 | ||
813 | case circle : | |
814 | { | |
73cd8a8a | 815 | Standard_Boolean sense = Standard_True; |
816 | if (radius < 0) { | |
817 | radius = -radius; | |
818 | sense = !sense; | |
819 | dx = -dx; | |
820 | dy = -dy; | |
821 | } | |
822 | gp_Ax2d ax(gp_Pnt2d(x-radius*dy,y+radius*dx),gp_Dir2d(dy,-dx)); | |
823 | if (angle < 0) { | |
824 | angle = -angle; | |
825 | sense = !sense; | |
826 | } | |
827 | Handle(Geom2d_Circle) c = new Geom2d_Circle(ax,radius,sense); | |
828 | if (isplanar) | |
829 | MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(c,P),0,angle)); | |
830 | else | |
831 | MW.Add(BRepBuilderAPI_MakeEdge(c,Surface,0,angle)); | |
832 | gp_Pnt2d p; | |
833 | gp_Vec2d v; | |
834 | c->D1(angle,p,v); | |
835 | x = p.X(); | |
836 | y = p.Y(); | |
837 | dx = v.X() / radius; | |
838 | dy = v.Y() / radius; | |
7fd59977 | 839 | } |
840 | break; | |
841 | ||
842 | case none: | |
843 | break; | |
844 | } | |
845 | ||
846 | // update first | |
847 | first = stayfirst; | |
848 | stayfirst = Standard_False; | |
849 | ||
850 | // next segment.... | |
851 | i++; | |
852 | if ((i == n) && close) { | |
853 | // the closing segment | |
854 | dx = x0-x; | |
855 | dy = y0-y; | |
856 | length = Sqrt(dx*dx+dy*dy); | |
857 | if (length > Precision::Confusion()) { | |
73cd8a8a | 858 | move = line; |
859 | dx = dx / length; | |
860 | dy = dy / length; | |
861 | goto again; | |
7fd59977 | 862 | } |
863 | } | |
864 | } | |
865 | ||
866 | ||
867 | // get the result, face or wire | |
868 | ||
869 | if (face) { | |
870 | if ( isplanar) | |
871 | S = BRepBuilderAPI_MakeFace(P,MW.Wire()); | |
872 | else { | |
873 | BRepBuilderAPI_MakeFace MFace; | |
1c72dff6 | 874 | MFace.Init(Surface,Standard_False,Precision::Confusion()); |
7fd59977 | 875 | MFace.Add(MW.Wire()); |
876 | S = MFace.Face(); | |
877 | } | |
878 | } | |
879 | else { | |
880 | S = MW; | |
881 | } | |
73cd8a8a | 882 | |
7fd59977 | 883 | if (!TheLocation.IsIdentity()) |
884 | S.Move(TheLocation); | |
885 | ||
886 | if ( !isplanar) { | |
887 | Standard_Real Tol = 1.e-5; | |
888 | BRepLib::BuildCurves3d(S,Tol); | |
889 | } | |
890 | ||
891 | DBRep::Set(a[1],S); | |
892 | ||
893 | return 0; | |
894 | ||
73cd8a8a | 895 | badargs: |
7fd59977 | 896 | di << "profile : bad number of arguments"; |
897 | return 1; | |
898 | } | |
899 | //======================================================================= | |
900 | // profile | |
901 | // command to build a profile | |
902 | //======================================================================= | |
903 | ||
904 | static Standard_Integer bsplineprof(Draw_Interpretor& di, | |
73cd8a8a | 905 | Standard_Integer n, |
906 | const char** a) | |
7fd59977 | 907 | { |
908 | // this command build a profile | |
909 | // from a moving point | |
910 | ||
911 | if (n == 1) { | |
912 | // print help | |
913 | ||
914 | //cout << " bsplineprof name [S face] [W WW] " << endl; | |
915 | //cout << " for an edge : <digitizes> ... <mouse button 2> " << endl ; | |
916 | //cout << " to end profile : <mouse button 3> " << endl ; | |
917 | //cout << " Build a profile in the XY plane from digitizes" << endl ; | |
918 | //cout << " By default the profile is closed and a face is built\n"; | |
919 | //cout << "\n"; | |
920 | //cout << " W Make a closed wire\n"; | |
921 | //cout << " WW Make an open wire\n"; | |
922 | //cout << endl; | |
923 | di << " bsplineprof name [S face] [W WW] " << "\n"; | |
924 | di << " for an edge : <digitizes> ... <mouse button 2> " << "\n"; | |
925 | di << " to end profile : <mouse button 3> " << "\n"; | |
926 | di << " Build a profile in the XY plane from digitizes" << "\n"; | |
927 | di << " By default the profile is closed and a face is built\n"; | |
928 | di << "\n"; | |
929 | di << " W Make a closed wire\n"; | |
930 | di << " WW Make an open wire\n"; | |
931 | di << "\n"; | |
932 | return 0; | |
933 | } | |
934 | ||
935 | gp_Pnt2d last_point(0.0e0, | |
73cd8a8a | 936 | 0.0e0) ; |
7fd59977 | 937 | gp_Pnt2d first_point(0.0e0, |
73cd8a8a | 938 | 0.0e0) ; |
7fd59977 | 939 | Standard_Integer i = 2, |
73cd8a8a | 940 | wait = 1 ; |
7fd59977 | 941 | // Standard_Real x0 = 0, y0 = 0, x = 0, y = 0, dx = 1, dy = 0; |
942 | Standard_Real x = 0, y = 0, dx = 1, dy = 0; | |
943 | BRepBuilderAPI_MakeWire MW; | |
944 | gp_Ax3 DummyHP(gp::XOY()); | |
945 | gp_Pln P(DummyHP); | |
946 | Standard_Boolean face = Standard_True; | |
947 | Standard_Boolean close = Standard_True; | |
948 | // Standard_Boolean first = Standard_True; | |
7fd59977 | 949 | Standard_Boolean isplanar = Standard_True; |
950 | Standard_Real length ; | |
951 | TopoDS_Shape S; | |
952 | TopLoc_Location TheLocation; | |
953 | Handle(Geom_Surface) Surface; | |
954 | if (n > 2) { | |
955 | while (i < n) { | |
73cd8a8a | 956 | |
7fd59977 | 957 | switch (a[i][0]) { |
73cd8a8a | 958 | |
7fd59977 | 959 | case 'S': |
960 | case 's': | |
73cd8a8a | 961 | i += 1; |
962 | { | |
963 | TopoDS_Shape aLocalShape(DBRep::Get(a[i],TopAbs_FACE)); | |
964 | TopoDS_Face Face = TopoDS::Face(aLocalShape); | |
965 | // TopoDS_Face Face = TopoDS::Face(DBRep::Get(a[i],TopAbs_FACE)); | |
966 | if (Face.IsNull()) { | |
967 | di << "profile : no face found"; | |
968 | return 1; | |
969 | } | |
970 | Surface = BRep_Tool::Surface(Face,TheLocation); | |
971 | Handle(Geom_Plane) Plane = Handle(Geom_Plane)::DownCast(Surface); | |
972 | if ( Plane.IsNull()) { | |
973 | isplanar = Standard_False; | |
974 | } | |
975 | else | |
976 | P = Plane->Pln(); | |
977 | } | |
7fd59977 | 978 | i += 1 ; |
73cd8a8a | 979 | break; |
980 | ||
7fd59977 | 981 | case 'W': |
982 | case 'w': | |
73cd8a8a | 983 | face = Standard_False; |
984 | if ((a[i][1] == 'W') || (a[i][1] == 'w')) { | |
985 | close = Standard_False; | |
986 | } | |
987 | i = n-1; | |
988 | break; | |
7fd59977 | 989 | |
990 | default: | |
73cd8a8a | 991 | di <<"profile : unknown code " << a[i]; |
992 | return 1; | |
7fd59977 | 993 | } |
994 | } | |
995 | } | |
996 | // | |
0d969553 Y |
997 | // to be done : close the profile using the first point of the contour |
998 | // and the point taken with mouse button 3 | |
7fd59977 | 999 | // |
73cd8a8a | 1000 | Handle(Geom2d_BSplineCurve) C ; |
1001 | Handle(Geom_Curve) curve3d_ptr ; | |
1002 | Standard_Integer id, ii; | |
1003 | Standard_Integer X,Y,b, not_done; | |
1004 | Standard_Integer num_points = 0 ; | |
1005 | gp_Pnt2d a_point( 0.0e0, | |
1006 | 0.0e0) ; | |
7fd59977 | 1007 | Handle(TColgp_HArray1OfPnt2d) points_array_ptr = |
1008 | new TColgp_HArray1OfPnt2d(1, 1); | |
1009 | Handle(TColgp_HArray1OfPnt2d) new_points_array_ptr ; | |
1010 | ||
1011 | not_done = 1 ; | |
1012 | while (not_done) { | |
73cd8a8a | 1013 | |
1014 | dout.Select(id,X,Y,b,wait); | |
1015 | Standard_Real z = dout.Zoom(id); | |
1016 | a_point.SetCoord(1,(Standard_Real)X /z) ; | |
1017 | a_point.SetCoord(2,(Standard_Real)Y /z) ; | |
1018 | if (num_points == 0) { | |
1019 | points_array_ptr = | |
1020 | new TColgp_HArray1OfPnt2d(1, 1); | |
1021 | points_array_ptr->ChangeArray1()(1) = a_point ; | |
1022 | first_point = a_point ; | |
1023 | ||
1024 | } | |
1025 | num_points += 1 ; | |
1026 | if (num_points >= 2) { | |
1027 | new_points_array_ptr = | |
1028 | new TColgp_HArray1OfPnt2d(1, num_points); | |
1029 | for (ii = 1 ; ii <= num_points -1 ; ii++) { | |
1030 | new_points_array_ptr->ChangeArray1()(ii) = | |
1031 | points_array_ptr->Array1()(ii) ; | |
1032 | } | |
1033 | new_points_array_ptr->ChangeArray1()(num_points) = a_point ; | |
1034 | Geom2dAPI_Interpolate a2dInterpolator(new_points_array_ptr, | |
1035 | Standard_False, | |
1036 | 1.0e-5) ; | |
1037 | a2dInterpolator.Perform() ; | |
1038 | if (a2dInterpolator.IsDone()) { | |
1039 | C = a2dInterpolator.Curve() ; | |
1040 | curve3d_ptr = | |
1041 | GeomAPI::To3d(C,P) ; | |
1042 | DrawTrSurf::Set(a[1], curve3d_ptr); | |
1043 | dout.RepaintView(id); | |
1044 | } | |
1045 | points_array_ptr = new_points_array_ptr ; | |
1046 | ||
1047 | } | |
1048 | ||
1049 | if (b == 2 || b == 3) { | |
1050 | if (num_points == 2) { | |
7fd59977 | 1051 | x = last_point.Coord(1) ; |
1052 | y = last_point.Coord(2) ; | |
1053 | dx = a_point.Coord(1) - x ; | |
1054 | dy = a_point.Coord(2) - y ; | |
1055 | gp_Vec2d a_vector(dx, | |
73cd8a8a | 1056 | dy) ; |
7fd59977 | 1057 | length = a_vector.Magnitude() ; |
73cd8a8a | 1058 | Handle(Geom2d_Line) l = |
1059 | new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy)); | |
1060 | if (isplanar) { | |
1061 | MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(l,P),0,length)); | |
7fd59977 | 1062 | } |
73cd8a8a | 1063 | else { |
1064 | MW.Add(BRepBuilderAPI_MakeEdge(l,Surface,0,length)); | |
7fd59977 | 1065 | } |
1066 | ||
1067 | } | |
73cd8a8a | 1068 | else if (num_points > 2) { |
7fd59977 | 1069 | if (isplanar) { |
73cd8a8a | 1070 | MW.Add(BRepBuilderAPI_MakeEdge(curve3d_ptr, |
1071 | curve3d_ptr->FirstParameter(), | |
1072 | curve3d_ptr->LastParameter())); | |
7fd59977 | 1073 | } |
73cd8a8a | 1074 | else { |
1075 | MW.Add(BRepBuilderAPI_MakeEdge(C, | |
1076 | Surface, | |
1077 | C->FirstParameter(), | |
1078 | C->LastParameter())); | |
7fd59977 | 1079 | } |
1080 | } | |
73cd8a8a | 1081 | if (num_points >= 2) { |
1082 | last_point = a_point ; | |
1083 | points_array_ptr->ChangeArray1()(1) = a_point ; | |
1084 | num_points = 1 ; | |
1085 | DBRep::Set(a[1], MW.Wire()) ; | |
1086 | } | |
1087 | ||
1088 | ||
1089 | } | |
1090 | if (b == 3) { | |
1091 | not_done = 0 ; | |
1092 | } | |
1093 | } | |
7fd59977 | 1094 | a_point = first_point ; |
1095 | if (close) { | |
73cd8a8a | 1096 | |
7fd59977 | 1097 | x = last_point.Coord(1) ; |
1098 | y = last_point.Coord(2) ; | |
1099 | dx = a_point.Coord(1) - x ; | |
1100 | dy = a_point.Coord(2) - y ; | |
1101 | gp_Vec2d a_vector(dx, | |
73cd8a8a | 1102 | dy) ; |
7fd59977 | 1103 | length = a_vector.Magnitude() ; |
1104 | Handle(Geom2d_Line) l = | |
1105 | new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy)); | |
1106 | if (isplanar) | |
1107 | MW.Add(BRepBuilderAPI_MakeEdge(GeomAPI::To3d(l,P),0,length)); | |
1108 | else | |
1109 | MW.Add(BRepBuilderAPI_MakeEdge(l,Surface,0,length)); | |
1110 | } | |
1111 | if (face) { | |
1112 | if ( isplanar) | |
1113 | S = BRepBuilderAPI_MakeFace(P,MW.Wire()); | |
1114 | else { | |
1115 | BRepBuilderAPI_MakeFace MFace; | |
1c72dff6 | 1116 | MFace.Init(Surface,Standard_False,Precision::Confusion()); |
7fd59977 | 1117 | MFace.Add(MW.Wire()); |
1118 | S = MFace.Face(); | |
1119 | } | |
1120 | } | |
1121 | else { | |
1122 | S = MW; | |
1123 | } | |
73cd8a8a | 1124 | |
7fd59977 | 1125 | if (!TheLocation.IsIdentity()) |
1126 | S.Move(TheLocation); | |
73cd8a8a | 1127 | |
7fd59977 | 1128 | if ( !isplanar) { |
1129 | Standard_Real Tol = 1.e-5; | |
1130 | BRepLib::BuildCurves3d(S,Tol); | |
1131 | } | |
73cd8a8a | 1132 | |
7fd59977 | 1133 | DBRep::Set(a[1],S); |
73cd8a8a | 1134 | |
7fd59977 | 1135 | return 0; |
7fd59977 | 1136 | } |
1137 | ||
1138 | ||
1139 | ||
1140 | //======================================================================= | |
1141 | // 2dprofile | |
1142 | // command to build a profile | |
1143 | //======================================================================= | |
1144 | ||
1145 | static Standard_Integer profile2d(Draw_Interpretor& di, | |
73cd8a8a | 1146 | Standard_Integer n, |
1147 | const char** a) | |
7fd59977 | 1148 | { |
1149 | // this command build a profile with 2d curves. | |
1150 | // from a moving point | |
1151 | ||
1152 | if (n == 1) { | |
1153 | // print help | |
1154 | ||
1155 | //cout << "profile name [code values] [code values] ...\n"; | |
1156 | //cout << " Build a profile in the UV plane from a moving point and direction\n"; | |
1157 | //cout << " The original point and direction are 0 0 and 1 0\n"; | |
1158 | //cout << " Codes and values describe the point or direction change\n"; | |
1159 | //cout << " When the point change the direction becomes the tangent\n"; | |
1160 | //cout << " All angles are in degree (may be negative)\n"; | |
1161 | //cout << " By default the profile is closed \n"; | |
1162 | //cout << "\n"; | |
1163 | //cout << " Instruction Parameters Action\n"; | |
1164 | //cout << " F X Y Set the first point\n"; | |
1165 | //cout << " X DX Translate point along X\n"; | |
1166 | //cout << " Y DY Translate point along Y\n"; | |
1167 | //cout << " L DL Translate point along direction\n"; | |
1168 | //cout << " XX X Set point X coordinate\n"; | |
1169 | //cout << " YY Y Set point Y coordinate\n"; | |
1170 | //cout << " T DX DY Translate point\n"; | |
1171 | //cout << " TT X Y Set point\n"; | |
1172 | //cout << " R Angle Rotate direction\n"; | |
1173 | //cout << " RR Angle Set direction\n"; | |
1174 | //cout << " D DX DY Set direction\n"; | |
1175 | //cout << " IX X Intersect with vertical\n"; | |
1176 | //cout << " IY Y Intersect with horizontal\n"; | |
1177 | //cout << " C Radius Angle Arc of circle tangent to direction\n"; | |
1178 | //cout << " W Make a closed wire\n"; | |
1179 | //cout << endl; | |
1180 | di << "profile name [code values] [code values] ...\n"; | |
1181 | di << " Build a profile in the UV plane from a moving point and direction\n"; | |
1182 | di << " The original point and direction are 0 0 and 1 0\n"; | |
1183 | di << " Codes and values describe the point or direction change\n"; | |
1184 | di << " When the point change the direction becomes the tangent\n"; | |
1185 | di << " All angles are in degree (may be negative)\n"; | |
1186 | di << " By default the profile is closed \n"; | |
1187 | di << "\n"; | |
1188 | di << " Instruction Parameters Action\n"; | |
1189 | di << " F X Y Set the first point\n"; | |
1190 | di << " X DX Translate point along X\n"; | |
1191 | di << " Y DY Translate point along Y\n"; | |
1192 | di << " L DL Translate point along direction\n"; | |
1193 | di << " XX X Set point X coordinate\n"; | |
1194 | di << " YY Y Set point Y coordinate\n"; | |
1195 | di << " T DX DY Translate point\n"; | |
1196 | di << " TT X Y Set point\n"; | |
1197 | di << " R Angle Rotate direction\n"; | |
1198 | di << " RR Angle Set direction\n"; | |
1199 | di << " D DX DY Set direction\n"; | |
1200 | di << " IX X Intersect with vertical\n"; | |
1201 | di << " IY Y Intersect with horizontal\n"; | |
1202 | di << " C Radius Angle Arc of circle tangent to direction\n"; | |
1203 | di << " W Make a closed wire\n"; | |
1204 | di << "\n"; | |
1205 | return 0; | |
1206 | } | |
1207 | ||
1208 | Standard_Integer i = 2, NbCurves = 0; | |
1209 | Standard_Real x0 = 0, y0 = 0, x = 0, y = 0, dx = 1, dy = 0; | |
1210 | enum {line , circle, none} move; | |
1211 | Standard_Boolean close = Standard_True; | |
1212 | Standard_Boolean first = Standard_True; | |
1213 | Standard_Boolean stayfirst = Standard_False; | |
1214 | char* name = new char[100]; | |
1215 | ||
1216 | while (i < n) { | |
1217 | ||
1218 | Standard_Real length=0,radius=0,angle=0; | |
1219 | move = none; | |
1220 | ||
1221 | switch (a[i][0]) { | |
1222 | ||
1223 | case 'F': | |
1224 | case 'f': | |
1225 | i += 2; | |
1226 | if (i >= n) goto badargs; | |
1227 | if (!first) { | |
73cd8a8a | 1228 | di << "profile: The F instruction must precede all moves"; |
1229 | return 1; | |
7fd59977 | 1230 | } |
91322f44 | 1231 | x0 = x = Draw::Atof(a[i-1]); |
1232 | y0 = y = Draw::Atof(a[i]); | |
7fd59977 | 1233 | stayfirst = Standard_True; |
1234 | break; | |
1235 | ||
1236 | case 'X': | |
1237 | case 'x': | |
1238 | i++; | |
1239 | if (i >= n) goto badargs; | |
91322f44 | 1240 | length = Draw::Atof(a[i]); |
7fd59977 | 1241 | if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) { |
73cd8a8a | 1242 | length -= x; |
7fd59977 | 1243 | } |
1244 | dx = 1; dy = 0; | |
1245 | move = line; | |
1246 | break; | |
73cd8a8a | 1247 | |
7fd59977 | 1248 | case 'Y': |
1249 | case 'y': | |
1250 | i++; | |
1251 | if (i >= n) goto badargs; | |
91322f44 | 1252 | length = Draw::Atof(a[i]); |
7fd59977 | 1253 | if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) { |
73cd8a8a | 1254 | length -= y; |
7fd59977 | 1255 | } |
1256 | dx = 0; dy = 1; | |
1257 | move = line; | |
1258 | break; | |
73cd8a8a | 1259 | |
7fd59977 | 1260 | case 'L': |
1261 | case 'l': | |
1262 | i++; | |
1263 | if (i >= n) goto badargs; | |
91322f44 | 1264 | length = Draw::Atof(a[i]); |
7fd59977 | 1265 | move = line; |
1266 | break; | |
1267 | ||
1268 | case 'T': | |
1269 | case 't': | |
1270 | i += 2; | |
1271 | if (i >= n) goto badargs; | |
1272 | { | |
73cd8a8a | 1273 | Standard_Real vx = Draw::Atof(a[i-1]); |
1274 | Standard_Real vy = Draw::Atof(a[i]); | |
1275 | if ((a[i-2][1] == 'T') || (a[i-2][1] == 't')) { | |
1276 | vx -= x; | |
1277 | vy -= y; | |
1278 | } | |
1279 | length = Sqrt(vx*vx+vy*vy); | |
1280 | if (length > Precision::Confusion()) { | |
1281 | move = line; | |
1282 | dx = vx / length; | |
1283 | dy = vy / length; | |
1284 | } | |
7fd59977 | 1285 | } |
1286 | break; | |
1287 | ||
1288 | case 'R': | |
1289 | case 'r': | |
1290 | i++; | |
1291 | if (i >= n) goto badargs; | |
91322f44 | 1292 | angle = Draw::Atof(a[i]) * (M_PI / 180.0); |
7fd59977 | 1293 | if ((a[i-1][1] == 'R') || (a[i-1][1] == 'r')) { |
73cd8a8a | 1294 | dx = Cos(angle); |
1295 | dy = Sin(angle); | |
7fd59977 | 1296 | } |
1297 | else { | |
73cd8a8a | 1298 | Standard_Real c = Cos(angle); |
1299 | Standard_Real s = Sin(angle); | |
1300 | Standard_Real t = c * dx - s * dy; | |
1301 | dy = s * dx + c * dy; | |
1302 | dx = t; | |
7fd59977 | 1303 | } |
1304 | break; | |
1305 | ||
1306 | case 'D': | |
1307 | case 'd': | |
1308 | i += 2; | |
1309 | if (i >= n) goto badargs; | |
1310 | { | |
73cd8a8a | 1311 | Standard_Real vx = Draw::Atof(a[i-1]); |
1312 | Standard_Real vy = Draw::Atof(a[i]); | |
1313 | length = Sqrt(vx*vx+vy*vy); | |
1314 | if (length > Precision::Confusion()) { | |
1315 | // move = line; DUB | |
1316 | dx = vx / length; | |
1317 | dy = vy / length; | |
1318 | } | |
7fd59977 | 1319 | } |
1320 | break; | |
1321 | ||
1322 | case 'C': | |
1323 | case 'c': | |
1324 | i += 2; | |
1325 | if (i >= n) goto badargs; | |
91322f44 | 1326 | radius = Draw::Atof(a[i-1]); |
7fd59977 | 1327 | if (Abs(radius) > Precision::Confusion()) { |
73cd8a8a | 1328 | angle = Draw::Atof(a[i]) * (M_PI / 180.0); |
1329 | move = circle; | |
7fd59977 | 1330 | } |
1331 | break; | |
1332 | ||
1333 | case 'I': | |
1334 | case 'i': | |
1335 | i++; | |
1336 | if (i >= n) goto badargs; | |
91322f44 | 1337 | length = Draw::Atof(a[i]); |
7fd59977 | 1338 | if ((a[i-1][1] == 'X') || (a[i-1][1] == 'x')) { |
73cd8a8a | 1339 | if (Abs(dx) < Precision::Confusion()) { |
1340 | di << "Profile : cannot intersect, arg " << i-1; | |
1341 | return 1; | |
1342 | } | |
1343 | length = (length - x) / dx; | |
1344 | move = line; | |
7fd59977 | 1345 | } |
1346 | else if ((a[i-1][1] == 'Y') || (a[i-1][1] == 'y')) { | |
73cd8a8a | 1347 | if (Abs(dy) < Precision::Confusion()) { |
1348 | di << "Profile : cannot intersect, arg " << i-1; | |
1349 | return 1; | |
1350 | } | |
1351 | length = (length - y) / dy; | |
1352 | move = line; | |
7fd59977 | 1353 | } |
73cd8a8a | 1354 | |
7fd59977 | 1355 | break; |
1356 | ||
1357 | case 'W': | |
1358 | case 'w': | |
1359 | close = Standard_False; | |
1360 | i = n-1; | |
1361 | break; | |
73cd8a8a | 1362 | |
7fd59977 | 1363 | default: |
1364 | di <<"profile : unknown code " << a[i]; | |
1365 | return 1; | |
1366 | } | |
1367 | ||
73cd8a8a | 1368 | again: |
1369 | ||
7fd59977 | 1370 | switch (move) { |
73cd8a8a | 1371 | |
7fd59977 | 1372 | case line : |
1373 | { | |
73cd8a8a | 1374 | if (length < 0) { |
1375 | length = -length; | |
1376 | dx = -dx; | |
1377 | dy = -dy; | |
1378 | } | |
1379 | Handle(Geom2d_Line) l = new Geom2d_Line(gp_Pnt2d(x,y),gp_Dir2d(dx,dy)); | |
1380 | Handle(Geom2d_TrimmedCurve) ct = | |
1381 | new Geom2d_TrimmedCurve(l,0,length); | |
1382 | NbCurves++; | |
1383 | Sprintf(name,"%s_%d",a[1],NbCurves); | |
1384 | DrawTrSurf::Set(name,ct); | |
1385 | di.AppendElement(name); | |
1386 | x += length*dx; | |
1387 | y += length*dy; | |
7fd59977 | 1388 | } |
1389 | break; | |
1390 | ||
1391 | case circle : | |
1392 | { | |
73cd8a8a | 1393 | Standard_Boolean sense = Standard_True; |
1394 | if (radius < 0) { | |
1395 | radius = -radius; | |
1396 | sense = !sense; | |
1397 | dx = -dx; | |
1398 | dy = -dy; | |
1399 | } | |
1400 | gp_Ax2d ax(gp_Pnt2d(x-radius*dy,y+radius*dx),gp_Dir2d(dy,-dx)); | |
1401 | if (angle < 0) { | |
1402 | angle = -angle; | |
1403 | sense = !sense; | |
1404 | } | |
1405 | Handle(Geom2d_Circle) c = new Geom2d_Circle(ax,radius,sense); | |
1406 | Handle(Geom2d_TrimmedCurve) ct = | |
1407 | new Geom2d_TrimmedCurve(c,0,angle); | |
1408 | NbCurves++; | |
1409 | Sprintf(name,"%s_%d",a[1],NbCurves); | |
1410 | DrawTrSurf::Set(name,ct); | |
1411 | di.AppendElement(name); | |
1412 | gp_Pnt2d p; | |
1413 | gp_Vec2d v; | |
1414 | c->D1(angle,p,v); | |
1415 | x = p.X(); | |
1416 | y = p.Y(); | |
1417 | dx = v.X() / radius; | |
1418 | dy = v.Y() / radius; | |
7fd59977 | 1419 | } |
1420 | break; | |
1421 | ||
1422 | case none: | |
1423 | break; | |
1424 | } | |
1425 | ||
1426 | // update first | |
1427 | first = stayfirst; | |
1428 | stayfirst = Standard_False; | |
1429 | ||
1430 | // next segment.... | |
1431 | i++; | |
1432 | if ((i == n) && close) { | |
1433 | // the closing segment | |
1434 | dx = x0-x; | |
1435 | dy = y0-y; | |
1436 | length = Sqrt(dx*dx+dy*dy); | |
1437 | if (length > Precision::Confusion()) { | |
73cd8a8a | 1438 | move = line; |
1439 | dx = dx / length; | |
1440 | dy = dy / length; | |
1441 | goto again; | |
7fd59977 | 1442 | } |
1443 | } | |
1444 | } | |
1445 | const char* aName; | |
1446 | aName = "CurX"; | |
1447 | Draw::Set(aName, x); | |
1448 | aName = "CurY"; | |
1449 | Draw::Set(aName, y); | |
1450 | aName = "CurDX"; | |
1451 | Draw::Set(aName, dx); | |
1452 | aName = "CurDY"; | |
1453 | Draw::Set(aName, dy); | |
1454 | ||
1455 | return 0; | |
1456 | ||
73cd8a8a | 1457 | badargs: |
7fd59977 | 1458 | di << "profile : bad number of arguments"; |
1459 | return 1; | |
1460 | } | |
1461 | ||
1462 | ||
1463 | ||
1464 | //======================================================================= | |
1465 | //function : mkoffset | |
1466 | //purpose : | |
1467 | //======================================================================= | |
1468 | ||
1469 | Standard_Integer mkoffset(Draw_Interpretor& di, | |
73cd8a8a | 1470 | Standard_Integer n, const char** a) |
7fd59977 | 1471 | { |
1472 | if (n < 5) return 1; | |
1473 | char name[100]; | |
1474 | ||
1475 | BRepOffsetAPI_MakeOffset Paral; | |
1476 | TopoDS_Shape Base = DBRep::Get(a[2],TopAbs_FACE); | |
1477 | ||
ab87e6fc | 1478 | if ( Base.IsNull()) |
73cd8a8a | 1479 | { |
7fd59977 | 1480 | Base = DBRep::Get(a[2]); |
1481 | if (Base.IsNull()) return 1; | |
1482 | Paral.Init(GeomAbs_Arc); | |
1483 | TopExp_Explorer exp; | |
ab87e6fc | 1484 | for (exp.Init(Base,TopAbs_WIRE); exp.More(); exp.Next()) |
73cd8a8a | 1485 | { |
7fd59977 | 1486 | TopoDS_Wire aLocalShape = TopoDS::Wire(exp.Current()); |
1487 | Paral.AddWire(aLocalShape); | |
7fd59977 | 1488 | } |
73cd8a8a | 1489 | } |
ab87e6fc | 1490 | else |
73cd8a8a | 1491 | { |
7fd59977 | 1492 | Base.Orientation(TopAbs_FORWARD); |
7fd59977 | 1493 | Paral.Init(TopoDS::Face(Base)); |
73cd8a8a | 1494 | } |
7fd59977 | 1495 | |
1496 | Standard_Real U, dU; | |
1497 | Standard_Integer Nb; | |
91322f44 | 1498 | dU = Draw::Atof(a[4]); |
1499 | Nb = Draw::Atoi(a[3]); | |
7fd59977 | 1500 | |
1501 | Standard_Real Alt = 0.; | |
ab87e6fc | 1502 | if ( n == 6) |
1503 | Alt = Draw::Atof(a[5]); | |
1504 | ||
7fd59977 | 1505 | Standard_Integer Compt = 1; |
1506 | ||
ab87e6fc | 1507 | for ( Standard_Integer i = 1; i <= Nb; i++) |
73cd8a8a | 1508 | { |
7fd59977 | 1509 | U = i * dU; |
1510 | Paral.Perform(U,Alt); | |
ab87e6fc | 1511 | |
1512 | if ( !Paral.IsDone()) | |
73cd8a8a | 1513 | { |
ab87e6fc | 1514 | di << " Error: Offset is not done." << "\n"; |
1515 | return 1; | |
73cd8a8a | 1516 | } |
ab87e6fc | 1517 | else |
73cd8a8a | 1518 | { |
91322f44 | 1519 | Sprintf(name,"%s_%d", a[1], Compt++); |
7fd59977 | 1520 | char* temp = name; // portage WNT |
1521 | DBRep::Set(temp,Paral.Shape()); | |
1522 | } | |
73cd8a8a | 1523 | } |
ab87e6fc | 1524 | |
7fd59977 | 1525 | return 0; |
73cd8a8a | 1526 | } |
7fd59977 | 1527 | |
1528 | //======================================================================= | |
1529 | //function : pickface | |
1530 | //purpose : | |
1531 | //======================================================================= | |
1532 | ||
1533 | Standard_Integer pickface(Draw_Interpretor& di, | |
73cd8a8a | 1534 | Standard_Integer , const char** ) |
7fd59977 | 1535 | { |
1536 | Standard_CString pick_name="."; | |
73cd8a8a | 1537 | |
7fd59977 | 1538 | TopoDS_Shape S = DBRep::Get(pick_name,TopAbs_FACE); |
1539 | if (S.IsNull()) return 1; | |
73cd8a8a | 1540 | |
7fd59977 | 1541 | char* name = new char[100]; |
91322f44 | 1542 | Sprintf(name,"PickedFace %s",pick_name); |
7fd59977 | 1543 | DBRep::Set(name,S); |
1544 | di.AppendElement(name); | |
1545 | return 0; | |
1546 | } | |
1547 | ||
1548 | ||
1549 | Standard_Integer edgeintersector(Draw_Interpretor& di, | |
73cd8a8a | 1550 | Standard_Integer n, const char** a) |
7fd59977 | 1551 | { |
1552 | if (n < 5) return 1; | |
1553 | ||
1554 | TopoDS_Edge E[2]; | |
1555 | TopoDS_Shape aLocalShape(DBRep::Get(a[2],TopAbs_EDGE)); | |
1556 | E[0] = TopoDS::Edge(aLocalShape); | |
1557 | // E[0] = TopoDS::Edge(DBRep::Get(a[2],TopAbs_EDGE)); | |
1558 | if ( E[0].IsNull()) return 1; | |
1559 | aLocalShape = DBRep::Get(a[3],TopAbs_EDGE); | |
1560 | E[1] = TopoDS::Edge(aLocalShape); | |
1561 | // E[1] = TopoDS::Edge(DBRep::Get(a[3],TopAbs_EDGE)); | |
1562 | if ( E[1].IsNull()) return 1; | |
1563 | aLocalShape = DBRep::Get(a[4],TopAbs_FACE); | |
1564 | TopoDS_Face F = TopoDS::Face(aLocalShape); | |
1565 | // TopoDS_Face F = TopoDS::Face(DBRep::Get(a[4],TopAbs_FACE)); | |
1566 | if ( F.IsNull()) return 1; | |
73cd8a8a | 1567 | |
7fd59977 | 1568 | TopOpeBRep_EdgesIntersector EInter; |
1569 | char name[100]; | |
1570 | //------------------------------------------------------ | |
0d969553 | 1571 | // Calculate point of intersection 2D |
7fd59977 | 1572 | //----------------------------------------------------- |
1573 | EInter.SetFaces(F,F); | |
1574 | Standard_Real TolInter = 1.e-7; | |
91322f44 | 1575 | if (n == 6) TolInter = Draw::Atof(a[5]); |
7fd59977 | 1576 | EInter.ForceTolerances(TolInter,TolInter); |
1577 | Standard_Boolean reducesegments = Standard_True; | |
1578 | EInter.Perform (E[0],E[1],reducesegments); | |
73cd8a8a | 1579 | |
7fd59977 | 1580 | if (EInter.IsEmpty()) { |
0d969553 Y |
1581 | //cout << " No intersection found" << endl; |
1582 | di << " No intersection found" << "\n"; | |
7fd59977 | 1583 | return 0; |
1584 | } | |
1585 | ||
1586 | BRep_Builder B; | |
1587 | ||
1588 | Standard_Integer NbV = 0; | |
1589 | Standard_Real Tol = Precision::PConfusion(); | |
1590 | ||
1591 | Standard_Boolean rejectreducedsegmentpoints = Standard_True; | |
1592 | EInter.InitPoint(rejectreducedsegmentpoints); | |
1593 | for (;EInter.MorePoint();EInter.NextPoint()) { | |
1594 | const TopOpeBRep_Point2d& P2D = EInter.Point(); | |
1595 | gp_Pnt P = P2D.Value(); | |
1596 | TopoDS_Vertex V = BRepLib_MakeVertex(P); | |
1597 | NbV ++; | |
91322f44 | 1598 | Sprintf(name,"%s_%d",a[1],NbV); |
7fd59977 | 1599 | DBRep::Set(name,V); |
1600 | for (Standard_Integer i = 1; i <= 2; i++) { | |
1601 | //--------------------------------------------------------------- | |
0d969553 Y |
1602 | // to be able to rank parameter on edge |
1603 | // it is necessary to code it internally | |
7fd59977 | 1604 | //--------------------------------------------------------------- |
1605 | Standard_Real U = P2D.Parameter(i); | |
73cd8a8a | 1606 | |
7fd59977 | 1607 | V.Orientation(TopAbs_INTERNAL); |
1608 | B.UpdateVertex(V,U,E[i-1],Tol); | |
73cd8a8a | 1609 | // B.UpdateVertex(TopoDS::Vertex(V.Oriented(TopAbs_INTERNAL)), |
1610 | // U,E[i-1],Tol); | |
7fd59977 | 1611 | //--------------------------------------------------------------- |
0d969553 | 1612 | // Orientation of vertex in the transition. |
7fd59977 | 1613 | //--------------------------------------------------------------- |
1614 | TopAbs_Orientation OO = TopAbs_REVERSED; | |
1615 | if (P2D.IsVertex(i)) { | |
73cd8a8a | 1616 | OO = P2D.Vertex(i).Orientation(); |
7fd59977 | 1617 | } |
1618 | else if (P2D.Transition(i).Before() == TopAbs_OUT) { | |
73cd8a8a | 1619 | OO = TopAbs_FORWARD; |
7fd59977 | 1620 | } |
0d969553 Y |
1621 | //cout << " Orientation of vertex " << NbV << " on " << a[i+1] << ": "; |
1622 | di << " Orientation of vertex " << NbV << " on " << a[i+1] << ": "; | |
7fd59977 | 1623 | if (OO == TopAbs_FORWARD) { |
73cd8a8a | 1624 | //cout << "FORWARD" << endl; |
1625 | di << "FORWARD" << "\n"; | |
7fd59977 | 1626 | } else { |
73cd8a8a | 1627 | //cout << "REVERSED" << endl; |
1628 | di << "REVERSED" << "\n"; | |
7fd59977 | 1629 | } |
1630 | } | |
1631 | } | |
1632 | //POP pour NT | |
1633 | return 0; | |
1634 | ||
1635 | } | |
51a849d7 | 1636 | |
1637 | //======================================================================= | |
1638 | //function : concatC0wire | |
1639 | //purpose : | |
1640 | //======================================================================= | |
1641 | ||
1642 | Standard_Integer concatC0wire(Draw_Interpretor&, Standard_Integer n, const char** c) | |
1643 | { | |
1644 | if ( n < 3 ) return 1; | |
73cd8a8a | 1645 | |
51a849d7 | 1646 | TopoDS_Shape S = DBRep::Get(c[2],TopAbs_WIRE) ; |
1647 | ||
1648 | if (S.IsNull()) | |
1649 | return 1; //test if the shape is empty | |
73cd8a8a | 1650 | |
51a849d7 | 1651 | TopoDS_Wire W = TopoDS::Wire(S) ; |
1652 | TopoDS_Shape res; | |
1653 | ||
1654 | ||
1655 | res = BRepAlgo::ConcatenateWireC0(W); //treatment | |
1656 | DBRep::Set(c[1], res); | |
1657 | return 0; | |
1658 | } | |
1659 | ||
7fd59977 | 1660 | //======================================================================= |
1661 | //function : concatwire | |
1662 | //purpose : reduce the multiply degree of the knots to the minimum without | |
1663 | // changing the geometry | |
1664 | //======================================================================= | |
1665 | ||
1666 | static Standard_Integer concatwire(Draw_Interpretor&, Standard_Integer n, const char** c) | |
73cd8a8a | 1667 | { |
1668 | GeomAbs_Shape Option=GeomAbs_C1; | |
1669 | if ( n < 3 ) return 1; | |
7fd59977 | 1670 | |
7fd59977 | 1671 | if(n==4) //check if it's C1 or G1 |
73cd8a8a | 1672 | if (! strcmp(c[3],"G1")) |
1673 | Option=GeomAbs_G1; | |
1674 | ||
7fd59977 | 1675 | TopoDS_Shape S = DBRep::Get(c[2],TopAbs_WIRE) ; |
1676 | ||
1677 | if (S.IsNull()) return 1 ; //test if the shape is empty | |
1678 | ||
1679 | TopoDS_Wire W = TopoDS::Wire(S) ; | |
1680 | TopoDS_Wire res; | |
0d969553 | 1681 | res=BRepAlgo::ConcatenateWire(W,Option); //processing |
7fd59977 | 1682 | DBRep::Set(c[1],res); |
1683 | return 0; | |
1684 | } | |
1685 | ||
1686 | //======================================================================= | |
1687 | //function : build3d | |
1688 | //purpose : | |
1689 | //======================================================================= | |
1690 | ||
1691 | Standard_Integer build3d(Draw_Interpretor& di, | |
73cd8a8a | 1692 | Standard_Integer n, const char** a) |
7fd59977 | 1693 | { |
1694 | ||
1695 | if ( (n <2) || (n>3) ) { | |
0d969553 Y |
1696 | //cout << " 1 or 2 arguments expected" << endl; |
1697 | di << " 1 or 2 arguments expected" << "\n"; | |
7fd59977 | 1698 | return 1; |
1699 | } | |
73cd8a8a | 1700 | |
7fd59977 | 1701 | Standard_Boolean Ok; |
1702 | TopoDS_Shape S = DBRep::Get(a[1],TopAbs_FACE); | |
1703 | if (S.IsNull()) return 1; | |
73cd8a8a | 1704 | |
7fd59977 | 1705 | if (n==2) { Ok = BRepLib::BuildCurves3d(S); } |
91322f44 | 1706 | else { Ok = BRepLib::BuildCurves3d(S,Draw::Atof(a[2])); } |
7fd59977 | 1707 | //if (!Ok) {cout << " one of the computation failed" << endl;} |
1708 | if (!Ok) {di << " one of the computation failed" << "\n";} | |
1709 | ||
1710 | return 0; | |
1711 | } | |
1712 | ||
01697018 J |
1713 | //======================================================================= |
1714 | //function : reducepcurves | |
1715 | //purpose : remove pcurves that are unused in this shape | |
1716 | //======================================================================= | |
1717 | ||
1718 | Standard_Integer reducepcurves(Draw_Interpretor& di, | |
73cd8a8a | 1719 | Standard_Integer n, const char** a) |
01697018 J |
1720 | { |
1721 | if (n < 2) return 1; | |
1722 | ||
1723 | Standard_Integer i; | |
1724 | for (i = 1; i < n; i++) | |
1725 | { | |
1726 | TopoDS_Shape aShape = DBRep::Get(a[i]); | |
1727 | if (aShape.IsNull()) | |
1728 | //cout << a[i] << " is not a valid shape" << endl; | |
1729 | di << a[i] << " is not a valid shape" << "\n"; | |
1730 | else | |
1731 | BRepTools::RemoveUnusedPCurves(aShape); | |
1732 | } | |
73cd8a8a | 1733 | |
01697018 J |
1734 | return 0; |
1735 | } | |
7fd59977 | 1736 | |
1737 | //======================================================================= | |
1738 | //function : CurveCommands | |
1739 | //purpose : | |
1740 | //======================================================================= | |
1741 | ||
1742 | void BRepTest::CurveCommands(Draw_Interpretor& theCommands) | |
1743 | { | |
1744 | static Standard_Boolean done = Standard_False; | |
1745 | if (done) return; | |
1746 | done = Standard_True; | |
1747 | ||
1748 | DBRep::BasicCommands(theCommands); | |
1749 | GeometryTest::CurveCommands(theCommands); | |
1750 | ||
1751 | const char* g = "TOPOLOGY Curve topology commands"; | |
1752 | ||
1753 | theCommands.Add("vertex", | |
73cd8a8a | 1754 | "vertex name [x y z / p edge]",__FILE__, |
1755 | vertex,g); | |
7fd59977 | 1756 | |
1757 | theCommands.Add("etrim", | |
73cd8a8a | 1758 | "etrim edge v1 [v2]",__FILE__, |
1759 | trim,g); | |
7fd59977 | 1760 | |
1761 | theCommands.Add("range", | |
73cd8a8a | 1762 | "range edge [face] first last",__FILE__, |
1763 | range,g); | |
7fd59977 | 1764 | |
1765 | theCommands.Add("polyline", | |
73cd8a8a | 1766 | "polyline name x1 y1 z1 x2 y2 z2 ...",__FILE__, |
1767 | polyline,g); | |
7fd59977 | 1768 | |
1769 | theCommands.Add("polyvertex", | |
73cd8a8a | 1770 | "polyvertex name v1 v2 ...",__FILE__, |
1771 | polyvertex,g); | |
7fd59977 | 1772 | |
1773 | theCommands.Add("wire", | |
73cd8a8a | 1774 | "wire wirename e1/w1 [e2/w2 ...]",__FILE__, |
1775 | wire,g); | |
7fd59977 | 1776 | |
1777 | theCommands.Add("profile", | |
73cd8a8a | 1778 | "profile, no args to get help",__FILE__, |
1779 | profile,g); | |
7fd59977 | 1780 | |
1781 | theCommands.Add("bsplineprof", | |
73cd8a8a | 1782 | "bsplineprof, no args to get help",__FILE__, |
1783 | bsplineprof,g); | |
7fd59977 | 1784 | |
1785 | theCommands.Add("2dprofile", | |
73cd8a8a | 1786 | "2dprofile, no args to get help",__FILE__, |
1787 | profile2d,g); | |
7fd59977 | 1788 | |
1789 | theCommands.Add("mkoffset", | |
73cd8a8a | 1790 | "mkoffset result face/compound of wires nboffset stepoffset [alt]",__FILE__, |
1791 | mkoffset); | |
7fd59977 | 1792 | |
1793 | ||
1794 | theCommands.Add("mkedge", | |
73cd8a8a | 1795 | "mkedge edge curve [surface] [pfirst plast] [vfirst [pfirst] vlast [plast]] ",__FILE__, |
1796 | mkedge,g); | |
1797 | ||
7fd59977 | 1798 | theCommands.Add("mkcurve", |
73cd8a8a | 1799 | "mkcurve curve edge",__FILE__, |
1800 | mkcurve,g); | |
7fd59977 | 1801 | |
1802 | theCommands.Add("mkoricurve", | |
73cd8a8a | 1803 | "mkoricurve curve edge: \n the curve is colored according to the orientation of the edge", |
1804 | __FILE__, | |
1805 | mkcurve,g); | |
7fd59977 | 1806 | |
1807 | theCommands.Add("mk2dcurve", | |
73cd8a8a | 1808 | "mk2dcurve curve edge [face]",__FILE__, |
1809 | mk2dcurve,g); | |
7fd59977 | 1810 | |
1811 | theCommands.Add("mkpoint", | |
73cd8a8a | 1812 | "mkpoint point vertex",__FILE__, |
1813 | mkpoint,g); | |
7fd59977 | 1814 | |
1815 | theCommands.Add("uisoedge", | |
73cd8a8a | 1816 | "uisoedge edge face u v1 v2",__FILE__, |
1817 | isoedge,g); | |
1818 | ||
7fd59977 | 1819 | theCommands.Add("edge", |
73cd8a8a | 1820 | "edge edgename v1 v2",__FILE__, |
1821 | edge,g); | |
1822 | ||
7fd59977 | 1823 | theCommands.Add("visoedge", |
73cd8a8a | 1824 | "visoedge edge face v u1 u2",__FILE__, |
1825 | isoedge,g); | |
7fd59977 | 1826 | |
1827 | theCommands.Add("transfert", | |
73cd8a8a | 1828 | "transfert edge1 edge2",__FILE__, |
1829 | transfert,g); | |
7fd59977 | 1830 | |
1831 | theCommands.Add("pickface", | |
73cd8a8a | 1832 | "pickface",__FILE__, |
1833 | pickface,g); | |
7fd59977 | 1834 | |
1835 | theCommands.Add("edgeintersector", | |
73cd8a8a | 1836 | "edgeintersector r E1 E2 F [Tol]",__FILE__, |
1837 | edgeintersector,g); | |
7fd59977 | 1838 | |
1839 | theCommands.Add("build3d", | |
73cd8a8a | 1840 | "build3d S [tol]", |
1841 | build3d, g); | |
7fd59977 | 1842 | |
01697018 | 1843 | theCommands.Add("reducepcurves", |
73cd8a8a | 1844 | "reducepcurves shape1 shape2 ...", |
1845 | reducepcurves, g); | |
01697018 | 1846 | |
51a849d7 | 1847 | theCommands.Add("concatC0wire", |
73cd8a8a | 1848 | "concatC0wire result wire", |
1849 | __FILE__, | |
1850 | concatC0wire, | |
1851 | g); | |
51a849d7 | 1852 | |
7fd59977 | 1853 | theCommands.Add("concatwire", |
73cd8a8a | 1854 | "concatwire result wire [option](G1/C1)", |
1855 | __FILE__, | |
1856 | concatwire, | |
1857 | g); | |
7fd59977 | 1858 | } |
1859 | ||
1860 |