d5f169599bfd7acf2dd893f0f146f722c8dce970
[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
19 IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveBox,Select3D_SensitiveEntity)
20
21 //==================================================
22 // Function: Select3D_SensitiveBox
23 // Purpose :
24 //==================================================
25 Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectMgr_EntityOwner)& theOwnerId,
26                                               const Bnd_Box& theBox)
27 : Select3D_SensitiveEntity (theOwnerId)
28 {
29   Standard_Real aXMax, aYMax, aZMax;
30   Standard_Real aXMin, aYMin, aZMin;
31   theBox.Get (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
32   myBox = Select3D_BndBox3d (SelectMgr_Vec3 (aXMin, aYMin, aZMin),
33                              SelectMgr_Vec3 (aXMax, aYMax, aZMax));
34   myCenter3d = (gp_XYZ (aXMin, aYMin, aZMin) + gp_XYZ (aXMax, aYMax, aZMax))
35                 * (1.0 / 2.0);
36 }
37
38 //==================================================
39 // Function: Select3D_SensitiveBox
40 // Purpose :
41 //==================================================
42
43 Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectMgr_EntityOwner)& theOwnerId,
44                                               const Standard_Real theXMin,
45                                               const Standard_Real theYMin,
46                                               const Standard_Real theZMin,
47                                               const Standard_Real theXMax,
48                                               const Standard_Real theYMax,
49                                               const Standard_Real theZMax)
50 : Select3D_SensitiveEntity (theOwnerId)
51 {
52   myBox = Select3D_BndBox3d (SelectMgr_Vec3 (theXMin, theYMin, theZMin),
53                              SelectMgr_Vec3 (theXMax, theYMax, theZMax));
54   myCenter3d = (gp_XYZ (theXMin, theYMin, theZMin) + gp_XYZ (theXMax, theYMax, theZMax))
55                 * (1.0 / 2.0);
56 }
57
58 //=======================================================================
59 // function : NbSubElements
60 // purpose  : Returns the amount of sub-entities in sensitive
61 //=======================================================================
62 Standard_Integer Select3D_SensitiveBox::NbSubElements()
63 {
64   return 1;
65 }
66
67 //=======================================================================
68 //function : GetConnected
69 //purpose  : 
70 //=======================================================================
71
72 Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected()
73 {
74   Bnd_Box aBox;
75   aBox.Update (myBox.CornerMin().x(), myBox.CornerMin().y(), myBox.CornerMin().z(),
76                myBox.CornerMax().x(), myBox.CornerMax().y(), myBox.CornerMax().z());
77   Handle(Select3D_SensitiveBox) aNewEntity =  new Select3D_SensitiveBox (myOwnerId, aBox);
78
79   return aNewEntity;
80 }
81
82 //=======================================================================
83 // function : Matches
84 // purpose  : Checks whether the box overlaps current selecting volume
85 //=======================================================================
86 Standard_Boolean Select3D_SensitiveBox::Matches (SelectBasics_SelectingVolumeManager& theMgr,
87                                                  SelectBasics_PickResult& thePickResult)
88 {
89   if (!theMgr.IsOverlapAllowed()) // check for inclusion
90   {
91     Standard_Boolean isInside = Standard_True;
92     return theMgr.Overlaps (myBox.CornerMin(), myBox.CornerMax(), &isInside) && isInside;
93   }
94
95   if (!theMgr.Overlaps (myBox.CornerMin(), myBox.CornerMax(), thePickResult)) // check for overlap
96   {
97     return Standard_False;
98   }
99
100   thePickResult.SetDistToGeomCenter (theMgr.DistToGeometryCenter(myCenter3d));
101   return Standard_True;
102 }
103
104 //=======================================================================
105 // function : CenterOfGeometry
106 // purpose  : Returns center of the box. If location transformation
107 //            is set, it will be applied
108 //=======================================================================
109 gp_Pnt Select3D_SensitiveBox::CenterOfGeometry() const
110 {
111   return myCenter3d;
112 }
113
114 //=======================================================================
115 // function : BoundingBox
116 // purpose  : Returns coordinates of the box. If location transformation
117 //            is set, it will be applied
118 //=======================================================================
119 Select3D_BndBox3d Select3D_SensitiveBox::BoundingBox()
120 {
121   return myBox;
122 }