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(0),
66 m_colorPopup(0),
67 m_selectionManager(iSM),
68 m_detailViewManager(iDVM),
69 m_colorManager(iCM),
70 m_guiManager(iGM),
71 m_seperator(0),
72 m_viewSeperator(0),
73 m_afterViewSeperator(0),
74 m_x(0),
75 m_y(0),
76 m_nDetailViewEntries(0),
77 m_nViewEntries(0),
78 m_viewHander(0)
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  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
129  for_each(m_selectionManager->selected().begin(),
130  m_selectionManager->selected().end(),
131  change_visibility(!props.isVisible())
132  );
133  break;
134  }
135  case kSetColorMO:
136  {
137  FWModelId id = *(m_selectionManager->selected().begin());
139  m_colorPopup->SetName("Selected");
140  std::vector<Color_t> colors;
143  m_colorPopup->SetSelection(id.item()->modelInfo(id.index()).displayProperties().color());
144  m_colorPopup->PlacePopup(m_x, m_y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
145  break;
146  }/*
147  case kPrint:
148  {
149  FWModelId id = *(m_selectionManager->selected().begin());
150  edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
151  edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
152 
153  // void* xx = &std::cout;
154  //const std::vector<void*> j(1, xx);
155  //edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
156  //edm::FunctionWithDict m = rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), edm::TypeModifiers::Const), edm::TypeModifiers::NoMod , inh))
157  //m.Invoke(o, 0, j);
158 
159  const char* cmd = Form("FWGUIManager::OStream() << *(%s*)%p ;", id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
160  //const char* cmd = Form("*((std::ostream*)%p) << (%s*)%p ;", (void*)(&std::cout), id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
161  std::cout << cmd << std::endl;
162  gROOT->ProcessLine(cmd);
163 
164 
165  break;
166  }*/
168  {
170  break;
171  }
173  {
175  break;
176  }
177  case kOpen3DRegion:
178  {
180  break;
181  }
182  case kOpenDetailViewMO:
183  case kViewOptionsMO:
184  default:
185  {
186  if(iChoice>=kViewOptionsMO) {
187  assert(0!=m_viewHander);
189  }else {
190  assert(iChoice<kOpenObjectControllerMO);
191  assert(m_selectionManager->selected().size()==1);
192  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
193  assert(0!=viewChoices.size());
195  }
196  break;
197  }
198  break;
199  }
200 }
201 
202 void
204 {
205  for(std::set<FWModelId>::const_iterator it =m_selectionManager->selected().begin(),
206  itEnd = m_selectionManager->selected().end();
207  it != itEnd;
208  ++it) {
209  FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
210  changeProperties.setColor(color);
211  it->item()->setDisplayProperties(it->index(), changeProperties);
212  }
213 }
214 
215 void
216 FWModelContextMenuHandler::addViewEntry(const char* iEntryName, int iEntryIndex, bool enabled)
217 {
218  if(!m_viewSeperator) {
219  m_modelPopup->AddSeparator(m_afterViewSeperator);
220  m_viewSeperator=dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
221  assert(0!=m_viewSeperator);
222  }
223 
224  if(static_cast<int>(m_nViewEntries) > iEntryIndex) {
225  m_modelPopup->GetEntry(iEntryIndex+kViewOptionsMO)->GetLabel()->SetString(iEntryName);
226  if(enabled)
227  m_modelPopup->EnableEntry(iEntryIndex+kViewOptionsMO);
228  else
229  m_modelPopup->DisableEntry(iEntryIndex+kViewOptionsMO);
230 
231  } else {
232  assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
233  m_modelPopup->AddEntry(iEntryName,kViewOptionsMO+iEntryIndex,0,0,m_viewSeperator);
234 
235  if (enabled)
236  m_modelPopup->EnableEntry(kViewOptionsMO+iEntryIndex);
237  else
238  m_modelPopup->DisableEntry(kViewOptionsMO+iEntryIndex);
239 
240  ++m_nViewEntries;
241  }
242 
243 }
244 //
245 // const member functions
246 //
247 void
249 {
250  m_viewHander=iHandler;
251  assert(!m_selectionManager->selected().empty());
253 
254  //setup the menu based on this object
255  FWModelId id = *(m_selectionManager->selected().begin());
256  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
257  if(props.isVisible()) {
258  m_modelPopup->CheckEntry(kSetVisibleMO);
259  }else {
260  m_modelPopup->UnCheckEntry(kSetVisibleMO);
261  }
262 
263 
264  if( m_selectionManager->selected().size()==1 ) {
265  {
266  //edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
267  //edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
268  //edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
269  //if ( rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), Long_t(kIsConstant)), 0, inh))
270  //{
271  //m_modelPopup->EnableEntry(kPrint);
272  // std::cout << "Enable " <<std::endl;
273  //}
274  //else
275  //{
276  m_modelPopup->DisableEntry(kPrint);
277  // printf("Disable print \n");
278  //}
279  }
280  //add the detail view entries
281  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
282  if(viewChoices.size()>0) {
283  if(m_nDetailViewEntries < viewChoices.size()) {
284  for(unsigned int index = m_nDetailViewEntries;
285  index != viewChoices.size();
286  ++index) {
288  }
289  m_nDetailViewEntries=viewChoices.size();
290  }
291  const std::string kStart("Open ");
292  const std::string kEnd(" Detail View ...");
293  for(unsigned int index=0; index != viewChoices.size(); ++index) {
294  m_modelPopup->EnableEntry(index+kOpenDetailViewMO); // need to call this to make it visible
295  if ( viewChoices[index][0] != '!') {
296  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+viewChoices[index]+kEnd).c_str());
297  }
298  else
299  {
300  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+&viewChoices[index][1]+kEnd).c_str());
301  m_modelPopup->DisableEntry(index+kOpenDetailViewMO);
302  }
303  }
304  for(unsigned int i =viewChoices.size(); i <m_nDetailViewEntries; ++i) {
305  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
306  }
307 
308  } else {
309  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
310  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
311  }
312  }
313  } else {
314  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
315  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
316  }
317  }
318  //add necessary entries from the view
319  m_modelPopup->DeleteEntry(m_viewSeperator);
320  m_viewSeperator=0;
321 
322  for(unsigned int i=0; i<m_nViewEntries; ++i) {
323  m_modelPopup->HideEntry(kViewOptionsMO+i);
324  }
325  if(m_viewHander) {
326  m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this), *(m_selectionManager->selected().begin()));
327  }
328 
329  m_x=iX;
330  m_y=iY;
331  m_modelPopup->PlaceMenu(iX,iY,false,true);
332 }
333 
334 void
336 {
337  if(0==m_modelPopup) {
338  m_modelPopup = new FWPopupMenu();
339 
340  m_modelPopup->AddEntry("Set Visible",kSetVisibleMO);
341  m_modelPopup->AddEntry("Set Color ...",kSetColorMO);
342  // m_modelPopup->AddEntry("Print ...",kPrint);
345  m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
346  assert(0!=m_seperator);
347  m_modelPopup->AddEntry("Open 3D Region ...",kOpen3DRegion);
348  m_modelPopup->AddSeparator();
349  m_modelPopup->AddEntry("Open Object Controller ...",kOpenObjectControllerMO);
350  m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
351  m_modelPopup->AddEntry("Open Collection Controller ...",kOpenCollectionControllerMO);
352 
353  m_modelPopup->Connect("Activated(Int_t)",
354  "FWModelContextMenuHandler",
355  const_cast<FWModelContextMenuHandler*>(this),
356  "chosenItem(Int_t)");
357  }
358 }
359 
360 void
362 {
363  if(0==m_colorPopup) {
364  std::vector<Color_t> colors;
366 
367  m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
368  m_colorPopup->InitContent("", colors);
369  m_colorPopup->Connect("ColorSelected(Color_t)","FWModelContextMenuHandler", const_cast<FWModelContextMenuHandler*>(this), "colorChangeRequested(Color_t)");
370  }
371 }
372 
373 //
374 // static member functions
375 //
376 
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 SetName(const char *iName)
void open3DRegion()
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:278
void fillLimitedColors(std::vector< Color_t > &cv) const
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