Diana Software
QGCanvasSetupFrame.cc
Go to the documentation of this file.
1 #include "QGCanvasSetupFrame.hh"
2 #include <iostream>
3 #include <string>
4 #include <vector>
5 #include "QGCanvasWindow.hh"
6 #include "QGFileHandler.hh"
7 #include "QGPlot.hh"
8 #include "QGPlotFrame.hh"
9 #include "QGSessionHandler.hh"
10 #include <TCanvas.h>
11 #include <TGButton.h>
12 #include <TGClient.h>
13 #include <TGIcon.h>
14 #include <TGPicture.h>
15 #include <TRootEmbeddedCanvas.h>
16 
17 // Images
18 #include "ImageCloseFiles.xpm"
19 #include "ImageListOpenFiles.xpm"
20 #include "ImageOpenFile.xpm"
21 #include "ImageOpenSession.xpm"
22 #include "ImageSaveSession.xpm"
23 
25 
26 using std::cout;
27 using std::endl;
28 using std::string;
29 using std::vector;
30 
32 TGCompositeFrame(p, w, h),
33 fCanvasWindow(p), fCloseFilesButton(0), fOpenFileButton(0), fOpenSessionButton(0), fSaveSessionButton(0)
34 {
35  SetCleanup(kDeepCleanup);
36 
37  fOpenFileButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("OpenFile", (char**)ImageOpenFile));
38  AddFrame(fOpenFileButton, new TGLayoutHints(kLHintsCenterX, 2, 2, 0, 0));
39  fOpenFileButton->SetToolTipText("Open a Diana ROOT file");
40  fOpenFileButton->Connect("Clicked()", "QGCanvasSetupFrame", this, "OpenFile()");
41 
42  fCloseFilesButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("CloseFiles", (char**)ImageCloseFiles));
43  AddFrame(fCloseFilesButton, new TGLayoutHints(kLHintsCenterX, 2, 2, 0, 0));
44  fCloseFilesButton->SetToolTipText("Close open files");
45  fCloseFilesButton->Connect("Clicked()", "QGCanvasSetupFrame", this, "HandleCloseFilesButton()");
46 
47  fListOpenFilesButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("ListOpenFiles", (char**)ImageListOpenFiles));
48  AddFrame(fListOpenFilesButton, new TGLayoutHints(kLHintsCenterX, 2, 2, 0, 0));
49  fListOpenFilesButton->SetToolTipText("Print a list of the open files to the console");
50  fListOpenFilesButton->Connect("Clicked()", "QGCanvasSetupFrame", this, "HandleListOpenFilesButton()");
51 
52  fOpenSessionButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("OpenSession", (char**)ImageOpenSession));
53  AddFrame(fOpenSessionButton, new TGLayoutHints(kLHintsCenterX, 2, 2, 0, 0));
54  fOpenSessionButton->SetToolTipText("Open a Diana GUI session");
55  fOpenSessionButton->Connect("Clicked()", "QGCanvasSetupFrame", this, "OpenSession()");
56 
57  fSaveSessionButton = new TGPictureButton(this, gClient->GetPicturePool()->GetPicture("SaveSession", (char**)ImageSaveSession));
58  AddFrame(fSaveSessionButton, new TGLayoutHints(kLHintsCenterX, 2, 2, 0, 0));
59  fSaveSessionButton->SetToolTipText("Save the GUI session to a file");
60  fSaveSessionButton->Connect("Clicked()", "QGCanvasSetupFrame", this, "HandleSaveSessionButton()");
61 }
62 
64 {
65  Cleanup();
66 }
67 
69 {
75  fCanvasWindow->GetPlotFrame()->GetEmbeddedCanvas()->GetCanvas()->Clear();
76 }
77 
79 {
81 }
82 
84 {
89  }
92 }
93 
95 {
96  QGSessionHandler *sessionHandler = new QGSessionHandler();
97  if (!fCanvasWindow->GetFileHandler()->IsFileOpen() && fCanvasWindow->GetPlots().size() == 0) {
98  // there is no file open and no plots associated with this canvas window
99  sessionHandler->OpenSession(fCanvasWindow);
100  } else {
101  sessionHandler->OpenSession();
102  }
103  delete sessionHandler;
104 }
105 
107 {
108  QGSessionHandler *sessionHandler = new QGSessionHandler();
109  sessionHandler->SaveSession();
110  delete sessionHandler;
111 }
112 
114 {
116  ShowFrame(fCloseFilesButton);
117  ShowFrame(fListOpenFilesButton);
118  } else {
119  HideFrame(fCloseFilesButton);
120  HideFrame(fListOpenFilesButton);
121  }
122 
123  if (fCanvasWindow->GetFileHandler()->IsFileOpen() || QGPlot::GetPlots().size() != 0) {
124  ShowFrame(fSaveSessionButton);
125  } else {
126  HideFrame(fSaveSessionButton);
127  }
128 
129  Resize(GetDefaultSize());
130 }
ClassImp(QObject)
Part of a canvas window for doing setup tasks.
void HandleSaveSessionButton()
Handle save session button.
void HandleListOpenFilesButton()
Handle list open files button.
virtual ~QGCanvasSetupFrame()
Destructor.
void OpenSession()
Pop up the session open dialog.
TGPictureButton * fListOpenFilesButton
Button to list open files.
TGPictureButton * fCloseFilesButton
Button to close files.
void OpenFile()
Pop up the file open dialog.
QGCanvasWindow * fCanvasWindow
Parent canvas window.
TGPictureButton * fSaveSessionButton
Button to save a session.
QGCanvasSetupFrame(QGCanvasWindow *p, UInt_t w, UInt_t h)
Private constructor.
TGPictureButton * fOpenFileButton
Button to open a file.
void HandleCloseFilesButton()
Handle close files button.
TGPictureButton * fOpenSessionButton
Button to open a session.
void SetDisplay()
Set the display based on the current state.
Window containing a ROOT canvas.
void DisplayPlotFrame()
Display the plot frame.
QGPlotFrame * GetPlotFrame()
Get pointer to the plot frame.
void DisplaySetupFrame()
Display the setup frame.
std::list< QGPlot * > & GetPlots()
Get collection of plots associated with this window.
void SetPlotsToRegenerate()
Set regenerate for each plot associated with this window.
QGFileHandler * GetFileHandler() const
Get pointer to file handler.
void ClearDrawnPlots()
Clears the collection of drawn plots.
void UpdateVariablesDropDownBoxes()
Update variables drop down boxes for plots associated with this window.
void UpdateFileLabel()
Update the file label.
bool IsFileOpen()
Check whether a file is open.
void OpenFile()
Pop up a file open dialog.
void ListOpenFiles()
Print a list of open files to the console.
void CloseFiles()
Close all open files, empty the chain.
TRootEmbeddedCanvas * GetEmbeddedCanvas()
Get pointer to canvas.
Definition: QGPlotFrame.hh:26
static const std::list< QGPlot * > & GetPlots()
Get collection of plots.
Definition: QGPlot.hh:84
Class to handle saving and opening sessions.
void SaveSession()
Save session.
void OpenSession(QGCanvasWindow *window=0)
Open session.
std::string Resize(const std::string &s, size_t len)
resize a string to len, adding spaces if necessary