DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
ContextMenu.cpp
Go to the documentation of this file.
1 //==========================================================================
2 // AIDA Detector description implementation
3 //--------------------------------------------------------------------------
4 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
5 // All rights reserved.
6 //
7 // For the licensing terms see $DD4hepINSTALL/LICENSE.
8 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
9 //
10 // Author : M.Frank
11 //
12 //==========================================================================
13 
14 // Framework include files
15 #include <DDEve/ContextMenu.h>
16 
17 // ROOT include files
18 #include <TList.h>
19 #include <TClassMenuItem.h>
20 
21 // C/C++ include files
22 #include <stdexcept>
23 #include <map>
24 
25 using namespace dd4hep;
26 
27 typedef std::map<std::string,ContextMenu*> Contexts;
28 static Contexts& mapped_entries() {
29  static Contexts e;
30  return e;
31 }
32 
34 
37 : m_call(cb), m_param(par)
38 {
39 }
40 
42 ContextMenuHandler::~ContextMenuHandler() {
43 }
44 
47  const void *args[] = {target,m_param,0};
48  m_call.execute(args);
49 }
50 
51 
53 
54 ContextMenu::ContextMenu(TClass* cl) : m_class(cl) {
56  if ( !cl ) {
57  throw std::runtime_error("Failure: Cannot create context menu for NULL class!");
58  }
59 }
60 
62 ContextMenu::~ContextMenu() {
63 }
64 
67  Contexts::const_iterator i = mapped_entries().find(cl->GetName());
68  if ( i != mapped_entries().end() ) return *((*i).second);
69  ContextMenu* m = new ContextMenu(cl);
70  mapped_entries().emplace(cl->GetName(),m);
71  return *m;
72 }
73 
76  if ( m_class->GetMenuList() ) {
77  m_class->GetMenuList()->Delete();
78  }
79  return *this;
80 }
81 
84  TClassMenuItem* item =
85  new TClassMenuItem(TClassMenuItem::kPopupSeparator,ContextMenuHandler::Class(),"seperator");
86  m_class->GetMenuList()->AddFirst(item);
87  return *this;
88 }
89 
91 ContextMenu& ContextMenu::Add(const std::string& title, Callback cb, void* ud) {
92  ContextMenuHandler* handler = new ContextMenuHandler(cb, ud);
93  TClassMenuItem* item =
94  new TClassMenuItem(TClassMenuItem::kPopupUserFunction,
95  ContextMenuHandler::Class(),title.c_str(),
96  "Context",handler,"TObject*",2);
97  m_calls.push_back(handler);
98  m_class->GetMenuList()->AddLast(item);
99  return *this;
100 }
dd4hep::ContextMenu::m_calls
Handlers m_calls
Callback map.
Definition: ContextMenu.h:67
dd4hep::ContextMenu
DD4hep specific TEve context menu.
Definition: ContextMenu.h:64
dd4hep::ContextMenu::Add
ContextMenu & Add(const std::string &title, Callback cb, void *ud)
Add user callback.
Definition: ContextMenu.cpp:91
dd4hep::ContextMenuHandler
DD4hep specific handler for TEve context menus.
Definition: ContextMenu.h:37
dd4hep::Callback
Definition of the generic callback structure for member functions.
Definition: Callback.h:38
dd4hep::ContextMenuHandler::ContextMenuHandler
ContextMenuHandler(Callback cb, void *param)
Initializing constructor.
dd4hep::ContextMenu::AddSeparator
ContextMenu & AddSeparator()
Add a separator.
Definition: ContextMenu.cpp:83
dd4hep::ContextMenu::Clear
ContextMenu & Clear()
Clear all existing items.
Definition: ContextMenu.cpp:75
Contexts
std::map< std::string, ContextMenu * > Contexts
Definition: ContextMenu.cpp:27
dd4hep::ContextMenu::m_class
TClass * m_class
List of menu entries.
Definition: ContextMenu.h:69
dd4hep::Callback::execute
unsigned long execute(const void *user_param[]) const
Execute the callback with the required number of user parameters.
Definition: Callback.h:76
dd4hep::ContextMenuHandler::m_param
void * m_param
User parameter.
Definition: ContextMenu.h:42
TObject
Class of the ROOT toolkit. See http://root.cern.ch/root/htmldoc/ClassIndex.html.
Definition: ROOTClasses.h:41
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::ContextMenu::instance
static ContextMenu & instance(TClass *cl)
Instantiator.
Definition: ContextMenu.cpp:66
ClassImp
ClassImp(ContextMenuHandler) ContextMenuHandler
Initializing constructor.
Definition: ContextMenu.cpp:33
dd4hep::ContextMenuHandler::m_call
Callback m_call
User callback.
Definition: ContextMenu.h:40
dd4hep::ContextMenuHandler::Context
void Context(TObject *target)
Callback.
Definition: ContextMenu.cpp:46
dd4hep::ContextMenu::ContextMenu
ContextMenu(TClass *cl)
Initializing constructor.
ContextMenu.h