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.16 2010/06/18 10:17:16 yana Exp $
12 //
13 
14 // system include files
15 #include <cassert>
16 #include "TGMenu.h"
17 #include "KeySymbols.h"
18 
19 // user include files
28 
29 //
30 // constants, enums and typedefs
31 //
41 };
42 
43 
44 class FWPopupMenu : public TGPopupMenu
45 {
46 public:
47  FWPopupMenu(const TGWindow* p=0, UInt_t w=10, UInt_t h=10, UInt_t options=0) :
48  TGPopupMenu(p, w, h, options)
49  {
50  AddInput(kKeyPressMask);
51  }
52 
53  // virtual void PlaceMenu(Int_t x, Int_t y, Bool_t stick_mode, Bool_t grab_pointer)
54  // {
55  // TGPopupMenu::PlaceMenu(x, y, stick_mode, grab_pointer);
56  // gVirtualX->GrabKey(fId, 0l, kAnyModifier, kTRUE);
57  // }
58 
59  virtual void PoppedUp()
60  {
61  TGPopupMenu::PoppedUp();
62  gVirtualX->SetInputFocus(fId);
63  gVirtualX->GrabKey(fId, 0l, kAnyModifier, kTRUE);
64 
65  }
66 
67  virtual void PoppedDown()
68  {
69  gVirtualX->GrabKey(fId, 0l, kAnyModifier, kFALSE);
70  TGPopupMenu::PoppedDown();
71  }
72 
73  virtual Bool_t HandleKey(Event_t* event)
74  {
75  if (event->fType != kGKeyPress) return kTRUE;
76 
77  UInt_t keysym;
78  char tmp[2];
79  gVirtualX->LookupString(event, tmp, sizeof(tmp), keysym);
80 
81  TGMenuEntry *ce = fCurrent;
82 
83  switch (keysym)
84  {
85  case kKey_Up:
86  {
87  if (ce) ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
88  while (ce && ((ce->GetType() == kMenuSeparator) ||
89  (ce->GetType() == kMenuLabel) ||
90  !(ce->GetStatus() & kMenuEnableMask)))
91  {
92  ce = (TGMenuEntry*)GetListOfEntries()->Before(ce);
93  }
94  if (!ce) ce = (TGMenuEntry*)GetListOfEntries()->Last();
95  Activate(ce);
96  break;
97  }
98  case kKey_Down:
99  {
100  if (ce) ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
101  while (ce && ((ce->GetType() == kMenuSeparator) ||
102  (ce->GetType() == kMenuLabel) ||
103  !(ce->GetStatus() & kMenuEnableMask)))
104  {
105  ce = (TGMenuEntry*)GetListOfEntries()->After(ce);
106  }
107  if (!ce) ce = (TGMenuEntry*)GetListOfEntries()->First();
108  Activate(ce);
109  break;
110  }
111  case kKey_Enter:
112  case kKey_Return:
113  {
114  Event_t ev;
115  ev.fType = kButtonRelease;
116  ev.fWindow = fId;
117  return HandleButton(&ev);
118  }
119  case kKey_Escape:
120  {
121  fCurrent = 0;
122  void *dummy = 0;
123  return EndMenu(dummy);
124  }
125  default:
126  {
127  break;
128  }
129  }
130 
131  return kTRUE;
132  }
133 };
134 
135 
136 //
137 // static data member definitions
138 //
139 static const char* const kOpenDetailView = "Open Detailed View ...";
140 
141 //
142 // constructors and destructor
143 //
145  FWDetailViewManager* iDVM,
146  FWColorManager* iCM,
147  FWGUIManager* iGM):
148 m_modelPopup(0),
149 m_colorPopup(0),
150 m_selectionManager(iSM),
151 m_detailViewManager(iDVM),
152 m_colorManager(iCM),
153 m_guiManager(iGM),
154 m_seperator(0),
155 m_viewSeperator(0),
156 m_afterViewSeperator(0),
157 m_x(0),
158 m_y(0),
159 m_nDetailViewEntries(0),
160 m_nViewEntries(0),
161 m_viewHander(0)
162 {
163 }
164 
165 // FWModelContextMenuHandler::FWModelContextMenuHandler(const FWModelContextMenuHandler& rhs)
166 // {
167 // // do actual copying here;
168 // }
169 
171 {
172  delete m_modelPopup;
173 }
174 
175 //
176 // assignment operators
177 //
178 // const FWModelContextMenuHandler& FWModelContextMenuHandler::operator=(const FWModelContextMenuHandler& rhs)
179 // {
180 // //An exception safe implementation is
181 // FWModelContextMenuHandler temp(rhs);
182 // swap(rhs);
183 //
184 // return *this;
185 // }
186 
187 //
188 // member functions
189 //
190 namespace {
191  class change_visibility {
192  public:
193  change_visibility(bool iIsVisible): m_isVisible(iIsVisible) {}
194  void operator()(const FWModelId& iID) const {
195  FWDisplayProperties p = iID.item()->modelInfo(iID.index()).displayProperties();
196  p.setIsVisible(m_isVisible);
197  iID.item()->setDisplayProperties(iID.index(), p);
198  }
199  bool m_isVisible;
200  };
201 }
202 void
204 {
205  assert(!m_selectionManager->selected().empty());
206  switch (iChoice) {
207  case kSetVisibleMO:
208  {
209  FWModelId id = *(m_selectionManager->selected().begin());
210  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
211  for_each(m_selectionManager->selected().begin(),
212  m_selectionManager->selected().end(),
213  change_visibility(!props.isVisible())
214  );
215  break;
216  }
217  case kSetColorMO:
218  {
219  FWModelId id = *(m_selectionManager->selected().begin());
221  m_colorPopup->SetName("Selected");
222  std::vector<Color_t> colors;
225  m_colorPopup->SetSelection(id.item()->modelInfo(id.index()).displayProperties().color());
226  m_colorPopup->PlacePopup(m_x, m_y, m_colorPopup->GetDefaultWidth(), m_colorPopup->GetDefaultHeight());
227  break;
228  }
230  {
232  break;
233  }
235  {
237  break;
238  }
239  case kOpenDetailViewMO:
240  case kViewOptionsMO:
241  default:
242  {
243  if(iChoice>=kViewOptionsMO) {
244  assert(0!=m_viewHander);
246  }else {
247  assert(iChoice<kOpenObjectControllerMO);
248  assert(m_selectionManager->selected().size()==1);
249  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
250  assert(0!=viewChoices.size());
252  }
253  break;
254  }
255  break;
256  }
257 }
258 
259 void
261 {
262  for(std::set<FWModelId>::const_iterator it =m_selectionManager->selected().begin(),
263  itEnd = m_selectionManager->selected().end();
264  it != itEnd;
265  ++it) {
266  FWDisplayProperties changeProperties = it->item()->modelInfo(it->index()).displayProperties();
267  changeProperties.setColor(color);
268  it->item()->setDisplayProperties(it->index(), changeProperties);
269  }
270 }
271 
272 void
273 FWModelContextMenuHandler::addViewEntry(const char* iEntryName, int iEntryIndex)
274 {
275  if(!m_viewSeperator) {
276  m_modelPopup->AddSeparator(m_afterViewSeperator);
277  m_viewSeperator=dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Before(m_afterViewSeperator));
278  assert(0!=m_viewSeperator);
279  }
280  if(static_cast<int>(m_nViewEntries) > iEntryIndex) {
281  m_modelPopup->GetEntry(iEntryIndex+kViewOptionsMO)->GetLabel()->SetString(iEntryName);
282  m_modelPopup->EnableEntry(iEntryIndex+kViewOptionsMO);
283  } else {
284  assert(static_cast<int>(m_nViewEntries) == iEntryIndex);
285  m_modelPopup->AddEntry(iEntryName,kViewOptionsMO+iEntryIndex,0,0,m_viewSeperator);
286  ++m_nViewEntries;
287  }
288 }
289 
290 //
291 // const member functions
292 //
293 void
295 {
296  m_viewHander=iHandler;
297  assert(!m_selectionManager->selected().empty());
299 
300  //setup the menu based on this object
301  FWModelId id = *(m_selectionManager->selected().begin());
302  const FWDisplayProperties& props = id.item()->modelInfo(id.index()).displayProperties();
303  if(props.isVisible()) {
304  m_modelPopup->CheckEntry(kSetVisibleMO);
305  }else {
306  m_modelPopup->UnCheckEntry(kSetVisibleMO);
307  }
308 
309  if(m_selectionManager->selected().size()==1) {
310  //add the detail view entries
311  std::vector<std::string> viewChoices = m_detailViewManager->detailViewsFor(*(m_selectionManager->selected().begin()));
312  if(viewChoices.size()>0) {
313  if(m_nDetailViewEntries < viewChoices.size()) {
314  for(unsigned int index = m_nDetailViewEntries;
315  index != viewChoices.size();
316  ++index) {
318  }
319  m_nDetailViewEntries=viewChoices.size();
320  }
321  const std::string kStart("Open ");
322  const std::string kEnd(" Detail View ...");
323  for(unsigned int index=0; index != viewChoices.size(); ++index) {
324  m_modelPopup->GetEntry(index+kOpenDetailViewMO)->GetLabel()->SetString((kStart+viewChoices[index]+kEnd).c_str());
325  m_modelPopup->EnableEntry(index+kOpenDetailViewMO);
326  }
327  for(unsigned int i =viewChoices.size(); i <m_nDetailViewEntries; ++i) {
328  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
329  }
330 
331  } else {
332  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
333  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
334  }
335  }
336  } else {
337  for(unsigned int i =0; i <m_nDetailViewEntries; ++i) {
338  m_modelPopup->HideEntry(kOpenDetailViewMO+i);
339  }
340  }
341  //add necessary entries from the view
342  m_modelPopup->DeleteEntry(m_viewSeperator);
343  m_viewSeperator=0;
344 
345  for(unsigned int i=0; i<m_nViewEntries; ++i) {
346  m_modelPopup->HideEntry(kViewOptionsMO+i);
347  }
348  if(m_viewHander) {
349  m_viewHander->addTo(const_cast<FWModelContextMenuHandler&>(*this));
350  }
351 
352  m_x=iX;
353  m_y=iY;
354  m_modelPopup->PlaceMenu(iX,iY,false,true);
355 }
356 
357 void
359 {
360  if(0==m_modelPopup) {
361  m_modelPopup = new FWPopupMenu();
362 
363  m_modelPopup->AddEntry("Set Visible",kSetVisibleMO);
364  m_modelPopup->AddEntry("Set Color ...",kSetColorMO);
367  m_modelPopup->AddSeparator();
368  m_seperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
369  assert(0!=m_seperator);
370  m_modelPopup->AddEntry("Open Object Controller ...",kOpenObjectControllerMO);
371  m_afterViewSeperator = dynamic_cast<TGMenuEntry*>(m_modelPopup->GetListOfEntries()->Last());
372  m_modelPopup->AddEntry("Open Collection Controller ...",kOpenCollectionControllerMO);
373 
374  m_modelPopup->Connect("Activated(Int_t)",
375  "FWModelContextMenuHandler",
376  const_cast<FWModelContextMenuHandler*>(this),
377  "chosenItem(Int_t)");
378  }
379 }
380 
381 void
383 {
384  if(0==m_colorPopup) {
385  std::vector<Color_t> colors;
387 
388  m_colorPopup = new FWColorPopup(gClient->GetDefaultRoot(), colors.front());
389  m_colorPopup->InitContent("", colors);
390  m_colorPopup->Connect("ColorSelected(Color_t)","FWModelContextMenuHandler", const_cast<FWModelContextMenuHandler*>(this), "colorChangeRequested(Color_t)");
391  }
392 }
393 
394 //
395 // static member functions
396 //
397 
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 addViewEntry(const char *, int)
void setDisplayProperties(int iIndex, const FWDisplayProperties &) const
Definition: FWEventItem.cc:287
std::vector< Color_t > colors
Definition: eve_filter.cc:26
void fillLimitedColors(std::vector< Color_t > &cv) const
FWPopupMenu(const TGWindow *p=0, UInt_t w=10, UInt_t h=10, UInt_t options=0)
virtual void PoppedDown()
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)
void addTo(FWModelContextMenuHandler &)
int index() const
Definition: FWModelId.h:50
static const char *const kOpenDetailView
virtual void PoppedUp()
BackgroundColorIndex backgroundColorIndex() const
void ResetColors(const std::vector< Color_t > &colors, bool backgroundIsBlack=true)
virtual Bool_t HandleKey(Event_t *event)
void SetSelection(Color_t)
How EventSelector::AcceptEvent() decides whether to accept an event for output otherwise it is excluding the probing of A single or multiple positive and the trigger will pass if any such matching triggers are PASS or EXCEPTION[A criterion thatmatches no triggers at all is detected and causes a throw.] A single negative with an expectation of appropriate bit checking in the decision and the trigger will pass if any such matching triggers are FAIL or EXCEPTION A wildcarded negative criterion that matches more than one trigger in the trigger but the state exists so we define the behavior If all triggers are the negative crieriion will lead to accepting the event(this again matches the behavior of"!*"before the partial wildcard feature was incorporated).The per-event"cost"of each negative criterion with multiple relevant triggers is about the same as!*was in the past
unsigned int UInt_t
Definition: FUTypes.h:12
FWViewContextMenuHandlerBase * m_viewHander
void showSelectedModelContext(Int_t iX, Int_t iY, FWViewContextMenuHandlerBase *) const
NOTE: iX and iY are in global coordinates.
std::vector< std::string > detailViewsFor(const FWModelId &) const
FWDetailViewManager * m_detailViewManager
void openDetailViewFor(const FWModelId &, const std::string &)
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
ModelInfo modelInfo(int iIndex) const
Definition: FWEventItem.cc:536
void setIsVisible(bool iSet)
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
const FWEventItem * item() const
Definition: FWModelId.h:45