Logo ROOT  
Reference Guide
REveDataProxyBuilderBase.cxx
Go to the documentation of this file.
1 // @(#)root/eve7:$Id$
2 // Authors: Matevz Tadel & Alja Mrak-Tadel, 2018
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2019, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 
15 #include <ROOT/REveViewContext.hxx>
16 #include <ROOT/REveCompound.hxx>
17 
18 #include <cassert>
19 
20 
21 using namespace ROOT::Experimental;
22 namespace REX = ROOT::Experimental;
23 
24 
25 REveDataProxyBuilderBase::Product::Product(std::string iViewType, const REveViewContext* c) : m_viewType(iViewType), m_viewContext(c), m_elements(0)
26 {
27  m_elements = new REveCompound("ProxyProduct", "", false);
29 }
30 
31 //______________________________________________________________________________
32 
33 
35  m_type(type),
36  m_collection(nullptr),
37  // m_interactionList(0),
38  m_haveWindow(false)
39 {
40 }
41 
43 {
44  // remove product from projected scene (RhoPhi or RhoZ)
45  for (auto i : m_elements->RefProjecteds())
46  {
47  REveElement *projected = i->GetProjectedAsElement();
48  projected->GetMother()->RemoveElement(projected);
49  }
50 
51  // XXXX This might break now ... m_elements will auto drestruct, no?
52  // We don't set incdenydestroy or additional something, do we?
53 
54  // remove from 3D scenes
55  if (m_elements->HasMother())
56  {
58  }
59 
61 }
62 
63 //------------------------------------------------------------------------------
64 
66 {
67  m_collection = c;
68 }
69 
70 //------------------------------------------------------------------------------
71 
72 /*
73 void
74 REveDataProxyBuilderBase::SetInteractionList(REveDataInteractionList* l, const std::string& purpose )
75 {
76  // Called if willHandleInteraction() returns false. Purpose ignored by default.
77 
78  m_interactionList = l;
79 }
80 */
81 
82 //------------------------------------------------------------------------------
83 
85 {
86  if (m_collection)
87  {
88  // printf("Base %p %s %s\n", m_collection, m_collection->GetCName(), m_type.c_str());
89  try
90  {
91  auto itemSize = m_collection->GetNItems(); //cashed
92 
93  Clean();
94  for (auto &pp: m_products)
95  {
96  // printf("build() %s \n", m_collection->GetCName());
97  REveElement* elms = pp->m_elements;
98  auto oldSize = elms->NumChildren();
99 
100  if (HaveSingleProduct())
101  {
102  Build(m_collection, elms, pp->m_viewContext);
103  }
104  else
105  {
106  BuildViewType(m_collection, elms, pp->m_viewType, pp->m_viewContext);
107  }
108 
109  // Project all children of current product.
110  // If product is not registered into any projection-manager,
111  // this does nothing.
112  REveProjectable* pable = dynamic_cast<REveProjectable*>(elms);
113  if (pable->HasProjecteds())
114  {
115  // loop projected holders
116  for (auto &prj: pable->RefProjecteds())
117  {
118  REveProjectionManager *pmgr = prj->GetManager();
119  Float_t oldDepth = pmgr->GetCurrentDepth();
120  pmgr->SetCurrentDepth(m_layer);
121  Int_t cnt = 0;
122 
123  REveElement *projectedAsElement = prj->GetProjectedAsElement();
124  auto parentIt = projectedAsElement->RefChildren().begin();
125  for (auto &prod: elms->RefChildren())
126  {
127  // reused projected holder
128  if (cnt < oldSize)
129  {
130  /*
131  // AMT no use case for this at the moment
132  if ((*parentIt)->NumChildren()) {
133  // update projected (mislleading name)
134  for ( REveElement::List_i pci = (*parentIt)->BeginChildren(); pci != (*parentIt)->EndChildren(); pci++)
135  pmgr->ProjectChildrenRecurse(*pci);
136  }
137  */
138  // import projectable
139  pmgr->SubImportChildren(prod, *parentIt);
140 
141  ++parentIt;
142  }
143  else if (cnt < itemSize)
144  {
145  // new product holder
146  pmgr->SubImportElements(prod, projectedAsElement);
147  }
148  else
149  {
150  break;
151  }
152  ++cnt;
153  }
154  pmgr->SetCurrentDepth(oldDepth);
155  }
156  }
157 
158  /*
159  if (m_interactionList && itemSize > oldSize)
160  {
161  auto elIt = elms->RefChildren().begin();
162  for (size_t cnt = 0; cnt < itemSize; ++cnt, ++elIt)
163  {
164  if (cnt >= oldSize )
165  m_interactionList->Added(*elIt, cnt);
166  }
167  }
168  */
169  }
170  }
171  catch (const std::runtime_error& iException)
172  {
173  std::cout << "Caught exception in build function for item " << m_collection->GetName() << ":\n"
174  << iException.what() << std::endl;
175  exit(1);
176  }
177  }
178 }
179 
180 //------------------------------------------------------------------------------
181 
182 void
184 {
185  assert("virtual Build(const REveEventItem*, REveElement*, const REveViewContext*) not implemented by inherited class");
186 }
187 
188 
189 void
191 {
192  assert("virtual BuildViewType(const FWEventItem*, TEveElementList*, FWViewType::EType, const FWViewContext*) not implemented by inherited class");
193 }
194 
195 //------------------------------------------------------------------------------
196 
198 REveDataProxyBuilderBase::CreateProduct( std::string viewType, const REveViewContext* viewContext)
199 {
200  if ( m_products.empty() == false)
201  {
202  if (HaveSingleProduct()) {
203  return m_products.back()->m_elements;
204  }
205  else {
206 
207  for (auto &prod: m_products)
208  {
209  if (viewType == prod->m_viewType)
210  return prod->m_elements;
211  }
212  }
213  }
214 
215  auto product = new Product(viewType, viewContext);
216  m_products.push_back(product);
217 
218  if (m_collection)
219  {
220  // debug info in eve browser
221  product->m_elements->SetName(Form("product %s", m_collection->GetCName()));
222  }
223  return product->m_elements;
224 }
225 
226 //------------------------------------------------------------------------------
227 
228 namespace
229 {
230  void applyColorAttrToChildren(REveElement* p) {
231  for (auto &it: p->RefChildren())
232  {
233  REveElement* c = it;
234  if (c->GetMainColor() != p->GetMainColor())
235  {
236  c->SetMainColor(p->GetMainColor());
237  // printf("apply color %d to %s\n", p->GetMainColor(), c->GetCName());
238  }
239  applyColorAttrToChildren(c);
240  }
241  }
242 }
243 
244 void
246 {
247  printf("REveDataProxyBuilderBase::ModelChanges %s \n", m_collection->GetCName());
248  REveElement* elms = p->m_elements;
249  assert(m_collection && static_cast<int>(m_collection->GetNItems()) <= elms->NumChildren() && "can not use default modelChanges implementation");
250 
251  for (auto itemIdx: iIds)
252  {
253  REveDataItem *item = m_collection->GetDataItem(itemIdx);
254 
255  // printf("Edit compound for item index %d \n", itemIdx);
256  // imitate FWInteractionList::modelChanges
257  auto itElement = elms->RefChildren().begin();
258  std::advance(itElement, itemIdx);
259  REveElement* comp = *itElement;
260  bool visible = (!item->GetFiltered()) && item->GetRnrSelf();
261  comp->SetRnrSelf(visible);
262  comp->SetRnrChildren(visible);
263 
264  if (item->GetMainColor() != comp->GetMainColor()) comp->SetMainColor(item->GetMainColor());
265  applyColorAttrToChildren(comp);
266 
267  if (VisibilityModelChanges(itemIdx, comp, p->m_viewContext))
268  {
269  elms->ProjectChild(comp);
270  printf("---REveDataProxyBuilderBase project child\n");
271  }
272  else
273  {
274  LocalModelChanges(itemIdx, comp, p->m_viewContext);
275  }
276  }
277 }
278 
279 void
281 {
282  // Nothing to be done in base class.
283  // Visibility, main color and main transparency are handled automatically throught compound.
284 }
285 
286 //------------------------------------------------------------------------------
287 
288 void
290 {
291  if(m_haveWindow) {
292  for (auto &prod: m_products)
293  {
294  ModelChanges(iIds, prod);
295  }
296  m_modelsChanged = false;
297  } else {
298  m_modelsChanged = true;
299  }
300 }
301 
302 //______________________________________________________________________________
303 void
305 {
306  if(m_haveWindow) {
307  Build();
308  }
309 }
310 
311 //------------------------------------------------------------------------------
312 
313 void
315 {
316  SetupElement(el, color);
317  // AMT -- this temprary to get right tooltip
318  el->SetName(parent->GetName());
319  parent->AddElement(el);
320 }
321 
322 /** This method is invoked to setup the per element properties of the various
323  objects being drawn.
324  */
325 void
327 {
328  el->CSCTakeMotherAsMaster();
329  el->SetPickable(true);
330 
331  if (color)
332  {
337  }
338 }
339 
340 
341 
343 REveDataProxyBuilderBase::CreateCompound(bool set_color, bool propagate_color_to_all_children) const
344 {
345  REveCompound *c = new REveCompound();
346  c->CSCImplySelectAllChildren();
347  c->SetPickable(true);
348  if (set_color)
349  {
350  c->SetMainColor(m_collection->GetMainColor());
351  c->SetMainTransparency(m_collection->GetMainTransparency());
352  }
353  if (propagate_color_to_all_children)
354  {
355  c->CSCApplyMainColorToAllChildren();
356  c->CSCApplyMainTransparencyToAllChildren();
357  }
358  else
359  {
360  c->CSCApplyMainColorToMatchingChildren();
361  c->CSCApplyMainTransparencyToMatchingChildren();
362  }
363  return c;
364 }
365 
366 //------------------------------------------------------------------------------
367 
369 {
370  // Cleans local common element list.
371  for (auto &prod: m_products)
372  {
373  if (prod->m_elements)
374  prod->m_elements->DestroyElements();
375  }
376 
377  CleanLocal();
378 }
379 
381 {
382  // Cleans local common element list.
383 }
384 
386 {
387  m_collection = nullptr;
388 
389  CleanLocal();
390 
391  for (auto &prod: m_products)
392  {
393 
394  // (*i)->m_scaleConnection.disconnect();
395  delete prod;
396  }
397 
398  m_products.clear();
399 }
400 
402 {
403  return false;
404 }
405 
407 {
408  m_haveWindow = iHaveAWindow;
409 }
ROOT::Experimental::REveViewContext
Definition: REveViewContext.hxx:33
c
#define c(i)
Definition: RSha256.hxx:119
ROOT::Experimental::REveDataItem::GetFiltered
Bool_t GetFiltered() const
Definition: REveDataClasses.hxx:106
ROOT::Experimental::REveDataProxyBuilderBase::ModelChanges
void ModelChanges(const REveDataCollection::Ids_t &)
Definition: REveDataProxyBuilderBase.cxx:289
ROOT::Experimental::REveDataCollection
Definition: REveDataClasses.hxx:31
ROOT::Experimental::REveDataCollection::Ids_t
std::vector< int > Ids_t
Definition: REveDataClasses.hxx:34
REveDataProxyBuilderBase.hxx
ROOT::Experimental::REveDataProxyBuilderBase::Product::Product
Product(std::string viewType, const REveViewContext *c)
Definition: REveDataProxyBuilderBase.cxx:25
ROOT::Experimental::REveProjectionManager::SubImportElements
virtual REveElement * SubImportElements(REveElement *el, REveElement *proj_parent)
Recursively import elements and apply projection to the newly imported objects.
Definition: REveProjectionManager.cxx:283
ROOT::Experimental::REveDataCollection::GetDataItem
REveDataItem * GetDataItem(Int_t i) const
Definition: REveDataClasses.hxx:77
ROOT::Experimental::REveElement::SetRnrChildren
virtual Bool_t SetRnrChildren(Bool_t rnr)
Set render state of this element's children, i.e.
Definition: REveElement.cxx:589
ROOT::Experimental::REveElement::ProjectChild
virtual void ProjectChild(REveElement *el, Bool_t same_depth=kTRUE)
If this is a projectable, loop over all projected replicas and add the projected image of child 'el' ...
Definition: REveElement.cxx:968
ROOT::Experimental::REveDataProxyBuilderBase::VisibilityModelChanges
virtual bool VisibilityModelChanges(int idx, REveElement *, const REveViewContext *)
Definition: REveDataProxyBuilderBase.cxx:401
ROOT::Experimental::REveDataProxyBuilderBase::Product::m_elements
REveCompound * m_elements
Definition: REveDataProxyBuilderBase.hxx:44
ROOT::Experimental::REveElement::SetRnrSelf
virtual Bool_t SetRnrSelf(Bool_t rnr)
Set render state of this element, i.e.
Definition: REveElement.cxx:566
Form
char * Form(const char *fmt,...)
ROOT::Experimental::REveDataProxyBuilderBase::m_modelsChanged
bool m_modelsChanged
Definition: REveDataProxyBuilderBase.hxx:110
ROOT::Experimental::REveDataProxyBuilderBase::Product::~Product
virtual ~Product()
Definition: REveDataProxyBuilderBase.cxx:42
ROOT::Experimental::REveDataProxyBuilderBase::m_layer
float m_layer
Definition: REveDataProxyBuilderBase.hxx:107
ROOT::Experimental::REveElement::NumChildren
Int_t NumChildren() const
Definition: REveElement.hxx:203
ROOT::Experimental::REveDataProxyBuilderBase::LocalModelChanges
virtual void LocalModelChanges(int idx, REveElement *el, const REveViewContext *ctx)
Definition: REveDataProxyBuilderBase.cxx:280
ROOT::Experimental::REveDataProxyBuilderBase::CollectionBeingDestroyed
virtual void CollectionBeingDestroyed(const REveDataCollection *)
Definition: REveDataProxyBuilderBase.cxx:385
ROOT::Experimental::REveDataProxyBuilderBase::HaveSingleProduct
virtual bool HaveSingleProduct() const
Definition: REveDataProxyBuilderBase.hxx:83
ROOT::Experimental::REveElement::CSCApplyMainColorToMatchingChildren
void CSCApplyMainColorToMatchingChildren()
Definition: REveElement.hxx:351
ROOT::Experimental::REveDataProxyBuilderBase::m_haveWindow
bool m_haveWindow
Definition: REveDataProxyBuilderBase.hxx:109
ROOT::Experimental::REveElement::GetMainTransparency
virtual Char_t GetMainTransparency() const
Definition: REveElement.hxx:277
ROOT::Experimental::REveDataProxyBuilderBase::REveDataProxyBuilderBase
REveDataProxyBuilderBase(const std::string &type)
Definition: REveDataProxyBuilderBase.cxx:34
ROOT::Experimental::REveElement
Definition: REveElement.hxx:79
ROOT::Experimental::REveElement::GetMainColor
virtual Color_t GetMainColor() const
Definition: REveElement.hxx:268
ROOT::Experimental::REveDataProxyBuilderBase::Product::m_viewContext
const REveViewContext * m_viewContext
Definition: REveDataProxyBuilderBase.hxx:43
ROOT::Experimental::REveDataProxyBuilderBase::CreateProduct
REveElement * CreateProduct(std::string viewType, const REveViewContext *)
Definition: REveDataProxyBuilderBase.cxx:198
ROOT::Experimental::REveElement::Annihilate
virtual void Annihilate()
Optimized destruction without check of reference-count.
Definition: REveElement.cxx:1178
ROOT::Experimental::REveDataProxyBuilderBase::Product
Definition: REveDataProxyBuilderBase.hxx:40
ROOT::Experimental::REveDataProxyBuilderBase::m_collection
const REveDataCollection * m_collection
Definition: REveDataProxyBuilderBase.hxx:105
ROOT::Experimental::REveDataProxyBuilderBase::SetHaveAWindow
void SetHaveAWindow(bool)
Definition: REveDataProxyBuilderBase.cxx:406
ROOT::Experimental::REveDataProxyBuilderBase::Clean
virtual void Clean()
Definition: REveDataProxyBuilderBase.cxx:368
ROOT::Experimental::REveElement::GetCName
const char * GetCName() const
Definition: REveElement.hxx:153
ROOT::Experimental::REveDataProxyBuilderBase::Build
void Build()
Definition: REveDataProxyBuilderBase.cxx:84
ROOT::Experimental::REveElement::CSCTakeMotherAsMaster
void CSCTakeMotherAsMaster()
Definition: REveElement.hxx:349
ROOT::Experimental::REveDataProxyBuilderBase::BuildViewType
virtual void BuildViewType(const REveDataCollection *iItem, REveElement *product, std::string viewType, const REveViewContext *)
Definition: REveDataProxyBuilderBase.cxx:190
ROOT::Experimental::REveProjectable
Definition: REveProjectionBases.hxx:37
REveCompound.hxx
ROOT::Experimental::REveElement::GetRnrSelf
virtual Bool_t GetRnrSelf() const
Definition: REveElement.hxx:250
ROOT::Experimental::REveDataProxyBuilderBase::SetupElement
void SetupElement(REveElement *el, bool color=true) const
This method is invoked to setup the per element properties of the various objects being drawn.
Definition: REveDataProxyBuilderBase.cxx:326
ROOT::Experimental::REveElement::RefChildren
List_t & RefChildren()
Definition: REveElement.hxx:201
ROOT::Experimental::REveElement::HasMother
bool HasMother()
Definition: REveElement.hxx:184
ROOT::Experimental::REveDataProxyBuilderBase::m_products
std::vector< Product * > m_products
Definition: REveDataProxyBuilderBase.hxx:101
REveProjectionManager.hxx
ROOT::Experimental::REveProjectionManager::GetCurrentDepth
Float_t GetCurrentDepth() const
Definition: REveProjectionManager.hxx:83
ROOT::Experimental::REveDataProxyBuilderBase::m_type
std::string m_type
Definition: REveDataProxyBuilderBase.hxx:104
ROOT::Experimental::REveElement::RemoveElement
virtual void RemoveElement(REveElement *el)
Remove el from the list of children.
Definition: REveElement.cxx:875
ROOT::Experimental::REveElement::SetName
void SetName(const std::string &name)
Set name of an element.
Definition: REveElement.cxx:211
ROOT::Experimental::REveElement::AddElement
virtual void AddElement(REveElement *el)
Add el to the list of children.
Definition: REveElement.cxx:842
Product
static Double_t Product(const Double_t *x, const Float_t *y)
Product.
Definition: TCTUB.cxx:101
ROOT::Experimental::REveElement::SetPickable
void SetPickable(Bool_t p)
Definition: REveElement.hxx:329
REveViewContext.hxx
ROOT::Experimental::REveElement::GetName
const std::string & GetName() const
Definition: REveElement.hxx:152
ROOT::Experimental::REveDataCollection::GetNItems
Int_t GetNItems() const
Definition: REveDataClasses.hxx:75
ROOT::Experimental::REveDataProxyBuilderBase::SetupAddElement
void SetupAddElement(REveElement *el, REveElement *parent, bool set_color=true) const
Definition: REveDataProxyBuilderBase.cxx:314
ROOT::Experimental::REveProjectable::RefProjecteds
ProjList_t & RefProjecteds()
Definition: REveProjectionBases.hxx:57
ROOT::Experimental::REveElement::IncDenyDestroy
void IncDenyDestroy()
Increases the deny-destroy count of the element.
Definition: REveElement.cxx:1313
ROOT::Experimental::REveProjectable::HasProjecteds
virtual Bool_t HasProjecteds() const
Definition: REveProjectionBases.hxx:55
ROOT::Experimental::REveProjectionManager::SetCurrentDepth
void SetCurrentDepth(Float_t d)
Definition: REveProjectionManager.hxx:82
ROOT::Experimental::REveProjectionManager::SubImportChildren
virtual Int_t SubImportChildren(REveElement *el, REveElement *proj_parent)
Recursively import children elements of el and apply projection to the newly imported objects.
Definition: REveProjectionManager.cxx:312
ROOT::Experimental::REveElement::CSCApplyMainTransparencyToMatchingChildren
void CSCApplyMainTransparencyToMatchingChildren()
Definition: REveElement.hxx:353
ROOT::Experimental
Definition: RDirectory.hxx:36
xmlio::cnt
const char * cnt
Definition: TXMLSetup.cxx:81
type
int type
Definition: TGX11.cxx:121
Float_t
ROOT::Experimental::REveProjectionManager
REveProjectionManager Manager class for steering of projections and managing projected objects.
Definition: REveProjectionManager.hxx:39
ROOT::Experimental::REveDataProxyBuilderBase::SetCollection
virtual void SetCollection(REveDataCollection *)
Definition: REveDataProxyBuilderBase.cxx:65
ROOT::Experimental::REveCompound
Definition: REveCompound.hxx:38
ROOT::Experimental::REveDataItem
Definition: REveDataClasses.hxx:96
ROOT::Experimental::REveElement::SetMainColor
virtual void SetMainColor(Color_t color)
Set main color of the element.
Definition: REveElement.cxx:673
ROOT::Experimental::REveDataProxyBuilderBase::CreateCompound
REveCompound * CreateCompound(bool set_color=true, bool propagate_color_to_all_children=false) const
Definition: REveDataProxyBuilderBase.cxx:343
ROOT::Experimental::REveElement::SetMainTransparency
virtual void SetMainTransparency(Char_t t)
Set main-transparency.
Definition: REveElement.cxx:726
ROOT::Experimental::REveDataProxyBuilderBase::CollectionChanged
void CollectionChanged(const REveDataCollection *)
Definition: REveDataProxyBuilderBase.cxx:304
ROOT::Experimental::REveDataProxyBuilderBase::CleanLocal
virtual void CleanLocal()
Definition: REveDataProxyBuilderBase.cxx:380
int
ROOT::Experimental::REveElement::GetMother
REveElement * GetMother()
Definition: REveElement.hxx:187