b311480e |
1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
6 | // This library is free software; you can redistribute it and/or modify it under |
7 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
8 | // by the Free Software Foundation, with special exception defined in the file |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
10 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
b311480e |
14 | |
7fd59977 |
15 | #include <DrawTrSurf_BezierCurve2d.ixx> |
16 | |
17 | #include <Geom2d_BezierCurve.hxx> |
18 | #include <gp_Pnt.hxx> |
19 | #include <TColgp_Array1OfPnt2d.hxx> |
20 | #include <TColStd_Array1OfReal.hxx> |
21 | |
22 | |
b311480e |
23 | DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d ( |
7fd59977 |
24 | const Handle(Geom2d_BezierCurve)& C) : |
25 | DrawTrSurf_Curve2d (C, Draw_vert, 50) { |
26 | |
27 | drawPoles = Standard_True; |
28 | polesLook = Draw_rouge; |
29 | } |
30 | |
31 | |
32 | DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d ( |
33 | const Handle(Geom2d_BezierCurve)& C, const Draw_Color& CurvColor, |
34 | const Draw_Color& PolesColor, const Standard_Boolean ShowPoles, |
35 | const Standard_Integer Discret) : DrawTrSurf_Curve2d (C, CurvColor, Discret) { |
36 | |
37 | drawPoles = ShowPoles; |
38 | polesLook = PolesColor; |
39 | } |
40 | |
41 | |
42 | void DrawTrSurf_BezierCurve2d::DrawOn (Draw_Display& dis) const |
43 | { |
44 | |
45 | Handle(Geom2d_BezierCurve) C = Handle(Geom2d_BezierCurve)::DownCast(curv); |
46 | |
47 | if (drawPoles) { |
48 | dis.SetColor(polesLook); |
49 | TColgp_Array1OfPnt2d CPoles (1, C->NbPoles()); |
50 | C->Poles (CPoles); |
51 | dis.MoveTo(CPoles(1)); |
52 | for (Standard_Integer i = 2; i <= C->NbPoles(); i++) { |
53 | dis.DrawTo(CPoles(i)); |
54 | } |
55 | } |
56 | |
57 | DrawTrSurf_Curve2d::DrawOn(dis); |
58 | |
59 | } |
60 | |
61 | |
62 | |
63 | void DrawTrSurf_BezierCurve2d::ShowPoles () |
64 | { |
65 | drawPoles = Standard_True; |
66 | } |
67 | |
68 | |
69 | void DrawTrSurf_BezierCurve2d::ClearPoles () |
70 | { |
71 | drawPoles = Standard_False; |
72 | } |
73 | |
74 | |
75 | void DrawTrSurf_BezierCurve2d::FindPole ( |
76 | const Standard_Real X, |
77 | const Standard_Real Y, |
78 | const Draw_Display& D, |
79 | const Standard_Real XPrec, |
80 | Standard_Integer& Index) const |
81 | { |
82 | |
83 | Handle(Geom2d_BezierCurve) bz = Handle(Geom2d_BezierCurve)::DownCast(curv); |
84 | gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom()); |
85 | Standard_Real Prec = XPrec / D.Zoom(); |
86 | Index++; |
87 | Standard_Integer NbPoles = bz->NbPoles(); |
88 | gp_Pnt P; |
89 | gp_Pnt2d P2d; |
90 | while (Index <= NbPoles) { |
91 | P2d = bz->Pole(Index); |
92 | P.SetCoord (P2d.X(), P2d.Y(), 0.0); |
93 | if (D.Project(P).Distance(p1) <= Prec) |
94 | return; |
95 | Index++; |
96 | } |
97 | Index = 0; |
98 | } |
99 | |
100 | //======================================================================= |
101 | //function : Copy |
102 | //purpose : |
103 | //======================================================================= |
104 | |
105 | Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve2d::Copy()const |
106 | { |
107 | Handle(DrawTrSurf_BezierCurve2d) DC = new DrawTrSurf_BezierCurve2d |
108 | (Handle(Geom2d_BezierCurve)::DownCast(curv->Copy()), |
109 | look,polesLook, |
110 | drawPoles, |
111 | GetDiscretisation()); |
112 | |
113 | return DC; |
114 | } |