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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /intercoms/src/G4UIcmdWith3VectorAndUnit.cc (Version 11.3.0) and /intercoms/src/G4UIcmdWith3VectorAndUnit.cc (Version 10.5)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 // G4UIcmdWith3VectorAndUnit                   << 
 27 //                                                 26 //
 28 // Author: M.Asai, 1998                        <<  27 //
 29 // ------------------------------------------- <<  28 //
 30                                                    29 
 31 #include "G4UIcmdWith3VectorAndUnit.hh"            30 #include "G4UIcmdWith3VectorAndUnit.hh"
 32                                                << 
 33 #include "G4Tokenizer.hh"                          31 #include "G4Tokenizer.hh"
 34 #include "G4UIcommandStatus.hh"                << 
 35 #include "G4UnitsTable.hh"                         32 #include "G4UnitsTable.hh"
 36                                                <<  33 #include "G4UIcommandStatus.hh"
 37 #include <sstream>                                 34 #include <sstream>
 38                                                    35 
 39 // ------------------------------------------- <<  36 G4UIcmdWith3VectorAndUnit::G4UIcmdWith3VectorAndUnit
 40 G4UIcmdWith3VectorAndUnit::G4UIcmdWith3VectorA <<  37 (const char * theCommandPath,G4UImessenger * theMessenger)
 41                                                <<  38 :G4UIcommand(theCommandPath,theMessenger)
 42   : G4UIcommand(theCommandPath, theMessenger)  << 
 43 {                                                  39 {
 44   auto* dblParamX = new G4UIparameter('d');    <<  40   G4UIparameter * dblParamX = new G4UIparameter('d');
 45   SetParameter(dblParamX);                         41   SetParameter(dblParamX);
 46   auto* dblParamY = new G4UIparameter('d');    <<  42   G4UIparameter * dblParamY = new G4UIparameter('d');
 47   SetParameter(dblParamY);                         43   SetParameter(dblParamY);
 48   auto* dblParamZ = new G4UIparameter('d');    <<  44   G4UIparameter * dblParamZ = new G4UIparameter('d');
 49   SetParameter(dblParamZ);                         45   SetParameter(dblParamZ);
 50   auto* untParam = new G4UIparameter('s');     <<  46   G4UIparameter * untParam = new G4UIparameter('s');
 51   untParam->SetParameterName("Unit");          << 
 52   SetParameter(untParam);                          47   SetParameter(untParam);
 53   SetCommandType(With3VectorAndUnitCmd);       <<  48   untParam->SetParameterName("Unit");
 54 }                                                  49 }
 55                                                    50 
 56 // ------------------------------------------- <<  51 G4int G4UIcmdWith3VectorAndUnit::DoIt(G4String parameterList)
 57 G4int G4UIcmdWith3VectorAndUnit::DoIt(const G4 << 
 58 {                                                  52 {
 59   std::vector<G4String> token_vector;              53   std::vector<G4String> token_vector;
 60   G4Tokenizer tkn(parameterList);                  54   G4Tokenizer tkn(parameterList);
 61   G4String str;                                    55   G4String str;
 62   while (!(str = tkn()).empty()) {             <<  56   while( (str = tkn()) != "" ) {
 63     token_vector.push_back(str);                   57     token_vector.push_back(str);
 64   }                                                58   }
 65                                                    59 
 66   // convert a value in default unit               60   // convert a value in default unit
 67   G4String converted_parameter;                    61   G4String converted_parameter;
 68   G4String default_unit = GetParameter(3)->Get <<  62   G4String default_unit = GetParameter(3)-> GetDefaultValue();
 69   if (!default_unit.empty() && token_vector.si <<  63   if (default_unit != "" && token_vector.size() >= 4) {
 70     if (CategoryOf(token_vector[3]) != Categor <<  64     if(CategoryOf(token_vector[3])!=CategoryOf(default_unit))
 71       return fParameterOutOfCandidates + 3;    <<  65     { return fParameterOutOfCandidates+3; }
 72     }                                          << 
 73     G4double value_given = ValueOf(token_vecto     66     G4double value_given = ValueOf(token_vector[3]);
 74     G4double value_default = ValueOf(default_u     67     G4double value_default = ValueOf(default_unit);
 75     G4double x = ConvertToDouble(token_vector[     68     G4double x = ConvertToDouble(token_vector[0]) * value_given / value_default;
 76     G4double y = ConvertToDouble(token_vector[     69     G4double y = ConvertToDouble(token_vector[1]) * value_given / value_default;
 77     G4double z = ConvertToDouble(token_vector[     70     G4double z = ConvertToDouble(token_vector[2]) * value_given / value_default;
 78                                                    71 
 79     // reconstruct parameter list                  72     // reconstruct parameter list
 80     converted_parameter += ConvertToString(x);     73     converted_parameter += ConvertToString(x);
 81     converted_parameter += " ";                    74     converted_parameter += " ";
 82     converted_parameter += ConvertToString(y);     75     converted_parameter += ConvertToString(y);
 83     converted_parameter += " ";                    76     converted_parameter += " ";
 84     converted_parameter += ConvertToString(z);     77     converted_parameter += ConvertToString(z);
 85     converted_parameter += " ";                    78     converted_parameter += " ";
 86     converted_parameter += default_unit;           79     converted_parameter += default_unit;
 87     for (std::size_t i = 4; i < token_vector.s <<  80     for ( size_t i=4 ; i< token_vector.size(); i++) {
 88       converted_parameter += " ";                  81       converted_parameter += " ";
 89       converted_parameter += token_vector[i];      82       converted_parameter += token_vector[i];
 90     }                                              83     }
 91   }                                            <<  84   } else {
 92   else {                                       << 
 93     converted_parameter = parameterList;           85     converted_parameter = parameterList;
 94   }                                                86   }
 95                                                    87 
 96   return G4UIcommand::DoIt(converted_parameter     88   return G4UIcommand::DoIt(converted_parameter);
 97 }                                                  89 }
 98                                                    90 
 99 // ------------------------------------------- << 
100 G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNe     91 G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorValue(const char* paramString)
101 {                                                  92 {
102   return ConvertToDimensioned3Vector(paramStri     93   return ConvertToDimensioned3Vector(paramString);
103 }                                                  94 }
104                                                    95 
105 // ------------------------------------------- << 
106 G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNe     96 G4ThreeVector G4UIcmdWith3VectorAndUnit::GetNew3VectorRawValue(const char* paramString)
107 {                                                  97 {
108   G4double vx;                                     98   G4double vx;
109   G4double vy;                                     99   G4double vy;
110   G4double vz;                                    100   G4double vz;
111   char unts[30];                                  101   char unts[30];
112   std::istringstream is(paramString);             102   std::istringstream is(paramString);
113   is >> vx >> vy >> vz >> unts;                   103   is >> vx >> vy >> vz >> unts;
114   return G4ThreeVector(vx, vy, vz);            << 104   return G4ThreeVector(vx,vy,vz);
115 }                                                 105 }
116                                                   106 
117 // ------------------------------------------- << 
118 G4double G4UIcmdWith3VectorAndUnit::GetNewUnit    107 G4double G4UIcmdWith3VectorAndUnit::GetNewUnitValue(const char* paramString)
119 {                                                 108 {
120   G4double vx;                                    109   G4double vx;
121   G4double vy;                                    110   G4double vy;
122   G4double vz;                                    111   G4double vz;
123   char unts[30];                                  112   char unts[30];
124   std::istringstream is(paramString);             113   std::istringstream is(paramString);
125   is >> vx >> vy >> vz >> unts;                   114   is >> vx >> vy >> vz >> unts;
126   G4String unt = unts;                            115   G4String unt = unts;
127   return ValueOf(unt);                            116   return ValueOf(unt);
128 }                                                 117 }
129                                                   118 
130 // ------------------------------------------- << 119 G4String G4UIcmdWith3VectorAndUnit::ConvertToStringWithBestUnit(G4ThreeVector vec)
131 G4String G4UIcmdWith3VectorAndUnit::ConvertToS << 
132 {                                                 120 {
133   G4UIparameter* unitParam = GetParameter(3);     121   G4UIparameter* unitParam = GetParameter(3);
134   G4String canList = unitParam->GetParameterCa    122   G4String canList = unitParam->GetParameterCandidates();
135   G4Tokenizer candidateTokenizer(canList);        123   G4Tokenizer candidateTokenizer(canList);
136   G4String aToken = candidateTokenizer();         124   G4String aToken = candidateTokenizer();
137                                                   125 
138   std::ostringstream os;                          126   std::ostringstream os;
139   os << G4BestUnit(vec, CategoryOf(aToken));   << 127   os << G4BestUnit(vec,CategoryOf(aToken));
140   G4String st = os.str();                         128   G4String st = os.str();
141                                                   129 
142   return st;                                      130   return st;
143 }                                                 131 }
144                                                   132 
145 // ------------------------------------------- << 133 G4String G4UIcmdWith3VectorAndUnit::ConvertToStringWithDefaultUnit(G4ThreeVector vec)
146 G4String G4UIcmdWith3VectorAndUnit::ConvertToS << 
147 {                                                 134 {
148   G4UIparameter* unitParam = GetParameter(3);     135   G4UIparameter* unitParam = GetParameter(3);
149   G4String st;                                    136   G4String st;
150   if (unitParam->IsOmittable()) {              << 137   if(unitParam->IsOmittable())
151     st = ConvertToString(vec, unitParam->GetDe << 138   { st = ConvertToString(vec,unitParam->GetDefaultValue()); }
152   }                                            << 139   else
153   else {                                       << 140   { st = ConvertToStringWithBestUnit(vec); }
154     st = ConvertToStringWithBestUnit(vec);     << 
155   }                                            << 
156   return st;                                      141   return st;
157 }                                                 142 }
158                                                   143 
159 // ------------------------------------------- << 144 void G4UIcmdWith3VectorAndUnit::SetParameterName
160 void G4UIcmdWith3VectorAndUnit::SetParameterNa << 145 (const char * theNameX,const char * theNameY,const char * theNameZ,
161                                                << 146 G4bool omittable,G4bool currentAsDefault)
162                                                << 
163 {                                                 147 {
164   G4UIparameter* theParamX = GetParameter(0);  << 148   G4UIparameter * theParamX = GetParameter(0);
165   theParamX->SetParameterName(theNameX);          149   theParamX->SetParameterName(theNameX);
166   theParamX->SetOmittable(omittable);             150   theParamX->SetOmittable(omittable);
167   theParamX->SetCurrentAsDefault(currentAsDefa    151   theParamX->SetCurrentAsDefault(currentAsDefault);
168   G4UIparameter* theParamY = GetParameter(1);  << 152   G4UIparameter * theParamY = GetParameter(1);
169   theParamY->SetParameterName(theNameY);          153   theParamY->SetParameterName(theNameY);
170   theParamY->SetOmittable(omittable);             154   theParamY->SetOmittable(omittable);
171   theParamY->SetCurrentAsDefault(currentAsDefa    155   theParamY->SetCurrentAsDefault(currentAsDefault);
172   G4UIparameter* theParamZ = GetParameter(2);  << 156   G4UIparameter * theParamZ = GetParameter(2);
173   theParamZ->SetParameterName(theNameZ);          157   theParamZ->SetParameterName(theNameZ);
174   theParamZ->SetOmittable(omittable);             158   theParamZ->SetOmittable(omittable);
175   theParamZ->SetCurrentAsDefault(currentAsDefa    159   theParamZ->SetCurrentAsDefault(currentAsDefault);
176 }                                                 160 }
177                                                   161 
178 // ------------------------------------------- << 162 void G4UIcmdWith3VectorAndUnit::SetDefaultValue(G4ThreeVector vec)
179 void G4UIcmdWith3VectorAndUnit::SetDefaultValu << 
180 {                                                 163 {
181   G4UIparameter* theParamX = GetParameter(0);  << 164   G4UIparameter * theParamX = GetParameter(0);
182   theParamX->SetDefaultValue(vec.x());            165   theParamX->SetDefaultValue(vec.x());
183   G4UIparameter* theParamY = GetParameter(1);  << 166   G4UIparameter * theParamY = GetParameter(1);
184   theParamY->SetDefaultValue(vec.y());            167   theParamY->SetDefaultValue(vec.y());
185   G4UIparameter* theParamZ = GetParameter(2);  << 168   G4UIparameter * theParamZ = GetParameter(2);
186   theParamZ->SetDefaultValue(vec.z());            169   theParamZ->SetDefaultValue(vec.z());
187 }                                                 170 }
188                                                   171 
189 // ------------------------------------------- << 172 void G4UIcmdWith3VectorAndUnit::SetUnitCategory(const char * unitCategory)
190 void G4UIcmdWith3VectorAndUnit::SetUnitCategor << 
191 {                                                 173 {
192   SetUnitCandidates(UnitsList(unitCategory));     174   SetUnitCandidates(UnitsList(unitCategory));
193 }                                                 175 }
194                                                   176 
195 // ------------------------------------------- << 177 void G4UIcmdWith3VectorAndUnit::SetUnitCandidates(const char * candidateList)
196 void G4UIcmdWith3VectorAndUnit::SetUnitCandida << 
197 {                                                 178 {
198   G4UIparameter* untParam = GetParameter(3);   << 179   G4UIparameter * untParam = GetParameter(3);
199   G4String canList = candidateList;               180   G4String canList = candidateList;
200   untParam->SetParameterCandidates(canList);      181   untParam->SetParameterCandidates(canList);
201 }                                                 182 }
202                                                   183 
203 // ------------------------------------------- << 184 void G4UIcmdWith3VectorAndUnit::SetDefaultUnit(const char * defUnit)
204 void G4UIcmdWith3VectorAndUnit::SetDefaultUnit << 
205 {                                                 185 {
206   G4UIparameter* untParam = GetParameter(3);   << 186   G4UIparameter * untParam = GetParameter(3);
207   untParam->SetOmittable(true);                   187   untParam->SetOmittable(true);
208   untParam->SetDefaultValue(defUnit);             188   untParam->SetDefaultValue(defUnit);
209   SetUnitCategory(CategoryOf(defUnit));           189   SetUnitCategory(CategoryOf(defUnit));
210 }                                                 190 }
                                                   >> 191 
211                                                   192