0026254: Inject GeomAbs_OffsetCurve into GeomAbs_CurveType enumeration
[occt.git] / src / DrawTrSurf / DrawTrSurf_BezierCurve2d.cxx
1 // Copyright (c) 1995-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
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.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15
16 #include <Draw_Color.hxx>
17 #include <Draw_Display.hxx>
18 #include <Draw_Drawable3D.hxx>
19 #include <DrawTrSurf_BezierCurve2d.hxx>
20 #include <Geom2d_BezierCurve.hxx>
21 #include <gp_Pnt.hxx>
22 #include <Standard_Type.hxx>
23 #include <TColgp_Array1OfPnt2d.hxx>
24 #include <TColStd_Array1OfReal.hxx>
25
26 DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d (
27    const Handle(Geom2d_BezierCurve)& C) :
28    DrawTrSurf_Curve2d (C, Draw_vert, 50) {
29
30       drawPoles = Standard_True;
31       polesLook = Draw_rouge;
32    }
33
34
35    DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d (
36    const Handle(Geom2d_BezierCurve)& C, const Draw_Color& CurvColor,
37    const Draw_Color& PolesColor, const Standard_Boolean ShowPoles,
38    const Standard_Integer Discret) : DrawTrSurf_Curve2d (C, CurvColor, Discret) {
39
40       drawPoles = ShowPoles;
41       polesLook = PolesColor;
42    }
43
44
45 void DrawTrSurf_BezierCurve2d::DrawOn (Draw_Display& dis) const 
46 {
47   
48   Handle(Geom2d_BezierCurve) C = Handle(Geom2d_BezierCurve)::DownCast(curv);
49   
50   if (drawPoles) {
51     dis.SetColor(polesLook);
52     TColgp_Array1OfPnt2d CPoles (1, C->NbPoles());
53     C->Poles (CPoles);
54     dis.MoveTo(CPoles(1));
55     for (Standard_Integer i = 2; i <= C->NbPoles(); i++) {
56       dis.DrawTo(CPoles(i));
57     }
58   }
59   
60   DrawTrSurf_Curve2d::DrawOn(dis);
61   
62 }
63
64
65
66 void DrawTrSurf_BezierCurve2d::ShowPoles () 
67 {
68   drawPoles = Standard_True; 
69 }
70
71
72 void DrawTrSurf_BezierCurve2d::ClearPoles () 
73 {
74   drawPoles = Standard_False; 
75 }
76
77
78 void DrawTrSurf_BezierCurve2d::FindPole (
79                                          const Standard_Real X, 
80                                          const Standard_Real Y, 
81                                          const Draw_Display& D,
82                                          const Standard_Real XPrec, 
83                                          Standard_Integer& Index) const 
84 {
85
86   Handle(Geom2d_BezierCurve) bz = Handle(Geom2d_BezierCurve)::DownCast(curv);
87   gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
88   Standard_Real Prec = XPrec / D.Zoom();
89   Index++;
90   Standard_Integer NbPoles = bz->NbPoles();
91   gp_Pnt P;
92   gp_Pnt2d P2d;
93   while (Index <= NbPoles) {
94     P2d = bz->Pole(Index);
95     P.SetCoord (P2d.X(), P2d.Y(), 0.0);
96     if (D.Project(P).Distance(p1) <= Prec)
97       return;
98     Index++;
99   }
100   Index = 0;
101 }
102
103 //=======================================================================
104 //function : Copy
105 //purpose  : 
106 //=======================================================================
107
108 Handle(Draw_Drawable3D)  DrawTrSurf_BezierCurve2d::Copy()const 
109 {
110   Handle(DrawTrSurf_BezierCurve2d) DC = new DrawTrSurf_BezierCurve2d
111     (Handle(Geom2d_BezierCurve)::DownCast(curv->Copy()),
112      look,polesLook,
113      drawPoles,
114      GetDiscretisation());
115      
116   return DC;
117 }