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