1 // Created on: 1995-03-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 #ifndef _Select3D_SensitiveEntity_HeaderFile
18 #define _Select3D_SensitiveEntity_HeaderFile
19 
20 #include <gp_GTrsf.hxx>
21 #include <gp_Trsf.hxx>
22 #include <Standard_Assert.hxx>
23 #include <Standard_Transient.hxx>
24 #include <Select3D_BndBox3d.hxx>
25 #include <SelectBasics_SelectingVolumeManager.hxx>
26 #include <SelectBasics_PickResult.hxx>
27 #include <SelectBasics_SensitiveEntity.hxx>
28 #include <SelectMgr_SelectingVolumeManager.hxx>
29 #include <TopLoc_Location.hxx>
30 
31 class SelectMgr_EntityOwner;
32 
33 //! Abstract framework to define 3D sensitive entities.
34 class Select3D_SensitiveEntity : public Standard_Transient
35 {
36   DEFINE_STANDARD_RTTIEXT(Select3D_SensitiveEntity, Standard_Transient)
37 public:
38 
39   //! Returns pointer to owner of the entity
Handle(SelectMgr_EntityOwner)40   const Handle(SelectMgr_EntityOwner)& OwnerId() const { return myOwnerId; }
41 
42   //! Sets owner of the entity
Set(const Handle (SelectMgr_EntityOwner)& theOwnerId)43   virtual void Set (const Handle(SelectMgr_EntityOwner)& theOwnerId)
44   {
45     myOwnerId = theOwnerId;
46   }
47 
48   //! allows a better sensitivity for a specific entity in selection algorithms useful for small sized entities.
SensitivityFactor() const49   Standard_Integer SensitivityFactor() const { return mySFactor; }
50 
51   //! Allows to manage sensitivity of a particular sensitive entity
SetSensitivityFactor(const Standard_Integer theNewSens)52   void SetSensitivityFactor (const Standard_Integer theNewSens)
53   {
54     Standard_ASSERT_RAISE (theNewSens > 0, "Error! Selection sensitivity have positive value.");
55     mySFactor = theNewSens;
56   }
57 
58   //! Originally this method intended to return sensitive entity with new location aLocation,
59   //! but currently sensitive entities do not hold a location,
60   //! instead HasLocation() and Location() methods call corresponding entity owner's methods.
61   //! Thus all entities returned by GetConnected() share the same location propagated from corresponding selectable object.
62   //! You must redefine this function for any type of sensitive entity which can accept another connected sensitive entity.
GetConnected()63   virtual Handle(Select3D_SensitiveEntity) GetConnected() { return Handle(Select3D_SensitiveEntity)(); }
64 
65   //! Checks whether sensitive overlaps current selecting volume.
66   //! Stores minimum depth, distance to center of geometry and closest point detected into thePickResult
67   virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
68                                     SelectBasics_PickResult& thePickResult) = 0;
69 
70   //! Returns the number of sub-entities or elements in sensitive entity.
71   //! Is used to determine if entity is complex and needs to pre-build BVH at the creation of sensitive entity step
72   //! or is light-weighted so the tree can be build on demand with unnoticeable delay.
73   virtual Standard_Integer NbSubElements() = 0;
74 
75   //! Returns bounding box of a sensitive with transformation applied
76   virtual Select3D_BndBox3d BoundingBox() = 0;
77 
78   //! Returns center of a sensitive with transformation applied
79   virtual gp_Pnt CenterOfGeometry() const = 0;
80 
81   //! Builds BVH tree for a sensitive if needed
BVH()82   virtual void BVH() {}
83 
84   //! Clears up all resources and memory
Clear()85   virtual void Clear() { Set (Handle(SelectMgr_EntityOwner)()); }
86 
87   //! Returns true if the shape corresponding to the entity has init location
HasInitLocation() const88   virtual Standard_Boolean HasInitLocation() const { return Standard_False; }
89 
90   //! Returns inversed location transformation matrix if the shape corresponding to this entity has init location set.
91   //! Otherwise, returns identity matrix.
InvInitLocation() const92   virtual gp_GTrsf InvInitLocation() const { return gp_GTrsf(); }
93 
94 protected:
95 
96   Standard_EXPORT Select3D_SensitiveEntity (const Handle(SelectMgr_EntityOwner)& theOwnerId);
97 
98 protected:
99 
100   Handle(SelectMgr_EntityOwner) myOwnerId;
101   Standard_Integer mySFactor;
102 
103 };
104 
105 DEFINE_STANDARD_HANDLE(Select3D_SensitiveEntity, Standard_Transient)
106 
107 // for porting old code
108 typedef Select3D_SensitiveEntity SelectBasics_SensitiveEntity;
109 
110 #endif // _Select3D_SensitiveEntity_HeaderFile
111