1 // Created on: 1995-07-24
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor3d_Curve.hxx>
19 #include <Geom_BezierCurve.hxx>
20 #include <Geom_BSplineCurve.hxx>
24 #include <Graphic3d_ArrayOfPolylines.hxx>
25 #include <Graphic3d_Group.hxx>
26 #include <Prs3d_Arrow.hxx>
27 #include <Prs3d_ArrowAspect.hxx>
28 #include <Prs3d_LineAspect.hxx>
29 #include <Prs3d_Presentation.hxx>
30 #include <StdPrs_PoleCurve.hxx>
31 #include <TColgp_Array1OfPnt.hxx>
33 //=======================================================================
36 //=======================================================================
37 void StdPrs_PoleCurve::Add (const Handle (Prs3d_Presentation)& aPresentation,
38 const Adaptor3d_Curve& aCurve,
39 const Handle (Prs3d_Drawer)& aDrawer)
41 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect());
43 GeomAbs_CurveType CType = aCurve.GetType();
44 if (CType == GeomAbs_BezierCurve || CType == GeomAbs_BSplineCurve) {
45 Standard_Integer i, Nb;
46 if (CType == GeomAbs_BezierCurve) {
47 Handle(Geom_BezierCurve) Bz = aCurve.Bezier();
49 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(Nb);
50 for (i = 1; i <= Nb; i++)
51 aPrims->AddVertex(Bz->Pole(i));
52 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
54 else if (CType == GeomAbs_BSplineCurve) {
55 Handle(Geom_BSplineCurve) Bs = aCurve.BSpline();
57 Handle(Graphic3d_ArrayOfPolylines) aPrims = new Graphic3d_ArrayOfPolylines(Nb);
58 for (i = 1; i <= Nb; i++)
59 aPrims->AddVertex(Bs->Pole(i));
60 Prs3d_Root::CurrentGroup(aPresentation)->AddPrimitiveArray(aPrims);
64 if (aDrawer->LineArrowDraw()) {
67 aCurve.D1(aCurve.LastParameter(),Location,Direction);
68 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation),
71 aDrawer->ArrowAspect()->Angle(),
72 aDrawer->ArrowAspect()->Length());
77 //=======================================================================
80 //=======================================================================
82 Standard_Boolean StdPrs_PoleCurve::Match(const Standard_Real X,
83 const Standard_Real Y,
84 const Standard_Real Z,
85 const Standard_Real aDistance,
86 const Adaptor3d_Curve& aCurve,
87 const Handle (Prs3d_Drawer)& /*aDrawer*/)
89 GeomAbs_CurveType CType = aCurve.GetType();
90 Standard_Integer i, Nb = 0;
92 if (CType == GeomAbs_BezierCurve) {
93 Handle(Geom_BezierCurve) Bz = aCurve.Bezier();
95 for (i = 1; i <= Nb; i++) {
96 Bz->Pole(i).Coord(x,y,z);
97 if ( Abs(X-x) +Abs(Y-y)+Abs(Z-z) <= aDistance) return Standard_True;
99 return Standard_False;
101 else if (CType == GeomAbs_BSplineCurve) {
102 Handle(Geom_BSplineCurve) Bs = aCurve.BSpline();
104 for (i = 1; i <= Nb; i++) {
105 Bs->Pole(i).Coord(x,y,z);
106 if ( Abs(X-x) +Abs(Y-y)+Abs(Z-z) <= aDistance) return Standard_True;
108 return Standard_False;
110 return Standard_False;
113 //=======================================================================
116 //=======================================================================
118 Standard_Integer StdPrs_PoleCurve::Pick
119 (const Standard_Real X,
120 const Standard_Real Y,
121 const Standard_Real Z,
122 const Standard_Real aDistance,
123 const Adaptor3d_Curve& aCurve,
124 const Handle(Prs3d_Drawer)& /*aDrawer*/)
126 Standard_Real x, y, z, DistMin = RealLast();
127 Standard_Integer num = 0, i, Nb = 0;
129 GeomAbs_CurveType CType = aCurve.GetType();
131 if (CType == GeomAbs_BezierCurve) {
132 Handle(Geom_BezierCurve) Bz = aCurve.Bezier();
134 for (i = 1; i <= Nb; i++) {
135 Bz->Pole(i).Coord(x,y,z);
136 dist = Abs(X-x) +Abs(Y-y)+Abs(Z-z);
137 if ( dist <= aDistance) {
138 if (dist < DistMin) {
145 else if (CType == GeomAbs_BSplineCurve) {
146 Handle(Geom_BSplineCurve) Bs = aCurve.BSpline();
148 for (i = 1; i <= Nb; i++) {
149 Bs->Pole(i).Coord(x,y,z);
150 dist = Abs(X-x) +Abs(Y-y)+Abs(Z-z);
151 if (dist <= aDistance) {
152 if (dist < DistMin) {