Diana Software
QGGraphicalCut.cc
Go to the documentation of this file.
1 #include "QGGraphicalCut.hh"
2 #include <algorithm>
3 #include <iostream>
4 #include <string>
5 #include "QGCanvasWindow.hh"
6 #include "QGCutsFrame.hh"
7 #include "QGFileHandler.hh"
8 #include "QGPlotFrame.hh"
9 #include "QGHistogram.hh"
10 #include "QGPlotEditWindow.hh"
11 #include "QGPlotListWindow.hh"
12 #include "QGPulse.hh"
13 #include "QGScatterPlot.hh"
14 #include "QGSessionHandler.hh"
15 #include "TCanvas.h"
16 #include "TRootEmbeddedCanvas.h"
17 #include "TString.h"
18 
20 
21 using std::list;
22 using std::string;
23 
24 list<QGGraphicalCut*> QGGraphicalCut::fGraphicalCuts;
25 
28 {
29  fGraphicalCuts.push_back(this);
30  SetName();
31  SetBit(kCanDelete, kFALSE);
32 }
33 
35 QGGraphicalCutBase(graphicalCut), QGPlot(graphicalCut)
36 {
37  fGraphicalCuts.push_back(this);
38  SetName();
39  SetBit(kCanDelete, kFALSE);
40 }
41 
43 {
44  if (find(fGraphicalCuts.begin(), fGraphicalCuts.end(), this) != fGraphicalCuts.end()) {
45  fGraphicalCuts.erase(find(fGraphicalCuts.begin(), fGraphicalCuts.end(), this));
46  }
47 }
48 
50 {
53 }
54 
56 {
57  GetCanvas()->cd();
58  GetCanvas()->Connect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
59  "QGGraphicalCut", this, "HandleCanvasEvent(Int_t, Int_t, Int_t, TObject*)");
60 }
61 
63 {
64  Draw();
65  if (gPad) {
66  gPad->Update();
67  }
68 }
69 
71 {
72  if (fCanvasWindow) {
73  fCanvasWindow->GetPlotFrame()->GetEmbeddedCanvas()->GetCanvas()->cd();
74  fCanvasWindow->GetPlotFrame()->GetEmbeddedCanvas()->GetCanvas()->RecursiveRemove(this);
75  fCanvasWindow->GetPlotFrame()->GetEmbeddedCanvas()->GetCanvas()->Update();
76  }
77 }
78 
79 const char *QGGraphicalCut::GetName() const
80 {
81  return TCutG::GetName();
82 }
83 
84 void QGGraphicalCut::HandleCanvasEvent(Int_t event, Int_t px, Int_t py, TObject *selected)
85 {
86  bool mouseMoved = (event == 51);
87  bool leftClick = (event == 11);
88  bool doubleClick = (event == 61);
89 
90  Double_t xpad = GetCanvas()->AbsPixeltoX(px);
91  Double_t ypad = GetCanvas()->AbsPixeltoY(py);
92  Double_t x = GetCanvas()->PadtoX(xpad); // needed in case of log scale
93  Double_t y = GetCanvas()->PadtoY(ypad); // needed in case of log scale
94 
95  if (leftClick && fPoints == 0) {
96  fX0 = x;
97  fY0 = y;
98  SetPoint(0, x, y);
99  SetPoint(1, x, y);
100  SetPoint(2, x, y);
101  }
102 
103  if (mouseMoved && fPoints > 0) {
104  SetPoint(fPoints, x, y);
105  SetPoint(fPoints + 1, fX0, fY0);
106  Draw();
107  GetCanvas()->Update();
108  }
109 
110  if (leftClick) {
111  if (x != fXLast || y != fYLast) { // this was &&, should it be || ???
112  ++fPoints;
113  fXLast = x;
114  fYLast = y;
115  }
116  }
117 
118  if (doubleClick) {
119  GetCanvas()->Disconnect("ProcessedEvent(Int_t, Int_t, Int_t, TObject*)",
120  this, "HandleCanvasEvent(Int_t, Int_t, Int_t, TObject*)");
121  if (fPoints < 3) {
122  GetCanvas()->RecursiveRemove(this);
123  GetCanvas()->Update();
124  delete this;
125  } else {
127  }
128  }
129 
130 }
131 
132 void QGGraphicalCut::SetName(const char *name)
133 {
134  if (name) {
135  string oldName = GetName();
136  string newName = name;
137  if (newName != oldName) {
138  if (IsNameInUse(name)) {
139  TCutG::SetName(GeneratePlotName(name).c_str());
140  } else {
141  TCutG::SetName(name);
142  }
143  }
144  } else {
145  TCutG::SetName(GeneratePlotName("GraphicalCut").c_str());
146  }
147 }
148 
149 void QGGraphicalCut::SetProperty(const string& key, const string& value)
150 {
152  QGPlot::SetProperty(key, value);
153  // QGPlot::SetProperty comes after QGGraphicalCutBase::SetProperty so that
154  // if key = NAME_KEY, the name can be overridden by QGPlot if necessary
155 }
156 
158 {
159  const list<QGPlot*>& drawnPlots = GetCanvasWindow()->GetDrawnPlots();
160  list<QGPlot*>::const_iterator plotIter;
161  for (plotIter = drawnPlots.begin(); plotIter != drawnPlots.end(); ++plotIter) {
162  QGCanvasWindow *newCanvasWindow = new QGCanvasWindow();
164  newCanvasWindow->GetFileHandler()->OpenFiles(GetCanvasWindow()->GetFileHandler()->GetFilenames());
165  newCanvasWindow->DisplayPlotFrame();
166  newCanvasWindow->UpdateFileLabel();
167  QGPulse *pulse = new QGPulse();
168  pulse->SetCanvasWindow(newCanvasWindow);
169  pulse->AutoSetStyle();
170  if (QGScatterPlot *scatterPlot = dynamic_cast<QGScatterPlot*>(*plotIter)) {
171  pulse->SetLineColor(scatterPlot->GetMarkerColor());
172  } else if (QGHistogram *histogram = dynamic_cast<QGHistogram*>(*plotIter)) {
173  pulse->SetLineColor(histogram->GetFillColor());
174  }
175  pulse->DisplayEditWindow();
176  pulse->GetEditWindow()->GetCutsFrame()->SetCuts((*plotIter)->GetCuts());
177  pulse->GetEditWindow()->GetCutsFrame()->AddCut(GetName());
178  pulse->Plot();
179  }
181 }
ahisto2 Draw()
ClassImp(QObject)
Window containing a ROOT canvas.
void DisplayPlotFrame()
Display the plot frame.
QGPlotFrame * GetPlotFrame()
Get pointer to the plot frame.
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
void OpenFiles(const std::vector< std::string > &files)
Open files, add them to the chain.
Base class for GUI graphical cuts. This class has minimal dependencies on other GUI classes so it is ...
void SetProperty(const std::string &key, const std::string &value)
Set property (used for opening a session)
Double_t fX0
X-coordinate of first point.
Int_t fPoints
Number of points selected by the mouse.
Double_t fY0
Y-coordinate of first point.
Class for graphical cuts.
static std::list< QGGraphicalCut * > fGraphicalCuts
Static list of existing graphical cuts.
void HandleCanvasEvent(Int_t event, Int_t px, Int_t py, TObject *selected)
Handle mouse events in the canvas.
void Erase()
Erase the graphical cut.
Double_t fXLast
X-coordinate of last selected point.
virtual ~QGGraphicalCut()
Destructor.
void Create()
Create the graphical cut with the mouse.
void CopyNameToClipboard() const
Copy name to clipboard.
void Display()
Display the graphical cut.
Double_t fYLast
Y-coordinate of last selected point.
const char * GetName() const
Get graphical cut name.
void SetName(const char *name=0)
Set graphical cut name.
void SetProperty(const std::string &key, const std::string &value)
Set property (used for opening a session)
QGGraphicalCut()
Default constructor.
void ViewPulses() const
View pulses.
Class for GUI histograms.
Definition: QGHistogram.hh:19
QGCutsFrame * GetCutsFrame()
Get pointer to the cuts frame.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to canvas.
Definition: QGPlotFrame.hh:26
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 std::string GeneratePlotName(const std::string &baseName) const
Generate a name for the plot.
Definition: QGPlot.cc:98
virtual bool IsNameInUse(const std::string &name) const
Check whether string is the name of any plot.
Definition: QGPlot.cc:168
virtual TCanvas * GetCanvas()
Get pointer to the associated canvas.
Definition: QGPlot.cc:111
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 QGCanvasWindow * GetCanvasWindow() const
Get pointer to the canvas window to which the plot is associated.
Definition: QGPlot.hh:60
virtual void SetProperty(const std::string &key, const std::string &value)
Set property (used for opening a session)
Definition: QGPlot.cc:245
virtual QGPlotEditWindow * GetEditWindow()
Get pointer to edit window.
Definition: QGPlot.hh:72
QGCanvasWindow * fCanvasWindow
Canvas window to which plot is associated.
Definition: QGPlot.hh:151
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.
static void UpdateWindowDropDownBoxes()
Update window drop down boxes.
Definition: QGWindow.cc:95