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
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.
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.
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.
24 #include <Select3D_SensitiveBox.ixx>
25 #include <gp_Pnt2d.hxx>
27 #include <Bnd_Box.hxx>
32 //==================================================
33 // Function: Constructor
35 //==================================================
37 Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
39 Select3D_SensitiveEntity(OwnerId),
42 //==================================================
43 // Function: Constructor
45 //==================================================
47 Select3D_SensitiveBox::
48 Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
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):
55 Select3D_SensitiveEntity(OwnerId)
57 mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax);
60 //==================================================
63 //==================================================
65 void Select3D_SensitiveBox::
66 Project(const Handle(Select3D_Projector)& aProj)
68 Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
72 Bnd_Box B = mybox3d.Transformed(Location().Transformation());
76 ProjectBox(aProj,mybox3d);
79 //==================================================
82 //==================================================
84 void Select3D_SensitiveBox::
85 Areas(SelectBasics_ListOfBox2d& aSeq)
86 { aSeq.Append(mybox2d);}
88 //=======================================================================
89 //function : GetConnected
91 //=======================================================================
93 Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLoc_Location& aLoc)
95 Handle(Select3D_SensitiveBox) NiouEnt = new Select3D_SensitiveBox(myOwnerId,mybox3d);
97 if(HasLocation()) NiouEnt->SetLocation(Location());
98 NiouEnt->UpdateLocation(aLoc);
102 //==================================================
105 //==================================================
106 Standard_Boolean Select3D_SensitiveBox::
107 Matches(const Standard_Real X,
108 const Standard_Real Y,
109 const Standard_Real aTol,
112 Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
115 return Standard_True;
118 //==================================================
121 //==================================================
123 Standard_Boolean Select3D_SensitiveBox::
124 Matches (const Standard_Real XMin,
125 const Standard_Real YMin,
126 const Standard_Real XMax,
127 const Standard_Real YMax,
128 const Standard_Real aTol)
131 BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
132 return(!BoundBox.IsOut(mybox2d));
135 //=======================================================================
138 //=======================================================================
140 Standard_Boolean Select3D_SensitiveBox::
141 Matches (const TColgp_Array1OfPnt2d& /*aPoly*/,
142 const Bnd_Box2d& aBox,
143 const Standard_Real /*aTol*/)
145 return(!aBox.IsOut(mybox2d));
148 //=======================================================================
151 //=======================================================================
153 void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
155 S<<"\tSensitiveBox 3D :\n";
157 S<<"\t\tExisting Location"<<endl;
159 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
160 mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
162 S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]";
163 S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl;
167 // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
168 Select3D_SensitiveEntity::DumpBox(S,mybox2d);
173 //=======================================================================
174 //function : ProjectBox
176 //=======================================================================
178 void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj,
183 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
184 aBox.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
186 aPrj->Project(gp_Pnt(XMin,YMin,ZMin),curp2d);
187 mybox2d.Update(curp2d.X(),curp2d.Y());
188 aPrj->Project(gp_Pnt(XMax,YMin,ZMin),curp2d);
189 mybox2d.Update(curp2d.X(),curp2d.Y());
190 aPrj->Project(gp_Pnt(XMax,YMax,ZMin),curp2d);
191 mybox2d.Update(curp2d.X(),curp2d.Y());
192 aPrj->Project(gp_Pnt(XMin,YMax,ZMin),curp2d);
193 mybox2d.Update(curp2d.X(),curp2d.Y());
194 aPrj->Project(gp_Pnt(XMin,YMin,ZMax),curp2d);
195 mybox2d.Update(curp2d.X(),curp2d.Y());
196 aPrj->Project(gp_Pnt(XMax,YMin,ZMax),curp2d);
197 mybox2d.Update(curp2d.X(),curp2d.Y());
198 aPrj->Project(gp_Pnt(XMax,YMax,ZMax),curp2d);
199 mybox2d.Update(curp2d.X(),curp2d.Y());
200 aPrj->Project(gp_Pnt(XMin,YMax,ZMax),curp2d);
201 mybox2d.Update(curp2d.X(),curp2d.Y());
204 //=======================================================================
205 //function : ComputeDepth
207 //=======================================================================
209 Standard_Real Select3D_SensitiveBox::ComputeDepth(const gp_Lin& EyeLine) const
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);