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
26
27////////////////////////////////////////////////////////////////////////////////
28/// Constructor.
29
30TEveSelection::TEveSelection(const char* n, const char* t) :
32 fPickToSelect (kPS_Projectable),
33 fActive (kTRUE),
34 fIsMaster (kTRUE)
35{
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// Set to 'highlight' mode.
43
45{
46 // Most importantly, this sets the pointers-to-function-members in
47 // TEveElement that are used to mark elements as (un)selected and
48 // implied-(un)selected.
49
52
56}
57
58////////////////////////////////////////////////////////////////////////////////
59/// Select element indicated by the entry and fill its
60/// implied-selected set.
61
63{
64 TEveElement *el = entry->first;
65 Set_t &set = entry->second;
66
67 (el->*fSelElement)(kTRUE);
69 for (Set_i i = set.begin(); i != set.end(); ++i)
70 ((*i)->*fIncImpSelElement)();
71}
72
73////////////////////////////////////////////////////////////////////////////////
74/// Deselect element indicated by the entry and clear its
75/// implied-selected set.
76
78{
79 TEveElement *el = entry->first;
80 Set_t &set = entry->second;
81
82 for (Set_i i = set.begin(); i != set.end(); ++i)
83 ((*i)->*fDecImpSelElement)();
84 set.clear();
85 (el->*fSelElement)(kFALSE);
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// Pre-addition check. Deny addition if el is already selected.
90/// Virtual from TEveElement.
91
93{
94 return el != this && fImpliedSelected.find(el) == fImpliedSelected.end() &&
95 el->IsA()->InheritsFrom(TEveSelection::Class()) == kFALSE;
96}
97
98////////////////////////////////////////////////////////////////////////////////
99/// Add an element into selection, virtual from TEveElement.
100
102{
104
105 SelMap_i i = fImpliedSelected.insert(std::make_pair(el, Set_t())).first;
106 if (fActive)
107 {
109 }
110 SelectionAdded(el);
111}
112
113////////////////////////////////////////////////////////////////////////////////
114/// Add an element into selection, virtual from TEveElement.
115/// Overriden here just so that a signal can be emitted.
116
118{
121}
122
123////////////////////////////////////////////////////////////////////////////////
124/// Virtual from TEveElement.
125
127{
128 SelMap_i i = fImpliedSelected.find(el);
129
130 if (i != fImpliedSelected.end())
131 {
132 if (fActive)
133 {
135 }
136 fImpliedSelected.erase(i);
137 }
138 else
139 {
140 Warning("TEveSelection::RemoveElementLocal", "element not found in map.");
141 }
142}
143
144////////////////////////////////////////////////////////////////////////////////
145/// Add an element into selection, virtual from TEveElement.
146/// Overriden here just so that a signal can be emitted.
147
149{
152}
153
154////////////////////////////////////////////////////////////////////////////////
155/// Virtual from TEveElement.
156
158{
159 if (fActive)
160 {
161 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
163 }
164 fImpliedSelected.clear();
165}
166
167////////////////////////////////////////////////////////////////////////////////
168/// Remove element from all implied-selected sets.
169///
170/// This is called as part of the element destruction from
171/// TEveManager::PreDeleteElement() and should not be called
172/// directly.
173
175{
176 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
177 {
178 Set_i j = i->second.find(el);
179 if (j != i->second.end())
180 i->second.erase(j);
181 }
182}
183
184////////////////////////////////////////////////////////////////////////////////
185/// Recalculate implied-selected state for given selection entry.
186/// Add new elements to implied-selected set and increase their
187/// implied-selected count.
188
190{
191 Set_t set;
192 smi->first->FillImpliedSelectedSet(set);
193 for (Set_i i = set.begin(); i != set.end(); ++i)
194 {
195 if (smi->second.find(*i) == smi->second.end())
196 {
197 smi->second.insert(*i);
198 ((*i)->*fIncImpSelElement)();
199 }
200 }
201}
202
203////////////////////////////////////////////////////////////////////////////////
204/// If given element is selected or implied-selected with this
205/// selection and recheck implied-set for given selection entry.
206
208{
209 // Top-level selected.
210 {
211 SelMap_i i = fImpliedSelected.find(el);
212 if (i != fImpliedSelected.end())
214 }
215
216 // Implied selected, need to loop over all.
217 {
218 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++ i)
219 {
220 if (i->second.find(el) != i->second.end())
222 }
223 }
224}
225
226////////////////////////////////////////////////////////////////////////////////
227/// Emit SelectionAdded signal.
228
230{
231 Emit("SelectionAdded(TEveElement*)", (Longptr_t)el);
232}
233
234////////////////////////////////////////////////////////////////////////////////
235/// Emit SelectionRemoved signal.
236
238{
239 Emit("SelectionRemoved(TEveElement*)", (Longptr_t)el);
240}
241
242////////////////////////////////////////////////////////////////////////////////
243/// Emit SelectionCleared signal.
244
246{
247 Emit("SelectionCleared()");
248}
249
250////////////////////////////////////////////////////////////////////////////////
251/// Called when secondary selection changed internally.
252
254{
255 Emit("SelectionRepeated(TEveElement*)", (Longptr_t)el);
256}
257
258////////////////////////////////////////////////////////////////////////////////
259/// Activate this selection.
260
262{
263 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
265 fActive = kTRUE;
266}
267
268////////////////////////////////////////////////////////////////////////////////
269/// Deactivate this selection.
270
272{
273 fActive = kFALSE;
274 for (SelMap_i i = fImpliedSelected.begin(); i != fImpliedSelected.end(); ++i)
276}
277
278////////////////////////////////////////////////////////////////////////////////
279/// Given element el that was picked or clicked by the user, find
280/// the parent/ancestor element that should actually become the main
281/// selected element according to current selection mode.
282
284{
285 if (el == 0)
286 return 0;
287
288 if (el->ForwardSelection())
289 {
290 return el->ForwardSelection();
291 }
292
293 switch (fPickToSelect)
294 {
295 case kPS_Ignore:
296 {
297 return 0;
298 }
299 case kPS_Element:
300 {
301 return el;
302 }
303 case kPS_Projectable:
304 {
305 TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
306 if (pted)
307 return dynamic_cast<TEveElement*>(pted->GetProjectable());
308 return el;
309 }
310 case kPS_Compound:
311 {
312 TEveElement* cmpnd = el->GetCompound();
313 if (cmpnd)
314 return cmpnd;
315 return el;
316 }
318 {
319 TEveProjected* pted = dynamic_cast<TEveProjected*>(el);
320 if (pted)
321 el = dynamic_cast<TEveElement*>(pted->GetProjectable());
322 TEveElement* cmpnd = el->GetCompound();
323 if (cmpnd)
324 return cmpnd;
325 return el;
326 }
327 case kPS_Master:
328 {
329 TEveElement* mstr = el->GetMaster();
330 if (mstr)
331 return mstr;
332 return el;
333 }
334 }
335 return el;
336}
337
338////////////////////////////////////////////////////////////////////////////////
339/// Called when user picks/clicks on an element. If multi is true,
340/// the user is requiring a multiple selection (usually this is
341/// associated with control-key being pressed at the time of pick
342/// event).
343
345{
346 TEveElement *edit_el = el ? el->ForwardEdit() : 0;
347
348 el = MapPickedToSelected(el);
349
350 if (el || HasChildren())
351 {
352 if (!multi)
354 if (el)
355 {
356 if (HasChild(el))
357 RemoveElement(el);
358 else
359 AddElement(el);
360 }
361 if (fIsMaster)
362 gEve->ElementSelect(edit_el ? edit_el : el);
363 gEve->Redraw3D();
364 }
365}
366
367////////////////////////////////////////////////////////////////////////////////
368/// Called when secondary selection becomes empty.
369
371{
372 el = MapPickedToSelected(el);
373 if (el && HasChild(el))
374 {
376 gEve->Redraw3D();
377 }
378}
379
380////////////////////////////////////////////////////////////////////////////////
381/// Called when secondary selection becomes empty.
382
384{
385 el = MapPickedToSelected(el);
386 if (el)
387 {
388 RemoveElement(el);
389 gEve->Redraw3D();
390 }
391}
long Longptr_t
Definition RtypesCore.h:82
const Bool_t kFALSE
Definition RtypesCore.h:101
const Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassImp(name)
Definition Rtypes.h:364
R__EXTERN TEveManager * gEve
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 FillImpliedSelectedSet(Set_t &impSelSet)
Populate set impSelSet with derived / dependant elements.
virtual TEveElement * ForwardSelection()
Returns element to be selected on click.
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
TEveElement * GetMaster()
Returns the master element - that is:
virtual void DecImpliedHighlighted()
Decrease element's implied-highlight count. Stamp appropriately.
TEveCompound * GetCompound()
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.
virtual TEveElement * ForwardEdit()
Returns element to be displayed in GUI editor on click.
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.
TEveProjectable * GetProjectable() const
Make sure there is a SINGLE running TEveSelection for each selection type (select/highlight).
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.
virtual Bool_t AcceptElement(TEveElement *el)
Pre-addition check.
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.
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.
virtual void RemoveElements()
Add an element into selection, virtual from TEveElement.
void RecheckImpliedSetForElement(TEveElement *el)
If given element is selected or implied-selected with this selection and recheck implied-set for give...
virtual void RemoveElement(TEveElement *el)
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.
virtual void RemoveElementsLocal()
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.
virtual void AddElement(TEveElement *el)
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 RemoveElementLocal(TEveElement *el)
Virtual from TEveElement.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
Definition TObject.cxx:949
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