Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:14:11

0001 //==========================================================================
0002 //  AIDA Detector description implementation 
0003 //--------------------------------------------------------------------------
0004 // Copyright (C) Organisation europeenne pour la Recherche nucleaire (CERN)
0005 // All rights reserved.
0006 //
0007 // For the licensing terms see $DD4hepINSTALL/LICENSE.
0008 // For the list of contributors see $DD4hepINSTALL/doc/CREDITS.
0009 //
0010 // Author     : M.Frank
0011 //
0012 //==========================================================================
0013 
0014 // Framework include files
0015 #include <DDEve/ContextMenu.h>
0016 
0017 // ROOT include files
0018 #include <TList.h>
0019 #include <TClassMenuItem.h>
0020 
0021 // C/C++ include files
0022 #include <stdexcept>
0023 #include <map>
0024 
0025 using namespace dd4hep;
0026 
0027 typedef std::map<std::string,ContextMenu*> Contexts;
0028 static Contexts& mapped_entries()  {
0029   static Contexts e;
0030   return e;
0031 }
0032 
0033 ClassImp(ContextMenuHandler)
0034 
0035 /// Initializing constructor
0036 ContextMenuHandler::ContextMenuHandler(Callback cb, void* par)
0037 : m_call(cb), m_param(par) 
0038 {
0039 }
0040 
0041 /// Default destructor
0042 ContextMenuHandler::~ContextMenuHandler()   {
0043 }
0044 
0045 /// Callback
0046 void ContextMenuHandler::Context(TObject* target)   {
0047   const void *args[] = {target,m_param,0};
0048   m_call.execute(args);
0049 }
0050 
0051 
0052 ClassImp(ContextMenu)
0053 
0054 /// Initializing constructor
0055 ContextMenu::ContextMenu(TClass* cl) : m_class(cl)  {
0056   if ( !cl )   {
0057     throw std::runtime_error("Failure: Cannot create context menu for NULL class!");
0058   }
0059 }
0060 
0061 /// Default destructor
0062 ContextMenu::~ContextMenu()   {
0063 }
0064 
0065 /// Instantiator
0066 ContextMenu& ContextMenu::instance(TClass* cl)  {
0067   Contexts::const_iterator i = mapped_entries().find(cl->GetName());
0068   if ( i != mapped_entries().end() ) return *((*i).second);
0069   ContextMenu* m = new ContextMenu(cl);
0070   mapped_entries().emplace(cl->GetName(),m);
0071   return *m;
0072 }
0073 
0074 /// Clear all existing items
0075 ContextMenu& ContextMenu::Clear()   {
0076   if ( m_class->GetMenuList() )  {
0077     m_class->GetMenuList()->Delete();
0078   }
0079   return *this;
0080 }
0081 
0082 /// Add a separator
0083 ContextMenu& ContextMenu::AddSeparator()   {
0084   TClassMenuItem* item = 
0085     new TClassMenuItem(TClassMenuItem::kPopupSeparator,ContextMenuHandler::Class(),"seperator");
0086   m_class->GetMenuList()->AddFirst(item);
0087   return *this;
0088 }
0089 
0090 /// Add user callback 
0091 ContextMenu& ContextMenu::Add(const std::string& title, Callback cb, void* ud)   {
0092   ContextMenuHandler* handler = new ContextMenuHandler(cb, ud);
0093   TClassMenuItem* item = 
0094     new TClassMenuItem(TClassMenuItem::kPopupUserFunction,
0095                        ContextMenuHandler::Class(),title.c_str(),
0096                        "Context",handler,"TObject*",2);
0097   m_calls.push_back(handler);
0098   m_class->GetMenuList()->AddLast(item);
0099   return *this;
0100 }