Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-04-13 |
2 | // Created by: Robert COUBLANC | |
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_SensitiveBox.ixx> | |
25 | #include <gp_Pnt2d.hxx> | |
26 | #include <gp_Pnt.hxx> | |
27 | #include <Bnd_Box.hxx> | |
28 | #include <ElCLib.hxx> | |
29 | ||
30 | ||
31 | ||
32 | //================================================== | |
33 | // Function: Constructor | |
34 | // Purpose : | |
35 | //================================================== | |
36 | ||
37 | Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId, | |
ac04d101 | 38 | const Bnd_Box& BBox): |
7fd59977 | 39 | Select3D_SensitiveEntity(OwnerId), |
40 | mybox3d(BBox){} | |
41 | ||
7fd59977 | 42 | //================================================== |
43 | // Function: Constructor | |
44 | // Purpose : | |
45 | //================================================== | |
46 | ||
47 | Select3D_SensitiveBox:: | |
48 | Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId, | |
ac04d101 SA |
49 | const Standard_Real XMin, |
50 | const Standard_Real YMin, | |
51 | const Standard_Real ZMin, | |
52 | const Standard_Real XMax, | |
53 | const Standard_Real YMax, | |
54 | const Standard_Real ZMax): | |
7fd59977 | 55 | Select3D_SensitiveEntity(OwnerId) |
56 | { | |
57 | mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax); | |
58 | } | |
59 | ||
7fd59977 | 60 | //================================================== |
61 | // Function: Project | |
62 | // Purpose : | |
63 | //================================================== | |
ac04d101 | 64 | |
7fd59977 | 65 | void Select3D_SensitiveBox:: |
4952a30a | 66 | Project(const Handle(Select3D_Projector)& aProj) |
7fd59977 | 67 | { |
68 | Select3D_SensitiveEntity::Project(aProj); // to set the field last proj... | |
4952a30a | 69 | |
ac04d101 SA |
70 | if(HasLocation()) |
71 | { | |
7fd59977 | 72 | Bnd_Box B = mybox3d.Transformed(Location().Transformation()); |
73 | ProjectBox(aProj,B); | |
74 | } | |
75 | else | |
76 | ProjectBox(aProj,mybox3d); | |
77 | } | |
78 | ||
79 | //================================================== | |
ac04d101 | 80 | // Function: Areas |
7fd59977 | 81 | // Purpose : |
82 | //================================================== | |
ac04d101 | 83 | |
7fd59977 | 84 | void Select3D_SensitiveBox:: |
85 | Areas(SelectBasics_ListOfBox2d& aSeq) | |
86 | { aSeq.Append(mybox2d);} | |
87 | ||
7fd59977 | 88 | //======================================================================= |
89 | //function : GetConnected | |
90 | //purpose : | |
91 | //======================================================================= | |
92 | ||
93 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLoc_Location& aLoc) | |
94 | { | |
95 | Handle(Select3D_SensitiveBox) NiouEnt = new Select3D_SensitiveBox(myOwnerId,mybox3d); | |
96 | ||
97 | if(HasLocation()) NiouEnt->SetLocation(Location()); | |
98 | NiouEnt->UpdateLocation(aLoc); | |
99 | return NiouEnt; | |
100 | } | |
101 | ||
7fd59977 | 102 | //================================================== |
ac04d101 | 103 | // Function: Matches |
7fd59977 | 104 | // Purpose : |
105 | //================================================== | |
106 | Standard_Boolean Select3D_SensitiveBox:: | |
ac04d101 SA |
107 | Matches(const Standard_Real X, |
108 | const Standard_Real Y, | |
109 | const Standard_Real aTol, | |
110 | Standard_Real& DMin) | |
7fd59977 | 111 | { |
112 | Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin); | |
113 | DMin=0.; | |
114 | ||
115 | return Standard_True; | |
7fd59977 | 116 | } |
117 | ||
118 | //================================================== | |
ac04d101 | 119 | // Function: Matches |
7fd59977 | 120 | // Purpose : |
121 | //================================================== | |
122 | ||
123 | Standard_Boolean Select3D_SensitiveBox:: | |
124 | Matches (const Standard_Real XMin, | |
ac04d101 SA |
125 | const Standard_Real YMin, |
126 | const Standard_Real XMax, | |
127 | const Standard_Real YMax, | |
128 | const Standard_Real aTol) | |
7fd59977 | 129 | { |
130 | Bnd_Box2d BoundBox; | |
131 | BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); | |
132 | return(!BoundBox.IsOut(mybox2d)); | |
133 | } | |
134 | ||
7fd59977 | 135 | //======================================================================= |
136 | //function : Matches | |
137 | //purpose : | |
138 | //======================================================================= | |
139 | ||
140 | Standard_Boolean Select3D_SensitiveBox:: | |
141 | Matches (const TColgp_Array1OfPnt2d& aPoly, | |
ac04d101 SA |
142 | const Bnd_Box2d& aBox, |
143 | const Standard_Real aTol) | |
144 | { | |
7fd59977 | 145 | return(!aBox.IsOut(mybox2d)); |
146 | } | |
147 | ||
7fd59977 | 148 | //======================================================================= |
149 | //function : Dump | |
150 | //purpose : | |
151 | //======================================================================= | |
152 | ||
153 | void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const | |
154 | { | |
155 | S<<"\tSensitiveBox 3D :\n"; | |
156 | if(HasLocation()) | |
157 | S<<"\t\tExisting Location"<<endl; | |
158 | ||
159 | Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax; | |
160 | mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax); | |
161 | ||
162 | S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]"; | |
163 | S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl; | |
164 | ||
ac04d101 SA |
165 | if(FullDump) |
166 | { | |
7fd59977 | 167 | // S<<"\t\t\tOwner:"<<myOwnerId<<endl; |
ac04d101 SA |
168 | Select3D_SensitiveEntity::DumpBox(S,mybox2d); |
169 | } | |
7fd59977 | 170 | } |
171 | ||
172 | ||
173 | //======================================================================= | |
174 | //function : ProjectBox | |
175 | //purpose : | |
176 | //======================================================================= | |
177 | ||
4952a30a | 178 | void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj, |
ac04d101 | 179 | const Bnd_Box& aBox) |
7fd59977 | 180 | { |
181 | mybox2d.SetVoid(); | |
182 | gp_Pnt2d curp2d; | |
183 | Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax; | |
184 | aBox.Get(XMin,YMin,ZMin,XMax,YMax,ZMax); | |
4952a30a | 185 | |
186 | aPrj->Project(gp_Pnt(XMin,YMin,ZMin),curp2d); | |
7fd59977 | 187 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
4952a30a | 188 | aPrj->Project(gp_Pnt(XMax,YMin,ZMin),curp2d); |
7fd59977 | 189 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
4952a30a | 190 | aPrj->Project(gp_Pnt(XMax,YMax,ZMin),curp2d); |
7fd59977 | 191 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
4952a30a | 192 | aPrj->Project(gp_Pnt(XMin,YMax,ZMin),curp2d); |
7fd59977 | 193 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
4952a30a | 194 | aPrj->Project(gp_Pnt(XMin,YMin,ZMax),curp2d); |
7fd59977 | 195 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
4952a30a | 196 | aPrj->Project(gp_Pnt(XMax,YMin,ZMax),curp2d); |
7fd59977 | 197 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
4952a30a | 198 | aPrj->Project(gp_Pnt(XMax,YMax,ZMax),curp2d); |
7fd59977 | 199 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
4952a30a | 200 | aPrj->Project(gp_Pnt(XMin,YMax,ZMax),curp2d); |
7fd59977 | 201 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
202 | } | |
203 | ||
204 | //======================================================================= | |
205 | //function : ComputeDepth | |
206 | //purpose : | |
207 | //======================================================================= | |
208 | ||
209 | Standard_Real Select3D_SensitiveBox::ComputeDepth(const gp_Lin& EyeLine) const | |
210 | { | |
211 | Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax; | |
212 | mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax); | |
213 | gp_Pnt PMid((XMin+XMax)/2.,(YMin+YMax)/2.,(ZMin+ZMax)/2.); | |
214 | return ElCLib::Parameter(EyeLine,PMid); | |
215 | } |