I have a problem with GUI in ROOT. I have a script very similar to the “rqfiller.C” (“Connection” method used in this example) in tutorials and try to modify that for collect some coordinates of mouse clicks, after that terminate GUI and execute some calculations with these coordinates. But I have no idea how to terminate GUI and send obtained data to the next commands.
1. #include <TROOT.h>
2. #include <TPad.h>
3. #include <TH1F.h>
4. #include <TCanvas.h>
5. #include <RQ_OBJECT.h>
6. #include "TF1.h"
7. #include <TMath.h>
8. #include "TROOT.h"
9. #include <TCanvas.h>
10. #include <cstring>
11. /////////////////////////////////////////////////////////////////////
12. class HFiller {
13. RQ_OBJECT("HFiller") // for classes not derived from TQObject
14. // RQ_OBJECT macro should be used
15. private:
16. TH1F *fHist; // histogram to fill
17. TPad *fPad; // pad in which histogram is drawn
18. TList *l;
19. public:
20. ~HFiller() { }
21. vector<double> x_vector;
22. vector<double> y_vector;
23. TH1F *GetHist() const { return fHist; }
24. TCanvas *c;// = (TCanvas *) gTQSender;
25. TPad *pad;
26. void SetHist(TH1F *hist);
27. TPad *GetPad() const { return fPad; }
28. void SetPad(TPad *pad);
29. void ExecuteEvent(Int_t event, Int_t px, Int_t py, TObject *sel);
30. void Draw(Option_t *opt = "") { fHist->AppendPad(opt); }
31. };
32. //___________________________________________________________________
33. void HFiller::SetHist(TH1F *hist)
34. {
35. // Sets new hist for manual filling.
36. if (!hist || (hist == fHist)) return;
37. fHist = hist;
38. }
39. //___________________________________________________________________
40. void HFiller::SetPad(TPad *pad)
41. {
42. // Sets new pad containing histogram.
43. if (!pad || (pad == fPad)) return;
44. fPad = pad;
45. }
46. //___________________________________________________________________
47. void HFiller::ExecuteEvent(Int_t event, Int_t px, Int_t py, TObject *sel)
48. {
49. // Actions in reponse to mouse button events.
50. //TCanvas *c = (TCanvas *) gTQSender;
51. c = (TCanvas *) gTQSender;
52. pad = (TPad *) c->GetSelectedPad();
53.
54.
55. if (!pad || !fHist) return;
56. if (pad != fPad) return;
57.
58. if(event==1) //left button click
59. {
60. Float_t x = pad->AbsPixeltoX(px);
61. Float_t y = pad->AbsPixeltoY(py);
62.
63. x_vector.push_back(x);
64. y_vector.push_back(y);
65.
66. cout<<" x="<<x<<" y="<<y<<endl;
67. }
68. if(event == 3)//right button click
69. {
70. //here I want to terminate gui
71. }
72. }
73. //___________________________________________________________________
74. void rqfiller()
75. {
76. // simple test of Pad Event Dispatcher
77. gROOT->Reset();
78. TCanvas *c1 = new TCanvas("c1", "Test of Canvas Event Signal",
79. 900, 500);
80. TPad *p1 = new TPad("p1","",0.01,0.05,0.95,0.95);
81. //TPad *p2 = new TPad("p2","",0.51,0.05,0.99,0.95);
82. p1->Draw();
83. ////// create 1-dim histogram filler
84. p1->cd();
85. HFiller *h1 = new HFiller();
86. TH1F* hist1 = new TH1F("h2","h2",1000,-4,4);
87. hist1->FillRandom("gaus",30000);
88. //hist1->Draw();
89.
90. h1->SetPad(p1);
91. h1->SetHist(hist1);
92. h1->GetHist()->SetFillColor(16);
93.
94. h1->Draw();
95. // connect signal to histogam
96. c1->Connect("ProcessedEvent(Int_t,Int_t,Int_t,TObject*)", "HFiller",h1, "ExecuteEvent(Int_t,Int_t,Int_t,TObject*)");
97.
98. //I want to write coordinates of clicks:
99. for(int i=0;i<h1->x_vector.size();i++)
100. {
101. cout<<"i="<<i<<" x="<<h1->x_vector[i]<<" y="<<h1->x_vector[i]<<endl;
102. }
103. }
I want to collect mouse clicks (string 58), collect them (strings 63,64), after that terminate gui (string 68, but I have no idea how to terminate it) and print collected coordinates (strings 99-102).