Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-02-14 13:27:10

0001 // -*- C++ -*-
0002 //
0003 // Package:     Core
0004 // Class  :     FWDigitSetProxyBuilder
0005 //
0006 // Implementation:
0007 //     [Notes on implementation]
0008 //
0009 // Original Author:  Alja Mrak-Tadel
0010 //         Created:  Tue Oct 19 12:00:50 CEST 2010
0011 //
0012 
0013 // system include files
0014 
0015 // user include files
0016 #include "TEveDigitSet.h"
0017 #include "TEveBoxSet.h"
0018 #include "TEveManager.h"
0019 #include "TEveSelection.h"
0020 
0021 #include "Fireworks/Core/interface/FWDigitSetProxyBuilder.h"
0022 #include "Fireworks/Core/interface/FWFromEveSelectorBase.h"
0023 #include "Fireworks/Core/interface/FWDisplayProperties.h"
0024 #include "Fireworks/Core/interface/FWModelId.h"
0025 #include "Fireworks/Core/interface/FWEventItem.h"
0026 
0027 class FWSecondarySelectableSelector : public FWFromEveSelectorBase {
0028 public:
0029   FWSecondarySelectableSelector(const TEveSecondarySelectable::SelectionSet_t& s, const FWEventItem* i)
0030       : m_selected(s), m_item(i) {}
0031   ~FWSecondarySelectableSelector() override {}
0032 
0033   void doSelect() override { syncSelection(); }
0034 
0035   void doUnselect() override { syncSelection(); }
0036 
0037   const FWEventItem* item() const { return m_item; }
0038 
0039 private:
0040   const TEveSecondarySelectable::SelectionSet_t& m_selected;
0041   const FWEventItem* m_item;
0042 
0043   void syncSelection() {
0044     size_t size = m_item->size();
0045     for (size_t i = 0; i < size; ++i) {
0046       FWEventItem::ModelInfo modelInfo = m_item->modelInfo(i);
0047       TEveSecondarySelectable::SelectionSet_ci si = m_selected.find(i);
0048       if ((si != m_selected.end()) != modelInfo.isSelected()) {
0049         if (si != m_selected.end())
0050           m_item->select(i);
0051         else
0052           m_item->unselect(i);
0053       }
0054     }
0055   }
0056 };
0057 
0058 //==============================================================================
0059 //==============================================================================
0060 //==============================================================================
0061 
0062 FWDigitSetProxyBuilder::FWDigitSetProxyBuilder() : m_boxSet(nullptr) {}
0063 
0064 FWDigitSetProxyBuilder::~FWDigitSetProxyBuilder() {}
0065 
0066 TString FWDigitSetProxyBuilder::getTooltip(TEveDigitSet* set, int idx) {
0067   TEveElement* el = static_cast<TEveElement*>(set);  // tmp-workaround
0068   FWSecondarySelectableSelector* ss = static_cast<FWSecondarySelectableSelector*>(el->GetUserData());
0069   return TString::Format(
0070       "%d %s %s", idx, ss->item()->name().c_str(), ss->item()->modelInterestingValueAsString(idx).c_str());
0071 }
0072 
0073 TEveBoxSet* FWDigitSetProxyBuilder::addBoxSetToProduct(TEveElementList* product) {
0074   assert(!product->HasChildren());
0075 
0076   m_boxSet = new TEveBoxSet();
0077   m_boxSet->SetTooltipCBFoo(getTooltip);
0078   m_boxSet->Reset(TEveBoxSet::kBT_FreeBox, true, 256);
0079   FWSecondarySelectableSelector* sel = new FWSecondarySelectableSelector(m_boxSet->RefSelectedSet(), item());
0080   m_boxSet->SetUserData(sel);
0081   m_boxSet->SetPickable(true);
0082   m_boxSet->SetAlwaysSecSelect(true);
0083 
0084   product->AddElement(m_boxSet);
0085 
0086   return m_boxSet;
0087 }
0088 
0089 TEveDigitSet* FWDigitSetProxyBuilder::digitSet(TEveElement* product) {
0090   assert(product->NumChildren() == 1);
0091   return static_cast<TEveDigitSet*>(*product->BeginChildren());
0092 }
0093 
0094 void FWDigitSetProxyBuilder::addBox(TEveBoxSet* boxSet, const float* pnts, const FWDisplayProperties& dp) {
0095   boxSet->AddBox(pnts);
0096   boxSet->DigitValue(dp.isVisible());
0097 
0098   if (dp.isVisible())
0099     boxSet->DigitColor(dp.color(), dp.transparency());
0100 
0101   if (dp.transparency())
0102     boxSet->SetMainTransparency(dp.transparency());
0103 }
0104 
0105 void FWDigitSetProxyBuilder::modelChanges(const FWModelIds& iIds, Product* product) {
0106   TEveDigitSet* digits = digitSet(product->m_elements);
0107   if (!digits)
0108     return;
0109 
0110   TEveSecondarySelectable::SelectionSet_t& selected =
0111       (TEveSecondarySelectable::SelectionSet_t&)(digits->RefSelectedSet());
0112 
0113   for (std::set<FWModelId>::const_iterator it = iIds.begin(); it != iIds.end(); ++it) {
0114     const FWEventItem::ModelInfo& info = item()->modelInfo(it->index());
0115 
0116     // id display properties
0117     const FWDisplayProperties& p = info.displayProperties();
0118     digits->SetCurrentDigit(it->index());
0119     digits->DigitValue(p.isVisible());
0120     if (p.isVisible())
0121       digits->DigitColor(p.color(), p.transparency());
0122 
0123     // id selection
0124     TEveSecondarySelectable::SelectionSet_ci si = selected.find(it->index());
0125     if (info.isSelected()) {
0126       if (si == selected.end())
0127         selected.insert(it->index());
0128     } else {
0129       if (si != selected.end())
0130         selected.erase(si);
0131     }
0132   }
0133 
0134   if (!selected.empty()) {
0135     if (0 == digits->GetSelectedLevel()) {
0136       gEve->GetSelection()->AddElement(digits);
0137     }
0138   } else {
0139     if (1 == digits->GetSelectedLevel() || 2 == digits->GetSelectedLevel()) {
0140       gEve->GetSelection()->RemoveElement(digits);
0141     }
0142   }
0143 
0144   digits->StampObjProps();
0145 }