Integration of OCCT 6.5.0 from SVN
[occt.git] / src / DrawTrSurf / DrawTrSurf_BSplineCurve2d.cxx
CommitLineData
7fd59977 1#include <DrawTrSurf_BSplineCurve2d.ixx>
2#include <Draw_MarkerShape.hxx>
3#include <Geom2d_BSplineCurve.hxx>
4#include <gp_Pnt.hxx>
5#include <TColgp_Array1OfPnt2d.hxx>
6#include <TColStd_Array1OfReal.hxx>
7
8
9 DrawTrSurf_BSplineCurve2d::DrawTrSurf_BSplineCurve2d (
10 const Handle(Geom2d_BSplineCurve)& C)
11 : DrawTrSurf_Curve2d (C, Draw_vert, 100) {
12
13 drawKnots = Standard_True;
14 knotsForm = Draw_Losange;
15 knotsLook = Draw_violet;
16 knotsDim = 5;
17 drawPoles = Standard_True;
18 polesLook = Draw_rouge;
19 }
20
21
22
23 DrawTrSurf_BSplineCurve2d::DrawTrSurf_BSplineCurve2d (
24 const Handle(Geom2d_BSplineCurve)& C, const Draw_Color& CurvColor,
25 const Draw_Color& PolesColor, const Draw_Color& KnotsColor,
26 const Draw_MarkerShape KnotsShape, const Standard_Integer KnotsSize,
27 const Standard_Boolean ShowPoles, const Standard_Boolean ShowKnots, const Standard_Integer Discret)
28 : DrawTrSurf_Curve2d (C, CurvColor, Discret) {
29
30 drawKnots = ShowKnots;
31 knotsForm = KnotsShape;
32 knotsLook = KnotsColor;
33 knotsDim = KnotsSize;
34 drawPoles = ShowPoles;
35 polesLook = PolesColor;
36 }
37
38
39
40void DrawTrSurf_BSplineCurve2d::DrawOn (Draw_Display& dis) const
41{
42
43 Handle(Geom2d_BSplineCurve) C = Handle(Geom2d_BSplineCurve)::DownCast(curv);
44
45 if (drawPoles) {
46 Standard_Integer NbPoles = C->NbPoles();
47 dis.SetColor(polesLook);
48 TColgp_Array1OfPnt2d CPoles (1, NbPoles);
49 C->Poles (CPoles);
50 dis.MoveTo(CPoles(1));
51 for (Standard_Integer i = 2; i <= NbPoles; i++) {
52 dis.DrawTo(CPoles(i));
53 }
54 if (C->IsPeriodic())
55 dis.DrawTo(CPoles(1));
56 }
57
58 DrawTrSurf_Curve2d::DrawOn(dis);
59
60 if (drawKnots) {
61 Standard_Integer NbKnots = C->NbKnots();
62 TColStd_Array1OfReal CKnots (1, NbKnots);
63 C->Knots (CKnots);
64 dis.SetColor(knotsLook);
65 for (Standard_Integer i = 1; i <= NbKnots; i++) {
66 gp_Pnt2d P = C->Value(CKnots(i));
67 dis.DrawMarker (P, knotsForm, knotsDim);
68 }
69 }
70}
71
72
73 void DrawTrSurf_BSplineCurve2d::ShowPoles () { drawPoles = Standard_True; }
74
75
76 void DrawTrSurf_BSplineCurve2d::ShowKnots () { drawKnots = Standard_True; }
77
78
79 void DrawTrSurf_BSplineCurve2d::ClearPoles () { drawPoles = Standard_False; }
80
81
82 void DrawTrSurf_BSplineCurve2d::ClearKnots () { drawKnots = Standard_False; }
83
84
85 void DrawTrSurf_BSplineCurve2d::FindPole (
86 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real XPrec,
87 Standard_Integer& Index) const {
88
89 Handle(Geom2d_BSplineCurve) bc = Handle(Geom2d_BSplineCurve)::DownCast(curv);
90 Standard_Real Prec = XPrec / D.Zoom();
91 gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
92 Index++;
93 Standard_Integer NbPoles = bc->NbPoles();
94 gp_Pnt P;
95 gp_Pnt2d P2d;
96 while (Index <= NbPoles) {
97 P2d = bc->Pole(Index);
98 P.SetCoord (P2d.X(), P2d.Y(), 0.0);
99 if (D.Project(P).Distance(p1) <= Prec)
100 return;
101 Index++;
102 }
103 Index = 0;
104 }
105
106
107 void DrawTrSurf_BSplineCurve2d::FindKnot (
108 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real Prec,
109 Standard_Integer& Index) const {
110
111 Handle(Geom2d_BSplineCurve) bc = Handle(Geom2d_BSplineCurve)::DownCast(curv);
112 gp_Pnt2d P2d;
113 gp_Pnt P;
114 gp_Pnt2d p1(X,Y);
115 Index++;
116 Standard_Integer NbKnots = bc->NbKnots();
117 while (Index <= NbKnots) {
118 P2d = bc->Value(bc->Knot(Index));
119 P.SetCoord (P2d.X(), P2d.Y(), 0.0);
120 if (D.Project(P).Distance(p1) <= Prec)
121 return;
122 Index++;
123 }
124 Index = 0;
125 }
126
127//=======================================================================
128//function : Copy
129//purpose :
130//=======================================================================
131
132Handle(Draw_Drawable3D) DrawTrSurf_BSplineCurve2d::Copy()const
133{
134 Handle(DrawTrSurf_BSplineCurve2d) DC = new DrawTrSurf_BSplineCurve2d
135 (Handle(Geom2d_BSplineCurve)::DownCast(curv->Copy()),
136 look,polesLook,knotsLook,knotsForm,knotsDim,
137 drawPoles,drawKnots,
138 GetDiscretisation());
139
140 return DC;
141}
142