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