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(FWSelectionManager *, FWDetailViewManager *, FWColorManager *, FWGUIManager *)
void setColor(Color_t iColor)
void showModelPopup()
void InitContent(const char *name, const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
FWSelectionManager * m_selectionManager
void open3DRegion()
int index() const
Definition: FWModelId.h:41
void SetName(const char *iName) override
std::vector< std::string > detailViewsFor(const FWModelId &) const
assert(be >=bs)
void showEDIFrame(int iInfoToShow=-1)
Allowed values are -1 or ones from FWDataCategories enum.
constexpr bool enabled
Definition: SoACommon.h:65
void showSelectedModelContext(Int_t iX, Int_t iY, FWViewContextMenuHandlerBase *) const
NOTE: iX and iY are in global coordinates.
virtual void select(int iEntryIndex, const FWModelId &id, int iX, int iY)=0
BackgroundColorIndex backgroundColorIndex() const
void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
static const char *const kOpenDetailView
void ResetColors(const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
void SetSelection(Color_t)
const FWEventItem * item() const
Definition: FWModelId.h:39
FWViewContextMenuHandlerBase * m_viewHander
void addTo(FWModelContextMenuHandler &, const FWModelId &id)
FWDetailViewManager * m_detailViewManager
void addViewEntry(const char *, int, bool enabled=true)
void openDetailViewFor(const FWModelId &, const std::string &)
const Int_t colors[8]
Definition: colors.py:1
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:247
ClassImp(FWModelContextMenuHandler)
const std::set< FWModelId > & selected() const
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:446
void fillLimitedColors(std::vector< Color_t > &cv) const