| 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 | |
| 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, |
| 38 | const Bnd_Box& BBox): |
| 39 | Select3D_SensitiveEntity(OwnerId), |
| 40 | mybox3d(BBox){} |
| 41 | |
| 42 | //================================================== |
| 43 | // Function: Constructor |
| 44 | // Purpose : |
| 45 | //================================================== |
| 46 | |
| 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) |
| 56 | { |
| 57 | mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax); |
| 58 | } |
| 59 | |
| 60 | //================================================== |
| 61 | // Function: Project |
| 62 | // Purpose : |
| 63 | //================================================== |
| 64 | |
| 65 | void Select3D_SensitiveBox:: |
| 66 | Project(const Handle(Select3D_Projector)& aProj) |
| 67 | { |
| 68 | if(HasLocation()) |
| 69 | { |
| 70 | Bnd_Box B = mybox3d.Transformed(Location().Transformation()); |
| 71 | ProjectBox(aProj,B); |
| 72 | } |
| 73 | else |
| 74 | ProjectBox(aProj,mybox3d); |
| 75 | } |
| 76 | |
| 77 | //================================================== |
| 78 | // Function: Areas |
| 79 | // Purpose : |
| 80 | //================================================== |
| 81 | |
| 82 | void Select3D_SensitiveBox:: |
| 83 | Areas(SelectBasics_ListOfBox2d& aSeq) |
| 84 | { aSeq.Append(mybox2d);} |
| 85 | |
| 86 | //======================================================================= |
| 87 | //function : GetConnected |
| 88 | //purpose : |
| 89 | //======================================================================= |
| 90 | |
| 91 | Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLoc_Location& aLoc) |
| 92 | { |
| 93 | Handle(Select3D_SensitiveBox) NiouEnt = new Select3D_SensitiveBox(myOwnerId,mybox3d); |
| 94 | |
| 95 | if(HasLocation()) NiouEnt->SetLocation(Location()); |
| 96 | NiouEnt->UpdateLocation(aLoc); |
| 97 | return NiouEnt; |
| 98 | } |
| 99 | |
| 100 | //================================================== |
| 101 | // Function: Matches |
| 102 | // Purpose : |
| 103 | //================================================== |
| 104 | |
| 105 | Standard_Boolean Select3D_SensitiveBox::Matches (const SelectBasics_PickArgs& thePickArgs, |
| 106 | Standard_Real& theMatchDMin, |
| 107 | Standard_Real& theMatchDepth) |
| 108 | { |
| 109 | // check that sensitive box passes by depth |
| 110 | Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine()); |
| 111 | if (thePickArgs.IsClipped (aDepth)) |
| 112 | { |
| 113 | return Standard_False; |
| 114 | } |
| 115 | |
| 116 | theMatchDMin = 0.0; |
| 117 | theMatchDepth = aDepth; |
| 118 | return Standard_True; |
| 119 | } |
| 120 | |
| 121 | //================================================== |
| 122 | // Function: Matches |
| 123 | // Purpose : |
| 124 | //================================================== |
| 125 | |
| 126 | Standard_Boolean Select3D_SensitiveBox:: |
| 127 | Matches (const Standard_Real XMin, |
| 128 | const Standard_Real YMin, |
| 129 | const Standard_Real XMax, |
| 130 | const Standard_Real YMax, |
| 131 | const Standard_Real aTol) |
| 132 | { |
| 133 | Bnd_Box2d BoundBox; |
| 134 | BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol); |
| 135 | return(!BoundBox.IsOut(mybox2d)); |
| 136 | } |
| 137 | |
| 138 | //======================================================================= |
| 139 | //function : Matches |
| 140 | //purpose : |
| 141 | //======================================================================= |
| 142 | |
| 143 | Standard_Boolean Select3D_SensitiveBox:: |
| 144 | Matches (const TColgp_Array1OfPnt2d& /*aPoly*/, |
| 145 | const Bnd_Box2d& aBox, |
| 146 | const Standard_Real /*aTol*/) |
| 147 | { |
| 148 | return(!aBox.IsOut(mybox2d)); |
| 149 | } |
| 150 | |
| 151 | //======================================================================= |
| 152 | //function : Dump |
| 153 | //purpose : |
| 154 | //======================================================================= |
| 155 | |
| 156 | void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const |
| 157 | { |
| 158 | S<<"\tSensitiveBox 3D :\n"; |
| 159 | if(HasLocation()) |
| 160 | S<<"\t\tExisting Location"<<endl; |
| 161 | |
| 162 | Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax; |
| 163 | mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax); |
| 164 | |
| 165 | S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]"; |
| 166 | S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl; |
| 167 | |
| 168 | if(FullDump) |
| 169 | { |
| 170 | // S<<"\t\t\tOwner:"<<myOwnerId<<endl; |
| 171 | Select3D_SensitiveEntity::DumpBox(S,mybox2d); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | |
| 176 | //======================================================================= |
| 177 | //function : ProjectBox |
| 178 | //purpose : |
| 179 | //======================================================================= |
| 180 | |
| 181 | void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj, |
| 182 | const Bnd_Box& aBox) |
| 183 | { |
| 184 | mybox2d.SetVoid(); |
| 185 | gp_Pnt2d curp2d; |
| 186 | Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax; |
| 187 | aBox.Get(XMin,YMin,ZMin,XMax,YMax,ZMax); |
| 188 | |
| 189 | aPrj->Project(gp_Pnt(XMin,YMin,ZMin),curp2d); |
| 190 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 191 | aPrj->Project(gp_Pnt(XMax,YMin,ZMin),curp2d); |
| 192 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 193 | aPrj->Project(gp_Pnt(XMax,YMax,ZMin),curp2d); |
| 194 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 195 | aPrj->Project(gp_Pnt(XMin,YMax,ZMin),curp2d); |
| 196 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 197 | aPrj->Project(gp_Pnt(XMin,YMin,ZMax),curp2d); |
| 198 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 199 | aPrj->Project(gp_Pnt(XMax,YMin,ZMax),curp2d); |
| 200 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 201 | aPrj->Project(gp_Pnt(XMax,YMax,ZMax),curp2d); |
| 202 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 203 | aPrj->Project(gp_Pnt(XMin,YMax,ZMax),curp2d); |
| 204 | mybox2d.Update(curp2d.X(),curp2d.Y()); |
| 205 | } |
| 206 | |
| 207 | //======================================================================= |
| 208 | //function : ComputeDepth |
| 209 | //purpose : |
| 210 | //======================================================================= |
| 211 | |
| 212 | Standard_Real Select3D_SensitiveBox::ComputeDepth(const gp_Lin& EyeLine) const |
| 213 | { |
| 214 | Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax; |
| 215 | mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax); |
| 216 | gp_Pnt PMid((XMin+XMax)/2.,(YMin+YMax)/2.,(ZMin+ZMax)/2.); |
| 217 | return ElCLib::Parameter(EyeLine,PMid); |
| 218 | } |