Diana Software
QGPlotIconsFrame.cc
Go to the documentation of this file.
1 #include "QGPlotIconsFrame.hh"
2 #include <list>
3 #include <sstream>
4 #include <string>
5 #include <typeinfo>
6 #include <vector>
7 #include "QGCanvasWindow.hh"
8 #include "QGCutsFrame.hh"
9 #include "QGFileHandler.hh"
10 #include "QGGraphicalCut.hh"
11 #include "QGHistogram.hh"
12 #include "QGPlot.hh"
13 #include "QGPlotFrame.hh"
14 #include "QGPlotListWindow.hh"
15 #include "QGPulse.hh"
16 #include "QGPulseEditWindow.hh"
17 #include "QGScatterPlot.hh"
18 #include "TCanvas.h"
19 #include "TFrame.h"
20 #include "TGButton.h"
21 #include "TGIcon.h"
22 #include "TGPicture.h"
23 #include "TRootEmbeddedCanvas.h"
24 
25 // Images
26 #include "ImageCopyLimits.xpm"
27 #include "ImageEditPlots.xpm"
28 #include "ImageGraphicalCutIcon.xpm"
29 #include "ImageHistogramIcon.xpm"
30 #include "ImageLogo.xpm"
31 #include "ImagePulseIcon.xpm"
32 #include "ImageScatterPlotIcon.xpm"
33 
34 
36 
37 using std::flush;
38 using std::list;
39 using std::string;
40 using std::stringstream;
41 using std::vector;
42 
44 TGVerticalFrame(p, w, h),
45 fPlotFrame(p)
46 {
47  SetCleanup(kDeepCleanup);
48 
49  fLogo = new TGIcon(this, gClient->GetPicturePool()->GetPicture("Logo", (char**)ImageLogo), 50, 50);
50  AddFrame(fLogo, new TGLayoutHints(kLHintsCenterX, 0, 0, 0, 0));
51 
52  fHistogramButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("HistogramIcon", (char**)ImageHistogramIcon));
53  AddFrame(fHistogramButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 0, 0, 15, 0));
54  fHistogramButton->SetToolTipText("Create a new histogram");
55  fHistogramButton->Connect("Clicked()", "QGPlotIconsFrame", this, "HandleHistogramButton()");
56 
57  fScatterPlotButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("ScatterPlotIcon", (char**)ImageScatterPlotIcon));
58  AddFrame(fScatterPlotButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 0, 0, 0, 0));
59  fScatterPlotButton->SetToolTipText("Create a new scatter plot");
60  fScatterPlotButton->Connect("Clicked()", "QGPlotIconsFrame", this, "HandleScatterPlotButton()");
61 
62  fPulsesButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("PulseIcon", (char**)ImagePulseIcon));
63  AddFrame(fPulsesButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 0, 0, 0, 0));
64  fPulsesButton->SetToolTipText("View pulses");
65  fPulsesButton->Connect("Clicked()", "QGPlotIconsFrame", this, "HandlePulsesButton()");
66 
67  fCopyLimitsButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("CopyLimits", (char**)ImageCopyLimits));
68  AddFrame(fCopyLimitsButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 0, 0, 0, 0));
69  fCopyLimitsButton->SetToolTipText("Copy plot limits to the clipboard");
70  fCopyLimitsButton->Connect("Clicked()", "QGPlotIconsFrame", this, "HandleCopyLimitsButton()");
71 
72  fGraphicalCutButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("GraphicalCutIcon", (char**)ImageGraphicalCutIcon));
73  AddFrame(fGraphicalCutButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 0, 0, 0, 0));
74  fGraphicalCutButton->SetToolTipText("Create a new graphical cut");
75  fGraphicalCutButton->Connect("Clicked()", "QGPlotIconsFrame", this, "HandleGraphicalCutButton()");
76 
77  fEditPlotsButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("EditPlots", (char**)ImageEditPlots));
78  AddFrame(fEditPlotsButton, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 0, 0, 0, 0));
79  fEditPlotsButton->SetToolTipText("Edit plots associated with this window");
80  fEditPlotsButton->Connect("Clicked()", "QGPlotIconsFrame", this, "HandleEditPlotsButton()");
81 }
82 
84 {
85  Cleanup();
86 }
87 
89 {
90  if (fPlotFrame->GetCanvasWindow()->GetDrawnPlots().size() != 0) {
91  const QGPlot *firstPlot = fPlotFrame->GetCanvasWindow()->GetDrawnPlots().front();
92  Double_t xLow = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetX1();
93  Double_t xHigh = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetX2();
94  Double_t yLow = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetY1();
95  Double_t yHigh = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetY2();
96  stringstream xLowerLimit, xUpperLimit, yLowerLimit, yUpperLimit;
97  xLowerLimit.precision(12);
98  xUpperLimit.precision(12);
99  yLowerLimit.precision(12);
100  yUpperLimit.precision(12);
101  xLowerLimit << xLow << " <= " << firstPlot->GetXVariable();
102  xUpperLimit << firstPlot->GetXVariable() << " < " << xHigh;
103  yLowerLimit << yLow << " <= " << firstPlot->GetYVariable();
104  yUpperLimit << firstPlot->GetYVariable() << " < " << yHigh;
105  if (typeid(*firstPlot) == typeid(QGHistogram)) {
107  QGCutsFrame::CopyCut(xLowerLimit.str());
108  QGCutsFrame::CopyCut(xUpperLimit.str());
109  } else if (typeid(*firstPlot) == typeid(QGScatterPlot)) {
111  QGCutsFrame::CopyCut(xLowerLimit.str());
112  QGCutsFrame::CopyCut(xUpperLimit.str());
113  QGCutsFrame::CopyCut(yLowerLimit.str());
114  QGCutsFrame::CopyCut(yUpperLimit.str());
115  }
116  }
117 }
118 
120 {
121  list<QGPlot*>& plots = fPlotFrame->GetCanvasWindow()->GetPlots();
122  list<QGPlot*>::const_iterator plotIter;
123  for (plotIter = plots.begin(); plotIter != plots.end(); ++plotIter) {
124  (*plotIter)->DisplayEditWindow();
125  }
126 }
127 
129 {
130  if (fPlotFrame->GetCanvasWindow()->GetDrawnPlots().size() != 0) {
131  const QGPlot *firstPlot = fPlotFrame->GetCanvasWindow()->GetDrawnPlots().front();
132  if (typeid(*firstPlot) == typeid(QGScatterPlot)) {
133  QGGraphicalCut *graphicalCut = new QGGraphicalCut();
134  graphicalCut->SetCanvasWindow(fPlotFrame->GetCanvasWindow());
135  graphicalCut->SetXVariable(firstPlot->GetXVariable());
136  graphicalCut->SetYVariable(firstPlot->GetYVariable());
137  graphicalCut->SetVarX(firstPlot->GetXVariable().c_str());
138  graphicalCut->SetVarY(firstPlot->GetYVariable().c_str());
139  graphicalCut->Create();
140  }
141  }
142 }
143 
145 {
146  QGHistogram *histogram = new QGHistogram();
148  histogram->AutoSetStyle();
149  histogram->DisplayEditWindow();
151 }
152 
154 {
155  if (fPlotFrame->GetCanvasWindow()->GetDrawnPlots().size() == 0) {
156  QGPulse *pulse = new QGPulse();
158  pulse->AutoSetStyle();
159  pulse->DisplayEditWindow();
160  pulse->Plot();
161  } else {
162  Double_t xLow = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetX1();
163  Double_t xHigh = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetX2();
164  Double_t yLow = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetY1();
165  Double_t yHigh = fPlotFrame->GetEmbeddedCanvas()->GetCanvas()->GetFrame()->GetY2();
166  const list<QGPlot*>& drawnPlots = fPlotFrame->GetCanvasWindow()->GetDrawnPlots();
167  list<QGPlot*>::const_iterator plotIter;
168  for (plotIter = drawnPlots.begin(); plotIter != drawnPlots.end(); ++plotIter) {
169  stringstream xLowerLimit, xUpperLimit, yLowerLimit, yUpperLimit;
170  xLowerLimit.precision(12);
171  xUpperLimit.precision(12);
172  yLowerLimit.precision(12);
173  yUpperLimit.precision(12);
174  xLowerLimit << xLow << " <= " << (*plotIter)->GetXVariable();
175  xUpperLimit << (*plotIter)->GetXVariable() << " < " << xHigh;
176  yLowerLimit << yLow << " <= " << (*plotIter)->GetYVariable();
177  yUpperLimit << (*plotIter)->GetYVariable() << " < " << yHigh;
178 
179  QGCanvasWindow *newCanvasWindow = new QGCanvasWindow();
182  newCanvasWindow->DisplayPlotFrame();
183  newCanvasWindow->UpdateFileLabel();
184 
185  QGPulse *pulse = new QGPulse();
186  pulse->SetCanvasWindow(newCanvasWindow);
187  pulse->AutoSetStyle();
188  pulse->DisplayEditWindow();
189  pulse->GetEditWindow()->GetCutsFrame()->SetCuts((*plotIter)->GetCuts());
190  if (typeid(**plotIter) == typeid(QGHistogram)) {
191  pulse->GetEditWindow()->GetCutsFrame()->AddCut(xLowerLimit.str());
192  pulse->GetEditWindow()->GetCutsFrame()->AddCut(xUpperLimit.str());
193  } else if (typeid(**plotIter) == typeid(QGScatterPlot)) {
194  pulse->GetEditWindow()->GetCutsFrame()->AddCut(xLowerLimit.str());
195  pulse->GetEditWindow()->GetCutsFrame()->AddCut(xUpperLimit.str());
196  pulse->GetEditWindow()->GetCutsFrame()->AddCut(yLowerLimit.str());
197  pulse->GetEditWindow()->GetCutsFrame()->AddCut(yUpperLimit.str());
198  }
199  pulse->Plot();
200  }
201  }
203 }
204 
206 {
207  QGScatterPlot *scatterPlot = new QGScatterPlot();
208  scatterPlot->SetCanvasWindow(fPlotFrame->GetCanvasWindow());
209  scatterPlot->AutoSetStyle();
210  scatterPlot->DisplayEditWindow();
212 }
ClassImp(QObject)
Window containing a ROOT canvas.
void DisplayPlotFrame()
Display the plot frame.
std::list< QGPlot * > & GetPlots()
Get collection of plots associated with this window.
QGFileHandler * GetFileHandler() const
Get pointer to file handler.
std::list< QGPlot * > & GetDrawnPlots()
Get collection of drawn plots.
void UpdateFileLabel()
Update the file label.
void AddCut(const std::string &cut)
Add cut.
Definition: QGCutsFrame.cc:83
static void ClearCopiedCuts()
Clear copied cuts.
Definition: QGCutsFrame.cc:91
static void CopyCut(const std::string &cut)
Copy cut.
Definition: QGCutsFrame.cc:96
void SetCuts(const std::vector< std::string > &cuts)
Set cuts.
Definition: QGCutsFrame.cc:192
std::vector< std::string > GetFilenames()
Get a vector containing the names of the open files.
void OpenFiles(const std::vector< std::string > &files)
Open files, add them to the chain.
Class for graphical cuts.
void Create()
Create the graphical cut with the mouse.
Class for GUI histograms.
Definition: QGHistogram.hh:19
void AutoSetStyle()
Automatically set the histogram style.
Definition: QGHistogram.cc:136
void DisplayEditWindow()
Display edit window for the histogram.
Definition: QGHistogram.cc:235
QGCutsFrame * GetCutsFrame()
Get pointer to the cuts frame.
Part of a canvas window containing the ROOT canvas.
Definition: QGPlotFrame.hh:17
QGCanvasWindow * GetCanvasWindow()
Get pointer to the canvas window.
Definition: QGPlotFrame.hh:23
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to canvas.
Definition: QGPlotFrame.hh:26
Part of a QGPlotFrame containing buttons to add new plots.
void HandleCopyLimitsButton()
Handle copy limits button.
void HandleGraphicalCutButton()
Handle graphical cut button.
void HandleHistogramButton()
Handle histogram button.
QGPlotIconsFrame(QGPlotFrame *p, UInt_t w, UInt_t h)
Constructor.
TGPictureButton * fHistogramButton
Histogram icon button.
TGPictureButton * fScatterPlotButton
Scatter plot icon button.
void HandleEditPlotsButton()
Handle edit plots button.
virtual ~QGPlotIconsFrame()
Destructor.
TGPictureButton * fEditPlotsButton
Edit plots button.
TGPictureButton * fGraphicalCutButton
Graphical cut icon button.
TGIcon * fLogo
Logo.
void HandlePulsesButton()
Handle pulses button.
QGPlotFrame * fPlotFrame
Pointer to plot frame.
void HandleScatterPlotButton()
Handle scatter plot button.
TGPictureButton * fCopyLimitsButton
Copy limits button.
TGPictureButton * fPulsesButton
Pulses icon button.
static void Update()
Update the plot list.
Base class for GUI plots including histograms, scatter plots, pulses, and graphical cuts.
Definition: QGPlot.hh:21
virtual void Plot()
Plot this in the associated canvas window, generating it if necessary.
Definition: QGPlot.cc:195
virtual void SetCanvasWindow(QGCanvasWindow *window)
Set the canvas window to which the plot is associated.
Definition: QGPlot.cc:216
virtual QGPlotEditWindow * GetEditWindow()
Get pointer to edit window.
Definition: QGPlot.hh:72
virtual void SetXVariable(const std::string &x)
Set X-axis variable.
Definition: QGPlot.cc:270
virtual void SetYVariable(const std::string &y)
Set Y-axis variable.
Definition: QGPlot.cc:278
virtual const std::string & GetXVariable() const
Get x-axis variable.
Definition: QGPlot.hh:90
virtual const std::string & GetYVariable() const
Get y-axis variable.
Definition: QGPlot.hh:96
Class for GUI pulse plots.
Definition: QGPulse.hh:18
void AutoSetStyle()
Automatically set the pulse style.
Definition: QGPulse.cc:104
void DisplayEditWindow()
Display edit window.
Definition: QGPulse.cc:199
Class for GUI scatter plots.
void DisplayEditWindow()
Display edit window.
void AutoSetStyle()
Automatically set the scatter plot style.
static void UpdateWindowDropDownBoxes()
Update window drop down boxes.
Definition: QGWindow.cc:95