0026344: Visualization - provide a support of zoom persistent selection
[occt.git] / src / SelectMgr / SelectMgr_SelectableObjectSet.hxx
1 // Created on: 2014-08-15
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 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 _SelectMgr_SelectableObjectSet_HeaderFile
17 #define _SelectMgr_SelectableObjectSet_HeaderFile
18
19 #include <BVH_PrimitiveSet.hxx>
20
21 #include <Select3D_BndBox3d.hxx>
22 #include <SelectMgr_SelectableObject.hxx>
23 #include <SelectMgr_VectorTypes.hxx>
24
25 #include <NCollection_IndexedMap.hxx>
26
27 //! The purpose of this class is to organize all selectable objects into
28 //! data structure, allowing to build BVH tree. For selectable objects
29 //! binned BVH builder is used with 32 bins and 1 element per leaf.
30 class SelectMgr_SelectableObjectSet : public BVH_PrimitiveSet<Standard_Real, 3>
31 {
32   Handle(SelectMgr_SelectableObject) EMPTY_OBJ;
33
34 public:
35
36   //! Creates new empty objects set and initializes BVH tree
37   //! builder to Binned builder with 1 element per list
38   Standard_EXPORT SelectMgr_SelectableObjectSet();
39
40   //! Releases resources of selectable object set.
41   virtual ~SelectMgr_SelectableObjectSet() { }
42
43   //! Adds new object to the set and marks BVH tree for rebuild.
44   //! @return true if structure added, otherwise returns false (structure already in the set).
45   Standard_EXPORT Standard_Boolean Append (const Handle(SelectMgr_SelectableObject)& theObject);
46
47   //! Removes object theObject from set and marks BVH tree for rebuild.
48   //! @return true if structure removed, otherwise returns false (structure is not in the set).
49   Standard_EXPORT Standard_Boolean Remove (const Handle(SelectMgr_SelectableObject)& theObject);
50
51   //! Returns bounding box of object with index theIndex
52   Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIndex) const Standard_OVERRIDE;
53
54   //! Returns center of object with index theIndex in the set
55   //! along the given axis theAxis
56   Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIndex,
57                                                 const Standard_Integer theAxis) const Standard_OVERRIDE;
58
59   //! Swaps items with indexes theIndex1 and theIndex2 in the set
60   Standard_EXPORT virtual void Swap (const Standard_Integer theIndex1,
61                                      const Standard_Integer theIndex2) Standard_OVERRIDE;
62
63   //! Returns size of objects set
64   Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
65
66   //! Returns object from set by theIndex given
67   const Handle(SelectMgr_SelectableObject)& GetObjectById (const Standard_Integer theIndex) const
68   {
69     return myObjects.FindKey (theIndex + 1);
70   }
71
72   //! Returns true if this objects set contains theObject given
73   Standard_Boolean Contains (const Handle(SelectMgr_SelectableObject)& theObject) const
74   {
75     return myObjects.Contains (theObject);
76   }
77
78 private:
79
80   NCollection_IndexedMap<Handle(SelectMgr_SelectableObject)> myObjects;
81 };
82
83 #endif // _SelectMgr_SelectableObjectSet_HeaderFile