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_BSplineCurve2d.hxx>
21 #include <Geom2d_BSplineCurve.hxx>
23 #include <Standard_Type.hxx>
24 #include <TColgp_Array1OfPnt2d.hxx>
25 #include <TColStd_Array1OfReal.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_BSplineCurve2d,DrawTrSurf_Curve2d)
29 DrawTrSurf_BSplineCurve2d::DrawTrSurf_BSplineCurve2d (
30 const Handle(Geom2d_BSplineCurve)& C)
31 : DrawTrSurf_Curve2d (C, Draw_vert, 100) {
33 drawKnots = Standard_True;
34 knotsForm = Draw_Losange;
35 knotsLook = Draw_violet;
37 drawPoles = Standard_True;
38 polesLook = Draw_rouge;
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) {
50 drawKnots = ShowKnots;
51 knotsForm = KnotsShape;
52 knotsLook = KnotsColor;
54 drawPoles = ShowPoles;
55 polesLook = PolesColor;
60 void DrawTrSurf_BSplineCurve2d::DrawOn (Draw_Display& dis) const
63 Handle(Geom2d_BSplineCurve) C = Handle(Geom2d_BSplineCurve)::DownCast(curv);
66 Standard_Integer NbPoles = C->NbPoles();
67 dis.SetColor(polesLook);
68 TColgp_Array1OfPnt2d 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_Curve2d::DrawOn(dis);
81 Standard_Integer NbKnots = C->NbKnots();
82 TColStd_Array1OfReal CKnots (1, NbKnots);
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);
93 void DrawTrSurf_BSplineCurve2d::ShowPoles () { drawPoles = Standard_True; }
96 void DrawTrSurf_BSplineCurve2d::ShowKnots () { drawKnots = Standard_True; }
99 void DrawTrSurf_BSplineCurve2d::ClearPoles () { drawPoles = Standard_False; }
102 void DrawTrSurf_BSplineCurve2d::ClearKnots () { drawKnots = Standard_False; }
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 {
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());
113 Standard_Integer NbPoles = bc->NbPoles();
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)
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 {
131 Handle(Geom2d_BSplineCurve) bc = Handle(Geom2d_BSplineCurve)::DownCast(curv);
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)
147 //=======================================================================
150 //=======================================================================
152 Handle(Draw_Drawable3D) DrawTrSurf_BSplineCurve2d::Copy()const
154 Handle(DrawTrSurf_BSplineCurve2d) DC = new DrawTrSurf_BSplineCurve2d
155 (Handle(Geom2d_BSplineCurve)::DownCast(curv->Copy()),
156 look,polesLook,knotsLook,knotsForm,knotsDim,
158 GetDiscretisation());