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