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
DD4hepMenu.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 "DD4hep/Plugins.h"
17 #include "DD4hep/Printout.h"
18 #include "DD4hep/Primitives.h"
19 #include "DD4hep/InstanceCount.h"
20 
21 #include "DDEve/View.h"
22 #include "DDEve/DD4hepMenu.h"
23 #include "DDEve/PopupMenu.h"
24 #include "DDEve/EventControl.h"
25 
26 // ROOT include files
27 #include "TEveBrowser.h"
28 #include "TEveManager.h"
29 #include "TEveElement.h"
30 #include "TEveWindow.h"
31 #include "TEveViewer.h"
32 #include "TGLViewer.h"
33 #include "TGClient.h"
34 #include "TSystem.h"
35 
36 // Forward declarations
37 class TEveWindowSlot;
38 
39 using namespace std;
40 using namespace DD4hep;
41 
43 
44 DD4hepMenu::DD4hepMenu(Display* display)
46 : PopupMenu(display->client().GetRoot()), m_display(display), m_evtCtrl(0)
47 {
48  InstanceCount::increment(this);
49 }
50 
52 DD4hepMenu::~DD4hepMenu() {
53  deletePtr(m_evtCtrl);
54  InstanceCount::decrement(this);
55 }
56 
58 void DD4hepMenu::Build(TGMenuBar* bar, int hints) {
59  int id;
60  PopupMenu& m = *this;
61  m.AddEntry("&Load XML", this, &DD4hepMenu::OnLoadXML);
62  //Not for now: m.AddEntry("&Load ROOT Geometry",this, &DD4hepMenu::OnLoadRootGeometry);
63  id = m.AddEntry("&Show Event I/O", this, &DD4hepMenu::OnCreateEventIO);
64  m.menu().DisableEntry(id);
65  id = m.AddEntry("&Open Event Data", this, &DD4hepMenu::OnOpenEventData);
66  m.menu().DisableEntry(id);
67  id = m.AddEntry("&Next Event", this, &DD4hepMenu::OnNextEvent);
68  m.menu().DisableEntry(id);
69  id = m.AddEntry("&Previous Event", this, &DD4hepMenu::OnPreviousEvent);
70  m.menu().DisableEntry(id);
71  m.AddEntry("&Exit", this, &DD4hepMenu::OnExit);
72  bar->AddPopup("&DD4hep",*this, new TGLayoutHints(hints, 0, 4, 0, 0));
73 }
74 
76 void DD4hepMenu::OnGeometryLoaded() {
77  TGPopupMenu& m = menu();
78  m.DisableEntry(m.GetEntry("Load XML")->GetEntryId());
79  m.EnableEntry(m.GetEntry("Show Event I/O")->GetEntryId());
80  m.EnableEntry(m.GetEntry("Open Event Data")->GetEntryId());
81  m.DisableEntry(m.GetEntry("Next Event")->GetEntryId());
82  m.DisableEntry(m.GetEntry("Previous Event")->GetEntryId());
83 }
84 
86 void DD4hepMenu::OnLoadXML(TGMenuEntry* /* entry */, void* /* ptr */) {
87  std::string fname = m_display->OpenXmlFileDialog(".");
88  if ( !fname.empty() ) {
89  m_display->LoadXML(fname.c_str());
90  OnGeometryLoaded();
91  }
92 }
93 
95 void DD4hepMenu::OnLoadRootGeometry(TGMenuEntry* /* entry */, void* /* ptr */) {
96  std::string fname = m_display->OpenEventFileDialog(".");
97  if ( !fname.empty() ) {
98  m_display->LoadGeometryRoot(fname.c_str());
99  }
100 }
101 
103 void DD4hepMenu::OnCreateEventIO(TGMenuEntry* /* entry */, void* /* ptr */) {
104  if ( 0 == m_evtCtrl ) {
105  TEveBrowser* browser = m_display->manager().GetBrowser();
106  browser->StartEmbedding(TRootBrowser::kLeft);
107  m_evtCtrl = new EventControl(m_display,600,450);
108  m_evtCtrl->Build();
109  browser->SetTabTitle("Evt I/O", 0);
110  browser->StopEmbedding();
111  menu().DisableEntry(menu().GetEntry("Show Event I/O")->GetEntryId());
112  }
113 }
114 
116 void DD4hepMenu::OnOpenEventData(TGMenuEntry* /* entry */, void* /* ptr */) {
117  if ( 0 == m_evtCtrl ) {
118  OnCreateEventIO(0,0);
119  }
120  if ( m_evtCtrl->Open() ) {
121  TGPopupMenu& m = menu();
122  m.EnableEntry(m.GetEntry("Open Event Data")->GetEntryId());
123  m.EnableEntry(m.GetEntry("Next Event")->GetEntryId());
124  m.EnableEntry(m.GetEntry("Previous Event")->GetEntryId());
125  }
126 }
127 
129 void DD4hepMenu::OnNextEvent(TGMenuEntry* /* entry */, void* /* ptr */) {
130  m_display->eventHandler().NextEvent();
131 }
132 
134 void DD4hepMenu::OnPreviousEvent(TGMenuEntry* /* entry */, void* /* ptr */) {
135  m_display->eventHandler().PreviousEvent();
136 }
137 
139 void DD4hepMenu::OnExit(TGMenuEntry* /* entry */, void* /* ptr */) {
140  delete m_display;
141  printout(INFO,"DDEve","+++ The life of this display instance ended.... good bye!");
142  gSystem->Exit(0,kTRUE);
143 }
void deletePtr(T *&p)
Helper to delete objects from heap and reset the pointer. Saves many many lines of code...
Definition: Primitives.h:234
DD4hep Menu for the ROOT browser.
Definition: DD4hepMenu.h:38
TGPopupMenu & menu()
Access to implementation.
Definition: PopupMenu.h:54
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:61
class PopupMenu PopupMenu.h DDEve/PopupMenu.h
Definition: PopupMenu.h:37
static const double bar
Definition: DD4hepUnits.h:180
ClassImp(DD4hepMenu) DD4hepMenu
Initializing constructor.
Definition: DD4hepMenu.cpp:42
int printout(PrintLevel severity, const char *src, const char *fmt,...)
Calls the display action with a given severity level.
Definition: Printout.cpp:111
The main class of the DDEve display.
Definition: Display.h:57
TGeoShape TGeoMedium * m
Definition: Volumes.cpp:294