CMS 3D CMS Logo

FWModelContextMenuHandler.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: Core
4 // Class : FWModelContextMenuHandler
5 //
6 // Implementation:
7 // <Notes on implementation>
8 //
9 // Original Author: Chris Jones
10 // Created: Tue Sep 22 13:26:04 CDT 2009
11 //
12 
13 // system include files
14 #include <cassert>
15 #include <iostream>
16 #include "TGMenu.h"
17 #include "KeySymbols.h"
18 
22 #include "TClass.h"
23 #include "TError.h"
24 
25 // user include files
35 
36 //
37 // constants, enums and typedefs
38 //
42  // kPrint,
50 };
51 
52 //
53 // static data member definitions
54 //
55 static const char* const kOpenDetailView = "Open Detailed View ...";
56 
57 //
58 // constructors and destructor
59 //
61  FWDetailViewManager* iDVM,
62  FWColorManager* iCM,
63  FWGUIManager* iGM)
64  : m_modelPopup(nullptr),
65  m_colorPopup(nullptr),
66  m_selectionManager(iSM),
67  m_detailViewManager(iDVM),
68  m_colorManager(iCM),
69  m_guiManager(iGM),
70  m_seperator(nullptr),
71  m_viewSeperator(nullptr),
72  m_afterViewSeperator(nullptr),
73  m_x(0),
74  m_y(0),
75  m_nDetailViewEntries(0),
76  m_nViewEntries(0),
77  m_viewHander(nullptr) {}
78 
79 // FWModelContextMenuHandler::FWModelContextMenuHandler(const FWModelContextMenuHandler& rhs)
80 // {
81 // // do actual copying here;
82 // }
83 
85 
86 //
87 // assignment operators
88 //
89 // const FWModelContextMenuHandler& FWModelContextMenuHandler::operator=(const FWModelContextMenuHandler& rhs)
90 // {
91 // //An exception safe implementation is
92 // FWModelContextMenuHandler temp(rhs);
93 // swap(rhs);
94 //
95 // return *this;
96 // }
97 
98 //
99 // member functions
100 //
101 #include "TROOT.h"
102 namespace {
103  class change_visibility {
104  public:
105  change_visibility(bool iIsVisible) : m_isVisible(iIsVisible) {}
106  void operator()(const FWModelId& iID) const {
107  FWDisplayProperties p = iID.item()->modelInfo(iID.index()).displayProperties();
108  p.setIsVisible(m_isVisible);
109  iID.item()->setDisplayProperties(iID.index(), p);
110  }
111  bool m_isVisible;
112  };
113 } // namespace
115  assert(!m_selectionManager->selected().empty());
116  switch (iChoice) {
117  case kSetVisibleMO: {
118  FWModelId id = *(m_selectionManager->selected().begin());
119  for_each(m_selectionManager->selected().begin(),
120  m_selectionManager->selected().end(),
121  change_visibility(!id.item()->modelInfo(id.index()).displayProperties().isVisible()));
122  break;
123  }
124  case kSetColorMO: {
125  FWModelId id = *(m_selectionManager->selected().begin());
127  m_colorPopup->SetName("Selected");
128  std::vector<Color_t> colors;
131  m_colorPopup->SetSelection(id.item()->modelInfo(id.index()).displayProperties().color());
132  m_colorPopup->PlacePopup(m_x, m_y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
133  break;
134  } /*
135  case kPrint:
136  {
137  FWModelId id = *(m_selectionManager->selected().begin());
138  edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
139  edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
140 
141  // void* xx = &std::cout;
142  //const std::vector<void*> j(1, xx);
143  //edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
144  //edm::FunctionWithDict m = rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), edm::TypeModifiers::Const), edm::TypeModifiers::NoMod , inh))
145  //m.Invoke(o, 0, j);
146 
147  const char* cmd = Form("FWGUIManager::OStream() << *(%s*)%p ;", id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
148  //const char* cmd = Form("*((std::ostream*)%p) << (%s*)%p ;", (void*)(&std::cout), id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
149  std::cout << cmd << std::endl;
150  gROOT->ProcessLine(cmd);
151 
152 
153  break;
154  }*/
157  break;
158  }
161  break;
162  }
163  case kOpen3DRegion: {
165  break;
166  }
167  case kOpenDetailViewMO:
168  case kViewOptionsMO:
169  default: {
170  if (iChoice >= kViewOptionsMO) {
171  assert(nullptr != m_viewHander);
172  m_viewHander->select(iChoice - kViewOptionsMO, *(m_selectionManager->selected().begin()), m_x, m_y);
173  } else {
174  assert(iChoice < kOpenObjectControllerMO);
175  assert(m_selectionManager->selected().size() == 1);
176  std::vector<std::string> viewChoices =
178  assert(!viewChoices.empty());
180  viewChoices[iChoice - kOpenDetailViewMO]);
181  }
182  break;
183  } break;
184  }
185 }
186 
188  for (std::set<FWModelId>::const_iterator it = m_selectionManager->selected().begin(),
189  itEnd = m_selectionManager->selected().end();
190  it != itEnd;
191  ++it) {
192  FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
193  changeProperties.setColor(color);
194  it->item()->setDisplayProperties(it->index(), changeProperties);
195  }
196 }
197 
198 void FWModelContextMenuHandler::addViewEntry(const char* iEntryName, int iEntryIndex, bool enabled) {
199  if (!m_viewSeperator) {
200  m_modelPopup->AddSeparator(m_afterViewSeperator);
201  m_viewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
202  assert(nullptr != m_viewSeperator);
203  }
204 
205  if (static_cast<int>(m_nViewEntries) > iEntryIndex) {
206  m_modelPopup->GetEntry(iEntryIndex + kViewOptionsMO)->GetLabel()->SetString(iEntryName);
207  if (enabled)
208  m_modelPopup->EnableEntry(iEntryIndex + kViewOptionsMO);
209  else
210  m_modelPopup->DisableEntry(iEntryIndex + kViewOptionsMO);
211 
212  } else {
213  assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
214  m_modelPopup->AddEntry(iEntryName, kViewOptionsMO + iEntryIndex, nullptr, nullptr, m_viewSeperator);
215 
216  if (enabled)
217  m_modelPopup->EnableEntry(kViewOptionsMO + iEntryIndex);
218  else
219  m_modelPopup->DisableEntry(kViewOptionsMO + iEntryIndex);
220 
221  ++m_nViewEntries;
222  }
223 }
224 //
225 // const member functions
226 //
228  Int_t iY,
229  FWViewContextMenuHandlerBase* iHandler) const {
230  m_viewHander = iHandler;
231  assert(!m_selectionManager->selected().empty());
233 
234  //setup the menu based on this object
235  FWModelId id = *(m_selectionManager->selected().begin());
236  if (id.item()->modelInfo(id.index()).displayProperties().isVisible()) {
237  m_modelPopup->CheckEntry(kSetVisibleMO);
238  } else {
239  m_modelPopup->UnCheckEntry(kSetVisibleMO);
240  }
241 
242  if (m_selectionManager->selected().size() == 1) {
243  {
244  //edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
245  //edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
246  //edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
247  //if ( rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), Long_t(kIsConstant)), 0, inh))
248  //{
249  //m_modelPopup->EnableEntry(kPrint);
250  // std::cout << "Enable " <<std::endl;
251  //}
252  //else
253  //{
254  m_modelPopup->DisableEntry(kPrint);
255  // printf("Disable print \n");
256  //}
257  }
258  //add the detail view entries
259  std::vector<std::string> viewChoices =
261  if (!viewChoices.empty()) {
262  if (m_nDetailViewEntries < viewChoices.size()) {
263  for (unsigned int index = m_nDetailViewEntries; index != viewChoices.size(); ++index) {
264  m_modelPopup->AddEntry(kOpenDetailView, kOpenDetailViewMO + index, nullptr, nullptr, m_seperator);
265  }
266  m_nDetailViewEntries = viewChoices.size();
267  }
268  const std::string kStart("Open ");
269  const std::string kEnd(" Detail View ...");
270  for (unsigned int index = 0; index != viewChoices.size(); ++index) {
271  m_modelPopup->EnableEntry(index + kOpenDetailViewMO); // need to call this to make it visible
272  if (viewChoices[index][0] != '!') {
274  ->GetLabel()
275  ->SetString((kStart + viewChoices[index] + kEnd).c_str());
276  } else {
278  ->GetLabel()
279  ->SetString((kStart + &viewChoices[index][1] + kEnd).c_str());
280  m_modelPopup->DisableEntry(index + kOpenDetailViewMO);
281  }
282  }
283  for (unsigned int i = viewChoices.size(); i < m_nDetailViewEntries; ++i) {
284  m_modelPopup->HideEntry(kOpenDetailViewMO + i);
285  }
286 
287  } else {
288  for (unsigned int i = 0; i < m_nDetailViewEntries; ++i) {
289  m_modelPopup->HideEntry(kOpenDetailViewMO + i);
290  }
291  }
292  } else {
293  for (unsigned int i = 0; i < m_nDetailViewEntries; ++i) {
294  m_modelPopup->HideEntry(kOpenDetailViewMO + i);
295  }
296  }
297  //add necessary entries from the view
298  m_modelPopup->DeleteEntry(m_viewSeperator);
299  m_viewSeperator = nullptr;
300 
301  for (unsigned int i = 0; i < m_nViewEntries; ++i) {
302  m_modelPopup->HideEntry(kViewOptionsMO + i);
303  }
304  if (m_viewHander) {
305  m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this), *(m_selectionManager->selected().begin()));
306  }
307 
308  m_x = iX;
309  m_y = iY;
310  m_modelPopup->PlaceMenu(iX, iY, false, true);
311 }
312 
314  if (nullptr == m_modelPopup) {
315  m_modelPopup = new FWPopupMenu();
316 
317  m_modelPopup->AddEntry("Set Visible", kSetVisibleMO);
318  m_modelPopup->AddEntry("Set Color ...", kSetColorMO);
319  // m_modelPopup->AddEntry("Print ...",kPrint);
322  m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
323  assert(nullptr != m_seperator);
324  m_modelPopup->AddEntry("Open 3D Region ...", kOpen3DRegion);
325  m_modelPopup->AddSeparator();
326  m_modelPopup->AddEntry("Open Object Controller ...", kOpenObjectControllerMO);
327  m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
328  m_modelPopup->AddEntry("Open Collection Controller ...", kOpenCollectionControllerMO);
329 
330  m_modelPopup->Connect("Activated(Int_t)",
331  "FWModelContextMenuHandler",
332  const_cast<FWModelContextMenuHandler*>(this),
333  "chosenItem(Int_t)");
334  }
335 }
336 
338  if (nullptr == m_colorPopup) {
339  std::vector<Color_t> colors;
341 
342  m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
344  m_colorPopup->Connect("ColorSelected(Color_t)",
345  "FWModelContextMenuHandler",
346  const_cast<FWModelContextMenuHandler*>(this),
347  "colorChangeRequested(Color_t)");
348  }
349 }
350 
351 //
352 // static member functions
353 //
354 
FWModelContextMenuHandler::m_colorPopup
FWColorPopup * m_colorPopup
Definition: FWModelContextMenuHandler.h:64
FWColorPopup::ResetColors
void ResetColors(const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
Definition: FWColorSelect.cc:216
FWEventItem::modelInfo
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
mps_fire.i
i
Definition: mps_fire.py:428
FWGUIManager
Definition: FWGUIManager.h:95
FWModelContextMenuHandler::m_seperator
TGMenuEntry * m_seperator
Definition: FWModelContextMenuHandler.h:69
colors
vector< Color_t > colors
Definition: trackSplitPlot.h:37
colors
Definition: colors.py:1
FWViewContextMenuHandlerBase::select
virtual void select(int iEntryIndex, const FWModelId &id, int iX, int iY)=0
FWColorPopup::SetName
void SetName(const char *iName) override
Definition: FWColorSelect.cc:274
FWGUIManager::showModelPopup
void showModelPopup()
Definition: FWGUIManager.cc:607
ClassImp
ClassImp(FWModelContextMenuHandler)
FWColorPopup::SetSelection
void SetSelection(Color_t)
Definition: FWColorSelect.cc:276
FWModelId
Definition: FWModelId.h:28
FWViewContextMenuHandlerBase
Definition: FWViewContextMenuHandlerBase.h:29
FWModelContextMenuHandler::m_nDetailViewEntries
unsigned int m_nDetailViewEntries
Definition: FWModelContextMenuHandler.h:74
FWModelContextMenuHandler
Definition: FWModelContextMenuHandler.h:37
FWDetailViewManager::openDetailViewFor
void openDetailViewFor(const FWModelId &, const std::string &)
Definition: FWDetailViewManager.cc:71
cms::cuda::assert
assert(be >=bs)
TypeWithDict.h
FWModelContextMenuHandler::m_modelPopup
TGPopupMenu * m_modelPopup
Definition: FWModelContextMenuHandler.h:63
FWColorManager::backgroundColorIndex
BackgroundColorIndex backgroundColorIndex() const
Definition: FWColorManager.cc:260
FWGUIManager::open3DRegion
void open3DRegion()
Definition: FWGUIManager.cc:565
FWModelId::item
const FWEventItem * item() const
Definition: FWModelId.h:39
FWModelContextMenuHandler::addViewEntry
void addViewEntry(const char *, int, bool enabled=true)
Definition: FWModelContextMenuHandler.cc:198
FWColorSelect.h
kOpenCollectionControllerMO
Definition: FWModelContextMenuHandler.cc:47
kSetColorMO
Definition: FWModelContextMenuHandler.cc:41
ObjectWithDict.h
FWDetailViewManager
Definition: FWDetailViewManager.h:35
FWModelContextMenuHandler::m_colorManager
FWColorManager * m_colorManager
Definition: FWModelContextMenuHandler.h:67
FWSelectionManager.h
FWColorManager.h
FWSelectionManager::selected
const std::set< FWModelId > & selected() const
Definition: FWSelectionManager.cc:168
FWModelContextMenuHandler::~FWModelContextMenuHandler
virtual ~FWModelContextMenuHandler()
Definition: FWModelContextMenuHandler.cc:84
FWModelId::index
int index() const
Definition: FWModelId.h:41
kOpenDetailViewMO
Definition: FWModelContextMenuHandler.cc:43
FWDetailViewManager::detailViewsFor
std::vector< std::string > detailViewsFor(const FWModelId &) const
Definition: FWDetailViewManager.cc:112
FWModelContextMenuHandler::m_x
Int_t m_x
Definition: FWModelContextMenuHandler.h:72
FWGUIManager::showEDIFrame
void showEDIFrame(int iInfoToShow=-1)
Allowed values are -1 or ones from FWDataCategories enum.
Definition: FWGUIManager.cc:557
FWModelContextMenuHandler::m_detailViewManager
FWDetailViewManager * m_detailViewManager
Definition: FWModelContextMenuHandler.h:66
FWDisplayProperties::setColor
void setColor(Color_t iColor)
Definition: FWDisplayProperties.h:62
FWModelContextMenuHandler::FWModelContextMenuHandler
FWModelContextMenuHandler(FWSelectionManager *, FWDetailViewManager *, FWColorManager *, FWGUIManager *)
Definition: FWModelContextMenuHandler.cc:60
AlCaHLTBitMon_ParallelJobs.p
def p
Definition: AlCaHLTBitMon_ParallelJobs.py:153
FWModelContextMenuHandler::m_afterViewSeperator
TGMenuEntry * m_afterViewSeperator
Definition: FWModelContextMenuHandler.h:71
kLastOfMO
Definition: FWModelContextMenuHandler.cc:49
FWSelectionManager
Definition: FWSelectionManager.h:34
MenuOptions
MenuOptions
Definition: FWModelContextMenuHandler.cc:39
FWPopupMenu
Definition: FWPopupMenu.cc:5
FWModelContextMenuHandler::colorChangeRequested
void colorChangeRequested(Color_t)
Definition: FWModelContextMenuHandler.cc:187
kOpen3DRegion
Definition: FWModelContextMenuHandler.cc:45
FWColorPopup::PlacePopup
void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
Definition: FWColorSelect.cc:229
kOpenDetailView
static const char *const kOpenDetailView
Definition: FWModelContextMenuHandler.cc:55
FWPopupMenu.cc
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
FWModelContextMenuHandler::m_y
Int_t m_y
Definition: FWModelContextMenuHandler.h:73
FWModelContextMenuHandler::m_guiManager
FWGUIManager * m_guiManager
Definition: FWModelContextMenuHandler.h:68
FWColorManager
Definition: FWColorManager.h:45
FWModelContextMenuHandler.h
FWEventItem::setDisplayProperties
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:247
FWColorPopup
Definition: FWColorSelect.h:68
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
FWEventItem.h
kSetVisibleMO
Definition: FWModelContextMenuHandler.cc:40
FWViewContextMenuHandlerBase.h
FWDisplayProperties
Definition: FWDisplayProperties.h:28
FWModelContextMenuHandler::m_viewSeperator
TGMenuEntry * m_viewSeperator
Definition: FWModelContextMenuHandler.h:70
FWDetailViewManager.h
FWModelContextMenuHandler::createModelContext
void createModelContext() const
Definition: FWModelContextMenuHandler.cc:313
FWColorManager::fillLimitedColors
void fillLimitedColors(std::vector< Color_t > &cv) const
Definition: FWColorManager.cc:253
FWModelContextMenuHandler::m_viewHander
FWViewContextMenuHandlerBase * m_viewHander
Definition: FWModelContextMenuHandler.h:76
FWModelContextMenuHandler::showSelectedModelContext
void showSelectedModelContext(Int_t iX, Int_t iY, FWViewContextMenuHandlerBase *) const
NOTE: iX and iY are in global coordinates.
Definition: FWModelContextMenuHandler.cc:227
FWColorManager::kBlackIndex
Definition: FWColorManager.h:73
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
kViewOptionsMO
Definition: FWModelContextMenuHandler.cc:48
kOpenObjectControllerMO
Definition: FWModelContextMenuHandler.cc:46
FWModelContextMenuHandler::m_nViewEntries
unsigned int m_nViewEntries
Definition: FWModelContextMenuHandler.h:75
FWModelContextMenuHandler::chosenItem
void chosenItem(Int_t)
Definition: FWModelContextMenuHandler.cc:114
FWModelContextMenuHandler::createColorPopup
void createColorPopup() const
Definition: FWModelContextMenuHandler.cc:337
FWColorPopup::InitContent
void InitContent(const char *name, const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
Definition: FWColorSelect.cc:165
FWViewContextMenuHandlerBase::addTo
void addTo(FWModelContextMenuHandler &, const FWModelId &id)
Definition: FWViewContextMenuHandlerBase.cc:61
FWModelContextMenuHandler::m_selectionManager
FWSelectionManager * m_selectionManager
Definition: FWModelContextMenuHandler.h:65
FunctionWithDict.h
kAfterOpenDetailViewMO
Definition: FWModelContextMenuHandler.cc:44
FWGUIManager.h
pixel_dqm_sourceclient-live_cfg.enabled
enabled
Definition: pixel_dqm_sourceclient-live_cfg.py:139