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