Skip to content
Snippets Groups Projects
Commit f5e8aa4d authored by mingf2's avatar mingf2
Browse files

save image

parent 4ae8ad25
No related branches found
No related tags found
No related merge requests found
...@@ -20,20 +20,33 @@ ...@@ -20,20 +20,33 @@
#include <TGFileDialog.h> #include <TGFileDialog.h>
#include <TText.h> #include <TText.h>
#include <TPaletteAxis.h> #include <TPaletteAxis.h>
#include <TG3DLine.h>
#include <TGToolBar.h>
#include "setup.h" #include "setup.h"
class MyMainFrame : public TGMainFrame { class MyMainFrame : public TGMainFrame {
private: 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; TGMainFrame *fMain;
TGMenuBar *fMenuBar;
TGPopupMenu* fMenuEntries[3];
// // tab // // tab
// TGTab *fTab; // TGTab *fTab;
//buttons //buttons
TGCompositeFrame* fF3; TGToolBar *fToolBar;
TGLayoutHints *fL3; ToolBarData_t tooBarData[3];
TGTextButton *fStartB; std::vector<std::string> tiptexts = {"Start", "Clear", "Stop"};
TGTextButton *fStopB; std::vector<std::string> xmpicons = {"ed_execute.png", "refresh1.xpm", "ed_interrupt.png"};
TGTextButton *fClearB;
// show counts // show counts
TText *countsText; TText *countsText;
// canvas // canvas
...@@ -67,10 +80,14 @@ public: ...@@ -67,10 +80,14 @@ public:
void addConeNormalized(std::vector<Cone>::const_iterator first, void addConeNormalized(std::vector<Cone>::const_iterator first,
std::vector<Cone>::const_iterator last); std::vector<Cone>::const_iterator last);
// slots // slots
void SaveImage();
void SaveImageAs();
void Start(); void Start();
void Stop(); void Stop();
void Clear(); void Clear();
void CloseWindow(); 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) ClassDef(MyMainFrame,0)
}; };
......
...@@ -98,7 +98,7 @@ public: ...@@ -98,7 +98,7 @@ public:
const Vector3D sgmpos = Vector3D(0.8 / 2, 0.43 / 2, 1.0 / 2); // mm const Vector3D sgmpos = Vector3D(0.8 / 2, 0.43 / 2, 1.0 / 2); // mm
// const Vector3D sgmpos(0, 0, 0); // mm // const Vector3D sgmpos(0, 0, 0); // mm
const int order=3; 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 // refresh every 10 events
const int chuckSize = 10; const int chuckSize = 10;
......
...@@ -21,17 +21,17 @@ MyMainFrame::MyMainFrame(const Setup* config_, const TGWindow *p,UInt_t w,UInt_t ...@@ -21,17 +21,17 @@ MyMainFrame::MyMainFrame(const Setup* config_, const TGWindow *p,UInt_t w,UInt_t
MyMainFrame::~MyMainFrame() { MyMainFrame::~MyMainFrame() {
// // Clean up used widgets: frames, buttons, layout hints // // Clean up used widgets: frames, buttons, layout hints
// fMain->Cleanup(); // fMain->Cleanup();
//buttons // menu
delete fF3; delete fMenuBar;
delete fL3; for (int i = 0; i < 3; i++)
delete fStopB; {
delete fClearB; delete fMenuEntries[i];
delete fStartB; }
delete fToolBar;
// canvas // canvas
delete fF5; delete fF5;
delete fL4; delete fL4;
delete fEcanvas; delete fEcanvas;
delete fMain;
delete histo; delete histo;
for (int i = 0; i < Nl; i++) for (int i = 0; i < Nl; i++)
{ {
...@@ -43,6 +43,7 @@ MyMainFrame::~MyMainFrame() { ...@@ -43,6 +43,7 @@ MyMainFrame::~MyMainFrame() {
} }
delete sourceMarker; delete sourceMarker;
delete countsText; delete countsText;
delete fMain;
} }
void MyMainFrame::CloseWindow() { void MyMainFrame::CloseWindow() {
...@@ -51,20 +52,59 @@ void MyMainFrame::CloseWindow() { ...@@ -51,20 +52,59 @@ void MyMainFrame::CloseWindow() {
} }
int MyMainFrame::Init(){ int MyMainFrame::Init(){
// buttons // create a menu bar
fF3 = new TGCompositeFrame(fMain, 60, 20, kHorizontalFrame); fMenuBar = new TGMenuBar(fMain, 1, 1, kHorizontalFrame);
fStartB = new TGTextButton(fF3, "Start"); // File menus
fStartB->Connect("Clicked()", "MyMainFrame", this, "Start()"); fMenuEntries[0] = new TGPopupMenu(gClient->GetRoot());
fClearB = new TGTextButton(fF3, "Clear"); fMenuEntries[0]->AddEntry("&Open", M_CONFIG_OPEN);
fClearB->Connect("Clicked()", "MyMainFrame", this, "Clear()"); fMenuEntries[0]->AddSeparator();
fStopB = new TGTextButton(fF3, "Stop"); fMenuEntries[0]->AddEntry("&Save", M_IMAGE_SAVE);
fStopB->Connect("Clicked()", "MyMainFrame", this, "Stop()"); 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, fMenuEntries[1] = new TGPopupMenu(gClient->GetRoot());
5, 5, 5, 5); fMenuEntries[1]->AddEntry("Start", M_RUN_START);
fF3->AddFrame(fStartB, fL3); fMenuEntries[1]->AddEntry("Stop", M_RUN_STOP);
fF3->AddFrame(fClearB, fL3); fMenuEntries[1]->AddEntry("Clear", M_RUN_CLEAR);
fF3->AddFrame(fStopB, fL3); 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 // embedded canvas
fF5 = new TGCompositeFrame(fMain, 60, 60, kHorizontalFrame); fF5 = new TGCompositeFrame(fMain, 60, 60, kHorizontalFrame);
...@@ -72,7 +112,6 @@ int MyMainFrame::Init(){ ...@@ -72,7 +112,6 @@ int MyMainFrame::Init(){
| kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5); | kLHintsExpandX | kLHintsExpandY, 5, 5, 5, 5);
fEcanvas = new TRootEmbeddedCanvas("ec1", fF5, 100, 100); fEcanvas = new TRootEmbeddedCanvas("ec1", fF5, 100, 100);
fF5->AddFrame(fEcanvas, fL4); fF5->AddFrame(fEcanvas, fL4);
fMain->AddFrame(fF3, fL3);
fMain->AddFrame(fF5, fL4); fMain->AddFrame(fF5, fL4);
initHist(); initHist();
...@@ -87,8 +126,94 @@ int MyMainFrame::Init(){ ...@@ -87,8 +126,94 @@ int MyMainFrame::Init(){
return 0; 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() { void MyMainFrame::initHist() {
histo = new TH2D("ROI", " ; Azimuth; Elevation", histo = new TH2D("ROI", " ; Azimuth (degree); Elevation (degree)",
config->phiBins, -180, 180, config->phiBins, -180, 180,
config->thetaBins, -90, 90); config->thetaBins, -90, 90);
// init image // init image
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment