Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisCommandsScene.cc
Go to the documentation of this file.
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$
28 
29 // /vis/scene commands - John Allison 9th August 1998
30 
31 #include "G4VisCommandsScene.hh"
32 
33 #include "G4VisManager.hh"
35 #include "G4RunManager.hh"
36 #include "G4Run.hh"
37 #include "G4PhysicalVolumeModel.hh"
38 #include "G4ApplicationState.hh"
39 #include "G4UImanager.hh"
40 #include "G4UIcommand.hh"
41 #include "G4UIcmdWithAString.hh"
42 #include "G4ios.hh"
43 #include <sstream>
44 
46 
48 
50  const G4Scene* pScene = fpVisManager -> GetCurrentScene ();
51  G4String currentSceneName = "none";
52  if (pScene) currentSceneName = pScene -> GetName ();
53  return currentSceneName;
54 }
55 
57 
59  G4bool omitable;
60  fpCommand = new G4UIcommand ("/vis/scene/activateModel", this);
61  fpCommand -> SetGuidance
62  ("Activate or de-activate model.");
63  fpCommand -> SetGuidance
64  ("Attempts to match search string to name of model - use unique sub-string.");
65  fpCommand -> SetGuidance
66  ("Use \"/vis/scene/list\" to see model names.");
67  fpCommand -> SetGuidance
68  ("If name == \"all\" (default), all models are activated.");
69  G4UIparameter* parameter;
70  parameter = new G4UIparameter ("search-string", 's', omitable = true);
71  parameter -> SetDefaultValue ("all");
72  fpCommand -> SetParameter (parameter);
73  parameter = new G4UIparameter ("activate", 'b', omitable = true);
74  parameter -> SetDefaultValue (true);
75  fpCommand -> SetParameter (parameter);
76 }
77 
79  delete fpCommand;
80 }
81 
83  return "";
84 }
85 
87  G4String newValue) {
88 
90 
91  G4String searchString, activateString;
92  std::istringstream is (newValue);
93  is >> searchString >> activateString;
94  G4bool activate = G4UIcommand::ConvertToBool(activateString);
95 
97  if (!pScene) {
98  if (verbosity >= G4VisManager::errors) {
99  G4cout << "ERROR: No current scene. Please create one." << G4endl;
100  }
101  return;
102  }
103 
105  if (!pSceneHandler) {
106  if (verbosity >= G4VisManager::errors) {
107  G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl;
108  }
109  return;
110  }
111 
112  if (searchString == "all" && !activate) {
113  if (verbosity >= G4VisManager::warnings) {
114  G4cout <<
115  "WARNING: You are not allowed to de-activate all models."
116  "\n Command ignored."
117  << G4endl;
118  }
119  return;
120  }
121 
122  G4bool any = false;
123 
124  std::vector<G4Scene::Model>& runDurationModelList =
125  pScene->SetRunDurationModelList();
126  for (size_t i = 0; i < runDurationModelList.size(); i++) {
127  const G4String& modelName =
128  runDurationModelList[i].fpModel->GetGlobalDescription();
129  if (searchString == "all" || modelName.find(searchString)
130  != std::string::npos) {
131  any = true;
132  runDurationModelList[i].fActive = activate;
133  if (verbosity >= G4VisManager::warnings) {
134  G4cout << "Model \"" << modelName;
135  if (activate) G4cout << "\" activated.";
136  else G4cout << "\" de-activated.";
137  G4cout << G4endl;
138  }
139  }
140  }
141 
142  std::vector<G4Scene::Model>& endOfEventModelList =
143  pScene->SetEndOfEventModelList();
144  for (size_t i = 0; i < endOfEventModelList.size(); i++) {
145  const G4String& modelName =
146  endOfEventModelList[i].fpModel->GetGlobalDescription();
147  if (searchString == "all" || modelName.find(searchString)
148  != std::string::npos) {
149  any = true;
150  endOfEventModelList[i].fActive = activate;
151  if (verbosity >= G4VisManager::warnings) {
152  G4cout << "Model \"" << modelName;
153  if (activate) G4cout << "\" activated.";
154  else G4cout << "\" de-activated.";
155  G4cout << G4endl;
156  }
157  }
158  }
159 
160  std::vector<G4Scene::Model>& endOfRunModelList =
161  pScene->SetEndOfRunModelList();
162  for (size_t i = 0; i < endOfRunModelList.size(); i++) {
163  const G4String& modelName =
164  endOfRunModelList[i].fpModel->GetGlobalDescription();
165  if (searchString == "all" || modelName.find(searchString)
166  != std::string::npos) {
167  any = true;
168  endOfRunModelList[i].fActive = activate;
169  if (verbosity >= G4VisManager::warnings) {
170  G4cout << "Model \"" << modelName;
171  if (activate) G4cout << "\" activated.";
172  else G4cout << "\" de-activated.";
173  G4cout << G4endl;
174  }
175  }
176  }
177 
178  if (!any) {
179  if (verbosity >= G4VisManager::warnings) {
180  G4cout << "WARNING: No match found." << G4endl;
181  }
182  return;
183  }
184 
185  const G4String& currentSceneName = pScene -> GetName ();
186  UpdateVisManagerScene (currentSceneName);
187 }
188 
190 
192  G4bool omitable;
193  fpCommand = new G4UIcmdWithAString ("/vis/scene/create", this);
194  fpCommand -> SetGuidance
195  ("Creates an empty scene.");
196  fpCommand -> SetGuidance
197  ("Invents a name if not supplied. This scene becomes current.");
198  fpCommand -> SetParameterName ("scene-name", omitable = true);
199 }
200 
202  delete fpCommand;
203 }
204 
205 G4String G4VisCommandSceneCreate::NextName () {
206  std::ostringstream oss;
207  oss << "scene-" << fId;
208  return oss.str();
209 }
210 
212  return "";
213 }
214 
216 
218 
219  G4String& newName = newValue;
220  G4String nextName = NextName ();
221 
222  if (newName == "") {
223  newName = nextName;
224  }
225  if (newName == nextName) fId++;
226 
227  G4SceneList& sceneList = fpVisManager -> SetSceneList ();
228  G4int iScene, nScenes = sceneList.size ();
229  for (iScene = 0; iScene < nScenes; iScene++) {
230  if (sceneList [iScene] -> GetName () == newName) break;
231  }
232  if (iScene < nScenes) {
233  if (verbosity >= G4VisManager::warnings) {
234  G4cout << "WARNING: Scene \"" << newName << "\" already exists."
235  << "\n New scene not created."
236  << G4endl;
237  }
238  } else {
239 
240  // Add empty scene data object to list...
241  G4Scene* pScene = new G4Scene (newName);
242  sceneList.push_back (pScene);
243  fpVisManager -> SetCurrentScene (pScene);
244 
245  if (verbosity >= G4VisManager::confirmations) {
246  G4cout << "New empty scene \"" << newName << "\" created." << G4endl;
247  }
248  }
249 }
250 
252 
254  G4bool omitable;
255  fpCommand = new G4UIcommand ("/vis/scene/endOfEventAction", this);
256  fpCommand -> SetGuidance
257  ("Accumulate or refresh the viewer for each new event.");
258  fpCommand -> SetGuidance
259  ("\"accumulate\": viewer accumulates hits, etc., event by event, or");
260  fpCommand -> SetGuidance
261  ("\"refresh\": viewer shows them at end of event or, for direct-screen"
262  "\n viewers, refreshes the screen just before drawing the next event.");
263  G4UIparameter* parameter;
264  parameter = new G4UIparameter ("action", 's', omitable = true);
265  parameter -> SetParameterCandidates ("accumulate refresh");
266  parameter -> SetDefaultValue ("refresh");
267  fpCommand -> SetParameter (parameter);
268  parameter = new G4UIparameter ("maxNumber", 'i', omitable = true);
269  parameter -> SetDefaultValue (100);
270  parameter -> SetGuidance
271  ("Maximum number of events kept. Unlimited if negative.");
272  fpCommand -> SetParameter (parameter);
273 }
274 
276  delete fpCommand;
277 }
278 
280  return "";
281 }
282 
284  G4String newValue) {
285 
287 
288  G4String action;
289  G4int maxNumberOfKeptEvents;
290  std::istringstream is (newValue);
291  is >> action >> maxNumberOfKeptEvents;
292 
293  G4Scene* pScene = fpVisManager->GetCurrentScene();
294  if (!pScene) {
295  if (verbosity >= G4VisManager::errors) {
296  G4cout << "ERROR: No current scene. Please create one." << G4endl;
297  }
298  return;
299  }
300 
302  if (!pSceneHandler) {
303  if (verbosity >= G4VisManager::errors) {
304  G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl;
305  }
306  return;
307  }
308 
309  if (action == "accumulate") {
310  pScene->SetRefreshAtEndOfEvent(false);
311  pScene->SetMaxNumberOfKeptEvents(maxNumberOfKeptEvents);
312  }
313  else if (action == "refresh") {
314  if (!pScene->GetRefreshAtEndOfRun()) {
315  if (verbosity >= G4VisManager::errors) {
316  G4cout <<
317  "ERROR: Cannot refresh events unless runs refresh too."
318  "\n Use \"/vis/scene/endOfRun refresh\"."
319  << G4endl;
320  }
321  } else {
322  pScene->SetRefreshAtEndOfEvent(true);
323  pSceneHandler->SetMarkForClearingTransientStore(true);
324  }
325  }
326  else {
327  if (verbosity >= G4VisManager::errors) {
328  G4cout <<
329  "ERROR: unrecognised parameter \"" << action << "\"."
330  << G4endl;
331  }
332  return;
333  }
334 
335  // Change of transients behaviour, so...
337 
338  // Are there any events currently kept...
339  size_t nCurrentlyKept = 0;
341  if (runManager) {
342  const G4Run* currentRun = runManager->GetCurrentRun();
343  if (currentRun) {
344  const std::vector<const G4Event*>* events =
345  currentRun->GetEventVector();
346  if (events) nCurrentlyKept = events->size();
347  }
348  }
349 
350  if (verbosity >= G4VisManager::confirmations) {
351  G4cout << "End of event action set to ";
352  if (pScene->GetRefreshAtEndOfEvent()) G4cout << "\"refresh\".";
353  else {
354  G4cout << "\"accumulate\"."
355  "\n Maximum number of events to be kept: "
356  << maxNumberOfKeptEvents
357  << " (unlimited if negative)."
358  "\n This may be changed with, e.g., "
359  "\"/vis/scene/endOfEventAction accumulate 1000\".";
360  }
361  G4cout << G4endl;
362  }
363 
364  if (!pScene->GetRefreshAtEndOfEvent() &&
365  maxNumberOfKeptEvents != 0 &&
366  verbosity >= G4VisManager::warnings) {
367  G4cout << "WARNING: ";
368  if (nCurrentlyKept) {
369  G4cout <<
370  "\n There are currently " << nCurrentlyKept
371  << " events kept for refreshing and/or reviewing.";
372  } else {
373  G4cout << "The vis manager will keep ";
374  if (maxNumberOfKeptEvents < 0) G4cout << "an unlimited number of";
375  else G4cout << "up to " << maxNumberOfKeptEvents;
376  G4cout << " events.";
377  if (maxNumberOfKeptEvents > 1 || maxNumberOfKeptEvents < 0)
378  G4cout <<
379  "\n This may use a lot of memory."
380  "\n It may be changed with, e.g., "
381  "\"/vis/scene/endOfEventAction accumulate 10\".";
382  }
383  G4cout << G4endl;
384  }
385 }
386 
388 
390  G4bool omitable;
391  fpCommand = new G4UIcmdWithAString ("/vis/scene/endOfRunAction", this);
392  fpCommand -> SetGuidance
393  ("Accumulate or refresh the viewer for each new run.");
394  fpCommand -> SetGuidance
395  ("\"accumulate\": viewer accumulates hits, etc., run by run, or");
396  fpCommand -> SetGuidance
397  ("\"refresh\": viewer shows them at end of run or, for direct-screen"
398  "\n viewers, refreshes the screen just before drawing the first"
399  "\n event of the next run.");
400  fpCommand -> SetGuidance ("The detector remains or is redrawn.");
401  fpCommand -> SetParameterName ("action", omitable = true);
402  fpCommand -> SetCandidates ("accumulate refresh");
403  fpCommand -> SetDefaultValue ("refresh");
404 }
405 
407  delete fpCommand;
408 }
409 
411  return "";
412 }
413 
415  G4String newValue) {
416 
418 
419  G4String action;
420  std::istringstream is (newValue);
421  is >> action;
422 
423  G4Scene* pScene = fpVisManager->GetCurrentScene();
424  if (!pScene) {
425  if (verbosity >= G4VisManager::errors) {
426  G4cout << "ERROR: No current scene. Please create one." << G4endl;
427  }
428  return;
429  }
430 
432  if (!pSceneHandler) {
433  if (verbosity >= G4VisManager::errors) {
434  G4cout << "ERROR: No current sceneHandler. Please create one." << G4endl;
435  }
436  return;
437  }
438 
439  if (action == "accumulate") {
440  if (pScene->GetRefreshAtEndOfEvent()) {
441  if (verbosity >= G4VisManager::errors) {
442  G4cout <<
443  "ERROR: Cannot accumulate runs unless events accumulate too."
444  "\n Use \"/vis/scene/endOfEventAction accumulate\"."
445  << G4endl;
446  }
447  }
448  else {
449  pScene->SetRefreshAtEndOfRun(false);
450  }
451  }
452  else if (action == "refresh") {
453  pScene->SetRefreshAtEndOfRun(true);
454  pSceneHandler->SetMarkForClearingTransientStore(true);
455  }
456  else {
457  if (verbosity >= G4VisManager::errors) {
458  G4cout <<
459  "ERROR: unrecognised parameter \"" << action << "\"."
460  << G4endl;
461  }
462  return;
463  }
464 
465  // Change of transients behaviour, so...
467 
468  if (verbosity >= G4VisManager::confirmations) {
469  G4cout << "End of run action set to \"";
470  if (pScene->GetRefreshAtEndOfRun()) G4cout << "refresh";
471  else G4cout << "accumulate";
472  G4cout << "\"" << G4endl;
473  }
474 }
475 
477 
479  G4bool omitable;
480  fpCommand = new G4UIcommand ("/vis/scene/list", this);
481  fpCommand -> SetGuidance ("Lists scene(s).");
482  fpCommand -> SetGuidance
483  ("\"help /vis/verbose\" for definition of verbosity.");
484  G4UIparameter* parameter;
485  parameter = new G4UIparameter ("scene-name", 's', omitable = true);
486  parameter -> SetDefaultValue ("all");
487  fpCommand -> SetParameter (parameter);
488  parameter = new G4UIparameter ("verbosity", 's', omitable = true);
489  parameter -> SetDefaultValue ("warnings");
490  fpCommand -> SetParameter (parameter);
491 }
492 
494  delete fpCommand;
495 }
496 
498  return "";
499 }
500 
502  G4String name, verbosityString;
503  std::istringstream is (newValue);
504  is >> name >> verbosityString;
505  G4VisManager::Verbosity verbosity =
506  fpVisManager->GetVerbosityValue(verbosityString);
507  const G4Scene* currentScene = fpVisManager -> GetCurrentScene ();
508  G4String currentName;
509  if (currentScene) currentName = currentScene->GetName();
510 
511  G4SceneList& sceneList = fpVisManager -> SetSceneList ();
512  G4int iScene, nScenes = sceneList.size ();
513  G4bool found = false;
514  for (iScene = 0; iScene < nScenes; iScene++) {
515  G4Scene* pScene = sceneList [iScene];
516  const G4String& iName = pScene -> GetName ();
517  if (name != "all") {
518  if (name != iName) continue;
519  }
520  found = true;
521  if (iName == currentName) {
522  G4cout << " (current)";
523  }
524  else {
525  G4cout << " ";
526  }
527  G4cout << " scene \"" << iName << "\"";
528  if (verbosity >= G4VisManager::warnings) {
529  G4int i;
530  G4cout << "\n Run-duration models:";
531  G4int nRunModels = pScene -> GetRunDurationModelList ().size ();
532  if (nRunModels == 0) {
533  G4cout << " none.";
534  }
535  for (i = 0; i < nRunModels; i++) {
536  if (pScene -> GetRunDurationModelList()[i].fActive)
537  G4cout << "\n Active: ";
538  else G4cout << "\n Inactive: ";
539  G4VModel* pModel = pScene -> GetRunDurationModelList()[i].fpModel;
540  G4cout << pModel -> GetGlobalDescription ();
541  }
542  G4cout << "\n End-of-event models:";
543  G4int nEOEModels = pScene -> GetEndOfEventModelList ().size ();
544  if (nEOEModels == 0) {
545  G4cout << " none.";
546  }
547  for (i = 0; i < nEOEModels; i++) {
548  if (pScene -> GetEndOfEventModelList()[i].fActive)
549  G4cout << "\n Active: ";
550  else G4cout << "\n Inactive: ";
551  G4VModel* pModel = pScene -> GetEndOfEventModelList()[i].fpModel;
552  G4cout << pModel -> GetGlobalDescription ();
553  }
554  G4cout << "\n End-of-run models:";
555  G4int nEORModels = pScene -> GetEndOfRunModelList ().size ();
556  if (nEORModels == 0) {
557  G4cout << " none.";
558  }
559  for (i = 0; i < nEORModels; i++) {
560  if (pScene -> GetEndOfRunModelList()[i].fActive)
561  G4cout << "\n Active: ";
562  else G4cout << "\n Inactive: ";
563  G4VModel* pModel = pScene -> GetEndOfRunModelList()[i].fpModel;
564  G4cout << pModel -> GetGlobalDescription ();
565  }
566  }
567  if (verbosity >= G4VisManager::parameters) {
568  G4cout << "\n " << *sceneList [iScene];
569  }
570  G4cout << G4endl;
571  }
572  if (!found) {
573  G4cout << "No scenes found";
574  if (name != "all") {
575  G4cout << " of name \"" << name << "\"";
576  }
577  G4cout << "." << G4endl;
578  }
579 }
580 
582 
584  G4bool omitable;
585  fpCommand = new G4UIcommand ("/vis/scene/notifyHandlers", this);
586  fpCommand -> SetGuidance
587  ("Notifies scene handlers and forces re-rendering.");
588  fpCommand -> SetGuidance
589  ("Notifies the handler(s) of the specified scene and forces a"
590  "\nreconstruction of any graphical databases."
591  "\nClears and refreshes all viewers of current scene."
592  "\n The default action \"refresh\" does not issue \"update\" (see"
593  "\n /vis/viewer/update)."
594  "\nIf \"flush\" is specified, it issues an \"update\" as well as"
595  "\n \"refresh\" - \"update\" and initiates post-processing"
596  "\n for graphics systems which need it.");
597  fpCommand -> SetGuidance
598  ("The default for <scene-name> is the current scene name.");
599  fpCommand -> SetGuidance
600  ("This command does not change current scene, scene handler or viewer.");
601  G4UIparameter* parameter;
602  parameter = new G4UIparameter ("scene-name", 's',
603  omitable = true);
604  parameter -> SetCurrentAsDefault(true);
605  fpCommand -> SetParameter (parameter);
606  parameter = new G4UIparameter ("refresh-flush", 's',
607  omitable = true);
608  parameter -> SetDefaultValue("refresh");
609  parameter -> SetParameterCandidates("r refresh f flush");
610  fpCommand -> SetParameter (parameter);
611 }
612 
614  delete fpCommand;
615 }
616 
618  return CurrentSceneName ();
619 }
620 
622  G4String newValue) {
623 
625 
626  G4String sceneName, refresh_flush;
627  std::istringstream is (newValue);
628  is >> sceneName >> refresh_flush;
629  G4bool flush = false;
630  if (refresh_flush(0) == 'f') flush = true;
631 
632  const G4SceneList& sceneList = fpVisManager -> GetSceneList ();
633  G4SceneHandlerList& sceneHandlerList =
634  fpVisManager -> SetAvailableSceneHandlers ();
635 
636  // Check scene name.
637  const G4int nScenes = sceneList.size ();
638  G4int iScene;
639  for (iScene = 0; iScene < nScenes; iScene++) {
640  G4Scene* scene = sceneList [iScene];
641  if (sceneName == scene -> GetName ()) break;
642  }
643  if (iScene >= nScenes ) {
644  if (verbosity >= G4VisManager::warnings) {
645  G4cout << "WARNING: Scene \"" << sceneName << "\" not found."
646  "\n /vis/scene/list to see scenes."
647  << G4endl;
648  }
649  return;
650  }
651 
652  // Store current context...
653  G4VSceneHandler* pCurrentSceneHandler =
654  fpVisManager -> GetCurrentSceneHandler();
655  if (!pCurrentSceneHandler) {
656  if (verbosity >= G4VisManager::warnings) {
657  G4cout << "WARNING: No current scene handler."
658  << G4endl;
659  }
660  return;
661  }
662  G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer();
663  if (!pCurrentViewer) {
664  if (verbosity >= G4VisManager::warnings) {
665  G4cout << "WARNING: No current viewer."
666  << G4endl;
667  }
668  return;
669  }
670  G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene();
671  if (!pCurrentScene) {
672  if (verbosity >= G4VisManager::warnings) {
673  G4cout << "WARNING: No current scene."
674  << G4endl;
675  }
676  return;
677  }
678 
679  G4VisManager::Verbosity currentVerbosity = fpVisManager -> GetVerbosity();
680 
681  // Suppress messages during this process (only print errors)...
682  //fpVisManager -> SetVerboseLevel(G4VisManager::errors);
683 
684  // For each scene handler, if it contains the scene, clear and
685  // rebuild the graphical database, then for each viewer set (make
686  // current), clear, (re)draw, and show.
687  const G4int nSceneHandlers = sceneHandlerList.size ();
688  for (G4int iSH = 0; iSH < nSceneHandlers; iSH++) {
689  G4VSceneHandler* aSceneHandler = sceneHandlerList [iSH];
690  G4Scene* aScene = aSceneHandler -> GetScene ();
691  if (aScene) {
692  const G4String& aSceneName = aScene -> GetName ();
693  if (sceneName == aSceneName) {
694  aScene->CalculateExtent(); // Check and recalculate extent
695  G4ViewerList& viewerList = aSceneHandler -> SetViewerList ();
696  const G4int nViewers = viewerList.size ();
697  for (G4int iV = 0; iV < nViewers; iV++) {
698  G4VViewer* aViewer = viewerList [iV];
699  // Force rebuild of graphical database, if any.
700  aViewer -> NeedKernelVisit();
701  if (aViewer->GetViewParameters().IsAutoRefresh()) {
702  aSceneHandler -> SetCurrentViewer (aViewer);
703  // Ensure consistency of vis manager...
704  fpVisManager -> SetCurrentViewer(aViewer);
705  fpVisManager -> SetCurrentSceneHandler(aSceneHandler);
706  fpVisManager -> SetCurrentScene(aScene);
707  aViewer -> SetView ();
708  aViewer -> ClearView ();
709  aViewer -> DrawView ();
710  if (flush) aViewer -> ShowView ();
711  if (verbosity >= G4VisManager::confirmations) {
712  G4cout << "Viewer \"" << aViewer -> GetName ()
713  << "\" of scene handler \"" << aSceneHandler -> GetName ()
714  << "\"\n ";
715  if (flush) G4cout << "flushed";
716  else G4cout << "refreshed";
717  G4cout << " at request of scene \"" << sceneName
718  << "\"." << G4endl;
719  }
720  } else {
721  if (verbosity >= G4VisManager::confirmations) {
722  G4cout << "NOTE: The scene, \""
723  << sceneName
724  << "\", of viewer \""
725  << aViewer -> GetName ()
726  << "\"\n of scene handler \""
727  << aSceneHandler -> GetName ()
728  << "\" has changed. To see effect,"
729  << "\n \"/vis/viewer/select "
730  << aViewer -> GetShortName ()
731  << "\" and \"/vis/viewer/rebuild\"."
732  << G4endl;
733  }
734  }
735  }
736  }
737  }
738  else {
739  if (verbosity >= G4VisManager::warnings) {
740  G4cout << "WARNING: G4VisCommandSceneNotifyHandlers: scene handler \""
741  << aSceneHandler->GetName()
742  << "\" has a null scene."
743  << G4endl;
744  }
745  }
746  }
747 
748  // Reclaim original context - but set viewer first, then scene
749  // handler, because the latter might have been created very recently
750  // and, not yet having a viewer, the current viewer will,
751  // temporarily, refer to another scene handler. SetCurrentViewer
752  // actually resets the scene handler, which is what we don't want,
753  // so we set it again on the next line...
754  fpVisManager -> SetCurrentViewer(pCurrentViewer);
755  fpVisManager -> SetCurrentSceneHandler(pCurrentSceneHandler);
756  fpVisManager -> SetCurrentScene(pCurrentScene);
757  fpVisManager -> SetVerboseLevel(currentVerbosity);
758  // Take care of special case of scene handler with no viewer yet.
759  if (pCurrentSceneHandler) {
760  G4ViewerList& viewerList = pCurrentSceneHandler -> SetViewerList ();
761  const G4int nViewers = viewerList.size ();
762  if (nViewers) {
763  pCurrentSceneHandler -> SetCurrentViewer (pCurrentViewer);
764  if (pCurrentViewer && pCurrentSceneHandler->GetScene()) {
765  pCurrentViewer -> SetView ();
766  }
767  }
768  }
769 }
770 
772 
774  G4bool omitable;
775  fpCommand = new G4UIcmdWithAString ("/vis/scene/select", this);
776  fpCommand -> SetGuidance ("Selects a scene");
777  fpCommand -> SetGuidance
778  ("Makes the scene current. \"/vis/scene/list\" to see"
779  "\n possible scene names.");
780  fpCommand -> SetParameterName ("scene-name", omitable = false);
781 }
782 
784  delete fpCommand;
785 }
786 
788  return "";
789 }
790 
792 
794 
795  G4String& selectName = newValue;
796  G4SceneList& sceneList = fpVisManager -> SetSceneList ();
797  G4int iScene, nScenes = sceneList.size ();
798  for (iScene = 0; iScene < nScenes; iScene++) {
799  if (sceneList [iScene] -> GetName () == selectName) break;
800  }
801  if (iScene >= nScenes) {
802  if (verbosity >= G4VisManager::warnings) {
803  G4cout << "WARNING: Scene \"" << selectName
804  << "\" not found - \"/vis/scene/list\" to see possibilities."
805  << G4endl;
806  }
807  return;
808  }
809 
810  if (verbosity >= G4VisManager::confirmations) {
811  G4cout << "Scene \"" << selectName
812  << "\" selected." << G4endl;
813  }
814  UpdateVisManagerScene (selectName);
815 }