0033661: Data Exchange, Step Import - Tessellated GDTs are not imported
[occt.git] / src / DrawTrSurf / DrawTrSurf_BezierCurve2d.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
a13df0fe 15#include <DrawTrSurf_BezierCurve2d.hxx>
7fd59977 16
42cf5bc1 17#include <Draw_Color.hxx>
18#include <Draw_Display.hxx>
a13df0fe 19#include <DrawTrSurf.hxx>
20#include <DrawTrSurf_Params.hxx>
7fd59977 21#include <Geom2d_BezierCurve.hxx>
a13df0fe 22#include <GeomTools_Curve2dSet.hxx>
7fd59977 23#include <gp_Pnt.hxx>
24#include <TColgp_Array1OfPnt2d.hxx>
25#include <TColStd_Array1OfReal.hxx>
26
a13df0fe 27IMPLEMENT_STANDARD_RTTIEXT(DrawTrSurf_BezierCurve2d, DrawTrSurf_Curve2d)
7fd59977 28
a13df0fe 29DrawTrSurf_BezierCurve2d::DrawTrSurf_BezierCurve2d (const Handle(Geom2d_BezierCurve)& C)
30: DrawTrSurf_Curve2d (C, Draw_vert, 50)
31{
32 drawPoles = Standard_True;
33 polesLook = Draw_rouge;
34}
7fd59977 35
a13df0fe 36DrawTrSurf_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)
40{
41 drawPoles = ShowPoles;
42 polesLook = PolesColor;
43}
7fd59977 44
a13df0fe 45void DrawTrSurf_BezierCurve2d::DrawOn (Draw_Display& dis) const
7fd59977 46{
7fd59977 47 Handle(Geom2d_BezierCurve) C = Handle(Geom2d_BezierCurve)::DownCast(curv);
a13df0fe 48 if (drawPoles)
49 {
7fd59977 50 dis.SetColor(polesLook);
51 TColgp_Array1OfPnt2d CPoles (1, C->NbPoles());
52 C->Poles (CPoles);
53 dis.MoveTo(CPoles(1));
54 for (Standard_Integer i = 2; i <= C->NbPoles(); i++) {
55 dis.DrawTo(CPoles(i));
56 }
57 }
58
59 DrawTrSurf_Curve2d::DrawOn(dis);
7fd59977 60}
61
a13df0fe 62void 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
7fd59977 66{
7fd59977 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();
70 Index++;
71 Standard_Integer NbPoles = bz->NbPoles();
72 gp_Pnt P;
73 gp_Pnt2d P2d;
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)
78 return;
79 Index++;
80 }
81 Index = 0;
82}
83
84//=======================================================================
85//function : Copy
a13df0fe 86//purpose :
7fd59977 87//=======================================================================
a13df0fe 88Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve2d::Copy() const
7fd59977 89{
90 Handle(DrawTrSurf_BezierCurve2d) DC = new DrawTrSurf_BezierCurve2d
91 (Handle(Geom2d_BezierCurve)::DownCast(curv->Copy()),
92 look,polesLook,
93 drawPoles,
94 GetDiscretisation());
a13df0fe 95
7fd59977 96 return DC;
97}
a13df0fe 98
99//=======================================================================
100//function : Restore
101//purpose :
102//=======================================================================
103Handle(Draw_Drawable3D) DrawTrSurf_BezierCurve2d::Restore (Standard_IStream& theStream)
104{
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);
110 return aDrawCurve;
111}