source: trunk/source/visualization/management/src/G4VisCommandsScene.cc @ 1315

Last change on this file since 1315 was 1308, checked in by garnier, 14 years ago

cvs update

  • Property svn:mime-type set to text/cpp
File size: 22.4 KB
Line 
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: G4VisCommandsScene.cc,v 1.68 2008/04/28 16:12:38 allison Exp $
28// GEANT4 tag $Name:  $
29
30// /vis/scene commands - John Allison  9th August 1998
31
32#include "G4VisCommandsScene.hh"
33
34#include "G4VisManager.hh"
35#include "G4TransportationManager.hh"
36#include "G4RunManager.hh"
37#include "G4Run.hh"
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
46G4VVisCommandScene::G4VVisCommandScene () {}
47
48G4VVisCommandScene::~G4VVisCommandScene () {}
49
50G4String 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
59G4VisCommandSceneCreate::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
69G4VisCommandSceneCreate::~G4VisCommandSceneCreate () {
70  delete fpCommand;
71}
72
73G4String G4VisCommandSceneCreate::NextName () {
74  std::ostringstream oss;
75  oss << "scene-" << fId;
76  return oss.str();
77}
78
79G4String G4VisCommandSceneCreate::GetCurrentValue (G4UIcommand*) {
80  return "";
81}
82
83void 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
121G4VisCommandSceneEndOfEventAction::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
143G4VisCommandSceneEndOfEventAction::~G4VisCommandSceneEndOfEventAction () {
144  delete fpCommand;
145}
146
147G4String G4VisCommandSceneEndOfEventAction::GetCurrentValue(G4UIcommand*) {
148  return "";
149}
150
151void 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
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
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., "
227        "\"/vis/scene/endOfEventAction accumulate 1000\".";
228    }
229    G4cout << G4endl;
230  }
231
232  if (!pScene->GetRefreshAtEndOfEvent() &&
233      maxNumberOfKeptEvents != 0 &&
234      verbosity >= G4VisManager::warnings) {
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)
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\".";
250    }
251    G4cout << G4endl;
252  }
253}
254
255////////////// /vis/scene/endOfRunAction ////////////////////////////
256
257G4VisCommandSceneEndOfRunAction::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
274G4VisCommandSceneEndOfRunAction::~G4VisCommandSceneEndOfRunAction () {
275  delete fpCommand;
276}
277
278G4String G4VisCommandSceneEndOfRunAction::GetCurrentValue(G4UIcommand*) {
279  return "";
280}
281
282void 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
346G4VisCommandSceneList::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
361G4VisCommandSceneList::~G4VisCommandSceneList () {
362  delete fpCommand;
363}
364
365G4String G4VisCommandSceneList::GetCurrentValue (G4UIcommand*) {
366  return "";
367}
368
369void 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
433G4VisCommandSceneNotifyHandlers::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
463G4VisCommandSceneNotifyHandlers::~G4VisCommandSceneNotifyHandlers () {
464  delete fpCommand;
465}
466
467G4String G4VisCommandSceneNotifyHandlers::GetCurrentValue(G4UIcommand*) {
468  return CurrentSceneName ();
469}
470
471void G4VisCommandSceneNotifyHandlers::SetNewValue (G4UIcommand*,
472                                                   G4String newValue) {
473
474#ifdef G4DEBUG_VIS_MANAGEMENT
475  printf("G4VisCommandSceneNotifyHandlers::SetNewValue :%s\n",newValue.data());
476#endif
477
478  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
479
480  G4String sceneName, refresh_flush;
481  std::istringstream is (newValue);
482  is >> sceneName >> refresh_flush;
483  G4bool flush = false;
484  if (refresh_flush(0) == 'f') flush = true;
485
486  const G4SceneList& sceneList = fpVisManager -> GetSceneList ();
487  G4SceneHandlerList& sceneHandlerList =
488    fpVisManager -> SetAvailableSceneHandlers ();
489
490  // Check scene name.
491  const G4int nScenes = sceneList.size ();
492  G4int iScene;
493  for (iScene = 0; iScene < nScenes; iScene++) {
494    G4Scene* scene = sceneList [iScene];
495    if (sceneName == scene -> GetName ()) break;
496  }
497  if (iScene >= nScenes ) {
498    if (verbosity >= G4VisManager::warnings) {
499      G4cout << "WARNING: Scene \"" << sceneName << "\" not found."
500        "\n  /vis/scene/list to see scenes."
501             << G4endl;
502    }
503    return;
504  }
505
506  // Store current context...
507  G4VSceneHandler* pCurrentSceneHandler =
508    fpVisManager -> GetCurrentSceneHandler();
509  if (!pCurrentSceneHandler) {
510    if (verbosity >= G4VisManager::warnings) {
511      G4cout << "WARNING: No current scene handler."
512             << G4endl;
513    }
514    return;
515  }
516  G4VViewer* pCurrentViewer = fpVisManager -> GetCurrentViewer();
517  if (!pCurrentViewer) {
518    if (verbosity >= G4VisManager::warnings) {
519      G4cout << "WARNING: No current viewer."
520             << G4endl;
521    }
522    return;
523  }
524  G4Scene* pCurrentScene = fpVisManager -> GetCurrentScene();
525  if (!pCurrentScene) {
526    if (verbosity >= G4VisManager::warnings) {
527      G4cout << "WARNING: No current scene."
528             << G4endl;
529    }
530    return;
531  }
532  G4VisManager::Verbosity currentVerbosity = fpVisManager -> GetVerbosity();
533
534  // Suppress messages during this process (only print errors)...
535  //fpVisManager -> SetVerboseLevel(G4VisManager::errors);
536
537  // For each scene handler, if it contains the scene, clear and
538  // rebuild the graphical database, then for each viewer set (make
539  // current), clear, (re)draw, and show.
540  const G4int nSceneHandlers = sceneHandlerList.size ();
541  for (G4int iSH = 0; iSH < nSceneHandlers; iSH++) {
542    G4VSceneHandler* aSceneHandler = sceneHandlerList [iSH];
543    G4Scene* aScene = aSceneHandler -> GetScene ();
544    if (aScene) {
545      const G4String& aSceneName = aScene -> GetName ();
546      if (sceneName == aSceneName) {
547        // Clear store and force a rebuild of graphical database...
548        //aSceneHandler -> ClearStore (); // Not nec??  Done below
549        //with NeedKernelVisit and DrawView.  JA.
550        G4ViewerList& viewerList = aSceneHandler -> SetViewerList ();
551        const G4int nViewers = viewerList.size ();
552        for (G4int iV = 0; iV < nViewers; iV++) {
553          G4VViewer* aViewer = viewerList [iV];
554          if (aViewer->GetViewParameters().IsAutoRefresh()) {
555            aSceneHandler -> SetCurrentViewer (aViewer);
556            // Ensure consistency of vis manager...
557            fpVisManager -> SetCurrentViewer(aViewer);
558            fpVisManager -> SetCurrentSceneHandler(aSceneHandler);
559            fpVisManager -> SetCurrentScene(aScene);
560            // Re-draw, forcing rebuild of graphics database, if any...
561            aViewer -> NeedKernelVisit();
562#ifdef G4DEBUG_VIS_MANAGEMENT
563  printf("G4VisCommandSceneNotifyHandlers::SetNewValue Set/Clear/Draw\n");
564#endif
565            aViewer -> SetView ();
566            aViewer -> ClearView ();
567            aViewer -> DrawView ();
568#ifdef G4DEBUG_VIS_MANAGEMENT
569  printf("G4VisCommandSceneNotifyHandlers::SetNewValue ^^^^^\n");
570#endif
571            if (flush) aViewer -> ShowView ();
572            if (verbosity >= G4VisManager::confirmations) {
573              G4cout << "Viewer \"" << aViewer -> GetName ()
574                     << "\" of scene handler \"" << aSceneHandler -> GetName ()
575                     << "\"\n  ";
576              if (flush) G4cout << "flushed";
577              else G4cout << "refreshed";
578              G4cout << " at request of scene \"" << sceneName
579                     << "\"." << G4endl;
580            }
581          } else {
582            if (verbosity >= G4VisManager::warnings) {
583              G4cout << "WARNING: The scene, \""
584                     << sceneName
585                     << "\", of viewer \""
586                     << aViewer -> GetName ()
587                     << "\"\n  of scene handler \""
588                     << aSceneHandler -> GetName ()
589                     << "\"  has changed.  To see effect,"
590                     << "\n  \"/vis/viewer/select "
591                     << aViewer -> GetShortName ()
592                     << "\" and \"/vis/viewer/rebuild\"."
593                     << G4endl;
594            }
595          }
596        }
597      }
598    }
599    else {
600      if (verbosity >= G4VisManager::warnings) {
601        G4cout << "WARNING: G4VisCommandSceneNotifyHandlers: scene handler \""
602               << aSceneHandler->GetName()
603               << "\" has a null scene."
604               << G4endl;
605      }
606    }
607  }
608
609  // Reclaim original context - but set viewer first, then scene
610  // handler, because the latter might have been created very recently
611  // and, not yet having a viewer, the current viewer will,
612  // temporarily, refer to another scene handler.  SetCurrentViewer
613  // actually resets the scene handler, which is what we don't want,
614  // so we set it again on the next line...
615  fpVisManager -> SetCurrentViewer(pCurrentViewer);
616  fpVisManager -> SetCurrentSceneHandler(pCurrentSceneHandler);
617  fpVisManager -> SetCurrentScene(pCurrentScene);
618  fpVisManager -> SetVerboseLevel(currentVerbosity);
619  // Take care of special case of scene handler with no viewer yet. 
620  if (pCurrentSceneHandler) {
621    G4ViewerList& viewerList = pCurrentSceneHandler -> SetViewerList ();
622    const G4int nViewers = viewerList.size ();
623    if (nViewers) {
624      pCurrentSceneHandler -> SetCurrentViewer (pCurrentViewer);
625      if (pCurrentViewer && pCurrentSceneHandler->GetScene()) {
626        pCurrentViewer -> SetView ();
627      }
628    }
629  }
630}
631
632////////////// /vis/scene/select ///////////////////////////////////////
633
634G4VisCommandSceneSelect::G4VisCommandSceneSelect () {
635  G4bool omitable;
636  fpCommand = new G4UIcmdWithAString ("/vis/scene/select", this);
637  fpCommand -> SetGuidance ("Selects a scene");
638  fpCommand -> SetGuidance
639    ("Makes the scene current.  \"/vis/scene/list\" to see"
640     "\n possible scene names.");
641  fpCommand -> SetParameterName ("scene-name", omitable = false);
642}
643
644G4VisCommandSceneSelect::~G4VisCommandSceneSelect () {
645  delete fpCommand;
646}
647
648G4String G4VisCommandSceneSelect::GetCurrentValue (G4UIcommand*) {
649  return "";
650}
651
652void G4VisCommandSceneSelect::SetNewValue (G4UIcommand*, G4String newValue) {
653
654  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
655
656  G4String& selectName = newValue;
657  G4SceneList& sceneList = fpVisManager -> SetSceneList ();
658  G4int iScene, nScenes = sceneList.size ();
659  for (iScene = 0; iScene < nScenes; iScene++) {
660    if (sceneList [iScene] -> GetName () == selectName) break;
661  }
662  if (iScene >= nScenes) {
663    if (verbosity >= G4VisManager::warnings) {
664      G4cout << "WARNING: Scene \"" << selectName
665             << "\" not found - \"/vis/scene/list\" to see possibilities."
666             << G4endl;
667    }
668    return;
669  }
670
671  if (verbosity >= G4VisManager::confirmations) {
672    G4cout << "Scene \"" << selectName
673           << "\" selected." << G4endl;
674  }
675  UpdateVisManagerScene (selectName);
676}
Note: See TracBrowser for help on using the repository browser.