CMS 3D CMS Logo

CmsShowCommonPopup.cc
Go to the documentation of this file.
1 #include "TGFont.h"
2 #include "TGButton.h"
3 #include "TGLabel.h"
4 #include "TGSlider.h"
5 #include "TGComboBox.h"
6 #include "TGClient.h"
7 #include "TG3DLine.h"
8 #include "TGResourcePool.h"
9 #include "TGLUtil.h"
10 #include "TGLViewer.h"
11 #include "TEveManager.h"
12 #include "TEveViewer.h"
13 #include "TColor.h"
15 
23 
25 
29 
30 #include <boost/bind.hpp>
31 
32 CmsShowCommonPopup::CmsShowCommonPopup(CmsShowCommon* model, const TGWindow* p, UInt_t w, UInt_t h) :
33  TGTransientFrame(gClient->GetDefaultRoot(),p,w,h),
34  m_common(model),
35  m_backgroundButton(nullptr),
36  m_gammaSlider(nullptr),
37  m_gammaButton(nullptr),
38  m_colorRnrCtxHighlightWidget(nullptr),
39  m_colorRnrCtxSelectWidget(nullptr),
40  m_combo(nullptr)
41 {
42  SetCleanup(kDeepCleanup);
43 
44  TGGC *fTextGC;
45  const TGFont *font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
46  if (!font)
47  font = gClient->GetResourcePool()->GetDefaultFont();
48  GCValues_t gval;
49  gval.fMask = kGCBackground | kGCFont | kGCForeground;
50  gval.fFont = font->GetFontHandle();
51  fTextGC = gClient->GetGC(&gval, kTRUE);
52 
53 
54  TGCompositeFrame* vf2 = new TGVerticalFrame(this);
55  AddFrame(vf2, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
56  //==============================================================================
57  // scales
58  //
59  {
60  TGLabel* xx = new TGLabel(vf2, "GlobalScales ", fTextGC->GetGC());
61  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2,2,4,4));
62  }
64  vf2->AddFrame(scaleEditor);
65  //==============================================================================
66  // Projections
67  //
68  vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4,8,3,3));
69  {
70  TGLabel* xx = new TGLabel(vf2, "Projections ", fTextGC->GetGC());
71  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2,2,4,4));
72  }
73  vf2->AddFrame(new TGLabel(vf2, "Track behavior when crossing y=0 in RhoZ view:"),
74  new TGLayoutHints(kLHintsLeft, 2,2,0,0));
77 
78  //==============================================================================
79  // general colors
80  //
81 
82  vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4,8,8,2));
83  {
84  TGLabel* xx = new TGLabel(vf2, "General Colors ", fTextGC->GetGC());
85  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,4,4));
86  }
87  {
88  TGCompositeFrame *hf = new TGHorizontalFrame(vf2);
89  vf2->AddFrame(hf, new TGLayoutHints(kLHintsExpandX));
90 
91  m_backgroundButton = new TGTextButton(hf, "Black/White Background");
92  hf->AddFrame(m_backgroundButton, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,2,2,2));
93  m_backgroundButton->Connect("Clicked()", "CmsShowCommonPopup", this, "switchBackground()");
94 
96  }
97 
98  TGFont* smallFont = nullptr;
99  FontStruct_t defaultFontStruct = m_backgroundButton->GetDefaultFontStruct();
100  try
101  {
102  TGFontPool *pool = gClient->GetFontPool();
103  TGFont* defaultFont = pool->GetFont(defaultFontStruct);
104  FontAttributes_t attributes = defaultFont->GetFontAttributes();
105  smallFont = pool->GetFont(attributes.fFamily, 8, attributes.fWeight, attributes.fSlant);
106  }
107  catch(...)
108  {
109  // Ignore exceptions.
110  }
111 
112 
113  // color palette swapping
114  if (true) {
115  const TGCompositeFrame* f = static_cast<const TGCompositeFrame*>(makeSetter(vf2, &m_common->m_palette));
116  // MTXXXX combo is at(0) (label on right!) and there is a tgframeelement in between!
117  // for (int i = 0; i < f->GetList()->GetEntries(); ++i)
118  // printf("QWE %d %s\n", i, ((TGFrameElement*)f->GetList()->At(i))->fFrame->ClassName());
119  // m_combo = static_cast<TGComboBox*>(f->GetList()->At(1));
120  m_combo = static_cast<TGComboBox*>(static_cast<TGFrameElement*>(f->GetList()->At(0))->fFrame);
121  m_common->m_palette.changed_.connect(boost::bind(&CmsShowCommonPopup::setPaletteGUI, this));
122 
123  TGCompositeFrame *hf = new TGHorizontalFrame(vf2);
124  vf2->AddFrame(hf, new TGLayoutHints(kLHintsExpandX));
125  {
126  TGButton *butt;
127  butt = new TGTextButton(hf, "Permute Colors");
128  butt->SetToolTipText("Randomize assigned collection colors");
129  hf->AddFrame(butt, new TGLayoutHints(kLHintsLeft|kLHintsCenterY, 2,2,2,2));
130  butt->Connect("Clicked()", "CmsShowCommonPopup", this, "permuteColors()");
131 
132 
133  butt = new TGTextButton(hf, "Randomize Colors");
134  butt->SetToolTipText("Randomize collection colors from full palette");
135  hf->AddFrame(butt, new TGLayoutHints(kLHintsNormal, 0, 0, 2,2));
136  butt->Connect("Clicked()", "CmsShowCommonPopup", this, "randomizeColors()");
137  }
138  }
139 
140  // rnrCtx colorset
141  {
142  int hci, sci;
143  getColorSetColors(hci, sci);
144  TGHorizontalFrame* top = new TGHorizontalFrame(vf2);
145  vf2->AddFrame(top);
146  {
147  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
148  top->AddFrame(hf);
149 
150  m_colorRnrCtxHighlightWidget = new FWColorSelect(hf, "Highlight", 0, m_common->colorManager(), 3);
151  hf->AddFrame(m_colorRnrCtxHighlightWidget);
153  m_colorRnrCtxHighlightWidget->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
154 
155  TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 45, 16, kFixedSize);
156  TGLabel* label = new TGLabel(lf, "Higlight");
157  label->SetTextFont(smallFont);
158  lf->AddFrame(label);
159  hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft|kLHintsCenterY));
160  }
161 
162  {
163  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
164  top->AddFrame(hf);
165 
166  m_colorRnrCtxSelectWidget = new FWColorSelect(hf, "Selection", 0, m_common->colorManager(), 1);
167  hf->AddFrame(m_colorRnrCtxSelectWidget);
169  m_colorRnrCtxSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
170 
171  TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 45, 16, kFixedSize);
172  TGLabel* label = new TGLabel(lf, "Selection");
173  label->SetTextFont(smallFont);
174  lf->AddFrame(label);
175  hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft|kLHintsCenterY));
176  }
177  }
178  vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4,8,8,2));
179 
180  //==============================================================================
181  // geom colors
182  //
183 
184  {
185  TGLabel* xx = new TGLabel(vf2, "DetectorColors ", fTextGC->GetGC());
186  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,8,0));
187  }
188 
189  TGHSlider* transpWidget2D = nullptr;
190  TGHSlider* transpWidget3D = nullptr;
191  TGCompositeFrame* top = new TGVerticalFrame(vf2);
192  vf2->AddFrame(top, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 0));
193 
194  {
195  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
196  hf->AddFrame(new TGLabel(hf, "Tansparency 2D:"), new TGLayoutHints(kLHintsBottom, 2, 2, 3, 3));
197  transpWidget2D = new TGHSlider(hf, 100, kSlider1);
198  hf->AddFrame( transpWidget2D);
199  top->AddFrame(hf,new TGLayoutHints( kLHintsNormal, 0, 0, 2, 2));
200  }
201  {
202  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
203  hf->AddFrame(new TGLabel(hf, "Tansparency 3D:") , new TGLayoutHints(kLHintsBottom,2, 2, 2, 2 ));
204  transpWidget3D = new TGHSlider(hf, 100, kSlider1);
205  hf->AddFrame( transpWidget3D);
206  top->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 10));
207  }
209  names[kFWPixelBarrelColorIndex ] = "Pixel Barrel";
210  names[kFWPixelEndcapColorIndex ] = "Pixel Endcap" ;
211  names[kFWTrackerBarrelColorIndex ] = "Tracker Barrel";
212  names[kFWTrackerEndcapColorIndex ] = "Tracker Endcap";
213  names[kFWMuonBarrelLineColorIndex] = "Muon Barrel";
214  names[kFWMuonEndcapLineColorIndex] = "Muon Endcap";
215  int i = 0;
216  for (int k = 0; k < 3; ++k)
217  {
218  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
219  top->AddFrame(hf);
220 
221  for (int j = 0; j < 2; ++j)
222  {
223  m_colorSelectWidget[i] = new FWColorSelect(hf, names[i].c_str(), 0, m_common->colorManager(), i);
224  hf->AddFrame(m_colorSelectWidget[i]);
226  m_colorSelectWidget[i]->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeGeomColor(Color_t)");
227 
228  TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
229  TGLabel* label = new TGLabel(lf, m_colorSelectWidget[i]->label().c_str());
230  label->SetTextFont(smallFont);
231  lf->AddFrame(label);
232  hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0));
233 
234  ++i;
235  }
236  }
237  //==============================================================================
238 
239  transpWidget2D->SetRange(0, 100);
240  transpWidget2D->SetPosition(m_common->colorManager()->geomTransparency(true));
241  transpWidget2D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency2D(Int_t)");
242 
243  transpWidget3D->SetRange(0, 100);
244  transpWidget3D->SetPosition(m_common->colorManager()->geomTransparency(false));
245  transpWidget3D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency3D(Int_t)");
246 
247  SetWindowName("Common Preferences");
248  MapSubwindows();
249  Resize(GetDefaultSize());
250  Layout();
251  CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
252 }
253 
254 
256 {}
257 
258 //==============================================================================
259 
260 void
262 
263 void
265 
266 void
268 
269 void
271 {
272  TGColorSelect *cs = (TGColorSelect *) gTQSender;
273  FWGeomColorIndex cidx = FWGeomColorIndex(cs->WidgetId());
274  m_common->setGeomColor(cidx, iColor);
275 }
276 
277 
278 void
280 {
281  TGColorSelect *cs = (TGColorSelect *) gTQSender;
282 
283  //printf("~~~~~ changeSelectionColorSet sel[%d] idx[%d]\n", cs->WidgetId(), idx);
284  for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it)
285  {
286  TGLViewer* v = ((TEveViewer*)(*it))->GetGLViewer();
287 
288  TGLColorSet& colorset = m_common->colorManager()->isColorSetDark() ? v->RefDarkColorSet():v->RefLightColorSet();
289  colorset.Selection(cs->WidgetId()).SetColor(idx);
290  colorset.Selection(cs->WidgetId()+1).SetColor(idx); // implied selected/higlighted
291  }
292 }
293 
294 
295 void
297 {
298  m_common->setGeomTransparency(iTransp, true);
299 }
300 
301 void
303 {
304  m_common->setGeomTransparency(iTransp, false);
305 }
306 
307 
308 /* Called by FWGUIManager when change background. */
309 void
311 {
312  for (int i = 0 ; i < kFWGeomColorSize; ++i)
313  m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
314 
315  int hci, sci;
316  getColorSetColors(hci, sci);
317  // printf("=============== colorSetChanged() dark ? [%d] %d %d \n",m_common->colorManager()->isColorSetDark(), hci, sci);
320 }
321 
322 void CmsShowCommonPopup::getColorSetColors (int& hci, int& sci)
323 {
324  TGLColorSet& colorset = m_common->colorManager()->isColorSetDark() ?
326  {
327  TGLColor& glc = colorset.Selection(3);
328  hci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
329  // printf("getSHcolors HIGH %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), hci);
330  }
331  {
332  TGLColor& glc = colorset.Selection(1);
333  sci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
334  // printf("getSHcolors SEL %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), sci);
335  }
336 }
337 
338 TGFrame*
339 CmsShowCommonPopup::makeSetter(TGCompositeFrame* frame, FWParameterBase* param)
340 {
341  std::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor(param) );
342  ptr->attach(param, this);
343 
344  TGFrame* pframe = ptr->build(frame);
345  frame->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
346 
347  m_setters.push_back(ptr);
348  return pframe;
349 }
350 
351 
352 
353 void
355 {
356  m_common->setPalette();
357 
358  for (int i = 0 ; i < kFWGeomColorSize; ++i) {
360  // m_common->m_geomColors[i]->set(cm->geomColor(FWGeomColorIndex(i)));
362  }
363 }
void changeSelectionColorSet(Color_t)
CmsShowCommonPopup(CmsShowCommon *, const TGWindow *p=nullptr, UInt_t w=1, UInt_t h=1)
FWColorSelect * m_colorSelectWidget[kFWGeomColorSize]
TGLColorSet m_lightColorSet
Color_t geomTransparency(bool projected) const
const double w
Definition: UKUtility.cc:23
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void SetColorByIndex(Color_t iColor)
FWBoolParameter m_drawBreakPoints
unique_ptr< ClusterSequence > cs
FWColorManager * colorManager() const
Definition: Context.h:65
FWGeomColorIndex
#define nullptr
sigc::signal< void, T > changed_
const FWColorManager * colorManager() const
const std::string names[nVars_]
Bool_t isColorSetDark() const
TGTextButton * m_backgroundButton
FWLongParameter m_gamma
void setGeomTransparency(int val, bool projected)
void changeGeomTransparency2D(int)
char const * label
void changeGeomTransparency3D(int)
void randomizeColors()
void changeGeomColor(Color_t)
void getColorSetColors(int &hci, int &sci)
std::vector< std::shared_ptr< FWParameterSetterBase > > m_setters
double f[11][100]
CmsShowCommon * m_common
void setGeomColor(FWGeomColorIndex, Color_t)
fireworks::Context * m_context
Definition: CmsShowCommon.h:97
void switchBackground()
globcontrol glc
Definition: vlib.cc:6
int k[5][pyjets_maxn]
TGFrame * makeSetter(TGCompositeFrame *frame, FWParameterBase *param)
FWViewEnergyScale * getEnergyScale() const
Definition: CmsShowCommon.h:72
void permuteColors()
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
FWColorSelect * m_colorRnrCtxHighlightWidget
TGLColorSet m_darkColorSet
FWColorSelect * m_colorRnrCtxSelectWidget
FWEnumParameter m_trackBreak
Definition: CmsShowCommon.h:99
Color_t geomColor(FWGeomColorIndex) const
FWEnumParameter m_palette