Geant4  10.02
G4VisCommandsViewer.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: G4VisCommandsViewer.cc 93303 2015-10-15 15:19:40Z gcosmo $
28 
29 // /vis/viewer commands - John Allison 25th October 1998
30 
31 #include "G4VisCommandsViewer.hh"
32 
33 #include "G4VisManager.hh"
34 #include "G4GraphicsSystemList.hh"
35 #include "G4VisCommandsScene.hh"
36 #include "G4UImanager.hh"
37 #include "G4UIcommand.hh"
39 #include "G4UIcmdWithAString.hh"
40 #include "G4UIcmdWithADouble.hh"
42 #include "G4UIcmdWith3Vector.hh"
43 #include "G4Point3D.hh"
44 #include "G4UnitsTable.hh"
45 #include "G4ios.hh"
46 #include <sstream>
47 #include <fstream>
48 
50 
52 
54 (G4VViewer* viewer, const G4ViewParameters& viewParams) {
55  viewer->SetViewParameters(viewParams);
56  RefreshIfRequired(viewer);
57 }
58 
61  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
62  const G4ViewParameters& viewParams = viewer->GetViewParameters();
63  if (sceneHandler && sceneHandler->GetScene()) {
64  if (viewParams.IsAutoRefresh()) {
65  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
66  }
67  else {
68  if (verbosity >= G4VisManager::warnings) {
69  G4cout << "Issue /vis/viewer/refresh or flush to see effect."
70  << G4endl;
71  }
72  }
73  }
74 }
75 
77 
79  G4bool omitable;
80  fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
81  fpCommand -> SetGuidance
82  ("Add cutaway plane to current viewer.");
83  G4UIparameter* parameter;
84  parameter = new G4UIparameter("x",'d',omitable = true);
85  parameter -> SetDefaultValue (0);
86  parameter -> SetGuidance ("Coordinate of point on the plane.");
87  fpCommand->SetParameter(parameter);
88  parameter = new G4UIparameter("y",'d',omitable = true);
89  parameter -> SetDefaultValue (0);
90  parameter -> SetGuidance ("Coordinate of point on the plane.");
91  fpCommand->SetParameter(parameter);
92  parameter = new G4UIparameter("z",'d',omitable = true);
93  parameter -> SetDefaultValue (0);
94  parameter -> SetGuidance ("Coordinate of point on the plane.");
95  fpCommand->SetParameter(parameter);
96  parameter = new G4UIparameter("unit",'s',omitable = true);
97  parameter -> SetDefaultValue ("m");
98  parameter -> SetGuidance ("Unit of point on the plane.");
99  fpCommand->SetParameter(parameter);
100  parameter = new G4UIparameter("nx",'d',omitable = true);
101  parameter -> SetDefaultValue (1);
102  parameter -> SetGuidance ("Component of plane normal.");
103  fpCommand->SetParameter(parameter);
104  parameter = new G4UIparameter("ny",'d',omitable = true);
105  parameter -> SetDefaultValue (0);
106  parameter -> SetGuidance ("Component of plane normal.");
107  fpCommand->SetParameter(parameter);
108  parameter = new G4UIparameter("nz",'d',omitable = true);
109  parameter -> SetDefaultValue (0);
110  parameter -> SetGuidance ("Component of plane normal.");
111  fpCommand->SetParameter(parameter);
112 }
113 
115  delete fpCommand;
116 }
117 
119  return "";
120 }
121 
123 
125 
126  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
127  if (!viewer) {
128  if (verbosity >= G4VisManager::errors) {
129  G4cerr <<
130  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
131  << G4endl;
132  }
133  return;
134  }
135 
136  G4double x, y, z, nx, ny, nz;
137  G4String unit;
138  std::istringstream is (newValue);
139  is >> x >> y >> z >> unit >> nx >> ny >> nz;
140  G4double F = G4UIcommand::ValueOf(unit);
141  x *= F; y *= F; z *= F;
142 
143  G4ViewParameters vp = viewer->GetViewParameters();
144  vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
145  if (verbosity >= G4VisManager::confirmations) {
146  G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
147  const G4Planes& cutaways = vp.GetCutawayPlanes();
148  for (size_t i = 0; i < cutaways.size(); ++i)
149  G4cout << "\n " << i << ": " << cutaways[i];
150  G4cout << G4endl;
151  }
152 
153  SetViewParameters(viewer, vp);
154 }
155 
157 
159  G4bool omitable;
160  fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
161  fpCommand -> SetGuidance("Change cutaway plane.");
162  G4UIparameter* parameter;
163  parameter = new G4UIparameter("index",'i',omitable = false);
164  parameter -> SetGuidance ("Index of plane: 0, 1, 2.");
165  fpCommand->SetParameter(parameter);
166  parameter = new G4UIparameter("x",'d',omitable = true);
167  parameter -> SetDefaultValue (0);
168  parameter -> SetGuidance ("Coordinate of point on the plane.");
169  fpCommand->SetParameter(parameter);
170  parameter = new G4UIparameter("y",'d',omitable = true);
171  parameter -> SetDefaultValue (0);
172  parameter -> SetGuidance ("Coordinate of point on the plane.");
173  fpCommand->SetParameter(parameter);
174  parameter = new G4UIparameter("z",'d',omitable = true);
175  parameter -> SetDefaultValue (0);
176  parameter -> SetGuidance ("Coordinate of point on the plane.");
177  fpCommand->SetParameter(parameter);
178  parameter = new G4UIparameter("unit",'s',omitable = true);
179  parameter -> SetDefaultValue ("m");
180  parameter -> SetGuidance ("Unit of point on the plane.");
181  fpCommand->SetParameter(parameter);
182  parameter = new G4UIparameter("nx",'d',omitable = true);
183  parameter -> SetDefaultValue (1);
184  parameter -> SetGuidance ("Component of plane normal.");
185  fpCommand->SetParameter(parameter);
186  parameter = new G4UIparameter("ny",'d',omitable = true);
187  parameter -> SetDefaultValue (0);
188  parameter -> SetGuidance ("Component of plane normal.");
189  fpCommand->SetParameter(parameter);
190  parameter = new G4UIparameter("nz",'d',omitable = true);
191  parameter -> SetDefaultValue (0);
192  parameter -> SetGuidance ("Component of plane normal.");
193  fpCommand->SetParameter(parameter);
194 }
195 
197  delete fpCommand;
198 }
199 
201  return "";
202 }
203 
205 
207 
208  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
209  if (!viewer) {
210  if (verbosity >= G4VisManager::errors) {
211  G4cerr <<
212  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
213  << G4endl;
214  }
215  return;
216  }
217 
218  size_t index;
219  G4double x, y, z, nx, ny, nz;
220  G4String unit;
221  std::istringstream is (newValue);
222  is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
223  G4double F = G4UIcommand::ValueOf(unit);
224  x *= F; y *= F; z *= F;
225 
226  G4ViewParameters vp = viewer->GetViewParameters();
227  vp.ChangeCutawayPlane(index,
228  G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
229  if (verbosity >= G4VisManager::confirmations) {
230  G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
231  const G4Planes& cutaways = vp.GetCutawayPlanes();
232  for (size_t i = 0; i < cutaways.size(); ++i)
233  G4cout << "\n " << i << ": " << cutaways[i];
234  G4cout << G4endl;
235  }
236 
237  SetViewParameters(viewer, vp);
238 }
239 
241 
243  G4bool omitable, currentAsDefault;
244  fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
245  fpCommand -> SetGuidance ("Clears viewer.");
246  fpCommand -> SetGuidance
247  ("By default, clears current viewer. Specified viewer becomes current."
248  "\n\"/vis/viewer/list\" to see possible viewer names.");
249  fpCommand -> SetParameterName ("viewer-name",
250  omitable = true,
251  currentAsDefault = true);
252 }
253 
255  delete fpCommand;
256 }
257 
259  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
260  return viewer ? viewer -> GetName () : G4String("none");
261 }
262 
264 
266 
267  G4String& clearName = newValue;
268  G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
269  if (!viewer) {
270  if (verbosity >= G4VisManager::errors) {
271  G4cerr << "ERROR: Viewer \"" << clearName
272  << "\" not found - \"/vis/viewer/list\" to see possibilities."
273  << G4endl;
274  }
275  return;
276  }
277 
278  viewer->ClearView();
279  viewer->FinishView();
280  if (verbosity >= G4VisManager::confirmations) {
281  G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
282  }
283 
284 }
285 
287 
290  ("/vis/viewer/clearCutawayPlanes", this);
291  fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
292 }
293 
295  delete fpCommand;
296 }
297 
299  return "";
300 }
301 
303 
305 
306  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
307  if (!viewer) {
308  if (verbosity >= G4VisManager::errors) {
309  G4cerr <<
310  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
311  << G4endl;
312  }
313  return;
314  }
315 
316  G4ViewParameters vp = viewer->GetViewParameters();
317  vp.ClearCutawayPlanes();
318  if (verbosity >= G4VisManager::confirmations) {
319  G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
320  << "\" now cleared." << G4endl;
321  }
322 
323  SetViewParameters(viewer, vp);
324 }
325 
327 
329  G4bool omitable, currentAsDefault;
330  fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
331  fpCommand -> SetGuidance ("Clears transients from viewer.");
332  fpCommand -> SetGuidance
333  ("By default, operates on current viewer. Specified viewer becomes current."
334  "\n\"/vis/viewer/list\" to see possible viewer names.");
335  fpCommand -> SetParameterName ("viewer-name",
336  omitable = true,
337  currentAsDefault = true);
338 }
339 
341  delete fpCommand;
342 }
343 
345  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
346  return viewer ? viewer -> GetName () : G4String("none");
347 }
348 
350 
352 
353  G4String& clearName = newValue;
354  G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
355  if (!viewer) {
356  if (verbosity >= G4VisManager::errors) {
357  G4cerr << "ERROR: Viewer \"" << clearName
358  << "\" not found - \"/vis/viewer/list\" to see possibilities."
359  << G4endl;
360  }
361  return;
362  }
363 
364  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
365  sceneHandler->SetMarkForClearingTransientStore(false);
367  sceneHandler->ClearTransientStore();
368  if (verbosity >= G4VisManager::confirmations) {
369  G4cout << "Viewer \"" << clearName << "\" cleared of transients."
370  << G4endl;
371  }
372 
373 }
374 
376 
378  G4bool omitable;
379  fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
380  fpCommand -> SetGuidance ("Clones viewer.");
381  fpCommand -> SetGuidance
382  ("By default, clones current viewer. Clone becomes current."
383  "\nClone name, if not provided, is derived from the original name."
384  "\n\"/vis/viewer/list\" to see possible viewer names.");
385  G4UIparameter* parameter;
386  parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
387  parameter -> SetCurrentAsDefault (true);
388  fpCommand -> SetParameter (parameter);
389  parameter = new G4UIparameter ("clone-name", 's', omitable = true);
390  parameter -> SetDefaultValue ("none");
391  fpCommand -> SetParameter (parameter);
392 }
393 
395  delete fpCommand;
396 }
397 
399  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
400  G4String originalName = viewer ? viewer -> GetName () : G4String("none");
401  return "\"" + originalName + "\"";
402 }
403 
405 
407 
408  G4String originalName, cloneName;
409  std::istringstream is (newValue);
410 
411  // Need to handle the possibility that the names contain embedded
412  // blanks within quotation marks...
413  char c;
414  while (is.get(c) && c == ' '){}
415  if (c == '"') {
416  while (is.get(c) && c != '"') {originalName += c;}
417  }
418  else {
419  originalName += c;
420  while (is.get(c) && c != ' ') {originalName += c;}
421  }
422  originalName = originalName.strip (G4String::both, ' ');
423  originalName = originalName.strip (G4String::both, '"');
424 
425  G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
426  if (!originalViewer) {
427  if (verbosity >= G4VisManager::errors) {
428  G4cerr << "ERROR: Viewer \"" << originalName
429  << "\" not found - \"/vis/viewer/list\" to see possibilities."
430  << G4endl;
431  }
432  return;
433  }
434  originalName = originalViewer->GetName(); // Ensures long name.
435 
436  while (is.get(c) && c == ' '){}
437  if (c == '"') {
438  while (is.get(c) && c != '"') {cloneName += c;}
439  }
440  else {
441  cloneName += c;
442  while (is.get(c) && c != ' ') {cloneName += c;}
443  }
444  cloneName = cloneName.strip (G4String::both, ' ');
445  cloneName = cloneName.strip (G4String::both, '"');
446 
447  G4bool errorWhileNaming = false;
448  if (cloneName == "none") {
449  G4int subID = 0;
450  do {
451  cloneName = originalName;
452  std::ostringstream oss;
453  oss << '-' << subID++;
454  G4String::size_type lastDashPosition, nextSpacePosition;
455  if ((lastDashPosition = cloneName.rfind('-')) != G4String::npos &&
456  (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
457  G4String::npos) {
458  cloneName.insert(nextSpacePosition, oss.str());
459  } else {
460  G4String::size_type spacePosition = cloneName.find(' ');
461  if (spacePosition != G4String::npos)
462  cloneName.insert(spacePosition, oss.str());
463  else
464  errorWhileNaming = true;
465  }
466  } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName));
467  }
468 
469  if (errorWhileNaming) {
470  if (verbosity >= G4VisManager::errors) {
471  G4cerr << "ERROR: While naming clone viewer \"" << cloneName
472  << "\"."
473  << G4endl;
474  }
475  return;
476  }
477 
478  if (fpVisManager -> GetViewer (cloneName)) {
479  if (verbosity >= G4VisManager::errors) {
480  G4cerr << "ERROR: Putative clone viewer \"" << cloneName
481  << "\" already exists."
482  << G4endl;
483  }
484  return;
485  }
486 
487  G4String windowSizeHint =
488  originalViewer->GetViewParameters().GetXGeometryString();
489 
490  G4UImanager* UImanager = G4UImanager::GetUIpointer();
491  G4int keepVerbose = UImanager->GetVerboseLevel();
492  G4int newVerbose(0);
493  if (keepVerbose >= 2 ||
495  newVerbose = 2;
496  UImanager->SetVerboseLevel(newVerbose);
497  UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
498  UImanager->ApplyCommand
499  (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
500  UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
501  UImanager->SetVerboseLevel(keepVerbose);
502 
503  if (verbosity >= G4VisManager::confirmations) {
504  G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
505  G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
506  }
507 }
508 
510 
512  G4bool omitable;
513  fpCommand = new G4UIcmdWithAString ("/vis/viewer/copyViewFrom", this);
514  fpCommand -> SetGuidance
515  ("Copy the camera-specific parameters from the specified viewer.");
516  fpCommand -> SetGuidance
517  ("Note: To copy scene modifications - style, etc. - please use"
518  "\n\"/vis/viewer/set/all\"");
519  fpCommand -> SetParameterName ("from-viewer-name", omitable = false);
520 }
521 
523  delete fpCommand;
524 }
525 
527  return "";
528 }
529 
531 
533 
534  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
535  if (!currentViewer) {
536  if (verbosity >= G4VisManager::errors) {
537  G4cerr <<
538  "ERROR: G4VisCommandsViewerCopyViewFrom::SetNewValue: no current viewer."
539  << G4endl;
540  }
541  return;
542  }
543 
544  const G4String& fromViewerName = newValue;
545  G4VViewer* fromViewer = fpVisManager -> GetViewer (fromViewerName);
546  if (!fromViewer) {
547  if (verbosity >= G4VisManager::errors) {
548  G4cerr << "ERROR: Viewer \"" << fromViewerName
549  << "\" not found - \"/vis/viewer/list\" to see possibilities."
550  << G4endl;
551  }
552  return;
553  }
554 
555  if (fromViewer == currentViewer) {
556  if (verbosity >= G4VisManager::warnings) {
557  G4cout <<
558  "WARNING: G4VisCommandsViewerSet::SetNewValue:"
559  "\n from-viewer and current viewer are identical."
560  << G4endl;
561  }
562  return;
563  }
564 
565  // Copy camera-specific view parameters
566  G4ViewParameters vp = currentViewer->GetViewParameters();
567  const G4ViewParameters& fromVP = fromViewer->GetViewParameters();
571  vp.SetUpVector (fromVP.GetUpVector());
572  vp.SetFieldHalfAngle (fromVP.GetFieldHalfAngle());
573  vp.SetZoomFactor (fromVP.GetZoomFactor());
574  vp.SetScaleFactor (fromVP.GetScaleFactor());
576  vp.SetDolly (fromVP.GetDolly());
577  SetViewParameters(currentViewer, vp);
578 
579  if (verbosity >= G4VisManager::confirmations) {
580  G4cout << "Camera parameters of viewer \"" << currentViewer->GetName()
581  << "\"\n set to those of viewer \"" << fromViewer->GetName()
582  << "\"."
583  << G4endl;
584  }
585 }
586 
588 
590  G4bool omitable;
591  fpCommand = new G4UIcommand ("/vis/viewer/create", this);
592  fpCommand -> SetGuidance
593  ("Creates a viewer for the specified scene handler.");
594  fpCommand -> SetGuidance
595  ("Default scene handler is the current scene handler. Invents a name"
596  "\nif not supplied. (Note: the system adds information to the name"
597  "\nfor identification - only the characters up to the first blank are"
598  "\nused for removing, selecting, etc.) This scene handler and viewer"
599  "\nbecome current.");
600  G4UIparameter* parameter;
601  parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
602  parameter -> SetCurrentAsDefault (true);
603  fpCommand -> SetParameter (parameter);
604  parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
605  parameter -> SetCurrentAsDefault (true);
606  fpCommand -> SetParameter (parameter);
607  parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
608  parameter->SetGuidance
609  ("integer (pixels) for square window placed by window manager or"
610  " X-Windows-type geometry string, e.g. 600x600-100+100");
611  parameter->SetDefaultValue("600");
612  fpCommand -> SetParameter (parameter);
613 }
614 
616  delete fpCommand;
617 }
618 
620  std::ostringstream oss;
621  G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
622  oss << "viewer-" << fId << " (";
623  if (sceneHandler) {
624  oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
625  }
626  else {
627  oss << "no_scene_handlers";
628  }
629  oss << ")";
630  return oss.str();
631 }
632 
634  G4String currentValue;
635  G4VSceneHandler* currentSceneHandler =
636  fpVisManager -> GetCurrentSceneHandler ();
637  if (currentSceneHandler) {
638  currentValue = currentSceneHandler -> GetName ();
639  }
640  else {
641  currentValue = "none";
642  }
643  currentValue += ' ';
644  currentValue += '"';
645  currentValue += NextName ();
646  currentValue += '"';
647 
648  currentValue += " 600"; // Default number of pixels for window size hint.
649 
650  return currentValue;
651 }
652 
654 
656 
657  G4String sceneHandlerName, newName;
658  G4String windowSizeHintString;
659  std::istringstream is (newValue);
660  is >> sceneHandlerName;
661 
662  // Now need to handle the possibility that the second string
663  // contains embedded blanks within quotation marks...
664  char c = ' ';
665  while (is.get(c) && c == ' '){}
666  if (c == '"') {
667  while (is.get(c) && c != '"') {newName += c;}
668  }
669  else {
670  newName += c;
671  while (is.get(c) && c != ' ') {newName += c;}
672  }
673  newName = newName.strip (G4String::both, ' ');
674  newName = newName.strip (G4String::both, '"');
675 
676  // Now get window size hint...
677  is >> windowSizeHintString;
678 
679  const G4SceneHandlerList& sceneHandlerList =
680  fpVisManager -> GetAvailableSceneHandlers ();
681  G4int nHandlers = sceneHandlerList.size ();
682  if (nHandlers <= 0) {
683  if (verbosity >= G4VisManager::errors) {
684  G4cerr <<
685  "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
686  "\n Create a scene handler with \"/vis/sceneHandler/create\""
687  << G4endl;
688  }
689  return;
690  }
691 
692  G4int iHandler;
693  for (iHandler = 0; iHandler < nHandlers; iHandler++) {
694  if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
695  }
696 
697  if (iHandler < 0 || iHandler >= nHandlers) {
698  // Invalid command line argument or none.
699  // This shouldn't happen!!!!!!
700  if (verbosity >= G4VisManager::errors) {
701  G4cout << "G4VisCommandViewerCreate::SetNewValue:"
702  " invalid scene handler specified."
703  << G4endl;
704  }
705  return;
706  }
707 
708  // Valid index. Set current scene handler and graphics system in
709  // preparation for creating viewer.
710  G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
711  if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
712  fpVisManager -> SetCurrentSceneHandler (sceneHandler);
713  }
714 
715  // Now deal with name of viewer.
716  G4String nextName = NextName ();
717  if (newName == "") {
718  newName = nextName;
719  }
720  if (newName == nextName) fId++;
721  G4String newShortName = fpVisManager -> ViewerShortName (newName);
722 
723  for (G4int ih = 0; ih < nHandlers; ih++) {
724  G4VSceneHandler* sh = sceneHandlerList [ih];
725  const G4ViewerList& viewerList = sh -> GetViewerList ();
726  for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
727  if (viewerList [iViewer] -> GetShortName () == newShortName ) {
728  if (verbosity >= G4VisManager::errors) {
729  G4cerr << "ERROR: Viewer \"" << newShortName << "\" already exists."
730  << G4endl;
731  }
732  return;
733  }
734  }
735  }
736 
737  // WindowSizeHint and XGeometryString are picked up from the vis
738  // manager in the G4VViewer constructor. In G4VisManager, after Viewer
739  // creation, we will store theses parameters in G4ViewParameters.
740 
741  fpVisManager -> CreateViewer (newName,windowSizeHintString);
742 
743  G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
744  if (newViewer && newViewer -> GetName () == newName) {
745  if (verbosity >= G4VisManager::confirmations) {
746  G4cout << "New viewer \"" << newName << "\" created." << G4endl;
747  }
748  }
749  else {
750  if (verbosity >= G4VisManager::errors) {
751  if (newViewer) {
752  G4cerr << "ERROR: New viewer doesn\'t match!!! Curious!!" << G4endl;
753  } else {
754  G4cout << "WARNING: No viewer created." << G4endl;
755  }
756  }
757  }
758  // Refresh if appropriate...
759  if (newViewer) {
760  if (newViewer->GetViewParameters().IsAutoRefresh()) {
761  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
762  }
763  else {
764  if (verbosity >= G4VisManager::warnings) {
765  G4cout << "Issue /vis/viewer/refresh or flush to see effect."
766  << G4endl;
767  }
768  }
769  }
770 }
771 
773 
775  fDollyIncrement (0.),
776  fDollyTo (0.)
777 {
778  G4bool omitable, currentAsDefault;
779 
781  ("/vis/viewer/dolly", this);
782  fpCommandDolly -> SetGuidance
783  ("Incremental dolly.");
784  fpCommandDolly -> SetGuidance
785  ("Moves the camera incrementally towards target point.");
786  fpCommandDolly -> SetParameterName("increment",
787  omitable=true,
788  currentAsDefault=true);
789  fpCommandDolly -> SetDefaultUnit("m");
790 
792  ("/vis/viewer/dollyTo", this);
793  fpCommandDollyTo -> SetGuidance
794  ("Dolly to specific coordinate.");
795  fpCommandDollyTo -> SetGuidance
796  ("Places the camera towards target point relative to standard camera point.");
797  fpCommandDollyTo -> SetParameterName("distance",
798  omitable=true,
799  currentAsDefault=true);
800  fpCommandDollyTo -> SetDefaultUnit("m");
801 }
802 
804  delete fpCommandDolly;
805  delete fpCommandDollyTo;
806 }
807 
809  G4String currentValue;
810  if (command == fpCommandDolly) {
811  currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
812  }
813  else if (command == fpCommandDollyTo) {
814  currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
815  }
816  return currentValue;
817 }
818 
820  G4String newValue) {
821 
822 
824 
825  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
826  if (!currentViewer) {
827  if (verbosity >= G4VisManager::errors) {
828  G4cerr <<
829  "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
830  << G4endl;
831  }
832  return;
833  }
834 
835  G4ViewParameters vp = currentViewer->GetViewParameters();
836 
837  if (command == fpCommandDolly) {
840  }
841  else if (command == fpCommandDollyTo) {
843  vp.SetDolly(fDollyTo);
844  }
845 
846  if (verbosity >= G4VisManager::confirmations) {
847  G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
848  }
849 
850  SetViewParameters(currentViewer, vp);
851 }
852 
854 
856  G4bool omitable, currentAsDefault;
857  fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
858  fpCommand -> SetGuidance
859  ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
860  fpCommand -> SetGuidance
861  ("Useful for refreshing and initiating post-processing for graphics"
862  "\nsystems which need post-processing. By default, acts on current"
863  "\nviewer. \"/vis/viewer/list\" to see possible viewers. Viewer"
864  "\nbecomes current.");
865  fpCommand -> SetParameterName ("viewer-name",
866  omitable = true,
867  currentAsDefault = true);
868 }
869 
871  delete fpCommand;
872 }
873 
876  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
877  return viewer ? viewer -> GetName () : G4String("none");
878 }
879 
881 
883 
884  G4String& flushName = newValue;
885  G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
886  if (!viewer) {
887  if (verbosity >= G4VisManager::errors) {
888  G4cerr << "ERROR: Viewer \"" << flushName << "\"" <<
889  " not found - \"/vis/viewer/list\"\n to see possibilities."
890  << G4endl;
891  }
892  return;
893  }
894 
896  G4int keepVerbose = ui->GetVerboseLevel();
897  G4int newVerbose(0);
898  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
899  newVerbose = 2;
900  ui->SetVerboseLevel(newVerbose);
901  ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
902  ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
903  ui->SetVerboseLevel(keepVerbose);
904  if (verbosity >= G4VisManager::confirmations) {
905  G4cout << "Viewer \"" << viewer -> GetName () << "\""
906  << " flushed." << G4endl;
907  }
908 }
909 
911 
913  G4bool omitable;
914  fpCommand = new G4UIcommand ("/vis/viewer/list", this);
915  fpCommand -> SetGuidance ("Lists viewers(s).");
916  fpCommand -> SetGuidance
917  ("See \"/vis/verbose\" for definition of verbosity.");
918  G4UIparameter* parameter;
919  parameter = new G4UIparameter("viewer-name", 's',
920  omitable = true);
921  parameter -> SetDefaultValue ("all");
922  fpCommand -> SetParameter (parameter);
923  parameter = new G4UIparameter ("verbosity", 's',
924  omitable = true);
925  parameter -> SetDefaultValue ("warnings");
926  fpCommand -> SetParameter (parameter);
927 }
928 
930  delete fpCommand;
931 }
932 
934  return "";
935 }
936 
938  G4String name, verbosityString;
939  std::istringstream is (newValue);
940  is >> name >> verbosityString;
941  G4String shortName = fpVisManager -> ViewerShortName (name);
942  G4VisManager::Verbosity verbosity =
943  fpVisManager->GetVerbosityValue(verbosityString);
944 
945  const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
946  G4String currentViewerShortName;
947  if (currentViewer) {
948  currentViewerShortName = currentViewer -> GetShortName ();
949  }
950  else {
951  currentViewerShortName = "none";
952  }
953 
954  const G4SceneHandlerList& sceneHandlerList =
955  fpVisManager -> GetAvailableSceneHandlers ();
956  G4int nHandlers = sceneHandlerList.size ();
957  G4bool found = false;
958  G4bool foundCurrent = false;
959  for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
960  G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
961  const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
962  G4cout << "Scene handler \"" << sceneHandler -> GetName ();
963  const G4Scene* pScene = sceneHandler -> GetScene ();
964  if (pScene) {
965  G4cout << "\", scene \"" << pScene -> GetName () << "\":";
966  }
967  G4int nViewers = viewerList.size ();
968  if (nViewers == 0) {
969  G4cout << "\n No viewers for this scene handler." << G4endl;
970  }
971  else {
972  for (int iViewer = 0; iViewer < nViewers; iViewer++) {
973  const G4VViewer* thisViewer = viewerList [iViewer];
974  G4String thisName = thisViewer -> GetName ();
975  G4String thisShortName = thisViewer -> GetShortName ();
976  if (name != "all") {
977  if (thisShortName != shortName) continue;
978  }
979  found = true;
980  G4cout << "\n ";
981  if (thisShortName == currentViewerShortName) {
982  foundCurrent = true;
983  G4cout << "(current)";
984  }
985  else {
986  G4cout << " ";
987  }
988  G4cout << " viewer \"" << thisName << "\"";
989  if (verbosity >= G4VisManager::parameters) {
990  G4cout << "\n " << *thisViewer;
991  }
992  }
993  }
994  G4cout << G4endl;
995  }
996 
997  if (!foundCurrent) {
998  G4cout << "No valid current viewer - please create or select one."
999  << G4endl;
1000  }
1001 
1002  if (!found) {
1003  G4cout << "No viewers";
1004  if (name != "all") {
1005  G4cout << " of name \"" << name << "\"";
1006  }
1007  G4cout << " found." << G4endl;
1008  }
1009 }
1010 
1012 
1014  fPanIncrementRight (0.),
1015  fPanIncrementUp (0.),
1016  fPanToRight (0.),
1017  fPanToUp (0.)
1018 {
1019  G4bool omitable;
1020 
1022  ("/vis/viewer/pan", this);
1023  fpCommandPan -> SetGuidance
1024  ("Incremental pan.");
1025  fpCommandPan -> SetGuidance
1026  ("Moves the camera incrementally right and up by these amounts (as seen"
1027  "\nfrom viewpoint direction).");
1028  G4UIparameter* parameter;
1029  parameter = new G4UIparameter("right-increment", 'd', omitable = true);
1030  parameter -> SetCurrentAsDefault (true);
1031  fpCommandPan -> SetParameter (parameter);
1032  parameter = new G4UIparameter("up-increment", 'd', omitable = true);
1033  parameter -> SetCurrentAsDefault (true);
1034  fpCommandPan -> SetParameter (parameter);
1035  parameter = new G4UIparameter ("unit", 's', omitable = true);
1036  parameter -> SetDefaultValue ("m");
1037  fpCommandPan -> SetParameter (parameter);
1038 
1040  ("/vis/viewer/panTo", this);
1041  fpCommandPanTo -> SetGuidance
1042  ("Pan to specific coordinate.");
1043  fpCommandPanTo -> SetGuidance
1044  ("Places the camera in this position right and up relative to standard"
1045  "\ntarget point (as seen from viewpoint direction).");
1046  parameter = new G4UIparameter("right", 'd', omitable = true);
1047  parameter -> SetCurrentAsDefault (true);
1048  fpCommandPanTo -> SetParameter (parameter);
1049  parameter = new G4UIparameter("up", 'd', omitable = true);
1050  parameter -> SetCurrentAsDefault (true);
1051  fpCommandPanTo -> SetParameter (parameter);
1052  parameter = new G4UIparameter ("unit", 's', omitable = true);
1053  parameter -> SetDefaultValue ("m");
1054  fpCommandPanTo -> SetParameter (parameter);
1055 }
1056 
1058  delete fpCommandPan;
1059  delete fpCommandPanTo;
1060 }
1061 
1063  G4String currentValue;
1064  if (command == fpCommandPan) {
1065  currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
1066  }
1067  else if (command == fpCommandPanTo) {
1068  currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
1069  }
1070  return currentValue;
1071 }
1072 
1074  G4String newValue) {
1075 
1076 
1078 
1079  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1080  if (!currentViewer) {
1081  if (verbosity >= G4VisManager::errors) {
1082  G4cerr <<
1083  "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
1084  << G4endl;
1085  }
1086  return;
1087  }
1088 
1089  G4ViewParameters vp = currentViewer->GetViewParameters();
1090 
1091  if (command == fpCommandPan) {
1094  }
1095  else if (command == fpCommandPanTo) {
1098  }
1099 
1100  if (verbosity >= G4VisManager::confirmations) {
1101  G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
1102  << G4endl;
1103  }
1104 
1105  SetViewParameters(currentViewer, vp);
1106 }
1107 
1109 
1111  G4bool omitable, currentAsDefault;
1112  fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
1113  fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
1114  fpCommand -> SetGuidance
1115  ("By default, acts on current viewer. \"/vis/viewer/list\""
1116  "\nto see possible viewers. Viewer becomes current.");
1117  fpCommand -> SetParameterName ("viewer-name",
1118  omitable = true,
1119  currentAsDefault = true);
1120 }
1121 
1123  delete fpCommand;
1124 }
1125 
1127  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1128  if (viewer) {
1129  return viewer -> GetName ();
1130  }
1131  else {
1132  return "none";
1133  }
1134 }
1135 
1137 
1139 
1140  G4String& rebuildName = newValue;
1141 
1142  G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
1143  if (!viewer) {
1144  if (verbosity >= G4VisManager::errors) {
1145  G4cerr << "ERROR: Viewer \"" << rebuildName
1146  << "\" not found - \"/vis/viewer/list\" to see possibilities."
1147  << G4endl;
1148  }
1149  return;
1150  }
1151 
1152  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1153  if (!sceneHandler) {
1154  if (verbosity >= G4VisManager::errors) {
1155  G4cerr << "ERROR: Viewer \"" << viewer->GetName() << "\"" <<
1156  " has no scene handler - report serious bug."
1157  << G4endl;
1158  }
1159  return;
1160  }
1161 
1162  sceneHandler->ClearTransientStore();
1163  viewer->NeedKernelVisit();
1164  viewer->SetView();
1165  viewer->ClearView();
1166  viewer->DrawView();
1167 
1168  // Check auto-refresh and print confirmations.
1169  RefreshIfRequired(viewer);
1170 }
1171 
1173 
1175  G4bool omitable, currentAsDefault;
1176  fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
1177  fpCommand -> SetGuidance
1178  ("Refreshes viewer.");
1179  fpCommand -> SetGuidance
1180  ("By default, acts on current viewer. \"/vis/viewer/list\""
1181  "\nto see possible viewers. Viewer becomes current.");
1182  fpCommand -> SetParameterName ("viewer-name",
1183  omitable = true,
1184  currentAsDefault = true);
1185 }
1186 
1188  delete fpCommand;
1189 }
1190 
1192  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1193  return viewer ? viewer -> GetName () : G4String("none");
1194 }
1195 
1197 
1199  G4bool warn(verbosity >= G4VisManager::warnings);
1200 
1201  G4String& refreshName = newValue;
1202  G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
1203  if (!viewer) {
1204  if (verbosity >= G4VisManager::errors) {
1205  G4cerr << "ERROR: Viewer \"" << refreshName << "\"" <<
1206  " not found - \"/vis/viewer/list\"\n to see possibilities."
1207  << G4endl;
1208  }
1209  return;
1210  }
1211 
1212  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1213  if (!sceneHandler) {
1214  if (verbosity >= G4VisManager::errors) {
1215  G4cerr << "ERROR: Viewer \"" << refreshName << "\"" <<
1216  " has no scene handler - report serious bug."
1217  << G4endl;
1218  }
1219  return;
1220  }
1221 
1222  G4Scene* scene = sceneHandler->GetScene();
1223  if (!scene) {
1224  if (verbosity >= G4VisManager::confirmations) {
1225  G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1226  << "\", to which viewer \"" << refreshName << "\"" <<
1227  "\n is attached, has no scene - \"/vis/scene/create\" and"
1228  " \"/vis/sceneHandler/attach\""
1229  "\n (or use compound command \"/vis/drawVolume\")."
1230  << G4endl;
1231  }
1232  return;
1233  }
1234  if (scene->GetRunDurationModelList().empty()) {
1235  G4bool successful = scene -> AddWorldIfEmpty (warn);
1236  if (!successful) {
1237  if (verbosity >= G4VisManager::warnings) {
1238  G4cout <<
1239  "WARNING: Scene is empty. Perhaps no geometry exists."
1240  "\n Try /run/initialize."
1241  << G4endl;
1242  }
1243  return;
1244  }
1245  // Scene has changed. UpdateVisManagerScene issues
1246  // /vis/scene/notifyHandlers, which does a refresh anyway, so the
1247  // ordinary refresh becomes part of the else phrase...
1248  UpdateVisManagerScene(scene->GetName());
1249  } else {
1250  if (verbosity >= G4VisManager::confirmations) {
1251  G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
1252  << G4endl;
1253  }
1254  viewer -> SetView ();
1255  viewer -> ClearView ();
1256  viewer -> DrawView ();
1257  if (verbosity >= G4VisManager::confirmations) {
1258  G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
1259  "\n (You might also need \"/vis/viewer/update\".)" << G4endl;
1260  }
1261  }
1262 }
1263 
1265 
1267  G4bool omitable, currentAsDefault;
1268  fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
1269  fpCommand -> SetGuidance ("Resets viewer.");
1270  fpCommand -> SetGuidance
1271  ("By default, acts on current viewer. \"/vis/viewer/list\""
1272  "\nto see possible viewers. Viewer becomes current.");
1273  fpCommand -> SetParameterName ("viewer-name",
1274  omitable = true,
1275  currentAsDefault = true);
1276 }
1277 
1279  delete fpCommand;
1280 }
1281 
1283  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1284  if (viewer) {
1285  return viewer -> GetName ();
1286  }
1287  else {
1288  return "none";
1289  }
1290 }
1291 
1293 
1295 
1296  G4String& resetName = newValue;
1297  G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
1298  if (!viewer) {
1299  if (verbosity >= G4VisManager::errors) {
1300  G4cerr << "ERROR: Viewer \"" << resetName
1301  << "\" not found - \"/vis/viewer/list\" to see possibilities."
1302  << G4endl;
1303  }
1304  return;
1305  }
1306 
1307  viewer->ResetView();
1308  RefreshIfRequired(viewer);
1309 }
1310 
1312 
1314  G4bool omitable;
1315  fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this);
1316  fpCommand -> SetGuidance
1317  ("Write commands that define the current view to file.");
1318  fpCommand -> SetGuidance
1319  ("Read them back into the same or any viewer with \"/control/execute <filename>\".");
1320  fpCommand -> SetParameterName ("file-name", omitable = true);
1321  fpCommand -> SetDefaultValue ("G4cout");
1322 }
1323 
1325  delete fpCommand;
1326 }
1327 
1330  return "";
1331 }
1332 
1333 namespace {
1334  void WriteCommands
1335  (std::ostream& os,
1336  const G4ViewParameters& vp,
1337  const G4Point3D& stp)
1338  {
1339  os
1340  << vp.CameraAndLightingCommands(stp)
1341  << vp.DrawingStyleCommands()
1342  << vp.SceneModifyingCommands()
1343  << vp.TouchableCommands()
1344  << std::endl;
1345  }
1346 }
1347 
1349 
1351 
1352  const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1353  if (!currentViewer) {
1354  if (verbosity >= G4VisManager::errors) {
1355  G4cerr <<
1356  "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer."
1357  << G4endl;
1358  }
1359  return;
1360  }
1361 
1362  const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
1363  if (!currentScene) {
1364  if (verbosity >= G4VisManager::errors) {
1365  G4cerr <<
1366  "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene."
1367  << G4endl;
1368  }
1369  return;
1370  }
1371 
1372  std::ofstream ofs;
1373  if (newValue != "G4cout") {
1374  // Check if file exists
1375  std::ifstream ifs(newValue);
1376  if (ifs) {
1377  if (verbosity >= G4VisManager::errors) {
1378  G4cerr <<
1379  "ERROR: G4VisCommandsViewerSave::SetNewValue: File \""
1380  << newValue << "\" already exists."
1381  << G4endl;
1382  }
1383  ifs.close();
1384  return;
1385  }
1386  ofs.open(newValue);
1387  if (!ofs) {
1388  if (verbosity >= G4VisManager::errors) {
1389  G4cerr <<
1390  "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
1391  << newValue << "\"."
1392  << G4endl;
1393  }
1394  ofs.close();
1395  return;
1396  }
1397  }
1398 
1399  G4ViewParameters vp = currentViewer->GetViewParameters();
1400  // Concatenate any private vis attributes modifiers...
1401  const std::vector<G4ModelingParameters::VisAttributesModifier>*
1402  privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
1403  if (privateVAMs) {
1404  std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i;
1405  for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) {
1406  vp.AddVisAttributesModifier(*i);
1407  }
1408  }
1409  const G4Point3D& stp = currentScene->GetStandardTargetPoint();
1410 
1411  if (newValue == "G4cout") {
1412  WriteCommands(G4cout,vp,stp);
1413  } else {
1414  WriteCommands(ofs,vp,stp);
1415  ofs.close();
1416  }
1417 
1418  if (verbosity >= G4VisManager::confirmations) {
1419  G4cout << "Viewer \"" << currentViewer -> GetName ()
1420  << "\"" << " saved to ";
1421  if (newValue == "G4cout") {
1422  G4cout << "G4cout.";
1423  } else {
1424  G4cout << "file \'" << newValue << "\"." <<
1425  "\n Read view parameters back into this or any viewer with"
1426  "\n \"/control/execute " << newValue << "\"";
1427  }
1428  G4cout << G4endl;
1429  }
1430 }
1431 
1433 
1435  fScaleMultiplier (G4Vector3D (1., 1., 1.)),
1436  fScaleTo (G4Vector3D (1., 1., 1.))
1437 {
1438  G4bool omitable, currentAsDefault;
1439 
1441  ("/vis/viewer/scale", this);
1442  fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
1443  fpCommandScale -> SetGuidance
1444  ("Multiplies components of current scaling by components of this factor."
1445  "\n Scales (x,y,z) by corresponding components of the resulting factor.");
1446  fpCommandScale -> SetGuidance
1447  ("");
1448  fpCommandScale -> SetParameterName
1449  ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
1450  omitable=true, currentAsDefault=true);
1451 
1453  ("/vis/viewer/scaleTo", this);
1454  fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
1455  fpCommandScaleTo -> SetGuidance
1456  ("Scales (x,y,z) by corresponding components of this factor.");
1457  fpCommandScaleTo -> SetParameterName
1458  ("x-scale-factor","y-scale-factor","z-scale-factor",
1459  omitable=true, currentAsDefault=true);
1460 }
1461 
1463  delete fpCommandScale;
1464  delete fpCommandScaleTo;
1465 }
1466 
1468  G4String currentValue;
1469  if (command == fpCommandScale) {
1471  }
1472  else if (command == fpCommandScaleTo) {
1474  }
1475  return currentValue;
1476 }
1477 
1479  G4String newValue) {
1480 
1481 
1483 
1484  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1485  if (!currentViewer) {
1486  if (verbosity >= G4VisManager::errors) {
1487  G4cerr <<
1488  "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
1489  << G4endl;
1490  }
1491  return;
1492  }
1493 
1494  G4ViewParameters vp = currentViewer->GetViewParameters();
1495 
1496  if (command == fpCommandScale) {
1499  }
1500  else if (command == fpCommandScaleTo) {
1503  }
1504 
1505  if (verbosity >= G4VisManager::confirmations) {
1506  G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
1507  }
1508 
1509  SetViewParameters(currentViewer, vp);
1510 }
1511 
1513 
1515  G4bool omitable;
1516  fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
1517  fpCommand -> SetGuidance ("Selects viewer.");
1518  fpCommand -> SetGuidance
1519  ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers.");
1520  fpCommand -> SetParameterName ("viewer-name", omitable = false);
1521 }
1522 
1524  delete fpCommand;
1525 }
1526 
1528  return "";
1529 }
1530 
1532 
1534 
1535  G4String& selectName = newValue;
1536  G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
1537 
1538  if (!viewer) {
1539  if (verbosity >= G4VisManager::errors) {
1540  G4cerr << "ERROR: Viewer \"" << selectName << "\"";
1541  G4cerr << " not found - \"/vis/viewer/list\""
1542  "\n to see possibilities."
1543  << G4endl;
1544  }
1545  return;
1546  }
1547 
1548  if (viewer == fpVisManager -> GetCurrentViewer ()) {
1549  if (verbosity >= G4VisManager::warnings) {
1550  G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
1551  << " already selected." << G4endl;
1552  }
1553  return;
1554  }
1555 
1556  fpVisManager -> SetCurrentViewer (viewer); // Prints confirmation.
1557 
1558  RefreshIfRequired(viewer);
1559 }
1560 
1562 
1564  G4bool omitable, currentAsDefault;
1565  fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
1566  fpCommand -> SetGuidance
1567  ("Triggers graphical database post-processing for viewers"
1568  "\nusing that technique.");
1569  fpCommand -> SetGuidance
1570  ("For such viewers the view only becomes visible with this command."
1571  "\nBy default, acts on current viewer. \"/vis/viewer/list\""
1572  "\nto see possible viewers. Viewer becomes current.");
1573  fpCommand -> SetParameterName ("viewer-name",
1574  omitable = true,
1575  currentAsDefault = true);
1576 }
1577 
1579  delete fpCommand;
1580 }
1581 
1583  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1584  if (viewer) {
1585  return viewer -> GetName ();
1586  }
1587  else {
1588  return "none";
1589  }
1590 }
1591 
1593 
1595 
1596  G4String& updateName = newValue;
1597 
1598  G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
1599  if (!viewer) {
1600  if (verbosity >= G4VisManager::errors) {
1601  G4cout <<
1602  "WARNING: command \"/vis/viewer/update\" could not be applied: no current viewer."
1603  << G4endl;
1604  }
1605  return;
1606  }
1607 
1608  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1609  if (!sceneHandler) {
1610  if (verbosity >= G4VisManager::errors) {
1611  G4cerr << "ERROR: Viewer \"" << updateName << "\"" <<
1612  " has no scene handler - report serious bug."
1613  << G4endl;
1614  }
1615  return;
1616  }
1617 
1618  G4Scene* scene = sceneHandler->GetScene();
1619  if (!scene) {
1620  if (verbosity >= G4VisManager::confirmations) {
1621  G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1622  << "\", to which viewer \"" << updateName << "\"" <<
1623  "\n is attached, has no scene - \"/vis/scene/create\" and"
1624  " \"/vis/sceneHandler/attach\""
1625  "\n (or use compound command \"/vis/drawVolume\")."
1626  << G4endl;
1627  }
1628  return;
1629  }
1630 
1631  if (verbosity >= G4VisManager::confirmations) {
1632  G4cout << "Viewer \"" << viewer -> GetName () << "\"";
1633  G4cout << " post-processing triggered." << G4endl;
1634  }
1635  viewer -> ShowView ();
1636  // Assume future need to "refresh" transients...
1637  sceneHandler -> SetMarkForClearingTransientStore(true);
1638 }
1639 
1641 
1643  fZoomMultiplier (1.),
1644  fZoomTo (1.)
1645 {
1646  G4bool omitable, currentAsDefault;
1647 
1649  ("/vis/viewer/zoom", this);
1650  fpCommandZoom -> SetGuidance ("Incremental zoom.");
1651  fpCommandZoom -> SetGuidance
1652  ("Multiplies current magnification by this factor.");
1653  fpCommandZoom -> SetParameterName("multiplier",
1654  omitable=true,
1655  currentAsDefault=true);
1656 
1658  ("/vis/viewer/zoomTo", this);
1659  fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
1660  fpCommandZoomTo -> SetGuidance
1661  ("Magnifies standard magnification by this factor.");
1662  fpCommandZoomTo -> SetParameterName("factor",
1663  omitable=true,
1664  currentAsDefault=true);
1665 }
1666 
1668  delete fpCommandZoom;
1669  delete fpCommandZoomTo;
1670 }
1671 
1673  G4String currentValue;
1674  if (command == fpCommandZoom) {
1676  }
1677  else if (command == fpCommandZoomTo) {
1678  currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
1679  }
1680  return currentValue;
1681 }
1682 
1684  G4String newValue) {
1685 
1686 
1688 
1689  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1690  if (!currentViewer) {
1691  if (verbosity >= G4VisManager::errors) {
1692  G4cerr <<
1693  "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
1694  << G4endl;
1695  }
1696  return;
1697  }
1698 
1699  G4ViewParameters vp = currentViewer->GetViewParameters();
1700 
1701  if (command == fpCommandZoom) {
1704  }
1705  else if (command == fpCommandZoomTo) {
1707  vp.SetZoomFactor(fZoomTo);
1708  }
1709 
1710  if (verbosity >= G4VisManager::confirmations) {
1711  G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
1712  }
1713 
1714  SetViewParameters(currentViewer, vp);
1715 }
const G4String & GetName() const
G4String GetCurrentValue(G4UIcommand *command)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4String TouchableCommands() const
G4UIcmdWithADouble * fpCommandZoom
G4String GetCurrentValue(G4UIcommand *command)
G4double GetZoomFactor() const
void IncrementPan(G4double right, G4double up)
void ClearCutawayPlanes()
G4String GetCurrentValue(G4UIcommand *command)
virtual void SetView()=0
void AddCutawayPlane(const G4Plane3D &cutawayPlane)
G4double GetDolly() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetLightpointDirection(const G4Vector3D &lightpointDirection)
void SetPan(G4double right, G4double up)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetScaleFactor(const G4Vector3D &scaleFactor)
CLHEP::Hep3Vector G4ThreeVector
virtual void ClearView()=0
G4double z
Definition: TRTMaterials.hh:39
G4String strip(G4int strip_Type=trailing, char c=' ')
void UpdateVisManagerScene(const G4String &sceneName="")
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String name
Definition: TRTMaterials.hh:40
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
void SetUpVector(const G4Vector3D &upVector)
const G4ViewParameters & GetViewParameters() const
void SetDefaultValue(const char *theDefaultValue)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:371
const G4String & GetName() const
G4String SceneModifyingCommands() const
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:130
void SetViewParameters(G4VViewer *, const G4ViewParameters &)
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
const G4Planes & GetCutawayPlanes() const
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWith3Vector * fpCommandScaleTo
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
static G4double GetNewDoubleValue(const char *paramString)
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
const G4String & GetName() const
int G4int
Definition: G4Types.hh:78
static Verbosity GetVerbosityValue(const G4String &)
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:225
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetLightsMoveWithCamera(G4bool moves)
G4String GetCurrentValue(G4UIcommand *command)
const G4Point3D & GetCurrentTargetPoint() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4UIcmdWithAString * fpCommand
G4UIcmdWithADoubleAndUnit * fpCommandDolly
const G4Vector3D & GetLightpointDirection() const
const G4String & GetXGeometryString() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
const G4Vector3D & GetViewpointDirection() const
G4GLOB_DLL std::ostream G4cout
void SetZoomFactor(G4double zoomFactor)
static G4ThreeVector GetNew3VectorValue(const char *paramString)
void ChangeCutawayPlane(size_t index, const G4Plane3D &cutawayPlane)
G4String GetCurrentValue(G4UIcommand *command)
virtual void ResetView()
const G4Point3D & GetStandardTargetPoint() const
G4UIcmdWithAString * fpCommand
bool G4bool
Definition: G4Types.hh:79
void SetNewValue(G4UIcommand *command, G4String newValue)
std::vector< G4Plane3D > G4Planes
static G4double GetNewDoubleValue(const char *paramString)
G4UIcmdWithAString * fpCommand
const std::vector< Model > & GetRunDurationModelList() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void ResetTransientsDrawnFlags()
void SetCurrentTargetPoint(const G4Point3D &currentTargetPoint)
void SetDolly(G4double dolly)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithAString * fpCommand
void SetFieldHalfAngle(G4double fieldHalfAngle)
G4UIcmdWithADouble * fpCommandZoomTo
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4String DrawingStyleCommands() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithAString * fpCommand
void RefreshIfRequired(G4VViewer *)
G4Scene * GetScene() const
void MultiplyZoomFactor(G4double zoomFactorMultiplier)
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
G4VSceneHandler * GetSceneHandler() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
const G4Vector3D & GetScaleFactor() const
virtual const std::vector< G4ModelingParameters::VisAttributesModifier > * GetPrivateVisAttributesModifiers() const
static G4String ConvertToString(G4double x, G4double y, const char *unitName)
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:308
G4UIcmdWith3Vector * fpCommandScale
const G4double x[NPOINTSGL]
static Verbosity GetVerbosity()
void NeedKernelVisit()
Definition: G4VViewer.cc:86
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithAString * fpCommand
G4String GetCurrentValue(G4UIcommand *command)
HepGeom::Plane3D< G4double > G4Plane3D
Definition: G4Plane3D.hh:37
G4String CameraAndLightingCommands(const G4Point3D standardTargetPoint) const
G4bool GetLightsMoveWithCamera() const
#define G4endl
Definition: G4ios.hh:61
G4VViewer * GetCurrentViewer() const
G4double GetFieldHalfAngle() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void MultiplyScaleFactor(const G4Vector3D &scaleFactorMultiplier)
double G4double
Definition: G4Types.hh:76
virtual void ClearTransientStore()
void SetGuidance(const char *theGuidance)
G4UIcmdWithADoubleAndUnit * fpCommandDollyTo
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
const G4Vector3D & GetUpVector() const
static void ConvertToDoublePair(const G4String &paramString, G4double &xval, G4double &yval)
G4UIcmdWithAString * fpCommand
void SetMarkForClearingTransientStore(G4bool)
G4bool IsAutoRefresh() const
void IncrementDolly(G4double dollyIncrement)
void SetViewpointDirection(const G4Vector3D &viewpointDirection)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
G4String GetCurrentValue(G4UIcommand *command)
virtual void FinishView()
Definition: G4VViewer.cc:111
G4GLOB_DLL std::ostream G4cerr
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
HepGeom::Normal3D< G4double > G4Normal3D
Definition: G4Normal3D.hh:35
virtual void DrawView()=0
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithAString * fpCommand
static G4VisManager * fpVisManager
void SetNewValue(G4UIcommand *command, G4String newValue)