DD4hep  1.30.0
Detector Description Toolkit for High Energy Physics
DD4hepMenu.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 <DD4hep/Plugins.h>
16 #include <DD4hep/Printout.h>
17 #include <DD4hep/Primitives.h>
18 #include <DD4hep/InstanceCount.h>
19 
20 #include <DDEve/View.h>
21 #include <DDEve/DD4hepMenu.h>
22 #include <DDEve/PopupMenu.h>
23 #include <DDEve/EventControl.h>
24 
25 // ROOT include files
26 #include <TEveBrowser.h>
27 #include <TEveManager.h>
28 #include <TEveElement.h>
29 #include <TEveWindow.h>
30 #include <TEveViewer.h>
31 #include <TGLViewer.h>
32 #include <TGClient.h>
33 #include <TSystem.h>
34 
35 // Forward declarations
36 class TEveWindowSlot;
37 
38 using namespace dd4hep;
39 
41 
44 : PopupMenu(display->client().GetRoot()), m_display(display), m_evtCtrl(0)
45 {
46  InstanceCount::increment(this);
47 }
48 
50 DD4hepMenu::~DD4hepMenu() {
51  detail::deletePtr(m_evtCtrl);
53 }
54 
56 void DD4hepMenu::Build(TGMenuBar* menubar, int hints) {
57  int id;
58  PopupMenu& pm = *this;
59  pm.AddEntry("&Load XML", this, &DD4hepMenu::OnLoadXML);
60  //Not for now: pm.AddEntry("&Load ROOT Geometry",this, &DD4hepMenu::OnLoadRootGeometry);
61  id = pm.AddEntry("&Show Event I/O", this, &DD4hepMenu::OnCreateEventIO);
62  pm.menu().DisableEntry(id);
63  id = pm.AddEntry("&Open Event Data", this, &DD4hepMenu::OnOpenEventData);
64  pm.menu().DisableEntry(id);
65  id = pm.AddEntry("&Next Event", this, &DD4hepMenu::OnNextEvent);
66  pm.menu().DisableEntry(id);
67  id = pm.AddEntry("&Previous Event", this, &DD4hepMenu::OnPreviousEvent);
68  pm.menu().DisableEntry(id);
69  pm.AddEntry("&Exit", this, &DD4hepMenu::OnExit);
70  menubar->AddPopup("&dd4hep",*this, new TGLayoutHints(hints, 0, 4, 0, 0));
71 }
72 
75  TGPopupMenu& pm = menu();
76  pm.DisableEntry(pm.GetEntry("Load XML")->GetEntryId());
77  pm.EnableEntry(pm.GetEntry("Show Event I/O")->GetEntryId());
78  pm.EnableEntry(pm.GetEntry("Open Event Data")->GetEntryId());
79  pm.DisableEntry(pm.GetEntry("Next Event")->GetEntryId());
80  pm.DisableEntry(pm.GetEntry("Previous Event")->GetEntryId());
81 }
82 
84 void DD4hepMenu::OnLoadXML(TGMenuEntry* /* entry */, void* /* ptr */) {
85  std::string fname = m_display->OpenXmlFileDialog(".");
86  if ( !fname.empty() ) {
87  m_display->LoadXML(fname.c_str());
89  }
90 }
91 
93 void DD4hepMenu::OnLoadRootGeometry(TGMenuEntry* /* entry */, void* /* ptr */) {
94  std::string fname = m_display->OpenEventFileDialog(".");
95  if ( !fname.empty() ) {
96  m_display->LoadGeometryRoot(fname.c_str());
97  }
98 }
99 
101 void DD4hepMenu::OnCreateEventIO(TGMenuEntry* /* entry */, void* /* ptr */) {
102  if ( 0 == m_evtCtrl ) {
103  TEveBrowser* browser = m_display->manager().GetBrowser();
104  browser->StartEmbedding(TRootBrowser::kLeft);
105  m_evtCtrl = new EventControl(m_display,600,450);
106  m_evtCtrl->Build();
107  browser->SetTabTitle("Evt I/O", 0);
108  browser->StopEmbedding();
109  menu().DisableEntry(menu().GetEntry("Show Event I/O")->GetEntryId());
110  }
111 }
112 
114 void DD4hepMenu::OnOpenEventData(TGMenuEntry* /* entry */, void* /* ptr */) {
115  if ( 0 == m_evtCtrl ) {
116  OnCreateEventIO(0,0);
117  }
118  if ( m_evtCtrl->Open() ) {
119  TGPopupMenu& pm = menu();
120  pm.EnableEntry(pm.GetEntry("Open Event Data")->GetEntryId());
121  pm.EnableEntry(pm.GetEntry("Next Event")->GetEntryId());
122  pm.EnableEntry(pm.GetEntry("Previous Event")->GetEntryId());
123  }
124 }
125 
127 void DD4hepMenu::OnNextEvent(TGMenuEntry* /* entry */, void* /* ptr */) {
129 }
130 
132 void DD4hepMenu::OnPreviousEvent(TGMenuEntry* /* entry */, void* /* ptr */) {
134 }
135 
137 void DD4hepMenu::OnExit(TGMenuEntry* /* entry */, void* /* ptr */) {
138  delete m_display;
139  printout(INFO,"DDEve","+++ The life of this display instance ended.... good bye!");
140  gSystem->Exit(0,kTRUE);
141 }
dd4hep::Display
The main class of the DDEve display.
Definition: Display.h:56
dd4hep::DD4hepMenu::m_display
Display * m_display
Reference to display manager.
Definition: DD4hepMenu.h:42
dd4hep::DD4hepMenu::OnCreateEventIO
void OnCreateEventIO(TGMenuEntry *entry, void *ptr)
Callback to show the event I/O panel.
Definition: DD4hepMenu.cpp:101
dd4hep::Display::OpenEventFileDialog
std::string OpenEventFileDialog(const std::string &default_dir) const
Popup ROOT file chooser. returns chosen file name; empty on cancel.
Definition: Display.cpp:313
dd4hep::DD4hepMenu::OnPreviousEvent
void OnPreviousEvent(TGMenuEntry *entry, void *ptr)
Callback when loading the previous event.
Definition: DD4hepMenu.cpp:132
dd4hep::DD4hepMenu::Build
virtual void Build(TGMenuBar *menuBar, int hints=kLHintsNormal) override
Add the menu to the menu bar.
Definition: DD4hepMenu.cpp:56
dd4hep::EventControl::Open
virtual bool Open()
Open a new event data file.
Definition: EventControl.cpp:81
dd4hep::DD4hepMenu::OnOpenEventData
void OnOpenEventData(TGMenuEntry *entry, void *ptr)
Callback when loading a new event data file.
Definition: DD4hepMenu.cpp:114
dd4hep::DD4hepMenu::OnExit
void OnExit(TGMenuEntry *entry, void *ptr)
Callback when exiting the display.
Definition: DD4hepMenu.cpp:137
dd4hep::GenericEventHandler::NextEvent
virtual bool NextEvent() override
Load the next event.
Definition: GenericEventHandler.cpp:147
dd4hep::Display::OpenXmlFileDialog
std::string OpenXmlFileDialog(const std::string &default_dir) const
Popup XML file chooser. returns chosen file name; empty on cancel.
Definition: Display.cpp:292
dd4hep::DD4hepMenu::OnNextEvent
void OnNextEvent(TGMenuEntry *entry, void *ptr)
Callback when loading the next event.
Definition: DD4hepMenu.cpp:127
ClassImp
ClassImp(DD4hepMenu) DD4hepMenu
Initializing constructor.
Definition: DD4hepMenu.cpp:40
dd4hep::DD4hepMenu::DD4hepMenu
DD4hepMenu(Display *eve)
Standard constructor.
dd4hep::GenericEventHandler::PreviousEvent
virtual bool PreviousEvent() override
User overloadable function: Load the previous event.
Definition: GenericEventHandler.cpp:171
dd4hep::InstanceCount::decrement
static void decrement(T *)
Decrement count according to type information.
Definition: InstanceCount.h:102
dd4hep::Display::LoadXML
void LoadXML(const char *xmlFile)
Load geometry from compact xml file.
Definition: Display.cpp:131
dd4hep::DD4hepMenu::OnLoadRootGeometry
void OnLoadRootGeometry(TGMenuEntry *entry, void *ptr)
Callback when loading the configuration.
Definition: DD4hepMenu.cpp:93
dd4hep::DD4hepMenu::OnLoadXML
void OnLoadXML(TGMenuEntry *entry, void *ptr)
Callback when loading the configuration.
Definition: DD4hepMenu.cpp:84
Plugins.h
dd4hep::EventControl
Event input control for DDEve: Interface class for event I/O.
Definition: EventControl.h:37
PopupMenu.h
dd4hep::FrameControl::Build
virtual void Build()
Build the control.
Definition: FrameControl.cpp:46
dd4hep::PopupMenu::AddEntry
virtual int AddEntry(const char *name, Callback cb, void *ud=0, const TGPicture *p=0, TGMenuEntry *before=0)
Add a new popup menu entry with a callback.
Definition: PopupMenu.cpp:60
Primitives.h
dd4hep::Display::LoadGeometryRoot
void LoadGeometryRoot(const char *rootFile)
Load geometry from compact xml file.
Definition: Display.cpp:148
dd4hep::PopupMenu
class PopupMenu PopupMenu.h DDEve/PopupMenu.h
Definition: PopupMenu.h:36
dd4hep::Display::eventHandler
GenericEventHandler & eventHandler() const
Access to the event reader.
Definition: Display.cpp:168
dd4hep::DD4hepMenu
dd4hep Menu for the ROOT browser
Definition: DD4hepMenu.h:37
dd4hep
Namespace for the AIDA detector description toolkit.
Definition: AlignmentsCalib.h:28
dd4hep::DD4hepMenu::OnGeometryLoaded
void OnGeometryLoaded()
Callback when the geometry was loaded.
Definition: DD4hepMenu.cpp:74
DD4hepMenu.h
InstanceCount.h
View.h
dd4hep::PopupMenu::menu
TGPopupMenu & menu()
Access to implementation.
Definition: PopupMenu.h:53
Printout.h
EventControl.h
dd4hep::Display::manager
TEveManager & manager() const
Access to the EVE manager.
Definition: Display.h:131
dd4hep::DD4hepMenu::m_evtCtrl
EventControl * m_evtCtrl
Definition: DD4hepMenu.h:43