56 const char*
what()
const throw()
override
58 return "G4InvalidUICommand: command does not exist or is of invalid type";
74 for(
const auto& propertie : properties)
76 delete propertie.second.command;
78 for(
const auto& method : methods)
80 delete method.second.command;
87 G4String fullpath = directory + name;
93 ->SetParameterName(
"valueX",
"valueY",
"valueZ",
false,
false);
100 var.
TypeInfo() ==
typeid(
unsigned int) ||
101 var.
TypeInfo() ==
typeid(
unsigned long))
103 else if(var.
TypeInfo() ==
typeid(
float) || var.
TypeInfo() ==
typeid(
double))
105 else if(var.
TypeInfo() ==
typeid(
bool))
115 return properties[name] =
Property(var, cmd);
127 G4String fullpath = directory + name;
133 ->SetParameterName(
"value",
false,
false);
140 ->SetParameterName(
"valueX",
"valueY",
"valueZ",
false,
false);
148 return properties[name] =
Property(var, cmd);
154 G4String fullpath = directory + name;
155 auto* cmd =
new G4UIcommand(fullpath.c_str(),
this);
158 cmd->SetGuidance(doc);
160 for(std::size_t i = 0; i < fun.
NArg(); ++i)
165 if(tInfo ==
typeid(
int) || tInfo ==
typeid(
long) ||
166 tInfo ==
typeid(
unsigned int) ||
167 tInfo ==
typeid(
unsigned long))
169 else if(tInfo ==
typeid(
float) || tInfo ==
typeid(
double))
171 else if(tInfo ==
typeid(
bool))
179 return methods[name] =
Method(fun,
object, cmd);
186 G4String fullpath = directory + name;
190 ed <<
"G4GenericMessenger::DeclareMethodWithUnit() does not support a "
191 "method that has more than\n"
192 <<
"one arguments (or no argument). Please use "
193 "G4GenericMessenger::DeclareMethod method for\n"
194 <<
"your command <" << fullpath <<
">.";
195 G4Exception(
"G4GenericMessenger::DeclareMethodWithUnit()",
"Intercom70002",
200 ->SetParameterName(
"value",
false,
false);
206 return methods[name] =
Method(fun,
object, cmd);
211 if(properties.find(command->
GetCommandName()) != properties.cend())
216 else if(methods.find(command->
GetCommandName()) != methods.cend())
218 G4cout <<
" GetCurrentValue() is not available for a command defined by "
219 "G4GenericMessenger::DeclareMethod()."
243 if(properties.find(command->
GetCommandName()) != properties.cend())
248 else if(methods.find(command->
GetCommandName()) != methods.cend())
281 ed <<
"G4GenericMessenger::Command::SetUnit() is thread-unsafe and should "
283 <<
"in multi-threaded mode. For your command <" << cmdpath <<
">, use\n"
284 <<
" DeclarePropertyWithUnit(const G4String& name, const G4String& "
286 <<
" const G4AnyType& variable, const G4String& "
289 <<
" DeclareMethodWithUnit(const G4String& name, const G4String& "
291 <<
" const G4AnyType& variable, const G4String& "
293 <<
"to define a command with a unit <" << unit <<
">.";
296 ed <<
"\nPlease use a default unit instead of unit category.";
298 G4Exception(
"G4GenericMessenger::Command::SetUnit()",
"Intercom70001",
306 std::vector<G4String> guidance;
315 G4UIcommand tmp((cmdpath +
"_tmp").c_str(), messenger);
318 if(*
type ==
typeid(
float) || *
type ==
typeid(
double))
323 cmd_t->SetDefaultUnit(unit);
327 cmd_t->SetUnitCategory(unit);
329 cmd_t->SetParameterName(par_name, par_omitable);
337 cmd_t->SetDefaultUnit(unit);
341 cmd_t->SetUnitCategory(unit);
347 G4cerr <<
"Only parameters of type <double> or <float> can be associated "
352 for(
auto& i : guidance)
363 return SetParameterName(0,name,omittable,currentAsDefault);
370 if(pIdx < 0 || pIdx >= (
G4int)(command->GetParameterEntries()))
372 G4cerr <<
"Invalid parameter index : " << pIdx <<
"\nMethod ignored."
389 G4cerr <<
"This SetParameterName method is for G4ThreeVector!! "
390 <<
"Method ignored." <<
G4endl;
397 theParam = command->GetParameter(1);
401 theParam = command->GetParameter(2);
411 return SetCandidates(0,candList);
417 if(pIdx < 0 || pIdx >= (
G4int)(command->GetParameterEntries()))
419 G4cerr <<
"Invalid parameter index : " << pIdx <<
"\nMethod ignored."
431 return SetDefaultValue(0,defVal);
437 if(pIdx < 0 || pIdx >= (
G4int)(command->GetParameterEntries()))
439 G4cerr <<
"Invalid parameter index : " << pIdx <<
"\nMethod ignored."
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const std::type_info & ArgType(size_t n=0) const
void FromString(const std::string &val)
const std::type_info & TypeInfo() const
std::string ToString() const
Command & DeclareMethod(const G4String &name, const G4AnyMethod &fun, const G4String &doc="")
void SetGuidance(const G4String &s)
~G4GenericMessenger() override
Command & DeclareProperty(const G4String &name, const G4AnyType &variable, const G4String &doc="")
Command & DeclareMethodWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyMethod &fun, const G4String &doc="")
G4GenericMessenger(void *obj, const G4String &dir="", const G4String &doc="")
void SetNewValue(G4UIcommand *command, G4String newValue) override
G4String GetCurrentValue(G4UIcommand *command) override
Command & DeclarePropertyWithUnit(const G4String &name, const G4String &defaultUnit, const G4AnyType &variable, const G4String &doc="")
G4InvalidUICommand()=default
const char * what() const override
G4UImessenger * GetMessenger() const
const G4String & GetGuidanceLine(G4int i) const
G4UIparameter * GetParameter(G4int i) const
static G4String ConvertToString(G4bool boolVal)
const G4String & GetCommandPath() const
void SetParameter(G4UIparameter *const newParameter)
void SetGuidance(const char *aGuidance)
std::size_t GetGuidanceEntries() const
void SetRange(const char *rs)
static G4double ConvertToDimensionedDouble(const char *st)
const G4String & GetCommandName() const
const G4String & GetRange() const
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
void SetDefaultValue(const char *theDefaultValue)
void SetParameterName(const char *pName)
G4bool IsOmittable() const
void SetOmittable(G4bool om)
void SetParameterCandidates(const char *theString)
void SetCurrentAsDefault(G4bool val)
const G4String & GetParameterName() const
G4bool IsMultithreadedApplication()
Command & SetParameterName(const G4String &, G4bool, G4bool=false)
Command & SetCandidates(const G4String &)
Command & SetDefaultValue(const G4String &)
const std::type_info * type
Command & SetUnit(const G4String &, UnitSpec=UnitDefault)