CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_0/src/Fireworks/Core/src/FWGUIEventSelector.cc

Go to the documentation of this file.
00001 #include "TGLabel.h"
00002 #include "TGComboBox.h"
00003 
00004 #include "Fireworks/Core/interface/FWGUIEventSelector.h"
00005 #include "Fireworks/Core/interface/FWEventSelector.h"
00006 #include "Fireworks/Core/interface/FWHLTValidator.h"
00007 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
00008 #include "Fireworks/Core/interface/FWCustomIconsButton.h"
00009 #include "Fireworks/Core/src/FWCheckBoxIcon.h"
00010 
00011 
00012 FWGUIEventSelector::FWGUIEventSelector(TGCompositeFrame* p, FWEventSelector* sel, std::vector<std::string>& triggerProcessList):
00013    TGHorizontalFrame(p),
00014    m_guiSelector(0),
00015    m_origSelector(0),
00016    m_text1(0),
00017    m_text2(0),
00018    m_enableBtn(0),
00019    m_deleteBtn(0),
00020    m_nEvents(0),
00021    m_combo(0),
00022    m_validator(0)
00023 {
00024    m_origSelector = sel;
00025    m_guiSelector = new FWEventSelector(m_origSelector);
00026    
00027    if (!m_guiSelector->m_triggerProcess.empty())
00028    {
00029       m_combo = new TGComboBox(this);
00030       int cnt = 0;
00031       int id = -1;
00032       for ( std::vector<std::string>::iterator i = triggerProcessList.begin(); i!=triggerProcessList.end(); ++i)
00033       {
00034          if ((*i).c_str() == sel->m_triggerProcess) id = cnt;
00035          m_combo->AddEntry((*i).c_str(), cnt++);
00036       }
00037 
00038       if (id < 0)
00039       {
00040          m_combo->AddEntry(sel->m_triggerProcess.c_str(), cnt);
00041          id = cnt;
00042       }
00043       m_combo->Select(id, false);
00044       m_combo->Resize(80, 21);
00045       AddFrame(m_combo, new TGLayoutHints(kLHintsNormal, 2,2,0,1));
00046 
00047       m_validator = new FWHLTValidator(m_guiSelector->m_triggerProcess);
00048       m_combo->Connect("Selected(const char*)", "FWGUIEventSelector", this, "triggerProcessCallback(const char*)");
00049    }
00050 
00051    // -------------- expression
00052 
00053    m_text1 = new FWGUIValidatingTextEntry(this, m_guiSelector->m_expression.c_str());
00054    m_text1->SetHeight(20);
00055    m_text1->setValidator(m_validator);
00056    m_text1->ChangeOptions(0);
00057    m_text1->Connect("TextChanged(char*)", "FWGUIEventSelector",  this, "expressionCallback(char*)");
00058    AddFrame(m_text1, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 2,2,1,1));
00059     
00060    // -------------- comment
00061 
00062    TGCompositeFrame *cfr = new TGHorizontalFrame(this, 120, 20, kFixedSize);
00063    AddFrame(cfr,new TGLayoutHints( kLHintsNormal, 2, 2, 1, 3 ));
00064    m_text2 = new FWGUIValidatingTextEntry(cfr, m_guiSelector->m_description.c_str());
00065    //   m_text2->SetHeight(21);
00066    m_text2->setValidator(m_validator);
00067    m_text2->ChangeOptions(0);
00068    m_text2->Connect("TextChanged(char*)", "string", &m_guiSelector->m_description, "assign(char*)");
00069    cfr->AddFrame(m_text2, new TGLayoutHints(kLHintsNormal | kLHintsExpandX, 2,2,0,0));
00070   
00071    // ---------------- selection info
00072 
00073    TGHorizontalFrame* labFrame = new TGHorizontalFrame(this, 60, 22, kFixedSize);
00074    AddFrame(labFrame, new TGLayoutHints(kLHintsBottom, 2, 2, 2, 2));
00075    m_nEvents = new TGLabel(labFrame, "");
00076    m_nEvents->SetTextJustify(kTextLeft );
00077    labFrame->AddFrame(m_nEvents,  new TGLayoutHints(kLHintsCenterY|kLHintsExpandX));
00078    updateNEvents();
00079   
00080    // ---------------- enable
00081 
00082    m_enableBtn = new TGCheckButton(this,"");
00083    m_enableBtn->SetToolTipText("Enable/disable the selection");
00084    m_enableBtn->SetOn(m_guiSelector->m_enabled);
00085    m_enableBtn->Connect("Toggled(bool)","FWGUIEventSelector", this, "enableCallback(bool)");
00086    AddFrame(m_enableBtn, new TGLayoutHints(kLHintsNormal |  kLHintsCenterY , 2, 2, 0, 0));
00087 
00088    // ---------------- delete 
00089    m_deleteBtn = new FWCustomIconsButton(this, fClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"delete.png"),
00090                                          fClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"delete-over.png"),
00091                                          fClient->GetPicture(FWCheckBoxIcon::coreIcondir()+"delete-disabled.png"));
00092    AddFrame(m_deleteBtn, new TGLayoutHints(kLHintsRight|kLHintsCenterY, 2,2,0, 0));
00093    TQObject::Connect(m_deleteBtn, "Clicked()", "FWGUIEventSelector",  this, "deleteCallback()");
00094 
00095 }
00096 //____________________________________________________________________________
00097 FWGUIEventSelector::~FWGUIEventSelector()
00098 {
00099    delete m_guiSelector;
00100    delete m_validator;
00101 }
00102 
00103 //____________________________________________________________________________
00104 void FWGUIEventSelector::enableCallback(bool x)
00105 {
00106    m_guiSelector->m_enabled = x;
00107    selectorChanged();
00108 }
00109 
00110 //______________________________________________________________________________
00111 void FWGUIEventSelector::removeSelector(FWGUIEventSelector* s)
00112 {
00113    Emit("removeSelector(FWGUIEventSelector*)", (Long_t)s);
00114 }
00115 
00116 //______________________________________________________________________________
00117 void FWGUIEventSelector::deleteCallback()
00118 {
00119    removeSelector(this);
00120 }
00121 
00122 //______________________________________________________________________________
00123 void FWGUIEventSelector::triggerProcessCallback(const char* txt)
00124 {
00125    m_guiSelector->m_triggerProcess = txt;
00126    m_validator->setProcess(txt);
00127    selectorChanged();
00128 }
00129 
00130 //______________________________________________________________________________
00131 void FWGUIEventSelector::expressionCallback(char* txt)
00132 {
00133    m_guiSelector->m_expression = txt;
00134    selectorChanged();
00135 }
00136 
00137 //______________________________________________________________________________
00138 void FWGUIEventSelector::selectorChanged()
00139 {
00140    if (m_origSelector) m_origSelector->m_updated = false;
00141    Emit("selectorChanged()");
00142 }
00143 
00144 //______________________________________________________________________________
00145 void FWGUIEventSelector::updateNEvents()
00146 {
00147   
00148    if (m_origSelector && m_origSelector->m_updated)
00149    {
00150       m_nEvents->Enable();
00151       const char* txtInfo  =  Form("%3d",  m_origSelector ? m_origSelector->m_selected : -1);
00152       m_nEvents->SetText(txtInfo);
00153    }
00154    else
00155    {
00156       m_nEvents->Disable();
00157       m_nEvents->SetText("no check");
00158    }
00159 }