Geant4 Cross Reference |
1 // 2 // ******************************************************************** 3 // * License and Disclaimer * 4 // * * 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. * 10 // * * 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitation of liability. * 17 // * * 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************************************** 25 // 26 /* 27 * MoleculeGunMessenger.cc 28 * 29 * Created on: 30 janv. 2014 30 * Author: kara 31 */ 32 33 #include "G4MoleculeGunMessenger.hh" 34 35 #include "G4MoleculeGun.hh" 36 #include "G4Tokenizer.hh" 37 #include "G4UIcmdWith3VectorAndUnit.hh" 38 #include "G4UIcmdWithADoubleAndUnit.hh" 39 #include "G4UIcmdWithAString.hh" 40 #include "G4UIcmdWithAnInteger.hh" 41 #include "G4UIdirectory.hh" 42 43 //------------------------------------------------------------------------------ 44 45 G4MoleculeGunMessenger::G4MoleculeGunMessenger(G4MoleculeGun* gun) : 46 G4UImessenger("/chem/gun/", "") 47 { 48 fpGunNewGunType = new G4UIcmdWithAString("/chem/gun/newShoot", 49 this); 50 fpMoleculeGun = gun; 51 } 52 53 //------------------------------------------------------------------------------ 54 55 G4MoleculeGunMessenger::~G4MoleculeGunMessenger() 56 { 57 delete fpGunNewGunType; 58 } 59 60 //------------------------------------------------------------------------------ 61 62 G4String G4MoleculeGunMessenger::GetCurrentValue(G4UIcommand* /*command*/) 63 { 64 return ""; 65 } 66 67 //------------------------------------------------------------------------------ 68 69 void G4MoleculeGunMessenger::SetNewValue(G4UIcommand* command, 70 G4String newValue) 71 { 72 if (command == fpGunNewGunType) 73 { 74 std::istringstream iss (newValue); 75 76 G4String shootName; 77 iss >> shootName; 78 79 G4String shootType; 80 iss >> shootType; 81 82 if(shootType.empty() || shootType.empty()) 83 { 84 CreateNewType<G4Track>(shootName); 85 } 86 else 87 { 88 CreateNewType<G4ContinuousMedium>(shootName); 89 } 90 } 91 } 92 93 //------------------------------------------------------------------------------ 94 95 G4MoleculeShootMessenger::G4MoleculeShootMessenger(const G4String& name, 96 G4MoleculeGunMessenger*, 97 G4shared_ptr<G4MoleculeShoot> shoot) 98 : fpShoot(std::move(shoot)) 99 { 100 G4String dir("/chem/gun/"); 101 dir += name; 102 CreateDirectory(dir, ""); 103 104 G4String tmp = dir; 105 tmp += "/species"; 106 fpGunSpecies = new G4UIcmdWithAString(tmp, this); 107 108 tmp = dir; 109 tmp += "/position"; 110 fpGunPosition = new G4UIcmdWith3VectorAndUnit(tmp, this); 111 112 tmp = dir; 113 tmp += "/time"; 114 fpGunTime = new G4UIcmdWithADoubleAndUnit(tmp, this); 115 116 tmp = dir; 117 tmp += "/number"; 118 fpGunN = new G4UIcmdWithAnInteger(tmp, this); 119 120 tmp = dir; 121 tmp += "/rndmPosition"; 122 fpGunRdnmPosition = new G4UIcmdWith3VectorAndUnit(tmp, this); 123 124 tmp = std::move(dir); 125 tmp += "/type"; 126 fpGunType = new G4UIcmdWithAString(tmp, this); 127 128 // fpShoot.reset(new TG4MoleculeShoot<G4Track>()); 129 } 130 131 //------------------------------------------------------------------------------ 132 133 G4MoleculeShootMessenger::~G4MoleculeShootMessenger() 134 { 135 delete fpGunSpecies; 136 delete fpGunPosition; 137 delete fpGunTime; 138 delete fpGunN; 139 } 140 141 //------------------------------------------------------------------------------ 142 143 void G4MoleculeShootMessenger::SetNewValue(G4UIcommand* command, G4String newValue) 144 { 145 if (command == fpGunSpecies) 146 { 147 fpShoot->fMoleculeName = newValue; 148 } 149 else if (command == fpGunPosition) 150 { 151 fpShoot->fPosition = fpGunPosition->GetNew3VectorValue(newValue); 152 } 153 else if(command == fpGunRdnmPosition) 154 { 155 fpShoot->fBoxSize = new G4ThreeVector(fpGunRdnmPosition->GetNew3VectorValue(newValue)); 156 } 157 else if (command == fpGunTime) 158 { 159 fpShoot->fTime = fpGunTime->GetNewDoubleValue(newValue); 160 } 161 else if (command == fpGunN) 162 { 163 fpShoot->fNumber = fpGunN->GetNewIntValue(newValue); 164 } 165 else if (command == fpGunType) 166 { 167 if(newValue == "CM") 168 { 169 // G4cout << "**** Change type" << G4endl; 170 // TG4MoleculeShoot<G4ContinuousMedium>* casted = static_cast<TG4MoleculeShoot<G4ContinuousMedium>*>(fpShoot.get()); 171 // fpShoot.reset(casted); 172 fpShoot = fpShoot.get()->ChangeType<G4ContinuousMedium>(); 173 } 174 } 175 } 176 177 //------------------------------------------------------------------------------ 178 179 G4String G4MoleculeShootMessenger::GetCurrentValue(G4UIcommand* command) 180 { 181 if (command == fpGunSpecies) 182 { 183 return fpShoot->fMoleculeName; 184 } 185 if (command == fpGunPosition) 186 { 187 return fpGunPosition->ConvertToStringWithBestUnit(fpShoot->fPosition); 188 } 189 if (command == fpGunRdnmPosition) 190 { 191 if(fpShoot->fBoxSize != nullptr) 192 { 193 return fpGunRdnmPosition->ConvertToStringWithBestUnit(*fpShoot->fBoxSize); 194 } 195 return fpGunRdnmPosition->ConvertToStringWithBestUnit(G4ThreeVector()); 196 } 197 if (command == fpGunTime) 198 { 199 return fpGunTime->ConvertToStringWithBestUnit(fpShoot->fTime); 200 } 201 if (command == fpGunN) 202 { 203 return fpGunN->ConvertToString(fpShoot->fNumber); 204 } 205 return ""; 206 } 207 208 //------------------------------------------------------------------------------ 209 210