Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exrdmMaterialMessenger.cc
Go to the documentation of this file.
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 //
28 //
30 //
32 #include "exrdmMaterial.hh"
33 
34 #include "G4SystemOfUnits.hh"
35 
36 #include <sstream>
37 
39 //
41  :fMaterialsManager(exrdmMat)
42 {
43  fMaterialDir = new G4UIdirectory("/geometry/material/");
44  fMaterialDir->SetGuidance(" Controls for defining geometry materials" );
45 
46  fAddCmd = new G4UIcommand("/geometry/material/add",this);
47  fAddCmd->SetGuidance(
48  " add a mateial by name, composition formula and density");
49  fAddCmd->SetGuidance(" name: e.g. water ");
50  fAddCmd->SetGuidance(" formula (e.g. H2-O for water");
51  fAddCmd->SetGuidance(" density (in units of g/cm3) : den>0.");
52  G4UIparameter* MatName = new G4UIparameter("material",'s',false);
53  MatName->SetGuidance("material name");
54  fAddCmd->SetParameter(MatName);
55  //
56  G4UIparameter* MatForm = new G4UIparameter("formula",'s',false);
57  MatForm->SetGuidance("material formula");
58  fAddCmd->SetParameter(MatForm);
59  //
60  G4UIparameter* DenPrm = new G4UIparameter("density",'d',false);
61  DenPrm->SetGuidance("density of the material");
62  DenPrm->SetParameterRange("density >0.");
63  fAddCmd->SetParameter(DenPrm);
65 
66  G4UIparameter* StatePrm = new G4UIparameter("state",'s',true);
67  StatePrm->SetGuidance("state of the material (optional): gas | solid");
68  fAddCmd->SetParameter(StatePrm);
70 
71  G4UIparameter* TempPrm = new G4UIparameter("temp",'d',true);
72  TempPrm->SetGuidance("temperature of the material in Kelvin (optional)");
73  fAddCmd->SetParameter(TempPrm);
75 
76  G4UIparameter* PresPrm = new G4UIparameter("pres",'d',true);
77  PresPrm->SetGuidance("pressure of the gas material in Pascal (optional)");
78  fAddCmd->SetParameter(PresPrm);
80  //
81  fDeleteIntCmd = new G4UIcmdWithAnInteger("/geometry/material/delete",this);
82  fDeleteIntCmd->SetGuidance("Delete material by its index");
83  fDeleteIntCmd->SetParameterName("matIdx",false);
84  fDeleteIntCmd->SetRange("matIdx>=0 && matIdx<100");
86 
87  fDeleteNameCmd = new G4UIcmdWithAString("/geometry/material/deleteName",this);
88  fDeleteNameCmd->SetGuidance("Delete material by its name.");
89  fDeleteNameCmd->SetParameterName("DeleteName",false);
91 
92  fListCmd = new G4UIcmdWithoutParameter("/geometry/material/list",this);
93  fListCmd->SetGuidance("List the materials defined");
95 }
97 //
99 {
100  delete fMaterialDir;
101  delete fAddCmd;
102  delete fDeleteIntCmd;
103  delete fDeleteNameCmd;
104  delete fListCmd;
105 }
107 //
109  G4String newValue)
110 {
111  if (command == fDeleteIntCmd) {
112  fMaterialsManager->DeleteMaterial(fDeleteIntCmd->GetNewIntValue(newValue));
113 
114  } else if (command == fDeleteNameCmd) {
115  fMaterialsManager->DeleteMaterial(newValue);
116 
117  } else if (command == fListCmd) {
118  fMaterialsManager->ListMaterial();
119 
120  } else if (command == fAddCmd) {
121  G4double den, tem, pres ;
122  G4String state;
123  char mat[80], form[80], stat[10];
124  stat[0] = ' ';
125  tem = pres = -1.;
126  const char* t = newValue;
127  std::istringstream is(t);
128  is >>mat >>form >>den >>stat >> tem >> pres ;
130  G4String formula=form;
131  if (pres == -1.) {
132  state = "";
133  } else {
134  state = stat;
135  }
136  // G4cout<< "stat = " <<state<< "tem = " << tem<< " pre = " << pres << G4endl;
137  // tick *= G4UIcommand::ValueOf(unt);
138  fMaterialsManager->AddMaterial(material,formula,den*g/cm3,state,tem,pres);
139  }
140 }