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