File indexing completed on 2025-09-18 09:15:54
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #ifndef G4UIcommand_hh
0039 #define G4UIcommand_hh 1
0040
0041 #include "G4ApplicationState.hh"
0042 #include "G4ThreeVector.hh"
0043 #include "G4UIparameter.hh"
0044 #include "globals.hh"
0045
0046 #include <vector>
0047
0048 class G4UImessenger;
0049
0050 class G4UIcommand
0051 {
0052 public:
0053
0054 G4UIcommand() = default;
0055
0056
0057
0058
0059
0060
0061 G4UIcommand(const char* theCommandPath, G4UImessenger* theMessenger, G4bool tBB = true);
0062
0063 virtual ~G4UIcommand();
0064
0065 G4bool operator==(const G4UIcommand& right) const;
0066 G4bool operator!=(const G4UIcommand& right) const;
0067
0068 virtual G4int DoIt(const G4String& parameterList);
0069
0070 G4String GetCurrentValue();
0071
0072
0073
0074
0075 void AvailableForStates(G4ApplicationState s1);
0076 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2);
0077 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3);
0078 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0079 G4ApplicationState s4);
0080 void AvailableForStates(G4ApplicationState s1, G4ApplicationState s2, G4ApplicationState s3,
0081 G4ApplicationState s4, G4ApplicationState s5);
0082
0083 G4bool IsAvailable();
0084
0085 virtual void List();
0086
0087
0088
0089
0090 static G4String ConvertToString(G4bool boolVal);
0091 static G4String ConvertToString(G4int intValue);
0092 static G4String ConvertToString(G4long longValue);
0093 static G4String ConvertToString(G4double doubleValue);
0094 static G4String ConvertToString(G4double doubleValue, const char* unitName);
0095 static G4String ConvertToString(const G4ThreeVector& vec);
0096 static G4String ConvertToString(const G4ThreeVector& vec, const char* unitName);
0097
0098
0099
0100
0101
0102 static G4bool ConvertToBool(const char* st);
0103 static G4int ConvertToInt(const char* st);
0104 static G4long ConvertToLongInt(const char* st);
0105 static G4double ConvertToDouble(const char* st);
0106 static G4double ConvertToDimensionedDouble(const char* st);
0107 static G4ThreeVector ConvertTo3Vector(const char* st);
0108 static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
0109
0110
0111 static G4double ValueOf(const char* unitName);
0112 static G4String CategoryOf(const char* unitName);
0113 static G4String UnitsList(const char* unitCategory);
0114
0115
0116
0117
0118
0119
0120 inline void SetRange(const char* rs) { rangeExpression = rs; }
0121
0122 inline const G4String& GetRange() const { return rangeExpression; }
0123 inline std::size_t GetGuidanceEntries() const { return commandGuidance.size(); }
0124 inline const G4String& GetGuidanceLine(G4int i) const { return commandGuidance[i]; }
0125 inline const G4String& GetCommandPath() const { return commandPath; }
0126 inline const G4String& GetCommandName() const { return commandName; }
0127 inline std::size_t GetParameterEntries() const { return parameter.size(); }
0128 inline G4UIparameter* GetParameter(G4int i) const { return parameter[i]; }
0129 inline std::vector<G4ApplicationState>* GetStateList() { return &availabelStateList; }
0130 inline G4UImessenger* GetMessenger() const { return messenger; }
0131
0132
0133
0134
0135
0136 inline void SetParameter(G4UIparameter* const newParameter)
0137 {
0138 parameter.push_back(newParameter);
0139 }
0140
0141
0142
0143
0144
0145 inline void SetGuidance(const char* aGuidance) { commandGuidance.emplace_back(aGuidance); }
0146
0147 inline const G4String GetTitle() const
0148 {
0149 return (commandGuidance.empty()) ? G4String("...Title not available...") : commandGuidance[0];
0150 }
0151
0152 inline void SetToBeBroadcasted(G4bool val) { toBeBroadcasted = val; }
0153 inline G4bool ToBeBroadcasted() const { return toBeBroadcasted; }
0154 inline void SetToBeFlushed(G4bool val) { toBeFlushed = val; }
0155 inline G4bool ToBeFlushed() const { return toBeFlushed; }
0156 inline void SetWorkerThreadOnly(G4bool val = true) { workerThreadOnly = val; }
0157 inline G4bool IsWorkerThreadOnly() const { return workerThreadOnly; }
0158
0159 inline void CommandFailed(G4int errCode, G4ExceptionDescription& ed)
0160 {
0161 commandFailureCode = errCode;
0162 failureDescription = ed.str();
0163 }
0164 inline void CommandFailed(G4ExceptionDescription& ed)
0165 {
0166 commandFailureCode = 1;
0167 failureDescription = ed.str();
0168 }
0169 inline G4int IfCommandFailed() { return commandFailureCode; }
0170 inline const G4String& GetFailureDescription() { return failureDescription; }
0171 inline void ResetFailure()
0172 {
0173 commandFailureCode = 0;
0174 failureDescription = "";
0175 }
0176
0177 public:
0178 enum CommandType
0179 {
0180 BaseClassCmd,
0181 WithoutParameterCmd,
0182 WithABoolCmd,
0183 WithAnIntegerCmd,
0184 WithALongIntCmd,
0185 WithADoubleCmd,
0186 WithADoubleAndUnitCmd,
0187 With3VectorCmd,
0188 With3VectorAndUnitCmd,
0189 WithAStringCmd,
0190 CmdDirectory = -1
0191 };
0192
0193 inline CommandType GetCommandType() const { return commandType; }
0194 void SetCommandType(CommandType);
0195
0196 inline void SetDefaultSortFlag(G4bool val) { ifSort = val; }
0197
0198 protected:
0199 G4int CheckNewValue(const char* newValue);
0200
0201 G4bool toBeBroadcasted = false;
0202 G4bool toBeFlushed = false;
0203 G4bool workerThreadOnly = false;
0204
0205 G4int commandFailureCode = 0;
0206 G4String failureDescription = "";
0207
0208 G4bool ifSort = false;
0209
0210 private:
0211 void G4UIcommandCommonConstructorCode(const char* theCommandPath);
0212
0213 private:
0214 CommandType commandType = BaseClassCmd;
0215 G4UImessenger* messenger = nullptr;
0216 G4String commandPath;
0217 G4String commandName;
0218 G4String rangeExpression;
0219 std::vector<G4UIparameter*> parameter;
0220 std::vector<G4String> commandGuidance;
0221 std::vector<G4ApplicationState> availabelStateList;
0222 };
0223
0224 #endif