ATLAS Offline Software
VisibleObjectToMaterialHelper.icc
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
6 ////////////////////////////////////////////////////////////////
7 // //
8 // Implementation of VisibleObjectToMaterialHelper inlines //
9 // //
10 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
11 // Initial version: February 2008 //
12 // //
13 ////////////////////////////////////////////////////////////////
14 
15 #include <QTimer>
16 #include "VP1Base/VP1Msg.h"
17 
18 //____________________________________________________________________
19 template <class objectT>
20 inline VisibleObjectToMaterialHelper<objectT>::VisibleObjectToMaterialHelper(QObject * parent,IVP1System*sys)
21  : VisibleObjectToMaterialHelper_Base(parent),
22  VP1HelperClassBase(sys,"VisibleObjectToMaterialHelper"),
23  m_hasscheduledupdate(false)
24 {
25 }
26 
27 //____________________________________________________________________
28 template <class objectT>
29 inline VisibleObjectToMaterialHelper<objectT>::~VisibleObjectToMaterialHelper()
30 {
31  setNoVisibleObjects();
32 }
33 
34 
35 //____________________________________________________________________
36 template <class objectT>
37 inline void VisibleObjectToMaterialHelper<objectT>::setState( const objectT* t, SoMaterial *mat )
38 {
39  if (!t) {
40  message("setState WARNING: Called with null pointer");
41  return;
42  }
43  if (VP1Msg::verbose())
44  messageVerbose("setState Called");
45 
46  typename std::map<const objectT*,SoMaterial*>::iterator it = m_visobjects.find(t);
47 
48  if (mat) {
49  if (it==m_visobjects.end()||it->second!=mat) {
50  m_visobjects[t] = mat;
51  scheduleUpdate();
52  }
53  } else {
54  if (it!=m_visobjects.end()) {
55  m_visobjects.erase(it);
56  scheduleUpdate();
57  }
58  }
59 }
60 
61 //____________________________________________________________________
62 template <class objectT>
63 inline void VisibleObjectToMaterialHelper<objectT>::setNoVisibleObjects()
64 {
65  bool hadobjects = ! m_visobjects.empty();
66  m_visobjects.clear();
67  if (hadobjects)
68  emitSignal(); // Don't do scheduleUpdate here, as can cause crash at end of event.
69 }
70 
71 //____________________________________________________________________
72 template <class objectT>
73 inline void VisibleObjectToMaterialHelper<objectT>::scheduleUpdate()
74 {
75  if (m_hasscheduledupdate)
76  return;
77  m_hasscheduledupdate = true;
78  messageVerbose("Schedule emission of visibleObjectsChanged()");
79  QTimer::singleShot(0, this, SLOT(emitSignal()));
80 }
81 
82 //____________________________________________________________________
83 template <class objectT>
84 inline void VisibleObjectToMaterialHelper<objectT>::emitSignal()
85 {
86  m_hasscheduledupdate = false;
87  visibleObjectsChanged();
88 }