0031425: Visualization - free Edge has selection sensitivity inconsistent to presentation
[occt.git] / src / StdPrs / StdPrs_PoleCurve.cxx
CommitLineData
b311480e 1// Created on: 1995-07-24
2// Created by: Modelistation
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
b311480e 16
b8ddfc2f 17
42cf5bc1 18#include <Adaptor3d_Curve.hxx>
19#include <Geom_BezierCurve.hxx>
20#include <Geom_BSplineCurve.hxx>
21#include <gp_Dir.hxx>
22#include <gp_Pnt.hxx>
23#include <gp_Vec.hxx>
b8ddfc2f 24#include <Graphic3d_ArrayOfPolylines.hxx>
7fd59977 25#include <Graphic3d_Group.hxx>
7fd59977 26#include <Prs3d_Arrow.hxx>
27#include <Prs3d_ArrowAspect.hxx>
42cf5bc1 28#include <Prs3d_LineAspect.hxx>
29#include <Prs3d_Presentation.hxx>
30#include <StdPrs_PoleCurve.hxx>
7fd59977 31#include <TColgp_Array1OfPnt.hxx>
7fd59977 32
33//=======================================================================
34//function : Add
35//purpose :
36//=======================================================================
7fd59977 37void StdPrs_PoleCurve::Add (const Handle (Prs3d_Presentation)& aPresentation,
38 const Adaptor3d_Curve& aCurve,
39 const Handle (Prs3d_Drawer)& aDrawer)
40{
41 Prs3d_Root::CurrentGroup(aPresentation)->SetPrimitivesAspect(aDrawer->LineAspect()->Aspect());
42
43 GeomAbs_CurveType CType = aCurve.GetType();
44 if (CType == GeomAbs_BezierCurve || CType == GeomAbs_BSplineCurve) {
7fd59977 45 Standard_Integer i, Nb;
46 if (CType == GeomAbs_BezierCurve) {
47 Handle(Geom_BezierCurve) Bz = aCurve.Bezier();
48 Nb = Bz->NbPoles();
b8ddfc2f 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);
7fd59977 53 }
54 else if (CType == GeomAbs_BSplineCurve) {
55 Handle(Geom_BSplineCurve) Bs = aCurve.BSpline();
56 Nb = Bs->NbPoles();
b8ddfc2f 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);
7fd59977 61 }
62 }
63
64 if (aDrawer->LineArrowDraw()) {
65 gp_Pnt Location;
66 gp_Vec Direction;
67 aCurve.D1(aCurve.LastParameter(),Location,Direction);
4ad142d9 68 Prs3d_Arrow::Draw (Prs3d_Root::CurrentGroup (aPresentation),
7fd59977 69 Location,
70 gp_Dir(Direction),
71 aDrawer->ArrowAspect()->Angle(),
72 aDrawer->ArrowAspect()->Length());
73 }
74}
75
76
77//=======================================================================
78//function : Match
79//purpose :
80//=======================================================================
81
ee2be2a8 82Standard_Boolean StdPrs_PoleCurve::Match(const Standard_Real X,
83 const Standard_Real Y,
84 const Standard_Real Z,
85 const Standard_Real aDistance,
7fd59977 86 const Adaptor3d_Curve& aCurve,
35e08fe8 87 const Handle (Prs3d_Drawer)& /*aDrawer*/)
7fd59977 88{
89 GeomAbs_CurveType CType = aCurve.GetType();
90 Standard_Integer i, Nb = 0;
91 Standard_Real x,y,z;
92 if (CType == GeomAbs_BezierCurve) {
93 Handle(Geom_BezierCurve) Bz = aCurve.Bezier();
94 Nb = Bz->NbPoles();
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;
98 }
99 return Standard_False;
100 }
101 else if (CType == GeomAbs_BSplineCurve) {
102 Handle(Geom_BSplineCurve) Bs = aCurve.BSpline();
103 Nb = Bs->NbPoles();
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;
107 }
108 return Standard_False;
109 }
110 return Standard_False;
111}
112
113//=======================================================================
114//function : Pick
115//purpose :
116//=======================================================================
117
118Standard_Integer StdPrs_PoleCurve::Pick
ee2be2a8 119 (const Standard_Real X,
120 const Standard_Real Y,
121 const Standard_Real Z,
122 const Standard_Real aDistance,
7fd59977 123 const Adaptor3d_Curve& aCurve,
35e08fe8 124 const Handle(Prs3d_Drawer)& /*aDrawer*/)
7fd59977 125{
126 Standard_Real x, y, z, DistMin = RealLast();
127 Standard_Integer num = 0, i, Nb = 0;
128 Standard_Real dist;
129 GeomAbs_CurveType CType = aCurve.GetType();
130
131 if (CType == GeomAbs_BezierCurve) {
132 Handle(Geom_BezierCurve) Bz = aCurve.Bezier();
133 Nb = Bz->NbPoles();
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) {
139 DistMin = dist;
140 num = i;
141 }
142 }
143 }
144 }
145 else if (CType == GeomAbs_BSplineCurve) {
146 Handle(Geom_BSplineCurve) Bs = aCurve.BSpline();
147 Nb = Bs->NbPoles();
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) {
153 DistMin = dist;
154 num = i;
155 }
156 }
157 }
158 }
159
160 return num;
161}
162
163
164
165
166
167
168