Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014 #include <stdio.h>
00015 #include <boost/bind.hpp>
00016 #include <algorithm>
00017
00018 #include "TClass.h"
00019 #include "TROOT.h"
00020 #include "TGWindow.h"
00021 #include "TGFrame.h"
00022 #include "TEveWindow.h"
00023 #include "TQObject.h"
00024
00025 #include "Fireworks/Core/interface/FWDetailViewManager.h"
00026 #include "Fireworks/Core/interface/FWColorManager.h"
00027 #include "Fireworks/Core/interface/FWDetailViewBase.h"
00028 #include "Fireworks/Core/interface/FWModelId.h"
00029 #include "Fireworks/Core/interface/FWEventItem.h"
00030 #include "Fireworks/Core/interface/FWDetailViewFactory.h"
00031 #include "Fireworks/Core/interface/FWSimpleRepresentationChecker.h"
00032 #include "Fireworks/Core/interface/FWRepresentationInfo.h"
00033 #include "Fireworks/Core/interface/fwLog.h"
00034
00035
00036 static
00037 std::string viewNameFrom(const std::string& iFull)
00038 {
00039 std::string::size_type first = iFull.find_first_of('@');
00040 std::string::size_type second = iFull.find_first_of('@',first+1);
00041 return iFull.substr(first+1,second-first-1);
00042
00043 }
00044
00045
00046
00047 FWDetailViewManager::FWDetailViewManager(FWColorManager* colMng):
00048 m_colorManager(colMng)
00049 {
00050
00051 gROOT->SetStyle("Plain");
00052
00053 m_colorManager->colorsHaveChanged_.connect(boost::bind(&FWDetailViewManager::colorsChanged,this));
00054 }
00055
00056 FWDetailViewManager::~FWDetailViewManager()
00057 {
00058 for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
00059 delete (*i).m_detailView;
00060
00061 }
00062
00063 void
00064 FWDetailViewManager::openDetailViewFor(const FWModelId &id, const std::string& iViewName)
00065 {
00066 TEveWindowSlot* slot = TEveWindow::CreateWindowMainFrame();
00067 TEveCompositeFrameInMainFrame* eveFrame = (TEveCompositeFrameInMainFrame*)slot->GetEveFrame();
00068
00069
00070 std::string typeName = ROOT::Reflex::Type::ByTypeInfo(*(id.item()->modelType()->GetTypeInfo())).Name(ROOT::Reflex::SCOPED);
00071 std::vector<std::string> viewerNames = findViewersFor(typeName);
00072 if(0==viewerNames.size()) {
00073 fwLog(fwlog::kError) << "FWDetailViewManager: don't know what detailed view to "
00074 "use for object " << id.item()->name() << std::endl;
00075 assert(0!=viewerNames.size());
00076 }
00077
00078
00079 std::string match;
00080 for(std::vector<std::string>::iterator it = viewerNames.begin(), itEnd = viewerNames.end(); it != itEnd; ++it) {
00081 std::string t = viewNameFrom(*it);
00082
00083 if(t == iViewName) {
00084 match = *it;
00085 break;
00086 }
00087 }
00088 assert(match.size() != 0);
00089 FWDetailViewBase* detailView = FWDetailViewFactory::get()->create(match);
00090 assert(0!=detailView);
00091 m_views.push_back(ViewFrame(eveFrame, detailView));
00092
00093 TEveWindowSlot* ws = (TEveWindowSlot*)(eveFrame->GetEveWindow());
00094 detailView->init(ws);
00095 detailView->build(id);
00096 detailView->setBackgroundColor(m_colorManager->background());
00097
00098 TGMainFrame* mf = (TGMainFrame*)(eveFrame->GetParent());
00099 mf->SetWindowName(Form("%s Detail View [%d]", id.item()->name().c_str(), id.index()));
00100 mf->Connect( "Destroyed()", "FWDetailViewManager", this, "eveWindowDestroyed()");
00101
00102 mf->MapRaised();
00103
00104 }
00105
00106 std::vector<std::string>
00107 FWDetailViewManager::detailViewsFor(const FWModelId& iId) const
00108 {
00109 std::string typeName = ROOT::Reflex::Type::ByTypeInfo(*(iId.item()->modelType()->GetTypeInfo())).Name(ROOT::Reflex::SCOPED);
00110 std::vector<std::string> fullNames = findViewersFor(typeName);
00111 std::vector<std::string> justViewNames;
00112 justViewNames.reserve(fullNames.size());
00113 std::transform(fullNames.begin(),fullNames.end(),std::back_inserter(justViewNames),&viewNameFrom);
00114 return justViewNames;
00115 }
00116
00117 std::vector<std::string>
00118 FWDetailViewManager::findViewersFor(const std::string& iType) const
00119 {
00120 std::vector<std::string> returnValue;
00121
00122 std::map<std::string,std::vector<std::string> >::const_iterator itFind = m_typeToViewers.find(iType);
00123 if(itFind != m_typeToViewers.end()) {
00124 return itFind->second;
00125 }
00126
00127 std::set<std::string> detailViews;
00128
00129 std::vector<edmplugin::PluginInfo> available = FWDetailViewFactory::get()->available();
00130 std::transform(available.begin(),
00131 available.end(),
00132 std::inserter(detailViews,detailViews.begin()),
00133 boost::bind(&edmplugin::PluginInfo::name_,_1));
00134 unsigned int closestMatch= 0xFFFFFFFF;
00135 for(std::set<std::string>::iterator it = detailViews.begin(), itEnd=detailViews.end();
00136 it!=itEnd;
00137 ++it) {
00138 std::string::size_type first = it->find_first_of('@');
00139 std::string type = it->substr(0,first);
00140
00141 if(type == iType) {
00142 returnValue.push_back(viewNameFrom(*it));
00143 }
00144
00145 FWSimpleRepresentationChecker checker(type,"",0,false);
00146 FWRepresentationInfo info = checker.infoFor(iType);
00147 if(closestMatch > info.proximity()) {
00148
00149 returnValue.push_back(*it);
00150 }
00151 }
00152 m_typeToViewers[iType]=returnValue;
00153 return returnValue;
00154 }
00155
00156 void
00157 FWDetailViewManager::colorsChanged()
00158 {
00159 for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
00160 (*i).m_detailView->setBackgroundColor(m_colorManager->background());
00161 }
00162
00163
00164 void
00165 FWDetailViewManager::newEventCallback()
00166 {
00167 for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
00168 {
00169 TGMainFrame* mf = (TGMainFrame*)(*i).m_eveFrame->GetParent();
00170 mf->CloseWindow();
00171 }
00172
00173 m_views.clear();
00174 }
00175
00176 void
00177 FWDetailViewManager::eveWindowDestroyed()
00178 {
00179 TGMainFrame *mf = static_cast<TGMainFrame *>(gTQSender);
00180
00181 for (vViews_i i = m_views.begin(); i != m_views.end(); ++i)
00182 {
00183 if (mf == (*i).m_eveFrame->GetParent())
00184 m_views.erase(i);
00185 }
00186 }