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