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.
15 #include <DrawTrSurf_BSplineCurve.ixx>
16 #include <Draw_MarkerShape.hxx>
17 #include <Geom_BSplineCurve.hxx>
18 #include <gp_Pnt2d.hxx>
21 #include <TColgp_Array1OfPnt.hxx>
22 #include <TColStd_Array1OfReal.hxx>
25 DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve (
26 const Handle(Geom_BSplineCurve)& C) :
27 DrawTrSurf_Curve (C, Draw_vert, 16, 0.05, 1) {
29 drawKnots = Standard_True;
30 knotsForm = Draw_Losange;
31 knotsLook = Draw_violet;
33 drawPoles = Standard_True;
34 polesLook = Draw_rouge;
40 DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve (
41 const Handle(Geom_BSplineCurve)& C, const Draw_Color& CurvColor,
42 const Draw_Color& PolesColor, const Draw_Color& KnotsColor,
43 const Draw_MarkerShape KnotsShape, const Standard_Integer KnotsSize,
44 const Standard_Boolean ShowPoles, const Standard_Boolean ShowKnots,
45 const Standard_Integer Discret, const Standard_Real Deflection,
46 const Standard_Integer DrawMode)
47 : DrawTrSurf_Curve (C , CurvColor, Discret, Deflection, DrawMode) {
49 drawKnots = ShowKnots;
50 knotsForm = KnotsShape;
51 knotsLook = KnotsColor;
53 drawPoles = ShowPoles;
54 polesLook = PolesColor;
59 void DrawTrSurf_BSplineCurve::DrawOn (Draw_Display& dis) const {
62 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
64 Standard_Integer NbPoles = C->NbPoles();
65 dis.SetColor(polesLook);
66 TColgp_Array1OfPnt CPoles (1, NbPoles);
68 dis.MoveTo(CPoles(1));
69 for (Standard_Integer i = 2; i <= NbPoles; i++) {
70 dis.DrawTo(CPoles(i));
73 dis.DrawTo(CPoles(1));
76 DrawTrSurf_Curve::DrawOn(dis);
79 Standard_Integer NbKnots = C->NbKnots();
80 TColStd_Array1OfReal CKnots (1, NbKnots);
82 dis.SetColor(knotsLook);
83 Standard_Integer first = C->FirstUKnotIndex();
84 Standard_Integer last = C->LastUKnotIndex();
85 for (Standard_Integer i = first; i <= last; i++) {
86 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
92 void DrawTrSurf_BSplineCurve::DrawOn (
95 const Standard_Boolean ShowPoles,
96 const Standard_Boolean ShowKnots
100 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
101 if (drawPoles && ShowPoles) {
102 Standard_Integer NbPoles = C->NbPoles();
103 dis.SetColor(polesLook);
104 TColgp_Array1OfPnt CPoles (1, NbPoles);
106 dis.MoveTo(CPoles(1));
107 for (Standard_Integer i = 2; i <= NbPoles; i++) {
108 dis.DrawTo(CPoles(i));
112 DrawTrSurf_Curve::DrawOn(dis);
114 if (drawKnots && ShowKnots) {
115 Standard_Integer NbKnots = C->NbKnots();
116 TColStd_Array1OfReal CKnots (1, NbKnots);
118 dis.SetColor(knotsLook);
119 for (Standard_Integer i = 1; i <= NbKnots; i++) {
120 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
128 void DrawTrSurf_BSplineCurve::DrawOn (
131 const Standard_Real U1,
132 const Standard_Real U2,
133 const Standard_Integer Pindex,
134 const Standard_Boolean ShowPoles,
135 const Standard_Boolean ShowKnots
139 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
140 Standard_Real Eps1 = Abs(Epsilon (U1));
141 Standard_Real Eps2 = Abs(Epsilon (U2));
142 Standard_Integer I1, J1, I2, J2;
143 C->LocateU (U1, Eps1, I1, J1);
144 C->LocateU (U2, Eps2, I2, J2);
145 Standard_Integer ka = C->FirstUKnotIndex ();
146 Standard_Integer kb = C->LastUKnotIndex ();
149 if (drawPoles && ShowPoles) {
150 Standard_Integer NbPoles = C->NbPoles();
151 dis.SetColor(polesLook);
152 TColgp_Array1OfPnt CPoles (1, NbPoles);
155 dis.MoveTo(CPoles(1));
156 for (Standard_Integer i = 2; i <= NbPoles; i++) {
157 dis.DrawTo(CPoles(i));
160 else if (Pindex == 1) {
161 dis.MoveTo(CPoles(1));
162 dis.DrawTo(CPoles(2));
164 else if (Pindex == NbPoles) {
165 dis.MoveTo(CPoles(NbPoles-1));
166 dis.DrawTo(CPoles(NbPoles));
169 dis.MoveTo(CPoles(Pindex-1));
170 dis.DrawTo(CPoles(Pindex));
171 dis.DrawTo(CPoles(Pindex+1));
178 Standard_Integer Degree = C->Degree();
181 dis.MoveTo(C->Value(U1));
182 dis.DrawTo(C->Value(U2));
185 Standard_Integer NbPoints;
186 Standard_Integer Discret = GetDiscretisation();
187 Standard_Real Ustart = C->Knot (ka);
188 Standard_Real Uend = C->Knot (kb);
189 Standard_Real Du, U, Ua, Ub, Uk1, Uk2;
191 if (I1 > ka) { ka = I1; Uk1 = U1; }
194 NbPoints = (Standard_Integer) Abs (Discret * (U1 - Ustart) / (Ustart - Uend));
195 NbPoints = Max (NbPoints, 30);
196 Du = (Ustart - U1) / NbPoints;
197 dis.MoveTo(C->Value (U));
198 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
200 dis.DrawTo(C->Value (U));
202 dis.DrawTo(C->Value (Ustart));
206 if (J2 < kb) { kb = J2; Uk2 = U2; }
210 NbPoints = (Standard_Integer) Abs (Discret * (U2 - Uend) / (Ustart - Uend));
211 NbPoints = Max (NbPoints, 30);
212 Du = (U2 - Uend) / NbPoints;
213 dis.MoveTo(C->Value (U));
214 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
216 dis.DrawTo(C->Value (U));
218 dis.DrawTo(C->Value (U2));
222 for (Standard_Integer k = ka; k < kb; k++) {
227 else if (k == kb-1) {
236 NbPoints = (Standard_Integer) Abs (Discret * (Ua - Ub) / (Ustart - Uend));
237 NbPoints = Max (NbPoints, 30);
238 Du = (Ub - Ua) / NbPoints;
239 dis.MoveTo(C->Value (U));
240 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
242 dis.DrawTo(C->Value (U));
244 dis.DrawTo(C->Value (Ub));
249 if (drawKnots && ShowKnots) {
250 Standard_Integer NbKnots = C->NbKnots();
251 TColStd_Array1OfReal CKnots (1, NbKnots);
253 dis.SetColor(knotsLook);
254 for (Standard_Integer i = J1; i <= I2; i++) {
255 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
263 void DrawTrSurf_BSplineCurve::ShowPoles () { drawPoles = Standard_True; }
266 void DrawTrSurf_BSplineCurve::ShowKnots () { drawKnots = Standard_True; }
269 void DrawTrSurf_BSplineCurve::ClearPoles () { drawPoles = Standard_False; }
272 void DrawTrSurf_BSplineCurve::ClearKnots () { drawKnots = Standard_False; }
275 void DrawTrSurf_BSplineCurve::FindPole (
276 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real XPrec,
277 Standard_Integer& Index) const {
279 Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv);
280 Standard_Real Prec = XPrec / D.Zoom();
281 gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
283 Standard_Integer NbPoles = bc->NbPoles();
284 while (Index <= NbPoles) {
285 if (D.Project(bc->Pole(Index)).Distance(p1) <= Prec)
293 void DrawTrSurf_BSplineCurve::FindKnot (
294 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real Prec,
295 Standard_Integer& Index) const {
297 Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv);
300 Standard_Integer NbKnots = bc->NbKnots();
301 while (Index <= NbKnots) {
302 if (D.Project(bc->Value(bc->Knot(Index))).Distance(p1) <= Prec)
310 //=======================================================================
313 //=======================================================================
315 Handle(Draw_Drawable3D) DrawTrSurf_BSplineCurve::Copy()const
317 Handle(DrawTrSurf_BSplineCurve) DC = new DrawTrSurf_BSplineCurve
318 (Handle(Geom_BSplineCurve)::DownCast(curv->Copy()),
319 look,polesLook,knotsLook,knotsForm,knotsDim,
321 GetDiscretisation(),GetDeflection(),GetDrawMode());