1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Draw_Color.hxx>
17 #include <Draw_Display.hxx>
18 #include <Draw_Drawable3D.hxx>
19 #include <Draw_MarkerShape.hxx>
20 #include <DrawTrSurf_BSplineCurve.hxx>
21 #include <Geom_BSplineCurve.hxx>
22 #include <gp_Pnt2d.hxx>
23 #include <Standard_Type.hxx>
24 #include <TColgp_Array1OfPnt.hxx>
25 #include <TColStd_Array1OfReal.hxx>
27 DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve (
28 const Handle(Geom_BSplineCurve)& C) :
29 DrawTrSurf_Curve (C, Draw_vert, 16, 0.05, 1) {
31 drawKnots = Standard_True;
32 knotsForm = Draw_Losange;
33 knotsLook = Draw_violet;
35 drawPoles = Standard_True;
36 polesLook = Draw_rouge;
42 DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve (
43 const Handle(Geom_BSplineCurve)& C, const Draw_Color& CurvColor,
44 const Draw_Color& PolesColor, const Draw_Color& KnotsColor,
45 const Draw_MarkerShape KnotsShape, const Standard_Integer KnotsSize,
46 const Standard_Boolean ShowPoles, const Standard_Boolean ShowKnots,
47 const Standard_Integer Discret, const Standard_Real Deflection,
48 const Standard_Integer DrawMode)
49 : DrawTrSurf_Curve (C , CurvColor, Discret, Deflection, DrawMode) {
51 drawKnots = ShowKnots;
52 knotsForm = KnotsShape;
53 knotsLook = KnotsColor;
55 drawPoles = ShowPoles;
56 polesLook = PolesColor;
61 void DrawTrSurf_BSplineCurve::DrawOn (Draw_Display& dis) const {
64 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
66 Standard_Integer NbPoles = C->NbPoles();
67 dis.SetColor(polesLook);
68 TColgp_Array1OfPnt CPoles (1, NbPoles);
70 dis.MoveTo(CPoles(1));
71 for (Standard_Integer i = 2; i <= NbPoles; i++) {
72 dis.DrawTo(CPoles(i));
75 dis.DrawTo(CPoles(1));
78 DrawTrSurf_Curve::DrawOn(dis);
81 Standard_Integer NbKnots = C->NbKnots();
82 TColStd_Array1OfReal CKnots (1, NbKnots);
84 dis.SetColor(knotsLook);
85 Standard_Integer first = C->FirstUKnotIndex();
86 Standard_Integer last = C->LastUKnotIndex();
87 for (Standard_Integer i = first; i <= last; i++) {
88 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
94 void DrawTrSurf_BSplineCurve::DrawOn (
97 const Standard_Boolean ShowPoles,
98 const Standard_Boolean ShowKnots
102 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
103 if (drawPoles && ShowPoles) {
104 Standard_Integer NbPoles = C->NbPoles();
105 dis.SetColor(polesLook);
106 TColgp_Array1OfPnt CPoles (1, NbPoles);
108 dis.MoveTo(CPoles(1));
109 for (Standard_Integer i = 2; i <= NbPoles; i++) {
110 dis.DrawTo(CPoles(i));
114 DrawTrSurf_Curve::DrawOn(dis);
116 if (drawKnots && ShowKnots) {
117 Standard_Integer NbKnots = C->NbKnots();
118 TColStd_Array1OfReal CKnots (1, NbKnots);
120 dis.SetColor(knotsLook);
121 for (Standard_Integer i = 1; i <= NbKnots; i++) {
122 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
130 void DrawTrSurf_BSplineCurve::DrawOn (
133 const Standard_Real U1,
134 const Standard_Real U2,
135 const Standard_Integer Pindex,
136 const Standard_Boolean ShowPoles,
137 const Standard_Boolean ShowKnots
141 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
142 Standard_Real Eps1 = Abs(Epsilon (U1));
143 Standard_Real Eps2 = Abs(Epsilon (U2));
144 Standard_Integer I1, J1, I2, J2;
145 C->LocateU (U1, Eps1, I1, J1);
146 C->LocateU (U2, Eps2, I2, J2);
147 Standard_Integer ka = C->FirstUKnotIndex ();
148 Standard_Integer kb = C->LastUKnotIndex ();
151 if (drawPoles && ShowPoles) {
152 Standard_Integer NbPoles = C->NbPoles();
153 dis.SetColor(polesLook);
154 TColgp_Array1OfPnt CPoles (1, NbPoles);
157 dis.MoveTo(CPoles(1));
158 for (Standard_Integer i = 2; i <= NbPoles; i++) {
159 dis.DrawTo(CPoles(i));
162 else if (Pindex == 1) {
163 dis.MoveTo(CPoles(1));
164 dis.DrawTo(CPoles(2));
166 else if (Pindex == NbPoles) {
167 dis.MoveTo(CPoles(NbPoles-1));
168 dis.DrawTo(CPoles(NbPoles));
171 dis.MoveTo(CPoles(Pindex-1));
172 dis.DrawTo(CPoles(Pindex));
173 dis.DrawTo(CPoles(Pindex+1));
180 Standard_Integer Degree = C->Degree();
183 dis.MoveTo(C->Value(U1));
184 dis.DrawTo(C->Value(U2));
187 Standard_Integer NbPoints;
188 Standard_Integer Discret = GetDiscretisation();
189 Standard_Real Ustart = C->Knot (ka);
190 Standard_Real Uend = C->Knot (kb);
191 Standard_Real Du, U, Ua, Ub, Uk1, Uk2;
193 if (I1 > ka) { ka = I1; Uk1 = U1; }
196 NbPoints = (Standard_Integer) Abs (Discret * (U1 - Ustart) / (Ustart - Uend));
197 NbPoints = Max (NbPoints, 30);
198 Du = (Ustart - U1) / NbPoints;
199 dis.MoveTo(C->Value (U));
200 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
202 dis.DrawTo(C->Value (U));
204 dis.DrawTo(C->Value (Ustart));
208 if (J2 < kb) { kb = J2; Uk2 = U2; }
212 NbPoints = (Standard_Integer) Abs (Discret * (U2 - Uend) / (Ustart - Uend));
213 NbPoints = Max (NbPoints, 30);
214 Du = (U2 - Uend) / NbPoints;
215 dis.MoveTo(C->Value (U));
216 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
218 dis.DrawTo(C->Value (U));
220 dis.DrawTo(C->Value (U2));
224 for (Standard_Integer k = ka; k < kb; k++) {
229 else if (k == kb-1) {
238 NbPoints = (Standard_Integer) Abs (Discret * (Ua - Ub) / (Ustart - Uend));
239 NbPoints = Max (NbPoints, 30);
240 Du = (Ub - Ua) / NbPoints;
241 dis.MoveTo(C->Value (U));
242 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
244 dis.DrawTo(C->Value (U));
246 dis.DrawTo(C->Value (Ub));
251 if (drawKnots && ShowKnots) {
252 Standard_Integer NbKnots = C->NbKnots();
253 TColStd_Array1OfReal CKnots (1, NbKnots);
255 dis.SetColor(knotsLook);
256 for (Standard_Integer i = J1; i <= I2; i++) {
257 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
265 void DrawTrSurf_BSplineCurve::ShowPoles () { drawPoles = Standard_True; }
268 void DrawTrSurf_BSplineCurve::ShowKnots () { drawKnots = Standard_True; }
271 void DrawTrSurf_BSplineCurve::ClearPoles () { drawPoles = Standard_False; }
274 void DrawTrSurf_BSplineCurve::ClearKnots () { drawKnots = Standard_False; }
277 void DrawTrSurf_BSplineCurve::FindPole (
278 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real XPrec,
279 Standard_Integer& Index) const {
281 Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv);
282 Standard_Real Prec = XPrec / D.Zoom();
283 gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
285 Standard_Integer NbPoles = bc->NbPoles();
286 while (Index <= NbPoles) {
287 if (D.Project(bc->Pole(Index)).Distance(p1) <= Prec)
295 void DrawTrSurf_BSplineCurve::FindKnot (
296 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real Prec,
297 Standard_Integer& Index) const {
299 Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv);
302 Standard_Integer NbKnots = bc->NbKnots();
303 while (Index <= NbKnots) {
304 if (D.Project(bc->Value(bc->Knot(Index))).Distance(p1) <= Prec)
312 //=======================================================================
315 //=======================================================================
317 Handle(Draw_Drawable3D) DrawTrSurf_BSplineCurve::Copy()const
319 Handle(DrawTrSurf_BSplineCurve) DC = new DrawTrSurf_BSplineCurve
320 (Handle(Geom_BSplineCurve)::DownCast(curv->Copy()),
321 look,polesLook,knotsLook,knotsForm,knotsDim,
323 GetDiscretisation(),GetDeflection(),GetDrawMode());