00001
00002
00003
00004
00005
00006
00007
00008 #include "EventDisplayBase/JobMenu.h"
00009 #include <cstdlib>
00010 #include <string>
00011 #include <iostream>
00012 #include "TROOT.h"
00013 #include "TSystem.h"
00014 #include "TGMsgBox.h"
00015 #include "TGMenu.h"
00016 #include "TGLayout.h"
00017 #include "TGFileDialog.h"
00018 #include "TTimer.h"
00019 #include "EventDisplayBase/evdb.h"
00020 #include "XMLInterface/xmli.h"
00021 #include "JobControl/Stack.h"
00022 #include "Config/Table.h"
00023 #include "Config/Config.h"
00024 #include "EventDisplayBase/CfgEdit.h"
00025 #include "EventDisplayBase/IoModule.h"
00026 using namespace evdb;
00027
00028
00029 enum {
00030 kM_JOB_OPENXML = 99001,
00031 kM_JOB_EDITCONFIG = 99002,
00032 kM_JOB_AUTO_ADVANCE_START = 99003,
00033 kM_JOB_AUTO_ADVANCE_STOP = 99004
00034 };
00035
00036 static cfg::Config* gsConfig[1024];
00037
00038
00039
00040 JobMenu::JobMenu(TGMenuBar* menubar, TGMainFrame* mf) :
00041 fMainFrame(mf)
00042 {
00043
00044
00045
00046 fJobMenu = new TGPopupMenu(gClient->GetRoot());
00047 fLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0);
00048
00049 fConfigMenu = new TGPopupMenu(gClient->GetRoot());
00050 this->BuildConfigMenu();
00051
00052
00053 fJobMenu->AddEntry("&Open XML", kM_JOB_OPENXML);
00054 fJobMenu->AddPopup("&Edit Config", fConfigMenu);
00055 fJobMenu->AddEntry("Start Auto Advance", kM_JOB_AUTO_ADVANCE_START);
00056 fJobMenu->AddEntry("Stop Auto Advance", kM_JOB_AUTO_ADVANCE_STOP);
00057
00058 fJobMenu->Connect("Activated(Int_t)",
00059 "evdb::JobMenu",this,"HandleMenu(int)");
00060
00061
00062 menubar->AddPopup("&Job",fJobMenu,fLayout);
00063 }
00064
00065
00066
00067 JobMenu::~JobMenu()
00068 {
00069
00070
00071
00072 if (fLayout) { delete fLayout; fLayout = 0; }
00073 if (fJobMenu) { delete fJobMenu; fJobMenu = 0; }
00074 }
00075
00076
00077
00078 void JobMenu::BuildConfigMenu()
00079 {
00080
00081 for (int i=0;;++i) {
00082 TGMenuEntry* m = fConfigMenu->GetEntry(i);
00083 if (m) fConfigMenu->DeleteEntry(i);
00084 else break;
00085 }
00086
00087
00088 int icfg = 0;
00089 cfg::Table::ConfigList& cfglist = cfg::Table::Instance().GetList();
00090 cfg::Table::ConfigList::iterator itr (cfglist.begin());
00091 cfg::Table::ConfigList::iterator itrEnd(cfglist.end());
00092 for (; itr!=itrEnd; ++itr) {
00093 fConfigMenu->AddEntry((*itr)->GetName(), icfg);
00094 gsConfig[icfg] = (*itr);
00095 ++icfg;
00096 }
00097 fConfigMenu->Connect("Activated(Int_t)",
00098 "evdb::JobMenu",this,"EditConfig(int)");
00099 }
00100
00101
00102
00103 void JobMenu::HandleMenu(int menu)
00104 {
00105
00106
00107
00108 switch(menu) {
00109 case kM_JOB_OPENXML:
00110 this->OpenJobXML();
00111 break;
00112 case kM_JOB_AUTO_ADVANCE_START:
00113 IoModule::Instance()->StartAutoAdvance();
00114 break;
00115 case kM_JOB_AUTO_ADVANCE_STOP:
00116 IoModule::Instance()->StopAutoAdvance();
00117 break;
00118 default:
00119
00120
00121 this->EditConfig(menu);
00122 break;
00123 }
00124 }
00125
00126
00127
00128 void JobMenu::EditConfig(int i)
00129 {
00130 new CfgEdit(gsConfig[i], fMainFrame);
00131 }
00132
00133
00134
00135 int JobMenu::OpenJobXML()
00136 {
00137 static TString dir(getenv("SRT_PRIVATE_CONTEXT"));
00138 const char* filetypes[] = {
00139 "XML Files", "*.xml",
00140 0, 0
00141 };
00142
00143 TGFileInfo finfo;
00144 finfo.fIniDir = StrDup(dir.Data());
00145 finfo.fFileTypes = filetypes;
00146
00147 new TGFileDialog(gClient->GetRoot(),
00148 gClient->GetRoot(),
00149 kFDOpen,
00150 &finfo);
00151 if (finfo.fFilename == 0) return 0;
00152
00153
00154
00155 xmli::AddToPath(finfo.fIniDir,-1);
00156
00157
00158 cfg::Config::SetEditAllOK();
00159
00160
00161 xmli::ReadFile(finfo.fFilename);
00162 jobc::Stack::Instance().PrintAll();
00163
00164
00165 this->BuildConfigMenu();
00166
00167
00168 IoModule::Instance()->Reload();
00169
00170 return 0;
00171 }
00172