CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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,
49 };
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(0),
65 m_colorPopup(0),
66 m_selectionManager(iSM),
67 m_detailViewManager(iDVM),
68 m_colorManager(iCM),
69 m_guiManager(iGM),
70 m_seperator(0),
71 m_viewSeperator(0),
72 m_afterViewSeperator(0),
73 m_x(0),
74 m_y(0),
75 m_nDetailViewEntries(0),
76 m_nViewEntries(0),
77 m_viewHander(0)
78 {
79 }
80 
81 // FWModelContextMenuHandler::FWModelContextMenuHandler(const FWModelContextMenuHandler& rhs)
82 // {
83 // // do actual copying here;
84 // }
85 
87 {
88  delete m_modelPopup;
89 }
90 
91 //
92 // assignment operators
93 //
94 // const FWModelContextMenuHandler& FWModelContextMenuHandler::operator=(const FWModelContextMenuHandler& rhs)
95 // {
96 // //An exception safe implementation is
97 // FWModelContextMenuHandler temp(rhs);
98 // swap(rhs);
99 //
100 // return *this;
101 // }
102 
103 //
104 // member functions
105 //
106 #include "TROOT.h"
107 namespace {
108  class change_visibility {
109  public:
110  change_visibility(bool iIsVisible): m_isVisible(iIsVisible) {}
111  void operator()(const FWModelId& iID) const {
112  FWDisplayProperties p = iID.item()->modelInfo(iID.index()).displayProperties();
113  p.setIsVisible(m_isVisible);
114  iID.item()->setDisplayProperties(iID.index(), p);
115  }
116  bool m_isVisible;
117  };
118 }
119 void
121 {
122  assert(!m_selectionManager->selected().empty());
123  switch (iChoice) {
124  case kSetVisibleMO:
125  {
126  FWModelId id = *(m_selectionManager->selected().begin());
127  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
128  for_each(m_selectionManager->selected().begin(),
129  m_selectionManager->selected().end(),
130  change_visibility(!props.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 kOpenDetailViewMO:
177  case kViewOptionsMO:
178  default:
179  {
180  if(iChoice>=kViewOptionsMO) {
181  assert(0!=m_viewHander);
183  }else {
185  assert(m_selectionManager->selected().size()==1);
186  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
187  assert(0!=viewChoices.size());
189  }
190  break;
191  }
192  break;
193  }
194 }
195 
196 void
198 {
199  for(std::set<FWModelId>::const_iterator it =m_selectionManager->selected().begin(),
200  itEnd = m_selectionManager->selected().end();
201  it != itEnd;
202  ++it) {
203  FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
204  changeProperties.setColor(color);
205  it->item()->setDisplayProperties(it->index(), changeProperties);
206  }
207 }
208 
209 void
210 FWModelContextMenuHandler::addViewEntry(const char* iEntryName, int iEntryIndex, bool enabled)
211 {
212  if(!m_viewSeperator) {
213  m_modelPopup->AddSeparator(m_afterViewSeperator);
214  m_viewSeperator=dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
215  assert(0!=m_viewSeperator);
216  }
217 
218  if(static_cast<int>(m_nViewEntries) > iEntryIndex) {
219  m_modelPopup->GetEntry(iEntryIndex+kViewOptionsMO)->GetLabel()->SetString(iEntryName);
220  if(enabled)
221  m_modelPopup->EnableEntry(iEntryIndex+kViewOptionsMO);
222  else
223  m_modelPopup->DisableEntry(iEntryIndex+kViewOptionsMO);
224 
225  } else {
226  assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
227  m_modelPopup->AddEntry(iEntryName,kViewOptionsMO+iEntryIndex,0,0,m_viewSeperator);
228 
229  if (enabled)
230  m_modelPopup->EnableEntry(kViewOptionsMO+iEntryIndex);
231  else
232  m_modelPopup->DisableEntry(kViewOptionsMO+iEntryIndex);
233 
234  ++m_nViewEntries;
235  }
236 
237 }
238 //
239 // const member functions
240 //
241 void
243 {
244  m_viewHander=iHandler;
245  assert(!m_selectionManager->selected().empty());
247 
248  //setup the menu based on this object
249  FWModelId id = *(m_selectionManager->selected().begin());
250  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
251  if(props.isVisible()) {
252  m_modelPopup->CheckEntry(kSetVisibleMO);
253  }else {
254  m_modelPopup->UnCheckEntry(kSetVisibleMO);
255  }
256 
257 
258  if( m_selectionManager->selected().size()==1 ) {
259  {
260  //edm::TypeWithDict rtype(edm::TypeWithDict::byName(id.item()->modelType()->GetName()));
261  //edm::ObjectWithDict o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
262  //edm::TypeMemberQuery inh = edm::TypeMemberQuery::InheritedAlso;
263  //if ( rtype.functionMemberByName("print",edm::TypeWithDict(edm::TypeWithDict::byName("void (std::ostream&)"), Long_t(kIsConstant)), 0, inh))
264  //{
265  //m_modelPopup->EnableEntry(kPrint);
266  // std::cout << "Enable " <<std::endl;
267  //}
268  //else
269  //{
270  m_modelPopup->DisableEntry(kPrint);
271  // printf("Disable print \n");
272  //}
273  }
274  //add the detail view entries
275  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
276  if(viewChoices.size()>0) {
277  if(m_nDetailViewEntries < viewChoices.size()) {
278  for(unsigned int index = m_nDetailViewEntries;
279  index != viewChoices.size();
280  ++index) {
282  }
283  m_nDetailViewEntries=viewChoices.size();
284  }
285  const std::string kStart("Open ");
286  const std::string kEnd(" Detail View ...");
287  for(unsigned int index=0; index != viewChoices.size(); ++index) {
288  m_modelPopup->EnableEntry(index+kOpenDetailViewMO); // need to call this to make it visible
289  if ( viewChoices[index][0] != '!') {
290  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+viewChoices[index]+kEnd).c_str());
291  }
292  else
293  {
294  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+&viewChoices[index][1]+kEnd).c_str());
295  m_modelPopup->DisableEntry(index+kOpenDetailViewMO);
296  }
297  }
298  for(unsigned int i =viewChoices.size(); i <m_nDetailViewEntries; ++i) {
299  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
300  }
301 
302  } else {
303  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
304  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
305  }
306  }
307  } else {
308  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
309  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
310  }
311  }
312  //add necessary entries from the view
313  m_modelPopup->DeleteEntry(m_viewSeperator);
314  m_viewSeperator=0;
315 
316  for(unsigned int i=0; i<m_nViewEntries; ++i) {
317  m_modelPopup->HideEntry(kViewOptionsMO+i);
318  }
319  if(m_viewHander) {
320  m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this), *(m_selectionManager->selected().begin()));
321  }
322 
323  m_x=iX;
324  m_y=iY;
325  m_modelPopup->PlaceMenu(iX,iY,false,true);
326 }
327 
328 void
330 {
331  if(0==m_modelPopup) {
332  m_modelPopup = new FWPopupMenu();
333 
334  m_modelPopup->AddEntry("Set Visible",kSetVisibleMO);
335  m_modelPopup->AddEntry("Set Color ...",kSetColorMO);
336  // m_modelPopup->AddEntry("Print ...",kPrint);
339  m_modelPopup->AddSeparator();
340  m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
341  assert(0!=m_seperator);
342  m_modelPopup->AddEntry("Open Object Controller ...",kOpenObjectControllerMO);
343  m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
344  m_modelPopup->AddEntry("Open Collection Controller ...",kOpenCollectionControllerMO);
345 
346  m_modelPopup->Connect("Activated(Int_t)",
347  "FWModelContextMenuHandler",
348  const_cast<FWModelContextMenuHandler*>(this),
349  "chosenItem(Int_t)");
350  }
351 }
352 
353 void
355 {
356  if(0==m_colorPopup) {
357  std::vector<Color_t> colors;
359 
360  m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
361  m_colorPopup->InitContent("", colors);
362  m_colorPopup->Connect("ColorSelected(Color_t)","FWModelContextMenuHandler", const_cast<FWModelContextMenuHandler*>(this), "colorChangeRequested(Color_t)");
363  }
364 }
365 
366 //
367 // static member functions
368 //
369 
const std::set< FWModelId > & selected() const
FWModelContextMenuHandler(FWSelectionManager *, FWDetailViewManager *, FWColorManager *, FWGUIManager *)
int i
Definition: DBlmapReader.cc:9
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)
assert(m_qm.get())
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:276
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)
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:535
void setIsVisible(bool iSet)
const FWEventItem * item() const
Definition: FWModelId.h:44