CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch13/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 
00010 #include "Fireworks/Core/interface/CmsShowCommonPopup.h"
00011 #include "Fireworks/Core/interface/CmsShowCommon.h"
00012 #include "Fireworks/Core/interface/FWColorManager.h"
00013 #include "Fireworks/Core/src/FWDialogBuilder.h"
00014 #include "Fireworks/Core/src/FWColorSelect.h"
00015 #include "Fireworks/Core/interface/FWViewEnergyScaleEditor.h"
00016 
00017 #include "Fireworks/Core/interface/FWParameterSetterEditorBase.h"
00018 
00019 #include "Fireworks/Core/interface/FWParameterSetterBase.h"
00020 
00021 CmsShowCommonPopup::CmsShowCommonPopup(CmsShowCommon* model, const TGWindow* p, UInt_t w, UInt_t h) :
00022    TGTransientFrame(gClient->GetDefaultRoot(),p,w,h),
00023    m_common(model),
00024    m_backgroundButton(0),
00025    m_gammaSlider(0),
00026    m_gammaButton(0)
00027 {
00028    SetCleanup(kDeepCleanup);
00029 
00030    TGGC *fTextGC;
00031    const TGFont *font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-14-*-*-*-*-*-iso8859-1");
00032    if (!font)
00033       font = gClient->GetResourcePool()->GetDefaultFont();
00034    GCValues_t   gval;
00035    gval.fMask = kGCBackground | kGCFont | kGCForeground;
00036    gval.fFont = font->GetFontHandle();
00037    fTextGC = gClient->GetGC(&gval, kTRUE);
00038 
00039    TGCompositeFrame* vf2 = new TGVerticalFrame(this);
00040    AddFrame(vf2, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
00041    //==============================================================================
00042    // scales
00043    //
00044    {
00045       TGLabel* xx = new TGLabel(vf2, "GlobalScales     ", fTextGC->GetGC());
00046       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft ,2,2,4,4));
00047    }
00048    FWViewEnergyScaleEditor* scaleEditor = new FWViewEnergyScaleEditor(m_common->m_energyScale.get(), vf2);
00049    vf2->AddFrame(scaleEditor);
00050    //==============================================================================
00051    // Projections
00052    //
00053    vf2->AddFrame(new TGHorizontal3DLine(vf2),  new TGLayoutHints(kLHintsExpandX,4 ,8, 3, 3));
00054    {
00055       TGLabel* xx = new TGLabel(vf2, "Projections     ", fTextGC->GetGC());
00056       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft ,2,2,4,4));
00057    }
00058    vf2->AddFrame(new TGLabel(vf2, "Track behaviour when crossing y=0 in RhoZ-view:"), new TGLayoutHints(kLHintsLeft ,2,2,0,0));
00059    makeSetter(vf2, &m_common->m_trackBreak);
00060    makeSetter(vf2, &m_common->m_drawBreakPoints);
00061 
00062    //==============================================================================
00063    // brigtness
00064    //
00065 
00066    vf2->AddFrame(new TGHorizontal3DLine(vf2),  new TGLayoutHints(kLHintsExpandX ,4 ,8, 8, 2));
00067    {
00068       TGLabel* xx = new TGLabel(vf2, "General Colors        ", fTextGC->GetGC());
00069       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,4,4));
00070    }
00071    m_backgroundButton = new TGTextButton(vf2, "Black/White Background");
00072    vf2->AddFrame(m_backgroundButton);
00073    makeSetter(vf2, &m_common->m_gamma);
00074 
00075 
00076    //==============================================================================
00077    // geom colors
00078    //
00079 
00080    {
00081       TGLabel* xx = new TGLabel(vf2, "DetectorColors       ", fTextGC->GetGC());
00082       vf2->AddFrame(xx, new TGLayoutHints(kLHintsLeft,2,2,8,0));
00083    }
00084 
00085    TGFont* smallFont = 0;
00086    FontStruct_t defaultFontStruct = m_backgroundButton->GetDefaultFontStruct();
00087    try
00088    { 
00089       TGFontPool *pool = gClient->GetFontPool();
00090       TGFont* defaultFont = pool->GetFont(defaultFontStruct);
00091       FontAttributes_t attributes = defaultFont->GetFontAttributes();
00092       smallFont = pool->GetFont(attributes.fFamily, 8,  attributes.fWeight, attributes.fSlant);                                      
00093    } 
00094    catch(...)
00095    {
00096       // Ignore exceptions.
00097    }
00098 
00099   
00100    TGHSlider* transpWidget2D = 0;
00101    TGHSlider* transpWidget3D = 0;
00102    TGCompositeFrame* top  = new TGVerticalFrame(vf2);
00103    vf2->AddFrame(top, new TGLayoutHints(kLHintsNormal, 2, 2, 2, 0));
00104 
00105    {
00106       TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00107       hf->AddFrame(new TGLabel(hf, "Tansparency 2D:"), new TGLayoutHints(kLHintsBottom, 2,  2, 3, 3));
00108       transpWidget2D = new TGHSlider(hf, 100, kSlider1);
00109       hf->AddFrame( transpWidget2D);
00110       top->AddFrame(hf,new TGLayoutHints( kLHintsNormal, 0, 0, 2, 2));
00111    }
00112    {
00113       TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00114       hf->AddFrame(new TGLabel(hf, "Tansparency 3D:") , new TGLayoutHints(kLHintsBottom,2, 2, 2, 2 ));
00115       transpWidget3D = new TGHSlider(hf, 100, kSlider1);
00116       hf->AddFrame( transpWidget3D);
00117       top->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 0, 0, 0, 10));
00118    }
00119    std::string names[kFWGeomColorSize];
00120    names[kFWPixelBarrelColorIndex   ] = "Pixel Barrel";
00121    names[kFWPixelEndcapColorIndex   ] = "Pixel Endcap" ;
00122    names[kFWTrackerBarrelColorIndex ] = "Tracker Barrel";
00123    names[kFWTrackerEndcapColorIndex ] = "Tracker Endcap";
00124    names[kFWMuonBarrelLineColorIndex] = "Muon Barrel";
00125    names[kFWMuonEndcapLineColorIndex] = "Muon Endcap";
00126    int i = 0;
00127    for (int k = 0; k < 3; ++k)
00128    {
00129       TGHorizontalFrame* hf = new TGHorizontalFrame(top); 
00130       top->AddFrame(hf);
00131 
00132       for (int j = 0 ; j < 2; ++j)
00133       {
00134          m_colorSelectWidget[i] = new FWColorSelect(hf, names[i].c_str(), 0, m_common->colorManager(), i);
00135          hf->AddFrame(m_colorSelectWidget[i]); 
00136          m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)) ,kFALSE);
00137          m_colorSelectWidget[i]->Connect("ColorChosen(Color_t)", "CmsShowCommonPopup", this, "changeGeomColor(Color_t)");
00138 
00139          TGFrame* lf = new TGHorizontalFrame(hf, 100, 16, kFixedSize);
00140          TGLabel* label = new TGLabel(lf, m_colorSelectWidget[i]->label().c_str());
00141          label->SetTextFont(smallFont);
00142          hf->AddFrame(lf, new TGLayoutHints(kLHintsLeft |kLHintsCenterY , 0, 0, 0,0)); 
00143 
00144          ++i;
00145       }
00146    }
00147    //==============================================================================
00148 
00149    m_backgroundButton->Connect("Clicked()", "CmsShowCommonPopup", this, "switchBackground()");
00150 
00151    transpWidget2D->SetRange(0, 100);
00152    transpWidget2D->SetPosition(m_common->colorManager()->geomTransparency(true));
00153    transpWidget2D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency2D(Int_t)");
00154 
00155    transpWidget3D->SetRange(0, 100);
00156    transpWidget3D->SetPosition(m_common->colorManager()->geomTransparency(false));
00157    transpWidget3D->Connect("PositionChanged(Int_t)", "CmsShowCommonPopup", this, "changeGeomTransparency3D(Int_t)");
00158 
00159    SetWindowName("Common Preferences");
00160    MapSubwindows();
00161    Resize(GetDefaultSize());
00162    Layout();
00163    CenterOnParent(kTRUE, TGTransientFrame::kTopRight);
00164 }
00165 
00166 CmsShowCommonPopup::~CmsShowCommonPopup()
00167 {
00168 }
00169 
00170 void
00171 CmsShowCommonPopup::switchBackground()
00172 {
00173    m_common->switchBackground();
00174 }
00175  
00176 
00177 void
00178 CmsShowCommonPopup::changeGeomColor(Color_t iColor)
00179 {
00180    TGColorSelect *cs = (TGColorSelect *) gTQSender;
00181    FWGeomColorIndex cidx = FWGeomColorIndex(cs->WidgetId());
00182    m_common->setGeomColor(cidx, iColor);
00183 }
00184 
00185 void
00186 CmsShowCommonPopup::changeGeomTransparency2D(int iTransp)
00187 {
00188    m_common->setGeomTransparency(iTransp, true);
00189 }
00190 
00191 void
00192 CmsShowCommonPopup::changeGeomTransparency3D(int iTransp)
00193 {
00194    m_common->setGeomTransparency(iTransp, false);
00195 }
00196 
00197 
00198 /* Called by FWGUIManager when change background. */
00199 void 
00200 CmsShowCommonPopup::colorSetChanged()
00201 {
00202    for (int i = 0 ; i < kFWGeomColorSize; ++i)
00203       m_colorSelectWidget[i]->SetColorByIndex(m_common->colorManager()->geomColor(FWGeomColorIndex(i)), kFALSE);
00204    
00205 }
00206 
00207 
00208 void
00209 CmsShowCommonPopup::makeSetter(TGCompositeFrame* frame, FWParameterBase* param) 
00210 {
00211    boost::shared_ptr<FWParameterSetterBase> ptr( FWParameterSetterBase::makeSetterFor(param) );
00212    ptr->attach(param, this);
00213  
00214    TGFrame* pframe = ptr->build(frame);
00215    frame->AddFrame(pframe, new TGLayoutHints(kLHintsExpandX, 0, 0, 2,2));
00216 
00217    m_setters.push_back(ptr);
00218 }