DD4hep - The AIDA detector description toolkit for high energy physics experiments
DD4hep  Rev:Unversioneddirectory
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ContextMenu.cpp
Go to the documentation of this file.
1 // $Id: $
2 //==========================================================================
3 // AIDA Detector description implementation for LCD
4 //--------------------------------------------------------------------------
5 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
6 // All rights reserved.
7 //
8 // For the licensing terms see $DD4hepINSTALL/LICENSE.
9 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
10 //
11 // Author : M.Frank
12 //
13 //==========================================================================
14 
15 // Framework include files
16 #include "DDEve/ContextMenu.h"
17 
18 // ROOT include files
19 #include "TList.h"
20 #include "TClassMenuItem.h"
21 
22 // C/C++ include files
23 #include <stdexcept>
24 #include <map>
25 
26 using namespace std;
27 using namespace DD4hep;
28 
29 typedef map<string,ContextMenu*> Contexts;
31  static Contexts e;
32  return e;
33 }
34 
36 
39 : m_call(cb), m_param(par)
40 {
41 }
42 
44 ContextMenuHandler::~ContextMenuHandler() {
45 }
46 
48 void ContextMenuHandler::Context(TObject* target) {
49  const void *args[] = {target,m_param,0};
50  m_call.execute(args);
51 }
52 
53 
55 
56 ContextMenu::ContextMenu(TClass* cl) : m_class(cl) {
58  if ( !cl ) {
59  throw runtime_error("Failure: Cannot create context menu for NULL class!");
60  }
61 }
62 
64 ContextMenu::~ContextMenu() {
65 }
66 
68 ContextMenu& ContextMenu::instance(TClass* cl) {
69  Contexts::const_iterator i = mapped_entries().find(cl->GetName());
70  if ( i != mapped_entries().end() ) return *((*i).second);
71  ContextMenu* m = new ContextMenu(cl);
72  mapped_entries().insert(make_pair(cl->GetName(),m));
73  return *m;
74 }
75 
77 ContextMenu& ContextMenu::Clear() {
78  if ( m_class->GetMenuList() ) {
79  m_class->GetMenuList()->Delete();
80  }
81  return *this;
82 }
83 
85 ContextMenu& ContextMenu::AddSeparator() {
86  TClassMenuItem* item =
87  new TClassMenuItem(TClassMenuItem::kPopupSeparator,ContextMenuHandler::Class(),"seperator");
88  m_class->GetMenuList()->AddFirst(item);
89  return *this;
90 }
91 
93 ContextMenu& ContextMenu::Add(const string& title, Callback cb, void* ud) {
94  ContextMenuHandler* handler = new ContextMenuHandler(cb, ud);
95  TClassMenuItem* item =
96  new TClassMenuItem(TClassMenuItem::kPopupUserFunction,
97  ContextMenuHandler::Class(),title.c_str(),
98  "Context",handler,"TObject*",2);
99  m_calls.push_back(handler);
100  m_class->GetMenuList()->AddLast(item);
101  return *this;
102 }
return e
Definition: Volumes.cpp:297
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:38
ClassImp(ContextMenuHandler) ContextMenuHandler
Initializing constructor.
Definition: ContextMenu.cpp:35
static Contexts & mapped_entries()
Definition: ContextMenu.cpp:30
map< string, ContextMenu * > Contexts
Definition: ContextMenu.cpp:29
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294