File indexing completed on 2025-03-13 08:19:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 #include <DD4hep/Plugins.h>
0016 #include <DD4hep/Printout.h>
0017 #include <DD4hep/Primitives.h>
0018 #include <DD4hep/InstanceCount.h>
0019
0020 #include <DDEve/View.h>
0021 #include <DDEve/DD4hepMenu.h>
0022 #include <DDEve/PopupMenu.h>
0023 #include <DDEve/EventControl.h>
0024
0025
0026 #include <TEveBrowser.h>
0027 #include <TEveManager.h>
0028 #include <TEveElement.h>
0029 #include <TEveWindow.h>
0030 #include <TEveViewer.h>
0031 #include <TGLViewer.h>
0032 #include <TGClient.h>
0033 #include <TSystem.h>
0034
0035
0036 class TEveWindowSlot;
0037
0038 using namespace dd4hep;
0039
0040 ClassImp(DD4hepMenu)
0041
0042
0043 DD4hepMenu::DD4hepMenu(Display* display)
0044 : PopupMenu(display->client().GetRoot()), m_display(display), m_evtCtrl(0)
0045 {
0046 InstanceCount::increment(this);
0047 }
0048
0049
0050 DD4hepMenu::~DD4hepMenu() {
0051 detail::deletePtr(m_evtCtrl);
0052 InstanceCount::decrement(this);
0053 }
0054
0055
0056 void DD4hepMenu::Build(TGMenuBar* menubar, int hints) {
0057 int id;
0058 PopupMenu& pm = *this;
0059 pm.AddEntry("&Load XML", this, &DD4hepMenu::OnLoadXML);
0060
0061 id = pm.AddEntry("&Show Event I/O", this, &DD4hepMenu::OnCreateEventIO);
0062 pm.menu().DisableEntry(id);
0063 id = pm.AddEntry("&Open Event Data", this, &DD4hepMenu::OnOpenEventData);
0064 pm.menu().DisableEntry(id);
0065 id = pm.AddEntry("&Next Event", this, &DD4hepMenu::OnNextEvent);
0066 pm.menu().DisableEntry(id);
0067 id = pm.AddEntry("&Previous Event", this, &DD4hepMenu::OnPreviousEvent);
0068 pm.menu().DisableEntry(id);
0069 pm.AddEntry("&Exit", this, &DD4hepMenu::OnExit);
0070 menubar->AddPopup("&dd4hep",*this, new TGLayoutHints(hints, 0, 4, 0, 0));
0071 }
0072
0073
0074 void DD4hepMenu::OnGeometryLoaded() {
0075 TGPopupMenu& pm = menu();
0076 pm.DisableEntry(pm.GetEntry("Load XML")->GetEntryId());
0077 pm.EnableEntry(pm.GetEntry("Show Event I/O")->GetEntryId());
0078 pm.EnableEntry(pm.GetEntry("Open Event Data")->GetEntryId());
0079 pm.DisableEntry(pm.GetEntry("Next Event")->GetEntryId());
0080 pm.DisableEntry(pm.GetEntry("Previous Event")->GetEntryId());
0081 }
0082
0083
0084 void DD4hepMenu::OnLoadXML(TGMenuEntry* , void* ) {
0085 std::string fname = m_display->OpenXmlFileDialog(".");
0086 if ( !fname.empty() ) {
0087 m_display->LoadXML(fname.c_str());
0088 OnGeometryLoaded();
0089 }
0090 }
0091
0092
0093 void DD4hepMenu::OnLoadRootGeometry(TGMenuEntry* , void* ) {
0094 std::string fname = m_display->OpenEventFileDialog(".");
0095 if ( !fname.empty() ) {
0096 m_display->LoadGeometryRoot(fname.c_str());
0097 }
0098 }
0099
0100
0101 void DD4hepMenu::OnCreateEventIO(TGMenuEntry* , void* ) {
0102 if ( 0 == m_evtCtrl ) {
0103 TEveBrowser* browser = m_display->manager().GetBrowser();
0104 browser->StartEmbedding(TRootBrowser::kLeft);
0105 m_evtCtrl = new EventControl(m_display,600,450);
0106 m_evtCtrl->Build();
0107 browser->SetTabTitle("Evt I/O", 0);
0108 browser->StopEmbedding();
0109 menu().DisableEntry(menu().GetEntry("Show Event I/O")->GetEntryId());
0110 }
0111 }
0112
0113
0114 void DD4hepMenu::OnOpenEventData(TGMenuEntry* , void* ) {
0115 if ( 0 == m_evtCtrl ) {
0116 OnCreateEventIO(0,0);
0117 }
0118 if ( m_evtCtrl->Open() ) {
0119 TGPopupMenu& pm = menu();
0120 pm.EnableEntry(pm.GetEntry("Open Event Data")->GetEntryId());
0121 pm.EnableEntry(pm.GetEntry("Next Event")->GetEntryId());
0122 pm.EnableEntry(pm.GetEntry("Previous Event")->GetEntryId());
0123 }
0124 }
0125
0126
0127 void DD4hepMenu::OnNextEvent(TGMenuEntry* , void* ) {
0128 m_display->eventHandler().NextEvent();
0129 }
0130
0131
0132 void DD4hepMenu::OnPreviousEvent(TGMenuEntry* , void* ) {
0133 m_display->eventHandler().PreviousEvent();
0134 }
0135
0136
0137 void DD4hepMenu::OnExit(TGMenuEntry* , void* ) {
0138 delete m_display;
0139 printout(INFO,"DDEve","+++ The life of this display instance ended.... good bye!");
0140 gSystem->Exit(0,kTRUE);
0141 }