Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-03-10 |
2 | // Created by: Mister rmi | |
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. | |
7fd59977 | 16 | |
17 | #include <Select3D_SensitivePoint.ixx> | |
18 | ||
19 | #include <Select3D_Projector.hxx> | |
20 | #include <Bnd_Box2d.hxx> | |
21 | #include <ElCLib.hxx> | |
22 | #include <CSLib_Class2d.hxx> | |
23 | ||
24 | //================================================== | |
ac04d101 | 25 | // Function: Creation |
7fd59977 | 26 | // Purpose : |
27 | //================================================== | |
28 | ||
29 | Select3D_SensitivePoint | |
30 | ::Select3D_SensitivePoint(const Handle(SelectBasics_EntityOwner)& anOwner, | |
ac04d101 | 31 | const gp_Pnt& aPoint): |
7fd59977 | 32 | Select3D_SensitiveEntity(anOwner) |
33 | { | |
34 | SetSensitivityFactor(4.); | |
35 | mypoint = aPoint; | |
36 | } | |
37 | ||
38 | //================================================== | |
ac04d101 | 39 | // Function: Project |
7fd59977 | 40 | // Purpose : |
41 | //================================================== | |
ac04d101 | 42 | |
7fd59977 | 43 | void Select3D_SensitivePoint |
4952a30a | 44 | ::Project (const Handle(Select3D_Projector)& aProj) |
7fd59977 | 45 | { |
7fd59977 | 46 | gp_Pnt2d aPoint2d; |
47 | if(!HasLocation()) | |
4952a30a | 48 | aProj->Project(mypoint, aPoint2d); |
ac04d101 SA |
49 | else |
50 | { | |
7fd59977 | 51 | gp_Pnt aP(mypoint.x, mypoint.y, mypoint.z); |
4952a30a | 52 | aProj->Project(aP.Transformed(Location().Transformation()), aPoint2d); |
7fd59977 | 53 | } |
54 | myprojpt = aPoint2d; | |
55 | } | |
56 | ||
57 | //================================================== | |
ac04d101 | 58 | // Function: Areas |
7fd59977 | 59 | // Purpose : |
60 | //================================================== | |
ac04d101 | 61 | |
7fd59977 | 62 | void Select3D_SensitivePoint |
63 | ::Areas(SelectBasics_ListOfBox2d& boxes) | |
64 | { | |
65 | Bnd_Box2d abox; | |
66 | abox.Set(myprojpt); | |
67 | boxes.Append(abox); | |
68 | } | |
69 | ||
7fd59977 | 70 | //================================================== |
ac04d101 | 71 | // Function: Matches |
7fd59977 | 72 | // Purpose : |
73 | //================================================== | |
ac04d101 | 74 | |
4269bd1b | 75 | Standard_Boolean Select3D_SensitivePoint::Matches (const SelectBasics_PickArgs& thePickArgs, |
76 | Standard_Real& theMatchDMin, | |
77 | Standard_Real& theMatchDepth) | |
7fd59977 | 78 | { |
4269bd1b | 79 | // check coordinate matching |
80 | Standard_Real aDist = gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()).Distance (myprojpt); | |
81 | if (aDist > thePickArgs.Tolerance() * SensitivityFactor()) | |
4952a30a | 82 | { |
4269bd1b | 83 | return Standard_False; |
7fd59977 | 84 | } |
4269bd1b | 85 | |
86 | Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine()); | |
87 | if (thePickArgs.IsClipped (aDepth)) | |
88 | { | |
89 | return Standard_False; | |
90 | } | |
91 | ||
92 | theMatchDMin = aDist; | |
93 | theMatchDepth = aDepth; | |
94 | return Standard_True; | |
7fd59977 | 95 | } |
96 | ||
ac04d101 SA |
97 | //================================================== |
98 | // Function: Matches | |
99 | // Purpose : | |
100 | //================================================== | |
101 | ||
7fd59977 | 102 | Standard_Boolean Select3D_SensitivePoint:: |
103 | Matches (const Standard_Real XMin, | |
ac04d101 SA |
104 | const Standard_Real YMin, |
105 | const Standard_Real XMax, | |
106 | const Standard_Real YMax, | |
107 | const Standard_Real aTol) | |
7fd59977 | 108 | { |
109 | Bnd_Box2d B; | |
110 | B.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax)); | |
111 | B.Enlarge(aTol); | |
112 | return !B.IsOut(myprojpt); | |
113 | } | |
114 | ||
7fd59977 | 115 | //======================================================================= |
116 | //function : Matches | |
aec37c15 | 117 | //purpose : |
7fd59977 | 118 | //======================================================================= |
119 | ||
120 | Standard_Boolean Select3D_SensitivePoint:: | |
121 | Matches (const TColgp_Array1OfPnt2d& aPoly, | |
ac04d101 SA |
122 | const Bnd_Box2d& aBox, |
123 | const Standard_Real aTol) | |
aec37c15 | 124 | { |
7fd59977 | 125 | Standard_Real Umin,Vmin,Umax,Vmax; |
126 | aBox.Get(Umin,Vmin,Umax,Vmax); | |
7fd59977 | 127 | CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax); |
128 | ||
129 | Standard_Integer RES = aClassifier2d.SiDans(myprojpt); | |
130 | if(RES==1) return Standard_True; | |
aec37c15 | 131 | |
7fd59977 | 132 | return Standard_False; |
133 | } | |
134 | ||
7fd59977 | 135 | //======================================================================= |
136 | //function : Point | |
aec37c15 | 137 | //purpose : |
7fd59977 | 138 | //======================================================================= |
ac04d101 | 139 | |
7fd59977 | 140 | gp_Pnt Select3D_SensitivePoint::Point() const |
141 | {return mypoint;} | |
142 | ||
143 | //======================================================================= | |
144 | //function : GetConnected | |
aec37c15 | 145 | //purpose : |
7fd59977 | 146 | //======================================================================= |
147 | ||
aec37c15 | 148 | Handle(Select3D_SensitiveEntity) Select3D_SensitivePoint::GetConnected(const TopLoc_Location& aLoc) |
7fd59977 | 149 | { |
150 | Handle(Select3D_SensitivePoint) NiouEnt = new Select3D_SensitivePoint(myOwnerId,mypoint); | |
151 | if(HasLocation()) NiouEnt->SetLocation(Location()); | |
152 | NiouEnt->UpdateLocation(aLoc); | |
153 | return NiouEnt; | |
154 | } | |
155 | ||
7fd59977 | 156 | //======================================================================= |
157 | //function : Dump | |
aec37c15 | 158 | //purpose : |
7fd59977 | 159 | //======================================================================= |
160 | ||
35e08fe8 | 161 | void Select3D_SensitivePoint::Dump(Standard_OStream& S,const Standard_Boolean /*FullDump*/) const |
7fd59977 | 162 | { |
163 | S<<"\tSensitivePoint 3D :"; | |
164 | if(HasLocation()) | |
165 | S<<"\t\tExisting Location"<<endl; | |
166 | ||
167 | S<<"\t\t P3d [ "<<mypoint.x<<" , "<<mypoint.y<<" , "<<mypoint.z<<" ]"<<endl; | |
168 | S<<"\t\t P2d [ "<<myprojpt.x<<" , "<<myprojpt.y<<" ]"<<endl; | |
169 | } | |
170 | ||
171 | //======================================================================= | |
172 | //function : ComputeDepth | |
aec37c15 | 173 | //purpose : |
7fd59977 | 174 | //======================================================================= |
175 | ||
176 | Standard_Real Select3D_SensitivePoint::ComputeDepth(const gp_Lin& EyeLine) const | |
177 | { | |
178 | return ElCLib::Parameter(EyeLine,mypoint); | |
179 | } |