Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-02-23 09:21:48

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 #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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0043 
0044 const char* SaveFileDialog()
0045 {
0046   // Prompt for file to be saved. Depending on navigation in
0047   // dialog the current working directory can be changed.
0048   // The returned file name is always with respect to the
0049   // current directory.
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 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   // Sets window name and shows the main frame
0104 
0105   SetWindowName("PlotG");
0106   MapSubwindows();
0107   Resize(GetDefaultSize());
0108   MapWindow();
0109 }
0110 
0111 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0112 
0113 CanvasInTab::~CanvasInTab()
0114 {
0115   Cleanup();
0116   //  if(fpTab)
0117   //  {
0118   ////    fpTab->Cleanup();
0119   //    delete fpTab;
0120   //  }
0121 
0122   //  if(fHintPlots)
0123   //    delete fHintPlots;
0124 }
0125 
0126 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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   //  fpTab->MapWindow();
0140   Resize();
0141   return output;
0142 }
0143 
0144 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
0145 
0146 TCanvas* CanvasInTab::GetCanvas(int i)
0147 {
0148   return fEcanvas[i]->GetCanvas();
0149 }
0150 
0151 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
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 }