1 // Created on: 1995-02-16
2 // Created by: Mister rmi
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 #include <Standard_NullObject.hxx>
19 #include <SelectBasics_EntityOwner.hxx>
20 #include <SelectMgr_Selection.hxx>
22 //==================================================
23 // Function: SelectMgr_Selection
25 //==================================================
26 SelectMgr_Selection::SelectMgr_Selection (const Standard_Integer theModeIdx)
27 : myMode (theModeIdx),
28 mySelectionState (SelectMgr_SOS_Unknown),
29 myBVHUpdateStatus (SelectMgr_TBU_None),
31 myIsCustomSens (Standard_False)
34 SelectMgr_Selection::~SelectMgr_Selection()
39 //==================================================
42 //==================================================
43 void SelectMgr_Selection::Destroy()
45 for (Standard_Integer anEntityIdx = 0; anEntityIdx < myEntities.Size(); ++anEntityIdx)
47 Handle(SelectMgr_SensitiveEntity)& anEntity = myEntities.ChangeValue (anEntityIdx);
48 anEntity->BaseSensitive()->Set (NULL);
53 //==================================================
56 //==================================================
57 void SelectMgr_Selection::Add (const Handle(SelectBasics_SensitiveEntity)& theSensitive)
60 // in debug mode raise exception
61 Standard_NullObject_Raise_if
62 (theSensitive.IsNull(), "Null sensitive entity is added to the selection");
64 // in release mode do not add
65 if (!theSensitive.IsNull())
67 Handle(SelectMgr_SensitiveEntity) anEntity = new SelectMgr_SensitiveEntity (theSensitive);
68 myEntities.Append (anEntity);
69 if (mySelectionState == SelectMgr_SOS_Activated &&
70 !anEntity->IsActiveForSelection())
72 anEntity->SetActiveForSelection();
77 anEntity->BaseSensitive()->SetSensitivityFactor (mySensFactor);
81 mySensFactor = Max (mySensFactor,
82 anEntity->BaseSensitive()->SensitivityFactor());
87 //==================================================
90 //==================================================
91 void SelectMgr_Selection::Clear()
93 for (Standard_Integer anIdx = 0; anIdx < myEntities.Size(); ++anIdx)
95 Handle(SelectMgr_SensitiveEntity)& anEntity = myEntities.ChangeValue (anIdx);
102 //==================================================
105 //==================================================
106 Standard_Boolean SelectMgr_Selection::IsEmpty() const
108 return myEntities.IsEmpty();
111 //==================================================
112 // function: GetEntityById
113 // purpose : Returns sensitive entity stored by
114 // index theIdx in entites vector
115 //==================================================
116 Handle(SelectMgr_SensitiveEntity)& SelectMgr_Selection::GetEntityById (const Standard_Integer theIdx)
118 return myEntities.ChangeValue (theIdx);
121 //==================================================
122 // function: GetSelectionState
123 // purpose : Returns status of selection
124 //==================================================
125 const SelectMgr_StateOfSelection SelectMgr_Selection::GetSelectionState() const
127 return mySelectionState;
130 //==================================================
131 // function: SetSelectionState
132 // purpose : Sets status of selection
133 //==================================================
134 void SelectMgr_Selection::SetSelectionState (const SelectMgr_StateOfSelection theState) const
136 mySelectionState = theState;
139 //==================================================
140 // function: Sensitivity
141 // purpose : Returns sensitivity of the selection
142 //==================================================
143 Standard_Integer SelectMgr_Selection::Sensitivity() const
148 //==================================================
149 // function: SetSensitivity
150 // purpose : Changes sensitivity of the selection and all its entities to the given value.
151 // IMPORTANT: This method does not update any outer selection structures, so for
152 // proper updates use SelectMgr_SelectionManager::SetSelectionSensitivity method.
153 //==================================================
154 void SelectMgr_Selection::SetSensitivity (const Standard_Integer theNewSens)
156 mySensFactor = theNewSens;
157 myIsCustomSens = Standard_True;
158 for (Standard_Integer anIdx = 0; anIdx < myEntities.Size(); ++anIdx)
160 Handle(SelectMgr_SensitiveEntity)& anEntity = myEntities.ChangeValue (anIdx);
161 anEntity->BaseSensitive()->SetSensitivityFactor (theNewSens);