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 // $Id: FWDetailViewManager.cc,v 1.63 2012/06/26 22:13:03 wmtan Exp $
12 //
13 
14 #include <stdio.h>
15 #include <boost/bind.hpp>
16 #include <algorithm>
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 
36 
37 
38 static
39 std::string viewNameFrom(const std::string& iFull)
40 {
41  std::string::size_type first = iFull.find_first_of('@');
42  std::string::size_type second = iFull.find_first_of('@',first+1);
43  return iFull.substr(first+1,second-first-1);
44 
45 }
46 //
47 // constructors and destructor
48 //
50  m_colorManager(colMng)
51 {
52  // force white background for all embedded canvases
53  gROOT->SetStyle("Plain");
54 
56  gEve->GetWindowManager()->Connect( "WindowDeleted(TEveWindow*)", "FWDetailViewManager", this, "eveWindowDestroyed(TEveWindow*)");
57 }
58 
60 {
62  gEve->GetWindowManager()->Disconnect("WindowDeleted(TEveWindow*)", this, "eveWindowDestroyed(TEveWindow*)" );
63 }
64 
65 void
66 FWDetailViewManager::openDetailViewFor(const FWModelId &id, const std::string& iViewName)
67 {
68  TEveWindowSlot* slot = TEveWindow::CreateWindowMainFrame();
69  TEveCompositeFrameInMainFrame* eveFrame = (TEveCompositeFrameInMainFrame*)slot->GetEveFrame();
70 
71  // find the right viewer for this item
72  std::string typeName = Reflex::Type::ByTypeInfo(*(id.item()->modelType()->GetTypeInfo())).Name(Reflex::SCOPED);
73  std::vector<std::string> viewerNames = findViewersFor(typeName);
74  if(0==viewerNames.size()) {
75  fwLog(fwlog::kError) << "FWDetailViewManager: don't know what detailed view to "
76  "use for object " << id.item()->name() << std::endl;
77  assert(0!=viewerNames.size());
78  }
79 
80  //see if one of the names matches iViewName
81  std::string match;
82  for(std::vector<std::string>::iterator it = viewerNames.begin(), itEnd = viewerNames.end(); it != itEnd; ++it) {
83  std::string t = viewNameFrom(*it);
84  //std::cout <<"'"<<iViewName<< "' '"<<t<<"'"<<std::endl;
85  if(t == iViewName) {
86  match = *it;
87  break;
88  }
89  }
90  assert(match.size() != 0);
91  FWDetailViewBase* detailView = FWDetailViewFactory::get()->create(match);
92  assert(0!=detailView);
93 
94  TEveWindowSlot* ws = (TEveWindowSlot*)(eveFrame->GetEveWindow());
95  detailView->init(ws);
96  detailView->build(id);
97  detailView->setBackgroundColor(m_colorManager->background());
98 
99  TGMainFrame* mf = (TGMainFrame*)(eveFrame->GetParent());
100  mf->SetWindowName(Form("%s Detail View [%d]", id.item()->name().c_str(), id.index()));
101 
102  m_views.push_back(ViewFrame(eveFrame, detailView, eveFrame->GetEveWindow()));
103 
104  mf->MapRaised();
105 }
106 
107 std::vector<std::string>
109 {
110  std::string typeName = Reflex::Type::ByTypeInfo(*(iId.item()->modelType()->GetTypeInfo())).Name(Reflex::SCOPED);
111  std::vector<std::string> fullNames = findViewersFor(typeName);
112  std::vector<std::string> justViewNames;
113  justViewNames.reserve(fullNames.size());
114  std::transform(fullNames.begin(),fullNames.end(),std::back_inserter(justViewNames),&viewNameFrom);
115  return justViewNames;
116 }
117 
118 std::vector<std::string>
119 FWDetailViewManager::findViewersFor(const std::string& iType) const
120 {
121  std::vector<std::string> returnValue;
122 
123  std::map<std::string,std::vector<std::string> >::const_iterator itFind = m_typeToViewers.find(iType);
124  if(itFind != m_typeToViewers.end()) {
125  return itFind->second;
126  }
127  //create a list of the available ViewManager's
128  std::set<std::string> detailViews;
129 
130  std::vector<edmplugin::PluginInfo> available = FWDetailViewFactory::get()->available();
131  std::transform(available.begin(),
132  available.end(),
133  std::inserter(detailViews,detailViews.begin()),
134  boost::bind(&edmplugin::PluginInfo::name_,_1));
135  unsigned int closestMatch= 0xFFFFFFFF;
136  for(std::set<std::string>::iterator it = detailViews.begin(), itEnd=detailViews.end();
137  it!=itEnd;
138  ++it) {
139  std::string::size_type first = it->find_first_of('@');
140  std::string type = it->substr(0,first);
141 
142  if(type == iType) {
143  returnValue.push_back(viewNameFrom(*it));
144  }
145  //see if we match via inheritance
146  FWSimpleRepresentationChecker checker(type,"",0,false);
147  FWRepresentationInfo info = checker.infoFor(iType);
148  if(closestMatch > info.proximity()) {
149  //closestMatch = info.proximity();
150  returnValue.push_back(*it);
151  }
152  }
153  m_typeToViewers[iType]=returnValue;
154  return returnValue;
155 }
156 
157 void
159 {
160  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
161  (*i).m_detailView->setBackgroundColor(m_colorManager->background());
162 }
163 
164 
165 void
167 {
168  while (!m_views.empty())
169  {
170  m_views.front().m_eveWindow->DestroyWindowAndSlot();
171  }
172 }
173 
174 void
176 {
177  for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
178  {
179  if (ew == i->m_eveWindow)
180  {
181  // printf("========================== delete %s \n", ew->GetElementName());
182  delete i->m_detailView;
183  m_views.erase(i);
184  break;
185  }
186  }
187 }
type
Definition: HCALResponse.h:22
int i
Definition: DBlmapReader.cc:9
FWDetailViewManager(FWColorManager *)
virtual FWRepresentationInfo infoFor(const std::string &iTypeName) const
Color_t background() const
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::map< std::string, std::vector< std::string > > m_typeToViewers
bool first
Definition: L1TdeRCT.cc:94
FWColorManager * m_colorManager
#define fwLog(_level_)
Definition: fwLog.h:51
std::vector< std::string > detailViewsFor(const FWModelId &) const
void openDetailViewFor(const FWModelId &, const std::string &)
std::string name_
Definition: PluginInfo.h:30
const TClass * modelType() const
Definition: FWEventItem.cc:561
std::pair< typename Association::data_type::first_type, double > match(Reference key, Association association, bool bestMatchByMaxValue)
Generic matching function.
Definition: Utils.h:6
sigc::signal< void > colorsHaveChanged_
const FWEventItem * item() const
Definition: FWModelId.h:45
T get(const Candidate &c)
Definition: component.h:56