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 <SelectMgr_SensitiveEntitySet.hxx>
18 #include <BVH_BinnedBuilder.hxx>
20 #include <Select3D_SensitiveEntity.hxx>
21 #include <SelectMgr_SensitiveEntity.hxx>
23 //=======================================================================
24 // function : SelectMgr_SensitiveEntitySet
26 //=======================================================================
27 SelectMgr_SensitiveEntitySet::SelectMgr_SensitiveEntitySet()
29 myBuilder = new BVH_BinnedBuilder<Standard_Real, 3, 4> (1, 32, Standard_True);
32 //=======================================================================
34 // purpose : Adds new entity to the set and marks BVH tree for rebuild
35 //=======================================================================
36 void SelectMgr_SensitiveEntitySet::Append (const Handle(SelectMgr_SensitiveEntity)& theEntity)
38 if (!theEntity->BaseSensitive()->IsKind ("Select3D_SensitiveEntity"))
40 theEntity->ResetSelectionActiveStatus();
43 mySensitives.Add (theEntity);
47 //=======================================================================
49 // purpose : Adds every entity of selection theSelection to the set
50 // and marks BVH tree for rebuild
51 //=======================================================================
52 void SelectMgr_SensitiveEntitySet::Append (const Handle(SelectMgr_Selection)& theSelection)
54 for (theSelection->Init(); theSelection->More(); theSelection->Next())
56 if (!theSelection->Sensitive()->BaseSensitive()->IsKind ("Select3D_SensitiveEntity"))
58 theSelection->Sensitive()->ResetSelectionActiveStatus();
61 mySensitives.Add (theSelection->Sensitive());
66 //=======================================================================
68 // purpose : Removes every entity of selection theSelection from the set
69 // and marks BVH tree for rebuild
70 //=======================================================================
71 void SelectMgr_SensitiveEntitySet::Remove (const Handle(SelectMgr_Selection)& theSelection)
73 for (theSelection->Init(); theSelection->More(); theSelection->Next())
75 Standard_Integer anEntIdx = mySensitives.FindIndex (theSelection->Sensitive());
79 if (anEntIdx != mySensitives.Size())
81 Swap (anEntIdx - 1, mySensitives.Size() - 1);
84 mySensitives.RemoveLast();
90 //=======================================================================
92 // purpose : Returns bounding box of entity with index theIdx
93 //=======================================================================
94 Select3D_BndBox3d SelectMgr_SensitiveEntitySet::Box (const Standard_Integer theIndex) const
96 return GetSensitiveById (theIndex)->BaseSensitive()->BoundingBox();
99 //=======================================================================
101 // purpose : Returns geometry center of sensitive entity index theIdx
102 // along the given axis theAxis
103 //=======================================================================
104 Standard_Real SelectMgr_SensitiveEntitySet::Center (const Standard_Integer theIndex,
105 const Standard_Integer theAxis) const
107 const Handle(SelectBasics_SensitiveEntity)& aBasicEntity =
108 GetSensitiveById (theIndex)->BaseSensitive();
109 Handle(Select3D_SensitiveEntity) aSensitive (Handle(Select3D_SensitiveEntity)::DownCast (aBasicEntity));
110 const gp_Pnt aCenter = aSensitive->CenterOfGeometry();
111 Standard_Real aCenterCoord = 0.0;
112 aCenterCoord = theAxis == 0 ? aCenter.X() :
113 (theAxis == 1 ? aCenter.Y() : aCenter.Z());
118 //=======================================================================
120 // purpose : Swaps items with indexes theIdx1 and theIdx2
121 //=======================================================================
122 void SelectMgr_SensitiveEntitySet::Swap (const Standard_Integer theIndex1,
123 const Standard_Integer theIndex2)
125 mySensitives.Swap (theIndex1 + 1, theIndex2 + 1);
128 //=======================================================================
130 // purpose : Returns the amount of entities
131 //=======================================================================
132 Standard_Integer SelectMgr_SensitiveEntitySet::Size() const
134 return mySensitives.Size();
137 //=======================================================================
138 // function : GetSensitiveById
139 // purpose : Returns the entity with index theIndex in the set
140 //=======================================================================
141 const Handle(SelectMgr_SensitiveEntity)& SelectMgr_SensitiveEntitySet::GetSensitiveById
142 (const Standard_Integer theIndex) const
144 return mySensitives.FindKey (theIndex + 1);