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_BezierCurve.hxx>
17 #include <Draw_Color.hxx>
18 #include <Draw_Display.hxx>
19 #include <DrawTrSurf.hxx>
20 #include <DrawTrSurf_Params.hxx>
21 #include <Geom_BezierCurve.hxx>
22 #include <GeomTools_CurveSet.hxx>
23 #include <gp_Pnt2d.hxx>
24 #include <TColgp_Array1OfPnt.hxx>
25 #include <TColStd_Array1OfReal.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_BezierCurve, DrawTrSurf_Curve)
29 DrawTrSurf_BezierCurve::DrawTrSurf_BezierCurve (const Handle(Geom_BezierCurve)& C)
30 : DrawTrSurf_Curve (C, Draw_vert, 16, 0.05, 1)
32 drawPoles = Standard_True;
33 polesLook = Draw_rouge;
36 DrawTrSurf_BezierCurve::DrawTrSurf_BezierCurve (
37 const Handle(Geom_BezierCurve)& C, const Draw_Color& CurvColor,
38 const Draw_Color& PolesColor, const Standard_Boolean ShowPoles,
39 const Standard_Integer Discret,const Standard_Real Deflection,
40 const Standard_Integer DrawMode )
41 : DrawTrSurf_Curve (C, CurvColor, Discret, Deflection, DrawMode)
43 drawPoles = ShowPoles;
44 polesLook = PolesColor;
47 void DrawTrSurf_BezierCurve::DrawOn (Draw_Display& dis) const
49 Handle(Geom_BezierCurve) C = Handle(Geom_BezierCurve)::DownCast(curv);
52 Standard_Integer NbPoles = C->NbPoles();
53 dis.SetColor(polesLook);
54 TColgp_Array1OfPnt CPoles (1, NbPoles);
56 dis.MoveTo(CPoles(1));
57 for (Standard_Integer i = 2; i <= NbPoles; i++)
59 dis.DrawTo(CPoles(i));
63 DrawTrSurf_Curve::DrawOn(dis);
66 void DrawTrSurf_BezierCurve::FindPole (const Standard_Real X, const Standard_Real Y, const Draw_Display& D,
67 const Standard_Real XPrec, Standard_Integer& Index) const
69 Handle(Geom_BezierCurve) bz = Handle(Geom_BezierCurve)::DownCast(curv);
70 gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
71 Standard_Real Prec = XPrec / D.Zoom();
73 Standard_Integer NbPoles = bz->NbPoles();
74 while (Index <= NbPoles)
76 if (D.Project(bz->Pole(Index)).Distance(p1) <= Prec)
85 //=======================================================================
88 //=======================================================================
89 Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve::Copy() const
91 Handle(DrawTrSurf_BezierCurve) DC = new DrawTrSurf_BezierCurve (Handle(Geom_BezierCurve)::DownCast(curv->Copy()),
94 GetDiscretisation(),GetDeflection(),GetDrawMode());
98 //=======================================================================
101 //=======================================================================
102 Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve::Restore (Standard_IStream& theStream)
104 const DrawTrSurf_Params& aParams = DrawTrSurf::Parameters();
105 Handle(Geom_BezierCurve) aGeomCurve = Handle(Geom_BezierCurve)::DownCast (GeomTools_CurveSet::ReadCurve (theStream));
106 Handle(DrawTrSurf_BezierCurve) aDrawCurve = new DrawTrSurf_BezierCurve (aGeomCurve,
107 aParams.CurvColor, aParams.PolesColor, aParams.IsShowPoles,
108 aParams.Discret, aParams.Deflection, aParams.DrawMode);