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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 3.1)


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