0029938: Visualization - SelectMgr_ViewerSelector::PickedPoint() should return point...
[occt.git] / src / MeshVS / MeshVS_CommonSensitiveEntity.hxx
1 // Created on: 2016-02-18
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2016 OPEN CASCADE SAS
4 //
5 // This file is part of Open CASCADE Technology software library.
6 //
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
12 //
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
15
16 #ifndef _MeshVS_CommonSensitiveEntity_Header
17 #define _MeshVS_CommonSensitiveEntity_Header
18
19 #include <MeshVS_DataSource.hxx>
20 #include <MeshVS_Mesh.hxx>
21 #include <MeshVS_MeshSelectionMethod.hxx>
22 #include <Select3D_SensitiveSet.hxx>
23
24 //! Sensitive entity covering entire mesh for global selection.
25 class MeshVS_CommonSensitiveEntity : public Select3D_SensitiveSet
26 {
27   DEFINE_STANDARD_RTTIEXT (MeshVS_CommonSensitiveEntity, Select3D_SensitiveSet)
28 public:
29
30   //! Default constructor.
31   Standard_EXPORT MeshVS_CommonSensitiveEntity (const Handle(SelectBasics_EntityOwner)& theOwner,
32                                                 const Handle(MeshVS_Mesh)&              theParentMesh,
33                                                 const MeshVS_MeshSelectionMethod        theSelMethod);
34
35   //! Destructor.
36   Standard_EXPORT virtual ~MeshVS_CommonSensitiveEntity();
37
38   //! Number of elements.
39   Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
40
41   //! Returns the amount of sub-entities of the complex entity
42   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
43
44   //! Returns bounding box of sub-entity with index theIdx in sub-entity list
45   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
46
47   //! Returns geometry center of sensitive entity index theIdx along the given axis theAxis
48   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
49                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
50
51   //! Swaps items with indexes theIdx1 and theIdx2
52   Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
53                                      const Standard_Integer theIdx2) Standard_OVERRIDE;
54
55   //! Returns bounding box of the triangulation. If location
56   //! transformation is set, it will be applied
57   Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
58
59   //! Returns center of a mesh
60   Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
61
62   //! Create a copy.
63   virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE { return new MeshVS_CommonSensitiveEntity (*this); }
64
65 protected:
66
67   //! Checks whether the entity with index theIdx overlaps the current selecting volume
68   Standard_EXPORT virtual Standard_Boolean overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
69                                                             Standard_Integer theElemIdx,
70                                                             SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
71
72   //! Checks whether the entity with index theIdx is inside the current selecting volume
73   Standard_EXPORT virtual Standard_Boolean elementIsInside (SelectBasics_SelectingVolumeManager& theMgr,
74                                                             const Standard_Integer theElemIdx) Standard_OVERRIDE;
75
76   //! Calculates distance from the 3d projection of used-picked screen point to center of the geometry
77   Standard_EXPORT virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
78
79   //! Protected copy constructor.
80   Standard_EXPORT MeshVS_CommonSensitiveEntity (const MeshVS_CommonSensitiveEntity& theOther);
81
82 private:
83
84   //! Return point for specified index.
85   gp_Pnt getVertexByIndex (const Standard_Integer theNodeIdx) const;
86
87 private:
88
89   Handle(MeshVS_DataSource)            myDataSource;   //!< mesh data source
90   NCollection_Vector<Standard_Integer> myItemIndexes;  //!< indices for BVH tree reordering
91   MeshVS_MeshSelectionMethod           mySelMethod;    //!< selection mode
92   Standard_Integer                     myMaxFaceNodes; //!< maximum nodes within the element in mesh
93   gp_Pnt                               myCOG;          //!< center of gravity
94   Select3D_BndBox3d                    myBndBox;       //!< bounding box
95
96 };
97
98 DEFINE_STANDARD_HANDLE (MeshVS_CommonSensitiveEntity, Select3D_SensitiveSet)
99
100 #endif // _MeshVS_CommonSensitiveEntity_Header