00001 #include "TridSetup.h"
00002 #include "TridPageDisplay.h"
00003 #include "TridControl.h"
00004
00005 #include <TEnv.h>
00006 #include <TSystem.h>
00007
00008 #include "Midad/Gui/GuiMainWindow.h"
00009
00010 #include "MessageService/MsgService.h"
00011
00012 #include "sigc++/sigc++.h"
00013 #include "sigc++/class_slot.h"
00014 #include "sigc++/slot.h"
00015
00016
00017 CVSID("$Id: TridSetup.cxx,v 1.12 2007/06/06 05:16:49 rhatcher Exp $");
00018
00019 #ifndef MACOSX
00020 Mint* gMint = NULL;
00021 #endif
00022
00023 PageDisplay* gPageDisplay = NULL;
00024
00025
00026 static GuiMainWindow* gPageDisplayWindow = NULL;
00027
00028
00029 void SaveControlWindow(TEnv& env)
00030 {
00031 MSG("TriD",Msg::kDebug) << "Calling SaveControlWindow()" << endl;
00032
00033 if(gPageDisplayWindow==NULL) {
00034 MSG("TriD",Msg::kWarning) << "Trid control window doesn't exist!" << endl;
00035 return;
00036 }
00037
00038 TString newname(gPageDisplayWindow->GetWindowName());
00039 newname.ReplaceAll(" ","_");
00040
00041 Int_t x,y;
00042 UInt_t w,h;
00043
00044 Window_t wind = (Window_t)(gVirtualX->GetParent(gPageDisplayWindow->GetId()));
00045 Window_t frame = wind;
00046
00047
00048
00049
00050
00051
00052
00053 WindowAttributes_t attr;
00054 gVirtualX->GetWindowAttributes(frame,attr);
00055 x = attr.fX;
00056 y = attr.fY;
00057 w = attr.fWidth;
00058 h = attr.fHeight;
00059
00060
00061 env.SetValue(
00062 Form("Trid.WindowGeom.%s",newname.Data()),
00063 Form("%dx%d+%d+%d",w,h,x,y),
00064 kEnvChange);
00065 MSG("TriD",Msg::kDebug)
00066 << "Setting env variable: "
00067 << Form("Trid.WindowGeom.%s",newname.Data())
00068 << "\t=\t"
00069 << Form("%dx%d+%d+%d",w,h,x,y)
00070 << endl;
00071 }
00072
00073 void RestoreControlWindow(TEnv& env)
00074 {
00075 MSG("TriD",Msg::kDebug) << "Calling RestoreControlWindow()" << endl;
00076
00077
00078
00079 if(gPageDisplayWindow==NULL) {
00080 MSG("TriD",Msg::kWarning) << "Trid control window doesn't exist!" << endl;
00081 return;
00082 }
00083 Int_t x,y;
00084 UInt_t w,h;
00085 TString newname(gPageDisplayWindow->GetWindowName());
00086 newname.ReplaceAll(" ","_");
00087 const char* value = env.GetValue(Form("Trid.WindowGeom.%s",newname.Data()),"");
00088
00089 if(strlen(value)>0) {
00090
00091 Window_t wind = (Window_t)((gPageDisplayWindow->GetId()));
00092 Window_t frame = wind;
00093
00094
00095
00096
00097
00098
00099
00100 WindowAttributes_t attr;
00101 gVirtualX->GetWindowAttributes(frame,attr);
00102 x = attr.fX;
00103 y = attr.fY;
00104 w = attr.fWidth;
00105 h = attr.fHeight;
00106
00107 sscanf(value,"%ux%u+%d+%d",&w,&h,&x,&y);
00108 MSG("TriD",Msg::kDebug) << "----> Got Value " << value << endl;
00109 if(w<20) w = 100;
00110 if(h<20) h = 100;
00111 gVirtualX->MoveResizeWindow(frame,x,y,w,h);
00112 }
00113
00114 }
00115
00116
00117 void TridSetup(JobC& jc)
00118 {
00119
00120 if(gMint) delete gMint;
00121 gMint = new Mint(jc);
00122
00123
00124 if(gPageDisplayWindow) delete gPageDisplayWindow;
00125 gPageDisplayWindow = new GuiMainWindow(500,400);
00126 gPageDisplayWindow->SetWindowName("TriD Minos Event Display");
00127
00128
00129
00130 if(gPageDisplay) delete gPageDisplay;
00131 TridPageDisplay* pd = new TridPageDisplay(*gPageDisplayWindow, gMint);
00132 gPageDisplay = pd;
00133
00134
00135
00136 pd->Init();
00137 pd->close_window.connect(slot(*gPageDisplayWindow,&GuiMainWindow::SendCloseMessage));
00138
00139
00140 pd->fNextSignal. connect(SigC::slot_class(*gMint,&Mint::Next));
00141 pd->fNextPassSignal.connect(SigC::slot_class(*gMint,&Mint::NextPass));
00142 pd->fPrevSignal. connect(SigC::slot_class(*gMint,&Mint::Prev));
00143
00144
00145
00146
00147
00148 gMint->GetJint().mom_modified.connect(slot_class(*(PageDisplay*)pd,
00149 &PageDisplay::ClearDisplay));
00150 gMint->GetJint().mom_modified.connect(slot_class(*(PageDisplay*)pd,
00151 &PageDisplay::UpdateDisplay));
00152
00153 pd->AddPage("EventInfoPage",true);
00154 pd->AddPage("SelectionInfoPage",true);
00155
00156
00157
00158 gPageDisplayWindow->Add(*pd);
00159 gPageDisplayWindow->ShowAll();
00160 gPageDisplayWindow->ConnectClose(true);
00161
00162
00163
00164
00165 const char* filename = gSystem->Getenv("TRID_CONFIG_FILE");
00166 if(filename ==0) filename = ".tridrc";
00167
00168 TEnv env(filename);
00169 const char* windowlist = env.GetValue("Trid.DefaultWindows","");
00170
00171 char windownames[10][100];
00172 int num = sscanf(windowlist,"%99s %99s %99s %99s %99s %99s %99s %99s %99s %99s",
00173 windownames[0],windownames[1],
00174 windownames[2],windownames[3],
00175 windownames[4],windownames[5],
00176 windownames[6],windownames[7],
00177 windownames[8],windownames[9]);
00178 for(int i=0;i<num;i++) {
00179 pd->MySpawnSinglePage(windownames[i]);
00180 }
00181
00182
00183
00184
00185
00186
00187 static SigC::Ptr<TridControl> tc = TridControl::Instance(pd);
00188
00189
00190 tc->fSignal_SaveWindowGeometry.connect (SigC::slot(&SaveControlWindow));
00191 tc->fSignal_RestoreWindowGeometry.connect(SigC::slot(&RestoreControlWindow));
00192
00193
00194 tc->RestoreWindowGeometries();
00195 RestoreControlWindow(env);
00196
00197
00198 pd->FullZoom();
00199 }
00200
00201