Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TEveCompound.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 "TEveCompound.h"
13 
14 /** \class TEveCompound
15 \ingroup TEve
16 Description of TEveCompound
17 */
18 
19 ClassImp(TEveCompound);
20 
21 ////////////////////////////////////////////////////////////////////////////////
22 /// Constructor.
23 
24 TEveCompound::TEveCompound(const char* n, const char* t, Bool_t doColor, Bool_t doTransparency) :
25  TEveElementList (n, t, doColor, doTransparency),
26  fCompoundOpen (0)
27 {
28 }
29 
30 ////////////////////////////////////////////////////////////////////////////////
31 /// SetMainColor for the compound.
32 /// The color is also propagated to children with compound set to this
33 /// whose current color is the same as the old color.
34 ///
35 /// The following CompoundSelectionColorBits have further influence:
36 /// - kCSCBApplyMainColorToAllChildren - apply color to all children;
37 /// - kCSCBApplyMainColorToMatchingChildren - apply color to children who have
38 /// matching old color.
39 
40 void TEveCompound::SetMainColor(Color_t color)
41 {
42  Color_t old_color = GetMainColor();
43 
44  TEveElement::SetMainColor(color);
45 
46  Bool_t color_all = TestCSCBits(kCSCBApplyMainColorToAllChildren);
47  Bool_t color_matching = TestCSCBits(kCSCBApplyMainColorToMatchingChildren);
48 
49  for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
50  {
51  if (color_all || (color_matching && (*i)->GetMainColor() == old_color) ||
52  ((*i)->GetCompound() == this && (*i)->GetMainColor() == old_color))
53  {
54  (*i)->SetMainColor(color);
55  }
56  }
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// SetMainTransparency for the compound.
61 /// The transparency is also propagated to children with compound set to this
62 /// whose current transparency is the same as the old transparency.
63 ///
64 /// The following CompoundSelectionColorBits have further influence:
65 /// - kCSCBApplyMainTransparencyToAllChildren - apply transparency to all children;
66 /// - kCSCBApplyMainTransparencyToMatchingChildren - apply transparency to children who have
67 /// matching transparency.
68 
69 void TEveCompound::SetMainTransparency(Char_t t)
70 {
71  Char_t old_t = GetMainTransparency();
72 
73  TEveElement::SetMainTransparency(t);
74 
75  Bool_t chg_all = TestCSCBits(kCSCBApplyMainTransparencyToAllChildren);
76  Bool_t chg_matching = TestCSCBits(kCSCBApplyMainTransparencyToMatchingChildren);
77 
78  for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
79  {
80  if (chg_all || (chg_matching && (*i)->GetMainTransparency() == old_t) ||
81  ((*i)->GetCompound() == this && (*i)->GetMainTransparency() == old_t))
82  {
83  (*i)->SetMainTransparency(t);
84  }
85  }
86 }
87 
88 ////////////////////////////////////////////////////////////////////////////////
89 /// Call base-class implementation.
90 /// If compound is open and compound of the new element is not set,
91 /// the el's compound is set to this.
92 /// You might also want to call RecheckImpliedSelections().
93 
94 void TEveCompound::AddElement(TEveElement* el)
95 {
96  TEveElementList::AddElement(el);
97  if (IsCompoundOpen() && el->GetCompound() == 0)
98  el->SetCompound(this);
99 }
100 
101 ////////////////////////////////////////////////////////////////////////////////
102 /// Decompoundofy el, call base-class version.
103 
104 void TEveCompound::RemoveElementLocal(TEveElement* el)
105 {
106  if (el->GetCompound() == this)
107  el->SetCompound(0);
108 
109  TEveElementList::RemoveElementLocal(el);
110 }
111 
112 ////////////////////////////////////////////////////////////////////////////////
113 /// Decompoundofy children, call base-class version.
114 
115 void TEveCompound::RemoveElementsLocal()
116 {
117  for (List_i i=fChildren.begin(); i!=fChildren.end(); ++i)
118  {
119  if ((*i)->GetCompound() == this)
120  (*i)->SetCompound(0);
121  }
122 
123  TEveElementList::RemoveElementsLocal();
124 }
125 
126 ////////////////////////////////////////////////////////////////////////////////
127 /// Recurse on all children that are in this compound and
128 /// call the base-class version.
129 /// If SelectionColorBit kSCBImplySelectAllChildren is set, then all
130 /// children are added to the set.
131 ///
132 /// Note that projected replicas of the compound will be added to
133 /// the set in base-class function that handles projectable.
134 
135 void TEveCompound::FillImpliedSelectedSet(Set_t& impSelSet)
136 {
137  Bool_t select_all = TestCSCBits(kCSCBImplySelectAllChildren);
138 
139  for (List_i i = fChildren.begin(); i != fChildren.end(); ++i)
140  {
141  if (select_all || (*i)->GetCompound() == this)
142  {
143  if (impSelSet.insert(*i).second)
144  (*i)->FillImpliedSelectedSet(impSelSet);
145  }
146  }
147 
148  TEveElementList::FillImpliedSelectedSet(impSelSet);
149 }
150 
151 ////////////////////////////////////////////////////////////////////////////////
152 /// Virtual from TEveProjectable, returns TEveCompoundProjected class.
153 
154 TClass* TEveCompound::ProjectedClass(const TEveProjection*) const
155 {
156  return TEveCompoundProjected::Class();
157 }
158 
159 
160 /** \class TEveCompoundProjected
161 \ingroup TEve
162 Description of TEveCompoundProjected
163 */
164 
165 ClassImp(TEveCompoundProjected);
166 
167 ////////////////////////////////////////////////////////////////////////////////
168 /// Constructor.
169 
170 TEveCompoundProjected::TEveCompoundProjected() :
171  TEveCompound (),
172  TEveProjected ()
173 {
174 }
175 
176 ////////////////////////////////////////////////////////////////////////////////
177 /// Revert back to the behaviour of TEveElement as color
178 /// is propagated:
179 /// 1. from projectable -> projected
180 /// 2. from compound -> compound elements
181 /// and we do not need to do this twice for projected-compound-elements.
182 
183 void TEveCompoundProjected::SetMainColor(Color_t color)
184 {
185  TEveElement::SetMainColor(color);
186 }