51 : toBeBroadcasted(tBB)
52 , messenger(theMessenger)
55 G4UIcommandCommonConstructorCode(comStr);
56 availabelStateList.clear();
66void G4UIcommand::G4UIcommandCommonConstructorCode(
const char* theCommandPath)
68 commandPath = theCommandPath;
69 commandName = theCommandPath;
70 G4int commandNameIndex = (
G4int)commandName.rfind(
'/');
71 commandName.erase(0, commandNameIndex + 1);
91 if(messenger==
nullptr)
96 ed <<
"A UI command <" << commandPath
97 <<
"> is defined without vaild messenger.";
101 else if(commandPath.back() !=
'/')
104 ed <<
"G4UIcommand Warning : \n"
105 <<
" <" << commandPath <<
"> must be a directory."
106 <<
" '/' is appended.";
107 G4Exception(
"G4UIcommand::SetCommandType",
"UI2032",
119 if(fUImanager !=
nullptr)
124 std::size_t n_parameterEntry = parameter.size();
125 for(std::size_t i_thParameter = 0; i_thParameter < n_parameterEntry;
128 delete parameter[i_thParameter];
149 std::size_t n_parameterEntry = parameter.size();
150 if(n_parameterEntry != 0)
155 for(std::size_t i_thParameter = 0; i_thParameter < n_parameterEntry;
158 if(i_thParameter > 0)
160 correctParameters.append(
" ");
162 aToken = parameterToken();
163 if(aToken.length() > 0 && aToken[0] ==
'"')
165 while(aToken.back() !=
'"' ||
166 (aToken.length() == 1 && aToken[0] ==
'"'))
168 G4String additionalToken = parameterToken();
169 if(additionalToken.empty())
174 aToken += additionalToken;
177 else if(i_thParameter == n_parameterEntry - 1 &&
178 parameter[i_thParameter]->GetParameterType() ==
's')
181 while(!((anotherToken = parameterToken()).empty()))
183 std::size_t idxs = anotherToken.find(
"#");
184 if(idxs == std::string::npos)
187 aToken += anotherToken;
192 aToken += anotherToken.substr(0, idxs);
202 if(aToken.empty() || aToken ==
"!")
204 if(parameter[i_thParameter]->IsOmittable())
206 if(parameter[i_thParameter]->GetCurrentAsDefault())
210 for(std::size_t ii = 0; ii < i_thParameter; ++ii)
215 while(parVal.back() !=
'"')
218 if(additionalToken.empty())
223 parVal += additionalToken;
228 if(aCVToken[0] ==
'"')
230 while(aCVToken.back() !=
'"')
233 if(additionalToken.empty())
238 aCVToken += additionalToken;
241 correctParameters.append(aCVToken);
245 correctParameters.append(
246 parameter[i_thParameter]->GetDefaultValue());
256 G4int stat = parameter[i_thParameter]->CheckNewValue(aToken);
259 return stat +
G4int(i_thParameter);
261 correctParameters.append(aToken);
289 availabelStateList.clear();
290 availabelStateList.push_back(s1);
297 availabelStateList.clear();
298 availabelStateList.push_back(s1);
299 availabelStateList.push_back(s2);
307 availabelStateList.clear();
308 availabelStateList.push_back(s1);
309 availabelStateList.push_back(s2);
310 availabelStateList.push_back(s3);
319 availabelStateList.clear();
320 availabelStateList.push_back(s1);
321 availabelStateList.push_back(s2);
322 availabelStateList.push_back(s3);
323 availabelStateList.push_back(s4);
333 availabelStateList.clear();
334 availabelStateList.push_back(s1);
335 availabelStateList.push_back(s2);
336 availabelStateList.push_back(s3);
337 availabelStateList.push_back(s4);
338 availabelStateList.push_back(s5);
348 std::size_t nState = availabelStateList.size();
349 for(std::size_t i = 0; i < nState; ++i)
351 if(availabelStateList[i] == currentState)
381 for(i = 0; i < UTbl.size(); ++i)
383 if(UTbl[i]->GetName() == unitCategory)
390 G4cerr <<
"Unit category <" << unitCategory <<
"> is not defined."
395 retStr = UCnt[0]->GetSymbol();
396 std::size_t je = UCnt.size();
397 for(std::size_t j = 1; j < je; ++j)
400 retStr += UCnt[j]->GetSymbol();
402 for(std::size_t k = 0; k < je; ++k)
405 retStr += UCnt[k]->GetName();
415 if(commandPath.back() !=
'/')
421 G4cout <<
" ---- available only in worker thread" <<
G4endl;
424 std::size_t n_guidanceEntry = commandGuidance.size();
425 for(std::size_t i_thGuidance = 0; i_thGuidance < n_guidanceEntry; ++i_thGuidance)
429 if(!rangeString.empty())
431 G4cout <<
" Range of parameters : " << rangeString <<
G4endl;
433 std::size_t n_parameterEntry = parameter.size();
434 if(n_parameterEntry > 0)
436 for(std::size_t i_thParameter = 0; i_thParameter < n_parameterEntry;
439 parameter[i_thParameter]->List();
459 std::ostringstream os;
468 std::ostringstream os;
477 std::ostringstream os;
480 os << std::setprecision(17) << doubleValue;
492 const char* unitName)
497 std::ostringstream os;
500 os << std::setprecision(17) << doubleValue / uv <<
" " << unitName;
504 os << doubleValue / uv <<
" " << unitName;
513 std::ostringstream os;
516 os << std::setprecision(17) << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z();
520 os << vec.
x() <<
" " << vec.
y() <<
" " << vec.
z();
528 const char* unitName)
533 std::ostringstream os;
536 os << std::setprecision(17) << vec.
x() / uv <<
" " << vec.
y() / uv <<
" "
537 << vec.
z() / uv <<
" " << unitName;
541 os << vec.
x() / uv <<
" " << vec.
y() / uv <<
" " << vec.
z() / uv <<
" "
553 if(v ==
"Y" || v ==
"YES" || v ==
"1" || v ==
"T" || v ==
"TRUE")
564 std::istringstream is(st);
573 std::istringstream is(st);
582 std::istringstream is(st);
593 std::istringstream is(st);
606 std::istringstream is(st);
607 is >> vx >> vy >> vz;
618 std::istringstream is(st);
619 is >> vx >> vy >> vz >> unts;
633 if(!rangeString.empty())
635 if(RangeCheck(newValue) == 0)
644G4int G4UIcommand::TypeCheck(
const char* t)
648 std::istringstream is(t);
649 for(
auto& i : parameter)
652 type = (char)std::toupper(i->GetParameterType());
656 if(IsDouble(aNewValue) == 0)
658 G4cerr << aNewValue <<
": double value expected." <<
G4endl;
663 if(IsInt(aNewValue, 10) == 0)
670 if(IsInt(aNewValue, 20) == 0)
672 G4cerr << aNewValue <<
": long int expected." <<
G4endl;
680 if(aNewValue ==
"Y" || aNewValue ==
"N" || aNewValue ==
"YES" ||
681 aNewValue ==
"NO" || aNewValue ==
"1" || aNewValue ==
"0" ||
682 aNewValue ==
"T" || aNewValue ==
"F" || aNewValue ==
"TRUE" ||
683 aNewValue ==
"FALSE")
699G4int G4UIcommand::IsInt(
const char* buf,
short maxDigits)
703 if(*p ==
'+' || *p ==
'-')
707 if(isdigit((
G4int) (*p)) != 0)
709 while(isdigit((
G4int) (*p)) != 0)
716 if(length > maxDigits)
736G4int G4UIcommand::ExpectExponent(
const char* str)
739 if(IsInt(str, maxExplength = 7) != 0)
750G4int G4UIcommand::IsDouble(
const char* buf)
760 while(isdigit((
G4int) (*p)) != 0)
771 return ExpectExponent(++p);
779 if(*p ==
'e' || *p ==
'E')
781 return ExpectExponent(++p);
785 while(isdigit((
G4int) (*p)) != 0)
793 if(*p ==
'e' || *p ==
'E')
795 return ExpectExponent(++p);
812 while(isdigit((
G4int) (*p)) != 0)
820 if(*p ==
'e' || *p ==
'E')
822 return ExpectExponent(++p);
831 while(isdigit((
G4int) (*p)) != 0)
839 if(*p ==
'e' || *p ==
'E')
841 return ExpectExponent(++p);
848 while(isdigit((
G4int) (*p)) != 0)
856 if(*p ==
'e' || *p ==
'E')
858 return ExpectExponent(++p);
867 if(*p ==
'e' || *p ==
'E')
869 return ExpectExponent(++p);
873 while(isdigit((
G4int) (*p)) != 0)
881 if(*p ==
'e' || *p ==
'E')
883 return ExpectExponent(++p);
893G4int G4UIcommand::RangeCheck(
const char* t)
898 std::istringstream is(t);
899 for(
unsigned i = 0; i < parameter.size(); ++i)
901 type = (char)std::toupper(parameter[i]->GetParameterType());
924 result = Expression();
932 G4cerr <<
"Illegal Expression in parameter range." <<
G4endl;
939 G4cerr <<
"parameter out of range: " << rangeString <<
G4endl;
945yystype G4UIcommand::Expression()
951 result = LogicalORExpression();
956yystype G4UIcommand::LogicalORExpression()
960 p = LogicalANDExpression();
967 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
974 p = LogicalANDExpression();
977 G4cerr <<
"Parameter range: illegal type at '||'" <<
G4endl;
987 result.I +=
static_cast<int>(p.L != 0
L);
991 result.I +=
static_cast<int>(p.D != 0.0);
1003yystype G4UIcommand::LogicalANDExpression()
1007 p = EqualityExpression();
1014 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
1021 p = EqualityExpression();
1024 G4cerr <<
"Parameter range: illegal type at '&&'" <<
G4endl;
1034 result.I *=
static_cast<int>(p.L != 0
L);
1038 result.I *=
static_cast<int>(p.D != 0.0);
1050yystype G4UIcommand::EqualityExpression()
1058 result = RelationalExpression();
1059 if(token ==
EQ || token ==
NE)
1064 arg2 = RelationalExpression();
1065 result.I = Eval2(arg1, operat, arg2);
1068 G4cerr <<
" return code of Eval2(): " << result.I <<
G4endl;
1075 G4cerr <<
"Parameter range: error at EqualityExpression" <<
G4endl;
1083yystype G4UIcommand::RelationalExpression()
1092 arg1 = AdditiveExpression();
1093 if(token ==
GT || token ==
GE || token ==
LT || token ==
LE)
1097 arg2 = AdditiveExpression();
1098 result.I = Eval2(arg1, operat, arg2);
1101 G4cerr <<
" return code of Eval2(): " << result.I <<
G4endl;
1115yystype G4UIcommand::AdditiveExpression()
1118 result = MultiplicativeExpression();
1119 if(token !=
'+' && token !=
'-')
1123 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
1130yystype G4UIcommand::MultiplicativeExpression()
1133 result = UnaryExpression();
1134 if(token !=
'*' && token !=
'/' && token !=
'%')
1138 G4cerr <<
"Parameter range: operator " << (char) token <<
" is not supported."
1145yystype G4UIcommand::UnaryExpression()
1156 p = UnaryExpression();
1175 result = UnaryExpression();
1179 G4cerr <<
"Parameter range error: "
1180 <<
"operator '!' is not supported (sorry)." <<
G4endl;
1182 result = UnaryExpression();
1185 result = PrimaryExpression();
1191yystype G4UIcommand::PrimaryExpression()
1200 result.S = yylval.S;
1201 result.type = token;
1205 result.I = yylval.I;
1206 result.type = token;
1210 result.L = yylval.L;
1211 result.type = token;
1215 result.D = yylval.D;
1216 result.type = token;
1221 result = Expression();
1242 G4cerr << commandName <<
": meaningless comparison" <<
G4endl;
1248 unsigned i = IndexOf(arg1.S);
1249 newValtype = (char)std::toupper(parameter[i]->GetParameterType());
1255 return CompareInt(newVal[i].
I, op, arg2.I);
1261 unsigned iii = IndexOf(arg2.S);
1262 char newValtype2 = (char)std::toupper(parameter[iii]->GetParameterType());
1263 if(newValtype2 ==
'I')
1265 return CompareInt(newVal[i].
I, op, newVal[iii].
I);
1267 else if(newValtype2 ==
'L')
1269 G4cerr <<
"Warning : Integer is compared with long int : "
1270 << rangeString <<
G4endl;
1271 return CompareLong(newVal[i].
I, op, newVal[iii].L);
1273 else if(newValtype2 ==
'D')
1275 G4cerr <<
"Warning : Integer is compared with double : "
1276 << rangeString <<
G4endl;
1277 return CompareDouble(newVal[i].
I, op, newVal[iii].
D);
1283 G4cerr <<
"integer operand expected for " << rangeString <<
'.'
1290 return CompareLong(newVal[i].L, op, arg2.I);
1294 return CompareLong(newVal[i].L, op, arg2.L);
1298 unsigned iii = IndexOf(arg2.S);
1299 char newValtype2 = (char)std::toupper(parameter[iii]->GetParameterType());
1300 if(newValtype2 ==
'I')
1302 return CompareLong(newVal[i].L, op, newVal[iii].
I);
1304 if(newValtype2 ==
'L')
1306 return CompareLong(newVal[i].L, op, newVal[iii].L);
1308 else if(newValtype2 ==
'D')
1310 G4cerr <<
"Warning : Long int is compared with double : "
1311 << rangeString <<
G4endl;
1312 return CompareDouble(newVal[i].L, op, newVal[iii].
D);
1318 G4cerr <<
"integer operand expected for " << rangeString <<
'.'
1325 return CompareDouble(newVal[i].
D, op, arg2.D);
1329 return CompareDouble(newVal[i].
D, op, arg2.I);
1335 return CompareDouble(newVal[i].
D, op, arg2.L);
1339 unsigned iii = IndexOf(arg2.S);
1340 char newValtype2 = (char)std::toupper(parameter[iii]->GetParameterType());
1341 if(newValtype2 ==
'I')
1343 return CompareDouble(newVal[i].
D, op, newVal[iii].
I);
1345 else if(newValtype2 ==
'L')
1347 return CompareDouble(newVal[i].
D, op, newVal[iii].L);
1349 else if(newValtype2 ==
'D')
1351 return CompareDouble(newVal[i].
D, op, newVal[iii].
D);
1361 unsigned i = IndexOf(arg2.S);
1362 newValtype = (char)std::toupper(parameter[i]->GetParameterType());
1368 return CompareInt(arg1.I, op, newVal[i].I);
1372 G4cerr <<
"integer operand expected for " << rangeString <<
'.'
1379 return CompareLong(arg1.L, op, newVal[i].L);
1383 G4cerr <<
"long int operand expected for " << rangeString <<
'.'
1390 return CompareDouble(arg1.D, op, newVal[i].D);
1394 return CompareDouble(arg1.I, op, newVal[i].D);
1411 result =
static_cast<G4int>(arg1 > arg2);
1415 result =
static_cast<G4int>(arg1 >= arg2);
1419 result =
static_cast<G4int>(arg1 < arg2);
1423 result =
static_cast<G4int>(arg1 <= arg2);
1427 result =
static_cast<G4int>(arg1 == arg2);
1431 result =
static_cast<G4int>(arg1 != arg2);
1435 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
1439 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
1453 result =
static_cast<G4int>(arg1 > arg2);
1457 result =
static_cast<G4int>(arg1 >= arg2);
1461 result =
static_cast<G4int>(arg1 < arg2);
1465 result =
static_cast<G4int>(arg1 <= arg2);
1469 result =
static_cast<G4int>(arg1 == arg2);
1473 result =
static_cast<G4int>(arg1 != arg2);
1477 G4cerr <<
"Parameter range: error at CompareInt" <<
G4endl;
1481 G4cerr <<
"CompareInt " << arg1 <<
" " << opr << arg2 <<
" result: " << result
1495 result =
static_cast<G4int>(arg1 > arg2);
1499 result =
static_cast<G4int>(arg1 >= arg2);
1503 result =
static_cast<G4int>(arg1 < arg2);
1507 result =
static_cast<G4int>(arg1 <= arg2);
1511 result =
static_cast<G4int>(arg1 == arg2);
1515 result =
static_cast<G4int>(arg1 != arg2);
1519 G4cerr <<
"Parameter range: error at CompareDouble" <<
G4endl;
1523 G4cerr <<
"CompareDouble " << arg1 <<
" " << opr <<
" " << arg2
1524 <<
" result: " << result <<
G4endl;
1530unsigned G4UIcommand::IndexOf(
const char* nam)
1534 for(i = 0; i < parameter.size(); ++i)
1536 pname = parameter[i]->GetParameterName();
1543 G4cerr <<
"parameter name:" << nam <<
" not found." <<
G4endl;
1548unsigned G4UIcommand::IsParameter(
const char* nam)
1551 for(
auto& i : parameter)
1553 pname = i->GetParameterName();
1569 while((c = G4UIpGetc()) ==
' ' || c ==
'\t' || c ==
'\n')
1578 if((isdigit(c) != 0) || c ==
'.')
1582 buf += (
unsigned char)c;
1584 }
while(c ==
'.' || (isdigit(c) != 0) || c ==
'e' || c ==
'E' || c ==
'+' ||
1587 const char* t = buf;
1588 std::istringstream is(t);
1589 if(IsInt(buf.data(), 20) != 0)
1594 else if(IsDouble(buf.data()) != 0)
1605 if((isalpha(c) != 0) || c ==
'_')
1609 buf += (
unsigned char) c;
1610 }
while((c = G4UIpGetc()) != EOF && ((isalnum(c) != 0) || c ==
'_'));
1612 if(IsParameter(buf) != 0u)
1619 G4cerr << buf <<
" is not a parameter name." <<
G4endl;
1645 G4int c = G4UIpGetc();
1656G4int G4UIcommand::G4UIpGetc()
1658 std::size_t length = rangeString.length();
1659 if(bp < (
G4int)length)
1661 return rangeString[bp++];
1676 if(bp > 0 && c == rangeString[bp - 1])
1683 G4cerr <<
"bp=" << bp <<
" c=" << c <<
" pR(bp-1)=" << rangeString[bp - 1]
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)
G4UItokenNum::yystype yystype
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()
void to_upper(G4String &str)
Convert string to uppercase.
G4String to_upper_copy(G4String str)
Return uppercase copy of string.
yystype { tokenNum type{ tokenNum::NONE } yystype