Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-08-05 22:48:06

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     CmsShowEDI
0005 //
0006 // Implementation:
0007 //     <Notes on implementation>
0008 //
0009 // Original Author:  Joshua Berger
0010 //         Created:  Mon Jun 23 15:48:11 EDT 2008
0011 //
0012 
0013 // system include files
0014 #include <iostream>
0015 #include <sstream>
0016 #include <sigc++/sigc++.h>
0017 #include <functional>
0018 #include "TClass.h"
0019 #include "TGFrame.h"
0020 #include "TGTab.h"
0021 #include "TGButton.h"
0022 #include "TGLabel.h"
0023 #include "TGString.h"
0024 #include "TColor.h"
0025 #include "TG3DLine.h"
0026 #include "TGNumberEntry.h"
0027 #include "TGTextEntry.h"
0028 #include "TGTextView.h"
0029 #include "TGLayout.h"
0030 #include "TGFont.h"
0031 #include "TEveManager.h"
0032 #include "TGSlider.h"
0033 #include "TGMsgBox.h"
0034 #include "TGComboBox.h"
0035 #include "TVirtualX.h"
0036 
0037 // user include files
0038 #include "Fireworks/Core/interface/CmsShowEDI.h"
0039 #include "Fireworks/Core/interface/FWSelectionManager.h"
0040 #include "Fireworks/Core/interface/FWDisplayProperties.h"
0041 #include "Fireworks/Core/interface/FWEventItem.h"
0042 #include "Fireworks/Core/interface/FWProxyBuilderConfiguration.h"
0043 #include "Fireworks/Core/src/FWColorSelect.h"
0044 #include "Fireworks/Core/interface/FWModelChangeSignal.h"
0045 #include "Fireworks/Core/interface/FWModelExpressionSelector.h"
0046 #include "Fireworks/Core/interface/FWModelChangeManager.h"
0047 #include "Fireworks/Core/interface/FWColorManager.h"
0048 #include "Fireworks/Core/interface/FWExpressionException.h"
0049 #include "Fireworks/Core/src/FWGUIValidatingTextEntry.h"
0050 #include "Fireworks/Core/src/FWExpressionValidator.h"
0051 #include "Fireworks/Core/interface/FWDialogBuilder.h"
0052 
0053 //
0054 // constants, enums and typedefs
0055 ///
0056 
0057 //
0058 // static data member definitions
0059 //
0060 
0061 //
0062 // constructors and destructor
0063 //
0064 CmsShowEDI::CmsShowEDI(const TGWindow* p, UInt_t w, UInt_t h, FWSelectionManager* selMgr, FWColorManager* colorMgr)
0065     : TGTransientFrame(gClient->GetDefaultRoot(), p, w, h),
0066       m_item(nullptr),
0067       m_validator(new FWExpressionValidator),
0068       m_colorManager(colorMgr),
0069       m_settersFrame(nullptr) {
0070   m_selectionManager = selMgr;
0071   SetCleanup(kDeepCleanup);
0072 
0073   m_selectionManager->itemSelectionChanged_.connect(std::bind(&CmsShowEDI::fillEDIFrame, this));
0074 
0075   TGVerticalFrame* vf = new TGVerticalFrame(this);
0076   AddFrame(vf, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 0, 0));
0077   FWDialogBuilder builder(vf, nullptr, true);
0078 
0079   builder.indent(0)
0080       .expand(true, false)
0081       .addLabel(" ", 14, 2, &m_objectLabel)
0082       // .vSpacer()
0083       .tabs(&m_tabs)
0084       .beginTab("Graphics")
0085       .indent(3)
0086       .addLabel("Color", 8)
0087       .addColorPicker(colorMgr, &m_colorSelectWidget)
0088       .expand(false)
0089       .addHSeparator()
0090       .addLabel("Opacity", 8)
0091       .addHSlider(150, &m_opacitySlider)
0092       .addHSeparator()
0093       .addCheckbox("Visible", &m_isVisibleButton)
0094       .addHSeparator()
0095       .addLabel("Drawing order", 8)
0096       .addTextButton("To back", &m_backButton)
0097       .floatLeft()
0098       .expand(false)
0099       .addNumberEntry(
0100           0.0, 4, TGNumberFormat::kNESInteger, FWEventItem::minLayerValue(), FWEventItem::maxLayerValue(), &m_layerEntry)
0101       .expand(false)
0102       .floatLeft()
0103       .addTextButton("To front", &m_frontButton)
0104       .expand(false)
0105       .vSpacer()
0106       .addHSeparator()
0107       .endTab()
0108       .beginTab("Filter")
0109       .indent(3)
0110       .addLabel("Expression", 8)
0111       .addValidatingTextEntry(nullptr, &m_filterExpressionEntry)
0112       .floatLeft()
0113       .addTextButton("Filter", &m_filterButton)
0114       .expand(false)
0115       .addTextView("", &m_filterError)
0116       .vSpacer()
0117       .endTab()
0118       .beginTab("Select")
0119       .indent(3)
0120       .addLabel("Expression", 8)
0121       .addValidatingTextEntry(nullptr, &m_selectExpressionEntry)
0122       .addTextButton("Select", &m_selectButton)
0123       .floatLeft()
0124       .expand(false)
0125       .addTextButton("Select all", &m_selectAllButton)
0126       .expand(false)
0127       .floatLeft()
0128       .addTextButton("Unselect all", &m_deselectAllButton)
0129       .expand(false)
0130       .indent(3)
0131       .addLabel("Color Selection", 8)
0132       .addColorPicker(colorMgr, &m_cw)
0133       .expand(false)
0134       .addTextView("", &m_selectError)
0135       .vSpacer()
0136       .endTab()
0137       .beginTab("Data")
0138       .indent(3)
0139       .addLabel("Name:", 8)
0140       .addTextEntry("None", &m_nameEntry)
0141       .addLabel("Labels:", 8)
0142       .addLabel("Type:", 8)
0143       .addTextEntry("None", &m_typeEntry)
0144       .addLabel("Module:", 8)
0145       .addTextEntry("None", &m_moduleEntry)
0146       .addLabel("Instance:", 8)
0147       .addTextEntry("None", &m_instanceEntry)
0148       .addLabel("Process:", 8)
0149       .addTextEntry("None", &m_processEntry)
0150       .addHSeparator()
0151       .addTextButton("Remove collection", &m_removeButton)
0152       .expand(false)
0153       .vSpacer()
0154       .endTab()
0155       .untabs();
0156 
0157   m_filterError->SetForegroundColor(gVirtualX->GetPixel(kRed));
0158   m_filterError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
0159   m_filterError->ChangeOptions(0);
0160 
0161   m_selectError->SetForegroundColor(gVirtualX->GetPixel(kRed));
0162   m_selectError->SetBackgroundColor(TGFrame::GetDefaultFrameBackground());
0163   m_selectError->ChangeOptions(0);
0164 
0165   m_filterExpressionEntry->setValidator(m_validator);
0166   m_selectExpressionEntry->setValidator(m_validator);
0167 
0168   m_colorSelectWidget->Connect("ColorChosen(Color_t)", "CmsShowEDI", this, "changeItemColor(Color_t)");
0169   m_cw->Connect("ColorChosen(Color_t)", "CmsShowEDI", this, "changeSelectionColor(Color_t)");
0170   m_opacitySlider->Connect("PositionChanged(Int_t)", "CmsShowEDI", this, "changeItemOpacity(Int_t)");
0171   m_isVisibleButton->Connect("Toggled(Bool_t)", "CmsShowEDI", this, "toggleItemVisible(Bool_t)");
0172   m_filterExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runFilter()");
0173   m_filterButton->Connect("Clicked()", "CmsShowEDI", this, "runFilter()");
0174   m_selectExpressionEntry->Connect("ReturnPressed()", "CmsShowEDI", this, "runSelection()");
0175   m_selectButton->Connect("Clicked()", "CmsShowEDI", this, "runSelection()");
0176   m_removeButton->Connect("Clicked()", "CmsShowEDI", this, "removeItem()");
0177   m_selectAllButton->Connect("Clicked()", "CmsShowEDI", this, "selectAll()");
0178   m_deselectAllButton->Connect("Clicked()", "CmsShowEDI", this, "deselectAll()");
0179   m_frontButton->Connect("Clicked()", "CmsShowEDI", this, "moveToFront()");
0180   m_backButton->Connect("Clicked()", "CmsShowEDI", this, "moveToBack()");
0181   m_layerEntry->Connect("ValueSet(Long_t)", "CmsShowEDI", this, "moveToLayer(Long_t)");
0182 
0183   TGCompositeFrame* cf = m_tabs->GetTabContainer(0);
0184   m_settersFrame = new TGVerticalFrame(cf);
0185   m_settersFrame->SetCleanup(kDeepCleanup);
0186   cf->AddFrame(m_settersFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
0187 
0188   SetWindowName("Collection Controller");
0189   MapSubwindows();
0190   Resize(GetDefaultSize());
0191   Layout();
0192 
0193   fillEDIFrame();
0194 }
0195 
0196 // CmsShowEDI::CmsShowEDI(const CmsShowEDI& rhs)
0197 // {
0198 //    // do actual copying here;
0199 // }
0200 
0201 CmsShowEDI::~CmsShowEDI() {
0202   disconnectAll();
0203   m_colorSelectWidget->Disconnect("ColorSelected(Pixel_t)", this, "changeItemColor(Pixel_t)");
0204   m_cw->Disconnect("ColorSelected(Pixel_t)", this, "changeSelectionColor(Pixel_t)");
0205   m_opacitySlider->Disconnect("PositionChanged(Int_t)", this, "changeItemColor");
0206   m_isVisibleButton->Disconnect("Toggled(Bool_t)", this, "toggleItemVisible(Bool_t)");
0207   m_filterExpressionEntry->Disconnect("ReturnPressed()", this, "runFilter()");
0208   m_selectExpressionEntry->Disconnect("ReturnPressed()", this, "runSelection()");
0209   m_filterButton->Disconnect("Clicked()", this, "runFilter()");
0210   m_selectButton->Disconnect("Clicked()", this, "runSelection()");
0211   m_selectAllButton->Disconnect("Clicked()", this, "selectAll()");
0212   m_deselectAllButton->Disconnect("Clicked()", this, "deselectAll()");
0213   m_removeButton->Disconnect("Clicked()", this, "removeItem()");
0214   m_frontButton->Disconnect("Clicked()", this, "moveToFront()");
0215   m_backButton->Disconnect("Clicked()", this, "moveToBack()");
0216   m_layerEntry->Disconnect("ValueSet(Long_t)", this, "moveToLayer(Long_t)");
0217   //  delete m_objectLabel;
0218   //  delete m_colorSelectWidget;
0219   //  delete m_isVisibleButton;
0220   delete m_validator;
0221 }
0222 
0223 //
0224 // assignment operators
0225 //
0226 // const CmsShowEDI& CmsShowEDI::operator=(const CmsShowEDI& rhs)
0227 // {
0228 //   //An exception safe implementation is
0229 //   CmsShowEDI temp(rhs);
0230 //   swap(rhs);
0231 //
0232 //   return *this;
0233 // }
0234 
0235 //
0236 // member functions
0237 //
0238 
0239 void CmsShowEDI::clearPBFrame() {
0240   if (!m_settersFrame->GetList()->IsEmpty()) {
0241     // printf("remove FRAME \n");
0242     TGFrameElement* el = (TGFrameElement*)m_settersFrame->GetList()->First();
0243     TGFrame* f = el->fFrame;
0244     f->UnmapWindow();
0245     m_settersFrame->RemoveFrame(f);
0246     f->DestroyWindow();
0247   }
0248 }
0249 
0250 void CmsShowEDI::fillEDIFrame() {
0251   FWEventItem* iItem = nullptr;
0252   bool multipleCollections = false;
0253   if (!m_selectionManager->selectedItems().empty()) {
0254     if (m_selectionManager->selectedItems().size() == 1) {
0255       iItem = *(m_selectionManager->selectedItems().begin());
0256     } else {
0257       multipleCollections = true;
0258     }
0259   }
0260   //m_item can be zero because we had 0 or many collections selected
0261   if (nullptr == m_item || iItem != m_item) {
0262     disconnectAll();
0263     m_item = iItem;
0264     if (nullptr != m_item) {
0265       const FWDisplayProperties& p = iItem->defaultDisplayProperties();
0266       m_objectLabel->SetText(iItem->name().c_str());
0267       m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
0268       m_opacitySlider->SetPosition(100 - p.transparency());
0269       m_isVisibleButton->SetDisabledAndSelected(p.isVisible());
0270       m_validator->setType(edm::TypeWithDict(*(iItem->modelType()->GetTypeInfo())));
0271       m_filterExpressionEntry->SetText(iItem->filterExpression().c_str());
0272       m_filterError->Clear();
0273       m_selectError->Clear();
0274       m_nameEntry->SetText(iItem->name().c_str());
0275       m_typeEntry->SetText(iItem->type()->GetName());
0276       m_moduleEntry->SetText(iItem->moduleLabel().c_str());
0277       m_instanceEntry->SetText(iItem->productInstanceLabel().c_str());
0278       m_processEntry->SetText(iItem->processName().c_str());
0279       //  else m_isVisibleButton->SetState(kButtonDown, kFALSE);
0280       m_colorSelectWidget->SetEnabled(kTRUE);
0281       m_opacitySlider->SetEnabled(kTRUE);
0282       m_isVisibleButton->SetEnabled(kTRUE);
0283       m_filterExpressionEntry->SetEnabled(kTRUE);
0284       m_selectExpressionEntry->SetEnabled(kTRUE);
0285       m_filterButton->SetEnabled(kTRUE);
0286       m_selectButton->SetEnabled(kTRUE);
0287       m_selectAllButton->SetEnabled(kTRUE);
0288       m_deselectAllButton->SetEnabled(kTRUE);
0289       m_cw->SetColorByIndex(p.color(), kFALSE);
0290       m_cw->SetEnabled(kTRUE);
0291       m_removeButton->SetEnabled(kTRUE);
0292       updateLayerControls();
0293       m_layerEntry->SetState(kTRUE);
0294       m_displayChangedConn =
0295           m_item->defaultDisplayPropertiesChanged_.connect(std::bind(&CmsShowEDI::updateDisplay, this));
0296       m_modelChangedConn = m_item->changed_.connect(std::bind(&CmsShowEDI::updateFilter, this));
0297       //    m_selectionChangedConn = m_selectionManager->selectionChanged_.connect(boost::bind(&CmsShowEDI::updateSelection, this));
0298       m_destroyedConn = m_item->goingToBeDestroyed_.connect(std::bind(&CmsShowEDI::disconnectAll, this));
0299 
0300       clearPBFrame();
0301       m_item->getConfig()->populateFrame(m_settersFrame);
0302     } else if (multipleCollections) {
0303       std::ostringstream s;
0304       s << m_selectionManager->selectedItems().size() << " Collections Selected";
0305       m_objectLabel->SetText(s.str().c_str());
0306     }
0307 
0308     Resize(GetDefaultSize());
0309     Layout();
0310   }
0311 }
0312 
0313 void CmsShowEDI::removeItem() {
0314   Int_t chosen = 0;
0315   std::string message("This action will remove the ");
0316   message += m_item->name();
0317   message +=
0318       " collection from the display."
0319       "\nIf you wish to return the collection you would have to use the 'Add Collection' window.";
0320   new TGMsgBox(gClient->GetDefaultRoot(),
0321                this,
0322                "Remove Collection Confirmation",
0323                message.c_str(),
0324                kMBIconExclamation,
0325                kMBCancel | kMBApply,
0326                &chosen);
0327   if (kMBApply == chosen) {
0328     m_item->destroy();
0329     m_item = nullptr;
0330     //make sure the ROOT global editor does not try to use this
0331     gEve->EditElement(nullptr);
0332     gEve->Redraw3D();
0333   }
0334 }
0335 
0336 void CmsShowEDI::updateDisplay() {
0337   //std::cout<<"Updating display"<<std::endl;
0338   const FWDisplayProperties& props = m_item->defaultDisplayProperties();
0339   m_colorSelectWidget->SetColorByIndex(props.color(), kFALSE);
0340   m_opacitySlider->SetPosition(100 - props.transparency());
0341   m_isVisibleButton->SetState(props.isVisible() ? kButtonDown : kButtonUp, kFALSE);
0342 }
0343 
0344 void CmsShowEDI::updateLayerControls() {
0345   m_backButton->SetEnabled(!m_item->isInBack());
0346   m_frontButton->SetEnabled(!m_item->isInFront());
0347   m_layerEntry->SetIntNumber(m_item->layer());
0348 }
0349 void CmsShowEDI::moveToBack() {
0350   m_item->moveToBack();
0351   updateLayerControls();
0352 }
0353 void CmsShowEDI::moveToFront() {
0354   m_item->moveToFront();
0355   updateLayerControls();
0356 }
0357 void CmsShowEDI::moveToLayer(Long_t) {
0358   m_item->moveToLayer(static_cast<Int_t>(m_layerEntry->GetIntNumber()));
0359   updateLayerControls();
0360 }
0361 
0362 void CmsShowEDI::updateFilter() { m_filterExpressionEntry->SetText(m_item->filterExpression().c_str()); }
0363 
0364 void CmsShowEDI::disconnectAll() {
0365   m_objectLabel->SetText("No Collection Selected");
0366   clearPBFrame();
0367   if (nullptr != m_item) {
0368     m_displayChangedConn.disconnect();
0369     m_modelChangedConn.disconnect();
0370     m_destroyedConn.disconnect();
0371     m_item = nullptr;
0372     m_colorSelectWidget->SetColorByIndex(0, kFALSE);
0373     m_opacitySlider->SetPosition(100);
0374     m_isVisibleButton->SetDisabledAndSelected(kTRUE);
0375     m_filterExpressionEntry->SetText(nullptr);
0376     m_selectExpressionEntry->SetText(nullptr);
0377     m_nameEntry->SetText(nullptr);
0378     m_typeEntry->SetText(nullptr);
0379     m_moduleEntry->SetText(nullptr);
0380     m_instanceEntry->SetText(nullptr);
0381     m_processEntry->SetText(nullptr);
0382     //  else m_isVisibleButton->SetState(kButtonDown, kFALSE);
0383     m_colorSelectWidget->SetEnabled(kFALSE);
0384     m_opacitySlider->SetEnabled(kFALSE);
0385 
0386     m_isVisibleButton->SetEnabled(kFALSE);
0387     m_filterExpressionEntry->SetEnabled(kFALSE);
0388     m_filterButton->SetEnabled(kFALSE);
0389     m_selectExpressionEntry->SetEnabled(kFALSE);
0390     m_selectButton->SetEnabled(kFALSE);
0391     m_selectAllButton->SetEnabled(kFALSE);
0392     m_deselectAllButton->SetEnabled(kFALSE);
0393     m_removeButton->SetEnabled(kFALSE);
0394     m_backButton->SetEnabled(kFALSE);
0395     m_frontButton->SetEnabled(kFALSE);
0396     m_layerEntry->SetIntNumber(0);
0397     m_layerEntry->SetState(kFALSE);
0398     m_layerEntry->GetNumberEntry()->SetEnabled(kFALSE);
0399     m_layerEntry->GetButtonUp()->SetEnabled(kFALSE);
0400     m_layerEntry->GetButtonDown()->SetEnabled(kFALSE);
0401   }
0402 }
0403 
0404 /** Set the item color. 
0405     
0406     Notice that I changed this to use a "Copy and modify approach", rather
0407     than a "create with old properties" method which was not propagating 
0408     transparency.
0409   */
0410 void CmsShowEDI::changeItemColor(Color_t color) {
0411   FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
0412   changeProperties.setColor(color);
0413   m_item->setDefaultDisplayProperties(changeProperties);
0414   m_cw->SetColorByIndex(color, kFALSE);
0415 }
0416 
0417 /** See changeItemColor for additional details.*/
0418 void CmsShowEDI::toggleItemVisible(Bool_t on) {
0419   FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
0420   changeProperties.setIsVisible(on);
0421   m_item->setDefaultDisplayProperties(changeProperties);
0422 }
0423 
0424 /** Changes selected item opacity. Notice that we use opacity rather than
0425     transparency because this way the slider is by default 100% rather than 0.
0426     This is more a more natural and positive way of looking at things. 
0427     
0428     Glass is full! 
0429     
0430     See changeItemColor for additional details.*/
0431 void CmsShowEDI::changeItemOpacity(Int_t opacity) {
0432   FWDisplayProperties changeProperties = m_item->defaultDisplayProperties();
0433   changeProperties.setTransparency(100 - opacity);
0434   m_item->setDefaultDisplayProperties(changeProperties);
0435 }
0436 
0437 void CmsShowEDI::runFilter() {
0438   const std::string filter(m_filterExpressionEntry->GetText());
0439   if (m_item != nullptr) {
0440     try {
0441       m_filterError->Clear();
0442       m_item->setFilterExpression(filter);
0443     } catch (const FWExpressionException& e) {
0444       m_filterError->AddLine(e.what().c_str());
0445       m_filterError->Update();
0446       if (e.column() > -1) {
0447         m_filterExpressionEntry->SetCursorPosition(e.column());
0448       }
0449     }
0450   }
0451 }
0452 
0453 void CmsShowEDI::runSelection() {
0454   FWModelExpressionSelector selector;
0455   const std::string selection(m_selectExpressionEntry->GetText());
0456   if (m_item != nullptr) {
0457     try {
0458       m_selectError->Clear();
0459       //NOTE call clearModelSelectionLeaveItem so that the item does not get deselected
0460       // just for safety use a copy of the pointer to m_item
0461       FWEventItem* item = m_item;
0462       item->selectionManager()->clearModelSelectionLeaveItem();
0463 
0464       selector.select(item, selection, TColor::GetColor(m_cw->GetColor()));
0465     } catch (const FWExpressionException& e) {
0466       m_selectError->AddLine(e.what().c_str());
0467       m_selectError->Update();
0468       if (e.column() > -1) {
0469         m_selectExpressionEntry->SetCursorPosition(e.column());
0470       }
0471     }
0472   }
0473 }
0474 
0475 void CmsShowEDI::selectAll() {
0476   FWChangeSentry sentry(*(m_item->changeManager()));
0477   for (int i = 0; i < static_cast<int>(m_item->size()); i++) {
0478     m_item->select(i);
0479   }
0480 }
0481 void CmsShowEDI::deselectAll() {
0482   FWChangeSentry sentry(*(m_item->changeManager()));
0483   for (int i = 0; i < static_cast<int>(m_item->size()); i++) {
0484     m_item->unselect(i);
0485   }
0486 }
0487 
0488 void CmsShowEDI::changeSelectionColor(Color_t c) {
0489   FWChangeSentry sentry(*(m_item->changeManager()));
0490   const std::set<FWModelId>& ss = m_item->selectionManager()->selected();
0491   FWDisplayProperties dp = m_item->defaultDisplayProperties();
0492   dp.setColor(c);
0493   for (std::set<FWModelId>::const_iterator i = ss.begin(); i != ss.end(); ++i) {
0494     m_item->setDisplayProperties(i->index(), dp);
0495   }
0496 }
0497 
0498 void CmsShowEDI::show(FWDataCategories iToView) { m_tabs->SetTab(iToView); }
0499 
0500 /* Called by FWGUIManager when change background/colorset. */
0501 void CmsShowEDI::colorSetChanged() {
0502   if (m_item) {
0503     const FWDisplayProperties& p = m_item->defaultDisplayProperties();
0504     m_colorSelectWidget->SetColorByIndex(p.color(), kFALSE);
0505     m_cw->SetColorByIndex(p.color(), kFALSE);
0506   }
0507 }