52 : toBeBroadcasted(tBB), messenger(theMessenger)
55 G4UIcommandCommonConstructorCode(comStr);
61void G4UIcommand::G4UIcommandCommonConstructorCode(
const char* theCommandPath)
63 commandPath = theCommandPath;
64 commandName = theCommandPath;
65 auto commandNameIndex = (
G4int)commandName.rfind(
'/');
66 commandName.erase(0, commandNameIndex + 1);
85 if (messenger ==
nullptr) {
88 ed <<
"A UI command <" << commandPath <<
"> is defined without vaild messenger.";
91 else if (commandPath.back() !=
'/') {
93 ed <<
"G4UIcommand Warning : \n"
94 <<
" <" << commandPath <<
"> must be a directory."
95 <<
" '/' is appended.";
107 if (fUImanager !=
nullptr) {
111 for (
const auto& p : parameter) {
132 std::size_t n_parameterEntry = parameter.size();
133 if (n_parameterEntry != 0) {
137 for (std::size_t i_thParameter = 0; i_thParameter < n_parameterEntry; ++i_thParameter) {
138 if (i_thParameter > 0) {
139 correctParameters.append(
" ");
141 aToken = parameterToken();
142 if (aToken.length() > 0 && aToken[0] ==
'"') {
143 while (aToken.back() !=
'"' || (aToken.length() == 1 && aToken[0] ==
'"')) {
144 G4String additionalToken = parameterToken();
145 if (additionalToken.empty()) {
149 aToken += additionalToken;
152 else if (i_thParameter == n_parameterEntry - 1
153 && parameter[i_thParameter]->GetParameterType() ==
's')
156 while (!((anotherToken = parameterToken()).empty())) {
157 std::size_t idxs = anotherToken.find(
'#');
158 if (idxs == std::string::npos) {
160 aToken += anotherToken;
164 aToken += anotherToken.substr(0, idxs);
173 if (aToken.empty() || aToken ==
"!") {
174 if (parameter[i_thParameter]->IsOmittable()) {
175 if (parameter[i_thParameter]->GetCurrentAsDefault()) {
178 for (std::size_t ii = 0; ii < i_thParameter; ++ii) {
180 if (parVal[0] ==
'"') {
181 while (parVal.back() !=
'"') {
183 if (additionalToken.empty()) {
187 parVal += additionalToken;
192 if (aCVToken[0] ==
'"') {
193 while (aCVToken.back() !=
'"') {
195 if (additionalToken.empty()) {
199 aCVToken += additionalToken;
202 correctParameters.append(aCVToken);
205 correctParameters.append(parameter[i_thParameter]->GetDefaultValue());
213 G4int stat = parameter[i_thParameter]->CheckNewValue(aToken);
215 return stat +
G4int(i_thParameter);
217 correctParameters.append(aToken);
243 availabelStateList = {s1};
249 availabelStateList = {s1, s2};
256 availabelStateList = {s1, s2, s3};
263 availabelStateList = {s1, s2, s3, s4};
271 availabelStateList = {s1, s2, s3, s4, s5};
279 for (
const auto& s : availabelStateList) {
280 if (s == currentState) {
305 auto ucatIter = std::find_if(std::cbegin(UTbl), std::cend(UTbl), [&unitCategory](
const auto& ud) {
306 return ud->GetName() == unitCategory;
309 if (ucatIter == std::cend(UTbl)) {
310 G4cerr <<
"Unit category <" << unitCategory <<
"> is not defined." <<
G4endl;
318 for (
const auto& uDef : UCnt) {
319 symList += uDef->GetSymbol();
321 nameList += uDef->GetName();
325 G4StrUtil::rstrip(symList);
334 if (commandPath.back() !=
'/') {
338 G4cout <<
" ---- available only in worker thread" <<
G4endl;
342 for (
const auto& i_thGuidance : commandGuidance) {
346 if (!rangeExpression.empty()) {
347 G4cout <<
" Range of parameters : " << rangeExpression <<
G4endl;
350 for (
const auto& i_thParameter : parameter) {
351 i_thParameter->List();
359 return boolVal ?
"1" :
"0";
377 std::ostringstream os;
379 os << std::setprecision(17);
388 std::ostringstream os;
390 os << std::setprecision(17);
392 os << doubleValue /
ValueOf(unitName) <<
" " << unitName;
399 std::ostringstream os;
401 os << std::setprecision(17);
403 os << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z();
412 std::ostringstream os;
414 os << std::setprecision(17);
416 os << vec.
x() / uv <<
" " << vec.
y() / uv <<
" " << vec.
z() / uv <<
" " << unitName;
423 G4String v = G4StrUtil::to_upper_copy(st);
424 return (v ==
"Y" || v ==
"YES" || v ==
"1" || v ==
"T" || v ==
"TRUE");
451 std::istringstream is(st);
464 std::istringstream is(st);
465 is >> vx >> vy >> vz;
476 std::istringstream is(st);
477 is >> vx >> vy >> vz >> unts;
488 if (!RangeCheck(newValue)) {
495G4bool G4UIcommand::RangeCheck(
const char* t)
497 if (rangeExpression.empty()) {
504 std::istringstream is(t);
505 for (
unsigned i = 0; i < parameter.size(); ++i) {
506 type = (char)std::toupper(parameter[i]->GetParameterType());
527 result = Expression();
533 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
539 G4cerr <<
"parameter out of range: " << rangeExpression <<
G4endl;
545yystype G4UIcommand::Expression()
547 return LogicalORExpression();
551yystype G4UIcommand::LogicalORExpression()
555 p = LogicalANDExpression();
560 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
566 p = LogicalANDExpression();
568 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
577 result.
I +=
static_cast<int>(p.
L != 0L);
581 result.
I +=
static_cast<int>(p.
D != 0.0);
593yystype G4UIcommand::LogicalANDExpression()
597 p = EqualityExpression();
602 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
608 p = EqualityExpression();
610 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
619 result.
I *=
static_cast<int>(p.
L != 0L);
623 result.
I *=
static_cast<int>(p.
D != 0.0);
635yystype G4UIcommand::EqualityExpression()
640 result = RelationalExpression();
641 if (token ==
EQ || token ==
NE) {
645 arg2 = RelationalExpression();
646 result.
I = Eval2(arg1, operat, arg2);
651 G4cerr <<
"Parameter range: error at EqualityExpression" <<
G4endl;
659yystype G4UIcommand::RelationalExpression()
665 arg1 = AdditiveExpression();
666 if (token ==
GT || token ==
GE || token ==
LT || token ==
LE) {
669 arg2 = AdditiveExpression();
670 result.
I = Eval2(arg1, operat, arg2);
680yystype G4UIcommand::AdditiveExpression()
682 yystype result = MultiplicativeExpression();
683 if (token !=
'+' && token !=
'-') {
686 G4cerr <<
"Parameter range: operator " << (char)token <<
" is not supported." <<
G4endl;
692yystype G4UIcommand::MultiplicativeExpression()
694 yystype result = UnaryExpression();
695 if (token !=
'*' && token !=
'/' && token !=
'%') {
698 G4cerr <<
"Parameter range: operator " << (char)token <<
" is not supported." <<
G4endl;
704yystype G4UIcommand::UnaryExpression()
711 p = UnaryExpression();
727 result = UnaryExpression();
731 G4cerr <<
"Parameter range error: "
732 <<
"operator '!' is not supported (sorry)." <<
G4endl;
734 result = UnaryExpression();
737 result = PrimaryExpression();
743yystype G4UIcommand::PrimaryExpression()
769 result = Expression();
788 G4cerr << commandName <<
": meaningless comparison" <<
G4endl;
793 unsigned i = IndexOf(arg1.
S);
794 newValtype = (char)std::toupper(parameter[i]->GetParameterType());
795 switch (newValtype) {
803 unsigned iii = IndexOf(arg2.
S);
804 char newValtype2 = (char)std::toupper(parameter[iii]->GetParameterType());
805 if (newValtype2 ==
'I') {
808 if (newValtype2 ==
'L') {
809 G4cerr <<
"Warning : Integer is compared with long int : " << rangeExpression <<
G4endl;
812 if (newValtype2 ==
'D') {
813 G4cerr <<
"Warning : Integer is compared with double : " << rangeExpression <<
G4endl;
819 G4cerr <<
"integer operand expected for " << rangeExpression <<
'.' <<
G4endl;
830 unsigned iii = IndexOf(arg2.
S);
831 char newValtype2 = (char)std::toupper(parameter[iii]->GetParameterType());
832 if (newValtype2 ==
'I') {
835 if (newValtype2 ==
'L') {
838 if (newValtype2 ==
'D') {
839 G4cerr <<
"Warning : Long int is compared with double : " << rangeExpression <<
G4endl;
845 G4cerr <<
"integer operand expected for " << rangeExpression <<
'.' <<
G4endl;
861 unsigned iii = IndexOf(arg2.
S);
862 char newValtype2 = (char)std::toupper(parameter[iii]->GetParameterType());
863 if (newValtype2 ==
'I') {
866 if (newValtype2 ==
'L') {
869 if (newValtype2 ==
'D') {
879 unsigned i = IndexOf(arg2.
S);
880 newValtype = (char)std::toupper(parameter[i]->GetParameterType());
881 switch (newValtype) {
887 G4cerr <<
"integer operand expected for " << rangeExpression <<
'.' <<
G4endl;
895 G4cerr <<
"long int operand expected for " << rangeExpression <<
'.' <<
G4endl;
913unsigned G4UIcommand::IndexOf(
const char* nam)
915 for (
unsigned i = 0; i < parameter.size(); ++i) {
916 if (parameter[i]->GetParameterName() == nam) {
921 G4cerr <<
"parameter name:" << nam <<
" not found." <<
G4endl;
926unsigned G4UIcommand::IsParameter(
const char* nam)
928 for (
auto& i : parameter) {
929 if (i->GetParameterName() == nam) {
943 while ((c = G4UIpGetc()) ==
' ' || c ==
'\t' || c ==
'\n') {
950 if ((isdigit(c) != 0) || c ==
'.') {
952 buf += (
unsigned char)c;
954 }
while (c ==
'.' || (isdigit(c) != 0) || c ==
'e' || c ==
'E' || c ==
'+' || c ==
'-');
957 std::istringstream is(t);
970 if ((isalpha(c) != 0) || c ==
'_') {
972 buf += (
unsigned char)c;
973 }
while ((c = G4UIpGetc()) != EOF && ((isalnum(c) != 0) || c ==
'_'));
975 if (IsParameter(buf) != 0u) {
1004 G4int c = G4UIpGetc();
1014G4int G4UIcommand::G4UIpGetc()
1016 std::size_t length = rangeExpression.length();
1017 if (bp < (
G4int)length) {
1018 return rangeExpression[bp++];
1030 if (bp > 0 && c == rangeExpression[bp - 1]) {
1035 G4cerr <<
"bp=" << bp <<
" c=" << c <<
" pR(bp-1)=" << rangeExpression[bp - 1] <<
G4endl;
G4double D(G4double temp)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
CLHEP::Hep3Vector G4ThreeVector
std::vector< G4UnitDefinition * > G4UnitsContainer
std::vector< G4UnitsCategory * > G4UnitsTable
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
static G4StateManager * GetStateManager()
static G4ThreeVector ConvertTo3Vector(const char *st)
static G4String CategoryOf(const char *unitName)
static G4double ValueOf(const char *unitName)
void SetCommandType(CommandType)
static G4long ConvertToLongInt(const char *st)
virtual G4int DoIt(G4String parameterList)
G4bool operator==(const G4UIcommand &right) const
static G4String ConvertToString(G4bool boolVal)
const G4String & GetCommandPath() const
G4int CheckNewValue(const char *newValue)
static G4int ConvertToInt(const char *st)
static G4String UnitsList(const char *unitCategory)
static G4bool ConvertToBool(const char *st)
static G4double ConvertToDouble(const char *st)
static G4double ConvertToDimensionedDouble(const char *st)
void AvailableForStates(G4ApplicationState s1)
G4bool operator!=(const G4UIcommand &right) const
static G4ThreeVector ConvertToDimensioned3Vector(const char *st)
G4String GetCurrentValue()
static G4bool DoublePrecisionStr()
static G4UImanager * GetMasterUIpointer()
void AddNewCommand(G4UIcommand *newCommand)
void RemoveCommand(G4UIcommand *aCommand)
static G4UImanager * GetUIpointer()
virtual G4String GetCurrentValue(G4UIcommand *command)
G4bool CommandsShouldBeInMaster() const
virtual void SetNewValue(G4UIcommand *command, G4String newValue)
static G4double GetValueOf(const G4String &)
static G4String GetCategory(const G4String &)
static G4UnitsTable & GetUnitsTable()
G4bool IsDouble(const char *str)
T StoT(const G4String &s)
G4int CompareLong(G4long arg1, G4int op, G4long arg2, G4int &errCode)
G4int CompareDouble(G4double arg1, G4int op, G4double arg2, G4int &errCode)
G4bool IsInt(const char *str, short maxDigits)
G4int CompareInt(G4int arg1, G4int op, G4int arg2, G4int &errCode)