1 // Created on: 1995-04-13
2 // Created by: Robert COUBLANC
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_SensitiveBox.ixx>
18 #include <gp_Pnt2d.hxx>
20 #include <Bnd_Box.hxx>
25 //==================================================
26 // Function: Constructor
28 //==================================================
30 Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
32 Select3D_SensitiveEntity(OwnerId),
35 //==================================================
36 // Function: Constructor
38 //==================================================
40 Select3D_SensitiveBox::
41 Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
42 const Standard_Real XMin,
43 const Standard_Real YMin,
44 const Standard_Real ZMin,
45 const Standard_Real XMax,
46 const Standard_Real YMax,
47 const Standard_Real ZMax):
48 Select3D_SensitiveEntity(OwnerId)
50 mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax);
53 //==================================================
56 //==================================================
58 void Select3D_SensitiveBox::
59 Project(const Handle(Select3D_Projector)& aProj)
63 Bnd_Box B = mybox3d.Transformed(Location().Transformation());
67 ProjectBox(aProj,mybox3d);
70 //==================================================
73 //==================================================
75 void Select3D_SensitiveBox::
76 Areas(SelectBasics_ListOfBox2d& aSeq)
77 { aSeq.Append(mybox2d);}
79 //=======================================================================
80 //function : GetConnected
82 //=======================================================================
84 Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLoc_Location& aLoc)
86 Handle(Select3D_SensitiveBox) NiouEnt = new Select3D_SensitiveBox(myOwnerId,mybox3d);
88 if(HasLocation()) NiouEnt->SetLocation(Location());
89 NiouEnt->UpdateLocation(aLoc);
93 //==================================================
96 //==================================================
98 Standard_Boolean Select3D_SensitiveBox::Matches (const SelectBasics_PickArgs& thePickArgs,
99 Standard_Real& theMatchDMin,
100 Standard_Real& theMatchDepth)
102 // check that sensitive box passes by depth
103 Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
104 if (thePickArgs.IsClipped (aDepth))
106 return Standard_False;
110 theMatchDepth = aDepth;
111 return Standard_True;
114 //==================================================
117 //==================================================
119 Standard_Boolean Select3D_SensitiveBox::
120 Matches (const Standard_Real XMin,
121 const Standard_Real YMin,
122 const Standard_Real XMax,
123 const Standard_Real YMax,
124 const Standard_Real aTol)
127 BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
128 return(!BoundBox.IsOut(mybox2d));
131 //=======================================================================
134 //=======================================================================
136 Standard_Boolean Select3D_SensitiveBox::
137 Matches (const TColgp_Array1OfPnt2d& /*aPoly*/,
138 const Bnd_Box2d& aBox,
139 const Standard_Real /*aTol*/)
141 return(!aBox.IsOut(mybox2d));
144 //=======================================================================
147 //=======================================================================
149 void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
151 S<<"\tSensitiveBox 3D :\n";
153 S<<"\t\tExisting Location"<<endl;
155 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
156 mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
158 S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]";
159 S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl;
163 // S<<"\t\t\tOwner:"<<myOwnerId<<endl;
164 Select3D_SensitiveEntity::DumpBox(S,mybox2d);
169 //=======================================================================
170 //function : ProjectBox
172 //=======================================================================
174 void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj,
179 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
180 aBox.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
182 aPrj->Project(gp_Pnt(XMin,YMin,ZMin),curp2d);
183 mybox2d.Update(curp2d.X(),curp2d.Y());
184 aPrj->Project(gp_Pnt(XMax,YMin,ZMin),curp2d);
185 mybox2d.Update(curp2d.X(),curp2d.Y());
186 aPrj->Project(gp_Pnt(XMax,YMax,ZMin),curp2d);
187 mybox2d.Update(curp2d.X(),curp2d.Y());
188 aPrj->Project(gp_Pnt(XMin,YMax,ZMin),curp2d);
189 mybox2d.Update(curp2d.X(),curp2d.Y());
190 aPrj->Project(gp_Pnt(XMin,YMin,ZMax),curp2d);
191 mybox2d.Update(curp2d.X(),curp2d.Y());
192 aPrj->Project(gp_Pnt(XMax,YMin,ZMax),curp2d);
193 mybox2d.Update(curp2d.X(),curp2d.Y());
194 aPrj->Project(gp_Pnt(XMax,YMax,ZMax),curp2d);
195 mybox2d.Update(curp2d.X(),curp2d.Y());
196 aPrj->Project(gp_Pnt(XMin,YMax,ZMax),curp2d);
197 mybox2d.Update(curp2d.X(),curp2d.Y());
200 //=======================================================================
201 //function : ComputeDepth
203 //=======================================================================
205 Standard_Real Select3D_SensitiveBox::ComputeDepth(const gp_Lin& EyeLine) const
207 Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
208 mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
209 gp_Pnt PMid((XMin+XMax)/2.,(YMin+YMax)/2.,(ZMin+ZMax)/2.);
210 return ElCLib::Parameter(EyeLine,PMid);