[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 | // |
---|
[846] | 27 | // $Id: G4VisCommandsScene.cc,v 1.68 2008/04/28 16:12:38 allison Exp $ |
---|
[954] | 28 | // GEANT4 tag $Name: $ |
---|
[531] | 29 | |
---|
| 30 | // /vis/scene commands - John Allison 9th August 1998 |
---|
| 31 | |
---|
| 32 | #include "G4VisCommandsScene.hh" |
---|
| 33 | |
---|
| 34 | #include "G4VisManager.hh" |
---|
| 35 | #include "G4TransportationManager.hh" |
---|
[606] | 36 | #include "G4RunManager.hh" |
---|
| 37 | #include "G4Run.hh" |
---|
[531] | 38 | #include "G4PhysicalVolumeModel.hh" |
---|
| 39 | #include "G4ApplicationState.hh" |
---|
| 40 | #include "G4UImanager.hh" |
---|
| 41 | #include "G4UIcommand.hh" |
---|
| 42 | #include "G4UIcmdWithAString.hh" |
---|
| 43 | #include "G4ios.hh" |
---|
| 44 | #include <sstream> |
---|
| 45 | |
---|
| 46 | G4VVisCommandScene::G4VVisCommandScene () {} |
---|
| 47 | |
---|
| 48 | G4VVisCommandScene::~G4VVisCommandScene () {} |
---|
| 49 | |
---|
| 50 | G4String G4VVisCommandScene::CurrentSceneName () { |
---|
| 51 | const G4Scene* pScene = fpVisManager -> GetCurrentScene (); |
---|
| 52 | G4String currentSceneName; |
---|
| 53 | if (pScene) currentSceneName = pScene -> GetName (); |
---|
| 54 | return currentSceneName; |
---|
| 55 | } |
---|
| 56 | |
---|
| 57 | ////////////// /vis/scene/create /////////////////////////////////////// |
---|
| 58 | |
---|
| 59 | G4VisCommandSceneCreate::G4VisCommandSceneCreate (): fId (0) { |
---|
| 60 | G4bool omitable; |
---|
| 61 | fpCommand = new G4UIcmdWithAString ("/vis/scene/create", this); |
---|
| 62 | fpCommand -> SetGuidance |
---|
| 63 | ("Creates an empty scene."); |
---|
| 64 | fpCommand -> SetGuidance |
---|
| 65 | ("Invents a name if not supplied. This scene becomes current."); |
---|
| 66 | fpCommand -> SetParameterName ("scene-name", omitable = true); |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | G4VisCommandSceneCreate::~G4VisCommandSceneCreate () { |
---|
| 70 | delete fpCommand; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | G4String G4VisCommandSceneCreate::NextName () { |
---|
| 74 | std::ostringstream oss; |
---|
| 75 | oss << "scene-" << fId; |
---|
| 76 | return oss.str(); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | G4String G4VisCommandSceneCreate::GetCurrentValue (G4UIcommand*) { |
---|
| 80 | return ""; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | void G4VisCommandSceneCreate::SetNewValue (G4UIcommand*, G4String newValue) { |
---|
| 84 | |
---|
| 85 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 86 | |
---|
| 87 | G4String& newName = newValue; |
---|
| 88 | G4String nextName = NextName (); |
---|
| 89 | |
---|
| 90 | if (newName == "") { |
---|
| 91 | newName = nextName; |
---|
| 92 | } |
---|
| 93 | if (newName == nextName) fId++; |
---|
| 94 | |
---|
| 95 | G4SceneList& sceneList = fpVisManager -> SetSceneList (); |
---|
| 96 | G4int iScene, nScenes = sceneList.size (); |
---|
| 97 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
| 98 | if (sceneList [iScene] -> GetName () == newName) break; |
---|
| 99 | } |
---|
| 100 | if (iScene < nScenes) { |
---|
| 101 | if (verbosity >= G4VisManager::warnings) { |
---|
| 102 | G4cout << "WARNING: Scene \"" << newName << "\" already exists." |
---|
| 103 | << "\n New scene not created." |
---|
| 104 | << G4endl; |
---|
| 105 | } |
---|
| 106 | } else { |
---|
| 107 | |
---|
| 108 | // Add empty scene data object to list... |
---|
| 109 | G4Scene* pScene = new G4Scene (newName); |
---|
| 110 | sceneList.push_back (pScene); |
---|
| 111 | fpVisManager -> SetCurrentScene (pScene); |
---|
| 112 | |
---|
| 113 | if (verbosity >= G4VisManager::confirmations) { |
---|
| 114 | G4cout << "New empty scene \"" << newName << "\" created." << G4endl; |
---|
| 115 | } |
---|
| 116 | } |
---|
| 117 | } |
---|
| 118 | |
---|
| 119 | ////////////// /vis/scene/endOfEventAction //////////////////////////// |
---|
| 120 | |
---|
| 121 | G4VisCommandSceneEndOfEventAction::G4VisCommandSceneEndOfEventAction () { |
---|
| 122 | G4bool omitable; |
---|
| 123 | fpCommand = new G4UIcommand ("/vis/scene/endOfEventAction", this); |
---|
| 124 | fpCommand -> SetGuidance |
---|
| 125 | ("Accumulate or refresh the viewer for each new event."); |
---|
| 126 | fpCommand -> SetGuidance |
---|
| 127 | ("\"accumulate\": viewer accumulates hits, etc., event by event, or"); |
---|
| 128 | fpCommand -> SetGuidance |
---|
| 129 | ("\"refresh\": viewer shows them at end of event or, for direct-screen" |
---|
| 130 | "\n viewers, refreshes the screen just before drawing the next event."); |
---|
| 131 | G4UIparameter* parameter; |
---|
| 132 | parameter = new G4UIparameter ("action", 's', omitable = true); |
---|
| 133 | parameter -> SetParameterCandidates ("accumulate refresh"); |
---|
| 134 | parameter -> SetDefaultValue ("refresh"); |
---|
| 135 | fpCommand -> SetParameter (parameter); |
---|
| 136 | parameter = new G4UIparameter ("maxNumber", 'i', omitable = true); |
---|
| 137 | parameter -> SetDefaultValue (100); |
---|
| 138 | parameter -> SetGuidance |
---|
| 139 | ("Maximum number of events kept. Unlimited if negative."); |
---|
| 140 | fpCommand -> SetParameter (parameter); |
---|
| 141 | } |
---|
| 142 | |
---|
| 143 | G4VisCommandSceneEndOfEventAction::~G4VisCommandSceneEndOfEventAction () { |
---|
| 144 | delete fpCommand; |
---|
| 145 | } |
---|
| 146 | |
---|
| 147 | G4String G4VisCommandSceneEndOfEventAction::GetCurrentValue(G4UIcommand*) { |
---|
| 148 | return ""; |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | void G4VisCommandSceneEndOfEventAction::SetNewValue (G4UIcommand*, |
---|
| 152 | G4String newValue) { |
---|
| 153 | |
---|
| 154 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 155 | |
---|
| 156 | G4String action; |
---|
| 157 | G4int maxNumberOfKeptEvents; |
---|
| 158 | std::istringstream is (newValue); |
---|
| 159 | is >> action >> maxNumberOfKeptEvents; |
---|
| 160 | |
---|
| 161 | G4Scene* pScene = fpVisManager->GetCurrentScene(); |
---|
| 162 | if (!pScene) { |
---|
| 163 | if (verbosity >= G4VisManager::errors) { |
---|
| 164 | G4cout << "ERROR: No current scene. Please create one." << G4endl; |
---|
| 165 | } |
---|
| 166 | return; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler(); |
---|
| 170 | if (!pSceneHandler) { |
---|
| 171 | if (verbosity >= G4VisManager::errors) { |
---|
| 172 | G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl; |
---|
| 173 | } |
---|
| 174 | return; |
---|
| 175 | } |
---|
| 176 | |
---|
| 177 | if (action == "accumulate") { |
---|
| 178 | pScene->SetRefreshAtEndOfEvent(false); |
---|
| 179 | pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents); |
---|
| 180 | } |
---|
| 181 | else if (action == "refresh") { |
---|
| 182 | if (!pScene->GetRefreshAtEndOfRun()) { |
---|
| 183 | if (verbosity >= G4VisManager::errors) { |
---|
| 184 | G4cout << |
---|
| 185 | "ERROR: Cannot refresh events unless runs refresh too." |
---|
| 186 | "\n Use \"/vis/scene/endOfRun refresh\"." |
---|
| 187 | << G4endl; |
---|
| 188 | } |
---|
| 189 | } else { |
---|
| 190 | pScene->SetRefreshAtEndOfEvent(true); |
---|
| 191 | pSceneHandler->SetMarkForClearingTransientStore(true); |
---|
| 192 | } |
---|
| 193 | } |
---|
| 194 | else { |
---|
| 195 | if (verbosity >= G4VisManager::errors) { |
---|
| 196 | G4cout << |
---|
| 197 | "ERROR: unrecognised parameter \"" << action << "\"." |
---|
| 198 | << G4endl; |
---|
| 199 | } |
---|
| 200 | return; |
---|
| 201 | } |
---|
| 202 | |
---|
| 203 | // Change of transients behaviour, so... |
---|
| 204 | fpVisManager->ResetTransientsDrawnFlags(); |
---|
| 205 | |
---|
[606] | 206 | // Are there any events currently kept... |
---|
| 207 | size_t nCurrentlyKept = 0; |
---|
| 208 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 209 | if (runManager) { |
---|
| 210 | const G4Run* currentRun = runManager->GetCurrentRun(); |
---|
| 211 | if (currentRun) { |
---|
| 212 | const std::vector<const G4Event*>* events = |
---|
| 213 | currentRun->GetEventVector(); |
---|
| 214 | if (events) nCurrentlyKept = events->size(); |
---|
| 215 | } |
---|
| 216 | } |
---|
| 217 | |
---|
[531] | 218 | if (verbosity >= G4VisManager::confirmations) { |
---|
| 219 | G4cout << "End of event action set to "; |
---|
| 220 | if (pScene->GetRefreshAtEndOfEvent()) G4cout << "\"refresh\"."; |
---|
| 221 | else { |
---|
| 222 | G4cout << "\"accumulate\"." |
---|
| 223 | "\n Maximum number of events to be kept: " |
---|
| 224 | << maxNumberOfKeptEvents |
---|
| 225 | << " (unlimited if negative)." |
---|
| 226 | "\n This may be changed with, e.g., " |
---|
[606] | 227 | "\"/vis/scene/endOfEventAction accumulate 1000\"."; |
---|
[531] | 228 | } |
---|
[606] | 229 | G4cout << G4endl; |
---|
[531] | 230 | } |
---|
[606] | 231 | |
---|
[531] | 232 | if (!pScene->GetRefreshAtEndOfEvent() && |
---|
| 233 | maxNumberOfKeptEvents != 0 && |
---|
| 234 | verbosity >= G4VisManager::warnings) { |
---|
[606] | 235 | G4cout << "WARNING: "; |
---|
| 236 | if (nCurrentlyKept) { |
---|
| 237 | G4cout << |
---|
| 238 | "\n There are currently " << nCurrentlyKept |
---|
| 239 | << " events kept for refreshing and/or reviewing."; |
---|
| 240 | } else { |
---|
| 241 | G4cout << "The vis manager will keep "; |
---|
| 242 | if (maxNumberOfKeptEvents < 0) G4cout << "an unlimited number of"; |
---|
| 243 | else G4cout << "up to " << maxNumberOfKeptEvents; |
---|
| 244 | G4cout << " events."; |
---|
| 245 | if (maxNumberOfKeptEvents > 1 || maxNumberOfKeptEvents < 0) |
---|
[846] | 246 | G4cout << |
---|
| 247 | "\n This may use a lot of memory." |
---|
| 248 | "\n It may be changed with, e.g., " |
---|
| 249 | "\"/vis/scene/endOfEventAction accumulate 10\"."; |
---|
[606] | 250 | } |
---|
[531] | 251 | G4cout << G4endl; |
---|
| 252 | } |
---|
| 253 | } |
---|
| 254 | |
---|
| 255 | ////////////// /vis/scene/endOfRunAction //////////////////////////// |
---|
| 256 | |
---|
| 257 | G4VisCommandSceneEndOfRunAction::G4VisCommandSceneEndOfRunAction () { |
---|
| 258 | G4bool omitable; |
---|
| 259 | fpCommand = new G4UIcmdWithAString ("/vis/scene/endOfRunAction", this); |
---|
| 260 | fpCommand -> SetGuidance |
---|
| 261 | ("Accumulate or refresh the viewer for each new run."); |
---|
| 262 | fpCommand -> SetGuidance |
---|
| 263 | ("\"accumulate\": viewer accumulates hits, etc., run by run, or"); |
---|
| 264 | fpCommand -> SetGuidance |
---|
| 265 | ("\"refresh\": viewer shows them at end of run or, for direct-screen" |
---|
| 266 | "\n viewers, refreshes the screen just before drawing the first" |
---|
| 267 | "\n event of the next run."); |
---|
| 268 | fpCommand -> SetGuidance ("The detector remains or is redrawn."); |
---|
| 269 | fpCommand -> SetParameterName ("action", omitable = true); |
---|
| 270 | fpCommand -> SetCandidates ("accumulate refresh"); |
---|
| 271 | fpCommand -> SetDefaultValue ("refresh"); |
---|
| 272 | } |
---|
| 273 | |
---|
| 274 | G4VisCommandSceneEndOfRunAction::~G4VisCommandSceneEndOfRunAction () { |
---|
| 275 | delete fpCommand; |
---|
| 276 | } |
---|
| 277 | |
---|
| 278 | G4String G4VisCommandSceneEndOfRunAction::GetCurrentValue(G4UIcommand*) { |
---|
| 279 | return ""; |
---|
| 280 | } |
---|
| 281 | |
---|
| 282 | void G4VisCommandSceneEndOfRunAction::SetNewValue (G4UIcommand*, |
---|
| 283 | G4String newValue) { |
---|
| 284 | |
---|
| 285 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 286 | |
---|
| 287 | G4String action; |
---|
| 288 | std::istringstream is (newValue); |
---|
| 289 | is >> action; |
---|
| 290 | |
---|
| 291 | G4Scene* pScene = fpVisManager->GetCurrentScene(); |
---|
| 292 | if (!pScene) { |
---|
| 293 | if (verbosity >= G4VisManager::errors) { |
---|
| 294 | G4cout << "ERROR: No current scene. Please create one." << G4endl; |
---|
| 295 | } |
---|
| 296 | return; |
---|
| 297 | } |
---|
| 298 | |
---|
| 299 | G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler(); |
---|
| 300 | if (!pSceneHandler) { |
---|
| 301 | if (verbosity >= G4VisManager::errors) { |
---|
| 302 | G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl; |
---|
| 303 | } |
---|
| 304 | return; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | if (action == "accumulate") { |
---|
| 308 | if (pScene->GetRefreshAtEndOfEvent()) { |
---|
| 309 | if (verbosity >= G4VisManager::errors) { |
---|
| 310 | G4cout << |
---|
| 311 | "ERROR: Cannot accumulate runs unless events accumulate too." |
---|
| 312 | "\n Use \"/vis/scene/endOfEventAction accumulate\"." |
---|
| 313 | << G4endl; |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | else { |
---|
| 317 | pScene->SetRefreshAtEndOfRun(false); |
---|
| 318 | } |
---|
| 319 | } |
---|
| 320 | else if (action == "refresh") { |
---|
| 321 | pScene->SetRefreshAtEndOfRun(true); |
---|
| 322 | pSceneHandler->SetMarkForClearingTransientStore(true); |
---|
| 323 | } |
---|
| 324 | else { |
---|
| 325 | if (verbosity >= G4VisManager::errors) { |
---|
| 326 | G4cout << |
---|
| 327 | "ERROR: unrecognised parameter \"" << action << "\"." |
---|
| 328 | << G4endl; |
---|
| 329 | } |
---|
| 330 | return; |
---|
| 331 | } |
---|
| 332 | |
---|
| 333 | // Change of transients behaviour, so... |
---|
| 334 | fpVisManager->ResetTransientsDrawnFlags(); |
---|
| 335 | |
---|
| 336 | if (verbosity >= G4VisManager::confirmations) { |
---|
| 337 | G4cout << "End of run action set to \""; |
---|
| 338 | if (pScene->GetRefreshAtEndOfRun()) G4cout << "refresh"; |
---|
| 339 | else G4cout << "accumulate"; |
---|
| 340 | G4cout << "\"" << G4endl; |
---|
| 341 | } |
---|
| 342 | } |
---|
| 343 | |
---|
| 344 | ////////////// /vis/scene/list /////////////////////////////////////// |
---|
| 345 | |
---|
| 346 | G4VisCommandSceneList::G4VisCommandSceneList () { |
---|
| 347 | G4bool omitable; |
---|
| 348 | fpCommand = new G4UIcommand ("/vis/scene/list", this); |
---|
| 349 | fpCommand -> SetGuidance ("Lists scene(s)."); |
---|
| 350 | fpCommand -> SetGuidance |
---|
| 351 | ("\"help /vis/verbose\" for definition of verbosity."); |
---|
| 352 | G4UIparameter* parameter; |
---|
| 353 | parameter = new G4UIparameter ("scene-name", 's', omitable = true); |
---|
| 354 | parameter -> SetDefaultValue ("all"); |
---|
| 355 | fpCommand -> SetParameter (parameter); |
---|
| 356 | parameter = new G4UIparameter ("verbosity", 's', omitable = true); |
---|
| 357 | parameter -> SetDefaultValue ("warnings"); |
---|
| 358 | fpCommand -> SetParameter (parameter); |
---|
| 359 | } |
---|
| 360 | |
---|
| 361 | G4VisCommandSceneList::~G4VisCommandSceneList () { |
---|
| 362 | delete fpCommand; |
---|
| 363 | } |
---|
| 364 | |
---|
| 365 | G4String G4VisCommandSceneList::GetCurrentValue (G4UIcommand*) { |
---|
| 366 | return ""; |
---|
| 367 | } |
---|
| 368 | |
---|
| 369 | void G4VisCommandSceneList::SetNewValue (G4UIcommand*, G4String newValue) { |
---|
| 370 | G4String name, verbosityString; |
---|
| 371 | std::istringstream is (newValue); |
---|
| 372 | is >> name >> verbosityString; |
---|
| 373 | G4VisManager::Verbosity verbosity = |
---|
| 374 | fpVisManager->GetVerbosityValue(verbosityString); |
---|
| 375 | const G4Scene* currentScene = fpVisManager -> GetCurrentScene (); |
---|
| 376 | G4String currentName; |
---|
| 377 | if (currentScene) currentName = currentScene->GetName(); |
---|
| 378 | |
---|
| 379 | G4SceneList& sceneList = fpVisManager -> SetSceneList (); |
---|
| 380 | G4int iScene, nScenes = sceneList.size (); |
---|
| 381 | G4bool found = false; |
---|
| 382 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
| 383 | G4Scene* pScene = sceneList [iScene]; |
---|
| 384 | const G4String& iName = pScene -> GetName (); |
---|
| 385 | if (name != "all") { |
---|
| 386 | if (name != iName) continue; |
---|
| 387 | } |
---|
| 388 | found = true; |
---|
| 389 | if (iName == currentName) { |
---|
| 390 | G4cout << " (current)"; |
---|
| 391 | } |
---|
| 392 | else { |
---|
| 393 | G4cout << " "; |
---|
| 394 | } |
---|
| 395 | G4cout << " scene \"" << iName << "\""; |
---|
| 396 | if (verbosity >= G4VisManager::confirmations) { |
---|
| 397 | G4int i; |
---|
| 398 | G4cout << "\n Run-duration models:"; |
---|
| 399 | G4int nRunModels = pScene -> GetRunDurationModelList ().size (); |
---|
| 400 | if (nRunModels == 0) { |
---|
| 401 | G4cout << " none."; |
---|
| 402 | } |
---|
| 403 | for (i = 0; i < nRunModels; i++) { |
---|
| 404 | G4VModel* pModel = pScene -> GetRunDurationModelList () [i]; |
---|
| 405 | G4cout << "\n " << pModel -> GetGlobalDescription (); |
---|
| 406 | } |
---|
| 407 | G4cout << "\n End-of-event models:"; |
---|
| 408 | G4int nEOEModels = pScene -> GetEndOfEventModelList ().size (); |
---|
| 409 | if (nEOEModels == 0) { |
---|
| 410 | G4cout << " none."; |
---|
| 411 | } |
---|
| 412 | for (i = 0; i < nEOEModels; i++) { |
---|
| 413 | G4VModel* pModel = pScene -> GetEndOfEventModelList () [i]; |
---|
| 414 | G4cout << "\n " << pModel -> GetGlobalDescription (); |
---|
| 415 | } |
---|
| 416 | } |
---|
| 417 | if (verbosity >= G4VisManager::parameters) { |
---|
| 418 | G4cout << "\n " << *sceneList [iScene]; |
---|
| 419 | } |
---|
| 420 | G4cout << G4endl; |
---|
| 421 | } |
---|
| 422 | if (!found) { |
---|
| 423 | G4cout << "No scenes found"; |
---|
| 424 | if (name != "all") { |
---|
| 425 | G4cout << " of name \"" << name << "\""; |
---|
| 426 | } |
---|
| 427 | G4cout << "." << G4endl; |
---|
| 428 | } |
---|
| 429 | } |
---|
| 430 | |
---|
| 431 | ////////////// /vis/scene/notifyHandlers ///////////////////////// |
---|
| 432 | |
---|
| 433 | G4VisCommandSceneNotifyHandlers::G4VisCommandSceneNotifyHandlers () { |
---|
| 434 | G4bool omitable; |
---|
| 435 | fpCommand = new G4UIcommand ("/vis/scene/notifyHandlers", this); |
---|
| 436 | fpCommand -> SetGuidance |
---|
| 437 | ("Notifies scene handlers and forces re-rendering."); |
---|
| 438 | fpCommand -> SetGuidance |
---|
| 439 | ("Notifies the handler(s) of the specified scene and forces a" |
---|
| 440 | "\nreconstruction of any graphical databases." |
---|
| 441 | "\nClears and refreshes all viewers of current scene." |
---|
| 442 | "\n The default action \"refresh\" does not issue \"update\" (see" |
---|
| 443 | "\n /vis/viewer/update)." |
---|
| 444 | "\nIf \"flush\" is specified, it issues an \"update\" as well as" |
---|
| 445 | "\n \"refresh\" - \"update\" and initiates post-processing" |
---|
| 446 | "\n for graphics systems which need it."); |
---|
| 447 | fpCommand -> SetGuidance |
---|
| 448 | ("The default for <scene-name> is the current scene name."); |
---|
| 449 | fpCommand -> SetGuidance |
---|
| 450 | ("This command does not change current scene, scene handler or viewer."); |
---|
| 451 | G4UIparameter* parameter; |
---|
| 452 | parameter = new G4UIparameter ("scene-name", 's', |
---|
| 453 | omitable = true); |
---|
| 454 | parameter -> SetCurrentAsDefault(true); |
---|
| 455 | fpCommand -> SetParameter (parameter); |
---|
| 456 | parameter = new G4UIparameter ("refresh-flush", 's', |
---|
| 457 | omitable = true); |
---|
| 458 | parameter -> SetDefaultValue("refresh"); |
---|
| 459 | parameter -> SetParameterCandidates("r refresh f flush"); |
---|
| 460 | fpCommand -> SetParameter (parameter); |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | G4VisCommandSceneNotifyHandlers::~G4VisCommandSceneNotifyHandlers () { |
---|
| 464 | delete fpCommand; |
---|
| 465 | } |
---|
| 466 | |
---|
| 467 | G4String G4VisCommandSceneNotifyHandlers::GetCurrentValue(G4UIcommand*) { |
---|
| 468 | return CurrentSceneName (); |
---|
| 469 | } |
---|
| 470 | |
---|
| 471 | void G4VisCommandSceneNotifyHandlers::SetNewValue (G4UIcommand*, |
---|
| 472 | G4String newValue) { |
---|
| 473 | |
---|
| 474 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 475 | |
---|
| 476 | G4String sceneName, refresh_flush; |
---|
| 477 | std::istringstream is (newValue); |
---|
| 478 | is >> sceneName >> refresh_flush; |
---|
| 479 | G4bool flush = false; |
---|
| 480 | if (refresh_flush(0) == 'f') flush = true; |
---|
| 481 | |
---|
| 482 | const G4SceneList& sceneList = fpVisManager -> GetSceneList (); |
---|
| 483 | G4SceneHandlerList& sceneHandlerList = |
---|
| 484 | fpVisManager -> SetAvailableSceneHandlers (); |
---|
| 485 | |
---|
| 486 | // Check scene name. |
---|
| 487 | const G4int nScenes = sceneList.size (); |
---|
| 488 | G4int iScene; |
---|
| 489 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
| 490 | G4Scene* scene = sceneList [iScene]; |
---|
| 491 | if (sceneName == scene -> GetName ()) break; |
---|
| 492 | } |
---|
| 493 | if (iScene >= nScenes ) { |
---|
| 494 | if (verbosity >= G4VisManager::warnings) { |
---|
| 495 | G4cout << "WARNING: Scene \"" << sceneName << "\" not found." |
---|
| 496 | "\n /vis/scene/list to see scenes." |
---|
| 497 | << G4endl; |
---|
| 498 | } |
---|
| 499 | return; |
---|
| 500 | } |
---|
| 501 | |
---|
| 502 | // Store current context... |
---|
| 503 | G4VSceneHandler* pCurrentSceneHandler = |
---|
| 504 | fpVisManager -> GetCurrentSceneHandler(); |
---|
[593] | 505 | if (!pCurrentSceneHandler) { |
---|
| 506 | if (verbosity >= G4VisManager::warnings) { |
---|
| 507 | G4cout << "WARNING: No current scene handler." |
---|
| 508 | << G4endl; |
---|
| 509 | } |
---|
| 510 | return; |
---|
| 511 | } |
---|
[531] | 512 | G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer(); |
---|
[593] | 513 | if (!pCurrentViewer) { |
---|
| 514 | if (verbosity >= G4VisManager::warnings) { |
---|
| 515 | G4cout << "WARNING: No current viewer." |
---|
| 516 | << G4endl; |
---|
| 517 | } |
---|
| 518 | return; |
---|
| 519 | } |
---|
[531] | 520 | G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene(); |
---|
[593] | 521 | if (!pCurrentScene) { |
---|
| 522 | if (verbosity >= G4VisManager::warnings) { |
---|
| 523 | G4cout << "WARNING: No current scene." |
---|
| 524 | << G4endl; |
---|
| 525 | } |
---|
| 526 | return; |
---|
| 527 | } |
---|
[531] | 528 | G4VisManager::Verbosity currentVerbosity = fpVisManager -> GetVerbosity(); |
---|
| 529 | |
---|
| 530 | // Suppress messages during this process (only print errors)... |
---|
| 531 | //fpVisManager -> SetVerboseLevel(G4VisManager::errors); |
---|
| 532 | |
---|
| 533 | // For each scene handler, if it contains the scene, clear and |
---|
| 534 | // rebuild the graphical database, then for each viewer set (make |
---|
| 535 | // current), clear, (re)draw, and show. |
---|
| 536 | const G4int nSceneHandlers = sceneHandlerList.size (); |
---|
| 537 | for (G4int iSH = 0; iSH < nSceneHandlers; iSH++) { |
---|
| 538 | G4VSceneHandler* aSceneHandler = sceneHandlerList [iSH]; |
---|
| 539 | G4Scene* aScene = aSceneHandler -> GetScene (); |
---|
| 540 | if (aScene) { |
---|
| 541 | const G4String& aSceneName = aScene -> GetName (); |
---|
| 542 | if (sceneName == aSceneName) { |
---|
| 543 | // Clear store and force a rebuild of graphical database... |
---|
| 544 | //aSceneHandler -> ClearStore (); // Not nec?? Done below |
---|
| 545 | //with NeedKernelVisit and DrawView. JA. |
---|
| 546 | G4ViewerList& viewerList = aSceneHandler -> SetViewerList (); |
---|
| 547 | const G4int nViewers = viewerList.size (); |
---|
| 548 | for (G4int iV = 0; iV < nViewers; iV++) { |
---|
| 549 | G4VViewer* aViewer = viewerList [iV]; |
---|
| 550 | if (aViewer->GetViewParameters().IsAutoRefresh()) { |
---|
| 551 | aSceneHandler -> SetCurrentViewer (aViewer); |
---|
| 552 | // Ensure consistency of vis manager... |
---|
| 553 | fpVisManager -> SetCurrentViewer(aViewer); |
---|
| 554 | fpVisManager -> SetCurrentSceneHandler(aSceneHandler); |
---|
| 555 | fpVisManager -> SetCurrentScene(aScene); |
---|
| 556 | // Re-draw, forcing rebuild of graphics database, if any... |
---|
| 557 | aViewer -> NeedKernelVisit(); |
---|
[1041] | 558 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
[1050] | 559 | G4cout << "G4VisCommandSceneNotifyHandlers::SetNewValue." << G4endl; |
---|
| 560 | printf("\n\nG4VisCommandSceneNotifyHandlers::SetNewValue ---%s--- Call SetView() 1\n",newValue.data()); |
---|
[1041] | 561 | #endif |
---|
[531] | 562 | aViewer -> SetView (); |
---|
[1041] | 563 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
[1050] | 564 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue Call SetView() END 2\n"); |
---|
| 565 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue Call ClearView() 3\n"); |
---|
[1041] | 566 | #endif |
---|
[531] | 567 | aViewer -> ClearView (); |
---|
[1041] | 568 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
[1050] | 569 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue Call ClearView() END 4\n"); |
---|
| 570 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue Call DrawView() 5\n"); |
---|
[1041] | 571 | #endif |
---|
[531] | 572 | aViewer -> DrawView (); |
---|
[1041] | 573 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
[1050] | 574 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue Call DrawView() END 6\n"); |
---|
[1041] | 575 | #endif |
---|
[531] | 576 | if (flush) aViewer -> ShowView (); |
---|
| 577 | if (verbosity >= G4VisManager::confirmations) { |
---|
| 578 | G4cout << "Viewer \"" << aViewer -> GetName () |
---|
| 579 | << "\" of scene handler \"" << aSceneHandler -> GetName () |
---|
| 580 | << "\"\n "; |
---|
| 581 | if (flush) G4cout << "flushed"; |
---|
| 582 | else G4cout << "refreshed"; |
---|
| 583 | G4cout << " at request of scene \"" << sceneName |
---|
| 584 | << "\"." << G4endl; |
---|
| 585 | } |
---|
| 586 | } else { |
---|
| 587 | if (verbosity >= G4VisManager::warnings) { |
---|
| 588 | G4cout << "WARNING: The scene, \"" |
---|
| 589 | << sceneName |
---|
| 590 | << "\", of viewer \"" |
---|
| 591 | << aViewer -> GetName () |
---|
| 592 | << "\"\n of scene handler \"" |
---|
| 593 | << aSceneHandler -> GetName () |
---|
| 594 | << "\" has changed. To see effect," |
---|
| 595 | << "\n \"/vis/viewer/select " |
---|
| 596 | << aViewer -> GetShortName () |
---|
| 597 | << "\" and \"/vis/viewer/rebuild\"." |
---|
| 598 | << G4endl; |
---|
| 599 | } |
---|
| 600 | } |
---|
| 601 | } |
---|
| 602 | } |
---|
| 603 | } |
---|
| 604 | else { |
---|
| 605 | if (verbosity >= G4VisManager::warnings) { |
---|
| 606 | G4cout << "WARNING: G4VisCommandSceneNotifyHandlers: scene handler \"" |
---|
| 607 | << aSceneHandler->GetName() |
---|
| 608 | << "\" has a null scene." |
---|
| 609 | << G4endl; |
---|
| 610 | } |
---|
| 611 | } |
---|
| 612 | } |
---|
| 613 | |
---|
| 614 | // Reclaim original context - but set viewer first, then scene |
---|
| 615 | // handler, because the latter might have been created very recently |
---|
| 616 | // and, not yet having a viewer, the current viewer will, |
---|
| 617 | // temporarily, refer to another scene handler. SetCurrentViewer |
---|
| 618 | // actually resets the scene handler, which is what we don't want, |
---|
| 619 | // so we set it again on the next line... |
---|
| 620 | fpVisManager -> SetCurrentViewer(pCurrentViewer); |
---|
| 621 | fpVisManager -> SetCurrentSceneHandler(pCurrentSceneHandler); |
---|
| 622 | fpVisManager -> SetCurrentScene(pCurrentScene); |
---|
| 623 | fpVisManager -> SetVerboseLevel(currentVerbosity); |
---|
| 624 | // Take care of special case of scene handler with no viewer yet. |
---|
| 625 | if (pCurrentSceneHandler) { |
---|
| 626 | G4ViewerList& viewerList = pCurrentSceneHandler -> SetViewerList (); |
---|
| 627 | const G4int nViewers = viewerList.size (); |
---|
| 628 | if (nViewers) { |
---|
| 629 | pCurrentSceneHandler -> SetCurrentViewer (pCurrentViewer); |
---|
| 630 | if (pCurrentViewer && pCurrentSceneHandler->GetScene()) { |
---|
[1041] | 631 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
[1050] | 632 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue Call SetView() 7\n"); |
---|
[1041] | 633 | #endif |
---|
[531] | 634 | pCurrentViewer -> SetView (); |
---|
[1041] | 635 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
[1050] | 636 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue Call SetView() END 8\n"); |
---|
[1041] | 637 | #endif |
---|
[531] | 638 | } |
---|
| 639 | } |
---|
| 640 | } |
---|
[1050] | 641 | #ifdef G4DEBUG_VIS_MANAGEMENT |
---|
| 642 | G4cout << "G4VisCommandSceneNotifyHandlers::SetNewValue. END" << G4endl; |
---|
| 643 | printf("G4VisCommandSceneNotifyHandlers::SetNewValue END 99\n\n\n"); |
---|
| 644 | #endif |
---|
[531] | 645 | } |
---|
| 646 | |
---|
| 647 | ////////////// /vis/scene/select /////////////////////////////////////// |
---|
| 648 | |
---|
| 649 | G4VisCommandSceneSelect::G4VisCommandSceneSelect () { |
---|
| 650 | G4bool omitable; |
---|
| 651 | fpCommand = new G4UIcmdWithAString ("/vis/scene/select", this); |
---|
| 652 | fpCommand -> SetGuidance ("Selects a scene"); |
---|
| 653 | fpCommand -> SetGuidance |
---|
| 654 | ("Makes the scene current. \"/vis/scene/list\" to see" |
---|
| 655 | "\n possible scene names."); |
---|
| 656 | fpCommand -> SetParameterName ("scene-name", omitable = false); |
---|
| 657 | } |
---|
| 658 | |
---|
| 659 | G4VisCommandSceneSelect::~G4VisCommandSceneSelect () { |
---|
| 660 | delete fpCommand; |
---|
| 661 | } |
---|
| 662 | |
---|
| 663 | G4String G4VisCommandSceneSelect::GetCurrentValue (G4UIcommand*) { |
---|
| 664 | return ""; |
---|
| 665 | } |
---|
| 666 | |
---|
| 667 | void G4VisCommandSceneSelect::SetNewValue (G4UIcommand*, G4String newValue) { |
---|
| 668 | |
---|
| 669 | G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity(); |
---|
| 670 | |
---|
| 671 | G4String& selectName = newValue; |
---|
| 672 | G4SceneList& sceneList = fpVisManager -> SetSceneList (); |
---|
| 673 | G4int iScene, nScenes = sceneList.size (); |
---|
| 674 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
| 675 | if (sceneList [iScene] -> GetName () == selectName) break; |
---|
| 676 | } |
---|
| 677 | if (iScene >= nScenes) { |
---|
| 678 | if (verbosity >= G4VisManager::warnings) { |
---|
| 679 | G4cout << "WARNING: Scene \"" << selectName |
---|
| 680 | << "\" not found - \"/vis/scene/list\" to see possibilities." |
---|
| 681 | << G4endl; |
---|
| 682 | } |
---|
| 683 | return; |
---|
| 684 | } |
---|
| 685 | |
---|
| 686 | if (verbosity >= G4VisManager::confirmations) { |
---|
| 687 | G4cout << "Scene \"" << selectName |
---|
| 688 | << "\" selected." << G4endl; |
---|
| 689 | } |
---|
| 690 | UpdateVisManagerScene (selectName); |
---|
| 691 | } |
---|