Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveSecondarySelectable.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 
13 #include "TEveElement.h"
14 
15 #include "TGLSelectRecord.h"
16 
17 /** \class TEveSecondarySelectable
18 \ingroup TEve
19 Semi-abstract interface for classes supporting secondary-selection.
20 
21 Element class that inherits from this, should also implement the
22 following virtual methods from TEveElement:
23 ~~~ {.cpp}
24  virtual void UnSelected();
25  virtual void UnHighlighted();
26 ~~~
27 and clear corresponding selection-set from there.
28 
29 To support tooltips for sub-elements, implement:
30 ~~~ {.cpp}
31  virtual TString TEveElement::GetHighlightTooltip();
32 ~~~
33 and return tooltip for the entry in the fHighlightedSet.
34 There should always be a single entry there.
35 See TEveDigitSet for an example.
36 */
37 
38 ClassImp(TEveSecondarySelectable);
39 
40 ////////////////////////////////////////////////////////////////////////////////
41 /// Constructor.
42 
43 TEveSecondarySelectable::TEveSecondarySelectable() :
44  fAlwaysSecSelect(kFALSE)
45 {
46 }
47 
48 ////////////////////////////////////////////////////////////////////////////////
49 /// Process secondary GL selection and populate selected set accordingly.
50 
51 void TEveSecondarySelectable::ProcessGLSelection(TGLSelectRecord& rec)
52 {
53  if (rec.GetHighlight())
54  ProcessGLSelectionInternal(rec, fHighlightedSet);
55  else
56  ProcessGLSelectionInternal(rec, fSelectedSet);
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Process secondary GL selection and populate given set accordingly.
61 
62 void TEveSecondarySelectable::ProcessGLSelectionInternal(TGLSelectRecord& rec,
63  SelectionSet_t& sset)
64 {
65  Int_t id = (rec.GetN() > 1) ? (Int_t) rec.GetItem(1) : -1;
66 
67  if (sset.empty())
68  {
69  if (id >= 0)
70  {
71  sset.insert(id);
72  rec.SetSecSelResult(TGLSelectRecord::kEnteringSelection);
73  }
74  }
75  else
76  {
77  if (id >= 0)
78  {
79  if (rec.GetMultiple())
80  {
81  if (sset.find(id) == sset.end())
82  {
83  sset.insert(id);
84  rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection);
85  }
86  else
87  {
88  sset.erase(id);
89  if (sset.empty())
90  rec.SetSecSelResult(TGLSelectRecord::kLeavingSelection);
91  else
92  rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection);
93  }
94  }
95  else
96  {
97  if (sset.size() != 1 || sset.find(id) == sset.end())
98  {
99  sset.clear();
100  sset.insert(id);
101  rec.SetSecSelResult(TGLSelectRecord::kModifyingInternalSelection);
102  }
103  }
104  }
105  else
106  {
107  if (!rec.GetMultiple())
108  {
109  sset.clear();
110  rec.SetSecSelResult(TGLSelectRecord::kLeavingSelection);
111  }
112  }
113  }
114 
115  if (rec.GetSecSelResult() != TGLSelectRecord::kNone)
116  {
117  dynamic_cast<TEveElement*>(this)->StampColorSelection();
118  }
119 }