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 <SelectMgr_Selection.hxx>
19 #include <SelectMgr_EntityOwner.hxx>
20 #include <Standard_NullObject.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(SelectMgr_Selection,Standard_Transient)
24 //==================================================
25 // Function: SelectMgr_Selection
27 //==================================================
28 SelectMgr_Selection::SelectMgr_Selection (const Standard_Integer theModeIdx)
29 : myMode (theModeIdx),
30 mySelectionState (SelectMgr_SOS_Unknown),
31 myBVHUpdateStatus (SelectMgr_TBU_None),
33 myIsCustomSens (Standard_False)
36 SelectMgr_Selection::~SelectMgr_Selection()
41 //==================================================
44 //==================================================
45 void SelectMgr_Selection::Destroy()
47 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
49 Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
50 anEntity->BaseSensitive()->Set (NULL);
55 //==================================================
58 //==================================================
59 void SelectMgr_Selection::Add (const Handle(Select3D_SensitiveEntity)& theSensitive)
61 // if input is null: in debug mode raise exception
62 Standard_NullObject_Raise_if (theSensitive.IsNull(), "Null sensitive entity is added to the selection");
63 if (theSensitive.IsNull())
65 // in release mode do not add
69 Handle(SelectMgr_SensitiveEntity) anEntity = new SelectMgr_SensitiveEntity (theSensitive);
70 myEntities.Append (anEntity);
71 if (mySelectionState == SelectMgr_SOS_Activated
72 && !anEntity->IsActiveForSelection())
74 anEntity->SetActiveForSelection();
79 anEntity->BaseSensitive()->SetSensitivityFactor (mySensFactor);
83 mySensFactor = Max (mySensFactor, anEntity->BaseSensitive()->SensitivityFactor());
87 //==================================================
90 //==================================================
91 void SelectMgr_Selection::Clear()
93 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
95 Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
102 //==================================================
103 // function: SetSensitivity
104 // purpose : Changes sensitivity of the selection and all its entities to the given value.
105 // IMPORTANT: This method does not update any outer selection structures, so for
106 // proper updates use SelectMgr_SelectionManager::SetSelectionSensitivity method.
107 //==================================================
108 void SelectMgr_Selection::SetSensitivity (const Standard_Integer theNewSens)
110 mySensFactor = theNewSens;
111 myIsCustomSens = Standard_True;
112 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anEntityIter (myEntities); anEntityIter.More(); anEntityIter.Next())
114 Handle(SelectMgr_SensitiveEntity)& anEntity = anEntityIter.ChangeValue();
115 anEntity->BaseSensitive()->SetSensitivityFactor (theNewSens);
119 // =======================================================================
120 // function : DumpJson
122 // =======================================================================
123 void SelectMgr_Selection::DumpJson (Standard_OStream& theOStream, Standard_Integer theDepth) const
125 OCCT_DUMP_TRANSIENT_CLASS_BEGIN (theOStream)
127 for (NCollection_Vector<Handle(SelectMgr_SensitiveEntity)>::Iterator anIterator (myEntities); anIterator.More(); anIterator.Next())
129 const Handle(SelectMgr_SensitiveEntity)& anEntity = anIterator.Value();
130 OCCT_DUMP_FIELD_VALUES_DUMPED (theOStream, theDepth, anEntity.get())
133 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myMode)
134 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, mySelectionState)
135 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, mySensFactor)
136 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myUpdateStatus)
137 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myBVHUpdateStatus)
138 OCCT_DUMP_FIELD_VALUE_NUMERICAL (theOStream, myIsCustomSens)