CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/src/Fireworks/Core/src/CmsShowCommonPopup.cc

Go to the documentation of this file.
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    TGFont* smallFont = 0;
00054    FontStruct_t defaultFontStruct = m_backgroundButton->GetDefaultFontStruct();
00055    try
00056    { 
00057       TGFontPool *pool = gClient->GetFontPool();
00058       TGFont* defaultFont = pool->GetFont(defaultFontStruct);
00059       FontAttributes_t attributes = defaultFont->GetFontAttributes();
00060       smallFont = pool->GetFont(attributes.fFamily, 8,  attributes.fWeight, attributes.fSlant);                                      
00061    } 
00062    catch(...)
00063    {
00064       // Ignore exceptions.
00065    }
00066    
00067    TGCompositeFrame* vf2 = new TGVerticalFrame(this);
00068    AddFrame(vf2, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
00069    //==============================================================================
00070    // scales
00071    //
00072    {
00073       TGLabel* xx = new TGLabel(vf2, "GlobalScales     ", fTextGC->GetGC());
00074       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft ,2,2,4,4));
00075    }
00076    FWViewEnergyScaleEditor* scaleEditor = new FWViewEnergyScaleEditor(m_common->m_energyScale.get(), vf2);
00077    vf2->AddFrame(scaleEditor);
00078    //==============================================================================
00079    // Projections
00080    //
00081    vf2->AddFrame(new TGHorizontal3DLine(vf2),  new TGLayoutHints(kLHintsExpandX,4 ,8, 3, 3));
00082    {
00083       TGLabel* xx = new TGLabel(vf2, "Projections     ", fTextGC->GetGC());
00084       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft ,2,2,4,4));
00085    }
00086    vf2->AddFrame(new TGLabel(vf2, "Track behaviour when crossing y=0 in RhoZ-view:"), new TGLayoutHints(kLHintsLeft ,2,2,0,0));
00087    makeSetter(vf2, &m_common->m_trackBreak);
00088    makeSetter(vf2, &m_common->m_drawBreakPoints);
00089 
00090    //==============================================================================
00091    // general colors
00092    //
00093 
00094    vf2->AddFrame(new TGHorizontal3DLine(vf2),  new TGLayoutHints(kLHintsExpandX ,4 ,8, 8, 2));
00095    {
00096       TGLabel* xx = new TGLabel(vf2, "General Colors        ", fTextGC->GetGC());
00097       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,4,4));
00098    }
00099    m_backgroundButton = new TGTextButton(vf2, "Black/White Background");
00100    vf2->AddFrame(m_backgroundButton);
00101    makeSetter(vf2, &m_common->m_gamma);
00102 
00103    // rnrCtx colorset
00104    {
00105       int hci, sci;
00106       getColorSetColors(hci, sci); 
00107       TGHorizontalFrame* top = new TGHorizontalFrame(vf2);
00108       vf2->AddFrame(top);
00109       {
00110          TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00111          top->AddFrame(hf);
00112          
00113          m_colorRnrCtxHighlightWidget = new FWColorSelect(hf, "highlight", 0, m_common->colorManager(), 3);
00114          hf->AddFrame(m_colorRnrCtxHighlightWidget); 
00115          m_colorRnrCtxHighlightWidget->SetColorByIndex(hci , kFALSE);
00116          m_colorRnrCtxHighlightWidget->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
00117          
00118          TGFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
00119          TGLabel* label = new TGLabel(lf, "Higlight");
00120          label->SetTextFont(smallFont);
00121          hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0)); 
00122       }
00123       
00124       {
00125          TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00126          top->AddFrame(hf);
00127          
00128          m_colorRnrCtxSelectWidget = new FWColorSelect(hf, "selectioyn", 0, m_common->colorManager(), 1);
00129          hf->AddFrame(m_colorRnrCtxSelectWidget); 
00130          m_colorRnrCtxSelectWidget->SetColorByIndex(sci , kFALSE);
00131          m_colorRnrCtxSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeSelectionColorSet(Color_t)");
00132          
00133          TGFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
00134          TGLabel* label = new TGLabel(lf, "Selection");
00135          label->SetTextFont(smallFont);
00136          hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0)); 
00137       }
00138    }
00139    
00140    vf2->AddFrame(new TGHorizontal3DLine(vf2),  new TGLayoutHints(kLHintsExpandX ,4 ,8, 8, 2));
00141 
00142    //==============================================================================
00143    // geom colors
00144    //
00145 
00146    {
00147       TGLabel* xx = new TGLabel(vf2, "DetectorColors       ", fTextGC->GetGC());
00148       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,8,0));
00149    }
00150 
00151    TGHSlider* transpWidget2D = 0;
00152    TGHSlider* transpWidget3D = 0;
00153    TGCompositeFrame* top  = new TGVerticalFrame(vf2);
00154    vf2->AddFrame(top, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 0));
00155 
00156    {
00157       TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00158       hf->AddFrame(new TGLabel(hf, "Tansparency 2D:"), new TGLayoutHints(kLHintsBottom, 2,  2, 3, 3));
00159       transpWidget2D = new TGHSlider(hf, 100, kSlider1);
00160       hf->AddFrame( transpWidget2D);
00161       top->AddFrame(hf,new TGLayoutHints( kLHintsNormal, 0, 0, 2, 2));
00162    }
00163    {
00164       TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00165       hf->AddFrame(new TGLabel(hf, "Tansparency 3D:") , new TGLayoutHints(kLHintsBottom,2, 2, 2, 2 ));
00166       transpWidget3D = new TGHSlider(hf, 100, kSlider1);
00167       hf->AddFrame( transpWidget3D);
00168       top->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 10));
00169    }
00170    std::string names[kFWGeomColorSize];
00171    names[kFWPixelBarrelColorIndex   ] = "Pixel Barrel";
00172    names[kFWPixelEndcapColorIndex   ] = "Pixel Endcap" ;
00173    names[kFWTrackerBarrelColorIndex ] = "Tracker Barrel";
00174    names[kFWTrackerEndcapColorIndex ] = "Tracker Endcap";
00175    names[kFWMuonBarrelLineColorIndex] = "Muon Barrel";
00176    names[kFWMuonEndcapLineColorIndex] = "Muon Endcap";
00177    int i = 0;
00178    for (int k = 0; k < 3; ++k)
00179    {
00180       TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00181       top->AddFrame(hf);
00182 
00183       for (int j = 0 ; j < 2; ++j)
00184       {
00185          m_colorSelectWidget[i] = new FWColorSelect(hf, names[i].c_str(), 0, m_common->colorManager(), i);
00186          hf->AddFrame(m_colorSelectWidget[i]); 
00187          m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
00188          m_colorSelectWidget[i]->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeGeomColor(Color_t)");
00189 
00190          TGFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
00191          TGLabel* label = new TGLabel(lf, m_colorSelectWidget[i]->label().c_str());
00192          label->SetTextFont(smallFont);
00193          hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0)); 
00194 
00195          ++i;
00196       }
00197    }
00198    //==============================================================================
00199 
00200    m_backgroundButton->Connect("Clicked()", "CmsShowCommonPopup", this, "switchBackground()");
00201 
00202    transpWidget2D->SetRange(0, 100);
00203    transpWidget2D->SetPosition(m_common->colorManager()->geomTransparency(true));
00204    transpWidget2D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency2D(Int_t)");
00205 
00206    transpWidget3D->SetRange(0, 100);
00207    transpWidget3D->SetPosition(m_common->colorManager()->geomTransparency(false));
00208    transpWidget3D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency3D(Int_t)");
00209 
00210    SetWindowName("Common Preferences");
00211    MapSubwindows();
00212    Resize(GetDefaultSize());
00213    Layout();
00214    CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
00215 }
00216 
00217 
00218 
00219 CmsShowCommonPopup::~CmsShowCommonPopup()
00220 {
00221 }
00222 
00223 void
00224 CmsShowCommonPopup::switchBackground()
00225 {
00226    m_common->switchBackground();
00227 }
00228  
00229 
00230 void
00231 CmsShowCommonPopup::changeGeomColor(Color_t iColor)
00232 {
00233    TGColorSelect *cs = (TGColorSelect *) gTQSender;
00234    FWGeomColorIndex cidx = FWGeomColorIndex(cs->WidgetId());
00235    m_common->setGeomColor(cidx, iColor);
00236 }
00237 
00238 
00239 void
00240 CmsShowCommonPopup::changeSelectionColorSet(Color_t idx)
00241 {
00242    TGColorSelect *cs = (TGColorSelect *) gTQSender;   
00243 
00244    //printf("~~~~~  changeSelectionColorSet sel[%d] idx[%d]\n", cs->WidgetId(), idx);
00245    for (TEveElement::List_i it = gEve->GetViewers()->BeginChildren(); it != gEve->GetViewers()->EndChildren(); ++it)
00246    { 
00247       TGLViewer* v = ((TEveViewer*)(*it))->GetGLViewer();
00248       
00249       TGLColorSet& colorset =  m_common->colorManager()->isColorSetDark() ?  v->RefDarkColorSet():v->RefLightColorSet();
00250       colorset.Selection(cs->WidgetId()).SetColor(idx);
00251       colorset.Selection(cs->WidgetId()+1).SetColor(idx); // implied selected/higlighted
00252 
00253    }
00254 }
00255 
00256 
00257 void
00258 CmsShowCommonPopup::changeGeomTransparency2D(int iTransp)
00259 {
00260    m_common->setGeomTransparency(iTransp, true);
00261 }
00262 
00263 void
00264 CmsShowCommonPopup::changeGeomTransparency3D(int iTransp)
00265 {
00266    m_common->setGeomTransparency(iTransp, false);
00267 }
00268 
00269 
00270 /* Called by FWGUIManager when change background. */
00271 void 
00272 CmsShowCommonPopup::colorSetChanged()
00273 {
00274    for (int i = 0 ; i < kFWGeomColorSize; ++i)
00275       m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
00276    
00277    int hci, sci;
00278    getColorSetColors(hci, sci);
00279    //printf("=============== colorSetChanged() dark ? [%d] %d %d \n",m_common->colorManager()->isColorSetDark(), hci, sci);
00280    m_colorRnrCtxHighlightWidget->SetColorByIndex(hci , kFALSE);
00281    m_colorRnrCtxSelectWidget->SetColorByIndex(sci , kFALSE);
00282 }
00283 
00284 void CmsShowCommonPopup::getColorSetColors (int& hci, int& sci)
00285 {
00286    TGLColorSet& colorset =  m_common->colorManager()->isColorSetDark() ?  gEve->GetDefaultGLViewer()->RefDarkColorSet():
00287    gEve->GetDefaultGLViewer()->RefLightColorSet();
00288    {
00289       TGLColor& glc = colorset.Selection(3);
00290       hci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
00291      // printf("getSHcolors HIGH %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), hci);
00292    }{
00293       TGLColor& glc = colorset.Selection(1);
00294       sci = TColor::GetColor(glc.GetRed(), glc.GetGreen(), glc.GetBlue());
00295      // printf("getSHcolors SEL  %d %d %d , [%d]\n", glc.GetRed(), glc.GetGreen(), glc.GetBlue(), sci);
00296    }
00297 }
00298 
00299 void
00300 CmsShowCommonPopup::makeSetter(TGCompositeFrame* frame, FWParameterBase* param) 
00301 {
00302    boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor(param) );
00303    ptr->attach(param, this);
00304  
00305    TGFrame* pframe = ptr->build(frame);
00306    frame->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX, 0, 0, 2,2));
00307 
00308    m_setters.push_back(ptr);
00309 }