Geant4  10.02.p01
G4PlotMessenger.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 // $Id$
27 
28 // Author: Ivana Hrivnacova, 21/10/2015 (ivana@ipno.in2p3.fr)
29 
30 #include "G4PlotMessenger.hh"
31 #include "G4PlotParameters.hh"
32 #include "G4AnalysisUtilities.hh"
34 
35 #include "G4UIdirectory.hh"
36 #include "G4UIcommand.hh"
37 #include "G4UIparameter.hh"
38 #include "G4UIcmdWithAString.hh"
39 //#include "G4Tokenizer.hh"
40 
41 #include <iostream>
42 #include <sstream>
43 #include <vector>
44 
45 using namespace G4Analysis;
46 
47 //_____________________________________________________________________________
49  : G4UImessenger(),
50  fPlotParameters(plotParameters),
51  fHelper(nullptr),
52  fDirectory(nullptr),
53  fSetLayoutCmd(nullptr),
54  fSetDimensionsCmd(nullptr),
55  fSetStyleCmd(nullptr)
56 {
57  fHelper = G4Analysis::make_unique<G4AnalysisMessengerHelper>("plot");
58 
59  fDirectory = fHelper->CreateHnDirectory();
60 
61  SetStyleCmd();
62  SetLayoutCmd();
64 }
65 
66 //_____________________________________________________________________________
68 {}
69 
70 //
71 // private functions
72 //
73 
74 //_____________________________________________________________________________
76 {
77  fSetStyleCmd = G4Analysis::make_unique<G4UIcmdWithAString>("/analysis/plot/setStyle",this);
78 #if defined(TOOLS_USE_FREETYPE)
79  fSetStyleCmd->SetGuidance("Set plotting style from: ");
80  fSetStyleCmd->SetGuidance(" ROOT_default: ROOT style with high resolution fonts");
81  fSetStyleCmd->SetGuidance(" hippodraw: hippodraw style with high resolution fonts");
82  fSetStyleCmd->SetGuidance(" inlib_default: PAW style with low resolution fonts");
83  fSetStyleCmd->SetParameterName("Style", false);
84 #else
85  fSetStyleCmd->SetGuidance("Only one plotting style is available in low resolution: ");
86  fSetStyleCmd->SetGuidance(" inlib_default: PAW style with low resolution fonts");
87  fSetStyleCmd->SetParameterName("Style", false);
88  fSetStyleCmd->SetCandidates("inlib_default");
89 #endif
91  fSetStyleCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
92 }
93 
94 //_____________________________________________________________________________
96 {
97  auto columns = new G4UIparameter("columns", 'i', false);
98  columns->SetGuidance("The number of columns in the page layout.");
99  G4String range = "columns>=1 && columns<=";
100  std::ostringstream osMaxColumns;
101  osMaxColumns << fPlotParameters->GetMaxColumns();
102  range.append(osMaxColumns.str());
103  columns->SetParameterRange(range);
104 
105  auto rows = new G4UIparameter("rows", 'i', false);
106  rows->SetGuidance("The number of rows in the page layout.");
107  range = "rows>=1 && rows<=";
108  std::ostringstream osMaxRows;
109  osMaxRows << fPlotParameters->GetMaxRows();
110  range.append(osMaxRows.str());
111  rows->SetParameterRange(range);
112 
113  fSetLayoutCmd = G4Analysis::make_unique<G4UIcommand>("/analysis/plot/setLayout", this);
114  // Guidance text:
115  // Set page layout (number of columns and rows per page).
116  // Suported layouts:
117  // columns = 1 .. maxValueAllowed
118  // rows = 1 .. maxValueAllowed, and >= columns
119  fSetLayoutCmd->SetGuidance("Set page layout (number of columns and rows per page).");
120  fSetLayoutCmd->SetGuidance(" Suported layouts: ");
121  G4String guidance = " columns = 1 .. ";
122  guidance.append(osMaxColumns.str());
123  fSetLayoutCmd->SetGuidance(guidance);
124  guidance = " rows = 1 .. ";
125  guidance.append(osMaxRows.str());
126  guidance.append(" and >= columns");
127  fSetLayoutCmd->SetGuidance(guidance);
128  fSetLayoutCmd->SetParameter(columns);
129  fSetLayoutCmd->SetParameter(rows);
130  fSetLayoutCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
131 }
132 
133 //_____________________________________________________________________________
135 {
136  auto width = new G4UIparameter("width", 'i', false);
137  width->SetGuidance("The page width.");
138 
139  auto height = new G4UIparameter("height", 'i', false);
140  height->SetGuidance("The page height.");
141 
142  fSetDimensionsCmd = G4Analysis::make_unique<G4UIcommand>("/analysis/plot/setDimensions", this);
143  fSetDimensionsCmd->SetGuidance("Set the plotter window size (width and height) in pixels.");
144  fSetDimensionsCmd->SetParameter(width);
145  fSetDimensionsCmd->SetParameter(height);
146  fSetDimensionsCmd->AvailableForStates(G4State_PreInit, G4State_Idle);
147 }
148 
149 //
150 // public functions
151 //
152 
153 //_____________________________________________________________________________
155 {
156  // tokenize parameters in a vector
157  std::vector<G4String> parameters;
158  G4Analysis::Tokenize(newValues, parameters);
159  // check consistency
160  if ( G4int(parameters.size()) != command->GetParameterEntries() ) {
161  // Should never happen but let's check anyway for consistency
162  fHelper->WarnAboutParameters(command, parameters.size());
163  return;
164  }
165 
166  if ( command == fSetLayoutCmd.get() ) {
167  auto counter = 0;
168  auto columns = G4UIcommand::ConvertToInt(parameters[counter++]);
169  auto rows = G4UIcommand::ConvertToInt(parameters[counter++]);
170  fPlotParameters->SetLayout(columns, rows);
171  }
172  else if ( command == fSetDimensionsCmd.get() ) {
173  auto counter = 0;
174  auto width = G4UIcommand::ConvertToInt(parameters[counter++]);
175  auto height = G4UIcommand::ConvertToInt(parameters[counter++]);
177  }
178 #if defined(TOOLS_USE_FREETYPE)
179  else if ( command == fSetStyleCmd.get() ) {
180  fPlotParameters->SetStyle(newValues);
181  }
182 #endif
183 }
G4String GetAvailableStyles()
std::unique_ptr< G4UIcmdWithAString > fSetStyleCmd
std::unique_ptr< G4UIcommand > fSetLayoutCmd
#define width
G4PlotParameters * fPlotParameters
Associated class.
std::unique_ptr< G4AnalysisMessengerHelper > fHelper
virtual void SetNewValue(G4UIcommand *command, G4String value) final
int G4int
Definition: G4Types.hh:78
std::unique_ptr< G4UIcommand > fSetDimensionsCmd
std::unique_ptr< G4UIdirectory > fDirectory
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
void Tokenize(const G4String &line, std::vector< G4String > &tokens)
G4String & append(const G4String &)
void SetLayout(G4int columns, G4int rows)
virtual ~G4PlotMessenger()
void SetDimensions(G4int width, G4int height)
void SetStyle(const G4String &style)
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4PlotMessenger(G4PlotParameters *plotParameters)