Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-05 07:50:19

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 /// \file CanvasInTab.cc
0027 /// \brief Implementation of the CanvasInTab class
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0046 
0047 const char* SaveFileDialog()
0048 {
0049   // Prompt for file to be saved. Depending on navigation in
0050   // dialog the current working directory can be changed.
0051   // The returned file name is always with respect to the
0052   // current directory.
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // Sets window name and shows the main frame
0107 
0108   SetWindowName("PlotG");
0109   MapSubwindows();
0110   Resize(GetDefaultSize());
0111   MapWindow();
0112 }
0113 
0114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0115 
0116 CanvasInTab::~CanvasInTab()
0117 {
0118   Cleanup();
0119   //  if(fpTab)
0120   //  {
0121   ////    fpTab->Cleanup();
0122   //    delete fpTab;
0123   //  }
0124 
0125   //  if(fHintPlots)
0126   //    delete fHintPlots;
0127 }
0128 
0129 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   //  fpTab->MapWindow();
0143   Resize();
0144   return output;
0145 }
0146 
0147 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0148 
0149 TCanvas* CanvasInTab::GetCanvas(int i)
0150 {
0151   return fEcanvas[i]->GetCanvas();
0152 }
0153 
0154 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 }