| [821] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4UIcommand.hh,v 1.15 2006/06/29 19:08:05 gunter Exp $
|
|---|
| [1228] | 28 | // GEANT4 tag $Name: geant4-09-03 $
|
|---|
| [821] | 29 | //
|
|---|
| 30 | //
|
|---|
| 31 |
|
|---|
| 32 | #ifndef G4UIcommand_h
|
|---|
| 33 | #define G4UIcommand_h 1
|
|---|
| 34 |
|
|---|
| 35 | #include "G4UIparameter.hh"
|
|---|
| 36 | class G4UImessenger;
|
|---|
| 37 | #include "globals.hh"
|
|---|
| 38 | #include "G4ApplicationState.hh"
|
|---|
| 39 | #include <vector>
|
|---|
| 40 | #include "G4UItokenNum.hh"
|
|---|
| 41 | #include "G4ThreeVector.hh"
|
|---|
| 42 |
|
|---|
| 43 | // class description:
|
|---|
| 44 | //
|
|---|
| 45 | // This G4UIcommand is the "concrete" base class which represents a command
|
|---|
| 46 | // used by Geant4 (G)UI. The user can use this class in case the parameter
|
|---|
| 47 | // arguments of a command are not suitable with respect to the derived command
|
|---|
| 48 | // classes.
|
|---|
| 49 | // Some methods defined in this base class are used by the derived classes.
|
|---|
| 50 | //
|
|---|
| 51 |
|
|---|
| 52 | class G4UIcommand
|
|---|
| 53 | {
|
|---|
| 54 | public:
|
|---|
| 55 | G4UIcommand();
|
|---|
| 56 | public: // with description
|
|---|
| 57 | G4UIcommand(const char * theCommandPath, G4UImessenger * theMessenger);
|
|---|
| 58 | // Constructor. The command string with full path directory
|
|---|
| 59 | // and the pointer to the messenger must be given.
|
|---|
| 60 | public:
|
|---|
| 61 | virtual ~G4UIcommand();
|
|---|
| 62 |
|
|---|
| 63 | G4int operator==(const G4UIcommand &right) const;
|
|---|
| 64 | G4int operator!=(const G4UIcommand &right) const;
|
|---|
| 65 |
|
|---|
| 66 | G4int DoIt(G4String parameterList);
|
|---|
| 67 | G4String GetCurrentValue();
|
|---|
| 68 | public: // with description
|
|---|
| 69 | void AvailableForStates(G4ApplicationState s1);
|
|---|
| 70 | void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2);
|
|---|
| 71 | void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
|
|---|
| 72 | G4ApplicationState s3);
|
|---|
| 73 | void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
|
|---|
| 74 | G4ApplicationState s3,G4ApplicationState s4);
|
|---|
| 75 | void AvailableForStates(G4ApplicationState s1,G4ApplicationState s2,
|
|---|
| 76 | G4ApplicationState s3,G4ApplicationState s4,
|
|---|
| 77 | G4ApplicationState s5);
|
|---|
| 78 | // These methods define the states where the command is available.
|
|---|
| 79 | // Once one of these commands is invoked, the command application will
|
|---|
| 80 | // be denied when Geant4 is NOT in the assigned states.
|
|---|
| 81 | public:
|
|---|
| 82 | G4bool IsAvailable();
|
|---|
| 83 | virtual void List();
|
|---|
| 84 |
|
|---|
| 85 | public: // with description
|
|---|
| 86 | static G4String ConvertToString(G4bool boolVal);
|
|---|
| 87 | static G4String ConvertToString(G4int intValue);
|
|---|
| 88 | static G4String ConvertToString(G4double doubleValue);
|
|---|
| 89 | static G4String ConvertToString(G4double doubleValue,const char* unitName);
|
|---|
| 90 | static G4String ConvertToString(G4ThreeVector vec);
|
|---|
| 91 | static G4String ConvertToString(G4ThreeVector vec,const char* unitName);
|
|---|
| 92 | // Static methods for conversion from value(s) to a string. These methods are to be
|
|---|
| 93 | // used by GetCurrentValues() methods of concrete messengers.
|
|---|
| 94 |
|
|---|
| 95 | static G4bool ConvertToBool(const char* st);
|
|---|
| 96 | static G4int ConvertToInt(const char* st);
|
|---|
| 97 | static G4double ConvertToDouble(const char* st);
|
|---|
| 98 | static G4double ConvertToDimensionedDouble(const char* st);
|
|---|
| 99 | static G4ThreeVector ConvertTo3Vector(const char* st);
|
|---|
| 100 | static G4ThreeVector ConvertToDimensioned3Vector(const char* st);
|
|---|
| 101 | // Static methods for conversion from a string to a value of the returning type.
|
|---|
| 102 | // These methods are to be used directly by SetNewValues() methods of concrete
|
|---|
| 103 | // messengers, or GetNewXXXValue() of classes derived from this G4UIcommand class.
|
|---|
| 104 |
|
|---|
| 105 | static G4double ValueOf(const char* unitName);
|
|---|
| 106 | static G4String CategoryOf(const char* unitName);
|
|---|
| 107 | static G4String UnitsList(const char* unitCategory);
|
|---|
| 108 | // Static methods for unit and its category.
|
|---|
| 109 |
|
|---|
| 110 | private:
|
|---|
| 111 | void G4UIcommandCommonConstructorCode (const char * theCommandPath);
|
|---|
| 112 | G4UImessenger *messenger;
|
|---|
| 113 | G4String commandPath;
|
|---|
| 114 | G4String commandName;
|
|---|
| 115 | G4String rangeString;
|
|---|
| 116 | std::vector<G4UIparameter*> parameter;
|
|---|
| 117 | std::vector<G4String> commandGuidance;
|
|---|
| 118 | std::vector<G4ApplicationState> availabelStateList;
|
|---|
| 119 |
|
|---|
| 120 | public: // with description
|
|---|
| 121 | inline void SetRange(const char* rs)
|
|---|
| 122 | { rangeString = rs; }
|
|---|
| 123 | // Defines the range the command parameter(s) can take.
|
|---|
| 124 | // The variable name(s) appear in the range expression must be same
|
|---|
| 125 | // as the name(s) of the parameter(s).
|
|---|
| 126 | // All the C++ syntax of relational operators are allowed for the
|
|---|
| 127 | // range expression.
|
|---|
| 128 | public:
|
|---|
| 129 | inline const G4String & GetRange() const
|
|---|
| 130 | { return rangeString; };
|
|---|
| 131 | inline G4int GetGuidanceEntries() const
|
|---|
| 132 | { return commandGuidance.size(); }
|
|---|
| 133 | inline const G4String & GetGuidanceLine(G4int i) const
|
|---|
| 134 | { return commandGuidance[i]; }
|
|---|
| 135 | inline const G4String & GetCommandPath() const
|
|---|
| 136 | { return commandPath; }
|
|---|
| 137 | inline const G4String & GetCommandName() const
|
|---|
| 138 | { return commandName; }
|
|---|
| 139 | inline G4int GetParameterEntries() const
|
|---|
| 140 | { return parameter.size(); }
|
|---|
| 141 | inline G4UIparameter * GetParameter(G4int i) const
|
|---|
| 142 | { return parameter[i]; }
|
|---|
| 143 | inline std::vector<G4ApplicationState>* GetStateList()
|
|---|
| 144 | { return &availabelStateList; }
|
|---|
| 145 | public: // with description
|
|---|
| 146 | inline void SetParameter(G4UIparameter *const newParameter)
|
|---|
| 147 | {
|
|---|
| 148 | parameter.push_back( newParameter );
|
|---|
| 149 | newVal.resize( parameter.size() );
|
|---|
| 150 | }
|
|---|
| 151 | // Defines a parameter. This method is used by the derived command classes
|
|---|
| 152 | // but the user can directly use this command when he/she defines a command
|
|---|
| 153 | // by hem(her)self without using the derived class. For this case, the order
|
|---|
| 154 | // of the parameters is the order of invoking this method.
|
|---|
| 155 | inline void SetGuidance(const char * aGuidance)
|
|---|
| 156 | {
|
|---|
| 157 | commandGuidance.push_back( G4String( aGuidance ) );
|
|---|
| 158 | }
|
|---|
| 159 | // Adds a guidance line. Unlimitted number of invokation of this method is
|
|---|
| 160 | // allowed. The given lines of guidance will appear for the help. The first
|
|---|
| 161 | // line of the guidance will be used as the title of the command, i.e. one
|
|---|
| 162 | // line list of the commands.
|
|---|
| 163 | public:
|
|---|
| 164 | inline const G4String GetTitle() const
|
|---|
| 165 | {
|
|---|
| 166 | if(commandGuidance.size() == 0)
|
|---|
| 167 | { return G4String("...Title not available..."); }
|
|---|
| 168 | else
|
|---|
| 169 | { return commandGuidance[0]; }
|
|---|
| 170 | }
|
|---|
| 171 |
|
|---|
| 172 | protected:
|
|---|
| 173 | G4int CheckNewValue(const char* newValue);
|
|---|
| 174 |
|
|---|
| 175 | // --- the following is used by CheckNewValue() --------
|
|---|
| 176 | private:
|
|---|
| 177 | G4int TypeCheck(const char* t);
|
|---|
| 178 | G4int RangeCheck(const char* t);
|
|---|
| 179 | G4int IsInt(const char* str, short maxLength);
|
|---|
| 180 | G4int IsDouble(const char* str);
|
|---|
| 181 | G4int ExpectExponent(const char* str);
|
|---|
| 182 | // syntax nodes
|
|---|
| 183 | yystype Expression( void );
|
|---|
| 184 | yystype LogicalORExpression( void );
|
|---|
| 185 | yystype LogicalANDExpression( void );
|
|---|
| 186 | yystype EqualityExpression ( void );
|
|---|
| 187 | yystype RelationalExpression( void );
|
|---|
| 188 | yystype AdditiveExpression( void );
|
|---|
| 189 | yystype MultiplicativeExpression( void );
|
|---|
| 190 | yystype UnaryExpression( void );
|
|---|
| 191 | yystype PrimaryExpression( void );
|
|---|
| 192 | // semantics routines
|
|---|
| 193 | G4int Eval2( yystype arg1, G4int op, yystype arg2 );
|
|---|
| 194 | G4int CompareInt( G4int arg1, G4int op, G4int arg2);
|
|---|
| 195 | G4int CompareDouble( G4double arg1, G4int op, G4double arg2);
|
|---|
| 196 | // utility
|
|---|
| 197 | tokenNum Yylex( void ); // returns next token
|
|---|
| 198 | unsigned IndexOf( const char* ); // returns the index of the var name
|
|---|
| 199 | unsigned IsParameter( const char* ); // returns 1 or 0
|
|---|
| 200 | G4int G4UIpGetc( void ); // read one char from rangeBuf
|
|---|
| 201 | G4int G4UIpUngetc( G4int c ); // put back
|
|---|
| 202 | G4int Backslash( G4int c );
|
|---|
| 203 | G4int Follow( G4int expect, G4int ifyes, G4int ifno );
|
|---|
| 204 | G4String TokenToStr(G4int token);
|
|---|
| 205 | void PrintToken(void); // for debug
|
|---|
| 206 | // data
|
|---|
| 207 | G4String rangeBuf;
|
|---|
| 208 | G4int bp; // buffer pointer for rangeBuf
|
|---|
| 209 | tokenNum token;
|
|---|
| 210 | yystype yylval;
|
|---|
| 211 | std::vector<yystype> newVal;
|
|---|
| 212 | G4int paramERR;
|
|---|
| 213 | };
|
|---|
| 214 |
|
|---|
| 215 | #endif
|
|---|
| 216 |
|
|---|