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 | |
42cf5bc1 |
15 | |
16 | #include <Draw_Color.hxx> |
17 | #include <Draw_Display.hxx> |
18 | #include <Draw_Drawable3D.hxx> |
19 | #include <DrawTrSurf_BezierCurve.hxx> |
7fd59977 |
20 | #include <Geom_BezierCurve.hxx> |
21 | #include <gp_Pnt2d.hxx> |
42cf5bc1 |
22 | #include <Standard_Type.hxx> |
7fd59977 |
23 | #include <TColgp_Array1OfPnt.hxx> |
24 | #include <TColStd_Array1OfReal.hxx> |
25 | |
b311480e |
26 | DrawTrSurf_BezierCurve::DrawTrSurf_BezierCurve ( |
7fd59977 |
27 | const Handle(Geom_BezierCurve)& C) |
28 | : DrawTrSurf_Curve (C, Draw_vert, 16, 0.05, 1) { |
29 | |
30 | drawPoles = Standard_True; |
31 | polesLook = Draw_rouge; |
32 | } |
33 | |
34 | |
35 | |
36 | DrawTrSurf_BezierCurve::DrawTrSurf_BezierCurve ( |
37 | const Handle(Geom_BezierCurve)& C, const Draw_Color& CurvColor, |
38 | const Draw_Color& PolesColor, const Standard_Boolean ShowPoles, |
39 | const Standard_Integer Discret,const Standard_Real Deflection, |
40 | const Standard_Integer DrawMode ) : |
41 | DrawTrSurf_Curve (C, CurvColor, Discret, Deflection, DrawMode) { |
42 | |
43 | drawPoles = ShowPoles; |
44 | polesLook = PolesColor; |
45 | } |
46 | |
47 | |
48 | void DrawTrSurf_BezierCurve::DrawOn (Draw_Display& dis) const { |
49 | |
50 | |
51 | Handle(Geom_BezierCurve) C = Handle(Geom_BezierCurve)::DownCast(curv); |
52 | |
53 | if (drawPoles) { |
54 | Standard_Integer NbPoles = C->NbPoles(); |
55 | dis.SetColor(polesLook); |
56 | TColgp_Array1OfPnt CPoles (1, NbPoles); |
57 | C->Poles (CPoles); |
58 | dis.MoveTo(CPoles(1)); |
59 | for (Standard_Integer i = 2; i <= NbPoles; i++) { |
60 | dis.DrawTo(CPoles(i)); |
61 | } |
62 | } |
63 | |
64 | DrawTrSurf_Curve::DrawOn(dis); |
65 | } |
66 | |
67 | |
68 | |
69 | void DrawTrSurf_BezierCurve::ShowPoles () { drawPoles = Standard_True; } |
70 | |
71 | |
72 | void DrawTrSurf_BezierCurve::ClearPoles () { drawPoles = Standard_False; } |
73 | |
74 | |
75 | void DrawTrSurf_BezierCurve::FindPole ( |
76 | const Standard_Real X, const Standard_Real Y, const Draw_Display& D, |
77 | const Standard_Real XPrec, Standard_Integer& Index) const { |
78 | |
79 | Handle(Geom_BezierCurve) bz = Handle(Geom_BezierCurve)::DownCast(curv); |
80 | gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom()); |
81 | Standard_Real Prec = XPrec / D.Zoom(); |
82 | Index++; |
83 | Standard_Integer NbPoles = bz->NbPoles(); |
84 | while (Index <= NbPoles) { |
85 | if (D.Project(bz->Pole(Index)).Distance(p1) <= Prec) |
86 | return; |
87 | Index++; |
88 | } |
89 | Index = 0; |
90 | } |
91 | |
92 | |
93 | //======================================================================= |
94 | //function : Copy |
95 | //purpose : |
96 | //======================================================================= |
97 | |
98 | Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve::Copy()const |
99 | { |
100 | Handle(DrawTrSurf_BezierCurve) DC = new DrawTrSurf_BezierCurve |
101 | (Handle(Geom_BezierCurve)::DownCast(curv->Copy()), |
102 | look,polesLook, |
103 | drawPoles, |
104 | GetDiscretisation(),GetDeflection(),GetDrawMode()); |
105 | |
106 | return DC; |
107 | } |
108 | |
109 | |
110 | |
111 | |
112 | |