| 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: G4VisCommands.cc,v 1.20 2006/11/26 15:49:10 allison Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-08-02-patch-01 $
|
|---|
| 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 |
|
|---|
| 43 | ////////////// /vis/enable ///////////////////////////////////////
|
|---|
| 44 |
|
|---|
| 45 | G4VisCommandEnable::G4VisCommandEnable () {
|
|---|
| 46 | G4bool omitable;
|
|---|
| 47 |
|
|---|
| 48 | fpCommand = new G4UIcmdWithABool("/vis/enable", this);
|
|---|
| 49 | fpCommand -> SetGuidance("Enables/disables visualization system.");
|
|---|
| 50 | fpCommand -> SetParameterName("enabled", omitable=true);
|
|---|
| 51 | fpCommand -> SetDefaultValue(true);
|
|---|
| 52 |
|
|---|
| 53 | fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
|
|---|
| 54 | fpCommand1 -> SetGuidance("Disables visualization system.");
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | G4VisCommandEnable::~G4VisCommandEnable () {
|
|---|
| 58 | delete fpCommand;
|
|---|
| 59 | delete fpCommand1;
|
|---|
| 60 | }
|
|---|
| 61 |
|
|---|
| 62 | G4String G4VisCommandEnable::GetCurrentValue (G4UIcommand*) {
|
|---|
| 63 | return G4String();
|
|---|
| 64 | }
|
|---|
| 65 |
|
|---|
| 66 | void G4VisCommandEnable::SetNewValue (G4UIcommand* command,
|
|---|
| 67 | G4String newValue) {
|
|---|
| 68 | if (command == fpCommand) {
|
|---|
| 69 | G4bool enable = G4UIcommand::ConvertToBool(newValue);
|
|---|
| 70 | if (enable) fpVisManager->Enable(); // Printing is in vis manager.
|
|---|
| 71 | else fpVisManager->Disable(); // Printing is in vis manager.
|
|---|
| 72 | } else fpVisManager->Disable(); // Printing is in vis manager.
|
|---|
| 73 | // Note: Printing is in vis manager.
|
|---|
| 74 | }
|
|---|
| 75 |
|
|---|
| 76 | ////////////// /vis/list ///////////////////////////////////////
|
|---|
| 77 |
|
|---|
| 78 | G4VisCommandList::G4VisCommandList ()
|
|---|
| 79 | {
|
|---|
| 80 | G4bool omitable;
|
|---|
| 81 |
|
|---|
| 82 | fpCommand = new G4UIcmdWithAString("/vis/list", this);
|
|---|
| 83 | fpCommand -> SetGuidance("Lists visualization parameters.");
|
|---|
| 84 | fpCommand -> SetParameterName("verbosity", omitable=true);
|
|---|
| 85 | fpCommand -> SetDefaultValue("warnings");
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | G4VisCommandList::~G4VisCommandList ()
|
|---|
| 89 | {
|
|---|
| 90 | delete fpCommand;
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | G4String G4VisCommandList::GetCurrentValue (G4UIcommand*)
|
|---|
| 94 | {
|
|---|
| 95 | return "";
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | void G4VisCommandList::SetNewValue (G4UIcommand*, G4String newValue)
|
|---|
| 99 | {
|
|---|
| 100 | G4String& verbosityString = newValue;
|
|---|
| 101 | G4VisManager::Verbosity verbosity =
|
|---|
| 102 | fpVisManager->GetVerbosityValue(verbosityString);
|
|---|
| 103 |
|
|---|
| 104 | fpVisManager->PrintAvailableGraphicsSystems();
|
|---|
| 105 | G4cout << G4endl;
|
|---|
| 106 | fpVisManager->PrintAvailableModels(verbosity);
|
|---|
| 107 | G4cout << G4endl;
|
|---|
| 108 | G4UImanager* UImanager = G4UImanager::GetUIpointer();
|
|---|
| 109 | UImanager->ApplyCommand(G4String("/vis/viewer/list ! ") + verbosityString);
|
|---|
| 110 | if (verbosity < G4VisManager::parameters)
|
|---|
| 111 | G4cout <<
|
|---|
| 112 | "\nTo get more information, \"/vis/list all all\" or use individual commands"
|
|---|
| 113 | "\n such as (use \"ls\" or \"help\"):"
|
|---|
| 114 | "\n /vis/viewer/list"
|
|---|
| 115 | "\n /vis/modeling/trajectories/list"
|
|---|
| 116 | "\n /vis/filtering/trajectories/list"
|
|---|
| 117 | << G4endl;
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | ////////////// /vis/reviewKeptEvents ///////////////////////////////////////
|
|---|
| 121 |
|
|---|
| 122 | G4VisCommandReviewKeptEvents::G4VisCommandReviewKeptEvents ()
|
|---|
| 123 | {
|
|---|
| 124 | G4bool omitable;
|
|---|
| 125 |
|
|---|
| 126 | fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
|
|---|
| 127 | fpCommand -> SetGuidance("Review kept events.");
|
|---|
| 128 | fpCommand -> SetGuidance
|
|---|
| 129 | ("If a macro file is specified, it is executed for each event.");
|
|---|
| 130 | fpCommand -> SetGuidance
|
|---|
| 131 | ("If a macro file is not specified, each event is drawn to the current"
|
|---|
| 132 | "\nviewer. After each event, the session is paused. The user may issue"
|
|---|
| 133 | "\nany allowed command. Then enter \"continue\" to continue to the next"
|
|---|
| 134 | "\nevent.");
|
|---|
| 135 | fpCommand -> SetParameterName("macro-file-name", omitable=true);
|
|---|
| 136 | fpCommand -> SetDefaultValue("");
|
|---|
| 137 | }
|
|---|
| 138 |
|
|---|
| 139 | G4VisCommandReviewKeptEvents::~G4VisCommandReviewKeptEvents ()
|
|---|
| 140 | {
|
|---|
| 141 | delete fpCommand;
|
|---|
| 142 | }
|
|---|
| 143 |
|
|---|
| 144 | G4String G4VisCommandReviewKeptEvents::GetCurrentValue (G4UIcommand*)
|
|---|
| 145 | {
|
|---|
| 146 | return "";
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | void G4VisCommandReviewKeptEvents::SetNewValue (G4UIcommand*, G4String newValue)
|
|---|
| 150 | {
|
|---|
| 151 | G4String& macroFileName = newValue;
|
|---|
| 152 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
|
|---|
| 153 |
|
|---|
| 154 | G4RunManager* runManager = G4RunManager::GetRunManager();
|
|---|
| 155 | const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
|
|---|
| 156 | const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
|
|---|
| 157 | size_t nKeptEvents = events? events->size(): 0;
|
|---|
| 158 |
|
|---|
| 159 | if (!nKeptEvents) {
|
|---|
| 160 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 161 | G4cout <<
|
|---|
| 162 | "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
|
|---|
| 163 | "\n or kept events not accessible."
|
|---|
| 164 | << G4endl;
|
|---|
| 165 | }
|
|---|
| 166 | return;
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | G4VViewer* viewer = fpVisManager->GetCurrentViewer();
|
|---|
| 170 | if (!viewer) {
|
|---|
| 171 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 172 | G4cout <<
|
|---|
| 173 | "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
|
|---|
| 174 | << G4endl;
|
|---|
| 175 | }
|
|---|
| 176 | return;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | G4Scene* pScene = fpVisManager->GetCurrentScene();
|
|---|
| 180 | if (!pScene) {
|
|---|
| 181 | if (verbosity >= G4VisManager::errors) {
|
|---|
| 182 | G4cout << "ERROR: No current scene. Please create one." << G4endl;
|
|---|
| 183 | }
|
|---|
| 184 | return;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | G4VSceneHandler* sceneHandler = fpVisManager->GetCurrentSceneHandler();
|
|---|
| 188 |
|
|---|
| 189 | G4UImanager* UImanager = G4UImanager::GetUIpointer();
|
|---|
| 190 | G4int keepVerbose = UImanager->GetVerboseLevel();
|
|---|
| 191 | G4int newVerbose(0);
|
|---|
| 192 | if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
|
|---|
| 193 | newVerbose = 2;
|
|---|
| 194 | UImanager->SetVerboseLevel(newVerbose);
|
|---|
| 195 |
|
|---|
| 196 | // Event by event refreshing...
|
|---|
| 197 | G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
|
|---|
| 198 | pScene->SetRefreshAtEndOfEvent(true);
|
|---|
| 199 | if (macroFileName.empty()) {
|
|---|
| 200 |
|
|---|
| 201 | // Draw to viewer and pause session...
|
|---|
| 202 | for (size_t i = 0; i < nKeptEvents; ++i) {
|
|---|
| 203 | const G4Event* event = (*events)[i];
|
|---|
| 204 | if (verbosity >= G4VisManager::warnings) {
|
|---|
| 205 | G4cout << "Drawing event : " << event->GetEventID() <<
|
|---|
| 206 | ". At EndOfEvent, enter any command, then \"continue\"..."
|
|---|
| 207 | << G4endl;
|
|---|
| 208 | }
|
|---|
| 209 | sceneHandler->SetEvent(event);
|
|---|
| 210 | UImanager->ApplyCommand("/vis/viewer/rebuild");
|
|---|
| 211 | /* The above command forces a rebuild of the scene, including
|
|---|
| 212 | the detector. This is fine for "immediate" viewers - a
|
|---|
| 213 | refresh requires a rebuild anyway. But for "stored mode"
|
|---|
| 214 | viewers, you could, in principle, avoid a rebuild of the
|
|---|
| 215 | detector with something like the following:
|
|---|
| 216 | sceneHandler->ClearTransientStore();
|
|---|
| 217 | viewer->DrawView();
|
|---|
| 218 | sceneHandler->DrawEvent(event);
|
|---|
| 219 | but this causes mayhem for "immediate" viewers because
|
|---|
| 220 | ClearTransientStore issues a DrawView and some curious sort
|
|---|
| 221 | of recursion takes place. For "stored" viewers, the event
|
|---|
| 222 | gets drawn but not the eventID, so something odd is happening
|
|---|
| 223 | there too. This needs further investigation - enhanced
|
|---|
| 224 | features or a complete re-think.
|
|---|
| 225 | */
|
|---|
| 226 | if (!viewer->GetViewParameters().IsAutoRefresh())
|
|---|
| 227 | UImanager->ApplyCommand("/vis/viewer/flush");
|
|---|
| 228 | G4UIsession* session = UImanager->GetSession();
|
|---|
| 229 | session->PauseSessionStart("EndOfEvent");
|
|---|
| 230 | sceneHandler->SetEvent(0);
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | } else {
|
|---|
| 234 |
|
|---|
| 235 | // Execute macro file...
|
|---|
| 236 | for (size_t i = 0; i < nKeptEvents; ++i) {
|
|---|
| 237 | const G4Event* event = (*events)[i];
|
|---|
| 238 | if (verbosity >= G4VisManager::warnings) {
|
|---|
| 239 | G4cout << "Drawing event : " << event->GetEventID()
|
|---|
| 240 | << " with macro file \"" << macroFileName << G4endl;
|
|---|
| 241 | }
|
|---|
| 242 | sceneHandler->SetEvent(event);
|
|---|
| 243 | UImanager->ApplyCommand("/control/execute " + macroFileName);
|
|---|
| 244 | sceneHandler->SetEvent(0);
|
|---|
| 245 | }
|
|---|
| 246 | }
|
|---|
| 247 | pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
|
|---|
| 248 |
|
|---|
| 249 | UImanager->SetVerboseLevel(keepVerbose);
|
|---|
| 250 | }
|
|---|
| 251 |
|
|---|
| 252 | ////////////// /vis/verbose ///////////////////////////////////////
|
|---|
| 253 |
|
|---|
| 254 | G4VisCommandVerbose::G4VisCommandVerbose () {
|
|---|
| 255 | G4bool omitable;
|
|---|
| 256 |
|
|---|
| 257 | fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
|
|---|
| 258 | for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
|
|---|
| 259 | fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]);
|
|---|
| 260 | }
|
|---|
| 261 | fpCommand -> SetParameterName("verbosity", omitable=true);
|
|---|
| 262 | fpCommand -> SetDefaultValue("warnings");
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | G4VisCommandVerbose::~G4VisCommandVerbose () {
|
|---|
| 266 | delete fpCommand;
|
|---|
| 267 | }
|
|---|
| 268 |
|
|---|
| 269 | G4String G4VisCommandVerbose::GetCurrentValue (G4UIcommand*) {
|
|---|
| 270 | return G4String();
|
|---|
| 271 | }
|
|---|
| 272 |
|
|---|
| 273 | void G4VisCommandVerbose::SetNewValue (G4UIcommand*,
|
|---|
| 274 | G4String newValue) {
|
|---|
| 275 | G4VisManager::Verbosity verbosity =
|
|---|
| 276 | fpVisManager->GetVerbosityValue(newValue);
|
|---|
| 277 | fpVisManager->SetVerboseLevel(verbosity);
|
|---|
| 278 | // Always prints whatever the verbosity...
|
|---|
| 279 | G4cout << "Visualization verbosity changed to "
|
|---|
| 280 | << G4VisManager::VerbosityString(verbosity) << G4endl;
|
|---|
| 281 | }
|
|---|