Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

TGo4MainWindow.cpp

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE 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 "TGo4MainWindow.h"
00017 
00018 #include <dlfcn.h>
00019 #include "Riostream.h"
00020 
00021 #include "qdockarea.h"
00022 #include "qcolor.h"
00023 #include "qcolordialog.h"
00024 #include "qnamespace.h"
00025 #include "qstring.h"
00026 #include "qvaluevector.h"
00027 #include "qtabwidget.h"
00028 #include "qvariant.h"
00029 #include "qmime.h"
00030 #include "qdragobject.h"
00031 #include "qlayout.h"
00032 #include "qtooltip.h"
00033 #include "qwhatsthis.h"
00034 #include "qaction.h"
00035 #include "qmenubar.h"
00036 #include "qpopupmenu.h"
00037 #include "qtoolbar.h"
00038 #include "qimage.h"
00039 #include "qpixmap.h"
00040 #include "qtextbrowser.h"
00041 #include "qfontdialog.h"
00042 #include "TGo4QSettings.h"
00043 #include "qapplication.h"
00044 #include "qclipboard.h"
00045 #include "qstatusbar.h"
00046 #include "qtoolbutton.h"
00047 #include "qsignalmapper.h"
00048 #include "qstylefactory.h"
00049 #include "qfiledialog.h"
00050 #include "qlayout.h"
00051 #include "qmessagebox.h"
00052 #include "qradiobutton.h"
00053 #include "qcombobox.h"
00054 #include "helpwindow.h"
00055 #include "qinputdialog.h"
00056 #include "qdir.h"
00057 #include "qfileinfo.h"
00058 #include "qevent.h"
00059 #include "qprocess.h"
00060 #include "qtimer.h"
00061 #include "qspinbox.h"
00062 #include "qstyle.h"
00063 
00065 #include "TSystem.h"
00066 #include "TROOT.h"
00067 #include "TMath.h"
00068 #include "TStyle.h"
00069 #include "TH1.h"
00070 #include "TTree.h"
00071 #include "TColor.h"
00072 #include "TCanvas.h"
00073 #include "TList.h"
00074 
00076 #include "qrootapplication.h"
00077 #include "TGo4Version.h"
00078 #include "TGo4Log.h"
00079 #include "TGo4LockGuard.h"
00080 #include "TGo4Parameter.h"
00081 #include "TGo4Condition.h"
00082 #include "TGo4Marker.h"
00083 #include "TGo4WorkSpace.h"
00084 #include "TGo4Fitter.h"
00085 #include "TGo4FitPanel.h"
00086 #include "TGo4DynamicEntry.h"
00087 #include "TGo4AnalysisStatus.h"
00088 
00089 #include "TGo4ObjectManager.h"
00090 #include "TGo4ObjectProxy.h"
00091 #include "TGo4BrowserProxy.h"
00092 #include "TGo4AnalysisProxy.h"
00093 #include "TGo4WidgetProxy.h"
00094 
00096 #include "QGo4Widget.h"
00097 #include "TGo4TreeViewer.h"
00098 #include "TGo4Browser.h"
00099 #include "TGo4BrowserOptions.h"
00100 #include "TGo4Style.h"
00101 #include "TGo4ViewPanel.h"
00102 #include "TGo4AnalysisConfiguration.h"
00103 #include "TGo4AnalysisWindow.h"
00104 #include "TGo4StartClient.h"
00105 #include "TGo4HisDrawOptions.h"
00106 #include "TGo4HisDrawOptionsShort.h"
00107 #include "TGo4ScaleOptions.h"
00108 #include "TGo4DividePad.h"
00109 #include "TGo4CreateNewHistogram.h"
00110 #include "TGo4CreateNewCondition.h"
00111 #include "TGo4CreateNewDynEntry.h"
00112 #include "TGo4ConditionInfo.h"
00113 #include "TGo4HistogramInfo.h"
00114 #include "TGo4EventInfo.h"
00115 #include "TGo4LoadedLibraries.h"
00116 #include "TGo4EditDynEntry.h"
00117 #include "TGo4ParaEdit.h"
00118 #include "TGo4AnalysisStatusMonitor.h"
00119 #include "TGo4ConditionEditor.h"
00120 #include "TGo4LogSettings.h"
00121 #include "TGo4LogInfo.h"
00122 #include "TGo4OpenRemoteDialog.h"
00123 #include "TGo4ConnectServer.h"
00124 #include "TGo4HServerConnection.h"
00125 #include "TGo4MBSViewer.h"
00126 
00127 #ifdef __GO4DIM__
00128 #include "TGo4DabcMonitor.h"
00129 #endif
00130 
00131 #include "TGo4SetScaleValues.h"
00132 #include "TGo4CommandLine.h"
00133 #include "TGo4MarkerSettings.h"
00134 #include "TGo4OptStatsSettings.h"
00135 
00136 #include "TGo4Script.h"
00137 
00138 enum { fiFetchWhenDrawId = 111,
00139        fiFetchWhenCopyId = 112,
00140        fiFetchWhenSaveId = 113,
00141        fiCrosshairId = 123,
00142        fiEventstatusId = 124,
00143        fiCloneId = 125,
00144        fiDrawTimeId = 126,
00145        fiDrawDateId = 127,
00146        fiDrawItemId = 128,
00147        fiLaunchAnal = 201,
00148        fiConnectAnal = 202,
00149        fiPrepareAnal = 203,
00150        fiDisconnectAnal = 204,
00151        fiShutdownAnal = 205,
00152        fiSumbStartAnal = 206,
00153        fiStartAnal = 207,
00154        fiStopAnal = 208,
00155        fiAnalConfig = 209,
00156        fiAnalTermin = 210 };
00157 
00158 TGo4MainWindow::TGo4MainWindow(QApplication* app, bool server) :
00159    QMainWindow(0, "MainWindow"),
00160    fApp(app),
00161    fbServerMode(server)
00162 {
00163    setDockWindowsMovable(TRUE);
00164    statusBar();
00165    resize( 1152, 864 );
00166 
00167    setIcon(QPixmap::fromMimeSource("go4logo2_big.png"));
00168    setRightJustification( TRUE );
00169    setUsesTextLabel(TRUE);
00170    setOpaqueMoving(FALSE);
00171 
00172    fxOM = new TGo4ObjectManager("GUI_OM","Gui object manager");
00173    fOMDataPath    = "data";
00174    fOMBrowserPath = "gui";
00175    fOMEditorsPath = "editors";
00176 
00177    fKillCommand = "";
00178    fLastPassword = "";
00179    fLastFileDir = QDir::currentDirPath();
00180 
00181    fCloseCounter = 0;
00182    fConnectingCounter = 0;
00183 
00184    fbPanelTimerActive = false;
00185 
00186     // create mount point for all data sources
00187    fxOM->MakeFolder(fOMDataPath.latin1());
00188 
00189    // create entry for browser
00190    TGo4BrowserProxy* br = new TGo4BrowserProxy(fOMDataPath.latin1(), fOMEditorsPath.latin1(), kFALSE);
00191    fxOM->AddProxy("", br, fOMBrowserPath.latin1(), "Place for gui slots");
00192    br->CreateMemoryFolder();
00193 
00194    TH1I* h1 = new TH1I("histo1","histo title", 100, -10., 10.);
00195    h1->FillRandom("gaus",10000);
00196    h1->SetDirectory(0);
00197    br->SaveToMemory("", h1, kTRUE);
00198 
00199    // br->OpenFile("asf.root");
00200 
00201 
00202    new TGo4Script(this);
00203 
00204 
00205    gStyle->SetPalette(1);
00206    //gStyle->SetOptStat(11111111);
00207    gStyle->SetOptStat(go4sett->getOptStat());
00208 
00209    fxTGo4WorkSpace = new TGo4WorkSpace(this);
00210    fxTGo4WorkSpace->setScrollBarsEnabled(TRUE);
00211    setCentralWidget(fxTGo4WorkSpace);
00212    fxTGo4WorkSpace->setFocus();
00213 
00214    AddFileMenu();
00215    AddFileToolBar();
00216 
00217    AddToolsMenu();
00218    AddToolsBar();
00219 
00220    AddAnalysisMenu();
00221    AddAnalysisBar();
00222 
00223    AddSettingMenu();
00224 
00225    UpdateCaptionButtons();
00226 
00227    windowsMenu = new QPopupMenu( this );
00228    connect( windowsMenu, SIGNAL( aboutToShow() ), this, SLOT( windowsMenuAboutToShow() ) );
00229    menuBar()->insertItem( "&Windows", windowsMenu );
00230 
00231    statusBar()->message("Ready");
00232    statusBar()->setSizeGripEnabled(TRUE);
00233 
00234    QDockWindow* BrowserDockWin = new QDockWindow();
00235    BrowserDockWin->setResizeEnabled(TRUE);
00236    BrowserDockWin->setCaption("Browser");
00237    setAppropriate(BrowserDockWin, true);
00238    TGo4Browser* browser = new TGo4Browser(BrowserDockWin,"Browser");
00239    ConnectGo4Widget(browser);
00240    browser->StartWorking();
00241    BrowserDockWin->setWidget(browser);
00242    addDockWindow(BrowserDockWin, Qt::DockRight);
00243    BrowserDockWin->show();
00244 
00245    QDockWindow* MBSDockWin = new QDockWindow();
00246    MBSDockWin->setResizeEnabled(TRUE);
00247    MBSDockWin->setCaption("MBS monitor");
00248    setAppropriate(MBSDockWin, true);
00249    TGo4MBSViewer* mbs = new TGo4MBSViewer(MBSDockWin, "MBSViewer");
00250    ConnectGo4Widget(mbs);
00251    MBSDockWin->setWidget(mbs);
00252    addDockWindow(MBSDockWin, Qt::DockBottom);
00253    MBSDockWin->show();
00254 #ifdef __GO4DIM__   
00255    QDockWindow* DABCDockWin = new QDockWindow();
00256    DABCDockWin->setResizeEnabled(TRUE);
00257    DABCDockWin->setCaption("DABC monitor");
00258    setAppropriate(DABCDockWin, true);
00259    TGo4DabcMonitor* dabc = new TGo4DabcMonitor(DABCDockWin, "DABCMonitor");
00260    ConnectGo4Widget(dabc);
00261    DABCDockWin->setWidget(dabc);
00262    addDockWindow(DABCDockWin, Qt::DockBottom);
00263    DABCDockWin->show();
00264 #endif    
00265 
00266    QToolBar* DividePanelBar = new QToolBar (this, "Canvas Tools");
00267    addDockWindow(DividePanelBar, "Canvas Tools", Qt::DockTop, TRUE );
00268    setAppropriate (DividePanelBar, true);
00269    DividePanelBar->setHorizontallyStretchable(FALSE);
00270    TGo4DividePad* dividepanel = new TGo4DividePad(DividePanelBar, "DividePad");
00271    dividepanel->polish();
00272    dividepanel->show();
00273 
00274    QToolBar* stylebar = new QToolBar(this, "Color Tools");
00275    addDockWindow(stylebar, "Color Tools", Qt::DockTop, TRUE );
00276    setAppropriate (stylebar, true);
00277    TGo4Style* style = new TGo4Style(stylebar, "StyleToolBar");
00278    style->polish();
00279    style->show();
00280 
00281    QToolBar* BrowserOptionsPanel = new QToolBar(this,"Browser Options Panel");
00282    addDockWindow(BrowserOptionsPanel, "Browser Options", Qt::DockTop, TRUE);
00283    TGo4BrowserOptions* bropt = new TGo4BrowserOptions(BrowserOptionsPanel,"BrowserOptions");
00284    ConnectGo4Widget(bropt);
00285    bropt->StartWorking();
00286    bropt->polish();
00287    bropt->show();
00288 
00289    QToolBar* DrawOptionPanel = new QToolBar(this,"Histogram Draw Options");
00290    addDockWindow(DrawOptionPanel, "Draw Options", Qt::DockTop, TRUE);
00291    TGo4HisDrawOptions* drawopt = new TGo4HisDrawOptions(DrawOptionPanel,"HisDrawOptions");
00292    drawopt->polish();
00293    drawopt->show();
00294 
00295    QToolBar* DrawOptionShortPanel = new QToolBar(this,"Histogram Short Draw Options");
00296    addDockWindow(DrawOptionShortPanel, "Draw Options Short", Qt::DockTop, TRUE);
00297    TGo4HisDrawOptionsShort* drawopts = new TGo4HisDrawOptionsShort(DrawOptionShortPanel,"HisDrawOptionsShort");
00298    drawopts->polish();
00299    drawopts->show();
00300 
00301    QToolBar* ScaleOptionBar = new QToolBar(this, "Zoom Tools");
00302    addDockWindow(ScaleOptionBar, "Zoom Tools", Qt::DockTop, TRUE );
00303    TGo4ScaleOptions* scopt = new TGo4ScaleOptions(ScaleOptionBar,"ScaleOptions");
00304    ConnectGo4Widget(scopt);
00305    scopt->polish();
00306    scopt->show();
00307    setAppropriate(ScaleOptionBar, TRUE);
00308 
00309    QDockWindow* commandlinebar = new QDockWindow();
00310    commandlinebar->setResizeEnabled(TRUE);
00311    commandlinebar->setCaption("Go4 Command Line");
00312    setAppropriate (commandlinebar, true);
00313    TGo4CommandLine* cli = new TGo4CommandLine(commandlinebar, "CommandlineToolBar");
00314    cli->setMainWindow(this);
00315    ConnectGo4Widget(cli);
00316    commandlinebar->setWidget(cli);
00317    cli->polish();
00318    cli->show();
00319    addDockWindow(commandlinebar, Qt::DockBottom);
00320    commandlinebar->show();
00321 
00322 
00323    QDockWindow* tviewerdock = new QDockWindow();
00324    tviewerdock->setResizeEnabled(TRUE);
00325    tviewerdock->setCaption("Tree viewer");
00326    setAppropriate(tviewerdock, true);
00327    TGo4TreeViewer* tviewer = new TGo4TreeViewer(tviewerdock, "TreeViewer");
00328    ConnectGo4Widget(tviewer);
00329    tviewerdock->setWidget(tviewer);
00330    addDockWindow(tviewerdock, Qt::DockBottom);
00331    tviewerdock->show();
00332 
00333    QDockWindow* lidock = new QDockWindow();
00334    lidock->setResizeEnabled( TRUE );
00335    lidock->setCaption("Log Window");
00336    setAppropriate(lidock, true);
00337    TGo4LogInfo* loginfo = new TGo4LogInfo(lidock, "LogInfo");
00338    ConnectGo4Widget(loginfo);
00339    lidock->setWidget(loginfo);
00340    addDockWindow(lidock, Qt::DockBottom);
00341    lidock->show();
00342 
00343    menuBar()->insertSeparator();
00344    QPopupMenu *HelpMenu = new QPopupMenu(this);
00345    menuBar()->insertItem( "&Help",HelpMenu);
00346    HelpMenu->insertItem("&Introduction (user manual)", this, SLOT(IntroHelpSlot()));
00347    HelpMenu->insertItem("&Reference manual", this, SLOT(RefHelpSlot()));
00348    HelpMenu->insertItem("&Fit Tutorial", this, SLOT(FitHelpSlot()));
00349    HelpMenu->insertItem("&GUI commandline (reference)", this, SLOT(InterfaceHelpSlot()));
00350    HelpMenu->insertSeparator();
00351 
00352    HelpMenu->insertItem( "About &Qt", this, SLOT(aboutQt()), Key_F2 );
00353    HelpMenu->insertItem( "About R&OOT", this, SLOT(aboutROOT()),Key_F3);
00354    HelpMenu->insertItem( "About &Go4", this, SLOT(about()), Key_F4);
00355 
00356    QStringList LibList = QStringList::split(":", getenv("GO4USERLIBRARY"));
00357 
00358    for (QStringList::Iterator it=LibList.begin(); it!=LibList.end(); ++it)
00359        gSystem->Load((*it).latin1());
00360 
00361    go4sett->RestoreSettings(this);
00362 
00363    go4sett->restoreGeometry(this);
00364 
00365    MakeStyleSlot(go4sett->getAppStyle());
00366 
00367    menuBar()->setItemChecked(fiCrosshairId, go4sett->getPadCrosshair());
00368    menuBar()->setItemChecked(fiEventstatusId, go4sett->getPadEventStatus());
00369 
00370    go4sett->getBasicSettings();
00371 
00372    // start mbs monitoring only after browser etc. is fully there:
00373    if(go4sett->getMbsMonitorMonitorActive()) mbs->TimerStart();
00374 
00375    go4sett->DumpSettingsLocation();
00376 }
00377 
00378 TGo4MainWindow::~TGo4MainWindow()
00379 {
00380     TGo4Script::DeleteInstance();
00381 
00382     delete fxOM;
00383 }
00384 
00385 const char* TGo4MainWindow::LastTypedPassword() const
00386 {
00387    return fLastPassword.latin1();
00388 }
00389 
00390 
00391 void TGo4MainWindow::about()
00392 {
00393    QString GO4STR("Go4  ");
00394    GO4STR.append ( __GO4RELEASE__);
00395    QString GO4STR1 = GO4STR;
00396    GO4STR1.append("\n");
00397    GO4STR1.append("The Go4 (GSI Object Oriented On-line Off-line system)  is based on ROOT\n with the specific requirements of the low and medium energy nuclear and atomic\n physics experiments implemented as extensions.\n See  http://go4.gsi.de  for more information") ;
00398 
00399    QMessageBox AboutGo4(GO4STR, GO4STR1, QMessageBox::NoIcon,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton ,this);
00400    AboutGo4.setIconPixmap(QPixmap::fromMimeSource( "go4logo2_big.png"));
00401    AboutGo4.exec();
00402 }
00403 
00404 void TGo4MainWindow::aboutQt()
00405 {
00406    QMessageBox::aboutQt(this, "Qt");
00407 }
00408 
00409 void TGo4MainWindow::aboutROOT()
00410 {
00411    QString mestring("This Go4 uses ROOT Version ");
00412    mestring.append(gROOT->GetVersion());
00413    mestring.append("\n ROOT is an object-oriented framework for large\n scale scientific data analysis and data mining.\n It has been developed at CERN\n See http://root.cern.ch for more information");
00414    QMessageBox AboutRoot("ROOT", mestring,
00415                          QMessageBox::NoIcon,QMessageBox::Ok,QMessageBox::NoButton,QMessageBox::NoButton ,this);
00416    AboutRoot.setIconPixmap(QPixmap::fromMimeSource( "root.png"));
00417    AboutRoot.exec();
00418 }
00419 
00420 void TGo4MainWindow::AddSettingMenu()
00421 {
00422    QPopupMenu* SettingMenu = new QPopupMenu( this );
00423    menuBar()->insertItem( "&Settings",SettingMenu);
00424 
00425    SettingMenu->insertItem("Sh&ow/hide", createDockWindowMenu());
00426 
00427    SettingMenu->insertItem("&Fonts...",this, SLOT(ChangeFontSlot()));
00428    QPopupMenu *style = new QPopupMenu( this );
00429    style->setCheckable( TRUE );
00430    SettingMenu->insertItem("St&yle", style);
00431 //   menuBar()->insertItem( "St&yle",style);
00432 
00433 
00434    QPopupMenu* PrefMenu = new QPopupMenu( this );
00435    SettingMenu->insertItem( "&Preferences", PrefMenu);
00436 
00437    PrefMenu->insertItem("Fetch when drawing", this, SLOT(ChangeFetchWhenDrawSlot()), 0, fiFetchWhenDrawId);
00438    PrefMenu->setItemChecked(fiFetchWhenDrawId, go4sett->getFetchDataWhenDraw());
00439    PrefMenu->insertItem("Fetch when copying", this, SLOT(ChangeFetchWhenCopySlot()), 0, fiFetchWhenCopyId);
00440    PrefMenu->setItemChecked(fiFetchWhenCopyId, go4sett->getFetchDataWhenCopy());
00441    PrefMenu->insertItem("Fetch when saving", this, SLOT(ChangeFetchWhenSaveSlot()), 0, fiFetchWhenSaveId);
00442    PrefMenu->setItemChecked(fiFetchWhenSaveId, go4sett->getFetchDataWhenSave());
00443 
00444    QPopupMenu* PanelMenu = new QPopupMenu( this );
00445    SettingMenu->insertItem( "&Panel defaults", PanelMenu);
00446 
00447    PanelMenu->insertItem("&Canvas color...",this, SLOT(CanvasColorSlot()));
00448    PanelMenu->insertItem("Marker labels...", this, SLOT(MarkerSettingsSlot()));
00449    PanelMenu->insertItem("Statistics box...", this, SLOT(OptStatsSlot()));
00450    PanelMenu->insertItem("Cross(&X)hair mode", this, SLOT(CrosshairSlot()), 0, fiCrosshairId);
00451    PanelMenu->setItemChecked(fiCrosshairId, go4sett->getPadCrosshair());
00452    PanelMenu->insertItem("Show Event Status", this, SLOT(EventStatusSlot()), 0, fiEventstatusId);
00453    PanelMenu->setItemChecked(fiEventstatusId, go4sett->getPadEventStatus());
00454 
00455    PanelMenu->insertItem("Objects cloning", this, SLOT(ChangeCloneFlagSlot()), 0, fiCloneId);
00456    PanelMenu->setItemChecked(fiCloneId, go4sett->getCloneFlag());
00457    PanelMenu->insertItem("Draw time", this, SLOT(ChangeDrawTimeFlagSlot()), 0, fiDrawTimeId);
00458    PanelMenu->setItemChecked(fiDrawTimeId, go4sett->getDrawTimeFlag());
00459    PanelMenu->setItemEnabled(fiDrawTimeId, go4sett->getCloneFlag());
00460    PanelMenu->insertItem("Draw date", this, SLOT(ChangeDrawDateFlagSlot()), 0, fiDrawDateId);
00461    PanelMenu->setItemChecked(fiDrawDateId, go4sett->getDrawDateFlag());
00462    PanelMenu->setItemEnabled(fiDrawDateId, go4sett->getCloneFlag());
00463    PanelMenu->insertItem("Draw item name", this, SLOT(ChangeDrawItemFlagSlot()), 0, fiDrawItemId);
00464    PanelMenu->setItemChecked(fiDrawItemId, go4sett->getDrawItemFlag());
00465    PanelMenu->setItemEnabled(fiDrawItemId, go4sett->getCloneFlag());
00466 
00467    SettingMenu->insertItem("&Log actions...",this, SLOT(LogSettingsSlot()));
00468 
00469    SettingMenu->insertItem("Generate &hotstart", this, SLOT(CreateGUIScriptSlot()));
00470    SettingMenu->insertItem("&Break hotstart execution", this, SLOT(StopGUIScriptSlot()));
00471 
00472    SettingMenu->insertItem("&Terminal history", this, SLOT(InputTerminalParametersSlot()));
00473 
00474    SettingMenu->insertItem("&Save Settings", this, SLOT(SaveSettingsSlot()));
00475 
00476    QActionGroup *ag = new QActionGroup( this, 0 );
00477    ag->setExclusive( TRUE );
00478    QSignalMapper *styleMapper = new QSignalMapper( this );
00479    connect( styleMapper, SIGNAL( mapped( const QString& ) ), this, SLOT( MakeStyleSlot(const QString& ) ) );
00480    QStringList list = QStyleFactory::keys();
00481    list.sort();
00482    QDict<int> stylesDict( 117, FALSE );
00483    for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
00484       QString styleStr = *it;
00485       QString styleAccel = styleStr;
00486       if ( stylesDict[styleAccel.left(1)] ) {
00487          for ( uint i = 0; i < styleAccel.length(); i++ ) {
00488             if ( !stylesDict[styleAccel.mid( i, 1 )] ) {
00489                stylesDict.insert(styleAccel.mid( i, 1 ), (const int *)1);
00490                styleAccel = styleAccel.insert( i, '&' );
00491                break;
00492              }
00493           }
00494        } else {
00495           stylesDict.insert(styleAccel.left(1), (const int *)1);
00496           styleAccel = "&"+styleAccel;
00497        }
00498        QAction *a = new QAction( styleStr, QIconSet(), styleAccel, 0, ag, 0, ag->isExclusive() );
00499        connect( a, SIGNAL( activated() ), styleMapper, SLOT(map()) );
00500        styleMapper->setMapping( a, a->text() );
00501    }
00502    ag->addTo(style);
00503    QApplication::setColorSpec( QApplication::ManyColor );
00504 }
00505 
00506 void TGo4MainWindow::AddFileMenu()
00507 {
00508     QPopupMenu *FileMenu = new QPopupMenu( this );
00509      menuBar()->insertItem( "&File",FileMenu);
00510 
00511      FileMenu->insertItem(QPixmap::fromMimeSource( "open.png" ), "&Open...",
00512              this, SLOT(OpenFileSlot()), CTRL+Key_O );
00513      FileMenu->insertItem(QPixmap::fromMimeSource( "network.png" ), "Open &Remote...",
00514              this, SLOT(OpenRemoteFileSlot()), CTRL+Key_R );
00515      FileMenu->insertItem(QPixmap::fromMimeSource( "histserv.png" ), "Open &HServer...",
00516              this, SLOT(ConnectHServerSlot()), CTRL+Key_H );
00517      FileMenu->insertItem(QPixmap::fromMimeSource( "filesave.png" ), "Save memor&y...",
00518              this, SLOT(SaveFileSlot()), CTRL+Key_Y );
00519      FileMenu->insertItem(QPixmap::fromMimeSource( "close.png" ),"Close all files",
00520              this, SLOT(CloseAllFilesSlot()), CTRL+Key_Q);
00521      FileMenu->insertItem(QPixmap::fromMimeSource( "exit.png" ), "E&xit",
00522              this, SLOT(close()), CTRL+Key_X );
00523 }
00524 
00525 void TGo4MainWindow::AddFileToolBar()
00526 {
00527    QToolBar *FileBar = new QToolBar( this, "File Toolbar" );
00528    addDockWindow(FileBar, "File Toolbar", Qt::DockTop, TRUE );
00529    FileBar->setNewLine ( FALSE );
00530 
00531    QToolButton *FileOpenB  = new QToolButton( QPixmap::fromMimeSource( "open.png" ), QString::null, QString::null,
00532                     this, SLOT(OpenFileSlot()), FileBar, "Open Local File" );
00533    FileOpenB->setUsesTextLabel(FALSE);
00534    QToolTip::add(FileOpenB, "Open a local file from disk");
00535 
00536    QToolButton *FileRemoteOpenB = new QToolButton( QPixmap::fromMimeSource( "network.png" ), QString::null, QString::null,
00537                     this, SLOT(OpenRemoteFileSlot()), FileBar, "Open Remote File" );
00538    FileRemoteOpenB->setUsesTextLabel(FALSE);
00539    QToolTip::add(FileRemoteOpenB, "Open a remote file from server");
00540 
00541    QToolButton *HServB = new QToolButton( QPixmap::fromMimeSource( "histserv.png" ), QString::null, QString::null,
00542                     this, SLOT(ConnectHServerSlot()), FileBar, "Open Remote Histogram Server" );
00543    HServB->setUsesTextLabel(FALSE);
00544    QToolTip::add(HServB, "Connect to running HServer");
00545 
00546    QToolButton *FileSaveB  = new QToolButton( QPixmap::fromMimeSource( "filesave.png" ), QString::null, QString::null,
00547                     this, SLOT(SaveFileSlot()), FileBar, "Save File" );
00548    FileSaveB->setUsesTextLabel(FALSE);
00549    QToolTip::add(FileSaveB, "Save the content of the browser to a root file");
00550 
00551    QToolButton *FileAllCloseB  = new QToolButton( QPixmap::fromMimeSource( "close.png" ), QString::null, QString::null,
00552                     this, SLOT(CloseAllFilesSlot() ), FileBar, "Close All Files" );
00553    FileAllCloseB->setUsesTextLabel(FALSE);
00554    QToolTip::add(FileAllCloseB, "Close all root files in file browser");
00555 
00556    QToolButton *FileExitB  = new QToolButton( QPixmap::fromMimeSource( "exit.png" ), QString::null, QString::null,
00557                    this, SLOT(close()), FileBar, "Exit" );
00558    FileExitB->setUsesTextLabel(FALSE);
00559    QToolTip::add(FileExitB, "Exit the Go4");
00560 }
00561 
00562 void TGo4MainWindow::AddToolsMenu()
00563 {
00564    QPopupMenu * Go4ToolMenu = new QPopupMenu(this);
00565    menuBar()->insertItem( "&Tools", Go4ToolMenu);
00566 
00567    Go4ToolMenu->insertItem(QPixmap::fromMimeSource( "chart.png" ), "&View Panel",
00568                 this, SLOT(MakeNewPanel()), CTRL+Key_V );
00569    Go4ToolMenu->insertItem(QPixmap::fromMimeSource( "fitpanel.png" ), "&Fit Panel...",
00570                 this, SLOT(StartFitPanel()), CTRL+Key_F );
00571    Go4ToolMenu->insertItem( QPixmap::fromMimeSource( "hislist.png" ),"&Histogram properties...",
00572                this, SLOT(StartHistogramInfo()));
00573    Go4ToolMenu->insertItem(QPixmap::fromMimeSource( "hiscre.png" ), "Create New H&is...",
00574                this, SLOT(CreateNewHistSlot()), CTRL+Key_I );
00575    Go4ToolMenu->insertItem( QPixmap::fromMimeSource( "condlist.png" ),"C&ondition properties...",
00576                this, SLOT(StartConditionInfo()));
00577    Go4ToolMenu->insertItem( QPixmap::fromMimeSource( "condcre.png" ),"&Condition Editor...",
00578                this, SLOT(CreateNewConditionSlot()), CTRL+Key_C);
00579    Go4ToolMenu->insertItem( QPixmap::fromMimeSource( "zoom.png" ),"&Event Printout...",
00580                this, SLOT(StartEventInfo()));
00581    Go4ToolMenu->insertItem( QPixmap::fromMimeSource( "dynlist.png" ),"Create &Dyn. List entry ...",
00582                this, SLOT(CreateNewDynEntrySlot()), CTRL+Key_D);
00583    Go4ToolMenu->insertItem(QPixmap::fromMimeSource( "dllicon.png" ), "Load Li&braries ...",
00584                this, SLOT(LoadLibrarySlot()), CTRL+Key_B);
00585    Go4ToolMenu->insertItem(QPixmap::fromMimeSource( "user.png" ), "&User GUI ...",
00586                this, SLOT(UserPanelSlot()), CTRL+Key_U);
00587 }
00588 
00589 void TGo4MainWindow::AddToolsBar()
00590 {
00591    QToolBar *Go4ToolBar = new QToolBar( this, "File operations" );
00592    addDockWindow(Go4ToolBar, "Tools Toolbar", Qt::DockTop, TRUE );
00593    Go4ToolBar->setNewLine ( FALSE );
00594 
00595    QToolButton *ViewB  = new QToolButton( QPixmap::fromMimeSource( "chart.png" ), QString::null, QString::null,
00596                  this, SLOT(MakeNewPanel()), Go4ToolBar, "View Panel" );
00597    ViewB->setUsesTextLabel(FALSE);
00598    QToolTip::add(ViewB , "Create a new view panel");
00599 
00600    QToolButton *FitPanelB  = new QToolButton( QPixmap::fromMimeSource( "fitpanel.png" ), QString::null, QString::null,
00601                     this, SLOT(StartFitPanel()), Go4ToolBar, "Fit Panel" );
00602    FitPanelB->setUsesTextLabel(FALSE);
00603    QToolTip::add(FitPanelB , "Show/hide the Go4 Fit Panel");
00604 
00605    QToolButton *HisInfoB  = new QToolButton( QPixmap::fromMimeSource( "hislist.png" ), QString::null, QString::null,
00606                     this, SLOT(StartHistogramInfo()), Go4ToolBar, "Histogram properties");
00607    HisInfoB->setUsesTextLabel(FALSE);
00608    QToolTip::add(HisInfoB , "Show histogram properties window");
00609 
00610    QToolButton *CreatHisB  = new QToolButton( QPixmap::fromMimeSource( "hiscre.png" ), QString::null, QString::null,
00611                     this, SLOT(CreateNewHistSlot()), Go4ToolBar, "Create New Histogram" );
00612    CreatHisB->setUsesTextLabel(FALSE);
00613    QToolTip::add(CreatHisB , "Create new ROOT Histogram");
00614 
00615    QToolButton *ConInfoB  = new QToolButton( QPixmap::fromMimeSource( "condlist.png" ), QString::null, QString::null,
00616                     this, SLOT(StartConditionInfo()), Go4ToolBar, "Condition properties");
00617    ConInfoB->setUsesTextLabel(FALSE);
00618    QToolTip::add(ConInfoB , "Show condition properties window");
00619 
00620    QToolButton *ConEditB  = new QToolButton( QPixmap::fromMimeSource( "condcre.png" ), QString::null, QString::null,
00621                     this, SLOT(CreateNewConditionSlot()), Go4ToolBar, "Condition editor");
00622    ConEditB->setUsesTextLabel(FALSE);
00623    QToolTip::add(ConEditB , "Create new condition in analysis");
00624 
00625    QToolButton *EveInfoB  = new QToolButton( QPixmap::fromMimeSource( "zoom.png" ), QString::null, QString::null,
00626                     this, SLOT(StartEventInfo()), Go4ToolBar, "Event printout");
00627    EveInfoB->setUsesTextLabel(FALSE);
00628    QToolTip::add(EveInfoB , "Event printout and examination window");
00629 
00630    QToolButton *DynEditorB  = new QToolButton( QPixmap::fromMimeSource( "dynlist.png" ), QString::null, QString::null,
00631                     this, SLOT(CreateNewDynEntrySlot()), Go4ToolBar, "Create Dyn. List");
00632    DynEditorB->setUsesTextLabel(FALSE);
00633    QToolTip::add(DynEditorB , "Create new Dynamic list entry");
00634 
00635    QToolButton *LibB  = new QToolButton( QPixmap::fromMimeSource( "dllicon.png" ), QString::null, QString::null,
00636                     this, SLOT(LoadLibrarySlot() ), Go4ToolBar, "Load Libraries" );
00637    LibB->setUsesTextLabel(FALSE);
00638    QToolTip::add(LibB , "Load Libraries");
00639 
00640    QToolButton *UsrB  = new QToolButton( QPixmap::fromMimeSource( "user.png" ), QString::null, QString::null,
00641                     this, SLOT(UserPanelSlot()), Go4ToolBar, "User GUI" );
00642    UsrB->setUsesTextLabel(FALSE);
00643    QToolTip::add(UsrB , "Start user panel");
00644 }
00645 
00646 void TGo4MainWindow::AddAnalysisMenu()
00647 {
00648    QPopupMenu * AnalysisMenu  = new QPopupMenu( this );
00649    menuBar()->insertItem( "&Analysis", AnalysisMenu);
00650 
00651    AnalysisMenu->insertItem(QPixmap::fromMimeSource( "launchanal.png" ), "Lau&nch analysis...",
00652            this, SLOT(LaunchClientSlot()), CTRL+Key_N, fiLaunchAnal);
00653 
00654    AnalysisMenu->insertItem(QPixmap::fromMimeSource("connect.png"), "&Connect to running server...",
00655              this, SLOT(ConnectServerSlot()), CTRL+Key_C, fiConnectAnal);
00656 
00657    AnalysisMenu->insertItem(QPixmap::fromMimeSource( "connect.png" ), "&Prepare for client connection...",
00658              this, SLOT(PrepareForClientConnectionSlot()), CTRL+Key_C, fiPrepareAnal );
00659 
00660    AnalysisMenu->insertItem(QPixmap::fromMimeSource("disconnect.png"), "Disconnect from analysis",
00661              this, SLOT(DisconnectAnalysisSlot()), CTRL+Key_M, fiDisconnectAnal );
00662 
00663    AnalysisMenu->insertItem(QPixmap::fromMimeSource("shutanal.png"), "Shutdown analysis server",
00664              this, SLOT(ShutdownAnalysisSlot()), CTRL+Key_M, fiShutdownAnal );
00665 
00666    AnalysisMenu->insertItem(QPixmap::fromMimeSource("restart.png"), "Submit+S&tart",
00667              this, SLOT(SubmitStartAnalysisSlot()), CTRL+Key_T, fiSumbStartAnal );
00668 
00669    AnalysisMenu->insertItem(QPixmap::fromMimeSource("start.png"), "&Start",
00670              this, SLOT(StartAnalysisSlot()), CTRL+Key_S, fiStartAnal );
00671 
00672    AnalysisMenu->insertItem(QPixmap::fromMimeSource("Stop.png"), "Stop (&Halt)",
00673              this, SLOT(StopAnalysisSlot()), CTRL+Key_H, fiStopAnal );
00674 
00675    AnalysisMenu->insertItem(QPixmap::fromMimeSource("control.png"), "Confi&guration...",
00676                this, SLOT(ToggleAnalysisConfiguration()), CTRL+Key_G, fiAnalConfig);
00677 
00678    AnalysisMenu->insertItem(QPixmap::fromMimeSource("analysiswin.png"), "Analysis &Window",
00679                this, SLOT(ToggleAnalysisWindow()), CTRL+Key_W, fiAnalTermin);
00680 }
00681 
00682 void TGo4MainWindow::AddAnalysisBar()
00683 {
00684    QToolBar *AnalysisToolBar = new QToolBar( this, "AnalysisToolBar" );
00685    addDockWindow(AnalysisToolBar, "Analysis Toolbar", Qt::DockTop, TRUE );
00686    AnalysisToolBar->setNewLine ( FALSE );
00687    QToolTip::add(AnalysisToolBar, "Analysis related tool buttons");
00688 
00689    QToolButton *LaunchB  = new QToolButton( QPixmap::fromMimeSource( "launchanal.png" ), QString::null, QString::null,
00690                    this, SLOT(LaunchClientSlot()), AnalysisToolBar, "Launch Analysis Button" );
00691    LaunchB->setUsesTextLabel(FALSE);
00692    QToolTip::add(LaunchB, "Launch an analysis");
00693 
00694    QToolButton *ConnectB  = new QToolButton( QPixmap::fromMimeSource( "connect.png" ), QString::null, QString::null,
00695                    this, SLOT(ConnectServerSlot()), AnalysisToolBar, "Connect Analysis Button" );
00696    ConnectB->setUsesTextLabel(FALSE);
00697    QToolTip::add(ConnectB, "Connect running analysis");
00698 
00699    QToolButton *DisconnectB  = new QToolButton( QPixmap::fromMimeSource( "disconnect.png" ), QString::null, QString::null,
00700                    this, SLOT(DisconnectAnalysisSlot()), AnalysisToolBar, "Disconnect Analysis Button" );
00701    DisconnectB->setUsesTextLabel(FALSE);
00702    QToolTip::add(DisconnectB, "Disconnect from running analysis");
00703 
00704    QToolButton *ShutdownB  = new QToolButton( QPixmap::fromMimeSource( "shutanal.png" ), QString::null, QString::null,
00705                   this, SLOT(ShutdownAnalysisSlot()), AnalysisToolBar, "Shutdown Analysis Button" );
00706    ShutdownB->setUsesTextLabel(FALSE);
00707    QToolTip::add(ShutdownB, "Shutdown running analysis");
00708 
00709    QToolButton *SetStartB  = new QToolButton( QPixmap::fromMimeSource( "restart.png" ), QString::null, QString::null,
00710                     this, SLOT(SubmitStartAnalysisSlot()), AnalysisToolBar, "Submit and Start Analysis" );
00711    SetStartB->setUsesTextLabel(FALSE);
00712    QToolTip::add(SetStartB, "Submit Settings and start analysis");
00713 
00714    QToolButton *StartB  = new QToolButton( QPixmap::fromMimeSource( "start.png" ), QString::null, QString::null,
00715                    this, SLOT(StartAnalysisSlot()), AnalysisToolBar, "Start Analysis" );
00716    StartB->setUsesTextLabel(FALSE);
00717    QToolTip::add(StartB, "Start analysis");
00718 
00719    QToolButton *StopB  = new QToolButton( QPixmap::fromMimeSource( "Stop.png" ), QString::null, QString::null,
00720                   this, SLOT(StopAnalysisSlot()), AnalysisToolBar, "Stop  Analysis" );
00721    StopB->setUsesTextLabel(FALSE);
00722    QToolTip::add(StopB, "Stop analysis");
00723 
00724    QToolButton *ConfigB  = new QToolButton( QPixmap::fromMimeSource( "control.png" ), QString::null, QString::null,
00725                   this, SLOT(ToggleAnalysisConfiguration()), AnalysisToolBar, "Analysis Configuration" );
00726    ConfigB->setUsesTextLabel(FALSE);
00727    QToolTip::add(ConfigB, "Show the analysis configuration");
00728 
00729    QToolButton *AnalysisWinB  = new QToolButton( QPixmap::fromMimeSource( "analysiswin.png" ), QString::null, QString::null,
00730                    this, SLOT(ToggleAnalysisWindow()), AnalysisToolBar, "Analysis Window" );
00731    AnalysisWinB->setUsesTextLabel(FALSE);
00732    QToolTip::add(AnalysisWinB, "Show the analysis window");
00733 }
00734 
00735 void TGo4MainWindow::windowsMenuAboutToShow()
00736 {
00737     windowsMenu->clear();
00738     int cascadeId = windowsMenu->insertItem("Ca&scade", centralWidget(), SLOT(cascade()));
00739     int tileId    = windowsMenu->insertItem("&Tile", centralWidget(), SLOT(tile()));
00740     int closallId = windowsMenu->insertItem("&Close all", this, SLOT(CloseAllWindows()));
00741     int minallId  = windowsMenu->insertItem("&Minimize all", this, SLOT(MinAllWindows()));
00742     if (fxTGo4WorkSpace->windowList().isEmpty()) {
00743         windowsMenu->setItemEnabled(cascadeId, FALSE);
00744         windowsMenu->setItemEnabled(tileId, FALSE);
00745         windowsMenu->setItemEnabled(closallId, FALSE);
00746         windowsMenu->setItemEnabled(minallId, FALSE);
00747     }
00748 
00749     QGo4Widget* loginfo = FindGo4Widget("LogInfo", false);
00750     QGo4Widget* anw = FindGo4Widget("AnalysisWindow", false);
00751 
00752     windowsMenu->insertSeparator();
00753     int savelogId  = windowsMenu->insertItem("Save L&ogwindow", loginfo, SLOT(SaveLogInfo()));
00754     int clearlogId = windowsMenu->insertItem("Clear &Logwindow", loginfo, SLOT(ClearLogInfo()));
00755     int saveAnaId  = windowsMenu->insertItem("Save &Analysis window", anw, SLOT(SaveAnalysisOutput()));
00756     int clearAnaId = windowsMenu->insertItem("Clear Analysis &window", anw, SLOT(ClearAnalysisOutput()));
00757     windowsMenu->setItemEnabled(clearlogId, loginfo!=0);
00758     windowsMenu->setItemEnabled(savelogId, loginfo!=0);
00759     windowsMenu->setItemEnabled(saveAnaId, anw!=0);
00760     windowsMenu->setItemEnabled(clearAnaId, anw!=0);
00761 
00762     windowsMenu->insertSeparator();
00763     QWidgetList windows =  fxTGo4WorkSpace->windowList();
00764     for (int i=0; i<int(windows.count()); ++i ) {
00765         int id = windowsMenu->insertItem(windows.at(i)->caption(),
00766                                          this, SLOT( windowsMenuActivated(int)));
00767         windowsMenu->setItemParameter(id, i);
00768         windowsMenu->setItemChecked(id, fxTGo4WorkSpace->activeWindow() == windows.at(i));
00769     }
00770 }
00771 
00772 void TGo4MainWindow::CloseAllWindows()
00773 {
00774    QWidgetList windows =  fxTGo4WorkSpace->windowList();
00775     for ( int i = 0; i < int(windows.count()); ++i )
00776        windows.at(i)->close();
00777 }
00778 
00779 void TGo4MainWindow::MinAllWindows()
00780 {
00781    QWidgetList windows =  fxTGo4WorkSpace->windowList();
00782    for ( int i = 0; i < int(windows.count()); ++i )
00783        windows.at(i)->showMinimized();
00784 }
00785 
00786 void TGo4MainWindow::windowsMenuActivated( int id )
00787 {
00788    QWidget* w = fxTGo4WorkSpace->windowList().at(id);
00789    if (w) w->showNormal();
00790    w->setFocus();
00791 }
00792 
00793 typedef void* (*TStartUserGuiFunc)(QWidget* parent);
00794 
00795 bool TGo4MainWindow::startUserGUI(const char* usergui)
00796 {
00797    QString dirname, libname;
00798 
00799    bool result = false;
00800 
00801    if ((usergui!=0) && (strlen(usergui)>0)) {
00802       QFileInfo info(usergui);
00803       if (info.exists())
00804         if (info.isFile()) {
00805            dirname = info.dirPath();
00806            libname = info.fileName();
00807 
00808         } else
00809         if (info.isDir()) {
00810            dirname = usergui;
00811         }
00812      if ((dirname.length()>0) && (dirname[dirname.length()-1]!='/')) dirname+="/";
00813    }
00814 
00815    bool defaultnames = libname.length()==0;
00816    if (defaultnames)
00817      libname = "libGo4UserGui.so";
00818 
00819    cout << "Try : " << dirname+libname << endl;
00820    void* lib1 = ::dlopen(dirname+libname, RTLD_LAZY | RTLD_GLOBAL);
00821 
00822    if (lib1==0) {
00823       const char* errmsg = ::dlerror();
00824       if (errmsg!=0) cout << errmsg << endl;
00825       return false;
00826    }
00827 
00828    TStartUserGuiFunc startfunc = (TStartUserGuiFunc) ::dlsym(lib1,"StartUserPanel");
00829 
00830    if (startfunc!=0) {
00831      QGo4Widget* userpanel = (QGo4Widget*) startfunc(centralWidget());
00832      if (userpanel!=0) {
00833         userpanel->setName("UserPanel");
00834         ConnectGo4Widget(userpanel);
00835         userpanel->show();
00836         result = true;
00837      } else
00838        StatusMessage("StartUserPanel() function didnot create user widget");
00839    }
00840 
00841    if (result) {
00842      cout << "Start user GUI from ";
00843      if (dirname.length()>0)
00844         cout << dirname << endl;
00845      else
00846         cout << "$LD_LIBRARY_PATH=" << ::getenv("LD_LIBRARY_PATH") << endl;
00847    } else {
00848       if (lib1!=0) dlclose(lib1);
00849    }
00850 
00851    return result;
00852 }
00853 
00854 void TGo4MainWindow::UserPanelSlot()
00855 {
00856    QGo4Widget* userpanel = FindGo4Widget("UserPanel", true);
00857    if (userpanel!=0) return;
00858 
00859    // check GO4USERGUI variable
00860    QString usergui = getenv("GO4USERGUI");
00861    if (usergui.length()>0)
00862      if (startUserGUI(usergui)) return;
00863 
00864    // check from standard LD_LIBRARY_PATHS
00865    if (startUserGUI(0)) return;
00866 
00867    usergui = getenv("GO4SYS");
00868    if (usergui.length()>0) {
00869      if (usergui[usergui.length()-1]!='/') usergui+="/";
00870      usergui+="Go4UserGUI";
00871      if (startUserGUI(usergui)) return;
00872    }
00873 
00874    QMessageBox::critical(this,"Starting user GUI", "No suitable libraries found");
00875 }
00876 
00877 
00878 TGo4ViewPanel* TGo4MainWindow::MakeNewPanel(int ndiv)
00879 {
00880    QString name;
00881 
00882    TGo4Slot* edslot = fxOM->GetSlot(fOMEditorsPath);
00883 
00884    int n = 0;
00885    do {
00886      n++;
00887      name = QString("Panel") + QString::number(n);
00888    } while ((edslot!=0) && (edslot->FindChild(name.latin1())!=0));
00889 
00890    TGo4ViewPanel* panel = new TGo4ViewPanel(centralWidget(), name);
00891    ConnectGo4Widget(panel);
00892    panel->CompleteInitialization();
00893 
00894    panel->polish();
00895    panel->show();
00896 
00897    panel->GetCanvas()->Resize();
00898 
00899    if(ndiv>1) {
00900       int DivX = (int) TMath::Sqrt(ndiv*1.);
00901       int DivY = DivX;
00902       if(DivX*DivY<ndiv) {
00903          do { DivX=DivX+1; } while(DivX*DivY<ndiv);
00904       }
00905       panel->Divide(DivX, DivY);
00906    }
00907 
00908    return panel;
00909 }
00910 
00911 void TGo4MainWindow::closeEvent( QCloseEvent* ce)
00912 {
00913    if (fCloseCounter!=0) return;
00914 
00915    if(QMessageBox::warning( this, "Go4 GUI", "Really Exit Go4?",
00916          QMessageBox::Yes ,
00917          QMessageBox::No | QMessageBox::Escape) != QMessageBox::Yes ) return;
00918 
00919 
00920    CloseAllWindows();
00921 
00922    Browser()->ToggleMonitoring(0);
00923 
00924    CloseAllFilesSlot();
00925 
00926    if(!RemoveAnalysisProxy(30)) {
00927       fCloseCounter = 100; // gui waits about 10 second to close analysis
00928       statusBar()->message("Exit....  please wait");
00929       QTimer::singleShot(100, this, SLOT(ForseCloseSlot()));
00930    } else {
00931       statusBar()->message("Closing GUI...");
00932 
00933       ce->accept();
00934    }
00935 }
00936 
00937 void TGo4MainWindow::ForseCloseSlot()
00938 {
00939    if (!RemoveAnalysisProxy(30) && (fCloseCounter>0)) {
00940       fCloseCounter--;
00941       QTimer::singleShot(100, this, SLOT(ForseCloseSlot()));
00942       return;
00943    }
00944    delete this;
00945 }
00946 
00947 void TGo4MainWindow::OpenFileSlot()
00948 {
00949    QFileDialog fd( this, "Read Root File", TRUE );
00950    fd.setCaption("Select a ROOT file to open it in the Go4 Disk Browser");
00951    fd.setMode( QFileDialog::ExistingFiles);
00952    fd.setName( "Open Root File ");
00953    fd.setFilters(QString("Root files (*.root);;Root xml files (*.xml);;All files (*.*)"));
00954    if (fLastFileDir.length()>0)
00955      fd.setDir(QDir(fLastFileDir));
00956    if ( fd.exec() != QDialog::Accepted ) return;
00957 
00958    QStringList list = fd.selectedFiles();
00959    QStringList::Iterator it = list.begin();
00960    while( it != list.end() ) {
00961       QString fileName = *it;
00962       fLastFileDir = QFileInfo(fileName).dirPath(true);
00963       Browser()->OpenFile(fileName.latin1());
00964       ++it;
00965    }
00966 }
00967 
00968 void TGo4MainWindow::OpenRemoteFileSlot()
00969 {
00970    TGo4OpenRemoteDialog fd( this, "Open Remote root file", TRUE );
00971    if (fd.exec() != QDialog::Accepted) return;
00972 
00973    QString ftype = fd.GetFileType();
00974    QString host = fd.GetServer();
00975 
00976    QString urlpath;
00977    if(ftype.contains("root:"))
00978       urlpath = "root://" + host + "/";
00979    else
00980    if (ftype.contains("rfio:")) {
00981       if(!host.isEmpty())
00982         urlpath="rfio:" + host + ":/";
00983       else
00984         urlpath="rfio:/";
00985    } else
00986    if (ftype.contains("http:")) {
00987       if(!host.isEmpty())
00988          urlpath="http://" + host + "/";
00989       else
00990          urlpath="http://";
00991    }
00992 
00993    QString fileName = fd.GetFileName();
00994 
00995    if(!fileName.isEmpty() && !fileName.contains(".root"))
00996       fileName.append(".root");
00997 
00998    fileName = urlpath + fileName;
00999 
01000    fxOM->AddFile(fOMDataPath.latin1(), fileName.latin1());
01001 }
01002 
01003 void TGo4MainWindow::ConnectHServerSlot()
01004 {
01005    TGo4HServerConnection dlg( this, "Connect to remote HServer", TRUE );
01006 
01007    dlg.ServerName->setText(go4sett->getHServName());
01008    dlg.BaseName->setText(go4sett->getHServBase());
01009    dlg.FilterList->setText(go4sett->getHServFilter());
01010    dlg.PortNumberSpin->setValue(go4sett->getHServPort());
01011 
01012    if (dlg.exec() != QDialog::Accepted) return;
01013 
01014    go4sett->setHServName(dlg.ServerName->text());
01015    go4sett->setHServBase(dlg.BaseName->text());
01016    go4sett->setHServFilter(dlg.FilterList->text());
01017    go4sett->setHServPort(dlg.PortNumberSpin->value());
01018 
01019    if (!Browser()->ConnectHServer(dlg.ServerName->text().latin1(),
01020                                   dlg.PortNumberSpin->value(),
01021                                   dlg.BaseName->text().latin1(),
01022                                   dlg.UserPassEdt->text().latin1(),
01023                                   dlg.FilterList->text().latin1()))
01024      QMessageBox::warning(0, "HServer", "Cannot connect to histogram server");
01025 }
01026 
01027 void TGo4MainWindow::SaveFileSlot()
01028 {
01029    QFileDialog fd(this, "export", kTRUE );
01030    fd.setMode( QFileDialog::AnyFile);
01031    if (go4sett->getFetchDataWhenSave())
01032       fd.setCaption("Select root file to fetch and export all browser objects");
01033    else
01034       fd.setCaption("Select root file to export all local browser objects");
01035 
01036    fd.setFilters(QString("ROOT (*.root)"));
01037    fd.setSelection("export.root");
01038    if (fLastFileDir.length()>0)
01039       fd.setDir(QDir(fLastFileDir));
01040 
01041    if (fd.exec() != QDialog::Accepted) return;
01042 
01043    QString fname = fd.selectedFile();
01044    fLastFileDir = QFileInfo(fname).dirPath(true);
01045    if (fname.find(".root", 0, FALSE)<0) fname+=".root";
01046 
01047    if (!Browser()->SaveBrowserToFile(fname.latin1(), go4sett->getFetchDataWhenSave()))
01048      QMessageBox::warning(this, "Save data to file", "Specified file can not be created");
01049 }
01050 
01051 void TGo4MainWindow::CloseAllFilesSlot()
01052 {
01053    fxOM->CloseFiles(fOMDataPath.latin1());
01054 }
01055 
01056 void TGo4MainWindow::InputTerminalParametersSlot()
01057 {
01058    int size = go4sett->getTermHistorySize();
01059 
01060    bool ok;
01061 
01062    size = QInputDialog::getInteger("Analysis terminal history size in bytes (minimum 10000 bytes)",
01063                                    "Input 0 if full analysis history should be preserved",
01064                                    size, 0, 100000000, 10000, &ok, this);
01065 
01066    if ((size>0) && (size<10000)) size = 10000;
01067 
01068    if (ok) {
01069      go4sett->setTermHistorySize(size);
01070      TGo4AnalysisWindow* anw = FindAnalysisWindow();
01071      if (anw!=0)
01072        anw->SetHistorySize(size);
01073    }
01074 }
01075 
01076 void TGo4MainWindow::LogSettingsSlot()
01077 {
01078    TGo4LogSettings dlg( this, "Logging setup for GUI:", TRUE );
01079    if (dlg.exec() != QDialog::Accepted) return;
01080 
01081    if(dlg.LogfileWrite->isChecked())
01082       TGo4Log::OpenLogfile(dlg.LogfileName->text(), "Logfile for Go4 GUI", true);
01083 
01084    TGo4Log::LogfileEnable(dlg.LogfileWrite->isChecked());
01085    TGo4Log::OutputEnable(dlg.LogfilePrint->isChecked());
01086    TGo4Log::SetIgnoreLevel(dlg.IgnoreCombo->currentItem());
01087    TGo4Log::AutoEnable(dlg.ModeCombo->currentItem());
01088 }
01089 
01090 void TGo4MainWindow::HelpWindow(const char* filename, const char* dir, const char* msg)
01091 {
01092    QApplication::setOverrideCursor( Qt::WaitCursor );
01093    if (msg!=0) StatusMessage(msg);
01094    TGo4HelpWindow*  helpw =  new TGo4HelpWindow(filename, centralWidget(), dir);
01095    helpw->show();
01096    QApplication::restoreOverrideCursor();
01097 }
01098 
01099 void  TGo4MainWindow::IntroHelpSlot()
01100 {
01101    HelpWindow("Go4introV3.htm", "", "Loading Go4 Introduction manual...");
01102 }
01103 
01104 void  TGo4MainWindow::RefHelpSlot()
01105 {
01106    HelpWindow("Go4refV3.htm", "", "Loading Go4 Reference manual...");
01107 }
01108 
01109 void TGo4MainWindow::FitHelpSlot()
01110 {
01111    HelpWindow("Go4FitTutorial.htm", "", "Loading Go4 Fit tutorial...");
01112 }
01113 
01114 void TGo4MainWindow::InterfaceHelpSlot()
01115 {
01116    HelpWindow("classTGo4AbstractInterface.html","doxygen/go4abstractinterface");
01117 }
01118 
01119 void TGo4MainWindow::SaveSettingsSlot()
01120 {
01121    go4sett->storeGeometry(this);
01122 
01123    go4sett->setBasicSettings();
01124 
01125    go4sett->setAppStyle(QApplication::style().name());
01126 
01127    go4sett->StoreSettings(this);
01128 
01129    go4sett->DumpSettingsLocation();
01130 
01131    delete go4sett;
01132 
01133    go4sett = new TGo4QSettings;
01134 }
01135 
01136 void TGo4MainWindow::ChangeFontSlot()
01137 {
01138     bool ok = false;
01139     QFont font = QFontDialog::getFont(&ok, QApplication::font(), this);
01140     if (ok)
01141        QApplication::setFont( font, true );
01142 }
01143 
01144 void TGo4MainWindow::MakeStyleSlot(const QString &style)
01145 {
01146    QApplication::setStyle(style);
01147    if(style == "Platinum") {
01148        QPalette p( QColor( 239, 239, 239 ) );
01149        QApplication::setPalette( p, TRUE );
01150        QApplication::setFont(QApplication::font(), TRUE);
01151    } else if(style == "Windows") {
01152        QApplication::setFont(QApplication::font(), TRUE);
01153    } else if(style == "CDE") {
01154        QPalette p( QColor( 75, 123, 130 ) );
01155        p.setColor( QPalette::Active, QColorGroup::Base, QColor( 55, 77, 78 ) );
01156        p.setColor( QPalette::Inactive, QColorGroup::Base, QColor( 55, 77, 78 ) );
01157        p.setColor( QPalette::Disabled, QColorGroup::Base, QColor( 55, 77, 78 ) );
01158        p.setColor( QPalette::Active, QColorGroup::Highlight, Qt::white );
01159        p.setColor( QPalette::Active, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
01160        p.setColor( QPalette::Inactive, QColorGroup::Highlight, Qt::white );
01161        p.setColor( QPalette::Inactive, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
01162        p.setColor( QPalette::Disabled, QColorGroup::Highlight, Qt::white );
01163        p.setColor( QPalette::Disabled, QColorGroup::HighlightedText, QColor( 55, 77, 78 ) );
01164        p.setColor( QPalette::Active, QColorGroup::Foreground, Qt::white );
01165        p.setColor( QPalette::Active, QColorGroup::Text, Qt::white );
01166        p.setColor( QPalette::Active, QColorGroup::ButtonText, Qt::white );
01167        p.setColor( QPalette::Inactive, QColorGroup::Foreground, Qt::white );
01168        p.setColor( QPalette::Inactive, QColorGroup::Text, Qt::white );
01169        p.setColor( QPalette::Inactive, QColorGroup::ButtonText, Qt::white );
01170        p.setColor( QPalette::Disabled, QColorGroup::Foreground, Qt::lightGray );
01171        p.setColor( QPalette::Disabled, QColorGroup::Text, Qt::lightGray );
01172        p.setColor( QPalette::Disabled, QColorGroup::ButtonText, Qt::lightGray );
01173        QApplication::setPalette( p, TRUE );
01174        QApplication::setFont( QFont( "times", QApplication::font().pointSize() ), TRUE );
01175    } else if(style == "Motif" || style == "MotifPlus") {
01176        QPalette p( QColor( 192, 192, 192 ) );
01177        QApplication::setPalette( p, TRUE );
01178        QApplication::setFont(QApplication::font(), TRUE );
01179    }
01180 }
01181 
01182 void TGo4MainWindow::StatusMessage(const QString& mess)
01183 {
01184    QString output = QDateTime::currentDateTime().toString(Qt::ISODate);
01185    output.append(": ");
01186    output.append(mess);
01187    statusBar()->message(output, 3000);
01188    if(TGo4Log::IsAutoEnabled())
01189       TGo4Log::Message(1,output);
01190 
01191    UpdateCaptionButtons();
01192 }
01193 
01194 void TGo4MainWindow::UpdateCaptionButtons()
01195 {
01196    TGo4AnalysisProxy* pr = Browser()->FindAnalysis();
01197 
01198    QString capt = "Go4 ";
01199    capt += __GO4RELEASE__;
01200    capt += " @";
01201    capt += gSystem->HostName();
01202    if ((pr!=0) && pr->IsConnected()) {
01203       capt += " <";
01204       capt += pr->GetContainedObjectInfo();
01205       capt += ">";
01206    }
01207    setCaption(capt);
01208 
01209    bool flag = (pr==0);
01210    QWidget* w1 = dynamic_cast<QWidget*> (child("Launch Analysis Button"));
01211    if (w1!=0) w1->setEnabled(flag);
01212    menuBar()->setItemEnabled(fiLaunchAnal, flag);
01213 
01214    if (pr==0) flag = (pr==0);
01215          else flag = (fConnectingCounter<=0) && pr->IsAnalysisServer() && !pr->IsConnected();
01216    QWidget* w2 = dynamic_cast<QWidget*> (child("Connect Analysis Button"));
01217    if (w2!=0) w2->setEnabled(flag);
01218    menuBar()->setItemEnabled(fiConnectAnal, flag);
01219 
01220    menuBar()->setItemEnabled(fiPrepareAnal, flag);
01221 
01222    if (pr==0) flag = false;
01223          else flag = pr->IsAnalysisServer() &&
01224                      (pr->IsConnected() || (fConnectingCounter<=0));
01225    QWidget* w3 = dynamic_cast<QWidget*> (child("Disconnect Analysis Button"));
01226    if (w3!=0) w3->setEnabled(flag);
01227    menuBar()->setItemEnabled(fiDisconnectAnal, flag);
01228 
01229    if (pr==0) flag = false;
01230          else flag = !pr->IsAnalysisServer() ||
01231                      (pr->IsConnected() && pr->IsAdministrator());
01232    QWidget* w4 = dynamic_cast<QWidget*> (child("Shutdown Analysis Button"));
01233    if (w4!=0) w4->setEnabled(flag);
01234    menuBar()->setItemEnabled(fiShutdownAnal, flag);
01235 
01236 
01237    bool iscontrolling = false;
01238    if (pr!=0)
01239      iscontrolling = pr->IsConnected() && (pr->IsAdministrator() || pr->IsController());
01240 
01241    QWidget* ww = dynamic_cast<QWidget*> (child("Submit and Start Analysis"));
01242    if (ww!=0) ww->setEnabled(iscontrolling);
01243    menuBar()->setItemEnabled(fiSumbStartAnal, iscontrolling);
01244 
01245    ww = dynamic_cast<QWidget*> (child("Start Analysis"));
01246    if (ww!=0) ww->setEnabled(iscontrolling);
01247    menuBar()->setItemEnabled(fiStartAnal, iscontrolling);
01248 
01249    ww = dynamic_cast<QWidget*> (child("Stop  Analysis"));
01250    if (ww!=0) ww->setEnabled(iscontrolling);
01251    menuBar()->setItemEnabled(fiStopAnal, iscontrolling);
01252 
01253    ww = dynamic_cast<QWidget*> (child("Analysis Configuration"));
01254    if (ww!=0) ww->setEnabled(iscontrolling);
01255    menuBar()->setItemEnabled(fiAnalConfig, iscontrolling);
01256 
01257    flag = (FindAnalysisWindow()!=0);
01258    ww = dynamic_cast<QWidget*> (child("Analysis Window"));
01259    if (ww!=0) ww->setEnabled(flag);
01260    menuBar()->setItemEnabled(fiAnalTermin, flag);
01261 }
01262 
01263 void TGo4MainWindow::ChangeFetchWhenDrawSlot()
01264 {
01265    bool s = !menuBar()->isItemChecked(fiFetchWhenDrawId);
01266    menuBar()->setItemChecked(fiFetchWhenDrawId, s);
01267    go4sett->setFetchDataWhenDraw(s);
01268 }
01269 
01270 void TGo4MainWindow::ChangeFetchWhenCopySlot()
01271 {
01272    bool s = !menuBar()->isItemChecked(fiFetchWhenCopyId);
01273    menuBar()->setItemChecked(fiFetchWhenCopyId, s);
01274    go4sett->setFetchDataWhenCopy(s);
01275 }
01276 
01277 void TGo4MainWindow::ChangeFetchWhenSaveSlot()
01278 {
01279    bool s = !menuBar()->isItemChecked(fiFetchWhenSaveId);
01280    menuBar()->setItemChecked(fiFetchWhenSaveId, s);
01281    go4sett->setFetchDataWhenSave(s);
01282 }
01283 
01284 void TGo4MainWindow::CanvasColorSlot()
01285 {
01286    QColor c = QColorDialog::getColor();
01287    if (c.isValid())
01288       go4sett->setCanvasColor(c.red(), c.green(), c.blue());
01289 }
01290 
01291 void TGo4MainWindow::MarkerSettingsSlot()
01292 {
01293    TGo4MarkerSettings mset(this, "Marker labels set up", true);
01294    if (mset.exec() != QDialog::Accepted) return;
01295    // all work is done inside dialog.
01296 }
01297 
01298 void TGo4MainWindow::OptStatsSlot()
01299 {
01300    TGo4OptStatsSettings stset(this, "Histogram statistics set up", true);
01301    if (stset.exec() != QDialog::Accepted) return;
01302    // all work is done inside dialog.
01303 }
01304 
01305 
01306 
01307 void TGo4MainWindow::CrosshairSlot()
01308 {
01309    bool s = !menuBar()->isItemChecked(fiCrosshairId);
01310    menuBar()->setItemChecked(fiCrosshairId, s);
01311    go4sett->setPadCrosshair(s);
01312 }
01313 
01314 void TGo4MainWindow::EventStatusSlot()
01315 {
01316    bool s = !menuBar()->isItemChecked(fiEventstatusId);
01317    menuBar()->setItemChecked(fiEventstatusId, s);
01318    go4sett->setPadEventStatus(s);
01319 }
01320 
01321 void TGo4MainWindow::ChangeCloneFlagSlot()
01322 {
01323    bool s = !menuBar()->isItemChecked(fiCloneId);
01324    menuBar()->setItemChecked(fiCloneId, s);
01325    menuBar()->setItemEnabled(fiDrawTimeId, s);
01326    menuBar()->setItemEnabled(fiDrawDateId, s);
01327    menuBar()->setItemEnabled(fiDrawItemId, s);
01328    go4sett->setCloneFlag(s);
01329 }
01330 
01331 void TGo4MainWindow::ChangeDrawTimeFlagSlot()
01332 {
01333    bool s = !menuBar()->isItemChecked(fiDrawTimeId);
01334    menuBar()->setItemChecked(fiDrawTimeId, s);
01335    go4sett->setDrawTimeFlag(s);
01336 }
01337 
01338 void TGo4MainWindow::ChangeDrawItemFlagSlot()
01339 {
01340    bool s = !menuBar()->isItemChecked(fiDrawItemId);
01341    menuBar()->setItemChecked(fiDrawItemId, s);
01342    go4sett->setDrawItemFlag(s);
01343 }
01344 
01345 void TGo4MainWindow::ChangeDrawDateFlagSlot()
01346 {
01347    bool s = !menuBar()->isItemChecked(fiDrawDateId);
01348    menuBar()->setItemChecked(fiDrawDateId, s);
01349    go4sett->setDrawDateFlag(s);
01350 }
01351 
01352 
01353 void TGo4MainWindow::LaunchClientSlot(bool interactive)
01354 {
01355    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01356    if (anal!=0) {
01357       QMessageBox::warning(this, "Launch analysis", "Please disconnect analysis first");
01358       return;
01359    }
01360 
01361    if (interactive) {
01362       TGo4StartClient dlg;
01363       if (dlg.exec()!=QDialog::Accepted) return;
01364       dlg.getResults();
01365    }
01366 
01367    int shellmode = go4sett->getClientShellMode();
01368    int termmode = go4sett->getClientTermMode();
01369    bool isserver = go4sett->getClientIsServer();
01370 
01371    TString launchcmd, killcmd;
01372    Bool_t res = kFALSE;
01373 
01374    if (!isserver) {
01375       TGo4AnalysisProxy* anal = AddAnalysisProxy(false, (termmode==1));
01376       if (anal!=0)
01377         res = anal->LaunchAsClient(launchcmd, killcmd,
01378                       (shellmode==2),
01379                       termmode,
01380                       go4sett->getClientName().latin1(),
01381                       go4sett->getClientNode().latin1(),
01382                       go4sett->getClientDir().latin1(),
01383                       go4sett->getClientExec().latin1());
01384       TGo4AnalysisWindow* anw = FindAnalysisWindow();
01385       if (res && (anw!=0) && (termmode==1))
01386          anw->StartAnalysisShell(launchcmd.Data());
01387    } else
01388       res = TGo4AnalysisProxy::LaunchAsServer(launchcmd, killcmd,
01389                       (shellmode==2),
01390                       termmode,
01391                       go4sett->getClientName().latin1(),
01392                       go4sett->getClientNode().latin1(),
01393                       go4sett->getClientDir().latin1(),
01394                       go4sett->getClientExec().latin1());
01395 
01396    if (res) fKillCommand = killcmd.Data();
01397        else fKillCommand = "";
01398 
01399    StatusMessage("Starting Analysis....  Please wait");
01400 
01401    if (isserver && interactive)
01402      ConnectServerSlot(true, "");
01403 }
01404 
01405 void TGo4MainWindow::PrepareForClientConnectionSlot()
01406 {
01407    TGo4AnalysisProxy* ana = AddAnalysisProxy(false, false);
01408    if (ana!=0)
01409      QMessageBox::information(this,"Prepare for client connection",
01410       "Now you can start client from other shell (node) and connect to port " +
01411        QString::number(ana->ConnectorPort()), "Ok");
01412 }
01413 
01414 TGo4AnalysisProxy* TGo4MainWindow::AddAnalysisProxy(bool isserver, bool needoutput)
01415 {
01416    const char* analisysitem = "Analysis";
01417 
01418    TGo4Slot* analslot = Browser()->DataSlot(analisysitem);
01419 
01420    if (analslot==0) {
01421       TGo4AnalysisProxy* anal = new TGo4AnalysisProxy(isserver);
01422       fxOM->AddProxy(fOMDataPath.latin1(), anal, analisysitem, "Analysis proxy");
01423       analslot = Browser()->DataSlot(analisysitem);
01424    }
01425 
01426    TGo4AnalysisProxy* anal = (analslot==0) ? 0 :
01427       dynamic_cast<TGo4AnalysisProxy*> (analslot->GetProxy());
01428 
01429    if (anal==0) return 0;
01430 
01431    anal->SetAnalysisReady(kFALSE);
01432 
01433    TGo4LogInfo* loginfo = (TGo4LogInfo*) FindGo4Widget("LogInfo", false);
01434    if (loginfo!=0)
01435      loginfo->WorkWithInfo(anal->LoginfoSlot());
01436 
01437    if (anal->IsAnalysisServer()) {
01438       EstablishRatemeter(anal->IsConnected() ? 2 : 0);
01439    } else
01440       EstablishRatemeter(1);
01441 
01442    EstablishAnalysisConfiguration(2);
01443 
01444    FindAnalysisConfiguration();
01445 
01446    TGo4AnalysisWindow* anw = FindAnalysisWindow();
01447    if (anw!=0)
01448     if (anw->HasOutput() && !needoutput) {
01449        delete anw;
01450        anw = 0;
01451     }
01452 
01453    if(anw==0)
01454      if (needoutput) {
01455         anw = new TGo4AnalysisWindow(centralWidget(), "AnalysisWindow", true);
01456         ConnectGo4Widget(anw);
01457         anw->show();
01458         anw->WorkWithUpdateObjectCmd(anal->UpdateObjectSlot());
01459      } else {
01460         UpdateDockAnalysisWindow();
01461      }
01462 
01463    return anal;
01464 }
01465 
01466 bool TGo4MainWindow::RemoveAnalysisProxy(int waittime, bool servershutdown)
01467 {
01468    EstablishAnalysisConfiguration(0);
01469 
01470    EstablishRatemeter(0);
01471 
01472    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01473    if (anal!=0)
01474       anal->DisconnectAnalysis(waittime, servershutdown);
01475 
01476    return Browser()->FindAnalysis()==0;
01477 }
01478 
01479 void TGo4MainWindow::UpdateDockAnalysisWindow()
01480 {
01481    TGo4AnalysisWindow* anw = FindAnalysisWindow();
01482    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01483 
01484    if ((anw!=0) && anw->HasOutput()) return;
01485 
01486    bool shouldexists = false;
01487    if (anal!=0)
01488      if (anal->IsAnalysisServer()) {
01489        if (anal->IsConnected() && (anal->IsController() || anal->IsAdministrator()))
01490          shouldexists = true;
01491      } else
01492        shouldexists = true;
01493 
01494    if (shouldexists && (anw==0)) {
01495      QDockWindow* dock = new QDockWindow();
01496      dock->setResizeEnabled(FALSE);
01497      dock->setCaption("AnalysisControls");
01498      setAppropriate(dock, true);
01499      bool showkill = !anal->IsAnalysisServer() || fKillCommand.length()>0;
01500      anw = new TGo4AnalysisWindow(dock, "AnalysisWindow", false, showkill);
01501      ConnectGo4Widget(anw);
01502      dock->setWidget(anw);
01503      addDockWindow(dock, Qt::DockTop);
01504      dock->show();
01505      anw->WorkWithUpdateObjectCmd(anal->UpdateObjectSlot());
01506    }
01507 }
01508 
01509 TGo4AnalysisStatusMonitor* TGo4MainWindow::EstablishRatemeter(int level)
01510 // level = 0 - delete
01511 // level = 1 - as is
01512 // level = 2 - create
01513 {
01514    TGo4AnalysisStatusMonitor* status =
01515      dynamic_cast<TGo4AnalysisStatusMonitor*>
01516       (statusBar()->child("AnalysisStatusMonitor"));
01517 
01518    if (level==2) {
01519      if (status==0) {
01520         status = new TGo4AnalysisStatusMonitor(statusBar(), "AnalysisStatusMonitor");
01521         ConnectGo4Widget(status);
01522         statusBar()->addWidget(status);
01523         TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01524         if (anal!=0)
01525           status->WorkWithRatemeter(anal->RatemeterSlot());
01526      }
01527    } else
01528    if (level==0) {
01529       if (status!=0) {
01530          statusBar()->removeWidget(status);
01531          delete status;
01532       }
01533       status = 0;
01534    }
01535 
01536    if (status!=0)
01537       status->show();
01538 
01539    return status;
01540 }
01541 
01542 TGo4AnalysisConfiguration* TGo4MainWindow::EstablishAnalysisConfiguration(int level)
01543 {
01544    // level: 0 - delete, 1 - keep as is, 2 - create, 3- create + request status
01545 
01546    TGo4AnalysisConfiguration* conf = FindAnalysisConfiguration();
01547 
01548    if (level==0) {
01549       if (conf!=0) {
01550          delete conf;
01551          conf = 0;
01552       }
01553    } else
01554    if (level>=2) {
01555      if (conf==0) {
01556        conf = new TGo4AnalysisConfiguration(centralWidget(), "AnalysisConfiguration");
01557        ConnectGo4Widget(conf);
01558      }
01559      TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01560      if (anal!=0) {
01561        conf->WorkWithAnalysis(anal);
01562        if (level>2) anal->RequestAnalysisSettings();
01563      }
01564    }
01565 
01566    return conf;
01567 }
01568 
01569 
01570 void TGo4MainWindow::ConnectServerSlot(bool interactive, const char* password)
01571 {
01572    if (fConnectingCounter>0) return;
01573 
01574    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01575    if (anal!=0) {
01576       if (anal->IsConnected() || !anal->IsAnalysisServer()) {
01577          if (interactive)
01578            QMessageBox::warning(this, "Connect client", "Analysis task is already connected");
01579          return;
01580       }
01581    }
01582 
01583    QString pass = password;
01584    if (interactive) {
01585       TGo4ConnectServer dlg;
01586       if (fLastPassword.length()>0)
01587         dlg.setPassword(fLastPassword.latin1());
01588       if (dlg.exec()!=QDialog::Accepted) return;
01589       pass = dlg.getInput();
01590    }
01591 
01592    if (anal==0) anal = AddAnalysisProxy(true, false);
01593    bool def = go4sett->getClientDefaultPass();
01594    if (!def) fLastPassword = pass;
01595 
01596    if (anal!=0)
01597      anal->ConnectToServer(go4sett->getClientNode().latin1(),
01598                            go4sett->getClientPort(),
01599                            go4sett->getClientControllerMode(),
01600                            def ? 0 : pass.latin1());
01601    StatusMessage("Connecting running analysis....  Please wait");
01602 
01603    // wait about 4 sec that analysis is connected
01604    fConnectingCounter = 41;
01605    UpdateCaptionButtons();
01606    CheckConnectingCounterSlot();
01607 }
01608 
01609 void TGo4MainWindow::CheckConnectingCounterSlot()
01610 {
01611    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01612 
01613    if ((anal==0) || anal->IsConnected() || (--fConnectingCounter<=0)) {
01614       if (fConnectingCounter<=0)
01615         StatusMessage("Analysis refused connection. Try again");
01616       fConnectingCounter = 0;
01617       EstablishRatemeter((anal!=0) && anal->IsConnected() ? 2 : 0);
01618       EstablishAnalysisConfiguration((anal!=0) && anal->IsConnected() && (anal->IsController() || anal->IsAdministrator()) ? 3 : 0);
01619       UpdateDockAnalysisWindow();
01620       UpdateCaptionButtons();
01621       if ((anal!=0) && !anal->IsConnected()) RemoveAnalysisProxy(1);
01622       return;
01623    }
01624    QTimer::singleShot(100, this, SLOT(CheckConnectingCounterSlot()));
01625 }
01626 
01627 void TGo4MainWindow::DisconnectAnalysisSlot(bool interactive)
01628 {
01629    if (interactive) {
01630       int res = QMessageBox::warning(this, "Disconnect analysis",
01631                 QString("Really disconnect from analysis task?"),
01632                 QString("Disconnect"),
01633                 QString("Cancel"),
01634                 QString::null, 0);
01635       if (res!=0) return;
01636    }
01637    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01638    if (anal==0) return;
01639 
01640    Browser()->ToggleMonitoring(0);
01641 
01642    RemoveAnalysisProxy(30, false);
01643 
01644    StatusMessage("Disconnect analysis");
01645 }
01646 
01647 void TGo4MainWindow::ShutdownAnalysisSlot(bool interactive)
01648 {
01649    if (interactive) {
01650       int res = QMessageBox::warning(this, "Shutdown analysis",
01651                 QString("Really shutdown analysis task?"),
01652                 QString("Shutdown"),
01653                 QString("Cancel"),
01654                 QString::null, 0);
01655       if (res!=0) return;
01656    }
01657 
01658    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01659    if (anal==0) return;
01660 
01661    Browser()->ToggleMonitoring(0);
01662 
01663    bool realshutdown = anal->IsAnalysisServer() &&
01664                        anal->IsConnected() &&
01665                        anal->IsAdministrator();
01666 
01667    RemoveAnalysisProxy(30, realshutdown);
01668 
01669    StatusMessage("Shutdown analysis");
01670 }
01671 
01672 void TGo4MainWindow::SubmitAnalysisSettings()
01673 {
01674    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01675    if (anal==0) return;
01676 
01677    if (anal!=0) {
01678       anal->SubmitAnalysisSettings();
01679       anal->RefreshNamesList();
01680    }
01681    StatusMessage("Press Ctrl+S or choose Analysis->Start from the Menu to start the analysis");
01682 }
01683 
01684 void TGo4MainWindow::SubmitStartAnalysisSlot()
01685 {
01686    SubmitAnalysisSettings();
01687    StartAnalysisSlot();
01688 }
01689 
01690 void TGo4MainWindow::StartAnalysisSlot()
01691 {
01692    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01693 
01694    if (anal==0) return;
01695 
01696    anal->StartAnalysis();
01697    anal->RefreshNamesList();
01698    anal->DelayedRefreshNamesList(4);
01699 
01700    EstablishRatemeter(2);
01701 }
01702 
01703 void TGo4MainWindow::StopAnalysisSlot()
01704 {
01705    TGo4AnalysisProxy* anal = Browser()->FindAnalysis();
01706 
01707    if (anal!=0)
01708       anal->StopAnalysis();
01709 }
01710 
01711 void TGo4MainWindow::TerminateAnalysis()
01712 {
01713    int res = QMessageBox::warning(this, "Kill analysis process",
01714              QString("Kill analysis by shell command: ") +fKillCommand + " ?",
01715              QString("Kill"),
01716              QString("Cancel"),
01717              QString::null, 0);
01718    if (res!=0) return;
01719 
01720    TGo4AnalysisWindow* anw = FindAnalysisWindow();
01721    if (anw!=0) anw->TerminateAnalysisProcess();
01722 
01723    // proxy will be deleted after 7 second
01724    //RemoveAnalysisProxy(7);
01725 
01726    anw = FindAnalysisWindow();
01727    if (anw!=0)
01728       anw->AppendOutputBuffer(QString("\nKilling analysis client: \n  ")+fKillCommand);
01729    else
01730       StatusMessage(QString("Killing analysis client with: ")+fKillCommand);
01731 
01732    if (fKillCommand.length()>0) {
01733       QProcess* killprocess = new QProcess;
01734       killprocess->setArguments(QStringList::split(" ",fKillCommand));
01735       if (!killprocess->start())
01736         StatusMessage("Can not start kill command");
01737       QTimer::singleShot(10000, killprocess, SLOT(deleteLater()));
01738    } else
01739       StatusMessage("Can not kill analysis. Do it by OS commands");
01740 
01741    EstablishAnalysisConfiguration(0);
01742 
01743    EstablishRatemeter(0);
01744 }
01745 
01746 QGo4Widget* TGo4MainWindow::FindGo4Widget(const char* name, bool activate)
01747 {
01748    if (fxOM==0) return 0;
01749 
01750    TGo4Slot* slot = fxOM->GetSlot(fOMEditorsPath.latin1());
01751 
01752    TGo4Slot* widgslot = slot==0 ? 0 : slot->FindChild(name);
01753    if (widgslot==0) return 0;
01754 
01755    TGo4WidgetProxy* wproxy = (TGo4WidgetProxy*) widgslot->GetProxy();
01756 
01757    QGo4Widget* widg = wproxy->GetWidget();
01758    if ((widg!=0) && activate) {
01759      if(!widg->isVisible()){
01760        widg->raise();
01761        widg->show();
01762        widg->setFocus();
01763      }
01764    }
01765 
01766    return widg;
01767 }
01768 
01769 
01770 TGo4FitPanel* TGo4MainWindow::StartFitPanel()
01771 {
01772    TGo4FitPanel* fitpanel = (TGo4FitPanel*) FindGo4Widget("FitPanel", true);
01773 
01774    if (fitpanel==0) {
01775       fitpanel = new TGo4FitPanel(centralWidget(),"FitPanel");
01776       ConnectGo4Widget(fitpanel);
01777       fitpanel->polish();
01778       fitpanel->show();
01779    }
01780    return fitpanel;
01781 }
01782 
01783 TGo4HistogramInfo* TGo4MainWindow::StartHistogramInfo()
01784 {
01785    TGo4HistogramInfo* hinfo = (TGo4HistogramInfo*) FindGo4Widget("HistogramInfo", true);
01786    if (hinfo==0) {
01787       hinfo = new TGo4HistogramInfo(centralWidget(), "HistogramInfo");
01788       ConnectGo4Widget(hinfo);
01789       hinfo->polish();
01790       hinfo->show();
01791       hinfo->adjustSize();
01792    }
01793    return hinfo;
01794 }
01795 
01796 TGo4ConditionInfo* TGo4MainWindow::StartConditionInfo()
01797 {
01798    TGo4ConditionInfo* cinfo = (TGo4ConditionInfo*) FindGo4Widget("ConditionInfo", true);
01799    if (cinfo==0) {
01800       cinfo = new TGo4ConditionInfo(centralWidget(), "ConditionInfo");
01801       ConnectGo4Widget(cinfo);
01802       cinfo->polish();
01803       cinfo->show();
01804       cinfo->adjustSize();
01805    }
01806    return cinfo;
01807 }
01808 
01809 void TGo4MainWindow::LoadLibrarySlot()
01810 {
01811    TGo4LoadedLibraries llib(this);
01812    llib.exec();
01813    TGo4Browser* br = (TGo4Browser*) FindGo4Widget("Browser", false);
01814    if (br!=0) br->ShootUpdateTimer();
01815 }
01816 
01817 TGo4ParaEdit* TGo4MainWindow::StartParaEdit(const char* itemname)
01818 {
01819    TGo4ParaEdit* pedit = (TGo4ParaEdit*) FindGo4Widget("ParaEdit", true);
01820 
01821    if (itemname!=0) {
01822       TClass* cl = Browser()->ItemClass(itemname);
01823       if (cl!=0)
01824          if (!cl->IsLoaded()) {
01825             QMessageBox::warning(0, "Parameter editor", QString("Cannot start parameter editor for incomplete class ") + cl->GetName());
01826             return pedit;
01827          }
01828    }
01829 
01830    if (pedit==0) {
01831       pedit = new TGo4ParaEdit(centralWidget(), "ParaEdit");
01832       ConnectGo4Widget(pedit);
01833       pedit->polish();
01834       pedit->show();
01835    }
01836 
01837    if (itemname!=0)
01838       pedit->WorkWithParameter(itemname, false);
01839 
01840    return pedit;
01841 }
01842 
01843 TGo4EditDynEntry* TGo4MainWindow::StartEditDynEntry()
01844 {
01845    TGo4EditDynEntry* dedit = (TGo4EditDynEntry*) FindGo4Widget("EditDynEntry", true);
01846 
01847    if (dedit==0) {
01848       dedit = new TGo4EditDynEntry(centralWidget(), "EditDynEntry");
01849       ConnectGo4Widget(dedit);
01850       dedit->polish();
01851       dedit->show();
01852    }
01853 
01854    return dedit;
01855 }
01856 
01857 TGo4ConditionEditor* TGo4MainWindow::StartConditionEditor()
01858 {
01859    TGo4ConditionEditor* wedit = (TGo4ConditionEditor*) FindGo4Widget("ConditionEditor", true);
01860    if (wedit==0) {
01861       wedit = new TGo4ConditionEditor(centralWidget(), "ConditionEditor");
01862       ConnectGo4Widget(wedit);
01863       wedit->polish();
01864       wedit->show();
01865    }
01866    return wedit;
01867 }
01868 
01869 TGo4EventInfo* TGo4MainWindow::StartEventInfo()
01870 {
01871    TGo4EventInfo* einfo = (TGo4EventInfo*) FindGo4Widget("EventInfo", true);
01872 
01873    if (einfo==0) {
01874       einfo = new TGo4EventInfo(centralWidget(), "EventInfo");
01875       ConnectGo4Widget(einfo);
01876       einfo->polish();
01877       einfo->show();
01878    }
01879 
01880    return einfo;
01881 }
01882 
01883 TGo4AnalysisConfiguration* TGo4MainWindow::FindAnalysisConfiguration()
01884 {
01885    return (TGo4AnalysisConfiguration*) FindGo4Widget("AnalysisConfiguration", false);
01886 }
01887 
01888 void TGo4MainWindow::ToggleAnalysisConfiguration()
01889 {
01890    TGo4AnalysisConfiguration* conf = FindAnalysisConfiguration();
01891    if (conf==0) return;
01892 
01893    if (conf->isVisible())
01894      conf->hide();
01895    else {
01896      conf->raise();
01897      conf->show();
01898      if (conf->isMinimized()) conf->showNormal();
01899    }
01900 }
01901 
01902 TGo4AnalysisWindow* TGo4MainWindow::FindAnalysisWindow()
01903 {
01904    return (TGo4AnalysisWindow*) FindGo4Widget("AnalysisWindow", false);
01905 }
01906 
01907 void TGo4MainWindow::ToggleAnalysisWindow()
01908 {
01909    TGo4AnalysisWindow* anw = FindAnalysisWindow();
01910    if (anw==0) return;
01911 
01912    if (anw->HasOutput()) {
01913       if (anw->isVisible())
01914         anw->hide();
01915       else {
01916         anw->raise();
01917         anw->show();
01918         if (anw->isMinimized()) anw->showNormal();
01919       }
01920    } else {
01921       QDockWindow* dock = dynamic_cast<QDockWindow*> (anw->parentWidget());
01922       if (dock->isVisible())
01923          dock->hide();
01924       else
01925          dock->show();
01926    }
01927 }
01928 
01929 void TGo4MainWindow::CloseAnalysisWindow()
01930 {
01931    TGo4AnalysisWindow* anw = FindAnalysisWindow();
01932    if (anw!=0) {
01933       QDockWindow* dock = dynamic_cast<QDockWindow*> (anw->parentWidget());
01934       removeDockWindow(dock);
01935       delete dock;
01936    }
01937 }
01938 
01939 
01940 void TGo4MainWindow::ToggleMbsMonitor(const char* nodename)
01941 {
01942    TGo4MBSViewer* mbs =
01943      dynamic_cast<TGo4MBSViewer*> (FindGo4Widget("MBSViewer", false));
01944    if (mbs==0) return;
01945    if (mbs->parentWidget()->isShown())
01946        mbs->parentWidget()->hide();
01947    else {
01948      mbs->SetNode(nodename);
01949      mbs->parentWidget()->show();
01950    }
01951 }
01952 
01953 
01954 TGo4SetScaleValues* TGo4MainWindow::ToggleScaleValues()
01955 {
01956    TGo4SetScaleValues* scl = 0;
01957 
01958    QWidgetList windows =  fxTGo4WorkSpace->windowList();
01959    for (int i=0; i<int(windows.count()); ++i ) {
01960       scl = dynamic_cast<TGo4SetScaleValues*> (windows.at(i));
01961       if (scl!=0) break;
01962    }
01963 
01964    if (scl==0) {
01965       scl = new TGo4SetScaleValues(centralWidget(), "ScaleValues", Qt::WStyle_StaysOnTop);
01966       scl->polish();
01967       scl->show();
01968    } else {
01969       delete scl;
01970       scl = 0;
01971    }
01972    return scl;
01973 }
01974 
01975 void TGo4MainWindow::CreateNewHistSlot(int isremote)
01976 {
01977    TGo4CreateNewHistogram dlg(this);
01978    TGo4AnalysisProxy* an = Browser()->FindAnalysis();
01979 
01980    dlg.SetAnalysisAvaliable((isremote!=0) && (an!=0) && an->IsAnalysisSettingsReady());
01981    dlg.SetLocalAvaliable(isremote!=1);
01982 
01983    if (dlg.exec() != QDialog::Accepted) return;
01984    TH1* h1 = dlg.MakeHistogram();
01985    if (h1==0) return;
01986 
01987    TGo4AnalysisWindow* anw = FindAnalysisWindow();
01988 
01989    if (dlg.GetSelectedCmd()==1) {
01990       TString newitem = Browser()->SaveToMemory("", h1, kTRUE);
01991 
01992       if (newitem.Length()>0)
01993          editorServiceSlot(anw,
01994                            QGo4Widget::service_ObjectCreated,
01995                            newitem.Data(), h1->IsA());
01996       h1 = 0;
01997    } else
01998    if ((dlg.GetSelectedCmd()==2) && (an!=0)) {
01999       h1->SetBit(TGo4Status::kGo4CanDelete);
02000       an->UpdateAnalysisObject("", h1);
02001       if (anw!=0) anw->WaitForNewObject(isremote==1);
02002    }
02003    if (h1!=0) delete h1;
02004 }
02005 
02006 void TGo4MainWindow::CreateNewConditionSlot(bool forothereditor)
02007 {
02008    TGo4AnalysisProxy* an = Browser()->FindAnalysis();
02009    if ((an==0) || !an->IsAnalysisSettingsReady()) {
02010       QMessageBox::information(this,"Create new condition","Cannot create new condition before analysis setup");
02011       return;
02012    }
02013 
02014    TGo4CreateNewCondition dlg(this);
02015 
02016    if (dlg.exec() != QDialog::Accepted) return;
02017 
02018    TGo4Condition* cond = dlg.MakeCondition();
02019    if (cond==0) return;
02020 
02021    cond->SetBit(TGo4Status::kGo4CanDelete);
02022    an->UpdateAnalysisObject("", cond);
02023    delete cond;
02024 
02025    TGo4AnalysisWindow* anw = FindAnalysisWindow();
02026    if(anw!=0) anw->WaitForNewObject(forothereditor);
02027 }
02028 
02029 void TGo4MainWindow::CreateNewDynEntrySlot(bool forothereditor)
02030 {
02031    TGo4AnalysisProxy* an = Browser()->FindAnalysis();
02032    if ((an==0) || !an->IsAnalysisSettingsReady()) {
02033       QMessageBox::information(this,"Create new dynamic entry","Cannot create new entry before analysis setup");
02034       return;
02035    }
02036 
02037    TGo4CreateNewDynEntry dlg(this);
02038 
02039    if (dlg.exec() != QDialog::Accepted) return;
02040 
02041    TGo4DynamicEntry* entry = dlg.MakeEntry();
02042    if (entry==0) return;
02043 
02044    entry->SetBit(TGo4Status::kGo4CanDelete);
02045    an->UpdateAnalysisObject("", entry);
02046    delete entry;
02047 
02048    TGo4AnalysisWindow* anw = FindAnalysisWindow();
02049    if (anw!=0) anw->WaitForNewObject(forothereditor);
02050 }
02051 
02052 void TGo4MainWindow::ConnectGo4Widget(QGo4Widget* editor)
02053 {
02054    if (editor==0) return;
02055    connect(editor, SIGNAL(widgetService(QGo4Widget*, int, const char*, void*)),
02056            this, SLOT(editorServiceSlot(QGo4Widget*, int, const char*, void*)));
02057    GetWidgetTopSlot(editor, true);
02058 }
02059 
02060 TGo4ViewPanel* TGo4MainWindow::DisplayBrowserItem(const char* itemname, TGo4ViewPanel* panel, TPad* pad, bool activate, int updatelevel, const char* drawopt)
02061 {
02062    TGo4BrowserProxy* br = Browser();
02063    if ((br==0) || (itemname==0)) return 0;
02064 
02065    TGo4Slot* guislot = br->BrowserSlot(itemname);
02066 
02067    if (guislot==0) return 0;
02068    if (guislot->GetProxy()==0) {
02069       cerr << " Problem with gui slots" << endl;
02070       return 0;
02071    }
02072 
02073    if (panel==0) {
02074       panel = MakeNewPanel();
02075       pad = panel->GetCanvas();
02076    } else
02077    if (pad==0) pad = panel->GetActivePad();
02078 
02079    if (panel->AddDrawObject(pad, TGo4ViewPanel::kind_Link, itemname, 0, false, drawopt)==0) return 0;
02080 
02081    if (activate) {
02082       panel->SetActivePad(pad);
02083       panel->ShootRepaintTimer();
02084    }
02085 
02086    if (updatelevel<0)
02087       if (go4sett->getFetchDataWhenDraw())
02088          updatelevel = 2;
02089       else
02090          updatelevel = 1;
02091 
02092    br->GetBrowserObject(itemname, updatelevel);
02093 
02094    return panel;
02095 }
02096 
02097 bool TGo4MainWindow::SaveBrowserItemToFile(const char* itemname, const char* subfolder)
02098 {
02099    TGo4BrowserProxy* br = Browser();
02100    if ((br==0) || (itemname==0)) return 0;
02101 
02102    TString fileslotname;
02103    const char* filepath = 0;
02104 
02105    bool res = false;
02106 
02107    if (br->DefineFileObject(itemname, fileslotname, filepath)) {
02108       int answer = QMessageBox::question(this, "Writing object to file",
02109          QString("Overwrite ") + filepath + " in file " + fileslotname.Data(),
02110          "Overwrite", "Save to other file", "Cancel");
02111       if (answer==2) return false;
02112       if (answer==0)
02113         res = br->UpdateObjectInFile(itemname, fileslotname.Data(), filepath);
02114    }
02115 
02116    if (!res) {
02117       QFileDialog fd(this, "Save object", kTRUE );
02118       fd.setMode( QFileDialog::AnyFile);
02119       fd.setCaption(QString("Save ") + itemname + " in root file");
02120       fd.setFilters(QString("ROOT (*.root);;ROOT XML (*.xml)"));
02121       fd.setSelection("file.root");
02122       if (fLastFileDir.length()>0)
02123          fd.setDir(QDir(fLastFileDir));
02124       if (fd.exec() == QDialog::Accepted) {
02125          res = br->SaveItemToFile(itemname, fd.selectedFile().latin1(), subfolder);
02126          fLastFileDir = QFileInfo(fd.selectedFile()).dirPath(true);
02127       }
02128    }
02129 
02130    return res;
02131 }
02132 
02133 void TGo4MainWindow::SavePanelCanvas(TGo4ViewPanel* panel)
02134 {
02135    if (panel==0) return;
02136 
02137    TCanvas* can = panel->GetCanvas();
02138    QFileDialog fd( this, "Save Canvas", TRUE);
02139    QString fdCaption = "Save ";
02140    fdCaption.append(name());
02141    fdCaption.append("  As");
02142    fd.setCaption(fdCaption);
02143    QString PS = "Post Script (*.ps)";
02144    QString PS_Portrait = "Post Script Portrait (*.ps)";
02145    QString PS_Landscape = "Post Script Landscape (*.ps)";
02146    QString EPS = "Encapsulated Post Script (*.eps)";
02147    QString EPS_Preview = "Encapsulated Post Script previw (*.eps)";
02148    QString GIF = "GIF format (*.gif)";
02149    QString PDF = "PDF format (*.pdf)";
02150    QString SVG = "SVG format (*.svg)";
02151    QString XPM = "XPM format (*.xpm)";
02152    QString PNG = "PNG format (*.png)";
02153    QString JPG = "JPG format (*.jpg)";
02154    QString TIFF = "TIFF format (*.tiff)";
02155 
02156    QString CXXM = "C++ Macro (*.C)";
02157    QString ROOTM = "root file (*.root)";
02158 
02159    fd.setMode( QFileDialog::AnyFile );
02160    fd.setName( "Save Canvas ");
02161    fd.setFilter(PS);
02162    fd.addFilter(PS_Portrait);
02163    fd.addFilter(PS_Landscape);
02164    fd.addFilter(EPS);
02165    fd.addFilter(EPS_Preview);
02166    fd.addFilter(PDF);
02167    fd.addFilter(SVG);
02168    fd.addFilter(GIF);
02169 
02170    #if ROOT_VERSION_CODE >= ROOT_VERSION(4,4,2)
02171    fd.addFilter(XPM);
02172    fd.addFilter(PNG);
02173    fd.addFilter(JPG);
02174    fd.addFilter(TIFF);
02175    #endif
02176 
02177    fd.addFilter(CXXM);
02178    fd.addFilter(ROOTM);
02179 
02180    if (fLastFileDir.length()>0)
02181       fd.setDir(QDir(fLastFileDir));
02182 
02183    if (fd.exec() != QDialog::Accepted) return;
02184 
02185    QString filename = fd.selectedFile();
02186    QString filter = fd.selectedFilter();
02187 
02188    fLastFileDir = QFileInfo(filename).dirPath(true);
02189 
02190    const char* opt = "ps";
02191 
02192    if(filter==EPS) {
02193       opt = "eps";
02194       if (!filename.endsWith(".eps")) filename.append(".eps");
02195    } else
02196    if(filter==EPS_Preview) {
02197       opt = "Preview";
02198       if (!filename.endsWith(".eps")) filename.append(".eps");
02199    } else
02200    if(filter==PS) {
02201       opt = "ps";
02202       if (!filename.endsWith(".ps")) filename.append(".ps");
02203    } else
02204    if(filter==PS_Portrait) {
02205       opt = "Portrait";
02206       if (!filename.endsWith(".ps")) filename.append(".ps");
02207    } else
02208    if(filter==PS_Landscape) {
02209       opt = "Landscape";
02210       if (!filename.endsWith(".ps")) filename.append(".ps");
02211    } else
02212    if(filter==GIF) {
02213       opt = "gif";
02214       if (!filename.endsWith(".gif")) filename.append(".gif");
02215    } else
02216    if(filter==PDF) {
02217       opt = "pdf";
02218       if (!filename.endsWith(".pdf")) filename.append(".pdf");
02219    } else
02220    if(filter==SVG) {
02221       opt = "svg";
02222       if (!filename.endsWith(".svg")) filename.append(".svg");
02223    } else
02224    if(filter==XPM) {
02225       opt = "xpm";
02226       if (!filename.endsWith(".xpm")) filename.append(".xpm");
02227    } else
02228    if(filter==PNG) {
02229       opt = "png";
02230       if (!filename.endsWith(".png")) filename.append(".png");
02231    } else
02232    if(filter==JPG) {
02233       opt = "jpg";
02234       if (!filename.endsWith(".jpg")) filename.append(".jpg");
02235    } else
02236    if(filter==TIFF) {
02237       opt = "tiff";
02238       if (!filename.endsWith(".tiff")) filename.append(".tiff");
02239    } else
02240    if(filter==CXXM) {
02241       opt = "cxx";
02242       if (!filename.endsWith(".C")) filename.append(".C");
02243    } else
02244    if (filter==ROOTM) {
02245       opt = "root";
02246       if (!filename.endsWith(".root")) filename.append(".root");
02247 
02248       // plain root browser might not know the go4 color numbers
02249       // canvas always saved with white background!
02250       panel->ResetPadFillColors(can,0);
02251    }
02252 
02253    //TString oldname = thiscanvas->GetName();
02254    //thiscanvas->SetName("Canvas");
02255    can->Print(filename.latin1(), opt);
02256 }
02257 
02258 TGo4ObjectManager* TGo4MainWindow::OM()
02259 {
02260    return fxOM;
02261 }
02262 
02263 TGo4BrowserProxy* TGo4MainWindow::Browser()
02264 {
02265    return (TGo4BrowserProxy*) fxOM->GetProxy(fOMBrowserPath.latin1());
02266 }
02267 
02268 TGo4Slot* TGo4MainWindow::GetWidgetTopSlot(QGo4Widget* widget, bool force)
02269 {
02270    if (widget==0) return 0;
02271 
02272    const char* EditorName = widget->name();
02273 
02274    TString editorslotname = fOMEditorsPath.latin1();
02275    editorslotname += "/";
02276    editorslotname += EditorName;
02277    TGo4Slot* edslot = fxOM->GetSlot(editorslotname.Data());
02278    if ((edslot==0) && force) {
02279       fxOM->AddProxy(fOMEditorsPath.latin1(), new TGo4WidgetProxy(widget), EditorName, "Links for Go4 widget");
02280       edslot = fxOM->GetSlot(editorslotname.Data());
02281    }
02282    return edslot;
02283 }
02284 
02285 void TGo4MainWindow::checkPanelRepaintSlot()
02286 {
02287    // block monitoring when start panel updates
02288    Browser()->SetMonitorBlockingFlag(kTRUE);
02289 
02290    fbPanelTimerActive = false;
02291 
02292    // first check if active viewpnael need update its content
02293    TGo4ViewPanel* actpanel = fxTGo4WorkSpace->GetActivePanel();
02294    if ((actpanel!=0) && actpanel->IsRepaintTimerActive())
02295       actpanel->checkRepaintSlot();
02296 
02297    if (fbPanelTimerActive) return;
02298 
02299    // now check if any other panel shold be repainted
02300    TGo4Slot* topslot = fxOM->GetSlot(fOMEditorsPath.latin1());
02301    for (int n=0;n<topslot->NumChilds();n++) {
02302       TGo4Slot* subslot = topslot->GetChild(n);
02303 
02304       TGo4WidgetProxy* wproxy =
02305           dynamic_cast<TGo4WidgetProxy*> (subslot->GetProxy());
02306       if (wproxy==0) continue;
02307 
02308       TGo4ViewPanel* panel =
02309         dynamic_cast<TGo4ViewPanel*> (wproxy->GetWidget());
02310 
02311       if ((panel!=0) && (panel!=actpanel))
02312         if (panel->IsRepaintTimerActive()) {
02313             panel->checkRepaintSlot();
02314             if (fbPanelTimerActive) return;
02315         }
02316    }
02317 
02318    // enable monitoring only when all drawing are finished
02319    Browser()->SetMonitorBlockingFlag(kFALSE);
02320 }
02321 
02322 //int temp_counter = 0;
02323 
02324 void TGo4MainWindow::editorServiceSlot(QGo4Widget* editor, int serviceid, const char* str, void* par)
02325 {
02326    if (editor==0) return;
02327 
02328    TGo4LockGuard lock;
02329 
02330    TGo4Slot* edslot = GetWidgetTopSlot(editor, false);
02331    if (edslot==0) return;
02332 
02333    switch (serviceid) {
02334       case QGo4Widget::service_DragEnter: {
02335          QDragEnterEvent* event = (QDragEnterEvent*) par;
02336          if (event==0) return;
02337          QString eventstr;
02338          if (!QTextDrag::decode(event, eventstr)) {
02339             event->ignore();
02340             return;
02341          }
02342 
02343          bool accept = false;
02344          if (event->source()==FindGo4Widget("Browser",false)) {
02345             int kind = Browser()->ItemKind(eventstr.latin1());
02346             TClass* cl = Browser()->ItemClass(eventstr.latin1());
02347             accept = editor->IsAcceptDrag(eventstr.latin1(), cl, kind);
02348          }
02349 
02350          if (accept) event->accept();
02351                 else event->ignore();
02352          break;
02353       }
02354 
02355       case QGo4Widget::service_DropEvent: {
02356          QDropEvent* event = (QDropEvent*) par;
02357          if (event==0) return;
02358          QString eventstr;
02359          if (!QTextDrag::decode(event, eventstr)) return;
02360          event->accept();
02361 
02362          if (event->source()==FindGo4Widget("Browser",false)) {
02363              int kind = Browser()->ItemKind(eventstr.latin1());
02364              TClass* cl = Browser()->ItemClass(eventstr.latin1());
02365 
02366              TGo4ViewPanel* panel = dynamic_cast<TGo4ViewPanel*> (editor);
02367              TGo4FitPanel* fitpanel = dynamic_cast<TGo4FitPanel*> (editor);
02368              if (panel!=0)
02369                 panel->DropOnPad((TPad*)str, eventstr.latin1(), cl, kind);
02370              else
02371              if (fitpanel!=0)
02372                 fitpanel->DropOnPanel(event, eventstr.latin1(), cl, kind);
02373              else
02374                 editor->DropItem(eventstr.latin1(), cl, kind);
02375          }
02376          break;
02377       }
02378 
02379       case QGo4Widget::service_CreateItem: {
02380          TClass* cl = (TClass*) par;
02381          int id = str!=0 ? atoi(str) : 0;
02382          if (cl!=0)
02383            if (cl->InheritsFrom(TH1::Class()))
02384               CreateNewHistSlot(id);
02385            else
02386            if (cl->InheritsFrom(TGo4Condition::Class()) && (id!=0))
02387               CreateNewConditionSlot(id==1);
02388            else
02389            if (cl->InheritsFrom(TGo4DynamicEntry::Class()) && (id!=0))
02390               CreateNewDynEntrySlot(id==1);
02391          break;
02392       }
02393       case QGo4Widget::service_DrawItem: {
02394          void** res = (void**) par;
02395          res[0] = DisplayBrowserItem(str, (TGo4ViewPanel*) res[0], (TPad*) res[1], *((bool*)res[2]), *((int*) res[3]), 0);
02396          break;
02397       }
02398 
02399       case QGo4Widget::service_WhereItemDrawn: {
02400          TGo4ViewPanel** res = (TGo4ViewPanel**) par;
02401          *res = 0;
02402 
02403          TGo4Slot* topslot = fxOM->GetSlot(fOMEditorsPath.latin1());
02404          for (int n=0;n<topslot->NumChilds();n++) {
02405             TGo4Slot* subslot = topslot->GetChild(n);
02406 
02407             TGo4WidgetProxy* wproxy =
02408                dynamic_cast<TGo4WidgetProxy*> (subslot->GetProxy());
02409             if (wproxy==0) continue;
02410 
02411             TGo4ViewPanel* panel =
02412                dynamic_cast<TGo4ViewPanel*> (wproxy->GetWidget());
02413 
02414             if (panel!=0)
02415               if (panel->FindPadWithItem(str)!=0) {
02416                 *res = panel;
02417                 break;
02418               }
02419          }
02420          break;
02421       }
02422 
02423       case QGo4Widget::service_UndrawItem: {
02424          TGo4Slot* topslot = fxOM->GetSlot(fOMEditorsPath.latin1());
02425 
02426          for (int n=0;n<topslot->NumChilds();n++) {
02427             TGo4Slot* subslot = topslot->GetChild(n);
02428 
02429             TGo4WidgetProxy* wproxy =
02430                dynamic_cast<TGo4WidgetProxy*> (subslot->GetProxy());
02431             if (wproxy==0) continue;
02432 
02433             TGo4ViewPanel* panel =
02434                dynamic_cast<TGo4ViewPanel*> (wproxy->GetWidget());
02435 
02436             if (panel!=0)
02437               panel->UndrawItemOnPanel(str);
02438          }
02439 
02440          break;
02441       }
02442 
02443       case QGo4Widget::service_EditItem: {
02444          TClass* cl = Browser()->ItemClass(str);
02445          Int_t kind = Browser()->ItemKind(str);
02446 
02447          if (kind==TGo4Access::kndGo4Param) {
02448             TGo4ParaEdit* paredit = StartParaEdit(str);
02449             break;
02450          } else
02451          if (kind==TGo4Access::kndTreeLeaf) {
02452             TGo4TreeViewer* tviewer =
02453                dynamic_cast<TGo4TreeViewer*> (FindGo4Widget("TreeViewer", false));
02454             if (tviewer!=0) {
02455                tviewer->WorkWithLeaf(str);
02456                tviewer->parentWidget()->show();
02457             }
02458             break;
02459          }
02460 
02461          if (cl==0) return;
02462 
02463          if (cl->InheritsFrom(TGo4Fitter::Class())) {
02464             TGo4FitPanel* fitpanel = StartFitPanel();
02465             TGo4ViewPanel* panel = dynamic_cast<TGo4ViewPanel*> (editor);
02466             fitpanel->WorkWithFitter(str, panel, panel==0 ? 0 : panel->GetActivePad());
02467          } else
02468          if (cl->InheritsFrom(TGo4Parameter::Class())) {
02469             TGo4ParaEdit* paredit = StartParaEdit(str);
02470          } else
02471          if (cl->InheritsFrom(TH1::Class())) {
02472             TGo4HistogramInfo* hinfo = StartHistogramInfo();
02473             hinfo->WorkWithHistogram(str);
02474          } else
02475          if (cl->InheritsFrom(TGo4Condition::Class())) {
02476             TGo4ConditionEditor* wedit = StartConditionEditor();
02477             wedit->WorkWithCondition(str);
02478          } else
02479          if (cl->InheritsFrom(TGo4DynamicEntry::Class())) {
02480             TGo4EditDynEntry* dedit = StartEditDynEntry();
02481             dedit->WorkWithEntry(str);
02482          }
02483          break;
02484       }
02485 
02486       case QGo4Widget::service_ShowInfo: {
02487         TClass* cl = Browser()->ItemClass(str);
02488         int kind = Browser()->ItemKind(str);
02489         if (kind==TGo4Access::kndEventElement) {
02490            TGo4EventInfo* einfo = StartEventInfo();
02491            einfo->WorkWithEvent(str);
02492            break;
02493         }
02494         if (cl==0) return;
02495         if (cl->InheritsFrom(TH1::Class())) {
02496            TGo4HistogramInfo* hinfo = StartHistogramInfo();
02497            hinfo->WorkWithHistogram(str);
02498         } else
02499         if (cl->InheritsFrom(TGo4Condition::Class())) {
02500            TGo4ConditionInfo* cinfo = StartConditionInfo();
02501            cinfo->WorkWithCondition(str);
02502         }
02503         break;
02504       }
02505 
02506       case QGo4Widget::service_EditInSlot: {
02507          TGo4Slot* slot = (TGo4Slot*) par;
02508          if (slot==0) break;
02509          TObject* obj = slot->GetAssignedObject();
02510          if (obj==0) break;
02511          if (obj->InheritsFrom(TGo4Fitter::Class())) {
02512             TGo4FitPanel* fitpanel = StartFitPanel();
02513             fitpanel->WorkWithFitterInSlot(slot);
02514          }
02515          break;
02516       }
02517 
02518       case QGo4Widget::service_SaveItem: {
02519          const char* subfolder = (const char*) par;
02520          bool* replace = (bool*) par;
02521          bool res = SaveBrowserItemToFile(str, subfolder);
02522          * ((char*) par) = res ? 1 : 0;
02523          break;
02524       }
02525 
02526       case QGo4Widget::service_UpdateAnalysisItem: {
02527          TObject** obj = (TObject**) par;
02528          Bool_t res = Browser()->UpdateAnalysisItem(str, *obj);
02529          if (res) *obj = (TObject*) 1; else *obj = 0;
02530          break;
02531       }
02532 
02533       case QGo4Widget::service_StatusMessage: {
02534           StatusMessage(str);
02535           break;
02536       }
02537 
02538       case QGo4Widget::service_CreateViewPanel: {
02539          TGo4ViewPanel** res = (TGo4ViewPanel**) par;
02540          *res = MakeNewPanel(atoi(str));
02541          break;
02542       }
02543 
02544       case QGo4Widget::service_BrowserItemRemote: {
02545          bool* res = (bool*) par;
02546          *res = Browser()->IsItemRemote(str);
02547          break;
02548       }
02549 
02550       case QGo4Widget::service_Browser: {
02551          TGo4BrowserProxy** res = (TGo4BrowserProxy**) par;
02552          *res= Browser();
02553          break;
02554       }
02555 
02556       case QGo4Widget::service_SaveToMemory: {
02557           TObject** obj = (TObject**) par;
02558           TString itemname = Browser()->SaveToMemory(str, *obj, true);
02559           QString** res = (QString**) par;
02560           *res = 0;
02561           if (itemname.Length()>0)
02562             *res = new QString(itemname.Data());
02563           break;
02564       }
02565 
02566       case QGo4Widget::service_GetAnalysis: {
02567          TGo4AnalysisProxy** res = (TGo4AnalysisProxy**) par;
02568          *res = Browser()->FindAnalysis(str);
02569          break;
02570       }
02571 
02572       case QGo4Widget::service_AddEditorLink: {
02573          TGo4Slot* brslot = Browser()->BrowserSlot((const char*)par);
02574 
02575          if (str==0) str = editor->name();
02576 
02577          TGo4Slot* link = fxOM->AddLink(brslot, edslot->GetFullName(),
02578                                         str, "link to browser item");
02579          if (link!=0)
02580             editor->SetLinkedName(link, (const char*)par);
02581 
02582          break;
02583       }
02584 
02585       case QGo4Widget::service_AddDirectLink: {
02586          //cout << " QGo4Widget::service_AddDirectLink " << endl;
02587          if (str==0) str = editor->name();
02588          TGo4Slot* slot = (TGo4Slot*) par;
02589          if (slot!=0) {
02590             //cout << "add link for " << str << " in edslot = " << edslot->GetFullName() << endl;
02591             fxOM->AddLink(slot, edslot->GetFullName(),
02592                           str, "direct link to OM slot");
02593             //edslot->Print("*");
02594          }
02595          break;
02596       }
02597 
02598       case QGo4Widget::service_AddLinkInSlot: {
02599          //cout << " QGo4Widget::service_AddLinkInSlot " << endl;
02600 
02601          TGo4Slot** res = (TGo4Slot**) par;
02602 
02603          TGo4Slot* parent = *res;
02604          *res = 0;
02605          if (parent==0) parent = edslot;
02606          TGo4Slot* brslot = Browser()->BrowserSlot(str);
02607 
02608          if (brslot!=0) {
02609             *res = fxOM->AddLink(brslot, parent->GetFullName(),
02610                                brslot->GetName(), "link in specific subfolder");
02611             if (*res!=0)
02612               editor->SetLinkedName(*res, str);
02613          }
02614          break;
02615       }
02616 
02617       case QGo4Widget::service_GetTopSlot: {
02618          TGo4Slot** res = (TGo4Slot**) par;
02619          *res = edslot;
02620          break;
02621       }
02622 
02623       case QGo4Widget::service_AddEditorSlot: {
02624          TGo4Slot* objslot = edslot->FindChild(str);
02625 
02626          if (objslot==0)
02627            objslot = fxOM->MakeObjSlot(edslot->GetFullName(), str, "Place for editor object");
02628          if (objslot!=0)
02629             objslot->SetProxy(new TGo4ObjectProxy);
02630 
02631          TGo4Slot** res = (TGo4Slot**) par;
02632          *res = objslot;
02633          break;
02634       }
02635 
02636       case QGo4Widget::service_SetLinkedName: {
02637          TGo4BrowserProxy::SetLinkedName((TGo4Slot*) par, str);
02638          break;
02639       }
02640 
02641       case QGo4Widget::service_GetLinkedName: {
02642          if (edslot==0) return;
02643          const char** res = (const char**) par;
02644          *res = TGo4BrowserProxy::GetLinkedName(edslot->FindChild(str));
02645          break;
02646       }
02647 
02648       case QGo4Widget::service_GetLinkedName2: {
02649          void** res = (void**) par;
02650          TGo4Slot* link = (TGo4Slot*) *res;
02651          *res = (void*) TGo4BrowserProxy::GetLinkedName(link);
02652          break;
02653       }
02654 
02655       case QGo4Widget::service_GetLinked0:
02656       case QGo4Widget::service_GetLinked1:
02657       case QGo4Widget::service_GetLinked2: {
02658          if (edslot==0) return;
02659          TGo4Slot* link = edslot->FindChild(str);
02660          if (link==0) return;
02661          const char* itemname = TGo4BrowserProxy::GetLinkedName(link);
02662          TObject** res = (TObject**) par;
02663          int updatelevel = serviceid - QGo4Widget::service_GetLinked0;
02664          if (itemname!=0)
02665             *res = Browser()->GetBrowserObject(itemname, updatelevel);
02666          else
02667             *res = link->GetAssignedObject();
02668          break;
02669       }
02670 
02671       case QGo4Widget::service_RemoveLink: {
02672          if (edslot==0) return;
02673          TGo4Slot* link = edslot->FindChild(str);
02674          if (link!=0) link->Delete();
02675          break;
02676       }
02677 
02678       case QGo4Widget::service_RemoveAllLinks: {
02679          if ((str==0) || (strcmp(str,"complete")!=0))
02680             edslot->DeleteChilds(str);
02681          else
02682             edslot->Delete();
02683          break;
02684       }
02685 
02686       case QGo4Widget::service_ObjectCreated: {
02687          TGo4Slot* slot = fxOM->GetSlot(fOMEditorsPath.latin1());
02688          for (int n=0;n<slot->NumChilds();n++) {
02689             TGo4Slot* subslot = slot->GetChild(n);
02690             if (edslot==subslot) continue;
02691 
02692             TGo4WidgetProxy* wproxy =
02693                dynamic_cast<TGo4WidgetProxy*>
02694                  (subslot->GetProxy());
02695 
02696             if (wproxy!=0)
02697               wproxy->GetWidget()->ObjectCreatedByWidget(str, (TClass*) par);
02698          }
02699          break;
02700       }
02701 
02702       case QGo4Widget::service_ConnectPad: {
02703          if (edslot==0) break;
02704 
02705          TGo4WidgetProxy* proxy =
02706            dynamic_cast<TGo4WidgetProxy*> (edslot->GetProxy());
02707          if (proxy!=0)
02708             proxy->ConnectPad((TPad*) par);
02709          break;
02710       }
02711 
02712       case QGo4Widget::service_LastActivePanel: {
02713          TGo4ViewPanel** res = (TGo4ViewPanel**) par;
02714          *res = fxTGo4WorkSpace->GetActivePanel();
02715          break;
02716       }
02717 
02718       case QGo4Widget::service_General: {
02719         if (strcmp(str,"CloseAnalysisWindow")==0) {
02720             // we should postpone window closing, while it is called from inside window itself
02721             // and it is create problem in sequence,
02722            QTimer::singleShot(100, this, SLOT(CloseAnalysisWindow()));
02723         } else
02724 
02725         if (strcmp(str,"PrintAnalysisHistograms")==0) {
02726            TGo4AnalysisWindow* anw = FindAnalysisWindow();
02727            if (anw!=0) anw->PrintHistograms();
02728         } else
02729 
02730         if (strcmp(str,"PrintAnalysisConditions")==0) {
02731            TGo4AnalysisWindow* anw = FindAnalysisWindow();
02732            if (anw!=0) anw->PrintConditions();
02733         } else
02734 
02735         if (strcmp(str,"DisplayMbsMonitor")==0) {
02736            ToggleMbsMonitor((const char*) par);
02737         } else
02738 
02739         if (strcmp(str,"SubmitAnalysisSettings")==0) {
02740            SubmitAnalysisSettings();
02741         } else
02742 
02743         if (strcmp(str,"SubmitStartAnalysis")==0) {
02744            SubmitStartAnalysisSlot();
02745         } else
02746 
02747         if (strcmp(str,"StartAnalysis")==0) {
02748           StartAnalysisSlot();
02749         } else
02750 
02751         if (strcmp(str,"StopAnalysis")==0) {
02752           StopAnalysisSlot();
02753         } else
02754 
02755         if (strcmp(str,"TerminateAnalysis")==0) {
02756            TerminateAnalysis();
02757         } else
02758 
02759         if (strcmp(str,"UpdateGuiLayout")==0) {
02760           UpdateCaptionButtons();
02761         } else
02762 
02763         if (strcmp(str, "StartEventInfo")==0) {
02764            StartEventInfo();
02765         } else
02766 
02767         if (strcmp(str, "ActivateConditionEditor")==0) {
02768            TGo4ConditionEditor* w =
02769              (TGo4ConditionEditor*) FindGo4Widget("ConditionEditor", true);
02770            if (w!=0) {
02771               w->setFocus();
02772               w->RefreshWidget(true);
02773            }
02774         } else
02775 
02776         if (strcmp(str, "SavePanelCanvas")==0) {
02777            SavePanelCanvas(dynamic_cast<TGo4ViewPanel*>(editor));
02778         } else
02779 
02780         if (strcmp(str, "ToggleScaleValues")==0) {
02781            ToggleScaleValues();
02782         } else
02783 
02784         if (strcmp(str, "GetFitterFromFitPanel")==0) {
02785            TGo4FitPanel* panel = (TGo4FitPanel*) FindGo4Widget("FitPanel", false);
02786            TGo4Fitter** res = (TGo4Fitter**) par;
02787            if ((panel!=0) && (res!=0))
02788               *res = panel->GetFitter();
02789         } else
02790 
02791         if (strcmp(str, "CloneFitterFromFitPanel")==0) {
02792            TGo4FitPanel* panel = (TGo4FitPanel*) FindGo4Widget("FitPanel", false);
02793            TGo4Fitter** res = (TGo4Fitter**) par;
02794            if ((panel!=0) && (res!=0))
02795               *res = panel->CloneFitter();
02796         }
02797 
02798         break;
02799       }
02800 
02801       case QGo4Widget::service_PanelTimer: {
02802          TGo4ViewPanel* panel = (TGo4ViewPanel*) editor;
02803 //         int interval = (int) par;
02804          if (!fbPanelTimerActive) {
02805            fbPanelTimerActive = true;
02806            QTimer::singleShot(0, this, SLOT(checkPanelRepaintSlot()));
02807          }
02808 
02809          break;
02810       }
02811 
02812       case QGo4Widget::service_HelpWindow: {
02813          QString msg = "Loading help from ";
02814          msg+=str;
02815          HelpWindow(str, (const char*) par, msg.latin1());
02816          break;
02817       }
02818 
02819       case QGo4Widget::panel_Activated:
02820       case QGo4Widget::panel_Modified:
02821       case QGo4Widget::panel_Updated:
02822       case QGo4Widget::panel_ActiveUpdated:
02823       case QGo4Widget::panel_PadDeleted:
02824       case QGo4Widget::panel_Deleted: {
02825          TGo4ViewPanel* panel = (TGo4ViewPanel*) editor;
02826          TPad* pad = (TPad*) par;
02827          fxTGo4WorkSpace->ResponseOnPanelEvent(serviceid, panel, pad);
02828          break;
02829       }
02830 
02831    }
02832 }
02833 
02834 // ******************** hot start functions *********************
02835 
02836 void TGo4MainWindow::HotStart(const char* fname)
02837 {
02838    if (fname==0) return;
02839 
02840    TGo4Script* exec = TGo4Script::ScriptInstance();
02841    if(exec==0) return;
02842 
02843    if (!exec->StartScriptExecution(fname)) return;
02844 
02845    QTimer::singleShot(TGo4Script::DelayMillisec(), this, SLOT(ProcessHotStart()));
02846 }
02847 
02848 void TGo4MainWindow::ProcessHotStart()
02849 {
02850    TGo4Script* exec = TGo4Script::ScriptInstance();
02851    if (exec==0) return;
02852 
02853    Bool_t res = kTRUE;
02854    do {
02855       res = exec->ContinueExecution();
02856    } while(res && !exec->IsWaitSomething());
02857 
02858    if (res) {
02859       QTimer::singleShot(TGo4Script::DelayMillisec(), this, SLOT(ProcessHotStart()));
02860       if (QApplication::overrideCursor()==0)
02861         QApplication::setOverrideCursor(Qt::WaitCursor);
02862    } else {
02863       exec->FinishExecution();
02864       StatusMessage("Script execution done");
02865       QApplication::restoreOverrideCursor();
02866    }
02867 }
02868 
02869 void TGo4MainWindow::StopGUIScriptSlot()
02870 {
02871    TGo4Script* exec = TGo4Script::ScriptInstance();
02872    if (exec!=0) exec->FinishExecution();
02873 }
02874 
02875 void TGo4MainWindow::CreateGUIScriptSlot()
02876 {
02877    QString ext = TGo4Script::FileExtension();
02878    QString fileName = QFileDialog::getSaveFileName(
02879         fLastFileDir, QString("GUI hotstart script (*") + ext + ")", this,
02880         "Create GUI script dialog", "Choose a file to be created");
02881    if (fileName.length()==0) return;
02882 
02883    int pos = fileName.find(ext);
02884 
02885    if ((pos<0) || (pos!=fileName.length()-strlen(ext)))
02886      fileName+=ext;
02887 
02888    StatusMessage(QString("Generate script ")+fileName);
02889 
02890    TGo4Script::ProduceScript(fileName.latin1(), this);
02891 }
02892 
02893 void TGo4MainWindow::ProcessQtEvents()
02894 {
02895    if (fApp!=0) fApp->processEvents(TGo4Script::DelayMillisec());
02896 }
02897 
02898 TGo4ViewPanel* TGo4MainWindow::FindViewPanel(const char* name)
02899 {
02900    if ((name==0) || (*name==0)) return 0;
02901 
02902    TGo4ViewPanel* panel = dynamic_cast<TGo4ViewPanel*> (FindGo4Widget(name, false));
02903 
02904    if (panel!=0) return panel;
02905 
02906    TGo4Slot* slot = fxOM->GetSlot(fOMEditorsPath.latin1());
02907 
02908    for (Int_t n=0;n<slot->NumChilds();n++) {
02909       TGo4Slot* widgslot = slot->GetChild(n);
02910       TGo4WidgetProxy* wproxy = widgslot==0 ? 0 : dynamic_cast<TGo4WidgetProxy*> (widgslot->GetProxy());
02911       panel = wproxy==0 ? 0 : dynamic_cast<TGo4ViewPanel*> (wproxy->GetWidget());
02912 
02913       if (panel!=0)
02914         if (strcmp(panel->GetPanelName(), name)==0) return panel;
02915    }
02916 
02917    return 0;
02918 }
02919 
02920 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:21 2008 for Go4-v3.04-1 by  doxygen 1.4.2