test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros 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 <stdio.h>
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 void
70 {
71 
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(0==viewerNames.size()) {
79  fwLog(fwlog::kError) << "FWDetailViewManager: don't know what detailed view to "
80  "use for object " << id.item()->name() << std::endl;
81  assert(0!=viewerNames.size());
82  }
83 
84  //see if one of the names matches iViewName
86  for(std::vector<std::string>::iterator it = viewerNames.begin(), itEnd = viewerNames.end(); it != itEnd; ++it) {
87  std::string t = viewNameFrom(*it);
88  //std::cout <<"'"<<iViewName<< "' '"<<t<<"'"<<std::endl;
89  if(t == iViewName) {
90  match = *it;
91  break;
92  }
93  }
94  assert(match.size() != 0);
95  FWDetailViewBase* detailView = FWDetailViewFactory::get()->create(match);
96  assert(0!=detailView);
97 
98  TEveWindowSlot* ws = (TEveWindowSlot*)(eveFrame->GetEveWindow());
99  detailView->init(ws);
100  detailView->build(id);
101  detailView->setBackgroundColor(m_context->colorManager()->background());
102 
103  TGMainFrame* mf = (TGMainFrame*)(eveFrame->GetParent());
104  mf->SetWindowName(Form("%s Detail View [%d]", id.item()->name().c_str(), id.index()));
105 
106  m_views.push_back(ViewFrame(eveFrame, detailView, eveFrame->GetEveWindow()));
107 
108  mf->MapRaised();
109 }
110 
111 std::vector<std::string>
113 {
114  std::string typeName = edm::TypeWithDict(*(iId.item()->modelType()->GetTypeInfo())).name();
115  std::vector<std::string> fullNames = findViewersFor(typeName);
116  std::vector<std::string> justViewNames;
117  justViewNames.reserve(fullNames.size());
118  std::transform(fullNames.begin(),fullNames.end(),std::back_inserter(justViewNames),&viewNameFrom);
119  return justViewNames;
120 }
121 namespace {
122 bool pluginComapreFunc (std::string a, std::string b) {
123  std::string::size_type as = a.find_first_of('&');
124  a = a.substr(0, as);
125  std::string::size_type bs = b.find_first_of('&');
126  b = b.substr(0, bs);
127  return a == b;
128 }
129 }
130 
131 std::vector<std::string>
133 {
134 
135  std::vector<std::string> returnValue;
136 
137  std::map<std::string,std::vector<std::string> >::const_iterator itFind = m_typeToViewers.find(iType);
138  if(itFind != m_typeToViewers.end()) {
139  return itFind->second;
140  }
141 
142  std::set<std::string> detailViews;
143 
144  std::vector<edmplugin::PluginInfo> all = edmplugin::PluginManager::get()->categoryToInfos().find(FWDetailViewFactory::get()->category())->second;
145  std::transform(all.begin(),
146  all.end(),
147  std::inserter(detailViews,detailViews.begin()),
148  boost::bind(&edmplugin::PluginInfo::name_,_1));
149  unsigned int closestMatch= 0xFFFFFFFF;
150 
151 
152  for(std::set<std::string>::iterator it = detailViews.begin(), itEnd=detailViews.end();
153  it!=itEnd;
154  ++it) {
155 
156  if (m_context->getHidePFBuilders()) {
157  std::size_t found = it->find("PF ");
158  if (found != std::string::npos)
159  continue;
160  }
161  std::string::size_type first = it->find_first_of('@');
162  std::string type = it->substr(0,first);
163 
164  //see if we match via inheritance
165  FWSimpleRepresentationChecker checker(type,"",0,false);
166  FWRepresentationInfo info = checker.infoFor(iType);
167  bool pass = false;
168  if(closestMatch > info.proximity()) {
169  pass = true;
170  std::string::size_type firstD = it->find_first_of('&')+1;
171  if(firstD != std::string::npos) {
172  std::stringstream ss(it->substr(firstD));
173  std::string ml;
174  while(std::getline(ss, ml, '&')) {
176  fwLog(fwlog::kDebug) << "DetailView "<< *it << " requires module label " << ml << std::endl;
177  pass = false;
178  break;
179  }
180  }
181  }
182  if (pass) {
183  returnValue.push_back(*it);
184  }
185  else {
186  std::string::size_type first = (*it).find_first_of('@');
187  std::string vn = *it;
188  vn.insert(++first, "!");
189  returnValue.push_back(vn);
190  }
191  }
192  }
193 
194  std::vector<std::string>::iterator it;
195  it = std::unique (returnValue.begin(), returnValue.end(), pluginComapreFunc);
196  returnValue.resize( std::distance(returnValue.begin(),it) );
197 
198  m_typeToViewers[iType]=returnValue;
199  return returnValue;
200 }
201 
202 void
204 {
205  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
206  (*i).m_detailView->setBackgroundColor(m_context->colorManager()->background());
207 }
208 
209 
210 void
212 {
213  while (!m_views.empty())
214  {
215  m_views.front().m_eveWindow->DestroyWindowAndSlot();
216  }
217 }
218 
219 void
221 {
222  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
223  {
224  if (ew == i->m_eveWindow)
225  {
226  // printf("========================== delete %s \n", ew->GetElementName());
227  delete i->m_detailView;
228  m_views.erase(i);
229  break;
230  }
231  }
232 }
const CategoryToInfos & categoryToInfos() const
Definition: PluginManager.h:82
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
virtual FWRepresentationInfo infoFor(const std::string &iTypeName) const
static const TGPicture * info(bool iBackgroundIsBlack)
Color_t background() const
virtual bool hasModuleLabel(std::string &moduleLabel)=0
FWColorManager * colorManager() const
Definition: Context.h:65
assert(m_qm.get())
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
bool getHidePFBuilders() const
Definition: Context.h:91
fireworks::Context * m_context
#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:563
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
T get(const Candidate &c)
Definition: component.h:55