File indexing completed on 2025-02-23 09:21:48
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026 #include "CanvasInTab.hh"
0027
0028 #include "TGFileDialog.h"
0029 #include "TGTab.h"
0030
0031 #include <TApplication.h>
0032 #include <TCanvas.h>
0033 #include <TF1.h>
0034 #include <TGButton.h>
0035 #include <TGClient.h>
0036 #include <TRandom.h>
0037 #include <TRootEmbeddedCanvas.h>
0038 #include <iostream>
0039 #include <map>
0040 #include <vector>
0041
0042
0043
0044 const char* SaveFileDialog()
0045 {
0046
0047
0048
0049
0050
0051 const char* gSaveAsTypes[] = {"Macro files",
0052 "*.C",
0053 "ROOT files",
0054 "*.root",
0055 "PostScript",
0056 "*.ps",
0057 "Encapsulated PostScript",
0058 "*.eps",
0059 "PDF files",
0060 "*.pdf",
0061 "Gif files",
0062 "*.gif",
0063 "PNG files",
0064 "*.png",
0065 "All files",
0066 "*",
0067 0,
0068 0};
0069
0070 static TGFileInfo fi;
0071 fi.fFileTypes = gSaveAsTypes;
0072
0073 new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
0074
0075 return fi.fFilename;
0076 }
0077
0078
0079
0080 CanvasInTab::CanvasInTab(const TGWindow* p, UInt_t w, UInt_t h) : TGMainFrame(p, w, h)
0081 {
0082 fpTab = new TGTab(this, 200, 200);
0083
0084 fHintPlots = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 2);
0085
0086 AddFrame(fpTab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 10, 10, 10, 1));
0087
0088 fpTab->Resize();
0089
0090
0091 TGHorizontalFrame* hframe = new TGHorizontalFrame(this, 200, 40);
0092
0093 TGTextButton* save = new TGTextButton(hframe, "&Save as ...");
0094 save->Connect("Clicked()", "CanvasInTab", this, "SaveCanvas()");
0095 hframe->AddFrame(save, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
0096
0097 TGTextButton* exit = new TGTextButton(hframe, "&Exit ", "gApplication->Terminate()");
0098 hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX, 5, 5, 3, 4));
0099
0100 AddFrame(hframe, new TGLayoutHints(kLHintsCenterX, 2, 2, 2, 2));
0101
0102
0103
0104
0105 SetWindowName("PlotG");
0106 MapSubwindows();
0107 Resize(GetDefaultSize());
0108 MapWindow();
0109 }
0110
0111
0112
0113 CanvasInTab::~CanvasInTab()
0114 {
0115 Cleanup();
0116
0117
0118
0119
0120
0121
0122
0123
0124 }
0125
0126
0127
0128 size_t CanvasInTab::AddCanvas(const char* name)
0129 {
0130 size_t output = fEcanvas.size();
0131 auto compositeFrame = fpTab->AddTab(name);
0132 TRootEmbeddedCanvas* embeddedCanvas = new TRootEmbeddedCanvas(name, compositeFrame, 500, 300);
0133 embeddedCanvas->SetAutoFit();
0134 fEcanvas.push_back(embeddedCanvas);
0135 compositeFrame->AddFrame(embeddedCanvas, fHintPlots);
0136 embeddedCanvas->SetContainer(compositeFrame);
0137 fpTab->Resize();
0138 fpTab->MapSubwindows();
0139
0140 Resize();
0141 return output;
0142 }
0143
0144
0145
0146 TCanvas* CanvasInTab::GetCanvas(int i)
0147 {
0148 return fEcanvas[i]->GetCanvas();
0149 }
0150
0151
0152
0153 void CanvasInTab::SaveCanvas()
0154 {
0155 if (fpTab->GetNumberOfTabs() == 0) return;
0156
0157 const char* name = SaveFileDialog();
0158
0159 if (name == 0 || strlen(name) == 0) return;
0160
0161 int current = fpTab->GetCurrent();
0162 TCanvas* canvas = fEcanvas[current]->GetCanvas();
0163 canvas->SaveAs(name);
0164 }