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 const Handle(Select3D_SensitiveEntity)& aSensitive =
110 Handle(Select3D_SensitiveEntity)::DownCast (aBasicEntity);
111 const gp_Pnt aCenter = aSensitive->CenterOfGeometry();
112 Standard_Real aCenterCoord = 0.0;
113 aCenterCoord = theAxis == 0 ? aCenter.X() :
114 (theAxis == 1 ? aCenter.Y() : aCenter.Z());
119 //=======================================================================
121 // purpose : Swaps items with indexes theIdx1 and theIdx2
122 //=======================================================================
123 void SelectMgr_SensitiveEntitySet::Swap (const Standard_Integer theIndex1,
124 const Standard_Integer theIndex2)
126 const Handle(SelectMgr_SensitiveEntity) anEntity1 = GetSensitiveById (theIndex1);
127 const Handle(SelectMgr_SensitiveEntity) anEntity2 = GetSensitiveById (theIndex2);
129 mySensitives.Substitute (theIndex1 + 1, EMPTY_ENT);
130 mySensitives.Substitute (theIndex2 + 1, anEntity1);
131 mySensitives.Substitute (theIndex1 + 1, anEntity2);
134 //=======================================================================
136 // purpose : Returns the amount of entities
137 //=======================================================================
138 Standard_Integer SelectMgr_SensitiveEntitySet::Size() const
140 return mySensitives.Size();
143 //=======================================================================
144 // function : GetSensitiveById
145 // purpose : Returns the entity with index theIndex in the set
146 //=======================================================================
147 const Handle(SelectMgr_SensitiveEntity)& SelectMgr_SensitiveEntitySet::GetSensitiveById
148 (const Standard_Integer theIndex) const
150 return mySensitives.FindKey (theIndex + 1);