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 9.2.p4)


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