b311480e |
1 | // Created on: 1995-01-04 |
2 | // Created by: Bruno DUMORTIER |
3 | // Copyright (c) 1995-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 | |
7fd59977 |
17 | |
7fd59977 |
18 | #include <BRep_Builder.hxx> |
42cf5bc1 |
19 | #include <BRep_Tool.hxx> |
20 | #include <BRepLib.hxx> |
21 | #include <BRepLib_MakeEdge2d.hxx> |
22 | #include <ElCLib.hxx> |
23 | #include <ElSLib.hxx> |
24 | #include <Extrema_ExtPC2d.hxx> |
7fd59977 |
25 | #include <Geom2d_Circle.hxx> |
42cf5bc1 |
26 | #include <Geom2d_Curve.hxx> |
7fd59977 |
27 | #include <Geom2d_Ellipse.hxx> |
7fd59977 |
28 | #include <Geom2d_Hyperbola.hxx> |
42cf5bc1 |
29 | #include <Geom2d_Line.hxx> |
30 | #include <Geom2d_Parabola.hxx> |
7fd59977 |
31 | #include <Geom2d_TrimmedCurve.hxx> |
32 | #include <Geom2dAdaptor_Curve.hxx> |
42cf5bc1 |
33 | #include <Geom_Plane.hxx> |
7fd59977 |
34 | #include <gp.hxx> |
42cf5bc1 |
35 | #include <gp_Circ2d.hxx> |
36 | #include <gp_Elips2d.hxx> |
37 | #include <gp_Hypr2d.hxx> |
38 | #include <gp_Lin2d.hxx> |
39 | #include <gp_Parab2d.hxx> |
40 | #include <gp_Pnt2d.hxx> |
7fd59977 |
41 | #include <Precision.hxx> |
42cf5bc1 |
42 | #include <StdFail_NotDone.hxx> |
43 | #include <TopoDS.hxx> |
44 | #include <TopoDS_Edge.hxx> |
45 | #include <TopoDS_Vertex.hxx> |
7fd59977 |
46 | |
47 | //======================================================================= |
48 | //function : Point |
49 | //purpose : make a 3d point on the current plane |
50 | //======================================================================= |
7fd59977 |
51 | static gp_Pnt Point(const gp_Pnt2d& P) |
52 | { |
53 | return BRepLib::Plane()->Value(P.X(),P.Y()); |
54 | } |
55 | |
56 | //======================================================================= |
57 | //function : Project |
58 | //purpose : project a vertex on the current plane |
59 | //======================================================================= |
60 | |
61 | static gp_Pnt2d Project(const TopoDS_Vertex& Ve) |
62 | { |
63 | gp_Pnt P = BRep_Tool::Pnt(Ve); |
64 | Standard_Real U,V; |
65 | ElSLib::Parameters(BRepLib::Plane()->Pln(),P,U,V); |
66 | return gp_Pnt2d(U,V); |
67 | } |
68 | |
69 | //======================================================================= |
70 | //function : Project |
71 | //purpose : project a vertex on a curve |
72 | //======================================================================= |
73 | |
74 | static Standard_Boolean Project(const Handle(Geom2d_Curve)& C, |
75 | const TopoDS_Vertex& V, |
76 | Standard_Real& p) |
77 | { |
78 | gp_Pnt2d P = Project(V); |
79 | Geom2dAdaptor_Curve AC(C); |
80 | if (AC.GetType() == GeomAbs_Line) { |
81 | p = ElCLib::LineParameter(AC.Line().Position(),P); |
82 | } |
83 | else if (AC.GetType() == GeomAbs_Circle) { |
84 | p = ElCLib::CircleParameter(AC.Circle().Position(),P); |
85 | } |
86 | else { |
87 | Extrema_ExtPC2d extrema(P,AC); |
88 | if (extrema.IsDone()) { |
89 | Standard_Integer i,n = extrema.NbExt(); |
90 | |
91 | Standard_Real d2 = RealLast(); |
92 | for (i = 1; i <= n; i++) { |
93 | //OCC16852:if (extrema.IsMin(i)) { |
94 | const Standard_Real dd2 = extrema.SquareDistance(i); |
95 | if (dd2 < d2) { |
96 | d2 = dd2; |
97 | p = extrema.Point(i).Parameter(); |
98 | } |
99 | //OCC16852:} |
100 | } |
101 | } |
102 | else |
103 | return Standard_False; |
104 | } |
105 | return Standard_True; |
106 | } |
107 | |
108 | //======================================================================= |
109 | //function : BRepLib_MakeEdge2d |
110 | //purpose : |
111 | //======================================================================= |
112 | |
113 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const TopoDS_Vertex& V1, |
114 | const TopoDS_Vertex& V2) |
115 | { |
116 | gp_Pnt2d P1 = Project(V1); |
117 | gp_Pnt2d P2 = Project(V2); |
118 | Standard_Real l = P1.Distance(P2); |
119 | if (l <= gp::Resolution()) { |
120 | myError = BRepLib_LineThroughIdenticPoints; |
121 | return; |
122 | } |
123 | gp_Lin2d L(P1,gp_Vec2d(P1,P2)); |
124 | Handle(Geom2d_Line) GL = new Geom2d_Line(L); |
125 | Init(GL,V1,V2,0,l); |
126 | } |
127 | |
128 | //======================================================================= |
129 | //function : BRepLib_MakeEdge2d |
130 | //purpose : |
131 | //======================================================================= |
132 | |
133 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Pnt2d& P1, |
134 | const gp_Pnt2d& P2) |
135 | { |
136 | Standard_Real l = P1.Distance(P2); |
137 | if (l <= gp::Resolution()) { |
138 | myError = BRepLib_LineThroughIdenticPoints; |
139 | return; |
140 | } |
141 | gp_Lin2d L(P1,gp_Vec2d(P1,P2)); |
142 | Handle(Geom2d_Line) GL = new Geom2d_Line(L); |
143 | Init(GL,P1,P2,0,l); |
144 | } |
145 | |
146 | |
147 | //======================================================================= |
148 | //function : BRepLib_MakeEdge2d |
149 | //purpose : |
150 | //======================================================================= |
151 | |
152 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Lin2d& L) |
153 | { |
154 | Handle(Geom2d_Line) GL = new Geom2d_Line(L); |
155 | Init(GL); |
156 | } |
157 | |
158 | //======================================================================= |
159 | //function : BRepLib_MakeEdge2d |
160 | //purpose : |
161 | //======================================================================= |
162 | |
163 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Lin2d& L, |
164 | const Standard_Real p1, |
165 | const Standard_Real p2) |
166 | { |
167 | Handle(Geom2d_Line) GL = new Geom2d_Line(L); |
168 | Init(GL,p1,p2); |
169 | } |
170 | |
171 | //======================================================================= |
172 | //function : BRepLib_MakeEdge2d |
173 | //purpose : |
174 | //======================================================================= |
175 | |
176 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Lin2d& L, |
177 | const gp_Pnt2d& P1, |
178 | const gp_Pnt2d& P2) |
179 | { |
180 | Handle(Geom2d_Line) GL = new Geom2d_Line(L); |
181 | Init(GL,P1,P2); |
182 | } |
183 | |
184 | //======================================================================= |
185 | //function : BRepLib_MakeEdge2d |
186 | //purpose : |
187 | //======================================================================= |
188 | |
189 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Lin2d& L, |
190 | const TopoDS_Vertex& V1, |
191 | const TopoDS_Vertex& V2) |
192 | { |
193 | Handle(Geom2d_Line) GL = new Geom2d_Line(L); |
194 | Init(GL,V1,V2); |
195 | } |
196 | |
197 | //======================================================================= |
198 | //function : BRepLib_MakeEdge2d |
199 | //purpose : |
200 | //======================================================================= |
201 | |
202 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Circ2d& C) |
203 | { |
204 | Handle(Geom2d_Circle) GC = new Geom2d_Circle(C); |
205 | Init(GC); |
206 | } |
207 | |
208 | //======================================================================= |
209 | //function : BRepLib_MakeEdge2d |
210 | //purpose : |
211 | //======================================================================= |
212 | |
213 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Circ2d& C, |
214 | const Standard_Real p1, |
215 | const Standard_Real p2) |
216 | { |
217 | Handle(Geom2d_Circle) GC = new Geom2d_Circle(C); |
218 | Init(GC,p1,p2); |
219 | } |
220 | |
221 | //======================================================================= |
222 | //function : BRepLib_MakeEdge2d |
223 | //purpose : |
224 | //======================================================================= |
225 | |
226 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Circ2d& C, |
227 | const gp_Pnt2d& P1, |
228 | const gp_Pnt2d& P2) |
229 | { |
230 | Handle(Geom2d_Circle) GC = new Geom2d_Circle(C); |
231 | Init(GC,P1,P2); |
232 | } |
233 | |
234 | //======================================================================= |
235 | //function : BRepLib_MakeEdge2d |
236 | //purpose : |
237 | //======================================================================= |
238 | |
239 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Circ2d& C, |
240 | const TopoDS_Vertex& V1, |
241 | const TopoDS_Vertex& V2) |
242 | { |
243 | Handle(Geom2d_Circle) GC = new Geom2d_Circle(C); |
244 | Init(GC,V1,V2); |
245 | } |
246 | |
247 | //======================================================================= |
248 | //function : BRepLib_MakeEdge2d |
249 | //purpose : |
250 | //======================================================================= |
251 | |
252 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Elips2d& E) |
253 | { |
254 | Handle(Geom2d_Ellipse) GE = new Geom2d_Ellipse(E); |
255 | Init(GE); |
256 | } |
257 | |
258 | //======================================================================= |
259 | //function : BRepLib_MakeEdge2d |
260 | //purpose : |
261 | //======================================================================= |
262 | |
263 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Elips2d& E, |
264 | const Standard_Real p1, |
265 | const Standard_Real p2) |
266 | { |
267 | Handle(Geom2d_Ellipse) GE = new Geom2d_Ellipse(E); |
268 | Init(GE,p1,p2); |
269 | } |
270 | |
271 | //======================================================================= |
272 | //function : BRepLib_MakeEdge2d |
273 | //purpose : |
274 | //======================================================================= |
275 | |
276 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Elips2d& E, |
277 | const gp_Pnt2d& P1, |
278 | const gp_Pnt2d& P2) |
279 | { |
280 | Handle(Geom2d_Ellipse) GE = new Geom2d_Ellipse(E); |
281 | Init(GE,P1,P2); |
282 | } |
283 | |
284 | //======================================================================= |
285 | //function : BRepLib_MakeEdge2d |
286 | //purpose : |
287 | //======================================================================= |
288 | |
289 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Elips2d& E, |
290 | const TopoDS_Vertex& V1, |
291 | const TopoDS_Vertex& V2) |
292 | { |
293 | Handle(Geom2d_Ellipse) GE = new Geom2d_Ellipse(E); |
294 | Init(GE,V1,V2); |
295 | } |
296 | |
297 | //======================================================================= |
298 | //function : BRepLib_MakeEdge2d |
299 | //purpose : |
300 | //======================================================================= |
301 | |
302 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Hypr2d& H) |
303 | { |
304 | Handle(Geom2d_Hyperbola) GH = new Geom2d_Hyperbola(H); |
305 | Init(GH); |
306 | } |
307 | |
308 | //======================================================================= |
309 | //function : BRepLib_MakeEdge2d |
310 | //purpose : |
311 | //======================================================================= |
312 | |
313 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Hypr2d& H, |
314 | const Standard_Real p1, |
315 | const Standard_Real p2) |
316 | { |
317 | Handle(Geom2d_Hyperbola) GH = new Geom2d_Hyperbola(H); |
318 | Init(GH,p1,p2); |
319 | } |
320 | |
321 | //======================================================================= |
322 | //function : BRepLib_MakeEdge2d |
323 | //purpose : |
324 | //======================================================================= |
325 | |
326 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Hypr2d& H, |
327 | const gp_Pnt2d& P1, |
328 | const gp_Pnt2d& P2) |
329 | { |
330 | Handle(Geom2d_Hyperbola) GH = new Geom2d_Hyperbola(H); |
331 | Init(GH,P1,P2); |
332 | } |
333 | |
334 | //======================================================================= |
335 | //function : BRepLib_MakeEdge2d |
336 | //purpose : |
337 | //======================================================================= |
338 | |
339 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Hypr2d& H, |
340 | const TopoDS_Vertex& V1, |
341 | const TopoDS_Vertex& V2) |
342 | { |
343 | Handle(Geom2d_Hyperbola) GH = new Geom2d_Hyperbola(H); |
344 | Init(GH,V1,V2); |
345 | } |
346 | |
347 | //======================================================================= |
348 | //function : BRepLib_MakeEdge2d |
349 | //purpose : |
350 | //======================================================================= |
351 | |
352 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Parab2d& P) |
353 | { |
354 | Handle(Geom2d_Parabola) GP = new Geom2d_Parabola(P); |
355 | Init(GP); |
356 | } |
357 | |
358 | //======================================================================= |
359 | //function : BRepLib_MakeEdge2d |
360 | //purpose : |
361 | //======================================================================= |
362 | |
363 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Parab2d& P, |
364 | const Standard_Real p1, |
365 | const Standard_Real p2) |
366 | { |
367 | Handle(Geom2d_Parabola) GP = new Geom2d_Parabola(P); |
368 | Init(GP,p1,p2); |
369 | } |
370 | |
371 | //======================================================================= |
372 | //function : BRepLib_MakeEdge2d |
373 | //purpose : |
374 | //======================================================================= |
375 | |
376 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Parab2d& P, |
377 | const gp_Pnt2d& P1, |
378 | const gp_Pnt2d& P2) |
379 | { |
380 | Handle(Geom2d_Parabola) GP = new Geom2d_Parabola(P); |
381 | Init(GP,P1,P2); |
382 | } |
383 | |
384 | //======================================================================= |
385 | //function : BRepLib_MakeEdge2d |
386 | //purpose : |
387 | //======================================================================= |
388 | |
389 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const gp_Parab2d& P, |
390 | const TopoDS_Vertex& V1, |
391 | const TopoDS_Vertex& V2) |
392 | { |
393 | Handle(Geom2d_Parabola) GP = new Geom2d_Parabola(P); |
394 | Init(GP,V1,V2); |
395 | } |
396 | |
397 | //======================================================================= |
398 | //function : BRepLib_MakeEdge2d |
399 | //purpose : |
400 | //======================================================================= |
401 | |
402 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const Handle(Geom2d_Curve)& L) |
403 | { |
404 | Init(L); |
405 | } |
406 | |
407 | //======================================================================= |
408 | //function : BRepLib_MakeEdge2d |
409 | //purpose : |
410 | //======================================================================= |
411 | |
412 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const Handle(Geom2d_Curve)& L, |
413 | const Standard_Real p1, |
414 | const Standard_Real p2) |
415 | { |
416 | Init(L,p1,p2); |
417 | } |
418 | |
419 | //======================================================================= |
420 | //function : BRepLib_MakeEdge2d |
421 | //purpose : |
422 | //======================================================================= |
423 | |
424 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const Handle(Geom2d_Curve)& L, |
425 | const gp_Pnt2d& P1, |
426 | const gp_Pnt2d& P2) |
427 | { |
428 | Init(L,P1,P2); |
429 | } |
430 | |
431 | //======================================================================= |
432 | //function : BRepLib_MakeEdge2d |
433 | //purpose : |
434 | //======================================================================= |
435 | |
436 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const Handle(Geom2d_Curve)& L, |
437 | const TopoDS_Vertex& V1, |
438 | const TopoDS_Vertex& V2) |
439 | { |
440 | Init(L,V1,V2); |
441 | } |
442 | |
443 | //======================================================================= |
444 | //function : BRepLib_MakeEdge2d |
445 | //purpose : |
446 | //======================================================================= |
447 | |
448 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const Handle(Geom2d_Curve)& L, |
449 | const gp_Pnt2d& P1, |
450 | const gp_Pnt2d& P2, |
451 | const Standard_Real p1, |
452 | const Standard_Real p2) |
453 | { |
454 | Init(L,P1,P2,p1,p2); |
455 | } |
456 | |
457 | //======================================================================= |
458 | //function : BRepLib_MakeEdge2d |
459 | //purpose : |
460 | //======================================================================= |
461 | |
462 | BRepLib_MakeEdge2d::BRepLib_MakeEdge2d(const Handle(Geom2d_Curve)& L, |
463 | const TopoDS_Vertex& V1, |
464 | const TopoDS_Vertex& V2, |
465 | const Standard_Real p1, |
466 | const Standard_Real p2) |
467 | { |
468 | Init(L,V1,V2,p1,p2); |
469 | } |
470 | |
471 | //======================================================================= |
472 | //function : Init |
473 | //purpose : |
474 | //======================================================================= |
475 | |
476 | void BRepLib_MakeEdge2d::Init(const Handle(Geom2d_Curve)& C) |
477 | { |
478 | Init(C,C->FirstParameter(),C->LastParameter()); |
479 | } |
480 | |
481 | //======================================================================= |
482 | //function : Init |
483 | //purpose : |
484 | //======================================================================= |
485 | |
486 | void BRepLib_MakeEdge2d::Init(const Handle(Geom2d_Curve)& C, |
487 | const Standard_Real p1, |
488 | const Standard_Real p2) |
489 | { |
490 | // BRep_Builder B; |
491 | |
492 | TopoDS_Vertex V1,V2; |
493 | Init(C,V1,V2,p1,p2); |
494 | } |
495 | |
496 | //======================================================================= |
497 | //function : Init |
498 | //purpose : |
499 | //======================================================================= |
500 | |
501 | void BRepLib_MakeEdge2d::Init(const Handle(Geom2d_Curve)& C, |
502 | const gp_Pnt2d& P1, |
503 | const gp_Pnt2d& P2) |
504 | { |
505 | BRep_Builder B; |
506 | TopoDS_Vertex V1,V2; |
507 | B.MakeVertex(V1,Point(P1),Precision::Confusion()); |
508 | if (P1.Distance(P2) < Precision::Confusion()) |
509 | V2 = V1; |
510 | else |
511 | B.MakeVertex(V2,Point(P2),Precision::Confusion()); |
512 | Init(C,V1,V2); |
513 | } |
514 | |
515 | //======================================================================= |
516 | //function : Init |
517 | //purpose : |
518 | //======================================================================= |
519 | |
520 | void BRepLib_MakeEdge2d::Init(const Handle(Geom2d_Curve)& C, |
521 | const TopoDS_Vertex& V1, |
522 | const TopoDS_Vertex& V2) |
523 | { |
524 | // try projecting the vertices on the curve |
525 | |
526 | Standard_Real p1,p2; |
527 | |
528 | if (V1.IsNull()) |
529 | p1 = C->FirstParameter(); |
530 | else |
531 | if (!Project(C,V1,p1)) { |
532 | myError = BRepLib_PointProjectionFailed; |
533 | return; |
534 | } |
535 | if (V2.IsNull()) |
536 | p2 = C->LastParameter(); |
537 | else |
538 | if (!Project(C,V2,p2)) { |
539 | myError = BRepLib_PointProjectionFailed; |
540 | return; |
541 | } |
542 | |
543 | Init(C,V1,V2,p1,p2); |
544 | } |
545 | |
546 | |
547 | //======================================================================= |
548 | //function : Init |
549 | //purpose : |
550 | //======================================================================= |
551 | |
552 | void BRepLib_MakeEdge2d::Init(const Handle(Geom2d_Curve)& C, |
553 | const gp_Pnt2d& P1, |
554 | const gp_Pnt2d& P2, |
555 | const Standard_Real p1, |
556 | const Standard_Real p2) |
557 | { |
558 | BRep_Builder B; |
559 | |
560 | TopoDS_Vertex V1,V2; |
561 | B.MakeVertex(V1,Point(P1),Precision::Confusion()); |
562 | if (P1.Distance(P2) < Precision::Confusion()) |
563 | V2 = V1; |
564 | else |
565 | B.MakeVertex(V2,Point(P2),Precision::Confusion()); |
566 | |
567 | |
568 | Init(C,V1,V2,p1,p2); |
569 | } |
570 | |
571 | |
572 | //======================================================================= |
573 | //function : Init |
574 | //purpose : this one really makes the job ... |
575 | //======================================================================= |
576 | |
577 | void BRepLib_MakeEdge2d::Init(const Handle(Geom2d_Curve)& CC, |
578 | const TopoDS_Vertex& VV1, |
579 | const TopoDS_Vertex& VV2, |
580 | const Standard_Real pp1, |
581 | const Standard_Real pp2) |
582 | { |
583 | // kill trimmed curves |
584 | Handle(Geom2d_Curve) C = CC; |
585 | Handle(Geom2d_TrimmedCurve) CT = Handle(Geom2d_TrimmedCurve)::DownCast(C); |
586 | while (!CT.IsNull()) { |
587 | C = CT->BasisCurve(); |
588 | CT = Handle(Geom2d_TrimmedCurve)::DownCast(C); |
589 | } |
590 | |
591 | // check parameters |
592 | Standard_Real p1 = pp1; |
593 | Standard_Real p2 = pp2; |
594 | Standard_Real cf = C->FirstParameter(); |
595 | Standard_Real cl = C->LastParameter(); |
596 | Standard_Real epsilon = Precision::Confusion(); |
597 | Standard_Boolean periodic = C->IsPeriodic(); |
598 | |
599 | |
600 | TopoDS_Vertex V1,V2; |
601 | if (periodic) { |
602 | // adjust in period |
603 | ElCLib::AdjustPeriodic(cf,cl,epsilon,p1,p2); |
604 | V1 = VV1; |
605 | V2 = VV2; |
606 | } |
607 | else { |
608 | // reordonate |
609 | if (p1 < p2) { |
610 | V1 = VV1; |
611 | V2 = VV2; |
612 | } |
613 | else { |
614 | V2 = VV1; |
615 | V1 = VV2; |
616 | Standard_Real x = p1; |
617 | p1 = p2; |
618 | p2 = x; |
619 | } |
620 | |
621 | // check range |
622 | if ((cf - p1 > epsilon) || (p2 - cl > epsilon)) { |
623 | myError = BRepLib_ParameterOutOfRange; |
624 | return; |
625 | } |
626 | } |
627 | |
628 | // compute points on the curve |
629 | Standard_Boolean p1inf = Precision::IsNegativeInfinite(p1); |
630 | Standard_Boolean p2inf = Precision::IsPositiveInfinite(p2); |
631 | gp_Pnt2d P1,P2; |
632 | if (!p1inf) P1 = C->Value(p1); |
633 | if (!p2inf) P2 = C->Value(p2); |
634 | |
635 | Standard_Real preci = Precision::Confusion(); |
636 | BRep_Builder B; |
637 | |
638 | // check for closed curve |
639 | Standard_Boolean closed = Standard_False; |
640 | if (!p1inf && !p2inf) |
641 | closed = (P1.Distance(P2) <= preci); |
642 | |
643 | // check if the vertices are on the curve |
644 | if (closed) { |
645 | if (V1.IsNull() && V2.IsNull()) { |
646 | B.MakeVertex(V1,Point(P1),preci); |
647 | V2 = V1; |
648 | } |
649 | else if (V1.IsNull()) |
650 | V1 = V2; |
651 | else if (V2.IsNull()) |
652 | V2 = V1; |
653 | else { |
654 | if (!V1.IsSame(V2)) { |
655 | myError = BRepLib_DifferentPointsOnClosedCurve; |
656 | return; |
657 | } |
658 | else if (Point(P1).Distance(BRep_Tool::Pnt(V1)) > preci) { |
659 | myError = BRepLib_DifferentPointsOnClosedCurve; |
660 | return; |
661 | } |
662 | } |
663 | } |
664 | |
665 | else { // not closed |
666 | |
667 | if (p1inf) { |
668 | if (!V1.IsNull()) { |
669 | myError = BRepLib_PointWithInfiniteParameter; |
670 | return; |
671 | } |
672 | } |
673 | else { |
674 | gp_Pnt P = Point(P1); |
675 | if (V1.IsNull()) { |
676 | B.MakeVertex(V1,P,preci); |
677 | } |
678 | #if 0 |
679 | // desctivate control (RLE) for speed in sketcher |
680 | else if (P.Distance(BRep_Tool::Pnt(V1)) > preci) { |
681 | myError = BRepLib_DifferentsPointAndParameter; |
682 | return; |
683 | } |
684 | #endif |
685 | } |
686 | |
687 | if (p2inf) { |
688 | if (!V2.IsNull()) { |
689 | myError = BRepLib_PointWithInfiniteParameter; |
690 | return; |
691 | } |
692 | } |
693 | else { |
694 | gp_Pnt P = Point(P2); |
695 | if (V2.IsNull()) { |
696 | B.MakeVertex(V2,P,preci); |
697 | } |
698 | #if 0 |
699 | // desctivate control (RLE) for speed in sketcher |
700 | else if (P.Distance(BRep_Tool::Pnt(V2)) > preci){ |
701 | myError = BRepLib_DifferentsPointAndParameter; |
702 | return; |
703 | } |
704 | #endif |
705 | } |
706 | } |
707 | |
708 | V1.Orientation(TopAbs_FORWARD); |
709 | V2.Orientation(TopAbs_REVERSED); |
710 | myVertex1 = V1; |
711 | myVertex2 = V2; |
712 | |
713 | TopoDS_Edge& E = TopoDS::Edge(myShape); |
714 | B.MakeEdge(E); |
715 | B.UpdateEdge(E,C,BRepLib::Plane(),TopLoc_Location(),preci); |
716 | if (!V1.IsNull()) { |
717 | B.Add(E,V1); |
718 | } |
719 | if (!V2.IsNull()) { |
720 | B.Add(E,V2); |
721 | } |
722 | B.Range(E,p1,p2); |
723 | Done(); |
724 | } |
725 | |
726 | //======================================================================= |
727 | //function : Error |
728 | //purpose : |
729 | //======================================================================= |
730 | |
731 | BRepLib_EdgeError BRepLib_MakeEdge2d::Error() const |
732 | { |
733 | return myError; |
734 | } |
735 | |
736 | //======================================================================= |
737 | //function : Edge |
738 | //purpose : |
739 | //======================================================================= |
740 | |
ecac41a9 |
741 | const TopoDS_Edge& BRepLib_MakeEdge2d::Edge() |
7fd59977 |
742 | { |
743 | return TopoDS::Edge(Shape()); |
744 | } |
745 | |
746 | |
747 | //======================================================================= |
748 | //function : Vertex1 |
749 | //purpose : |
750 | //======================================================================= |
751 | |
752 | const TopoDS_Vertex& BRepLib_MakeEdge2d::Vertex1()const |
753 | { |
754 | Check(); |
755 | return myVertex1; |
756 | } |
757 | |
758 | |
759 | //======================================================================= |
760 | //function : Vertex2 |
761 | //purpose : |
762 | //======================================================================= |
763 | |
764 | const TopoDS_Vertex& BRepLib_MakeEdge2d::Vertex2()const |
765 | { |
766 | Check(); |
767 | return myVertex2; |
768 | } |
769 | |
770 | |
771 | |
772 | //======================================================================= |
773 | //function : operator |
774 | //purpose : |
775 | //======================================================================= |
776 | |
ecac41a9 |
777 | BRepLib_MakeEdge2d::operator TopoDS_Edge() |
7fd59977 |
778 | { |
779 | return Edge(); |
780 | } |