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