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 <functional>
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  SetCleanup(kDeepCleanup);
42 
43  TGGC* fTextGC;
44  const TGFont* font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
45  if (!font)
46  font = gClient->GetResourcePool()->GetDefaultFont();
47  GCValues_t gval;
48  gval.fMask = kGCBackground | kGCFont | kGCForeground;
49  gval.fFont = font->GetFontHandle();
50  fTextGC = gClient->GetGC(&gval, kTRUE);
51 
52  TGCompositeFrame* vf2 = new TGVerticalFrame(this);
53  AddFrame(vf2, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
54  //==============================================================================
55  // scales
56  //
57  {
58  TGLabel* xx = new TGLabel(vf2, "GlobalScales ", fTextGC->GetGC());
59  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
60  }
62  vf2->AddFrame(scaleEditor);
63  //==============================================================================
64  // Projections
65  //
66  vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4, 8, 3, 3));
67  {
68  TGLabel* xx = new TGLabel(vf2, "Projections ", fTextGC->GetGC());
69  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
70  }
71  vf2->AddFrame(new TGLabel(vf2, "Track behavior when crossing y=0 in RhoZ view:"),
72  new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
75 
76  //==============================================================================
77  // general colors
78  //
79 
80  vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4, 8, 8, 2));
81  {
82  TGLabel* xx = new TGLabel(vf2, "General Colors ", fTextGC->GetGC());
83  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
84  }
85  {
86  TGCompositeFrame* hf = new TGHorizontalFrame(vf2);
87  vf2->AddFrame(hf, new TGLayoutHints(kLHintsExpandX));
88 
89  m_backgroundButton = new TGTextButton(hf, "Black/White Background");
90  hf->AddFrame(m_backgroundButton, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
91  m_backgroundButton->Connect("Clicked()", "CmsShowCommonPopup", this, "switchBackground()");
92 
94  }
95 
96  TGFont* smallFont = nullptr;
97  FontStruct_t defaultFontStruct = m_backgroundButton->GetDefaultFontStruct();
98  try {
99  TGFontPool* pool = gClient->GetFontPool();
100  TGFont* defaultFont = pool->GetFont(defaultFontStruct);
101  FontAttributes_t attributes = defaultFont->GetFontAttributes();
102  smallFont = pool->GetFont(attributes.fFamily, 8, attributes.fWeight, attributes.fSlant);
103  } catch (...) {
104  // Ignore exceptions.
105  }
106 
107  // color palette swapping
108  if (true) {
109  const TGCompositeFrame* f = static_cast<const TGCompositeFrame*>(makeSetter(vf2, &m_common->m_palette));
110  // MTXXXX combo is at(0) (label on right!) and there is a tgframeelement in between!
111  // for (int i = 0; i < f->GetList()->GetEntries(); ++i)
112  // printf("QWE %d %s\n", i, ((TGFrameElement*)f->GetList()->At(i))->fFrame->ClassName());
113  // m_combo = static_cast<TGComboBox*>(f->GetList()->At(1));
114  m_combo = static_cast<TGComboBox*>(static_cast<TGFrameElement*>(f->GetList()->At(0))->fFrame);
115  m_common->m_palette.changed_.connect(std::bind(&CmsShowCommonPopup::setPaletteGUI, this));
116 
117  TGCompositeFrame* hf = new TGHorizontalFrame(vf2);
118  vf2->AddFrame(hf, new TGLayoutHints(kLHintsExpandX));
119  {
120  TGButton* butt;
121  butt = new TGTextButton(hf, "Permute Colors");
122  butt->SetToolTipText("Randomize assigned collection colors");
123  hf->AddFrame(butt, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
124  butt->Connect("Clicked()", "CmsShowCommonPopup", this, "permuteColors()");
125 
126  butt = new TGTextButton(hf, "Randomize Colors");
127  butt->SetToolTipText("Randomize collection colors from full palette");
128  hf->AddFrame(butt, new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
129  butt->Connect("Clicked()", "CmsShowCommonPopup", this, "randomizeColors()");
130  }
131  }
132 
133  // rnrCtx colorset
134  {
135  int hci, sci;
136  getColorSetColors(hci, sci);
137  TGHorizontalFrame* top = new TGHorizontalFrame(vf2);
138  vf2->AddFrame(top);
139  {
140  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
141  top->AddFrame(hf);
142 
143  m_colorRnrCtxHighlightWidget = new FWColorSelect(hf, "Highlight", 0, m_common->colorManager(), 3);
144  hf->AddFrame(m_colorRnrCtxHighlightWidget);
147  "ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
148 
149  TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 45, 16, kFixedSize);
150  TGLabel* label = new TGLabel(lf, "Higlight");
151  label->SetTextFont(smallFont);
152  lf->AddFrame(label);
153  hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
154  }
155 
156  {
157  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
158  top->AddFrame(hf);
159 
160  m_colorRnrCtxSelectWidget = new FWColorSelect(hf, "Selection", 0, m_common->colorManager(), 1);
161  hf->AddFrame(m_colorRnrCtxSelectWidget);
163  m_colorRnrCtxSelectWidget->Connect(
164  "ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
165 
166  TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 45, 16, kFixedSize);
167  TGLabel* label = new TGLabel(lf, "Selection");
168  label->SetTextFont(smallFont);
169  lf->AddFrame(label);
170  hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
171  }
172  }
173  vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4, 8, 8, 2));
174 
175  //==============================================================================
176  // geom colors
177  //
178 
179  {
180  TGLabel* xx = new TGLabel(vf2, "DetectorColors ", fTextGC->GetGC());
181  vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 8, 0));
182  }
183 
184  TGHSlider* transpWidget2D = nullptr;
185  TGHSlider* transpWidget3D = nullptr;
186  TGCompositeFrame* top = new TGVerticalFrame(vf2);
187  vf2->AddFrame(top, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 0));
188 
189  {
190  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
191  hf->AddFrame(new TGLabel(hf, "Tansparency 2D:"), new TGLayoutHints(kLHintsBottom, 2, 2, 3, 3));
192  transpWidget2D = new TGHSlider(hf, 100, kSlider1);
193  hf->AddFrame(transpWidget2D);
194  top->AddFrame(hf, new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
195  }
196  {
197  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
198  hf->AddFrame(new TGLabel(hf, "Tansparency 3D:"), new TGLayoutHints(kLHintsBottom, 2, 2, 2, 2));
199  transpWidget3D = new TGHSlider(hf, 100, kSlider1);
200  hf->AddFrame(transpWidget3D);
201  top->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 10));
202  }
203 
205  names[kFWPixelBarrelColorIndex] = "Pixel Barrel";
206  names[kFWPixelEndcapColorIndex] = "Pixel Endcap";
207  names[kFWTrackerBarrelColorIndex] = "Tracker Barrel";
208  names[kFWTrackerEndcapColorIndex] = "Tracker Endcap";
209  names[kFWMuonBarrelLineColorIndex] = "Muon Barrel";
210  names[kFWMuonEndcapLineColorIndex] = "Muon Endcap";
211  int i = 0;
212  for (int k = 0; k < 3; ++k) {
213  TGHorizontalFrame* hf = new TGHorizontalFrame(top);
214  top->AddFrame(hf);
215  for (int j = 0; j < 3; ++j) {
216  m_colorSelectWidget[i] = new FWColorSelect(hf, names[i].c_str(), 0, m_common->colorManager(), i);
217  hf->AddFrame(m_colorSelectWidget[i]);
219  m_colorSelectWidget[i]->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeGeomColor(Color_t)");
220 
221  TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
222  TGLabel* label = new TGLabel(lf, m_colorSelectWidget[i]->label().c_str());
223  label->SetTextFont(smallFont);
224  lf->AddFrame(label);
225  hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 0, 0, 0));
226 
227  ++i;
228  }
229  }
230  //==============================================================================
231 
232  transpWidget2D->SetRange(0, 100);
233  transpWidget2D->SetPosition(m_common->colorManager()->geomTransparency(true));
234  transpWidget2D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency2D(Int_t)");
235 
236  transpWidget3D->SetRange(0, 100);
237  transpWidget3D->SetPosition(m_common->colorManager()->geomTransparency(false));
238  transpWidget3D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency3D(Int_t)");
239 
240  SetWindowName("Common Preferences");
241  MapSubwindows();
242  Resize(GetDefaultSize());
243  Layout();
244  CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
245 }
246 
248 
249 //==============================================================================
250 
252 
254 
256 
258  TGColorSelect* cs = (TGColorSelect*)gTQSender;
259  FWGeomColorIndex cidx = FWGeomColorIndex(cs->WidgetId());
260  m_common->setGeomColor(cidx, iColor);
261 }
262 
264  TGColorSelect* cs = (TGColorSelect*)gTQSender;
265 
266  //printf("~~~~~ changeSelectionColorSet sel[%d] idx[%d]\n", cs->WidgetId(), idx);
267  for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it) {
268  TGLViewer* v = ((TEveViewer*)(*it))->GetGLViewer();
269 
270  TGLColorSet& colorset = m_common->colorManager()->isColorSetDark() ? v->RefDarkColorSet() : v->RefLightColorSet();
271  colorset.Selection(cs->WidgetId()).SetColor(idx);
272  colorset.Selection(cs->WidgetId() + 1).SetColor(idx); // implied selected/higlighted
273  }
274 }
275 
277 
279 
280 /* Called by FWGUIManager when change background. */
282  for (int i = 0; i < kFWGeomColorSize; ++i)
283  m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
284 
285  int hci, sci;
286  getColorSetColors(hci, sci);
287  // printf("=============== colorSetChanged() dark ? [%d] %d %d \n",m_common->colorManager()->isColorSetDark(), hci, sci);
290 }
291 
292 void CmsShowCommonPopup::getColorSetColors(int& hci, int& sci) {
293  TGLColorSet& colorset =
295  {
296  TGLColor& glc = colorset.Selection(3);
297  hci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
298  // printf("getSHcolors HIGH %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), hci);
299  }
300  {
301  TGLColor& glc = colorset.Selection(1);
302  sci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
303  // printf("getSHcolors SEL %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), sci);
304  }
305 }
306 
307 TGFrame* CmsShowCommonPopup::makeSetter(TGCompositeFrame* frame, FWParameterBase* param) {
308  std::shared_ptr<FWParameterSetterBase> ptr(FWParameterSetterBase::makeSetterFor(param));
309  ptr->attach(param, this);
310 
311  TGFrame* pframe = ptr->build(frame);
312  frame->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
313 
314  m_setters.push_back(ptr);
315  return pframe;
316 }
317 
319  m_common->setPalette();
320 
321  for (int i = 0; i < kFWGeomColorSize; ++i) {
323  // m_common->m_geomColors[i]->set(cm->geomColor(FWGeomColorIndex(i)));
325  }
326 }
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
void SetColorByIndex(Color_t iColor)
FWBoolParameter m_drawBreakPoints
Definition: CmsShowCommon.h:95
T w() const
Bool_t isColorSetDark() const
FWGeomColorIndex
Color_t geomTransparency(bool projected) const
const std::string names[nVars_]
TGTextButton * m_backgroundButton
FWLongParameter m_gamma
Definition: CmsShowCommon.h:99
void setGeomTransparency(int val, bool projected)
void changeGeomTransparency2D(int)
char const * label
Color_t geomColor(FWGeomColorIndex) const
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:92
const FWColorManager * colorManager() const
void switchBackground()
FWViewEnergyScale * getEnergyScale() const
Definition: CmsShowCommon.h:70
TGFrame * makeSetter(TGCompositeFrame *frame, FWParameterBase *param)
void permuteColors()
static std::shared_ptr< FWParameterSetterBase > makeSetterFor(FWParameterBase *)
FWColorSelect * m_colorRnrCtxHighlightWidget
TGLColorSet m_darkColorSet
FWColorSelect * m_colorRnrCtxSelectWidget
sigc::signal< void(T)> changed_
FWEnumParameter m_trackBreak
Definition: CmsShowCommon.h:94
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
FWColorManager * colorManager() const
Definition: Context.h:58
FWEnumParameter m_palette