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 // $Id: FWModelContextMenuHandler.cc,v 1.23 2012/06/26 22:09:35 wmtan Exp $
12 //
13 
14 // system include files
15 #include <cassert>
16 #include "TGMenu.h"
17 #include "KeySymbols.h"
18 
19 #include "Reflex/Object.h"
20 #include "Reflex/Type.h"
21 #include "TClass.h"
22 
23 // user include files
33 
34 //
35 // constants, enums and typedefs
36 //
47 };
48 
49 
50 //
51 // static data member definitions
52 //
53 static const char* const kOpenDetailView = "Open Detailed View ...";
54 
55 //
56 // constructors and destructor
57 //
59  FWDetailViewManager* iDVM,
60  FWColorManager* iCM,
61  FWGUIManager* iGM):
62 m_modelPopup(0),
63 m_colorPopup(0),
64 m_selectionManager(iSM),
65 m_detailViewManager(iDVM),
66 m_colorManager(iCM),
67 m_guiManager(iGM),
68 m_seperator(0),
69 m_viewSeperator(0),
70 m_afterViewSeperator(0),
71 m_x(0),
72 m_y(0),
73 m_nDetailViewEntries(0),
74 m_nViewEntries(0),
75 m_viewHander(0)
76 {
77 }
78 
79 // FWModelContextMenuHandler::FWModelContextMenuHandler(const FWModelContextMenuHandler& rhs)
80 // {
81 // // do actual copying here;
82 // }
83 
85 {
86  delete m_modelPopup;
87 }
88 
89 //
90 // assignment operators
91 //
92 // const FWModelContextMenuHandler& FWModelContextMenuHandler::operator=(const FWModelContextMenuHandler& rhs)
93 // {
94 // //An exception safe implementation is
95 // FWModelContextMenuHandler temp(rhs);
96 // swap(rhs);
97 //
98 // return *this;
99 // }
100 
101 //
102 // member functions
103 //
104 #include "TROOT.h"
105 namespace {
106  class change_visibility {
107  public:
108  change_visibility(bool iIsVisible): m_isVisible(iIsVisible) {}
109  void operator()(const FWModelId& iID) const {
110  FWDisplayProperties p = iID.item()->modelInfo(iID.index()).displayProperties();
111  p.setIsVisible(m_isVisible);
112  iID.item()->setDisplayProperties(iID.index(), p);
113  }
114  bool m_isVisible;
115  };
116 }
117 void
119 {
120  assert(!m_selectionManager->selected().empty());
121  switch (iChoice) {
122  case kSetVisibleMO:
123  {
124  FWModelId id = *(m_selectionManager->selected().begin());
125  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
126  for_each(m_selectionManager->selected().begin(),
127  m_selectionManager->selected().end(),
128  change_visibility(!props.isVisible())
129  );
130  break;
131  }
132  case kSetColorMO:
133  {
134  FWModelId id = *(m_selectionManager->selected().begin());
136  m_colorPopup->SetName("Selected");
137  std::vector<Color_t> colors;
140  m_colorPopup->SetSelection(id.item()->modelInfo(id.index()).displayProperties().color());
141  m_colorPopup->PlacePopup(m_x, m_y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
142  break;
143  }
144  case kPrint:
145  {
146  FWModelId id = *(m_selectionManager->selected().begin());
147  Reflex::Type rtype(Reflex::Type::ByName(id.item()->modelType()->GetName()));
148  Reflex::Object o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
149 
150  // void* xx = &std::cout;
151  //const std::vector<void*> j(1, xx);
152  //Reflex::Member m = rtype.FunctionMemberByName("print",Reflex::Type(Reflex::Type::ByName("void (std::ostream&)"), Reflex::CONST), 0 ,INHERITEDMEMBERS_ALSO );
153  //m.Invoke(o, 0, j);
154 
155  const char* cmd = Form("FWGUIManager::OStream() << *(%s*)%p ;", id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
156  //const char* cmd = Form("*((std::ostream*)%p) << (%s*)%p ;", (void*)(&std::cout), id.item()->modelType()->GetName(), (void*)id.item()->modelData(id.index()));
157  std::cout << cmd << std::endl;
158  gROOT->ProcessLine(cmd);
159 
160 
161  break;
162  }
164  {
166  break;
167  }
169  {
171  break;
172  }
173  case kOpenDetailViewMO:
174  case kViewOptionsMO:
175  default:
176  {
177  if(iChoice>=kViewOptionsMO) {
178  assert(0!=m_viewHander);
180  }else {
181  assert(iChoice<kOpenObjectControllerMO);
182  assert(m_selectionManager->selected().size()==1);
183  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
184  assert(0!=viewChoices.size());
186  }
187  break;
188  }
189  break;
190  }
191 }
192 
193 void
195 {
196  for(std::set<FWModelId>::const_iterator it =m_selectionManager->selected().begin(),
197  itEnd = m_selectionManager->selected().end();
198  it != itEnd;
199  ++it) {
200  FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
201  changeProperties.setColor(color);
202  it->item()->setDisplayProperties(it->index(), changeProperties);
203  }
204 }
205 
206 void
207 FWModelContextMenuHandler::addViewEntry(const char* iEntryName, int iEntryIndex, bool enabled)
208 {
209  if(!m_viewSeperator) {
210  m_modelPopup->AddSeparator(m_afterViewSeperator);
211  m_viewSeperator=dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
212  assert(0!=m_viewSeperator);
213  }
214 
215  if(static_cast<int>(m_nViewEntries) > iEntryIndex) {
216  m_modelPopup->GetEntry(iEntryIndex+kViewOptionsMO)->GetLabel()->SetString(iEntryName);
217  if(enabled)
218  m_modelPopup->EnableEntry(iEntryIndex+kViewOptionsMO);
219  else
220  m_modelPopup->DisableEntry(iEntryIndex+kViewOptionsMO);
221 
222  } else {
223  assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
224  m_modelPopup->AddEntry(iEntryName,kViewOptionsMO+iEntryIndex,0,0,m_viewSeperator);
225 
226  if (enabled)
227  m_modelPopup->EnableEntry(kViewOptionsMO+iEntryIndex);
228  else
229  m_modelPopup->DisableEntry(kViewOptionsMO+iEntryIndex);
230 
231  ++m_nViewEntries;
232  }
233 
234 }
235 //
236 // const member functions
237 //
238 void
240 {
241  m_viewHander=iHandler;
242  assert(!m_selectionManager->selected().empty());
244 
245  //setup the menu based on this object
246  FWModelId id = *(m_selectionManager->selected().begin());
247  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
248  if(props.isVisible()) {
249  m_modelPopup->CheckEntry(kSetVisibleMO);
250  }else {
251  m_modelPopup->UnCheckEntry(kSetVisibleMO);
252  }
253 
254 
255  if( m_selectionManager->selected().size()==1 ) {
256  {
257  Reflex::Type rtype(Reflex::Type::ByName(id.item()->modelType()->GetName()));
258  Reflex::Object o(rtype, const_cast<void *>(id.item()->modelData(id.index())));
259  Reflex::EMEMBERQUERY inh = Reflex::INHERITEDMEMBERS_ALSO;
260  if ( rtype.FunctionMemberByName("print",Reflex::Type(Reflex::Type::ByName("void (std::ostream&)"), Reflex::CONST), 0 , inh))
261  {
262  m_modelPopup->EnableEntry(kPrint);
263  // std::cout << "Enable " <<std::endl;
264  }
265  else
266  {
267  m_modelPopup->DisableEntry(kPrint);
268  // printf("Disable print \n");
269  }
270  }
271  //add the detail view entries
272  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
273  if(viewChoices.size()>0) {
274  if(m_nDetailViewEntries < viewChoices.size()) {
275  for(unsigned int index = m_nDetailViewEntries;
276  index != viewChoices.size();
277  ++index) {
279  }
280  m_nDetailViewEntries=viewChoices.size();
281  }
282  const std::string kStart("Open ");
283  const std::string kEnd(" Detail View ...");
284  for(unsigned int index=0; index != viewChoices.size(); ++index) {
285  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+viewChoices[index]+kEnd).c_str());
286  m_modelPopup->EnableEntry(index+kOpenDetailViewMO);
287  }
288  for(unsigned int i =viewChoices.size(); 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  } else {
298  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
299  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
300  }
301  }
302  //add necessary entries from the view
303  m_modelPopup->DeleteEntry(m_viewSeperator);
304  m_viewSeperator=0;
305 
306  for(unsigned int i=0; i<m_nViewEntries; ++i) {
307  m_modelPopup->HideEntry(kViewOptionsMO+i);
308  }
309  if(m_viewHander) {
310  m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this), *(m_selectionManager->selected().begin()));
311  }
312 
313  m_x=iX;
314  m_y=iY;
315  m_modelPopup->PlaceMenu(iX,iY,false,true);
316 }
317 
318 void
320 {
321  if(0==m_modelPopup) {
322  m_modelPopup = new FWPopupMenu();
323 
324  m_modelPopup->AddEntry("Set Visible",kSetVisibleMO);
325  m_modelPopup->AddEntry("Set Color ...",kSetColorMO);
326  m_modelPopup->AddEntry("Print ...",kPrint);
329  m_modelPopup->AddSeparator();
330  m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
331  assert(0!=m_seperator);
332  m_modelPopup->AddEntry("Open Object Controller ...",kOpenObjectControllerMO);
333  m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
334  m_modelPopup->AddEntry("Open Collection Controller ...",kOpenCollectionControllerMO);
335 
336  m_modelPopup->Connect("Activated(Int_t)",
337  "FWModelContextMenuHandler",
338  const_cast<FWModelContextMenuHandler*>(this),
339  "chosenItem(Int_t)");
340  }
341 }
342 
343 void
345 {
346  if(0==m_colorPopup) {
347  std::vector<Color_t> colors;
349 
350  m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
351  m_colorPopup->InitContent("", colors);
352  m_colorPopup->Connect("ColorSelected(Color_t)","FWModelContextMenuHandler", const_cast<FWModelContextMenuHandler*>(this), "colorChangeRequested(Color_t)");
353  }
354 }
355 
356 //
357 // static member functions
358 //
359 
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)
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:277
std::vector< Color_t > colors
Definition: eve_filter.cc:26
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)
int index() const
Definition: FWModelId.h:50
static const char *const kOpenDetailView
BackgroundColorIndex backgroundColorIndex() const
string cmd
Definition: asciidump.py:19
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 &)
tuple cout
Definition: gather_cfg.py:121
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:535
void setIsVisible(bool iSet)
const FWEventItem * item() const
Definition: FWModelId.h:45