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