CMS 3D CMS Logo

FWDigitSetProxyBuilder.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWDigitSetProxyBuilder
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Alja Mrak-Tadel
10 // Created: Tue Oct 19 12:00:50 CEST 2010
11 //
12 
13 // system include files
14 
15 // user include files
16 #include "TEveDigitSet.h"
17 #include "TEveBoxSet.h"
18 #include "TEveManager.h"
19 #include "TEveSelection.h"
20 
26 
28 public:
29  FWSecondarySelectableSelector(const TEveSecondarySelectable::SelectionSet_t& s, const FWEventItem* i)
30  : m_selected(s), m_item(i) {}
32 
33  void doSelect() override { syncSelection(); }
34 
35  void doUnselect() override { syncSelection(); }
36 
37  const FWEventItem* item() const { return m_item; }
38 
39 private:
40  const TEveSecondarySelectable::SelectionSet_t& m_selected;
42 
43  void syncSelection() {
44  size_t size = m_item->size();
45  for (size_t i = 0; i < size; ++i) {
47  TEveSecondarySelectable::SelectionSet_ci si = m_selected.find(i);
48  if ((si != m_selected.end()) != modelInfo.isSelected()) {
49  if (si != m_selected.end())
50  m_item->select(i);
51  else
52  m_item->unselect(i);
53  }
54  }
55  }
56 };
57 
58 //==============================================================================
59 //==============================================================================
60 //==============================================================================
61 
63 
65 
66 TString FWDigitSetProxyBuilder::getTooltip(TEveDigitSet* set, int idx) {
67  TEveElement* el = static_cast<TEveElement*>(set); // tmp-workaround
68  FWSecondarySelectableSelector* ss = static_cast<FWSecondarySelectableSelector*>(el->GetUserData());
69  return TString::Format(
70  "%d %s %s", idx, ss->item()->name().c_str(), ss->item()->modelInterestingValueAsString(idx).c_str());
71 }
72 
73 TEveBoxSet* FWDigitSetProxyBuilder::addBoxSetToProduct(TEveElementList* product) {
74  assert(!product->HasChildren());
75 
76  m_boxSet = new TEveBoxSet();
77  m_boxSet->SetTooltipCBFoo(getTooltip);
78  m_boxSet->Reset(TEveBoxSet::kBT_FreeBox, true, 256);
80  m_boxSet->SetUserData(sel);
81  m_boxSet->SetPickable(true);
82  m_boxSet->SetAlwaysSecSelect(true);
83 
84  product->AddElement(m_boxSet);
85 
86  return m_boxSet;
87 }
88 
89 TEveDigitSet* FWDigitSetProxyBuilder::digitSet(TEveElement* product) {
90  assert(product->NumChildren() == 1);
91  return static_cast<TEveDigitSet*>(*product->BeginChildren());
92 }
93 
94 void FWDigitSetProxyBuilder::addBox(TEveBoxSet* boxSet, const float* pnts, const FWDisplayProperties& dp) {
95  boxSet->AddBox(pnts);
96  boxSet->DigitValue(dp.isVisible());
97 
98  if (dp.isVisible())
99  boxSet->DigitColor(dp.color(), dp.transparency());
100 
101  if (dp.transparency())
102  boxSet->SetMainTransparency(dp.transparency());
103 }
104 
106  TEveDigitSet* digits = digitSet(product->m_elements);
107  if (!digits)
108  return;
109 
110  TEveSecondarySelectable::SelectionSet_t& selected =
111  (TEveSecondarySelectable::SelectionSet_t&)(digits->RefSelectedSet());
112 
113  for (std::set<FWModelId>::const_iterator it = iIds.begin(); it != iIds.end(); ++it) {
114  const FWEventItem::ModelInfo& info = item()->modelInfo(it->index());
115 
116  // id display properties
117  const FWDisplayProperties& p = info.displayProperties();
118  digits->SetCurrentDigit(it->index());
119  digits->DigitValue(p.isVisible());
120  if (p.isVisible())
121  digits->DigitColor(p.color(), p.transparency());
122 
123  // id selection
124  TEveSecondarySelectable::SelectionSet_ci si = selected.find(it->index());
125  if (info.isSelected()) {
126  if (si == selected.end())
127  selected.insert(it->index());
128  } else {
129  if (si != selected.end())
130  selected.erase(si);
131  }
132  }
133 
134  if (!selected.empty()) {
135  if (0 == digits->GetSelectedLevel()) {
136  gEve->GetSelection()->AddElement(digits);
137  }
138  } else {
139  if (1 == digits->GetSelectedLevel() || 2 == digits->GetSelectedLevel()) {
140  gEve->GetSelection()->RemoveElement(digits);
141  }
142  }
143 
144  digits->StampObjProps();
145 }
size
Write out results.
size_t size() const
Definition: FWEventItem.cc:457
static const TGPicture * info(bool iBackgroundIsBlack)
FWSecondarySelectableSelector(const TEveSecondarySelectable::SelectionSet_t &s, const FWEventItem *i)
assert(be >=bs)
void select(int iIndex) const
Definition: FWEventItem.cc:224
static TString getTooltip(TEveDigitSet *set, int idx)
bool isSelected() const
Definition: FWEventItem.h:65
void unselect(int iIndex) const
Definition: FWEventItem.cc:215
void modelChanges(const FWModelIds &, Product *) override
std::set< FWModelId > FWModelIds
const TEveSecondarySelectable::SelectionSet_t & m_selected
TEveBoxSet * addBoxSetToProduct(TEveElementList *product)
const FWEventItem * item() const
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
void addBox(TEveBoxSet *set, const float *pnts, const FWDisplayProperties &dp)
TEveDigitSet * digitSet(TEveElement *product)
const FWEventItem * item() const