CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: FWDigitSetProxyBuilder.cc,v 1.4 2012/06/18 23:56:21 amraktad Exp $
12 //
13 
14 // system include files
15 
16 // user include files
17 #include "TEveDigitSet.h"
18 #include "TEveBoxSet.h"
19 #include "TEveManager.h"
20 #include "TEveSelection.h"
21 
27 
28 
30 {
31 public:
32  FWSecondarySelectableSelector(const TEveSecondarySelectable::SelectionSet_t& s, const FWEventItem* i): m_selected(s), m_item(i) {}
34 
35  virtual void doSelect()
36  {
37  syncSelection();
38  }
39 
40  virtual void doUnselect()
41  {
42  syncSelection();
43  }
44 
45  const FWEventItem* item() const { return m_item; }
46 
47 private:
48  const TEveSecondarySelectable::SelectionSet_t& m_selected;
50 
52  {
53  size_t size = m_item->size();
54  for (size_t i = 0; i < size; ++i)
55  {
57  TEveSecondarySelectable::SelectionSet_ci si = m_selected.find(i);
58  if ((si != m_selected.end()) != modelInfo.isSelected() )
59  {
60  if (si != m_selected.end())
61  m_item->select(i);
62  else
63  m_item->unselect(i);
64  }
65  }
66  }
67 };
68 
69 //==============================================================================
70 //==============================================================================
71 //==============================================================================
72 
74 {
75 }
76 
78 {
79 }
80 
81 TString FWDigitSetProxyBuilder::getTooltip(TEveDigitSet* set, int idx)
82 {
83  TEveElement* el = static_cast<TEveElement*>(set); // tmp-workaround
84  FWSecondarySelectableSelector* ss = static_cast<FWSecondarySelectableSelector*>(el->GetUserData());
85  return TString::Format("%d %s %s", idx, ss->item()->name().c_str(), ss->item()->modelInterestingValueAsString(idx).c_str());
86 }
87 
88 TEveBoxSet* FWDigitSetProxyBuilder::addBoxSetToProduct(TEveElementList* product)
89 {
90  assert(!product->HasChildren());
91 
92  TEveBoxSet* boxSet = new TEveBoxSet();
93  boxSet->SetTooltipCBFoo(getTooltip);
94  boxSet->Reset(TEveBoxSet::kBT_FreeBox, true, 256);
95  FWSecondarySelectableSelector* sel = new FWSecondarySelectableSelector(boxSet->RefSelectedSet(), item());
96  boxSet->SetUserData(sel);
97  boxSet->SetPickable(1);
98  boxSet->SetAlwaysSecSelect(1);
99 
100  product->AddElement(boxSet);
101 
102  return boxSet;
103 }
104 
105 TEveDigitSet* FWDigitSetProxyBuilder::digitSet(TEveElement* product)
106 {
107  assert(product->NumChildren() == 1);
108  return static_cast<TEveDigitSet*>(*product->BeginChildren());
109 }
110 
111 void FWDigitSetProxyBuilder::addBox(TEveBoxSet* boxSet, const float* pnts, const FWDisplayProperties& dp)
112 {
113  boxSet->AddBox(pnts);
114  boxSet->DigitValue(dp.isVisible());
115 
116  if (dp.isVisible())
117  boxSet->DigitColor(dp.color(), dp.transparency());
118 
119  if (dp.transparency())
120  boxSet->SetMainTransparency(dp.transparency());
121 }
122 
124 {
125  TEveDigitSet* digits = digitSet(product->m_elements);
126  if (!digits) return;
127 
128  TEveSecondarySelectable::SelectionSet_t& selected = (TEveSecondarySelectable::SelectionSet_t&)(digits->RefSelectedSet());
129 
130  for (std::set<FWModelId>::const_iterator it = iIds.begin(); it != iIds.end(); ++it)
131  {
132  const FWEventItem::ModelInfo& info = item()->modelInfo(it->index());
133 
134  // id display properties
135  const FWDisplayProperties &p = info.displayProperties();
136  digits->SetCurrentDigit(it->index());
137  digits->DigitValue(p.isVisible());
138  if (p.isVisible())
139  digits->DigitColor(p.color(), p.transparency());
140 
141  // id selection
142  TEveSecondarySelectable::SelectionSet_ci si = selected.find(it->index());
143  if (info.isSelected())
144  {
145  if (si == selected.end())
146  selected.insert(it->index());
147  }
148  else
149  {
150  if ( si != selected.end())
151  selected.erase(si);
152  }
153  }
154 
155  if(!selected.empty()) {
156  if(0==digits->GetSelectedLevel()) {
157  gEve->GetSelection()->AddElement(digits);
158  }
159  } else {
160  if(1==digits->GetSelectedLevel()||2==digits->GetSelectedLevel()) {
161  gEve->GetSelection()->RemoveElement(digits);
162  }
163  }
164 
165  digits->StampObjProps();
166 }
int i
Definition: DBlmapReader.cc:9
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:68
FWSecondarySelectableSelector(const TEveSecondarySelectable::SelectionSet_t &s, const FWEventItem *i)
const std::string & name() const
Definition: FWEventItem.cc:501
bool isSelected() const
Definition: FWEventItem.h:71
void unselect(int iIndex) const
Definition: FWEventItem.cc:240
const FWEventItem * item() const
Color_t color() const
static TString getTooltip(TEveDigitSet *set, int idx)
Char_t transparency() const
virtual void modelChanges(const FWModelIds &, Product *)
std::set< FWModelId > FWModelIds
const std::string & modelInterestingValueAsString(int iIndex) const
Definition: FWEventItem.cc:595
const FWEventItem * item() const
size_t size() const
Definition: FWEventItem.cc:549
const TEveSecondarySelectable::SelectionSet_t & m_selected
auto dp
Definition: deltaR.h:24
tuple idx
DEBUGGING if hasattr(process,&quot;trackMonIterativeTracking2012&quot;): print &quot;trackMonIterativeTracking2012 D...
TEveBoxSet * addBoxSetToProduct(TEveElementList *product)
void select(int iIndex) const
Definition: FWEventItem.cc:251
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:536
void addBox(TEveBoxSet *set, const float *pnts, const FWDisplayProperties &dp)
TEveDigitSet * digitSet(TEveElement *product)
tuple size
Write out results.