CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/Fireworks/Core/src/FWGUIEventFilter.cc

Go to the documentation of this file.
00001 #include "TGLabel.h"
00002 #include "TG3DLine.h"
00003 #include "TGResourcePool.h"
00004 #include "Fireworks/Core/interface/RootGuiUtils.h"
00005 #include "Fireworks/Core/interface/FWGUIEventFilter.h"
00006 #include "Fireworks/Core/interface/FWGUIEventSelector.h"
00007 #include "Fireworks/Core/interface/FWConfiguration.h"
00008 #include "Fireworks/Core/interface/FWCustomIconsButton.h"
00009 #include "Fireworks/Core/interface/FWJobMetadataManager.h"
00010 #include "Fireworks/Core/interface/CmsShowNavigator.h"
00011 #include "Fireworks/Core/interface/Context.h"
00012 #include "Fireworks/Core/interface/CSGAction.h"
00013 #include "Fireworks/Core/src/FWCheckBoxIcon.h"
00014 #include "Fireworks/Core/interface/FWGUIManager.h"
00015 #include "Fireworks/Core/interface/CmsShowMainFrame.h"
00016 
00017 FWGUIEventFilter::FWGUIEventFilter(CmsShowNavigator* n):
00018    TGMainFrame(gClient->GetRoot(), 560, 300),
00019 
00020 
00021    m_origFilterMode(CmsShowNavigator::kOr),
00022    m_isOpen(false),
00023    m_filtersRemoved(false),
00024 
00025    m_eventSelectionFrameParent(0),
00026    m_eventSelectionFrame(0),
00027    m_triggerSelectionFrameParent(0),
00028    m_triggerSelectionFrame(0),
00029 
00030    m_rad1(0),
00031    m_rad2(0),
00032    m_stateLabel(0),
00033    m_disableFilteringBtn(0),
00034    m_addBtn(0),
00035 
00036    m_navigator(n)
00037 {
00038    SetWindowName("Event Filters");
00039 
00040    TGVerticalFrame* v1 = new TGVerticalFrame(this);
00041    AddFrame(v1, new TGLayoutHints(kLHintsExpandX |kLHintsExpandY));
00042 
00043 
00044    //----------------------- Event selection
00045   
00046    {
00047       m_eventSelectionFrameParent =  new TGVerticalFrame(v1, GetWidth(), s_entryHeight, 0);
00048       v1->AddFrame(m_eventSelectionFrameParent, new TGLayoutHints(kLHintsExpandX|kLHintsTop, 2, 2, 0,0));
00049 
00050       // headers
00051       TGHorizontalFrame* selH = new TGHorizontalFrame(m_eventSelectionFrameParent);
00052       m_eventSelectionFrameParent->AddFrame(selH, new TGLayoutHints(kLHintsExpandX));
00053 
00054       {
00055          TGCompositeFrame *cfr = new TGHorizontalFrame(selH);
00056          selH->AddFrame(cfr, new TGLayoutHints(kLHintsExpandX));
00057          cfr->AddFrame(new TGLabel(cfr, "Event Filter Expression:"), new TGLayoutHints(kLHintsLeft|kLHintsBottom, 2, 2, 6, 4));
00058       }
00059       {
00060          TGCompositeFrame *cfr = new TGHorizontalFrame(selH, 122, 22, kFixedSize);
00061          selH->AddFrame(cfr);
00062          cfr->AddFrame(new TGLabel(cfr, "Comment:"), new TGLayoutHints(kLHintsLeft|kLHintsBottom, 2, 2, 2, 0));
00063       }
00064       {
00065          TGCompositeFrame *cfr = new TGHorizontalFrame(selH, 105, 22, kFixedSize);
00066          selH->AddFrame(cfr);
00067          cfr->AddFrame(new TGLabel(cfr, "Pass:"), new TGLayoutHints(kLHintsLeft|kLHintsBottom, 2, 2, 2, 0));
00068       }
00069 
00070 
00071       TGHorizontalFrame* addBtnFrame = new TGHorizontalFrame(v1);
00072       v1->AddFrame(addBtnFrame, new TGLayoutHints(kLHintsExpandX));
00073       addBtnFrame->AddFrame(new TGHorizontal3DLine(addBtnFrame),  new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,4 ,8, 2, 2));
00074     
00075       m_addBtn = new FWCustomIconsButton(addBtnFrame, fClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "plus-sign.png"),
00076                                          fClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "plus-sign-over.png"),
00077                                          fClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "plus-sign-disabled.png"));
00078 
00079       addBtnFrame->AddFrame(m_addBtn, new TGLayoutHints(kLHintsRight/*|kLHintsExpandX|kLHintsExpandY*/, 0, 6, 4, 1));
00080       TQObject::Connect(m_addBtn, "Clicked()", "FWGUIEventFilter",  this, "newEventEntry()");
00081    }
00082 
00083    //----------------------- TriggerResults selection
00084 
00085    {
00086       m_triggerSelectionFrameParent =  new TGVerticalFrame(v1, GetWidth(), s_entryHeight, 0);
00087       v1->AddFrame(m_triggerSelectionFrameParent, new TGLayoutHints(kLHintsExpandX|kLHintsTop, 2, 2, 0,0));
00088 
00089       // headers
00090       TGHorizontalFrame* selH = new TGHorizontalFrame(m_triggerSelectionFrameParent);
00091       m_triggerSelectionFrameParent->AddFrame(selH, new TGLayoutHints(kLHintsExpandX));
00092 
00093       {
00094          TGCompositeFrame *cfr = new TGHorizontalFrame(selH);
00095          selH->AddFrame(cfr, new TGLayoutHints(kLHintsExpandX));
00096          cfr->AddFrame(new TGLabel(cfr, "TriggerResults Filter Expression:"), new TGLayoutHints(kLHintsLeft|kLHintsBottom, 2, 2, 6, 04));
00097       }
00098       {
00099          TGCompositeFrame *cfr = new TGHorizontalFrame(selH, 122, 22, kFixedSize);
00100          selH->AddFrame(cfr);
00101          cfr->AddFrame(new TGLabel(cfr, "Comment:"), new TGLayoutHints(kLHintsLeft|kLHintsBottom, 2, 2, 0, 0));
00102       }
00103       {
00104          TGCompositeFrame *cfr = new TGHorizontalFrame(selH, 105, 22, kFixedSize);
00105          selH->AddFrame(cfr);
00106          cfr->AddFrame(new TGLabel(cfr, "Pass:"), new TGLayoutHints(kLHintsLeft|kLHintsBottom, 2, 2, 0, 0));
00107       }
00108 
00109       //-------------------- adding new selection
00110 
00111       TGHorizontalFrame* addBtnFrame = new TGHorizontalFrame(v1);
00112       v1->AddFrame(addBtnFrame, new TGLayoutHints(kLHintsExpandX));
00113 
00114       addBtnFrame->AddFrame(new TGHorizontal3DLine(addBtnFrame),  new TGLayoutHints(kLHintsExpandX | kLHintsCenterY,4 ,8, 2, 2));
00115       m_addBtn = new FWCustomIconsButton(addBtnFrame, fClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "plus-sign.png"),
00116                                          fClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "plus-sign-over.png"),
00117                                          fClient->GetPicture(FWCheckBoxIcon::coreIcondir() + "plus-sign-disabled.png"));
00118 
00119       addBtnFrame->AddFrame(m_addBtn, new TGLayoutHints(kLHintsRight/*|kLHintsExpandX|kLHintsExpandY*/, 0, 6, 4, 1));
00120       TQObject::Connect(m_addBtn, "Clicked()", "FWGUIEventFilter",  this, "newTriggerEntry()");
00121 
00122    }
00123 
00124    //-------------------- logical operations
00125 
00126    TGHorizontalFrame* headerFrame = new TGHorizontalFrame(v1/*, 360, 61, kHorizontalFrame | kFixedSize*/);
00127 
00128    {
00129       TGHorizontalFrame* xx = new TGHorizontalFrame(v1);
00130       fireworks_root_gui::makeLabel(xx, "Combine Expression Width:", 152, 2,2,2,2);
00131       m_rad1 =  new TGRadioButton(xx, "OR", 81);
00132       xx->AddFrame(m_rad1, new TGLayoutHints(kLHintsNormal, 2,10, 0, 0));
00133       m_rad1->SetState(kButtonDown);
00134       m_rad2 =  new TGRadioButton(xx, "AND", 82);
00135       xx->AddFrame(m_rad2);
00136       m_rad1->Connect("Clicked()", "FWGUIEventFilter", this, "changeFilterMode()");
00137       m_rad2->Connect("Clicked()", "FWGUIEventFilter", this, "changeFilterMode()");
00138 
00139       v1->AddFrame(xx, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 2));
00140    }
00141    v1->AddFrame(headerFrame, new TGLayoutHints(kLHintsNormal, 1, 1, 1, 1));
00142 
00143 
00144    //-------------------- status
00145    {
00146       TGHorizontalFrame* hf = new TGHorizontalFrame(v1);
00147       v1->AddFrame(hf, new TGLayoutHints(kLHintsExpandX, 2, 2, 2, 20));
00148       fireworks_root_gui::makeLabel(hf, "Status:", 37, 2,2,2,2);
00149       {     
00150          TGGC *fTextGC;
00151          const TGFont *font = gClient->GetFont("-adobe-helvetica-bold-r-*-*-12-*-*-*-*-*-iso8859-1");
00152          if (!font)
00153             font = gClient->GetResourcePool()->GetDefaultFont();
00154          GCValues_t   gval;
00155          gval.fMask = kGCBackground | kGCFont | kGCForeground;
00156          gval.fFont = font->GetFontHandle();
00157          fTextGC = gClient->GetGC(&gval, kTRUE);
00158 
00159          TGHorizontalFrame *labFrame = new TGHorizontalFrame(hf, 380, 22, kHorizontalFrame | kFixedWidth);
00160          hf->AddFrame(labFrame, new TGLayoutHints(kLHintsNormal));
00161 
00162          m_stateLabel = new TGLabel(labFrame, "x", fTextGC->GetGC());
00163          labFrame->AddFrame(m_stateLabel, new TGLayoutHints( kLHintsLeft,2,2,2,2));
00164                                      
00165       }
00166    }
00167    //-------------------- external actions
00168 
00169    TGHorizontalFrame* btnFrame = new TGHorizontalFrame(v1, 280, 30);
00170    v1->AddFrame(btnFrame, new TGLayoutHints(kLHintsCenterX | kLHintsExpandX | kLHintsBottom , 0, 0, 2, 4));
00171 
00172    TGTextButton* cancel = new TGTextButton(btnFrame," Close ");
00173    btnFrame->AddFrame(cancel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY , 20, 20, 2, 4));
00174    cancel->Connect("Clicked()","FWGUIEventFilter", this, "CloseWindow()");
00175 
00176    {
00177       TGHorizontalFrame* f = new TGHorizontalFrame(btnFrame);
00178       btnFrame->AddFrame(f, new TGLayoutHints(kLHintsRight, 4, 18, 2, 4));
00179       m_disableFilteringBtn = new TGTextButton(f, " Disable Filtering ");
00180       f->AddFrame(m_disableFilteringBtn, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4, 10, 2, 4));
00181       m_disableFilteringBtn->Connect("Clicked()","FWGUIEventFilter", this, "disableFilters()");
00182 
00183       m_applyBtn = new TGTextButton(f,"Apply Filters");
00184       f->AddFrame(m_applyBtn, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 4, 8, 2, 4));
00185       m_applyBtn->Connect("Clicked()","FWGUIEventFilter", this, "apply()");
00186       m_applyBtn->SetToolTipText("Enable filtering and apply changes.");
00187    }
00188 
00189 
00190 }
00191 
00192 FWGUIEventFilter::~FWGUIEventFilter()
00193 {
00194 }
00195 
00196 void
00197 FWGUIEventFilter::addSelector(FWEventSelector* sel)
00198 {
00199    TGCompositeFrame* parent = sel->m_triggerProcess.empty() ? m_eventSelectionFrame : m_triggerSelectionFrame;
00200    FWGUIEventSelector* es = new FWGUIEventSelector(parent, sel, m_navigator->getProcessList() );
00201    parent->AddFrame(es, new TGLayoutHints(kLHintsExpandX));
00202    TQObject::Connect(es, "removeSelector(FWGUIEventSelector*)", "FWGUIEventFilter",  this, "deleteEntry(FWGUIEventSelector*)");
00203    TQObject::Connect(es, "selectorChanged()", "FWGUIEventFilter",  this, "checkApplyButton()");
00204 
00205    m_guiSelectors.push_back(es);
00206  
00207 }
00208 
00209 void
00210 FWGUIEventFilter::changeFilterMode()
00211 {
00212    TGButton *btn = (TGButton *) gTQSender;
00213 
00214    if (btn->WidgetId() == 81)
00215       m_rad2->SetState(kButtonUp);
00216    else
00217       m_rad1->SetState(kButtonUp);
00218    checkApplyButton();
00219 }
00220 
00221 void
00222 FWGUIEventFilter::show( std::list<FWEventSelector*>* sels, int filterMode, int filterState)
00223 {
00224    m_applyBtn->SetForegroundColor(0x000000);
00225    m_filtersRemoved = false;
00226 
00227    m_isOpen = true;
00228 
00229    m_origFilterMode = filterMode;
00230 
00231    if (filterMode == CmsShowNavigator::kOr)
00232    {
00233       m_rad1->SetState(kButtonDown, false);
00234       m_rad2->SetState(kButtonUp, false);
00235    }
00236    else
00237    {
00238       m_rad2->SetState(kButtonDown, false);
00239       m_rad1->SetState(kButtonUp, false);
00240    }
00241 
00242    assert(m_eventSelectionFrame == 0);
00243    
00244    m_eventSelectionFrame = new TGVerticalFrame(m_eventSelectionFrameParent);
00245    m_eventSelectionFrameParent->AddFrame(m_eventSelectionFrame,  new TGLayoutHints(kLHintsExpandX));
00246 
00247    m_triggerSelectionFrame = new TGVerticalFrame(m_triggerSelectionFrameParent);
00248    m_triggerSelectionFrameParent->AddFrame(m_triggerSelectionFrame,  new TGLayoutHints(kLHintsExpandX));
00249 
00250    for(std::list<FWEventSelector*>::iterator i = sels->begin(); i != sels->end(); ++i)
00251       addSelector(*i);
00252 
00253    updateFilterStateLabel(filterState);
00254 
00255    MapSubwindows();
00256    Layout();
00257    MapRaised();
00258 }
00259 
00260 void
00261 FWGUIEventFilter::reset()
00262 {
00263    // called on load of configuration
00264    if (m_eventSelectionFrameParent) {
00265       m_eventSelectionFrameParent->RemoveFrame(m_eventSelectionFrame);
00266       m_eventSelectionFrame = 0;
00267    }
00268    if (m_triggerSelectionFrameParent) {
00269       m_triggerSelectionFrameParent->RemoveFrame(m_triggerSelectionFrame);
00270       m_triggerSelectionFrame = 0;
00271    }
00272 
00273    for (std::list<FWGUIEventSelector*>::iterator i = m_guiSelectors.begin(); i != m_guiSelectors.end(); ++i)
00274       delete *i;
00275    
00276    m_guiSelectors.clear();
00277 }
00278 
00280 //   Callbacks
00282 
00283 void
00284 FWGUIEventFilter::deleteEntry(FWGUIEventSelector* sel)
00285 {
00286    m_filtersRemoved = true;
00287 
00288    m_guiSelectors.remove(sel);
00289 
00290    TGCompositeFrame* p = 0;
00291    if (sel->origSelector()->m_triggerProcess.empty())
00292       p = m_eventSelectionFrame;
00293    else
00294       p = m_triggerSelectionFrame;
00295 
00296    p->RemoveFrame(sel);
00297    Resize(GetWidth(), GetDefaultHeight());
00298    Layout();
00299    gClient->NeedRedraw(this);
00300 }
00301 
00302 void
00303 FWGUIEventFilter::newTriggerEntry()
00304 { 
00305    FWEventSelector* s = new FWEventSelector;
00306    s->m_triggerProcess = "HLT";
00307    addSelector(s);
00308    MapSubwindows();
00309 
00310    Resize(GetWidth(), GetDefaultHeight());
00311 
00312    Layout();
00313 }
00314 
00315 void
00316 FWGUIEventFilter::newEventEntry()
00317 {
00318    addSelector(new FWEventSelector());
00319    MapSubwindows();
00320    Resize(GetWidth(), GetDefaultHeight());
00321    Layout();
00322 }
00323 
00324 void
00325 FWGUIEventFilter::apply()
00326 {
00327    m_navigator->applyFiltersFromGUI();
00328 
00329    m_origFilterMode = getFilterMode();
00330    m_filtersRemoved = false;
00331    m_applyBtn->SetForegroundColor(0x000000);
00332    fClient->NeedRedraw( this);
00333 
00334 }
00335 
00336 void
00337 FWGUIEventFilter::setupDisableFilteringButton(bool x)
00338 {
00339    m_disableFilteringBtn->SetEnabled(x);
00340 }
00341 
00342 void
00343 FWGUIEventFilter::disableFilters()
00344 {
00345    m_navigator->toggleFilterEnable();
00346 }
00347 
00348 int
00349 FWGUIEventFilter::getFilterMode()
00350 {
00351    if (m_rad1->IsOn())
00352       return CmsShowNavigator::kOr;
00353    else
00354       return CmsShowNavigator::kAnd;
00355 }
00356 
00357 void
00358 FWGUIEventFilter::CloseWindow()
00359 {
00360    m_isOpen = false;
00361    m_eventSelectionFrameParent->RemoveFrame(m_eventSelectionFrame);
00362    m_eventSelectionFrame = 0;
00363    m_triggerSelectionFrameParent->RemoveFrame(m_triggerSelectionFrame);
00364    m_triggerSelectionFrame = 0;
00365 
00366    FWGUIEventSelector* gs;
00367    for (std::list<FWGUIEventSelector*>::iterator i = m_guiSelectors.begin(); i != m_guiSelectors.end(); ++i)
00368    {
00369       gs = *i;
00370       delete gs;
00371    }
00372 
00373    m_guiSelectors.clear();
00374    UnmapWindow();
00375    m_navigator->editFiltersExternally();
00376 }
00377 
00378 
00379 void
00380 FWGUIEventFilter::checkApplyButton()
00381 {
00382    bool changed = m_filtersRemoved;
00383 
00384    if (!changed)
00385    {
00386       changed = (getFilterMode() != m_origFilterMode);
00387 
00388       if (!changed)
00389       {
00390          std::list<FWGUIEventSelector*>::iterator i = m_guiSelectors.begin();
00391          while (i != m_guiSelectors.end())
00392          {
00393             if ((*i)->origSelector() == 0)
00394                break;
00395 
00396             if ( (*i)->guiSelector()->m_enabled    != (*i)->origSelector()->m_enabled  ||
00397                  (*i)->guiSelector()->m_expression != (*i)->origSelector()->m_expression )
00398                break;
00399 
00400             ++i;
00401          }
00402          changed = (i != m_guiSelectors.end());
00403       }
00404    }
00405 
00406    m_applyBtn->SetForegroundColor(changed ? 0x40FF80 : 0x000000);
00407    gClient->NeedRedraw( m_applyBtn);
00408 }
00409 
00410 void
00411 FWGUIEventFilter::updateFilterStateLabel(int state)
00412 {
00413    if (state == CmsShowNavigator::kOn)
00414       m_stateLabel->SetText(Form("%d events selected from %d   ", m_navigator->getNSelectedEvents(), m_navigator->getNTotalEvents()));
00415    else if (state == CmsShowNavigator::kOff)
00416       m_stateLabel->SetText("Filtering Disabled  ");
00417    else
00418       m_stateLabel->SetText("Filtering Withdrawn  ");
00419 
00420    Layout();
00421 }
00422 
00423 /*
00424   AMT  no effect after resize
00425 void
00426 FWGUIEventFilter::addTo(FWConfiguration& iTo) const
00427 {
00428    FWConfiguration tmp;
00429    {
00430       std::stringstream s;
00431       s << GetWidth();
00432       tmp.addKeyValue("width", s.str());
00433    } 
00434    {
00435       std::stringstream s;
00436       s << GetHeight();
00437       tmp.addKeyValue("height", s.str());
00438    }
00439 
00440    iTo.addKeyValue("EventFilterGUI", tmp, true);
00441     
00442 }
00443 
00444 void
00445 FWGUIEventFilter::setFrom(const FWConfiguration& iFrom)
00446 {
00447    const FWConfiguration* conf = iFrom.valueForKey("EventFilterGUI");
00448    if (conf) {
00449       UInt_t w = atoi(conf->valueForKey("width")->value().c_str());
00450       UInt_t h = atoi(conf->valueForKey("height")->value().c_str());
00451       Resize(w, h);
00452    }
00453 }
00454 */
00455 
00456 bool FWGUIEventFilter::HandleKey(Event_t *event)
00457 { 
00458    // AMT workaround for problems  to override root's action  for 'Ctrl+s'
00459   
00460    if (GetBindList()->IsEmpty())
00461       FWGUIManager::getGUIManager()->getMainFrame()->bindCSGActionKeys(this);
00462 
00463    TIter next(fBindList);
00464    TGMapKey *m;
00465    TGFrame  *w = 0;
00466 
00467    while ((m = (TGMapKey *) next())) {
00468       if (m->fKeyCode == event->fCode) {
00469          w = (TGFrame *) m->fWindow;
00470          if (w->HandleKey(event)) return kTRUE;
00471       }
00472    }
00473    return kFALSE;
00474 }