Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/management/src/G4VisCommandsViewer.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/management/src/G4VisCommandsViewer.cc (Version 11.3.0) and /visualization/management/src/G4VisCommandsViewer.cc (Version 10.6)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
 26 //                                                 26 //
 27                                                    27 
 28 // /vis/viewer commands - John Allison  25th O     28 // /vis/viewer commands - John Allison  25th October 1998
 29                                                    29 
 30 #include "G4VisCommandsViewer.hh"                  30 #include "G4VisCommandsViewer.hh"
 31                                                    31 
 32 #include "G4VisManager.hh"                         32 #include "G4VisManager.hh"
 33 #include "G4GraphicsSystemList.hh"                 33 #include "G4GraphicsSystemList.hh"
 34 #include "G4VisCommandsScene.hh"                   34 #include "G4VisCommandsScene.hh"
 35 #include "G4UImanager.hh"                          35 #include "G4UImanager.hh"
 36 #include "G4UIcommand.hh"                          36 #include "G4UIcommand.hh"
 37 #include "G4UIcmdWithoutParameter.hh"              37 #include "G4UIcmdWithoutParameter.hh"
 38 #include "G4UIcmdWithAString.hh"                   38 #include "G4UIcmdWithAString.hh"
 39 #include "G4UIcmdWithADouble.hh"                   39 #include "G4UIcmdWithADouble.hh"
 40 #include "G4UIcmdWithADoubleAndUnit.hh"            40 #include "G4UIcmdWithADoubleAndUnit.hh"
 41 #include "G4UIcmdWith3Vector.hh"                   41 #include "G4UIcmdWith3Vector.hh"
 42 #include "G4PhysicalVolumesSearchScene.hh"         42 #include "G4PhysicalVolumesSearchScene.hh"
 43 #include "G4TransportationManager.hh"              43 #include "G4TransportationManager.hh"
 44 #include "G4Point3D.hh"                            44 #include "G4Point3D.hh"
 45 #include "G4SystemOfUnits.hh"                      45 #include "G4SystemOfUnits.hh"
 46 #include "G4UnitsTable.hh"                         46 #include "G4UnitsTable.hh"
 47 #include "G4Filesystem.hh"                     <<  47 #include "G4ios.hh"
                                                   >>  48 #ifdef G4VIS_USE_STD11
 48 #include <chrono>                                  49 #include <chrono>
 49 #include <thread>                                  50 #include <thread>
                                                   >>  51 #endif
 50 #include <sstream>                                 52 #include <sstream>
 51 #include <fstream>                                 53 #include <fstream>
                                                   >>  54 #include <sstream>
 52 #include <iomanip>                                 55 #include <iomanip>
 53 #include <cstdio>                                  56 #include <cstdio>
                                                   >>  57 #ifdef WIN32
 54 #include <regex>                                   58 #include <regex>
 55 #include <set>                                 <<  59 #include <filesystem>
 56                                                <<  60 #endif //WIN32
 57 #define G4warn G4cout                          << 
 58                                                    61 
 59 ////////////// /vis/viewer/addCutawayPlane ///     62 ////////////// /vis/viewer/addCutawayPlane ///////////////////////////////////////
 60                                                    63 
 61 G4VisCommandViewerAddCutawayPlane::G4VisComman     64 G4VisCommandViewerAddCutawayPlane::G4VisCommandViewerAddCutawayPlane () {
 62   G4bool omitable;                                 65   G4bool omitable;
 63   fpCommand = new G4UIcommand ("/vis/viewer/ad     66   fpCommand = new G4UIcommand ("/vis/viewer/addCutawayPlane", this);
 64   fpCommand -> SetGuidance                         67   fpCommand -> SetGuidance
 65     ("Add cutaway plane to current viewer.");      68     ("Add cutaway plane to current viewer.");
 66   G4UIparameter* parameter;                        69   G4UIparameter* parameter;
 67   parameter  =  new G4UIparameter("x",'d',omit     70   parameter  =  new G4UIparameter("x",'d',omitable = true);
 68   parameter  -> SetDefaultValue  (0);              71   parameter  -> SetDefaultValue  (0);
 69   parameter  -> SetGuidance      ("Coordinate      72   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
 70   fpCommand->SetParameter(parameter);              73   fpCommand->SetParameter(parameter);
 71   parameter  =  new G4UIparameter("y",'d',omit     74   parameter  =  new G4UIparameter("y",'d',omitable = true);
 72   parameter  -> SetDefaultValue  (0);              75   parameter  -> SetDefaultValue  (0);
 73   parameter  -> SetGuidance      ("Coordinate      76   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
 74   fpCommand->SetParameter(parameter);              77   fpCommand->SetParameter(parameter);
 75   parameter  =  new G4UIparameter("z",'d',omit     78   parameter  =  new G4UIparameter("z",'d',omitable = true);
 76   parameter  -> SetDefaultValue  (0);              79   parameter  -> SetDefaultValue  (0);
 77   parameter  -> SetGuidance      ("Coordinate      80   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
 78   fpCommand->SetParameter(parameter);              81   fpCommand->SetParameter(parameter);
 79   parameter  =  new G4UIparameter("unit",'s',o     82   parameter  =  new G4UIparameter("unit",'s',omitable = true);
 80   parameter  -> SetDefaultValue  ("m");            83   parameter  -> SetDefaultValue  ("m");
 81   parameter  -> SetGuidance      ("Unit of poi     84   parameter  -> SetGuidance      ("Unit of point on the plane.");
 82   fpCommand->SetParameter(parameter);              85   fpCommand->SetParameter(parameter);
 83   parameter  =  new G4UIparameter("nx",'d',omi     86   parameter  =  new G4UIparameter("nx",'d',omitable = true);
 84   parameter  -> SetDefaultValue  (1);              87   parameter  -> SetDefaultValue  (1);
 85   parameter  -> SetGuidance      ("Component o     88   parameter  -> SetGuidance      ("Component of plane normal.");
 86   fpCommand->SetParameter(parameter);              89   fpCommand->SetParameter(parameter);
 87   parameter  =  new G4UIparameter("ny",'d',omi     90   parameter  =  new G4UIparameter("ny",'d',omitable = true);
 88   parameter  -> SetDefaultValue  (0);              91   parameter  -> SetDefaultValue  (0);
 89   parameter  -> SetGuidance      ("Component o     92   parameter  -> SetGuidance      ("Component of plane normal.");
 90   fpCommand->SetParameter(parameter);              93   fpCommand->SetParameter(parameter);
 91   parameter  =  new G4UIparameter("nz",'d',omi     94   parameter  =  new G4UIparameter("nz",'d',omitable = true);
 92   parameter  -> SetDefaultValue  (0);              95   parameter  -> SetDefaultValue  (0);
 93   parameter  -> SetGuidance      ("Component o     96   parameter  -> SetGuidance      ("Component of plane normal.");
 94   fpCommand->SetParameter(parameter);              97   fpCommand->SetParameter(parameter);
 95 }                                                  98 }
 96                                                    99 
 97 G4VisCommandViewerAddCutawayPlane::~G4VisComma    100 G4VisCommandViewerAddCutawayPlane::~G4VisCommandViewerAddCutawayPlane () {
 98   delete fpCommand;                               101   delete fpCommand;
 99 }                                                 102 }
100                                                   103 
101 G4String G4VisCommandViewerAddCutawayPlane::Ge    104 G4String G4VisCommandViewerAddCutawayPlane::GetCurrentValue (G4UIcommand*) {
102   return "";                                      105   return "";
103 }                                                 106 }
104                                                   107 
105 void G4VisCommandViewerAddCutawayPlane::SetNew    108 void G4VisCommandViewerAddCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
106                                                   109 
107   G4VisManager::Verbosity verbosity = fpVisMan    110   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
108                                                   111 
109   G4VViewer* viewer = fpVisManager -> GetCurre    112   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
110   if (!viewer) {                                  113   if (!viewer) {
111     if (verbosity >= G4VisManager::errors) {      114     if (verbosity >= G4VisManager::errors) {
112       G4warn <<                                << 115       G4cerr <<
113   "ERROR: No current viewer - \"/vis/viewer/li    116   "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
114        << G4endl;                                 117        << G4endl;
115     }                                             118     }
116     return;                                       119     return;
117   }                                               120   }
118                                                   121 
119   G4double x, y, z, nx, ny, nz;                   122   G4double x, y, z, nx, ny, nz;
120   G4String unit;                                  123   G4String unit;
121   std::istringstream is (newValue);               124   std::istringstream is (newValue);
122   is >> x >> y >> z >> unit >> nx >> ny >> nz;    125   is >> x >> y >> z >> unit >> nx >> ny >> nz;
123   G4double F = G4UIcommand::ValueOf(unit);        126   G4double F = G4UIcommand::ValueOf(unit);
124   x *= F; y *= F; z *= F;                         127   x *= F; y *= F; z *= F;
125                                                   128 
126   G4ViewParameters vp = viewer->GetViewParamet    129   G4ViewParameters vp = viewer->GetViewParameters();
127   // Make sure normal is normalised.           << 130   vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
128   vp.AddCutawayPlane(G4Plane3D(G4Normal3D(nx,n << 
129   if (verbosity >= G4VisManager::confirmations    131   if (verbosity >= G4VisManager::confirmations) {
130     G4cout << "Cutaway planes for viewer \"" <    132     G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
131     const G4Planes& cutaways = vp.GetCutawayPl    133     const G4Planes& cutaways = vp.GetCutawayPlanes();
132     for (std::size_t i = 0; i < cutaways.size( << 134     for (size_t i = 0; i < cutaways.size(); ++i)
133       G4cout << "\n  " << i << ": " << cutaway    135       G4cout << "\n  " << i << ": " << cutaways[i];
134     G4cout << G4endl;                             136     G4cout << G4endl;
135   }                                               137   }
136                                                   138 
137   SetViewParameters(viewer, vp);                  139   SetViewParameters(viewer, vp);
138 }                                                 140 }
139                                                   141 
140 ////////////// /vis/viewer/centreOn //////////    142 ////////////// /vis/viewer/centreOn ///////////////////////////////////////
141                                                   143 
142 G4VisCommandViewerCentreOn::G4VisCommandViewer    144 G4VisCommandViewerCentreOn::G4VisCommandViewerCentreOn () {
143   G4bool omitable;                                145   G4bool omitable;
144   fpCommandCentreAndZoomInOn = new G4UIcommand    146   fpCommandCentreAndZoomInOn = new G4UIcommand ("/vis/viewer/centreAndZoomInOn", this);
145   fpCommandCentreAndZoomInOn->SetGuidance         147   fpCommandCentreAndZoomInOn->SetGuidance
146   ("Centre and zoom in on the given physical v    148   ("Centre and zoom in on the given physical volume.");
147   fpCommandCentreAndZoomInOn->SetGuidance         149   fpCommandCentreAndZoomInOn->SetGuidance
148   ("The names of all volumes in all worlds are    150   ("The names of all volumes in all worlds are matched against pv-name. If"
149    "\ncopy-no is supplied, it matches the copy    151    "\ncopy-no is supplied, it matches the copy number too. If pv-name is of the"
150    "\nform \"/regexp/\", where regexp is a reg    152    "\nform \"/regexp/\", where regexp is a regular expression (see C++ regex),"
151    "\nthe match uses the usual rules of regula    153    "\nthe match uses the usual rules of regular expression matching."
152    "\nOtherwise an exact match is required."      154    "\nOtherwise an exact match is required."
153    "\nFor example, \"/Shap/\" matches \"Shape1    155    "\nFor example, \"/Shap/\" matches \"Shape1\" and \"Shape2\".");
154   fpCommandCentreAndZoomInOn->SetGuidance         156   fpCommandCentreAndZoomInOn->SetGuidance
155   ("It may help to see a textual representatio    157   ("It may help to see a textual representation of the geometry hierarchy of"
156    "\nthe worlds. Try \"/vis/drawTree [worlds]    158    "\nthe worlds. Try \"/vis/drawTree [worlds]\" or one of the driver/browser"
157    "\ncombinations that have the required func    159    "\ncombinations that have the required functionality, e.g., HepRepFile.");
158   fpCommandCentreAndZoomInOn->SetGuidance         160   fpCommandCentreAndZoomInOn->SetGuidance
159    ("If there are more than one matching physi    161    ("If there are more than one matching physical volumes they will all be"
160     "\nincluded. If this is not what you want,    162     "\nincluded. If this is not what you want, and what you want is to centre on a"
161     "\nparticular touchable, then select the t    163     "\nparticular touchable, then select the touchable (\"/vis/set/touchable\") and"
162     "\nuse \"/vis/touchable/centreOn\". (You m    164     "\nuse \"/vis/touchable/centreOn\". (You may need \"/vis/touchable/findPath\".)");
163   G4UIparameter* parameter;                       165   G4UIparameter* parameter;
164   parameter =  new G4UIparameter("pv-name",'s'    166   parameter =  new G4UIparameter("pv-name",'s',omitable = false);
165   parameter->SetGuidance      ("Physical volum    167   parameter->SetGuidance      ("Physical volume name.");
166   fpCommandCentreAndZoomInOn->SetParameter(par    168   fpCommandCentreAndZoomInOn->SetParameter(parameter);
167   parameter =  new G4UIparameter("copy-no",'i'    169   parameter =  new G4UIparameter("copy-no",'i',omitable = true);
168   parameter->SetDefaultValue  (-1);               170   parameter->SetDefaultValue  (-1);
169   parameter->SetGuidance      ("Copy number. -    171   parameter->SetGuidance      ("Copy number. -1 means any or all copy numbers");
170   fpCommandCentreAndZoomInOn->SetParameter(par    172   fpCommandCentreAndZoomInOn->SetParameter(parameter);
171                                                   173 
172   fpCommandCentreOn = new G4UIcommand ("/vis/v    174   fpCommandCentreOn = new G4UIcommand ("/vis/viewer/centreOn", this);
173   fpCommandCentreOn->SetGuidance ("Centre the     175   fpCommandCentreOn->SetGuidance ("Centre the view on the given physical volume.");
174   // Pick up additional guidance from /vis/vie    176   // Pick up additional guidance from /vis/viewer/centreAndZoomInOn
175   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,    177   CopyGuidanceFrom(fpCommandCentreAndZoomInOn,fpCommandCentreOn,1);
176   // Pick up parameters from /vis/viewer/centr    178   // Pick up parameters from /vis/viewer/centreAndZoomInOn
177   CopyParametersFrom(fpCommandCentreAndZoomInO    179   CopyParametersFrom(fpCommandCentreAndZoomInOn,fpCommandCentreOn);
178 }                                                 180 }
179                                                   181 
180 G4VisCommandViewerCentreOn::~G4VisCommandViewe    182 G4VisCommandViewerCentreOn::~G4VisCommandViewerCentreOn () {
181   delete fpCommandCentreAndZoomInOn;              183   delete fpCommandCentreAndZoomInOn;
182   delete fpCommandCentreOn;                       184   delete fpCommandCentreOn;
183 }                                                 185 }
184                                                   186 
185 G4String G4VisCommandViewerCentreOn::GetCurren    187 G4String G4VisCommandViewerCentreOn::GetCurrentValue (G4UIcommand*) {
186   return "";                                      188   return "";
187 }                                                 189 }
188                                                   190 
189 void G4VisCommandViewerCentreOn::SetNewValue (    191 void G4VisCommandViewerCentreOn::SetNewValue (G4UIcommand* command, G4String newValue) {
190                                                   192   
191   G4VisManager::Verbosity verbosity = fpVisMan    193   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
192   G4bool warn = verbosity >= G4VisManager::war    194   G4bool warn = verbosity >= G4VisManager::warnings;
193                                                   195 
194   G4VViewer* currentViewer = fpVisManager -> G    196   G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
195   if (!currentViewer) {                           197   if (!currentViewer) {
196     if (verbosity >= G4VisManager::errors) {      198     if (verbosity >= G4VisManager::errors) {
197       G4warn <<                                << 199       G4cerr <<
198       "ERROR: No current viewer - \"/vis/viewe    200       "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
199       << G4endl;                                  201       << G4endl;
200     }                                             202     }
201     return;                                       203     return;
202   }                                               204   }
203                                                   205   
204   G4String pvName;                                206   G4String pvName;
205   G4int copyNo;                                   207   G4int copyNo;
206   std::istringstream is (newValue);               208   std::istringstream is (newValue);
207   is >> pvName >> copyNo;                         209   is >> pvName >> copyNo;
208                                                   210 
209   // Find physical volumes                        211   // Find physical volumes
210   G4TransportationManager* transportationManag    212   G4TransportationManager* transportationManager =
211   G4TransportationManager::GetTransportationMa    213   G4TransportationManager::GetTransportationManager ();
212   std::size_t nWorlds = transportationManager- << 214   size_t nWorlds = transportationManager->GetNoWorlds();
213   std::vector<G4PhysicalVolumesSearchScene::Fi    215   std::vector<G4PhysicalVolumesSearchScene::Findings> findingsVector;
214   std::vector<G4VPhysicalVolume*>::iterator it    216   std::vector<G4VPhysicalVolume*>::iterator iterWorld =
215   transportationManager->GetWorldsIterator();     217   transportationManager->GetWorldsIterator();
216   for (std::size_t i = 0; i < nWorlds; ++i, ++ << 218   for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
217     G4PhysicalVolumeModel searchModel (*iterWo    219     G4PhysicalVolumeModel searchModel (*iterWorld);  // Unlimited depth.
218     G4ModelingParameters mp;  // Default - no     220     G4ModelingParameters mp;  // Default - no culling.
219     searchModel.SetModelingParameters (&mp);      221     searchModel.SetModelingParameters (&mp);
220     // Find all instances at any position in t << 
221     G4PhysicalVolumesSearchScene searchScene (    222     G4PhysicalVolumesSearchScene searchScene (&searchModel, pvName, copyNo);
222     searchModel.DescribeYourselfTo (searchScen    223     searchModel.DescribeYourselfTo (searchScene);  // Initiate search.
223     for (const auto& findings: searchScene.Get    224     for (const auto& findings: searchScene.GetFindings()) {
224       findingsVector.push_back(findings);         225       findingsVector.push_back(findings);
225     }                                             226     }
226   }                                               227   }
227                                                   228   
228   if (findingsVector.empty()) {                   229   if (findingsVector.empty()) {
229     if (verbosity >= G4VisManager::warnings) {    230     if (verbosity >= G4VisManager::warnings) {
230       G4warn                                   << 231       G4cerr
231       << "WARNING: Volume \"" << pvName << "\"    232       << "WARNING: Volume \"" << pvName << "\" ";
232       if (copyNo > 0) {                           233       if (copyNo > 0) {
233         G4warn << "copy number " << copyNo;    << 234         G4cerr << "copy number " << copyNo;
234       }                                           235       }
235       G4warn << " not found." << G4endl;       << 236       G4cerr << " not found." << G4endl;
236     }                                             237     }
237     return;                                       238     return;
238   }                                               239   }
239                                                   240 
240   // A vector of found paths so that we can hi << 
241   std::vector<std::vector<G4PhysicalVolumeMode << 
242                                                << 
243   // Use a temporary scene in order to find vi    241   // Use a temporary scene in order to find vis extent
244   G4Scene tempScene("Centre Scene");              242   G4Scene tempScene("Centre Scene");
245   G4bool successfullyAdded = true;             << 
246   for (const auto& findings: findingsVector) {    243   for (const auto& findings: findingsVector) {
247     // To handle paramaterisations we have to     244     // To handle paramaterisations we have to set the copy number
248     findings.fpFoundPV->SetCopyNo(findings.fFo    245     findings.fpFoundPV->SetCopyNo(findings.fFoundPVCopyNo);
249     // Create a temporary physical volume mode    246     // Create a temporary physical volume model.
250     // They have to be created on the heap bec    247     // They have to be created on the heap because they have
251     // to hang about long enough to be conflat    248     // to hang about long enough to be conflated.
252     G4PhysicalVolumeModel* tempPVModel = new G    249     G4PhysicalVolumeModel* tempPVModel = new G4PhysicalVolumeModel
253     (findings.fpFoundPV,                          250     (findings.fpFoundPV,
254      0, // Only interested in top volume          251      0, // Only interested in top volume
255      findings.fFoundObjectTransformation,         252      findings.fFoundObjectTransformation,
256      0, // No modelling parameters (these are     253      0, // No modelling parameters (these are set later by the scene handler).
257      true,  // Use full extent                    254      true,  // Use full extent
258      findings.fFoundBasePVPath);                  255      findings.fFoundBasePVPath);
259     // ...and add it to the scene.                256     // ...and add it to the scene.
260     auto successful = tempScene.AddRunDuration << 257     G4bool successful = tempScene.AddRunDurationModel(tempPVModel,warn);
261     if (!successful) {                         << 258     if (successful) {
262       successfullyAdded = false;               << 259       if (verbosity >= G4VisManager::confirmations) {
263       continue;                                << 260         G4cout << "\"" << findings.fpFoundPV->GetName()
264     }                                          << 261         << "\", copy no. " << findings.fFoundPVCopyNo
265     if (verbosity >= G4VisManager::parameters) << 262         << ",\n  found in searched volume \""
266       G4cout << "\"" << findings.fpFoundPV->Ge << 263         << findings.fpSearchPV->GetName()
267       << "\", copy no. " << findings.fFoundPVC << 264         << "\" at depth " << findings.fFoundDepth
268       << ",\n  found in searched volume \""    << 265         << ",\n  base path: \"" << findings.fFoundBasePVPath
269       << findings.fpSearchPV->GetName()        << 266         << ",\n  has been added to temporary scene \"" << tempScene.GetName() << "\"."
270       << "\" at depth " << findings.fFoundDept << 267         << G4endl;
271       << ",\n  base path: \"" << findings.fFou << 268       }
272       << ",\n  has been added to temporary sce << 
273       << G4endl;                               << 
274     }                                             269     }
275     foundPaths.push_back(findings.fFoundFullPV << 
276   }                                               270   }
277   // Delete temporary physical volume models      271   // Delete temporary physical volume models
278   for (const auto& sceneModel: tempScene.GetRu    272   for (const auto& sceneModel: tempScene.GetRunDurationModelList()) {
279     delete sceneModel.fpModel;                    273     delete sceneModel.fpModel;
280   }                                               274   }
281   if (!successfullyAdded) return;              << 275   
282                                                << 
283   // Relevant results                             276   // Relevant results
284   const G4VisExtent& newExtent = tempScene.Get    277   const G4VisExtent& newExtent = tempScene.GetExtent();
285   const G4ThreeVector& newTargetPoint = newExt    278   const G4ThreeVector& newTargetPoint = newExtent.GetExtentCentre();
286                                                << 279   
287   G4Scene* currentScene = currentViewer->GetSc    280   G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
288   G4ViewParameters saveVP = currentViewer->Get    281   G4ViewParameters saveVP = currentViewer->GetViewParameters();
289   G4ViewParameters newVP = saveVP;                282   G4ViewParameters newVP = saveVP;
290   if (command == fpCommandCentreAndZoomInOn) {    283   if (command == fpCommandCentreAndZoomInOn) {
291     // Calculate the new zoom factor              284     // Calculate the new zoom factor
292     const G4double zoomFactor                     285     const G4double zoomFactor
293     = currentScene->GetExtent().GetExtentRadiu    286     = currentScene->GetExtent().GetExtentRadius()/newExtent.GetExtentRadius();
294     newVP.SetZoomFactor(zoomFactor);              287     newVP.SetZoomFactor(zoomFactor);
295   }                                               288   }
296   // Change the target point                      289   // Change the target point
297   const G4Point3D& standardTargetPoint = curre    290   const G4Point3D& standardTargetPoint = currentScene->GetStandardTargetPoint();
298   newVP.SetCurrentTargetPoint(newTargetPoint -    291   newVP.SetCurrentTargetPoint(newTargetPoint - standardTargetPoint);
299                                                << 292   // Interpolate
300   // If this particular view is simple enough  << 293   InterpolateToNewView(currentViewer, saveVP, newVP);
301   if (currentViewer->GetKernelVisitElapsedTime << 
302     // Interpolate                             << 
303     auto keepVisVerbosity = fpVisManager->GetV << 
304     fpVisManager->SetVerboseLevel(G4VisManager << 
305     if (newVP != saveVP) InterpolateToNewView( << 
306     // ...and twinkle                          << 
307     Twinkle(currentViewer,newVP,foundPaths);   << 
308     fpVisManager->SetVerboseLevel(keepVisVerbo << 
309   }                                            << 
310                                                   294 
311   if (verbosity >= G4VisManager::confirmations    295   if (verbosity >= G4VisManager::confirmations) {
312     G4cout                                        296     G4cout
313     << "Viewer \"" << currentViewer->GetName()    297     << "Viewer \"" << currentViewer->GetName()
314     << "\" centred ";                             298     << "\" centred ";
315     if (fpCommandCentreAndZoomInOn) {             299     if (fpCommandCentreAndZoomInOn) {
316       G4cout << "and zoomed in";                  300       G4cout << "and zoomed in";
317     }                                             301     }
318     G4cout << " on physical volume(s) \"" << p    302     G4cout << " on physical volume(s) \"" << pvName << '\"'
319     << G4endl;                                    303     << G4endl;
320   }                                            << 304   }  
321                                                << 305   
322   SetViewParameters(currentViewer, newVP);        306   SetViewParameters(currentViewer, newVP);
323 }                                                 307 }
324                                                   308 
325 ////////////// /vis/viewer/changeCutawayPlane     309 ////////////// /vis/viewer/changeCutawayPlane ///////////////////////////////////////
326                                                   310 
327 G4VisCommandViewerChangeCutawayPlane::G4VisCom    311 G4VisCommandViewerChangeCutawayPlane::G4VisCommandViewerChangeCutawayPlane () {
328   G4bool omitable;                                312   G4bool omitable;
329   fpCommand = new G4UIcommand ("/vis/viewer/ch    313   fpCommand = new G4UIcommand ("/vis/viewer/changeCutawayPlane", this);
330   fpCommand -> SetGuidance("Change cutaway pla    314   fpCommand -> SetGuidance("Change cutaway plane.");
331   G4UIparameter* parameter;                       315   G4UIparameter* parameter;
332   parameter  =  new G4UIparameter("index",'i',    316   parameter  =  new G4UIparameter("index",'i',omitable = false);
333   parameter  -> SetGuidance      ("Index of pl    317   parameter  -> SetGuidance      ("Index of plane: 0, 1, 2.");
334   fpCommand->SetParameter(parameter);             318   fpCommand->SetParameter(parameter);
335   parameter  =  new G4UIparameter("x",'d',omit    319   parameter  =  new G4UIparameter("x",'d',omitable = true);
336   parameter  -> SetDefaultValue  (0);             320   parameter  -> SetDefaultValue  (0);
337   parameter  -> SetGuidance      ("Coordinate     321   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
338   fpCommand->SetParameter(parameter);             322   fpCommand->SetParameter(parameter);
339   parameter  =  new G4UIparameter("y",'d',omit    323   parameter  =  new G4UIparameter("y",'d',omitable = true);
340   parameter  -> SetDefaultValue  (0);             324   parameter  -> SetDefaultValue  (0);
341   parameter  -> SetGuidance      ("Coordinate     325   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
342   fpCommand->SetParameter(parameter);             326   fpCommand->SetParameter(parameter);
343   parameter  =  new G4UIparameter("z",'d',omit    327   parameter  =  new G4UIparameter("z",'d',omitable = true);
344   parameter  -> SetDefaultValue  (0);             328   parameter  -> SetDefaultValue  (0);
345   parameter  -> SetGuidance      ("Coordinate     329   parameter  -> SetGuidance      ("Coordinate of point on the plane.");
346   fpCommand->SetParameter(parameter);             330   fpCommand->SetParameter(parameter);
347   parameter  =  new G4UIparameter("unit",'s',o    331   parameter  =  new G4UIparameter("unit",'s',omitable = true);
348   parameter  -> SetDefaultValue  ("m");           332   parameter  -> SetDefaultValue  ("m");
349   parameter  -> SetGuidance      ("Unit of poi    333   parameter  -> SetGuidance      ("Unit of point on the plane.");
350   fpCommand->SetParameter(parameter);             334   fpCommand->SetParameter(parameter);
351   parameter  =  new G4UIparameter("nx",'d',omi    335   parameter  =  new G4UIparameter("nx",'d',omitable = true);
352   parameter  -> SetDefaultValue  (1);             336   parameter  -> SetDefaultValue  (1);
353   parameter  -> SetGuidance      ("Component o    337   parameter  -> SetGuidance      ("Component of plane normal.");
354   fpCommand->SetParameter(parameter);             338   fpCommand->SetParameter(parameter);
355   parameter  =  new G4UIparameter("ny",'d',omi    339   parameter  =  new G4UIparameter("ny",'d',omitable = true);
356   parameter  -> SetDefaultValue  (0);             340   parameter  -> SetDefaultValue  (0);
357   parameter  -> SetGuidance      ("Component o    341   parameter  -> SetGuidance      ("Component of plane normal.");
358   fpCommand->SetParameter(parameter);             342   fpCommand->SetParameter(parameter);
359   parameter  =  new G4UIparameter("nz",'d',omi    343   parameter  =  new G4UIparameter("nz",'d',omitable = true);
360   parameter  -> SetDefaultValue  (0);             344   parameter  -> SetDefaultValue  (0);
361   parameter  -> SetGuidance      ("Component o    345   parameter  -> SetGuidance      ("Component of plane normal.");
362   fpCommand->SetParameter(parameter);             346   fpCommand->SetParameter(parameter);
363 }                                                 347 }
364                                                   348 
365 G4VisCommandViewerChangeCutawayPlane::~G4VisCo    349 G4VisCommandViewerChangeCutawayPlane::~G4VisCommandViewerChangeCutawayPlane () {
366   delete fpCommand;                               350   delete fpCommand;
367 }                                                 351 }
368                                                   352 
369 G4String G4VisCommandViewerChangeCutawayPlane:    353 G4String G4VisCommandViewerChangeCutawayPlane::GetCurrentValue (G4UIcommand*) {
370   return "";                                      354   return "";
371 }                                                 355 }
372                                                   356 
373 void G4VisCommandViewerChangeCutawayPlane::Set    357 void G4VisCommandViewerChangeCutawayPlane::SetNewValue (G4UIcommand*, G4String newValue) {
374                                                   358 
375   G4VisManager::Verbosity verbosity = fpVisMan    359   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
376                                                   360 
377   G4VViewer* viewer = fpVisManager -> GetCurre    361   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
378   if (!viewer) {                                  362   if (!viewer) {
379     if (verbosity >= G4VisManager::errors) {      363     if (verbosity >= G4VisManager::errors) {
380       G4warn <<                                << 364       G4cerr <<
381   "ERROR: No current viewer - \"/vis/viewer/li    365   "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
382        << G4endl;                                 366        << G4endl;
383     }                                             367     }
384     return;                                       368     return;
385   }                                               369   }
386                                                   370 
387   std::size_t index;                           << 371   size_t index;
388   G4double x, y, z, nx, ny, nz;                   372   G4double x, y, z, nx, ny, nz;
389   G4String unit;                                  373   G4String unit;
390   std::istringstream is (newValue);               374   std::istringstream is (newValue);
391   is >> index >> x >> y >> z >> unit >> nx >>     375   is >> index >> x >> y >> z >> unit >> nx >> ny >> nz;
392   G4double F = G4UIcommand::ValueOf(unit);        376   G4double F = G4UIcommand::ValueOf(unit);
393   x *= F; y *= F; z *= F;                         377   x *= F; y *= F; z *= F;
394                                                   378 
395   G4ViewParameters vp = viewer->GetViewParamet    379   G4ViewParameters vp = viewer->GetViewParameters();
396   // Make sure normal is normalised.           << 
397   vp.ChangeCutawayPlane(index,                    380   vp.ChangeCutawayPlane(index,
398       G4Plane3D(G4Normal3D(nx,ny,nz).unit(), G << 381       G4Plane3D(G4Normal3D(nx,ny,nz), G4Point3D(x,y,z)));
399   if (verbosity >= G4VisManager::confirmations    382   if (verbosity >= G4VisManager::confirmations) {
400     G4cout << "Cutaway planes for viewer \"" <    383     G4cout << "Cutaway planes for viewer \"" << viewer->GetName() << "\" now:";
401     const G4Planes& cutaways = vp.GetCutawayPl    384     const G4Planes& cutaways = vp.GetCutawayPlanes();
402     for (std::size_t i = 0; i < cutaways.size( << 385     for (size_t i = 0; i < cutaways.size(); ++i)
403       G4cout << "\n  " << i << ": " << cutaway    386       G4cout << "\n  " << i << ": " << cutaways[i];
404     G4cout << G4endl;                             387     G4cout << G4endl;
405   }                                               388   }
406                                                   389 
407   SetViewParameters(viewer, vp);                  390   SetViewParameters(viewer, vp);
408 }                                                 391 }
409                                                   392 
410 ////////////// /vis/viewer/clear /////////////    393 ////////////// /vis/viewer/clear ///////////////////////////////////////
411                                                   394 
412 G4VisCommandViewerClear::G4VisCommandViewerCle    395 G4VisCommandViewerClear::G4VisCommandViewerClear () {
413   G4bool omitable, currentAsDefault;              396   G4bool omitable, currentAsDefault;
414   fpCommand = new G4UIcmdWithAString ("/vis/vi    397   fpCommand = new G4UIcmdWithAString ("/vis/viewer/clear", this);
415   fpCommand -> SetGuidance ("Clears viewer.");    398   fpCommand -> SetGuidance ("Clears viewer.");
416   fpCommand -> SetGuidance                        399   fpCommand -> SetGuidance 
417     ("By default, clears current viewer.  Spec    400     ("By default, clears current viewer.  Specified viewer becomes current."
418      "\n\"/vis/viewer/list\" to see  possible     401      "\n\"/vis/viewer/list\" to see  possible viewer names.");
419   fpCommand -> SetParameterName ("viewer-name"    402   fpCommand -> SetParameterName ("viewer-name",
420          omitable = true,                         403          omitable = true,
421          currentAsDefault = true);                404          currentAsDefault = true);
422 }                                                 405 }
423                                                   406 
424 G4VisCommandViewerClear::~G4VisCommandViewerCl    407 G4VisCommandViewerClear::~G4VisCommandViewerClear () {
425   delete fpCommand;                               408   delete fpCommand;
426 }                                                 409 }
427                                                   410 
428 G4String G4VisCommandViewerClear::GetCurrentVa    411 G4String G4VisCommandViewerClear::GetCurrentValue (G4UIcommand*) {
429   G4VViewer* viewer = fpVisManager -> GetCurre    412   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
430   return viewer ? viewer -> GetName () : G4Str    413   return viewer ? viewer -> GetName () : G4String("none");
431 }                                                 414 }
432                                                   415 
433 void G4VisCommandViewerClear::SetNewValue (G4U    416 void G4VisCommandViewerClear::SetNewValue (G4UIcommand*, G4String newValue) {
434                                                   417 
435   G4VisManager::Verbosity verbosity = fpVisMan    418   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
436                                                   419 
437   G4String& clearName = newValue;                 420   G4String& clearName = newValue;
438   G4VViewer* viewer = fpVisManager -> GetViewe    421   G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
439   if (!viewer) {                                  422   if (!viewer) {
440     if (verbosity >= G4VisManager::errors) {      423     if (verbosity >= G4VisManager::errors) {
441       G4warn << "ERROR: Viewer \"" << clearNam << 424       G4cerr << "ERROR: Viewer \"" << clearName
442        << "\" not found - \"/vis/viewer/list\"    425        << "\" not found - \"/vis/viewer/list\" to see possibilities."
443        << G4endl;                                 426        << G4endl;
444     }                                             427     }
445     return;                                       428     return;
446   }                                               429   }
447                                                   430 
448   viewer->SetView();                              431   viewer->SetView();
449   viewer->ClearView();                            432   viewer->ClearView();
450   viewer->FinishView();                           433   viewer->FinishView();
451   if (verbosity >= G4VisManager::confirmations    434   if (verbosity >= G4VisManager::confirmations) {
452     G4cout << "Viewer \"" << clearName << "\"     435     G4cout << "Viewer \"" << clearName << "\" cleared." << G4endl;
453   }                                               436   }
454                                                   437 
455 }                                                 438 }
456                                                   439 
457 ////////////// /vis/viewer/clearCutawayPlanes     440 ////////////// /vis/viewer/clearCutawayPlanes ///////////////////////////////////////
458                                                   441 
459 G4VisCommandViewerClearCutawayPlanes::G4VisCom    442 G4VisCommandViewerClearCutawayPlanes::G4VisCommandViewerClearCutawayPlanes () {
460   fpCommand = new G4UIcmdWithoutParameter         443   fpCommand = new G4UIcmdWithoutParameter
461     ("/vis/viewer/clearCutawayPlanes", this);     444     ("/vis/viewer/clearCutawayPlanes", this);
462   fpCommand -> SetGuidance ("Clear cutaway pla    445   fpCommand -> SetGuidance ("Clear cutaway planes of current viewer.");
463 }                                                 446 }
464                                                   447 
465 G4VisCommandViewerClearCutawayPlanes::~G4VisCo    448 G4VisCommandViewerClearCutawayPlanes::~G4VisCommandViewerClearCutawayPlanes () {
466   delete fpCommand;                               449   delete fpCommand;
467 }                                                 450 }
468                                                   451 
469 G4String G4VisCommandViewerClearCutawayPlanes:    452 G4String G4VisCommandViewerClearCutawayPlanes::GetCurrentValue (G4UIcommand*) {
470   return "";                                      453   return "";
471 }                                                 454 }
472                                                   455 
473 void G4VisCommandViewerClearCutawayPlanes::Set    456 void G4VisCommandViewerClearCutawayPlanes::SetNewValue (G4UIcommand*, G4String) {
474                                                   457 
475   G4VisManager::Verbosity verbosity = fpVisMan    458   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
476                                                   459 
477   G4VViewer* viewer = fpVisManager -> GetCurre    460   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
478   if (!viewer) {                                  461   if (!viewer) {
479     if (verbosity >= G4VisManager::errors) {      462     if (verbosity >= G4VisManager::errors) {
480       G4warn <<                                << 463       G4cerr <<
481   "ERROR: No current viewer - \"/vis/viewer/li    464   "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
482        << G4endl;                                 465        << G4endl;
483     }                                             466     }
484     return;                                       467     return;
485   }                                               468   }
486                                                   469 
487   G4ViewParameters vp = viewer->GetViewParamet    470   G4ViewParameters vp = viewer->GetViewParameters();
488   vp.ClearCutawayPlanes();                        471   vp.ClearCutawayPlanes();
489   if (verbosity >= G4VisManager::confirmations    472   if (verbosity >= G4VisManager::confirmations) {
490     G4cout << "Cutaway planes for viewer \"" <    473     G4cout << "Cutaway planes for viewer \"" << viewer->GetName()
491      << "\" now cleared." << G4endl;              474      << "\" now cleared." << G4endl;
492   }                                               475   }
493                                                   476 
494   SetViewParameters(viewer, vp);                  477   SetViewParameters(viewer, vp);
495 }                                                 478 }
496                                                   479 
497 ////////////// /vis/viewer/clearTransients ///    480 ////////////// /vis/viewer/clearTransients //////////////////////////
498                                                   481 
499 G4VisCommandViewerClearTransients::G4VisComman    482 G4VisCommandViewerClearTransients::G4VisCommandViewerClearTransients () {
500   G4bool omitable, currentAsDefault;              483   G4bool omitable, currentAsDefault;
501   fpCommand = new G4UIcmdWithAString ("/vis/vi    484   fpCommand = new G4UIcmdWithAString ("/vis/viewer/clearTransients", this);
502   fpCommand -> SetGuidance ("Clears transients    485   fpCommand -> SetGuidance ("Clears transients from viewer.");
503   fpCommand -> SetGuidance                        486   fpCommand -> SetGuidance 
504   ("By default, operates on current viewer.  S    487   ("By default, operates on current viewer.  Specified viewer becomes current."
505      "\n\"/vis/viewer/list\" to see  possible     488      "\n\"/vis/viewer/list\" to see  possible viewer names.");
506   fpCommand -> SetParameterName ("viewer-name"    489   fpCommand -> SetParameterName ("viewer-name",
507          omitable = true,                         490          omitable = true,
508          currentAsDefault = true);                491          currentAsDefault = true);
509 }                                                 492 }
510                                                   493 
511 G4VisCommandViewerClearTransients::~G4VisComma    494 G4VisCommandViewerClearTransients::~G4VisCommandViewerClearTransients () {
512   delete fpCommand;                               495   delete fpCommand;
513 }                                                 496 }
514                                                   497 
515 G4String G4VisCommandViewerClearTransients::Ge    498 G4String G4VisCommandViewerClearTransients::GetCurrentValue (G4UIcommand*) {
516   G4VViewer* viewer = fpVisManager -> GetCurre    499   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
517   return viewer ? viewer -> GetName () : G4Str    500   return viewer ? viewer -> GetName () : G4String("none");
518 }                                                 501 }
519                                                   502 
520 void G4VisCommandViewerClearTransients::SetNew    503 void G4VisCommandViewerClearTransients::SetNewValue (G4UIcommand*, G4String newValue) {
521                                                   504 
522   G4VisManager::Verbosity verbosity = fpVisMan    505   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
523                                                   506 
524   G4String& clearName = newValue;                 507   G4String& clearName = newValue;
525   G4VViewer* viewer = fpVisManager -> GetViewe    508   G4VViewer* viewer = fpVisManager -> GetViewer (clearName);
526   if (!viewer) {                                  509   if (!viewer) {
527     if (verbosity >= G4VisManager::errors) {      510     if (verbosity >= G4VisManager::errors) {
528       G4warn << "ERROR: Viewer \"" << clearNam << 511       G4cerr << "ERROR: Viewer \"" << clearName
529        << "\" not found - \"/vis/viewer/list\"    512        << "\" not found - \"/vis/viewer/list\" to see possibilities."
530        << G4endl;                                 513        << G4endl;
531     }                                             514     }
532     return;                                       515     return;
533   }                                               516   }
534                                                   517 
535   G4VSceneHandler* sceneHandler = viewer->GetS    518   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
536   sceneHandler->SetMarkForClearingTransientSto    519   sceneHandler->SetMarkForClearingTransientStore(false);
537   fpVisManager->ResetTransientsDrawnFlags();      520   fpVisManager->ResetTransientsDrawnFlags();
538   sceneHandler->ClearTransientStore();            521   sceneHandler->ClearTransientStore();
539   if (verbosity >= G4VisManager::confirmations    522   if (verbosity >= G4VisManager::confirmations) {
540     G4cout << "Viewer \"" << clearName << "\"     523     G4cout << "Viewer \"" << clearName << "\" cleared of transients."
541      << G4endl;                                   524      << G4endl;
542   }                                               525   }
543                                                   526 
544 }                                                 527 }
545                                                   528 
546 ////////////// /vis/viewer/clearVisAttributesM    529 ////////////// /vis/viewer/clearVisAttributesModifiers ///////////////////////////////////////
547                                                   530 
548 G4VisCommandViewerClearVisAttributesModifiers:    531 G4VisCommandViewerClearVisAttributesModifiers::G4VisCommandViewerClearVisAttributesModifiers () {
549   fpCommand = new G4UIcmdWithoutParameter         532   fpCommand = new G4UIcmdWithoutParameter
550   ("/vis/viewer/clearVisAttributesModifiers",     533   ("/vis/viewer/clearVisAttributesModifiers", this);
551   fpCommand -> SetGuidance ("Clear vis attribu    534   fpCommand -> SetGuidance ("Clear vis attribute modifiers of current viewer.");
552   fpCommand -> SetGuidance ("(These are used f    535   fpCommand -> SetGuidance ("(These are used for touchables, etc.)");
553 }                                                 536 }
554                                                   537 
555 G4VisCommandViewerClearVisAttributesModifiers:    538 G4VisCommandViewerClearVisAttributesModifiers::~G4VisCommandViewerClearVisAttributesModifiers () {
556   delete fpCommand;                               539   delete fpCommand;
557 }                                                 540 }
558                                                   541 
559 G4String G4VisCommandViewerClearVisAttributesM    542 G4String G4VisCommandViewerClearVisAttributesModifiers::GetCurrentValue (G4UIcommand*) {
560   return "";                                      543   return "";
561 }                                                 544 }
562                                                   545 
563 void G4VisCommandViewerClearVisAttributesModif    546 void G4VisCommandViewerClearVisAttributesModifiers::SetNewValue (G4UIcommand*, G4String) {
564                                                   547 
565   G4VisManager::Verbosity verbosity = fpVisMan    548   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
566                                                   549 
567   G4VViewer* viewer = fpVisManager -> GetCurre    550   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
568   if (!viewer) {                                  551   if (!viewer) {
569     if (verbosity >= G4VisManager::errors) {      552     if (verbosity >= G4VisManager::errors) {
570       G4warn <<                                << 553       G4cerr <<
571       "ERROR: No current viewer - \"/vis/viewe    554       "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
572        << G4endl;                                 555        << G4endl;
573     }                                             556     }
574     return;                                       557     return;
575   }                                               558   }
576                                                   559 
577   G4ViewParameters vp = viewer->GetViewParamet    560   G4ViewParameters vp = viewer->GetViewParameters();
578   vp.ClearVisAttributesModifiers();               561   vp.ClearVisAttributesModifiers();
579   if (verbosity >= G4VisManager::confirmations    562   if (verbosity >= G4VisManager::confirmations) {
580     G4cout << "Vis attributes modifiers for vi    563     G4cout << "Vis attributes modifiers for viewer \"" << viewer->GetName()
581      << "\" now cleared." << G4endl;              564      << "\" now cleared." << G4endl;
582   }                                               565   }
583                                                   566 
584   SetViewParameters(viewer, vp);                  567   SetViewParameters(viewer, vp);
585 }                                                 568 }
586                                                   569 
587 ////////////// /vis/viewer/clone /////////////    570 ////////////// /vis/viewer/clone ///////////////////////////////////////
588                                                   571 
589 G4VisCommandViewerClone::G4VisCommandViewerClo    572 G4VisCommandViewerClone::G4VisCommandViewerClone () {
590   G4bool omitable;                                573   G4bool omitable;
591   fpCommand = new G4UIcommand ("/vis/viewer/cl    574   fpCommand = new G4UIcommand ("/vis/viewer/clone", this);
592   fpCommand -> SetGuidance ("Clones viewer.");    575   fpCommand -> SetGuidance ("Clones viewer.");
593   fpCommand -> SetGuidance                        576   fpCommand -> SetGuidance 
594     ("By default, clones current viewer.  Clon    577     ("By default, clones current viewer.  Clone becomes current."
595      "\nClone name, if not provided, is derive    578      "\nClone name, if not provided, is derived from the original name."
596      "\n\"/vis/viewer/list\" to see  possible     579      "\n\"/vis/viewer/list\" to see  possible viewer names.");
597   G4UIparameter* parameter;                       580   G4UIparameter* parameter;
598   parameter = new G4UIparameter ("original-vie    581   parameter = new G4UIparameter ("original-viewer-name", 's', omitable = true);
599   parameter -> SetCurrentAsDefault (true);        582   parameter -> SetCurrentAsDefault (true);
600   fpCommand -> SetParameter (parameter);          583   fpCommand -> SetParameter (parameter);
601   parameter = new G4UIparameter ("clone-name",    584   parameter = new G4UIparameter ("clone-name", 's', omitable = true);
602   parameter -> SetDefaultValue ("none");          585   parameter -> SetDefaultValue ("none");
603   fpCommand -> SetParameter (parameter);          586   fpCommand -> SetParameter (parameter);
604 }                                                 587 }
605                                                   588 
606 G4VisCommandViewerClone::~G4VisCommandViewerCl    589 G4VisCommandViewerClone::~G4VisCommandViewerClone () {
607   delete fpCommand;                               590   delete fpCommand;
608 }                                                 591 }
609                                                   592 
610 G4String G4VisCommandViewerClone::GetCurrentVa    593 G4String G4VisCommandViewerClone::GetCurrentValue (G4UIcommand*) {
611   G4VViewer* viewer = fpVisManager -> GetCurre    594   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
612   G4String originalName = viewer ? viewer -> G    595   G4String originalName = viewer ? viewer -> GetName () : G4String("none");
613   return "\"" + originalName + "\"";              596   return "\"" + originalName + "\"";
614 }                                                 597 }
615                                                   598 
616 void G4VisCommandViewerClone::SetNewValue (G4U    599 void G4VisCommandViewerClone::SetNewValue (G4UIcommand*, G4String newValue) {
617                                                   600 
618   G4VisManager::Verbosity verbosity = fpVisMan    601   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
619                                                   602 
620   G4String originalName, cloneName;               603   G4String originalName, cloneName;
621   std::istringstream is (newValue);               604   std::istringstream is (newValue);
622                                                   605 
623   // Need to handle the possibility that the n    606   // Need to handle the possibility that the names contain embedded
624   // blanks within quotation marks...             607   // blanks within quotation marks...
625   char c = ' ';                                   608   char c = ' ';
626   while (is.get(c) && c == ' '){}                 609   while (is.get(c) && c == ' '){}
627   if (c == '"') {                                 610   if (c == '"') {
628     while (is.get(c) && c != '"') {originalNam    611     while (is.get(c) && c != '"') {originalName += c;}
629   }                                               612   }
630   else {                                          613   else {
631     originalName += c;                            614     originalName += c;
632     while (is.get(c) && c != ' ') {originalNam    615     while (is.get(c) && c != ' ') {originalName += c;}
633   }                                               616   }
634   G4StrUtil::strip(originalName, ' ');         << 617   originalName = originalName.strip (G4String::both, ' ');
635   G4StrUtil::strip(originalName, '"');         << 618   originalName = originalName.strip (G4String::both, '"');
636                                                   619 
637   G4VViewer* originalViewer = fpVisManager ->     620   G4VViewer* originalViewer = fpVisManager -> GetViewer (originalName);
638   if (!originalViewer) {                          621   if (!originalViewer) {
639     if (verbosity >= G4VisManager::errors) {      622     if (verbosity >= G4VisManager::errors) {
640       G4warn << "ERROR: Viewer \"" << original << 623       G4cerr << "ERROR: Viewer \"" << originalName
641        << "\" not found - \"/vis/viewer/list\"    624        << "\" not found - \"/vis/viewer/list\" to see possibilities."
642        << G4endl;                                 625        << G4endl;
643     }                                             626     }
644     return;                                       627     return;
645   }                                               628   }
646   originalName = originalViewer->GetName();  /    629   originalName = originalViewer->GetName();  // Ensures long name.
647                                                   630 
648   while (is.get(c) && c == ' '){}                 631   while (is.get(c) && c == ' '){}
649   if (c == '"') {                                 632   if (c == '"') {
650     while (is.get(c) && c != '"') {cloneName +    633     while (is.get(c) && c != '"') {cloneName += c;}
651   }                                               634   }
652   else {                                          635   else {
653     cloneName += c;                               636     cloneName += c;
654     while (is.get(c) && c != ' ') {cloneName +    637     while (is.get(c) && c != ' ') {cloneName += c;}
655   }                                               638   }
656   G4StrUtil::strip(cloneName, ' ');            << 639   cloneName = cloneName.strip (G4String::both, ' ');
657   G4StrUtil::strip(cloneName, '"');            << 640   cloneName = cloneName.strip (G4String::both, '"');
658                                                   641 
659   G4bool errorWhileNaming = false;                642   G4bool errorWhileNaming = false;
660   if (cloneName == "none") {                      643   if (cloneName == "none") {
661     G4int subID = 0;                              644     G4int subID = 0;
662     do {                                          645     do {
663       cloneName = originalName;                   646       cloneName = originalName;
664       std::ostringstream oss;                     647       std::ostringstream oss;
665       oss << '-' << subID++;                      648       oss << '-' << subID++;
666       G4String::size_type lastDashPosition, ne    649       G4String::size_type lastDashPosition, nextSpacePosition;
667       if ((lastDashPosition = cloneName.rfind(    650       if ((lastDashPosition = cloneName.rfind('-')) !=  G4String::npos &&
668     (nextSpacePosition = cloneName.find(" ", l    651     (nextSpacePosition = cloneName.find(" ", lastDashPosition)) !=
669     G4String::npos) {                             652     G4String::npos) {
670   cloneName.insert(nextSpacePosition, oss.str(    653   cloneName.insert(nextSpacePosition, oss.str());
671       } else {                                    654       } else {
672   G4String::size_type spacePosition = cloneNam    655   G4String::size_type spacePosition = cloneName.find(' ');
673   if (spacePosition != G4String::npos)            656   if (spacePosition != G4String::npos)
674     cloneName.insert(spacePosition, oss.str())    657     cloneName.insert(spacePosition, oss.str());
675   else                                            658   else
676     errorWhileNaming = true;                      659     errorWhileNaming = true;
677       }                                           660       }
678     } while (!errorWhileNaming && fpVisManager    661     } while (!errorWhileNaming && fpVisManager -> GetViewer (cloneName));
679   }                                               662   }
680                                                   663 
681   if (errorWhileNaming) {                         664   if (errorWhileNaming) {
682     if (verbosity >= G4VisManager::errors) {      665     if (verbosity >= G4VisManager::errors) {
683       G4warn << "ERROR: While naming clone vie << 666       G4cerr << "ERROR: While naming clone viewer \"" << cloneName
684        << "\"."                                   667        << "\"."
685        << G4endl;                                 668        << G4endl;
686     }                                             669     }
687     return;                                       670     return;
688   }                                               671   }
689                                                   672 
690   if (fpVisManager -> GetViewer (cloneName)) {    673   if (fpVisManager -> GetViewer (cloneName)) {
691     if (verbosity >= G4VisManager::errors) {      674     if (verbosity >= G4VisManager::errors) {
692       G4warn << "ERROR: Putative clone viewer  << 675       G4cerr << "ERROR: Putative clone viewer \"" << cloneName
693        << "\" already exists."                    676        << "\" already exists."
694        << G4endl;                                 677        << G4endl;
695     }                                             678     }
696     return;                                       679     return;
697   }                                               680   }
698                                                   681 
699   G4String windowSizeHint =                       682   G4String windowSizeHint =
700     originalViewer->GetViewParameters().GetXGe    683     originalViewer->GetViewParameters().GetXGeometryString();
701                                                   684 
702   G4UImanager* UImanager = G4UImanager::GetUIp    685   G4UImanager* UImanager = G4UImanager::GetUIpointer();
                                                   >> 686   G4int keepVerbose = UImanager->GetVerboseLevel();
                                                   >> 687   G4int newVerbose(0);
                                                   >> 688   if (keepVerbose >= 2 ||
                                                   >> 689       fpVisManager->GetVerbosity() >= G4VisManager::confirmations)
                                                   >> 690     newVerbose = 2;
                                                   >> 691   UImanager->SetVerboseLevel(newVerbose);
703   UImanager->ApplyCommand(G4String("/vis/viewe    692   UImanager->ApplyCommand(G4String("/vis/viewer/select " + originalName));
704   UImanager->ApplyCommand                         693   UImanager->ApplyCommand
705     (G4String("/vis/viewer/create ! \"" + clon    694     (G4String("/vis/viewer/create ! \"" + cloneName + "\" " + windowSizeHint));
706   UImanager->ApplyCommand(G4String("/vis/viewe    695   UImanager->ApplyCommand(G4String("/vis/viewer/set/all " + originalName));
                                                   >> 696   UImanager->SetVerboseLevel(keepVerbose);
707                                                   697 
708   if (verbosity >= G4VisManager::confirmations    698   if (verbosity >= G4VisManager::confirmations) {
709     G4cout << "Viewer \"" << originalName << "    699     G4cout << "Viewer \"" << originalName << "\" cloned." << G4endl;
710     G4cout << "Clone \"" << cloneName << "\" n    700     G4cout << "Clone \"" << cloneName << "\" now current." << G4endl;
711   }                                               701   }
712 }                                                 702 }
713                                                   703 
714 ////////////// /vis/viewer/colourByDensity ///    704 ////////////// /vis/viewer/colourByDensity ///////////////////////////////////////
715                                                   705 
716 G4VisCommandViewerColourByDensity::G4VisComman    706 G4VisCommandViewerColourByDensity::G4VisCommandViewerColourByDensity () {
717   G4bool omitable;                                707   G4bool omitable;
718   fpCommand = new G4UIcommand ("/vis/viewer/co    708   fpCommand = new G4UIcommand ("/vis/viewer/colourByDensity", this);
719   fpCommand -> SetGuidance                        709   fpCommand -> SetGuidance
720   ("If a volume has no vis attributes, colour     710   ("If a volume has no vis attributes, colour it by density.");
721   fpCommand -> SetGuidance                        711   fpCommand -> SetGuidance
722   ("Provide algorithm number, e.g., \"1\" (or     712   ("Provide algorithm number, e.g., \"1\" (or \"0\" to switch off)."
723    "\nThen a unit of density, e.g., \"g/cm3\".    713    "\nThen a unit of density, e.g., \"g/cm3\"."
724    "\nThen parameters for the algorithm assume    714    "\nThen parameters for the algorithm assumed to be densities in that unit.");
725   fpCommand -> SetGuidance                        715   fpCommand -> SetGuidance
726   ("Algorithm 1: Simple algorithm takes 3 para    716   ("Algorithm 1: Simple algorithm takes 3 parameters: d0, d1 and d2."
727    "\n  Volumes with density < d0 are invisibl    717    "\n  Volumes with density < d0 are invisible."
728    "\n  Volumes with d0 <= density < d1 have c    718    "\n  Volumes with d0 <= density < d1 have colour on range red->green."
729    "\n  Volumes with d1 <= density < d2 have c    719    "\n  Volumes with d1 <= density < d2 have colour on range green->blue."
730    "\n  Volumes with density > d2 are blue.");    720    "\n  Volumes with density > d2 are blue.");
731   G4UIparameter* parameter;                       721   G4UIparameter* parameter;
732   parameter  =  new G4UIparameter("n",'i',omit    722   parameter  =  new G4UIparameter("n",'i',omitable = true);
733   parameter  -> SetGuidance      ("Algorithm n    723   parameter  -> SetGuidance      ("Algorithm number (or \"0\" to switch off).");
734   parameter  -> SetDefaultValue  (1);             724   parameter  -> SetDefaultValue  (1);
735   fpCommand->SetParameter(parameter);             725   fpCommand->SetParameter(parameter);
736   parameter  =  new G4UIparameter("unit",'s',o    726   parameter  =  new G4UIparameter("unit",'s',omitable = true);
737   parameter  -> SetGuidance      ("Unit of fol    727   parameter  -> SetGuidance      ("Unit of following densities, e.g., \"g/cm3\".");
738   parameter  -> SetDefaultValue  ("g/cm3");       728   parameter  -> SetDefaultValue  ("g/cm3");
739   fpCommand->SetParameter(parameter);             729   fpCommand->SetParameter(parameter);
740   parameter  =  new G4UIparameter("d0",'d',omi    730   parameter  =  new G4UIparameter("d0",'d',omitable = true);
741   parameter  -> SetGuidance      ("Density par    731   parameter  -> SetGuidance      ("Density parameter 0");
742   parameter  -> SetDefaultValue  (0.5);           732   parameter  -> SetDefaultValue  (0.5);
743   fpCommand->SetParameter(parameter);             733   fpCommand->SetParameter(parameter);
744   parameter  =  new G4UIparameter("d1",'d',omi    734   parameter  =  new G4UIparameter("d1",'d',omitable = true);
745   parameter  -> SetGuidance      ("Density par    735   parameter  -> SetGuidance      ("Density parameter 1");
746   parameter  -> SetDefaultValue  (3.0);           736   parameter  -> SetDefaultValue  (3.0);
747   fpCommand->SetParameter(parameter);             737   fpCommand->SetParameter(parameter);
748   parameter  =  new G4UIparameter("d2",'d',omi    738   parameter  =  new G4UIparameter("d2",'d',omitable = true);
749   parameter  -> SetGuidance      ("Density par    739   parameter  -> SetGuidance      ("Density parameter 2.");
750   parameter  -> SetDefaultValue  (10.0);          740   parameter  -> SetDefaultValue  (10.0);
751   fpCommand->SetParameter(parameter);             741   fpCommand->SetParameter(parameter);
752 }                                                 742 }
753                                                   743 
754 G4VisCommandViewerColourByDensity::~G4VisComma    744 G4VisCommandViewerColourByDensity::~G4VisCommandViewerColourByDensity () {
755   delete fpCommand;                               745   delete fpCommand;
756 }                                                 746 }
757                                                   747 
758 G4String G4VisCommandViewerColourByDensity::Ge    748 G4String G4VisCommandViewerColourByDensity::GetCurrentValue (G4UIcommand*) {
759   return "";                                      749   return "";
760 }                                                 750 }
761                                                   751 
762 void G4VisCommandViewerColourByDensity::SetNew    752 void G4VisCommandViewerColourByDensity::SetNewValue (G4UIcommand*, G4String newValue) {
763                                                   753 
764   G4VisManager::Verbosity verbosity = fpVisMan    754   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
765                                                   755 
766   G4VViewer* viewer = fpVisManager -> GetCurre    756   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
767   if (!viewer) {                                  757   if (!viewer) {
768     if (verbosity >= G4VisManager::errors) {      758     if (verbosity >= G4VisManager::errors) {
769       G4warn <<                                << 759       G4cerr <<
770       "ERROR: No current viewer - \"/vis/viewe    760       "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
771       << G4endl;                                  761       << G4endl;
772     }                                             762     }
773     return;                                       763     return;
774   }                                               764   }
775   G4ViewParameters vp = viewer->GetViewParamet    765   G4ViewParameters vp = viewer->GetViewParameters();
776                                                   766 
777   G4int algorithmNumber;                          767   G4int algorithmNumber;
778   G4double d0, d1, d2;                            768   G4double d0, d1, d2;
779   G4String unit;                                  769   G4String unit;
780   std::istringstream is (newValue);               770   std::istringstream is (newValue);
781   is >> algorithmNumber >> unit >> d0 >> d1 >>    771   is >> algorithmNumber >> unit >> d0 >> d1 >> d2;
782                                                   772 
783   if (algorithmNumber < 0 || algorithmNumber >    773   if (algorithmNumber < 0 || algorithmNumber > 1) {
784     if (verbosity >= G4VisManager::errors) {      774     if (verbosity >= G4VisManager::errors) {
785       G4warn <<                                << 775       G4cerr <<
786       "ERROR: Unrecognised algorithm number: "    776       "ERROR: Unrecognised algorithm number: " << algorithmNumber
787       << G4endl;                                  777       << G4endl;
788     }                                             778     }
789     return;                                       779     return;
790   }                                               780   }
791                                                   781 
792   std::vector<G4double> parameters;               782   std::vector<G4double> parameters;
793   if (algorithmNumber > 0) {                      783   if (algorithmNumber > 0) {
794     const G4String where = "G4VisCommandViewer    784     const G4String where = "G4VisCommandViewerColourByDensity::SetNewValue";
795     G4double valueOfUnit;                         785     G4double valueOfUnit;
796     // "Volumic Mass" is Michel's phrase for "    786     // "Volumic Mass" is Michel's phrase for "Density"
797     if (ProvideValueOfUnit(where,unit,"Volumic    787     if (ProvideValueOfUnit(where,unit,"Volumic Mass",valueOfUnit)) {
798       // Successful outcome of unit search        788       // Successful outcome of unit search
799       d0 *= valueOfUnit; d1 *= valueOfUnit; d2    789       d0 *= valueOfUnit; d1 *= valueOfUnit; d2 *= valueOfUnit;
800     } else {                                      790     } else {
801       if (verbosity >= G4VisManager::errors) {    791       if (verbosity >= G4VisManager::errors) {
802         G4warn <<                              << 792         G4cerr <<
803         "ERROR: Unrecognised or inappropriate     793         "ERROR: Unrecognised or inappropriate unit: " << unit
804         << G4endl;                                794         << G4endl;
805       }                                           795       }
806       return;                                     796       return;
807     }                                             797     }
808     parameters.push_back(d0);                     798     parameters.push_back(d0);
809     parameters.push_back(d1);                     799     parameters.push_back(d1);
810     parameters.push_back(d2);                     800     parameters.push_back(d2);
811   }                                               801   }
812   vp.SetCBDAlgorithmNumber(algorithmNumber);      802   vp.SetCBDAlgorithmNumber(algorithmNumber);
813   vp.SetCBDParameters(parameters);                803   vp.SetCBDParameters(parameters);
814                                                   804 
815   if (verbosity >= G4VisManager::confirmations    805   if (verbosity >= G4VisManager::confirmations) {
816     if (vp.GetCBDAlgorithmNumber() == 0) {        806     if (vp.GetCBDAlgorithmNumber() == 0) {
817       G4cout << "Colour by density deactivated    807       G4cout << "Colour by density deactivated" << G4endl;
818     } else {                                      808     } else {
819       G4cout << "Colour by density algorithm "    809       G4cout << "Colour by density algorithm " << vp.GetCBDAlgorithmNumber()
820       << " selected for viewer \"" << viewer->    810       << " selected for viewer \"" << viewer->GetName()
821       << "\n  Parameters:";                       811       << "\n  Parameters:";
822       for (auto p: vp.GetCBDParameters()) {       812       for (auto p: vp.GetCBDParameters()) {
823         G4cout << ' ' << G4BestUnit(p,"Volumic    813         G4cout << ' ' << G4BestUnit(p,"Volumic Mass");
824       }                                           814       }
825       G4cout << G4endl;                           815       G4cout << G4endl;
826     }                                             816     }
827   }                                               817   }
828                                                   818 
829   SetViewParameters(viewer, vp);                  819   SetViewParameters(viewer, vp);
830 }                                                 820 }
831                                                   821 
832 ////////////// /vis/viewer/copyViewFrom //////    822 ////////////// /vis/viewer/copyViewFrom //////////////////////////
833                                                   823 
834 G4VisCommandViewerCopyViewFrom::G4VisCommandVi    824 G4VisCommandViewerCopyViewFrom::G4VisCommandViewerCopyViewFrom () {
835   G4bool omitable;                                825   G4bool omitable;
836   fpCommand = new G4UIcmdWithAString ("/vis/vi    826   fpCommand = new G4UIcmdWithAString ("/vis/viewer/copyViewFrom", this);
837   fpCommand -> SetGuidance                        827   fpCommand -> SetGuidance
838   ("Copy the camera-specific parameters from t    828   ("Copy the camera-specific parameters from the specified viewer.");
839   fpCommand -> SetGuidance                        829   fpCommand -> SetGuidance
840   ("Note: To copy ALL view parameters, includi    830   ("Note: To copy ALL view parameters, including scene modifications,"
841    "\nuse \"/vis/viewer/set/all\"");              831    "\nuse \"/vis/viewer/set/all\"");
842   fpCommand -> SetParameterName ("from-viewer-    832   fpCommand -> SetParameterName ("from-viewer-name", omitable = false);
843 }                                                 833 }
844                                                   834 
845 G4VisCommandViewerCopyViewFrom::~G4VisCommandV    835 G4VisCommandViewerCopyViewFrom::~G4VisCommandViewerCopyViewFrom () {
846   delete fpCommand;                               836   delete fpCommand;
847 }                                                 837 }
848                                                   838 
849 G4String G4VisCommandViewerCopyViewFrom::GetCu    839 G4String G4VisCommandViewerCopyViewFrom::GetCurrentValue (G4UIcommand*) {
850   return "";                                      840   return "";
851 }                                                 841 }
852                                                   842 
853 void G4VisCommandViewerCopyViewFrom::SetNewVal    843 void G4VisCommandViewerCopyViewFrom::SetNewValue (G4UIcommand*, G4String newValue) {
854                                                   844 
855   G4VisManager::Verbosity verbosity = fpVisMan    845   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
856                                                   846 
857   G4VViewer* currentViewer = fpVisManager->Get    847   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
858   if (!currentViewer) {                           848   if (!currentViewer) {
859     if (verbosity >= G4VisManager::errors) {      849     if (verbosity >= G4VisManager::errors) {
860       G4warn <<                                << 850       G4cerr <<
861   "ERROR: G4VisCommandsViewerCopyViewFrom::Set    851   "ERROR: G4VisCommandsViewerCopyViewFrom::SetNewValue: no current viewer."
862              << G4endl;                           852              << G4endl;
863     }                                             853     }
864     return;                                       854     return;
865   }                                               855   }
866                                                   856 
867   const G4String& fromViewerName = newValue;      857   const G4String& fromViewerName = newValue;
868   G4VViewer* fromViewer = fpVisManager -> GetV    858   G4VViewer* fromViewer = fpVisManager -> GetViewer (fromViewerName);
869   if (!fromViewer) {                              859   if (!fromViewer) {
870     if (verbosity >= G4VisManager::errors) {      860     if (verbosity >= G4VisManager::errors) {
871       G4warn << "ERROR: Viewer \"" << fromView << 861       G4cerr << "ERROR: Viewer \"" << fromViewerName
872        << "\" not found - \"/vis/viewer/list\"    862        << "\" not found - \"/vis/viewer/list\" to see possibilities."
873        << G4endl;                                 863        << G4endl;
874     }                                             864     }
875     return;                                       865     return;
876   }                                               866   }
877                                                   867 
878   if (fromViewer == currentViewer) {              868   if (fromViewer == currentViewer) {
879     if (verbosity >= G4VisManager::warnings) {    869     if (verbosity >= G4VisManager::warnings) {
880       G4warn <<                                << 870       G4cout <<
881         "WARNING: G4VisCommandsViewerSet::SetN    871         "WARNING: G4VisCommandsViewerSet::SetNewValue:"
882         "\n  from-viewer and current viewer ar    872         "\n  from-viewer and current viewer are identical."
883              << G4endl;                           873              << G4endl;
884     }                                             874     }
885     return;                                       875     return;
886   }                                               876   }
887                                                   877 
888   // Copy camera-specific view parameters         878   // Copy camera-specific view parameters
889   G4ViewParameters vp = currentViewer->GetView    879   G4ViewParameters vp = currentViewer->GetViewParameters();
890   CopyCameraParameters(vp, fromViewer->GetView << 880   const G4ViewParameters& fromVP = fromViewer->GetViewParameters();
                                                   >> 881   vp.SetViewpointDirection  (fromVP.GetViewpointDirection());
                                                   >> 882   vp.SetLightpointDirection (fromVP.GetLightpointDirection());
                                                   >> 883   vp.SetLightsMoveWithCamera(fromVP.GetLightsMoveWithCamera());
                                                   >> 884   vp.SetUpVector            (fromVP.GetUpVector());
                                                   >> 885   vp.SetFieldHalfAngle      (fromVP.GetFieldHalfAngle());
                                                   >> 886   vp.SetZoomFactor          (fromVP.GetZoomFactor());
                                                   >> 887   vp.SetScaleFactor         (fromVP.GetScaleFactor());
                                                   >> 888   vp.SetCurrentTargetPoint  (fromVP.GetCurrentTargetPoint());
                                                   >> 889   vp.SetDolly               (fromVP.GetDolly());
891   SetViewParameters(currentViewer, vp);           890   SetViewParameters(currentViewer, vp);
892                                                   891   
893   if (verbosity >= G4VisManager::confirmations    892   if (verbosity >= G4VisManager::confirmations) {
894     G4cout << "Camera parameters of viewer \""    893     G4cout << "Camera parameters of viewer \"" << currentViewer->GetName()
895      << "\"\n  set to those of viewer \"" << f    894      << "\"\n  set to those of viewer \"" << fromViewer->GetName()
896      << "\"."                                     895      << "\"."
897      << G4endl;                                   896      << G4endl;
898   }                                               897   }
899 }                                                 898 }
900                                                   899 
901 ////////////// /vis/viewer/create ////////////    900 ////////////// /vis/viewer/create ///////////////////////////////////////
902                                                   901 
903 G4VisCommandViewerCreate::G4VisCommandViewerCr    902 G4VisCommandViewerCreate::G4VisCommandViewerCreate (): fId (0) {
904   G4bool omitable;                                903   G4bool omitable;
905   fpCommand = new G4UIcommand ("/vis/viewer/cr    904   fpCommand = new G4UIcommand ("/vis/viewer/create", this);
906   fpCommand -> SetGuidance                        905   fpCommand -> SetGuidance
907     ("Creates a viewer. If the scene handler n << 906     ("Creates a viewer for the specified scene handler.");
908      "\nviewer of that scene handler is create << 
909      "\nof the current scene handler is create << 
910   fpCommand -> SetGuidance                     << 
911     ("If the viewer name is not specified a na << 
912      "\nof the scene handler and a serial numb << 
913   fpCommand -> SetGuidance("The scene handler  << 
914   fpCommand -> SetGuidance                     << 
915     ("(Note: the system adds the graphics syst << 
916      "\nfor identification, but for selecting, << 
917      "\nup to the first blank are used. For ex << 
918      "\n\"viewer-0 (G4OpenGLStoredQt)\", it ma << 
919      "\nfor example in \"/vis/viewer/select vi << 
920   fpCommand -> SetGuidance                     << 
921   ("Window size and placement hints, e.g. 600x << 
922   fpCommand -> SetGuidance                        907   fpCommand -> SetGuidance
923   ("- single number, e.g., \"600\": square win << 908     ("Default scene handler is the current scene handler.  Invents a name"
924   fpCommand -> SetGuidance                     << 909      "\nif not supplied.  (Note: the system adds information to the name"
925   ("- two numbers, e.g., \"800x600\": rectangl << 910      "\nfor identification - only the characters up to the first blank are"
926   fpCommand -> SetGuidance                     << 911      "\nused for removing, selecting, etc.)  This scene handler and viewer"
927   ("- two numbers plus placement hint, e.g., \ << 912      "\nbecome current.");
928    "\n  600x600 100 pixels left and 100 pixels << 
929   fpCommand -> SetGuidance                     << 
930   ("- If not specified, the default is \"600\" << 
931    "\n  at the window manager's discretion...o << 
932   fpCommand -> SetGuidance                     << 
933   ("- This is an X-Windows-type geometry strin << 
934    "\n  https://en.wikibooks.org/wiki/Guide_to << 
935    "\n  \"Specifying window geometry\".");     << 
936   G4UIparameter* parameter;                       913   G4UIparameter* parameter;
937   parameter = new G4UIparameter ("scene-handle    914   parameter = new G4UIparameter ("scene-handler", 's', omitable = true);
938   parameter -> SetCurrentAsDefault (true);        915   parameter -> SetCurrentAsDefault (true);
939   fpCommand -> SetParameter (parameter);          916   fpCommand -> SetParameter (parameter);
940   parameter = new G4UIparameter ("viewer-name"    917   parameter = new G4UIparameter ("viewer-name", 's', omitable = true);
941   parameter -> SetCurrentAsDefault (true);        918   parameter -> SetCurrentAsDefault (true);
942   fpCommand -> SetParameter (parameter);          919   fpCommand -> SetParameter (parameter);
943   parameter = new G4UIparameter ("window-size-    920   parameter = new G4UIparameter ("window-size-hint", 's', omitable = true);
944   parameter -> SetCurrentAsDefault (true);     << 921   parameter->SetGuidance
                                                   >> 922     ("integer (pixels) for square window placed by window manager or"
                                                   >> 923      " X-Windows-type geometry string, e.g. 600x600-100+100");
                                                   >> 924   parameter->SetDefaultValue("600");
945   fpCommand -> SetParameter (parameter);          925   fpCommand -> SetParameter (parameter);
946 }                                                 926 }
947                                                   927 
948 G4VisCommandViewerCreate::~G4VisCommandViewerC    928 G4VisCommandViewerCreate::~G4VisCommandViewerCreate () {
949   delete fpCommand;                               929   delete fpCommand;
950 }                                                 930 }
951                                                   931 
952 G4String G4VisCommandViewerCreate::NextName ()    932 G4String G4VisCommandViewerCreate::NextName () {
953   std::ostringstream oss;                         933   std::ostringstream oss;
954   G4VSceneHandler* sceneHandler = fpVisManager    934   G4VSceneHandler* sceneHandler = fpVisManager -> GetCurrentSceneHandler ();
955   oss << "viewer-" << fId << " (";                935   oss << "viewer-" << fId << " (";
956   if (sceneHandler) {                             936   if (sceneHandler) {
957     oss << sceneHandler -> GetGraphicsSystem (    937     oss << sceneHandler -> GetGraphicsSystem () -> GetName ();
958   }                                               938   }
959   else {                                          939   else {
960     oss << "no_scene_handlers";                   940     oss << "no_scene_handlers";
961   }                                               941   }
962   oss << ")";                                     942   oss << ")";
963   return oss.str();                               943   return oss.str();
964 }                                                 944 }
965                                                   945 
966 G4String G4VisCommandViewerCreate::GetCurrentV << 946 G4String G4VisCommandViewerCreate::GetCurrentValue (G4UIcommand*) {
967 {                                              << 947   G4String currentValue;
968   G4String sceneHandlerName;                   << 948   G4VSceneHandler* currentSceneHandler =
969   auto currentSceneHandler = fpVisManager->Get << 949     fpVisManager -> GetCurrentSceneHandler ();
970   if (currentSceneHandler) {  // Get name of l << 950   if (currentSceneHandler) {
971     sceneHandlerName = currentSceneHandler->Ge << 951     currentValue = currentSceneHandler -> GetName ();
972   }                                               952   }
973   else {  // No scene handler - ensure a warni << 953   else {
974     sceneHandlerName = "none";                 << 954     currentValue = "none";
975   }                                               955   }
                                                   >> 956   currentValue += ' ';
                                                   >> 957   currentValue += '"';
                                                   >> 958   currentValue += NextName ();
                                                   >> 959   currentValue += '"';
976                                                   960 
977   // Default name                              << 961   currentValue += " 600";  // Default number of pixels for window size hint.
978   const auto& viewerName = NextName();         << 
979                                                   962 
980   // Size hint                                 << 963   return currentValue;
981   G4String windowSizeHint;                     << 
982   auto currentViewer = fpVisManager->GetCurren << 
983   if (currentViewer) {  // Get hint from last  << 
984     windowSizeHint = currentViewer->GetViewPar << 
985   }                                            << 
986   else {  // No viewer - must be first time    << 
987     windowSizeHint = fpVisManager->GetDefaultX << 
988   }                                            << 
989                                                << 
990   // Add quotes around viewer name             << 
991   return sceneHandlerName + " \"" + viewerName << 
992 }                                                 964 }
993                                                   965 
994 void G4VisCommandViewerCreate::SetNewValue (G4 << 966 void G4VisCommandViewerCreate::SetNewValue (G4UIcommand*, G4String newValue) {
995                                                   967 
996   G4VisManager::Verbosity verbosity = fpVisMan    968   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
997                                                   969 
998   G4String sceneHandlerName, newName;             970   G4String sceneHandlerName, newName;
999   G4String windowSizeHintString;                  971   G4String windowSizeHintString;
1000   std::istringstream is (newValue);              972   std::istringstream is (newValue);
1001   is >> sceneHandlerName;                        973   is >> sceneHandlerName;
1002                                                  974 
1003   // Now need to handle the possibility that     975   // Now need to handle the possibility that the second string
1004   // contains embedded blanks within quotatio    976   // contains embedded blanks within quotation marks...
1005   char c = ' ';                                  977   char c = ' ';
1006   while (is.get(c) && c == ' '){}                978   while (is.get(c) && c == ' '){}
1007   if (c == '"') {                                979   if (c == '"') {
1008     while (is.get(c) && c != '"') {newName +=    980     while (is.get(c) && c != '"') {newName += c;}
1009   }                                              981   }
1010   else {                                         982   else {
1011     newName += c;                                983     newName += c;
1012     while (is.get(c) && c != ' ') {newName +=    984     while (is.get(c) && c != ' ') {newName += c;}
1013   }                                              985   }
1014   G4StrUtil::strip(newName, ' ');             << 986   newName = newName.strip (G4String::both, ' ');
1015   G4StrUtil::strip(newName, '"');             << 987   newName = newName.strip (G4String::both, '"');
1016                                                  988 
1017   // Now get window size hint...                 989   // Now get window size hint...
1018   is >> windowSizeHintString;                    990   is >> windowSizeHintString;
1019                                                  991 
1020   const G4SceneHandlerList& sceneHandlerList     992   const G4SceneHandlerList& sceneHandlerList =
1021     fpVisManager -> GetAvailableSceneHandlers    993     fpVisManager -> GetAvailableSceneHandlers ();
1022   std::size_t nHandlers = sceneHandlerList.si << 994   G4int nHandlers = sceneHandlerList.size ();
1023   if (nHandlers == 0) {                       << 995   if (nHandlers <= 0) {
1024     G4ExceptionDescription ed;                << 996     if (verbosity >= G4VisManager::errors) {
1025     ed <<                                     << 997       G4cerr <<
1026     "ERROR: G4VisCommandViewerCreate::SetNewV << 998   "ERROR: G4VisCommandViewerCreate::SetNewValue: no scene handlers."
1027     "\n  Create a scene handler with \"/vis/s << 999   "\n  Create a scene handler with \"/vis/sceneHandler/create\""
1028     command->CommandFailed(ed);               << 1000        << G4endl;
                                                   >> 1001     }
1029     return;                                      1002     return;
1030   }                                              1003   }
1031                                                  1004 
1032   std::size_t iHandler;                       << 1005   G4int iHandler;
1033   for (iHandler = 0; iHandler < nHandlers; ++ << 1006   for (iHandler = 0; iHandler < nHandlers; iHandler++) {
1034     if (sceneHandlerList [iHandler] -> GetNam    1007     if (sceneHandlerList [iHandler] -> GetName () == sceneHandlerName) break;
1035   }                                              1008   }
1036                                                  1009 
1037   if (iHandler >= nHandlers) {                << 1010   if (iHandler < 0 || iHandler >= nHandlers) {
1038     // Invalid command line argument or none.    1011     // Invalid command line argument or none.
1039     // This shouldn't happen!!!!!!               1012     // This shouldn't happen!!!!!!
1040     G4ExceptionDescription ed;                << 1013     if (verbosity >= G4VisManager::errors) {
1041     ed <<                                     << 1014       G4cout << "G4VisCommandViewerCreate::SetNewValue:"
1042     "G4VisCommandViewerCreate::SetNewValue: i << 1015   " invalid scene handler specified."
1043     command->CommandFailed(ed);               << 1016       << G4endl;
                                                   >> 1017     }
1044     return;                                      1018     return;
1045   }                                              1019   }
1046                                                  1020 
1047   // Valid index.  Set current scene handler     1021   // Valid index.  Set current scene handler and graphics system in
1048   // preparation for creating viewer.            1022   // preparation for creating viewer.
1049   G4VSceneHandler* sceneHandler = sceneHandle    1023   G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
1050   if (sceneHandler != fpVisManager -> GetCurr    1024   if (sceneHandler != fpVisManager -> GetCurrentSceneHandler ()) {
1051     fpVisManager -> SetCurrentSceneHandler (s    1025     fpVisManager -> SetCurrentSceneHandler (sceneHandler);
1052   }                                              1026   }
1053                                                  1027 
1054   // Now deal with name of viewer.               1028   // Now deal with name of viewer.
1055   G4String nextName = NextName ();               1029   G4String nextName = NextName ();
1056   if (newName == "") {                           1030   if (newName == "") {
1057     newName = nextName;                          1031     newName = nextName;
1058   }                                              1032   }
1059   if (newName == nextName) fId++;                1033   if (newName == nextName) fId++;
1060   G4String newShortName = fpVisManager -> Vie    1034   G4String newShortName = fpVisManager -> ViewerShortName (newName);
1061                                                  1035 
1062   for (std::size_t ih = 0; ih < nHandlers; ++ << 1036   for (G4int ih = 0; ih < nHandlers; ih++) {
1063     G4VSceneHandler* sh = sceneHandlerList [i    1037     G4VSceneHandler* sh = sceneHandlerList [ih];
1064     const G4ViewerList& viewerList = sh -> Ge    1038     const G4ViewerList& viewerList = sh -> GetViewerList ();
1065     for (std::size_t iViewer = 0; iViewer < v << 1039     for (size_t iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1066       if (viewerList [iViewer] -> GetShortNam    1040       if (viewerList [iViewer] -> GetShortName () == newShortName ) {
1067   G4ExceptionDescription ed;                  << 1041   if (verbosity >= G4VisManager::errors) {
1068   ed <<                                       << 1042     G4cerr << "ERROR: Viewer \"" << newShortName << "\" already exists."
1069   "ERROR: Viewer \"" << newShortName << "\" a << 1043      << G4endl;
1070   command->CommandFailed(ed);                 << 1044   }
1071   return;                                        1045   return;
1072       }                                          1046       }
1073     }                                            1047     }
1074   }                                              1048   }
1075                                                  1049 
1076   if (fThereWasAViewer && windowSizeHintStrin << 1050   // WindowSizeHint and XGeometryString are picked up from the vis
1077     // The user did not specify a window size << 1051   // manager in the G4VViewer constructor. In G4VisManager, after Viewer
1078     windowSizeHintString = fExistingVP.GetXGe << 1052   // creation, we will store theses parameters in G4ViewParameters.
1079   }                                           << 
1080                                                  1053 
1081   fpVisManager -> CreateViewer (newName,windo    1054   fpVisManager -> CreateViewer (newName,windowSizeHintString);
1082                                                  1055 
1083   // Now we have a new viewer                 << 
1084   G4VViewer* newViewer = fpVisManager -> GetC    1056   G4VViewer* newViewer = fpVisManager -> GetCurrentViewer ();
1085                                               << 
1086   if (newViewer && newViewer -> GetName () ==    1057   if (newViewer && newViewer -> GetName () == newName) {
1087     if (fThereWasAViewer) {                   << 
1088       G4ViewParameters vp = newViewer->GetVie << 
1089       // Copy view parameters from existing v << 
1090       fExistingVP.SetAutoRefresh(vp.IsAutoRef << 
1091       fExistingVP.SetBackgroundColour(vp.GetB << 
1092       fExistingVP.SetGlobalMarkerScale(vp.Get << 
1093       // ...including window hint paramaters  << 
1094       fExistingVP.SetXGeometryString(vp.GetXG << 
1095       vp = fExistingVP;                       << 
1096       newViewer->SetViewParameters(vp);       << 
1097       newViewer->AccessSceneTree() = fExistin << 
1098     }                                         << 
1099     if (verbosity >= G4VisManager::confirmati    1058     if (verbosity >= G4VisManager::confirmations) {
1100       G4cout << "New viewer \"" << newName <<    1059       G4cout << "New viewer \"" << newName << "\" created." << G4endl;
1101     }                                            1060     }
1102     // Keep for next time...                  << 1061   }
1103     fThereWasAViewer = true;                  << 1062   else {
1104     auto viewer = fpVisManager->GetCurrentVie << 1063     if (verbosity >= G4VisManager::errors) {
1105     fExistingVP = viewer->GetViewParameters() << 1064       if (newViewer) {
1106     fExistingSceneTree = viewer->GetSceneTree << 1065   G4cerr << "ERROR: New viewer doesn\'t match!!!  Curious!!" << G4endl;
1107   } else {                                    << 1066       } else {
1108     G4ExceptionDescription ed;                << 1067   G4cout << "WARNING: No viewer created." << G4endl;
1109     if (newViewer) {                          << 1068       }
1110       ed << "ERROR: New viewer doesn\'t match << 
1111     } else {                                  << 
1112       ed << "WARNING: No viewer created.";    << 
1113     }                                            1069     }
1114     command->CommandFailed(ed);               << 
1115     return;                                   << 
1116   }                                              1070   }
1117   // Refresh if appropriate...                   1071   // Refresh if appropriate...
1118   if (newViewer) {                               1072   if (newViewer) {
1119     if (newViewer->GetViewParameters().IsAuto    1073     if (newViewer->GetViewParameters().IsAutoRefresh()) {
1120       G4UImanager::GetUIpointer()->ApplyComma    1074       G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/refresh");
1121     }                                            1075     }
1122     else {                                       1076     else {
1123       if (verbosity >= G4VisManager::warnings    1077       if (verbosity >= G4VisManager::warnings) {
1124   G4warn << "Issue /vis/viewer/refresh or flu << 1078   G4cout << "Issue /vis/viewer/refresh or flush to see effect."
1125          << G4endl;                              1079          << G4endl;
1126       }                                          1080       }
1127     }                                            1081     }
1128   }                                              1082   }
1129 }                                                1083 }
1130                                                  1084 
1131 ////////////// /vis/viewer/dolly and dollyTo     1085 ////////////// /vis/viewer/dolly and dollyTo ////////////////////////////
1132                                                  1086 
1133 G4VisCommandViewerDolly::G4VisCommandViewerDo    1087 G4VisCommandViewerDolly::G4VisCommandViewerDolly ():
1134   fDollyIncrement  (0.),                         1088   fDollyIncrement  (0.),
1135   fDollyTo (0.)                                  1089   fDollyTo (0.)
1136 {                                                1090 {
1137   G4bool omitable, currentAsDefault;             1091   G4bool omitable, currentAsDefault;
1138                                                  1092 
1139   fpCommandDolly = new G4UIcmdWithADoubleAndU    1093   fpCommandDolly = new G4UIcmdWithADoubleAndUnit
1140     ("/vis/viewer/dolly", this);                 1094     ("/vis/viewer/dolly", this);
1141   fpCommandDolly -> SetGuidance                  1095   fpCommandDolly -> SetGuidance
1142     ("Incremental dolly.");                      1096     ("Incremental dolly.");
1143   fpCommandDolly -> SetGuidance                  1097   fpCommandDolly -> SetGuidance
1144     ("Moves the camera incrementally towards     1098     ("Moves the camera incrementally towards target point.");
1145   fpCommandDolly -> SetParameterName("increme    1099   fpCommandDolly -> SetParameterName("increment",
1146              omitable=true,                      1100              omitable=true,
1147              currentAsDefault=true);             1101              currentAsDefault=true);
1148   fpCommandDolly -> SetDefaultUnit("m");         1102   fpCommandDolly -> SetDefaultUnit("m");
1149                                                  1103 
1150   fpCommandDollyTo = new G4UIcmdWithADoubleAn    1104   fpCommandDollyTo = new G4UIcmdWithADoubleAndUnit
1151     ("/vis/viewer/dollyTo", this);               1105     ("/vis/viewer/dollyTo", this);
1152   fpCommandDollyTo -> SetGuidance                1106   fpCommandDollyTo -> SetGuidance
1153     ("Dolly to specific coordinate.");           1107     ("Dolly to specific coordinate.");
1154   fpCommandDollyTo -> SetGuidance                1108   fpCommandDollyTo -> SetGuidance
1155  ("Places the camera towards target point rel    1109  ("Places the camera towards target point relative to standard camera point.");
1156   fpCommandDollyTo -> SetParameterName("dista    1110   fpCommandDollyTo -> SetParameterName("distance",
1157                omitable=true,                    1111                omitable=true,
1158                currentAsDefault=true);           1112                currentAsDefault=true);
1159   fpCommandDollyTo -> SetDefaultUnit("m");       1113   fpCommandDollyTo -> SetDefaultUnit("m");
1160 }                                                1114 }
1161                                                  1115 
1162 G4VisCommandViewerDolly::~G4VisCommandViewerD    1116 G4VisCommandViewerDolly::~G4VisCommandViewerDolly () {
1163   delete fpCommandDolly;                         1117   delete fpCommandDolly;
1164   delete fpCommandDollyTo;                       1118   delete fpCommandDollyTo;
1165 }                                                1119 }
1166                                                  1120 
1167 G4String G4VisCommandViewerDolly::GetCurrentV    1121 G4String G4VisCommandViewerDolly::GetCurrentValue (G4UIcommand* command) {
1168   G4String currentValue;                         1122   G4String currentValue;
1169   if (command == fpCommandDolly) {               1123   if (command == fpCommandDolly) {
1170     currentValue = fpCommandDolly->ConvertToS    1124     currentValue = fpCommandDolly->ConvertToString(fDollyIncrement, "m");
1171   }                                              1125   }
1172   else if (command == fpCommandDollyTo) {        1126   else if (command == fpCommandDollyTo) {
1173     currentValue = fpCommandDollyTo->ConvertT    1127     currentValue = fpCommandDollyTo->ConvertToString(fDollyTo, "m");
1174   }                                              1128   }
1175   return currentValue;                           1129   return currentValue;
1176 }                                                1130 }
1177                                                  1131 
1178 void G4VisCommandViewerDolly::SetNewValue (G4    1132 void G4VisCommandViewerDolly::SetNewValue (G4UIcommand* command,
1179              G4String newValue) {                1133              G4String newValue) {
1180                                                  1134 
1181                                                  1135 
1182   G4VisManager::Verbosity verbosity = fpVisMa    1136   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1183                                                  1137 
1184   G4VViewer* currentViewer = fpVisManager->Ge    1138   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1185   if (!currentViewer) {                          1139   if (!currentViewer) {
1186     if (verbosity >= G4VisManager::errors) {     1140     if (verbosity >= G4VisManager::errors) {
1187       G4warn <<                               << 1141       G4cerr <<
1188   "ERROR: G4VisCommandsViewerDolly::SetNewVal    1142   "ERROR: G4VisCommandsViewerDolly::SetNewValue: no current viewer."
1189        << G4endl;                                1143        << G4endl;
1190     }                                            1144     }
1191     return;                                      1145     return;
1192   }                                              1146   }
1193                                                  1147 
1194   G4ViewParameters vp = currentViewer->GetVie    1148   G4ViewParameters vp = currentViewer->GetViewParameters();
1195                                                  1149 
1196   if (command == fpCommandDolly) {               1150   if (command == fpCommandDolly) {
1197     fDollyIncrement = fpCommandDolly->GetNewD    1151     fDollyIncrement = fpCommandDolly->GetNewDoubleValue(newValue);
1198     vp.IncrementDolly(fDollyIncrement);          1152     vp.IncrementDolly(fDollyIncrement);
1199   }                                              1153   }
1200   else if (command == fpCommandDollyTo) {        1154   else if (command == fpCommandDollyTo) {
1201     fDollyTo = fpCommandDolly->GetNewDoubleVa    1155     fDollyTo = fpCommandDolly->GetNewDoubleValue(newValue);
1202     vp.SetDolly(fDollyTo);                       1156     vp.SetDolly(fDollyTo);
1203   }                                              1157   }
1204                                                  1158 
1205   if (verbosity >= G4VisManager::confirmation    1159   if (verbosity >= G4VisManager::confirmations) {
1206     G4cout << "Dolly distance changed to " <<    1160     G4cout << "Dolly distance changed to " << vp.GetDolly() << G4endl;
1207   }                                              1161   }
1208                                                  1162 
1209   SetViewParameters(currentViewer, vp);          1163   SetViewParameters(currentViewer, vp);
1210 }                                                1164 }
1211                                                  1165 
1212 ////////////// /vis/viewer/flush ////////////    1166 ////////////// /vis/viewer/flush ///////////////////////////////////////
1213                                                  1167 
1214 G4VisCommandViewerFlush::G4VisCommandViewerFl    1168 G4VisCommandViewerFlush::G4VisCommandViewerFlush () {
1215   G4bool omitable, currentAsDefault;             1169   G4bool omitable, currentAsDefault;
1216   fpCommand = new G4UIcmdWithAString ("/vis/v    1170   fpCommand = new G4UIcmdWithAString ("/vis/viewer/flush", this);
1217   fpCommand -> SetGuidance                       1171   fpCommand -> SetGuidance
1218     ("Compound command: \"/vis/viewer/refresh    1172     ("Compound command: \"/vis/viewer/refresh\" + \"/vis/viewer/update\".");
1219   fpCommand -> SetGuidance                       1173   fpCommand -> SetGuidance
1220     ("Useful for refreshing and initiating po    1174     ("Useful for refreshing and initiating post-processing for graphics"
1221      "\nsystems which need post-processing.      1175      "\nsystems which need post-processing.  By default, acts on current"
1222      "\nviewer.  \"/vis/viewer/list\" to see     1176      "\nviewer.  \"/vis/viewer/list\" to see possible viewers.  Viewer"
1223      "\nbecomes current.");                      1177      "\nbecomes current.");
1224   fpCommand -> SetParameterName ("viewer-name    1178   fpCommand -> SetParameterName ("viewer-name",
1225          omitable = true,                        1179          omitable = true,
1226          currentAsDefault = true);               1180          currentAsDefault = true);
1227 }                                                1181 }
1228                                                  1182 
1229 G4VisCommandViewerFlush::~G4VisCommandViewerF    1183 G4VisCommandViewerFlush::~G4VisCommandViewerFlush () {
1230   delete fpCommand;                              1184   delete fpCommand;
1231 }                                                1185 }
1232                                                  1186 
1233 G4String G4VisCommandViewerFlush::GetCurrentV    1187 G4String G4VisCommandViewerFlush::GetCurrentValue 
1234 (G4UIcommand*) {                                 1188 (G4UIcommand*) {
1235   G4VViewer* viewer = fpVisManager -> GetCurr    1189   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1236   return viewer ? viewer -> GetName () : G4St    1190   return viewer ? viewer -> GetName () : G4String("none");
1237 }                                                1191 }
1238                                                  1192 
1239 void G4VisCommandViewerFlush::SetNewValue (G4    1193 void G4VisCommandViewerFlush::SetNewValue (G4UIcommand*, G4String newValue) {
1240                                                  1194 
1241   G4VisManager::Verbosity verbosity = fpVisMa    1195   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1242                                                  1196 
1243   G4String& flushName = newValue;                1197   G4String& flushName = newValue;
1244   G4VViewer* viewer = fpVisManager -> GetView    1198   G4VViewer* viewer = fpVisManager -> GetViewer (flushName);
1245   if (!viewer) {                                 1199   if (!viewer) {
1246     if (verbosity >= G4VisManager::errors) {     1200     if (verbosity >= G4VisManager::errors) {
1247       G4warn << "ERROR: Viewer \"" << flushNa << 1201       G4cerr << "ERROR: Viewer \"" << flushName << "\"" <<
1248   " not found - \"/vis/viewer/list\"\n  to se    1202   " not found - \"/vis/viewer/list\"\n  to see possibilities."
1249        << G4endl;                                1203        << G4endl;
1250     }                                            1204     }
1251     return;                                      1205     return;
1252   }                                              1206   }
1253                                                  1207 
1254   G4UImanager* ui = G4UImanager::GetUIpointer    1208   G4UImanager* ui = G4UImanager::GetUIpointer();
                                                   >> 1209   G4int keepVerbose = ui->GetVerboseLevel();
                                                   >> 1210   G4int newVerbose(0);
                                                   >> 1211   if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
                                                   >> 1212     newVerbose = 2;
                                                   >> 1213   ui->SetVerboseLevel(newVerbose);
1255   ui->ApplyCommand(G4String("/vis/viewer/refr    1214   ui->ApplyCommand(G4String("/vis/viewer/refresh " + flushName));
1256   ui->ApplyCommand(G4String("/vis/viewer/upda    1215   ui->ApplyCommand(G4String("/vis/viewer/update " + flushName));
                                                   >> 1216   ui->SetVerboseLevel(keepVerbose);
1257   if (verbosity >= G4VisManager::confirmation    1217   if (verbosity >= G4VisManager::confirmations) {
1258     G4cout << "Viewer \"" << viewer -> GetNam    1218     G4cout << "Viewer \"" << viewer -> GetName () << "\""
1259      << " flushed." << G4endl;                   1219      << " flushed." << G4endl;
1260   }                                              1220   }
1261 }                                                1221 }
1262                                                  1222 
1263 ////////////// /vis/viewer/interpolate //////    1223 ////////////// /vis/viewer/interpolate ///////////////////////////////////////
1264                                                  1224 
1265 G4VisCommandViewerInterpolate::G4VisCommandVi    1225 G4VisCommandViewerInterpolate::G4VisCommandViewerInterpolate () {
1266   G4bool omitable;                               1226   G4bool omitable;
1267   fpCommand = new G4UIcommand ("/vis/viewer/i    1227   fpCommand = new G4UIcommand ("/vis/viewer/interpolate", this);
1268   fpCommand -> SetGuidance                       1228   fpCommand -> SetGuidance
1269   ("Interpolate views defined by the first ar    1229   ("Interpolate views defined by the first argument, which can contain "
1270    "Unix-shell-style pattern matching charact    1230    "Unix-shell-style pattern matching characters such as '*', '?' and '[' "
1271    "- see \"man sh\" and look for \"Pattern M    1231    "- see \"man sh\" and look for \"Pattern Matching\". The contents "
1272    "of each file are assumed to be \"/vis/vie    1232    "of each file are assumed to be \"/vis/viewer\" commands "
1273    "that specify a particular view. The files    1233    "that specify a particular view. The files are processed in alphanumeric "
1274    "order of filename. The files may be writt    1234    "order of filename. The files may be written by hand or produced by the "
1275    "\"/vis/viewer/save\" command.");             1235    "\"/vis/viewer/save\" command.");
1276   fpCommand -> SetGuidance                       1236   fpCommand -> SetGuidance
1277   ("The default is to search the working dire    1237   ("The default is to search the working directory for files with a .g4view "
1278    "extension. Another procedure is to assemb    1238    "extension. Another procedure is to assemble view files in a subdirectory, "
1279    "e.g., \"myviews\"; then they can be inter    1239    "e.g., \"myviews\"; then they can be interpolated with\n"
1280    "\"/vis/viewer/interpolate myviews\".");   << 1240    "\"/vis/viewer/interpolate myviews/*\".");
1281   fpCommand -> SetGuidance                       1241   fpCommand -> SetGuidance
1282   ("To export interpolated views to file for     1242   ("To export interpolated views to file for a future possible movie, "
1283    "write \"export\" as 5th parameter (OpenGL    1243    "write \"export\" as 5th parameter (OpenGL only).");
1284   G4UIparameter* parameter;                      1244   G4UIparameter* parameter;
1285   parameter = new G4UIparameter("pattern", 's    1245   parameter = new G4UIparameter("pattern", 's', omitable = true);
1286   parameter -> SetGuidance("Pattern that defi    1246   parameter -> SetGuidance("Pattern that defines the view files.");
1287   parameter -> SetDefaultValue("*.g4view");      1247   parameter -> SetDefaultValue("*.g4view");
1288   fpCommand -> SetParameter(parameter);          1248   fpCommand -> SetParameter(parameter);
1289   parameter = new G4UIparameter("no-of-points    1249   parameter = new G4UIparameter("no-of-points", 'i', omitable = true);
1290   parameter -> SetGuidance ("Number of interp    1250   parameter -> SetGuidance ("Number of interpolation points per interval.");
1291   parameter -> SetDefaultValue(50);              1251   parameter -> SetDefaultValue(50);
1292   fpCommand -> SetParameter(parameter);          1252   fpCommand -> SetParameter(parameter);
1293   parameter = new G4UIparameter("wait-time",     1253   parameter = new G4UIparameter("wait-time", 's', omitable = true);
1294   parameter -> SetGuidance("Wait time per int    1254   parameter -> SetGuidance("Wait time per interpolated point");
1295   parameter -> SetDefaultValue("20.");           1255   parameter -> SetDefaultValue("20.");
1296   fpCommand -> SetParameter(parameter);          1256   fpCommand -> SetParameter(parameter);
1297   parameter = new G4UIparameter("time-unit",     1257   parameter = new G4UIparameter("time-unit", 's', omitable = true);
1298   parameter -> SetDefaultValue("millisecond")    1258   parameter -> SetDefaultValue("millisecond");
1299   fpCommand -> SetParameter (parameter);         1259   fpCommand -> SetParameter (parameter);
1300   parameter = new G4UIparameter("export", 's'    1260   parameter = new G4UIparameter("export", 's', omitable = true);
1301   parameter -> SetDefaultValue("no");            1261   parameter -> SetDefaultValue("no");
1302   fpCommand -> SetParameter (parameter);         1262   fpCommand -> SetParameter (parameter);
1303 }                                                1263 }
1304                                                  1264 
1305 G4VisCommandViewerInterpolate::~G4VisCommandV    1265 G4VisCommandViewerInterpolate::~G4VisCommandViewerInterpolate () {
1306   delete fpCommand;                              1266   delete fpCommand;
1307 }                                                1267 }
1308                                                  1268 
1309 G4String G4VisCommandViewerInterpolate::GetCu    1269 G4String G4VisCommandViewerInterpolate::GetCurrentValue (G4UIcommand*) {
1310   return "";                                     1270   return "";
1311 }                                                1271 }
1312                                                  1272 
1313 void G4VisCommandViewerInterpolate::SetNewVal    1273 void G4VisCommandViewerInterpolate::SetNewValue (G4UIcommand*, G4String newValue) {
1314                                                  1274 
1315   G4VisManager::Verbosity verbosity = fpVisMa    1275   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1316                                                  1276 
1317   G4VViewer* currentViewer = fpVisManager->Ge    1277   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1318   if (!currentViewer) {                          1278   if (!currentViewer) {
1319     if (verbosity >= G4VisManager::errors) {     1279     if (verbosity >= G4VisManager::errors) {
1320       G4warn <<                               << 1280       G4cerr <<
1321       "ERROR: G4VisCommandViewerInterpolate::    1281       "ERROR: G4VisCommandViewerInterpolate::SetNewValue: no current viewer."
1322        << G4endl;                                1282        << G4endl;
1323     }                                            1283     }
1324     return;                                      1284     return;
1325   }                                              1285   }
1326                                                  1286 
1327   G4String pattern;                              1287   G4String pattern;
1328   G4int nInterpolationPoints;                    1288   G4int nInterpolationPoints;
1329   G4String waitTimePerPointString;               1289   G4String waitTimePerPointString;
1330   G4String timeUnit;                             1290   G4String timeUnit;
1331   G4String exportString;                         1291   G4String exportString;
1332                                                  1292 
1333   std::istringstream iss (newValue);             1293   std::istringstream iss (newValue);
1334   iss                                            1294   iss
1335   >> pattern                                     1295   >> pattern
1336   >> nInterpolationPoints                        1296   >> nInterpolationPoints
1337   >> waitTimePerPointString                      1297   >> waitTimePerPointString
1338   >> timeUnit                                    1298   >> timeUnit
1339   >> exportString;                               1299   >> exportString;
1340   G4String waitTimePerPointDimString(waitTime    1300   G4String waitTimePerPointDimString(waitTimePerPointString + ' ' + timeUnit);
1341   const G4double waitTimePerPoint =              1301   const G4double waitTimePerPoint =
1342   G4UIcommand::ConvertToDimensionedDouble(wai    1302   G4UIcommand::ConvertToDimensionedDouble(waitTimePerPointDimString.c_str());
1343   G4int waitTimePerPointmilliseconds = waitTi    1303   G4int waitTimePerPointmilliseconds = waitTimePerPoint/millisecond;
1344   if (waitTimePerPointmilliseconds < 0) waitT    1304   if (waitTimePerPointmilliseconds < 0) waitTimePerPointmilliseconds = 0;
1345                                                  1305 
1346   G4UImanager* uiManager = G4UImanager::GetUI    1306   G4UImanager* uiManager = G4UImanager::GetUIpointer();
1347                                                  1307 
1348   // Save current view parameters                1308   // Save current view parameters
1349   G4ViewParameters saveVP = currentViewer->Ge    1309   G4ViewParameters saveVP = currentViewer->GetViewParameters();
1350                                                  1310 
1351   // Save current verbosities                    1311   // Save current verbosities
1352   G4VisManager::Verbosity keepVisVerbosity =     1312   G4VisManager::Verbosity keepVisVerbosity = fpVisManager->GetVerbosity();
1353   G4int keepUIVerbosity = uiManager->GetVerbo    1313   G4int keepUIVerbosity = uiManager->GetVerboseLevel();
1354                                                  1314 
1355   // Set verbosities for this operation          1315   // Set verbosities for this operation
1356   fpVisManager->SetVerboseLevel(G4VisManager:    1316   fpVisManager->SetVerboseLevel(G4VisManager::errors);
1357   uiManager->SetVerboseLevel(0);                 1317   uiManager->SetVerboseLevel(0);
1358                                                  1318 
1359   // Switch off auto-refresh while we read in    1319   // Switch off auto-refresh while we read in the view files (it will be
1360   // restored later).  Note: the view files d    1320   // restored later).  Note: the view files do not set auto-refresh.
1361   G4ViewParameters non_auto = saveVP;            1321   G4ViewParameters non_auto = saveVP;
1362   non_auto.SetAutoRefresh(false);                1322   non_auto.SetAutoRefresh(false);
1363   currentViewer->SetViewParameters(non_auto);    1323   currentViewer->SetViewParameters(non_auto);
1364                                                  1324 
1365   const G4int safety = 99;                    << 1325   // View vector of way points
1366   G4int safetyCount = 0;                      << 1326   std::vector<G4ViewParameters> viewVector;
1367   G4fs::path pathPattern = pattern.c_str();   << 
1368                                                  1327 
1369   // Parent path - add "./" for empty directo << 1328   const G4int safety = 9999;
1370   G4String parentPathString                   << 1329   G4int safetyCount = 0;
1371   (pathPattern.parent_path().string().length( << 1330   G4String pathname;
1372    pathPattern.parent_path().string() :       << 
1373    std::string("./"));                        << 
1374   G4fs::path parentPath = parentPathString.c_ << 
1375                                               << 
1376   // Fill selected paths                      << 
1377   std::set<G4fs::path> paths;  // Use std::se << 
1378                                               << 
1379   if (G4fs::is_directory(pathPattern)) {      << 
1380                                               << 
1381     // The user has specified a directory. Fi << 
1382     for (const auto& path: G4fs::directory_it << 
1383       if (safetyCount++ >= safety) break;     << 
1384       paths.insert(path);                     << 
1385     }                                         << 
1386                                                  1331 
1387   } else {                                    << 1332 #ifndef WIN32
1388                                                  1333 
1389     // Assume user has specified a Unix "glob << 1334   // Execute pattern and get resulting list of files
1390     // Default pattern is *.g4view, which tra << 1335   G4String shellCommand = "echo " + pattern;
1391     // Convert pattern into a regexp          << 1336   FILE *filelist = popen(shellCommand.c_str(), "r");
1392     G4String regexp_pattern("^");             << 1337   if (!filelist) {
1393     for (G4int i = 0; i < (G4int)pattern.leng << 1338     if (verbosity >= G4VisManager::errors) {
1394       if (pattern[i] == '.') {                << 1339       G4cerr
1395   regexp_pattern += "\\.";                    << 1340       << "ERROR: G4VisCommandViewerInterpolate::SetNewValue:"
1396       } else if (pattern[i] == '*') {         << 1341       << "\n  Error obtaining pipe."
1397   regexp_pattern += ".*";                     << 1342        << G4endl;
1398       } else if (pattern[i] == '?') {         << 
1399   regexp_pattern += "(.{1,1})";               << 
1400       } else {                                << 
1401   regexp_pattern += pattern[i];               << 
1402       }                                       << 
1403     }                                            1343     }
1404     std::regex regexp(regexp_pattern, std::re << 1344     return;
                                                   >> 1345   }
1405                                                  1346 
1406     for (const auto& path: G4fs::directory_it << 1347   // Build view vector of way points
1407       const auto& pathname = path.path().rela << 1348   const size_t BUFLENGTH = 999999;
1408       if (std::regex_match(pathname, regexp)) << 1349   char buf[BUFLENGTH];
1409   if (safetyCount++ >= safety) break;         << 1350   char* result = std::fgets(buf, BUFLENGTH, filelist);
1410   paths.insert(path);                         << 1351   if (result) {
1411       }                                       << 1352     std::istringstream fileliststream(result);
                                                   >> 1353     while (fileliststream >> pathname
                                                   >> 1354            && safetyCount++ < safety) {  // Loop checking, 16.02.2016, J.Allison
                                                   >> 1355       uiManager->ApplyCommand("/control/execute " + pathname);
                                                   >> 1356       G4ViewParameters vp = currentViewer->GetViewParameters();
                                                   >> 1357       // Set original auto-refresh status.
                                                   >> 1358       vp.SetAutoRefresh(saveVP.IsAutoRefresh());
                                                   >> 1359       viewVector.push_back(vp);
                                                   >> 1360     }
                                                   >> 1361   }
                                                   >> 1362   pclose(filelist);
                                                   >> 1363 
                                                   >> 1364 #else // WIN32 (popen is not available in Windows)
                                                   >> 1365 
                                                   >> 1366   std::filesystem::path filePattern = pattern.c_str();
                                                   >> 1367 
                                                   >> 1368   // Default pattern : *.g4view
                                                   >> 1369   // Translated to a regexp : ^.*\\.g4view
                                                   >> 1370   // Convert pattern into a regexp
                                                   >> 1371   std::string regexp_pattern("^" + filePattern.filename().string());
                                                   >> 1372   std::string result_pattern = "";
                                                   >> 1373   // Replace '.' by "\\."
                                                   >> 1374   size_t currentPos = 0;
                                                   >> 1375   size_t nextPos = 0;
                                                   >> 1376   std::string currentReplacement = "";
                                                   >> 1377   size_t pos1 = regexp_pattern.find('.', nextPos);
                                                   >> 1378   size_t pos2 = regexp_pattern.find('*', nextPos);
                                                   >> 1379   size_t pos3 = regexp_pattern.find('?', nextPos);
                                                   >> 1380   while ((pos1 != std::string::npos) || (pos2 != std::string::npos) || (pos3 != std::string::npos)) {
                                                   >> 1381     nextPos = pos1;
                                                   >> 1382     currentReplacement = "\\.";
                                                   >> 1383     if (pos2 < nextPos) {
                                                   >> 1384       nextPos = pos2;
                                                   >> 1385       currentReplacement = ".*";
                                                   >> 1386     }
                                                   >> 1387     if (pos3 < nextPos) {
                                                   >> 1388       nextPos = pos3;
                                                   >> 1389       currentReplacement = "(.{1,1})";
                                                   >> 1390     }
                                                   >> 1391     result_pattern += regexp_pattern.substr(currentPos, nextPos - currentPos) + currentReplacement;
                                                   >> 1392     nextPos++;
                                                   >> 1393     currentPos = nextPos;
                                                   >> 1394     pos1 = regexp_pattern.find('.', currentPos);
                                                   >> 1395     pos2 = regexp_pattern.find('*', currentPos);
                                                   >> 1396     pos3 = regexp_pattern.find('?', currentPos);
                                                   >> 1397   }
                                                   >> 1398   result_pattern += regexp_pattern.substr(currentPos);
                                                   >> 1399 
                                                   >> 1400   // Build view vector of way points
                                                   >> 1401   // Add "./" for empty paths
                                                   >> 1402   G4String parentPath(filePattern.parent_path().string().length() ? filePattern.parent_path().string() : std::string("./"));
                                                   >> 1403   std::filesystem::path parentPathPattern = parentPath.c_str();
                                                   >> 1404   // Iterate through files in directory and apply regex match to filter appropriate files
                                                   >> 1405   std::regex result_pattern_regex (result_pattern, std::regex_constants::basic | std::regex_constants::icase);
                                                   >> 1406   for (auto iter = std::filesystem::directory_iterator(parentPathPattern);
                                                   >> 1407        iter != std::filesystem::directory_iterator() && safetyCount++ < safety;
                                                   >> 1408        ++iter)
                                                   >> 1409   {
                                                   >> 1410     const auto& file = iter->path();
                                                   >> 1411 
                                                   >> 1412     G4String filename(file.filename().string());
                                                   >> 1413     if (std::regex_match(filename, result_pattern_regex))
                                                   >> 1414     {
                                                   >> 1415       uiManager->ApplyCommand("/control/execute " + filename);
                                                   >> 1416       G4ViewParameters vp = currentViewer->GetViewParameters();
                                                   >> 1417       // Set original auto-refresh status.
                                                   >> 1418       vp.SetAutoRefresh(saveVP.IsAutoRefresh());
                                                   >> 1419       viewVector.push_back(vp);
1412     }                                            1420     }
1413   }                                              1421   }
1414                                                  1422 
1415   if (safetyCount > safety) {                 << 1423 #endif // WIN32
                                                   >> 1424 
                                                   >> 1425   if (safetyCount >= safety) {
1416     if (verbosity >= G4VisManager::errors) {     1426     if (verbosity >= G4VisManager::errors) {
1417       G4warn <<                               << 1427       G4cout <<
1418       "/vis/viewer/interpolate:"                 1428       "/vis/viewer/interpolate:"
1419       "\n  the number of way points has been  << 1429       "\n  the number of way points exceeds the maximum currently allowed: "
1420       << safety << G4endl;                       1430       << safety << G4endl;
1421     }                                            1431     }
1422   }                                           << 1432     return;
1423                                               << 
1424   // Fill view vector of way points           << 
1425   std::vector<G4ViewParameters> viewVector;   << 
1426   for (const auto& path: paths) {             << 
1427     uiManager->ApplyCommand("/control/execute << 
1428     G4ViewParameters vp = currentViewer->GetV << 
1429     // Set original auto-refresh status.      << 
1430     vp.SetAutoRefresh(saveVP.IsAutoRefresh()) << 
1431     viewVector.push_back(vp);                 << 
1432   }                                              1433   }
1433                                                  1434 
1434   InterpolateViews                               1435   InterpolateViews
1435   (currentViewer,viewVector,                     1436   (currentViewer,viewVector,
1436    nInterpolationPoints,waitTimePerPointmilli    1437    nInterpolationPoints,waitTimePerPointmilliseconds,exportString);
1437                                                  1438 
1438   // Restore original verbosities                1439   // Restore original verbosities
1439   uiManager->SetVerboseLevel(keepUIVerbosity)    1440   uiManager->SetVerboseLevel(keepUIVerbosity);
1440   fpVisManager->SetVerboseLevel(keepVisVerbos    1441   fpVisManager->SetVerboseLevel(keepVisVerbosity);
1441                                                  1442 
1442   // Restore original view parameters            1443   // Restore original view parameters
1443   currentViewer->SetViewParameters(saveVP);      1444   currentViewer->SetViewParameters(saveVP);
1444   currentViewer->RefreshView();                  1445   currentViewer->RefreshView();
1445   if (verbosity >= G4VisManager::confirmation    1446   if (verbosity >= G4VisManager::confirmations) {
1446     G4cout << "Viewer \"" << currentViewer ->    1447     G4cout << "Viewer \"" << currentViewer -> GetName () << "\""
1447     << " restored." << G4endl;                   1448     << " restored." << G4endl;
1448   }                                              1449   }
1449 }                                                1450 }
1450                                                  1451 
1451 ////////////// /vis/viewer/list /////////////    1452 ////////////// /vis/viewer/list ///////////////////////////////////////
1452                                                  1453 
1453 G4VisCommandViewerList::G4VisCommandViewerLis    1454 G4VisCommandViewerList::G4VisCommandViewerList () {
1454   G4bool omitable;                               1455   G4bool omitable;
1455   fpCommand = new G4UIcommand ("/vis/viewer/l    1456   fpCommand = new G4UIcommand ("/vis/viewer/list", this);
1456   fpCommand -> SetGuidance ("Lists viewers(s)    1457   fpCommand -> SetGuidance ("Lists viewers(s).");
1457   fpCommand -> SetGuidance                       1458   fpCommand -> SetGuidance
1458     ("See \"/vis/verbose\" for definition of     1459     ("See \"/vis/verbose\" for definition of verbosity.");
1459   G4UIparameter* parameter;                      1460   G4UIparameter* parameter;
1460   parameter = new G4UIparameter("viewer-name"    1461   parameter = new G4UIparameter("viewer-name", 's',
1461         omitable = true);                        1462         omitable = true);
1462   parameter -> SetDefaultValue ("all");          1463   parameter -> SetDefaultValue ("all");
1463   fpCommand -> SetParameter (parameter);         1464   fpCommand -> SetParameter (parameter);
1464   parameter = new G4UIparameter ("verbosity",    1465   parameter = new G4UIparameter ("verbosity", 's',
1465          omitable = true);                       1466          omitable = true);
1466   parameter -> SetDefaultValue ("warnings");     1467   parameter -> SetDefaultValue ("warnings");
1467   fpCommand -> SetParameter (parameter);         1468   fpCommand -> SetParameter (parameter);
1468 }                                                1469 }
1469                                                  1470 
1470 G4VisCommandViewerList::~G4VisCommandViewerLi    1471 G4VisCommandViewerList::~G4VisCommandViewerList () {
1471   delete fpCommand;                              1472   delete fpCommand;
1472 }                                                1473 }
1473                                                  1474 
1474 G4String G4VisCommandViewerList::GetCurrentVa    1475 G4String G4VisCommandViewerList::GetCurrentValue (G4UIcommand*) {
1475   return "";                                     1476   return "";
1476 }                                                1477 }
1477                                                  1478 
1478 void G4VisCommandViewerList::SetNewValue (G4U    1479 void G4VisCommandViewerList::SetNewValue (G4UIcommand*, G4String newValue) {
1479   G4String name, verbosityString;                1480   G4String name, verbosityString;
1480   std::istringstream is (newValue);              1481   std::istringstream is (newValue);
1481   is >> name >> verbosityString;                 1482   is >> name >> verbosityString;
1482   G4String shortName = fpVisManager -> Viewer    1483   G4String shortName = fpVisManager -> ViewerShortName (name);
1483   G4VisManager::Verbosity verbosity =            1484   G4VisManager::Verbosity verbosity =
1484     fpVisManager->GetVerbosityValue(verbosity    1485     fpVisManager->GetVerbosityValue(verbosityString);
1485                                                  1486 
1486   const G4VViewer* currentViewer = fpVisManag    1487   const G4VViewer* currentViewer = fpVisManager -> GetCurrentViewer ();
1487   G4String currentViewerShortName;               1488   G4String currentViewerShortName;
1488   if (currentViewer) {                           1489   if (currentViewer) {
1489     currentViewerShortName = currentViewer ->    1490     currentViewerShortName = currentViewer -> GetShortName ();
1490   }                                              1491   }
1491   else {                                         1492   else {
1492     currentViewerShortName = "none";             1493     currentViewerShortName = "none";
1493   }                                              1494   }
1494                                                  1495 
1495   const G4SceneHandlerList& sceneHandlerList     1496   const G4SceneHandlerList& sceneHandlerList =
1496     fpVisManager -> GetAvailableSceneHandlers    1497     fpVisManager -> GetAvailableSceneHandlers ();
1497   std::size_t nHandlers = sceneHandlerList.si << 1498   G4int nHandlers = sceneHandlerList.size ();
1498   G4bool found = false;                          1499   G4bool found = false;
1499   G4bool foundCurrent = false;                   1500   G4bool foundCurrent = false;
1500   for (std::size_t iHandler = 0; iHandler < n << 1501   for (int iHandler = 0; iHandler < nHandlers; iHandler++) {
1501     G4VSceneHandler* sceneHandler = sceneHand    1502     G4VSceneHandler* sceneHandler = sceneHandlerList [iHandler];
1502     const G4ViewerList& viewerList = sceneHan    1503     const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
1503     G4cout                                       1504     G4cout
1504     << "Scene handler \"" << sceneHandler ->     1505     << "Scene handler \"" << sceneHandler -> GetName () << "\" ("
1505     << sceneHandler->GetGraphicsSystem()->Get    1506     << sceneHandler->GetGraphicsSystem()->GetNickname() << ')';
1506     const G4Scene* pScene = sceneHandler -> G    1507     const G4Scene* pScene = sceneHandler -> GetScene ();
1507     if (pScene) {                                1508     if (pScene) {
1508       G4cout << ", scene \"" << pScene -> Get    1509       G4cout << ", scene \"" << pScene -> GetName () << "\"";
1509     }                                            1510     }
1510     G4cout << ':';                               1511     G4cout << ':';
1511     std::size_t nViewers = viewerList.size () << 1512     G4int nViewers = viewerList.size ();
1512     if (nViewers == 0) {                         1513     if (nViewers == 0) {
1513       G4cout << "\n            No viewers for    1514       G4cout << "\n            No viewers for this scene handler." << G4endl;
1514     }                                            1515     }
1515     else {                                       1516     else {
1516       for (std::size_t iViewer = 0; iViewer < << 1517       for (int iViewer = 0; iViewer < nViewers; iViewer++) {
1517   const G4VViewer* thisViewer = viewerList [i    1518   const G4VViewer* thisViewer = viewerList [iViewer];
1518   G4String thisName = thisViewer -> GetName (    1519   G4String thisName = thisViewer -> GetName ();
1519   G4String thisShortName = thisViewer -> GetS    1520   G4String thisShortName = thisViewer -> GetShortName ();
1520   if (name != "all") {                           1521   if (name != "all") {
1521     if (thisShortName != shortName) continue;    1522     if (thisShortName != shortName) continue;
1522   }                                              1523   }
1523   found = true;                                  1524   found = true;
1524   G4cout << "\n  ";                              1525   G4cout << "\n  ";
1525   if (thisShortName == currentViewerShortName    1526   if (thisShortName == currentViewerShortName) {
1526     foundCurrent = true;                         1527     foundCurrent = true;
1527     G4cout << "(current)";                       1528     G4cout << "(current)";
1528   }                                              1529   }
1529   else {                                         1530   else {
1530     G4cout << "         ";                       1531     G4cout << "         ";
1531   }                                              1532   }
1532   G4cout << " viewer \"" << thisName << "\"";    1533   G4cout << " viewer \"" << thisName << "\"";
1533   if (verbosity >= G4VisManager::parameters)     1534   if (verbosity >= G4VisManager::parameters) {
1534     G4cout << "\n  " << *thisViewer;             1535     G4cout << "\n  " << *thisViewer;
1535   }                                              1536   }
1536       }                                          1537       }
1537     }                                            1538     }
1538     G4cout << G4endl;                            1539     G4cout << G4endl;
1539   }                                              1540   }
1540                                                  1541 
1541   if (!foundCurrent) {                           1542   if (!foundCurrent) {
1542     G4cout << "No valid current viewer - plea    1543     G4cout << "No valid current viewer - please create or select one."
1543      << G4endl;                                  1544      << G4endl;
1544   }                                              1545   }
1545                                                  1546 
1546   if (!found) {                                  1547   if (!found) {
1547     G4cout << "No viewers";                      1548     G4cout << "No viewers";
1548     if (name != "all") {                         1549     if (name != "all") {
1549       G4cout << " of name \"" << name << "\""    1550       G4cout << " of name \"" << name << "\"";
1550     }                                            1551     }
1551     G4cout << " found." << G4endl;               1552     G4cout << " found." << G4endl;
1552   }                                              1553   }
1553 }                                                1554 }
1554                                                  1555 
1555 ////////////// /vis/viewer/pan and panTo ////    1556 ////////////// /vis/viewer/pan and panTo ////////////////////////////
1556                                                  1557 
1557 G4VisCommandViewerPan::G4VisCommandViewerPan     1558 G4VisCommandViewerPan::G4VisCommandViewerPan ():
1558   fPanIncrementRight  (0.),                      1559   fPanIncrementRight  (0.),
1559   fPanIncrementUp  (0.),                         1560   fPanIncrementUp  (0.),
1560   fPanToRight (0.),                              1561   fPanToRight (0.),
1561   fPanToUp (0.)                                  1562   fPanToUp (0.)
1562 {                                                1563 {
1563   G4bool omitable;                               1564   G4bool omitable;
1564                                                  1565 
1565   fpCommandPan = new G4UIcommand                 1566   fpCommandPan = new G4UIcommand
1566     ("/vis/viewer/pan", this);                   1567     ("/vis/viewer/pan", this);
1567   fpCommandPan -> SetGuidance                    1568   fpCommandPan -> SetGuidance
1568     ("Incremental pan.");                        1569     ("Incremental pan.");
1569   fpCommandPan -> SetGuidance                    1570   fpCommandPan -> SetGuidance
1570     ("Moves the camera incrementally right an    1571     ("Moves the camera incrementally right and up by these amounts (as seen"
1571      "\nfrom viewpoint direction).");            1572      "\nfrom viewpoint direction).");
1572   G4UIparameter* parameter;                      1573   G4UIparameter* parameter;
1573   parameter = new G4UIparameter("right-increm    1574   parameter = new G4UIparameter("right-increment", 'd', omitable = true);
1574   parameter -> SetCurrentAsDefault (true);       1575   parameter -> SetCurrentAsDefault (true);
1575   fpCommandPan -> SetParameter (parameter);      1576   fpCommandPan -> SetParameter (parameter);
1576   parameter = new G4UIparameter("up-increment    1577   parameter = new G4UIparameter("up-increment", 'd', omitable = true);
1577   parameter -> SetCurrentAsDefault (true);       1578   parameter -> SetCurrentAsDefault (true);
1578   fpCommandPan -> SetParameter (parameter);      1579   fpCommandPan -> SetParameter (parameter);
1579   parameter = new G4UIparameter ("unit", 's',    1580   parameter = new G4UIparameter ("unit", 's', omitable = true);
1580   parameter -> SetDefaultValue ("m");            1581   parameter -> SetDefaultValue ("m");
1581   fpCommandPan -> SetParameter (parameter);      1582   fpCommandPan -> SetParameter (parameter);
1582                                                  1583 
1583   fpCommandPanTo = new G4UIcommand               1584   fpCommandPanTo = new G4UIcommand
1584     ("/vis/viewer/panTo", this);                 1585     ("/vis/viewer/panTo", this);
1585   fpCommandPanTo -> SetGuidance                  1586   fpCommandPanTo -> SetGuidance
1586     ("Pan to specific coordinate.");             1587     ("Pan to specific coordinate.");
1587   fpCommandPanTo -> SetGuidance                  1588   fpCommandPanTo -> SetGuidance
1588     ("Places the camera in this position righ    1589     ("Places the camera in this position right and up relative to standard"
1589      "\ntarget point (as seen from viewpoint     1590      "\ntarget point (as seen from viewpoint direction).");
1590   parameter = new G4UIparameter("right", 'd',    1591   parameter = new G4UIparameter("right", 'd', omitable = true);
1591   parameter -> SetCurrentAsDefault (true);       1592   parameter -> SetCurrentAsDefault (true);
1592   fpCommandPanTo -> SetParameter (parameter);    1593   fpCommandPanTo -> SetParameter (parameter);
1593   parameter = new G4UIparameter("up", 'd', om    1594   parameter = new G4UIparameter("up", 'd', omitable = true);
1594   parameter -> SetCurrentAsDefault (true);       1595   parameter -> SetCurrentAsDefault (true);
1595   fpCommandPanTo -> SetParameter (parameter);    1596   fpCommandPanTo -> SetParameter (parameter);
1596   parameter = new G4UIparameter ("unit", 's',    1597   parameter = new G4UIparameter ("unit", 's', omitable = true);
1597   parameter -> SetDefaultValue ("m");            1598   parameter -> SetDefaultValue ("m");
1598   fpCommandPanTo -> SetParameter (parameter);    1599   fpCommandPanTo -> SetParameter (parameter);
1599 }                                                1600 }
1600                                                  1601 
1601 G4VisCommandViewerPan::~G4VisCommandViewerPan    1602 G4VisCommandViewerPan::~G4VisCommandViewerPan () {
1602   delete fpCommandPan;                           1603   delete fpCommandPan;
1603   delete fpCommandPanTo;                         1604   delete fpCommandPanTo;
1604 }                                                1605 }
1605                                                  1606 
1606 G4String G4VisCommandViewerPan::GetCurrentVal    1607 G4String G4VisCommandViewerPan::GetCurrentValue (G4UIcommand* command) {
1607   G4String currentValue;                         1608   G4String currentValue;
1608   if (command == fpCommandPan) {                 1609   if (command == fpCommandPan) {
1609     currentValue = ConvertToString(fPanIncrem    1610     currentValue = ConvertToString(fPanIncrementRight, fPanIncrementUp, "m");
1610   }                                              1611   }
1611   else if (command == fpCommandPanTo) {          1612   else if (command == fpCommandPanTo) {
1612     currentValue = ConvertToString(fPanToRigh    1613     currentValue = ConvertToString(fPanToRight, fPanToUp, "m");
1613   }                                              1614   }
1614   return currentValue;                           1615   return currentValue;
1615 }                                                1616 }
1616                                                  1617 
1617 void G4VisCommandViewerPan::SetNewValue (G4UI    1618 void G4VisCommandViewerPan::SetNewValue (G4UIcommand* command,
1618            G4String newValue) {                  1619            G4String newValue) {
1619                                                  1620 
1620                                                  1621 
1621   G4VisManager::Verbosity verbosity = fpVisMa    1622   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1622                                                  1623 
1623   G4VViewer* currentViewer = fpVisManager->Ge    1624   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1624   if (!currentViewer) {                          1625   if (!currentViewer) {
1625     if (verbosity >= G4VisManager::errors) {     1626     if (verbosity >= G4VisManager::errors) {
1626       G4warn <<                               << 1627       G4cerr <<
1627   "ERROR: G4VisCommandsViewerPan::SetNewValue    1628   "ERROR: G4VisCommandsViewerPan::SetNewValue: no current viewer."
1628        << G4endl;                                1629        << G4endl;
1629     }                                            1630     }
1630     return;                                      1631     return;
1631   }                                              1632   }
1632                                                  1633 
1633   G4ViewParameters vp = currentViewer->GetVie    1634   G4ViewParameters vp = currentViewer->GetViewParameters();
1634                                                  1635 
1635   if (command == fpCommandPan) {                 1636   if (command == fpCommandPan) {
1636     ConvertToDoublePair(newValue, fPanIncreme    1637     ConvertToDoublePair(newValue, fPanIncrementRight, fPanIncrementUp);
1637     vp.IncrementPan(fPanIncrementRight, fPanI    1638     vp.IncrementPan(fPanIncrementRight, fPanIncrementUp);
1638   }                                              1639   }
1639   else if (command == fpCommandPanTo) {          1640   else if (command == fpCommandPanTo) {
1640     ConvertToDoublePair(newValue, fPanToRight    1641     ConvertToDoublePair(newValue, fPanToRight, fPanToUp);
1641     vp.SetPan(fPanToRight, fPanToUp);            1642     vp.SetPan(fPanToRight, fPanToUp);
1642   }                                              1643   }
1643                                                  1644 
1644   if (verbosity >= G4VisManager::confirmation    1645   if (verbosity >= G4VisManager::confirmations) {
1645     G4cout << "Current target point now " <<     1646     G4cout << "Current target point now " << vp.GetCurrentTargetPoint()
1646      << G4endl;                                  1647      << G4endl;
1647   }                                              1648   }
1648                                                  1649 
1649   SetViewParameters(currentViewer, vp);          1650   SetViewParameters(currentViewer, vp);
1650 }                                                1651 }
1651                                                  1652 
1652 ////////////// /vis/viewer/rebuild //////////    1653 ////////////// /vis/viewer/rebuild ///////////////////////////////////////
1653                                                  1654 
1654 G4VisCommandViewerRebuild::G4VisCommandViewer    1655 G4VisCommandViewerRebuild::G4VisCommandViewerRebuild () {
1655   G4bool omitable, currentAsDefault;             1656   G4bool omitable, currentAsDefault;
1656   fpCommand = new G4UIcmdWithAString ("/vis/v    1657   fpCommand = new G4UIcmdWithAString ("/vis/viewer/rebuild", this);
1657   fpCommand -> SetGuidance ("Forces rebuild o    1658   fpCommand -> SetGuidance ("Forces rebuild of graphical database.");
1658   fpCommand -> SetGuidance                       1659   fpCommand -> SetGuidance 
1659     ("By default, acts on current viewer.  \"    1660     ("By default, acts on current viewer.  \"/vis/viewer/list\""
1660      "\nto see possible viewers.  Viewer beco    1661      "\nto see possible viewers.  Viewer becomes current.");
1661   fpCommand -> SetParameterName ("viewer-name    1662   fpCommand -> SetParameterName ("viewer-name",
1662          omitable = true,                        1663          omitable = true,
1663          currentAsDefault = true);               1664          currentAsDefault = true);
1664 }                                                1665 }
1665                                                  1666 
1666 G4VisCommandViewerRebuild::~G4VisCommandViewe    1667 G4VisCommandViewerRebuild::~G4VisCommandViewerRebuild () {
1667   delete fpCommand;                              1668   delete fpCommand;
1668 }                                                1669 }
1669                                                  1670 
1670 G4String G4VisCommandViewerRebuild::GetCurren    1671 G4String G4VisCommandViewerRebuild::GetCurrentValue (G4UIcommand*) {
1671   G4VViewer* viewer = fpVisManager -> GetCurr    1672   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1672   if (viewer) {                                  1673   if (viewer) {
1673     return viewer -> GetName ();                 1674     return viewer -> GetName ();
1674   }                                              1675   }
1675   else {                                         1676   else {
1676     return "none";                               1677     return "none";
1677   }                                              1678   }
1678 }                                                1679 }
1679                                                  1680 
1680 void G4VisCommandViewerRebuild::SetNewValue (    1681 void G4VisCommandViewerRebuild::SetNewValue (G4UIcommand*, G4String newValue) {
1681                                                  1682 
1682   G4VisManager::Verbosity verbosity = fpVisMa    1683   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1683                                                  1684 
1684   G4String& rebuildName = newValue;              1685   G4String& rebuildName = newValue;
1685                                                  1686 
1686   G4VViewer* viewer = fpVisManager -> GetView    1687   G4VViewer* viewer = fpVisManager -> GetViewer (rebuildName);
1687   if (!viewer) {                                 1688   if (!viewer) {
1688     if (verbosity >= G4VisManager::errors) {     1689     if (verbosity >= G4VisManager::errors) {
1689       G4warn << "ERROR: Viewer \"" << rebuild << 1690       G4cerr << "ERROR: Viewer \"" << rebuildName
1690        << "\" not found - \"/vis/viewer/list\    1691        << "\" not found - \"/vis/viewer/list\" to see possibilities."
1691        << G4endl;                                1692        << G4endl;
1692     }                                            1693     }
1693     return;                                      1694     return;
1694   }                                              1695   }
1695                                                  1696 
1696   G4VSceneHandler* sceneHandler = viewer->Get    1697   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1697   if (!sceneHandler) {                           1698   if (!sceneHandler) {
1698     if (verbosity >= G4VisManager::errors) {     1699     if (verbosity >= G4VisManager::errors) {
1699       G4warn << "ERROR: Viewer \"" << viewer- << 1700       G4cerr << "ERROR: Viewer \"" << viewer->GetName() << "\"" <<
1700   " has no scene handler - report serious bug    1701   " has no scene handler - report serious bug."
1701        << G4endl;                                1702        << G4endl;
1702     }                                            1703     }
1703     return;                                      1704     return;
1704   }                                              1705   }
1705                                                  1706 
1706   sceneHandler->ClearTransientStore();           1707   sceneHandler->ClearTransientStore();
1707   viewer->NeedKernelVisit();                     1708   viewer->NeedKernelVisit();
1708   viewer->SetView();                             1709   viewer->SetView();
1709   viewer->ClearView();                           1710   viewer->ClearView();
1710   viewer->DrawView();                            1711   viewer->DrawView();
1711                                                  1712 
1712   // Check auto-refresh and print confirmatio    1713   // Check auto-refresh and print confirmations.
1713   RefreshIfRequired(viewer);                     1714   RefreshIfRequired(viewer);
1714 }                                                1715 }
1715                                                  1716 
1716 ////////////// /vis/viewer/refresh //////////    1717 ////////////// /vis/viewer/refresh ///////////////////////////////////////
1717                                                  1718 
1718 G4VisCommandViewerRefresh::G4VisCommandViewer    1719 G4VisCommandViewerRefresh::G4VisCommandViewerRefresh () {
1719   G4bool omitable, currentAsDefault;             1720   G4bool omitable, currentAsDefault;
1720   fpCommand = new G4UIcmdWithAString ("/vis/v    1721   fpCommand = new G4UIcmdWithAString ("/vis/viewer/refresh", this);
1721   fpCommand -> SetGuidance                       1722   fpCommand -> SetGuidance
1722     ("Refreshes viewer.");                       1723     ("Refreshes viewer.");
1723   fpCommand -> SetGuidance                       1724   fpCommand -> SetGuidance 
1724     ("By default, acts on current viewer.  \"    1725     ("By default, acts on current viewer.  \"/vis/viewer/list\""
1725      "\nto see possible viewers.  Viewer beco    1726      "\nto see possible viewers.  Viewer becomes current.");
1726   fpCommand -> SetParameterName ("viewer-name    1727   fpCommand -> SetParameterName ("viewer-name",
1727          omitable = true,                        1728          omitable = true,
1728          currentAsDefault = true);               1729          currentAsDefault = true);
1729 }                                                1730 }
1730                                                  1731 
1731 G4VisCommandViewerRefresh::~G4VisCommandViewe    1732 G4VisCommandViewerRefresh::~G4VisCommandViewerRefresh () {
1732   delete fpCommand;                              1733   delete fpCommand;
1733 }                                                1734 }
1734                                                  1735 
1735 G4String G4VisCommandViewerRefresh::GetCurren    1736 G4String G4VisCommandViewerRefresh::GetCurrentValue (G4UIcommand*) {
1736   G4VViewer* viewer = fpVisManager -> GetCurr    1737   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1737   return viewer ? viewer -> GetName () : G4St    1738   return viewer ? viewer -> GetName () : G4String("none");
1738 }                                                1739 }
1739                                                  1740 
1740 void G4VisCommandViewerRefresh::SetNewValue (    1741 void G4VisCommandViewerRefresh::SetNewValue (G4UIcommand*, G4String newValue) {
1741                                                  1742 
1742   G4VisManager::Verbosity verbosity = fpVisMa    1743   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1743   G4bool warn(verbosity >= G4VisManager::warn    1744   G4bool warn(verbosity >= G4VisManager::warnings);
1744                                                  1745 
1745   G4String& refreshName = newValue;              1746   G4String& refreshName = newValue;
1746   G4VViewer* viewer = fpVisManager -> GetView    1747   G4VViewer* viewer = fpVisManager -> GetViewer (refreshName);
1747   if (!viewer) {                                 1748   if (!viewer) {
1748     if (verbosity >= G4VisManager::errors) {     1749     if (verbosity >= G4VisManager::errors) {
1749       G4warn << "ERROR: Viewer \"" << refresh << 1750       G4cerr << "ERROR: Viewer \"" << refreshName << "\"" <<
1750   " not found - \"/vis/viewer/list\"\n  to se    1751   " not found - \"/vis/viewer/list\"\n  to see possibilities."
1751        << G4endl;                                1752        << G4endl;
1752     }                                            1753     }
1753     return;                                      1754     return;
1754   }                                              1755   }
1755                                                  1756 
1756   G4VSceneHandler* sceneHandler = viewer->Get    1757   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
1757   if (!sceneHandler) {                           1758   if (!sceneHandler) {
1758     if (verbosity >= G4VisManager::errors) {     1759     if (verbosity >= G4VisManager::errors) {
1759       G4warn << "ERROR: Viewer \"" << refresh << 1760       G4cerr << "ERROR: Viewer \"" << refreshName << "\"" <<
1760   " has no scene handler - report serious bug    1761   " has no scene handler - report serious bug."
1761        << G4endl;                                1762        << G4endl;
1762     }                                            1763     }
1763     return;                                      1764     return;
1764   }                                              1765   }
1765                                                  1766 
1766   G4Scene* scene = sceneHandler->GetScene();     1767   G4Scene* scene = sceneHandler->GetScene();
1767   if (!scene) {                                  1768   if (!scene) {
1768     if (verbosity >= G4VisManager::confirmati    1769     if (verbosity >= G4VisManager::confirmations) {
1769       G4cout << "NOTE: SceneHandler \"" << sc    1770       G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
1770        << "\", to which viewer \"" << refresh    1771        << "\", to which viewer \"" << refreshName << "\"" <<
1771   "\n  is attached, has no scene - \"/vis/sce    1772   "\n  is attached, has no scene - \"/vis/scene/create\" and"
1772   " \"/vis/sceneHandler/attach\""                1773   " \"/vis/sceneHandler/attach\""
1773   "\n  (or use compound command \"/vis/drawVo    1774   "\n  (or use compound command \"/vis/drawVolume\")."
1774        << G4endl;                                1775        << G4endl;
1775     }                                            1776     }
1776     return;                                      1777     return;
1777   }                                              1778   }
1778   if (scene->GetRunDurationModelList().empty(    1779   if (scene->GetRunDurationModelList().empty()) {
1779     G4bool successful = scene -> AddWorldIfEm    1780     G4bool successful = scene -> AddWorldIfEmpty (warn);
1780     if (!successful) {                           1781     if (!successful) {
1781       if (verbosity >= G4VisManager::warnings    1782       if (verbosity >= G4VisManager::warnings) {
1782   G4warn <<                                   << 1783   G4cout <<
1783     "WARNING: Scene is empty.  Perhaps no geo    1784     "WARNING: Scene is empty.  Perhaps no geometry exists."
1784     "\n  Try /run/initialize."                   1785     "\n  Try /run/initialize."
1785          << G4endl;                              1786          << G4endl;
1786       }                                          1787       }
1787       return;                                    1788       return;
1788     }                                            1789     }
1789     // Scene has changed.  CheckSceneAndNotif    1790     // Scene has changed.  CheckSceneAndNotifyHandlers issues
1790     // /vis/scene/notifyHandlers, which does     1791     // /vis/scene/notifyHandlers, which does a refresh anyway, so the
1791     // ordinary refresh becomes part of the e    1792     // ordinary refresh becomes part of the else phrase...
1792     CheckSceneAndNotifyHandlers(scene);          1793     CheckSceneAndNotifyHandlers(scene);
1793   } else {                                       1794   } else {
1794     if (verbosity >= G4VisManager::confirmati    1795     if (verbosity >= G4VisManager::confirmations) {
1795       G4cout << "Refreshing viewer \"" << vie    1796       G4cout << "Refreshing viewer \"" << viewer -> GetName () << "\"..."
1796        << G4endl;                                1797        << G4endl;
1797     }                                            1798     }
1798     viewer -> SetView ();                        1799     viewer -> SetView ();
1799     viewer -> ClearView ();                      1800     viewer -> ClearView ();
1800     viewer -> DrawView ();                       1801     viewer -> DrawView ();
1801     if (verbosity >= G4VisManager::confirmati    1802     if (verbosity >= G4VisManager::confirmations) {
1802       G4cout << "Viewer \"" << viewer -> GetN    1803       G4cout << "Viewer \"" << viewer -> GetName () << "\"" << " refreshed."
1803   "\n  (You might also need \"/vis/viewer/upd    1804   "\n  (You might also need \"/vis/viewer/update\".)" << G4endl;
1804     }                                            1805     }
1805   }                                              1806   }
1806 }                                                1807 }
1807                                                  1808 
1808 ////////////// /vis/viewer/reset ////////////    1809 ////////////// /vis/viewer/reset ///////////////////////////////////////
1809                                                  1810 
1810 G4VisCommandViewerReset::G4VisCommandViewerRe    1811 G4VisCommandViewerReset::G4VisCommandViewerReset () {
1811   G4bool omitable, currentAsDefault;             1812   G4bool omitable, currentAsDefault;
1812   fpCommand = new G4UIcmdWithAString ("/vis/v    1813   fpCommand = new G4UIcmdWithAString ("/vis/viewer/reset", this);
1813   fpCommand -> SetGuidance ("Resets viewer.")    1814   fpCommand -> SetGuidance ("Resets viewer.");
1814   fpCommand -> SetGuidance                       1815   fpCommand -> SetGuidance 
1815     ("By default, acts on current viewer.  \"    1816     ("By default, acts on current viewer.  \"/vis/viewer/list\""
1816      "\nto see possible viewers.  Viewer beco    1817      "\nto see possible viewers.  Viewer becomes current.");
1817   fpCommand -> SetParameterName ("viewer-name    1818   fpCommand -> SetParameterName ("viewer-name",
1818          omitable = true,                        1819          omitable = true,
1819          currentAsDefault = true);               1820          currentAsDefault = true);
1820 }                                                1821 }
1821                                                  1822 
1822 G4VisCommandViewerReset::~G4VisCommandViewerR    1823 G4VisCommandViewerReset::~G4VisCommandViewerReset () {
1823   delete fpCommand;                              1824   delete fpCommand;
1824 }                                                1825 }
1825                                                  1826 
1826 G4String G4VisCommandViewerReset::GetCurrentV    1827 G4String G4VisCommandViewerReset::GetCurrentValue (G4UIcommand*) {
1827   G4VViewer* viewer = fpVisManager -> GetCurr    1828   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
1828   if (viewer) {                                  1829   if (viewer) {
1829     return viewer -> GetName ();                 1830     return viewer -> GetName ();
1830   }                                              1831   }
1831   else {                                         1832   else {
1832     return "none";                               1833     return "none";
1833   }                                              1834   }
1834 }                                                1835 }
1835                                                  1836 
1836 void G4VisCommandViewerReset::SetNewValue (G4    1837 void G4VisCommandViewerReset::SetNewValue (G4UIcommand*, G4String newValue) {
1837                                                  1838 
1838   G4VisManager::Verbosity verbosity = fpVisMa    1839   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1839                                                  1840 
1840   G4String& resetName = newValue;                1841   G4String& resetName = newValue;
1841   G4VViewer* viewer = fpVisManager -> GetView    1842   G4VViewer* viewer = fpVisManager -> GetViewer (resetName);
1842   if (!viewer) {                                 1843   if (!viewer) {
1843     if (verbosity >= G4VisManager::errors) {     1844     if (verbosity >= G4VisManager::errors) {
1844       G4warn << "ERROR: Viewer \"" << resetNa << 1845       G4cerr << "ERROR: Viewer \"" << resetName
1845        << "\" not found - \"/vis/viewer/list\    1846        << "\" not found - \"/vis/viewer/list\" to see possibilities."
1846        << G4endl;                                1847        << G4endl;
1847     }                                            1848     }
1848     return;                                      1849     return;
1849   }                                              1850   }
1850                                                  1851 
1851   viewer->ResetView();                           1852   viewer->ResetView();
1852   RefreshIfRequired(viewer);                     1853   RefreshIfRequired(viewer);
1853 }                                                1854 }
1854                                                  1855 
1855 ////////////// /vis/viewer/resetCameraParamet << 
1856                                               << 
1857 G4VisCommandViewerResetCameraParameters::G4Vi << 
1858   G4bool omitable, currentAsDefault;          << 
1859   fpCommand = new G4UIcmdWithAString ("/vis/v << 
1860   fpCommand -> SetGuidance ("Resets only the  << 
1861   fpCommand -> SetGuidance                    << 
1862   ("By default, acts on current viewer.  \"/v << 
1863    "\nto see possible viewers.  Viewer become << 
1864   fpCommand -> SetParameterName ("viewer-name << 
1865                                  omitable = t << 
1866                                  currentAsDef << 
1867 }                                             << 
1868                                               << 
1869 G4VisCommandViewerResetCameraParameters::~G4V << 
1870   delete fpCommand;                           << 
1871 }                                             << 
1872                                               << 
1873 G4String G4VisCommandViewerResetCameraParamet << 
1874   G4VViewer* viewer = fpVisManager -> GetCurr << 
1875   if (viewer) {                               << 
1876     return viewer -> GetName ();              << 
1877   }                                           << 
1878   else {                                      << 
1879     return "none";                            << 
1880   }                                           << 
1881 }                                             << 
1882                                               << 
1883 void G4VisCommandViewerResetCameraParameters: << 
1884                                               << 
1885   G4VisManager::Verbosity verbosity = fpVisMa << 
1886                                               << 
1887   G4String& resetName = newValue;             << 
1888   G4VViewer* viewer = fpVisManager -> GetView << 
1889   if (!viewer) {                              << 
1890     if (verbosity >= G4VisManager::errors) {  << 
1891       G4warn << "ERROR: Viewer \"" << resetNa << 
1892       << "\" not found - \"/vis/viewer/list\" << 
1893       << G4endl;                              << 
1894     }                                         << 
1895     return;                                   << 
1896   }                                           << 
1897                                               << 
1898   G4ViewParameters newVP = viewer->GetViewPar << 
1899   CopyCameraParameters(newVP,viewer->GetDefau << 
1900   viewer->SetViewParameters(newVP);           << 
1901   RefreshIfRequired(viewer);                  << 
1902 }                                             << 
1903                                               << 
1904 ////////////// /vis/viewer/save /////////////    1856 ////////////// /vis/viewer/save ///////////////////////////////////////
1905                                                  1857 
1906 G4VisCommandViewerSave::G4VisCommandViewerSav    1858 G4VisCommandViewerSave::G4VisCommandViewerSave () {
1907   G4bool omitable;                               1859   G4bool omitable;
1908   fpCommand = new G4UIcmdWithAString ("/vis/v    1860   fpCommand = new G4UIcmdWithAString ("/vis/viewer/save", this);
1909   fpCommand -> SetGuidance                       1861   fpCommand -> SetGuidance
1910   ("Write commands that define the current vi    1862   ("Write commands that define the current view to file.");
1911   fpCommand -> SetGuidance                       1863   fpCommand -> SetGuidance
1912   ("Read them back into the same or any viewe    1864   ("Read them back into the same or any viewer with \"/control/execute\".");
1913   fpCommand -> SetGuidance                       1865   fpCommand -> SetGuidance
1914   ("If the filename is omitted the view is sa    1866   ("If the filename is omitted the view is saved to a file "
1915    "\"g4_nn.g4view\", where nn is a sequentia    1867    "\"g4_nn.g4view\", where nn is a sequential two-digit number.");
1916   fpCommand -> SetGuidance                       1868   fpCommand -> SetGuidance
1917   ("If the filename is \"-\", the data are wr    1869   ("If the filename is \"-\", the data are written to G4cout.");
1918   fpCommand -> SetGuidance                       1870   fpCommand -> SetGuidance
1919   ("If you are wanting to save views for futu    1871   ("If you are wanting to save views for future interpolation a recommended "
1920    "procedure is: save views to \"g4_nn.g4vie    1872    "procedure is: save views to \"g4_nn.g4view\", as above, then move the files "
1921    "into a sub-directory, say, \"views\", the    1873    "into a sub-directory, say, \"views\", then interpolate with"
1922    "\"/vis/viewer/interpolate views\"");      << 1874    "\"/vis/viewer/interpolate views/\" (note the trailing \'/\').");
1923   fpCommand -> SetParameterName ("filename",     1875   fpCommand -> SetParameterName ("filename", omitable = true);
1924   fpCommand -> SetDefaultValue ("");             1876   fpCommand -> SetDefaultValue ("");
1925 }                                                1877 }
1926                                                  1878 
1927 G4VisCommandViewerSave::~G4VisCommandViewerSa    1879 G4VisCommandViewerSave::~G4VisCommandViewerSave () {
1928   delete fpCommand;                              1880   delete fpCommand;
1929 }                                                1881 }
1930                                                  1882 
1931 G4String G4VisCommandViewerSave::GetCurrentVa    1883 G4String G4VisCommandViewerSave::GetCurrentValue
1932 (G4UIcommand*) {                                 1884 (G4UIcommand*) {
1933   return "";                                     1885   return "";
1934 }                                                1886 }
1935                                                  1887 
1936 namespace {                                      1888 namespace {
1937   void WriteCommands                             1889   void WriteCommands
1938   (std::ostream& os,                             1890   (std::ostream& os,
1939    const G4ViewParameters& vp,                   1891    const G4ViewParameters& vp,
1940    const G4Point3D& stp)  // Standard Target     1892    const G4Point3D& stp)  // Standard Target Point
1941   {                                              1893   {
1942     os                                           1894     os
1943     << vp.CameraAndLightingCommands(stp)         1895     << vp.CameraAndLightingCommands(stp)
1944     << vp.DrawingStyleCommands()                 1896     << vp.DrawingStyleCommands()
1945     << vp.SceneModifyingCommands()               1897     << vp.SceneModifyingCommands()
1946     << vp.TouchableCommands()                    1898     << vp.TouchableCommands()
1947     << vp.TimeWindowCommands()                   1899     << vp.TimeWindowCommands()
1948     << std::endl;                                1900     << std::endl;
1949   }                                              1901   }
1950 }                                                1902 }
1951                                                  1903 
1952 void G4VisCommandViewerSave::SetNewValue (G4U    1904 void G4VisCommandViewerSave::SetNewValue (G4UIcommand*, G4String newValue) {
1953                                                  1905   
1954   G4VisManager::Verbosity verbosity = fpVisMa    1906   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1955                                                  1907   
1956   const G4VViewer* currentViewer = fpVisManag    1908   const G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
1957   if (!currentViewer) {                          1909   if (!currentViewer) {
1958     if (verbosity >= G4VisManager::errors) {     1910     if (verbosity >= G4VisManager::errors) {
1959       G4warn <<                               << 1911       G4cerr <<
1960       "ERROR: G4VisCommandsViewerSave::SetNew    1912       "ERROR: G4VisCommandsViewerSave::SetNewValue: no current viewer."
1961       << G4endl;                                 1913       << G4endl;
1962     }                                            1914     }
1963     return;                                      1915     return;
1964   }                                              1916   }
1965                                                  1917   
1966   const G4Scene* currentScene = currentViewer    1918   const G4Scene* currentScene = currentViewer->GetSceneHandler()->GetScene();
1967   if (!currentScene) {                           1919   if (!currentScene) {
1968     if (verbosity >= G4VisManager::errors) {     1920     if (verbosity >= G4VisManager::errors) {
1969       G4warn <<                               << 1921       G4cerr <<
1970       "ERROR: G4VisCommandsViewerSave::SetNew    1922       "ERROR: G4VisCommandsViewerSave::SetNewValue: no current scene."
1971       << G4endl;                                 1923       << G4endl;
1972     }                                            1924     }
1973     return;                                      1925     return;
1974   }                                              1926   }
1975                                                  1927 
1976   // Get view parameters and ther relevant in    1928   // Get view parameters and ther relevant information.
1977   G4ViewParameters vp = currentViewer->GetVie    1929   G4ViewParameters vp = currentViewer->GetViewParameters();
1978   // Concatenate any private vis attributes m    1930   // Concatenate any private vis attributes modifiers...
1979   const std::vector<G4ModelingParameters::Vis    1931   const std::vector<G4ModelingParameters::VisAttributesModifier>*
1980   privateVAMs = currentViewer->GetPrivateVisA    1932   privateVAMs = currentViewer->GetPrivateVisAttributesModifiers();
1981   if (privateVAMs) {                             1933   if (privateVAMs) {
1982     std::vector<G4ModelingParameters::VisAttr    1934     std::vector<G4ModelingParameters::VisAttributesModifier>::const_iterator i;
1983     for (i = privateVAMs->begin(); i != priva    1935     for (i = privateVAMs->begin(); i != privateVAMs->end(); ++i) {
1984       vp.AddVisAttributesModifier(*i);           1936       vp.AddVisAttributesModifier(*i);
1985     }                                            1937     }
1986   }                                              1938   }
1987   const G4Point3D& stp = currentScene->GetSta    1939   const G4Point3D& stp = currentScene->GetStandardTargetPoint();
1988                                                  1940 
1989   G4String filename = newValue;                  1941   G4String filename = newValue;
1990                                                  1942 
1991   if (newValue.length() == 0) {                  1943   if (newValue.length() == 0) {
1992     // Null filename - generate a filename       1944     // Null filename - generate a filename
1993     const G4int maxNoOfFiles = 100;              1945     const G4int maxNoOfFiles = 100;
1994     static G4int sequenceNumber = 0;             1946     static G4int sequenceNumber = 0;
1995     if (sequenceNumber >= maxNoOfFiles) {        1947     if (sequenceNumber >= maxNoOfFiles) {
1996       if (verbosity >= G4VisManager::errors)     1948       if (verbosity >= G4VisManager::errors) {
1997         G4warn                                << 1949         G4cerr
1998         << "ERROR: G4VisCommandsViewerSave::S    1950         << "ERROR: G4VisCommandsViewerSave::SetNewValue: Maximum number, "
1999         << maxNoOfFiles                          1951         << maxNoOfFiles
2000         << ", of files exceeded."                1952         << ", of files exceeded."
2001         << G4endl;                               1953         << G4endl;
2002       }                                          1954       }
2003       return;                                    1955       return;
2004     }                                            1956     }
2005     std::ostringstream oss;                      1957     std::ostringstream oss;
2006     oss << std::setw(2) << std::setfill('0')     1958     oss << std::setw(2) << std::setfill('0') << sequenceNumber++;
2007     filename = "g4_" + oss.str() + ".g4view";    1959     filename = "g4_" + oss.str() + ".g4view";
2008   }                                              1960   }
2009                                                  1961 
2010   if (filename == "-") {                         1962   if (filename == "-") {
2011     // Write to standard output                  1963     // Write to standard output
2012     WriteCommands(G4cout,vp,stp);                1964     WriteCommands(G4cout,vp,stp);
2013   } else {                                       1965   } else {
2014     // Write to file - but add extension if n    1966     // Write to file - but add extension if not prescribed
2015     if (!G4StrUtil::contains(filename, '.'))  << 1967     if (!filename.contains('.')) {
2016       // No extension supplied - add .g4view     1968       // No extension supplied - add .g4view
2017       filename += ".g4view";                     1969       filename += ".g4view";
2018     }                                            1970     }
2019     std::ofstream ofs(filename);                 1971     std::ofstream ofs(filename);
2020     if (!ofs) {                                  1972     if (!ofs) {
2021       if (verbosity >= G4VisManager::errors)     1973       if (verbosity >= G4VisManager::errors) {
2022         G4warn <<                             << 1974         G4cerr <<
2023         "ERROR: G4VisCommandsViewerSave::SetN    1975         "ERROR: G4VisCommandsViewerSave::SetNewValue: Trouble opening file \""
2024         << filename << "\"."                     1976         << filename << "\"."
2025         << G4endl;                               1977         << G4endl;
2026       }                                          1978       }
2027       ofs.close();                               1979       ofs.close();
2028       return;                                    1980       return;
2029     }                                            1981     }
2030     WriteCommands(ofs,vp,stp);                   1982     WriteCommands(ofs,vp,stp);
2031     ofs.close();                                 1983     ofs.close();
2032   }                                              1984   }
2033                                                  1985   
2034   if (verbosity >= G4VisManager::warnings) {     1986   if (verbosity >= G4VisManager::warnings) {
2035     G4warn << "Viewer \"" << currentViewer -> << 1987     G4cout << "Viewer \"" << currentViewer -> GetName ()
2036     << "\"" << " saved to ";                     1988     << "\"" << " saved to ";
2037     if (filename == "-") {                       1989     if (filename == "-") {
2038       G4warn << "G4cout.";                    << 1990       G4cout << "G4cout.";
2039     } else {                                     1991     } else {
2040       G4warn << "file \'" << filename << "\". << 1992       G4cout << "file \'" << filename << "\"." <<
2041       "\n  Read the view back into this or an    1993       "\n  Read the view back into this or any viewer with"
2042       "\n  \"/control/execute " << filename <    1994       "\n  \"/control/execute " << filename << "\" or use"
2043       "\n  \"/vis/viewer/interpolate\" if you    1995       "\n  \"/vis/viewer/interpolate\" if you have several saved files -"
2044       "\n  see \"help /vis/viewer/interpolate    1996       "\n  see \"help /vis/viewer/interpolate\" for guidance.";
2045     }                                            1997     }
2046     G4warn << G4endl;                         << 1998     G4cout << G4endl;
2047   }                                              1999   }
2048 }                                                2000 }
2049                                                  2001 
2050 ////////////// /vis/viewer/scale and scaleTo     2002 ////////////// /vis/viewer/scale and scaleTo ////////////////////////////
2051                                                  2003 
2052 G4VisCommandViewerScale::G4VisCommandViewerSc    2004 G4VisCommandViewerScale::G4VisCommandViewerScale ():
2053   fScaleMultiplier (G4Vector3D (1., 1., 1.)),    2005   fScaleMultiplier (G4Vector3D (1., 1., 1.)),
2054   fScaleTo         (G4Vector3D (1., 1., 1.))     2006   fScaleTo         (G4Vector3D (1., 1., 1.))
2055 {                                                2007 {
2056   G4bool omitable, currentAsDefault;             2008   G4bool omitable, currentAsDefault;
2057                                                  2009 
2058   fpCommandScale = new G4UIcmdWith3Vector        2010   fpCommandScale = new G4UIcmdWith3Vector
2059     ("/vis/viewer/scale", this);                 2011     ("/vis/viewer/scale", this);
2060   fpCommandScale -> SetGuidance ("Incremental    2012   fpCommandScale -> SetGuidance ("Incremental (non-uniform) scaling.");
2061   fpCommandScale -> SetGuidance                  2013   fpCommandScale -> SetGuidance
2062     ("Multiplies components of current scalin    2014     ("Multiplies components of current scaling by components of this factor."
2063      "\n Scales (x,y,z) by corresponding comp    2015      "\n Scales (x,y,z) by corresponding components of the resulting factor.");
2064   fpCommandScale -> SetGuidance                  2016   fpCommandScale -> SetGuidance
2065     ("");                                        2017     ("");
2066   fpCommandScale -> SetParameterName             2018   fpCommandScale -> SetParameterName
2067     ("x-scale-multiplier","y-scale-multiplier    2019     ("x-scale-multiplier","y-scale-multiplier","z-scale-multiplier",
2068      omitable=true, currentAsDefault=true);      2020      omitable=true, currentAsDefault=true);
2069                                                  2021 
2070   fpCommandScaleTo = new G4UIcmdWith3Vector      2022   fpCommandScaleTo = new G4UIcmdWith3Vector
2071     ("/vis/viewer/scaleTo", this);               2023     ("/vis/viewer/scaleTo", this);
2072   fpCommandScaleTo -> SetGuidance ("Absolute     2024   fpCommandScaleTo -> SetGuidance ("Absolute (non-uniform) scaling.");
2073   fpCommandScaleTo -> SetGuidance                2025   fpCommandScaleTo -> SetGuidance
2074     ("Scales (x,y,z) by corresponding compone    2026     ("Scales (x,y,z) by corresponding components of this factor.");
2075   fpCommandScaleTo -> SetParameterName           2027   fpCommandScaleTo -> SetParameterName
2076     ("x-scale-factor","y-scale-factor","z-sca    2028     ("x-scale-factor","y-scale-factor","z-scale-factor",
2077      omitable=true, currentAsDefault=true);      2029      omitable=true, currentAsDefault=true);
2078 }                                                2030 }
2079                                                  2031 
2080 G4VisCommandViewerScale::~G4VisCommandViewerS    2032 G4VisCommandViewerScale::~G4VisCommandViewerScale () {
2081   delete fpCommandScale;                         2033   delete fpCommandScale;
2082   delete fpCommandScaleTo;                       2034   delete fpCommandScaleTo;
2083 }                                                2035 }
2084                                                  2036 
2085 G4String G4VisCommandViewerScale::GetCurrentV    2037 G4String G4VisCommandViewerScale::GetCurrentValue (G4UIcommand* command) {
2086   G4String currentValue;                         2038   G4String currentValue;
2087   if (command == fpCommandScale) {               2039   if (command == fpCommandScale) {
2088     currentValue = fpCommandScale->ConvertToS    2040     currentValue = fpCommandScale->ConvertToString(G4ThreeVector(fScaleMultiplier));
2089   }                                              2041   }
2090   else if (command == fpCommandScaleTo) {        2042   else if (command == fpCommandScaleTo) {
2091     currentValue = fpCommandScaleTo->ConvertT    2043     currentValue = fpCommandScaleTo->ConvertToString(G4ThreeVector(fScaleTo));
2092   }                                              2044   }
2093   return currentValue;                           2045   return currentValue;
2094 }                                                2046 }
2095                                                  2047 
2096 void G4VisCommandViewerScale::SetNewValue (G4    2048 void G4VisCommandViewerScale::SetNewValue (G4UIcommand* command,
2097              G4String newValue) {                2049              G4String newValue) {
2098                                                  2050 
2099                                                  2051 
2100   G4VisManager::Verbosity verbosity = fpVisMa    2052   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2101                                                  2053 
2102   G4VViewer* currentViewer = fpVisManager->Ge    2054   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
2103   if (!currentViewer) {                          2055   if (!currentViewer) {
2104     if (verbosity >= G4VisManager::errors) {     2056     if (verbosity >= G4VisManager::errors) {
2105       G4warn <<                               << 2057       G4cerr <<
2106   "ERROR: G4VisCommandsViewerScale::SetNewVal    2058   "ERROR: G4VisCommandsViewerScale::SetNewValue: no current viewer."
2107        << G4endl;                                2059        << G4endl;
2108     }                                            2060     }
2109     return;                                      2061     return;
2110   }                                              2062   }
2111                                                  2063 
2112   G4ViewParameters vp = currentViewer->GetVie    2064   G4ViewParameters vp = currentViewer->GetViewParameters();
2113                                                  2065 
2114   if (command == fpCommandScale) {               2066   if (command == fpCommandScale) {
2115     fScaleMultiplier = fpCommandScale->GetNew    2067     fScaleMultiplier = fpCommandScale->GetNew3VectorValue(newValue);
2116     vp.MultiplyScaleFactor(fScaleMultiplier);    2068     vp.MultiplyScaleFactor(fScaleMultiplier);
2117   }                                              2069   }
2118   else if (command == fpCommandScaleTo) {        2070   else if (command == fpCommandScaleTo) {
2119     fScaleTo = fpCommandScale->GetNew3VectorV    2071     fScaleTo = fpCommandScale->GetNew3VectorValue(newValue);
2120     vp.SetScaleFactor(fScaleTo);                 2072     vp.SetScaleFactor(fScaleTo);
2121   }                                              2073   }
2122                                                  2074 
2123   if (verbosity >= G4VisManager::confirmation    2075   if (verbosity >= G4VisManager::confirmations) {
2124     G4cout << "Scale factor changed to " << v    2076     G4cout << "Scale factor changed to " << vp.GetScaleFactor() << G4endl;
2125   }                                              2077   }
2126                                                  2078 
2127   SetViewParameters(currentViewer, vp);          2079   SetViewParameters(currentViewer, vp);
2128 }                                                2080 }
2129                                                  2081 
2130 ////////////// /vis/viewer/select ///////////    2082 ////////////// /vis/viewer/select ///////////////////////////////////////
2131                                                  2083 
2132 G4VisCommandViewerSelect::G4VisCommandViewerS    2084 G4VisCommandViewerSelect::G4VisCommandViewerSelect () {
2133   G4bool omitable;                               2085   G4bool omitable;
2134   fpCommand = new G4UIcmdWithAString ("/vis/v    2086   fpCommand = new G4UIcmdWithAString ("/vis/viewer/select", this);
2135   fpCommand -> SetGuidance ("Selects viewer."    2087   fpCommand -> SetGuidance ("Selects viewer.");
2136   fpCommand -> SetGuidance                       2088   fpCommand -> SetGuidance
2137     ("Specify viewer by name.  \"/vis/viewer/    2089     ("Specify viewer by name.  \"/vis/viewer/list\" to see possible viewers.");
2138   fpCommand -> SetParameterName ("viewer-name    2090   fpCommand -> SetParameterName ("viewer-name", omitable = false);
2139 }                                                2091 }
2140                                                  2092 
2141 G4VisCommandViewerSelect::~G4VisCommandViewer    2093 G4VisCommandViewerSelect::~G4VisCommandViewerSelect () {
2142   delete fpCommand;                              2094   delete fpCommand;
2143 }                                                2095 }
2144                                                  2096 
2145 G4String G4VisCommandViewerSelect::GetCurrent    2097 G4String G4VisCommandViewerSelect::GetCurrentValue (G4UIcommand*) {
2146   return "";                                     2098   return "";
2147 }                                                2099 }
2148                                                  2100 
2149 void G4VisCommandViewerSelect::SetNewValue (G    2101 void G4VisCommandViewerSelect::SetNewValue (G4UIcommand*, G4String newValue) {
2150                                                  2102 
2151   G4VisManager::Verbosity verbosity = fpVisMa    2103   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2152                                                  2104 
2153   G4String& selectName = newValue;               2105   G4String& selectName = newValue;
2154   G4VViewer* viewer = fpVisManager -> GetView    2106   G4VViewer* viewer = fpVisManager -> GetViewer (selectName);
2155                                                  2107 
2156   if (!viewer) {                                 2108   if (!viewer) {
2157     if (verbosity >= G4VisManager::errors) {     2109     if (verbosity >= G4VisManager::errors) {
2158       G4warn << "ERROR: Viewer \"" << selectN << 2110       G4cerr << "ERROR: Viewer \"" << selectName << "\"";
2159       G4warn << " not found - \"/vis/viewer/l << 2111       G4cerr << " not found - \"/vis/viewer/list\""
2160   "\n  to see possibilities."                    2112   "\n  to see possibilities."
2161        << G4endl;                                2113        << G4endl;
2162     }                                            2114     }
2163     return;                                      2115     return;
2164   }                                              2116   }
2165                                                  2117 
2166   if (viewer == fpVisManager -> GetCurrentVie    2118   if (viewer == fpVisManager -> GetCurrentViewer ()) {
2167     if (verbosity >= G4VisManager::warnings)     2119     if (verbosity >= G4VisManager::warnings) {
2168       G4warn << "WARNING: Viewer \"" << viewe << 2120       G4cout << "WARNING: Viewer \"" << viewer -> GetName () << "\""
2169        << " already selected." << G4endl;        2121        << " already selected." << G4endl;
2170     }                                            2122     }
2171     return;                                      2123     return;
2172   }                                              2124   }
2173                                                  2125 
2174   // Set pointers, call SetView and print con    2126   // Set pointers, call SetView and print confirmation.
2175   fpVisManager -> SetCurrentViewer (viewer);     2127   fpVisManager -> SetCurrentViewer (viewer);
2176                                                  2128 
2177   RefreshIfRequired(viewer);                     2129   RefreshIfRequired(viewer);
2178                                               << 
2179   // Update GUI scene tree (make sure it's in << 
2180   viewer->UpdateGUISceneTree();               << 
2181 }                                                2130 }
2182                                                  2131 
2183 ////////////// /vis/viewer/update ///////////    2132 ////////////// /vis/viewer/update ///////////////////////////////////////
2184                                                  2133 
2185 G4VisCommandViewerUpdate::G4VisCommandViewerU    2134 G4VisCommandViewerUpdate::G4VisCommandViewerUpdate () {
2186   G4bool omitable, currentAsDefault;             2135   G4bool omitable, currentAsDefault;
2187   fpCommand = new G4UIcmdWithAString ("/vis/v    2136   fpCommand = new G4UIcmdWithAString ("/vis/viewer/update", this);
2188   fpCommand -> SetGuidance                       2137   fpCommand -> SetGuidance
2189     ("Triggers graphical database post-proces    2138     ("Triggers graphical database post-processing for viewers"
2190      "\nusing that technique.");                 2139      "\nusing that technique.");
2191   fpCommand -> SetGuidance                       2140   fpCommand -> SetGuidance
2192     ("For such viewers the view only becomes     2141     ("For such viewers the view only becomes visible with this command."
2193      "\nBy default, acts on current viewer.      2142      "\nBy default, acts on current viewer.  \"/vis/viewer/list\""
2194      "\nto see possible viewers.  Viewer beco    2143      "\nto see possible viewers.  Viewer becomes current.");
2195   fpCommand -> SetParameterName ("viewer-name    2144   fpCommand -> SetParameterName ("viewer-name",
2196          omitable = true,                        2145          omitable = true,
2197          currentAsDefault = true);               2146          currentAsDefault = true);
2198 }                                                2147 }
2199                                                  2148 
2200 G4VisCommandViewerUpdate::~G4VisCommandViewer    2149 G4VisCommandViewerUpdate::~G4VisCommandViewerUpdate () {
2201   delete fpCommand;                              2150   delete fpCommand;
2202 }                                                2151 }
2203                                                  2152 
2204 G4String G4VisCommandViewerUpdate::GetCurrent    2153 G4String G4VisCommandViewerUpdate::GetCurrentValue (G4UIcommand*) {
2205   G4VViewer* viewer = fpVisManager -> GetCurr    2154   G4VViewer* viewer = fpVisManager -> GetCurrentViewer ();
2206   if (viewer) {                                  2155   if (viewer) {
2207     return viewer -> GetName ();                 2156     return viewer -> GetName ();
2208   }                                              2157   }
2209   else {                                         2158   else {
2210     return "none";                               2159     return "none";
2211   }                                              2160   }
2212 }                                                2161 }
2213                                                  2162 
2214 void G4VisCommandViewerUpdate::SetNewValue (G    2163 void G4VisCommandViewerUpdate::SetNewValue (G4UIcommand*, G4String newValue) {
2215                                                  2164 
2216   G4VisManager::Verbosity verbosity = fpVisMa    2165   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2217                                                  2166 
2218   G4String& updateName = newValue;               2167   G4String& updateName = newValue;
2219                                                  2168 
2220   G4VViewer* viewer = fpVisManager -> GetView    2169   G4VViewer* viewer = fpVisManager -> GetViewer (updateName);
2221   if (!viewer) {                                 2170   if (!viewer) {
2222     if (verbosity >= G4VisManager::errors) {     2171     if (verbosity >= G4VisManager::errors) {
2223       G4warn <<                               << 2172       G4cout <<
2224   "WARNING: command \"/vis/viewer/update\" co    2173   "WARNING: command \"/vis/viewer/update\" could not be applied: no current viewer."
2225        << G4endl;                                2174        << G4endl;
2226     }                                            2175     }
2227     return;                                      2176     return;
2228   }                                              2177   }
2229                                                  2178 
2230   G4VSceneHandler* sceneHandler = viewer->Get    2179   G4VSceneHandler* sceneHandler = viewer->GetSceneHandler();
2231   if (!sceneHandler) {                           2180   if (!sceneHandler) {
2232     if (verbosity >= G4VisManager::errors) {     2181     if (verbosity >= G4VisManager::errors) {
2233       G4warn << "ERROR: Viewer \"" << updateN << 2182       G4cerr << "ERROR: Viewer \"" << updateName << "\"" <<
2234   " has no scene handler - report serious bug    2183   " has no scene handler - report serious bug."
2235        << G4endl;                                2184        << G4endl;
2236     }                                            2185     }
2237     return;                                      2186     return;
2238   }                                              2187   }
2239                                                  2188 
2240   G4Scene* scene = sceneHandler->GetScene();     2189   G4Scene* scene = sceneHandler->GetScene();
2241   if (!scene) {                                  2190   if (!scene) {
2242     if (verbosity >= G4VisManager::confirmati    2191     if (verbosity >= G4VisManager::confirmations) {
2243       G4cout << "NOTE: SceneHandler \"" << sc    2192       G4cout << "NOTE: SceneHandler \"" << sceneHandler->GetName()
2244        << "\", to which viewer \"" << updateN    2193        << "\", to which viewer \"" << updateName << "\"" <<
2245   "\n  is attached, has no scene - \"/vis/sce    2194   "\n  is attached, has no scene - \"/vis/scene/create\" and"
2246   " \"/vis/sceneHandler/attach\""                2195   " \"/vis/sceneHandler/attach\""
2247   "\n  (or use compound command \"/vis/drawVo    2196   "\n  (or use compound command \"/vis/drawVolume\")."
2248        << G4endl;                                2197        << G4endl;
2249     }                                            2198     }
2250     return;                                      2199     return;
2251   }                                              2200   }
2252                                                  2201 
2253   if (verbosity >= G4VisManager::confirmation    2202   if (verbosity >= G4VisManager::confirmations) {
2254     G4cout << "Viewer \"" << viewer -> GetNam    2203     G4cout << "Viewer \"" << viewer -> GetName () << "\"";
2255     G4cout << " post-processing triggered." <    2204     G4cout << " post-processing triggered." << G4endl;
2256   }                                              2205   }
2257   viewer -> ShowView ();                         2206   viewer -> ShowView ();
2258   // Assume future need to "refresh" transien    2207   // Assume future need to "refresh" transients...
2259   sceneHandler -> SetMarkForClearingTransient    2208   sceneHandler -> SetMarkForClearingTransientStore(true);
2260 }                                                2209 }
2261                                                  2210 
2262 ////////////// /vis/viewer/zoom and zoomTo //    2211 ////////////// /vis/viewer/zoom and zoomTo ////////////////////////////
2263                                                  2212 
2264 G4VisCommandViewerZoom::G4VisCommandViewerZoo    2213 G4VisCommandViewerZoom::G4VisCommandViewerZoom ():
2265   fZoomMultiplier (1.),                          2214   fZoomMultiplier (1.),
2266   fZoomTo         (1.)                           2215   fZoomTo         (1.)
2267 {                                                2216 {
2268   G4bool omitable, currentAsDefault;             2217   G4bool omitable, currentAsDefault;
2269                                                  2218 
2270   fpCommandZoom = new G4UIcmdWithADouble         2219   fpCommandZoom = new G4UIcmdWithADouble
2271     ("/vis/viewer/zoom", this);                  2220     ("/vis/viewer/zoom", this);
2272   fpCommandZoom -> SetGuidance ("Incremental     2221   fpCommandZoom -> SetGuidance ("Incremental zoom.");
2273   fpCommandZoom -> SetGuidance                   2222   fpCommandZoom -> SetGuidance
2274     ("Multiplies current magnification by thi    2223     ("Multiplies current magnification by this factor.");
2275   fpCommandZoom -> SetParameterName("multipli    2224   fpCommandZoom -> SetParameterName("multiplier",
2276              omitable=true,                      2225              omitable=true,
2277              currentAsDefault=true);             2226              currentAsDefault=true);
2278                                                  2227 
2279   fpCommandZoomTo = new G4UIcmdWithADouble       2228   fpCommandZoomTo = new G4UIcmdWithADouble
2280     ("/vis/viewer/zoomTo", this);                2229     ("/vis/viewer/zoomTo", this);
2281   fpCommandZoomTo -> SetGuidance ("Absolute z    2230   fpCommandZoomTo -> SetGuidance ("Absolute zoom.");
2282   fpCommandZoomTo -> SetGuidance                 2231   fpCommandZoomTo -> SetGuidance
2283     ("Magnifies standard magnification by thi    2232     ("Magnifies standard magnification by this factor.");
2284   fpCommandZoomTo -> SetParameterName("factor    2233   fpCommandZoomTo -> SetParameterName("factor",
2285                omitable=true,                    2234                omitable=true,
2286                currentAsDefault=true);           2235                currentAsDefault=true);
2287 }                                                2236 }
2288                                                  2237 
2289 G4VisCommandViewerZoom::~G4VisCommandViewerZo    2238 G4VisCommandViewerZoom::~G4VisCommandViewerZoom () {
2290   delete fpCommandZoom;                          2239   delete fpCommandZoom;
2291   delete fpCommandZoomTo;                        2240   delete fpCommandZoomTo;
2292 }                                                2241 }
2293                                                  2242 
2294 G4String G4VisCommandViewerZoom::GetCurrentVa    2243 G4String G4VisCommandViewerZoom::GetCurrentValue (G4UIcommand* command) {
2295   G4String currentValue;                         2244   G4String currentValue;
2296   if (command == fpCommandZoom) {                2245   if (command == fpCommandZoom) {
2297     currentValue = fpCommandZoom->ConvertToSt    2246     currentValue = fpCommandZoom->ConvertToString(fZoomMultiplier);
2298   }                                              2247   }
2299   else if (command == fpCommandZoomTo) {         2248   else if (command == fpCommandZoomTo) {
2300     currentValue = fpCommandZoomTo->ConvertTo    2249     currentValue = fpCommandZoomTo->ConvertToString(fZoomTo);
2301   }                                              2250   }
2302   return currentValue;                           2251   return currentValue;
2303 }                                                2252 }
2304                                                  2253 
2305 void G4VisCommandViewerZoom::SetNewValue (G4U    2254 void G4VisCommandViewerZoom::SetNewValue (G4UIcommand* command,
2306             G4String newValue) {                 2255             G4String newValue) {
2307                                                  2256 
2308                                                  2257 
2309   G4VisManager::Verbosity verbosity = fpVisMa    2258   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2310                                                  2259 
2311   G4VViewer* currentViewer = fpVisManager->Ge    2260   G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
2312   if (!currentViewer) {                          2261   if (!currentViewer) {
2313     if (verbosity >= G4VisManager::errors) {     2262     if (verbosity >= G4VisManager::errors) {
2314       G4warn <<                               << 2263       G4cerr <<
2315   "ERROR: G4VisCommandsViewerZoom::SetNewValu    2264   "ERROR: G4VisCommandsViewerZoom::SetNewValue: no current viewer."
2316        << G4endl;                                2265        << G4endl;
2317     }                                            2266     }
2318     return;                                      2267     return;
2319   }                                              2268   }
2320                                                  2269 
2321   G4ViewParameters vp = currentViewer->GetVie    2270   G4ViewParameters vp = currentViewer->GetViewParameters();
2322                                                  2271 
2323   if (command == fpCommandZoom) {                2272   if (command == fpCommandZoom) {
2324     fZoomMultiplier = fpCommandZoom->GetNewDo    2273     fZoomMultiplier = fpCommandZoom->GetNewDoubleValue(newValue);
2325     vp.MultiplyZoomFactor(fZoomMultiplier);      2274     vp.MultiplyZoomFactor(fZoomMultiplier);
2326   }                                              2275   }
2327   else if (command == fpCommandZoomTo) {         2276   else if (command == fpCommandZoomTo) {
2328     fZoomTo = fpCommandZoom->GetNewDoubleValu    2277     fZoomTo = fpCommandZoom->GetNewDoubleValue(newValue);
2329     vp.SetZoomFactor(fZoomTo);                   2278     vp.SetZoomFactor(fZoomTo);
2330   }                                              2279   }
2331                                                  2280 
2332   if (verbosity >= G4VisManager::confirmation    2281   if (verbosity >= G4VisManager::confirmations) {
2333     G4cout << "Zoom factor changed to " << vp    2282     G4cout << "Zoom factor changed to " << vp.GetZoomFactor() << G4endl;
2334   }                                              2283   }
2335                                                  2284 
2336   SetViewParameters(currentViewer, vp);          2285   SetViewParameters(currentViewer, vp);
2337 }                                                2286 }
2338                                                  2287