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