CXMainWindow.cpp 51.1 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

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

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

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

    //----------------Menu File--------------------
    
    fMenuFile = new TGPopupMenu(gClient->GetRoot());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
72 73 74 75
    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
76
    fMenuFile->AddSeparator();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
77
    fMenuFile->AddEntry("Exit", M_Exit, nullptr, gClient->GetPicture("bld_exit.png"));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
78 79 80 81 82 83 84
    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)");

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

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

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

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

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

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

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

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

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

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
115
    fMenuTools->AddEntry("Energy calibration", M_Hist1DCalib,nullptr,gClient->GetPicture("calib.png"));
116 117 118
    //    fMenuTools->CheckEntry(M_Hist1DPlayer);
    IsHist1DCalibPlayerEnabled= true;

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

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

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

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

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

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

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
147 148
    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
149 150 151

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

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

    fMenuOptions = new TGPopupMenu(gClient->GetRoot());
Jérémie Dudouet's avatar
Jérémie Dudouet committed
155 156
    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
157 158 159 160 161 162

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

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

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

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

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

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

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

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

216 217 218 219 220 221 222
    // ------- 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));
Jérémie Dudouet's avatar
Jérémie Dudouet committed
223
    ToggleTab(IsHist1DCalibPlayerEnabled,fHist1DCalibTab,Name);
224

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

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

241 242 243
    // ------- RadCube Player -----------
    Name = "RadCube Player";
    fRadCubePlayerTab = fMainTab->AddTab(Name);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
244
    fRadCubePlayer = new CXRadCubePlayer(fRadCubePlayerTab,10,10,this);
245 246 247
    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
248
    ToggleTab(IsRadCubePlayerEnabled,fRadCubePlayerTab,Name);
249

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

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

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

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

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

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

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

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

    gSystem->ProcessEvents();

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

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

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

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

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

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

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

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

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

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

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

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

}

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

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

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
481
    TGFrameElement *el = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
482 483 484 485 486
    if (tab->GetTabContainer(tabnr))
        el = (TGFrameElement *)tab->GetTabContainer(tabnr)->GetList()->First();
    
    if (el && el->fFrame) {
        el->fFrame->Disconnect("ProcessedConfigure(Event_t*)");
Jérémie Dudouet's avatar
Jérémie Dudouet committed
487
        el->fFrame->SetFrameElement(nullptr);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
488 489 490 491 492 493 494 495 496
        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;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
497
        el->fFrame = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
498 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
        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
531 532 533 534 535 536 537

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

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

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

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
565
        if(last.IsDigit()) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
566 567 568
            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
569
        else {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
570 571 572 573 574 575 576 577 578 579 580 581 582 583
            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();
J. Dudouet's avatar
J. Dudouet committed
584
    delete fRootCanvas->GetCanvas();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
585 586 587 588 589 590 591
    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
592 593 594 595
    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
596 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

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

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

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
736
void CXMainWindow::ToggleTab(Bool_t &Enable, TGCompositeFrame *tab, const char * name)
Jérémie Dudouet's avatar
Jérémie Dudouet committed
737 738 739 740 741 742 743 744 745 746
{
    if(!Enable)
    {
        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
747
        if(fMainTab->GetNumberOfTabs()>3) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
748 749 750
            TString Name = fMainTab->GetTabTab(0)->GetText()->GetString();

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

        fMainTab->SetTab(name);

Jérémie Dudouet's avatar
Jérémie Dudouet committed
774 775
        Layout();
    }
Jérémie Dudouet's avatar
Jérémie Dudouet committed
776
    else {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
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
        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",    "*",
Jérémie Dudouet's avatar
Jérémie Dudouet committed
804
        nullptr,        nullptr
Jérémie Dudouet's avatar
Jérémie Dudouet committed
805 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
    };
    
    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
836 837 838
void CXMainWindow::RefreshPads()
{   
    TList *pList = fCanvas->GetListOfPrimitives();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
839
    TObjOptLink *lnk = nullptr;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
840 841 842 843 844 845 846 847 848 849
    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
850 851 852
    gPad->Modified();
    gPad->Update();

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

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

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

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

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

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

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

    while (lnk) {
        obj = lnk->GetObject();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
893
        if (obj->InheritsFrom(TH1::Class()) && strncmp(obj->GetName() ,"hframe",strlen(obj->GetName())) != 0) {
Jérémie Dudouet's avatar
Jérémie Dudouet committed
894
            hist = dynamic_cast<TH1*>(obj);
J. Dudouet's avatar
J. Dudouet committed
895
            hist->Print();
Jérémie Dudouet's avatar
Jérémie Dudouet committed
896
            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 900
    }

Jérémie Dudouet's avatar
Jérémie Dudouet committed
901
    return hist;
Jérémie Dudouet's avatar
Jérémie Dudouet committed
902 903 904 905
}

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

    TClassMenuItem *n;

Jérémie Dudouet's avatar
Jérémie Dudouet committed
913 914 915
    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);
916 917 918
    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
919
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
920

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
926
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
927 928 929 930 931
    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
932

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
938 939 940
    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);
941 942
    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
943
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
944

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
950
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
951 952 953 954 955
    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
956 957 958 959 960 961

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
962 963
    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);
964 965
    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
966
    n = new TClassMenuItem(TClassMenuItem::kPopupSeparator,cl); ml->AddFirst(n);
Jérémie Dudouet's avatar
Jérémie Dudouet committed
967

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

Jérémie Dudouet's avatar
Jérémie Dudouet committed
973
    for(int i=0 ; i<6 ; i++) ml->RemoveAt(ml->GetEntries()-1);
974 975 976 977 978
    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
979 980 981 982 983 984 985 986

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