1 // Created on: 2014-08-15
2 // Created by: Varvara POSKONINA
3 // Copyright (c) 2005-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
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.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 #include <Bnd_Box.hxx>
17 #include <BVH_BinnedBuilder.hxx>
19 #include <SelectMgr_SelectableObjectSet.hxx>
21 //=======================================================================
22 // function : SelectMgr_SelectableObjectSet
23 // purpose : Creates new empty objects set and initializes BVH tree
24 // builder to Binned builder with 1 element per list
25 //=======================================================================
26 SelectMgr_SelectableObjectSet::SelectMgr_SelectableObjectSet()
28 myBuilder = new BVH_BinnedBuilder<Standard_Real, 3, 32> (1, 32, Standard_False);
31 //=======================================================================
33 // purpose : Adds new object to the set and marks BVH tree for rebuild
34 //=======================================================================
35 Standard_Boolean SelectMgr_SelectableObjectSet::Append (const Handle(SelectMgr_SelectableObject)& theObject)
37 Standard_Integer aSize = Size();
39 if (aSize < myObjects.Add (theObject))
46 return Standard_False;
49 //=======================================================================
51 // purpose : Removes object theObject from set and marks BVH tree for
53 //=======================================================================
54 Standard_Boolean SelectMgr_SelectableObjectSet::Remove (const Handle(SelectMgr_SelectableObject)& theObject)
56 const Standard_Integer anIndex = myObjects.FindIndex (theObject);
60 if (anIndex != Size())
62 Swap (anIndex - 1, Size() - 1);
65 myObjects.RemoveLast();
72 return Standard_False;
75 //=======================================================================
77 // purpose : Returns bounding box of object with index theIndex
78 //=======================================================================
79 Select3D_BndBox3d SelectMgr_SelectableObjectSet::Box (const Standard_Integer theIndex) const
81 const Handle(SelectMgr_SelectableObject)& anObject = GetObjectById (theIndex);
83 anObject->BoundingBox (aBox);
85 return Select3D_BndBox3d();
87 return Select3D_BndBox3d (SelectMgr_Vec3 (aBox.CornerMin().X(), aBox.CornerMin().Y(), aBox.CornerMin().Z()),
88 SelectMgr_Vec3 (aBox.CornerMax().X(), aBox.CornerMax().Y(), aBox.CornerMax().Z()));
91 //=======================================================================
93 // purpose : Returns center of object with index theIndex in the set
94 // along the given axis theAxis
95 //=======================================================================
96 Standard_Real SelectMgr_SelectableObjectSet::Center (const Standard_Integer theIndex,
97 const Standard_Integer theAxis) const
99 Select3D_BndBox3d aBndBox = Box (theIndex);
101 return (aBndBox.CornerMin()[theAxis] +
102 aBndBox.CornerMax()[theAxis]) * 0.5;
105 //=======================================================================
107 // purpose : Swaps items with indexes theIndex1 and theIndex2 in the set
108 //=======================================================================
109 void SelectMgr_SelectableObjectSet::Swap (const Standard_Integer theIndex1,
110 const Standard_Integer theIndex2)
112 const Standard_Integer aIndex1 = theIndex1 + 1;
113 const Standard_Integer aIndex2 = theIndex2 + 1;
115 Handle(SelectMgr_SelectableObject) anObject1 = myObjects.FindKey (aIndex1);
116 Handle(SelectMgr_SelectableObject) anObject2 = myObjects.FindKey (aIndex2);
118 myObjects.Substitute (aIndex1, EMPTY_OBJ);
119 myObjects.Substitute (aIndex2, anObject1);
120 myObjects.Substitute (aIndex1, anObject2);
123 //=======================================================================
125 // purpose : Returns size of objects set
126 //=======================================================================
127 Standard_Integer SelectMgr_SelectableObjectSet::Size() const
129 return myObjects.Size();