CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
FWProxyBuilderBase.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWProxyBuilderBase
5 //
6 // Implementation:
7 // [Notes on implementation]
8 //
9 // Original Author: Chris Jones, Matevz Tadel, Alja Mrak-Tadel
10 // Created: Thu Mar 18 14:12:00 CET 2010
11 //
12 
13 // system include files
14 #include <iostream>
15 #include <boost/bind.hpp>
16 
17 // user include files
18 #include "TEveElement.h"
19 #include "TEveCompound.h"
20 #include "TEveManager.h"
21 #include "TEveProjectionManager.h"
22 #include "TEveSelection.h"
23 
30 
31 //
32 // constants, enums and typedefs
33 //
34 
35 //
36 // static data member definitions
37 //
38 
39 //
40 // constructors and destructor
41 //
42 
43 
44 FWProxyBuilderBase::Product::Product(FWViewType::EType t, const FWViewContext* c) : m_viewType(t), m_viewContext(c), m_elements(0)
45 {
46  m_elements = new TEveElementList("ProxyProduct");
47  m_elements->IncDenyDestroy();
48 }
49 
50 
52 {
53  // remove product from projected scene (RhoPhi or RhoZ)
54  TEveProjectable* pable = dynamic_cast<TEveProjectable*>(m_elements);
55  // don't have to check cast, because TEveElementList is TEveProjectable
56  for (TEveProjectable::ProjList_i i = pable->BeginProjecteds(); i != pable->EndProjecteds(); ++i)
57  {
58  TEveElement* projected = (*i)->GetProjectedAsElement();
59  (*projected->BeginParents())->RemoveElement(projected);
60  }
61 
62  // remove from 3D scenes
63  while (m_elements->HasParents())
64  {
65  TEveElement* parent = *m_elements->BeginParents();
66  parent->RemoveElement(m_elements);
67  }
68 
69  m_elements->Annihilate();
70 }
71 
72 //______________________________________________________________________________
73 
76  m_item(0),
80  m_layer(0)
81 {
82 }
83 
85 {
86  m_products.clear();
87 }
88 
89 //
90 // member functions
91 //
92 
93 void
95 {
96  m_item = iItem;
97 }
98 
99 void
101 {
102  bool oldValue = m_haveWindow;
103  m_haveWindow=iFlag;
104 
105  if(iFlag && !oldValue) {
106  //this is our first view so may need to rerun our building
107  if(m_mustBuild) {
108  build();
109  }
110  }
111 }
112 
113 void
115 {
116  m_item=0;
117 
118  cleanLocal();
119 
120  for (Product_it i = m_products.begin(); i!= m_products.end(); i++)
121  {
122 
123  (*i)->m_scaleConnection.disconnect();
124  delete (*i);
125  }
126 
127  m_products.clear();
128 }
129 
130 void
132 {
133  if (m_item)
134  {
135  try
136  {
137  size_t itemSize = m_item->size(); //cashed
138 
139  clean();
140  for (Product_it i = m_products.begin(); i != m_products.end(); ++i)
141  {
142  //printf("build() %s \n", m_item->name().c_str());
143  TEveElementList* elms = (*i)->m_elements;
144  size_t oldSize = elms->NumChildren();
145 
146  if (haveSingleProduct())
147  {
148  build(m_item, elms, (*i)->m_viewContext);
149  }
150  else
151  {
152  buildViewType(m_item, elms, (*i)->m_viewType, (*i)->m_viewContext);
153  }
154 
155  // Project all children of current product.
156  // If product is not registered into any projection-manager,
157  // this does nothing.
158  TEveProjectable* pable = dynamic_cast<TEveProjectable*>(elms);
159  if (pable->HasProjecteds())
160  {
161  // loop projected holders
162  for (TEveProjectable::ProjList_i i = pable->BeginProjecteds(); i != pable->EndProjecteds(); ++i)
163  {
164  TEveProjectionManager *pmgr = (*i)->GetManager();
165  Float_t oldDepth = pmgr->GetCurrentDepth();
166  pmgr->SetCurrentDepth(item()->layer());
167  size_t cnt = 0;
168 
169  TEveElement* projectedAsElement = (*i)->GetProjectedAsElement();
170  TEveElement::List_i parentIt = projectedAsElement->BeginChildren();
171  for (TEveElement::List_i prodIt = elms->BeginChildren(); prodIt != elms->EndChildren(); ++prodIt, ++cnt)
172  {
173  // reused projected holder
174  if (cnt < oldSize)
175  {
176  if ((*parentIt)->NumChildren()) {
177  // update projected (mislleading name)
178  for ( TEveElement::List_i pci = (*parentIt)->BeginChildren(); pci != (*parentIt)->EndChildren(); pci++)
179  pmgr->ProjectChildrenRecurse(*parentIt);
180  }
181  else {
182  // import projectable
183  pmgr->SubImportChildren(*prodIt, *parentIt);
184  }
185 
186  ++parentIt;
187  }
188  else if (cnt < itemSize)
189  {
190  // new product holder
191  pmgr->SubImportElements(*prodIt, projectedAsElement);
192  }
193  else
194  {
195  break;
196  }
197  }
198  pmgr->SetCurrentDepth(oldDepth);
199  }
200  }
201 
202 
203  if (m_interactionList && itemSize > oldSize)
204  {
205  TEveElement::List_i elIt = elms->BeginChildren();
206  for (size_t cnt = 0; cnt < itemSize; ++cnt, ++elIt)
207  {
208  if (cnt >= oldSize )
209  m_interactionList->added(*elIt, cnt);
210  }
211  }
212  }
213  }
214  catch (const std::runtime_error& iException)
215  {
216  fwLog(fwlog::kError) << "Caught exception in build function for item " << m_item->name() << ":\n"
217  << iException.what() << std::endl;
218  exit(1);
219  }
220  }
221  m_mustBuild = false;
222 }
223 
224 //______________________________________________________________________________
225 void
227 {
228  TEveElementList* elms = p->m_elements;
229  assert(m_item && static_cast<int>(m_item->size()) <= elms->NumChildren() && "can not use default modelChanges implementation");
230 
231  TEveElement::List_i itElement = elms->BeginChildren();
232  int index = 0;
233  for (FWModelIds::const_iterator it = iIds.begin(), itEnd = iIds.end();
234  it != itEnd;
235  ++it,++itElement,++index)
236  {
237  assert(itElement != elms->EndChildren());
238  while (index < it->index())
239  {
240  ++itElement;
241  ++index;
242  assert(itElement != elms->EndChildren());
243  }
244  if (visibilityModelChanges(*it, *itElement, p->m_viewType, p->m_viewContext))
245  {
246  elms->ProjectChild(*itElement);
247  }
248  else
249  {
250  localModelChanges(*it, *itElement, p->m_viewType, p->m_viewContext);
251  }
252  }
253 }
254 
255 void
257 {
258  if(m_haveWindow) {
259  for (Product_it i = m_products.begin(); i!= m_products.end(); ++i)
260  {
261  modelChanges(iIds, *i);
262  }
263  m_modelsChanged=false;
264  } else {
265  m_modelsChanged=true;
266  }
267 }
268 
269 //______________________________________________________________________________
270 void
272 {
273  if (iItem->layer() != m_layer)
274  setProjectionLayer(iItem->layer());
275 
276  if(m_haveWindow) {
277  build();
278  } else {
279  m_mustBuild=true;
280  }
281  m_modelsChanged=false;
282 }
283 
284 //______________________________________________________________________________
285 bool
287 {
288  if (m_item)
289  return (item.purpose() == m_item->purpose());
290 
291  return false;
292 }
293 
294 //______________________________________________________________________________
295 
296 TEveElementList*
298 {
299  if ( havePerViewProduct(viewType) == false && m_products.empty() == false)
300  {
301  if (haveSingleProduct())
302  {
303  return m_products.back()->m_elements;
304  }
305  else
306  {
307  for (Product_it i = m_products.begin(); i!= m_products.end(); ++i)
308  {
309  if (viewType == (*i)->m_viewType)
310  return (*i)->m_elements;
311  }
312  }
313  }
314 
315  // printf("new product %s for item %s \n", FWViewType::idToName(viewType).c_str(), item()->name().c_str()); fflush(stdout);
316 
317  Product* product = new Product(viewType, viewContext);
318  m_products.push_back(product);
319  if (viewContext)
320  {
321  product->m_scaleConnection = viewContext->scaleChanged_.connect(boost::bind(&FWProxyBuilderBase::scaleChanged, this, _1));
322  }
323 
324  if (item())
325  {
326  // debug info in eve browser
327  product->m_elements->SetElementName(item()->name().c_str());
328  }
329  return product->m_elements;
330 }
331 
332 //______________________________________________________________________________
333 
334 void
336 {
337  for (Product_it i = m_products.begin(); i!= m_products.end(); ++i)
338  {
339  if (havePerViewProduct(type) && (*i)->m_viewContext == vc)
340  {
341  if ((*i)->m_elements)
342  (*i)->m_elements->DestroyElements();
343 
344  if ( (*i)->m_viewContext)
345  (*i)->m_scaleConnection.disconnect();
346 
347  delete (*i);
348  m_products.erase(i);
349  break;
350  }
351  }
352 }
353 
354 //------------------------------------------------------------------------------
355 
356 void
358 {
359  // Called if willHandleInteraction() returns false. Purpose ignored by default.
360 
362 }
363 
364 
365 bool
367 {
368  return false;
369 }
370 
371 void
373 {
374  // Nothing to be done in base class.
375  // Visibility, main color and main transparency are handled through FWInteractionList.
376 }
377 
378 
379 void
381 {
382  for (Product_it i = m_products.begin(); i!= m_products.end(); ++i)
383  {
384  if ( havePerViewProduct((*i)->m_viewType) && (*i)->m_viewContext == vc)
385  {
386  scaleProduct((*i)->m_elements, (*i)->m_viewType, (*i)->m_viewContext);
387  }
388  }
389  gEve->Redraw3D();
390 }
391 
392 void
394 {
395  // Cleans local common element list.
396  for (Product_it i = m_products.begin(); i != m_products.end(); ++i)
397  {
398  if ((*i)->m_elements)
399  (*i)->m_elements->DestroyElements();
400  }
401 
402  cleanLocal();
403 }
404 
405 void
407 {
408  // Cleans local common element list.
409 }
410 
411 
412 void
413 FWProxyBuilderBase::build(const FWEventItem*, TEveElementList*, const FWViewContext*)
414 {
415  assert("virtual build(const FWEventItem*, TEveElementList*, const FWViewContext*) not implemented by inherited class");
416 }
417 
418 void
420 {
421  assert("virtual buildViewType(const FWEventItem*, TEveElementList*, FWViewType::EType, const FWViewContext*) not implemented by inherited class");
422 }
423 
424 void
426 {
427  m_layer = layer;
428  for (Product_it pIt = m_products.begin(); pIt != m_products.end(); ++pIt)
429  {
430  TEveProjectable* pable = static_cast<TEveProjectable*>((*pIt)->m_elements);
431  for (TEveProjectable::ProjList_i i = pable->BeginProjecteds(); i != pable->EndProjecteds(); ++i)
432  (*i)->SetDepth(m_layer);
433  }
434 }
435 
436 //------------------------------------------------------------------------------
437 
438 void
439 FWProxyBuilderBase::setupAddElement(TEveElement* el, TEveElement* parent, bool color) const
440 {
441  setupElement(el, color);
442  parent->AddElement(el);
443 }
444 
448 void
449 FWProxyBuilderBase::setupElement(TEveElement* el, bool color) const
450 {
451  el->CSCTakeAnyParentAsMaster();
452  el->SetPickable(true);
453 
454  if (color)
455  {
456  el->CSCApplyMainColorToMatchingChildren();
457  el->CSCApplyMainTransparencyToMatchingChildren();
458  el->SetMainColor(m_item->defaultDisplayProperties().color());
460  && (m_item->defaultDisplayProperties().transparency() <= 100));
461  el->SetMainTransparency(m_item->defaultDisplayProperties().transparency());
462  }
463 }
464 
465 //------------------------------------------------------------------------------
466 
467 TEveCompound*
468 FWProxyBuilderBase::createCompound(bool set_color, bool propagate_color_to_all_children) const
469 {
470  TEveCompound* c = new TEveCompound();
471  c->CSCTakeAnyParentAsMaster();
472  c->CSCImplySelectAllChildren();
473  c->SetPickable(true);
474  if (set_color)
475  {
476  c->SetMainColor(m_item->defaultDisplayProperties().color());
477  c->SetMainTransparency(m_item->defaultDisplayProperties().transparency());
478  }
479  if (propagate_color_to_all_children)
480  {
481  c->CSCApplyMainColorToAllChildren();
482  c->CSCApplyMainTransparencyToAllChildren();
483  }
484  else
485  {
486  c->CSCApplyMainColorToMatchingChildren();
487  c->CSCApplyMainTransparencyToMatchingChildren();
488  }
489  return c;
490 }
491 
492 void
494  const std::string& name, Char_t transpOffset)
495 {
496  // Helper function to increse transparency of certain components.
497 
498  const FWDisplayProperties& dp = item()->modelInfo(index).displayProperties();
499  Char_t transp = TMath::Min(100, transpOffset + (100 - transpOffset) * dp.transparency() / 100);
501  holder->FindChildren(matches, name.c_str());
502  for (TEveElement::List_i m = matches.begin(); m != matches.end(); ++m)
503  {
504  (*m)->SetMainTransparency(transp);
505  }
506 }
507 
508 //
509 // const member functions
510 //
511 
512 const fireworks::Context&
514 {
515  return m_item->context();
516 }
517 
518 int
520 {
521  return m_item->layer();
522 }
523 
524 //
525 // static member functions
526 //
527 
529 {
530  return std::string();
531 }
532 
534 {
535  return false;
536 }
type
Definition: HCALResponse.h:21
const fireworks::Context & context() const
tuple t
Definition: tree.py:139
virtual void buildViewType(const FWEventItem *iItem, TEveElementList *, FWViewType::EType, const FWViewContext *)
int i
Definition: DBlmapReader.cc:9
virtual void scaleProduct(TEveElementList *parent, FWViewType::EType, const FWViewContext *vc)
std::vector< Product * >::iterator Product_it
const FWDisplayProperties & defaultDisplayProperties() const
Definition: FWEventItem.cc:451
const FWDisplayProperties & displayProperties() const
Definition: FWEventItem.h:67
static std::string typeOfBuilder()
Used by the plugin system to determine how the proxy uses the data from FWEventItem.
std::vector< Product * > m_products
list parent
Definition: dbtoconf.py:74
virtual void itemBeingDestroyed(const FWEventItem *)
virtual bool havePerViewProduct(FWViewType::EType) const
const std::string & name() const
Definition: FWEventItem.cc:500
virtual bool visibilityModelChanges(const FWModelId &, TEveElement *, FWViewType::EType, const FWViewContext *)
void setupAddElement(TEveElement *el, TEveElement *parent, bool set_color=true) const
static bool representsSubPart()
assert(m_qm.get())
const FWViewContext * m_viewContext
T Min(T a, T b)
Definition: MathUtil.h:39
virtual void cleanLocal()
void scaleChanged(const FWViewContext *)
const FWEventItem * m_item
void added(TEveElement *, unsigned int)
const FWEventItem * item() const
std::list< Particle > List_t
Definition: Particle.h:143
Color_t color() const
int layer() const
Definition: FWEventItem.cc:457
sigc::connection m_scaleConnection
virtual void localModelChanges(const FWModelId &iId, TEveElement *iCompound, FWViewType::EType viewType, const FWViewContext *vc)
Char_t transparency() const
sigc::signal< void, const FWViewContext * > scaleChanged_
Definition: FWViewContext.h:43
Product(FWViewType::EType t, const FWViewContext *c)
std::set< FWModelId > FWModelIds
void set_color(TEveElement *element, Color_t color, float alpha, unsigned int levels)
Definition: eve_macros.cc:154
virtual void setItem(const FWEventItem *iItem)
const fireworks::Context & context() const
Definition: FWEventItem.h:126
void removePerViewProduct(FWViewType::EType, const FWViewContext *vc)
void setHaveWindow(bool iFlag)
virtual bool haveSingleProduct() const
size_t size() const
Definition: FWEventItem.cc:548
#define fwLog(_level_)
Definition: fwLog.h:50
virtual bool canHandle(const FWEventItem &)
FWInteractionList * m_interactionList
TEveCompound * createCompound(bool set_color=true, bool propagate_color_to_all_children=false) const
TEveElementList * createProduct(FWViewType::EType, const FWViewContext *)
volatile std::atomic< bool > shutdown_flag false
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535
const std::string & purpose() const
Definition: FWEventItem.cc:512
void setProjectionLayer(float)
void increaseComponentTransparency(unsigned int index, TEveElement *holder, const std::string &name, Char_t transpOffset)
void itemChanged(const FWEventItem *)
void modelChanges(const FWModelIds &)
virtual void setInteractionList(FWInteractionList *, const std::string &)
void setupElement(TEveElement *el, bool color=true) const