1 // Copyright (c) 1998-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
15 #include <AIS_Selection.hxx>
17 #include <AIS_InteractiveObject.hxx>
19 IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection, Standard_Transient)
23 static const Standard_Integer THE_MaxSizeOfResult = 100000;
26 //=======================================================================
27 //function : AIS_Selection
29 //=======================================================================
30 AIS_Selection::AIS_Selection()
32 // for maximum performance on medium selections (< 100000 objects)
33 myResultMap.ReSize (THE_MaxSizeOfResult);
36 //=======================================================================
39 //=======================================================================
40 void AIS_Selection::Clear()
42 for (AIS_NListOfEntityOwner::Iterator aSelIter (Objects()); aSelIter.More(); aSelIter.Next())
44 const Handle(SelectMgr_EntityOwner) anObject = aSelIter.Value();
45 anObject->SetSelected (Standard_False);
49 myIterator = AIS_NListOfEntityOwner::Iterator();
52 //=======================================================================
55 //=======================================================================
56 AIS_SelectStatus AIS_Selection::Select (const Handle(SelectMgr_EntityOwner)& theObject)
58 if (theObject.IsNull()
59 || !theObject->HasSelectable())
61 return AIS_SS_NotDone;
64 if (!myResultMap.IsBound (theObject))
66 AIS_NListOfEntityOwner::Iterator aListIter;
67 myresult.Append (theObject, aListIter);
68 myResultMap.Bind (theObject, aListIter);
69 theObject->SetSelected (Standard_True);
73 AIS_NListOfEntityOwner::Iterator aListIter = myResultMap.Find (theObject);
74 if (myIterator == aListIter)
76 if (myIterator.More())
82 myIterator = AIS_NListOfEntityOwner::Iterator();
86 // In the mode of advanced mesh selection only one owner is created for all selection modes.
87 // It is necessary to check the current detected entity
88 // and remove the owner from map only if the detected entity is the same as previous selected (IsForcedHilight call)
89 if (theObject->IsForcedHilight())
94 myresult.Remove (aListIter);
95 myResultMap.UnBind (theObject);
96 theObject->SetSelected (Standard_False);
98 // update list iterator for next object in <myresult> list if any
101 const Handle(SelectMgr_EntityOwner)& aNextObject = aListIter.Value();
102 if (myResultMap.IsBound (aNextObject))
104 myResultMap (aNextObject) = aListIter;
108 myResultMap.Bind (aNextObject, aListIter);
111 return AIS_SS_Removed;
114 //=======================================================================
115 //function : AddSelect
117 //=======================================================================
118 AIS_SelectStatus AIS_Selection::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
120 if (theObject.IsNull()
121 || !theObject->HasSelectable()
122 || myResultMap.IsBound (theObject))
124 return AIS_SS_NotDone;
127 AIS_NListOfEntityOwner::Iterator aListIter;
128 myresult.Append (theObject, aListIter);
129 myResultMap.Bind (theObject, aListIter);
130 theObject->SetSelected (Standard_True);