Geant4  10.00.p02
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 77246 2013-11-22 10:01:21Z 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  G4cout <<
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  G4cout <<
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  G4cout << "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  G4cout <<
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  G4cout << "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  G4cout << "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  G4cout << "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  G4cout << "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  G4cout <<
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  G4cout << "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  G4cout <<
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  G4cout << "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  G4cout << "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  G4cout <<
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  G4cout << "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  G4cout <<
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  G4cout << "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  G4cout << "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  G4cout << "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  G4cout << "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  G4cout << "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 -> SetParameterName ("file-name", omitable = true);
1319  fpCommand -> SetDefaultValue ("G4cout");
1320 }
1321 
1323  delete fpCommand;
1324 }
1325 
1328  return "";
1329 }
1330 
1331 namespace {
1332  void WriteCommands
1333  (std::ostream& os,
1334  const G4ViewParameters& vp,
1335  const G4Point3D& stp)
1336  {
1337  os
1338  << vp.CameraAndLightingCommands(stp)
1339  << vp.DrawingStyleCommands()
1340  << vp.SceneModifyingCommands()
1341  << vp.TouchableCommands()
1342  << std::endl;
1343  }
1344 }
1345 
1347 
1349 
1350  const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1351  if (!currentViewer) {
1352  if (verbosity >= G4VisManager::errors) {
1353  G4cout <<
1354  "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer."
1355  << G4endl;
1356  }
1357  return;
1358  }
1359 
1360  const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
1361  if (!currentScene) {
1362  if (verbosity >= G4VisManager::errors) {
1363  G4cout <<
1364  "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene."
1365  << G4endl;
1366  }
1367  return;
1368  }
1369 
1370  std::ofstream ofs;
1371  if (newValue != "G4cout") {
1372  // Check if file exists
1373  std::ifstream ifs(newValue);
1374  if (ifs) {
1375  if (verbosity >= G4VisManager::errors) {
1376  G4cout <<
1377  "ERROR: G4VisCommandsViewerSave::SetNewValue: File \""
1378  << newValue << "\" already exists."
1379  << G4endl;
1380  }
1381  ifs.close();
1382  return;
1383  }
1384  ofs.open(newValue);
1385  if (!ofs) {
1386  if (verbosity >= G4VisManager::errors) {
1387  G4cout <<
1388  "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
1389  << newValue << "\"."
1390  << G4endl;
1391  }
1392  ofs.close();
1393  return;
1394  }
1395  }
1396 
1397  G4ViewParameters vp = currentViewer->GetViewParameters();
1398  // Concatenate any private vis attributes modifiers...
1399  const std::vector<G4ModelingParameters::VisAttributesModifier>*
1400  privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
1401  if (privateVAMs) {
1402  std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i;
1403  for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) {
1404  vp.AddVisAttributesModifier(*i);
1405  }
1406  }
1407  const G4Point3D& stp = currentScene->GetStandardTargetPoint();
1408 
1409  if (newValue == "G4cout") {
1410  WriteCommands(G4cout,vp,stp);
1411  } else {
1412  WriteCommands(ofs,vp,stp);
1413  ofs.close();
1414  }
1415 
1416  if (verbosity >= G4VisManager::confirmations) {
1417  G4cout << "Viewer \"" << currentViewer -> GetName ()
1418  << "\"" << " saved to ";
1419  if (newValue == "G4cout") {
1420  G4cout << "G4cout.";
1421  } else {
1422  G4cout << "file \'" << newValue << "\".";
1423  }
1424  G4cout << G4endl;
1425  }
1426 }
1427 
1429 
1431  fScaleMultiplier (G4Vector3D (1., 1., 1.)),
1432  fScaleTo (G4Vector3D (1., 1., 1.))
1433 {
1434  G4bool omitable, currentAsDefault;
1435 
1437  ("/vis/viewer/scale", this);
1438  fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
1439  fpCommandScale -> SetGuidance
1440  ("Multiplies components of current scaling by components of this factor."
1441  "\n Scales (x,y,z) by corresponding components of the resulting factor.");
1442  fpCommandScale -> SetGuidance
1443  ("");
1444  fpCommandScale -> SetParameterName
1445  ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
1446  omitable=true, currentAsDefault=true);
1447 
1449  ("/vis/viewer/scaleTo", this);
1450  fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
1451  fpCommandScaleTo -> SetGuidance
1452  ("Scales (x,y,z) by corresponding components of this factor.");
1453  fpCommandScaleTo -> SetParameterName
1454  ("x-scale-factor","y-scale-factor","z-scale-factor",
1455  omitable=true, currentAsDefault=true);
1456 }
1457 
1459  delete fpCommandScale;
1460  delete fpCommandScaleTo;
1461 }
1462 
1464  G4String currentValue;
1465  if (command == fpCommandScale) {
1467  }
1468  else if (command == fpCommandScaleTo) {
1470  }
1471  return currentValue;
1472 }
1473 
1475  G4String newValue) {
1476 
1477 
1479 
1480  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1481  if (!currentViewer) {
1482  if (verbosity >= G4VisManager::errors) {
1483  G4cout <<
1484  "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
1485  << G4endl;
1486  }
1487  return;
1488  }
1489 
1490  G4ViewParameters vp = currentViewer->GetViewParameters();
1491 
1492  if (command == fpCommandScale) {
1495  }
1496  else if (command == fpCommandScaleTo) {
1499  }
1500 
1501  if (verbosity >= G4VisManager::confirmations) {
1502  G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
1503  }
1504 
1505  SetViewParameters(currentViewer, vp);
1506 }
1507 
1509 
1511  G4bool omitable;
1512  fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
1513  fpCommand -> SetGuidance ("Selects viewer.");
1514  fpCommand -> SetGuidance
1515  ("Specify viewer by name. \"/vis/viewer/list\" to see possible viewers.");
1516  fpCommand -> SetParameterName ("viewer-name", omitable = false);
1517 }
1518 
1520  delete fpCommand;
1521 }
1522 
1524  return "";
1525 }
1526 
1528 
1530 
1531  G4String& selectName = newValue;
1532  G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
1533 
1534  if (!viewer) {
1535  if (verbosity >= G4VisManager::errors) {
1536  G4cout << "ERROR: Viewer \"" << selectName << "\"";
1537  G4cout << " not found - \"/vis/viewer/list\""
1538  "\n to see possibilities."
1539  << G4endl;
1540  }
1541  return;
1542  }
1543 
1544  if (viewer == fpVisManager -> GetCurrentViewer ()) {
1545  if (verbosity >= G4VisManager::warnings) {
1546  G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
1547  << " already selected." << G4endl;
1548  }
1549  return;
1550  }
1551 
1552  fpVisManager -> SetCurrentViewer (viewer); // Prints confirmation.
1553 
1554  RefreshIfRequired(viewer);
1555 }
1556 
1558 
1560  G4bool omitable, currentAsDefault;
1561  fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
1562  fpCommand -> SetGuidance
1563  ("Triggers graphical database post-processing for viewers"
1564  "\nusing that technique.");
1565  fpCommand -> SetGuidance
1566  ("For such viewers the view only becomes visible with this command."
1567  "\nBy default, acts on current viewer. \"/vis/viewer/list\""
1568  "\nto see possible viewers. Viewer becomes current.");
1569  fpCommand -> SetParameterName ("viewer-name",
1570  omitable = true,
1571  currentAsDefault = true);
1572 }
1573 
1575  delete fpCommand;
1576 }
1577 
1579  G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1580  if (viewer) {
1581  return viewer -> GetName ();
1582  }
1583  else {
1584  return "none";
1585  }
1586 }
1587 
1589 
1591 
1592  G4String& updateName = newValue;
1593 
1594  G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
1595  if (!viewer) {
1596  if (verbosity >= G4VisManager::errors) {
1597  G4cout <<
1598  "ERROR: G4VisCommandsViewerUpdate::SetNewValue: no current viewer."
1599  << G4endl;
1600  }
1601  return;
1602  }
1603 
1604  G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1605  if (!sceneHandler) {
1606  if (verbosity >= G4VisManager::errors) {
1607  G4cout << "ERROR: Viewer \"" << updateName << "\"" <<
1608  " has no scene handler - report serious bug."
1609  << G4endl;
1610  }
1611  return;
1612  }
1613 
1614  G4Scene* scene = sceneHandler->GetScene();
1615  if (!scene) {
1616  if (verbosity >= G4VisManager::confirmations) {
1617  G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1618  << "\", to which viewer \"" << updateName << "\"" <<
1619  "\n is attached, has no scene - \"/vis/scene/create\" and"
1620  " \"/vis/sceneHandler/attach\""
1621  "\n (or use compound command \"/vis/drawVolume\")."
1622  << G4endl;
1623  }
1624  return;
1625  }
1626 
1627  if (verbosity >= G4VisManager::confirmations) {
1628  G4cout << "Viewer \"" << viewer -> GetName () << "\"";
1629  G4cout << " post-processing triggered." << G4endl;
1630  }
1631  viewer -> ShowView ();
1632  // Assume future need to "refresh" transients...
1633  sceneHandler -> SetMarkForClearingTransientStore(true);
1634 }
1635 
1637 
1639  fZoomMultiplier (1.),
1640  fZoomTo (1.)
1641 {
1642  G4bool omitable, currentAsDefault;
1643 
1645  ("/vis/viewer/zoom", this);
1646  fpCommandZoom -> SetGuidance ("Incremental zoom.");
1647  fpCommandZoom -> SetGuidance
1648  ("Multiplies current magnification by this factor.");
1649  fpCommandZoom -> SetParameterName("multiplier",
1650  omitable=true,
1651  currentAsDefault=true);
1652 
1654  ("/vis/viewer/zoomTo", this);
1655  fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
1656  fpCommandZoomTo -> SetGuidance
1657  ("Magnifies standard magnification by this factor.");
1658  fpCommandZoomTo -> SetParameterName("factor",
1659  omitable=true,
1660  currentAsDefault=true);
1661 }
1662 
1664  delete fpCommandZoom;
1665  delete fpCommandZoomTo;
1666 }
1667 
1669  G4String currentValue;
1670  if (command == fpCommandZoom) {
1672  }
1673  else if (command == fpCommandZoomTo) {
1674  currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
1675  }
1676  return currentValue;
1677 }
1678 
1680  G4String newValue) {
1681 
1682 
1684 
1685  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1686  if (!currentViewer) {
1687  if (verbosity >= G4VisManager::errors) {
1688  G4cout <<
1689  "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
1690  << G4endl;
1691  }
1692  return;
1693  }
1694 
1695  G4ViewParameters vp = currentViewer->GetViewParameters();
1696 
1697  if (command == fpCommandZoom) {
1700  }
1701  else if (command == fpCommandZoomTo) {
1703  vp.SetZoomFactor(fZoomTo);
1704  }
1705 
1706  if (verbosity >= G4VisManager::confirmations) {
1707  G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
1708  }
1709 
1710  SetViewParameters(currentViewer, vp);
1711 }
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:357
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:294
G4UIcmdWith3Vector * fpCommandScale
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:432
G4String GetCurrentValue(G4UIcommand *command)
virtual void FinishView()
Definition: G4VViewer.cc:111
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)