0024947: Redesign OCCT legacy type system -- automatic
[occt.git] / src / Select3D / Select3D_SensitiveBox.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <Select3D_SensitiveBox.hxx>
18 #include <gp_Pnt2d.hxx>
19 #include <gp_Pnt.hxx>
20 #include <Bnd_Box.hxx>
21 #include <ElCLib.hxx>
22
23
24 //==================================================
25 // Function: Select3D_SensitiveBox
26 // Purpose :
27 //==================================================
28 Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectBasics_EntityOwner)& theOwnerId,
29                                               const Bnd_Box& theBox)
30 : Select3D_SensitiveEntity (theOwnerId)
31 {
32   Standard_Real aXMax, aYMax, aZMax;
33   Standard_Real aXMin, aYMin, aZMin;
34   theBox.Get (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
35   myBox = Select3D_BndBox3d (SelectMgr_Vec3 (aXMin, aYMin, aZMin),
36                              SelectMgr_Vec3 (aXMax, aYMax, aZMax));
37   myCenter3d = (gp_XYZ (aXMin, aYMin, aZMin) + gp_XYZ (aXMax, aYMax, aZMax))
38                 * (1.0 / 2.0);
39 }
40
41 //==================================================
42 // Function: Select3D_SensitiveBox
43 // Purpose :
44 //==================================================
45
46 Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectBasics_EntityOwner)& theOwnerId,
47                                               const Standard_Real theXMin,
48                                               const Standard_Real theYMin,
49                                               const Standard_Real theZMin,
50                                               const Standard_Real theXMax,
51                                               const Standard_Real theYMax,
52                                               const Standard_Real theZMax)
53 : Select3D_SensitiveEntity (theOwnerId)
54 {
55   myBox = Select3D_BndBox3d (SelectMgr_Vec3 (theXMin, theYMin, theZMin),
56                              SelectMgr_Vec3 (theXMax, theYMax, theZMax));
57   myCenter3d = (gp_XYZ (theXMin, theYMin, theZMin) + gp_XYZ (theXMax, theYMax, theZMax))
58                 * (1.0 / 2.0);
59 }
60
61 //=======================================================================
62 // function : NbSubElements
63 // purpose  : Returns the amount of sub-entities in sensitive
64 //=======================================================================
65 Standard_Integer Select3D_SensitiveBox::NbSubElements()
66 {
67   return 1;
68 }
69
70 //=======================================================================
71 //function : GetConnected
72 //purpose  : 
73 //=======================================================================
74
75 Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected()
76 {
77   Bnd_Box aBox;
78   aBox.Update (myBox.CornerMin().x(), myBox.CornerMin().y(), myBox.CornerMin().z(),
79                myBox.CornerMax().x(), myBox.CornerMax().y(), myBox.CornerMax().z());
80   Handle(Select3D_SensitiveBox) aNewEntity =  new Select3D_SensitiveBox (myOwnerId, aBox);
81
82   return aNewEntity;
83 }
84
85 //=======================================================================
86 // function : Matches
87 // purpose  : Checks whether the box overlaps current selecting volume
88 //=======================================================================
89 Standard_Boolean Select3D_SensitiveBox::Matches (SelectBasics_SelectingVolumeManager& theMgr,
90                                                  SelectBasics_PickResult& thePickResult)
91 {
92   thePickResult = SelectBasics_PickResult (RealLast(), RealLast());
93
94   if (!theMgr.IsOverlapAllowed()) // check for inclusion
95   {
96     Standard_Boolean isInside = Standard_True;
97     return theMgr.Overlaps (myBox.CornerMin(), myBox.CornerMax(), &isInside) && isInside;
98   }
99
100   Standard_Real aDepth;
101   if (!theMgr.Overlaps (myBox, aDepth)) // check for overlap
102   {
103     return Standard_False;
104   }
105
106   thePickResult = SelectBasics_PickResult (
107     aDepth, theMgr.DistToGeometryCenter (myCenter3d));
108
109   return Standard_True;
110 }
111
112 //=======================================================================
113 // function : CenterOfGeometry
114 // purpose  : Returns center of the box. If location transformation
115 //            is set, it will be applied
116 //=======================================================================
117 gp_Pnt Select3D_SensitiveBox::CenterOfGeometry() const
118 {
119   return myCenter3d;
120 }
121
122 //=======================================================================
123 // function : BoundingBox
124 // purpose  : Returns coordinates of the box. If location transformation
125 //            is set, it will be applied
126 //=======================================================================
127 Select3D_BndBox3d Select3D_SensitiveBox::BoundingBox()
128 {
129   return myBox;
130 }
131
132 //=======================================================================
133 // function : Box
134 // purpose  :
135 //=======================================================================
136 Bnd_Box Select3D_SensitiveBox::Box() const
137 {
138   Bnd_Box aBox;
139   aBox.Update (myBox.CornerMin().x(), myBox.CornerMin().y(), myBox.CornerMin().z(),
140                myBox.CornerMax().x(), myBox.CornerMax().y(), myBox.CornerMax().z());
141
142   return aBox;
143 }