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 <Select3D_SensitiveEntity.hxx>
19 #include <SelectMgr_SensitiveEntity.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_SensitiveEntitySet, BVH_PrimitiveSet3d)
23 //=======================================================================
24 // function : SelectMgr_SensitiveEntitySet
26 //=======================================================================
27 SelectMgr_SensitiveEntitySet::SelectMgr_SensitiveEntitySet (const Handle(Select3D_BVHBuilder3d)& theBuilder)
28 : BVH_PrimitiveSet3d (theBuilder)
33 //=======================================================================
35 // purpose : Adds new entity to the set and marks BVH tree for rebuild
36 //=======================================================================
37 void SelectMgr_SensitiveEntitySet::Append (const Handle(SelectMgr_SensitiveEntity)& theEntity)
39 if (!theEntity->BaseSensitive()->IsKind (STANDARD_TYPE(Select3D_SensitiveEntity)))
41 theEntity->ResetSelectionActiveStatus();
44 mySensitives.Add (theEntity);
48 //=======================================================================
50 // purpose : Adds every entity of selection theSelection to the set
51 // and marks BVH tree for rebuild
52 //=======================================================================
53 void SelectMgr_SensitiveEntitySet::Append (const Handle(SelectMgr_Selection)& theSelection)
55 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (theSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
57 if (!aSelEntIter.Value()->BaseSensitive()->IsKind (STANDARD_TYPE(Select3D_SensitiveEntity)))
59 aSelEntIter.Value()->ResetSelectionActiveStatus();
62 mySensitives.Add (aSelEntIter.Value());
67 //=======================================================================
69 // purpose : Removes every entity of selection theSelection from the set
70 // and marks BVH tree for rebuild
71 //=======================================================================
72 void SelectMgr_SensitiveEntitySet::Remove (const Handle(SelectMgr_Selection)& theSelection)
74 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator aSelEntIter (theSelection->Entities()); aSelEntIter.More(); aSelEntIter.Next())
76 const Standard_Integer anEntIdx = mySensitives.FindIndex (aSelEntIter.Value());
82 if (anEntIdx != mySensitives.Size())
84 Swap (anEntIdx - 1, mySensitives.Size() - 1);
87 mySensitives.RemoveLast();
93 //=======================================================================
95 // purpose : Returns bounding box of entity with index theIdx
96 //=======================================================================
97 Select3D_BndBox3d SelectMgr_SensitiveEntitySet::Box (const Standard_Integer theIndex) const
99 return GetSensitiveById (theIndex)->BaseSensitive()->BoundingBox();
102 //=======================================================================
104 // purpose : Returns geometry center of sensitive entity index theIdx
105 // along the given axis theAxis
106 //=======================================================================
107 Standard_Real SelectMgr_SensitiveEntitySet::Center (const Standard_Integer theIndex,
108 const Standard_Integer theAxis) const
110 const Handle(SelectBasics_SensitiveEntity)& aBasicEntity =
111 GetSensitiveById (theIndex)->BaseSensitive();
112 Handle(Select3D_SensitiveEntity) aSensitive (Handle(Select3D_SensitiveEntity)::DownCast (aBasicEntity));
113 const gp_Pnt aCenter = aSensitive->CenterOfGeometry();
114 Standard_Real aCenterCoord = 0.0;
115 aCenterCoord = theAxis == 0 ? aCenter.X() :
116 (theAxis == 1 ? aCenter.Y() : aCenter.Z());
121 //=======================================================================
123 // purpose : Swaps items with indexes theIdx1 and theIdx2
124 //=======================================================================
125 void SelectMgr_SensitiveEntitySet::Swap (const Standard_Integer theIndex1,
126 const Standard_Integer theIndex2)
128 mySensitives.Swap (theIndex1 + 1, theIndex2 + 1);
131 //=======================================================================
133 // purpose : Returns the amount of entities
134 //=======================================================================
135 Standard_Integer SelectMgr_SensitiveEntitySet::Size() const
137 return mySensitives.Size();
140 //=======================================================================
141 // function : GetSensitiveById
142 // purpose : Returns the entity with index theIndex in the set
143 //=======================================================================
144 const Handle(SelectMgr_SensitiveEntity)& SelectMgr_SensitiveEntitySet::GetSensitiveById
145 (const Standard_Integer theIndex) const
147 return mySensitives.FindKey (theIndex + 1);