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