0024070: OpenGL capped object-level clipping planes
[occt.git] / src / Select3D / Select3D_SensitivePoint.cxx
CommitLineData
b311480e 1// Created on: 1995-03-10
2// Created by: Mister rmi
3// Copyright (c) 1995-1999 Matra Datavision
4// Copyright (c) 1999-2012 OPEN CASCADE SAS
5//
6// The content of this file is subject to the Open CASCADE Technology Public
7// License Version 6.5 (the "License"). You may not use the content of this file
8// except in compliance with the License. Please obtain a copy of the License
9// at http://www.opencascade.org and read it completely before using this file.
10//
11// The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12// main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13//
14// The Original Code and all software distributed under the License is
15// distributed on an "AS IS" basis, without warranty of any kind, and the
16// Initial Developer hereby disclaims all such warranties, including without
17// limitation, any warranties of merchantability, fitness for a particular
18// purpose or non-infringement. Please see the License for the specific terms
19// and conditions governing the rights and limitations under the License.
20
7fd59977 21
22
23
24#include <Select3D_SensitivePoint.ixx>
25
26#include <Select3D_Projector.hxx>
27#include <Bnd_Box2d.hxx>
28#include <ElCLib.hxx>
29#include <CSLib_Class2d.hxx>
30
31//==================================================
ac04d101 32// Function: Creation
7fd59977 33// Purpose :
34//==================================================
35
36Select3D_SensitivePoint
37::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
ac04d101 38 const gp_Pnt& aPoint):
7fd59977 39Select3D_SensitiveEntity(anOwner)
40{
41 SetSensitivityFactor(4.);
42 mypoint = aPoint;
43}
44
45//==================================================
ac04d101 46// Function: Project
7fd59977 47// Purpose :
48//==================================================
ac04d101 49
7fd59977 50void Select3D_SensitivePoint
4952a30a 51::Project (const Handle(Select3D_Projector)& aProj)
7fd59977 52{
7fd59977 53 gp_Pnt2d aPoint2d;
54 if(!HasLocation())
4952a30a 55 aProj->Project(mypoint, aPoint2d);
ac04d101
SA
56 else
57 {
7fd59977 58 gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z);
4952a30a 59 aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
7fd59977 60 }
61 myprojpt = aPoint2d;
62}
63
64//==================================================
ac04d101 65// Function: Areas
7fd59977 66// Purpose :
67//==================================================
ac04d101 68
7fd59977 69void Select3D_SensitivePoint
70::Areas(SelectBasics_ListOfBox2d& boxes)
71{
72 Bnd_Box2d abox;
73 abox.Set(myprojpt);
74 boxes.Append(abox);
75}
76
7fd59977 77//==================================================
ac04d101 78// Function: Matches
7fd59977 79// Purpose :
80//==================================================
ac04d101 81
4269bd1b 82Standard_Boolean Select3D_SensitivePoint::Matches (const SelectBasics_PickArgs& thePickArgs,
83 Standard_Real& theMatchDMin,
84 Standard_Real& theMatchDepth)
7fd59977 85{
4269bd1b 86 // check coordinate matching
87 Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt);
88 if (aDist > thePickArgs.Tolerance() * SensitivityFactor())
4952a30a 89 {
4269bd1b 90 return Standard_False;
7fd59977 91 }
4269bd1b 92
93 Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
94 if (thePickArgs.IsClipped (aDepth))
95 {
96 return Standard_False;
97 }
98
99 theMatchDMin = aDist;
100 theMatchDepth = aDepth;
101 return Standard_True;
7fd59977 102}
103
ac04d101
SA
104//==================================================
105// Function: Matches
106// Purpose :
107//==================================================
108
7fd59977 109Standard_Boolean Select3D_SensitivePoint::
110Matches (const Standard_Real XMin,
ac04d101
SA
111 const Standard_Real YMin,
112 const Standard_Real XMax,
113 const Standard_Real YMax,
114 const Standard_Real aTol)
7fd59977 115{
116 Bnd_Box2d B;
117 B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
118 B.Enlarge(aTol);
119 return !B.IsOut(myprojpt);
120}
121
7fd59977 122//=======================================================================
123//function : Matches
aec37c15 124//purpose :
7fd59977 125//=======================================================================
126
127Standard_Boolean Select3D_SensitivePoint::
128Matches (const TColgp_Array1OfPnt2d& aPoly,
ac04d101
SA
129 const Bnd_Box2d& aBox,
130 const Standard_Real aTol)
aec37c15 131{
7fd59977 132 Standard_Real Umin,Vmin,Umax,Vmax;
133 aBox.Get(Umin,Vmin,Umax,Vmax);
7fd59977 134 CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
135
136 Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
137 if(RES==1) return Standard_True;
aec37c15 138
7fd59977 139 return Standard_False;
140}
141
7fd59977 142//=======================================================================
143//function : Point
aec37c15 144//purpose :
7fd59977 145//=======================================================================
ac04d101 146
7fd59977 147gp_Pnt Select3D_SensitivePoint::Point() const
148{return mypoint;}
149
150//=======================================================================
151//function : GetConnected
aec37c15 152//purpose :
7fd59977 153//=======================================================================
154
aec37c15 155Handle(Select3D_SensitiveEntity) Select3D_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
7fd59977 156{
157 Handle(Select3D_SensitivePoint) NiouEnt = new Select3D_SensitivePoint(myOwnerId,mypoint);
158 if(HasLocation()) NiouEnt->SetLocation(Location());
159 NiouEnt->UpdateLocation(aLoc);
160 return NiouEnt;
161}
162
7fd59977 163//=======================================================================
164//function : Dump
aec37c15 165//purpose :
7fd59977 166//=======================================================================
167
35e08fe8 168void Select3D_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
7fd59977 169{
170 S<<"\tSensitivePoint 3D :";
171 if(HasLocation())
172 S<<"\t\tExisting Location"<<endl;
173
174 S<<"\t\t P3d [ "<<mypoint.x<<" , "<<mypoint.y<<" , "<<mypoint.z<<" ]"<<endl;
175 S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
176}
177
178//=======================================================================
179//function : ComputeDepth
aec37c15 180//purpose :
7fd59977 181//=======================================================================
182
183Standard_Real Select3D_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
184{
185 return ElCLib::Parameter(EyeLine,mypoint);
186}