Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 //
27 // $Id$
28 //
29 //
30 
32 #include "G4Tokenizer.hh"
33 #include "G4UnitsTable.hh"
34 #include <sstream>
35 
37 (const char * theCommandPath,G4UImessenger * theMessenger)
38 :G4UIcommand(theCommandPath,theMessenger)
39 {
40  G4UIparameter * dblParamX = new G4UIparameter('d');
41  SetParameter(dblParamX);
42  G4UIparameter * dblParamY = new G4UIparameter('d');
43  SetParameter(dblParamY);
44  G4UIparameter * dblParamZ = new G4UIparameter('d');
45  SetParameter(dblParamZ);
46  G4UIparameter * untParam = new G4UIparameter('s');
47  SetParameter(untParam);
48  untParam->SetParameterName("Unit");
49 }
50 
52 {
53  std::vector<G4String> token_vector;
54  G4Tokenizer tkn(parameterList);
55  G4String str;
56  while( (str = tkn()) != "" ) {
57  token_vector.push_back(str);
58  }
59 
60  // convert a value in default unit
61  G4String converted_parameter;
62  G4String default_unit = GetParameter(3)-> GetDefaultValue();
63  if (default_unit != "" && token_vector.size() >= 4) {
64  G4double value_given = ValueOf(token_vector[3]);
65  G4double value_default = ValueOf(default_unit);
66  G4double x = ConvertToDouble(token_vector[0]) * value_given / value_default;
67  G4double y = ConvertToDouble(token_vector[1]) * value_given / value_default;
68  G4double z = ConvertToDouble(token_vector[2]) * value_given / value_default;
69 
70  // reconstruct parameter list
71  converted_parameter += ConvertToString(x);
72  converted_parameter += " ";
73  converted_parameter += ConvertToString(y);
74  converted_parameter += " ";
75  converted_parameter += ConvertToString(z);
76  converted_parameter += " ";
77  converted_parameter += default_unit;
78  for ( size_t i=4 ; i< token_vector.size(); i++) {
79  converted_parameter += " ";
80  converted_parameter += token_vector[i];
81  }
82  } else {
83  converted_parameter = parameterList;
84  }
85 
86  return G4UIcommand::DoIt(converted_parameter);
87 }
88 
90 {
91  return ConvertToDimensioned3Vector(paramString);
92 }
93 
95 {
96  G4double vx;
97  G4double vy;
98  G4double vz;
99  char unts[30];
100  std::istringstream is(paramString);
101  is >> vx >> vy >> vz >> unts;
102  return G4ThreeVector(vx,vy,vz);
103 }
104 
106 {
107  G4double vx;
108  G4double vy;
109  G4double vz;
110  char unts[30];
111  std::istringstream is(paramString);
112  is >> vx >> vy >> vz >> unts;
113  G4String unt = unts;
114  return ValueOf(unt);
115 }
116 
118 {
119  G4UIparameter* unitParam = GetParameter(3);
120  G4String canList = unitParam->GetParameterCandidates();
121  G4Tokenizer candidateTokenizer(canList);
122  G4String aToken = candidateTokenizer();
123 
124  std::ostringstream os;
125  os << G4BestUnit(vec,CategoryOf(aToken));
126  G4String st = os.str();
127 
128  return st;
129 }
130 
132 {
133  G4UIparameter* unitParam = GetParameter(3);
134  G4String st;
135  if(unitParam->IsOmittable())
136  { st = ConvertToString(vec,unitParam->GetDefaultValue()); }
137  else
138  { st = ConvertToStringWithBestUnit(vec); }
139  return st;
140 }
141 
143 (const char * theNameX,const char * theNameY,const char * theNameZ,
144 G4bool omittable,G4bool currentAsDefault)
145 {
146  G4UIparameter * theParamX = GetParameter(0);
147  theParamX->SetParameterName(theNameX);
148  theParamX->SetOmittable(omittable);
149  theParamX->SetCurrentAsDefault(currentAsDefault);
150  G4UIparameter * theParamY = GetParameter(1);
151  theParamY->SetParameterName(theNameY);
152  theParamY->SetOmittable(omittable);
153  theParamY->SetCurrentAsDefault(currentAsDefault);
154  G4UIparameter * theParamZ = GetParameter(2);
155  theParamZ->SetParameterName(theNameZ);
156  theParamZ->SetOmittable(omittable);
157  theParamZ->SetCurrentAsDefault(currentAsDefault);
158 }
159 
161 {
162  G4UIparameter * theParamX = GetParameter(0);
163  theParamX->SetDefaultValue(vec.x());
164  G4UIparameter * theParamY = GetParameter(1);
165  theParamY->SetDefaultValue(vec.y());
166  G4UIparameter * theParamZ = GetParameter(2);
167  theParamZ->SetDefaultValue(vec.z());
168 }
169 
170 void G4UIcmdWith3VectorAndUnit::SetUnitCategory(const char * unitCategory)
171 {
172  SetUnitCandidates(UnitsList(unitCategory));
173 }
174 
175 void G4UIcmdWith3VectorAndUnit::SetUnitCandidates(const char * candidateList)
176 {
177  G4UIparameter * untParam = GetParameter(3);
178  G4String canList = candidateList;
179  untParam->SetParameterCandidates(canList);
180 }
181 
183 {
184  G4UIparameter * untParam = GetParameter(3);
185  untParam->SetOmittable(true);
186  untParam->SetDefaultValue(defUnit);
187  SetUnitCategory(CategoryOf(defUnit));
188 }
189