0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / DrawTrSurf / DrawTrSurf_BezierCurve.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 #include <DrawTrSurf_BezierCurve.hxx>
16
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>
26
27 IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_BezierCurve, DrawTrSurf_Curve)
28
29 DrawTrSurf_BezierCurve::DrawTrSurf_BezierCurve (const Handle(Geom_BezierCurve)& C)
30 : DrawTrSurf_Curve (C, Draw_vert, 16, 0.05, 1)
31 {
32   drawPoles = Standard_True;
33   polesLook = Draw_rouge;
34 }
35
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)
42 {
43   drawPoles = ShowPoles;
44   polesLook = PolesColor;
45 }
46
47 void DrawTrSurf_BezierCurve::DrawOn (Draw_Display& dis) const
48 {
49   Handle(Geom_BezierCurve) C = Handle(Geom_BezierCurve)::DownCast(curv);
50   if (drawPoles)
51   {
52     Standard_Integer NbPoles = C->NbPoles();
53     dis.SetColor(polesLook);
54     TColgp_Array1OfPnt CPoles (1, NbPoles);
55     C->Poles (CPoles);
56     dis.MoveTo(CPoles(1));
57     for (Standard_Integer i = 2; i <= NbPoles; i++)
58     {
59       dis.DrawTo(CPoles(i));
60     }
61   }
62
63   DrawTrSurf_Curve::DrawOn(dis);
64 }
65
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
68 {
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();
72   Index++;
73   Standard_Integer NbPoles = bz->NbPoles();
74   while (Index <= NbPoles)
75   {
76     if (D.Project(bz->Pole(Index)).Distance(p1) <= Prec)
77     {
78       return;
79     }
80     Index++;
81   }
82   Index = 0;
83 }
84
85 //=======================================================================
86 //function : Copy
87 //purpose  :
88 //=======================================================================
89 Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve::Copy() const
90 {
91   Handle(DrawTrSurf_BezierCurve) DC = new DrawTrSurf_BezierCurve (Handle(Geom_BezierCurve)::DownCast(curv->Copy()),
92      look, polesLook,
93      drawPoles,
94      GetDiscretisation(),GetDeflection(),GetDrawMode());
95   return DC;
96 }
97
98 //=======================================================================
99 //function : Restore
100 //purpose  :
101 //=======================================================================
102 Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve::Restore (Standard_IStream& theStream)
103 {
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);
109   return aDrawCurve;
110 }