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