histaction.cxx

Go to the documentation of this file.
00001 //---------------------------------------------------------------
00002 //
00003 //      Control Panel for histogram operations
00004 //      Demo version
00005 //
00006 //      Author: Dmitry Vasiliev (LNS, Catania)
00007 //
00008 //---------------------------------------------------------------
00009 
00010 #include "histaction.h"
00011 #include <TCollection.h>
00012 #include <TFile.h>
00013 #include <TKey.h>
00014 #include <TROOT.h>
00015 #include <TGMsgBox.h>
00016 #include <TSystem.h>
00017 #include <TH1.h>
00018 #include "canvsave.h"
00019 #include <TCanvas.h>
00020 
00021 #if !defined S_ISDIR
00022 #define S_ISDIR(m) (((m)&(0170000)) == (0040000))
00023 #endif
00024 
00025 ClassImp(HistAction)
00026 
00027 
00028 Bool_t kSTATUS; //to suppress call of drawHist() when no histo is highlighted
00029                 //in ListBoxA
00030 TCanvas *cA;    //canvas in fCanvasA
00031 TCanvas *cB;    //canvas in fCanvasB
00032 TH1F *hist;     //clone histo in Scan panel
00033 TH1F *temph;    //bin highlight in canvas cB
00034 Long_t cursA, cursB; //current position in ListBoxA and ListBoxB
00035 Int_t totalA, totalB;  //total number of entries in ListBoxA and ListBoxB
00036 Int_t *array;     //array of non empty bins of a histo under scan
00037 Int_t count;      //number of user highlighted buttons in Display Layout
00038 Int_t indi[2];    //survice arrays for algorithm which calculates
00039 Int_t indj[2];    //display layout
00040 
00041 
00042 HistAction::HistAction(const TGWindow *p, UInt_t w, UInt_t h) :
00043       TGMainFrame(p, w, h)
00044 {
00045    //--------------------------------------------------------------------
00046    // Constructor for the class HistAction. Draws a control panel, divides it
00047    // into sub areas and maps all subwindows
00048    //--------------------------------------------------------------------
00049 
00050 
00051    Int_t i;
00052 
00053    for (i = 0; i < 16; i++) {
00054       pads[i] = NULL;
00055       histInd[i] = -1;
00056    }
00057    fHisto = new TObjArray(kMaxHist);
00058    position = 0;
00059    totalA = 0;
00060    resetIter();
00061    resetFlags();
00062 
00063 
00064    /*
00065 
00066                                 --------------------------
00067                                 |                        |
00068                                 |                        |
00069                                 -------------fF0----------
00070                                 |                        |
00071                                 --------------------------
00072                                /                         \
00073                        ---------------               -------------------
00074                        |      |      |               |Import \ Scan    |
00075                        |     fFA     |               |        ---------|
00076                        |      |      |               |                 |
00077                        |      |      |               |      fTab       |
00078                        ---------------               -------------------
00079 
00080    */
00081 
00082 
00083    fF0 = new TGCompositeFrame(this, 200, 20, kVerticalFrame);
00084    AddFrame(fF0, new TGLayoutHints(kLHintsLeft | kLHintsTop));
00085 
00086 
00087    fFA = new TGCompositeFrame(fF0, 200, 20, kHorizontalFrame);
00088    fF0->AddFrame(fFA, new TGLayoutHints(kLHintsTop | kLHintsLeft));
00089 
00090 
00091    fTab = new TGTab(fF0, 200, 20);
00092    fF0->AddFrame(fTab, new TGLayoutHints(kLHintsLeft | kLHintsTop));
00093 
00094    /*
00095    //-------------------------------------------------------------------
00096    //
00097    //  Panel A (main presentation canvas, list box with the names of
00098    //           histogrammes, control buttons, display layout, close button)
00099    //
00100    //-------------------------------------------------------------------
00101    //
00102    //
00103    //               --------------------
00104    //               |      |           |
00105    //               |     fFA          |
00106    //               |      |           |
00107    //               --------------------
00108    //              /                    \
00109    //   ---------------            ----------------
00110    //   |             |            |              |
00111    //   |             |            |----fA1-------|
00112    //   |  fCanvasA   |            |              |
00113    //   |             |            |              |
00114    //   ---------------            ----------------
00115    //                              /               \
00116    //                             /                 \
00117    //                      ---------------       ----------------
00118    //                      |             |       |      |       |
00119    //              Control |     fA2     |       |      |       |
00120    //              Buttons |             |       |     fA3      |
00121    //                      |Matrix Layout|       |      |       |
00122    //                      |             |       |      |       |
00123    //                      ---------------       ----------------
00124    //                                           /               \
00125    //                                          /                 \  fA4
00126    //                                 --------------         --------------
00127    //                                 |            |         |fMultiButton|
00128    //                                 |            |         |------------|
00129    //                                 | fListBoxA  |         |fPrevButtonA|
00130    //                                 |            |         |------------|
00131    //                                 |            |         |fNextButtonA|
00132    //                                 --------------         |------------|
00133    //                                                        |fA5(Display |
00134    //                                                        |    Layout) |
00135    //                                                        |------------|
00136    //                                                        |fCloseButton|
00137    //                                                        --------------
00138    //
00139    //------------------------------------------------------------------------
00140    */
00141 
00142    fCanvasA = new TRootEmbeddedCanvas("canvasA", fFA, 400, 400);
00143    fFA->AddFrame(fCanvasA, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
00144    cA = fCanvasA->GetCanvas();
00145    //cA->SetCanvasSize(396,396);
00146    cA->SetFillColor(10);
00147 
00148 
00149    fA1 = new TGCompositeFrame(fFA, 100, 20, kVerticalFrame);
00150    fFA->AddFrame(fA1, new TGLayoutHints(kLHintsTop | kLHintsLeft));
00151 
00152 
00153    fA2 = new TGGroupFrame(fA1, "Control Buttons", kHorizontalFrame);
00154    fA2->SetLayoutManager(new TGMatrixLayout(fA2, 0, 3, 8));
00155    fA1->AddFrame(fA2, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
00156 
00157 
00158    fA3 = new TGCompositeFrame(fA1, 200, 50, kHorizontalFrame);
00159    fA1->AddFrame(fA3, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
00160 
00161 
00162    fListBoxA = new TGListBox(fA3, M_LIST_A);
00163    fListBoxA->Associate(this);
00164    fA3->AddFrame(fListBoxA, new TGLayoutHints(kLHintsTop | kLHintsLeft));
00165    fListBoxA->Resize(140, 305);
00166    fListBoxA->Connect("DoubleClicked(char*)", "HistAction", this, "doubleclickedBoxA(char*)");
00167 
00168 
00169    fA4 = new TGCompositeFrame(fA3, 100, 20, kVerticalFrame);
00170    fA3->AddFrame(fA4, new TGLayoutHints(kLHintsTop | kLHintsLeft));
00171 
00172 
00173    fMultiButton = new TGCheckButton(fA4, "Multiple selection", M_MULTI);
00174    fMultiButton->Associate(this);
00175    fMultiButton->SetState(kButtonUp);
00176    fA4->AddFrame(fMultiButton, new TGLayoutHints(kLHintsTop | kLHintsLeft,
00177                  5, 5, 5, 5));
00178 
00179 
00180    fPrevButtonA = new TGTextButton(fA4, "Previous", M_PREV_A);
00181    fPrevButtonA->Associate(this);
00182    fA4->AddFrame(fPrevButtonA, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00183                  10, 5, 5, 5));
00184 
00185 
00186    fNextButtonA = new TGTextButton(fA4, "   Next   ", M_NEXT_A);
00187    fNextButtonA->Associate(this);
00188    fA4->AddFrame(fNextButtonA, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00189                  10, 5, 5, 5));
00190 
00191 
00192    fA5 = new TGGroupFrame(fA4, "Display Layout", kVerticalFrame);
00193    fA4->AddFrame(fA5, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 5, 5));
00194    fA5->SetLayoutManager(new TGMatrixLayout(fA5, 0, 4, kVerticalFrame));
00195 
00196 
00197    for (i = 0;i < 16;i++) {
00198       fLayoutButton[i] = new TGTextButton(fA5, "     ", 500 + i);
00199       fLayoutButton[i]->Associate(this);
00200       fA5->AddFrame(fLayoutButton[i], new TGLayoutHints(kLHintsTop | kLHintsLeft,
00201                     5, 5, 5, 5));
00202    }
00203 
00204 
00205    fDrawButton = new TGTextButton(fA2, "Draw", M_DRAW);
00206    fDrawButton->Associate(this);
00207    fDrawButton->Resize(65, fDrawButton->GetDefaultHeight());
00208    fA2->AddFrame(fDrawButton);
00209 
00210 
00211    fSelectButton = new TGTextButton(fA2, "Select All", M_SELECT);
00212    fSelectButton->Associate(this);
00213    fSelectButton->Resize(65, fSelectButton->GetDefaultHeight());
00214    fA2->AddFrame(fSelectButton);
00215 
00216 
00217    fClearButtonA = new TGTextButton(fA2, "Clear", M_CLEAR_A);
00218    fClearButtonA->Associate(this);
00219    fClearButtonA->Resize(65, fClearButtonA->GetDefaultHeight());
00220    fA2->AddFrame(fClearButtonA);
00221 
00222 
00223    fSaveButton = new TGTextButton(fA2, "Save Pic", M_SAVE);
00224    fSaveButton->Associate(this);
00225    fSaveButton->Resize(65, fSaveButton->GetDefaultHeight());
00226    fA2->AddFrame(fSaveButton);
00227 
00228 
00229    fEditButton = new TGTextButton(fA2, "Edit Pic", M_EDIT);
00230    fEditButton->Associate(this);
00231    fEditButton->Resize(65, fEditButton->GetDefaultHeight());
00232    fA2->AddFrame(fEditButton);
00233 
00234 
00235    fCloseButton = new TGTextButton(fA4, "Close Window", M_CLOSE);
00236    fCloseButton->Associate(this);
00237    SetWindowAttributes_t wattr;
00238    wattr.fMask = kWABackPixel;
00239    gClient->GetColorByName("red", wattr.fBackgroundPixel);
00240    gVirtualX->ChangeWindowAttributes(fCloseButton->GetId(), &wattr);
00241    fA4->AddFrame(fCloseButton, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00242                  kLHintsCenterX, 0, 0, 40, 5));
00243 
00244 
00245    /*
00246    //---------------------------------------------------------------------
00247    //
00248    // Panel C (File Manager)
00249    //
00250    //---------------------------------------------------------------------
00251    //
00252    //
00253    //                   ----------------------------------
00254    //                   |                                |
00255    //                   |  tf = fTab->AddTab("Import")   |
00256    //                   |                                |
00257    //                   ----------------------------------
00258    //                    /                             \
00259    //                   /                               \
00260    //          ----------------------              ----------------------
00261    //          |  |  |    |    |    |              |                    |
00262    //          |  |  | fC1|    |    |              |        fC2         |
00263    //          |  |  |    |    |    |              |                    |
00264    //          ----------------------              ----------------------
00265    //         /    |    |     |      \                         |
00266    //   ------  -----  -----  -----  ---------     ----------------------
00267    //   |    |  |   |  |   |  |   |  |       |     |                    |
00268    //   |fDir|  |   |  |   |  |   |  |fFilter|     |       fFileView    |
00269    //   |    |  |   |  |   |  |   |  |  Box  |     |                    |
00270    //   ------  -----  -----  -----  ---------     ----------------------
00271    //           fCdup  fList  fDetail
00272    //                   Mode   Mode
00273    //
00274    //
00275    //----------------------------------------------------------------------
00276    */
00277 
00278    TGCompositeFrame *tf = fTab->AddTab("Import");
00279    fC1 = new TGCompositeFrame(tf, 500, 50, kHorizontalFrame);
00280    tf->AddFrame(fC1, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5));
00281 
00282 
00283    fC2 = new TGCompositeFrame(tf, 500, 300, kVerticalFrame);
00284    tf->AddFrame(fC2, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5));
00285 
00286 
00287    fDir = new TGListBox(fC1, -1);
00288    //fDir->Associate(this);
00289    fDir->Resize(400, 20);
00290    TString tmp;
00291    tmp.Form("%s", gSystem->WorkingDirectory());
00292    fDir->AddEntry(tmp, 1);
00293    fC1->AddFrame(fDir, new TGLayoutHints(kLHintsLeft | kLHintsTop, 2, 2, 2, 2));
00294 
00295 
00296    fPcdup = fClient->GetPicture("tb_uplevel.xpm");
00297    fCdup = new TGPictureButton(fC1, fPcdup, M_CDUP);
00298    fCdup->SetToolTipText("Up One Level");
00299    fCdup->Associate(this);
00300    fC1->AddFrame(fCdup, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5));
00301 
00302 
00303    fPlist = fClient->GetPicture("tb_list.xpm");
00304    fListMode = new TGPictureButton(fC1, fPlist, M_LIST_MODE);
00305    fListMode->SetToolTipText("List Mode");
00306    fListMode->Associate(this);
00307    fListMode->SetState(kButtonUp);
00308    fListMode->AllowStayDown(kTRUE);
00309    fC1->AddFrame(fListMode, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5));
00310 
00311 
00312    fPdetail = fClient->GetPicture("tb_details.xpm");
00313    fDetailMode = new TGPictureButton(fC1, fPdetail, M_DETAIL_MODE);
00314    fDetailMode->SetToolTipText("Details Mode");
00315    fDetailMode->Associate(this);
00316    fDetailMode->SetState(kButtonEngaged);
00317    fDetailMode->AllowStayDown(kTRUE);
00318    fC1->AddFrame(fDetailMode, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00319                  5, 5, 5, 5));
00320 
00321 
00322    fC1->AddFrame(new TGLabel(fC1, new TGHotString("Filter:")),
00323                  new TGLayoutHints(kLHintsLeft | kLHintsTop, 10, 5, 5, 5));
00324 
00325 
00326    fFilterBox = new TGComboBox(fC1, M_FILTER);
00327    fFilterBox->Associate(this);
00328    char filt[50];
00329    snprintf(filt,50, "%s", "All files  (*)");
00330    fFilterBox->AddEntry(filt, 1);
00331    snprintf(filt,50, "%s", "ROOT files  (*.root)");
00332    fFilterBox->AddEntry(filt, 2);
00333    fFilterBox->Resize(150, 20);
00334    fFilterBox->Select(2);
00335    fC1->AddFrame(fFilterBox, new TGLayoutHints(kLHintsLeft | kLHintsTop, 5, 5, 5, 5));
00336 
00337 
00338    fFileView = new TGListView(fC2, 540, 180);
00339    fFileCont = new TGFileContainer(fFileView->GetViewPort(), 100, 100,
00340                                    kVerticalFrame, GetWhitePixel());
00341    fFileCont->Associate(this);
00342    fFileView->GetViewPort()->SetBackgroundColor(GetWhitePixel());
00343    fFileView->SetContainer(fFileCont);
00344    fFileCont->SetFilter("*.root");
00345    fFileCont->ChangeDirectory(".");
00346    fFileView->SetViewMode(kLVDetails);
00347    fFileCont->Sort(kSortByName);
00348    fC2->AddFrame(fFileView, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00349                  2, 2, 2, 2));
00350 
00351 
00352    /*
00353    //---------------------------------------------------------------------
00354    //
00355    //  Panel B (histo presentation canvas, list box with the indices of non
00356    //           empty bins, control buttons, fields for displaying digital
00357    //           information about a histogram)
00358    //
00359    //---------------------------------------------------------------------
00360    //
00361    //
00362    //                        ------------------------------
00363    //                        |                            |
00364    //                        |  tf = fTab->AddTab("Scan") |
00365    //                        |                            |
00366    //                        ------------------------------
00367    //                                      |
00368    //                        ------------------------------
00369    //                        |         |         |        |
00370    //                        |         |   fFB   |        |
00371    //                        |         |         |        |
00372    //                        ------------------------------
00373    //                       /              |               \
00374    //                 fB1  /               |                \
00375    //              ------------      -------------     -----------------
00376    //              | fName    |      |           |     |               |
00377    //              |----------|      |  fCanvasB |     |-----fB2-------|
00378    //              | fTitle   |      |           |     |               |
00379    //      Matrix  |----------|      -------------     -----------------
00380    //      Layout  | fChan    |                       /                \
00381    //              |----------|                      /                  \
00382    //              | fRange   |             ---------------         -------------
00383    //              |----------|             |     |       |         |           |
00384    //              | fEntries |             |    fB4      |         |----fB3----|
00385    //              ------------             |     |       |         |           |
00386    //                                       ---------------         -------------
00387    //                                      /           |           /          |
00388    //                                     /            |          /           |
00389    //                               -----------   ----------   --------   -------
00390    //                               |         |   |        |   |      |   |     |
00391    //                               | fList   |   |   fB5  |   | fBin |   |fBin |
00392    //                               |  BoxB   |   |        |   | Cont |   |Range|
00393    //                               |         |   | Matrix |   |      |   |     |
00394    //                               -----------   | Layout |   --------   -------
00395    //                                             |        |
00396    //                                             ----------
00397    //                                               Control
00398    //                                               Buttons
00399    //
00400    //
00401    //--------------------------------------------------------------------------
00402    */
00403 
00404    tf = fTab->AddTab("Scan");
00405    fFB = new TGGroupFrame(tf, "Scan Panel", kHorizontalFrame);
00406    tf->AddFrame(fFB, new TGLayoutHints(kLHintsTop | kLHintsLeft));
00407 
00408 
00409    fB1 = new TGGroupFrame(fFB, "General Histo Info", kVerticalFrame);
00410    fB1->SetLayoutManager(new TGMatrixLayout(fB1, 0, 2, 10));
00411    fFB->AddFrame(fB1, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00412                                         kLHintsExpandY));
00413 
00414 
00415    fCanvasB = new TRootEmbeddedCanvas("canvasB", fFB, 200, 200);
00416    fFB->AddFrame(fCanvasB, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00417                  kLHintsExpandX | kLHintsExpandY,
00418                  5, 5, 5, 5));
00419    cB = fCanvasB->GetCanvas();
00420    cB->SetFillColor(10);
00421 
00422 
00423    fB2 = new TGCompositeFrame(fFB, 100, 100, kVerticalFrame);
00424    fFB->AddFrame(fB2, new TGLayoutHints(kLHintsTop | kLHintsLeft |
00425                                         kLHintsExpandY));
00426 
00427 
00428    fB2->AddFrame(new TGLabel(fB2, new TGHotString("Non empty bins")),
00429                  new TGLayoutHints(kLHintsLeft | kLHintsTop));
00430 
00431 
00432    fB4 = new TGCompositeFrame(fB2, 220, 100, kHorizontalFrame);
00433    fB2->AddFrame(fB4, new TGLayoutHints(kLHintsTop | kLHintsLeft));
00434 
00435 
00436    fListBoxB = new TGListBox(fB4, M_LIST_B);
00437    fListBoxB->Associate(this);
00438    fB4->AddFrame(fListBoxB, new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 0, 5, 0));
00439    fListBoxB->Resize(70, 100);
00440 
00441 
00442    fB5 = new TGGroupFrame(fB4, "Control Buttons", kVerticalFrame);
00443    fB5->SetLayoutManager(new TGMatrixLayout(fB5, 0, 2, 10));
00444    fB4->AddFrame(fB5, new TGLayoutHints(kLHintsTop | kLHintsLeft, 20, 0, 0, 0));
00445 
00446 
00447    fPrevButtonB = new TGTextButton(fB5, "Previous", M_PREV_B);
00448    fPrevButtonB->Associate(this);
00449    fPrevButtonB->Resize(55, fPrevButtonB->GetDefaultHeight());
00450    fB5->AddFrame(fPrevButtonB, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00451                  10, 1, 5, 5));
00452 
00453 
00454    fGetButton = new TGTextButton(fB5, "Import", M_IMPORT);
00455    fGetButton->Associate(this);
00456    fGetButton->Resize(55, fGetButton->GetDefaultHeight());
00457    fB5->AddFrame(fGetButton, new TGLayoutHints(kLHintsTop | kLHintsLeft,
00458                  1, 2, 5, 5));
00459 
00460 
00461    fNextButtonB = new TGTextButton(fB5, "Next", M_NEXT_B);
00462    fNextButtonB->Associate(this);
00463    fNextButtonB->Resize(55, fNextButtonB->GetDefaultHeight());
00464    fB5->AddFrame(fNextButtonB, new TGLayoutHints(kLHintsLeft | kLHintsTop,
00465                  10, 1, 5, 5));
00466 
00467 
00468    fClearButtonB = new TGTextButton(fB5, "Clear", M_CLEAR_B);
00469    fClearButtonB->Associate(this);
00470    fClearButtonB->Resize(55, fClearButtonB->GetDefaultHeight());
00471    fB5->AddFrame(fClearButtonB, new TGLayoutHints(kLHintsTop | kLHintsLeft,
00472                  1, 2, 5, 5));
00473 
00474 
00475    fB3 = new TGCompositeFrame(fB2, 100, 20, kVerticalFrame);
00476    fB3->SetLayoutManager(new TGMatrixLayout(fB3, 0, 2, 10));
00477    fB2->AddFrame(fB3, new TGLayoutHints(kLHintsTop | kLHintsLeft));
00478 
00479 
00480    fB1->AddFrame(new TGLabel(fB1, new TGHotString("Name")),
00481                  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00482 
00483 
00484    fName = new TGTextEntry(fB1, fNameBuf = new TGTextBuffer(100), -1);
00485    fB1->AddFrame(fName, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 2, 2, 2));
00486    fName->Resize(100, fName->GetDefaultHeight());
00487 
00488 
00489    fB1->AddFrame(new TGLabel(fB1, new TGHotString("Title")),
00490                  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00491 
00492 
00493    fTitle = new TGTextEntry(fB1, fTitleBuf = new TGTextBuffer(100), -1);
00494    fB1->AddFrame(fTitle, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 2, 2, 2));
00495    fTitle->Resize(100, fTitle->GetDefaultHeight());
00496 
00497 
00498    fB1->AddFrame(new TGLabel(fB1, new TGHotString("Channels")),
00499                  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00500 
00501 
00502    fChan = new TGTextEntry(fB1, fChanBuf = new TGTextBuffer(100), -1);
00503    fB1->AddFrame(fChan, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 2, 2, 2));
00504    fChan->Resize(100, fChan->GetDefaultHeight());
00505 
00506 
00507    fB1->AddFrame(new TGLabel(fB1, new TGHotString("Range")),
00508                  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00509 
00510 
00511    fRange = new TGTextEntry(fB1, fRangeBuf = new TGTextBuffer(100), -1);
00512    fB1->AddFrame(fRange, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 2, 2, 2));
00513    fRange->Resize(100, fRange->GetDefaultHeight());
00514 
00515 
00516    fB1->AddFrame(new TGLabel(fB1, new TGHotString("Entries")),
00517                  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00518 
00519 
00520    fEntries = new TGTextEntry(fB1, fEntriesBuf = new TGTextBuffer(100), -1);
00521    fB1->AddFrame(fEntries, new TGLayoutHints(kLHintsTop | kLHintsLeft, 10, 2, 2, 2));
00522    fEntries->Resize(100, fEntries->GetDefaultHeight());
00523 
00524 
00525    fB3->AddFrame(new TGLabel(fB3, new TGHotString("Bin content")),
00526                  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00527 
00528 
00529    fBinCont = new TGTextEntry(fB3, fBinContBuf = new TGTextBuffer(100), -1);
00530    fB3->AddFrame(fBinCont, new TGLayoutHints(kLHintsTop | kLHintsLeft,
00531                  0, 2, 2, 2));
00532    fBinCont->Resize(110, fBinCont->GetDefaultHeight());
00533 
00534 
00535    fB3->AddFrame(new TGLabel(fB3, new TGHotString("Bin range")),
00536                  new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX));
00537 
00538 
00539    fBinRange = new TGTextEntry(fB3, fBinRangeBuf = new TGTextBuffer(100), -1);
00540    fB3->AddFrame(fBinRange, new TGLayoutHints(kLHintsTop | kLHintsLeft,
00541                  0, 2, 2, 2));
00542    fBinRange->Resize(110, fBinRange->GetDefaultHeight());
00543 
00544 
00545    //----------------------------------------------------------------
00546 
00547    MapSubwindows();
00548 
00549    SetWindowName("Histogram Viewer");
00550 
00551    Resize(GetDefaultSize());
00552    MapWindow();
00553 }
00554 
00555 HistAction::~HistAction()
00556 {
00557    //----------------------------------------------------------
00558    //
00559    //    Destructor for the class HistAction
00560    //
00561    //----------------------------------------------------------
00562 
00563    delete fCloseButton;
00564    delete fDrawButton;
00565    delete fGetButton;
00566    delete fSelectButton;
00567    delete fSaveButton;
00568    delete fEditButton;
00569    delete fClearButtonB;
00570    delete fClearButtonA;
00571    delete fPrevButtonA;
00572    delete fNextButtonA;
00573    delete fPrevButtonB;
00574    delete fNextButtonB;
00575    delete fMultiButton;
00576    delete fCdup;
00577    delete fListMode;
00578    delete fDetailMode;
00579    delete fLayoutButton[0];
00580    delete fLayoutButton[1];
00581    delete fLayoutButton[2];
00582    delete fLayoutButton[3];
00583    delete fLayoutButton[4];
00584    delete fLayoutButton[5];
00585    delete fLayoutButton[6];
00586    delete fLayoutButton[7];
00587    delete fLayoutButton[8];
00588    delete fLayoutButton[9];
00589    delete fLayoutButton[10];
00590    delete fLayoutButton[11];
00591    delete fLayoutButton[12];
00592    delete fLayoutButton[13];
00593    delete fLayoutButton[14];
00594    delete fLayoutButton[15];
00595    delete fListBoxA;
00596    delete fListBoxB;
00597    delete fFilterBox;
00598    delete fDir;
00599    delete fName;
00600    delete fTitle;
00601    delete fChan;
00602    delete fRange;
00603    delete fEntries;
00604    delete fBinCont;
00605    delete fBinRange;
00606    delete fC1;
00607    delete fC2;
00608    delete fTab;
00609    delete fA5;
00610    delete fA4;
00611    delete fA3;
00612    delete fA2;
00613    delete fCanvasA;
00614    delete fA1;
00615    delete fB5;
00616    delete fB4;
00617    delete fB3;
00618    delete fB2;
00619    delete fCanvasB;
00620    delete fB1;
00621    delete fFA;
00622    delete fFB;
00623    delete fF0;
00624 }
00625 
00626 void HistAction::CloseWindow()
00627 {
00628    //-----------------------------------------------------
00629    //
00630    //           CloseWindow()
00631    //
00632    //     Closes the panel "Histogram Viewer"
00633    //
00634    //-----------------------------------------------------
00635 
00636    delete this;
00637 
00638 }
00639 
00640 Bool_t HistAction::importHist(const char *name)
00641 {
00642    //------------------------------------------------------------------
00643    //
00644    //               importHist(const char *name)
00645    //
00646    // Allows to import an existing histogram from the memory
00647    // (needs histo name as an input parameter).
00648    // This function is not used in GUI at the moment, one can call it from
00649    // the interpreter.
00650    //
00651    // Example:
00652    //           gui = new HistAction(gClient->GetRoot(),1,1);
00653    //           TH1F *hist = new TH1F("myhisto","bla-bla-bla",100,0,100);
00654    //           {
00655    //           ...
00656    //           hist->Fill(x);
00657    //           ...
00658    //           }
00659    //           gui->importHist(hist->GetName());
00660    //
00661    //-------------------------------------------------------------------
00662 
00663    TH1F *h;
00664    h = (TH1F*) gROOT->FindObject(name);
00665    if (!h) return kFALSE;
00666    if (position == kMaxHist) return kFALSE;
00667    fHisto->AddAt(h, position++);
00668    fListBoxA->AddEntry(h->GetName(), ++totalA);
00669    fListBoxA->MapSubwindows();
00670    fListBoxA->Layout();
00671    return kTRUE;
00672 }
00673 
00674 Bool_t HistAction::importFromFile(const char *filename)
00675 {
00676    //-------------------------------------------------------------------
00677    //
00678    //                 importFromFile(const char *filename)
00679    //
00680    // Imports histogrammes from a file with the name "filename".
00681    // Opens the file, scans it, if finds an object of the class TH1F or TH2F,
00682    // imports it.
00683    // All the other objects are ignored.
00684    // In case of not a ROOT file returns an error message and takes no further
00685    // action.
00686    // This function is called when a user doubly clicks on the file icon
00687    // in the file list view.
00688    //
00689    //--------------------------------------------------------------------
00690 
00691    Int_t retval;
00692    Int_t l;
00693    TFile *f;
00694    TH1F *fH;
00695    f = new TFile(filename);
00696    if (!f) return kFALSE;
00697    if (f->IsZombie()) {
00698       new TGMsgBox(fClient->GetRoot(), this, "Error Message",
00699                    "You have chosen not a ROOT file. Please, be attentive.",
00700                    kMBIconExclamation, kMBOk, &retval);
00701       delete f;
00702       f = NULL;
00703       return kFALSE;
00704    }
00705    TKey *key;
00706    TIter it(f->GetListOfKeys());
00707    while ((key = (TKey*) it())) {
00708       if (!strcmp(key->GetClassName(), "TH1F") ||
00709             !strcmp(key->GetClassName(), "TH2F")) {
00710          fH = (TH1F*) key->ReadObj();
00711          if (fH && position < kMaxHist) fHisto->AddAt(fH, position++);
00712       }
00713    }
00714    for (l = totalA; l < position; l++) {
00715       fListBoxA->AddEntry(fHisto->At(l)->GetName(), l + 1);
00716    }
00717    fListBoxA->MapSubwindows();
00718    fListBoxA->Layout();
00719    totalA = position;
00720    return kTRUE;
00721 }
00722 
00723 int HistAction::getNextTrueIndex()
00724 {
00725    //---------------------------------------------------------------
00726    //
00727    //                 getNextTrueIndex()
00728    //
00729    // Iterates over array "flags", returns the next "TRUE index".
00730    // In case of no "TRUE index" found returns -1.
00731    // "TRUE index" means the index of a histogram currently highlighted in
00732    // the large list box (ListBoxA).
00733    //
00734    //---------------------------------------------------------------
00735 
00736    while (cursorIter < kMaxHist) {
00737       cursorIter++;
00738       if (flags[cursorIter]) return cursorIter;
00739    }
00740    return -1;
00741 }
00742 
00743 void HistAction::setCanvasDivision(Int_t number)
00744 {
00745    //---------------------------------------------------------------
00746    //
00747    //              setCanvasDivision(Int_t number)
00748    //
00749    // Calculates the xDiv and yDiv parameters which are used to divide
00750    // the main canvas (CanvasA) into subpads.
00751    // This function is used in case of the automatic display layout
00752    // (checkbutton "Multiple selection" is engaged).
00753    // The function takes as an input parameter the total number of histogrammes
00754    // to be displayed.
00755    // Called from drawHist()
00756    //
00757    //---------------------------------------------------------------
00758 
00759    Int_t i, j, k;
00760    for (i = 1; i < 50; i++) {
00761       k = 0;
00762       for (j = i - 1; j <= i; j++) {
00763          if (number <= i*j) {
00764             k = j;
00765             break;
00766          }
00767       }
00768       if (number <= i*k) break;
00769    }
00770    xDiv = i;
00771    yDiv = k;
00772 }
00773 
00774 void HistAction::drawHist()
00775 {
00776    //-----------------------------------------------------------------
00777    //
00778    //                drawHist()
00779    //
00780    // Draws a set of histogrammes in the canvas cA in case of the automatic
00781    // display layout (checkbutton "Multiple selection" is engaged).
00782    // Called when the button "Draw" is clicked.
00783    //
00784    //----------------------------------------------------------------
00785 
00786    Int_t number;  //number of highlighted histos in ListBoxA
00787    Int_t i;
00788    number = -1;
00789    resetIter();
00790    while (getNextTrueIndex() != -1) number++;
00791    setCanvasDivision(number);
00792    cA->Clear();
00793    cA->Divide(xDiv, yDiv);
00794    resetIter();
00795    for (i = 0; i < number; i++) {
00796       cA->cd(i + 1);
00797       ((TH1F*) fHisto->At(getNextTrueIndex()))->Draw();
00798    }
00799    cA->cd();
00800    cA->Modified();
00801    cA->Update();
00802 }
00803 
00804 void HistAction::toScan()
00805 {
00806    //---------------------------------------------------------------
00807    //
00808    //                     toScan()
00809    //
00810    // Makes a clone of a selected histo.
00811    // Puts the clone object to the scan panel (panel B).
00812    // Called when the button "Import" is clicked.
00813    //
00814    //---------------------------------------------------------------
00815 
00816    Int_t retval;
00817    Int_t chan;
00818    Float_t from, to;
00819    Int_t entries;
00820    TObject *p;
00821    TString tmp;
00822    Int_t i;
00823    Float_t bcont;
00824 
00825    clearScan();
00826    TIter it(gPad->GetListOfPrimitives());
00827    while ((p = it())) {
00828       if (!strcmp(p->ClassName(), "TH1F")) hist = (TH1F*) p->Clone();
00829    }
00830    if (!hist) {
00831       new TGMsgBox(fClient->GetRoot(), this, "Help message",
00832                    "Choose a histogram by clicking on its area the middle button of the mouse.",
00833                    kMBIconExclamation, kMBOk, &retval);
00834       return;
00835    }
00836    cB->cd();
00837    if (hist) {
00838 
00839       hist->Draw();
00840       chan = hist->GetXaxis()->GetNbins();
00841       from = hist->GetXaxis()->GetXmin();
00842       to = hist->GetXaxis()->GetXmax();
00843       entries = (Int_t) hist->GetEntries();
00844 
00845       tmp.Form("%s", hist->GetName());
00846       fNameBuf->Clear();
00847       fNameBuf->AddText(0, tmp);
00848       fClient->NeedRedraw(fName);
00849 
00850       tmp.Form("%s", hist->GetTitle());
00851       fTitleBuf->Clear();
00852       fTitleBuf->AddText(0, tmp);
00853       fClient->NeedRedraw(fTitle);
00854 
00855       tmp.Form("%i", chan);
00856       fChanBuf->Clear();
00857       fChanBuf->AddText(0, tmp);
00858       fClient->NeedRedraw(fChan);
00859 
00860       tmp.Form("%.1f%s%.1f", from, "...", to);
00861       fRangeBuf->Clear();
00862       fRangeBuf->AddText(0, tmp);
00863       fClient->NeedRedraw(fRange);
00864 
00865       tmp.Form("%i", entries);
00866       fEntriesBuf->Clear();
00867       fEntriesBuf->AddText(0, tmp);
00868       fClient->NeedRedraw(fEntries);
00869 
00870       array = new Int_t[chan];
00871       for (i = 1; i <= chan; i++) {
00872          bcont = (float) hist->GetBinContent(i);
00873          if (bcont > 0.0) {
00874             tmp.Form("%i", i);
00875             array[totalB] = i;
00876             fListBoxB->AddEntry(tmp, ++totalB);
00877          }
00878       }
00879       fListBoxB->MapSubwindows();
00880       fListBoxB->Layout();
00881    }
00882    cB->Update();
00883 }
00884 
00885 void HistAction::processBoxB(Int_t par)
00886 {
00887    //-----------------------------------------------------------
00888    //
00889    //        processBoxB(Int_t par)
00890    //
00891    // Processes information from the listbox "Non empty bins" (ListBoxB).
00892    // Updates the fields "Bin content" and "Bin range".
00893    // Higlights the selected bin on the canvas cB.
00894    // Called when an item in the listbox "Non empty bins" is highlighted.
00895    // Input parameter - bin index.
00896    //
00897    //------------------------------------------------------------
00898 
00899    Int_t chan;
00900    Float_t from, to;
00901    Float_t bfrom, bto;
00902    TString tmp;
00903    Float_t bcont;
00904 
00905    if (temph) {
00906       delete temph;
00907       temph = NULL;
00908    }
00909    if (hist) {
00910       chan = hist->GetXaxis()->GetNbins();
00911       from = hist->GetXaxis()->GetXmin();
00912       to = hist->GetXaxis()->GetXmax();
00913       temph = new TH1F("h", "h", chan, from, to);
00914       temph->SetLineColor(kRed);
00915       temph->SetFillColor(kRed);
00916       temph->SetBinContent(array[par-1], hist->GetBinContent(array[par-1]));
00917       cB->cd();
00918       temph->Draw("SAME");
00919 
00920       bcont = (float) hist->GetBinContent(array[par-1]);
00921       tmp.Form("%.2f", bcont);
00922       fBinContBuf->Clear();
00923       fBinContBuf->AddText(0, tmp);
00924       fClient->NeedRedraw(fBinCont);
00925 
00926       bfrom = hist->GetBinLowEdge(array[par-1]);
00927       bto = bfrom + hist->GetBinWidth(array[par-1]);
00928       tmp.Form("%.2f%s%.2f", bfrom, "...", bto);
00929       fBinRangeBuf->Clear();
00930       fBinRangeBuf->AddText(0, tmp);
00931       fClient->NeedRedraw(fBinRange);
00932    }
00933    cB->Update();
00934 }
00935 
00936 void HistAction::clearScan()
00937 {
00938    //-----------------------------------------------------------
00939    //
00940    //              clearScan()
00941    //
00942    // Clears all the fields in the scan panel (panel B).
00943    //
00944    //-----------------------------------------------------------
00945 
00946    TVirtualPad *padsav = gPad;
00947 
00948    fNameBuf->Clear();
00949    fClient->NeedRedraw(fName);
00950 
00951    fTitleBuf->Clear();
00952    fClient->NeedRedraw(fTitle);
00953 
00954    fChanBuf->Clear();
00955    fClient->NeedRedraw(fChan);
00956 
00957    fRangeBuf->Clear();
00958    fClient->NeedRedraw(fRange);
00959 
00960    fEntriesBuf->Clear();
00961    fClient->NeedRedraw(fEntries);
00962 
00963    fBinContBuf->Clear();
00964    fClient->NeedRedraw(fBinCont);
00965 
00966    fBinRangeBuf->Clear();
00967    fClient->NeedRedraw(fBinRange);
00968 
00969    if (hist) {
00970       delete hist;
00971       hist = NULL;
00972    }
00973 
00974    if (temph) {
00975       delete temph;
00976       temph = NULL;
00977    }
00978 
00979    if (totalB) {
00980       fListBoxB->RemoveEntries(1, totalB);
00981       totalB = 0;
00982       fListBoxB->MapSubwindows();
00983       fListBoxB->Layout();
00984    }
00985 
00986    cursB = 0;
00987 
00988    if (array) {
00989       delete [] array;
00990       array = NULL;
00991    }
00992 
00993    cB->Clear();
00994    cB->Update();
00995 
00996    gPad = padsav;
00997 }
00998 
00999 Bool_t HistAction::toDefault(Window_t id)
01000 {
01001    //------------------------------------------------------------------
01002    //
01003    //      toDefault(Window_t id)
01004    //
01005    // Changes the color attributes of a window to default values (gray).
01006    // Used to change the colors of the buttons in the panel "Display Layout".
01007    // Does not redraw the button.
01008    // So to visually change the color needs to be followed by
01009    // the function NeedRedraw(TGWindow *).
01010    // Input paramater - ID of the button to which the action must be applied.
01011    //
01012    //------------------------------------------------------------------
01013 
01014    SetWindowAttributes_t wattr;
01015    wattr.fMask = kWABackPixel;
01016    wattr.fBackgroundPixel = GetDefaultFrameBackground();
01017    gVirtualX->ChangeWindowAttributes(id, &wattr);
01018    return kTRUE;
01019 
01020 }
01021 
01022 Bool_t HistAction::toGreen(Window_t id)
01023 {
01024    //-------------------------------------------------------------
01025    //
01026    //       toGreen(Window_t id)
01027    //
01028    // The same as above except changing the color to green.
01029    //
01030    //-------------------------------------------------------------
01031 
01032    SetWindowAttributes_t wattr;
01033    wattr.fMask = kWABackPixel;
01034    gClient->GetColorByName("green", wattr.fBackgroundPixel);
01035    gVirtualX->ChangeWindowAttributes(id, &wattr);
01036    return kTRUE;
01037 }
01038 
01039 Bool_t HistAction::isOverlap()
01040 {
01041    //-------------------------------------------------------------
01042    //
01043    //         isOverlap()
01044    //
01045    // Checks if a selected display layout overlaps with already existing
01046    // pads in the canvas cA.
01047    //
01048    //-------------------------------------------------------------
01049 
01050    Int_t i, j;
01051    Int_t tmpIndex;
01052 
01053    for (i = 0; i < 4; i++) {
01054       for (j = 0; j < 4; j++) {
01055          if (verLay[i] && horLay[j]) {
01056             tmpIndex = 4 * i + j;
01057             if (histInd[tmpIndex] != -1) return kTRUE;
01058          }
01059       }
01060    }
01061    return kFALSE;
01062 
01063 }
01064 
01065 Bool_t HistAction::isLayout()
01066 {
01067    //-------------------------------------------------------
01068    //
01069    //        isLayout()
01070    //
01071    // Checks if display layout is set.
01072    //
01073    //--------------------------------------------------------
01074 
01075    Int_t i;
01076    for (i = 0;i < 4;i++) {
01077       if (horLay[i] != 0) return kTRUE;
01078       if (verLay[i] != 0) return kTRUE;
01079    }
01080    return kFALSE;
01081 
01082 }
01083 
01084 void HistAction::paintHist()
01085 {
01086    //--------------------------------------------------------------------
01087    //
01088    //              paintHist()
01089    //
01090    // Draws a histo in the canvas cA in case of the user defined display layout.
01091    // The latest display layout has the highest priority. If an overlap
01092    // with existing pads is detected, they are deleted from cA.
01093    // Algorithm virtually divides cA into subpads with the matrix layout (4x4).
01094    // A real pad in which histo will be drawn is constructed from virtual subpads.
01095    // The number of virtual subpads for the real pad can change in the range 1-16.
01096    // Arrays histInd[16] and pads[16] keep the "id" of the histo and the
01097    // address of the real pad
01098    //
01099    //            -----------------
01100    //            |   |   |   |   |
01101    //            | 1 | 2 | 3 | 4 |
01102    //            |---|---|---|---|
01103    //            |   |   |   |   |
01104    //            | 5 | 6 | 7 | 8 |
01105    //            |---|---|---|---|
01106    //            |   |   |   |   |
01107    //            | 9 | 10| 11| 12|
01108    //            |---|---|---|---|
01109    //            |   |   |   |   |
01110    //            | 13| 14| 15| 16|
01111    //            -----------------
01112    //
01113    //
01114    // If a histo with id=20 must be drawn in a pad which embraces virtual subpads
01115    // 1,2,5,6 then
01116    //              histInd[0] = 20        pads[0] = address of the real pad
01117    //              histInd[1] = 20        pads[1] = NULL
01118    //              histInd[4] = 20        pads[4] = NULL
01119    //              histInd[5] = 20        pads[5] = NULL
01120    //
01121    // To search for the pads to be deleted the algorithm uses only array
01122    // histInd[].
01123    // Only one of the virtual subpads of the real pad keeps the address
01124    // to avoid double deleting of the same object.
01125    // If there is an overlap between the pads which contain the histo with
01126    // the same "id", then only the latest version is drawn.
01127    // All the other pads with this histo (even non overlapping with the current
01128    // one) will be deleted from the canvas.
01129    // To have several versions of the same histo drawn in the canvas one has
01130    // to avoid pads overlapping when setting display layout.
01131    //--------------------------------------------------------------------
01132 
01133    Int_t retval;
01134    Float_t xmin = 0.0F;
01135    Float_t xmax = 0.0F;
01136    Float_t ymin = 0.0F;
01137    Float_t ymax = 0.0F;
01138    Int_t i, j, countLocal;
01139    Int_t ind;
01140    Int_t tempind;
01141    TPad *pad;
01142    const Float_t ratio = 0.25;
01143 
01144    if (!isLayout()) {
01145       new TGMsgBox(fClient->GetRoot(), this, "Message",
01146                    "Set Display Layout.",
01147                    kMBIconExclamation, kMBOk, &retval);
01148       return;
01149    }
01150    resetIter();
01151    ind = getNextTrueIndex();
01152    for (i = 0; i < 4; i++) {
01153       if (horLay[i] && (xmin == 0.0)) xmin = i * ratio + 0.01;
01154       if (horLay[i] && (xmin != 0.0)) xmax = (i + 1) * ratio - 0.01;
01155    }
01156    for (i = 3; i > -1; i--) {
01157       if (verLay[i] && (ymin == 0.0)) ymin = (3 - i) * ratio + 0.01;
01158       if (verLay[i] && (ymin != 0.0)) ymax = (4 - i) * ratio - 0.01;
01159    }
01160    if (isOverlap()) {
01161       for (i = 0; i < 16; i++) {
01162          if (verLay[i/4] && horLay[i%4]) {
01163             tempind = histInd[i];
01164             for (j = 0; j < 16; j++) {
01165                if (histInd[j] == tempind) {
01166                   histInd[j] = -1;
01167                   if (pads[j]) {
01168                      delete pads[j];
01169                      pads[j] = NULL;
01170                   }
01171                }
01172             }
01173          }
01174       }
01175    }
01176    pad = new TPad("pad", "pad", xmin, ymin, xmax, ymax);
01177    pad->SetFillColor(10);
01178    cA->cd();
01179    pad->Draw();
01180    pad->cd();
01181    if (fHisto->At(ind))((TH1F*) fHisto->At(ind))->Draw();
01182    cA->cd();
01183    cA->Modified();
01184    cA->Update();
01185 
01186    countLocal = 0;
01187    for (i = 0; i < 4; i++) {
01188       for (j = 0; j < 4; j++) {
01189          if (verLay[i] && horLay[j]) {
01190             countLocal++;
01191             histInd[4*i+j] = ind;
01192             if (countLocal == 1) pads[4*i+j] = pad;
01193             else pads[4*i+j] = NULL;
01194          }
01195       }
01196    }
01197    return;
01198 }
01199 
01200 Bool_t HistAction::ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
01201 {
01202    //------------------------------------------------------------------
01203    //
01204    //    ProcessMessage(Long_t msg, Long_t parm1, Long_t parm2)
01205    //
01206    // Processes information from all GUI items.
01207    // Selecting an item usually generates an event with 4 parameters.
01208    // The first two are packed into msg (first and second bytes).
01209    // The other two are parm1 and parm2.
01210    //
01211    //------------------------------------------------------------------
01212 
01213    Int_t retval; //for class TGMsgBox
01214    Int_t buttons;//used to construct message panel when Close button is clicked
01215    Int_t numb;//to update layout of list boxes
01216    Int_t i, j;
01217    Int_t imin, imax;//to calculate display layout
01218    Int_t jmin, jmax;//to calculate display layout
01219    TString tmp, filename, ext;//to process information in file container
01220    TGFileItem *f;//the same as above
01221    void *p = 0;//the same as above
01222    TString command;//the same as above
01223 
01224    switch (GET_MSG(msg)) {
01225       case kC_COMMAND:
01226 
01227          switch (GET_SUBMSG(msg)) {
01228 
01229             case kCM_BUTTON:
01230 
01231                switch (parm1) {
01232                   case M_DRAW:
01233                      if (!totalA) {
01234                         new TGMsgBox(fClient->GetRoot(), this, "Error message",
01235                                      "Histo container is empty.",
01236                                      kMBIconExclamation, kMBOk, &retval);
01237                         break;
01238                      }
01239 
01240                      if (!kSTATUS) {
01241                         new TGMsgBox(fClient->GetRoot(), this, "Help message",
01242                                      "Highlight the name of the histogram to be displayed.",
01243                                      kMBIconExclamation, kMBOk, &retval);
01244                         break;
01245                      }
01246 
01247                      if (fMultiButton->GetState()) drawHist();//Automatic display layout
01248                      else {
01249                         paintHist(); //User defined display layout
01250 
01251                         // Total number of buttons which can be set in "Display Layout" panel by a user
01252                         count = 2;
01253                      }
01254                      break;
01255 
01256                   case M_CLEAR_A:
01257                      for (int k = 0; k < 16; k++) {
01258                         histInd[k] = -1;
01259                         if (pads[k]) delete pads[k];
01260                         pads[k] = NULL;
01261                      }
01262                      cA->cd();
01263                      cA->Clear();
01264                      cA->Update();
01265                      break;
01266 
01267                   case M_SAVE:
01268 
01269                      // Ask confirmation to close the window
01270 
01271                      new CanvSave(fClient->GetRoot(), this, 400, 200);
01272                      fFileCont->DisplayDirectory();
01273                      break;
01274 
01275                   case M_EDIT:
01276                      cA->cd();
01277                      cA->EditorBar();
01278                      break;
01279 
01280                   case M_IMPORT:
01281 
01282                      // Put a histo to the Scan panel
01283 
01284                      toScan();
01285                      break;
01286 
01287                   case M_CLEAR_B:
01288                      clearScan();
01289                      break;
01290 
01291                   case M_CLOSE:
01292                      retval = 0;
01293                      buttons = 0;
01294                      buttons |= kMBYes;
01295                      buttons |= kMBNo;
01296                      new TGMsgBox(fClient->GetRoot(), this, "Confirm action",
01297                                   "Close Panel 'Histogram Viewer' ?",
01298                                   kMBIconQuestion, buttons, &retval);
01299                      if (retval == 1) CloseWindow();
01300                      break;
01301 
01302                   case M_PREV_B:
01303 
01304                      // One bin up in ListBoxB (non empty bins)
01305 
01306                      if (totalB > 0) {
01307                         if ((cursB > 0) && (cursB <= totalB)) cursB--;
01308                         if (cursB < 1) cursB = 1;
01309                         if (cursB > totalB) cursB = totalB;
01310                         fListBoxB->Select(cursB);
01311                         numb = cursB;
01312                         while (((--numb) % 5) != 0) { }
01313                         fListBoxB->SetTopEntry(++numb);
01314                         SendMessage(this, MK_MSG(kC_COMMAND, kCM_LISTBOX), M_LIST_B, cursB);
01315                      }
01316                      break;
01317 
01318                   case M_NEXT_B:
01319 
01320                      // One bin down in ListBoxB (non empty bins)
01321 
01322                      if (totalB > 0) {
01323                         if ((cursB > 0) && (cursB <= totalB)) cursB++;
01324                         if (cursB < 1) cursB = 1;
01325                         if (cursB > totalB) cursB = totalB;
01326                         fListBoxB->Select(cursB);
01327                         numb = cursB;
01328                         while (((--numb) % 5) != 0) { }
01329                         fListBoxB->SetTopEntry(++numb);
01330                         SendMessage(this, MK_MSG(kC_COMMAND, kCM_LISTBOX), M_LIST_B, cursB);
01331                      }
01332                      break;
01333 
01334                   case M_PREV_A:
01335 
01336                      // One histo up in ListBoxA
01337 
01338                      if (!fMultiButton->GetState() && (totalA > 0)) {
01339                         if ((cursA > 0) && (cursA <= totalA)) cursA--;
01340                         if (cursA < 1) cursA = 1;
01341                         if (cursA > totalA) cursA = totalA;
01342                         fListBoxA->Select(cursA);
01343                         numb = cursA;
01344                         while (((--numb) % 14) != 0) { }
01345                         fListBoxA->SetTopEntry(++numb);
01346                         SendMessage(this, MK_MSG(kC_COMMAND, kCM_LISTBOX), M_LIST_A, cursA);
01347                         SendMessage(this, MK_MSG(kC_COMMAND, kCM_BUTTON), M_DRAW, 0);
01348                      }
01349                      break;
01350 
01351                   case M_NEXT_A:
01352 
01353                      // One histo down in ListBoxA
01354 
01355                      if (!fMultiButton->GetState() && (totalA > 0)) {
01356                         if ((cursA > 0) && (cursA <= totalA)) cursA++;
01357                         if (cursA < 1) cursA = 1;
01358                         if (cursA > totalA) cursA = totalA;
01359                         fListBoxA->Select(cursA);
01360                         numb = cursA;
01361                         while (((--numb) % 14) != 0) { }
01362                         fListBoxA->SetTopEntry(++numb);
01363                         SendMessage(this, MK_MSG(kC_COMMAND, kCM_LISTBOX), M_LIST_A, cursA);
01364                         SendMessage(this, MK_MSG(kC_COMMAND, kCM_BUTTON), M_DRAW, 0);
01365                      }
01366                      break;
01367 
01368                   case M_SELECT:
01369 
01370                      // "Select All" button is clicked
01371 
01372                      fMultiButton->SetState(kButtonDown);
01373                      SendMessage(this, MK_MSG(kC_COMMAND, kCM_CHECKBUTTON), M_MULTI, 0);
01374 
01375                      // Call twice SetMultipleSelections(kTRUE), otherwise items in the list box
01376                      // are not highlighted (though proper functionality remains)
01377 
01378                      fListBoxA->SetMultipleSelections(kTRUE);
01379                      for (i = 1; i <= totalA; i++) {
01380                         fListBoxA->Select(i);
01381                         SendMessage(this, MK_MSG(kC_COMMAND, kCM_LISTBOX), M_LIST_A, i);
01382                      }
01383                      break;
01384 
01385                   case M_CDUP:
01386 
01387                      // To the parent directory
01388 
01389                      gSystem->ChangeDirectory("..");
01390                      tmp.Form("%s", gSystem->WorkingDirectory());
01391                      fDir->RemoveEntry(1);
01392                      fDir->AddEntry(tmp, 1);
01393                      fDir->MapSubwindows();
01394                      fDir->Layout();
01395                      fFileCont->DisplayDirectory();//otherwise the current directory is
01396                      //not always updated
01397                      break;
01398 
01399                   case M_LIST_MODE:
01400 
01401                      // "List" mode of file view
01402 
01403                      fFileView->SetViewMode(kLVList);
01404                      fDetailMode->SetState(kButtonUp);
01405                      break;
01406 
01407                   case M_DETAIL_MODE:
01408 
01409                      // "Details" mode of file view
01410 
01411                      fFileView->SetViewMode(kLVDetails);
01412                      fListMode->SetState(kButtonUp);
01413                      break;
01414 
01415                   default:
01416 
01417                      // Process the panel "Display Layout"
01418 
01419                      if (parm1 >= 500 && parm1 <= 515 && !fMultiButton->GetState()) {
01420                         if (count == 2) count = 0;
01421                         if (count < 2) {
01422                            toGreen(fLayoutButton[parm1-500]->GetId());
01423                            verLay[(parm1-500)/4] = 1;
01424                            horLay[(parm1-500)%4] = 1;
01425                            fClient->NeedRedraw(fLayoutButton[parm1-500]);
01426                            indi[count] = (parm1 - 500) / 4;
01427                            indj[count] = (parm1 - 500) % 4;
01428                            count++;
01429                            if (count == 2) {
01430                               imin = (indi[0] < indi[1]) ? indi[0] : indi[1];
01431                               imax = (indi[0] > indi[1]) ? indi[0] : indi[1];
01432                               jmin = (indj[0] < indj[1]) ? indj[0] : indj[1];
01433                               jmax = (indj[0] > indj[1]) ? indj[0] : indj[1];
01434                               for (i = 0;i < 4;i++) {
01435                                  for (j = 0;j < 4;j++) {
01436                                     if (i >= imin && i <= imax && j >= jmin && j <= jmax) {
01437                                        toGreen(fLayoutButton[4*i+j]->GetId());
01438                                        verLay[i] = 1;
01439                                        horLay[j] = 1;
01440                                     } else {
01441                                        toDefault(fLayoutButton[4*i+j]->GetId());
01442                                        if (i < imin || i > imax) verLay[i] = 0;
01443                                        if (j < jmin || j > jmax) horLay[j] = 0;
01444                                     }
01445                                     fClient->NeedRedraw(fLayoutButton[4*i+j]);
01446                                  }
01447                               }
01448                            }
01449                            if (count == 1) {
01450                               for (i = 0;i < 16;i++) {
01451                                  if (i != (parm1 - 500)) {
01452                                     toDefault(fLayoutButton[i]->GetId());
01453                                     if (i / 4 != (parm1 - 500) / 4) verLay[i/4] = 0;
01454                                     if (i % 4 != (parm1 - 500) % 4) horLay[i%4] = 0;
01455                                     fClient->NeedRedraw(fLayoutButton[i]);
01456                                  }
01457                               }
01458                            }
01459                         }
01460                      }
01461                      break;
01462                }
01463 
01464             case kCM_CHECKBUTTON:
01465 
01466                // Multiple selection
01467 
01468                switch (parm1) {
01469                   case M_MULTI:
01470                      if (!fListBoxA->GetMultipleSelections()) {
01471                         if (fListBoxA->GetSelectedEntry())
01472                            fListBoxA->GetSelectedEntry()->Activate(kFALSE);
01473                      }
01474                      fListBoxA->SetMultipleSelections(fMultiButton->GetState());
01475 
01476                      cursA = 0;
01477                      cA->Clear();
01478                      cA->Update();
01479                      for (i = 0; i < 16; i++) {
01480                         toDefault(fLayoutButton[i]->GetId());
01481                         fClient->NeedRedraw(fLayoutButton[i]);
01482                         verLay[i/4] = 0;
01483                         horLay[i%4] = 0;
01484                      }
01485                      count = 0;
01486                      for (j = 0; j < 16; j++) {
01487                         pads[j] = NULL;
01488                         histInd[j] = -1;
01489                      }
01490                      resetFlags();
01491                      kSTATUS = kFALSE;
01492                      break;
01493 
01494                   default:
01495                      break;
01496                }
01497 
01498             case kCM_LISTBOX:
01499 
01500                switch (parm1) {
01501                   case M_LIST_A:
01502 
01503                      // ListBoxA
01504 
01505                      cursA = parm2; //necessary for "Previous", "Next" buttons in case of
01506                      //random jumps in list box window
01507 
01508                      if (!fListBoxA->GetMultipleSelections()) {
01509                         resetFlags();
01510                         flags[parm2-1] = kTRUE;
01511                      } else
01512                         flags[parm2-1] = !flags[parm2-1];
01513                      kSTATUS = kTRUE;
01514                      break;
01515 
01516                   case M_LIST_B:
01517 
01518                      // ListBoxB (non empty bins)
01519 
01520                      cursB = parm2; //for "Previous", "Next" buttons
01521                      processBoxB(parm2);
01522                      break;
01523 
01524                   default:
01525                      break;
01526                }
01527 
01528             case kCM_COMBOBOX:
01529                switch (parm1) {
01530 
01531                   case M_FILTER:
01532 
01533                      // Set filter on the file type
01534 
01535                      if (parm2 == 1) fFileCont->SetFilter("*");
01536                      if (parm2 == 2) fFileCont->SetFilter("*.root");
01537                      fFileCont->DisplayDirectory();
01538                      break;
01539 
01540                   default:
01541                      break;
01542                }
01543 
01544             default:
01545                break;
01546          }
01547 
01548       case kC_CONTAINER:
01549          switch (GET_SUBMSG(msg)) {
01550 
01551             case kCT_ITEMDBLCLICK:
01552 
01553                // Process mouse double clicking in file view container
01554 
01555                if (parm1 == kButton1) {
01556                   if (fFileCont->NumSelected() == 1) {
01557                      f = (TGFileItem *) fFileCont->GetNextSelected(&p);
01558                      if (S_ISDIR(f->GetType())) {
01559                         fFileCont->ChangeDirectory(f->GetItemName()->GetString());
01560                         tmp.Form("%s", gSystem->WorkingDirectory());
01561                         fDir->RemoveEntry(1);
01562                         fDir->AddEntry(tmp, 1);
01563                         fDir->MapSubwindows();
01564                         fDir->Layout();
01565                      } else {
01566                         filename.Form("%s", f->GetItemName()->GetString());
01567                         ext = filename(filename.Last('.')+1, filename.Length());
01568 
01569                         // Call gv for postscript and pdf files
01570 
01571                         if (ext == "ps" || ext == "PDF" || ext == "pdf") {
01572                            command.Form("%s%s%s%s%s", "gv ",
01573                                         gSystem->WorkingDirectory(),
01574                                         "/",
01575                                         filename.Data(),
01576                                         "&");
01577                            gSystem->Exec(command);
01578                            break;
01579                         }
01580 
01581                         // Call xv for jpg, gif and bmp files
01582 
01583                         if (ext == "gif" || ext == "jpg" || ext == "bmp") {
01584                            command.Form("%s%s%s%s%s", "xv ",
01585                                         gSystem->WorkingDirectory(),
01586                                         "/",
01587                                         filename.Data(),
01588                                         "&");
01589                            gSystem->Exec(command);
01590                            break;
01591                         }
01592 
01593                         // Import root file
01594 
01595                         filename.Form("%s%s%s",
01596                                 gSystem->WorkingDirectory(),
01597                                 "/",
01598                                 f->GetItemName()->GetString());
01599                         importFromFile(filename);
01600                      }
01601                   }
01602                }
01603                break;
01604 
01605             default:
01606                break;
01607          }
01608 
01609       default:
01610          break;
01611    }
01612 
01613    return kTRUE;
01614 
01615 }
01616 
01617 void HistAction::doubleclickedBoxA(const char * /*text*/)
01618 {
01619    //------------------------------------------------------------------
01620    //
01621    //    doubleclickBoxA(const char *)
01622    //
01623    // Handle double click events in fListBoxA.
01624    // Double clicking in the list of histograms will draw the selected
01625    // histogram.
01626    //
01627    //------------------------------------------------------------------
01628 
01629    paintHist(); //User defined display layout
01630    // Total number of buttons which can be set in "Display Layout" panel by a user
01631    count = 2;
01632 }

Generated on Tue Jul 5 15:15:03 2011 for ROOT_528-00b_version by  doxygen 1.5.1