Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TEveSelection.cxx
Go to the documentation of this file.
1// @(#)root/eve:$Id$
2// Author: Matevz Tadel 2007
3
4/*************************************************************************
5 * Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#include "TEveSelection.h"
13#include "TEveProjectionBases.h"
14#include "TEveCompound.h"
15#include "TEveManager.h"
16
17#include "TClass.h"
18
19/** \class TEveSelection
20\ingroup TEve
21Make sure there is a SINGLE running TEveSelection for each
22selection type (select/highlight).
23*/
24
25
26////////////////////////////////////////////////////////////////////////////////
27/// Constructor.
28
29TEveSelection::TEveSelection(const char* n, const char* t) :
31 fPickToSelect (kPS_Projectable),
32 fActive (kTRUE),
33 fIsMaster (kTRUE)
34{
38}
39
40////////////////////////////////////////////////////////////////////////////////
41/// Set to 'highlight' mode.
42
44{
45 // Most importantly, this sets the pointers-to-function-members in
46 // TEveElement that are used to mark elements as (un)selected and
47 // implied-(un)selected.
48
51
55}
56
57////////////////////////////////////////////////////////////////////////////////
58/// Select element indicated by the entry and fill its
59/// implied-selected set.
60
62{
63 TEveElement *el = entry->first;
64 Set_t &set = entry->second;
65
66 (el->*fSelElement)(kTRUE);
67 el->FillImpliedSelectedSet(set);
68 for (Set_i i = set.begin(); i != set.end(); ++i)
69 ((*i)->*fIncImpSelElement)();
70}
71
72////////////////////////////////////////////////////////////////////////////////
73/// Deselect element indicated by the entry and clear its
74/// implied-selected set.
75
77{
78 TEveElement *el = entry->first;
79 Set_t &set = entry->second;
80
81 for (Set_i i = set.begin(); i != set.end(); ++i)
82 ((*i)->*fDecImpSelElement)();
83 set.clear();
85}
86
87////////////////////////////////////////////////////////////////////////////////
88/// Pre-addition check. Deny addition if el is already selected.
89/// Virtual from TEveElement.
90
92{
93 return el != this && fImpliedSelected.find(el) == fImpliedSelected.end() &&
94 el->IsA()->InheritsFrom(TEveSelection::Class()) == kFALSE;
95}
96
97////////////////////////////////////////////////////////////////////////////////
98/// Add an element into selection, virtual from TEveElement.
99
101{
103
104 SelMap_i i = fImpliedSelected.insert(std::make_pair(el, Set_t())).first;
105 if (fActive)
106 {
108 }
110}
111
112////////////////////////////////////////////////////////////////////////////////
113/// Add an element into selection, virtual from TEveElement.
114/// Overriden here just so that a signal can be emitted.
115
121
122////////////////////////////////////////////////////////////////////////////////
123/// Virtual from TEveElement.
124
126{
127 SelMap_i i = fImpliedSelected.find(el);
128
129 if (i != fImpliedSelected.end())
130 {
131 if (fActive)
132 {
134 }
135 fImpliedSelected.erase(i);
136 }
137 else
138 {
139 Warning("TEveSelection::RemoveElementLocal", "element not found in map.");
140 }
141}
142
143////////////////////////////////////////////////////////////////////////////////
144/// Add an element into selection, virtual from TEveElement.
145/// Overriden here just so that a signal can be emitted.
146
152
153////////////////////////////////////////////////////////////////////////////////
154/// Virtual from TEveElement.
155
157{
158 if (fActive)
159 {
160 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
162 }
163 fImpliedSelected.clear();
164}
165
166////////////////////////////////////////////////////////////////////////////////
167/// Remove element from all implied-selected sets.
168///
169/// This is called as part of the element destruction from
170/// TEveManager::PreDeleteElement() and should not be called
171/// directly.
172
174{
175 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
176 {
177 Set_i j = i->second.find(el);
178 if (j != i->second.end())
179 i->second.erase(j);
180 }
181}
182
183////////////////////////////////////////////////////////////////////////////////
184/// Recalculate implied-selected state for given selection entry.
185/// Add new elements to implied-selected set and increase their
186/// implied-selected count.
187
189{
190 Set_t set;
191 smi->first->FillImpliedSelectedSet(set);
192 for (Set_i i = set.begin(); i != set.end(); ++i)
193 {
194 if (smi->second.find(*i) == smi->second.end())
195 {
196 smi->second.insert(*i);
197 ((*i)->*fIncImpSelElement)();
198 }
199 }
200}
201
202////////////////////////////////////////////////////////////////////////////////
203/// If given element is selected or implied-selected with this
204/// selection and recheck implied-set for given selection entry.
205
207{
208 // Top-level selected.
209 {
210 SelMap_i i = fImpliedSelected.find(el);
211 if (i != fImpliedSelected.end())
213 }
214
215 // Implied selected, need to loop over all.
216 {
217 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++ i)
218 {
219 if (i->second.find(el) != i->second.end())
221 }
222 }
223}
224
225////////////////////////////////////////////////////////////////////////////////
226/// Emit SelectionAdded signal.
227
229{
230 Emit("SelectionAdded(TEveElement*)", (Longptr_t)el);
231}
232
233////////////////////////////////////////////////////////////////////////////////
234/// Emit SelectionRemoved signal.
235
237{
238 Emit("SelectionRemoved(TEveElement*)", (Longptr_t)el);
239}
240
241////////////////////////////////////////////////////////////////////////////////
242/// Emit SelectionCleared signal.
243
245{
246 Emit("SelectionCleared()");
247}
248
249////////////////////////////////////////////////////////////////////////////////
250/// Called when secondary selection changed internally.
251
253{
254 Emit("SelectionRepeated(TEveElement*)", (Longptr_t)el);
255}
256
257////////////////////////////////////////////////////////////////////////////////
258/// Activate this selection.
259
261{
262 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
264 fActive = kTRUE;
265}
266
267////////////////////////////////////////////////////////////////////////////////
268/// Deactivate this selection.
269
271{
272 fActive = kFALSE;
273 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
275}
276
277////////////////////////////////////////////////////////////////////////////////
278/// Given element el that was picked or clicked by the user, find
279/// the parent/ancestor element that should actually become the main
280/// selected element according to current selection mode.
281
283{
284 if (el == nullptr)
285 return nullptr;
286
287 if (el->ForwardSelection())
288 {
289 return el->ForwardSelection();
290 }
291
292 switch (fPickToSelect)
293 {
294 case kPS_Ignore:
295 {
296 return nullptr;
297 }
298 case kPS_Element:
299 {
300 return el;
301 }
302 case kPS_Projectable:
303 {
304 TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
305 if (pted)
306 return dynamic_cast<TEveElement*>(pted->GetProjectable());
307 return el;
308 }
309 case kPS_Compound:
310 {
311 TEveElement* cmpnd = el->GetCompound();
312 if (cmpnd)
313 return cmpnd;
314 return el;
315 }
317 {
318 TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
319 if (pted)
320 el = dynamic_cast<TEveElement*>(pted->GetProjectable());
321 TEveElement* cmpnd = el->GetCompound();
322 if (cmpnd)
323 return cmpnd;
324 return el;
325 }
326 case kPS_Master:
327 {
328 TEveElement* mstr = el->GetMaster();
329 if (mstr)
330 return mstr;
331 return el;
332 }
333 }
334 return el;
335}
336
337////////////////////////////////////////////////////////////////////////////////
338/// Called when user picks/clicks on an element. If multi is true,
339/// the user is requiring a multiple selection (usually this is
340/// associated with control-key being pressed at the time of pick
341/// event).
342
344{
345 TEveElement *edit_el = el ? el->ForwardEdit() : nullptr;
346
348
349 if (el || HasChildren())
350 {
351 if (!multi)
353 if (el)
354 {
355 if (HasChild(el))
357 else
358 AddElement(el);
359 }
360 if (fIsMaster)
362 gEve->Redraw3D();
363 }
364}
365
366////////////////////////////////////////////////////////////////////////////////
367/// Called when secondary selection becomes empty.
368
378
379////////////////////////////////////////////////////////////////////////////////
380/// Called when secondary selection becomes empty.
381
383{
385 if (el)
386 {
388 gEve->Redraw3D();
389 }
390}
long Longptr_t
Integer large enough to hold a pointer (platform-dependent)
Definition RtypesCore.h:89
constexpr Bool_t kFALSE
Definition RtypesCore.h:108
constexpr Bool_t kTRUE
Definition RtypesCore.h:107
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
R__EXTERN TEveManager * gEve
const_iterator end() const
A list of TEveElements.
Base class for TEveUtil visualization elements, providing hierarchy management, rendering control and...
Definition TEveElement.h:36
virtual void SelectElement(Bool_t state)
Set element's selection state. Stamp appropriately.
virtual void AddElement(TEveElement *el)
Add el to the list of children.
virtual void HighlightElement(Bool_t state)
Set element's highlight state. Stamp appropriately.
virtual void RemoveElements()
Remove all elements.
Set_t::iterator Set_i
Definition TEveElement.h:76
virtual void IncImpliedHighlighted()
Increase element's implied-highlight count. Stamp appropriately.
Bool_t HasChildren() const
virtual void DecImpliedHighlighted()
Decrease element's implied-highlight count. Stamp appropriately.
std::set< TEveElement * > Set_t
Definition TEveElement.h:75
virtual void RemoveElement(TEveElement *el)
Remove el from the list of children.
virtual void DecImpliedSelected()
Decrease element's implied-selection count. Stamp appropriately.
Bool_t HasChild(TEveElement *el)
Check if element el is a child of this element.
virtual void IncImpliedSelected()
Increase element's implied-selection count. Stamp appropriately.
void ElementSelect(TEveElement *element)
Select an element.
void Redraw3D(Bool_t resetCameras=kFALSE, Bool_t dropLogicals=kFALSE)
Abstract base class for classes that hold results of a non-linear projection transformation.
Bool_t AcceptElement(TEveElement *el) override
Pre-addition check.
TEveElement * MapPickedToSelected(TEveElement *el)
Given element el that was picked or clicked by the user, find the parent/ancestor element that should...
ImplySelect_foo fIncImpSelElement
ImplySelect_foo fDecImpSelElement
virtual void RemoveImpliedSelected(TEveElement *el)
Remove element from all implied-selected sets.
void RemoveElementsLocal() override
Virtual from TEveElement.
SelMap_t fImpliedSelected
void RecheckImpliedSet(SelMap_i smi)
Recalculate implied-selected state for given selection entry.
void SelectionRepeated(TEveElement *el)
Called when secondary selection changed internally.
static TClass * Class()
void SetHighlightMode()
Set to 'highlight' mode.
void SelectionRemoved(TEveElement *el)
Emit SelectionRemoved signal.
TEveSelection(const TEveSelection &)
void DoElementUnselect(SelMap_i entry)
Deselect element indicated by the entry and clear its implied-selected set.
void RecheckImpliedSetForElement(TEveElement *el)
If given element is selected or implied-selected with this selection and recheck implied-set for give...
void RemoveElements() override
Add an element into selection, virtual from TEveElement.
Select_foo fSelElement
virtual void DeactivateSelection()
Deactivate this selection.
virtual void UserRePickedElement(TEveElement *el)
Called when secondary selection becomes empty.
virtual void ActivateSelection()
Activate this selection.
void RemoveElementLocal(TEveElement *el) override
Virtual from TEveElement.
virtual void UserPickedElement(TEveElement *el, Bool_t multi=kFALSE)
Called when user picks/clicks on an element.
void SelectionAdded(TEveElement *el)
Emit SelectionAdded signal.
virtual void UserUnPickedElement(TEveElement *el)
Called when secondary selection becomes empty.
void AddElement(TEveElement *el) override
Add an element into selection, virtual from TEveElement.
void RemoveElement(TEveElement *el) override
Add an element into selection, virtual from TEveElement.
void SelectionCleared()
Emit SelectionCleared signal.
void DoElementSelect(SelMap_i entry)
Select element indicated by the entry and fill its implied-selected set.
std::map< TEveElement *, Set_t >::iterator SelMap_i
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:1057
void Emit(const char *signal, const T &arg)
Activate signal with single parameter.
Definition TQObject.h:164
const Int_t n
Definition legend1.C:16