Geant4  10.03.p03
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CanvasInTab.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 #include <TApplication.h>
27 #include <TGClient.h>
28 #include <TCanvas.h>
29 #include <TF1.h>
30 #include <TRandom.h>
31 #include <TGButton.h>
32 #include <TRootEmbeddedCanvas.h>
33 #include "CanvasInTab.hh"
34 #include "TGTab.h"
35 #include "TGFileDialog.h"
36 
37 
38 #include <vector>
39 #include <map>
40 #include <iostream>
41 
42 
43 const char* SaveFileDialog()
44 {
45  // Prompt for file to be saved. Depending on navigation in
46  // dialog the current working directory can be changed.
47  // The returned file name is always with respect to the
48  // current directory.
49 
50  const char *gSaveAsTypes[] = {
51  "Macro files", "*.C",
52  "ROOT files", "*.root",
53  "PostScript", "*.ps",
54  "Encapsulated PostScript", "*.eps",
55  "PDF files", "*.pdf",
56  "Gif files", "*.gif",
57  "PNG files", "*.png",
58  "All files", "*",
59  0, 0
60  };
61 
62  static TGFileInfo fi;
63  fi.fFileTypes = gSaveAsTypes;
64 
65  new TGFileDialog(gClient->GetRoot(), gClient->GetRoot(), kFDSave, &fi);
66 
67  return fi.fFilename;
68 }
69 
70 CanvasInTab::CanvasInTab(const TGWindow *p,UInt_t w,UInt_t h)
71 : TGMainFrame(p,w,h)
72 {
73  fpTab = new TGTab(this, 200, 200);
74 
75  fHintPlots = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY,
76  10,10,10,2);
77 
78  AddFrame(fpTab,
79  new TGLayoutHints(kLHintsExpandX |
80  kLHintsExpandY, 10,10,10,1));
81 
82  fpTab->Resize();
83 
84  //-----
85  TGHorizontalFrame* hframe=new TGHorizontalFrame(this, 200,40);
86 
87  TGTextButton* save = new TGTextButton(hframe,"&Save as ...");
88  save->Connect("Clicked()","CanvasInTab",this,"SaveCanvas()");
89  hframe->AddFrame(save, new TGLayoutHints(kLHintsCenterX,
90  5,5,3,4));
91 
92  TGTextButton *exit = new TGTextButton(hframe,"&Exit ",
93  "gApplication->Terminate()");
94  hframe->AddFrame(exit, new TGLayoutHints(kLHintsCenterX,
95  5,5,3,4));
96 
97  AddFrame(hframe,new TGLayoutHints(kLHintsCenterX,2,2,2,2));
98 
99  //-----
100  // Sets window name and shows the main frame
101 
102  SetWindowName("PlotG");
103  MapSubwindows();
104  Resize(GetDefaultSize());
105  MapWindow();
106 }
107 
109 {
110  Cleanup();
111 // if(fpTab)
112 // {
114 // delete fpTab;
115 // }
116 
117 // if(fHintPlots)
118 // delete fHintPlots;
119 }
120 
121 size_t CanvasInTab::AddCanvas(const char* name)
122 {
123  size_t output = fEcanvas.size();
124  auto compositeFrame = fpTab->AddTab(name);
125  TRootEmbeddedCanvas* embeddedCanvas =
126  new TRootEmbeddedCanvas(name,
127  compositeFrame,
128  500, 300);
129  embeddedCanvas->SetAutoFit();
130  fEcanvas.push_back(embeddedCanvas);
131  compositeFrame->AddFrame(embeddedCanvas, fHintPlots);
132  embeddedCanvas->SetContainer(compositeFrame);
133  fpTab->Resize();
134  fpTab->MapSubwindows();
135 // fpTab->MapWindow();
136  Resize();
137  return output;
138 }
139 
140 TCanvas* CanvasInTab::GetCanvas(int i)
141 {
142  return fEcanvas[i]->GetCanvas();
143 }
144 
146 {
147  if(fpTab->GetNumberOfTabs() == 0) return;
148 
149  const char* name = SaveFileDialog();
150 
151  if(name == 0 || strlen(name) == 0) return;
152 
153  int current = fpTab->GetCurrent();
154  TCanvas* canvas = fEcanvas[current]->GetCanvas();
155  canvas->SaveAs(name);
156 }
CanvasInTab(const TGWindow *p, UInt_t w, UInt_t h)
Definition: CanvasInTab.cc:70
const XML_Char * name
Definition: expat.h:151
TCanvas * GetCanvas(int i)
Definition: CanvasInTab.cc:140
const char * p
Definition: xmltok.h:285
virtual ~CanvasInTab()
Definition: CanvasInTab.cc:108
const char * SaveFileDialog()
Definition: CanvasInTab.cc:43
void SaveCanvas()
Definition: CanvasInTab.cc:145
size_t AddCanvas(const char *name="New tab")
Definition: CanvasInTab.cc:121