CMS 3D CMS Logo

CmsShowCommon.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : CmsShowCommon
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel
10 // Created: Fri Sep 10 14:50:32 CEST 2010
11 //
12 
13 // system include files
14 #include <boost/bind.hpp>
15 #include <iostream>
16 // user include files
17 
18 #include "TEveManager.h"
19 #include "TEveTrackPropagator.h"
20 #include "TGLViewer.h"
21 #include "TEveViewer.h"
22 #include "TGComboBox.h"
23 #include "TGClient.h"
24 #include "TGTextEntry.h"
25 
30 
34 
35 //
36 // constructors and destructor
37 //
40  m_view(0),
41  m_context(c),
42  m_trackBreak(this, " ", 2l, 0l, 2l), // do not want to render text at setter
43  m_drawBreakPoints(this, "Show y=0 points as markers", false),
44  m_backgroundColor(this, "backgroundColIdx", 1l, 0l, 1000l),
45  m_gamma(this, "Brightness", 0l, -15l, 15l),
46  m_palette(this, "Palette", 1l, 0l, 2l ),
47  m_geomTransparency2D(this, "Transparency 2D", long(colorManager()->geomTransparency(true)), 0l, 100l),
48  m_geomTransparency3D(this, "Transparency 3D", long(colorManager()->geomTransparency(false)), 0l, 100l),
49  m_energyScale(new FWViewEnergyScale("global", 2))
50 {
51  // projections
52  m_trackBreak.addEntry(0, "Jump to proper hemisphere");
53  m_trackBreak.addEntry(1, "Stay on first point side");
54  m_trackBreak.addEntry(2, "Stay on last point side");
55 
61 
62  // colors
63  char name[32];
64  for (int i = 0; i < kFWGeomColorSize; ++i)
65  {
66  snprintf(name, 31, "GeometryColor %d ", i);
67  m_geomColors[i] = new FWLongParameter(this, name , long(colorManager()->geomColor(FWGeomColorIndex(i))), 1000l, 1100l);
68  }
69 
70  m_trackBreak.changed_.connect(boost::bind(&CmsShowCommon::setTrackBreakMode, this));
73  m_gamma.changed_.connect(boost::bind(&CmsShowCommon::setGamma, this));
74 
75  m_lightColorSet.StdLightBackground();
76  m_darkColorSet .StdDarkBackground();
77 }
78 
80 {
81 }
82 
83 
85 {
86  return m_context->colorManager();
87 }
88 //
89 // member functions
90 //
91 
92 
93 void
95 {
96  if (m_context->getTrackPropagator()->GetProjTrackBreaking() != m_trackBreak.value())
97  {
98  m_context->getTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
99  m_context->getTrackerTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
100  m_context->getMuonTrackPropagator()->SetProjTrackBreaking(m_trackBreak.value());
101  gEve->Redraw3D();
102  }
103 }
104 
105 
106 
107 
108 void
110 {
111  if (m_context->getTrackPropagator()->GetRnrPTBMarkers() != m_drawBreakPoints.value())
112  {
113  m_context->getTrackPropagator()->SetRnrPTBMarkers(m_drawBreakPoints.value());
116  gEve->Redraw3D();
117  }
118 }
119 
120 void
122 {
124 }
125 
126 void
128 {
130  m_backgroundColor.set(colorManager()->background());
131 }
132 
133 
134 void
136 {
137  // printf("Reverting order of existing colors ...\n");
138 
139  std::vector<Color_t> colv;
140  colv.reserve(64);
141 
143  i != m_context->eventItemsManager()->end(); ++i)
144  {
145  colv.push_back((*i)->defaultDisplayProperties().color());
146  }
147 
148  int vi = colv.size() - 1;
150  i != m_context->eventItemsManager()->end(); ++i, --vi)
151  {
152  FWDisplayProperties prop = (*i)->defaultDisplayProperties();
153  prop.setColor(colv[vi]);
154  (*i)->setDefaultDisplayProperties(prop);
155 
156  (*i)->defaultDisplayPropertiesChanged_(*i);
157  }
158  }
159 
160 void
162 {
163  // printf("Doing random_shuffle on existing colors ...\n");
164 
165  int vi = 0;
167  i != m_context->eventItemsManager()->end(); ++i, ++vi)
168  {
169  FWDisplayProperties prop = (*i)->defaultDisplayProperties();
170 
171  int col = rand() % 17; // randomize in first row of palette
172  prop.setColor(col);
173  (*i)->setDefaultDisplayProperties(prop);
174 
175  (*i)->defaultDisplayPropertiesChanged_(*i);
176  }
177 }
178 
179 void
181 {
182  m_geomColors[cidx]->set(iColor);
183  m_context->colorManager()->setGeomColor(cidx, iColor);
184 }
185 
186 void
187 CmsShowCommon::setGeomTransparency(int iTransp, bool projected)
188 {
189  if (projected)
190  m_geomTransparency2D.set(iTransp);
191  else
192  m_geomTransparency3D.set(iTransp);
193 
194  m_context->colorManager()->setGeomTransparency(iTransp, projected);
195 }
196 
197 //____________________________________________________________________________
198 
199 namespace
200 {
201  void addGLColorToConfig(const char* cname, const TGLColor& c, FWConfiguration& oTo)
202  {
203  FWConfiguration pc;
204 
205  std::ostringstream sRed;
206  sRed << (int)c.GetRed();
207  pc.addKeyValue("Red", sRed.str());
208 
209  std::ostringstream sGreen;
210  sGreen << (int)c.GetGreen();
211  pc.addKeyValue("Green", sGreen.str());
212 
213  std::ostringstream sBlue;
214  sBlue << (int)c.GetBlue();
215  pc.addKeyValue("Blue", sBlue.str());
216 
217  oTo.addKeyValue(cname, pc, true);
218  }
219 
220  void setGLColorFromConfig(TGLColor& d, const FWConfiguration* iFrom )
221  {
222  if (!iFrom) return;
223  d.Arr()[0] = atoi(iFrom->valueForKey("Red")->value().c_str());
224  d.Arr()[1] = atoi(iFrom->valueForKey("Green")->value().c_str());
225  d.Arr()[2] = atoi(iFrom->valueForKey("Blue")->value().c_str());
226  // printf("22222 colors %d %d %d \n", d.Arr()[0], d.Arr()[1], d.Arr()[2]);
227  }
228 }
229 
230 void
232 {
233  m_backgroundColor.set(int(colorManager()->background()));
234 
236  m_energyScale->addTo(oTo);
237 
238  if (gEve)
239  {
240  addGLColorToConfig("SelectionColorLight", m_lightColorSet.Selection(1), oTo);
241  addGLColorToConfig("HighlightColorLight", m_lightColorSet.Selection(3), oTo);
242  addGLColorToConfig("SelectionColorDark", m_darkColorSet .Selection(1), oTo);
243  addGLColorToConfig("HighlightColorDark", m_darkColorSet .Selection(3), oTo);
244  }
245 }
246 
247 void
249 {
250  for(const_iterator it =begin(), itEnd = end();
251  it != itEnd;
252  ++it) {
253  (*it)->setFrom(iFrom);
254  }
255 
256  if (iFrom.valueForKey("Palette"))
257  setPalette();
258 
259  // handle old and new energy scale configuration if existing
260  if (iFrom.valueForKey("ScaleMode"))
261  {
262  long mode = atol(iFrom.valueForKey("ScaleMode")->value().c_str());
263 
264  float convert;
265  if (iFrom.valueForKey("EnergyToLength [GeV/m]"))
266  convert = atof(iFrom.valueForKey("EnergyToLength [GeV/m]")->value().c_str());
267  else
268  convert = atof(iFrom.valueForKey("ValueToHeight [GeV/m]")->value().c_str());
269 
270  float maxH;
271  if (iFrom.valueForKey("MaximumLength [m]"))
272  maxH = atof(iFrom.valueForKey("MaximumLength [m]")->value().c_str());
273  else
274  maxH = atof(iFrom.valueForKey("MaxTowerH [m]")->value().c_str());
275 
276  int et = atoi(iFrom.valueForKey("PlotEt")->value().c_str());
277  m_energyScale->SetFromCmsShowCommonConfig(mode, convert, maxH, et);
278  }
279 
280  // background
283 
284  // geom colors
287 
288  for (int i = 0; i < kFWGeomColorSize; ++i)
290 
291  if (gEve)
292  {
293  setGLColorFromConfig(m_lightColorSet.Selection(1), iFrom.valueForKey("SelectionColorLight"));
294  setGLColorFromConfig(m_lightColorSet.Selection(3), iFrom.valueForKey("HighlightColorLight"));
295  setGLColorFromConfig(m_darkColorSet .Selection(1), iFrom.valueForKey("SelectionColorDark"));
296  setGLColorFromConfig(m_darkColorSet .Selection(3), iFrom.valueForKey("HighlightColorDark"));
297  }
298 }
299 
300 
301 
302 void
304 {
306  cm->setPalette(m_palette.value());
307 
308  for (int i = 0 ; i < kFWGeomColorSize; ++i) {
311  // m_colorSelectWidget[i]->SetColorByIndex(cm->geomColor(FWGeomColorIndex(i)), kFALSE);
312  }
313 
316  i != m_context->eventItemsManager()->end(); ++i)
317  {
318  (*i)->resetColor();
319  }
320 }
321 
322 
323 void
325 {
326  int val = m_palette.value();
327  val++;
328 
329  if (val >= FWColorManager::kPaletteLast)
331 
332  if (m_view)
333  {
334  TGComboBox* combo = m_view->getCombo();
335  combo->Select(val, true);
336  }
337  else
338  {
339  m_palette.set(val);
340  setPalette();
341  }
342 }
void setColor(Color_t iColor)
TGLColorSet m_lightColorSet
std::vector< FWParameterBase * >::const_iterator const_iterator
const FWEventItemsManager * eventItemsManager() const
Definition: Context.h:61
const_iterator begin() const
FWBoolParameter m_drawBreakPoints
Definition: CmsShowCommon.h:91
TEveTrackPropagator * getTrackerTrackPropagator() const
Definition: Context.h:74
FWLongParameter m_backgroundColor
Definition: CmsShowCommon.h:94
FWColorManager * colorManager() const
Definition: Context.h:65
FWGeomColorIndex
void setTrackBreakMode()
FWLongParameter * m_geomColors[kFWGeomColorSize]
TEveTrackPropagator * getTrackPropagator() const
Definition: Context.h:73
sigc::signal< void, T > changed_
const FWColorManager * colorManager() const
FWLongParameter m_gamma
Definition: CmsShowCommon.h:95
void setGeomColor(FWGeomColorIndex, Color_t)
void setGeomTransparency(int val, bool projected)
void setGeomTransparency(Color_t idx, bool projectedType)
void setPalette(long long)
virtual ~CmsShowCommon()
void randomizeColors()
const_iterator end() const
bool addEntry(Long_t id, const std::string &txt)
void setBrightness(int)
void setGeomColor(FWGeomColorIndex, Color_t)
fireworks::Context * m_context
Definition: CmsShowCommon.h:88
def convert(infile, ofile)
void switchBackground()
FWLongParameter m_geomTransparency3D
void setDrawBreakMarkers()
TEveTrackPropagator * getMuonTrackPropagator() const
Definition: Context.h:75
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const std::string & value(unsigned int iIndex=0) const
FWLongParameter m_geomTransparency2D
Definition: CmsShowCommon.h:99
TGComboBox * getCombo()
const_iterator begin() const
NOTE: iterator is allowed to return a null object for items that have been removed.
std::auto_ptr< FWViewEnergyScale > m_energyScale
virtual void addTo(FWConfiguration &) const
CmsShowCommonPopup * m_view
Definition: CmsShowCommon.h:87
void permuteColors()
et
define resolution functions of each parameter
void setBackgroundAndBrightness(BackgroundColorIndex, int)
void propagatePaletteChanges() const
col
Definition: cuy.py:1008
Signal rand(Signal arg)
Definition: vlib.cc:442
TGLColorSet m_darkColorSet
FWParameters::Long FWLongParameter
Definition: FWParameters.h:35
virtual void setFrom(const FWConfiguration &)
const FWConfiguration * valueForKey(const std::string &iKey) const
FWEnumParameter m_trackBreak
Definition: CmsShowCommon.h:90
Color_t geomColor(FWGeomColorIndex) const
EPalette getPalette() const
std::vector< FWEventItem * >::const_iterator const_iterator
CmsShowCommon(fireworks::Context *)
const_iterator end() const
virtual void addTo(FWConfiguration &) const
FWEnumParameter m_palette
Definition: CmsShowCommon.h:96