Commit | Line | Data |
---|---|---|
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 | ||
36 | Select3D_SensitivePoint | |
37 | ::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner, | |
ac04d101 | 38 | const gp_Pnt& aPoint): |
7fd59977 | 39 | Select3D_SensitiveEntity(anOwner) |
40 | { | |
41 | SetSensitivityFactor(4.); | |
42 | mypoint = aPoint; | |
43 | } | |
44 | ||
45 | //================================================== | |
ac04d101 | 46 | // Function: Project |
7fd59977 | 47 | // Purpose : |
48 | //================================================== | |
ac04d101 | 49 | |
7fd59977 | 50 | void Select3D_SensitivePoint |
4952a30a | 51 | ::Project (const Handle(Select3D_Projector)& aProj) |
7fd59977 | 52 | { |
53 | Select3D_SensitiveEntity::Project(aProj); // to set the field last proj... | |
54 | gp_Pnt2d aPoint2d; | |
55 | if(!HasLocation()) | |
4952a30a | 56 | aProj->Project(mypoint, aPoint2d); |
ac04d101 SA |
57 | else |
58 | { | |
7fd59977 | 59 | gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z); |
4952a30a | 60 | aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d); |
7fd59977 | 61 | } |
62 | myprojpt = aPoint2d; | |
63 | } | |
64 | ||
65 | //================================================== | |
ac04d101 | 66 | // Function: Areas |
7fd59977 | 67 | // Purpose : |
68 | //================================================== | |
ac04d101 | 69 | |
7fd59977 | 70 | void Select3D_SensitivePoint |
71 | ::Areas(SelectBasics_ListOfBox2d& boxes) | |
72 | { | |
73 | Bnd_Box2d abox; | |
74 | abox.Set(myprojpt); | |
75 | boxes.Append(abox); | |
76 | } | |
77 | ||
7fd59977 | 78 | //================================================== |
ac04d101 | 79 | // Function: Matches |
7fd59977 | 80 | // Purpose : |
81 | //================================================== | |
ac04d101 | 82 | |
7fd59977 | 83 | Standard_Boolean Select3D_SensitivePoint |
84 | ::Matches(const Standard_Real X, | |
ac04d101 SA |
85 | const Standard_Real Y, |
86 | const Standard_Real aTol, | |
87 | Standard_Real& DMin) | |
7fd59977 | 88 | { |
89 | DMin = gp_Pnt2d(X,Y).Distance(myprojpt); | |
4952a30a | 90 | if(DMin<=aTol*SensitivityFactor()) |
91 | { | |
92 | // compute and validate the depth (::Depth()) along the eyeline | |
93 | return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin); | |
7fd59977 | 94 | } |
95 | return Standard_False; | |
96 | } | |
97 | ||
ac04d101 SA |
98 | //================================================== |
99 | // Function: Matches | |
100 | // Purpose : | |
101 | //================================================== | |
102 | ||
7fd59977 | 103 | Standard_Boolean Select3D_SensitivePoint:: |
104 | Matches (const Standard_Real XMin, | |
ac04d101 SA |
105 | const Standard_Real YMin, |
106 | const Standard_Real XMax, | |
107 | const Standard_Real YMax, | |
108 | const Standard_Real aTol) | |
7fd59977 | 109 | { |
110 | Bnd_Box2d B; | |
111 | B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax)); | |
112 | B.Enlarge(aTol); | |
113 | return !B.IsOut(myprojpt); | |
114 | } | |
115 | ||
7fd59977 | 116 | //======================================================================= |
117 | //function : Matches | |
118 | //purpose : | |
119 | //======================================================================= | |
120 | ||
121 | Standard_Boolean Select3D_SensitivePoint:: | |
122 | Matches (const TColgp_Array1OfPnt2d& aPoly, | |
ac04d101 SA |
123 | const Bnd_Box2d& aBox, |
124 | const Standard_Real aTol) | |
7fd59977 | 125 | { |
126 | Standard_Real Umin,Vmin,Umax,Vmax; | |
127 | aBox.Get(Umin,Vmin,Umax,Vmax); | |
128 | Standard_Real Tolu,Tolv; | |
129 | Tolu = 1e-7; | |
130 | Tolv = 1e-7; | |
131 | CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); | |
132 | ||
133 | Standard_Integer RES = aClassifier2d.SiDans(myprojpt); | |
134 | if(RES==1) return Standard_True; | |
135 | ||
136 | return Standard_False; | |
137 | } | |
138 | ||
7fd59977 | 139 | //======================================================================= |
140 | //function : Point | |
141 | //purpose : | |
142 | //======================================================================= | |
ac04d101 | 143 | |
7fd59977 | 144 | gp_Pnt Select3D_SensitivePoint::Point() const |
145 | {return mypoint;} | |
146 | ||
147 | //======================================================================= | |
148 | //function : GetConnected | |
149 | //purpose : | |
150 | //======================================================================= | |
151 | ||
152 | Handle(Select3D_SensitiveEntity) Select3D_SensitivePoint::GetConnected(const TopLoc_Location& aLoc) | |
153 | { | |
154 | Handle(Select3D_SensitivePoint) NiouEnt = new Select3D_SensitivePoint(myOwnerId,mypoint); | |
155 | if(HasLocation()) NiouEnt->SetLocation(Location()); | |
156 | NiouEnt->UpdateLocation(aLoc); | |
157 | return NiouEnt; | |
158 | } | |
159 | ||
7fd59977 | 160 | //======================================================================= |
161 | //function : Dump | |
162 | //purpose : | |
163 | //======================================================================= | |
164 | ||
165 | void Select3D_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const | |
166 | { | |
167 | S<<"\tSensitivePoint 3D :"; | |
168 | if(HasLocation()) | |
169 | S<<"\t\tExisting Location"<<endl; | |
170 | ||
171 | S<<"\t\t P3d [ "<<mypoint.x<<" , "<<mypoint.y<<" , "<<mypoint.z<<" ]"<<endl; | |
172 | S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl; | |
173 | } | |
174 | ||
175 | //======================================================================= | |
176 | //function : ComputeDepth | |
177 | //purpose : | |
178 | //======================================================================= | |
179 | ||
180 | Standard_Real Select3D_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const | |
181 | { | |
182 | return ElCLib::Parameter(EyeLine,mypoint); | |
183 | } |