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