[531] | 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 | // |
---|
[944] | 27 | // $Id: G4VisCommands.cc,v 1.24 2009/03/09 12:42:00 allison Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
[531] | 29 | |
---|
| 30 | // /vis/ top level commands - John Allison 5th February 2001 |
---|
| 31 | |
---|
| 32 | #include "G4VisCommands.hh" |
---|
| 33 | |
---|
| 34 | #include "G4VisManager.hh" |
---|
| 35 | #include "G4UImanager.hh" |
---|
| 36 | #include "G4UIcmdWithABool.hh" |
---|
| 37 | #include "G4UIcmdWithAString.hh" |
---|
| 38 | #include "G4UIcmdWithoutParameter.hh" |
---|
| 39 | #include "G4RunManager.hh" |
---|
| 40 | #include "G4Run.hh" |
---|
| 41 | #include "G4UIsession.hh" |
---|
| 42 | |
---|
[593] | 43 | ////////////// /vis/abortReviewKeptEvents ///////////////////////////// |
---|
| 44 | |
---|
| 45 | G4VisCommandAbortReviewKeptEvents::G4VisCommandAbortReviewKeptEvents () { |
---|
| 46 | G4bool omitable; |
---|
| 47 | |
---|
| 48 | fpCommand = new G4UIcmdWithABool("/vis/abortReviewKeptEvents", this); |
---|
| 49 | fpCommand -> SetGuidance("Abort review of kept events."); |
---|
| 50 | fpCommand -> SetParameterName("abort", omitable=true); |
---|
| 51 | fpCommand -> SetDefaultValue(true); |
---|
| 52 | } |
---|
| 53 | |
---|
| 54 | G4VisCommandAbortReviewKeptEvents::~G4VisCommandAbortReviewKeptEvents () { |
---|
| 55 | delete fpCommand; |
---|
| 56 | } |
---|
| 57 | |
---|
| 58 | G4String G4VisCommandAbortReviewKeptEvents::GetCurrentValue (G4UIcommand*) { |
---|
| 59 | return G4String(); |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | void G4VisCommandAbortReviewKeptEvents::SetNewValue (G4UIcommand*, |
---|
| 63 | G4String newValue) { |
---|
| 64 | fpVisManager->SetAbortReviewKeptEvents(G4UIcommand::ConvertToBool(newValue)); |
---|
| 65 | G4cout << "Type \"continue\" to complete the abort." << G4endl; |
---|
| 66 | } |
---|
| 67 | |
---|
[531] | 68 | ////////////// /vis/enable /////////////////////////////////////// |
---|
| 69 | |
---|
| 70 | G4VisCommandEnable::G4VisCommandEnable () { |
---|
| 71 | G4bool omitable; |
---|
| 72 | |
---|
| 73 | fpCommand = new G4UIcmdWithABool("/vis/enable", this); |
---|
| 74 | fpCommand -> SetGuidance("Enables/disables visualization system."); |
---|
| 75 | fpCommand -> SetParameterName("enabled", omitable=true); |
---|
| 76 | fpCommand -> SetDefaultValue(true); |
---|
| 77 | |
---|
| 78 | fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this); |
---|
| 79 | fpCommand1 -> SetGuidance("Disables visualization system."); |
---|
| 80 | } |
---|
| 81 | |
---|
| 82 | G4VisCommandEnable::~G4VisCommandEnable () { |
---|
| 83 | delete fpCommand; |
---|
| 84 | delete fpCommand1; |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | G4String G4VisCommandEnable::GetCurrentValue (G4UIcommand*) { |
---|
| 88 | return G4String(); |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | void G4VisCommandEnable::SetNewValue (G4UIcommand* command, |
---|
| 92 | G4String newValue) { |
---|
| 93 | if (command == fpCommand) { |
---|
| 94 | G4bool enable = G4UIcommand::ConvertToBool(newValue); |
---|
| 95 | if (enable) fpVisManager->Enable(); // Printing is in vis manager. |
---|
| 96 | else fpVisManager->Disable(); // Printing is in vis manager. |
---|
| 97 | } else fpVisManager->Disable(); // Printing is in vis manager. |
---|
| 98 | // Note: Printing is in vis manager. |
---|
| 99 | } |
---|
| 100 | |
---|
[944] | 101 | ////////////// /vis/initialize /////////////////////////////////////// |
---|
| 102 | |
---|
| 103 | G4VisCommandInitialize::G4VisCommandInitialize () |
---|
| 104 | { |
---|
| 105 | fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this); |
---|
| 106 | fpCommand -> SetGuidance("Initialise visualisation manager."); |
---|
| 107 | } |
---|
| 108 | |
---|
| 109 | G4VisCommandInitialize::~G4VisCommandInitialize () { |
---|
| 110 | delete fpCommand; |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | void G4VisCommandInitialize::SetNewValue (G4UIcommand*, |
---|
| 114 | G4String) { |
---|
| 115 | fpVisManager->Initialize(); |
---|
| 116 | } |
---|
| 117 | |
---|
[531] | 118 | ////////////// /vis/list /////////////////////////////////////// |
---|
| 119 | |
---|
| 120 | G4VisCommandList::G4VisCommandList () |
---|
| 121 | { |
---|
| 122 | G4bool omitable; |
---|
| 123 | |
---|
| 124 | fpCommand = new G4UIcmdWithAString("/vis/list", this); |
---|
| 125 | fpCommand -> SetGuidance("Lists visualization parameters."); |
---|
| 126 | fpCommand -> SetParameterName("verbosity", omitable=true); |
---|
| 127 | fpCommand -> SetDefaultValue("warnings"); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | G4VisCommandList::~G4VisCommandList () |
---|
| 131 | { |
---|
| 132 | delete fpCommand; |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | G4String G4VisCommandList::GetCurrentValue (G4UIcommand*) |
---|
| 136 | { |
---|
| 137 | return ""; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | void G4VisCommandList::SetNewValue (G4UIcommand*, G4String newValue) |
---|
| 141 | { |
---|
| 142 | G4String& verbosityString = newValue; |
---|
| 143 | G4VisManager::Verbosity verbosity = |
---|
| 144 | fpVisManager->GetVerbosityValue(verbosityString); |
---|
| 145 | |
---|
| 146 | fpVisManager->PrintAvailableGraphicsSystems(); |
---|
| 147 | G4cout << G4endl; |
---|
| 148 | fpVisManager->PrintAvailableModels(verbosity); |
---|
| 149 | G4cout << G4endl; |
---|
| 150 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
| 151 | UImanager->ApplyCommand(G4String("/vis/viewer/list ! ") + verbosityString); |
---|
| 152 | if (verbosity < G4VisManager::parameters) |
---|
| 153 | G4cout << |
---|
| 154 | "\nTo get more information, \"/vis/list all all\" or use individual commands" |
---|
| 155 | "\n such as (use \"ls\" or \"help\"):" |
---|
| 156 | "\n /vis/viewer/list" |
---|
| 157 | "\n /vis/modeling/trajectories/list" |
---|
| 158 | "\n /vis/filtering/trajectories/list" |
---|
| 159 | << G4endl; |
---|
| 160 | } |
---|
| 161 | |
---|
| 162 | ////////////// /vis/reviewKeptEvents /////////////////////////////////////// |
---|
| 163 | |
---|
| 164 | G4VisCommandReviewKeptEvents::G4VisCommandReviewKeptEvents () |
---|
| 165 | { |
---|
| 166 | G4bool omitable; |
---|
| 167 | |
---|
| 168 | fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this); |
---|
| 169 | fpCommand -> SetGuidance("Review kept events."); |
---|
| 170 | fpCommand -> SetGuidance |
---|
| 171 | ("If a macro file is specified, it is executed for each event."); |
---|
[593] | 172 | fpCommand -> SetGuidance( |
---|
| 173 | "If a macro file is not specified, each event is drawn to the current" |
---|
| 174 | "\nviewer. After each event, the session is paused. The user may issue" |
---|
| 175 | "\nany allowed command. Then enter \"cont[inue]\" to continue to the next" |
---|
| 176 | "\nevent." |
---|
| 177 | "\nUseful commands might be:" |
---|
| 178 | "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)." |
---|
| 179 | "\n \"/vis/oglx/printEPS\" to get hard copy." |
---|
| 180 | "\n \"/vis/open\" to get alternative viewer." |
---|
| 181 | "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."); |
---|
[531] | 182 | fpCommand -> SetParameterName("macro-file-name", omitable=true); |
---|
| 183 | fpCommand -> SetDefaultValue(""); |
---|
| 184 | } |
---|
| 185 | |
---|
| 186 | G4VisCommandReviewKeptEvents::~G4VisCommandReviewKeptEvents () |
---|
| 187 | { |
---|
| 188 | delete fpCommand; |
---|
| 189 | } |
---|
| 190 | |
---|
| 191 | G4String G4VisCommandReviewKeptEvents::GetCurrentValue (G4UIcommand*) |
---|
| 192 | { |
---|
| 193 | return ""; |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | void G4VisCommandReviewKeptEvents::SetNewValue (G4UIcommand*, G4String newValue) |
---|
| 197 | { |
---|
[849] | 198 | static bool reviewing = false; |
---|
| 199 | if (reviewing) { |
---|
| 200 | G4cout << |
---|
| 201 | "\"/vis/reviewKeptEvents\" not allowed within an already started review." |
---|
| 202 | "\n No action taken." |
---|
| 203 | << G4endl; |
---|
| 204 | return; |
---|
| 205 | } |
---|
| 206 | |
---|
[531] | 207 | G4String& macroFileName = newValue; |
---|
| 208 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 209 | |
---|
| 210 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 211 | const G4Run* run = runManager? runManager->GetCurrentRun(): 0; |
---|
| 212 | const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0; |
---|
| 213 | size_t nKeptEvents = events? events->size(): 0; |
---|
| 214 | |
---|
| 215 | if (!nKeptEvents) { |
---|
| 216 | if (verbosity >= G4VisManager::errors) { |
---|
| 217 | G4cout << |
---|
| 218 | "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events," |
---|
| 219 | "\n or kept events not accessible." |
---|
| 220 | << G4endl; |
---|
| 221 | } |
---|
| 222 | return; |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | G4VViewer* viewer = fpVisManager->GetCurrentViewer(); |
---|
| 226 | if (!viewer) { |
---|
| 227 | if (verbosity >= G4VisManager::errors) { |
---|
| 228 | G4cout << |
---|
| 229 | "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities." |
---|
| 230 | << G4endl; |
---|
| 231 | } |
---|
| 232 | return; |
---|
| 233 | } |
---|
| 234 | |
---|
| 235 | G4Scene* pScene = fpVisManager->GetCurrentScene(); |
---|
| 236 | if (!pScene) { |
---|
| 237 | if (verbosity >= G4VisManager::errors) { |
---|
| 238 | G4cout << "ERROR: No current scene. Please create one." << G4endl; |
---|
| 239 | } |
---|
| 240 | return; |
---|
| 241 | } |
---|
| 242 | |
---|
| 243 | G4UImanager* UImanager = G4UImanager::GetUIpointer(); |
---|
| 244 | G4int keepVerbose = UImanager->GetVerboseLevel(); |
---|
| 245 | G4int newVerbose(0); |
---|
| 246 | if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations) |
---|
| 247 | newVerbose = 2; |
---|
| 248 | UImanager->SetVerboseLevel(newVerbose); |
---|
| 249 | |
---|
| 250 | // Event by event refreshing... |
---|
[849] | 251 | reviewing = true; |
---|
[531] | 252 | G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent(); |
---|
| 253 | pScene->SetRefreshAtEndOfEvent(true); |
---|
| 254 | if (macroFileName.empty()) { |
---|
| 255 | |
---|
| 256 | // Draw to viewer and pause session... |
---|
[593] | 257 | G4UIsession* session = UImanager->GetSession(); |
---|
[531] | 258 | for (size_t i = 0; i < nKeptEvents; ++i) { |
---|
| 259 | const G4Event* event = (*events)[i]; |
---|
| 260 | if (verbosity >= G4VisManager::warnings) { |
---|
| 261 | G4cout << "Drawing event : " << event->GetEventID() << |
---|
[593] | 262 | ". At EndOfEvent, enter any command, then \"cont[inue]\"..." |
---|
[531] | 263 | << G4endl; |
---|
[593] | 264 | static G4bool first = true; |
---|
| 265 | if (first) { |
---|
| 266 | first = false; |
---|
| 267 | G4cout << |
---|
| 268 | " Useful commands might be:" |
---|
| 269 | "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)." |
---|
| 270 | "\n \"/vis/oglx/printEPS\" to get hard copy." |
---|
| 271 | "\n \"/vis/open\" to get alternative viewer." |
---|
| 272 | "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort." |
---|
| 273 | << G4endl; |
---|
| 274 | } |
---|
[531] | 275 | } |
---|
[593] | 276 | fpVisManager->SetRequestedEvent(event); |
---|
[531] | 277 | UImanager->ApplyCommand("/vis/viewer/rebuild"); |
---|
| 278 | /* The above command forces a rebuild of the scene, including |
---|
| 279 | the detector. This is fine for "immediate" viewers - a |
---|
| 280 | refresh requires a rebuild anyway. But for "stored mode" |
---|
| 281 | viewers, you could, in principle, avoid a rebuild of the |
---|
| 282 | detector with something like the following: |
---|
| 283 | sceneHandler->ClearTransientStore(); |
---|
| 284 | viewer->DrawView(); |
---|
| 285 | sceneHandler->DrawEvent(event); |
---|
| 286 | but this causes mayhem for "immediate" viewers because |
---|
| 287 | ClearTransientStore issues a DrawView and some curious sort |
---|
| 288 | of recursion takes place. For "stored" viewers, the event |
---|
| 289 | gets drawn but not the eventID, so something odd is happening |
---|
| 290 | there too. This needs further investigation - enhanced |
---|
| 291 | features or a complete re-think. |
---|
| 292 | */ |
---|
[593] | 293 | UImanager->ApplyCommand("/vis/viewer/flush"); |
---|
[531] | 294 | session->PauseSessionStart("EndOfEvent"); |
---|
[593] | 295 | fpVisManager->SetRequestedEvent(0); |
---|
| 296 | if (fpVisManager->GetAbortReviewKeptEvents()) break; |
---|
[531] | 297 | } |
---|
[593] | 298 | fpVisManager->SetAbortReviewKeptEvents(false); |
---|
[531] | 299 | |
---|
| 300 | } else { |
---|
| 301 | |
---|
| 302 | // Execute macro file... |
---|
| 303 | for (size_t i = 0; i < nKeptEvents; ++i) { |
---|
| 304 | const G4Event* event = (*events)[i]; |
---|
| 305 | if (verbosity >= G4VisManager::warnings) { |
---|
| 306 | G4cout << "Drawing event : " << event->GetEventID() |
---|
| 307 | << " with macro file \"" << macroFileName << G4endl; |
---|
| 308 | } |
---|
[593] | 309 | fpVisManager->SetRequestedEvent(event); |
---|
[531] | 310 | UImanager->ApplyCommand("/control/execute " + macroFileName); |
---|
[593] | 311 | fpVisManager->SetRequestedEvent(0); |
---|
[531] | 312 | } |
---|
| 313 | } |
---|
| 314 | pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent); |
---|
[849] | 315 | reviewing = false; |
---|
[531] | 316 | |
---|
| 317 | UImanager->SetVerboseLevel(keepVerbose); |
---|
| 318 | } |
---|
| 319 | |
---|
| 320 | ////////////// /vis/verbose /////////////////////////////////////// |
---|
| 321 | |
---|
| 322 | G4VisCommandVerbose::G4VisCommandVerbose () { |
---|
| 323 | G4bool omitable; |
---|
| 324 | |
---|
| 325 | fpCommand = new G4UIcmdWithAString("/vis/verbose", this); |
---|
| 326 | for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) { |
---|
| 327 | fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]); |
---|
| 328 | } |
---|
| 329 | fpCommand -> SetParameterName("verbosity", omitable=true); |
---|
| 330 | fpCommand -> SetDefaultValue("warnings"); |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | G4VisCommandVerbose::~G4VisCommandVerbose () { |
---|
| 334 | delete fpCommand; |
---|
| 335 | } |
---|
| 336 | |
---|
| 337 | G4String G4VisCommandVerbose::GetCurrentValue (G4UIcommand*) { |
---|
| 338 | return G4String(); |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | void G4VisCommandVerbose::SetNewValue (G4UIcommand*, |
---|
| 342 | G4String newValue) { |
---|
| 343 | G4VisManager::Verbosity verbosity = |
---|
| 344 | fpVisManager->GetVerbosityValue(newValue); |
---|
| 345 | fpVisManager->SetVerboseLevel(verbosity); |
---|
| 346 | // Always prints whatever the verbosity... |
---|
| 347 | G4cout << "Visualization verbosity changed to " |
---|
| 348 | << G4VisManager::VerbosityString(verbosity) << G4endl; |
---|
| 349 | } |
---|