00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #include "G4VisCommandsScene.hh"
00032
00033 #include "G4VisManager.hh"
00034 #include "G4TransportationManager.hh"
00035 #include "G4RunManager.hh"
00036 #include "G4Run.hh"
00037 #include "G4PhysicalVolumeModel.hh"
00038 #include "G4ApplicationState.hh"
00039 #include "G4UImanager.hh"
00040 #include "G4UIcommand.hh"
00041 #include "G4UIcmdWithAString.hh"
00042 #include "G4ios.hh"
00043 #include <sstream>
00044
00045 G4VVisCommandScene::G4VVisCommandScene () {}
00046
00047 G4VVisCommandScene::~G4VVisCommandScene () {}
00048
00049 G4String G4VVisCommandScene::CurrentSceneName () {
00050 const G4Scene* pScene = fpVisManager -> GetCurrentScene ();
00051 G4String currentSceneName = "none";
00052 if (pScene) currentSceneName = pScene -> GetName ();
00053 return currentSceneName;
00054 }
00055
00057
00058 G4VisCommandSceneActivateModel::G4VisCommandSceneActivateModel () {
00059 G4bool omitable;
00060 fpCommand = new G4UIcommand ("/vis/scene/activateModel", this);
00061 fpCommand -> SetGuidance
00062 ("Activate or de-activate model.");
00063 fpCommand -> SetGuidance
00064 ("Attempts to match search string to name of model - use unique sub-string.");
00065 fpCommand -> SetGuidance
00066 ("Use \"/vis/scene/list\" to see model names.");
00067 fpCommand -> SetGuidance
00068 ("If name == \"all\" (default), all models are activated.");
00069 G4UIparameter* parameter;
00070 parameter = new G4UIparameter ("search-string", 's', omitable = true);
00071 parameter -> SetDefaultValue ("all");
00072 fpCommand -> SetParameter (parameter);
00073 parameter = new G4UIparameter ("activate", 'b', omitable = true);
00074 parameter -> SetDefaultValue (true);
00075 fpCommand -> SetParameter (parameter);
00076 }
00077
00078 G4VisCommandSceneActivateModel::~G4VisCommandSceneActivateModel () {
00079 delete fpCommand;
00080 }
00081
00082 G4String G4VisCommandSceneActivateModel::GetCurrentValue(G4UIcommand*) {
00083 return "";
00084 }
00085
00086 void G4VisCommandSceneActivateModel::SetNewValue (G4UIcommand*,
00087 G4String newValue) {
00088
00089 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00090
00091 G4String searchString, activateString;
00092 std::istringstream is (newValue);
00093 is >> searchString >> activateString;
00094 G4bool activate = G4UIcommand::ConvertToBool(activateString);
00095
00096 G4Scene* pScene = fpVisManager->GetCurrentScene();
00097 if (!pScene) {
00098 if (verbosity >= G4VisManager::errors) {
00099 G4cout << "ERROR: No current scene. Please create one." << G4endl;
00100 }
00101 return;
00102 }
00103
00104 G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler();
00105 if (!pSceneHandler) {
00106 if (verbosity >= G4VisManager::errors) {
00107 G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl;
00108 }
00109 return;
00110 }
00111
00112 if (searchString == "all" && !activate) {
00113 if (verbosity >= G4VisManager::warnings) {
00114 G4cout <<
00115 "WARNING: You are not allowed to de-activate all models."
00116 "\n Command ignored."
00117 << G4endl;
00118 }
00119 return;
00120 }
00121
00122 G4bool any = false;
00123
00124 std::vector<G4Scene::Model>& runDurationModelList =
00125 pScene->SetRunDurationModelList();
00126 for (size_t i = 0; i < runDurationModelList.size(); i++) {
00127 const G4String& modelName =
00128 runDurationModelList[i].fpModel->GetGlobalDescription();
00129 if (searchString == "all" || modelName.find(searchString)
00130 != std::string::npos) {
00131 any = true;
00132 runDurationModelList[i].fActive = activate;
00133 if (verbosity >= G4VisManager::warnings) {
00134 G4cout << "Model \"" << modelName;
00135 if (activate) G4cout << "\" activated.";
00136 else G4cout << "\" de-activated.";
00137 G4cout << G4endl;
00138 }
00139 }
00140 }
00141
00142 std::vector<G4Scene::Model>& endOfEventModelList =
00143 pScene->SetEndOfEventModelList();
00144 for (size_t i = 0; i < endOfEventModelList.size(); i++) {
00145 const G4String& modelName =
00146 endOfEventModelList[i].fpModel->GetGlobalDescription();
00147 if (searchString == "all" || modelName.find(searchString)
00148 != std::string::npos) {
00149 any = true;
00150 endOfEventModelList[i].fActive = activate;
00151 if (verbosity >= G4VisManager::warnings) {
00152 G4cout << "Model \"" << modelName;
00153 if (activate) G4cout << "\" activated.";
00154 else G4cout << "\" de-activated.";
00155 G4cout << G4endl;
00156 }
00157 }
00158 }
00159
00160 std::vector<G4Scene::Model>& endOfRunModelList =
00161 pScene->SetEndOfRunModelList();
00162 for (size_t i = 0; i < endOfRunModelList.size(); i++) {
00163 const G4String& modelName =
00164 endOfRunModelList[i].fpModel->GetGlobalDescription();
00165 if (searchString == "all" || modelName.find(searchString)
00166 != std::string::npos) {
00167 any = true;
00168 endOfRunModelList[i].fActive = activate;
00169 if (verbosity >= G4VisManager::warnings) {
00170 G4cout << "Model \"" << modelName;
00171 if (activate) G4cout << "\" activated.";
00172 else G4cout << "\" de-activated.";
00173 G4cout << G4endl;
00174 }
00175 }
00176 }
00177
00178 if (!any) {
00179 if (verbosity >= G4VisManager::warnings) {
00180 G4cout << "WARNING: No match found." << G4endl;
00181 }
00182 return;
00183 }
00184
00185 const G4String& currentSceneName = pScene -> GetName ();
00186 UpdateVisManagerScene (currentSceneName);
00187 }
00188
00190
00191 G4VisCommandSceneCreate::G4VisCommandSceneCreate (): fId (0) {
00192 G4bool omitable;
00193 fpCommand = new G4UIcmdWithAString ("/vis/scene/create", this);
00194 fpCommand -> SetGuidance
00195 ("Creates an empty scene.");
00196 fpCommand -> SetGuidance
00197 ("Invents a name if not supplied. This scene becomes current.");
00198 fpCommand -> SetParameterName ("scene-name", omitable = true);
00199 }
00200
00201 G4VisCommandSceneCreate::~G4VisCommandSceneCreate () {
00202 delete fpCommand;
00203 }
00204
00205 G4String G4VisCommandSceneCreate::NextName () {
00206 std::ostringstream oss;
00207 oss << "scene-" << fId;
00208 return oss.str();
00209 }
00210
00211 G4String G4VisCommandSceneCreate::GetCurrentValue (G4UIcommand*) {
00212 return "";
00213 }
00214
00215 void G4VisCommandSceneCreate::SetNewValue (G4UIcommand*, G4String newValue) {
00216
00217 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00218
00219 G4String& newName = newValue;
00220 G4String nextName = NextName ();
00221
00222 if (newName == "") {
00223 newName = nextName;
00224 }
00225 if (newName == nextName) fId++;
00226
00227 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
00228 G4int iScene, nScenes = sceneList.size ();
00229 for (iScene = 0; iScene < nScenes; iScene++) {
00230 if (sceneList [iScene] -> GetName () == newName) break;
00231 }
00232 if (iScene < nScenes) {
00233 if (verbosity >= G4VisManager::warnings) {
00234 G4cout << "WARNING: Scene \"" << newName << "\" already exists."
00235 << "\n New scene not created."
00236 << G4endl;
00237 }
00238 } else {
00239
00240
00241 G4Scene* pScene = new G4Scene (newName);
00242 sceneList.push_back (pScene);
00243 fpVisManager -> SetCurrentScene (pScene);
00244
00245 if (verbosity >= G4VisManager::confirmations) {
00246 G4cout << "New empty scene \"" << newName << "\" created." << G4endl;
00247 }
00248 }
00249 }
00250
00252
00253 G4VisCommandSceneEndOfEventAction::G4VisCommandSceneEndOfEventAction () {
00254 G4bool omitable;
00255 fpCommand = new G4UIcommand ("/vis/scene/endOfEventAction", this);
00256 fpCommand -> SetGuidance
00257 ("Accumulate or refresh the viewer for each new event.");
00258 fpCommand -> SetGuidance
00259 ("\"accumulate\": viewer accumulates hits, etc., event by event, or");
00260 fpCommand -> SetGuidance
00261 ("\"refresh\": viewer shows them at end of event or, for direct-screen"
00262 "\n viewers, refreshes the screen just before drawing the next event.");
00263 G4UIparameter* parameter;
00264 parameter = new G4UIparameter ("action", 's', omitable = true);
00265 parameter -> SetParameterCandidates ("accumulate refresh");
00266 parameter -> SetDefaultValue ("refresh");
00267 fpCommand -> SetParameter (parameter);
00268 parameter = new G4UIparameter ("maxNumber", 'i', omitable = true);
00269 parameter -> SetDefaultValue (100);
00270 parameter -> SetGuidance
00271 ("Maximum number of events kept. Unlimited if negative.");
00272 fpCommand -> SetParameter (parameter);
00273 }
00274
00275 G4VisCommandSceneEndOfEventAction::~G4VisCommandSceneEndOfEventAction () {
00276 delete fpCommand;
00277 }
00278
00279 G4String G4VisCommandSceneEndOfEventAction::GetCurrentValue(G4UIcommand*) {
00280 return "";
00281 }
00282
00283 void G4VisCommandSceneEndOfEventAction::SetNewValue (G4UIcommand*,
00284 G4String newValue) {
00285
00286 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00287
00288 G4String action;
00289 G4int maxNumberOfKeptEvents;
00290 std::istringstream is (newValue);
00291 is >> action >> maxNumberOfKeptEvents;
00292
00293 G4Scene* pScene = fpVisManager->GetCurrentScene();
00294 if (!pScene) {
00295 if (verbosity >= G4VisManager::errors) {
00296 G4cout << "ERROR: No current scene. Please create one." << G4endl;
00297 }
00298 return;
00299 }
00300
00301 G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler();
00302 if (!pSceneHandler) {
00303 if (verbosity >= G4VisManager::errors) {
00304 G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl;
00305 }
00306 return;
00307 }
00308
00309 if (action == "accumulate") {
00310 pScene->SetRefreshAtEndOfEvent(false);
00311 pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents);
00312 }
00313 else if (action == "refresh") {
00314 if (!pScene->GetRefreshAtEndOfRun()) {
00315 if (verbosity >= G4VisManager::errors) {
00316 G4cout <<
00317 "ERROR: Cannot refresh events unless runs refresh too."
00318 "\n Use \"/vis/scene/endOfRun refresh\"."
00319 << G4endl;
00320 }
00321 } else {
00322 pScene->SetRefreshAtEndOfEvent(true);
00323 pSceneHandler->SetMarkForClearingTransientStore(true);
00324 }
00325 }
00326 else {
00327 if (verbosity >= G4VisManager::errors) {
00328 G4cout <<
00329 "ERROR: unrecognised parameter \"" << action << "\"."
00330 << G4endl;
00331 }
00332 return;
00333 }
00334
00335
00336 fpVisManager->ResetTransientsDrawnFlags();
00337
00338
00339 size_t nCurrentlyKept = 0;
00340 G4RunManager* runManager = G4RunManager::GetRunManager();
00341 if (runManager) {
00342 const G4Run* currentRun = runManager->GetCurrentRun();
00343 if (currentRun) {
00344 const std::vector<const G4Event*>* events =
00345 currentRun->GetEventVector();
00346 if (events) nCurrentlyKept = events->size();
00347 }
00348 }
00349
00350 if (verbosity >= G4VisManager::confirmations) {
00351 G4cout << "End of event action set to ";
00352 if (pScene->GetRefreshAtEndOfEvent()) G4cout << "\"refresh\".";
00353 else {
00354 G4cout << "\"accumulate\"."
00355 "\n Maximum number of events to be kept: "
00356 << maxNumberOfKeptEvents
00357 << " (unlimited if negative)."
00358 "\n This may be changed with, e.g., "
00359 "\"/vis/scene/endOfEventAction accumulate 1000\".";
00360 }
00361 G4cout << G4endl;
00362 }
00363
00364 if (!pScene->GetRefreshAtEndOfEvent() &&
00365 maxNumberOfKeptEvents != 0 &&
00366 verbosity >= G4VisManager::warnings) {
00367 G4cout << "WARNING: ";
00368 if (nCurrentlyKept) {
00369 G4cout <<
00370 "\n There are currently " << nCurrentlyKept
00371 << " events kept for refreshing and/or reviewing.";
00372 } else {
00373 G4cout << "The vis manager will keep ";
00374 if (maxNumberOfKeptEvents < 0) G4cout << "an unlimited number of";
00375 else G4cout << "up to " << maxNumberOfKeptEvents;
00376 G4cout << " events.";
00377 if (maxNumberOfKeptEvents > 1 || maxNumberOfKeptEvents < 0)
00378 G4cout <<
00379 "\n This may use a lot of memory."
00380 "\n It may be changed with, e.g., "
00381 "\"/vis/scene/endOfEventAction accumulate 10\".";
00382 }
00383 G4cout << G4endl;
00384 }
00385 }
00386
00388
00389 G4VisCommandSceneEndOfRunAction::G4VisCommandSceneEndOfRunAction () {
00390 G4bool omitable;
00391 fpCommand = new G4UIcmdWithAString ("/vis/scene/endOfRunAction", this);
00392 fpCommand -> SetGuidance
00393 ("Accumulate or refresh the viewer for each new run.");
00394 fpCommand -> SetGuidance
00395 ("\"accumulate\": viewer accumulates hits, etc., run by run, or");
00396 fpCommand -> SetGuidance
00397 ("\"refresh\": viewer shows them at end of run or, for direct-screen"
00398 "\n viewers, refreshes the screen just before drawing the first"
00399 "\n event of the next run.");
00400 fpCommand -> SetGuidance ("The detector remains or is redrawn.");
00401 fpCommand -> SetParameterName ("action", omitable = true);
00402 fpCommand -> SetCandidates ("accumulate refresh");
00403 fpCommand -> SetDefaultValue ("refresh");
00404 }
00405
00406 G4VisCommandSceneEndOfRunAction::~G4VisCommandSceneEndOfRunAction () {
00407 delete fpCommand;
00408 }
00409
00410 G4String G4VisCommandSceneEndOfRunAction::GetCurrentValue(G4UIcommand*) {
00411 return "";
00412 }
00413
00414 void G4VisCommandSceneEndOfRunAction::SetNewValue (G4UIcommand*,
00415 G4String newValue) {
00416
00417 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00418
00419 G4String action;
00420 std::istringstream is (newValue);
00421 is >> action;
00422
00423 G4Scene* pScene = fpVisManager->GetCurrentScene();
00424 if (!pScene) {
00425 if (verbosity >= G4VisManager::errors) {
00426 G4cout << "ERROR: No current scene. Please create one." << G4endl;
00427 }
00428 return;
00429 }
00430
00431 G4VSceneHandler* pSceneHandler = fpVisManager->GetCurrentSceneHandler();
00432 if (!pSceneHandler) {
00433 if (verbosity >= G4VisManager::errors) {
00434 G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl;
00435 }
00436 return;
00437 }
00438
00439 if (action == "accumulate") {
00440 if (pScene->GetRefreshAtEndOfEvent()) {
00441 if (verbosity >= G4VisManager::errors) {
00442 G4cout <<
00443 "ERROR: Cannot accumulate runs unless events accumulate too."
00444 "\n Use \"/vis/scene/endOfEventAction accumulate\"."
00445 << G4endl;
00446 }
00447 }
00448 else {
00449 pScene->SetRefreshAtEndOfRun(false);
00450 }
00451 }
00452 else if (action == "refresh") {
00453 pScene->SetRefreshAtEndOfRun(true);
00454 pSceneHandler->SetMarkForClearingTransientStore(true);
00455 }
00456 else {
00457 if (verbosity >= G4VisManager::errors) {
00458 G4cout <<
00459 "ERROR: unrecognised parameter \"" << action << "\"."
00460 << G4endl;
00461 }
00462 return;
00463 }
00464
00465
00466 fpVisManager->ResetTransientsDrawnFlags();
00467
00468 if (verbosity >= G4VisManager::confirmations) {
00469 G4cout << "End of run action set to \"";
00470 if (pScene->GetRefreshAtEndOfRun()) G4cout << "refresh";
00471 else G4cout << "accumulate";
00472 G4cout << "\"" << G4endl;
00473 }
00474 }
00475
00477
00478 G4VisCommandSceneList::G4VisCommandSceneList () {
00479 G4bool omitable;
00480 fpCommand = new G4UIcommand ("/vis/scene/list", this);
00481 fpCommand -> SetGuidance ("Lists scene(s).");
00482 fpCommand -> SetGuidance
00483 ("\"help /vis/verbose\" for definition of verbosity.");
00484 G4UIparameter* parameter;
00485 parameter = new G4UIparameter ("scene-name", 's', omitable = true);
00486 parameter -> SetDefaultValue ("all");
00487 fpCommand -> SetParameter (parameter);
00488 parameter = new G4UIparameter ("verbosity", 's', omitable = true);
00489 parameter -> SetDefaultValue ("warnings");
00490 fpCommand -> SetParameter (parameter);
00491 }
00492
00493 G4VisCommandSceneList::~G4VisCommandSceneList () {
00494 delete fpCommand;
00495 }
00496
00497 G4String G4VisCommandSceneList::GetCurrentValue (G4UIcommand*) {
00498 return "";
00499 }
00500
00501 void G4VisCommandSceneList::SetNewValue (G4UIcommand*, G4String newValue) {
00502 G4String name, verbosityString;
00503 std::istringstream is (newValue);
00504 is >> name >> verbosityString;
00505 G4VisManager::Verbosity verbosity =
00506 fpVisManager->GetVerbosityValue(verbosityString);
00507 const G4Scene* currentScene = fpVisManager -> GetCurrentScene ();
00508 G4String currentName;
00509 if (currentScene) currentName = currentScene->GetName();
00510
00511 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
00512 G4int iScene, nScenes = sceneList.size ();
00513 G4bool found = false;
00514 for (iScene = 0; iScene < nScenes; iScene++) {
00515 G4Scene* pScene = sceneList [iScene];
00516 const G4String& iName = pScene -> GetName ();
00517 if (name != "all") {
00518 if (name != iName) continue;
00519 }
00520 found = true;
00521 if (iName == currentName) {
00522 G4cout << " (current)";
00523 }
00524 else {
00525 G4cout << " ";
00526 }
00527 G4cout << " scene \"" << iName << "\"";
00528 if (verbosity >= G4VisManager::warnings) {
00529 G4int i;
00530 G4cout << "\n Run-duration models:";
00531 G4int nRunModels = pScene -> GetRunDurationModelList ().size ();
00532 if (nRunModels == 0) {
00533 G4cout << " none.";
00534 }
00535 for (i = 0; i < nRunModels; i++) {
00536 if (pScene -> GetRunDurationModelList()[i].fActive)
00537 G4cout << "\n Active: ";
00538 else G4cout << "\n Inactive: ";
00539 G4VModel* pModel = pScene -> GetRunDurationModelList()[i].fpModel;
00540 G4cout << pModel -> GetGlobalDescription ();
00541 }
00542 G4cout << "\n End-of-event models:";
00543 G4int nEOEModels = pScene -> GetEndOfEventModelList ().size ();
00544 if (nEOEModels == 0) {
00545 G4cout << " none.";
00546 }
00547 for (i = 0; i < nEOEModels; i++) {
00548 if (pScene -> GetEndOfEventModelList()[i].fActive)
00549 G4cout << "\n Active: ";
00550 else G4cout << "\n Inactive: ";
00551 G4VModel* pModel = pScene -> GetEndOfEventModelList()[i].fpModel;
00552 G4cout << pModel -> GetGlobalDescription ();
00553 }
00554 G4cout << "\n End-of-run models:";
00555 G4int nEORModels = pScene -> GetEndOfRunModelList ().size ();
00556 if (nEORModels == 0) {
00557 G4cout << " none.";
00558 }
00559 for (i = 0; i < nEORModels; i++) {
00560 if (pScene -> GetEndOfRunModelList()[i].fActive)
00561 G4cout << "\n Active: ";
00562 else G4cout << "\n Inactive: ";
00563 G4VModel* pModel = pScene -> GetEndOfRunModelList()[i].fpModel;
00564 G4cout << pModel -> GetGlobalDescription ();
00565 }
00566 }
00567 if (verbosity >= G4VisManager::parameters) {
00568 G4cout << "\n " << *sceneList [iScene];
00569 }
00570 G4cout << G4endl;
00571 }
00572 if (!found) {
00573 G4cout << "No scenes found";
00574 if (name != "all") {
00575 G4cout << " of name \"" << name << "\"";
00576 }
00577 G4cout << "." << G4endl;
00578 }
00579 }
00580
00582
00583 G4VisCommandSceneNotifyHandlers::G4VisCommandSceneNotifyHandlers () {
00584 G4bool omitable;
00585 fpCommand = new G4UIcommand ("/vis/scene/notifyHandlers", this);
00586 fpCommand -> SetGuidance
00587 ("Notifies scene handlers and forces re-rendering.");
00588 fpCommand -> SetGuidance
00589 ("Notifies the handler(s) of the specified scene and forces a"
00590 "\nreconstruction of any graphical databases."
00591 "\nClears and refreshes all viewers of current scene."
00592 "\n The default action \"refresh\" does not issue \"update\" (see"
00593 "\n /vis/viewer/update)."
00594 "\nIf \"flush\" is specified, it issues an \"update\" as well as"
00595 "\n \"refresh\" - \"update\" and initiates post-processing"
00596 "\n for graphics systems which need it.");
00597 fpCommand -> SetGuidance
00598 ("The default for <scene-name> is the current scene name.");
00599 fpCommand -> SetGuidance
00600 ("This command does not change current scene, scene handler or viewer.");
00601 G4UIparameter* parameter;
00602 parameter = new G4UIparameter ("scene-name", 's',
00603 omitable = true);
00604 parameter -> SetCurrentAsDefault(true);
00605 fpCommand -> SetParameter (parameter);
00606 parameter = new G4UIparameter ("refresh-flush", 's',
00607 omitable = true);
00608 parameter -> SetDefaultValue("refresh");
00609 parameter -> SetParameterCandidates("r refresh f flush");
00610 fpCommand -> SetParameter (parameter);
00611 }
00612
00613 G4VisCommandSceneNotifyHandlers::~G4VisCommandSceneNotifyHandlers () {
00614 delete fpCommand;
00615 }
00616
00617 G4String G4VisCommandSceneNotifyHandlers::GetCurrentValue(G4UIcommand*) {
00618 return CurrentSceneName ();
00619 }
00620
00621 void G4VisCommandSceneNotifyHandlers::SetNewValue (G4UIcommand*,
00622 G4String newValue) {
00623
00624 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00625
00626 G4String sceneName, refresh_flush;
00627 std::istringstream is (newValue);
00628 is >> sceneName >> refresh_flush;
00629 G4bool flush = false;
00630 if (refresh_flush(0) == 'f') flush = true;
00631
00632 const G4SceneList& sceneList = fpVisManager -> GetSceneList ();
00633 G4SceneHandlerList& sceneHandlerList =
00634 fpVisManager -> SetAvailableSceneHandlers ();
00635
00636
00637 const G4int nScenes = sceneList.size ();
00638 G4int iScene;
00639 for (iScene = 0; iScene < nScenes; iScene++) {
00640 G4Scene* scene = sceneList [iScene];
00641 if (sceneName == scene -> GetName ()) break;
00642 }
00643 if (iScene >= nScenes ) {
00644 if (verbosity >= G4VisManager::warnings) {
00645 G4cout << "WARNING: Scene \"" << sceneName << "\" not found."
00646 "\n /vis/scene/list to see scenes."
00647 << G4endl;
00648 }
00649 return;
00650 }
00651
00652
00653 G4VSceneHandler* pCurrentSceneHandler =
00654 fpVisManager -> GetCurrentSceneHandler();
00655 if (!pCurrentSceneHandler) {
00656 if (verbosity >= G4VisManager::warnings) {
00657 G4cout << "WARNING: No current scene handler."
00658 << G4endl;
00659 }
00660 return;
00661 }
00662 G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer();
00663 if (!pCurrentViewer) {
00664 if (verbosity >= G4VisManager::warnings) {
00665 G4cout << "WARNING: No current viewer."
00666 << G4endl;
00667 }
00668 return;
00669 }
00670 G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene();
00671 if (!pCurrentScene) {
00672 if (verbosity >= G4VisManager::warnings) {
00673 G4cout << "WARNING: No current scene."
00674 << G4endl;
00675 }
00676 return;
00677 }
00678
00679 G4VisManager::Verbosity currentVerbosity = fpVisManager -> GetVerbosity();
00680
00681
00682
00683
00684
00685
00686
00687 const G4int nSceneHandlers = sceneHandlerList.size ();
00688 for (G4int iSH = 0; iSH < nSceneHandlers; iSH++) {
00689 G4VSceneHandler* aSceneHandler = sceneHandlerList [iSH];
00690 G4Scene* aScene = aSceneHandler -> GetScene ();
00691 if (aScene) {
00692 const G4String& aSceneName = aScene -> GetName ();
00693 if (sceneName == aSceneName) {
00694 aScene->CalculateExtent();
00695 G4ViewerList& viewerList = aSceneHandler -> SetViewerList ();
00696 const G4int nViewers = viewerList.size ();
00697 for (G4int iV = 0; iV < nViewers; iV++) {
00698 G4VViewer* aViewer = viewerList [iV];
00699
00700 aViewer -> NeedKernelVisit();
00701 if (aViewer->GetViewParameters().IsAutoRefresh()) {
00702 aSceneHandler -> SetCurrentViewer (aViewer);
00703
00704 fpVisManager -> SetCurrentViewer(aViewer);
00705 fpVisManager -> SetCurrentSceneHandler(aSceneHandler);
00706 fpVisManager -> SetCurrentScene(aScene);
00707 aViewer -> SetView ();
00708 aViewer -> ClearView ();
00709 aViewer -> DrawView ();
00710 if (flush) aViewer -> ShowView ();
00711 if (verbosity >= G4VisManager::confirmations) {
00712 G4cout << "Viewer \"" << aViewer -> GetName ()
00713 << "\" of scene handler \"" << aSceneHandler -> GetName ()
00714 << "\"\n ";
00715 if (flush) G4cout << "flushed";
00716 else G4cout << "refreshed";
00717 G4cout << " at request of scene \"" << sceneName
00718 << "\"." << G4endl;
00719 }
00720 } else {
00721 if (verbosity >= G4VisManager::confirmations) {
00722 G4cout << "NOTE: The scene, \""
00723 << sceneName
00724 << "\", of viewer \""
00725 << aViewer -> GetName ()
00726 << "\"\n of scene handler \""
00727 << aSceneHandler -> GetName ()
00728 << "\" has changed. To see effect,"
00729 << "\n \"/vis/viewer/select "
00730 << aViewer -> GetShortName ()
00731 << "\" and \"/vis/viewer/rebuild\"."
00732 << G4endl;
00733 }
00734 }
00735 }
00736 }
00737 }
00738 else {
00739 if (verbosity >= G4VisManager::warnings) {
00740 G4cout << "WARNING: G4VisCommandSceneNotifyHandlers: scene handler \""
00741 << aSceneHandler->GetName()
00742 << "\" has a null scene."
00743 << G4endl;
00744 }
00745 }
00746 }
00747
00748
00749
00750
00751
00752
00753
00754 fpVisManager -> SetCurrentViewer(pCurrentViewer);
00755 fpVisManager -> SetCurrentSceneHandler(pCurrentSceneHandler);
00756 fpVisManager -> SetCurrentScene(pCurrentScene);
00757 fpVisManager -> SetVerboseLevel(currentVerbosity);
00758
00759 if (pCurrentSceneHandler) {
00760 G4ViewerList& viewerList = pCurrentSceneHandler -> SetViewerList ();
00761 const G4int nViewers = viewerList.size ();
00762 if (nViewers) {
00763 pCurrentSceneHandler -> SetCurrentViewer (pCurrentViewer);
00764 if (pCurrentViewer && pCurrentSceneHandler->GetScene()) {
00765 pCurrentViewer -> SetView ();
00766 }
00767 }
00768 }
00769 }
00770
00772
00773 G4VisCommandSceneSelect::G4VisCommandSceneSelect () {
00774 G4bool omitable;
00775 fpCommand = new G4UIcmdWithAString ("/vis/scene/select", this);
00776 fpCommand -> SetGuidance ("Selects a scene");
00777 fpCommand -> SetGuidance
00778 ("Makes the scene current. \"/vis/scene/list\" to see"
00779 "\n possible scene names.");
00780 fpCommand -> SetParameterName ("scene-name", omitable = false);
00781 }
00782
00783 G4VisCommandSceneSelect::~G4VisCommandSceneSelect () {
00784 delete fpCommand;
00785 }
00786
00787 G4String G4VisCommandSceneSelect::GetCurrentValue (G4UIcommand*) {
00788 return "";
00789 }
00790
00791 void G4VisCommandSceneSelect::SetNewValue (G4UIcommand*, G4String newValue) {
00792
00793 G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00794
00795 G4String& selectName = newValue;
00796 G4SceneList& sceneList = fpVisManager -> SetSceneList ();
00797 G4int iScene, nScenes = sceneList.size ();
00798 for (iScene = 0; iScene < nScenes; iScene++) {
00799 if (sceneList [iScene] -> GetName () == selectName) break;
00800 }
00801 if (iScene >= nScenes) {
00802 if (verbosity >= G4VisManager::warnings) {
00803 G4cout << "WARNING: Scene \"" << selectName
00804 << "\" not found - \"/vis/scene/list\" to see possibilities."
00805 << G4endl;
00806 }
00807 return;
00808 }
00809
00810 if (verbosity >= G4VisManager::confirmations) {
00811 G4cout << "Scene \"" << selectName
00812 << "\" selected." << G4endl;
00813 }
00814 UpdateVisManagerScene (selectName);
00815 }