0026195: Visualization - optimize selection algorithms
[occt.git] / src / Select3D / Select3D_SensitiveEntity.hxx
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 <Standard.hxx>
21 #include <Standard_Type.hxx>
22
23 #include <SelectBasics_SensitiveEntity.hxx>
24 #include <Standard_Boolean.hxx>
25 #include <Standard_Integer.hxx>
26 #include <SelectMgr_SelectingVolumeManager.hxx>
27 #include <Standard_Real.hxx>
28 #include <Standard_OStream.hxx>
29
30 #include <TopLoc_Location.hxx>
31
32 class Select3D_SensitiveEntity;
33 class SelectBasics_EntityOwner;
34
35 //!  Abstract framework to define 3D sensitive entities.
36 //! As the selection process uses the principle of a
37 //! projection of 3D shapes onto a 2D view where
38 //! nearness to a rectangle determines whether a shape
39 //! is picked or not, all 3D shapes need to be converted
40 //! into 2D ones in order to be selected.
41 class Select3D_SensitiveEntity : public SelectBasics_SensitiveEntity
42 {
43 public:
44
45   //! Originally this method intended to return sensitive
46   //! entity with new location aLocation, but currently sensitive
47   //! entities do not hold a location, instead HasLocation() and
48   //! Location() methods call corresponding entity owner's methods.
49   //! Thus all entities returned by GetConnected() share the same
50   //! location propagated from corresponding selectable object.
51   //! You must redefine this function for any type of
52   //! sensitive entity which can accept another connected
53   //! sensitive entity.//can be connected to another sensitive entity.
54   Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected();
55
56   //! Checks whether sensitive overlaps current selecting volume.
57   //! Stores minimum depth, distance to center of geometry and
58   //! closest point detected into thePickResult
59   Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
60                                                     SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
61
62   //! Returns the number of sub-entities or elements in
63   //! sensitive entity. Is used to determine if entity is
64   //! complex and needs to pre-build BVH at the creation of
65   //! sensitive entity step or is light-weighted so the tree
66   //! can be build on demand with unnoticeable delay
67   virtual Standard_Integer NbSubElements() = 0;
68
69   //! Returns bounding box of a sensitive with transformation applied
70   virtual Select3D_BndBox3d BoundingBox() = 0;
71
72   //! Returns center of a sensitive with transformation applied
73   virtual gp_Pnt CenterOfGeometry() const = 0;
74
75   //! Builds BVH tree for a sensitive if needed
76   Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
77
78   //! Clears up all resources and memory
79   Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
80
81   //! Returns true if the shape corresponding to the entity has init location
82   Standard_EXPORT virtual Standard_Boolean HasInitLocation() const Standard_OVERRIDE;
83
84   //! Returns inversed location transformation matrix if the shape corresponding
85   //! to this entity has init location set. Otherwise, returns identity matrix.
86   Standard_EXPORT virtual gp_Trsf InvInitLocation() const;
87
88   DEFINE_STANDARD_RTTI(Select3D_SensitiveEntity, SelectBasics_SensitiveEntity)
89
90 protected:
91
92   Standard_EXPORT Select3D_SensitiveEntity (const Handle(SelectBasics_EntityOwner)& theOwnerId);
93 };
94
95 DEFINE_STANDARD_HANDLE(Select3D_SensitiveEntity, SelectBasics_SensitiveEntity)
96
97 #endif // _Select3D_SensitiveEntity_HeaderFile