[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: G4UIcontrolMessenger.cc,v 1.11 2007/06/06 15:14:51 asaim Exp $ |
---|
[1016] | 28 | // GEANT4 tag $Name: geant4-09-02 $ |
---|
[821] | 29 | // |
---|
| 30 | |
---|
| 31 | #include <stdlib.h> |
---|
| 32 | #include "G4UIcontrolMessenger.hh" |
---|
| 33 | #include "G4UImanager.hh" |
---|
| 34 | #include "G4UIdirectory.hh" |
---|
| 35 | #include "G4UIcommand.hh" |
---|
| 36 | #include "G4UIparameter.hh" |
---|
| 37 | #include "G4UIcmdWithAString.hh" |
---|
| 38 | #include "G4UIcmdWithAnInteger.hh" |
---|
| 39 | #include "G4UIcmdWithoutParameter.hh" |
---|
| 40 | #include "G4UIaliasList.hh" |
---|
| 41 | #include "G4StateManager.hh" |
---|
| 42 | #include "G4ios.hh" |
---|
| 43 | |
---|
| 44 | G4UIcontrolMessenger::G4UIcontrolMessenger() |
---|
| 45 | { |
---|
| 46 | controlDirectory = new G4UIdirectory("/control/"); |
---|
| 47 | controlDirectory->SetGuidance("UI control commands."); |
---|
| 48 | |
---|
| 49 | ExecuteCommand = new G4UIcmdWithAString("/control/execute",this); |
---|
| 50 | ExecuteCommand->SetGuidance("Execute a macro file."); |
---|
| 51 | ExecuteCommand->SetParameterName("fileName",false); |
---|
| 52 | |
---|
| 53 | loopCommand = new G4UIcommand("/control/loop",this); |
---|
| 54 | loopCommand->SetGuidance("Execute a macro file more than once."); |
---|
| 55 | loopCommand->SetGuidance("Loop counter can be used as an aliased variable."); |
---|
| 56 | G4UIparameter* param1 = new G4UIparameter("macroFile",'s',false); |
---|
| 57 | loopCommand->SetParameter(param1); |
---|
| 58 | G4UIparameter* param2 = new G4UIparameter("counterName",'s',false); |
---|
| 59 | loopCommand->SetParameter(param2); |
---|
| 60 | G4UIparameter* param3 = new G4UIparameter("initialValue",'d',false); |
---|
| 61 | loopCommand->SetParameter(param3); |
---|
| 62 | G4UIparameter* param4 = new G4UIparameter("finalValue",'d',false); |
---|
| 63 | loopCommand->SetParameter(param4); |
---|
| 64 | G4UIparameter* param5 = new G4UIparameter("stepSize",'d',true); |
---|
| 65 | param5->SetDefaultValue(1.0); |
---|
| 66 | loopCommand->SetParameter(param5); |
---|
| 67 | |
---|
| 68 | foreachCommand = new G4UIcommand("/control/foreach",this); |
---|
| 69 | foreachCommand->SetGuidance("Execute a macro file more than once."); |
---|
| 70 | foreachCommand->SetGuidance("Loop counter can be used as an aliased variable."); |
---|
| 71 | foreachCommand->SetGuidance("Values must be separated by a space."); |
---|
| 72 | G4UIparameter* param6 = new G4UIparameter("macroFile",'s',false); |
---|
| 73 | foreachCommand->SetParameter(param6); |
---|
| 74 | G4UIparameter* param7 = new G4UIparameter("counterName",'s',false); |
---|
| 75 | foreachCommand->SetParameter(param7); |
---|
| 76 | G4UIparameter* param8 = new G4UIparameter("valueList",'s',false); |
---|
| 77 | foreachCommand->SetParameter(param8); |
---|
| 78 | |
---|
| 79 | suppressAbortionCommand = new G4UIcmdWithAnInteger("/control/suppressAbortion",this); |
---|
| 80 | suppressAbortionCommand->SetGuidance("Suppress the program abortion caused by G4Exception."); |
---|
| 81 | suppressAbortionCommand->SetGuidance("Suppression level = 0 : no suppression"); |
---|
| 82 | suppressAbortionCommand->SetGuidance(" = 1 : suppress during EventProc state"); |
---|
| 83 | suppressAbortionCommand->SetGuidance(" = 2 : full suppression, i.e. no abortion by G4Exception"); |
---|
| 84 | suppressAbortionCommand->SetGuidance("When abortion is suppressed, you will get error messages issued by G4Exception,"); |
---|
| 85 | suppressAbortionCommand->SetGuidance("and there is NO guarantee for the correct result after the G4Exception error message."); |
---|
| 86 | suppressAbortionCommand->SetParameterName("level",true); |
---|
| 87 | suppressAbortionCommand->SetRange("level >= 0 && level <= 2"); |
---|
| 88 | suppressAbortionCommand->SetDefaultValue(0); |
---|
| 89 | |
---|
| 90 | verboseCommand = new G4UIcmdWithAnInteger("/control/verbose",this); |
---|
| 91 | verboseCommand->SetGuidance("Applied command will also be shown on screen."); |
---|
| 92 | verboseCommand->SetGuidance("This command is useful with MACRO file."); |
---|
| 93 | verboseCommand->SetGuidance(" 0 : silent"); |
---|
| 94 | verboseCommand->SetGuidance(" 1 : only the valid commands are shown."); |
---|
| 95 | verboseCommand->SetGuidance(" 2 : comment lines are also shown (default)."); |
---|
| 96 | verboseCommand->SetParameterName("switch",true); |
---|
| 97 | verboseCommand->SetRange("switch >= 0 && switch <=2"); |
---|
| 98 | verboseCommand->SetDefaultValue(2); |
---|
| 99 | |
---|
| 100 | historyCommand = new G4UIcmdWithAString("/control/saveHistory",this); |
---|
| 101 | historyCommand->SetGuidance("Store command history to a file."); |
---|
| 102 | historyCommand->SetGuidance("Defaul file name is G4history.macro."); |
---|
| 103 | historyCommand->SetParameterName("fileName",true); |
---|
| 104 | historyCommand->SetDefaultValue("G4History.macro"); |
---|
| 105 | |
---|
| 106 | stopStoreHistoryCommand |
---|
| 107 | = new G4UIcmdWithoutParameter("/control/stopSavingHistory",this); |
---|
| 108 | stopStoreHistoryCommand->SetGuidance("Stop saving history file."); |
---|
| 109 | |
---|
| 110 | aliasCommand = new G4UIcommand("/control/alias",this); |
---|
| 111 | aliasCommand->SetGuidance("Set an alias."); |
---|
| 112 | aliasCommand->SetGuidance("String can be aliased by this command."); |
---|
| 113 | aliasCommand->SetGuidance("The string may contain one or more spaces,"); |
---|
| 114 | aliasCommand->SetGuidance("the string must be enclosed by double quotes (\")."); |
---|
| 115 | aliasCommand->SetGuidance("To use an alias, enclose the alias name with"); |
---|
| 116 | aliasCommand->SetGuidance("parenthis \"{\" and \"}\"."); |
---|
| 117 | G4UIparameter* aliasNameParam = new G4UIparameter("aliasName",'s',false); |
---|
| 118 | aliasCommand->SetParameter(aliasNameParam); |
---|
| 119 | G4UIparameter* aliasValueParam = new G4UIparameter("aliasValue",'s',false); |
---|
| 120 | aliasCommand->SetParameter(aliasValueParam); |
---|
| 121 | |
---|
| 122 | unaliasCommand = new G4UIcmdWithAString("/control/unalias",this); |
---|
| 123 | unaliasCommand->SetGuidance("Remove an alias."); |
---|
| 124 | unaliasCommand->SetParameterName("aliasName",false); |
---|
| 125 | |
---|
| 126 | listAliasCommand = new G4UIcmdWithoutParameter("/control/listAlias",this); |
---|
| 127 | listAliasCommand->SetGuidance("List aliases."); |
---|
| 128 | |
---|
| 129 | getEnvCmd = new G4UIcmdWithAString("/control/getEnv",this); |
---|
| 130 | getEnvCmd->SetGuidance("Get a shell environment variable and define it as an alias."); |
---|
| 131 | |
---|
| 132 | echoCmd = new G4UIcmdWithAString("/control/echo",this); |
---|
| 133 | echoCmd->SetGuidance("Display the aliased value."); |
---|
| 134 | |
---|
| 135 | shellCommand = new G4UIcmdWithAString("/control/shell",this); |
---|
| 136 | shellCommand->SetGuidance("Execute a (Unix) SHELL command."); |
---|
| 137 | |
---|
| 138 | ManualCommand = new G4UIcmdWithAString("/control/manual",this); |
---|
| 139 | ManualCommand->SetGuidance("Display all of sub-directories and commands."); |
---|
| 140 | ManualCommand->SetGuidance("Directory path should be given by FULL-PATH."); |
---|
| 141 | ManualCommand->SetParameterName("dirPath",true); |
---|
| 142 | ManualCommand->SetDefaultValue("/"); |
---|
| 143 | |
---|
| 144 | HTMLCommand = new G4UIcmdWithAString("/control/createHTML",this); |
---|
| 145 | HTMLCommand->SetGuidance("Generate HTML files for all of sub-directories and commands."); |
---|
| 146 | HTMLCommand->SetGuidance("Directory path should be given by FULL-PATH."); |
---|
| 147 | HTMLCommand->SetParameterName("dirPath",true); |
---|
| 148 | HTMLCommand->SetDefaultValue("/"); |
---|
| 149 | |
---|
| 150 | maxStoredHistCommand = new G4UIcmdWithAnInteger("/control/maximumStoredHistory",this); |
---|
| 151 | maxStoredHistCommand->SetGuidance("Set maximum number of stored UI commands."); |
---|
| 152 | maxStoredHistCommand->SetParameterName("max",true); |
---|
| 153 | maxStoredHistCommand->SetDefaultValue(20); |
---|
| 154 | } |
---|
| 155 | |
---|
| 156 | G4UIcontrolMessenger::~G4UIcontrolMessenger() |
---|
| 157 | { |
---|
| 158 | delete ExecuteCommand; |
---|
| 159 | delete suppressAbortionCommand; |
---|
| 160 | delete verboseCommand; |
---|
| 161 | delete historyCommand; |
---|
| 162 | delete stopStoreHistoryCommand; |
---|
| 163 | delete ManualCommand; |
---|
| 164 | delete aliasCommand; |
---|
| 165 | delete unaliasCommand; |
---|
| 166 | delete listAliasCommand; |
---|
| 167 | delete getEnvCmd; |
---|
| 168 | delete echoCmd; |
---|
| 169 | delete shellCommand; |
---|
| 170 | delete loopCommand; |
---|
| 171 | delete foreachCommand; |
---|
| 172 | delete HTMLCommand; |
---|
| 173 | delete maxStoredHistCommand; |
---|
| 174 | delete controlDirectory; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | void G4UIcontrolMessenger::SetNewValue(G4UIcommand * command,G4String newValue) |
---|
| 178 | { |
---|
| 179 | G4UImanager * UI = G4UImanager::GetUIpointer(); |
---|
| 180 | |
---|
| 181 | if(command==ExecuteCommand) |
---|
| 182 | { |
---|
| 183 | UI->ExecuteMacroFile(newValue); |
---|
| 184 | } |
---|
| 185 | if(command==suppressAbortionCommand) |
---|
| 186 | { |
---|
| 187 | G4StateManager::GetStateManager()->SetSuppressAbortion(suppressAbortionCommand->GetNewIntValue(newValue)); |
---|
| 188 | } |
---|
| 189 | if(command==verboseCommand) |
---|
| 190 | { |
---|
| 191 | UI->SetVerboseLevel(verboseCommand->GetNewIntValue(newValue)); |
---|
| 192 | } |
---|
| 193 | if(command==historyCommand) |
---|
| 194 | { |
---|
| 195 | UI->StoreHistory(newValue); |
---|
| 196 | } |
---|
| 197 | if(command==stopStoreHistoryCommand) |
---|
| 198 | { |
---|
| 199 | UI->StoreHistory(false); |
---|
| 200 | } |
---|
| 201 | if(command==ManualCommand) |
---|
| 202 | { |
---|
| 203 | UI->ListCommands(newValue); |
---|
| 204 | } |
---|
| 205 | if(command==aliasCommand) |
---|
| 206 | { |
---|
| 207 | UI->SetAlias(newValue); |
---|
| 208 | } |
---|
| 209 | if(command==unaliasCommand) |
---|
| 210 | { |
---|
| 211 | UI->RemoveAlias(newValue); |
---|
| 212 | } |
---|
| 213 | if(command==listAliasCommand) |
---|
| 214 | { |
---|
| 215 | UI->ListAlias(); |
---|
| 216 | } |
---|
| 217 | if(command==getEnvCmd) |
---|
| 218 | { |
---|
| 219 | if(getenv(newValue)) |
---|
| 220 | { |
---|
| 221 | G4String st = "/control/alias "; |
---|
| 222 | st += newValue; |
---|
| 223 | st += " "; |
---|
| 224 | st += getenv(newValue); |
---|
| 225 | UI->ApplyCommand(st); |
---|
| 226 | } |
---|
| 227 | else |
---|
| 228 | { G4cerr << "<" << newValue << "> is not defined as a shell variable. Command ignored." << G4endl; } |
---|
| 229 | } |
---|
| 230 | if(command==echoCmd) |
---|
| 231 | { G4cout << UI->SolveAlias(newValue) << G4endl; } |
---|
| 232 | if(command==shellCommand) |
---|
| 233 | { |
---|
| 234 | system(newValue); |
---|
| 235 | } |
---|
| 236 | if(command==loopCommand) |
---|
| 237 | { |
---|
| 238 | UI->LoopS(newValue); |
---|
| 239 | } |
---|
| 240 | if(command==foreachCommand) |
---|
| 241 | { |
---|
| 242 | UI->ForeachS(newValue); |
---|
| 243 | } |
---|
| 244 | if(command==HTMLCommand) |
---|
| 245 | { |
---|
| 246 | UI->CreateHTML(newValue); |
---|
| 247 | } |
---|
| 248 | if(command==maxStoredHistCommand) |
---|
| 249 | { |
---|
| 250 | UI->SetMaxHistSize(maxStoredHistCommand->GetNewIntValue(newValue)); |
---|
| 251 | } |
---|
| 252 | |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | G4String G4UIcontrolMessenger::GetCurrentValue(G4UIcommand * command) |
---|
| 256 | { |
---|
| 257 | G4UImanager * UI = G4UImanager::GetUIpointer(); |
---|
| 258 | G4String currentValue; |
---|
| 259 | |
---|
| 260 | if(command==verboseCommand) |
---|
| 261 | { |
---|
| 262 | currentValue = verboseCommand->ConvertToString(UI->GetVerboseLevel()); |
---|
| 263 | } |
---|
| 264 | if(command==suppressAbortionCommand) |
---|
| 265 | { |
---|
| 266 | currentValue = suppressAbortionCommand->ConvertToString(G4StateManager::GetStateManager()->GetSuppressAbortion()); |
---|
| 267 | } |
---|
| 268 | if(command==maxStoredHistCommand) |
---|
| 269 | { |
---|
| 270 | currentValue = maxStoredHistCommand->ConvertToString(UI->GetMaxHistSize()); |
---|
| 271 | } |
---|
| 272 | |
---|
| 273 | return currentValue; |
---|
| 274 | } |
---|
| 275 | |
---|
| 276 | |
---|