00001 #include "TGFont.h"
00002 #include "TGButton.h"
00003 #include "TGLabel.h"
00004 #include "TGSlider.h"
00005 #include "TGComboBox.h"
00006 #include "TGClient.h"
00007 #include "TG3DLine.h"
00008 #include "TGResourcePool.h"
00009 #include "TGLUtil.h"
00010 #include "TGLViewer.h"
00011 #include "TEveManager.h"
00012 #include "TEveViewer.h"
00013 #include "TColor.h"
00014
00015 #include "Fireworks/Core/interface/CmsShowCommonPopup.h"
00016 #include "Fireworks/Core/interface/CmsShowCommon.h"
00017 #include "Fireworks/Core/interface/FWColorManager.h"
00018 #include "Fireworks/Core/src/FWDialogBuilder.h"
00019 #include "Fireworks/Core/src/FWColorSelect.h"
00020 #include "Fireworks/Core/interface/FWViewEnergyScaleEditor.h"
00021
00022 #include "Fireworks/Core/interface/FWParameterSetterEditorBase.h"
00023
00024 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
00025
00026
00027
00028
00029
00030
00031
00032 CmsShowCommonPopup::CmsShowCommonPopup(CmsShowCommon* model, const TGWindow* p, UInt_t w, UInt_t h) :
00033 TGTransientFrame(gClient->GetDefaultRoot(),p,w,h),
00034 m_common(model),
00035 m_backgroundButton(0),
00036 m_gammaSlider(0),
00037 m_gammaButton(0),
00038 m_colorRnrCtxHighlightWidget(0),
00039 m_colorRnrCtxSelectWidget(0)
00040 {
00041 SetCleanup(kDeepCleanup);
00042
00043 TGGC *fTextGC;
00044 const TGFont *font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
00045 if (!font)
00046 font = gClient->GetResourcePool()->GetDefaultFont();
00047 GCValues_t gval;
00048 gval.fMask = kGCBackground | kGCFont | kGCForeground;
00049 gval.fFont = font->GetFontHandle();
00050 fTextGC = gClient->GetGC(&gval, kTRUE);
00051
00052
00053
00054
00055 TGCompositeFrame* vf2 = new TGVerticalFrame(this);
00056 AddFrame(vf2, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
00057
00058
00059
00060 {
00061 TGLabel* xx = new TGLabel(vf2, "GlobalScales ", fTextGC->GetGC());
00062 vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft ,2,2,4,4));
00063 }
00064 FWViewEnergyScaleEditor* scaleEditor = new FWViewEnergyScaleEditor(m_common->m_energyScale.get(), vf2);
00065 vf2->AddFrame(scaleEditor);
00066
00067
00068
00069 vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX,4 ,8, 3, 3));
00070 {
00071 TGLabel* xx = new TGLabel(vf2, "Projections ", fTextGC->GetGC());
00072 vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft ,2,2,4,4));
00073 }
00074 vf2->AddFrame(new TGLabel(vf2, "Track behaviour when crossing y=0 in RhoZ-view:"), new TGLayoutHints(kLHintsLeft ,2,2,0,0));
00075 makeSetter(vf2, &m_common->m_trackBreak);
00076 makeSetter(vf2, &m_common->m_drawBreakPoints);
00077
00078
00079
00080
00081
00082 vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX ,4 ,8, 8, 2));
00083 {
00084 TGLabel* xx = new TGLabel(vf2, "General Colors ", fTextGC->GetGC());
00085 vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,4,4));
00086 }
00087 m_backgroundButton = new TGTextButton(vf2, "Black/White Background");
00088 vf2->AddFrame(m_backgroundButton);
00089 makeSetter(vf2, &m_common->m_gamma);
00090
00091 TGFont* smallFont = 0;
00092 FontStruct_t defaultFontStruct = m_backgroundButton->GetDefaultFontStruct();
00093 try
00094 {
00095 TGFontPool *pool = gClient->GetFontPool();
00096 TGFont* defaultFont = pool->GetFont(defaultFontStruct);
00097 FontAttributes_t attributes = defaultFont->GetFontAttributes();
00098 smallFont = pool->GetFont(attributes.fFamily, 8, attributes.fWeight, attributes.fSlant);
00099 }
00100 catch(...)
00101 {
00102
00103 }
00104
00105
00106 {
00107 int hci, sci;
00108 getColorSetColors(hci, sci);
00109 TGHorizontalFrame* top = new TGHorizontalFrame(vf2);
00110 vf2->AddFrame(top);
00111 {
00112 TGHorizontalFrame* hf = new TGHorizontalFrame(top);
00113 top->AddFrame(hf);
00114
00115 m_colorRnrCtxHighlightWidget = new FWColorSelect(hf, "highlight", 0, m_common->colorManager(), 3);
00116 hf->AddFrame(m_colorRnrCtxHighlightWidget);
00117 m_colorRnrCtxHighlightWidget->SetColorByIndex(hci , kFALSE);
00118 m_colorRnrCtxHighlightWidget->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
00119
00120 TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
00121 TGLabel* label = new TGLabel(lf, "Higlight");
00122 label->SetTextFont(smallFont);
00123 lf->AddFrame(label);
00124 hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0));
00125 }
00126
00127 {
00128 TGHorizontalFrame* hf = new TGHorizontalFrame(top);
00129 top->AddFrame(hf);
00130
00131 m_colorRnrCtxSelectWidget = new FWColorSelect(hf, "selectioyn", 0, m_common->colorManager(), 1);
00132 hf->AddFrame(m_colorRnrCtxSelectWidget);
00133 m_colorRnrCtxSelectWidget->SetColorByIndex(sci , kFALSE);
00134 m_colorRnrCtxSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
00135
00136 TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
00137 TGLabel* label = new TGLabel(lf, "Selection");
00138 label->SetTextFont(smallFont);
00139 lf->AddFrame(label);
00140 hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0));
00141 }
00142 }
00143
00144 vf2->AddFrame(new TGHorizontal3DLine(vf2), new TGLayoutHints(kLHintsExpandX ,4 ,8, 8, 2));
00145
00146
00147
00148
00149
00150 {
00151 TGLabel* xx = new TGLabel(vf2, "DetectorColors ", fTextGC->GetGC());
00152 vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,8,0));
00153 }
00154
00155 TGHSlider* transpWidget2D = 0;
00156 TGHSlider* transpWidget3D = 0;
00157 TGCompositeFrame* top = new TGVerticalFrame(vf2);
00158 vf2->AddFrame(top, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 0));
00159
00160 {
00161 TGHorizontalFrame* hf = new TGHorizontalFrame(top);
00162 hf->AddFrame(new TGLabel(hf, "Tansparency 2D:"), new TGLayoutHints(kLHintsBottom, 2, 2, 3, 3));
00163 transpWidget2D = new TGHSlider(hf, 100, kSlider1);
00164 hf->AddFrame( transpWidget2D);
00165 top->AddFrame(hf,new TGLayoutHints( kLHintsNormal, 0, 0, 2, 2));
00166 }
00167 {
00168 TGHorizontalFrame* hf = new TGHorizontalFrame(top);
00169 hf->AddFrame(new TGLabel(hf, "Tansparency 3D:") , new TGLayoutHints(kLHintsBottom,2, 2, 2, 2 ));
00170 transpWidget3D = new TGHSlider(hf, 100, kSlider1);
00171 hf->AddFrame( transpWidget3D);
00172 top->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 10));
00173 }
00174 std::string names[kFWGeomColorSize];
00175 names[kFWPixelBarrelColorIndex ] = "Pixel Barrel";
00176 names[kFWPixelEndcapColorIndex ] = "Pixel Endcap" ;
00177 names[kFWTrackerBarrelColorIndex ] = "Tracker Barrel";
00178 names[kFWTrackerEndcapColorIndex ] = "Tracker Endcap";
00179 names[kFWMuonBarrelLineColorIndex] = "Muon Barrel";
00180 names[kFWMuonEndcapLineColorIndex] = "Muon Endcap";
00181 int i = 0;
00182 for (int k = 0; k < 3; ++k)
00183 {
00184 TGHorizontalFrame* hf = new TGHorizontalFrame(top);
00185 top->AddFrame(hf);
00186
00187 for (int j = 0 ; j < 2; ++j)
00188 {
00189 m_colorSelectWidget[i] = new FWColorSelect(hf, names[i].c_str(), 0, m_common->colorManager(), i);
00190 hf->AddFrame(m_colorSelectWidget[i]);
00191 m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
00192 m_colorSelectWidget[i]->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeGeomColor(Color_t)");
00193
00194 TGHorizontalFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
00195 TGLabel* label = new TGLabel(lf, m_colorSelectWidget[i]->label().c_str());
00196 label->SetTextFont(smallFont);
00197 lf->AddFrame(label);
00198 hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0));
00199
00200 ++i;
00201 }
00202 }
00203
00204
00205 m_backgroundButton->Connect("Clicked()", "CmsShowCommonPopup", this, "switchBackground()");
00206
00207 transpWidget2D->SetRange(0, 100);
00208 transpWidget2D->SetPosition(m_common->colorManager()->geomTransparency(true));
00209 transpWidget2D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency2D(Int_t)");
00210
00211 transpWidget3D->SetRange(0, 100);
00212 transpWidget3D->SetPosition(m_common->colorManager()->geomTransparency(false));
00213 transpWidget3D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency3D(Int_t)");
00214
00215 SetWindowName("Common Preferences");
00216 MapSubwindows();
00217 Resize(GetDefaultSize());
00218 Layout();
00219 CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
00220 }
00221
00222
00223
00224 CmsShowCommonPopup::~CmsShowCommonPopup()
00225 {
00226 }
00227
00228 void
00229 CmsShowCommonPopup::switchBackground()
00230 {
00231 m_common->switchBackground();
00232 }
00233
00234
00235 void
00236 CmsShowCommonPopup::changeGeomColor(Color_t iColor)
00237 {
00238 TGColorSelect *cs = (TGColorSelect *) gTQSender;
00239 FWGeomColorIndex cidx = FWGeomColorIndex(cs->WidgetId());
00240 m_common->setGeomColor(cidx, iColor);
00241 }
00242
00243
00244 void
00245 CmsShowCommonPopup::changeSelectionColorSet(Color_t idx)
00246 {
00247 TGColorSelect *cs = (TGColorSelect *) gTQSender;
00248
00249
00250 for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it)
00251 {
00252 TGLViewer* v = ((TEveViewer*)(*it))->GetGLViewer();
00253
00254 TGLColorSet& colorset = m_common->colorManager()->isColorSetDark() ? v->RefDarkColorSet():v->RefLightColorSet();
00255 colorset.Selection(cs->WidgetId()).SetColor(idx);
00256 colorset.Selection(cs->WidgetId()+1).SetColor(idx);
00257
00258 }
00259 }
00260
00261
00262 void
00263 CmsShowCommonPopup::changeGeomTransparency2D(int iTransp)
00264 {
00265 m_common->setGeomTransparency(iTransp, true);
00266 }
00267
00268 void
00269 CmsShowCommonPopup::changeGeomTransparency3D(int iTransp)
00270 {
00271 m_common->setGeomTransparency(iTransp, false);
00272 }
00273
00274
00275
00276 void
00277 CmsShowCommonPopup::colorSetChanged()
00278 {
00279 for (int i = 0 ; i < kFWGeomColorSize; ++i)
00280 m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
00281
00282 int hci, sci;
00283 getColorSetColors(hci, sci);
00284
00285 m_colorRnrCtxHighlightWidget->SetColorByIndex(hci , kFALSE);
00286 m_colorRnrCtxSelectWidget->SetColorByIndex(sci , kFALSE);
00287 }
00288
00289 void CmsShowCommonPopup::getColorSetColors (int& hci, int& sci)
00290 {
00291 TGLColorSet& colorset = m_common->colorManager()->isColorSetDark() ? gEve->GetDefaultGLViewer()->RefDarkColorSet():
00292 gEve->GetDefaultGLViewer()->RefLightColorSet();
00293 {
00294 TGLColor& glc = colorset.Selection(3);
00295 hci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
00296
00297 }{
00298 TGLColor& glc = colorset.Selection(1);
00299 sci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
00300
00301 }
00302 }
00303
00304 void
00305 CmsShowCommonPopup::makeSetter(TGCompositeFrame* frame, FWParameterBase* param)
00306 {
00307 boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor(param) );
00308 ptr->attach(param, this);
00309
00310 TGFrame* pframe = ptr->build(frame);
00311 frame->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX, 0, 0, 2,2));
00312
00313 m_setters.push_back(ptr);
00314 }