00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <cassert>
00016 #include "TGMenu.h"
00017 #include "KeySymbols.h"
00018
00019 #include "FWCore/Utilities/interface/ObjectWithDict.h"
00020 #include "FWCore/Utilities/interface/TypeWithDict.h"
00021 #include "TClass.h"
00022
00023
00024 #include "Fireworks/Core/src/FWModelContextMenuHandler.h"
00025 #include "Fireworks/Core/interface/FWSelectionManager.h"
00026 #include "Fireworks/Core/interface/FWDetailViewManager.h"
00027 #include "Fireworks/Core/interface/FWColorManager.h"
00028 #include "Fireworks/Core/src/FWColorSelect.h"
00029 #include "Fireworks/Core/src/FWPopupMenu.cc"
00030 #include "Fireworks/Core/interface/FWEventItem.h"
00031 #include "Fireworks/Core/interface/FWGUIManager.h"
00032 #include "Fireworks/Core/interface/FWViewContextMenuHandlerBase.h"
00033
00034
00035
00036
00037 enum MenuOptions {
00038 kSetVisibleMO,
00039 kSetColorMO,
00040 kPrint,
00041 kOpenDetailViewMO,
00042 kAfterOpenDetailViewMO,
00043 kOpenObjectControllerMO=100,
00044 kOpenCollectionControllerMO,
00045 kViewOptionsMO=1000,
00046 kLastOfMO
00047 };
00048
00049
00050
00051
00052
00053 static const char* const kOpenDetailView = "Open Detailed View ...";
00054
00055
00056
00057
00058 FWModelContextMenuHandler::FWModelContextMenuHandler(FWSelectionManager* iSM,
00059 FWDetailViewManager* iDVM,
00060 FWColorManager* iCM,
00061 FWGUIManager* iGM):
00062 m_modelPopup(0),
00063 m_colorPopup(0),
00064 m_selectionManager(iSM),
00065 m_detailViewManager(iDVM),
00066 m_colorManager(iCM),
00067 m_guiManager(iGM),
00068 m_seperator(0),
00069 m_viewSeperator(0),
00070 m_afterViewSeperator(0),
00071 m_x(0),
00072 m_y(0),
00073 m_nDetailViewEntries(0),
00074 m_nViewEntries(0),
00075 m_viewHander(0)
00076 {
00077 }
00078
00079
00080
00081
00082
00083
00084 FWModelContextMenuHandler::~FWModelContextMenuHandler()
00085 {
00086 delete m_modelPopup;
00087 }
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104 #include "TROOT.h"
00105 namespace {
00106 class change_visibility {
00107 public:
00108 change_visibility(bool iIsVisible): m_isVisible(iIsVisible) {}
00109 void operator()(const FWModelId& iID) const {
00110 FWDisplayProperties p = iID.item()->modelInfo(iID.index()).displayProperties();
00111 p.setIsVisible(m_isVisible);
00112 iID.item()->setDisplayProperties(iID.index(), p);
00113 }
00114 bool m_isVisible;
00115 };
00116 }
00117 void
00118 FWModelContextMenuHandler::chosenItem(Int_t iChoice)
00119 {
00120 assert(!m_selectionManager->selected().empty());
00121 switch (iChoice) {
00122 case kSetVisibleMO:
00123 {
00124 FWModelId id = *(m_selectionManager->selected().begin());
00125 const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
00126 for_each(m_selectionManager->selected().begin(),
00127 m_selectionManager->selected().end(),
00128 change_visibility(!props.isVisible())
00129 );
00130 break;
00131 }
00132 case kSetColorMO:
00133 {
00134 FWModelId id = *(m_selectionManager->selected().begin());
00135 createColorPopup();
00136 m_colorPopup->SetName("Selected");
00137 std::vector<Color_t> colors;
00138 m_colorManager->fillLimitedColors(colors);
00139 m_colorPopup->ResetColors(colors, m_colorManager->backgroundColorIndex()==FWColorManager::kBlackIndex);
00140 m_colorPopup->SetSelection(id.item()->modelInfo(id.index()).displayProperties().color());
00141 m_colorPopup->PlacePopup(m_x, m_y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
00142 break;
00143 }
00144 case kPrint:
00145 {
00146 FWModelId id = *(m_selectionManager->selected().begin());
00147 edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
00148 edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
00149
00150
00151
00152
00153
00154
00155
00156 const char* cmd = Form("FWGUIManager::OStream() << *(%s*)%p ;", id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
00157
00158 std::cout << cmd << std::endl;
00159 gROOT->ProcessLine(cmd);
00160
00161
00162 break;
00163 }
00164 case kOpenObjectControllerMO:
00165 {
00166 m_guiManager->showModelPopup();
00167 break;
00168 }
00169 case kOpenCollectionControllerMO:
00170 {
00171 m_guiManager->showEDIFrame();
00172 break;
00173 }
00174 case kOpenDetailViewMO:
00175 case kViewOptionsMO:
00176 default:
00177 {
00178 if(iChoice>=kViewOptionsMO) {
00179 assert(0!=m_viewHander);
00180 m_viewHander->select(iChoice-kViewOptionsMO, *(m_selectionManager->selected().begin()), m_x, m_y);
00181 }else {
00182 assert(iChoice<kOpenObjectControllerMO);
00183 assert(m_selectionManager->selected().size()==1);
00184 std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
00185 assert(0!=viewChoices.size());
00186 m_detailViewManager->openDetailViewFor(*(m_selectionManager->selected().begin()),viewChoices[iChoice-kOpenDetailViewMO]) ;
00187 }
00188 break;
00189 }
00190 break;
00191 }
00192 }
00193
00194 void
00195 FWModelContextMenuHandler::colorChangeRequested(Color_t color)
00196 {
00197 for(std::set<FWModelId>::const_iterator it =m_selectionManager->selected().begin(),
00198 itEnd = m_selectionManager->selected().end();
00199 it != itEnd;
00200 ++it) {
00201 FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
00202 changeProperties.setColor(color);
00203 it->item()->setDisplayProperties(it->index(), changeProperties);
00204 }
00205 }
00206
00207 void
00208 FWModelContextMenuHandler::addViewEntry(const char* iEntryName, int iEntryIndex, bool enabled)
00209 {
00210 if(!m_viewSeperator) {
00211 m_modelPopup->AddSeparator(m_afterViewSeperator);
00212 m_viewSeperator=dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
00213 assert(0!=m_viewSeperator);
00214 }
00215
00216 if(static_cast<int>(m_nViewEntries) > iEntryIndex) {
00217 m_modelPopup->GetEntry(iEntryIndex+kViewOptionsMO)->GetLabel()->SetString(iEntryName);
00218 if(enabled)
00219 m_modelPopup->EnableEntry(iEntryIndex+kViewOptionsMO);
00220 else
00221 m_modelPopup->DisableEntry(iEntryIndex+kViewOptionsMO);
00222
00223 } else {
00224 assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
00225 m_modelPopup->AddEntry(iEntryName,kViewOptionsMO+iEntryIndex,0,0,m_viewSeperator);
00226
00227 if (enabled)
00228 m_modelPopup->EnableEntry(kViewOptionsMO+iEntryIndex);
00229 else
00230 m_modelPopup->DisableEntry(kViewOptionsMO+iEntryIndex);
00231
00232 ++m_nViewEntries;
00233 }
00234
00235 }
00236
00237
00238
00239 void
00240 FWModelContextMenuHandler::showSelectedModelContext(Int_t iX, Int_t iY, FWViewContextMenuHandlerBase* iHandler) const
00241 {
00242 m_viewHander=iHandler;
00243 assert(!m_selectionManager->selected().empty());
00244 createModelContext();
00245
00246
00247 FWModelId id = *(m_selectionManager->selected().begin());
00248 const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
00249 if(props.isVisible()) {
00250 m_modelPopup->CheckEntry(kSetVisibleMO);
00251 }else {
00252 m_modelPopup->UnCheckEntry(kSetVisibleMO);
00253 }
00254
00255
00256 if( m_selectionManager->selected().size()==1 ) {
00257 {
00258 edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
00259 edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
00260 edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
00261 if ( rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), edm::TypeModifiers::Const), edm::TypeModifiers::NoMod, inh))
00262 {
00263 m_modelPopup->EnableEntry(kPrint);
00264
00265 }
00266 else
00267 {
00268 m_modelPopup->DisableEntry(kPrint);
00269
00270 }
00271 }
00272
00273 std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
00274 if(viewChoices.size()>0) {
00275 if(m_nDetailViewEntries < viewChoices.size()) {
00276 for(unsigned int index = m_nDetailViewEntries;
00277 index != viewChoices.size();
00278 ++index) {
00279 m_modelPopup->AddEntry(kOpenDetailView,kOpenDetailViewMO+index,0,0,m_seperator);
00280 }
00281 m_nDetailViewEntries=viewChoices.size();
00282 }
00283 const std::string kStart("Open ");
00284 const std::string kEnd(" Detail View ...");
00285 for(unsigned int index=0; index != viewChoices.size(); ++index) {
00286 m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+viewChoices[index]+kEnd).c_str());
00287 m_modelPopup->EnableEntry(index+kOpenDetailViewMO);
00288 }
00289 for(unsigned int i =viewChoices.size(); i <m_nDetailViewEntries; ++i) {
00290 m_modelPopup->HideEntry(kOpenDetailViewMO+i);
00291 }
00292
00293 } else {
00294 for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
00295 m_modelPopup->HideEntry(kOpenDetailViewMO+i);
00296 }
00297 }
00298 } else {
00299 for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
00300 m_modelPopup->HideEntry(kOpenDetailViewMO+i);
00301 }
00302 }
00303
00304 m_modelPopup->DeleteEntry(m_viewSeperator);
00305 m_viewSeperator=0;
00306
00307 for(unsigned int i=0; i<m_nViewEntries; ++i) {
00308 m_modelPopup->HideEntry(kViewOptionsMO+i);
00309 }
00310 if(m_viewHander) {
00311 m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this), *(m_selectionManager->selected().begin()));
00312 }
00313
00314 m_x=iX;
00315 m_y=iY;
00316 m_modelPopup->PlaceMenu(iX,iY,false,true);
00317 }
00318
00319 void
00320 FWModelContextMenuHandler::createModelContext() const
00321 {
00322 if(0==m_modelPopup) {
00323 m_modelPopup = new FWPopupMenu();
00324
00325 m_modelPopup->AddEntry("Set Visible",kSetVisibleMO);
00326 m_modelPopup->AddEntry("Set Color ...",kSetColorMO);
00327 m_modelPopup->AddEntry("Print ...",kPrint);
00328 m_modelPopup->AddEntry(kOpenDetailView,kOpenDetailViewMO);
00329 m_nDetailViewEntries=1;
00330 m_modelPopup->AddSeparator();
00331 m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
00332 assert(0!=m_seperator);
00333 m_modelPopup->AddEntry("Open Object Controller ...",kOpenObjectControllerMO);
00334 m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
00335 m_modelPopup->AddEntry("Open Collection Controller ...",kOpenCollectionControllerMO);
00336
00337 m_modelPopup->Connect("Activated(Int_t)",
00338 "FWModelContextMenuHandler",
00339 const_cast<FWModelContextMenuHandler*>(this),
00340 "chosenItem(Int_t)");
00341 }
00342 }
00343
00344 void
00345 FWModelContextMenuHandler::createColorPopup() const
00346 {
00347 if(0==m_colorPopup) {
00348 std::vector<Color_t> colors;
00349 m_colorManager->fillLimitedColors(colors);
00350
00351 m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
00352 m_colorPopup->InitContent("", colors);
00353 m_colorPopup->Connect("ColorSelected(Color_t)","FWModelContextMenuHandler", const_cast<FWModelContextMenuHandler*>(this), "colorChangeRequested(Color_t)");
00354 }
00355 }
00356
00357
00358
00359
00360
00361 ClassImp(FWModelContextMenuHandler)