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 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_BSplineCurve,DrawTrSurf_Curve)
29 DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve (
30 const Handle(Geom_BSplineCurve)& C) :
31 DrawTrSurf_Curve (C, Draw_vert, 16, 0.05, 1) {
33 drawKnots = Standard_True;
34 knotsForm = Draw_Losange;
35 knotsLook = Draw_violet;
37 drawPoles = Standard_True;
38 polesLook = Draw_rouge;
44 DrawTrSurf_BSplineCurve::DrawTrSurf_BSplineCurve (
45 const Handle(Geom_BSplineCurve)& C, const Draw_Color& CurvColor,
46 const Draw_Color& PolesColor, const Draw_Color& KnotsColor,
47 const Draw_MarkerShape KnotsShape, const Standard_Integer KnotsSize,
48 const Standard_Boolean ShowPoles, const Standard_Boolean ShowKnots,
49 const Standard_Integer Discret, const Standard_Real Deflection,
50 const Standard_Integer DrawMode)
51 : DrawTrSurf_Curve (C , CurvColor, Discret, Deflection, DrawMode) {
53 drawKnots = ShowKnots;
54 knotsForm = KnotsShape;
55 knotsLook = KnotsColor;
57 drawPoles = ShowPoles;
58 polesLook = PolesColor;
63 void DrawTrSurf_BSplineCurve::DrawOn (Draw_Display& dis) const {
66 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
68 Standard_Integer NbPoles = C->NbPoles();
69 dis.SetColor(polesLook);
70 TColgp_Array1OfPnt CPoles (1, NbPoles);
72 dis.MoveTo(CPoles(1));
73 for (Standard_Integer i = 2; i <= NbPoles; i++) {
74 dis.DrawTo(CPoles(i));
77 dis.DrawTo(CPoles(1));
80 DrawTrSurf_Curve::DrawOn(dis);
83 Standard_Integer NbKnots = C->NbKnots();
84 TColStd_Array1OfReal CKnots (1, NbKnots);
86 dis.SetColor(knotsLook);
87 Standard_Integer first = C->FirstUKnotIndex();
88 Standard_Integer last = C->LastUKnotIndex();
89 for (Standard_Integer i = first; i <= last; i++) {
90 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
96 void DrawTrSurf_BSplineCurve::DrawOn (
99 const Standard_Boolean ShowPoles,
100 const Standard_Boolean ShowKnots
104 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
105 if (drawPoles && ShowPoles) {
106 Standard_Integer NbPoles = C->NbPoles();
107 dis.SetColor(polesLook);
108 TColgp_Array1OfPnt CPoles (1, NbPoles);
110 dis.MoveTo(CPoles(1));
111 for (Standard_Integer i = 2; i <= NbPoles; i++) {
112 dis.DrawTo(CPoles(i));
116 DrawTrSurf_Curve::DrawOn(dis);
118 if (drawKnots && ShowKnots) {
119 Standard_Integer NbKnots = C->NbKnots();
120 TColStd_Array1OfReal CKnots (1, NbKnots);
122 dis.SetColor(knotsLook);
123 for (Standard_Integer i = 1; i <= NbKnots; i++) {
124 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
132 void DrawTrSurf_BSplineCurve::DrawOn (
135 const Standard_Real U1,
136 const Standard_Real U2,
137 const Standard_Integer Pindex,
138 const Standard_Boolean ShowPoles,
139 const Standard_Boolean ShowKnots
143 Handle(Geom_BSplineCurve) C = Handle(Geom_BSplineCurve)::DownCast(curv);
144 Standard_Real Eps1 = Abs(Epsilon (U1));
145 Standard_Real Eps2 = Abs(Epsilon (U2));
146 Standard_Integer I1, J1, I2, J2;
147 C->LocateU (U1, Eps1, I1, J1);
148 C->LocateU (U2, Eps2, I2, J2);
149 Standard_Integer ka = C->FirstUKnotIndex ();
150 Standard_Integer kb = C->LastUKnotIndex ();
153 if (drawPoles && ShowPoles) {
154 Standard_Integer NbPoles = C->NbPoles();
155 dis.SetColor(polesLook);
156 TColgp_Array1OfPnt CPoles (1, NbPoles);
159 dis.MoveTo(CPoles(1));
160 for (Standard_Integer i = 2; i <= NbPoles; i++) {
161 dis.DrawTo(CPoles(i));
164 else if (Pindex == 1) {
165 dis.MoveTo(CPoles(1));
166 dis.DrawTo(CPoles(2));
168 else if (Pindex == NbPoles) {
169 dis.MoveTo(CPoles(NbPoles-1));
170 dis.DrawTo(CPoles(NbPoles));
173 dis.MoveTo(CPoles(Pindex-1));
174 dis.DrawTo(CPoles(Pindex));
175 dis.DrawTo(CPoles(Pindex+1));
182 Standard_Integer Degree = C->Degree();
185 dis.MoveTo(C->Value(U1));
186 dis.DrawTo(C->Value(U2));
189 Standard_Integer NbPoints;
190 Standard_Integer Discret = GetDiscretisation();
191 Standard_Real Ustart = C->Knot (ka);
192 Standard_Real Uend = C->Knot (kb);
193 Standard_Real Du, U, Ua, Ub, Uk1, Uk2;
195 if (I1 > ka) { ka = I1; Uk1 = U1; }
198 NbPoints = (Standard_Integer) Abs (Discret * (U1 - Ustart) / (Ustart - Uend));
199 NbPoints = Max (NbPoints, 30);
200 Du = (Ustart - U1) / NbPoints;
201 dis.MoveTo(C->Value (U));
202 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
204 dis.DrawTo(C->Value (U));
206 dis.DrawTo(C->Value (Ustart));
210 if (J2 < kb) { kb = J2; Uk2 = U2; }
214 NbPoints = (Standard_Integer) Abs (Discret * (U2 - Uend) / (Ustart - Uend));
215 NbPoints = Max (NbPoints, 30);
216 Du = (U2 - Uend) / NbPoints;
217 dis.MoveTo(C->Value (U));
218 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
220 dis.DrawTo(C->Value (U));
222 dis.DrawTo(C->Value (U2));
226 for (Standard_Integer k = ka; k < kb; k++) {
231 else if (k == kb-1) {
240 NbPoints = (Standard_Integer) Abs (Discret * (Ua - Ub) / (Ustart - Uend));
241 NbPoints = Max (NbPoints, 30);
242 Du = (Ub - Ua) / NbPoints;
243 dis.MoveTo(C->Value (U));
244 for (Standard_Integer i = 1; i <= NbPoints - 2; i++) {
246 dis.DrawTo(C->Value (U));
248 dis.DrawTo(C->Value (Ub));
253 if (drawKnots && ShowKnots) {
254 Standard_Integer NbKnots = C->NbKnots();
255 TColStd_Array1OfReal CKnots (1, NbKnots);
257 dis.SetColor(knotsLook);
258 for (Standard_Integer i = J1; i <= I2; i++) {
259 dis.DrawMarker (C->Value (CKnots (i)), knotsForm, knotsDim);
267 void DrawTrSurf_BSplineCurve::ShowPoles () { drawPoles = Standard_True; }
270 void DrawTrSurf_BSplineCurve::ShowKnots () { drawKnots = Standard_True; }
273 void DrawTrSurf_BSplineCurve::ClearPoles () { drawPoles = Standard_False; }
276 void DrawTrSurf_BSplineCurve::ClearKnots () { drawKnots = Standard_False; }
279 void DrawTrSurf_BSplineCurve::FindPole (
280 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real XPrec,
281 Standard_Integer& Index) const {
283 Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv);
284 Standard_Real Prec = XPrec / D.Zoom();
285 gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
287 Standard_Integer NbPoles = bc->NbPoles();
288 while (Index <= NbPoles) {
289 if (D.Project(bc->Pole(Index)).Distance(p1) <= Prec)
297 void DrawTrSurf_BSplineCurve::FindKnot (
298 const Standard_Real X, const Standard_Real Y, const Draw_Display& D, const Standard_Real Prec,
299 Standard_Integer& Index) const {
301 Handle(Geom_BSplineCurve) bc = Handle(Geom_BSplineCurve)::DownCast(curv);
304 Standard_Integer NbKnots = bc->NbKnots();
305 while (Index <= NbKnots) {
306 if (D.Project(bc->Value(bc->Knot(Index))).Distance(p1) <= Prec)
314 //=======================================================================
317 //=======================================================================
319 Handle(Draw_Drawable3D) DrawTrSurf_BSplineCurve::Copy()const
321 Handle(DrawTrSurf_BSplineCurve) DC = new DrawTrSurf_BSplineCurve
322 (Handle(Geom_BSplineCurve)::DownCast(curv->Copy()),
323 look,polesLook,knotsLook,knotsForm,knotsDim,
325 GetDiscretisation(),GetDeflection(),GetDrawMode());