CXMainWindow.cpp 51.2 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"
23
#include "TVirtualX.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
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"
31
#include "CXHist1DCalib.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
32
#include "CXHist2DPlayer.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
33
#include "CXRad2DPlayer.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
34
#include "CXGammaSearch.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
35
#include "CXNucChart.h"
36
#include "CXRadReader.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
37 38 39 40
#include "CXRadCubePlayer.h"
#include "CXSavedList.h"
#include "CXRadCubeTH1Proj.h"
#include "CXTH1Proj.h"
41
#include "CXArrow.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
42
#include "CXNDManager.h"
Jérémie Dudouet's avatar
Jérémie Dudouet committed
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

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
63 64 65
    if(gNDManager == nullptr)
        gNDManager = new CXNDManager(this);

66
    auto *fHf = new TGHorizontalFrame(this,GetWidth(),GetHeight());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
67 68 69 70 71 72
    
    //------- Menu -----------

    //----------------Menu File--------------------
    
    fMenuFile = new TGPopupMenu(gClient->GetRoot());
73 74 75 76
    fMenuFile->AddEntry("New Canvas", M_New_Canvas, nullptr , gClient->GetPicture("newcanvas.xpm"));
    fMenuFile->AddEntry("New Browser", M_New_Browser, nullptr, gClient->GetPicture("browser.xpm"));
    fMenuFile->AddEntry("Save Canvas as", M_Save_As, nullptr, gClient->GetPicture("bld_save.png"));
    fMenuFile->AddEntry("Save hist to ascii", M_Save_To_Ascii, nullptr, gClient->GetPicture("query_new.xpm"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
77
    fMenuFile->AddSeparator();
78
    fMenuFile->AddEntry("Exit", M_Exit, nullptr, gClient->GetPicture("bld_exit.png"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
79 80 81 82 83 84 85
    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)");

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

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

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

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

100 101 102 103 104 105
    //---------------- Menu Tools --------------------

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

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

107
    fMenuTools->AddEntry("ENSDF reader", M_LSPlayerUtility,nullptr,gClient->GetPicture("levelscheme_t.png"));
108

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

112
    fMenuTools->AddEntry("Peak fitter", M_Hist1DPlayer,nullptr,gClient->GetPicture("FitTool.xpm"));
113
    //    fMenuTools->CheckEntry(M_Hist1DPlayer);
114 115
    IsHist1DPlayerEnabled= true;

116
    fMenuTools->AddEntry("Energy calibration", M_Hist1DCalib,nullptr,gClient->GetPicture("calib.png"));
117 118 119
    //    fMenuTools->CheckEntry(M_Hist1DPlayer);
    IsHist1DCalibPlayerEnabled= true;

120
    fMenuTools->AddEntry("Background player", M_BkdUtility,nullptr,gClient->GetPicture("h1_t.xpm"));
121
    //    fMenuTools->CheckEntry(M_BkdUtility);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
122 123
    IsBkdUtilityEnabled = true;

124 125 126
    fMenuTools->AddSeparator();
    fMenuTools->AddLabel("2D Tools...",gClient->GetPicture("h2_t.xpm"));
    fMenuTools->AddSeparator();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
127

128
    fMenuTools->AddEntry("GxG standard", M_Hist2DPlayer,nullptr,gClient->GetPicture("h2_t.xpm"));
129
    //    fMenuTools->CheckEntry(M_Hist2DPlayer);
130
    IsHist2DPlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
131

132
    fMenuTools->AddEntry("GxG radware's style", M_Rad2DPlayer,nullptr,gClient->GetPicture("rw3.gif"));
133
    //    fMenuTools->CheckEntry(M_Rad2DPlayer);
134
    IsRad2DPlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
135

136 137 138 139
    fMenuTools->AddSeparator();
    fMenuTools->AddLabel("3D Tools...",gClient->GetPicture("h3_t.xpm"));
    fMenuTools->AddSeparator();

140
    fMenuTools->AddEntry("GxGxG radware's style", M_RadCubePlayer,nullptr,gClient->GetPicture("rw3.gif"));
141
    //    fMenuTools->CheckEntry(M_RadCubePlayer);
142
    IsRadCubePlayerEnabled= true;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
143 144

    fMenuTools->AddSeparator();
145 146 147
    fMenuTools->AddLabel("Others...");
    fMenuTools->AddSeparator();

148 149
    fMenuTools->AddEntry("Gamma search", M_GammaSearch,nullptr,gClient->GetPicture("ed_find.png"));
    fMenuTools->AddEntry("Nuclear Chart", M_NucChart,nullptr,gClient->GetPicture("app-map-icon.png"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
150 151 152

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
153 154 155
    //---------------- Menu Options --------------------

    fMenuOptions = new TGPopupMenu(gClient->GetRoot());
156 157
    fMenuOptions->AddEntry("Show Stats", M_ShowStats,nullptr,gClient->GetPicture("stats.png"));
    fMenuOptions->AddEntry("Show Title", M_ShowTitle,nullptr,gClient->GetPicture("eve_text.gif"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
158 159 160 161 162 163

    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
164 165 166 167 168
    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
169
    fMenuBar->AddPopup("Options", fMenuOptions, new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
170

171
    auto *fline = new TGHorizontal3DLine(this);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
172 173 174 175 176 177 178
    AddFrame(fline,new TGLayoutHints(kLHintsExpandX));

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

179
    auto *VFrame = new TGVerticalFrame(fTGCanvas->GetViewPort());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
180 181
    fTGCanvas->SetContainer(VFrame);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
182
    fTGCanvas->Resize(GetWidth()*0.27, GetHeight());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
183 184 185 186 187 188 189

    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
190 191 192 193 194 195 196
    // ------- 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));
197
    ToggleTab(IsSavedListEnabled,fSavedListTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
198

Jérémie Dudouet's avatar
Jérémie Dudouet committed
199 200 201 202 203 204 205
    // ------- 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));
206
    ToggleTab(IsBkdUtilityEnabled,fBkdToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
207 208 209 210 211 212 213 214

    // ------- 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));
215
    ToggleTab(IsHist1DPlayerEnabled,fHist1DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
216

217 218 219 220 221 222 223
    // ------- Hist1D Calib -----------
    Name = "1D Calib";
    fHist1DCalibTab = fMainTab->AddTab(Name);
    fHist1DCalib = new CXHist1DCalib(fHist1DCalibTab,10,10);
    fHist1DCalib->SetMainWindow(this);
    fHist1DCalib->SetName(Name);
    fHist1DCalibTab->AddFrame(fHist1DCalib, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
224
    ToggleTab(IsHist1DCalibPlayerEnabled,fHist1DCalibTab,Name);
225

Jérémie Dudouet's avatar
Jérémie Dudouet committed
226 227 228
    // ------- Hist2D Player -----------
    Name = "2D Player";
    fHist2DPlayerTab = fMainTab->AddTab(Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
229
    fHist2DPlayer = new CXHist2DPlayer(fHist2DPlayerTab,10,10,this);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
230 231
    fHist2DPlayer->SetName(Name);
    fHist2DPlayerTab->AddFrame(fHist2DPlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
232
    ToggleTab(IsHist2DPlayerEnabled,fHist2DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
233

Jérémie Dudouet's avatar
Jérémie Dudouet committed
234 235 236 237 238 239
    // ------- 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));
240
    ToggleTab(IsRad2DPlayerEnabled,fRad2DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
241

242 243 244
    // ------- RadCube Player -----------
    Name = "RadCube Player";
    fRadCubePlayerTab = fMainTab->AddTab(Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
245
    fRadCubePlayer = new CXRadCubePlayer(fRadCubePlayerTab,10,10,this);
246 247 248
    fRadCubePlayer->SetMainWindow(this);
    fRadCubePlayer->SetName(Name);
    fRadCubePlayerTab->AddFrame(fRadCubePlayer, new TGLayoutHints(kLHintsTop | kLHintsLeft | kLHintsExpandX | kLHintsExpandY, 0, 4, 0, 0));
249
    ToggleTab(IsRadCubePlayerEnabled,fRadCubePlayerTab,Name);
250

Jérémie Dudouet's avatar
Jérémie Dudouet committed
251 252 253 254 255 256 257
    // ------- 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));
258
    ToggleTab(IsLSPlayerToolEnabled,fLSPlayerToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
259

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
262
    //    // ------- Brows File Tool -----------
Jérémie Dudouet's avatar
Jérémie Dudouet committed
263 264 265 266 267 268 269
    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();
270
    ToggleTab(IsFileListUtilityEnabled,fFileListTab,fFileList->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
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

    //    //////////////////******************** 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);
298
    ToggleTab(IsEditorEnabled,fEditorTab,"Editor");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
299 300

    // status bar
301
    array<Int_t,5> parts{20 , 20 , 20 , 20 ,20};
Jérémie Dudouet's avatar
Jérémie Dudouet committed
302
    fStatusBar = new TGStatusBar(fVFRight,50,10,kHorizontalFrame);
303
    fStatusBar->SetParts(parts.data(),5);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
304 305 306 307
    fStatusBar->Draw3DCorner(kFALSE);
    fVFRight->AddFrame(fStatusBar, new TGLayoutHints(kLHintsBottom | kLHintsLeft | kLHintsExpandX, 0, 0, 2, 0));
    
    AddFrame(fHf, new TGLayoutHints(kLHintsRight | kLHintsExpandX | kLHintsExpandY));
308

Jérémie Dudouet's avatar
Jérémie Dudouet committed
309 310 311 312 313 314 315
    UpdateContextMenus();

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
319 320 321 322 323 324 325
    MapSubwindows();
    Layout();
    Resize(GetDefaultSize());
    MapWindow();

    gSystem->ProcessEvents();

326
    ToggleTab(IsFileListUtilityEnabled,fFileListTab,fFileList->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
327 328 329 330

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

//    HandleMenu(M_NucChart);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
333 334
}

335
CXMainWindow::~CXMainWindow() = default;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
336 337 338

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
339 340
    SetPalette();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
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 371 372 373 374 375 376 377 378 379 380 381 382
    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

383
    if(EventType == kMouseMotion) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
384 385 386
        fCanvas->AbsPixeltoXY(EventX,EventY,fLastXPosition,fLastYPosition);
    }

387
    if(EventType == kKeyPress) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
388
        if((EKeySym)EventY==kKey_f && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
389
            if(IsHist1DPlayerEnabled==false)
390
                ToggleTab(IsHist1DPlayerEnabled,fHist1DPlayerTab,fHist1DPlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
391 392
            fMainTab->SetTab(fHist1DPlayer->GetName());

Jérémie Dudouet's avatar
Jérémie Dudouet committed
393
            fHist1DPlayer->NewFit();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
394
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
395
        if((EKeySym)EventY==kKey_f && fCTRL) {
396
            fHist1DPlayer->DoFit();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
397 398
        }
        if((EKeySym)EventY==kKey_s && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
399
            if(IsHist1DPlayerEnabled==false)
400
                ToggleTab(IsHist1DPlayerEnabled,fHist1DPlayerTab,fHist1DPlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
401 402
            fMainTab->SetTab(fHist1DPlayer->GetName());

Jérémie Dudouet's avatar
Jérémie Dudouet committed
403
            fHist1DPlayer->PeakSearchClear();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
404 405
            fHist1DPlayer->PeakSearch();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
406 407 408
        if((EKeySym)EventY==kKey_c && !fCTRL) {
            fHist1DPlayer->ClearFits();
            fHist1DPlayer->PeakSearchClear();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
409
        }
410 411 412 413 414 415
        if((EKeySym)EventY==kKey_a && fCTRL) {
            if(IsHist1DCalibPlayerEnabled==false)
                ToggleTab(IsHist1DCalibPlayerEnabled,fHist1DCalibTab,fHist1DCalib->GetName());
            fMainTab->SetTab(fHist1DCalib->GetName());
            fHist1DCalib->Calibrate();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
416
        if((EKeySym)EventY==kKey_n && !fCTRL) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
417 418
            NewTab();
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
419
        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
420 421
            AddToStoredSpectra(selected);
        }
422 423 424
        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
425 426 427
    }

    /// Don't work with the touch pad
Jérémie Dudouet's avatar
Jérémie Dudouet committed
428 429 430 431 432
    //    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
433 434 435 436 437 438 439 440 441 442 443

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

}

void CXMainWindow::SetStatusText(const char *txt, Int_t pi)
{
    // Set text in status bar.
444
    if(fStatusBar!=nullptr) fStatusBar->SetText(txt,pi);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
445 446 447 448 449 450 451
}

void CXMainWindow::CloseToolsTab(Int_t tabnr)
{
    TGTabElement *tab = fMainTab->GetTabTab(tabnr);
    TString Name = tab->GetText()->Data();
    if(Name==fFileList->GetName())
452
        ToggleTab(IsFileListUtilityEnabled,fFileListTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
453
    else if(Name==fLSPlayerTool->GetName())
454
        ToggleTab(IsLSPlayerToolEnabled,fLSPlayerToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
455
    else if(Name==fHist1DPlayer->GetName())
456
        ToggleTab(IsHist1DPlayerEnabled,fHist1DPlayerTab,Name);
457
    else if(Name==fHist1DCalib->GetName())
458
        ToggleTab(IsHist1DCalibPlayerEnabled,fHist1DCalibTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
459
    else if(Name==fHist2DPlayer->GetName())
460
        ToggleTab(IsHist2DPlayerEnabled,fHist2DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
461
    else if(Name==fRad2DPlayer->GetName())
462
        ToggleTab(IsRad2DPlayerEnabled,fRad2DPlayerTab,Name);
463
    else if(Name==fRadCubePlayer->GetName())
464
        ToggleTab(IsRadCubePlayerEnabled,fRadCubePlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
465
    else if(Name=="Editor")
466
        ToggleTab(IsEditorEnabled,fEditorTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
467
    else if(Name==fBkdSubtract->GetName())
468
        ToggleTab(IsBkdUtilityEnabled,fBkdToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
469
    else if(Name==fSavedList->GetName())
470
        ToggleTab(IsSavedListEnabled,fSavedListTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
471 472 473 474 475 476 477 478 479 480 481
}

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;
    }

482
    TGFrameElement *el = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
483 484 485 486 487
    if (tab->GetTabContainer(tabnr))
        el = (TGFrameElement *)tab->GetTabContainer(tabnr)->GetList()->First();
    
    if (el && el->fFrame) {
        el->fFrame->Disconnect("ProcessedConfigure(Event_t*)");
488
        el->fFrame->SetFrameElement(nullptr);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
489 490 491 492 493 494 495 496 497
        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;
498
        el->fFrame = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531
        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
532 533 534 535 536 537 538

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

    if(name.BeginsWith("RadCube")) {
        if(IsRadCubePlayerEnabled)
            fMainTab->SetTab(fRadCubePlayer->GetName());
        else
539
            ToggleTab(IsRadCubePlayerEnabled,fRadCubePlayerTab,fRadCubePlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
540 541 542 543 544
    }
    else if(name.BeginsWith("RadGG")) {
        if(IsRad2DPlayerEnabled)
            fMainTab->SetTab(fRad2DPlayer->GetName());
        else
545
            ToggleTab(IsRad2DPlayerEnabled,fRad2DPlayerTab,fRad2DPlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
546 547 548 549 550
    }
    else if(name.BeginsWith("GxG")) {
        if(IsHist2DPlayerEnabled)
            fMainTab->SetTab(fHist2DPlayer->GetName());
        else
551
            ToggleTab(IsHist2DPlayerEnabled,fHist2DPlayerTab,fHist2DPlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
552
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
553 554
}

555
void CXMainWindow::NewTab(Int_t px, Int_t py, const TString &name)
Jérémie Dudouet's avatar
Jérémie Dudouet committed
556 557 558 559 560
{
    TString TabName = Form("Canvas %d",fCanvasTab->GetNumberOfTabs());
    if(name != "")
        TabName = name;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
561
    while(fCanvasTab->GetTabTab(TabName)) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
562 563 564 565
        TObjArray *arr = TabName.Tokenize("_");
        TString last = arr->Last()->GetName();
        delete arr;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
566
        if(last.IsDigit()) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
567 568 569
            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
570
        else {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584
            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();
585
    delete fRootCanvas->GetCanvas();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
586 587 588 589 590 591 592
    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
593 594 595 596
    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
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629

    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
630 631
    fCanvas->SetNPads(px*py);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662
    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:
663
        ToggleTab(IsEditorEnabled,fEditorTab,"Editor");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
664 665
        break;
    case M_BkdUtility:
666
        ToggleTab(IsBkdUtilityEnabled,fBkdToolTab,fBkdSubtract->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
667
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
668
    case M_SavedList:
669
        ToggleTab(IsSavedListEnabled,fSavedListTab,fSavedList->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
670
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
671
    case M_Hist1DPlayer:
672
        ToggleTab(IsHist1DPlayerEnabled,fHist1DPlayerTab,fHist1DPlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
673
        break;
674
    case M_Hist1DCalib:
675
        ToggleTab(IsHist1DCalibPlayerEnabled,fHist1DCalibTab,fHist1DCalib->GetName());
676
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
677
    case M_Hist2DPlayer:
678
        ToggleTab(IsHist2DPlayerEnabled,fHist2DPlayerTab,fHist2DPlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
679
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
680
    case M_Rad2DPlayer:
681
        ToggleTab(IsRad2DPlayerEnabled,fRad2DPlayerTab,fRad2DPlayer->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
682
        break;
683
    case M_RadCubePlayer:
684
        ToggleTab(IsRadCubePlayerEnabled,fRadCubePlayerTab,fRadCubePlayer->GetName());
685
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
686
    case M_LSPlayerUtility:
687
        ToggleTab(IsLSPlayerToolEnabled,fLSPlayerToolTab,fLSPlayerTool->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
688 689
        break;
    case M_FileListUtility:
690
        ToggleTab(IsFileListUtilityEnabled,fFileListTab,fFileList->GetName());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
691
        break;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715
    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
716 717 718 719 720 721
    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
722 723 724 725 726 727
    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
728

729
        if(gPad != nullptr) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
730 731 732 733 734 735 736
            gPad->Modified();
            gPad->Update();
        }
        break;
    }
}

737
void CXMainWindow::ToggleTab(Bool_t &Enable, TGCompositeFrame *tab, const char * name)
Jérémie Dudouet's avatar
Jérémie Dudouet committed
738 739 740 741 742 743 744 745 746 747
{
    if(!Enable)
    {
        fMainTab->AddTab(name,tab);

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

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

748
        if(fMainTab->GetNumberOfTabs()>3) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
749 750 751
            TString Name = fMainTab->GetTabTab(0)->GetText()->GetString();

            if(Name==fFileList->GetName())
752
                ToggleTab(IsFileListUtilityEnabled,fFileListTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
753
            else if(Name==fLSPlayerTool->GetName())
754
                ToggleTab(IsLSPlayerToolEnabled,fLSPlayerToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
755
            else if(Name==fHist1DPlayer->GetName())
756
                ToggleTab(IsHist1DPlayerEnabled,fHist1DPlayerTab,Name);
757
            else if(Name==fHist1DCalib->GetName())
758
                ToggleTab(IsHist1DCalibPlayerEnabled,fHist1DCalibTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
759
            else if(Name==fHist2DPlayer->GetName())
760
                ToggleTab(IsHist2DPlayerEnabled,fHist2DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
761
            else if(Name==fRad2DPlayer->GetName())
762
                ToggleTab(IsRad2DPlayerEnabled,fRad2DPlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
763
            else if(Name==fRadCubePlayer->GetName())
764
                ToggleTab(IsRadCubePlayerEnabled,fRadCubePlayerTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
765
            else if(Name=="Editor")
766
                ToggleTab(IsEditorEnabled,fEditorTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
767
            else if(Name==fBkdSubtract->GetName())
768
                ToggleTab(IsBkdUtilityEnabled,fBkdToolTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
769
            else if(Name==fSavedList->GetName())
770
                ToggleTab(IsSavedListEnabled,fSavedListTab,Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
771 772 773 774
        }

        fMainTab->SetTab(name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
775 776
        Layout();
    }
777
    else {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
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
        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",    "*",
805
        nullptr,        nullptr
Jérémie Dudouet's avatar
Jérémie Dudouet committed
806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836
    };
    
    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
837 838 839
void CXMainWindow::RefreshPads()
{   
    TList *pList = fCanvas->GetListOfPrimitives();
840
    TObjOptLink *lnk = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
841 842 843 844 845 846 847 848 849 850
    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
851 852 853
    gPad->Modified();
    gPad->Update();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
854
    fCanvas->Modified();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
855
    fCanvas->Update();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
856 857 858 859 860 861 862
}

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
863 864 865
    if(fNucChartWindow)
        fNucChartWindow->CloseWindow();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
866 867 868 869 870 871 872 873 874
    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
875
TH1 *CXMainWindow::GetHisto(TVirtualPad *pad, bool GetFirst)
Jérémie Dudouet's avatar
Jérémie Dudouet committed
876
{
Jérémie Dudouet's avatar
Jérémie Dudouet committed
877
    TH1 *hist = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
878

Jérémie Dudouet's avatar
Jérémie Dudouet committed
879 880 881 882
    if(pad == nullptr && fSelectedPad == nullptr) {
        fCanvas->cd();
        fSelectedPad = fCanvas->cd();
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
883 884 885
    if(pad == nullptr)
        pad = fSelectedPad;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
886 887
    TObjOptLink *lnk = nullptr;
    TObject *obj = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
888

Jérémie Dudouet's avatar
Jérémie Dudouet committed
889 890 891 892 893
    TList *pList = pad->GetListOfPrimitives();
    if (pList) lnk = (TObjOptLink*)pList->FirstLink();

    while (lnk) {
        obj = lnk->GetObject();
894
        if (obj->InheritsFrom(TH1::Class()) && strcmp(obj->GetName() ,"hframe") != 0) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
895 896
            hist = dynamic_cast<TH1*>(obj);
            if(GetFirst) return hist;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
897
        }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
898
        lnk = (TObjOptLink*)lnk->Next();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
899
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
900
    return hist;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
901 902 903 904
}

void CXMainWindow::UpdateContextMenus()
{
905
    /// TH1F ///
Jérémie Dudouet's avatar
Jérémie Dudouet committed
906 907 908 909 910 911
    TClass *cl = gROOT->GetClass("TH1F");
    cl->MakeCustomMenuList();
    TList * ml = cl->GetMenuList();

    TClassMenuItem *n;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
912 913 914
    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);
915 916 917
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1); ml->AddFirst(n);

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
920 921 922 923
    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
924

Jérémie Dudouet's avatar
Jérémie Dudouet committed
925
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
926 927 928 929 930
    ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-4);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-10);
    ml->RemoveAt(ml->GetEntries()-15);
    for(int i=0 ; i<3 ; i++) ml->RemoveAt(ml->GetEntries()-16);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
931

932
    /// TH1D///
Jérémie Dudouet's avatar
Jérémie Dudouet committed
933 934 935 936
    cl = gROOT->GetClass("TH1D");
    cl->MakeCustomMenuList();
    ml = cl->GetMenuList();

Jérémie Dudouet's avatar
Jérémie Dudouet committed
937 938 939
    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);
940 941
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
942
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
943

Jérémie Dudouet's avatar
Jérémie Dudouet committed
944 945 946 947
    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
948

Jérémie Dudouet's avatar
Jérémie Dudouet committed
949
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
950 951 952 953 954
    ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-4);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-10);
    ml->RemoveAt(ml->GetEntries()-15);
    for(int i=0 ; i<3 ; i++) ml->RemoveAt(ml->GetEntries()-16);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
955 956 957 958 959 960

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
961 962
    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);
963 964
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Normalize","HistNorm",this,"TObject*", 0); ml->AddFirst(n);
    n = new TClassMenuItem(TClassMenuItem::kPopupUserFunction,cl,"Scale","HistScale",this,"Float_t,TObject*", 1); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
965
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
966

Jérémie Dudouet's avatar
Jérémie Dudouet committed
967 968 969 970
    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
971

Jérémie Dudouet's avatar
Jérémie Dudouet committed
972
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
973 974 975 976 977
    ml->RemoveAt(ml->GetEntries()-3);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-4);
    for(int i=0 ; i<2 ; i++) ml->RemoveAt(ml->GetEntries()-10);
    ml->RemoveAt(ml->GetEntries()-15);
    for(int i=0 ; i<3 ; i++) ml->RemoveAt(ml->GetEntries()-16);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
978 979 980 981