Import Geant4 8.1.0 source tree
This commit is contained in:
@@ -0,0 +1,594 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// File name: RadmonMaterialsManager.cc
|
||||
// Creation date: Sep 2005
|
||||
// Main author: Riccardo Capra <capra@ge.infn.it>
|
||||
//
|
||||
// Id: $Id: RadmonMaterialsManager.cc,v 1.4 2006/06/29 16:16:51 gunter Exp $
|
||||
// Tag: $Name: geant4-08-01 $
|
||||
//
|
||||
|
||||
// Include files
|
||||
#include "RadmonMaterialsManager.hh"
|
||||
#include "RadmonMaterialsMessenger.hh"
|
||||
#include "RadmonMaterialsDumpStyle.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
#include "G4VisAttributes.hh"
|
||||
#include "G4Color.hh"
|
||||
|
||||
#include <iomanip>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RadmonMaterialsManager * RadmonMaterialsManager :: Instance(void)
|
||||
{
|
||||
if (!instance)
|
||||
{
|
||||
instance=new RadmonMaterialsManager;
|
||||
|
||||
if (!instance)
|
||||
G4Exception("RadmonMaterialsManager::Instance: RadmonMaterialsManager singleton not allocated.");
|
||||
}
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
G4Element & RadmonMaterialsManager :: CreateElement(const G4String & elementName, const G4String & symbol, G4double zEff, G4double aEff)
|
||||
{
|
||||
G4Element * element(FindElement(elementName));
|
||||
|
||||
if (element!=0)
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::CreateElement: Element \"" << elementName << "\" just exists." << G4endl;
|
||||
return (* element);
|
||||
}
|
||||
|
||||
element=new G4Element(elementName, symbol, zEff, aEff);
|
||||
|
||||
if (element==0)
|
||||
{
|
||||
G4String text("RadmonMaterialsManager::CreateElement: Element \"");
|
||||
text+=elementName;
|
||||
text+="\" not created.";
|
||||
|
||||
G4Exception(text);
|
||||
}
|
||||
|
||||
return (* element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4Element & RadmonMaterialsManager :: GetElement(const G4String & elementName)
|
||||
{
|
||||
G4Element * element(FindElement(elementName));
|
||||
|
||||
if (element)
|
||||
return (* element);
|
||||
|
||||
G4String text("RadmonMaterialsManager::GetElement: Element \"");
|
||||
text+=elementName;
|
||||
text+="\" not found.";
|
||||
|
||||
G4Exception(text);
|
||||
return (* element);
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4bool RadmonMaterialsManager :: ExistsElement(const G4String & elementName) const
|
||||
{
|
||||
return const_cast<RadmonMaterialsManager *>(this)->FindElement(elementName)!=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: CreateMaterial(const G4String & materialName, G4double density, G4int nComponents)
|
||||
{
|
||||
if (FindMaterial(materialName)!=0 || FindIncompleteMaterial(materialName)!=0)
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::CreateMaterial: Material \"" << materialName << "\" just exists." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (nComponents==0)
|
||||
{
|
||||
G4String text("RadmonMaterialsManager::CreateMaterial: Material \"");
|
||||
text+=materialName;
|
||||
text+="\" must have at least one component.";
|
||||
|
||||
G4Exception(text);
|
||||
}
|
||||
|
||||
G4Material * material(new G4Material(materialName, density, nComponents));
|
||||
|
||||
if (material==0)
|
||||
{
|
||||
G4String text("RadmonMaterialsManager::CreateMaterial: Material \"");
|
||||
text+=materialName;
|
||||
text+="\" not created.";
|
||||
|
||||
G4Exception(text);
|
||||
}
|
||||
|
||||
incompleteMaterialsList.push_back(material);
|
||||
G4VisAttributes * visAttributes(new G4VisAttributes);
|
||||
attributesMap[materialName]=visAttributes;
|
||||
visAttributes->SetColor(1., 1., 1., 1.);
|
||||
visAttributes->SetVisibility(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: AddComponentByAtoms(const G4String & materialName, const G4String & elementName, G4int nAtoms)
|
||||
{
|
||||
G4Material * material(FindIncompleteMaterialOrAbort(materialName));
|
||||
G4Element & element(GetElement(elementName));
|
||||
|
||||
material->AddElement(&element, nAtoms);
|
||||
|
||||
UpdateIncompleteStatus(materialName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: AddComponentByFraction(const G4String & materialName, const G4String & componentName, G4double fraction)
|
||||
{
|
||||
G4Material * material(FindIncompleteMaterialOrAbort(materialName));
|
||||
|
||||
G4Material * componentMat(FindMaterial(componentName));
|
||||
if (componentMat)
|
||||
{
|
||||
material->AddMaterial(componentMat, fraction);
|
||||
UpdateIncompleteStatus(materialName);
|
||||
return;
|
||||
}
|
||||
|
||||
G4Element * componentElem(FindElement(componentName));
|
||||
if (componentElem)
|
||||
{
|
||||
material->AddElement(componentElem, fraction);
|
||||
UpdateIncompleteStatus(materialName);
|
||||
return;
|
||||
}
|
||||
|
||||
G4String text("RadmonMaterialsManager::AddComponentByFraction: Component \"");
|
||||
text+=componentName;
|
||||
text+="\" not found.";
|
||||
|
||||
G4Exception(text);
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4Material & RadmonMaterialsManager :: GetMaterial(const G4String & materialName)
|
||||
{
|
||||
G4Material *material(FindMaterial(materialName));
|
||||
|
||||
if (material)
|
||||
return (* material);
|
||||
|
||||
G4String text("RadmonMaterialsManager::GetMaterial: Material \"");
|
||||
text+=materialName;
|
||||
text+="\" not found.";
|
||||
|
||||
G4Exception(text);
|
||||
return (* material);
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4bool RadmonMaterialsManager :: ExistsMaterial(const G4String & materialName) const
|
||||
{
|
||||
return const_cast<RadmonMaterialsManager *>(this)->FindMaterial(materialName)!=0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: SetMaterialColor(const G4String & materialName, const G4Color & color)
|
||||
{
|
||||
if (attributesMap.find(materialName)==attributesMap.end())
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::SetMaterialColor: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
attributesMap[materialName]->SetColor(color);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: SetMaterialVisibility(const G4String & materialName, G4bool visibility)
|
||||
{
|
||||
if (attributesMap.find(materialName)==attributesMap.end())
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::SetMaterialVisibility: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
attributesMap[materialName]->SetVisibility(visibility);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: SetMaterialForceWireframe(const G4String & materialName, G4bool force)
|
||||
{
|
||||
if (attributesMap.find(materialName)==attributesMap.end())
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::SetMaterialForceWireframe: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
attributesMap[materialName]->SetForceWireframe(force);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: SetMaterialForceSolid(const G4String & materialName, G4bool force)
|
||||
{
|
||||
if (attributesMap.find(materialName)==attributesMap.end())
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::SetMaterialForceSolid: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
attributesMap[materialName]->SetForceSolid(force);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
const G4Color & RadmonMaterialsManager :: GetMaterialColor(const G4String & materialName) const
|
||||
{
|
||||
MaterialAttributes::const_iterator i(attributesMap.find(materialName));
|
||||
|
||||
if (i==attributesMap.end())
|
||||
{
|
||||
static G4Color white(1., 1., 1., 1.);
|
||||
G4cout << "RadmonMaterialsManager::GetMaterialColor: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
|
||||
return white;
|
||||
}
|
||||
|
||||
return i->second->GetColor();
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4bool RadmonMaterialsManager :: GetMaterialVisibility(const G4String & materialName) const
|
||||
{
|
||||
MaterialAttributes::const_iterator i(attributesMap.find(materialName));
|
||||
|
||||
if (i==attributesMap.end())
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::GetMaterialVisibility: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
return i->second->IsVisible();
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4bool RadmonMaterialsManager :: GetMaterialForceWireframe(const G4String & materialName) const
|
||||
{
|
||||
MaterialAttributes::const_iterator i(attributesMap.find(materialName));
|
||||
|
||||
if (i==attributesMap.end())
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::GetMaterialForceWireframe: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!i->second->IsForceDrawingStyle())
|
||||
return false;
|
||||
|
||||
return i->second->GetForcedDrawingStyle()==G4VisAttributes::wireframe;
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4bool RadmonMaterialsManager :: GetMaterialForceSolid(const G4String & materialName) const
|
||||
{
|
||||
MaterialAttributes::const_iterator i(attributesMap.find(materialName));
|
||||
|
||||
if (i==attributesMap.end())
|
||||
{
|
||||
G4cout << "RadmonMaterialsManager::GetMaterialForceSolid: Material \"" << materialName << "\" does not exist." << G4endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!i->second->IsForceDrawingStyle())
|
||||
return false;
|
||||
|
||||
return i->second->GetForcedDrawingStyle()==G4VisAttributes::solid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: Dump(std::ostream & out, const G4String &indent) const
|
||||
{
|
||||
G4int width(RADMONMATERIALDUMP_INDENT_WIDTH-indent.length());
|
||||
if (width<0)
|
||||
width=0;
|
||||
|
||||
G4String indent2(indent);
|
||||
indent2.prepend(" ");
|
||||
G4int width2(width-2);
|
||||
if (width2<0)
|
||||
width2=0;
|
||||
|
||||
G4String indent3(indent2);
|
||||
indent3.prepend(" ");
|
||||
G4int width3(width2-2);
|
||||
if (width3<0)
|
||||
width3=0;
|
||||
|
||||
out << indent << "Elements:\n";
|
||||
|
||||
G4int n(GetNElements());
|
||||
|
||||
if (n==0)
|
||||
out << indent2 << "No elements defined.\n\n";
|
||||
else
|
||||
{
|
||||
const G4Element * element;
|
||||
|
||||
for (G4int i(0); i<n; i++)
|
||||
{
|
||||
element=&GetElement(i);
|
||||
out << indent2 << "Element # " << i << '\n'
|
||||
<< indent3 << std::setw(width3); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Name"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = \"" << element->GetName() << "\"\n"
|
||||
<< indent3 << std::setw(width3); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Zeff"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = " << std::setprecision(RADMONMATERIALDUMP_DOUBLE_PRECISION) << std::setw(RADMONMATERIALDUMP_DOUBLE_WIDTH) << element->GetZ() << '\n'
|
||||
<< indent3 << std::setw(width3); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Aeff"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = " << std::setprecision(RADMONMATERIALDUMP_DOUBLE_PRECISION) << std::setw(RADMONMATERIALDUMP_DOUBLE_WIDTH) << G4BestUnit(element->GetA(), "Molar Mass") << "\n\n";
|
||||
}
|
||||
}
|
||||
|
||||
out << indent << "Materials:\n";
|
||||
|
||||
n=GetNMaterials();
|
||||
|
||||
if (n==0)
|
||||
out << indent2 << "No materials defined.\n";
|
||||
else
|
||||
{
|
||||
const G4Material * material;
|
||||
G4int m;
|
||||
|
||||
G4String indent4(indent3);
|
||||
indent4.prepend(" ");
|
||||
G4int width4(width3-2);
|
||||
if (width4<0)
|
||||
width4=0;
|
||||
|
||||
const G4double * massFractions;
|
||||
const G4double * nAtoms;
|
||||
|
||||
for (G4int i(0); i<n; i++)
|
||||
{
|
||||
if (i>0)
|
||||
out << '\n';
|
||||
|
||||
material=&GetMaterial(i);
|
||||
out << indent2 << "Material # " << i << '\n'
|
||||
<< indent3 << std::setw(width3); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Name"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = \"" << material->GetName() << "\"\n"
|
||||
<< indent3 << std::setw(width3); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Density"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = " << std::setprecision(RADMONMATERIALDUMP_DOUBLE_PRECISION) << std::setw(RADMONMATERIALDUMP_DOUBLE_WIDTH) << G4BestUnit(material->GetDensity(), "Volumic Mass") << '\n';
|
||||
|
||||
m=material->GetNumberOfElements();
|
||||
massFractions=material->GetFractionVector();
|
||||
nAtoms=material->GetVecNbOfAtomsPerVolume();
|
||||
|
||||
for (G4int j(0); j<m; j++)
|
||||
{
|
||||
out << indent4 << std::setw(width4); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Element"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = \"" << material->GetElement(j)->GetName() << "\"\n"
|
||||
<< std::setw(indent4.length()) << "" << std::setw(width4); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Mass fraction"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = " << std::setprecision(RADMONMATERIALDUMP_PERCENT_PRECISION) << std::setw(RADMONMATERIALDUMP_PERCENT_WIDTH) << (massFractions[j]/perCent) << " %\n"
|
||||
<< std::setw(indent4.length()) << "" << std::setw(width4); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Abundance"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = " << std::setprecision(RADMONMATERIALDUMP_PERCENT_PRECISION) << std::setw(RADMONMATERIALDUMP_PERCENT_WIDTH) << (nAtoms[j]/(perCent*material->GetTotNbOfAtomsPerVolume())) << " %\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!incompleteMaterialsList.empty())
|
||||
{
|
||||
out << '\n' << indent << "Materials to be completed:\n";
|
||||
|
||||
MaterialsList::const_iterator i(incompleteMaterialsList.begin());
|
||||
MaterialsList::const_iterator end(incompleteMaterialsList.end());
|
||||
|
||||
while (i!=end)
|
||||
{
|
||||
out << indent2 << std::setw(width2); out.setf(std::ostream::left, std::ostream::adjustfield); out << "Name"; out.setf(std::ostream::right, std::ostream::adjustfield); out << " = \"" << (*i)->GetName() << "\"\n";
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
G4bool RadmonMaterialsManager :: Insert(std::istream & /* in */)
|
||||
{
|
||||
// TO BE DONE
|
||||
G4cout << "RadmonMaterialsManager::Insert(): PLEASE CHECK" << G4endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4bool RadmonMaterialsManager :: Save(std::ostream & /* out */) const
|
||||
{
|
||||
// TO BE DONE
|
||||
G4cout << "RadmonMaterialsManager::Save(): PLEASE CHECK" << G4endl;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline G4Element * RadmonMaterialsManager :: FindElement(const G4String & elementName)
|
||||
{
|
||||
G4int n(GetNElements());
|
||||
G4Element * element;
|
||||
|
||||
while (n>0)
|
||||
{
|
||||
n--;
|
||||
element=&GetElement(n);
|
||||
|
||||
if (element->GetName()==elementName)
|
||||
return element;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline G4Material * RadmonMaterialsManager :: FindMaterial(const G4String & materialName)
|
||||
{
|
||||
G4int n(GetNMaterials());
|
||||
G4Material * material;
|
||||
|
||||
while (n>0)
|
||||
{
|
||||
n--;
|
||||
material=&GetMaterial(n);
|
||||
|
||||
if (material->GetName()==materialName)
|
||||
return material;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4Material * RadmonMaterialsManager :: FindIncompleteMaterial(const G4String & materialName)
|
||||
{
|
||||
MaterialsList::iterator i(incompleteMaterialsList.begin());
|
||||
MaterialsList::iterator end(incompleteMaterialsList.end());
|
||||
|
||||
while (i!=end)
|
||||
{
|
||||
if ((*i)->GetName()==materialName)
|
||||
return (*i);
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
G4Material * RadmonMaterialsManager :: FindIncompleteMaterialOrAbort(const G4String & materialName)
|
||||
{
|
||||
G4Material * material(FindIncompleteMaterial(materialName));
|
||||
|
||||
if (material)
|
||||
return material;
|
||||
|
||||
if (&GetMaterial(materialName))
|
||||
{
|
||||
G4String text("RadmonMaterialsManager::FindIncompleteMaterialOrAbort: Material \"");
|
||||
text+=materialName;
|
||||
text+="\" does not need further components.";
|
||||
|
||||
G4Exception(text);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsManager :: UpdateIncompleteStatus(const G4String & materialName)
|
||||
{
|
||||
if (!FindMaterial(materialName))
|
||||
return;
|
||||
|
||||
MaterialsList::iterator i(incompleteMaterialsList.begin());
|
||||
MaterialsList::iterator end(incompleteMaterialsList.end());
|
||||
|
||||
while (i!=end)
|
||||
{
|
||||
if ((*i)->GetName()==materialName)
|
||||
{
|
||||
incompleteMaterialsList.erase(i);
|
||||
return;
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline RadmonMaterialsManager :: RadmonMaterialsManager()
|
||||
:
|
||||
messenger(new RadmonMaterialsMessenger(this))
|
||||
{
|
||||
new G4UnitDefinition("g/mole", "g/mole", "Molar Mass", g/mole);
|
||||
new G4UnitDefinition("mg/mole", "mg/mole", "Molar Mass", mg/mole);
|
||||
new G4UnitDefinition("kg/mole", "kg/mole", "Molar Mass", kg/mole);
|
||||
|
||||
new G4Material("RADMON_VACUUM", 1., 1.01*g/mole, universe_mean_density, kStateGas, 0.1*kelvin, 1.e-19*pascal);
|
||||
}
|
||||
|
||||
|
||||
|
||||
RadmonMaterialsManager :: ~RadmonMaterialsManager()
|
||||
{
|
||||
if (messenger)
|
||||
delete messenger;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
RadmonMaterialsManager * RadmonMaterialsManager :: instance(0);
|
||||
@@ -0,0 +1,413 @@
|
||||
//
|
||||
// ********************************************************************
|
||||
// * License and Disclaimer *
|
||||
// * *
|
||||
// * The Geant4 software is copyright of the Copyright Holders of *
|
||||
// * the Geant4 Collaboration. It is provided under the terms and *
|
||||
// * conditions of the Geant4 Software License, included in the file *
|
||||
// * LICENSE and available at http://cern.ch/geant4/license . These *
|
||||
// * include a list of copyright holders. *
|
||||
// * *
|
||||
// * Neither the authors of this software system, nor their employing *
|
||||
// * institutes,nor the agencies providing financial support for this *
|
||||
// * work make any representation or warranty, express or implied, *
|
||||
// * regarding this software system or assume any liability for its *
|
||||
// * use. Please see the license in the file LICENSE and URL above *
|
||||
// * for the full disclaimer and the limitation of liability. *
|
||||
// * *
|
||||
// * This code implementation is the result of the scientific and *
|
||||
// * technical work of the GEANT4 collaboration. *
|
||||
// * By using, copying, modifying or distributing the software (or *
|
||||
// * any work based on the software) you agree to acknowledge its *
|
||||
// * use in resulting scientific publications, and indicate your *
|
||||
// * acceptance of all terms of the Geant4 Software license. *
|
||||
// ********************************************************************
|
||||
//
|
||||
//
|
||||
// File name: RadmonMaterialsMessenger.cc
|
||||
// Creation date: Sep 2005
|
||||
// Main author: Riccardo Capra <capra@ge.infn.it>
|
||||
//
|
||||
// Id: $Id: RadmonMaterialsMessenger.cc,v 1.4 2006/06/29 16:16:53 gunter Exp $
|
||||
// Tag: $Name: geant4-08-01 $
|
||||
//
|
||||
|
||||
// Messenger commands path
|
||||
#define COMMANDS_PATH "/radmon/materials/"
|
||||
|
||||
// Include files
|
||||
#include "RadmonMaterialsMessenger.hh"
|
||||
#include "RadmonMaterialsManager.hh"
|
||||
#include "G4UnitsTable.hh"
|
||||
|
||||
|
||||
|
||||
RadmonMaterialsMessenger :: RadmonMaterialsMessenger(RadmonMaterialsManager * manager)
|
||||
:
|
||||
RadmonMessenger(COMMANDS_PATH, "Interactive materials definition commands."),
|
||||
materialsManager(manager),
|
||||
RADMON_INITIALIZE_COMMAND(CreateElement),
|
||||
RADMON_INITIALIZE_COMMAND(CreateMaterial),
|
||||
RADMON_INITIALIZE_COMMAND(AddComponentByAtoms),
|
||||
RADMON_INITIALIZE_COMMAND(AddComponentByFraction),
|
||||
RADMON_INITIALIZE_COMMAND(SetMaterialColor),
|
||||
RADMON_INITIALIZE_COMMAND(SetMaterialTrasparency),
|
||||
RADMON_INITIALIZE_COMMAND(SetMaterialVisibility),
|
||||
RADMON_INITIALIZE_COMMAND(SetMaterialStyle),
|
||||
RADMON_INITIALIZE_COMMAND(Dump),
|
||||
RADMON_INITIALIZE_COMMAND(Insert),
|
||||
RADMON_INITIALIZE_COMMAND(Save)
|
||||
{
|
||||
RADMON_CREATE_COMMAND_5ARGS(CreateElement, "Creates a new element", "material", "symbol", "Z", "A", "unit");
|
||||
RADMON_CREATE_COMMAND_4ARGS(CreateMaterial, "Creates a new material", "material", "density", "unit", "totComponents");
|
||||
RADMON_CREATE_COMMAND_3ARGS(AddComponentByAtoms, "Adds a element into a material specifying the number of atoms", "material", "element", "atoms");
|
||||
RADMON_CREATE_COMMAND_3ARGS(AddComponentByFraction, "Adds a element or material into another material specifying the percentage", "material", "component", "fraction");
|
||||
RADMON_CREATE_COMMAND_4ARGS(SetMaterialColor, "Set default color for all elements made of this material", "material", "red", "green", "blue");
|
||||
RADMON_CREATE_COMMAND_2ARGS(SetMaterialTrasparency, "Set default trasparency for all elements made of this material", "material", "alpha");
|
||||
RADMON_CREATE_COMMAND_2ARGS(SetMaterialVisibility, "Set default visibility for all elements made of this material", "material", "visibility");
|
||||
RADMON_CREATE_COMMAND_2ARGS(SetMaterialStyle, "Set default style for all elements made of this material", "material", "style");
|
||||
RADMON_CREATE_COMMAND_0ARGS(Dump, "Print currently declared elements and materials");
|
||||
RADMON_CREATE_COMMAND_1ARG (Insert, "Inserts elements and materials from file", "fileName");
|
||||
RADMON_CREATE_COMMAND_1ARG (Save, "Saves a elements and materials declarations into a file", "fileName");
|
||||
}
|
||||
|
||||
|
||||
|
||||
RadmonMaterialsMessenger :: ~RadmonMaterialsMessenger()
|
||||
{
|
||||
RADMON_DESTROY_COMMAND(Save);
|
||||
RADMON_DESTROY_COMMAND(Insert);
|
||||
RADMON_DESTROY_COMMAND(Dump);
|
||||
RADMON_DESTROY_COMMAND(SetMaterialStyle);
|
||||
RADMON_DESTROY_COMMAND(SetMaterialVisibility);
|
||||
RADMON_DESTROY_COMMAND(SetMaterialTrasparency);
|
||||
RADMON_DESTROY_COMMAND(SetMaterialColor);
|
||||
RADMON_DESTROY_COMMAND(AddComponentByFraction);
|
||||
RADMON_DESTROY_COMMAND(AddComponentByAtoms);
|
||||
RADMON_DESTROY_COMMAND(CreateMaterial);
|
||||
RADMON_DESTROY_COMMAND(CreateElement);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
G4String RadmonMaterialsMessenger :: GetCurrentValue(G4UIcommand * /* command */)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::GetCurrentValue(): Not supported" << G4endl;
|
||||
|
||||
return G4String();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: SetNewValue(G4UIcommand * command, G4String newValue)
|
||||
{
|
||||
RADMON_BEGIN_LIST_SET_COMMANDS
|
||||
RADMON_SET_COMMAND(CreateElement)
|
||||
RADMON_SET_COMMAND(CreateMaterial)
|
||||
RADMON_SET_COMMAND(AddComponentByAtoms)
|
||||
RADMON_SET_COMMAND(AddComponentByFraction)
|
||||
RADMON_SET_COMMAND(SetMaterialColor)
|
||||
RADMON_SET_COMMAND(SetMaterialTrasparency)
|
||||
RADMON_SET_COMMAND(SetMaterialVisibility)
|
||||
RADMON_SET_COMMAND(SetMaterialStyle)
|
||||
RADMON_SET_COMMAND(Dump)
|
||||
RADMON_SET_COMMAND(Insert)
|
||||
RADMON_SET_COMMAND(Save)
|
||||
RADMON_END_LIST_SET_COMMANDS
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// Events
|
||||
void RadmonMaterialsMessenger :: OnCreateElement(const G4String & value)
|
||||
{
|
||||
G4String args[5];
|
||||
|
||||
if (!ProcessArguments(value, 5, args))
|
||||
return;
|
||||
|
||||
G4double z(G4UIcommand::ConvertToDouble(args[2]));
|
||||
|
||||
if (z<=0.)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnCreateElement(): z must be positive." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
G4double a(GetUnit(args[4], "Molar Mass"));
|
||||
|
||||
if (a<0.)
|
||||
return;
|
||||
|
||||
a*=G4UIcommand::ConvertToDouble(args[3]);
|
||||
|
||||
if (a<=0.)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnCreateElement(): a must be positive." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
materialsManager->CreateElement(args[0], args[1], z, a);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnCreateMaterial(const G4String & value)
|
||||
{
|
||||
G4String args[4];
|
||||
|
||||
if (!ProcessArguments(value, 4, args))
|
||||
return;
|
||||
|
||||
G4double density(GetUnit(args[2], "Volumic Mass"));
|
||||
|
||||
if (density<0.)
|
||||
return;
|
||||
|
||||
density*=G4UIcommand::ConvertToDouble(args[1]);
|
||||
|
||||
if (density<=0.)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnCreateMaterial(): Material density must be positive." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
G4int components(G4UIcommand::ConvertToInt(args[3]));
|
||||
|
||||
if (components<0)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnCreateMaterial(): Number of components must be positive (>=0)." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
materialsManager->CreateMaterial(args[0], density, components);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnAddComponentByAtoms(const G4String & value)
|
||||
{
|
||||
G4String args[3];
|
||||
|
||||
if (!ProcessArguments(value, 3, args))
|
||||
return;
|
||||
|
||||
if (!materialsManager->IsIncompleteMaterial(args[0]))
|
||||
{
|
||||
if (!materialsManager->ExistsMaterial(args[0]))
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByAtoms(): Material \"" << args[0] << "\" not found." << G4endl;
|
||||
else
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByAtoms(): No more components to be added to \"" << args[0] << "\"." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!materialsManager->ExistsElement(args[1]))
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByAtoms(): Element \"" << args[1] << "\" not found." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
G4int atoms(G4UIcommand::ConvertToInt(args[2]));
|
||||
|
||||
if (atoms<=0)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByAtoms(): Number of atoms must be positive (>0)." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
materialsManager->AddComponentByAtoms(args[0], args[1], atoms);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnAddComponentByFraction(const G4String & value)
|
||||
{
|
||||
G4String args[3];
|
||||
|
||||
if (!ProcessArguments(value, 3, args))
|
||||
return;
|
||||
|
||||
if (!materialsManager->IsIncompleteMaterial(args[0]))
|
||||
{
|
||||
if (!materialsManager->ExistsMaterial(args[0]))
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByFraction(): Material \"" << args[0] << "\" not found." << G4endl;
|
||||
else
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByFraction(): No more components to be added to \"" << args[0] << "\"." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if ((!materialsManager->ExistsElement(args[1])) && (!materialsManager->ExistsMaterial(args[1])))
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByFraction(): Element/Material \"" << args[1] << "\" not found." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
G4double fraction(G4UIcommand::ConvertToDouble(args[2]));
|
||||
|
||||
if (fraction<=0)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnAddComponentByFraction(): Material fraction must be positive (>0)." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
materialsManager->AddComponentByFraction(args[0], args[1], fraction);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnSetMaterialColor(const G4String & value)
|
||||
{
|
||||
G4String args[4];
|
||||
|
||||
if (!ProcessArguments(value, 4, args))
|
||||
return;
|
||||
|
||||
if (!materialsManager->ExistsMaterial(args[0]) && !materialsManager->IsIncompleteMaterial(args[0]))
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialColor(): Material \"" << args[0] << "\" not found." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
G4double red(G4UIcommand::ConvertToDouble(args[1]));
|
||||
G4double green(G4UIcommand::ConvertToDouble(args[2]));
|
||||
G4double blue(G4UIcommand::ConvertToDouble(args[3]));
|
||||
|
||||
if (red<0. || red>1. || green<0. || green>1. || blue<0. || blue>1.)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialColor(): Red, green and blue components must be set between 0 and 1." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
materialsManager->SetMaterialColor(args[0], G4Color(red, green, blue, materialsManager->GetMaterialColor(args[0]).GetAlpha()));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnSetMaterialTrasparency(const G4String & value)
|
||||
{
|
||||
G4String args[2];
|
||||
|
||||
if (!ProcessArguments(value, 2, args))
|
||||
return;
|
||||
|
||||
if (!materialsManager->ExistsMaterial(args[0]) && !materialsManager->IsIncompleteMaterial(args[0]))
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialTrasparency(): Material \"" << args[0] << "\" not found." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
G4double alpha(G4UIcommand::ConvertToDouble(args[1]));
|
||||
|
||||
if (alpha<0. || alpha>1.)
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialTrasparency(): Alpha component must be set between 0 and 1." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
const G4Color &c(materialsManager->GetMaterialColor(args[0]));
|
||||
materialsManager->SetMaterialColor(args[0], G4Color(c.GetRed(), c.GetGreen(), c.GetBlue(), alpha));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnSetMaterialVisibility(const G4String & value)
|
||||
{
|
||||
G4String args[2];
|
||||
|
||||
if (!ProcessArguments(value, 2, args))
|
||||
return;
|
||||
|
||||
if (!materialsManager->ExistsMaterial(args[0]) && !materialsManager->IsIncompleteMaterial(args[0]))
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialVisibility(): Material \"" << args[0] << "\" not found." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[1]=="hidden")
|
||||
materialsManager->SetMaterialVisibility(args[0], false);
|
||||
else if (args[1]=="visible")
|
||||
materialsManager->SetMaterialVisibility(args[0], true);
|
||||
else
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialVisibility(): Visibility must be set to visible or hidden." << G4endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnSetMaterialStyle(const G4String & value)
|
||||
{
|
||||
G4String args[2];
|
||||
|
||||
if (!ProcessArguments(value, 2, args))
|
||||
return;
|
||||
|
||||
if (!materialsManager->ExistsMaterial(args[0]) && !materialsManager->IsIncompleteMaterial(args[0]))
|
||||
{
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialStyle(): Material \"" << args[0] << "\" not found." << G4endl;
|
||||
return;
|
||||
}
|
||||
|
||||
if (args[1]=="wireframe")
|
||||
materialsManager->SetMaterialForceWireframe(args[0], true);
|
||||
else if (args[1]=="solid")
|
||||
materialsManager->SetMaterialForceSolid(args[0], true);
|
||||
else if (args[1]=="default")
|
||||
{
|
||||
materialsManager->SetMaterialForceWireframe(args[0], false);
|
||||
materialsManager->SetMaterialForceSolid(args[0], false);
|
||||
}
|
||||
else
|
||||
G4cout << "RadmonMaterialsMessenger::OnSetMaterialStyle(): Style must be set to wireframe, solid or default." << G4endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnDump(const G4String & /* value */)
|
||||
{
|
||||
materialsManager->Dump(G4cout, "- ");
|
||||
G4cout << G4endl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnInsert(const G4String & value)
|
||||
{
|
||||
G4String args[1];
|
||||
|
||||
if (!ProcessArguments(value, 1, args))
|
||||
return;
|
||||
|
||||
std::istream * in(OpenForInput(args[0]));
|
||||
|
||||
if (!in)
|
||||
return;
|
||||
|
||||
if (!materialsManager->Insert(*in))
|
||||
G4cout << "RadmonMaterialsMessenger::OnInsert(): Error reading from file \"" << args[0] << "\"." << G4endl;
|
||||
|
||||
delete in;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RadmonMaterialsMessenger :: OnSave(const G4String & value)
|
||||
{
|
||||
G4String args[1];
|
||||
|
||||
if (!ProcessArguments(value, 1, args))
|
||||
return;
|
||||
|
||||
std::ostream * out(OpenForOutput(args[0]));
|
||||
|
||||
if (!out)
|
||||
return;
|
||||
|
||||
if (!materialsManager->Save(*out))
|
||||
G4cout << "RadmonMaterialsMessenger::OnSave(): Cannot write layout into file \"" << args[0] << "\"." << G4endl;
|
||||
|
||||
delete out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user