SCC/TFndSCCgui.cxx

00001 // @(#)fROOT/SCC:$Name:  $:$Id: TFndSCCgui.cxx,v 1.43 2007/09/24 07:32:41 Diego_Faso Exp $
00002 // Author: Diego Faso <mailto:faso@to.infn.it>, 2006/03/03
00003 
00005 //                                                    //
00006 //  Class for the FINUDA Slow Control Center main GUI //
00007 //                                                    //
00009 
00010 
00011 #include "TFndSCCgui.h"
00012 
00013 ClassImp(TFndSCCgui)
00014 
00015 //_______________________
00016 TFndSCCgui::TFndSCCgui():
00017   fMainFrame()
00018 {
00019 
00020   fCurPicture = 0;
00021   fFontType = "-adobe-helvetica-medium-r-*-*-";
00022   fFontSize = 10;
00023   fFontISO = "-*-*-*-*-*-iso8859-1";
00024 
00025   UInt_t NewHeightWidth = (Int_t)(Gui::GetTGadj(0) * 109);
00026 
00027   if(gClient){
00028     fPictureList[0] = gClient->GetPicture("$FROOTSYS/images/fnd_logo.gif",NewHeightWidth,NewHeightWidth);
00029     fPictureList[1] = gClient->GetPicture("$FROOTSYS/images/CAD_SpectrometerDesign.jpg",NewHeightWidth,NewHeightWidth);
00030     fPictureList[2] = gClient->GetPicture("$FROOTSYS/images/ISIM_OSIM_scheme_3D.jpg",NewHeightWidth,NewHeightWidth);
00031     fPictureList[3] = gClient->GetPicture("$FROOTSYS/images/InteractionRegionScheme.jpg",NewHeightWidth,NewHeightWidth);
00032     fPictureList[4] = gClient->GetPicture("$FROOTSYS/images/LMD_Photo.jpg",NewHeightWidth,NewHeightWidth);
00033     fPictureList[5] = gClient->GetPicture("$FROOTSYS/images/StrawsAssembled.jpg",NewHeightWidth,NewHeightWidth);
00034     fPictureList[6] = gClient->GetPicture("$FROOTSYS/images/TofinoSlabsMontate.jpg",NewHeightWidth,NewHeightWidth);
00035     fPictureList[7] = gClient->GetPicture("$FROOTSYS/images/TofinoSlabsMontateInterno.jpg",NewHeightWidth,NewHeightWidth);
00036     fPictureList[8] = gClient->GetPicture("$FROOTSYS/images/TofinoSlabsMontateInterno_2.jpg",NewHeightWidth,NewHeightWidth);
00037     fPictureList[9] = gClient->GetPicture("$FROOTSYS/images/Tofone_Assembled.jpg",NewHeightWidth,NewHeightWidth);
00038   }
00039 
00040   // ---
00041   TString BaseVocalMessage = "Error detected: ";
00042 
00043   fVocalErrorMessage[TOFI].Form("%s TOFINO",BaseVocalMessage.Data()) ;
00044   fVocalErrorMessage[TOFO].Form("%s TOFONI",BaseVocalMessage.Data()) ;
00045   fVocalErrorMessage[LMD].Form("%s DRIFT CHAMBERS",BaseVocalMessage.Data()) ;
00046   fVocalErrorMessage[STB].Form("%s STRAW TUBES",   BaseVocalMessage.Data()) ;
00047   fVocalErrorMessage[GAS].Form("%s GAS SYSTEM",    BaseVocalMessage.Data()) ;
00048   fVocalErrorMessage[SIL].Form("%s SILICON DETECTORS",BaseVocalMessage.Data()) ;
00049   fVocalErrorMessage[MAG].Form("%s MAGNETIC FIELD",   BaseVocalMessage.Data()) ;
00050   
00051   for(Int_t i=0;i<K_N_SLOWS;i++) fLastErrorSolved[i] = kTRUE;
00052 }
00053 
00054 //_______________________
00055 TFndSCCgui::~TFndSCCgui(){
00056   
00057   //  fMainFrame->Cleanup();
00058   if(K_DEBUG_LEV > 0) Printf("TFndSCCgui Destructor succesfully called");
00059 }
00060 
00061 //_______________________
00062 void TFndSCCgui::Relax(Bool_t more){
00063   // This method has been added in order
00064   // to allow GUI operations (for example pressing buttons)
00065   // while receiving data
00066 
00067   //  unsigned long how_much = 5;
00068   //  if(more)
00069   //  how_much = 100;
00070   //  gSystem->Sleep(how_much);
00071   //  fMainFrame->Layout(); 
00072   //  fMainFrame->RequestFocus();
00073   //gClient->ProcessEventsFor(fMainFrame); // don't use this method within button methods
00074   gClient->NeedRedraw(fMainFrame);
00075   if(more) gClient->ProcessEventsFor(fMainFrame); // don't use this method within button methods
00076 }
00077 
00078 //_______________________
00079 void TFndSCCgui::BuildGUI(){
00080 
00081   fMainFrame = new TGMainFrame(gClient->GetRoot(),10,10,kMainFrame | kVerticalFrame);
00082   //
00083   //  fMainFrame->SetLayoutBroken(kTRUE);
00084   fMainFrame->SetCleanup(kDeepCleanup);
00085   // ---
00086 
00087   fCompFrame = new TGCompositeFrame(fMainFrame,10,10,kVerticalFrame);
00088   fCompFrame->SetLayoutBroken(kTRUE);
00089 
00090 
00091   SetFontType(fFontType);
00092   SetFontSize(18);
00093   //   fontstring+=(Int_t)(Gui::GetTGadj(1) * 18.);
00094   //   fontstring+=fFontISO;
00095   TGFont *u_title_font = gClient->GetFont(fFontString.Data());
00096   TGGC   *u_title_GC;           
00097   GCValues_t g_context_title;
00098   g_context_title.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
00099   gClient->GetColorByName("#000000",g_context_title.fForeground);
00100   gClient->GetColorByName("#c6c2c6",g_context_title.fBackground);
00101   g_context_title.fFillStyle = kFillSolid;
00102   g_context_title.fFont = u_title_font->GetFontHandle();
00103   g_context_title.fGraphicsExposures = kFALSE;
00104   u_title_GC = gClient->GetGC(&g_context_title, kTRUE);
00105 
00106   fLblTitle = new TGLabel(fCompFrame,"SCC (the FINUDA Slow Control Center)",u_title_GC->GetGC(),u_title_font->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00107   fCompFrame->AddFrame(fLblTitle, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00108   Gui::MoveResizeSafe(1.46,1., 899,29,fLblTitle);
00109 
00110   // Build Control Group frame for all detectors (slow-controls)
00111   //  enum SlowDetectors_e {TOFI = 0, TOFO, LMD, STB, GAS, SIL, MAG};
00112   BuildSingleSlwFrame(TOFI);
00113   BuildSingleSlwFrame(TOFO);
00114   BuildSingleSlwFrame(LMD);
00115   BuildSingleSlwFrame(STB);
00116   BuildSingleSlwFrame(GAS);
00117   BuildSingleSlwFrame(SIL);
00118   BuildSingleSlwFrame(MAG);
00119   for(Int_t i=0;i<K_N_SLOWS;i++) AdjustSingleSlwFrame(i);
00120 
00121   // graphics context changes
00122   // TGFont will reflect user font changes
00123   // TGGC will reflect user GC changes
00124   SetFontType(fFontType);
00125   SetFontSize(8.7);
00126   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 8.7);
00127   //   fFontString+=fFontISO;
00128 
00129   TGFont *ufont = gClient->GetFont(fFontString.Data());
00130   TGGC   *uGC;           
00131   GCValues_t g_context_default;
00132   g_context_default.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
00133   gClient->GetColorByName("#000000",g_context_default.fForeground);
00134   gClient->GetColorByName("#c6c2c6",g_context_default.fBackground);
00135   g_context_default.fFillStyle = kFillSolid;
00136   g_context_default.fFont = ufont->GetFontHandle();
00137   g_context_default.fGraphicsExposures = kFALSE;
00138   uGC = gClient->GetGC(&g_context_default, kTRUE);
00139 
00141   // "Receivers control" group frame
00142   fGrpFrmRcvCntrl = new TGGroupFrame(fCompFrame,"Receivers control frame");
00143   fGrpFrmRcvCntrl->SetLayoutBroken(kTRUE);
00144   fGrpFrmRcvCntrl->SetTitlePos(TGGroupFrame::kCenter);
00145  
00146   fPictBut = new TGPictureButton(fGrpFrmRcvCntrl,fPictureList[0]);
00147   fGrpFrmRcvCntrl->AddFrame(fPictBut, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00148   Gui::MoveResizeSafe(14.6, 22,117,117,fPictBut);
00149   
00150   fQuitBut = new TGTextButton(fGrpFrmRcvCntrl,"QUIT");
00151 
00152   SetFontType(fFontType);
00153   SetFontSize(18.);
00154 //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 18.);
00155 //   fFontString+=fFontISO;
00156   fQuitBut->SetFont(fFontString.Data(),kTRUE);
00157 
00158   fGrpFrmRcvCntrl->AddFrame(fQuitBut, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00159   Gui::MoveResizeSafe(14.6,146, 117,36.5,fQuitBut);
00160 
00161   // --- Single detector SCC run control
00162   //  enum SlowDetectors_e {TOFI = 0, TOFO, LMD, STB, GAS, SIL, MAG};
00163   Float_t RunButStart = 150;
00164   Float_t RunButGap = 19;
00165   TString StrSet = "";  
00166   
00167   for(Int_t i=0;i<K_N_SLOWS+1;i++){
00168     StrSet="START "; 
00169     if(i==K_N_SLOWS) StrSet+= "Low voltage";
00170     else StrSet+=fSlowDetNames[i];
00171     fButSCCRunReceiver[i] = new TGTextButton(fGrpFrmRcvCntrl,StrSet.Data());
00172     fGrpFrmRcvCntrl->AddFrame(fButSCCRunReceiver[i], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00173     Gui::MoveResizeSafe(14.6,(RunButStart + RunButGap*(i+2)), 117,18,fButSCCRunReceiver[i]); 
00174   }
00175 
00176   SetFontType(fFontType);
00177   SetFontSize(10.);  
00178   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 10.);
00179   //   fFontString+=fFontISO;
00180 
00181   // --- START/STOP ALL receivers buttons
00182   fButStartAllRcv = new TGTextButton(fGrpFrmRcvCntrl,"START ALL");
00183   fGrpFrmRcvCntrl->AddFrame(fButStartAllRcv, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00184   fButStartAllRcv->SetFont(fFontString.Data(),kTRUE);
00185   fButStartAllRcv->SetTextJustify(kTextCenterX);
00186   Gui::MoveResizeSafe(14.6,360, 117,20,fButStartAllRcv);
00187   
00188   fButStopAllRcv = new TGTextButton(fGrpFrmRcvCntrl,"STOP ALL");
00189   fGrpFrmRcvCntrl->AddFrame(fButStopAllRcv, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00190   fButStopAllRcv->SetFont(fFontString.Data(),kTRUE);
00191   fButStopAllRcv->SetTextJustify(kTextCenterX);
00192   Gui::MoveResizeSafe(14.6,385, 117,20,fButStopAllRcv);
00193   
00194   // --- Global PrintInfo  button
00195   fButPrintAllInfo = new TGTextButton(fGrpFrmRcvCntrl,"PRINT ALL INFO");
00196   fGrpFrmRcvCntrl->AddFrame(fButPrintAllInfo, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00197 
00198   fButPrintAllInfo->SetFont(fFontString.Data(),kTRUE);
00199   fButPrintAllInfo->SetTextJustify(kTextCenterX);
00200   Gui::MoveResizeSafe(14.6,420, 117,50,fButPrintAllInfo);
00201 
00203   // "SCC 2 DAQ frame" group frame
00204   fGrpFrmSCC2DAQ = new TGGroupFrame(fCompFrame,"SCC 2 DAQ frame");
00205   fGrpFrmSCC2DAQ->SetLayoutBroken(kTRUE);
00206   fGrpFrmSCC2DAQ->SetTitlePos(TGGroupFrame::kCenter);
00207 
00208   // ---
00209 
00210   // ---
00211   fLblSCCLastEvts = new TGLabel(fGrpFrmSCC2DAQ,"Last 5 events stored");
00212   fGrpFrmSCC2DAQ->AddFrame(fLblSCCLastEvts, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00213   SetFontType(fFontType);
00214   SetFontSize(10.);  
00215   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 10.);
00216   //   fFontString+=fFontISO;
00217   fLblSCCLastEvts->SetTextFont(fFontString.Data(),kTRUE);
00218   fLblSCCLastEvts->SetTextJustify(kTextCenterX);
00219   Gui::MoveResizeSafe(7.3,20, 131.6,14.6,fLblSCCLastEvts);
00220   // ---
00221   fLblSCCDateLastEvts = new TGLabel(fGrpFrmSCC2DAQ,"date");
00222   fGrpFrmSCC2DAQ->AddFrame(fLblSCCDateLastEvts, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00223   fLblSCCDateLastEvts->SetTextFont(fFontString.Data(),kTRUE);
00224   Gui::MoveResizeSafe(7.3,35, 44, 14.6,fLblSCCDateLastEvts);
00225   // ---
00226   fLblSCCTimeLastEvts = new TGLabel(fGrpFrmSCC2DAQ,"time");
00227   fGrpFrmSCC2DAQ->AddFrame(fLblSCCTimeLastEvts, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00228   fLblSCCTimeLastEvts->SetTextFont(fFontString.Data(),kTRUE);
00229   Gui::MoveResizeSafe(51,35, 44,14.6,fLblSCCTimeLastEvts);
00230   // ---
00231   fLblSCCBytesLastEvts = new TGLabel(fGrpFrmSCC2DAQ,"bytes");
00232   fGrpFrmSCC2DAQ->AddFrame(fLblSCCBytesLastEvts, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00233   fLblSCCBytesLastEvts->SetTextFont(fFontString.Data(),kTRUE);
00234   Gui::MoveResizeSafe(95,35, 44,14.6,fLblSCCBytesLastEvts);
00235   // ---
00236 
00237   Float_t Start_x[3] = {7.3, 51, 95};
00238   Float_t Start_y = 50.;
00239   Float_t Gap_y = 14.6;
00240   Float_t LastEvsTxtSize[2] = {44, 14.6};
00241 
00242   for(Int_t ilast=0;ilast<5;ilast++){
00243     fTxtSCC_LastDate[ilast] = new TGTextEntry(fGrpFrmSCC2DAQ, new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00244     fTxtSCC_LastDate[ilast]->SetMaxLength(255);
00245     fTxtSCC_LastDate[ilast]->SetAlignment(kTextLeft);
00246     fTxtSCC_LastDate[ilast]->SetText("--/--/--");
00247     fGrpFrmSCC2DAQ->AddFrame(fTxtSCC_LastDate[ilast], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00248     Gui::MoveResizeSafe(  Start_x[0], (Start_y + ilast * Gap_y),
00249                           LastEvsTxtSize[0],LastEvsTxtSize[1],
00250                           fTxtSCC_LastDate[ilast]);
00251     
00252     fTxtSCC_LastTime[ilast] = new TGTextEntry(fGrpFrmSCC2DAQ, new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00253     fTxtSCC_LastTime[ilast]->SetMaxLength(255);
00254     fTxtSCC_LastTime[ilast]->SetAlignment(kTextLeft);
00255     fTxtSCC_LastTime[ilast]->SetText("--:--:--");
00256     fGrpFrmSCC2DAQ->AddFrame(fTxtSCC_LastTime[ilast], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00257     Gui::MoveResizeSafe( Start_x[1],(Start_y + ilast * Gap_y),
00258                          LastEvsTxtSize[0],LastEvsTxtSize[1],
00259                          fTxtSCC_LastTime[ilast]);
00260     
00261     fTxtSCC_LastBytes[ilast] = new TGTextEntry(fGrpFrmSCC2DAQ, new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00262     fTxtSCC_LastBytes[ilast]->SetMaxLength(255);
00263     fTxtSCC_LastBytes[ilast]->SetAlignment(kTextLeft);
00264     fTxtSCC_LastBytes[ilast]->SetText(" --- ");
00265     fGrpFrmSCC2DAQ->AddFrame(fTxtSCC_LastBytes[ilast], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00266     Gui::MoveResizeSafe( Start_x[2],(Start_y + ilast * Gap_y),
00267                          LastEvsTxtSize[0],LastEvsTxtSize[1],
00268                          fTxtSCC_LastBytes[ilast]);
00269   }
00270   
00271   // ---
00272   
00273   // status bar
00274   fStatusSCC2DAQ = new TGStatusBar(fGrpFrmSCC2DAQ,10,10);
00275   fGrpFrmSCC2DAQ->AddFrame(fStatusSCC2DAQ, new TGLayoutHints(kLHintsBottom | kLHintsExpandX));
00276   Gui::MoveResizeSafe(Start_x[0],130, 131.6,14.6,fStatusSCC2DAQ);
00277   
00278   // --- 
00279   fGrpFrmRcvCntrl->SetLayoutManager( new TGVerticalLayout(fGrpFrmRcvCntrl));
00280   fGrpFrmSCC2DAQ->SetLayoutManager( new TGVerticalLayout(fGrpFrmSCC2DAQ));
00281 
00282   fCompFrame->AddFrame(fGrpFrmRcvCntrl, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00283   fCompFrame->AddFrame(fGrpFrmSCC2DAQ, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00284 
00285   Gui::MoveResizeSafe(750,31, 146,490,fGrpFrmRcvCntrl);
00286   
00287   
00288   Gui::MoveResizeSafe(750,518, 146,160,fGrpFrmSCC2DAQ);
00289   
00290   //---------------
00291   fMainFrame->AddFrame(fCompFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY));
00292 
00293 
00294 }
00295 
00296 //_______________________
00297 void TFndSCCgui::BuildSingleSlwFrame(Int_t slow_id){
00298 
00299 
00300   SetFontType(fFontType);
00301   SetFontSize(14.);  
00302   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 14.);
00303   //   fFontString+=fFontISO;
00304   TGFont *u_subtitle_font = gClient->GetFont(fFontString.Data());
00305   TGGC   *u_subtitle_GC;
00306   GCValues_t g_context_subtitle;
00307   g_context_subtitle.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
00308   gClient->GetColorByName("#000000",g_context_subtitle.fForeground);
00309   gClient->GetColorByName("#c6c2c6",g_context_subtitle.fBackground);
00310   g_context_subtitle.fFillStyle = kFillSolid;
00311   g_context_subtitle.fFont = u_subtitle_font->GetFontHandle();
00312   g_context_subtitle.fGraphicsExposures = kFALSE;
00313   u_subtitle_GC = gClient->GetGC(&g_context_subtitle, kTRUE);
00314 
00315   fGrpFrm[slow_id] = new TGGroupFrame(fCompFrame,fSlowDetNames[slow_id],kVerticalFrame,u_subtitle_GC->GetGC(),u_subtitle_font->GetFontStruct());
00316   fGrpFrm[slow_id]->SetTitlePos(TGGroupFrame::kCenter);
00317   fGrpFrm[slow_id]->SetLayoutBroken(kTRUE);
00318   fGrpFrm[slow_id]->SetBackgroundColor(TColor::RGB2Pixel(0xbb,0xbb,0xbb));
00319 
00320   // graphics context changes
00321   // TGFont will reflect user font changes
00322   // TGGC will reflect user GC changes
00323   SetFontType(fFontType);
00324   SetFontSize(10.);  
00325   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 10);
00326   //   fFontString+=fFontISO;
00327   TGFont *ufont = gClient->GetFont(fFontString.Data());
00328   TGGC   *uGC;           
00329   GCValues_t g_context_default;
00330   g_context_default.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
00331   gClient->GetColorByName("#000000",g_context_default.fForeground);
00332   gClient->GetColorByName("#c6c2c6",g_context_default.fBackground);
00333   g_context_default.fFillStyle = kFillSolid;
00334   g_context_default.fFont = ufont->GetFontHandle();
00335   g_context_default.fGraphicsExposures = kFALSE;
00336   uGC = gClient->GetGC(&g_context_default, kTRUE);
00337 
00338 
00339   fTxtDateMsg[slow_id] = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00340   fTxtDateMsg[slow_id]->SetMaxLength(255);
00341   fTxtDateMsg[slow_id]->SetAlignment(kTextLeft);
00342   //  fTxtDateMsg[slow_id]->SetText("11/11/11");
00343   fTxtDateMsg[slow_id]->SetText("--/--/--");
00344   fGrpFrm[slow_id]->AddFrame(fTxtDateMsg[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00345   Gui::MoveResizeSafe(110,15.5, 65.,16,fTxtDateMsg[slow_id]);
00346   
00347   fTxtTimeMsg[slow_id] = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00348   fTxtTimeMsg[slow_id]->SetMaxLength(255);
00349   fTxtTimeMsg[slow_id]->SetAlignment(kTextLeft);
00350   //  fTxtTimeMsg[slow_id]->SetText("11:11:11");
00351   fTxtTimeMsg[slow_id]->SetText("--:--:--");
00352   fGrpFrm[slow_id]->AddFrame(fTxtTimeMsg[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00353   Gui::MoveResizeSafe(175,15.5, 65.,16,fTxtTimeMsg[slow_id]);
00354   
00355   fTxtMsg[slow_id] = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00356   fTxtMsg[slow_id]->SetMaxLength(255);
00357   fTxtMsg[slow_id]->SetAlignment(kTextLeft);
00358   if(slow_id == SIL) fTxtMsg[slow_id]->SetText("Waiting for first complete buffer...");
00359   else fTxtMsg[slow_id]->SetText("No data received yet.");
00360   fGrpFrm[slow_id]->AddFrame(fTxtMsg[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00361   Gui::MoveResizeSafe(240,15.5, 500,16,fTxtMsg[slow_id]);
00362   
00364   fTxtSockMsg[slow_id] = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00365   fTxtSockMsg[slow_id]->SetMaxLength(255);
00366   fTxtSockMsg[slow_id]->SetAlignment(kTextCenterX);
00367   fTxtSockMsg[slow_id]->SetText("just created");
00368   ModifyTextEntry(fTxtSockMsg[slow_id],"Stopped",TColor::RGB2Pixel(0x99,0x99,0x99));
00369   fGrpFrm[slow_id]->AddFrame(fTxtSockMsg[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00370   Gui::MoveResizeSafe(3.,15.5, 102,16,fTxtSockMsg[slow_id]);
00371   
00372   fStatusReceiveRun[slow_id] = new TGStatusBar(fGrpFrm[slow_id],10,10);
00373   fGrpFrm[slow_id]->AddFrame(fStatusReceiveRun[slow_id], new TGLayoutHints(kLHintsBottom | kLHintsExpandX));
00374   Gui::MoveResizeSafe(3.,35, 102,16,fStatusReceiveRun[slow_id]);
00375   // ---
00376   fButPrintInfo[slow_id] = new TGTextButton(fGrpFrm[slow_id],"PRINT INFO");
00377   fGrpFrm[slow_id]->AddFrame(fButPrintInfo[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00378   SetFontType(fFontType);
00379   SetFontSize(10.);  
00380   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 10.);
00381   //   fFontString+=fFontISO;
00382   fButPrintInfo[slow_id]->SetFont(fFontString.Data(),kTRUE);
00383   fButPrintInfo[slow_id]->SetTextJustify(kTextCenterX);
00384   Gui::MoveResizeSafe(3.,52, 102,20,fButPrintInfo[slow_id]);
00385   
00386   
00387   // status bar
00388   fStatusReceiveMsg[slow_id] = new TGStatusBar(fGrpFrm[slow_id],10,10);
00389   fGrpFrm[slow_id]->AddFrame(fStatusReceiveMsg[slow_id], new TGLayoutHints(kLHintsBottom | kLHintsExpandX));
00390   Gui::MoveResizeSafe(110,57, 630,16,fStatusReceiveMsg[slow_id]);
00391   // ---
00392   fLblEvtSize[slow_id] = new TGLabel(fGrpFrm[slow_id],"evt size (B):  ");
00393   SetFontType(fFontType);
00394   SetFontSize(8);  
00395   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 6.);
00396   //   fFontString+=fFontISO;
00397   fLblEvtSize[slow_id]->SetTextJustify(kTextCenterX);
00398   fLblEvtSize[slow_id]->SetTextFont(fFontString.Data(),kTRUE);
00399   fGrpFrm[slow_id]->AddFrame(fLblEvtSize[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00400   Gui::MoveResizeSafe(110,35, 80,16,fLblEvtSize[slow_id]);
00401   
00402   fTxtEvtSize[slow_id] = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00403   fTxtEvtSize[slow_id]->SetMaxLength(255);
00404   fTxtEvtSize[slow_id]->SetAlignment(kTextLeft);
00405   fTxtEvtSize[slow_id]->SetText("evt size");
00406   fGrpFrm[slow_id]->AddFrame(fTxtEvtSize[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00407   Gui::MoveResizeSafe(190,35, 50,16,fTxtEvtSize[slow_id]);
00408   
00409   fGrpFrm[slow_id]->SetLayoutManager( new TGVerticalLayout(fGrpFrm[slow_id]));
00410   fCompFrame->AddFrame(fGrpFrm[slow_id], new TGLayoutHints(kLHintsLeft | kLHintsCenterX | kLHintsTop,5,5,5,5));
00411   Gui::MoveResizeSafe(2.2, (29+(83*slow_id)),
00412                       745, 83,
00413                       fGrpFrm[slow_id]);
00414   
00415 }
00416 
00417 //_______________________
00418 void TFndSCCgui::AdjustSingleSlwFrame(Int_t slow_id){
00419   // used for GAS/LMD/(STB?)
00420   //  enum SlowDetectors_e {TOFI = 0, TOFO, LMD, STB, GAS, SIL, MAG};  // SlowDetectors_e = -1 is used for the "Global Header"
00421 
00422   SetFontType(fFontType);
00423   SetFontSize(10.);  
00424   //   fFontString+=(Int_t)(Gui::GetTGadj(1) * 10.);
00425   //   fFontString+=fFontISO;
00426   TGFont *ufont = gClient->GetFont(fFontString.Data());
00427   TGGC   *uGC;           
00428   GCValues_t g_context_default;
00429   g_context_default.fMask = kGCForeground | kGCBackground | kGCFillStyle | kGCFont | kGCGraphicsExposures;
00430   gClient->GetColorByName("#000000",g_context_default.fForeground);
00431   gClient->GetColorByName("#c6c2c6",g_context_default.fBackground);
00432   g_context_default.fFillStyle = kFillSolid;
00433   g_context_default.fFont = ufont->GetFontHandle();
00434   g_context_default.fGraphicsExposures = kFALSE;
00435   uGC = gClient->GetGC(&g_context_default, kTRUE);
00436   
00438   TString ind_lbl = "";
00439   Float_t Lbl1Start = 0;
00440   Float_t LblW     = 0;
00441   Float_t IndW     = 0;
00442   Float_t hgap      = 0;
00443   
00444   Float_t cur_pos = 0;
00446 
00447   switch(slow_id){
00448   case LMD: // add mixture indicator    
00449     fLmdMixLbl = new TGLabel(fGrpFrm[slow_id],"C(4) H(10) %:");
00450     fGrpFrm[slow_id]->AddFrame(fLmdMixLbl, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00451     SetFontType(fFontType);
00452     SetFontSize(10.);  
00453     //     fFontString+=(Int_t)(Gui::GetTGadj(1) * 10.);
00454     //     fFontString+=fFontISO;
00455     fLmdMixLbl->SetTextFont(fFontString.Data(),kTRUE);
00456     Gui::MoveResizeSafe(278,35, 73,14.6,fLmdMixLbl);    
00457     
00458     fLmdMixture = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00459     fLmdMixture->SetMaxLength(255);
00460     fLmdMixture->SetAlignment(kTextLeft);
00461     fLmdMixture->SetText("LMD mix");
00462     fGrpFrm[slow_id]->AddFrame(fLmdMixture, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00463     Gui::MoveResizeSafe(351,35, 73,14.6,fLmdMixture);
00464     break;
00465   case STB: // add mixture indicator
00466     fStbMixLbl = new TGLabel(fGrpFrm[slow_id],"Argon %:");
00467     fGrpFrm[slow_id]->AddFrame(fStbMixLbl, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00468     SetFontType(fFontType);
00469     SetFontSize(10.);  
00470     //     fFontString+=(Int_t)(Gui::GetTGadj(1) * 10.);
00471     //     fFontString+=fFontISO;
00472     fStbMixLbl->SetTextFont(fFontString.Data(),kTRUE);
00473     Gui::MoveResizeSafe(278,35, 73,14.6,fStbMixLbl);
00474     
00475     fStbMixture = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00476     fStbMixture->SetMaxLength(255);
00477     fStbMixture->SetAlignment(kTextLeft);
00478     fStbMixture->SetText("STB mix");
00479     fGrpFrm[slow_id]->AddFrame(fStbMixture, new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00480     Gui::MoveResizeSafe(351,35, 73,14.6,fStbMixture);
00481     break;
00482   case GAS: // add security switch indicators
00483     SetFontType(fFontType);
00484     SetFontSize(10.);  
00485     //     fFontString+=(Int_t)(Gui::GetTGadj(1) * 10.);
00486     //     fFontString+=fFontISO;
00487     
00488     Lbl1Start = 280;
00489     LblW = 40;
00490     IndW = 35;
00491     hgap = 7;
00492 
00493     cur_pos = Lbl1Start;
00494     for(Int_t i=0;i<K_N_SECUR_SWITCHES;i++){
00495       ind_lbl = "c_";ind_lbl += i;
00496       fGasSecurLbl[i] = new TGLabel(fGrpFrm[slow_id],ind_lbl.Data());
00497       fGrpFrm[slow_id]->AddFrame(fGasSecurLbl[i], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00498       fGasSecurLbl[i]->SetTextFont(fFontString.Data(),kTRUE);
00499       Gui::MoveResizeSafe((cur_pos+hgap),35, LblW,14.6,fGasSecurLbl[i]);
00500       cur_pos = cur_pos + hgap + LblW;
00501       
00502       fGasSecurInd[i] = new TGTextEntry(fGrpFrm[slow_id], new TGTextBuffer(15),-1,uGC->GetGC(),ufont->GetFontStruct(),kSunkenFrame | kDoubleBorder | kOwnBackground);
00503       fGasSecurInd[i]->SetMaxLength(255);
00504       fGasSecurInd[i]->SetAlignment(kTextLeft);
00505       fGasSecurInd[i]->SetText("...");
00506       fGrpFrm[slow_id]->AddFrame(fGasSecurInd[i], new TGLayoutHints(kLHintsLeft | kLHintsTop,5,5,5,5));
00507       Gui::MoveResizeSafe( cur_pos,35, IndW,14.6,fGasSecurInd[i]);
00508       cur_pos = cur_pos + hgap + IndW;
00509     }
00510     break;
00511   default: return;
00512   }
00513 
00514 }
00515 
00516 //_______________________
00517 void TFndSCCgui::MapGUI(){
00518 
00519   fMainFrame->MapSubwindows();
00520 
00521   Gui::MoveResizeSafe( 2,10,900,675,fMainFrame);
00522 
00523   fMainFrame->MapWindow();
00524   fMainFrame->DontCallClose();
00525 
00526   // Wait until is really mapped
00527   while(!fMainFrame->IsMapped() || !fMainFrame->IsMapSubwindows()){
00528     if(K_DEBUG_LEV > 2) Printf("TFndSCCgui::MapGUI ===> still not mapped");
00529     usleep(5000);
00530   }
00531 
00532   fTimer = new TTimer();
00533   fTimer->Connect("Timeout()","TFndSCCgui",this,"ChangePicture()");
00534   fTimer->Start( 2000, kFALSE);   // kTRUE:single-shot ; kFALSE:repetitive          
00535   fTimer->TurnOn();
00536   //fTimer->TurnOff();
00537 
00538   //  fMainFrame->RequestFocus();
00539   gClient->ProcessEventsFor(fMainFrame); // don't use this method within button methods
00540 
00541   if(K_DEBUG_LEV > 0) Printf("GUI succesfully mapped.");
00542 }
00543 
00544 //_______________________
00545 void TFndSCCgui::MakeConnections(Bool_t ConnectDisconnect){
00546   
00547   if(ConnectDisconnect){
00548     //    fPictBut->Connect("Clicked()","TFndSCCgui",this,"MethodTest()");
00549     //
00550     enum SlowDetectors_e {TOFI = 0, TOFO, LMD, STB, GAS, SIL, MAG};  // SlowDetectors_e = -1 is used for the "Global Header"
00551     
00552     fButSCCRunReceiver[TOFI]->Connect("Clicked()","TFndSCCgui",this,"StartStopTofi()");
00553     fButSCCRunReceiver[TOFO]->Connect("Clicked()","TFndSCCgui",this,"StartStopTofo()");
00554     fButSCCRunReceiver[LMD]->Connect("Clicked()","TFndSCCgui",this,"StartStopLMD()");
00555     fButSCCRunReceiver[STB]->Connect("Clicked()","TFndSCCgui",this,"StartStopSTB()");
00556     fButSCCRunReceiver[GAS]->Connect("Clicked()","TFndSCCgui",this,"StartStopGAS()");
00557     fButSCCRunReceiver[SIL]->Connect("Clicked()","TFndSCCgui",this,"StartStopSIL()");
00558     fButSCCRunReceiver[MAG]->Connect("Clicked()","TFndSCCgui",this,"StartStopMAG()");
00559     fButSCCRunReceiver[K_N_SLOWS]->Connect("Clicked()","TFndSCCgui",this,"StartStopLowVolt()"); // Low voltage after all detectors
00560     //
00561     
00562     fButStartAllRcv->Connect("Clicked()","TFndSCCgui",this,"StartAllReceivers()");
00563     fButStopAllRcv ->Connect("Clicked()","TFndSCCgui",this,"StopAllReceivers()");
00564     // ---  
00565     fButPrintInfo[TOFI]->Connect("Clicked()","TFndSCCgui",this,"PrintInfoTofi()");
00566     fButPrintInfo[TOFO]->Connect("Clicked()","TFndSCCgui",this,"PrintInfoTofo()");
00567     fButPrintInfo[LMD]->Connect("Clicked()","TFndSCCgui",this,"PrintInfoLMD()");
00568     fButPrintInfo[STB]->Connect("Clicked()","TFndSCCgui",this,"PrintInfoSTB()");
00569     fButPrintInfo[GAS]->Connect("Clicked()","TFndSCCgui",this,"PrintInfoGAS()");
00570     fButPrintInfo[SIL]->Connect("Clicked()","TFndSCCgui",this,"PrintInfoSIL()");
00571     fButPrintInfo[MAG]->Connect("Clicked()","TFndSCCgui",this,"PrintInfoMAG()");    
00572     //
00573     fButPrintAllInfo->Connect("Clicked()","TFndSCCgui",this,"PrintAllInfoFromGUI()");
00574 
00575     //
00576     fQuitBut->Connect("Clicked()","TFndSCCgui",this,"CloseWindow()");
00577   }
00578   else{
00579     //    fPictBut->Disconnect("Clicked()","TFndSCCgui",this,"MethodTest()");
00580     //
00581     fButSCCRunReceiver[0]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopTofi()");
00582     fButSCCRunReceiver[1]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopTofo()");
00583     fButSCCRunReceiver[2]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopLMD()");
00584     fButSCCRunReceiver[3]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopSTB()");
00585     fButSCCRunReceiver[4]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopGAS()");
00586     fButSCCRunReceiver[5]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopSIL()");
00587     fButSCCRunReceiver[6]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopMAG()");
00588     fButSCCRunReceiver[7]->Disconnect("Clicked()","TFndSCCgui",this,"StartStopLowVolt()");
00589     //
00590     fButStartAllRcv->Disconnect("Clicked()","TFndSCCgui",this,"StartAllReceivers()");
00591     fButStopAllRcv ->Disconnect("Clicked()","TFndSCCgui",this,"StopAllReceivers()");
00592     // ---  
00593     fButPrintInfo[0]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoTofi()");
00594     fButPrintInfo[1]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoTofo()");
00595     fButPrintInfo[2]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoLMD()");
00596     fButPrintInfo[3]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoSTB()");
00597     fButPrintInfo[4]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoGAS()");
00598     fButPrintInfo[5]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoSIL()");
00599     fButPrintInfo[6]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoMAG()");
00600     fButPrintInfo[7]->Disconnect("Clicked()","TFndSCCgui",this,"PrintInfoLowVolt()");
00601     //  
00602     fButPrintAllInfo->Disconnect("Clicked()","TFndSCCgui",this,"PrintAllInfoFromGUI()");
00603     //    
00604     fQuitBut->Disconnect("Clicked()","TFndSCCgui",this,"CloseWindow()");    
00605   }
00606 
00607   SayToUser("Slow Control Center ready",1);
00608 
00609 }
00610 
00611 
00612 //_______________________
00613 void TFndSCCgui::EnableConnections(Bool_t enabled){
00614   
00615   fPictBut->SetEnabled(enabled);
00616   //  gClient->ProcessEventsFor(fPictBut);
00617   
00618   fQuitBut->SetEnabled(enabled);
00619   //  gClient->ProcessEventsFor(fQuitBut);
00620   
00621   for(Int_t i=0;i<K_N_SLOWS+1;i++){
00622     fButSCCRunReceiver[i]->SetEnabled(enabled);
00623     //    gClient->ProcessEventsFor(fButSCCRunReceiver[i]);
00624   }
00625 
00626 }
00627 
00628 //_______________________
00629 void TFndSCCgui::StartStopSlowReceiver(Int_t slow_det){
00630   // Check if the selected thread is running,
00631   // then set the text of the button and
00632   // perform the required operation
00633   
00634   Int_t is_running = IsReceiveThreadRunning(slow_det);
00635   TString StrSet = "";
00636   
00637   switch (is_running){
00638   case -1:   
00639     ResetMessages(slow_det,"start command received",SCC_MSG_RESET_ALL);
00640     StartReceiveThread(slow_det);
00641     ModifyTextEntry(fTxtSockMsg[slow_det],"Started",TColor::RGB2Pixel(0x99,0x99,0x99));
00642     StrSet="STOP "; StrSet+=fSlowDetNames[slow_det];
00643     fButSCCRunReceiver[slow_det]->SetText(StrSet.Data());
00644     fStatusReceiveRun[slow_det]->SetText("...running...");
00645     gClient->NeedRedraw(fButSCCRunReceiver[slow_det]);  // last change
00646     gClient->NeedRedraw(fStatusReceiveRun[slow_det]);  // last change
00647     //     gClient->ProcessEventsFor(fButSCCRunReceiver[slow_det]);
00648     //     gClient->ProcessEventsFor(fStatusReceiveRun[slow_det]);
00649     return;
00650   case TThread::kRunningState:
00651     ResetMessages(slow_det,"stop command received",SCC_MSG_RESET_NORM);
00652     StopReceiveThread(slow_det);
00653     ModifyTextEntry(fTxtSockMsg[slow_det],"Stopped",TColor::RGB2Pixel(0x99,0x99,0x99));
00654     StrSet="START "; StrSet+=fSlowDetNames[slow_det];
00655     fButSCCRunReceiver[slow_det]->SetText(StrSet.Data());
00656     fStatusReceiveRun[slow_det]->SetText("...stopped...");
00657     gClient->NeedRedraw(fButSCCRunReceiver[slow_det]);  // last change
00658     gClient->NeedRedraw(fStatusReceiveRun[slow_det]);  // last change
00659     //     gClient->ProcessEventsFor(fButSCCRunReceiver[slow_det]);
00660     //     gClient->ProcessEventsFor(fStatusReceiveRun[slow_det]);
00661     return;
00662   default:    
00663     StartReceiveThread(slow_det);
00664     ModifyTextEntry(fTxtSockMsg[slow_det],"IDLE",TColor::RGB2Pixel(0x99,0x99,0x99));
00665     StrSet="STOP "; StrSet+=fSlowDetNames[slow_det];
00666     fButSCCRunReceiver[slow_det]->SetText(StrSet.Data());
00667     fStatusReceiveRun[slow_det]->SetText("...running...");
00668     gClient->NeedRedraw(fButSCCRunReceiver[slow_det]);  // last change
00669     gClient->NeedRedraw(fStatusReceiveRun[slow_det]);  // last change
00670 //     gClient->ProcessEventsFor(fButSCCRunReceiver[slow_det]);
00671 //     gClient->ProcessEventsFor(fStatusReceiveRun[slow_det]);
00672     return;
00673   } 
00674 }
00675 
00676 //_______________________
00677 void TFndSCCgui::SetFontType(TString ftype){
00678 
00679   TString fontstring = ftype;
00680   fontstring+=(Int_t)(Gui::GetTGadj(1) * (Double_t)(fFontSize));
00681   fontstring+=fFontISO;
00682   
00683   if(!gClient->GetFontPool()->GetFont(fontstring.Data(),0)){
00684     Warning("SetFontType","selected font is not available: \"%s\"",ftype.Data());
00685     return;
00686   }
00687   fFontType = ftype;
00688   fFontString = fontstring;
00689 }
00690 
00691 //_______________________
00692 void TFndSCCgui::SetFontSize(Float_t fsize){
00693   // round to the smaller one if not accepted
00694 
00695   Int_t check_size = (Int_t) (Gui::GetTGadj(1) * fsize );
00696   
00697   TString fontstring;
00698   
00699   Int_t accepted = kFALSE;
00700   while(!accepted){
00701     if(check_size <=0){
00702       Error("SetFontSize","Problems while setting font size: using \"8\".");
00703       fFontSize = 8;
00704       fFontString = fFontType;
00705       fFontString+=fFontSize;
00706       fFontString+=fFontISO;
00707       return;
00708     }
00709     fontstring = fFontType;
00710     fontstring+=check_size;
00711     fontstring+=fFontISO;
00712     
00713     accepted = (Int_t)gClient->GetFontPool()->GetFont(fontstring.Data(),0);
00714     if(K_DEBUG_LEV > 0) Printf("accepted = \"%x\"",accepted);
00715     if(!accepted){
00716       Warning("SetFontType","selected font size (\"%d\") not available: trying \"%d\"",check_size,check_size-1);
00717       check_size--;
00718     }
00719   }
00720   
00721   fFontSize = check_size; 
00722   fFontString = fontstring;
00723 }
00724 
00725 //_______________________
00726 void TFndSCCgui::ChangePicture(){
00727 
00728   if(!fPictBut){
00729     Warning("ChangePicture","Can not change picture: Picture-Button not built yet...");
00730   }
00731   if(K_DEBUG_LEV > 0) Info("ChangePicture","Changing picture %d",fCurPicture);
00732 
00733   if(fCurPicture < (SCC_PICTURES - 1)) fCurPicture++;
00734   else fCurPicture = 0;
00735   fPictBut->SetPicture(fPictureList[fCurPicture]);
00736   gClient->NeedRedraw(fPictBut);
00737 
00738 }
00739 
00740 //______________________
00741 void TFndSCCgui::RedrawTextEntry(TGTextEntry *txt_entry){
00742   
00743   txt_entry->Deselect();
00744   gClient->NeedRedraw(txt_entry);
00745 }
00746 
00747 
00748 //______________________
00749 void TFndSCCgui::ModifyTextEntry(TGTextEntry *txt_entry,const Char_t *text,Pixel_t bck_col,Pixel_t frg_col){
00750 
00751   txt_entry->Clear();
00752   //  txt_entry->SetCursorPosition(txt_entry->GetCursorPosition());
00753   txt_entry->SetText(text);
00754   txt_entry->SetBackgroundColor(bck_col);
00755   txt_entry->SetForegroundColor(frg_col);
00756 
00757   RedrawTextEntry(txt_entry);
00758   
00759   //   txt_entry->Deselect();
00760   //   gClient->NeedRedraw(txt_entry);
00761   //  gClient->ProcessEventsFor(txt_entry); 
00762 }
00763 
00764 //_________________________
00765 void TFndSCCgui::SetCanReceiveFlag(Int_t can_receive){
00766   // possible values are:
00767   //             TFndSCCgui::k_CanReceive
00768   //             TFndSCCgui::k_WaitReceive
00769   //             TFndSCCgui::k_DontReceive
00770 
00771   if(can_receive != k_CanReceive && can_receive != k_WaitReceive && can_receive != k_DontReceive){
00772     Printf("TFndSCCMan::SetCanReceiveFlag BUG: %d value not accepted!",can_receive);
00773     return;
00774   }
00775   fCanReceive = can_receive;
00776 }
00777 
00778 //______________________
00779 void TFndSCCgui::ReceivedEvent(Int_t slow_det,Int_t part){  
00780   // Event reception can be controlled by setting the "fCanReceive" data-member
00781   // (seet the "SetCanReceiveFlag(Int_t can_emit)" method)
00782 
00783   Int_t sock_idx = SlowId2SockId(slow_det, part);
00784   //   if(slow_det == SIL) Printf("=============> TFndSCCgui SIL event received",sock_idx);
00785   
00786   if(fCanReceive == k_DontReceive){
00787     if(K_DEBUG_LEV > 0) Printf("TFndSCCgui::ReceivedEvent ===> Can not receive events");    
00788     return;
00789   }
00790   while(fCanReceive == k_WaitReceive) {
00791     usleep(100000);
00792     if(K_DEBUG_LEV > 0) Printf("TFndSCCgui::ReceivedEvent ===> Waiting for GUI to be idle");
00793   }
00794 
00795   if(K_DEBUG_LEV > 0)  Printf("MySCCTest ReceivedEvent method: slow_det = %d",slow_det);
00796   ModifyTextEntry(fTxtSockMsg[slow_det],"RECEIVING",TColor::RGB2Pixel(0xff,0xff,0x00),TColor::RGB2Pixel(0x00,0x00,0xee));
00797   usleep(250000);
00798   ModifyTextEntry(fTxtSockMsg[slow_det],"WAITING");
00799   // ---
00800   TString DateString = "";
00801   TString TimeString = "";
00802   TDatime curtime;
00803   curtime.Set();
00804   DateString=curtime.AsString();
00805   DateString.Resize(DateString.Sizeof()-14);
00806   //
00807   TimeString=curtime.AsSQLString();
00808   TimeString.Remove(0, 11);  
00809   //
00810 
00811   ModifyTextEntry(fTxtDateMsg[slow_det],DateString.Data());
00812   ModifyTextEntry(fTxtTimeMsg[slow_det],TimeString.Data());
00813   // ---
00814   TString message = GetMessagePart(slow_det);
00815   //
00816   if(message.IsNull() && slow_det != SIL){
00817     ModifyTextEntry(fTxtMsg[slow_det],"NO MESSAGE RECEIVED.");
00818     return;
00819   }
00820   if(slow_det == SIL && !IsDataReady(slow_det) ) message+=" (complete data not available)";
00821   //
00822 
00823   ModifyTextEntry(fTxtMsg[slow_det],message.Data());
00824   TString sizestr = ""; sizestr+= fSingleRawData[slow_det][HdrDet_evlen];
00825   ModifyTextEntry(fTxtEvtSize[slow_det],sizestr.Data());
00826 
00827   // --- Change background color depending on the error message
00828   TString CmpStr[3] = {0};
00829   CmpStr[0] = "ok";
00830   CmpStr[1] = "warning";
00831   CmpStr[2] = "error";
00832 
00833   TString grep_str[4];
00834   grep_str[0] = "New pedestals run required";
00835   grep_str[1] = "warning  Dig IO: Watchdog switched off";
00836   grep_str[2] = "Error AIR%>20%";
00837   grep_str[3] = " (complete data not available)"; // still not used
00838 
00839   Int_t i = 0;
00840   for(i=0;i<3;i++){
00841     if(!strncasecmp(CmpStr[i],message.Data(),CmpStr[i].Sizeof()-1)) break;
00842   }
00843 
00844   Float_t stb_argon = 0; // used by STB
00845   Float_t stb_ethan = 0; // used by STB
00846   Float_t ar_perc = 0;  // used by STB
00847 
00848 
00849   TString err_chk = "";
00850   TRegexp r = TRegexp("\".*\""); //. select errors between \"\" (included)
00851   Bool_t upd_err = kTRUE;
00852 
00853   Bool_t upd_solved = kFALSE;
00854 
00855   switch(i){
00856   case 0: // ok
00857     fLastError[slow_det] = "";
00858     fTxtMsg[slow_det]->SetBackgroundColor(TColor::RGB2Pixel(0xff,0xff,0xff));
00859     fTxtMsg[slow_det]->SetForegroundColor(TColor::RGB2Pixel(0x01,0x01,0x01));
00860     if( fLastErrorSolved[slow_det] == kFALSE){
00861       fLastErrorSolved[slow_det] = kTRUE;
00862       upd_solved = kTRUE;
00863     }
00864     break;
00865   case 1: // warning
00866     fLastError[slow_det] = "";
00867     fTxtMsg[slow_det]->SetBackgroundColor(TColor::RGB2Pixel(0xff,0xff,0x99));
00868     fTxtMsg[slow_det]->SetForegroundColor(TColor::RGB2Pixel(0x00,0x00,0x88));
00869     if( fLastErrorSolved[slow_det] == kFALSE){
00870       fLastErrorSolved[slow_det] = kTRUE;
00871       upd_solved = kTRUE;
00872     }
00873     break;
00874   case 2: // error
00875     fLastErrorSolved[slow_det] = kFALSE;
00876     if(!fLastError[slow_det].IsNull()){
00877       err_chk = fLastError[slow_det](r);
00878       if(!err_chk.IsNull() && err_chk.CompareTo(message.Data()) ){
00879         //Printf(" =============> %s ---> %d %s",fLastError[slow_det].Data(),slow_det,err_chk.Data());
00880         //Printf("            ===> SAME ERROR MESSAGE DETECTED <===");
00881         upd_err = kFALSE;
00882       }
00883     }
00884     
00885     if(upd_err){
00886       fLastError[slow_det] = curtime.AsString();
00887       fLastError[slow_det]+=": \""; fLastError[slow_det]+=message.Data(); fLastError[slow_det]+="\".";
00888       if(slow_det != (Int_t) GAS ) ScheduledOperation();
00889     }
00890     fStatusReceiveMsg[slow_det]->SetText(fLastError[slow_det].Data());
00891     //
00892     fTxtMsg[slow_det]->SetBackgroundColor(TColor::RGB2Pixel(0xff,0x00,0x33));
00893     fTxtMsg[slow_det]->SetForegroundColor(TColor::RGB2Pixel(0x01,0x01,0x01));
00894     
00895 
00896     // --- Support for Vocal messages
00897     if(slow_det != (Int_t) GAS ) SayToUser(fVocalErrorMessage[slow_det],1);
00898     //    SayToUser("Error");
00899     break;
00900   default:Printf("TFndSCCgui::ReceivedEvent ===> Selection: %d not available",i);
00901   }
00902 
00903   if(upd_solved) ScheduledOperation();
00904 
00905   // Custom colors for exceptions 
00906   if( message.Contains(grep_str[0].Data()) ) fTxtMsg[slow_det]->SetBackgroundColor(TColor::RGB2Pixel(0xff,0x77,0x24));   // SIL
00907   if( !message.CompareTo(grep_str[1].Data()) ) fTxtMsg[slow_det]->SetBackgroundColor(TColor::RGB2Pixel(0xe0,0xff,0xff)); // SIL
00908   if( !message.CompareTo(grep_str[2].Data()) ) fTxtMsg[slow_det]->SetBackgroundColor(TColor::RGB2Pixel(0xe0,0xff,0xff)); // GAS
00909 
00910   fTxtMsg[slow_det]->Deselect();
00911   gClient->NeedRedraw(fTxtMsg[slow_det]);
00912   
00913   // --- Adds on
00914   TString Num2Txt_tmp = ""; // string buffer for the current misc info
00915   switch(slow_det){
00916   case LMD: // add mixture indicator    
00917     Num2Txt_tmp = ""; Num2Txt_tmp.Form("%.2f",
00918                                        ( (Float_t)GetMiscInfo(slow_det,0)) / 100
00919                                        );
00920 
00921     fLmdMixture->SetText(Num2Txt_tmp.Data());
00922     gClient->NeedRedraw(fLmdMixture);
00923     break;
00924   case STB: // add mixture indicator
00925     stb_argon = GetMiscInfo(slow_det,3);
00926     stb_ethan = GetMiscInfo(slow_det,2);
00927     ar_perc = 100 *(Float_t)( stb_argon / (stb_argon + stb_ethan) );
00928     //    Num2Txt_tmp = ""; Num2Txt_tmp+= ar_perc;
00929     Num2Txt_tmp = ""; Num2Txt_tmp.Form("%.2f",ar_perc);
00930 
00931     fStbMixture->SetText(Num2Txt_tmp.Data());
00932     gClient->NeedRedraw(fStbMixture);
00933     break;
00934   case GAS: // add security switch indicators
00935     for(Int_t i=0;i<K_N_SECUR_SWITCHES;i++){
00936       Num2Txt_tmp = ""; Num2Txt_tmp+= GetMiscInfo(slow_det,i);
00937       fGasSecurInd[i]->SetText(Num2Txt_tmp.Data());
00938       gClient->NeedRedraw(fGasSecurInd[i]);
00939     }
00940     break;
00941   default: return;
00942   }
00943 
00944 
00945   if(K_DEBUG_LEV > 0) Printf("Selection: %d (%s)",i,CmpStr[i].Data());
00946   Relax(0);
00947 
00948 }
00949 
00950 //______________________
00951 void TFndSCCgui::SocketError(Int_t slow_det){
00952   
00953   if(K_DEBUG_LEV > 1) Printf("MySCCTest SocketError method: slow_det = %d",slow_det);
00954   ModifyTextEntry(fTxtSockMsg[slow_det],"SOCKET ERROR",TColor::RGB2Pixel(0xff,0x33,0x00),TColor::RGB2Pixel(0xff,0xff,0x00));
00955 
00956 }
00957 
00958 //_______________________
00959 void TFndSCCgui::DisableTxtEntry(TGTextEntry *txt_entry){
00960   // Called by DTOR in order to avoid segmentation faults
00961   // (cursor may be active in some text entries)
00962 
00963   txt_entry->Clear();
00964   txt_entry->SetEnabled(kFALSE);
00965   gClient->ProcessEventsFor(txt_entry); 
00966   usleep(25000);
00967 }
00968 
00969 //_______________________
00970 void TFndSCCgui::CloseWindow(){
00971   // Called when window is closed via the window manager.
00972   
00973 
00974   if(fTimer) fTimer->TurnOff();
00975   delete fTimer;
00976   fTimer = 0;
00977 
00978   SetCanReceiveFlag(k_DontReceive);
00979   gClient->ProcessEventsFor(fMainFrame);
00980   gSystem->Sleep(300);
00981   gClient->ProcessEventsFor(fMainFrame);
00982 
00983   // --- (Adds on)
00984   DisableTxtEntry(fLmdMixture);
00985   DisableTxtEntry(fStbMixture);
00986   for(Int_t i=0;i<K_N_SECUR_SWITCHES;i++) DisableTxtEntry(fGasSecurInd[i]);
00987 
00988   for(Int_t i=0;i<K_N_SLOWS;i++){ // important to avoid segmentation faults
00989     DisableTxtEntry(fTxtSockMsg[i]);
00990     //
00991     DisableTxtEntry(fTxtDateMsg[i]);
00992     DisableTxtEntry(fTxtTimeMsg[i]);
00993     DisableTxtEntry(fTxtMsg[i]);
00994     //
00995     DisableTxtEntry(fTxtEvtSize[i]);
00996   }
00997 
00998   gClient->ProcessEventsFor(fMainFrame);
00999   fMainFrame->Cleanup();
01000   fMainFrame->SendCloseMessage();
01001   gClient->ProcessEventsFor(fMainFrame);
01002 
01003   if(K_DEBUG_LEV > 1) Printf("TFndSCCgui::CloseWindow ---> Now stopping all threads");
01004   StopAllThreads();
01005   if(K_DEBUG_LEV > 1) Printf("TFndSCCgui::CloseWindow ---> ...done.");
01006 
01007   if(K_DEBUG_LEV > 1) Printf("Main Window Closed");
01008   Printf("...Good bye");
01009   SayToUser("Bye bye",1);
01010   gApplication->Terminate(0);
01011   return;
01012 }
01013 
01014 //_______________________
01015 void TFndSCCgui::ResetMessages(Int_t slow_det, TString default_msg,Scc_Msg_Reset_e reset_mode){
01016   
01017   TString DateString = "";
01018   TString TimeString = "";
01019   TDatime curtime;
01020   curtime.Set();
01021   DateString=curtime.AsString();
01022   DateString.Resize(DateString.Sizeof()-14);
01023   //
01024   TimeString=curtime.AsSQLString();
01025   TimeString.Remove(0, 11);  
01026   //
01027   
01028   ModifyTextEntry(fTxtSockMsg[slow_det],default_msg);
01029   fStatusReceiveRun[slow_det]->SetText("...idle...");
01030   ModifyTextEntry(fTxtDateMsg[slow_det],DateString.Data());
01031   ModifyTextEntry(fTxtTimeMsg[slow_det],TimeString.Data());
01032   ModifyTextEntry(fTxtMsg[slow_det],default_msg);
01033  
01034   if(reset_mode == SCC_MSG_RESET_ALL) fStatusReceiveMsg[slow_det]->SetText("");
01035 }
01036 
01037 //_______________________
01038 void TFndSCCgui::ResetMessages(TString default_msg,Scc_Msg_Reset_e reset_mode){
01039   
01040   for(Int_t slow_det = (Int_t)TOFI;slow_det <= (Int_t)MAG; slow_det++){
01041     ResetMessages(slow_det,default_msg,reset_mode);
01042   }
01043   
01044 }
01045 
01046 // SEND management
01047 //_______________________
01048 // void TFndSCCgui::PerformingScheduledOperation() { 
01049 //   // Automatically called by receiver threads
01050   
01051 
01052 
01053 //   fStatusSCC2DAQ->SetText("Building data");
01054 //   fStatusSCC2DAQ->SetBackgroundColor(TColor::RGB2Pixel(0xff,0xff,0x99));
01055 //   gClient->NeedRedraw(fStatusSCC2DAQ);
01056 //   //  gClient->ProcessEventsFor(fStatusSCC2DAQ);
01057 
01058 //   gSystem->Sleep(700);
01059   
01060 // }
01061 
01062 //_______________________
01063 void TFndSCCgui::ScheduledOperationPerformed(E_SCC_MAN_GuiComm_t oper,Bool_t UpdateTime){
01064   // Automatically called by receiver threads
01065 
01066   // ---
01067   TString DateString = "";
01068   TString TimeString = "";
01069   TDatime curtime;
01070   curtime.Set();
01071   DateString=curtime.AsString();
01072   DateString.Resize(DateString.Sizeof()-14);
01073   DateString.Remove(0,4);
01074   //
01075   TimeString=curtime.AsSQLString();
01076   TimeString.Remove(0, 11);  
01077   // ---
01078   TString BytesString = "0";
01079   BytesString.Form("%u",fGlobalEvent[HdrTot_EvLen]);
01080  
01081   // --- status bar information 
01082 
01083   switch(oper){
01084   case E_SCC_MAN_GuiComm_Building:
01085     break;
01086     //
01087   case E_SCC_MAN_GuiComm_Stored:
01088     fStatusSCC2DAQ->SetText("");
01089     fStatusSCC2DAQ->SetBackgroundColor(TColor::RGB2Pixel(0xff,0xa0,0x4f));
01090     gClient->NeedRedraw(fStatusSCC2DAQ);
01091     usleep(300000);
01092 
01093     fStatusSCC2DAQ->SetText("Data stored");
01094     fStatusSCC2DAQ->SetBackgroundColor(TColor::RGB2Pixel(0xff,0xa5,0x4f));
01095     gClient->NeedRedraw(fStatusSCC2DAQ);
01096 
01097     //   TThread::Sleep(300,0);
01098     usleep(300000);
01099     break;
01100     //
01101   case E_SCC_MAN_GuiComm_Sent:
01102     fStatusSCC2DAQ->SetText("Data sent");
01103     fStatusSCC2DAQ->SetBackgroundColor(TColor::RGB2Pixel(0xff,0x77,0x24));
01104     gClient->NeedRedraw(fStatusSCC2DAQ);
01105     
01106     //    TThread::Sleep(300,0);
01107     usleep(300000);
01108     break;
01109   
01110   case E_SCC_MAN_GuiComm_Idle:
01111     fStatusSCC2DAQ->SetText("idle");
01112     fStatusSCC2DAQ->SetBackgroundColor(TColor::RGB2Pixel(0xaa,0xff,0x99));
01113     gClient->NeedRedraw(fStatusSCC2DAQ);
01114      break;
01115   default:
01116     Error("ScheduledOperationPerformed","operation \"%d\" not defined",oper);
01117     return;
01118   }
01119 
01120   Relax(0);
01121 
01122   if(UpdateTime){
01123     // --- text entries
01124     for(Int_t i=SCC_SUMMARY_NUM-1;i>0;i--){
01125       ModifyTextEntry(fTxtSCC_LastDate[i], fTxtSCC_LastDate[i-1] ->GetText() );
01126       ModifyTextEntry(fTxtSCC_LastTime[i], fTxtSCC_LastTime[i-1] ->GetText() );
01127       ModifyTextEntry(fTxtSCC_LastBytes[i],fTxtSCC_LastBytes[i-1] ->GetText() );
01128     } 
01129     
01130     ModifyTextEntry(fTxtSCC_LastDate[0],DateString.Data());
01131     ModifyTextEntry(fTxtSCC_LastTime[0],TimeString.Data());
01132     ModifyTextEntry(fTxtSCC_LastBytes[0],BytesString.Data());
01133   }
01134   else { // no change: just a GUI update
01135     for(Int_t i=SCC_SUMMARY_NUM-1;i>0;i--){
01136       RedrawTextEntry(fTxtSCC_LastDate[i]);
01137       RedrawTextEntry(fTxtSCC_LastTime[i]);
01138       RedrawTextEntry(fTxtSCC_LastBytes[i]);
01139     } 
01140   }
01141 
01142   return;
01143 }
01144 

Generated on Tue Oct 16 15:40:48 2007 by  doxygen 1.5.2