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>
18 #include <AIS_SelectionScheme.hxx>
19 #include <SelectMgr_Filter.hxx>
21 IMPLEMENT_STANDARD_RTTIEXT(AIS_Selection, Standard_Transient)
25 static const Standard_Integer THE_MaxSizeOfResult = 100000;
28 //=======================================================================
29 //function : AIS_Selection
31 //=======================================================================
32 AIS_Selection::AIS_Selection()
34 // for maximum performance on medium selections (< 100000 objects)
35 myResultMap.ReSize (THE_MaxSizeOfResult);
38 //=======================================================================
41 //=======================================================================
42 void AIS_Selection::Clear()
44 for (AIS_NListOfEntityOwner::Iterator aSelIter (Objects()); aSelIter.More(); aSelIter.Next())
46 const Handle(SelectMgr_EntityOwner) anObject = aSelIter.Value();
47 anObject->SetSelected (Standard_False);
51 myIterator = AIS_NListOfEntityOwner::Iterator();
54 //=======================================================================
57 //=======================================================================
58 AIS_SelectStatus AIS_Selection::Select (const Handle(SelectMgr_EntityOwner)& theObject)
60 if (theObject.IsNull()
61 || !theObject->HasSelectable())
63 return AIS_SS_NotDone;
66 if (!myResultMap.IsBound (theObject))
68 AIS_NListOfEntityOwner::Iterator aListIter;
69 myresult.Append (theObject, aListIter);
70 myResultMap.Bind (theObject, aListIter);
71 theObject->SetSelected (Standard_True);
75 AIS_NListOfEntityOwner::Iterator aListIter = myResultMap.Find (theObject);
76 if (myIterator == aListIter)
78 if (myIterator.More())
84 myIterator = AIS_NListOfEntityOwner::Iterator();
88 // In the mode of advanced mesh selection only one owner is created for all selection modes.
89 // It is necessary to check the current detected entity
90 // and remove the owner from map only if the detected entity is the same as previous selected (IsForcedHilight call)
91 if (theObject->IsForcedHilight())
96 myresult.Remove (aListIter);
97 myResultMap.UnBind (theObject);
98 theObject->SetSelected (Standard_False);
100 // update list iterator for next object in <myresult> list if any
101 if (aListIter.More())
103 const Handle(SelectMgr_EntityOwner)& aNextObject = aListIter.Value();
104 if (myResultMap.IsBound (aNextObject))
106 myResultMap (aNextObject) = aListIter;
110 myResultMap.Bind (aNextObject, aListIter);
113 return AIS_SS_Removed;
116 //=======================================================================
117 //function : AddSelect
119 //=======================================================================
120 AIS_SelectStatus AIS_Selection::AddSelect (const Handle(SelectMgr_EntityOwner)& theObject)
122 if (theObject.IsNull()
123 || !theObject->HasSelectable()
124 || myResultMap.IsBound (theObject))
126 return AIS_SS_NotDone;
129 AIS_NListOfEntityOwner::Iterator aListIter;
130 myresult.Append (theObject, aListIter);
131 myResultMap.Bind (theObject, aListIter);
132 theObject->SetSelected (Standard_True);
136 //=======================================================================
137 //function : SelectOwners
139 //=======================================================================
140 void AIS_Selection::SelectOwners (const AIS_NArray1OfEntityOwner& thePickedOwners,
141 const AIS_SelectionScheme theSelScheme,
142 const Standard_Boolean theToAllowSelOverlap,
143 const Handle(SelectMgr_Filter)& theFilter)
145 (void )theToAllowSelOverlap;
146 switch (theSelScheme)
148 case AIS_SelectionScheme_UNKNOWN:
152 case AIS_SelectionScheme_Replace:
155 for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
157 appendOwner (aSelIter.Value(), theFilter);
162 case AIS_SelectionScheme_Add:
164 for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
166 appendOwner (aSelIter.Value(), theFilter);
170 case AIS_SelectionScheme_Remove:
172 for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
174 if (myResultMap.IsBound (aSelIter.Value()))
176 Select (aSelIter.Value());
181 case AIS_SelectionScheme_XOR:
183 for (AIS_NArray1OfEntityOwner::Iterator aSelIter (thePickedOwners); aSelIter.More(); aSelIter.Next())
185 const Handle(SelectMgr_EntityOwner)& anOwner = aSelIter.Value();
187 || !anOwner->HasSelectable()
188 || !theFilter->IsOk (anOwner))
197 case AIS_SelectionScheme_Clear:
205 //=======================================================================
206 //function : appendOwner
208 //=======================================================================
209 AIS_SelectStatus AIS_Selection::appendOwner (const Handle(SelectMgr_EntityOwner)& theOwner,
210 const Handle(SelectMgr_Filter)& theFilter)
212 if (theOwner.IsNull()
213 || !theOwner->HasSelectable()
214 || !theFilter->IsOk (theOwner))
216 return AIS_SS_NotDone;
219 return AddSelect (theOwner);