Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:33

0001 #include "TGFont.h"
0002 #include "TGButton.h"
0003 #include "TGLabel.h"
0004 #include "TGSlider.h"
0005 #include "TGComboBox.h"
0006 #include "TGClient.h"
0007 #include "TG3DLine.h"
0008 #include "TGResourcePool.h"
0009 #include "TGLUtil.h"
0010 #include "TGLViewer.h"
0011 #include "TEveManager.h"
0012 #include "TEveViewer.h"
0013 #include "TColor.h"
0014 #include "Fireworks/Core/interface/Context.h"
0015 
0016 #include "Fireworks/Core/interface/CmsShowCommonPopup.h"
0017 #include "Fireworks/Core/interface/CmsShowCommon.h"
0018 #include "Fireworks/Core/interface/FWColorManager.h"
0019 #include "Fireworks/Core/interface/FWDialogBuilder.h"
0020 #include "Fireworks/Core/src/FWColorSelect.h"
0021 #include "Fireworks/Core/interface/FWViewEnergyScaleEditor.h"
0022 #include "Fireworks/Core/interface/FWViewEnergyScale.h"
0023 
0024 #include "Fireworks/Core/interface/FWParameterSetterEditorBase.h"
0025 
0026 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
0027 #include "Fireworks/Core/interface/FWEventItemsManager.h"
0028 #include "Fireworks/Core/interface/FWEventItem.h"
0029 
0030 #include <functional>
0031 
0032 CmsShowCommonPopup::CmsShowCommonPopup(CmsShowCommon* model, const TGWindow* p, UInt_t w, UInt_t h)
0033     : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h),
0034       m_common(model),
0035       m_backgroundButton(nullptr),
0036       m_gammaSlider(nullptr),
0037       m_gammaButton(nullptr),
0038       m_colorRnrCtxHighlightWidget(nullptr),
0039       m_colorRnrCtxSelectWidget(nullptr),
0040       m_combo(nullptr) {
0041   SetCleanup(kDeepCleanup);
0042 
0043   TGGC* fTextGC;
0044   const TGFont* font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
0045   if (!font)
0046     font = gClient->GetResourcePool()->GetDefaultFont();
0047   GCValues_t gval;
0048   gval.fMask = kGCBackground | kGCFont | kGCForeground;
0049   gval.fFont = font->GetFontHandle();
0050   fTextGC = gClient->GetGC(&gval, kTRUE);
0051 
0052   TGCompositeFrame* vf2 = new TGVerticalFrame(this);
0053   AddFrame(vf2, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
0054   //==============================================================================
0055   // scales
0056   //
0057   {
0058     TGLabel* xx = new TGLabel(vf2, "GlobalScales     ", fTextGC->GetGC());
0059     vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
0060   }
0061   FWViewEnergyScaleEditor* scaleEditor = new FWViewEnergyScaleEditor(m_common->getEnergyScale(), vf2);
0062   vf2->AddFrame(scaleEditor);
0063   //==============================================================================
0064   // Projections
0065   //
0066   vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4, 8, 3, 3));
0067   {
0068     TGLabel* xx = new TGLabel(vf2, "Projections     ", fTextGC->GetGC());
0069     vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
0070   }
0071   vf2->AddFrame(new TGLabel(vf2, "Track behavior when crossing y=0 in RhoZ view:"),
0072                 new TGLayoutHints(kLHintsLeft, 2, 2, 0, 0));
0073   makeSetter(vf2, &m_common->m_trackBreak);
0074   makeSetter(vf2, &m_common->m_drawBreakPoints);
0075 
0076   //==============================================================================
0077   // general colors
0078   //
0079 
0080   vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4, 8, 8, 2));
0081   {
0082     TGLabel* xx = new TGLabel(vf2, "General Colors        ", fTextGC->GetGC());
0083     vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 4, 4));
0084   }
0085   {
0086     TGCompositeFrame* hf = new TGHorizontalFrame(vf2);
0087     vf2->AddFrame(hf, new TGLayoutHints(kLHintsExpandX));
0088 
0089     m_backgroundButton = new TGTextButton(hf, "Black/White Background");
0090     hf->AddFrame(m_backgroundButton, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
0091     m_backgroundButton->Connect("Clicked()", "CmsShowCommonPopup", this, "switchBackground()");
0092 
0093     makeSetter(hf, &m_common->m_gamma);
0094   }
0095 
0096   TGFont* smallFont = nullptr;
0097   FontStruct_t defaultFontStruct = m_backgroundButton->GetDefaultFontStruct();
0098   try {
0099     TGFontPool* pool = gClient->GetFontPool();
0100     TGFont* defaultFont = pool->GetFont(defaultFontStruct);
0101     FontAttributes_t attributes = defaultFont->GetFontAttributes();
0102     smallFont = pool->GetFont(attributes.fFamily, 8, attributes.fWeight, attributes.fSlant);
0103   } catch (...) {
0104     // Ignore exceptions.
0105   }
0106 
0107   // color palette swapping
0108   if (true) {
0109     const TGCompositeFrame* f = static_cast<const TGCompositeFrame*>(makeSetter(vf2, &m_common->m_palette));
0110     // MTXXXX combo is at(0) (label on right!) and there is a tgframeelement in between!
0111     // for (int i = 0; i < f->GetList()->GetEntries(); ++i)
0112     //   printf("QWE %d %s\n", i, ((TGFrameElement*)f->GetList()->At(i))->fFrame->ClassName());
0113     // m_combo = static_cast<TGComboBox*>(f->GetList()->At(1));
0114     m_combo = static_cast<TGComboBox*>(static_cast<TGFrameElement*>(f->GetList()->At(0))->fFrame);
0115     m_common->m_palette.changed_.connect(std::bind(&CmsShowCommonPopup::setPaletteGUI, this));
0116 
0117     TGCompositeFrame* hf = new TGHorizontalFrame(vf2);
0118     vf2->AddFrame(hf, new TGLayoutHints(kLHintsExpandX));
0119     {
0120       TGButton* butt;
0121       butt = new TGTextButton(hf, "Permute Colors");
0122       butt->SetToolTipText("Randomize assigned collection colors");
0123       hf->AddFrame(butt, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 2, 2, 2, 2));
0124       butt->Connect("Clicked()", "CmsShowCommonPopup", this, "permuteColors()");
0125 
0126       butt = new TGTextButton(hf, "Randomize Colors");
0127       butt->SetToolTipText("Randomize collection colors from full palette");
0128       hf->AddFrame(butt, new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
0129       butt->Connect("Clicked()", "CmsShowCommonPopup", this, "randomizeColors()");
0130     }
0131   }
0132 
0133   // rnrCtx colorset
0134   {
0135     int hci, sci;
0136     getColorSetColors(hci, sci);
0137     TGHorizontalFrame* top = new TGHorizontalFrame(vf2);
0138     vf2->AddFrame(top);
0139     {
0140       TGHorizontalFrame* hf = new TGHorizontalFrame(top);
0141       top->AddFrame(hf);
0142 
0143       m_colorRnrCtxHighlightWidget = new FWColorSelect(hf, "Highlight", 0, m_common->colorManager(), 3);
0144       hf->AddFrame(m_colorRnrCtxHighlightWidget);
0145       m_colorRnrCtxHighlightWidget->SetColorByIndex(hci, kFALSE);
0146       m_colorRnrCtxHighlightWidget->Connect(
0147           "ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
0148 
0149       TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 45, 16, kFixedSize);
0150       TGLabel* label = new TGLabel(lf, "Higlight");
0151       label->SetTextFont(smallFont);
0152       lf->AddFrame(label);
0153       hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
0154     }
0155 
0156     {
0157       TGHorizontalFrame* hf = new TGHorizontalFrame(top);
0158       top->AddFrame(hf);
0159 
0160       m_colorRnrCtxSelectWidget = new FWColorSelect(hf, "Selection", 0, m_common->colorManager(), 1);
0161       hf->AddFrame(m_colorRnrCtxSelectWidget);
0162       m_colorRnrCtxSelectWidget->SetColorByIndex(sci, kFALSE);
0163       m_colorRnrCtxSelectWidget->Connect(
0164           "ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
0165 
0166       TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 45, 16, kFixedSize);
0167       TGLabel* label = new TGLabel(lf, "Selection");
0168       label->SetTextFont(smallFont);
0169       lf->AddFrame(label);
0170       hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY));
0171     }
0172   }
0173   vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX, 4, 8, 8, 2));
0174 
0175   //==============================================================================
0176   // geom colors
0177   //
0178 
0179   {
0180     TGLabel* xx = new TGLabel(vf2, "DetectorColors       ", fTextGC->GetGC());
0181     vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft, 2, 2, 8, 0));
0182   }
0183 
0184   TGHSlider* transpWidget2D = nullptr;
0185   TGHSlider* transpWidget3D = nullptr;
0186   TGCompositeFrame* top = new TGVerticalFrame(vf2);
0187   vf2->AddFrame(top, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 0));
0188 
0189   {
0190     TGHorizontalFrame* hf = new TGHorizontalFrame(top);
0191     hf->AddFrame(new TGLabel(hf, "Tansparency 2D:"), new TGLayoutHints(kLHintsBottom, 2, 2, 3, 3));
0192     transpWidget2D = new TGHSlider(hf, 100, kSlider1);
0193     hf->AddFrame(transpWidget2D);
0194     top->AddFrame(hf, new TGLayoutHints(kLHintsNormal, 0, 0, 2, 2));
0195   }
0196   {
0197     TGHorizontalFrame* hf = new TGHorizontalFrame(top);
0198     hf->AddFrame(new TGLabel(hf, "Tansparency 3D:"), new TGLayoutHints(kLHintsBottom, 2, 2, 2, 2));
0199     transpWidget3D = new TGHSlider(hf, 100, kSlider1);
0200     hf->AddFrame(transpWidget3D);
0201     top->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 10));
0202   }
0203 
0204   std::string names[kFWGeomColorSize];
0205   names[kFWPixelBarrelColorIndex] = "Pixel Barrel";
0206   names[kFWPixelEndcapColorIndex] = "Pixel Endcap";
0207   names[kFWTrackerBarrelColorIndex] = "Tracker Barrel";
0208   names[kFWTrackerEndcapColorIndex] = "Tracker Endcap";
0209   names[kFWMuonBarrelLineColorIndex] = "Muon Barrel";
0210   names[kFWMuonEndcapLineColorIndex] = "Muon Endcap";
0211   int i = 0;
0212   for (int k = 0; k < 3; ++k) {
0213     TGHorizontalFrame* hf = new TGHorizontalFrame(top);
0214     top->AddFrame(hf);
0215     for (int j = 0; j < 3; ++j) {
0216       m_colorSelectWidget[i] = new FWColorSelect(hf, names[i].c_str(), 0, m_common->colorManager(), i);
0217       hf->AddFrame(m_colorSelectWidget[i]);
0218       m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
0219       m_colorSelectWidget[i]->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeGeomColor(Color_t)");
0220 
0221       TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
0222       TGLabel* label = new TGLabel(lf, m_colorSelectWidget[i]->label().c_str());
0223       label->SetTextFont(smallFont);
0224       lf->AddFrame(label);
0225       hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 0, 0, 0));
0226 
0227       ++i;
0228     }
0229   }
0230   //==============================================================================
0231 
0232   transpWidget2D->SetRange(0, 100);
0233   transpWidget2D->SetPosition(m_common->colorManager()->geomTransparency(true));
0234   transpWidget2D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency2D(Int_t)");
0235 
0236   transpWidget3D->SetRange(0, 100);
0237   transpWidget3D->SetPosition(m_common->colorManager()->geomTransparency(false));
0238   transpWidget3D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency3D(Int_t)");
0239 
0240   SetWindowName("Common Preferences");
0241   MapSubwindows();
0242   Resize(GetDefaultSize());
0243   Layout();
0244   CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
0245 }
0246 
0247 CmsShowCommonPopup::~CmsShowCommonPopup() {}
0248 
0249 //==============================================================================
0250 
0251 void CmsShowCommonPopup::switchBackground() { m_common->switchBackground(); }
0252 
0253 void CmsShowCommonPopup::randomizeColors() { m_common->randomizeColors(); }
0254 
0255 void CmsShowCommonPopup::permuteColors() { m_common->permuteColors(); }
0256 
0257 void CmsShowCommonPopup::changeGeomColor(Color_t iColor) {
0258   TGColorSelect* cs = (TGColorSelect*)gTQSender;
0259   FWGeomColorIndex cidx = FWGeomColorIndex(cs->WidgetId());
0260   m_common->setGeomColor(cidx, iColor);
0261 }
0262 
0263 void CmsShowCommonPopup::changeSelectionColorSet(Color_t idx) {
0264   TGColorSelect* cs = (TGColorSelect*)gTQSender;
0265 
0266   //printf("~~~~~  changeSelectionColorSet sel[%d] idx[%d]\n", cs->WidgetId(), idx);
0267   for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it) {
0268     TGLViewer* v = ((TEveViewer*)(*it))->GetGLViewer();
0269 
0270     TGLColorSet& colorset = m_common->colorManager()->isColorSetDark() ? v->RefDarkColorSet() : v->RefLightColorSet();
0271     colorset.Selection(cs->WidgetId()).SetColor(idx);
0272     colorset.Selection(cs->WidgetId() + 1).SetColor(idx);  // implied selected/higlighted
0273   }
0274 }
0275 
0276 void CmsShowCommonPopup::changeGeomTransparency2D(int iTransp) { m_common->setGeomTransparency(iTransp, true); }
0277 
0278 void CmsShowCommonPopup::changeGeomTransparency3D(int iTransp) { m_common->setGeomTransparency(iTransp, false); }
0279 
0280 /* Called by FWGUIManager when change background. */
0281 void CmsShowCommonPopup::colorSetChanged() {
0282   for (int i = 0; i < kFWGeomColorSize; ++i)
0283     m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
0284 
0285   int hci, sci;
0286   getColorSetColors(hci, sci);
0287   // printf("=============== colorSetChanged() dark ? [%d] %d %d \n",m_common->colorManager()->isColorSetDark(), hci, sci);
0288   m_colorRnrCtxHighlightWidget->SetColorByIndex(hci, kFALSE);
0289   m_colorRnrCtxSelectWidget->SetColorByIndex(sci, kFALSE);
0290 }
0291 
0292 void CmsShowCommonPopup::getColorSetColors(int& hci, int& sci) {
0293   TGLColorSet& colorset =
0294       m_common->colorManager()->isColorSetDark() ? m_common->m_darkColorSet : m_common->m_lightColorSet;
0295   {
0296     TGLColor& glc = colorset.Selection(3);
0297     hci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
0298     // printf("getSHcolors HIGH %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), hci);
0299   }
0300   {
0301     TGLColor& glc = colorset.Selection(1);
0302     sci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
0303     // printf("getSHcolors SEL  %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), sci);
0304   }
0305 }
0306 
0307 TGFrame* CmsShowCommonPopup::makeSetter(TGCompositeFrame* frame, FWParameterBase* param) {
0308   std::shared_ptr<FWParameterSetterBase> ptr(FWParameterSetterBase::makeSetterFor(param));
0309   ptr->attach(param, this);
0310 
0311   TGFrame* pframe = ptr->build(frame);
0312   frame->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX, 0, 0, 2, 2));
0313 
0314   m_setters.push_back(ptr);
0315   return pframe;
0316 }
0317 
0318 void CmsShowCommonPopup::setPaletteGUI() {
0319   m_common->setPalette();
0320 
0321   for (int i = 0; i < kFWGeomColorSize; ++i) {
0322     FWColorManager* cm = m_common->m_context->colorManager();
0323     //  m_common->m_geomColors[i]->set(cm->geomColor(FWGeomColorIndex(i)));
0324     m_colorSelectWidget[i]->SetColorByIndex(cm->geomColor(FWGeomColorIndex(i)), kFALSE);
0325   }
0326 }