b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
2 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
3 | // |
4 | // The content of this file is subject to the Open CASCADE Technology Public |
5 | // License Version 6.5 (the "License"). You may not use the content of this file |
6 | // except in compliance with the License. Please obtain a copy of the License |
7 | // at http://www.opencascade.org and read it completely before using this file. |
8 | // |
9 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
10 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
11 | // |
12 | // The Original Code and all software distributed under the License is |
13 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
14 | // Initial Developer hereby disclaims all such warranties, including without |
15 | // limitation, any warranties of merchantability, fitness for a particular |
16 | // purpose or non-infringement. Please see the License for the specific terms |
17 | // and conditions governing the rights and limitations under the License. |
18 | |
7fd59977 |
19 | #include <DrawTrSurf_BezierCurve2d.ixx> |
20 | |
21 | #include <Geom2d_BezierCurve.hxx> |
22 | #include <gp_Pnt.hxx> |
23 | #include <TColgp_Array1OfPnt2d.hxx> |
24 | #include <TColStd_Array1OfReal.hxx> |
25 | |
26 | |
b311480e |
27 | DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d ( |
7fd59977 |
28 | const Handle(Geom2d_BezierCurve)& C) : |
29 | DrawTrSurf_Curve2d (C, Draw_vert, 50) { |
30 | |
31 | drawPoles = Standard_True; |
32 | polesLook = Draw_rouge; |
33 | } |
34 | |
35 | |
36 | DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d ( |
37 | const Handle(Geom2d_BezierCurve)& C, const Draw_Color& CurvColor, |
38 | const Draw_Color& PolesColor, const Standard_Boolean ShowPoles, |
39 | const Standard_Integer Discret) : DrawTrSurf_Curve2d (C, CurvColor, Discret) { |
40 | |
41 | drawPoles = ShowPoles; |
42 | polesLook = PolesColor; |
43 | } |
44 | |
45 | |
46 | void DrawTrSurf_BezierCurve2d::DrawOn (Draw_Display& dis) const |
47 | { |
48 | |
49 | Handle(Geom2d_BezierCurve) C = Handle(Geom2d_BezierCurve)::DownCast(curv); |
50 | |
51 | if (drawPoles) { |
52 | dis.SetColor(polesLook); |
53 | TColgp_Array1OfPnt2d CPoles (1, C->NbPoles()); |
54 | C->Poles (CPoles); |
55 | dis.MoveTo(CPoles(1)); |
56 | for (Standard_Integer i = 2; i <= C->NbPoles(); i++) { |
57 | dis.DrawTo(CPoles(i)); |
58 | } |
59 | } |
60 | |
61 | DrawTrSurf_Curve2d::DrawOn(dis); |
62 | |
63 | } |
64 | |
65 | |
66 | |
67 | void DrawTrSurf_BezierCurve2d::ShowPoles () |
68 | { |
69 | drawPoles = Standard_True; |
70 | } |
71 | |
72 | |
73 | void DrawTrSurf_BezierCurve2d::ClearPoles () |
74 | { |
75 | drawPoles = Standard_False; |
76 | } |
77 | |
78 | |
79 | void DrawTrSurf_BezierCurve2d::FindPole ( |
80 | const Standard_Real X, |
81 | const Standard_Real Y, |
82 | const Draw_Display& D, |
83 | const Standard_Real XPrec, |
84 | Standard_Integer& Index) const |
85 | { |
86 | |
87 | Handle(Geom2d_BezierCurve) bz = Handle(Geom2d_BezierCurve)::DownCast(curv); |
88 | gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom()); |
89 | Standard_Real Prec = XPrec / D.Zoom(); |
90 | Index++; |
91 | Standard_Integer NbPoles = bz->NbPoles(); |
92 | gp_Pnt P; |
93 | gp_Pnt2d P2d; |
94 | while (Index <= NbPoles) { |
95 | P2d = bz->Pole(Index); |
96 | P.SetCoord (P2d.X(), P2d.Y(), 0.0); |
97 | if (D.Project(P).Distance(p1) <= Prec) |
98 | return; |
99 | Index++; |
100 | } |
101 | Index = 0; |
102 | } |
103 | |
104 | //======================================================================= |
105 | //function : Copy |
106 | //purpose : |
107 | //======================================================================= |
108 | |
109 | Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve2d::Copy()const |
110 | { |
111 | Handle(DrawTrSurf_BezierCurve2d) DC = new DrawTrSurf_BezierCurve2d |
112 | (Handle(Geom2d_BezierCurve)::DownCast(curv->Copy()), |
113 | look,polesLook, |
114 | drawPoles, |
115 | GetDiscretisation()); |
116 | |
117 | return DC; |
118 | } |