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_BezierCurve2d.hxx>
17 #include <Draw_Color.hxx>
18 #include <Draw_Display.hxx>
19 #include <DrawTrSurf.hxx>
20 #include <DrawTrSurf_Params.hxx>
21 #include <Geom2d_BezierCurve.hxx>
22 #include <GeomTools_Curve2dSet.hxx>
24 #include <TColgp_Array1OfPnt2d.hxx>
25 #include <TColStd_Array1OfReal.hxx>
27 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_BezierCurve2d, DrawTrSurf_Curve2d)
29 DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d (const Handle(Geom2d_BezierCurve)& C)
30 : DrawTrSurf_Curve2d (C, Draw_vert, 50)
32 drawPoles = Standard_True;
33 polesLook = Draw_rouge;
36 DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d (const Handle(Geom2d_BezierCurve)& C, const Draw_Color& CurvColor,
37 const Draw_Color& PolesColor, const Standard_Boolean ShowPoles,
38 const Standard_Integer Discret)
39 : DrawTrSurf_Curve2d (C, CurvColor, Discret)
41 drawPoles = ShowPoles;
42 polesLook = PolesColor;
45 void DrawTrSurf_BezierCurve2d::DrawOn (Draw_Display& dis) const
47 Handle(Geom2d_BezierCurve) C = Handle(Geom2d_BezierCurve)::DownCast(curv);
50 dis.SetColor(polesLook);
51 TColgp_Array1OfPnt2d CPoles (1, C->NbPoles());
53 dis.MoveTo(CPoles(1));
54 for (Standard_Integer i = 2; i <= C->NbPoles(); i++) {
55 dis.DrawTo(CPoles(i));
59 DrawTrSurf_Curve2d::DrawOn(dis);
62 void DrawTrSurf_BezierCurve2d::FindPole (const Standard_Real X, const Standard_Real Y,
63 const Draw_Display& D,
64 const Standard_Real XPrec,
65 Standard_Integer& Index) const
67 Handle(Geom2d_BezierCurve) bz = Handle(Geom2d_BezierCurve)::DownCast(curv);
68 gp_Pnt2d p1(X/D.Zoom(),Y/D.Zoom());
69 Standard_Real Prec = XPrec / D.Zoom();
71 Standard_Integer NbPoles = bz->NbPoles();
74 while (Index <= NbPoles) {
75 P2d = bz->Pole(Index);
76 P.SetCoord (P2d.X(), P2d.Y(), 0.0);
77 if (D.Project(P).Distance(p1) <= Prec)
84 //=======================================================================
87 //=======================================================================
88 Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve2d::Copy() const
90 Handle(DrawTrSurf_BezierCurve2d) DC = new DrawTrSurf_BezierCurve2d
91 (Handle(Geom2d_BezierCurve)::DownCast(curv->Copy()),
99 //=======================================================================
102 //=======================================================================
103 Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve2d::Restore (Standard_IStream& theStream)
105 const DrawTrSurf_Params& aParams = DrawTrSurf::Parameters();
106 Handle(Geom2d_BezierCurve) aGeomCurve = Handle(Geom2d_BezierCurve)::DownCast(GeomTools_Curve2dSet::ReadCurve2d (theStream));
107 Handle(DrawTrSurf_BezierCurve2d) aDrawCurve = new DrawTrSurf_BezierCurve2d (aGeomCurve,
108 aParams.CurvColor, aParams.PolesColor,
109 aParams.IsShowPoles, aParams.Discret);