[824] | 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 | // $Id: G4ParticleMessenger.cc,v 1.9 2007/03/15 06:53:27 kurasige Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
| 29 | // |
---|
| 30 | // |
---|
| 31 | //--------------------------------------------------------------- |
---|
| 32 | // |
---|
| 33 | // G4ParticleMessenger.cc |
---|
| 34 | // |
---|
| 35 | // Description: |
---|
| 36 | // This is a messenger class to interface to exchange information |
---|
| 37 | // between Particle related classes and UI. |
---|
| 38 | // |
---|
| 39 | // History: |
---|
| 40 | // 13 June 1997, H. Kurashige : The 1st version created. |
---|
| 41 | // 10 Nov. 1997 H. Kurashige : fixed bugs |
---|
| 42 | // 08 Jan. 1998 H. Kurashige : new UIcommnds |
---|
| 43 | // 08 June 1998, H. Kurashige : remove fProcessManagerMessenger |
---|
| 44 | // 25 Nov. 1998, H. Kurashige : add /particle/find |
---|
| 45 | //--------------------------------------------------------------- |
---|
| 46 | |
---|
| 47 | #include "G4ios.hh" // Include from 'system' |
---|
| 48 | #include <iomanip> // Include from 'system' |
---|
| 49 | |
---|
| 50 | #include "G4ParticleMessenger.hh" |
---|
| 51 | #include "G4UImanager.hh" |
---|
| 52 | #include "G4UIdirectory.hh" |
---|
| 53 | #include "G4UIcmdWithAString.hh" |
---|
| 54 | #include "G4UIcmdWithAnInteger.hh" |
---|
| 55 | #include "G4ParticleTable.hh" |
---|
| 56 | #include "G4ParticleDefinition.hh" |
---|
| 57 | #include "G4ParticlePropertyMessenger.hh" |
---|
| 58 | |
---|
| 59 | G4ParticleMessenger::G4ParticleMessenger(G4ParticleTable* pTable) |
---|
| 60 | { |
---|
| 61 | // get the pointer to ParticleTable |
---|
| 62 | if ( pTable == 0) { |
---|
| 63 | theParticleTable = G4ParticleTable::GetParticleTable(); |
---|
| 64 | } else { |
---|
| 65 | theParticleTable = pTable; |
---|
| 66 | } |
---|
| 67 | |
---|
| 68 | //Directory /particle/ |
---|
| 69 | thisDirectory = new G4UIdirectory("/particle/"); |
---|
| 70 | thisDirectory->SetGuidance("Particle control commands."); |
---|
| 71 | |
---|
| 72 | //Commnad /particle/select |
---|
| 73 | selectCmd = new G4UIcmdWithAString("/particle/select",this); |
---|
| 74 | selectCmd->SetGuidance("Select particle "); |
---|
| 75 | selectCmd->SetDefaultValue("none"); |
---|
| 76 | selectCmd->SetParameterName("particle name", false); |
---|
| 77 | |
---|
| 78 | //Commnad /particle/list |
---|
| 79 | listCmd = new G4UIcmdWithAString("/particle/list",this); |
---|
| 80 | listCmd->SetGuidance("List name of particles."); |
---|
| 81 | listCmd->SetGuidance(" all(default)/lepton/baryon/meson/nucleus/quarks"); |
---|
| 82 | listCmd->SetParameterName("particle type", true); |
---|
| 83 | listCmd->SetDefaultValue("all"); |
---|
| 84 | listCmd->SetCandidates("all lepton baryon meson nucleus quarks"); |
---|
| 85 | |
---|
| 86 | //Commnad /particle/find |
---|
| 87 | findCmd = new G4UIcmdWithAnInteger("/particle/find",this); |
---|
| 88 | findCmd->SetGuidance("Find particle by encoding"); |
---|
| 89 | findCmd->SetDefaultValue(0); |
---|
| 90 | findCmd->SetParameterName("encoding", false); |
---|
| 91 | |
---|
| 92 | currentParticle = 0; |
---|
| 93 | |
---|
| 94 | //UI messenger for Particle Properties |
---|
| 95 | fParticlePropertyMessenger = new G4ParticlePropertyMessenger(theParticleTable); |
---|
| 96 | |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | G4ParticleMessenger::~G4ParticleMessenger() |
---|
| 100 | { |
---|
| 101 | delete fParticlePropertyMessenger; |
---|
| 102 | delete listCmd; |
---|
| 103 | delete selectCmd; |
---|
| 104 | delete thisDirectory; |
---|
| 105 | delete findCmd; |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | |
---|
| 109 | void G4ParticleMessenger::SetNewValue(G4UIcommand * command,G4String newValues) |
---|
| 110 | { |
---|
| 111 | if( command==listCmd ){ |
---|
| 112 | //Commnad /particle/List |
---|
| 113 | G4int counter = 0; |
---|
| 114 | G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator(); |
---|
| 115 | piter -> reset(); |
---|
| 116 | |
---|
| 117 | while( (*piter)() ){ |
---|
| 118 | G4ParticleDefinition *particle = piter->value(); |
---|
| 119 | if ((newValues=="all") || (newValues==particle->GetParticleType())) { |
---|
| 120 | G4cout << std::setw(19) << particle->GetParticleName(); |
---|
| 121 | if ((counter++)%4 == 3) { |
---|
| 122 | G4cout << G4endl; |
---|
| 123 | } else { |
---|
| 124 | G4cout << ","; |
---|
| 125 | } |
---|
| 126 | } |
---|
| 127 | } |
---|
| 128 | G4cout << G4endl; |
---|
| 129 | if (counter == 0) G4cout << newValues << " is not found " << G4endl; |
---|
| 130 | |
---|
| 131 | //Command /particle/select |
---|
| 132 | // set candidate List |
---|
| 133 | G4String candidates("none"); |
---|
| 134 | piter -> reset(); |
---|
| 135 | while( (*piter)() ){ |
---|
| 136 | G4ParticleDefinition *particle = piter->value(); |
---|
| 137 | candidates += " " + particle->GetParticleName(); |
---|
| 138 | } |
---|
| 139 | selectCmd->SetCandidates((const char *)(candidates)); |
---|
| 140 | |
---|
| 141 | } else if( command==selectCmd ){ |
---|
| 142 | //Commnad /particle/select |
---|
| 143 | currentParticle = theParticleTable->FindParticle(newValues); |
---|
| 144 | if(currentParticle == 0) { |
---|
| 145 | G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl; |
---|
| 146 | } |
---|
| 147 | } else if( command==findCmd ){ |
---|
| 148 | //Commnad /particle/find |
---|
| 149 | G4ParticleDefinition* tmp = theParticleTable->FindParticle( findCmd->GetNewIntValue(newValues)); |
---|
| 150 | if(tmp == 0) { |
---|
| 151 | G4cout << "Unknown particle [" << newValues << "]. Command ignored." << G4endl; |
---|
| 152 | } else { |
---|
| 153 | G4cout << tmp->GetParticleName() << G4endl; |
---|
| 154 | tmp->DumpTable(); |
---|
| 155 | } |
---|
| 156 | } |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | G4String G4ParticleMessenger::GetCurrentValue(G4UIcommand * command) |
---|
| 160 | { |
---|
| 161 | if( command==selectCmd ){ |
---|
| 162 | //Command /particle/select |
---|
| 163 | // set candidate List |
---|
| 164 | G4String candidates("none"); |
---|
| 165 | G4ParticleTable::G4PTblDicIterator *piter = theParticleTable->GetIterator(); |
---|
| 166 | piter -> reset(); |
---|
| 167 | while( (*piter)() ){ |
---|
| 168 | G4ParticleDefinition *particle = piter->value(); |
---|
| 169 | candidates += " " + particle->GetParticleName(); |
---|
| 170 | } |
---|
| 171 | selectCmd->SetCandidates((const char *)(candidates)); |
---|
| 172 | |
---|
| 173 | static G4String noName("none"); |
---|
| 174 | // current value |
---|
| 175 | if(currentParticle == 0) { |
---|
| 176 | // no particle is selected. return null |
---|
| 177 | return noName; |
---|
| 178 | } else { |
---|
| 179 | return currentParticle->GetParticleName(); |
---|
| 180 | } |
---|
| 181 | } |
---|
| 182 | return ""; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | |
---|
| 186 | |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | |
---|