Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIcmdWith3VectorAndUnit.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// G4UIcmdWith3VectorAndUnit
27//
28// Author: M.Asai, 1998
29// --------------------------------------------------------------------
30
32#include "G4Tokenizer.hh"
33#include "G4UnitsTable.hh"
34#include "G4UIcommandStatus.hh"
35#include <sstream>
36
37// --------------------------------------------------------------------
39 const char* theCommandPath, G4UImessenger* theMessenger)
40 : G4UIcommand(theCommandPath, theMessenger)
41{
42 G4UIparameter* dblParamX = new G4UIparameter('d');
43 SetParameter(dblParamX);
44 G4UIparameter* dblParamY = new G4UIparameter('d');
45 SetParameter(dblParamY);
46 G4UIparameter* dblParamZ = new G4UIparameter('d');
47 SetParameter(dblParamZ);
48 G4UIparameter* untParam = new G4UIparameter('s');
49 SetParameter(untParam);
50 untParam->SetParameterName("Unit");
51}
52
53// --------------------------------------------------------------------
55{
56 std::vector<G4String> token_vector;
57 G4Tokenizer tkn(parameterList);
58 G4String str;
59 while((str = tkn()) != "")
60 {
61 token_vector.push_back(str);
62 }
63
64 // convert a value in default unit
65 G4String converted_parameter;
66 G4String default_unit = GetParameter(3)->GetDefaultValue();
67 if(default_unit != "" && token_vector.size() >= 4)
68 {
69 if(CategoryOf(token_vector[3]) != CategoryOf(default_unit))
70 {
72 }
73 G4double value_given = ValueOf(token_vector[3]);
74 G4double value_default = ValueOf(default_unit);
75 G4double x = ConvertToDouble(token_vector[0]) * value_given / value_default;
76 G4double y = ConvertToDouble(token_vector[1]) * value_given / value_default;
77 G4double z = ConvertToDouble(token_vector[2]) * value_given / value_default;
78
79 // reconstruct parameter list
80 converted_parameter += ConvertToString(x);
81 converted_parameter += " ";
82 converted_parameter += ConvertToString(y);
83 converted_parameter += " ";
84 converted_parameter += ConvertToString(z);
85 converted_parameter += " ";
86 converted_parameter += default_unit;
87 for(std::size_t i = 4; i < token_vector.size(); ++i)
88 {
89 converted_parameter += " ";
90 converted_parameter += token_vector[i];
91 }
92 }
93 else
94 {
95 converted_parameter = parameterList;
96 }
97
98 return G4UIcommand::DoIt(converted_parameter);
99}
100
101// --------------------------------------------------------------------
103 const char* paramString)
104{
105 return ConvertToDimensioned3Vector(paramString);
106}
107
108// --------------------------------------------------------------------
110 const char* paramString)
111{
112 G4double vx;
113 G4double vy;
114 G4double vz;
115 char unts[30];
116 std::istringstream is(paramString);
117 is >> vx >> vy >> vz >> unts;
118 return G4ThreeVector(vx, vy, vz);
119}
120
121// --------------------------------------------------------------------
123{
124 G4double vx;
125 G4double vy;
126 G4double vz;
127 char unts[30];
128 std::istringstream is(paramString);
129 is >> vx >> vy >> vz >> unts;
130 G4String unt = unts;
131 return ValueOf(unt);
132}
133
134// --------------------------------------------------------------------
136 G4ThreeVector vec)
137{
138 G4UIparameter* unitParam = GetParameter(3);
139 G4String canList = unitParam->GetParameterCandidates();
140 G4Tokenizer candidateTokenizer(canList);
141 G4String aToken = candidateTokenizer();
142
143 std::ostringstream os;
144 os << G4BestUnit(vec, CategoryOf(aToken));
145 G4String st = os.str();
146
147 return st;
148}
149
150// --------------------------------------------------------------------
152 G4ThreeVector vec)
153{
154 G4UIparameter* unitParam = GetParameter(3);
155 G4String st;
156 if(unitParam->IsOmittable())
157 {
158 st = ConvertToString(vec, unitParam->GetDefaultValue());
159 }
160 else
161 {
163 }
164 return st;
165}
166
167// --------------------------------------------------------------------
169 const char* theNameY,
170 const char* theNameZ,
171 G4bool omittable,
172 G4bool currentAsDefault)
173{
174 G4UIparameter* theParamX = GetParameter(0);
175 theParamX->SetParameterName(theNameX);
176 theParamX->SetOmittable(omittable);
177 theParamX->SetCurrentAsDefault(currentAsDefault);
178 G4UIparameter* theParamY = GetParameter(1);
179 theParamY->SetParameterName(theNameY);
180 theParamY->SetOmittable(omittable);
181 theParamY->SetCurrentAsDefault(currentAsDefault);
182 G4UIparameter* theParamZ = GetParameter(2);
183 theParamZ->SetParameterName(theNameZ);
184 theParamZ->SetOmittable(omittable);
185 theParamZ->SetCurrentAsDefault(currentAsDefault);
186}
187
188// --------------------------------------------------------------------
190{
191 G4UIparameter* theParamX = GetParameter(0);
192 theParamX->SetDefaultValue(vec.x());
193 G4UIparameter* theParamY = GetParameter(1);
194 theParamY->SetDefaultValue(vec.y());
195 G4UIparameter* theParamZ = GetParameter(2);
196 theParamZ->SetDefaultValue(vec.z());
197}
198
199// --------------------------------------------------------------------
200void G4UIcmdWith3VectorAndUnit::SetUnitCategory(const char* unitCategory)
201{
202 SetUnitCandidates(UnitsList(unitCategory));
203}
204
205// --------------------------------------------------------------------
206void G4UIcmdWith3VectorAndUnit::SetUnitCandidates(const char* candidateList)
207{
208 G4UIparameter* untParam = GetParameter(3);
209 G4String canList = candidateList;
210 untParam->SetParameterCandidates(canList);
211}
212
213// --------------------------------------------------------------------
215{
216 G4UIparameter* untParam = GetParameter(3);
217 untParam->SetOmittable(true);
218 untParam->SetDefaultValue(defUnit);
219 SetUnitCategory(CategoryOf(defUnit));
220}
#define G4BestUnit(a, b)
CLHEP::Hep3Vector G4ThreeVector
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
@ fParameterOutOfCandidates
double z() const
double x() const
double y() const
G4String ConvertToStringWithDefaultUnit(G4ThreeVector vec)
void SetDefaultUnit(const char *defUnit)
G4String ConvertToStringWithBestUnit(G4ThreeVector vec)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void SetParameterName(const char *theNameX, const char *theNameY, const char *theNameZ, G4bool omittable, G4bool currentAsDefault=false)
static G4double GetNewUnitValue(const char *paramString)
void SetUnitCandidates(const char *candidateList)
void SetUnitCategory(const char *unitCategory)
static G4ThreeVector GetNew3VectorRawValue(const char *paramString)
G4UIcmdWith3VectorAndUnit(const char *theCommandPath, G4UImessenger *theMessenger)
void SetDefaultValue(G4ThreeVector defVal)
virtual G4int DoIt(G4String parameterList)
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:139
static G4String CategoryOf(const char *unitName)
Definition: G4UIcommand.cc:356
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:348
virtual G4int DoIt(G4String parameterList)
Definition: G4UIcommand.cc:135
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:430
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
static G4String UnitsList(const char *unitCategory)
Definition: G4UIcommand.cc:362
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:561
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
Definition: G4UIcommand.cc:594
const G4String & GetParameterCandidates() const
void SetDefaultValue(const char *theDefaultValue)
void SetParameterName(const char *pName)
G4bool IsOmittable() const
void SetOmittable(G4bool om)
void SetParameterCandidates(const char *theString)
void SetCurrentAsDefault(G4bool val)
const G4String & GetDefaultValue() const