Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4UIcommand << 27 // 26 // 28 // Class description: << 27 // $Id$ >> 28 // 29 // 29 // 30 // This G4UIcommand is the "concrete" base cla << 31 // used by Geant4 (G)UI. The user can use this << 32 // arguments of a command are not suitable wit << 33 // classes. << 34 // Some methods defined in this base class are << 35 30 36 // Author: Makoto Asai (SLAC), 1998 << 31 #ifndef G4UIcommand_h 37 // ------------------------------------------- << 32 #define G4UIcommand_h 1 38 #ifndef G4UIcommand_hh << 39 #define G4UIcommand_hh 1 << 40 33 41 #include "G4ApplicationState.hh" << 42 #include "G4ThreeVector.hh" << 43 #include "G4UIparameter.hh" 34 #include "G4UIparameter.hh" >> 35 class G4UImessenger; 44 #include "globals.hh" 36 #include "globals.hh" 45 << 37 #include "G4ApplicationState.hh" 46 #include <vector> 38 #include <vector> >> 39 #include "G4UItokenNum.hh" >> 40 #include "G4ThreeVector.hh" 47 41 48 class G4UImessenger; << 42 // class description: >> 43 // >> 44 // This G4UIcommand is the "concrete" base class which represents a command >> 45 // used by Geant4 (G)UI. The user can use this class in case the parameter >> 46 // arguments of a command are not suitable with respect to the derived command >> 47 // classes. >> 48 // Some methods defined in this base class are used by the derived classes. >> 49 // 49 50 50 class G4UIcommand 51 class G4UIcommand 51 { 52 { 52 public: 53 public: 53 // Dummy default constructor << 54 G4UIcommand(); 54 G4UIcommand() = default; << 55 public: // with description >> 56 G4UIcommand(const char * theCommandPath, G4UImessenger * theMessenger, >> 57 G4bool tBB = true); >> 58 // Constructor. The command string with full path directory >> 59 // and the pointer to the messenger must be given. >> 60 // If tBB is set to false, this command won't be sent to worker threads. >> 61 // This tBB parameter could be changed with SetToBeBroadcasted() method >> 62 // except for G4UIdirectory. 55 63 56 // Constructor. The command string with fu << 64 public: 57 // and the pointer to the messenger must b << 65 virtual ~G4UIcommand(); 58 // If tBB is set to false, this command wo << 59 // This tBB parameter could be changed wit << 60 // except for G4UIdirectory << 61 G4UIcommand(const char* theCommandPath, G4 << 62 << 63 virtual ~G4UIcommand(); << 64 << 65 G4bool operator==(const G4UIcommand& right << 66 G4bool operator!=(const G4UIcommand& right << 67 << 68 virtual G4int DoIt(const G4String& paramet << 69 << 70 G4String GetCurrentValue(); << 71 << 72 // These methods define the states where t << 73 // Once one of these commands is invoked, << 74 // be denied when Geant4 is NOT in the ass << 75 void AvailableForStates(G4ApplicationState << 76 void AvailableForStates(G4ApplicationState << 77 void AvailableForStates(G4ApplicationState << 78 void AvailableForStates(G4ApplicationState << 79 G4ApplicationState << 80 void AvailableForStates(G4ApplicationState << 81 G4ApplicationState << 82 << 83 G4bool IsAvailable(); << 84 << 85 virtual void List(); << 86 << 87 // Static methods for conversion from valu << 88 // These methods are to be used by GetCurr << 89 // of concrete messengers << 90 static G4String ConvertToString(G4bool boo << 91 static G4String ConvertToString(G4int intV << 92 static G4String ConvertToString(G4long lon << 93 static G4String ConvertToString(G4double d << 94 static G4String ConvertToString(G4double d << 95 static G4String ConvertToString(const G4Th << 96 static G4String ConvertToString(const G4Th << 97 << 98 // Static methods for conversion from a st << 99 // type. These methods are to be used dire << 100 // of concrete messengers, or GetNewXXXVal << 101 // this G4UIcommand class << 102 static G4bool ConvertToBool(const char* st << 103 static G4int ConvertToInt(const char* st); << 104 static G4long ConvertToLongInt(const char* << 105 static G4double ConvertToDouble(const char << 106 static G4double ConvertToDimensionedDouble << 107 static G4ThreeVector ConvertTo3Vector(cons << 108 static G4ThreeVector ConvertToDimensioned3 << 109 << 110 // Static methods for unit and its categor << 111 static G4double ValueOf(const char* unitNa << 112 static G4String CategoryOf(const char* uni << 113 static G4String UnitsList(const char* unit << 114 << 115 // Defines the range the command parameter << 116 // The variable name(s) appear in the rang << 117 // as the name(s) of the parameter(s). << 118 // All the C++ syntax of relational operat << 119 // range expression << 120 inline void SetRange(const char* rs) { ran << 121 << 122 inline const G4String& GetRange() const { << 123 inline std::size_t GetGuidanceEntries() co << 124 inline const G4String& GetGuidanceLine(G4i << 125 inline const G4String& GetCommandPath() co << 126 inline const G4String& GetCommandName() co << 127 inline std::size_t GetParameterEntries() c << 128 inline G4UIparameter* GetParameter(G4int i << 129 inline std::vector<G4ApplicationState>* Ge << 130 inline G4UImessenger* GetMessenger() const << 131 << 132 // Defines a parameter. This method is use << 133 // classes but the user can directly use t << 134 // a command, without using the derived cl << 135 // of the parameters is the order of invok << 136 inline void SetParameter(G4UIparameter* co << 137 { << 138 parameter.push_back(newParameter); << 139 } << 140 << 141 // Adds a guidance line. Unlimited times o << 142 // allowed. The given lines of guidance wi << 143 // The first line of the guidance will be << 144 // command, i.e. one line list of the comm << 145 inline void SetGuidance(const char* aGuida << 146 << 147 inline const G4String GetTitle() const << 148 { << 149 return (commandGuidance.empty()) ? G4Str << 150 } << 151 << 152 inline void SetToBeBroadcasted(G4bool val) << 153 inline G4bool ToBeBroadcasted() const { re << 154 inline void SetToBeFlushed(G4bool val) { t << 155 inline G4bool ToBeFlushed() const { return << 156 inline void SetWorkerThreadOnly(G4bool val << 157 inline G4bool IsWorkerThreadOnly() const { << 158 << 159 inline void CommandFailed(G4int errCode, G << 160 { << 161 commandFailureCode = errCode; << 162 failureDescription = ed.str(); << 163 } << 164 inline void CommandFailed(G4ExceptionDescr << 165 { << 166 commandFailureCode = 1; << 167 failureDescription = ed.str(); << 168 } << 169 inline G4int IfCommandFailed() { return co << 170 inline const G4String& GetFailureDescripti << 171 inline void ResetFailure() << 172 { << 173 commandFailureCode = 0; << 174 failureDescription = ""; << 175 } << 176 << 177 public: << 178 enum CommandType << 179 { << 180 BaseClassCmd, << 181 WithoutParameterCmd, << 182 WithABoolCmd, << 183 WithAnIntegerCmd, << 184 WithALongIntCmd, << 185 WithADoubleCmd, << 186 WithADoubleAndUnitCmd, << 187 With3VectorCmd, << 188 With3VectorAndUnitCmd, << 189 WithAStringCmd, << 190 CmdDirectory = -1 << 191 }; << 192 66 193 inline CommandType GetCommandType() const << 67 G4int operator==(const G4UIcommand &right) const; 194 void SetCommandType(CommandType); << 68 G4int operator!=(const G4UIcommand &right) const; 195 69 196 inline void SetDefaultSortFlag(G4bool val) << 70 virtual G4int DoIt(G4String parameterList); >> 71 G4String GetCurrentValue(); >> 72 public: // with description >> 73 void AvailableForStates(G4ApplicationState s1); >> 74 void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2); >> 75 void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2, >> 76 G4ApplicationState s3); >> 77 void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2, >> 78 G4ApplicationState s3,G4ApplicationState s4); >> 79 void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2, >> 80 G4ApplicationState s3,G4ApplicationState s4, >> 81 G4ApplicationState s5); >> 82 // These methods define the states where the command is available. >> 83 // Once one of these commands is invoked, the command application will >> 84 // be denied when Geant4 is NOT in the assigned states. >> 85 public: >> 86 G4bool IsAvailable(); >> 87 virtual void List(); 197 88 198 protected: << 89 public: // with description 199 G4int CheckNewValue(const char* newValue); << 90 static G4String ConvertToString(G4bool boolVal); >> 91 static G4String ConvertToString(G4int intValue); >> 92 static G4String ConvertToString(G4double doubleValue); >> 93 static G4String ConvertToString(G4double doubleValue,const char* unitName); >> 94 static G4String ConvertToString(G4ThreeVector vec); >> 95 static G4String ConvertToString(G4ThreeVector vec,const char* unitName); >> 96 // Static methods for conversion from value(s) to a string. These methods are to be >> 97 // used by GetCurrentValues() methods of concrete messengers. >> 98 >> 99 static G4bool ConvertToBool(const char* st); >> 100 static G4int ConvertToInt(const char* st); >> 101 static G4double ConvertToDouble(const char* st); >> 102 static G4double ConvertToDimensionedDouble(const char* st); >> 103 static G4ThreeVector ConvertTo3Vector(const char* st); >> 104 static G4ThreeVector ConvertToDimensioned3Vector(const char* st); >> 105 // Static methods for conversion from a string to a value of the returning type. >> 106 // These methods are to be used directly by SetNewValues() methods of concrete >> 107 // messengers, or GetNewXXXValue() of classes derived from this G4UIcommand class. >> 108 >> 109 static G4double ValueOf(const char* unitName); >> 110 static G4String CategoryOf(const char* unitName); >> 111 static G4String UnitsList(const char* unitCategory); >> 112 // Static methods for unit and its category. 200 113 201 G4bool toBeBroadcasted = false; << 114 private: 202 G4bool toBeFlushed = false; << 115 void G4UIcommandCommonConstructorCode (const char * theCommandPath); 203 G4bool workerThreadOnly = false; << 116 G4UImessenger *messenger; >> 117 G4String commandPath; >> 118 G4String commandName; >> 119 G4String rangeString; >> 120 std::vector<G4UIparameter*> parameter; >> 121 std::vector<G4String> commandGuidance; >> 122 std::vector<G4ApplicationState> availabelStateList; >> 123 >> 124 public: // with description >> 125 inline void SetRange(const char* rs) >> 126 { rangeString = rs; } >> 127 // Defines the range the command parameter(s) can take. >> 128 // The variable name(s) appear in the range expression must be same >> 129 // as the name(s) of the parameter(s). >> 130 // All the C++ syntax of relational operators are allowed for the >> 131 // range expression. >> 132 public: >> 133 inline const G4String & GetRange() const >> 134 { return rangeString; }; >> 135 inline G4int GetGuidanceEntries() const >> 136 { return commandGuidance.size(); } >> 137 inline const G4String & GetGuidanceLine(G4int i) const >> 138 { return commandGuidance[i]; } >> 139 inline const G4String & GetCommandPath() const >> 140 { return commandPath; } >> 141 inline const G4String & GetCommandName() const >> 142 { return commandName; } >> 143 inline G4int GetParameterEntries() const >> 144 { return parameter.size(); } >> 145 inline G4UIparameter * GetParameter(G4int i) const >> 146 { return parameter[i]; } >> 147 inline std::vector<G4ApplicationState>* GetStateList() >> 148 { return &availabelStateList; } >> 149 inline G4UImessenger * GetMessenger() const >> 150 { return messenger; } >> 151 public: // with description >> 152 inline void SetParameter(G4UIparameter *const newParameter) >> 153 { >> 154 parameter.push_back( newParameter ); >> 155 newVal.resize( parameter.size() ); >> 156 } >> 157 // Defines a parameter. This method is used by the derived command classes >> 158 // but the user can directly use this command when he/she defines a command >> 159 // by hem(her)self without using the derived class. For this case, the order >> 160 // of the parameters is the order of invoking this method. >> 161 inline void SetGuidance(const char * aGuidance) >> 162 { >> 163 commandGuidance.push_back( G4String( aGuidance ) ); >> 164 } >> 165 // Adds a guidance line. Unlimitted number of invokation of this method is >> 166 // allowed. The given lines of guidance will appear for the help. The first >> 167 // line of the guidance will be used as the title of the command, i.e. one >> 168 // line list of the commands. >> 169 public: >> 170 inline const G4String GetTitle() const >> 171 { >> 172 if(commandGuidance.size() == 0) >> 173 { return G4String("...Title not available..."); } >> 174 else >> 175 { return commandGuidance[0]; } >> 176 } 204 177 205 G4int commandFailureCode = 0; << 178 protected: 206 G4String failureDescription = ""; << 179 G4bool toBeBroadcasted; >> 180 G4bool toBeFlushed; >> 181 G4bool workerThreadOnly; 207 182 208 G4bool ifSort = false; << 183 public: >> 184 inline void SetToBeBroadcasted(G4bool val) >> 185 { toBeBroadcasted = val; } >> 186 inline G4bool ToBeBroadcasted() const >> 187 { return toBeBroadcasted; } >> 188 inline void SetToBeFlushed(G4bool val) >> 189 { toBeFlushed = val; } >> 190 inline G4bool ToBeFlushed() const >> 191 { return toBeFlushed; } >> 192 inline void SetWorkerThreadOnly(G4bool val=true) >> 193 { workerThreadOnly = val; } >> 194 inline G4bool IsWorkerThreadOnly() const >> 195 { return workerThreadOnly; } 209 196 210 private: << 197 protected: 211 void G4UIcommandCommonConstructorCode(cons << 198 G4int commandFailureCode; >> 199 G4String failureDescription; >> 200 >> 201 public: >> 202 inline void CommandFailed( G4int errCode, G4ExceptionDescription& ed ) >> 203 { commandFailureCode = errCode; failureDescription = ed.str(); } >> 204 inline void CommandFailed( G4ExceptionDescription& ed ) >> 205 { commandFailureCode = 1; failureDescription = ed.str(); } >> 206 inline G4int IfCommandFailed() >> 207 { return commandFailureCode; } >> 208 inline G4String& GetFailureDescription() >> 209 { return failureDescription; } >> 210 inline void ResetFailure() >> 211 { commandFailureCode = 0; failureDescription = ""; } >> 212 >> 213 protected: >> 214 G4int CheckNewValue(const char* newValue); 212 215 >> 216 // --- the following is used by CheckNewValue() -------- 213 private: 217 private: 214 CommandType commandType = BaseClassCmd; << 218 G4int TypeCheck(const char* t); 215 G4UImessenger* messenger = nullptr; << 219 G4int RangeCheck(const char* t); 216 G4String commandPath; << 220 G4int IsInt(const char* str, short maxLength); 217 G4String commandName; << 221 G4int IsDouble(const char* str); 218 G4String rangeExpression; << 222 G4int ExpectExponent(const char* str); 219 std::vector<G4UIparameter*> parameter; << 223 // syntax nodes 220 std::vector<G4String> commandGuidance; << 224 yystype Expression( void ); 221 std::vector<G4ApplicationState> availabelS << 225 yystype LogicalORExpression( void ); >> 226 yystype LogicalANDExpression( void ); >> 227 yystype EqualityExpression ( void ); >> 228 yystype RelationalExpression( void ); >> 229 yystype AdditiveExpression( void ); >> 230 yystype MultiplicativeExpression( void ); >> 231 yystype UnaryExpression( void ); >> 232 yystype PrimaryExpression( void ); >> 233 // semantics routines >> 234 G4int Eval2( yystype arg1, G4int op, yystype arg2 ); >> 235 G4int CompareInt( G4int arg1, G4int op, G4int arg2); >> 236 G4int CompareDouble( G4double arg1, G4int op, G4double arg2); >> 237 // utility >> 238 tokenNum Yylex( void ); // returns next token >> 239 unsigned IndexOf( const char* ); // returns the index of the var name >> 240 unsigned IsParameter( const char* ); // returns 1 or 0 >> 241 G4int G4UIpGetc( void ); // read one char from rangeBuf >> 242 G4int G4UIpUngetc( G4int c ); // put back >> 243 G4int Backslash( G4int c ); >> 244 G4int Follow( G4int expect, G4int ifyes, G4int ifno ); >> 245 G4String TokenToStr(G4int token); >> 246 void PrintToken(void); // for debug >> 247 // data >> 248 G4String rangeBuf; >> 249 G4int bp; // buffer pointer for rangeBuf >> 250 tokenNum token; >> 251 yystype yylval; >> 252 std::vector<yystype> newVal; >> 253 G4int paramERR; 222 }; 254 }; 223 255 224 #endif 256 #endif >> 257 225 258