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.hxx>
18 #include <gp_Pnt2d.hxx>
20 #include <Bnd_Box.hxx>
24 //==================================================
25 // Function: Select3D_SensitiveBox
27 //==================================================
28 Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectBasics_EntityOwner)& theOwnerId,
29 const Bnd_Box& theBox)
30 : Select3D_SensitiveEntity (theOwnerId)
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))
41 //==================================================
42 // Function: Select3D_SensitiveBox
44 //==================================================
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)
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))
61 //=======================================================================
62 // function : NbSubElements
63 // purpose : Returns the amount of sub-entities in sensitive
64 //=======================================================================
65 Standard_Integer Select3D_SensitiveBox::NbSubElements()
70 //=======================================================================
71 //function : GetConnected
73 //=======================================================================
75 Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected()
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);
85 //=======================================================================
87 // purpose : Checks whether the box overlaps current selecting volume
88 //=======================================================================
89 Standard_Boolean Select3D_SensitiveBox::Matches (SelectBasics_SelectingVolumeManager& theMgr,
90 SelectBasics_PickResult& thePickResult)
92 thePickResult = SelectBasics_PickResult (RealLast(), RealLast());
94 if (!theMgr.IsOverlapAllowed()) // check for inclusion
96 Standard_Boolean isInside = Standard_True;
97 return theMgr.Overlaps (myBox.CornerMin(), myBox.CornerMax(), &isInside) && isInside;
100 Standard_Real aDepth;
101 if (!theMgr.Overlaps (myBox, aDepth)) // check for overlap
103 return Standard_False;
106 thePickResult = SelectBasics_PickResult (
107 aDepth, theMgr.DistToGeometryCenter (myCenter3d));
109 return Standard_True;
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
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()
132 //=======================================================================
135 //=======================================================================
136 Bnd_Box Select3D_SensitiveBox::Box() const
139 aBox.Update (myBox.CornerMin().x(), myBox.CornerMin().y(), myBox.CornerMin().z(),
140 myBox.CornerMax().x(), myBox.CornerMax().y(), myBox.CornerMax().z());