CMS 3D CMS Logo

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 <boost/bind.hpp>
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 
38 
42 static
44 {
45  std::string::size_type first = iFull.find_first_of('@');
46  std::string::size_type second = iFull.find_first_of('@',first+1);
47  return iFull.substr(first+1,second-first-1);
48 }
49 //
50 // constructors and destructor
51 //
53  m_context(iCtx)
54 {
55  // force white background for all embedded canvases
56  gROOT->SetStyle("Plain");
57 
59  gEve->GetWindowManager()->Connect( "WindowDeleted(TEveWindow*)", "FWDetailViewManager", this, "eveWindowDestroyed(TEveWindow*)");
60 }
61 
63 {
65  gEve->GetWindowManager()->Disconnect("WindowDeleted(TEveWindow*)", this, "eveWindowDestroyed(TEveWindow*)" );
66 }
67 
68 FWDetailViewManager::ViewFrame::ViewFrame(TEveCompositeFrameInMainFrame *f, std::unique_ptr<FWDetailViewBase> v, TEveWindow* w):
69  m_eveFrame(f), m_detailView(std::move(v)), m_eveWindow(w) {}
71 
72 void
74 {
75 
76  TEveWindowSlot* slot = TEveWindow::CreateWindowMainFrame();
77  TEveCompositeFrameInMainFrame* eveFrame = (TEveCompositeFrameInMainFrame*)slot->GetEveFrame();
78 
79  // find the right viewer for this item
80  std::string typeName = edm::TypeWithDict(*(id.item()->modelType()->GetTypeInfo())).name();
81  std::vector<std::string> viewerNames = findViewersFor(typeName);
82  if(viewerNames.empty()) {
83  fwLog(fwlog::kError) << "FWDetailViewManager: don't know what detailed view to "
84  "use for object " << id.item()->name() << std::endl;
85  assert(!viewerNames.empty());
86  }
87 
88  //see if one of the names matches iViewName
90  for(std::vector<std::string>::iterator it = viewerNames.begin(), itEnd = viewerNames.end(); it != itEnd; ++it) {
91  std::string t = viewNameFrom(*it);
92  //std::cout <<"'"<<iViewName<< "' '"<<t<<"'"<<std::endl;
93  if(t == iViewName) {
94  match = *it;
95  break;
96  }
97  }
98  assert(!match.empty());
99  std::unique_ptr<FWDetailViewBase> detailView{FWDetailViewFactory::get()->create(match)};
100  assert(nullptr!=detailView);
101 
102  TEveWindowSlot* ws = (TEveWindowSlot*)(eveFrame->GetEveWindow());
103  detailView->init(ws);
104  detailView->build(id);
105  detailView->setBackgroundColor(m_context->colorManager()->background());
106 
107  TGMainFrame* mf = (TGMainFrame*)(eveFrame->GetParent());
108  mf->SetWindowName(Form("%s Detail View [%d]", id.item()->name().c_str(), id.index()));
109 
110  m_views.emplace_back(eveFrame, std::move(detailView), eveFrame->GetEveWindow());
111 
112  mf->MapRaised();
113 }
114 
115 std::vector<std::string>
117 {
118  std::string typeName = edm::TypeWithDict(*(iId.item()->modelType()->GetTypeInfo())).name();
119  std::vector<std::string> fullNames = findViewersFor(typeName);
120  std::vector<std::string> justViewNames;
121  justViewNames.reserve(fullNames.size());
122  std::transform(fullNames.begin(),fullNames.end(),std::back_inserter(justViewNames),&viewNameFrom);
123  return justViewNames;
124 }
125 namespace {
126 bool pluginComapreFunc (std::string a, std::string b) {
127  std::string::size_type as = a.find_first_of('&');
128  a = a.substr(0, as);
129  std::string::size_type bs = b.find_first_of('&');
130  b = b.substr(0, bs);
131  return a == b;
132 }
133 }
134 
135 std::vector<std::string>
137 {
138 
139  std::vector<std::string> returnValue;
140 
141  std::map<std::string,std::vector<std::string> >::const_iterator itFind = m_typeToViewers.find(iType);
142  if(itFind != m_typeToViewers.end()) {
143  return itFind->second;
144  }
145 
146  std::set<std::string> detailViews;
147 
148  std::vector<edmplugin::PluginInfo> all = edmplugin::PluginManager::get()->categoryToInfos().find(FWDetailViewFactory::get()->category())->second;
149  std::transform(all.begin(),
150  all.end(),
151  std::inserter(detailViews,detailViews.begin()),
152  boost::bind(&edmplugin::PluginInfo::name_,_1));
153  unsigned int closestMatch= 0xFFFFFFFF;
154 
155 
156  for(std::set<std::string>::iterator it = detailViews.begin(), itEnd=detailViews.end();
157  it!=itEnd;
158  ++it) {
159 
160  if (m_context->getHidePFBuilders()) {
161  std::size_t found = it->find("PF ");
162  if (found != std::string::npos)
163  continue;
164  }
165  std::string::size_type first = it->find_first_of('@');
166  std::string type = it->substr(0,first);
167 
168  //see if we match via inheritance
169  FWSimpleRepresentationChecker checker(type,"",0,false);
170  FWRepresentationInfo info = checker.infoFor(iType);
171  bool pass = false;
172  if(closestMatch > info.proximity()) {
173  pass = true;
174  std::string::size_type firstD = it->find_first_of('&')+1;
175  if(firstD != std::string::npos) {
176  std::stringstream ss(it->substr(firstD));
177  std::string ml;
178  while(std::getline(ss, ml, '&')) {
180  fwLog(fwlog::kDebug) << "DetailView "<< *it << " requires module label " << ml << std::endl;
181  pass = false;
182  break;
183  }
184  }
185  }
186  if (pass) {
187  returnValue.push_back(*it);
188  }
189  else {
190  std::string::size_type first = (*it).find_first_of('@');
191  std::string vn = *it;
192  vn.insert(++first, "!");
193  returnValue.push_back(vn);
194  }
195  }
196  }
197 
198  std::vector<std::string>::iterator it;
199  it = std::unique (returnValue.begin(), returnValue.end(), pluginComapreFunc);
200  returnValue.resize( std::distance(returnValue.begin(),it) );
201 
202  m_typeToViewers[iType]=returnValue;
203  return returnValue;
204 }
205 
206 void
208 {
209  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
210  (*i).m_detailView->setBackgroundColor(m_context->colorManager()->background());
211 }
212 
213 
214 void
216 {
217  while (!m_views.empty())
218  {
219  m_views.front().m_eveWindow->DestroyWindowAndSlot();
220  }
221 }
222 
223 void
225 {
226  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
227  {
228  if (ew == i->m_eveWindow)
229  {
230  // printf("========================== delete %s \n", ew->GetElementName());
231  m_views.erase(i);
232  break;
233  }
234  }
235 }
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:83
type
Definition: HCALResponse.h:21
static const TGPicture * info(bool iBackgroundIsBlack)
Color_t background() const
virtual bool hasModuleLabel(std::string &moduleLabel)=0
const double w
Definition: UKUtility.cc:23
FWColorManager * colorManager() const
Definition: Context.h:65
vViews_t::iterator vViews_i
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 *)
U second(std::pair< T, U > const &p)
std::string name() const
std::map< std::string, std::vector< std::string > > m_typeToViewers
def unique(seq, keepstr=True)
Definition: tier0.py:25
bool getHidePFBuilders() const
Definition: Context.h:91
double f[11][100]
fireworks::Context * m_context
ViewFrame(TEveCompositeFrameInMainFrame *f, std::unique_ptr< FWDetailViewBase > v, TEveWindow *w)
#define fwLog(_level_)
Definition: fwLog.h:50
FWJobMetadataManager * metadataManager() const
Definition: Context.h:69
double b
Definition: hdecay.h:120
std::vector< std::string > detailViewsFor(const FWModelId &) const
void openDetailViewFor(const FWModelId &, const std::string &)
double a
Definition: hdecay.h:121
std::string name_
Definition: PluginInfo.h:29
const TClass * modelType() const
Definition: FWEventItem.cc:566
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
sigc::signal< void > colorsHaveChanged_
static PluginManager * get()
const FWEventItem * item() const
Definition: FWModelId.h:44
def move(src, dest)
Definition: eostools.py:511
T get(const Candidate &c)
Definition: component.h:55
FWRepresentationInfo infoFor(const std::string &iTypeName) const override