diff --git a/Headers/gui.h b/Headers/gui.h index 976052ff65d3ea0f9df3755fc490fbabf0eb324b..e7423cdfb9d88527fcaa8bb6d1954748b33837c1 100644 --- a/Headers/gui.h +++ b/Headers/gui.h @@ -20,20 +20,33 @@ #include <TGFileDialog.h> #include <TText.h> #include <TPaletteAxis.h> - +#include <TG3DLine.h> +#include <TGToolBar.h> #include "setup.h" class MyMainFrame : public TGMainFrame { private: + constexpr static Int_t M_EXIT=100; // must be non-negative + constexpr static Int_t M_CONFIG_OPEN=0; + constexpr static Int_t M_IMAGE_SAVE=1; + constexpr static Int_t M_IMAGE_SAVEAS=2; + constexpr static Int_t M_RUN_START=3; + constexpr static Int_t M_RUN_CLEAR=4; + constexpr static Int_t M_RUN_STOP=5; + constexpr static Int_t M_ABOUT=6; + TGFileInfo fin; + TGFileInfo fout; TGMainFrame *fMain; + TGMenuBar *fMenuBar; + TGPopupMenu* fMenuEntries[3]; // // tab // TGTab *fTab; //buttons - TGCompositeFrame* fF3; - TGLayoutHints *fL3; - TGTextButton *fStartB; - TGTextButton *fStopB; - TGTextButton *fClearB; + TGToolBar *fToolBar; + ToolBarData_t tooBarData[3]; + std::vector<std::string> tiptexts = {"Start", "Clear", "Stop"}; + std::vector<std::string> xmpicons = {"ed_execute.png", "refresh1.xpm", "ed_interrupt.png"}; + // show counts TText *countsText; // canvas @@ -67,10 +80,14 @@ public: void addConeNormalized(std::vector<Cone>::const_iterator first, std::vector<Cone>::const_iterator last); // slots + void SaveImage(); + void SaveImageAs(); void Start(); void Stop(); void Clear(); void CloseWindow(); + void response2Menu(Int_t menu_id); // respond based on menu id + void response2ToolBar(Int_t button_id); // respond based on menu id ClassDef(MyMainFrame,0) }; diff --git a/Headers/setup.h b/Headers/setup.h index 121749b647e319ea49b145ea287dfe190df73bf3..893d6931205fe8f22576fb53673941bd3a8b3491 100644 --- a/Headers/setup.h +++ b/Headers/setup.h @@ -98,7 +98,7 @@ public: const Vector3D sgmpos = Vector3D(0.8 / 2, 0.43 / 2, 1.0 / 2); // mm // const Vector3D sgmpos(0, 0, 0); // mm const int order=3; - const std::string conefilePath = "Data/cones_ideal.txt"; + const std::string conefilePath = "Data/cones_selected_channels.txt"; // refresh every 10 events const int chuckSize = 10; diff --git a/Sources/gui.cpp b/Sources/gui.cpp index b45f27059059f10f227e74a98dc7209035b3552b..4e730469205efa29ffde0c405c695e0911ab277d 100644 --- a/Sources/gui.cpp +++ b/Sources/gui.cpp @@ -21,17 +21,17 @@ MyMainFrame::MyMainFrame(const Setup* config_, const TGWindow *p,UInt_t w,UInt_t MyMainFrame::~MyMainFrame() { // // Clean up used widgets: frames, buttons, layout hints // fMain->Cleanup(); - //buttons - delete fF3; - delete fL3; - delete fStopB; - delete fClearB; - delete fStartB; + // menu + delete fMenuBar; + for (int i = 0; i < 3; i++) + { + delete fMenuEntries[i]; + } + delete fToolBar; // canvas delete fF5; delete fL4; delete fEcanvas; - delete fMain; delete histo; for (int i = 0; i < Nl; i++) { @@ -43,6 +43,7 @@ MyMainFrame::~MyMainFrame() { } delete sourceMarker; delete countsText; + delete fMain; } void MyMainFrame::CloseWindow() { @@ -51,20 +52,59 @@ void MyMainFrame::CloseWindow() { } int MyMainFrame::Init(){ - // buttons - fF3 = new TGCompositeFrame(fMain, 60, 20, kHorizontalFrame); - fStartB = new TGTextButton(fF3, "Start"); - fStartB->Connect("Clicked()", "MyMainFrame", this, "Start()"); - fClearB = new TGTextButton(fF3, "Clear"); - fClearB->Connect("Clicked()", "MyMainFrame", this, "Clear()"); - fStopB = new TGTextButton(fF3, "Stop"); - fStopB->Connect("Clicked()", "MyMainFrame", this, "Stop()"); + // create a menu bar + fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame); + // File menus + fMenuEntries[0] = new TGPopupMenu(gClient->GetRoot()); + fMenuEntries[0]->AddEntry("&Open", M_CONFIG_OPEN); + fMenuEntries[0]->AddSeparator(); + fMenuEntries[0]->AddEntry("&Save", M_IMAGE_SAVE); + fMenuEntries[0]->AddEntry("S&ave as", M_IMAGE_SAVEAS); + fMenuEntries[0]->AddSeparator(); + fMenuEntries[0]->AddEntry("&Exit", M_EXIT); + fMenuBar->AddPopup("File", fMenuEntries[0], new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 2, 2)); + fMenuEntries[0]->Connect("Activated(Int_t)", /* signal */ + "MyMainFrame", this, /* receiver calls, object*/ + "response2Menu(Int_t)"); - fL3 = new TGLayoutHints(kLHintsTop | kLHintsLeft, - 5, 5, 5, 5); - fF3->AddFrame(fStartB, fL3); - fF3->AddFrame(fClearB, fL3); - fF3->AddFrame(fStopB, fL3); + fMenuEntries[1] = new TGPopupMenu(gClient->GetRoot()); + fMenuEntries[1]->AddEntry("Start", M_RUN_START); + fMenuEntries[1]->AddEntry("Stop", M_RUN_STOP); + fMenuEntries[1]->AddEntry("Clear", M_RUN_CLEAR); + fMenuBar->AddPopup("Run", fMenuEntries[1], new TGLayoutHints(kLHintsTop | kLHintsLeft, 5, 5, 2, 2)); + fMenuEntries[1]->Connect("Activated(Int_t)", /* signal */ + "MyMainFrame", this, /* receiver calls, object*/ + "response2Menu(Int_t)"); + + fMenuEntries[2] = new TGPopupMenu(gClient->GetRoot()); + fMenuEntries[2]->AddEntry("About", M_ABOUT); + fMenuEntries[2]->Connect("Activated(Int_t)", /* signal */ + "MyMainFrame", this, /* receiver calls, object*/ + "response2Menu(Int_t)"); + fMenuBar->AddPopup("Help", fMenuEntries[2], new TGLayoutHints(kLHintsTop | kLHintsRight)); + + fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsExpandX, 5, 5, 2, 2) ); + TGHorizontal3DLine *lhMenu = new TGHorizontal3DLine(fMain); + fMain->AddFrame(lhMenu, new TGLayoutHints(kLHintsTop|kLHintsExpandX)); + + // toolbar + fToolBar = new TGToolBar(fMain,520,80); + for (int i = 0; i < 3; i++) + { + tooBarData[i].fPixmap = xmpicons[i].c_str(); + tooBarData[i].fTipText = tiptexts[i].c_str(); + tooBarData[i].fStayDown = kFALSE; + tooBarData[i].fId = i+1; + tooBarData[i].fButton = NULL; + fToolBar->AddButton(fMain, &tooBarData[i], 5); + } + fToolBar->Connect("Clicked(Int_t)", /* signal */ + "MyMainFrame", this, /* receiver calls, object*/ + "response2ToolBar(Int_t"); + fMain->AddFrame(fToolBar, new TGLayoutHints(kLHintsTop| kLHintsLeft| kLHintsExpandX, 10, 5, 2, 2)); + // adding a horizontal line as a separator + TGHorizontal3DLine *lhToolBar = new TGHorizontal3DLine(fMain); + fMain->AddFrame(lhToolBar, new TGLayoutHints(kLHintsTop|kLHintsExpandX)); // embedded canvas fF5 = new TGCompositeFrame(fMain, 60, 60, kHorizontalFrame); @@ -72,7 +112,6 @@ int MyMainFrame::Init(){ | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5); fEcanvas = new TRootEmbeddedCanvas("ec1", fF5, 100, 100); fF5->AddFrame(fEcanvas, fL4); - fMain->AddFrame(fF3, fL3); fMain->AddFrame(fF5, fL4); initHist(); @@ -87,8 +126,94 @@ int MyMainFrame::Init(){ return 0; } +void MyMainFrame::SaveImage() +{ + if(!fout.fFilename) + { + SaveImageAs(); + } + else + { + canvas->SaveAs(fout.fFilename); + printf("Image saved to: %s\n", fout.fFilename); + } +} + +void MyMainFrame::SaveImageAs() +{ + static TString outdir("."); + const char* WriteOutTypes[]={ "PNG", "*.png", + "ROOT files", "*.root", + "ROOT macros", "*.C", + "All files", "*", + 0, 0 }; + fout.fFileTypes = WriteOutTypes; + fout.SetIniDir(outdir); + // printf("fIniDir = %s\n", fout.fIniDir); + new TGFileDialog(gClient->GetRoot(), fMain, kFDSave, &fout); + if (fout.fFilename) + { + outdir = fout.fIniDir; + canvas->SaveAs(fout.fFilename); + printf("Image saved to: %s\n", fout.fFilename); + // printf("Save configuration as xx!\n"); + } +} +void MyMainFrame::response2Menu(Int_t menu_id) +{ + switch (menu_id) + { + case M_CONFIG_OPEN: + // LoadConfig(); + printf("Load config! \n"); + break; + case M_IMAGE_SAVE: + SaveImage(); + break; + case M_IMAGE_SAVEAS: + // SaveConfigAs(); + // printf("Save image as \n"); + SaveImageAs(); + break; + case M_EXIT: + CloseWindow(); + break; + case M_RUN_START: + Start(); + break; + case M_RUN_STOP: + Stop(); + break; + case M_RUN_CLEAR: + Clear(); + break; + case M_ABOUT: + printf("Show help. \n"); + break; + default: + break; + } +} + +void MyMainFrame::response2ToolBar(Int_t button_id) +{ + switch (button_id) + { + case 1: + Start(); + break; + case 2: + Clear(); + break; + case 3: + Stop(); + break; + default: + break; + } +} void MyMainFrame::initHist() { - histo = new TH2D("ROI", " ; Azimuth; Elevation", + histo = new TH2D("ROI", " ; Azimuth (degree); Elevation (degree)", config->phiBins, -180, 180, config->thetaBins, -90, 90); // init image