CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
FWDetailViewManager.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWDetailViewManager
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Wed Mar 5 09:13:47 EST 2008
11 //
12 
13 #include <cstdio>
14 #include <functional>
15 #include <algorithm>
16 #include <sstream>
17 
18 #include "TClass.h"
19 #include "TROOT.h"
20 #include "TGWindow.h"
21 #include "TGFrame.h"
22 #include "TEveManager.h"
23 #include "TEveWindowManager.h"
24 #include "TEveWindow.h"
25 #include "TQObject.h"
26 #include "TObjString.h"
27 
39 
43 static std::string viewNameFrom(const std::string& iFull) {
44  std::string::size_type first = iFull.find_first_of('@');
45  std::string::size_type second = iFull.find_first_of('@', first + 1);
46  return iFull.substr(first + 1, second - first - 1);
47 }
48 //
49 // constructors and destructor
50 //
52  // force white background for all embedded canvases
53  gROOT->SetStyle("Plain");
54 
56  gEve->GetWindowManager()->Connect(
57  "WindowDeleted(TEveWindow*)", "FWDetailViewManager", this, "eveWindowDestroyed(TEveWindow*)");
58 }
59 
62  gEve->GetWindowManager()->Disconnect("WindowDeleted(TEveWindow*)", this, "eveWindowDestroyed(TEveWindow*)");
63 }
64 
65 FWDetailViewManager::ViewFrame::ViewFrame(TEveCompositeFrameInMainFrame* f,
66  std::unique_ptr<FWDetailViewBase> v,
67  TEveWindow* w)
68  : m_eveFrame(f), m_detailView(std::move(v)), m_eveWindow(w) {}
70 
72  TEveWindowSlot* slot = TEveWindow::CreateWindowMainFrame();
73  TEveCompositeFrameInMainFrame* eveFrame = (TEveCompositeFrameInMainFrame*)slot->GetEveFrame();
74 
75  // find the right viewer for this item
76  std::string typeName = edm::TypeWithDict(*(id.item()->modelType()->GetTypeInfo())).name();
77  std::vector<std::string> viewerNames = findViewersFor(typeName);
78  if (viewerNames.empty()) {
79  fwLog(fwlog::kError) << "FWDetailViewManager: don't know what detailed view to "
80  "use for object "
81  << id.item()->name() << std::endl;
82  assert(!viewerNames.empty());
83  }
84 
85  //see if one of the names matches iViewName
87  for (std::vector<std::string>::iterator it = viewerNames.begin(), itEnd = viewerNames.end(); it != itEnd; ++it) {
88  std::string t = viewNameFrom(*it);
89  //std::cout <<"'"<<iViewName<< "' '"<<t<<"'"<<std::endl;
90  if (t == iViewName) {
91  match = *it;
92  break;
93  }
94  }
95  assert(!match.empty());
96  std::unique_ptr<FWDetailViewBase> detailView{FWDetailViewFactory::get()->create(match)};
97  assert(nullptr != detailView);
98 
99  TEveWindowSlot* ws = (TEveWindowSlot*)(eveFrame->GetEveWindow());
100  detailView->init(ws);
101  detailView->build(id);
102  detailView->setBackgroundColor(m_context->colorManager()->background());
103 
104  TGMainFrame* mf = (TGMainFrame*)(eveFrame->GetParent());
105  mf->SetWindowName(Form("%s Detail View [%d]", id.item()->name().c_str(), id.index()));
106 
107  m_views.emplace_back(eveFrame, std::move(detailView), eveFrame->GetEveWindow());
108 
109  mf->MapRaised();
110 }
111 
112 std::vector<std::string> FWDetailViewManager::detailViewsFor(const FWModelId& iId) const {
113  std::string typeName = edm::TypeWithDict(*(iId.item()->modelType()->GetTypeInfo())).name();
114  std::vector<std::string> fullNames = findViewersFor(typeName);
115  std::vector<std::string> justViewNames;
116  justViewNames.reserve(fullNames.size());
117  std::transform(fullNames.begin(), fullNames.end(), std::back_inserter(justViewNames), &viewNameFrom);
118  return justViewNames;
119 }
120 namespace {
121  bool pluginComapreFunc(std::string a, std::string b) {
122  std::string::size_type as = a.find_first_of('&');
123  a = a.substr(0, as);
124  std::string::size_type bs = b.find_first_of('&');
125  b = b.substr(0, bs);
126  return a == b;
127  }
128 } // namespace
129 
130 std::vector<std::string> FWDetailViewManager::findViewersFor(const std::string& iType) const {
131  std::vector<std::string> returnValue;
132 
133  std::map<std::string, std::vector<std::string> >::const_iterator itFind = m_typeToViewers.find(iType);
134  if (itFind != m_typeToViewers.end()) {
135  return itFind->second;
136  }
137 
138  std::set<std::string> detailViews;
139 
140  std::vector<edmplugin::PluginInfo> all =
142  std::transform(all.begin(),
143  all.end(),
144  std::inserter(detailViews, detailViews.begin()),
145  std::bind(&edmplugin::PluginInfo::name_, std::placeholders::_1));
146  unsigned int closestMatch = 0xFFFFFFFF;
147 
148  for (std::set<std::string>::iterator it = detailViews.begin(), itEnd = detailViews.end(); it != itEnd; ++it) {
149  if (m_context->getHidePFBuilders()) {
150  std::size_t found = it->find("PF ");
151  if (found != std::string::npos)
152  continue;
153  }
154  std::string::size_type first = it->find_first_of('@');
155  std::string type = it->substr(0, first);
156 
157  //see if we match via inheritance
158  FWSimpleRepresentationChecker checker(type, "", 0, false);
159  FWRepresentationInfo info = checker.infoFor(iType);
160  bool pass = false;
161  if (closestMatch > info.proximity()) {
162  pass = true;
163  std::string::size_type firstD = it->find_first_of('&') + 1;
164  if (firstD != std::string::npos) {
165  std::stringstream ss(it->substr(firstD));
166  std::string ml;
167  while (std::getline(ss, ml, '&')) {
169  fwLog(fwlog::kDebug) << "DetailView " << *it << " requires module label " << ml << std::endl;
170  pass = false;
171  break;
172  }
173  }
174  }
175  if (pass) {
176  returnValue.push_back(*it);
177  } else {
178  std::string::size_type first = (*it).find_first_of('@');
179  std::string vn = *it;
180  vn.insert(++first, "!");
181  returnValue.push_back(vn);
182  }
183  }
184  }
185 
186  std::vector<std::string>::iterator it;
187  it = std::unique(returnValue.begin(), returnValue.end(), pluginComapreFunc);
188  returnValue.resize(std::distance(returnValue.begin(), it));
189 
190  m_typeToViewers[iType] = returnValue;
191  return returnValue;
192 }
193 
195  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
196  (*i).m_detailView->setBackgroundColor(m_context->colorManager()->background());
197 }
198 
200  while (!m_views.empty()) {
201  m_views.front().m_eveWindow->DestroyWindowAndSlot();
202  }
203 }
204 
206  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i) {
207  if (ew == i->m_eveWindow) {
208  // printf("========================== delete %s \n", ew->GetElementName());
209  m_views.erase(i);
210  break;
211  }
212  }
213 }
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
static const TGPicture * info(bool iBackgroundIsBlack)
Color_t background() const
virtual bool hasModuleLabel(std::string &moduleLabel)=0
const double w
Definition: UKUtility.cc:23
static const char category[]
FWRepresentationInfo infoFor(const std::string &iTypeName) const override
FWColorManager * colorManager() const
Definition: Context.h:58
vViews_t::iterator vViews_i
def unique
Definition: tier0.py:24
assert(be >=bs)
uint16_t size_type
static std::string viewNameFrom(const std::string &iFull)
std::vector< std::string > findViewersFor(const std::string &) const
unsigned int proximity() const
measures how &#39;close&#39; this representation is to the type in question, the large the number the farther...
void eveWindowDestroyed(TEveWindow *)
auto &__restrict__ ws
U second(std::pair< T, U > const &p)
std::string name() const
std::map< std::string, std::vector< std::string > > m_typeToViewers
def move
Definition: eostools.py:511
bool getHidePFBuilders() const
Definition: Context.h:80
fireworks::Context * m_context
def all
workaround iterator generators for ROOT classes
Definition: cmstools.py:25
ViewFrame(TEveCompositeFrameInMainFrame *f, std::unique_ptr< FWDetailViewBase > v, TEveWindow *w)
#define fwLog(_level_)
Definition: fwLog.h:45
FWJobMetadataManager * metadataManager() const
Definition: Context.h:60
double b
Definition: hdecay.h:118
std::vector< std::string > detailViewsFor(const FWModelId &) const
void openDetailViewFor(const FWModelId &, const std::string &)
double a
Definition: hdecay.h:119
std::string name_
Definition: PluginInfo.h:29
const TClass * modelType() const
Definition: FWEventItem.cc:464
FWDetailViewManager(fireworks::Context *)
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:10
#define get
sigc::signal< void > colorsHaveChanged_
static PluginManager * get()
const FWEventItem * item() const
Definition: FWModelId.h:39
unsigned transform(const HcalDetId &id, unsigned transformCode)