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 //
54 // static data member definitions
55 //
56 static const char* const kOpenDetailView = "Open Detailed View ...";
57 
58 //
59 // constructors and destructor
60 //
62  FWDetailViewManager* iDVM,
63  FWColorManager* iCM,
64  FWGUIManager* iGM):
65 m_modelPopup(nullptr),
66 m_colorPopup(nullptr),
67 m_selectionManager(iSM),
68 m_detailViewManager(iDVM),
69 m_colorManager(iCM),
70 m_guiManager(iGM),
71 m_seperator(nullptr),
72 m_viewSeperator(nullptr),
73 m_afterViewSeperator(nullptr),
74 m_x(0),
75 m_y(0),
76 m_nDetailViewEntries(0),
77 m_nViewEntries(0),
78 m_viewHander(nullptr)
79 {
80 }
81 
82 // FWModelContextMenuHandler::FWModelContextMenuHandler(const FWModelContextMenuHandler& rhs)
83 // {
84 // // do actual copying here;
85 // }
86 
88 {
89  delete m_modelPopup;
90 }
91 
92 //
93 // assignment operators
94 //
95 // const FWModelContextMenuHandler& FWModelContextMenuHandler::operator=(const FWModelContextMenuHandler& rhs)
96 // {
97 // //An exception safe implementation is
98 // FWModelContextMenuHandler temp(rhs);
99 // swap(rhs);
100 //
101 // return *this;
102 // }
103 
104 //
105 // member functions
106 //
107 #include "TROOT.h"
108 namespace {
109  class change_visibility {
110  public:
111  change_visibility(bool iIsVisible): m_isVisible(iIsVisible) {}
112  void operator()(const FWModelId& iID) const {
113  FWDisplayProperties p = iID.item()->modelInfo(iID.index()).displayProperties();
114  p.setIsVisible(m_isVisible);
115  iID.item()->setDisplayProperties(iID.index(), p);
116  }
117  bool m_isVisible;
118  };
119 }
120 void
122 {
123  assert(!m_selectionManager->selected().empty());
124  switch (iChoice) {
125  case kSetVisibleMO:
126  {
127  FWModelId id = *(m_selectionManager->selected().begin());
128  for_each(m_selectionManager->selected().begin(),
129  m_selectionManager->selected().end(),
130  change_visibility(!id.item()->modelInfo(id.index()).displayProperties().isVisible())
131  );
132  break;
133  }
134  case kSetColorMO:
135  {
136  FWModelId id = *(m_selectionManager->selected().begin());
138  m_colorPopup->SetName("Selected");
139  std::vector<Color_t> colors;
142  m_colorPopup->SetSelection(id.item()->modelInfo(id.index()).displayProperties().color());
143  m_colorPopup->PlacePopup(m_x, m_y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
144  break;
145  }/*
146  case kPrint:
147  {
148  FWModelId id = *(m_selectionManager->selected().begin());
149  edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
150  edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
151 
152  // void* xx = &std::cout;
153  //const std::vector<void*> j(1, xx);
154  //edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
155  //edm::FunctionWithDict m = rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), edm::TypeModifiers::Const), edm::TypeModifiers::NoMod , inh))
156  //m.Invoke(o, 0, j);
157 
158  const char* cmd = Form("FWGUIManager::OStream() << *(%s*)%p ;", id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
159  //const char* cmd = Form("*((std::ostream*)%p) << (%s*)%p ;", (void*)(&std::cout), id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
160  std::cout << cmd << std::endl;
161  gROOT->ProcessLine(cmd);
162 
163 
164  break;
165  }*/
167  {
169  break;
170  }
172  {
174  break;
175  }
176  case kOpen3DRegion:
177  {
179  break;
180  }
181  case kOpenDetailViewMO:
182  case kViewOptionsMO:
183  default:
184  {
185  if(iChoice>=kViewOptionsMO) {
186  assert(nullptr!=m_viewHander);
188  }else {
189  assert(iChoice<kOpenObjectControllerMO);
190  assert(m_selectionManager->selected().size()==1);
191  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
192  assert(!viewChoices.empty());
194  }
195  break;
196  }
197  break;
198  }
199 }
200 
201 void
203 {
204  for(std::set<FWModelId>::const_iterator it =m_selectionManager->selected().begin(),
205  itEnd = m_selectionManager->selected().end();
206  it != itEnd;
207  ++it) {
208  FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
209  changeProperties.setColor(color);
210  it->item()->setDisplayProperties(it->index(), changeProperties);
211  }
212 }
213 
214 void
215 FWModelContextMenuHandler::addViewEntry(const char* iEntryName, int iEntryIndex, bool enabled)
216 {
217  if(!m_viewSeperator) {
218  m_modelPopup->AddSeparator(m_afterViewSeperator);
219  m_viewSeperator=dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
220  assert(nullptr!=m_viewSeperator);
221  }
222 
223  if(static_cast<int>(m_nViewEntries) > iEntryIndex) {
224  m_modelPopup->GetEntry(iEntryIndex+kViewOptionsMO)->GetLabel()->SetString(iEntryName);
225  if(enabled)
226  m_modelPopup->EnableEntry(iEntryIndex+kViewOptionsMO);
227  else
228  m_modelPopup->DisableEntry(iEntryIndex+kViewOptionsMO);
229 
230  } else {
231  assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
232  m_modelPopup->AddEntry(iEntryName,kViewOptionsMO+iEntryIndex,nullptr,nullptr,m_viewSeperator);
233 
234  if (enabled)
235  m_modelPopup->EnableEntry(kViewOptionsMO+iEntryIndex);
236  else
237  m_modelPopup->DisableEntry(kViewOptionsMO+iEntryIndex);
238 
239  ++m_nViewEntries;
240  }
241 
242 }
243 //
244 // const member functions
245 //
246 void
248 {
249  m_viewHander=iHandler;
250  assert(!m_selectionManager->selected().empty());
252 
253  //setup the menu based on this object
254  FWModelId id = *(m_selectionManager->selected().begin());
255  if(id.item()->modelInfo(id.index()).displayProperties().isVisible()) {
256  m_modelPopup->CheckEntry(kSetVisibleMO);
257  }else {
258  m_modelPopup->UnCheckEntry(kSetVisibleMO);
259  }
260 
261 
262  if( m_selectionManager->selected().size()==1 ) {
263  {
264  //edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
265  //edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
266  //edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
267  //if ( rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), Long_t(kIsConstant)), 0, inh))
268  //{
269  //m_modelPopup->EnableEntry(kPrint);
270  // std::cout << "Enable " <<std::endl;
271  //}
272  //else
273  //{
274  m_modelPopup->DisableEntry(kPrint);
275  // printf("Disable print \n");
276  //}
277  }
278  //add the detail view entries
279  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
280  if(!viewChoices.empty()) {
281  if(m_nDetailViewEntries < viewChoices.size()) {
282  for(unsigned int index = m_nDetailViewEntries;
283  index != viewChoices.size();
284  ++index) {
286  }
287  m_nDetailViewEntries=viewChoices.size();
288  }
289  const std::string kStart("Open ");
290  const std::string kEnd(" Detail View ...");
291  for(unsigned int index=0; index != viewChoices.size(); ++index) {
292  m_modelPopup->EnableEntry(index+kOpenDetailViewMO); // need to call this to make it visible
293  if ( viewChoices[index][0] != '!') {
294  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+viewChoices[index]+kEnd).c_str());
295  }
296  else
297  {
298  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+&viewChoices[index][1]+kEnd).c_str());
299  m_modelPopup->DisableEntry(index+kOpenDetailViewMO);
300  }
301  }
302  for(unsigned int i =viewChoices.size(); i <m_nDetailViewEntries; ++i) {
303  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
304  }
305 
306  } else {
307  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
308  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
309  }
310  }
311  } else {
312  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
313  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
314  }
315  }
316  //add necessary entries from the view
317  m_modelPopup->DeleteEntry(m_viewSeperator);
318  m_viewSeperator=nullptr;
319 
320  for(unsigned int i=0; i<m_nViewEntries; ++i) {
321  m_modelPopup->HideEntry(kViewOptionsMO+i);
322  }
323  if(m_viewHander) {
324  m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this), *(m_selectionManager->selected().begin()));
325  }
326 
327  m_x=iX;
328  m_y=iY;
329  m_modelPopup->PlaceMenu(iX,iY,false,true);
330 }
331 
332 void
334 {
335  if(nullptr==m_modelPopup) {
336  m_modelPopup = new FWPopupMenu();
337 
338  m_modelPopup->AddEntry("Set Visible",kSetVisibleMO);
339  m_modelPopup->AddEntry("Set Color ...",kSetColorMO);
340  // m_modelPopup->AddEntry("Print ...",kPrint);
343  m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
344  assert(nullptr!=m_seperator);
345  m_modelPopup->AddEntry("Open 3D Region ...",kOpen3DRegion);
346  m_modelPopup->AddSeparator();
347  m_modelPopup->AddEntry("Open Object Controller ...",kOpenObjectControllerMO);
348  m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
349  m_modelPopup->AddEntry("Open Collection Controller ...",kOpenCollectionControllerMO);
350 
351  m_modelPopup->Connect("Activated(Int_t)",
352  "FWModelContextMenuHandler",
353  const_cast<FWModelContextMenuHandler*>(this),
354  "chosenItem(Int_t)");
355  }
356 }
357 
358 void
360 {
361  if(nullptr==m_colorPopup) {
362  std::vector<Color_t> colors;
364 
365  m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
366  m_colorPopup->InitContent("", colors);
367  m_colorPopup->Connect("ColorSelected(Color_t)","FWModelContextMenuHandler", const_cast<FWModelContextMenuHandler*>(this), "colorChangeRequested(Color_t)");
368  }
369 }
370 
371 //
372 // static member functions
373 //
374 
const std::set< FWModelId > & selected() const
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()
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:278
void fillLimitedColors(std::vector< Color_t > &cv) const
void SetName(const char *iName) override
#define nullptr
void showEDIFrame(int iInfoToShow=-1)
Allowed values are -1 or ones from FWDataCategories enum.
virtual void select(int iEntryIndex, const FWModelId &id, int iX, int iY)=0
void PlacePopup(Int_t x, Int_t y, UInt_t w, UInt_t h)
ClassImp(AliDaqEventHeader) ClassImp(AliDaqPosition2D) ClassImp(AliDaqPositionCOPS) ClassImp(AliDaqTilt) ClassImp(AliDaqDistance) ClassImp(AliDaqTemperature) ClassImp(CocoaDaqRootEvent) CocoaDaqRootEvent
vector< Color_t > colors
int index() const
Definition: FWModelId.h:49
static const char *const kOpenDetailView
BackgroundColorIndex backgroundColorIndex() const
void ResetColors(const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
void SetSelection(Color_t)
FWViewContextMenuHandlerBase * m_viewHander
void showSelectedModelContext(Int_t iX, Int_t iY, FWViewContextMenuHandlerBase *) const
NOTE: iX and iY are in global coordinates.
void addTo(FWModelContextMenuHandler &, const FWModelId &id)
std::vector< std::string > detailViewsFor(const FWModelId &) const
FWDetailViewManager * m_detailViewManager
void addViewEntry(const char *, int, bool enabled=true)
void openDetailViewFor(const FWModelId &, const std::string &)
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:537
void setIsVisible(bool iSet)
const FWEventItem * item() const
Definition: FWModelId.h:44