20 #include <G4UIcmdWithoutParameter.hh>
21 #include <G4UIcmdWithAString.hh>
29 struct InstallProperties {
31 const std::string& path;
34 : cmds(c), path(p), msg(m) {
36 void operator()(
const std::pair<std::string, dd4hep::Property>& o) {
37 std::string n = path + o.first;
38 G4UIcmdWithAString* cmd =
new G4UIcmdWithAString(n.c_str(), msg);
39 cmd->SetParameterName(o.first.c_str(),
true);
40 cmd->SetGuidance((
"Property item of type " + o.second.type()).c_str());
47 :
G4UImessenger(), m_directory(0), m_properties(0), m_name(name), m_path(path) {
49 printout(INFO,
"Geant4UI",
"+++ %s> Install Geant4 control directory:%s", name.c_str(), path.c_str());
50 m_directory->SetGuidance((
"Control hierarchy for Geant4 action:" + name).c_str());
62 G4UIcommand* cmd =
new G4UIcmdWithoutParameter((
m_path + name).c_str(),
this);
63 cmd->SetGuidance(description.c_str());
66 else if ( 1 == npar ) {
67 G4UIcmdWithAString* cmd =
new G4UIcmdWithAString((
m_path + name).c_str(),
this);
68 cmd->SetParameterName(
"p1",
true);
69 cmd->SetGuidance(description.c_str());
73 except(
"Geant4UIMessenger",
"+++ Currently only callbacks with one argument are handled! [Contact developers if more are required]");
81 addCall(
"show",
"Show all properties of Geant4 component:" +
m_name,
90 const std::string& n = (*i).second;
93 printout(INFO,
"Geant4UI",
94 "+++ %s> Failed to access property value.",
m_name.c_str());
102 const std::string& n = (*i).second;
107 printout(INFO,
"Geant4UI",
108 "+++ %s> Setting property value %s = %s native:%s.",
109 m_name.c_str(), n.c_str(),
v.c_str(), p.
str().c_str());
112 std::string value = (*m_properties)[n].str();
113 printout(INFO,
"Geant4UI",
"+++ %s> Unchanged property value %s = %s.",
114 m_name.c_str(), n.c_str(), value.c_str());
118 printout(INFO,
"Geant4UI",
"+++ %s> Exception: Failed to change property %s = '%s'.",
119 m_name.c_str(), n.c_str(),
v.c_str());
120 printout(INFO,
"Geant4UI",
"+++ %s> Exception: %s",
m_name.c_str(), e.what());
123 printout(INFO,
"Geant4UI",
"+++ %s> UNKNOWN Exception: Failed to change property %s = '%s'.",
124 m_name.c_str(), n.c_str(),
v.c_str());
132 const void* args[] = {
v.c_str(), 0};
133 (*j).second.execute(args);
136 printout(INFO,
"Geant4UI",
"+++ %s> Exception: Failed to exec action '%s' [%s].",
137 m_name.c_str(), c->GetCommandName().c_str(), c->GetCommandPath().c_str());
138 printout(INFO,
"Geant4UI",
"+++ %s> Exception: %s",e.what());
141 printout(INFO,
"Geant4UI",
"+++ %s> UNKNOWN Exception: Failed to exec action '%s' [%s].",
142 m_name.c_str(), c->GetCommandName().c_str(), c->GetCommandPath().c_str());
147 printout(INFO,
"Geant4UI",
"+++ %s> Unknown command callback!",
m_name.c_str());