Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

/Go4GUI/TGo4ScriptSlots.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //        Go4 Release Package v2.10-5 (build 21005) 
00003 //                      03-Nov-2005
00004 //---------------------------------------------------------------
00005 //       The GSI Online Offline Object Oriented (Go4) Project
00006 //       Experiment Data Processing at DVEE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 #include "TGo4ScriptSlots.h"
00017 
00018 #include <iostream.h>
00019 
00020 #include "TPad.h"
00021 #include "TH1.h"
00022 #include "TObjArray.h"
00023 #include "TList.h"
00024 #include "THStack.h"
00025 #include "TObjString.h"
00026 #include "TInterpreter.h"
00027 
00028 #include "qstring.h"
00029 #include "qdir.h"
00030 #include "qtextedit.h"
00031 #include "qobjectlist.h"
00032 
00033 #include "Go4GUIRegistry/TGo4GUIRegistry.h"
00034 #include "TGo4StartClientSlots.h"
00035 #include "TGo4StartClientStatus.h"
00036 #include "TGo4MainWindow.h"
00037 #include "Go4Display/TGo4Display.h"
00038 #include "Go4TaskHandler/TGo4TaskHandler.h"
00039 #include "TGo4AnalysisConfigurationSlots.h"
00040 #include "TGo4AnalysisConfiguration.h"
00041 #include "TGo4ConfigStep.h"
00042 #include "TGo4PreviewPanel.h"
00043 #include "TGo4PreviewPanelSlots.h"
00044 #include "TGo4PreviewPanelStatus.h"
00045 #include "TGo4PadOptions.h"
00046 #include "Go4CommandsAnalysis/TGo4ComGetObject.h"
00047 #include "TGo4QRootCanvas.h"
00048 #include "TGo4DockBrowsers.h"
00049 #include "Go4QtBaseWidgets/TGo4QItem.h"
00050 #include "TGo4RemoteBrowserSlots.h"
00051 #include "TGo4MonitoredListSlots.h"
00052 #include "TGo4MonitoredList.h"
00053 #include "TGo4AnalysisStatusMonitorSlots.h"
00054 #include "TGo4AnalysisStatusMonitor.h"
00055 #include "Go4QtBaseWidgets/TGo4WorkSpace.h"
00056 #include "TGo4AnalysisWindow.h"
00057 #include "Go4ConditionsBase/TGo4Condition.h"
00058 #include "TGo4DiskFileBrowserSlots.h"
00059 #include "TGo4ScriptStatus.h"
00060 #include "TGo4ScriptWidget.h"
00061 #include "TGo4QSettings.h"
00062 
00063 const char* TGo4ScriptSlots::GUIScriptExtension = ".hotstart";
00064 
00065 TGo4ScriptSlots::TGo4ScriptSlots(const char * name, const char * title, TGo4ScriptWidget *p) :
00066    TGo4SlotsBaseClass(name, title), fxScriptWidget(p) {
00067 
00068    fxRegistry = TGo4GUIRegistry::Instance();
00069 
00070    fxStatus = new TGo4ScriptStatus("TGo4ScriptStatus","TGo4ScriptStatus title");
00071 
00072    fxRegistry->RegisterSlotClass(this, fxStatus, p);
00073 }
00074 
00075 TGo4ScriptSlots::~TGo4ScriptSlots() {
00076    delete fxStatus;
00077 }
00078 
00079 TGo4Status* TGo4ScriptSlots::GetStatus() {
00080    return fxStatus;
00081 }
00082 
00083 void TGo4ScriptSlots::SetGUI(TGo4ScriptWidget *p) {
00084    fxScriptWidget = p;
00085    fxRegistry->GuiIsChanged(this, p);
00086 }
00087 
00088 void TGo4ScriptSlots::setOutput(QTextEdit* output) {
00089    fxOutput = output;
00090 }
00091 
00092 
00093 void TGo4ScriptSlots::doOutput(const char* str) {
00094    if (fxOutput==0) return;
00095    if (str==0) fxOutput->append("");
00096           else fxOutput->append(str);
00097 //   cout << str << endl;
00098 }
00099 
00100 int getCounts(double tm) {
00101    return int(tm*100.);
00102 }
00103 
00104 
00105 bool TGo4ScriptSlots::StartScriptExecution() {
00106    if (fxStatus==0) return false;
00107 
00108    gROOT->Reset();
00109 
00110    fxStatus->fxCommandCounter = 0;
00111 
00112    TString cmd = "TGo4ScriptSlots* go4 = TGo4GUIRegistry::Instance()->GetSlotClass(\"TGo4ScriptSlots\");";
00113 
00114    doOutput(cmd);
00115 
00116    Int_t error = 0;
00117    gROOT->ProcessLine(cmd, &error);
00118 
00119    if (error!=0) {
00120      TString err("Error = ");
00121      err+=error;
00122      doOutput(err);
00123      return false;
00124    }
00125 
00126    fiWaitForGUIReaction = 0;
00127    fiWaitCounter = getCounts(0.1);
00128 
00129    return true;
00130 }
00131 
00132 bool TGo4ScriptSlots::ProcessScriptExecution() {
00133    if (fxStatus==0) return false;
00134 
00135    switch (execGUICommands()) {
00136       case 0:
00137          return false;
00138       case 1:
00139          fiWaitForGUIReaction = 0;
00140          fiWaitCounter = 0;
00141          break;
00142       case 2:
00143          fiWaitCounter--;
00144          return true;
00145    }
00146 
00147    TObjString* str = dynamic_cast<TObjString*> (fxStatus->fxCommands.At(fxStatus->fxCommandCounter));
00148    fxStatus->fxCommandCounter++;
00149    if (str==0) return false;
00150 
00151    doOutput(str->GetName());
00152 
00153    Int_t error = 0;
00154    gROOT->ProcessLine(str->GetName(), &error);
00155 
00156    if (error!=0) {
00157      TString err("Error = ");
00158      err+=error;
00159      doOutput(err);
00160      return false;
00161    }
00162 
00163    return true;
00164 }
00165 
00166 Bool_t TGo4ScriptSlots::IsAnalysisReady()
00167 {
00168    TGo4Display* displ = fxRegistry->GetDisplay();
00169     
00170    return displ->IsServer() ? fxRegistry->IsAnalysisReady() : displ->IsConnected(); 
00171 }
00172 
00173 int TGo4ScriptSlots::execGUICommands() 
00174 {
00175  // return 0 (false) - abbort, 1(true) - exec next command, 2 - wait
00176 
00177    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
00178 
00179    switch (fiWaitForGUIReaction) {
00180       case 0:
00181         return 1;
00182 
00183       case 1: { // execute lanch client method
00184          if(IsAnalysisReady()) {
00185              doOutput("// Disconnect old analysis first");
00186              main->RemoveClientSlot();
00187              fiWaitForGUIReaction = 3;
00188              fiWaitCounter = getCounts(10.);
00189              return 2;
00190          }
00191 
00192          main->StartAnalysisWin(true);
00193 
00194          TGo4StartClientSlots* sl = (TGo4StartClientSlots*) fxRegistry->GetSlotClass("TGo4StartClientSlots");
00195          if (sl==0) {
00196             doOutput("TGo4StartClientSlots disappear");
00197             return 0;
00198          }
00199 
00200          TGo4StartClientStatus* status = (TGo4StartClientStatus*)  sl->GetStatus();
00201 
00202          sl->StartClient(status->GetSlaveName(), 
00203                          status->GetSlaveNode(),
00204                          status->GetSlaveDir(), 
00205                          status->GetSlaveExec(),
00206                          status->GetServerPort(),
00207                          status->IsStartServer());
00208 
00209          doOutput("// Start analysis client");
00210 
00211          fiWaitForGUIReaction = 2;
00212          fiWaitCounter = getCounts(30.);
00213 
00214          return 2;
00215       }
00216 
00217       case 2: {  // check if analysis is ready, can continue if not ok
00218          if (IsAnalysisReady()) {
00219             TGo4Display* displ = fxRegistry->GetDisplay();
00220             TGo4RemoteBrowserSlots* remsl = 
00221               dynamic_cast <TGo4RemoteBrowserSlots *> (fxRegistry->GetSlotClass("TGo4RemoteBrowserSlots"));
00222             TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
00223             
00224             if (!displ->IsServer()) { 
00225                remsl->Refresh(true); 
00226                main->AnalysisStatusSlot();
00227             }
00228             return 1;
00229          }
00230          return (fiWaitCounter<2) ? 1 : 2;
00231       }
00232 
00233       case 3: {   // wait while analysis is disconnected
00234          TGo4Display *fxDisplay = fxRegistry->GetDisplay();
00235          if(fxDisplay && (fxDisplay->GetTask()->GetTaskHandler()==0)) {
00236             fiWaitForGUIReaction = 4;
00237             fiWaitCounter = getCounts(5.);
00238             return 2;
00239          }
00240          return (fiWaitCounter<2) ? 0 : 2;
00241       }
00242 
00243       case 4: { // wait time and lunch analysis again
00244         if (fiWaitCounter<5)
00245           fiWaitForGUIReaction = 1;
00246         return 2;
00247       }
00248 
00249       case 5: {  // check if analysis is ready, abort if not ok
00250          if (IsAnalysisReady()) return 1;
00251          return (fiWaitCounter<2) ? 0 : 2;
00252       }
00253 
00254       case 10: { // wait until submitted settings are set
00255         if (fxRegistry->IsAnaSettingsReady()) {
00256           TGo4RemoteBrowserSlots* sl = dynamic_cast <TGo4RemoteBrowserSlots *> (fxRegistry->GetSlotClass("TGo4RemoteBrowserSlots"));
00257           if (sl) {
00258             sl->Refresh(kFALSE);
00259             fiWaitForGUIReaction = 11;
00260             fiWaitCounter = getCounts(20.);
00261             return 2;
00262           }
00263           return 1;
00264         }
00265         return (fiWaitCounter<2) ? 0 : 2;
00266       }
00267 
00268       case 11: { // wait until remote browser refresh it's data
00269          TGo4RemoteBrowserSlots* sl = dynamic_cast <TGo4RemoteBrowserSlots *> (fxRegistry->GetSlotClass("TGo4RemoteBrowserSlots"));
00270          if (sl && sl->BrowserRefreshed()) return 1;
00271          return (fiWaitCounter<2) ? 0 : 2;
00272       }
00273 
00274       case 20 : { // wait unit object appear in local browser
00275          TGo4DockBrowsers* dock = main->DockBrowsers();
00276          if (dock->FindItem(1, fStrBuf.Data())) return 1;
00277          return (fiWaitCounter<2) ? 1 : 2;
00278       }
00279 
00280       case 21 : { // wait unit object appear in monitor browser
00281          TGo4DockBrowsers* dock = main->DockBrowsers();
00282          if (dock->FindItem(2, fStrBuf.Data())) return 1;
00283          return (fiWaitCounter<2) ? 1 : 2;
00284       }
00285 
00286       case 111: { // just wait time and take next command
00287          return (fiWaitCounter<2) ? 1 : 2;
00288       }
00289    } //switch
00290 
00291    return 2;
00292 }
00293 
00294 void TGo4ScriptSlots::GenerateStartupScript(const char* fname) {
00295    ofstream fs(fname);
00296    doOutput(TString("Generate script ")+fname);
00297    fs << "// Automatically generated startup script" << endl;
00298    fs << "// Do not change it!" << endl << endl;
00299 
00300    TString libs = gInterpreter->GetSharedLibs();
00301    const char* token = strtok((char*) libs.Data(), " ,\t\n");
00302    while(token != 0) {
00303       if ((strstr(token,"libGX11.")==0) &&
00304           (strstr(token,"libGX11TTF.")==0) &&
00305           (strstr(token,"libHistPainter.")==0))
00306          fs << "go4->LoadLibrary(\"" << token << "\");" << endl;
00307       token = strtok(NULL, " ,\t\n");
00308    }
00309    fs << endl;
00310 
00311    TGo4Display* displ = fxRegistry->GetDisplay();
00312    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
00313    TGo4DockBrowsers* dock = main->DockBrowsers();
00314 
00315    TGo4WorkSpace* space = dynamic_cast<TGo4WorkSpace*> (fxRegistry->GetCentralWindow());
00316 
00317    TGo4StartClientSlots* startsl =
00318        dynamic_cast<TGo4StartClientSlots*>
00319          (fxRegistry->GetSlotClass("TGo4StartClientSlots"));
00320 
00321    TGo4AnalysisConfigurationSlots* confsl =
00322       dynamic_cast <TGo4AnalysisConfigurationSlots *>
00323         (fxRegistry->GetSlotClass("TGo4AnalysisConfigurationSlots"));
00324 
00325    TGo4AnalysisConfiguration* confgui =
00326      dynamic_cast<TGo4AnalysisConfiguration*> (fxRegistry->GetGUIClass(confsl));
00327 
00328    TGo4MonitoredListSlots* monsl =
00329      dynamic_cast <TGo4MonitoredListSlots *> (fxRegistry->GetSlotClass("TGo4MonitoredListSlots"));
00330 
00331    TGo4MonitoredList* mongui =
00332      dynamic_cast<TGo4MonitoredList*> (fxRegistry->GetGUIClass(monsl));
00333 
00334    TGo4AnalysisWindow* termgui = main->AnalysisShell();
00335    
00336    // standard situation with gui as server
00337    if (displ->IsServer()) {
00338 
00339       if (fxRegistry->IsAnalysisReady()) {
00340          if (startsl==0) return;
00341          TGo4StartClientStatus* status = (TGo4StartClientStatus*)  startsl->GetStatus();
00342 
00343          fs << "go4->LaunchAnalysis(\"" 
00344             << status->GetSlaveName() << "\", \""
00345             << status->GetSlaveDir() <<  "\", \""
00346             << status->GetSlaveExec() << "\", \""
00347             << status->GetSlaveNode() << "\", "
00348             << status->GetSlaveMode() << ", "
00349             << status->GetSlaveShell() << ");" << endl;
00350          fs << "go4->WaitAnalysis(300);" << endl << endl;
00351 
00352          ProduceAnalysisSetupScript(fs, confgui);
00353 
00354          if (confsl!=0)
00355             if (fxRegistry->IsAnaSettingsReady()) 
00356                fs << "go4->SubmitAnalysisConfig();" << endl << endl;
00357                
00358       } else {
00359          fs << "go4->DisconnectAnalysis();" << endl;
00360          return;
00361       }
00362       
00363    } else {
00364       
00365       if (displ->IsConnected()) {
00366          if (startsl==0) return;
00367          TGo4StartClientStatus* status = (TGo4StartClientStatus*)  startsl->GetStatus();
00368           
00369          fs << "go4->ConnectAnalysis(\""
00370             << status->GetSlaveNode() << "\", "
00371             << status->GetServerPort() << ", "
00372             << status->GetLoginMode() << ", \""
00373             << status->GetPasswd() << "\");" << endl;
00374       } else {
00375          fs << "go4->DisconnectAnalysis();" << endl;
00376          return;
00377       }
00378        
00379    }
00380 
00381    int mode = 1;
00382    if (confgui) {
00383       if (confgui->isHidden()) mode = -1; else
00384       if (confgui->isMinimized()) mode = 0;
00385    }
00386    fs << "go4->SetAnalysisConfigMode(" << mode << ");" << endl;
00387 
00388    mode = 1;
00389    if (termgui) {
00390       if (termgui->isHidden()) mode = -1; else
00391       if (termgui->isMinimized()) mode = 0;
00392    }
00393    fs << "go4->SetAnalysisTerminalMode(" << mode << ");" << endl << endl;
00394 
00395    QWidgetList panels;
00396    TObjArray panelspads;
00397 
00398    if (space!=0)  {
00399       QWidgetList wlist = space->windowList();
00400       QWidget* widg = wlist.first();
00401       while (widg!=0) {
00402         TGo4PreviewPanel* panel = dynamic_cast<TGo4PreviewPanel*> (widg);
00403         if (panel) panels.append(panel);
00404         widg = wlist.next();
00405       }
00406    }
00407 
00408    fs << "// Request objects from analysis " << endl;
00409 
00410    if (dock!=0)
00411      for (int ntab=1; ntab<=2; ntab++) {
00412        QListViewItemIterator it(dock->GetListView(ntab));
00413        while (it.current()) {
00414           TGo4QItem* item = dynamic_cast<TGo4QItem*> (it.current());
00415           if (item && dock->FindItem(3, item->text(0))) {
00416               if (ntab==1) fs << "go4->GetObject";
00417                       else fs << "go4->MonitorObject";
00418               fs << "(\"" << item->text(0) << "\");" << endl;
00419           }
00420           it++;
00421        }
00422      }
00423 
00424    fs << endl << "// reconstruct all preview panels " << endl;
00425 
00426    int numactivepanel = -1;
00427 
00428    for (unsigned int npanel=0; npanel<panels.count(); npanel++) {
00429       TGo4PreviewPanel* panel = dynamic_cast<TGo4PreviewPanel*> (panels.at(npanel));
00430       TObjArray* arr = new TObjArray();
00431       panelspads.Add(arr);
00432 
00433       if (panel==0) continue;
00434 
00435       if (space->GetLastActiveViewPanel() == panel)
00436         numactivepanel = int(npanel);
00437 
00438 //      TGo4PreviewPanelStatus* status = panel->GetStatus();
00439 
00440       ExploreAllPads(panel->GetCanvas(), arr);
00441 
00442       fs << "void* panel" << npanel << " = go4->StartViewPanel();" << endl;
00443 
00444       QPoint pos = panel->parentWidget()->pos();
00445       panel->parentWidget()->mapToParent(pos);
00446       QSize size = panel->parentWidget()->size();
00447       mode = 1;
00448       if (panel->isHidden()) mode = -1; else
00449       if (panel->isMinimized()) mode = 0; else
00450       if (panel->isMaximized()) mode = 2;
00451 
00452       fs << "go4->SetViewPanelPosition(panel" << npanel << ", "
00453          << pos.x() << ", "
00454          << pos.y() << ", "
00455          << size.width() << ", "
00456          << size.height() << ", "
00457          << mode << ");" << endl;
00458 
00459 /*      if (status)
00460         fs << "go4->SetPadOptions(panel" << npanel << ", " << 0 << ", \""
00461            << status->GetPadStringDrawOption(panel->GetCanvas()) << "\");" << endl;
00462 */
00463 
00464        for(int nsubpad=1;nsubpad<=arr->GetLast();nsubpad++) {
00465           TPad* subpad = (TPad*) arr->At(nsubpad);
00466           Int_t nmother = arr->IndexOf(subpad->GetMother());
00467           if (nmother<0) nmother = 0;
00468           Double_t xlow, ylow, xup, yup;
00469           subpad->GetPadPar(xlow, ylow, xup, yup);
00470 
00471           fs << "go4->CreateSubPad(panel" << npanel << ", " << nmother << ", "
00472                                           << xlow << ", " <<  ylow << ", "
00473                                           << xup << ", " << yup << ");" << endl;
00474 
00475 /*          if (status)
00476              fs << "go4->SetPadOptions(panel" << npanel << ", " << nsubpad << ", \""
00477                 << status->GetPadStringDrawOption(subpad) << "\");" << endl;
00478 */       }
00479 
00480        fs << endl;
00481    }
00482 
00483    if ((numactivepanel<0) && (panels.count()>0))
00484       numactivepanel = panels.count() - 1;
00485 
00486    fs << "// Display object from memory browser and monitor list" << endl;
00487 
00488    Int_t waitobjtime = 10;
00489 
00490    if (dock!=0)
00491      for (int ntab=1; ntab<=2; ntab++) {
00492        QListViewItemIterator it(dock->GetListView(ntab));
00493        while (it.current()) {
00494          TGo4QItem* item = dynamic_cast<TGo4QItem*> (it.current());
00495          it++;
00496          if (item==0) continue;
00497 
00498          TObject* obj = item->GetWorkObject();
00499          if (obj==0) continue;
00500 
00501          Bool_t dowait = kTRUE;
00502 
00503          for (unsigned int npanel=0; npanel<panels.count(); npanel++) {
00504             TGo4PreviewPanel* panel = dynamic_cast<TGo4PreviewPanel*> (panels.at(npanel));
00505             if (panel==0) continue;
00506             TObjArray* arr = (TObjArray*) panelspads.At(npanel);
00507             for(int npad=0;npad<=arr->GetLast();npad++) {
00508                TPad* pad = (TPad*) arr->At(npad);
00509                if (pad->GetListOfPrimitives()->FindObject(obj) || (obj == (TObject*) panel->GetPadHistogram(pad))) {
00510                   if (dowait) {
00511                      if (ntab==1) fs << "go4->WaitObject";
00512                              else fs << "go4->WaitMonitor";
00513                      fs << "(\"" << item->text(0) << "\", " << waitobjtime << ");" << endl;
00514                      dowait = kFALSE;
00515                      waitobjtime = 1;
00516                   }
00517                   if (ntab==1) fs << "go4->DisplayObject";
00518                           else fs << "go4->DisplayMonitorObject";
00519                   fs << "(\"" << item->text(0) << "\", panel" << npanel;
00520                   if (npad>0) fs << ", " << npad;
00521                   fs << ");" << endl;
00522                }
00523             }
00524          }
00525        }
00526      }
00527 
00528    // Loop over all panels to reinvent superimpose
00529    for (unsigned int npanel=0; npanel<panels.count(); npanel++) {
00530      TGo4PreviewPanel* panel = dynamic_cast<TGo4PreviewPanel*> (panels.at(npanel));
00531      if (panel==0) continue;
00532      TObjArray* arr = (TObjArray*) panelspads.At(npanel);
00533      for(int npad=0;npad<=arr->GetLast();npad++) {
00534         TPad* pad = (TPad*) arr->At(npad);
00535         TGo4PadOptions* padoptions = panel->GetPadOptions(pad);
00536         if ((padoptions==0) || (!padoptions->DragAddOption())) continue;
00537         THStack* hs = panel->GetPadTHStack(pad);
00538         if (hs==0) continue;
00539 
00540         fs << endl << "// superimpose histograms " << endl;
00541         int nhists = hs->GetHists()->GetSize();
00542 
00543         fs << "go4->SwitchSuperImpose(panel" << npanel << ", " << npad << ");" << endl;
00544         for(int i=0;i<nhists;i++) {
00545           fs << "go4->WaitObject(\"" << hs->GetHists()->At(i)->GetName()
00546                                      << "\", " << waitobjtime << ");" << endl;
00547           waitobjtime = 1;
00548           fs << "go4->DisplayObject(\"" << hs->GetHists()->At(i)->GetName()
00549                                         << "\", panel" << npanel
00550                                         << ", " << npad << ", "
00551                                         << ( (i==nhists-1) ? "kTRUE" : "kFALSE")
00552                                         << ");" << endl;
00553          }
00554      }
00555    }
00556 
00557    fs << endl << "// set pad options" << endl;
00558    // Loop over all panels to reinvent superimpose
00559    for (unsigned int npanel=0; npanel<panels.count(); npanel++) {
00560      TGo4PreviewPanel* panel = dynamic_cast<TGo4PreviewPanel*> (panels.at(npanel));
00561      if (panel==0) continue;
00562 
00563      TGo4PreviewPanelStatus* status = panel->GetStatus();
00564      TObjArray* arr = (TObjArray*) panelspads.At(npanel);
00565      for(int npad=0;npad<=arr->GetLast();npad++) {
00566         TPad* pad = (TPad*) arr->At(npad);
00567         TGo4PadOptions* opt = panel->GetPadOptions(pad);
00568         
00569         if (status) {
00570           int logscale = 0, padstatus = 11001;
00571           if (opt) {
00572              logscale = opt->GetHisXStyle() * 100 + 
00573                         opt->GetHisYStyle() * 10 +
00574                         opt->GetHisZStyle();
00575              
00576              padstatus = (opt->IsHisStats() ? 10000 : 0) +
00577                          (opt->IsHisTitle() ? 1000 : 0) + 
00578                          (opt->IsLegendDraw() ? 100 : 0) + 
00579                          (opt->IsCrosshair() ? 10 : 0) +
00580                          (opt->GetAutoScale() ? 1 : 0);
00581           }
00582            
00583             
00584           fs << "go4->SetPadOptions(panel" << npanel << ", " << npad << ", \""
00585              << status->GetPadStringDrawOption(pad) << "\", " 
00586              << logscale << ", " << padstatus <<");" << endl;
00587         }
00588 
00589         double xmin, xmax, ymin, ymax, zmin, zmax;
00590         if (panel->GetPadRanges(pad, xmin, xmax, ymin, ymax, zmin, zmax))
00591            fs << "go4->SetPadRange(panel" << npanel << ", " << npad << ", "
00592                                           << xmin << ", " << xmax << ", "
00593                                           << ymin << ", " << ymax << ", "
00594                                           << zmin << ", " << zmax << ");" << endl;
00595         if (opt && opt->GetCondition())
00596           fs << "go4->GetCondition(\"" << opt->GetCondition()->GetName()
00597                                        << "\", panel" << npanel
00598                                        << ", " << npad << ");" << endl;
00599      }
00600    }
00601    fs << endl;
00602 
00603    if (numactivepanel>=0) {
00604      TGo4PreviewPanel* panel = dynamic_cast<TGo4PreviewPanel*> (panels.at(numactivepanel));
00605      if (panel!=0) {
00606        TObjArray* arr = (TObjArray*) panelspads.At(numactivepanel);
00607        Int_t numactivepad = arr->IndexOf(panel->GetActivePad());
00608        if (numactivepad<0) numactivepad = 0;
00609        fs << "go4->SetActivePad(panel" << numactivepanel << ", "
00610                                        << numactivepad << ");" << endl << endl;
00611      }
00612    }
00613 
00614 
00615 
00616    if (mongui)
00617      switch (mongui->GetMonitorState()) {
00618         case 0:
00619           fs << "go4->StopMonitor();" << endl;
00620           break;
00621         case 1:
00622           fs << "go4->StartMonitor(" << mongui->GetMonitorInterval() << ");" << endl;
00623           break;
00624         case 2:
00625           fs << "go4->StartMonitor(" << mongui->GetMonitorInterval() << ", kTRUE);" << endl;
00626           break;
00627      }
00628 
00629    panelspads.Delete();
00630 }
00631 
00632 void TGo4ScriptSlots::ExploreAllPads(TPad* toppad, TObjArray* arr) {
00633    if (arr==0) return;
00634    arr->Clear();
00635    arr->Compress();
00636    if (toppad==0) return;
00637 
00638    arr->Add(toppad);
00639 
00640    int first = 0, last = 0;
00641 
00642    do {
00643       for(int n=first;n<=last;n++) {
00644          TPad* pad = (TPad*) arr->At(n);
00645 
00646          TIter iter(pad->GetListOfPrimitives());
00647 
00648          TObject* obj = 0;
00649          while ((obj = iter()) != 0)
00650             if (obj->InheritsFrom(TPad::Class()))
00651               arr->Add(obj);
00652       }
00653 
00654       first = last+1;
00655       last = arr->GetLast();
00656    } while (first<=last);
00657 }
00658 
00659 TPad* TGo4ScriptSlots::FindPad(TGo4PreviewPanel* panel, int npad) {
00660    if ((panel==0) || (npad<0)) return 0;
00661 
00662    if (npad==0) return panel->GetCanvas();
00663 
00664    TObjArray arr;
00665    ExploreAllPads(panel->GetCanvas(), &arr);
00666    if (npad<=arr.GetLast())
00667      return (TPad*) arr.At(npad);
00668 
00669    return 0;
00670 }
00671 
00672 void TGo4ScriptSlots::ProduceAnalysisSetupScript(ofstream& fs, TGo4AnalysisConfiguration* confgui) 
00673 {
00674    if (confgui==0) return;
00675    fs << "// configuration of analysis" << endl;
00676 
00677    QString fname;
00678    int interval, compression;
00679    bool asenabled, asoverwrite;
00680 
00681    confgui->GetAutoSaveConfig(fname, interval, compression, asenabled, asoverwrite);
00682    fs << "go4->AnalysisAutoSave(\"" << fname << "\", "
00683                                     << interval << ", "
00684                                     << compression << ", "
00685                                     << (asenabled ? "kTRUE" : "kFALSE") << ", "
00686                                     << (asoverwrite ? "kTRUE" : "kFALSE") << ");" << endl;
00687 
00688    confgui->GetAnalysisConfigFile(fname);
00689    fs << "go4->AnalysisConfigName(\"" << fname << "\");" << endl << endl;
00690 
00691    for(int nstep=0;nstep<confgui->GetNumSteps();nstep++) {
00692       TGo4ConfigStep* stepconf = confgui->GetStepConfig(nstep);
00693       fs << "// step " << stepconf->GetStepName() << endl;
00694 
00695       bool process, source, store;
00696       stepconf->GetStepControl(process, source, store);
00697       fs << "go4->ConfigStep(\"" << stepconf->GetStepName() << "\", "
00698                                  << (process ? "kTRUE" : "kFALSE") << ", "
00699                                  << (source ? "kTRUE" : "kFALSE") << ", "
00700                                  << (store ? "kTRUE" : "kFALSE") << ");" << endl;
00701 
00702       QString srcname;
00703       int timeout;
00704       int nsrc = stepconf->GetSourceSetup(srcname, timeout);
00705       TString srcargs = "(\"";
00706       srcargs += stepconf->GetStepName();
00707       srcargs += "\", \"";
00708       srcargs += srcname;
00709       srcargs += "\", ";
00710       srcargs += timeout;
00711 
00712       switch(nsrc) {
00713          case 0:
00714            fs << "go4->StepFileSource" << srcargs;
00715            break;
00716          case 1: {
00717            QString TagFile;
00718            int start,stop,interval;
00719            stepconf->GetMbsFileSource(TagFile,start,stop,interval);
00720            fs << "go4->StepMbsFileSource" << srcargs << ", \""
00721                                           << TagFile  << "\", "
00722                                           << start  << ", "
00723                                           << stop  << ", "
00724                                           << interval;
00725            break;
00726          }
00727          case 2:
00728            fs << "go4->StepMbsStreamSource" << srcargs;
00729            break;
00730          case 3:
00731            fs << "go4->StepMbsTransportSource" << srcargs;
00732            break;
00733          case 4:
00734            fs << "go4->StepMbsEventServerSource" << srcargs;
00735            break;
00736          case 5: {
00737            int port;
00738            stepconf->GetMbsRevServSource(port);
00739            fs << "go4->StepMbsRevServSource" << srcargs << ", " << port;
00740            break;
00741          }
00742          case 6:
00743            fs << "go4->StepRandomSource" << srcargs;
00744            break;
00745          case 7: {
00746            int port;
00747            QString expr;
00748            stepconf->GetUserSource(port, expr);
00749            fs << "go4->StepUserSource" << srcargs << ", " << port << ", \""
00750                                        << expr << "\"";
00751            break;
00752          }
00753 
00754       } //  switch(nsrc)
00755       fs << ");" << endl;
00756 
00757       QString storename;
00758       int nstore = stepconf->GetStoreSetup(storename);
00759       switch(nstore) {
00760          case 0: {
00761             bool overwrite;
00762             int bufsize, splitlevel, compression;
00763             stepconf->GetFileStore(overwrite, bufsize, splitlevel, compression);
00764             fs << "go4->StepFileStore(\"" << stepconf->GetStepName() << "\", \""
00765                                           << storename << "\", "
00766                                           << (overwrite ? "kTRUE" : "kFALSE") << ", "
00767                                           << bufsize << ", "
00768                                           << splitlevel << ", "
00769                                           << compression << ");" << endl;
00770             break;
00771          }
00772 
00773          case 1: {
00774             int bufsize, splitlevel;
00775             stepconf->GetBackStore(bufsize, splitlevel);
00776             fs << "go4->StepBackStore(\"" << stepconf->GetStepName() << "\", \""
00777                                           << storename << "\", "
00778                                           << bufsize << ", "
00779                                           << splitlevel << ");" << endl;
00780             break;
00781          }
00782       } // switch
00783 
00784       fs << endl;
00785    }
00786 }
00787 
00788 TGo4ConfigStep* TGo4ScriptSlots::GetStepGUI(const char* stepname) {
00789    TGo4AnalysisConfigurationSlots* sl =
00790      dynamic_cast <TGo4AnalysisConfigurationSlots *>
00791        (fxRegistry->GetSlotClass("TGo4AnalysisConfigurationSlots"));
00792    if (sl==0) return 0;
00793 
00794    TGo4AnalysisConfiguration* gui =
00795      dynamic_cast<TGo4AnalysisConfiguration*> (fxRegistry->GetGUIClass(sl));
00796    if (gui==0) return 0;
00797 
00798    return gui->FindStepConfig(stepname);
00799 }
00800 
00801 
00802 // Functions to be used in GUI script
00803 
00804 void TGo4ScriptSlots::LoadLibrary(const char* fname) {
00805    if ((fname==0) || (strlen(fname)==0)) return;
00806 
00807    TString libs = gInterpreter->GetSharedLibs();
00808 
00809    const char* token = strtok((char*) libs.Data(), " ,\t\n");
00810 
00811    while(token != 0) {
00812       if (strcmp(token, fname)==0) return;
00813       token = strtok(NULL, " ,\t\n");
00814    }
00815 
00816    gSystem->Load(fname);
00817 }
00818 
00819 
00820 void TGo4ScriptSlots::LaunchAnalysis() {
00821     TGo4QSettings settings;
00822 
00823     QString ClientName = settings.readEntry( TGo4QSettings::GetSettingsName()+"/ClientSetting/Name", "MyAnalysis");
00824     QString ClientDir  = settings.readEntry( TGo4QSettings::GetSettingsName()+"/ClientSetting/Dir", (QDir::currentDirPath()).data());
00825     QString ClientExec = settings.readEntry( TGo4QSettings::GetSettingsName()+"/ClientSetting/Exec", "MainUserAnalysis");
00826     QString ClientNode = settings.readEntry( TGo4QSettings::GetSettingsName()+"/ClientSetting/Node", "localhost");
00827 
00828     LaunchAnalysis(ClientName, ClientDir, ClientExec, ClientNode, 2, 1);
00829 }
00830 
00831 void TGo4ScriptSlots::LaunchAnalysis(const char* ClientName,
00832                                      const char* ClientDir,
00833                                      const char* ClientExec,
00834                                      const char* ClientNode,
00835                                      Int_t ClientMode,
00836                                      Int_t ClientShell) {
00837 
00838     TGo4StartClientSlots* sl =
00839       dynamic_cast<TGo4StartClientSlots*>
00840         (fxRegistry->GetSlotClass("TGo4StartClientSlots"));
00841     if(sl==0)
00842       sl = new TGo4StartClientSlots ("TGo4StartClientSlots", "Slots Class for Qt GUI", 0);
00843     TGo4StartClientStatus* status = (TGo4StartClientStatus*)  sl->GetStatus();
00844 
00845     status->SetSlaveName(ClientName);
00846     status->SetSlaveDir(ClientDir);
00847     status->SetSlaveNode(ClientNode);
00848     status->SetSlaveExec(ClientExec);
00849 
00850     status->SetSlaveMode(ClientMode);
00851     status->SetSlaveShell(ClientShell);
00852 
00853     fiWaitForGUIReaction = 1;
00854     fiWaitCounter = getCounts(1.);
00855 }
00856 
00857 void TGo4ScriptSlots::ConnectAnalysis(const char* ServerNode,
00858                                       Int_t ServerPort,
00859                                       Int_t ControllMode,
00860                                       const char* ControllPass)
00861 {
00862     TGo4StartClientSlots* sl =
00863       dynamic_cast<TGo4StartClientSlots*>
00864         (fxRegistry->GetSlotClass("TGo4StartClientSlots"));
00865     if(sl==0)
00866       sl = new TGo4StartClientSlots ("TGo4StartClientSlots", "Slots Class for Qt GUI", 0);
00867     TGo4StartClientStatus* status = (TGo4StartClientStatus*)  sl->GetStatus();
00868 
00869     status->SetSlaveNode(ServerNode);
00870     status->SetServerPort(ServerPort);
00871     status->SetLoginMode(ControllMode);
00872     status->SetPasswd(ControllPass);
00873     status->SetStartServer(kFALSE);
00874 
00875     fiWaitForGUIReaction = 1;
00876     fiWaitCounter = getCounts(1.);
00877 }                                      
00878 
00879 
00880 void TGo4ScriptSlots::WaitAnalysis(Int_t delay_sec) {
00881     fiWaitForGUIReaction = 5;
00882     fiWaitCounter = getCounts(delay_sec);
00883 }
00884 
00885 void TGo4ScriptSlots::DisconnectAnalysis() {
00886     TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
00887     main->RemoveClientSlot();
00888     Wait(3.0);
00889 }
00890 
00891 void TGo4ScriptSlots::SubmitAnalysisConfig() {
00892    TGo4AnalysisConfigurationSlots* sl =
00893      dynamic_cast <TGo4AnalysisConfigurationSlots *>
00894        (fxRegistry->GetSlotClass("TGo4AnalysisConfigurationSlots"));
00895    if (sl==0) return;
00896 
00897    fxRegistry->SetAnaSettingsReady(kFALSE);
00898 
00899    sl->SubmitConfiguration();
00900 
00901    TGo4RemoteBrowserSlots* sl2 = dynamic_cast <TGo4RemoteBrowserSlots *> (fxRegistry->GetSlotClass("TGo4RemoteBrowserSlots"));
00902    if (sl2) sl2->ClearBrowser();
00903 
00904    fiWaitForGUIReaction = 10;
00905    fiWaitCounter = getCounts(20.);
00906 }
00907 
00908 void TGo4ScriptSlots::SetAnalysisTerminalMode(int mode) {
00909 /*   TGo4AnalysisStatusMonitorSlots* sl =
00910      dynamic_cast <TGo4AnalysisStatusMonitorSlots*>
00911        (fxRegistry->GetSlotClass("TGo4AnalysisStatusMonitorSlots"));
00912    if (sl==0) return;
00913 */
00914    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
00915    TGo4AnalysisWindow* gui = main->AnalysisShell();
00916 //     dynamic_cast<TGo4AnalysisStatusMonitor*> (fxRegistry->GetGUIClass(sl));
00917    if (gui==0) return;
00918 
00919    if (mode<0) gui->close(); else
00920    if (mode==0) gui->showMinimized(); else
00921                 gui->showNormal();
00922 }
00923 
00924 void TGo4ScriptSlots::SetAnalysisConfigMode(int mode) {
00925    TGo4AnalysisConfigurationSlots* sl =
00926      dynamic_cast <TGo4AnalysisConfigurationSlots *>
00927        (fxRegistry->GetSlotClass("TGo4AnalysisConfigurationSlots"));
00928    if (sl==0) return;
00929 
00930    TGo4AnalysisConfiguration* gui =
00931      dynamic_cast<TGo4AnalysisConfiguration*> (fxRegistry->GetGUIClass(sl));
00932    if (gui==0) return;
00933 
00934    if (mode<0) gui->close(); else
00935    if (mode==0) gui->showMinimized(); else
00936                 gui->showNormal();
00937 }
00938 
00939 void TGo4ScriptSlots::AnalysisAutoSave(const char* filename,
00940                                        Int_t interval,
00941                                        Int_t compression,
00942                                        Bool_t enabled,
00943                                        Bool_t overwrite) {
00944   TGo4AnalysisConfigurationSlots* confsl =
00945       dynamic_cast <TGo4AnalysisConfigurationSlots *>
00946         (fxRegistry->GetSlotClass("TGo4AnalysisConfigurationSlots"));
00947 
00948    TGo4AnalysisConfiguration* confgui =
00949      dynamic_cast<TGo4AnalysisConfiguration*> (fxRegistry->GetGUIClass(confsl));
00950 
00951    if(confgui)
00952      confgui->SetAutoSaveConfig(filename, interval, compression, enabled, overwrite);
00953 
00954 }
00955 
00956 void TGo4ScriptSlots::AnalysisConfigName(const char* filename) {
00957   TGo4AnalysisConfigurationSlots* confsl =
00958       dynamic_cast <TGo4AnalysisConfigurationSlots *>
00959         (fxRegistry->GetSlotClass("TGo4AnalysisConfigurationSlots"));
00960 
00961    TGo4AnalysisConfiguration* confgui =
00962      dynamic_cast<TGo4AnalysisConfiguration*> (fxRegistry->GetGUIClass(confsl));
00963 
00964    if(confgui)
00965       confgui->SetAnalysisConfigFile(filename);
00966 }
00967 
00968 
00969 void TGo4ScriptSlots::ConfigStep(const char* stepname,
00970                                  Bool_t enableprocess,
00971                                  Bool_t enablesource,
00972                                  Bool_t enablestore) {
00973    TGo4ConfigStep* step = GetStepGUI(stepname);
00974    if (step)
00975       step->SetStepControl(enableprocess, enablesource, enablestore);
00976 }
00977 
00978 void TGo4ScriptSlots::StepFileSource(const char* stepname,
00979                                      const char* sourcename,
00980                                      int timeout) {
00981    TGo4ConfigStep* step = GetStepGUI(stepname);
00982    if (step) {
00983       step->ResetSourceWidgets(sourcename, timeout);
00984       step->SetFileSource();
00985    }
00986 }
00987 
00988 void TGo4ScriptSlots::StepMbsFileSource(const char* stepname,
00989                                         const char* sourcename,
00990                                         int timeout,
00991                                         const char* TagFile,
00992                                         int start,
00993                                         int stop,
00994                                         int interval) {
00995    TGo4ConfigStep* step = GetStepGUI(stepname);
00996    if (step) {
00997       step->ResetSourceWidgets(sourcename, timeout);
00998       step->SetMbsFileSource(TagFile, start, stop, interval);
00999    }
01000 }
01001 
01002 void TGo4ScriptSlots::StepMbsStreamSource(const char* stepname,
01003                                           const char* sourcename,
01004                                           int timeout) {
01005    TGo4ConfigStep* step = GetStepGUI(stepname);
01006    if (step) {
01007       step->ResetSourceWidgets(sourcename, timeout);
01008       step->SetMbsStreamSource();
01009    }
01010 }
01011 
01012 void TGo4ScriptSlots::StepMbsTransportSource(const char* stepname,
01013                                              const char* sourcename,
01014                                              int timeout) {
01015    TGo4ConfigStep* step = GetStepGUI(stepname);
01016    if (step) {
01017       step->ResetSourceWidgets(sourcename, timeout);
01018       step->SetMbsTransportSource();
01019    }
01020 }
01021 
01022 void TGo4ScriptSlots::StepMbsEventServerSource(const char* stepname,
01023                                                const char* sourcename,
01024                                                int timeout) {
01025    TGo4ConfigStep* step = GetStepGUI(stepname);
01026    if (step) {
01027       step->ResetSourceWidgets(sourcename, timeout);
01028       step->SetMbsEventServerSource();
01029    }
01030 }
01031 
01032 void TGo4ScriptSlots::StepMbsRevServSource(const char* stepname,
01033                                            const char* sourcename,
01034                                            int timeout,
01035                                            int port) {
01036    TGo4ConfigStep* step = GetStepGUI(stepname);
01037    if (step) {
01038       step->ResetSourceWidgets(sourcename, timeout);
01039       step->SetMbsRevServSource(port);
01040    }
01041 }
01042 
01043 void TGo4ScriptSlots::StepRandomSource(const char* stepname,
01044                                        const char* sourcename,
01045                                        int timeout) {
01046    TGo4ConfigStep* step = GetStepGUI(stepname);
01047    if (step) {
01048       step->ResetSourceWidgets(sourcename, timeout);
01049       step->SetRandomSource();
01050    }
01051 }
01052 
01053 void TGo4ScriptSlots::StepUserSource(const char* stepname,
01054                                      const char* sourcename,
01055                                      int timeout,
01056                                      int port,
01057                                      const char* expr) {
01058    TGo4ConfigStep* step = GetStepGUI(stepname);
01059    if (step) {
01060       step->ResetSourceWidgets(sourcename, timeout);
01061       step->SetUserSource(port, expr);
01062    }
01063 }
01064 
01065 void TGo4ScriptSlots::StepFileStore(const char* stepname,
01066                                     const char* storename,
01067                                     bool overwrite,
01068                                     int bufsize,
01069                                     int splitlevel,
01070                                     int compression) {
01071    TGo4ConfigStep* step = GetStepGUI(stepname);
01072    if (step)
01073       step->SetFileStore(storename, overwrite, bufsize, splitlevel, compression);
01074 }
01075 
01076 void TGo4ScriptSlots::StepBackStore(const char* stepname,
01077                                     const char* storename,
01078                                     int bufsize,
01079                                     int splitlevel) {
01080    TGo4ConfigStep* step = GetStepGUI(stepname);
01081    if (step)
01082       step->SetBackStore(storename, bufsize, splitlevel);
01083 }
01084 
01085 void TGo4ScriptSlots::StartAnalysis() {
01086    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01087    main->StartAnalysisSlot();
01088    Wait(5.);
01089 }
01090 
01091 void TGo4ScriptSlots::StopAnalysis() {
01092    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01093    main->StopAnalysisSlot();
01094    Wait(2.);
01095 }
01096 
01097 void TGo4ScriptSlots::StartMonitor(Int_t delay_sec, Bool_t monitorall) {
01098    TGo4MonitoredListSlots* sl = dynamic_cast <TGo4MonitoredListSlots *> (fxRegistry->GetSlotClass("TGo4MonitoredListSlots"));
01099    if (sl==0) return;
01100 
01101    TGo4MonitoredList* gui = dynamic_cast<TGo4MonitoredList*> (fxRegistry->GetGUIClass(sl));
01102    if (gui==0) return;
01103 
01104    gui->SetMonitorInterval(delay_sec);
01105 
01106    if (monitorall) gui->MonitorAll();
01107               else gui->MonitorVisible();
01108 
01109    Wait(1.);
01110 }
01111 
01112 void TGo4ScriptSlots::StopMonitor() {
01113    TGo4MonitoredListSlots* sl = dynamic_cast <TGo4MonitoredListSlots *> (fxRegistry->GetSlotClass("TGo4MonitoredListSlots"));
01114    if (sl==0) return;
01115 
01116    TGo4MonitoredList* gui = dynamic_cast<TGo4MonitoredList*> (fxRegistry->GetGUIClass(sl));
01117    if (gui==0) return;
01118 
01119    gui->StopMonitoring();
01120 }
01121 
01122 
01123 void TGo4ScriptSlots::Wait(double tm_sec) {
01124    fiWaitForGUIReaction = 111;
01125    fiWaitCounter = getCounts(tm_sec);
01126    if (fiWaitCounter<0) fiWaitCounter = 1;
01127 }
01128 
01129 void* TGo4ScriptSlots::StartViewPanel(int numpads) {
01130    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01131    TGo4PreviewPanel* res = main->ViewPanelSlot(numpads);
01132    return res;
01133 }
01134 
01135 void* TGo4ScriptSlots::StartViewPanel(int numx, int numy) {
01136    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01137    TGo4PreviewPanel* res = main->ViewPanelSlot(1);
01138    if ((numx>0) && (numy>0))
01139      res->Divide(numx, numy);
01140    return res;
01141 }
01142 
01143 void TGo4ScriptSlots::SetViewPanelPosition(void* panel, int x, int y, int width, int height, int mode) {
01144    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01145    TGo4WorkSpace* space = dynamic_cast<TGo4WorkSpace*> (fxRegistry->GetCentralWindow());
01146 
01147    if ((p==0) || (space==0)) return;
01148 
01149    if (mode<0) p->close(); else
01150    if (mode==0) p->showMinimized(); else
01151    if (mode==2) p->showMaximized(); else {
01152       p->showNormal();
01153       p->parentWidget()->move(QPoint(x,y));
01154       p->parentWidget()->resize(QSize(width, height));
01155       p->parentWidget()->show();
01156       p->GetQCanvas()->SetNeedsMinmaxResize(true);
01157       p->show();
01158 
01159 /*
01160       cout << " Space = " << space << "  " << space->name() << endl;
01161       cout << " parent = " << p->parentWidget() << "  " << p->parentWidget()->name() << endl;
01162       cout << " 2 parent = " << p->parentWidget()->parentWidget() << "  " << p->parentWidget()->parentWidget()->name() << endl;
01163 */
01164    }
01165 }
01166 
01167 void TGo4ScriptSlots::SetViewPanelMode(void* panel, int mode) {
01168    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01169    if (p==0) return;
01170    if (mode<0) p->close(); else
01171    if (mode==0) p->showMinimized(); else
01172    if (mode==2) p->showMaximized(); else
01173                 p->showNormal();
01174 }
01175 
01176 void TGo4ScriptSlots::SetPadOptions(void* panel, 
01177                                     int npad, 
01178                                     const char* options,
01179                                     int logscale,     // 000 - all linear, 100 - only x log, 111 - all three logarithm
01180                                     int padstatus)    // xxxx, where x is 0 or 1, 1-stats, 2-title, 3-legend, 4-crosshair
01181 {
01182    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01183    TPad* pad = FindPad(p, npad);
01184    TGo4PreviewPanelStatus* status = p->GetStatus();
01185 
01186    if ((pad==0) || (status==0)) return;
01187 
01188    pad->cd();
01189    gROOT->SetSelectedPad(pad);
01190    status->SetPadDrawOption(pad, options);
01191    
01192    TGo4PadOptions* padopt = status->GetPadOptions(pad);
01193    if (padopt!=0) {
01194       int logx = logscale / 100;
01195       int logy = (logscale % 100) / 10;
01196       int logz = logscale % 10;
01197       
01198       padopt->SetHisXStyle(logx);
01199       padopt->SetHisYStyle(logy);
01200       padopt->SetHisZStyle(logz);
01201       pad->SetLogx(logx);
01202       pad->SetLogy(logy);
01203       pad->SetLogz(logz);
01204        
01205       padopt->SetHisStats(padstatus / 10000 > 0);
01206       padopt->SetHisTitle((padstatus % 10000) / 1000 > 0);
01207       padopt->SetLegendDraw((padstatus % 1000) / 100 > 0);
01208       padopt->SetCrosshair((padstatus % 100) / 10 > 0);
01209       padopt->SetAutoScale(padstatus % 10 > 0);
01210    }
01211 
01212 //   p->SetActivePad(pad);
01213 
01214 //   p->Redraw();
01215 
01216    p->RedrawPad(pad);
01217 }
01218 
01219 void TGo4ScriptSlots::SetPadRange(void* panel, int npad,
01220                                   Double_t minx, Double_t maxx,
01221                                   Double_t miny, Double_t maxy,
01222                                   Double_t minz, Double_t maxz) {
01223    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01224    TPad* pad = FindPad(p, npad);
01225    if (pad==0) return;
01226    p->SetPadScaleRange(pad, minx, maxx, miny, maxy, minz, maxz, false);
01227 }
01228 
01229 
01230 void TGo4ScriptSlots::CreateSubPad(void* panel, int npad,
01231                                    Double_t xlow, Double_t ylow,
01232                                    Double_t xup, Double_t yup) {
01233    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01234    if (p==0) return;
01235 
01236    TObjArray arr;
01237 
01238    ExploreAllPads(p->GetCanvas(), &arr);
01239    if ((npad>arr.GetLast()) || (npad<0)) npad = 0;
01240 
01241    TPad* mother = (TPad*) arr.At(npad);
01242 
01243    TPad* old = (TPad*) gPad;
01244 
01245    mother->cd();
01246 
01247    TString name("Pad_");
01248    name += (arr.GetLast()+1);
01249 
01250    TPad* subpad = new TPad(name, "Subpad", xlow, ylow, xup, yup);
01251    p->InitPad(subpad);
01252    subpad->SetNumber(arr.GetLast()+1);
01253 
01254    subpad->Draw();
01255 
01256    TGo4PreviewPanelStatus* status = p->GetStatus();
01257    status->SetNoOfPads(status->GetNoOfPads()+1);
01258 
01259    gPad = old;
01260 }
01261 
01262 
01263 void* TGo4ScriptSlots::ViewPanelPad(void* panel) {
01264    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01265    if (p==0) return 0;
01266    return p->GetCanvas();
01267 
01268 }
01269 
01270 void TGo4ScriptSlots::SetActivePad(void* panel, int npad) {
01271    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01272    TPad* pad = FindPad(p, npad);
01273    if (p && pad) {
01274      pad->cd();
01275      p->SetActivePad(pad);
01276      p->Redraw();
01277      p->setFocus();
01278 
01279      TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01280      main->ActivePadChanged(p, pad);
01281 
01282      // calculate middle of pad in canvas coordinate
01283      double ndcx = pad->GetXlowNDC() + pad->GetWNDC() / 2.;
01284      double ndcy = pad->GetYlowNDC() + pad->GetHNDC() / 2.;
01285 
01286      while ((pad->GetMother()!=0) && (pad->GetMother()!=p->GetCanvas())) {
01287         TPad* mother = (TPad*) pad->GetMother();
01288         ndcx = mother->GetXlowNDC() + ndcx * mother->GetWNDC();
01289         ndcy = mother->GetYlowNDC() + ndcy * mother->GetHNDC();
01290         pad = mother;
01291      }
01292 
01293      p->GetCanvas()->HandleInput(kButton2Down, p->GetCanvas()->XtoPixel(ndcx), p->GetCanvas()->YtoPixel(ndcy));
01294      
01295    }
01296    
01297 }
01298 
01299 
01300 void TGo4ScriptSlots::GetObject(const char* objname, void* panel, int npad) {
01301    TGo4ComGetObject* com = new TGo4ComGetObject(objname);
01302    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01303    TPad* pad = FindPad(p, npad);
01304 
01305    fxRegistry->SubmitCommand(com, objname, 0, kFALSE, p ? p->GetQCanvas() : 0, pad);
01306 }
01307 
01308 void TGo4ScriptSlots::GetCondition(const char* condname, void* panel, int npad) {
01309    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01310    TPad* pad = FindPad(p, npad);
01311    if ((p==0) || (pad==0)) return;
01312 
01313    TGo4ComGetObject* com = new TGo4ComGetObject(condname);
01314    fxRegistry->SubmitCommand(com, condname, p->GetSlots(), kFALSE, p->GetQCanvas(), pad);
01315 }
01316 
01317 
01318 void TGo4ScriptSlots::MonitorObject(const char* objname) {
01319    TGo4RemoteBrowserSlots* sl = dynamic_cast <TGo4RemoteBrowserSlots *> (fxRegistry->GetSlotClass("TGo4RemoteBrowserSlots"));
01320 
01321    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01322    TGo4DockBrowsers* dock = main->DockBrowsers();
01323    TGo4QItem* item = dock ? dock->FindItem(3, objname) : 0;
01324 
01325    if (sl && item)
01326      sl->MonitorRemoteObj(item);
01327 }
01328 
01329 void TGo4ScriptSlots::WaitObject(const char* objname, double tm_sec) {
01330    if (objname!=0) {
01331       fiWaitForGUIReaction = 20;
01332       fiWaitCounter = getCounts(tm_sec);
01333       fStrBuf = objname;
01334    }
01335 }
01336 
01337 void TGo4ScriptSlots::WaitMonitor(const char* objname, double tm_sec) {
01338    if (objname!=0) {
01339       fiWaitForGUIReaction = 21;
01340       fiWaitCounter = getCounts(tm_sec);
01341       fStrBuf = objname;
01342    }
01343 }
01344 
01345 void TGo4ScriptSlots::OpenFile(const char* filename) {
01346      TGo4DiskFileBrowserSlots* sl =
01347         dynamic_cast<TGo4DiskFileBrowserSlots*>
01348           (fxRegistry->GetSlotClass("TGo4DiskFileBrowserSlots"));
01349     if (sl) {
01350       QString name(filename), dir;
01351       sl->OpenSelectedRootFile(name, dir);
01352     }
01353 }
01354 
01355 void TGo4ScriptSlots::CloseFile(const char* filename) {
01356 
01357 }
01358 
01359 
01360 void TGo4ScriptSlots::DisplayFileObject(const char* objname, void* panel, int npad, bool update) {
01361    DisplayObj(0, objname, panel, npad, update);
01362 }
01363 
01364 void TGo4ScriptSlots::DisplayObject(const char* objname, void* panel, int npad, bool update) {
01365    DisplayObj(1, objname, panel, npad, update);
01366 }
01367 
01368 void TGo4ScriptSlots::DisplayMonitorObject(const char* objname, void* panel, int npad, bool update) {
01369    DisplayObj(2, objname, panel, npad, update);
01370 }
01371 
01372 void TGo4ScriptSlots::DisplayObj(int numtab, const char* objname, void* panel, int npad, bool update) {
01373    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01374    TGo4DockBrowsers* dock = main->DockBrowsers();
01375    TGo4QItem* item = dock ? dock->FindItem(numtab, objname) : 0;
01376 
01377    if (item) {
01378       TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01379       if (p==0) p = main->ViewPanelSlot(1);
01380       TPad* pad = FindPad(p, npad);
01381 
01382       if (pad!=0) {
01383         item->DrawObj(p, pad);
01384         if (update) {
01385           pad->Modified();
01386           pad->Update();
01387         }
01388       }
01389    }
01390 }
01391 
01392 void TGo4ScriptSlots::SwitchSuperImpose(void* panel, int npad, Bool_t superimpose) {
01393    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01394    TPad* pad = FindPad(p, npad);
01395    if (pad==0) return;
01396 
01397    p->SetActivePad(pad);
01398    p->ChangeSuperImpose(superimpose);
01399 }
01400 
01401 void TGo4ScriptSlots::SuperImpose(void* panel, int npad,
01402                                   const char* objname0,
01403                                   const char* objname1,
01404                                   const char* objname2,
01405                                   const char* objname3,
01406                                   const char* objname4,
01407                                   const char* objname5,
01408                                   const char* objname6,
01409                                   const char* objname7,
01410                                   const char* objname8,
01411                                   const char* objname9) {
01412    const char* names[10];
01413    names[0] = objname0;
01414    names[1] = objname1;
01415    names[2] = objname2;
01416    names[3] = objname3;
01417    names[4] = objname4;
01418    names[5] = objname5;
01419    names[6] = objname6;
01420    names[7] = objname7;
01421    names[8] = objname8;
01422    names[9] = objname9;
01423    SuperImpose(10, names, panel, npad);
01424 }
01425 
01426 void TGo4ScriptSlots::SuperImpose(int num, const char** names,
01427                                   void* panel, int npad) {
01428    TGo4MainWindow* main = (TGo4MainWindow*) fxRegistry->GetMainWindow();
01429    TGo4DockBrowsers* dock = main->DockBrowsers();
01430 
01431    TGo4PreviewPanel* p = (TGo4PreviewPanel*) panel;
01432    if (p==0) p = main->ViewPanelSlot(1);
01433    TPad* pad = FindPad(p, npad);
01434    if (pad==0) return;
01435 
01436    p->SetActivePad(pad);
01437    p->ChangeSuperImpose(true);
01438 
01439    for (int n=0;n<num;n++) {
01440      TGo4QItem* item = dock->FindItem(1, names[n]);
01441      if (item) item->DrawObj(p, pad);
01442    }
01443 
01444    pad->Modified();
01445    pad->Update();
01446 }
01447 
01448 
01449 
01450 ClassImp(TGo4ScriptSlots);
01451 
01452 
01453 
01454 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Tue Nov 8 10:56:03 2005 for Go4-v2.10-5 by doxygen1.2.15