1 // Created on: 1995-03-10
2 // Created by: Mister rmi
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.
17 #include <Select3D_SensitivePoint.ixx>
19 #include <Select3D_Projector.hxx>
20 #include <Bnd_Box2d.hxx>
22 #include <CSLib_Class2d.hxx>
24 //==================================================
27 //==================================================
29 Select3D_SensitivePoint
30 ::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner,
31 const gp_Pnt& aPoint):
32 Select3D_SensitiveEntity(anOwner)
34 SetSensitivityFactor(4.);
38 //==================================================
41 //==================================================
43 void Select3D_SensitivePoint
44 ::Project (const Handle(Select3D_Projector)& aProj)
48 aProj->Project(mypoint, aPoint2d);
51 gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z);
52 aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d);
57 //==================================================
60 //==================================================
62 void Select3D_SensitivePoint
63 ::Areas(SelectBasics_ListOfBox2d& boxes)
70 //==================================================
73 //==================================================
75 Standard_Boolean Select3D_SensitivePoint::Matches (const SelectBasics_PickArgs& thePickArgs,
76 Standard_Real& theMatchDMin,
77 Standard_Real& theMatchDepth)
79 // check coordinate matching
80 Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt);
81 if (aDist > thePickArgs.Tolerance() * SensitivityFactor())
83 return Standard_False;
86 Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
87 if (thePickArgs.IsClipped (aDepth))
89 return Standard_False;
93 theMatchDepth = aDepth;
97 //==================================================
100 //==================================================
102 Standard_Boolean Select3D_SensitivePoint::
103 Matches (const Standard_Real XMin,
104 const Standard_Real YMin,
105 const Standard_Real XMax,
106 const Standard_Real YMax,
107 const Standard_Real aTol)
110 B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
112 return !B.IsOut(myprojpt);
115 //=======================================================================
118 //=======================================================================
120 Standard_Boolean Select3D_SensitivePoint::
121 Matches (const TColgp_Array1OfPnt2d& aPoly,
122 const Bnd_Box2d& aBox,
123 const Standard_Real aTol)
125 Standard_Real Umin,Vmin,Umax,Vmax;
126 aBox.Get(Umin,Vmin,Umax,Vmax);
127 CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
129 Standard_Integer RES = aClassifier2d.SiDans(myprojpt);
130 if(RES==1) return Standard_True;
132 return Standard_False;
135 //=======================================================================
138 //=======================================================================
140 gp_Pnt Select3D_SensitivePoint::Point() const
143 //=======================================================================
144 //function : GetConnected
146 //=======================================================================
148 Handle(Select3D_SensitiveEntity) Select3D_SensitivePoint::GetConnected(const TopLoc_Location& aLoc)
150 Handle(Select3D_SensitivePoint) NiouEnt = new Select3D_SensitivePoint(myOwnerId,mypoint);
151 if(HasLocation()) NiouEnt->SetLocation(Location());
152 NiouEnt->UpdateLocation(aLoc);
156 //=======================================================================
159 //=======================================================================
161 void Select3D_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const
163 S<<"\tSensitivePoint 3D :";
165 S<<"\t\tExisting Location"<<endl;
167 S<<"\t\t P3d [ "<<mypoint.x<<" , "<<mypoint.y<<" , "<<mypoint.z<<" ]"<<endl;
168 S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl;
171 //=======================================================================
172 //function : ComputeDepth
174 //=======================================================================
176 Standard_Real Select3D_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const
178 return ElCLib::Parameter(EyeLine,mypoint);