Integration of OCCT 6.5.0 from SVN
[occt.git] / src / DrawTrSurf / DrawTrSurf_BezierCurve2d.cxx
CommitLineData
7fd59977 1#include <DrawTrSurf_BezierCurve2d.ixx>
2
3#include <Geom2d_BezierCurve.hxx>
4#include <gp_Pnt.hxx>
5#include <TColgp_Array1OfPnt2d.hxx>
6#include <TColStd_Array1OfReal.hxx>
7
8
9 DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d (
10 const Handle(Geom2d_BezierCurve)& C) :
11 DrawTrSurf_Curve2d (C, Draw_vert, 50) {
12
13 drawPoles = Standard_True;
14 polesLook = Draw_rouge;
15 }
16
17
18 DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d (
19 const Handle(Geom2d_BezierCurve)& C, const Draw_Color& CurvColor,
20 const Draw_Color& PolesColor, const Standard_Boolean ShowPoles,
21 const Standard_Integer Discret) : DrawTrSurf_Curve2d (C, CurvColor, Discret) {
22
23 drawPoles = ShowPoles;
24 polesLook = PolesColor;
25 }
26
27
28void DrawTrSurf_BezierCurve2d::DrawOn (Draw_Display& dis) const
29{
30
31 Handle(Geom2d_BezierCurve) C = Handle(Geom2d_BezierCurve)::DownCast(curv);
32
33 if (drawPoles) {
34 dis.SetColor(polesLook);
35 TColgp_Array1OfPnt2d CPoles (1, C->NbPoles());
36 C->Poles (CPoles);
37 dis.MoveTo(CPoles(1));
38 for (Standard_Integer i = 2; i <= C->NbPoles(); i++) {
39 dis.DrawTo(CPoles(i));
40 }
41 }
42
43 DrawTrSurf_Curve2d::DrawOn(dis);
44
45}
46
47
48
49void DrawTrSurf_BezierCurve2d::ShowPoles ()
50{
51 drawPoles = Standard_True;
52}
53
54
55void DrawTrSurf_BezierCurve2d::ClearPoles ()
56{
57 drawPoles = Standard_False;
58}
59
60
61void DrawTrSurf_BezierCurve2d::FindPole (
62 const Standard_Real X,
63 const Standard_Real Y,
64 const Draw_Display& D,
65 const Standard_Real XPrec,
66 Standard_Integer& Index) const
67{
68
69 Handle(Geom2d_BezierCurve) bz = Handle(Geom2d_BezierCurve)::DownCast(curv);
70 gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
71 Standard_Real Prec = XPrec / D.Zoom();
72 Index++;
73 Standard_Integer NbPoles = bz->NbPoles();
74 gp_Pnt P;
75 gp_Pnt2d P2d;
76 while (Index <= NbPoles) {
77 P2d = bz->Pole(Index);
78 P.SetCoord (P2d.X(), P2d.Y(), 0.0);
79 if (D.Project(P).Distance(p1) <= Prec)
80 return;
81 Index++;
82 }
83 Index = 0;
84}
85
86//=======================================================================
87//function : Copy
88//purpose :
89//=======================================================================
90
91Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve2d::Copy()const
92{
93 Handle(DrawTrSurf_BezierCurve2d) DC = new DrawTrSurf_BezierCurve2d
94 (Handle(Geom2d_BezierCurve)::DownCast(curv->Copy()),
95 look,polesLook,
96 drawPoles,
97 GetDiscretisation());
98
99 return DC;
100}