CXMainWindow.cpp 50.8 KB
Newer Older
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#include "CXMainWindow.h"

#include "TStyle.h"
#include "TG3DLine.h"
#include "TApplication.h"
#include "TGraphErrors.h"
#include "TGMenu.h"
#include "TGSplitter.h"
#include "TRootEmbeddedCanvas.h"
#include "TGTab.h"
#include "TGStatusBar.h"
#include "TVirtualPadEditor.h"
#include "TFrame.h"
#include "TGFileBrowser.h"
#include "KeySymbols.h"
#include "TGListView.h"
#include "TClassMenuItem.h"
#include "TROOT.h"
#include "TGFSContainer.h"
#include "TBrowser.h"
#include "TClass.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
22
#include "TExec.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
23 24 25 26 27 28 29 30

#include "CXGateBox.h"
#include "CXBgdUtility.h"
#include "CXGuiToolbar.h"
#include "CXFileList.h"
#include "CXGuiLSPlayer.h"
#include "CXHist1DPlayer.h"
#include "CXHist2DPlayer.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
31
#include "CXRad2DPlayer.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
32
#include "CXGammaSearch.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
33
#include "CXNucChart.h"
34
#include "CXRadReader.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
35 36 37 38
#include "CXRadCubePlayer.h"
#include "CXSavedList.h"
#include "CXRadCubeTH1Proj.h"
#include "CXTH1Proj.h"
39
#include "CXArrow.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
40
#include "CXNDManager.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60

using namespace std;

ULong_t CXred;
ULong_t CXblue;
ULong_t CXblack;
ULong_t CXgreen;

CXMainWindow::CXMainWindow(const TGWindow *p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
{
    Init();
}

void CXMainWindow::Init()
{
    gClient->GetColorByName("red",  CXred);
    gClient->GetColorByName("blue", CXblue);
    gClient->GetColorByName("black",CXblack);
    gClient->GetColorByName("green",CXgreen);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
61 62 63
    if(gNDManager == nullptr)
        gNDManager = new CXNDManager(this);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
    TGHorizontalFrame *fHf = new TGHorizontalFrame(this,GetWidth(),GetHeight());
    
    //------- Menu -----------

    //----------------Menu File--------------------
    
    fMenuFile = new TGPopupMenu(gClient->GetRoot());
    fMenuFile->AddEntry("New Canvas", M_New_Canvas, 0 , gClient->GetPicture("newcanvas.xpm"));
    fMenuFile->AddEntry("New Browser", M_New_Browser, 0, gClient->GetPicture("browser.xpm"));
    fMenuFile->AddEntry("Save Canvas as", M_Save_As, 0, gClient->GetPicture("bld_save.png"));
    fMenuFile->AddEntry("Save hist to ascii", M_Save_To_Ascii, 0, gClient->GetPicture("query_new.xpm"));
    fMenuFile->AddSeparator();
    fMenuFile->AddEntry("Exit", M_Exit, 0, gClient->GetPicture("bld_exit.png"));
    fMenuFile->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

    //----------------Menu View--------------------

    fMenuView = new TGPopupMenu(gClient->GetRoot());
    fMenuView->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

84
    fMenuView->AddEntry("Browse Files", M_FileListUtility,0,gClient->GetPicture("ed_open.png"));
85
    //    fMenuView->CheckEntry(M_FileListUtility);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
86 87
    IsFileListUtilityEnabled = true;

88
    fMenuView->AddEntry("Saved list", M_SavedList,0,gClient->GetPicture("bld_listbox.xpm"));
89
    //    fMenuView->CheckEntry(M_SavedList);
90
    IsSavedListEnabled = true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
91

92
    fMenuView->AddSeparator();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
93

94
    fMenuView->AddEntry("Show editor", M_Editor,0,gClient->GetPicture("bld_edit.png"));
95
    //    fMenuView->CheckEntry(M_Editor);
96
    IsEditorEnabled = true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
97

98 99 100 101 102 103
    //---------------- Menu Tools --------------------

    fMenuTools = new TGPopupMenu(gClient->GetRoot());

    fMenuTools->AddLabel("1D Tools...",gClient->GetPicture("h1_t.xpm"));
    fMenuTools->AddSeparator();
104

Jérémie Dudouet's avatar
Jérémie Dudouet committed
105
    fMenuTools->AddEntry("ENSDF reader", M_LSPlayerUtility,0,gClient->GetPicture("levelscheme_t.png"));
106

107
    //    fMenuTools->CheckEntry(M_LSPlayerUtility);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
108 109
    IsLSPlayerToolEnabled = true;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
110
    fMenuTools->AddEntry("Peak fitter", M_Hist1DPlayer,0,gClient->GetPicture("FitTool.xpm"));
111
    //    fMenuTools->CheckEntry(M_Hist1DPlayer);
112 113
    IsHist1DPlayerEnabled= true;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
114
    fMenuTools->AddEntry("Background player", M_BkdUtility,0,gClient->GetPicture("h1_t.xpm"));
115
    //    fMenuTools->CheckEntry(M_BkdUtility);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
116 117
    IsBkdUtilityEnabled = true;

118 119 120
    fMenuTools->AddSeparator();
    fMenuTools->AddLabel("2D Tools...",gClient->GetPicture("h2_t.xpm"));
    fMenuTools->AddSeparator();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
121

Jérémie Dudouet's avatar
Jérémie Dudouet committed
122
    fMenuTools->AddEntry("GxG standard", M_Hist2DPlayer,0,gClient->GetPicture("h2_t.xpm"));
123
    //    fMenuTools->CheckEntry(M_Hist2DPlayer);
124
    IsHist2DPlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
125

Jérémie Dudouet's avatar
Jérémie Dudouet committed
126
    fMenuTools->AddEntry("GxG radware's style", M_Rad2DPlayer,0,gClient->GetPicture("rw3.gif"));
127
    //    fMenuTools->CheckEntry(M_Rad2DPlayer);
128
    IsRad2DPlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
129

130 131 132 133
    fMenuTools->AddSeparator();
    fMenuTools->AddLabel("3D Tools...",gClient->GetPicture("h3_t.xpm"));
    fMenuTools->AddSeparator();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
134
    fMenuTools->AddEntry("GxGxG radware's style", M_RadCubePlayer,0,gClient->GetPicture("rw3.gif"));
135
    //    fMenuTools->CheckEntry(M_RadCubePlayer);
136
    IsRadCubePlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
137 138

    fMenuTools->AddSeparator();
139 140 141 142
    fMenuTools->AddLabel("Others...");
    fMenuTools->AddSeparator();

    fMenuTools->AddEntry("Gamma search", M_GammaSearch,0,gClient->GetPicture("ed_find.png"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
143
    fMenuTools->AddEntry("Nuclear Chart", M_NucChart,0,gClient->GetPicture("app-map-icon.png"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
144 145 146

    fMenuTools->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
147 148 149
    //---------------- Menu Options --------------------

    fMenuOptions = new TGPopupMenu(gClient->GetRoot());
150 151
    fMenuOptions->AddEntry("Show Stats", M_ShowStats,0,gClient->GetPicture("stats.png"));
    fMenuOptions->AddEntry("Show Title", M_ShowTitle,0,gClient->GetPicture("eve_text.gif"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
152 153 154 155 156 157

    gStyle->SetOptTitle(0);
    gStyle->SetOptStat(0);

    fMenuOptions->Connect("Activated(Int_t)", "CXMainWindow", this, "HandleMenu(Int_t)");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
158 159 160 161 162
    fMenuBar = new TGMenuBar(this, 1, 1, kHorizontalFrame);
    this->AddFrame(fMenuBar, new TGLayoutHints(kLHintsExpandX));
    fMenuBar->AddPopup("File", fMenuFile, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("View", fMenuView, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
    fMenuBar->AddPopup("Tools", fMenuTools, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
163
    fMenuBar->AddPopup("Options", fMenuOptions, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
164 165 166 167 168 169 170 171 172 173 174 175

    TGHorizontal3DLine *fline = new TGHorizontal3DLine(this);
    AddFrame(fline,new TGLayoutHints(kLHintsExpandX));

    //    //////////////////******************** partie gauche ********************////////////////////////////////
    
    fTGCanvas = new TGCanvas(fHf, 10, 10, kFixedWidth);
    fHf->AddFrame(fTGCanvas, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));

    TGVerticalFrame *VFrame = new TGVerticalFrame(fTGCanvas->GetViewPort());
    fTGCanvas->SetContainer(VFrame);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
176
    fTGCanvas->Resize(GetWidth()*0.27, GetHeight());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
177 178 179 180 181 182 183

    fMainTab = new TGTab(VFrame);
    VFrame->AddFrame(fMainTab, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    fMainTab->Connect("CloseTab(Int_t)", "CXMainWindow", this, "CloseToolsTab(Int_t)");

    TString Name;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
184 185 186 187 188 189 190 191 192
    // ------- Background subtract Tool -----------
    Name = "Saved List";
    fSavedListTab = fMainTab->AddTab(Name);
    fSavedList = new CXSavedList(fSavedListTab,10,10);
    fSavedList->SetMainWindow(this);
    fSavedList->SetName(Name);
    fSavedListTab->AddFrame(fSavedList, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,Name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
    // ------- Background subtract Tool -----------
    Name = "Bkgd Player";
    fBkdToolTab = fMainTab->AddTab(Name);
    fBkdSubtract = new CXBgdUtility(fBkdToolTab,10,10);
    fBkdSubtract->SetMainWindow(this);
    fBkdSubtract->SetName(Name);
    fBkdToolTab->AddFrame(fBkdSubtract, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,Name);

    // ------- Hist1D Player -----------
    Name = "1D Player";
    fHist1DPlayerTab = fMainTab->AddTab(Name);
    fHist1DPlayer = new CXHist1DPlayer(fHist1DPlayerTab,10,10);
    fHist1DPlayer->SetMainWindow(this);
    fHist1DPlayer->SetName(Name);
    fHist1DPlayerTab->AddFrame(fHist1DPlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,Name);

    // ------- Hist2D Player -----------
    Name = "2D Player";
    fHist2DPlayerTab = fMainTab->AddTab(Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
214
    fHist2DPlayer = new CXHist2DPlayer(fHist2DPlayerTab,10,10,this);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
215 216 217 218
    fHist2DPlayer->SetName(Name);
    fHist2DPlayerTab->AddFrame(fHist2DPlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,Name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
219 220 221 222 223 224 225 226
    // ------- Rad2D Player -----------
    Name = "Rad2D Player";
    fRad2DPlayerTab = fMainTab->AddTab(Name);
    fRad2DPlayer = new CXRad2DPlayer(fRad2DPlayerTab,10,10,this);
    fRad2DPlayer->SetName(Name);
    fRad2DPlayerTab->AddFrame(fRad2DPlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,Name);

227 228 229
    // ------- RadCube Player -----------
    Name = "RadCube Player";
    fRadCubePlayerTab = fMainTab->AddTab(Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
230
    fRadCubePlayer = new CXRadCubePlayer(fRadCubePlayerTab,10,10,this);
231 232 233
    fRadCubePlayer->SetMainWindow(this);
    fRadCubePlayer->SetName(Name);
    fRadCubePlayerTab->AddFrame(fRadCubePlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
234
    ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,Name);
235

Jérémie Dudouet's avatar
Jérémie Dudouet committed
236 237 238 239 240 241 242 243 244
    // ------- LS Player Tool -----------
    Name = "LS Player";
    fLSPlayerToolTab = fMainTab->AddTab(Name);
    fLSPlayerTool = new CXGuiLSPlayer(fLSPlayerToolTab,10,10);
    fLSPlayerTool->SetMainWindow(this);
    fLSPlayerTool->SetName(Name);
    fLSPlayerToolTab->AddFrame(fLSPlayerTool, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,Name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
245 246
    gNDManager->InitLevels();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
247
    //    // ------- Brows File Tool -----------
Jérémie Dudouet's avatar
Jérémie Dudouet committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
    Name = "Files";
    fFileListTab = fMainTab->AddTab(Name);
    fFileList = new CXFileList(fFileListTab,GetWidth(), GetHeight());
    fFileList->SetMainWindow(this);
    fFileList->SetName(Name);
    fFileListTab->AddFrame(fFileList, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
    fMainTab->GetTabTab(fFileList->GetName())->ShowClose();
    ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,fFileList->GetName());

    //    //////////////////******************** partie droite ********************////////////////////////////////
    
    fSplitter = new TGVFileSplitter(fHf,2,2);
    fSplitter->SetFrame(fTGCanvas, kTRUE);
    fHf->AddFrame(fSplitter, new TGLayoutHints(kLHintsLeft | kLHintsExpandY));
    fSplitter->Connect("LayoutHeader(TGFrame *)", "CXMainWindow", this, "DoRefresh()");

    fVFRight = new TGVerticalFrame(fHf, 10, 10);
    fHf->AddFrame(fVFRight, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY));
    
    fListOfCanvases = new TList();
    
    fCanvasTab = new TGTab(fVFRight);
    fCanvasTab->Connect("CloseTab(Int_t)", "CXMainWindow", this, "CloseCanvasTab(Int_t)");
    fCanvasTab->Connect("Selected(Int_t)", "CXMainWindow", this, "DoTab(Int_t)");
    fVFRight->AddFrame(fCanvasTab, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));

    NewTab();
    DoTab();

    //------- Editor -----------
    fEditorTab = fMainTab->AddTab("Editor");
    fEditorTab->SetEditable();
    fEditor = TVirtualPadEditor::LoadEditor();
    fEditor->SetGlobal(kFALSE);
    fEditorTab->SetEditable(kFALSE);
    ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,"Editor");

    // status bar
    Int_t parts[] = {20 , 20 , 20 , 20 ,20};
    fStatusBar = new TGStatusBar(fVFRight,50,10,kHorizontalFrame);
    fStatusBar->SetParts(parts,5);
    fStatusBar->Draw3DCorner(kFALSE);
    fVFRight->AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 0, 0, 2, 0));
    
    AddFrame(fHf, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY));
    
    UpdateContextMenus();

    // What to clean up in destructor
    SetCleanup(kDeepCleanup);
    
    // Set a name to the main frame
    SetWindowName("Cubix Spectra Player");
301 302 303
    SetIconPixmap("Cubix.png");
    SetIconName("Cubix");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
304 305 306 307 308 309 310 311
    MapSubwindows();
    Layout();
    Resize(GetDefaultSize());
    MapWindow();

    gSystem->ProcessEvents();

    ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,fFileList->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
312 313 314 315

    fListOfSavedGates = new TList;
    fListOfSavedGates->SetOwner();
    fListOfSavedGates->SetName("ListOfGates");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
316 317

//    HandleMenu(M_NucChart);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
318 319 320 321 322 323 324 325 326
}

CXMainWindow::~CXMainWindow()
{
    
}

void CXMainWindow::HandleMovement(Int_t EventType, Int_t EventX, Int_t EventY, TObject *selected)
{
Jérémie Dudouet's avatar
Jérémie Dudouet committed
327 328
    SetPalette();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
    fSelectedPad = fCanvas->GetClickSelectedPad();

    if(gPad && selected != nullptr)
    {
        const char *text0, *text1, *text2, *text4;
        char text3[50];
        text0 = selected->ClassName();
        SetStatusText(text0,0);
        text1 = selected->GetTitle();
        SetStatusText(text1,1);
        text2 = selected->GetName();
        SetStatusText(text2,2);

        if(fCanvas->GetCrosshair() == 1 && (selected->InheritsFrom("TFrame") || selected->InheritsFrom("TH1") || selected->InheritsFrom("CXCanvas") || selected->InheritsFrom("TPad")))
        {
            if (EventType == kButton2){
                fRefX = gPad->AbsPixeltoX(EventX);
                fRefY = gPad->AbsPixeltoY(EventY);
            }
            if (EventType == kButton1){
                fRefX = 0;
                fRefY = 0;
            }
        }

        if (EventType == kKeyPress)
            sprintf(text3, "%c", (char) EventY);
        else
            sprintf(text3, "%.2f,%.2f", gPad->AbsPixeltoX(EventX)- fRefX, gPad->AbsPixeltoY(EventY) - fRefY );
        SetStatusText(text3,3);

        text4 = selected->GetObjectInfo(EventX,EventY);
        SetStatusText(text4,4);
    }

    //    if (EventType == kButton1Down)
    //    {
    //        if(fMainTab->GetCurrentTab() == fMainTab->GetTabTab("Editor")) fMainTab->CloseTab(fMainTab->GetCurrent());
    //    }

    /// Recuperation de la derniere position de la souris

371
    if(EventType == kMouseMotion) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
372 373 374
        fCanvas->AbsPixeltoXY(EventX,EventY,fLastXPosition,fLastYPosition);
    }

375
    if(EventType == kKeyPress) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
376
        if((EKeySym)EventY==kKey_f && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
377 378 379 380
            if(IsHist1DPlayerEnabled==false)
                ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());
            fMainTab->SetTab(fHist1DPlayer->GetName());

Jérémie Dudouet's avatar
Jérémie Dudouet committed
381
            fHist1DPlayer->NewFit();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
382
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
383
        if((EKeySym)EventY==kKey_f && fCTRL) {
384
            fHist1DPlayer->DoFit();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
385 386
        }
        if((EKeySym)EventY==kKey_s && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
387 388 389 390
            if(IsHist1DPlayerEnabled==false)
                ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());
            fMainTab->SetTab(fHist1DPlayer->GetName());

Jérémie Dudouet's avatar
Jérémie Dudouet committed
391
            fHist1DPlayer->PeakSearchClear();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
392 393
            fHist1DPlayer->PeakSearch();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
394 395 396
        if((EKeySym)EventY==kKey_c && !fCTRL) {
            fHist1DPlayer->ClearFits();
            fHist1DPlayer->PeakSearchClear();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
397
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
398
        if((EKeySym)EventY==kKey_n && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
399 400
            NewTab();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
401
        if((EKeySym)EventY==kKey_S && !fCTRL && selected && (selected->InheritsFrom("TH1") || selected->InheritsFrom("TGraph") || selected->InheritsFrom("TF1") )) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
402 403
            AddToStoredSpectra(selected);
        }
404 405 406
        if((EKeySym)EventY==kKey_r && !fCTRL && selected && (selected->InheritsFrom(CXArrowBox::Class()))) {
            ((CXArrowBox*)selected)->Clean();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
407 408 409
    }

    /// Don't work with the touch pad
Jérémie Dudouet's avatar
Jérémie Dudouet committed
410 411 412 413 414
    //    if(EventType == kMouseMotion && fLastEventType == kButton1Up && EventX==fLastEventX && EventY==fLastEventY ) //equivalent to escape
    //    {
    //        if(fHist1DPlayer->IsCurrentFit())
    //            fHist1DPlayer->EndFit();
    //    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440

    fLastEventType = EventType;
    fLastEventX = EventX;
    fLastEventY = EventY;
    fLastSelected = selected;

}

void CXMainWindow::SetStatusText(const char *txt, Int_t pi)
{
    // Set text in status bar.
    if(fStatusBar!=0x0) fStatusBar->SetText(txt,pi);
}

void CXMainWindow::CloseToolsTab(Int_t tabnr)
{
    TGTabElement *tab = fMainTab->GetTabTab(tabnr);
    TString Name = tab->GetText()->Data();
    if(Name==fFileList->GetName())
        ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,Name);
    else if(Name==fLSPlayerTool->GetName())
        ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,Name);
    else if(Name==fHist1DPlayer->GetName())
        ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,Name);
    else if(Name==fHist2DPlayer->GetName())
        ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
441 442
    else if(Name==fRad2DPlayer->GetName())
        ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,Name);
443 444
    else if(Name==fRadCubePlayer->GetName())
        ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
445 446 447 448
    else if(Name=="Editor")
        ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,Name);
    else if(Name==fBkdSubtract->GetName())
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
449 450
    else if(Name==fSavedList->GetName())
        ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511
}

void CXMainWindow::CloseTab(TGTab *tab, Int_t tabnr)
{
    for(int i=0 ; i<fCanvas->GetListOfPrimitives()->GetEntries() ; i++)
    {
        TObject *o = fCanvas->GetListOfPrimitives()->At(i);
        if(o->InheritsFrom("TH1"))
            delete o;
    }

    TGFrameElement *el = 0;
    if (tab->GetTabContainer(tabnr))
        el = (TGFrameElement *)tab->GetTabContainer(tabnr)->GetList()->First();
    
    if (el && el->fFrame) {
        el->fFrame->Disconnect("ProcessedConfigure(Event_t*)");
        el->fFrame->SetFrameElement(0);
        if (el->fFrame->InheritsFrom("TGMainFrame")) {
            Bool_t sleep = (el->fFrame->InheritsFrom("TRootCanvas")) ? kTRUE : kFALSE;
            ((TGMainFrame *)el->fFrame)->CloseWindow();
            if (sleep)
                gSystem->Sleep(150);
            gSystem->ProcessEvents();
        }
        else
            delete el->fFrame;
        el->fFrame = 0;
        if (el->fLayout && (el->fLayout != fgDefaultHints) &&
                (el->fLayout->References() > 0)) {
            el->fLayout->RemoveReference();
            if (!el->fLayout->References()) {
                delete el->fLayout;
            }
        }
        tab->GetTabContainer(tabnr)->GetList()->Remove(el);
        delete el;
        tab->RemoveTab(tabnr);
    }
    
    if(tab == fCanvasTab) fListOfCanvases->RemoveAt(tabnr);
}

void CXMainWindow::DoTab(Int_t tabnr)
{
    fCanvas = (CXCanvas*)fListOfCanvases->At(tabnr);
    fSelectedPad = fCanvas->cd();
    if(fCanvas->GetUniqueID() == 666)
        fSelectedPad = fCanvas->cd(1);
    fCanvas->SetSelectedPad((TPad*)fSelectedPad);
    fCanvas->Update();

    //------- Editor -----------
    if(fEditorTab != nullptr)
    {
        delete fEditor;
        fEditorTab->SetEditable();
        fEditor = TVirtualPadEditor::LoadEditor();
        fEditor->SetGlobal(kFALSE);
        fEditorTab->SetEditable(kFALSE);
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532

    TString name = fCanvasTab->GetTabTab(tabnr)->GetText()->Data();

    if(name.BeginsWith("RadCube")) {
        if(IsRadCubePlayerEnabled)
            fMainTab->SetTab(fRadCubePlayer->GetName());
        else
            ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,fRadCubePlayer->GetName());
    }
    else if(name.BeginsWith("RadGG")) {
        if(IsRad2DPlayerEnabled)
            fMainTab->SetTab(fRad2DPlayer->GetName());
        else
            ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,fRad2DPlayer->GetName());
    }
    else if(name.BeginsWith("GxG")) {
        if(IsHist2DPlayerEnabled)
            fMainTab->SetTab(fHist2DPlayer->GetName());
        else
            ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,fHist2DPlayer->GetName());
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
533 534 535 536 537 538 539 540
}

void CXMainWindow::NewTab(Int_t px, Int_t py, TString name)
{
    TString TabName = Form("Canvas %d",fCanvasTab->GetNumberOfTabs());
    if(name != "")
        TabName = name;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
541
    while(fCanvasTab->GetTabTab(TabName)) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
542 543 544 545
        TObjArray *arr = TabName.Tokenize("_");
        TString last = arr->Last()->GetName();
        delete arr;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
546
        if(last.IsDigit()) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
547 548 549
            Int_t n = last.Atoi();
            TabName.ReplaceAll(Form("_%d",n),Form("_%d",n+1));
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
550
        else {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
            TabName.Append("_2");
        }
    }
    
    TGCompositeFrame *atab = fCanvasTab->AddTab(TabName);
    fCanvasTab->GetTabTab(TabName)->ShowClose();

    fToolBar = new CXGuiToolbar(atab, 60, 20, kHorizontalFrame);

    atab->AddFrame(fToolBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX));

    fRootCanvas = new TRootEmbeddedCanvas("ec1", atab);
    atab->AddFrame(fRootCanvas, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5));
    Int_t canvasid = fRootCanvas->GetCanvasWindowId();
    fCanvas = new CXCanvas(TabName.Copy().ReplaceAll(" ","_"), 10, 10, canvasid);
    fCanvas->SetMainWindow(this);
    fListOfCanvases->Add(fCanvas);
    fCanvas->ToggleToolBar();
    fRootCanvas->AdoptCanvas(fCanvas);
    fRootCanvas->GetContainer()->Connect("ProcessedEvent(Event_t*)", "CXMainWindow", this, "ProcessedKeyEvent(Event_t*)");

Jérémie Dudouet's avatar
Jérémie Dudouet committed
572 573 574 575
    fCanvas->SetRightMargin(0.01);
    fCanvas->SetBottomMargin(0.09);
    fCanvas->SetLeftMargin(0.083);
    fCanvas->SetTopMargin(0.04);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608

    fCanvas->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)", "CXMainWindow", this, "HandleMovement(Int_t,Int_t,Int_t, TObject*)");

    if(px*py>1)
    {
        fCanvas->SetUniqueID(666);
        fCanvas->cd();
        fCanvas->Divide(px,py,0.001,0.001);
        fCanvas->Update();

        for(int i=0 ;i<px*py ; i++){
            TVirtualPad *pad = fCanvas->GetPad(i+1);
            pad->cd();
            pad->SetLeftMargin(0.05);
            pad->SetRightMargin(fCanvas->GetRightMargin());
            pad->SetBottomMargin(fCanvas->GetBottomMargin());
            pad->SetTopMargin(fCanvas->GetTopMargin());
            pad->DrawFrame(0,0,1,1);
            pad->Update();
            pad->SetBit(TPad::kCannotMove);
            pad->GetFrame()->SetBit(TObject::kCannotPick);
        }

        fCanvas->SetClickSelectedPad((TPad*) fCanvas->GetPad(1));
        fSelectedPad = (TPad*) fCanvas->GetPad(1);
    }
    else
    {
        fCanvas->DrawFrame(0,0,1,1);
        fCanvas->SetClickSelectedPad((TPad*)fCanvas);
        fSelectedPad = (TPad*) fCanvas;
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
609 610
    fCanvas->SetNPads(px*py);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646
    fCanvas->Update();
    fCanvas->GetFrame()->SetBit(TObject::kCannotPick);

    fCanvasTab->SetTab(fCanvasTab->GetNumberOfTabs()-1);

    fToolBar->SetCanvas(fCanvas);

    fCanvasTab->MapSubwindows();
    fCanvasTab->Layout();
}

void CXMainWindow::HandleMenu(Int_t id)
{
    // Handle menu items.
    switch (id) {
    case M_New_Canvas:
        NewTab();
        break;
    case M_New_Browser:
        new TBrowser;
        break;
    case M_Save_As:
        fCanvas->SaveCanvasAs();
        break;
    case M_Save_To_Ascii:
        SaveToAscii();
        break;
    case M_Exit:
        CloseWindow();
        break;
    case M_Editor:
        ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,"Editor");
        break;
    case M_BkdUtility:
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,fBkdSubtract->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
647 648 649
    case M_SavedList:
        ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,fSavedList->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
650 651 652 653 654 655
    case M_Hist1DPlayer:
        ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,fHist1DPlayer->GetName());
        break;
    case M_Hist2DPlayer:
        ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,fHist2DPlayer->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
656 657 658
    case M_Rad2DPlayer:
        ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,fRad2DPlayer->GetName());
        break;
659 660 661
    case M_RadCubePlayer:
        ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,fRadCubePlayer->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
662 663 664 665 666 667
    case M_LSPlayerUtility:
        ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,fLSPlayerTool->GetName());
        break;
    case M_FileListUtility:
        ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,fFileList->GetName());
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691
    case M_ShowStats:
        IsStatsShown = 1-IsStatsShown;
        if(IsStatsShown) {
            fMenuOptions->CheckEntry(M_ShowStats);
            gStyle->SetOptStat(1000011);
        }
        else {
            fMenuOptions->UnCheckEntry(M_ShowStats);
            gStyle->SetOptStat(0);
        }
        RefreshPads();
        break;
    case M_ShowTitle:
        IsTitleShown = 1-IsTitleShown;
        if(IsTitleShown) {
            fMenuOptions->CheckEntry(M_ShowTitle);
            gStyle->SetOptTitle(1);
        }
        else {
            fMenuOptions->UnCheckEntry(M_ShowTitle);
            gStyle->SetOptTitle(0);
        }
        RefreshPads();
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
692 693 694 695 696 697
    case M_GammaSearch:
        if(fGammaSearchWindow == nullptr)
            fGammaSearchWindow = new CXGammaSearch(gClient->GetRoot(),gClient->GetRoot(),1200,450, this);
        else
            fGammaSearchWindow->MapRaised();
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
698 699 700 701 702 703
    case M_NucChart:
        if(fNucChartWindow == nullptr)
            fNucChartWindow = new CXNucChart(gClient->GetRoot(),gClient->GetRoot(),1200,550, this);
        else
            fNucChartWindow->MapRaised();
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
704 705 706 707 708 709 710 711 712 713 714 715 716 717

        if(gPad != 0x0)
        {
            gPad->Modified();
            gPad->Update();
        }
        break;
    }
}

void CXMainWindow::ToggleTab(Bool_t &Enable, ETestCommandIdentifiers id, TGCompositeFrame *tab, const char * name)
{
    if(!Enable)
    {
718 719 720 721
        //        if(fMenuView->GetEntry(id))
        //            fMenuView->CheckEntry(id);
        //        if(fMenuTools->GetEntry(id))
        //            fMenuTools->CheckEntry(id);
722

Jérémie Dudouet's avatar
Jérémie Dudouet committed
723 724 725 726 727 728 729
        fMainTab->AddTab(name,tab);

        fMainTab->SetTab(name);
        fMainTab->GetTabTab(name)->ShowClose();

        if(tab != fEditorTab) tab->MapSubwindows();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754
        if(fMainTab->GetNumberOfTabs()>3){
            TString Name = fMainTab->GetTabTab(0)->GetText()->GetString();

            if(Name==fFileList->GetName())
                ToggleTab(IsFileListUtilityEnabled,M_FileListUtility,fFileListTab,Name);
            else if(Name==fLSPlayerTool->GetName())
                ToggleTab(IsLSPlayerToolEnabled,M_LSPlayerUtility,fLSPlayerToolTab,Name);
            else if(Name==fHist1DPlayer->GetName())
                ToggleTab(IsHist1DPlayerEnabled,M_Hist1DPlayer,fHist1DPlayerTab,Name);
            else if(Name==fHist2DPlayer->GetName())
                ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,Name);
            else if(Name==fRad2DPlayer->GetName())
                ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,Name);
            else if(Name==fRadCubePlayer->GetName())
                ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,Name);
            else if(Name=="Editor")
                ToggleTab(IsEditorEnabled,M_Editor,fEditorTab,Name);
            else if(Name==fBkdSubtract->GetName())
                ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,Name);
            else if(Name==fSavedList->GetName())
                ToggleTab(IsSavedListEnabled,M_SavedList,fSavedListTab,Name);
        }

        fMainTab->SetTab(name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
755 756 757 758
        Layout();
    }
    else
    {
759 760 761 762
        //        if(fMenuView->GetEntry(id))
        //            fMenuView->UnCheckEntry(id);
        //        if(fMenuTools->GetEntry(id))
        //            fMenuTools->UnCheckEntry(id);
763

Jérémie Dudouet's avatar
Jérémie Dudouet committed
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822
        fMainTab->SetTab(name);
        fMainTab->RemoveTab(fMainTab->GetCurrent());
    }

    Enable = !Enable;
}


void CXMainWindow::SaveCanvasAs()
{
    
    const char* SaveAsTypes[] = {
        "PDF",          "*.pdf",
        "PostScript",   "*.ps",
        "Encapsulated PostScript", "*.eps",
        "SVG",          "*.svg",
        "TeX",          "*.tex",
        "GIF",          "*.gif",
        "ROOT macros",  "*.C",
        "ROOT files",   "*.root",
        "XML",          "*.xml",
        "PNG",          "*.png",
        "XPM",          "*.xpm",
        "JPEG",         "*.jpg",
        "TIFF",         "*.tiff",
        "XCF",          "*.xcf",
        "All files",    "*",
        0,              0
    };
    
    TString workdir = gSystem->WorkingDirectory();
    static TString dir(".");
    static Int_t typeidx = 0;
    static Bool_t overwr = kFALSE;
    TGFileInfo fi;
    fi.fFileTypes   = SaveAsTypes;
    fi.fIniDir      = StrDup(dir);
    fi.fFileTypeIdx = typeidx;
    fi.fOverwrite   = overwr;
    new TGFileDialog(gClient->GetDefaultRoot(), gClient->GetDefaultRoot(), kFDSave, &fi);
    gSystem->ChangeDirectory(workdir.Data());
    if (!fi.fFilename) return;
    TString fn = fi.fFilename;
    dir     = fi.fIniDir;
    typeidx = fi.fFileTypeIdx;
    overwr  = fi.fOverwrite;

    if(!fn.EndsWith(fi.fFileTypes[1]))
        fn.Append(fi.fFileTypes[1]);

    fCanvas->SaveAs(fn);
}

void CXMainWindow::DoRefresh()
{
    fMainTab->Resize(10,10);
    Layout();
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
823 824 825 826 827 828 829 830 831 832 833 834 835 836
void CXMainWindow::RefreshPads()
{   
    TList *pList = fCanvas->GetListOfPrimitives();
    TObjOptLink *lnk = 0;
    if (pList) lnk = (TObjOptLink*)pList->FirstLink();
    TObject *obj;
    while (lnk) {
        obj = lnk->GetObject();
        if (obj->InheritsFrom(TPad::Class())) {
            ((TPad*)obj)->Modified();
        }
        lnk = (TObjOptLink*)lnk->Next();
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
837 838 839
    gPad->Modified();
    gPad->Update();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
840
    fCanvas->Modified();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
841
    fCanvas->Update();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
842 843 844 845 846 847 848
}

void CXMainWindow::CloseWindow()
{
    if(fGammaSearchWindow)
        fGammaSearchWindow->CloseWindow();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
849 850 851
    if(fNucChartWindow)
        fNucChartWindow->CloseWindow();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
852 853 854 855 856 857 858 859 860
    UnmapWindow();
    DeleteWindow();//  launch a delete but after a short time like a thread.

    cout << " Bye Bye Cubix!" <<endl;

    gApplication->SetReturnFromRun(false);
    gApplication->Terminate(false);
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
861
TH1 *CXMainWindow::GetHisto(TVirtualPad *pad, bool GetFirst)
Jérémie Dudouet's avatar
Jérémie Dudouet committed
862
{
Jérémie Dudouet's avatar
Jérémie Dudouet committed
863
    TH1 *hist = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
864

Jérémie Dudouet's avatar
Jérémie Dudouet committed
865 866 867 868
    if(pad == nullptr && fSelectedPad == nullptr) {
        fCanvas->cd();
        fSelectedPad = fCanvas->cd();
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
869 870 871
    if(pad == nullptr)
        pad = fSelectedPad;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
872 873
    TObjOptLink *lnk = nullptr;
    TObject *obj = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
874

Jérémie Dudouet's avatar
Jérémie Dudouet committed
875 876 877 878 879 880 881 882
    TList *pList = pad->GetListOfPrimitives();
    if (pList) lnk = (TObjOptLink*)pList->FirstLink();

    while (lnk) {
        obj = lnk->GetObject();
        if (obj->InheritsFrom(TH1::Class())) {
            hist = dynamic_cast<TH1*>(obj);
            if(GetFirst) return hist;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
883
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
884
        lnk = (TObjOptLink*)lnk->Next();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
885 886
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
887
    return hist;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
888 889 890 891
}

void CXMainWindow::UpdateContextMenus()
{
892
    /// TH1F ///
Jérémie Dudouet's avatar
Jérémie Dudouet committed
893 894 895 896 897 898
    TClass *cl = gROOT->GetClass("TH1F");
    cl->MakeCustomMenuList();
    TList * ml = cl->GetMenuList();

    TClassMenuItem *n;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
899 900 901 902
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Copy","CopyObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Cut","CutObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Undraw","UndrawObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
903

Jérémie Dudouet's avatar
Jérémie Dudouet committed
904 905 906 907
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Fit Peaks","PopUpFitPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Find Peaks","PopUpFindPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Show Background","PopUpShowBackground",this,"TObject *",0); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
908

Jérémie Dudouet's avatar
Jérémie Dudouet committed
909 910 911
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-9);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
912
    ml->RemoveAt(ml->GetEntries()-13);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
913
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-14);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
914

Jérémie Dudouet's avatar
Jérémie Dudouet committed
915 916
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0); ml->AddAt(n,5);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1); ml->AddAt(n,5);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
917

918
    /// TH1D///
Jérémie Dudouet's avatar
Jérémie Dudouet committed
919 920 921 922
    cl = gROOT->GetClass("TH1D");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
923 924 925 926
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Copy","CopyObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Cut","CutObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Undraw","UndrawObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
927

Jérémie Dudouet's avatar
Jérémie Dudouet committed
928 929 930 931
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Fit Peaks","PopUpFitPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Find Peaks","PopUpFindPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Show Background","PopUpShowBackground",this,"TObject *",0); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
932

Jérémie Dudouet's avatar
Jérémie Dudouet committed
933 934 935
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-9);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
936
    ml->RemoveAt(ml->GetEntries()-13);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
937
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-14);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
938

Jérémie Dudouet's avatar
Jérémie Dudouet committed
939 940
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0); ml->AddAt(n,5);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1); ml->AddAt(n,5);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
941 942 943 944 945 946

    /// TH1Proj ///
    cl = gROOT->GetClass("CXTH1Proj");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
947 948
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Copy","CopyObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Undraw","UndrawObject",fCanvas,"TObject *",0); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
949

Jérémie Dudouet's avatar
Jérémie Dudouet committed
950
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
951

Jérémie Dudouet's avatar
Jérémie Dudouet committed
952 953 954 955
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Fit Peaks","PopUpFitPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Find Peaks","PopUpFindPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Show Background","PopUpShowBackground",this,"TObject *",0); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
956

Jérémie Dudouet's avatar
Jérémie Dudouet committed
957 958 959
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-9);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
960
    ml->RemoveAt(ml->GetEntries()-13);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
961 962 963 964 965 966 967 968 969 970 971 972 973 974
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-14);

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0); ml->AddAt(n,5);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1); ml->AddAt(n,5);

    /// CXRadCubeTH1Proj ///
    cl = gROOT->GetClass("CXRadCubeTH1Proj");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Copy","CopyObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Undraw","UndrawObject",fCanvas,"TObject *",0); ml->AddFirst(n);

    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
975

Jérémie Dudouet's avatar
Jérémie Dudouet committed
976 977 978 979
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Fit Peaks","PopUpFitPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Find Peaks","PopUpFindPeaks",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Show Background","PopUpShowBackground",this,"TObject *",0); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
980

Jérémie Dudouet's avatar
Jérémie Dudouet committed
981 982 983 984 985
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-9);
    ml->RemoveAt(ml->GetEntries()-13);
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-14);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
986

Jérémie Dudouet's avatar
Jérémie Dudouet committed
987 988
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0); ml->AddAt(n,5);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1); ml->AddAt(n,5);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
989 990 991 992 993 994

    /// TH2F ///
    cl = gROOT->GetClass("TH2F");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
995 996 997 998
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Copy","CopyObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Cut","CutObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Undraw","UndrawObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
999

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1000 1001 1002 1003
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Eval Background","PopUpEval2DBackground",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Init Radware GxG","PopUpInitRadGG",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Init GxG","PopUpInitGG",this,"TObject *",0); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1004

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1005 1006
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-3);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1007
    ml->RemoveAt(ml->GetEntries()-9);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1008
    for(int i=0 ; i<7 ; i++) ml->RemoveAt(ml->GetEntries()-12);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1009

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1010
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Rebin","Rebin2D",this,"Int_t, Int_t, TObject*", 2); ml->AddAt(n,12);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1011 1012 1013 1014 1015 1016 1017
    //    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);

    /// TH2D ///
    cl = gROOT->GetClass("TH2D");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1018 1019 1020 1021
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Copy","CopyObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Cut","CutObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Undraw","UndrawObject",fCanvas,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1022

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1023 1024 1025 1026
        n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Add to Stored spectra","AddToStoredSpectra",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Eval Background","PopUpEval2DBackground",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Init Radware GxG","PopUpInitRadGG",this,"TObject *",0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl, "Init GxG","PopUpInitGG",this,"TObject *",0); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1027

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1028 1029
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
    for(int i=0 ; i<4 ; i++) ml->RemoveAt(ml->GetEntries()-3);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1030
    ml->RemoveAt(ml->GetEntries()-9);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1031
    for(int i=0 ; i<7 ; i++) ml->RemoveAt(ml->GetEntries()-12);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1032

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1033
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Rebin","Rebin2D",this,"Int_t, Int_t, TObject*", 2); ml->AddAt(n,12);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1034
    //    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1035 1036 1037 1038 1039 1040

    /// CXArrow ///
    cl = gROOT->GetClass("CXArrow");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1041
    for(int i=0 ; i<18 ; i++) ml->RemoveAt(ml->GetEntries()-1);
1042 1043 1044 1045 1046

    /// TGraph ///
    cl = gROOT->GetClass("TGraph");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1047
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","GraphScale",this,"Float_t,TObject*", 1); ml->AddAt(n,3);
1048 1049 1050 1051 1052

    /// TGraphErrors ///
    cl = gROOT->GetClass("TGraphErrors");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1053
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","GraphScale",this,"Float_t,TObject*", 1); ml->AddAt(n,3);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1054
    //    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl);ml->AddAt(n,ml->GetEntries()-4);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064
}

void CXMainWindow::Rebin2D(Int_t RebinX, Int_t RebinY, TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);
    TString DrawOpt = hist->GetDrawOption();
    if(DrawOpt=="")
        DrawOpt = "col";
    hist = hist->Rebin2D(RebinX,RebinY,hist->GetName());
    hist->Draw(DrawOpt);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1065
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090
}

void CXMainWindow::PopUpEval2DBackground(TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);

    if(IsBkdUtilityEnabled==false)
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,fBkdSubtract->GetName());

    fMainTab->SetTab(fBkdSubtract->GetName());

    fBkdSubtract->Do2DEvaluation(hist);
}

void CXMainWindow::PopUpInitGG(TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);

    if(IsHist2DPlayerEnabled==false)
        ToggleTab(IsHist2DPlayerEnabled,M_Hist2DPlayer,fHist2DPlayerTab,fHist2DPlayer->GetName());

    fMainTab->SetTab(fHist2DPlayer->GetName());

    fHist2DPlayer->InitGG(hist);
}
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104

void CXMainWindow::PopUpInitRadGG(TObject *c)
{
    TH2 *hist = static_cast<TH2*>(c);

    if(IsRad2DPlayerEnabled==false)
        ToggleTab(IsRad2DPlayerEnabled,M_Rad2DPlayer,fRad2DPlayerTab,fRad2DPlayer->GetName());

    fMainTab->SetTab(fRad2DPlayer->GetName());

    fRad2DPlayer->Init(hist);
}

void CXMainWindow::InitRadCubePlayer(CXRadReader *radreader)
1105 1106 1107 1108 1109 1110 1111 1112 1113
{
    if(IsRadCubePlayerEnabled==false)
        ToggleTab(IsRadCubePlayerEnabled,M_RadCubePlayer,fRadCubePlayerTab,fRadCubePlayer->GetName());

    fMainTab->SetTab(fRadCubePlayer->GetName());

    fRadCubePlayer->Init(radreader);
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125

void CXMainWindow::HistNorm(TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    Float_t x1,x2;
    x1=gPad->GetUxmin();
    x2=gPad->GetUxmax();
    hist->GetXaxis()->UnZoom();
    hist->Scale(1./hist->Integral());
    hist->GetXaxis()->SetRangeUser(x1,x2);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1126
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1127 1128 1129 1130 1131 1132 1133 1134
}

void CXMainWindow::HistScale(Float_t scaleFact, TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    hist->Scale(scaleFact);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1135
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1136 1137
}

1138 1139 1140 1141 1142 1143 1144 1145
void CXMainWindow::GraphScale(Float_t scaleFact, TObject *c)
{
    TGraph *graph = static_cast<TGraph*>(c);

    for(int i=0 ; i<graph->GetN() ; i++){
        graph->SetPoint(i,graph->GetX()[i],graph->GetY()[i]*scaleFact);
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1146
    RefreshPads();
1147 1148
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1149 1150 1151 1152 1153 1154 1155 1156
void CXMainWindow::PopUpShowBackground(TObject *c)
{
    TH1 *hist = static_cast<TH1*>(c);

    if(GetHisto()->GetName() != hist->GetName())
    {
        fCanvas->cd();
        hist->Draw("hist");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1157
        RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1158 1159 1160 1161 1162 1163 1164 1165
    }
    if(IsBkdUtilityEnabled==false)
        ToggleTab(IsBkdUtilityEnabled,M_BkdUtility,fBkdToolTab,fBkdSubtract->GetName());

    fMainTab->SetTab(fBkdSubtract->GetName());

    fBkdSubtract->DoActivate();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1166
    RefreshPads();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
1167 1168
}

Jérémie Dudouet's avatar
Jérémie Dudouet committed
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183