Geant4  10.01.p03
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 //
26 // $Id: exrdmMaterialMessenger.cc 68030 2013-03-13 13:51:27Z gcosmo $
27 //
30 //
32 //
34 #include "exrdmMaterial.hh"
35 
36 #include "G4SystemOfUnits.hh"
37 
38 #include <sstream>
39 
41 //
43  :G4UImessenger(),
44  fMaterialsManager(exrdmMat),
45  fMaterialDir(0),
46  fListCmd(0),
47  fDeleteIntCmd(0),
48  fDeleteNameCmd(0),
49  fAddCmd(0)
50 {
51  fMaterialDir = new G4UIdirectory("/geometry/material/");
52  fMaterialDir->SetGuidance(" Controls for defining geometry materials" );
53 
54  fAddCmd = new G4UIcommand("/geometry/material/add",this);
56  " add a mateial by name, composition formula and density");
57  fAddCmd->SetGuidance(" name: e.g. water ");
58  fAddCmd->SetGuidance(" formula (e.g. H2-O for water");
59  fAddCmd->SetGuidance(" density (in units of g/cm3) : den>0.");
60  G4UIparameter* MatName = new G4UIparameter("material",'s',false);
61  MatName->SetGuidance("material name");
62  fAddCmd->SetParameter(MatName);
63  //
64  G4UIparameter* MatForm = new G4UIparameter("formula",'s',false);
65  MatForm->SetGuidance("material formula");
66  fAddCmd->SetParameter(MatForm);
67  //
68  G4UIparameter* DenPrm = new G4UIparameter("density",'d',false);
69  DenPrm->SetGuidance("density of the material");
70  DenPrm->SetParameterRange("density >0.");
71  fAddCmd->SetParameter(DenPrm);
73 
74  G4UIparameter* StatePrm = new G4UIparameter("state",'s',true);
75  StatePrm->SetGuidance("state of the material (optional): gas | solid");
76  fAddCmd->SetParameter(StatePrm);
78 
79  G4UIparameter* TempPrm = new G4UIparameter("temp",'d',true);
80  TempPrm->SetGuidance("temperature of the material in Kelvin (optional)");
81  fAddCmd->SetParameter(TempPrm);
83 
84  G4UIparameter* PresPrm = new G4UIparameter("pres",'d',true);
85  PresPrm->SetGuidance("pressure of the gas material in Pascal (optional)");
86  fAddCmd->SetParameter(PresPrm);
88  //
89  fDeleteIntCmd = new G4UIcmdWithAnInteger("/geometry/material/delete",this);
90  fDeleteIntCmd->SetGuidance("Delete material by its index");
91  fDeleteIntCmd->SetParameterName("matIdx",false);
92  fDeleteIntCmd->SetRange("matIdx>=0 && matIdx<100");
94 
95  fDeleteNameCmd = new G4UIcmdWithAString("/geometry/material/deleteName",this);
96  fDeleteNameCmd->SetGuidance("Delete material by its name.");
97  fDeleteNameCmd->SetParameterName("DeleteName",false);
99 
100  fListCmd = new G4UIcmdWithoutParameter("/geometry/material/list",this);
101  fListCmd->SetGuidance("List the materials defined");
103 }
105 //
107 {
108  delete fMaterialDir;
109  delete fAddCmd;
110  delete fDeleteIntCmd;
111  delete fDeleteNameCmd;
112  delete fListCmd;
113 }
115 //
117  G4String newValue)
118 {
119  if (command == fDeleteIntCmd) {
121 
122  } else if (command == fDeleteNameCmd) {
124 
125  } else if (command == fListCmd) {
127 
128  } else if (command == fAddCmd) {
129  G4double den, tem, pres ;
130  G4String state;
131  char mat[80], form[80], stat[10];
132  stat[0] = ' ';
133  tem = pres = -1.;
134  const char* t = newValue;
135  std::istringstream is(t);
136  is >>mat >>form >>den >>stat >> tem >> pres ;
137  G4String material=mat;
138  G4String formula=form;
139  if (pres == -1.) {
140  state = "";
141  } else {
142  state = stat;
143  }
144  // G4cout<< "stat = " <<state<< "tem = " << tem<< " pre = " << pres << G4endl;
145  // tick *= G4UIcommand::ValueOf(unt);
146  fMaterialsManager->AddMaterial(material,formula,den*g/cm3,state,tem,pres);
147  }
148 }
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4UIcmdWithoutParameter * fListCmd
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetParameterRange(const char *theRange)
G4UIcmdWithAnInteger * fDeleteIntCmd
Definition of the exrdmMaterialMessenger class.
exrdmMaterialMessenger(exrdmMaterial *)
void AddMaterial(G4String, G4String, G4double, G4String, G4double tem=CLHEP::STP_Temperature, G4double pres=CLHEP::STP_Pressure)
Definition of the exrdmMaterial class.
void DeleteMaterial(G4int)
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
static const double cm3
Definition: G4SIunits.hh:108
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:239
G4UIcmdWithAString * fDeleteNameCmd
static const double g
Definition: G4SIunits.hh:162
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
virtual void SetNewValue(G4UIcommand *, G4String)