Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/management/src/G4VisCommandsSceneAdd.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/G4VisCommandsSceneAdd.cc (Version 11.3.0) and /visualization/management/src/G4VisCommandsSceneAdd.cc (Version 10.4.p2)


  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: G4VisCommandsSceneAdd.cc 104163 2017-05-15 06:52:42Z gcosmo $
 27 // /vis/scene/add commands - John Allison  9th     28 // /vis/scene/add commands - John Allison  9th August 1998
 28                                                    29 
 29 #include "G4VisCommandsSceneAdd.hh"                30 #include "G4VisCommandsSceneAdd.hh"
 30                                                    31 
 31 #include "G4TransportationManager.hh"              32 #include "G4TransportationManager.hh"
 32 #include "G4LogicalVolumeStore.hh"                 33 #include "G4LogicalVolumeStore.hh"
 33 #include "G4PhysicalVolumeModel.hh"                34 #include "G4PhysicalVolumeModel.hh"
 34 #include "G4LogicalVolumeModel.hh"                 35 #include "G4LogicalVolumeModel.hh"
 35 #include "G4ModelingParameters.hh"                 36 #include "G4ModelingParameters.hh"
 36 #include "G4HitsModel.hh"                          37 #include "G4HitsModel.hh"
 37 #include "G4DigiModel.hh"                          38 #include "G4DigiModel.hh"
 38 #include "G4GPSModel.hh"                           39 #include "G4GPSModel.hh"
 39 #include "G4ElectricFieldModel.hh"             << 
 40 #include "G4MagneticFieldModel.hh"                 40 #include "G4MagneticFieldModel.hh"
 41 #include "G4PSHitsModel.hh"                        41 #include "G4PSHitsModel.hh"
 42 #include "G4TrajectoriesModel.hh"                  42 #include "G4TrajectoriesModel.hh"
                                                   >>  43 #include "G4ScaleModel.hh"
 43 #include "G4TextModel.hh"                          44 #include "G4TextModel.hh"
 44 #include "G4ArrowModel.hh"                         45 #include "G4ArrowModel.hh"
 45 #include "G4AxesModel.hh"                          46 #include "G4AxesModel.hh"
 46 #include "G4PlotterModel.hh"                   <<  47 #include "G4PhysicalVolumeSearchScene.hh"
 47 #include "G4PhysicalVolumesSearchScene.hh"     << 
 48 #include "G4ParticleTable.hh"                      48 #include "G4ParticleTable.hh"
 49 #include "G4ParticleDefinition.hh"                 49 #include "G4ParticleDefinition.hh"
 50 #include "G4ApplicationState.hh"                   50 #include "G4ApplicationState.hh"
 51 #include "G4VUserVisAction.hh"                     51 #include "G4VUserVisAction.hh"
 52 #include "G4CallbackModel.hh"                      52 #include "G4CallbackModel.hh"
 53 #include "G4UnionSolid.hh"                         53 #include "G4UnionSolid.hh"
 54 #include "G4SubtractionSolid.hh"                   54 #include "G4SubtractionSolid.hh"
 55 #include "G4Polyhedron.hh"                         55 #include "G4Polyhedron.hh"
 56 #include "G4UImanager.hh"                          56 #include "G4UImanager.hh"
 57 #include "G4UIcommandTree.hh"                  << 
 58 #include "G4UIcommand.hh"                          57 #include "G4UIcommand.hh"
 59 #include "G4UIcmdWithAString.hh"                   58 #include "G4UIcmdWithAString.hh"
 60 #include "G4UIcmdWithoutParameter.hh"              59 #include "G4UIcmdWithoutParameter.hh"
 61 #include "G4UIcmdWithAnInteger.hh"                 60 #include "G4UIcmdWithAnInteger.hh"
 62 #include "G4Tokenizer.hh"                          61 #include "G4Tokenizer.hh"
 63 #include "G4RunManager.hh"                         62 #include "G4RunManager.hh"
 64 #include "G4RunManagerFactory.hh"              <<  63 #ifdef G4MULTITHREADED
                                                   >>  64 #include "G4MTRunManager.hh"
                                                   >>  65 #endif
 65 #include "G4StateManager.hh"                       66 #include "G4StateManager.hh"
 66 #include "G4Run.hh"                                67 #include "G4Run.hh"
 67 #include "G4Event.hh"                              68 #include "G4Event.hh"
 68 #include "G4Trajectory.hh"                         69 #include "G4Trajectory.hh"
 69 #include "G4TrajectoryPoint.hh"                    70 #include "G4TrajectoryPoint.hh"
 70 #include "G4RichTrajectory.hh"                     71 #include "G4RichTrajectory.hh"
 71 #include "G4RichTrajectoryPoint.hh"                72 #include "G4RichTrajectoryPoint.hh"
 72 #include "G4SmoothTrajectory.hh"                   73 #include "G4SmoothTrajectory.hh"
 73 #include "G4SmoothTrajectoryPoint.hh"              74 #include "G4SmoothTrajectoryPoint.hh"
 74 #include "G4AttDef.hh"                             75 #include "G4AttDef.hh"
 75 #include "G4AttCheck.hh"                           76 #include "G4AttCheck.hh"
 76 #include "G4Polyline.hh"                           77 #include "G4Polyline.hh"
 77 #include "G4UnitsTable.hh"                         78 #include "G4UnitsTable.hh"
 78 #include "G4PhysicalConstants.hh"                  79 #include "G4PhysicalConstants.hh"
 79 #include "G4SystemOfUnits.hh"                      80 #include "G4SystemOfUnits.hh"
 80 #include "G4GeneralParticleSourceData.hh"          81 #include "G4GeneralParticleSourceData.hh"
 81 #include "G4PlotterManager.hh"                 << 
 82                                                    82 
 83 #include <sstream>                                 83 #include <sstream>
 84                                                    84 
 85 #define G4warn G4cout                          <<  85 // Local function with some frequently used error printing...
                                                   >>  86 static void G4VisCommandsSceneAddUnsuccessful
                                                   >>  87 (G4VisManager::Verbosity verbosity) {
                                                   >>  88   if (verbosity >= G4VisManager::warnings) {
                                                   >>  89     G4cout <<
                                                   >>  90       "WARNING: For some reason, possibly mentioned above, it has not been"
                                                   >>  91       "\n  possible to add to the scene."
                                                   >>  92      << G4endl;
                                                   >>  93   }
                                                   >>  94 }
 86                                                    95 
 87 ////////////// /vis/scene/add/arrow //////////     96 ////////////// /vis/scene/add/arrow ///////////////////////////////////////
 88                                                    97 
 89 G4VisCommandSceneAddArrow::G4VisCommandSceneAd     98 G4VisCommandSceneAddArrow::G4VisCommandSceneAddArrow () {
 90   fpCommand = new G4UIcommand("/vis/scene/add/     99   fpCommand = new G4UIcommand("/vis/scene/add/arrow", this);
 91   fpCommand -> SetGuidance ("Adds arrow to cur    100   fpCommand -> SetGuidance ("Adds arrow to current scene.");
 92   G4bool omitable;                                101   G4bool omitable;
 93   G4UIparameter* parameter;                       102   G4UIparameter* parameter;
 94   parameter = new G4UIparameter ("x1", 'd', om    103   parameter = new G4UIparameter ("x1", 'd', omitable = false);
 95   fpCommand -> SetParameter (parameter);          104   fpCommand -> SetParameter (parameter);
 96   parameter = new G4UIparameter ("y1", 'd', om    105   parameter = new G4UIparameter ("y1", 'd', omitable = false);
 97   fpCommand -> SetParameter (parameter);          106   fpCommand -> SetParameter (parameter);
 98   parameter = new G4UIparameter ("z1", 'd', om    107   parameter = new G4UIparameter ("z1", 'd', omitable = false);
 99   fpCommand -> SetParameter (parameter);          108   fpCommand -> SetParameter (parameter);
100   parameter = new G4UIparameter ("x2", 'd', om    109   parameter = new G4UIparameter ("x2", 'd', omitable = false);
101   fpCommand -> SetParameter (parameter);          110   fpCommand -> SetParameter (parameter);
102   parameter = new G4UIparameter ("y2", 'd', om    111   parameter = new G4UIparameter ("y2", 'd', omitable = false);
103   fpCommand -> SetParameter (parameter);          112   fpCommand -> SetParameter (parameter);
104   parameter = new G4UIparameter ("z2", 'd', om    113   parameter = new G4UIparameter ("z2", 'd', omitable = false);
105   fpCommand -> SetParameter (parameter);          114   fpCommand -> SetParameter (parameter);
106   parameter =  new G4UIparameter ("unit", 's',    115   parameter =  new G4UIparameter ("unit", 's', omitable = true);
107   parameter->SetDefaultValue ("m");               116   parameter->SetDefaultValue ("m");
108   fpCommand->SetParameter    (parameter);         117   fpCommand->SetParameter    (parameter);
109 }                                                 118 }
110                                                   119 
111 G4VisCommandSceneAddArrow::~G4VisCommandSceneA    120 G4VisCommandSceneAddArrow::~G4VisCommandSceneAddArrow () {
112   delete fpCommand;                               121   delete fpCommand;
113 }                                                 122 }
114                                                   123 
115 G4String G4VisCommandSceneAddArrow::GetCurrent    124 G4String G4VisCommandSceneAddArrow::GetCurrentValue (G4UIcommand*) {
116   return "";                                      125   return "";
117 }                                                 126 }
118                                                   127 
119 void G4VisCommandSceneAddArrow::SetNewValue (G    128 void G4VisCommandSceneAddArrow::SetNewValue (G4UIcommand*, G4String newValue)
120 {                                                 129 {
121   G4VisManager::Verbosity verbosity = fpVisMan    130   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
122   G4bool warn(verbosity >= G4VisManager::warni    131   G4bool warn(verbosity >= G4VisManager::warnings);
123                                                   132 
124   G4Scene* pScene = fpVisManager->GetCurrentSc    133   G4Scene* pScene = fpVisManager->GetCurrentScene();
125   if (!pScene) {                                  134   if (!pScene) {
126     if (verbosity >= G4VisManager::errors) {      135     if (verbosity >= G4VisManager::errors) {
127       G4warn << "ERROR: No current scene.  Ple << 136       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
128     }                                             137     }
129     return;                                       138     return;
130   }                                               139   }
131                                                   140 
132   G4String unitString;                            141   G4String unitString;
133   G4double x1, y1, z1, x2, y2, z2;                142   G4double x1, y1, z1, x2, y2, z2;
134   std::istringstream is(newValue);                143   std::istringstream is(newValue);
135   is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> un    144   is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> unitString;
136   G4double unit = G4UIcommand::ValueOf(unitStr    145   G4double unit = G4UIcommand::ValueOf(unitString);
137   x1 *= unit; y1 *= unit; z1 *= unit;             146   x1 *= unit; y1 *= unit; z1 *= unit;
138   x2 *= unit; y2 *= unit; z2 *= unit;             147   x2 *= unit; y2 *= unit; z2 *= unit;
139                                                   148 
140   // Consult scene for arrow width.               149   // Consult scene for arrow width.
141   const G4VisExtent& sceneExtent = pScene->Get    150   const G4VisExtent& sceneExtent = pScene->GetExtent();
142   G4double arrowWidth =                           151   G4double arrowWidth =
143     0.005 * fCurrentLineWidth * sceneExtent.Ge    152     0.005 * fCurrentLineWidth * sceneExtent.GetExtentRadius();
144                                                   153 
145   G4VModel* model = new G4ArrowModel              154   G4VModel* model = new G4ArrowModel
146     (x1, y1, z1, x2, y2, z2,                      155     (x1, y1, z1, x2, y2, z2,
147      arrowWidth, fCurrentColour, newValue,        156      arrowWidth, fCurrentColour, newValue,
148      fCurrentArrow3DLineSegmentsPerCircle);       157      fCurrentArrow3DLineSegmentsPerCircle);
149                                                   158 
150   const G4String& currentSceneName = pScene ->    159   const G4String& currentSceneName = pScene -> GetName ();
151   G4bool successful = pScene -> AddRunDuration    160   G4bool successful = pScene -> AddRunDurationModel (model, warn);
152   if (successful) {                               161   if (successful) {
153     if (verbosity >= G4VisManager::confirmatio    162     if (verbosity >= G4VisManager::confirmations) {
154       G4cout << "Arrow has been added to scene    163       G4cout << "Arrow has been added to scene \""
155        << currentSceneName << "\"."               164        << currentSceneName << "\"."
156        << G4endl;                                 165        << G4endl;
157     }                                             166     }
158   }                                               167   }
159   else G4VisCommandsSceneAddUnsuccessful(verbo    168   else G4VisCommandsSceneAddUnsuccessful(verbosity);
160                                                << 169   UpdateVisManagerScene (currentSceneName);
161   CheckSceneAndNotifyHandlers (pScene);        << 
162 }                                                 170 }
163                                                   171 
164 ////////////// /vis/scene/add/arrow2D ////////    172 ////////////// /vis/scene/add/arrow2D ///////////////////////////////////////
165                                                   173 
166 G4VisCommandSceneAddArrow2D::G4VisCommandScene    174 G4VisCommandSceneAddArrow2D::G4VisCommandSceneAddArrow2D () {
167   fpCommand = new G4UIcommand("/vis/scene/add/    175   fpCommand = new G4UIcommand("/vis/scene/add/arrow2D", this);
168   fpCommand -> SetGuidance ("Adds 2D arrow to     176   fpCommand -> SetGuidance ("Adds 2D arrow to current scene.");
169   fpCommand -> SetGuidance ("x,y in range [-1, << 
170   G4bool omitable;                                177   G4bool omitable;
171   G4UIparameter* parameter;                       178   G4UIparameter* parameter;
172   parameter = new G4UIparameter ("x1", 'd', om    179   parameter = new G4UIparameter ("x1", 'd', omitable = false);
173   fpCommand -> SetParameter (parameter);          180   fpCommand -> SetParameter (parameter);
174   parameter = new G4UIparameter ("y1", 'd', om    181   parameter = new G4UIparameter ("y1", 'd', omitable = false);
175   fpCommand -> SetParameter (parameter);          182   fpCommand -> SetParameter (parameter);
176   parameter = new G4UIparameter ("x2", 'd', om    183   parameter = new G4UIparameter ("x2", 'd', omitable = false);
177   fpCommand -> SetParameter (parameter);          184   fpCommand -> SetParameter (parameter);
178   parameter = new G4UIparameter ("y2", 'd', om    185   parameter = new G4UIparameter ("y2", 'd', omitable = false);
179   fpCommand -> SetParameter (parameter);          186   fpCommand -> SetParameter (parameter);
180 }                                                 187 }
181                                                   188 
182 G4VisCommandSceneAddArrow2D::~G4VisCommandScen    189 G4VisCommandSceneAddArrow2D::~G4VisCommandSceneAddArrow2D () {
183   delete fpCommand;                               190   delete fpCommand;
184 }                                                 191 }
185                                                   192 
186 G4String G4VisCommandSceneAddArrow2D::GetCurre    193 G4String G4VisCommandSceneAddArrow2D::GetCurrentValue (G4UIcommand*) {
187   return "";                                      194   return "";
188 }                                                 195 }
189                                                   196 
190 void G4VisCommandSceneAddArrow2D::SetNewValue     197 void G4VisCommandSceneAddArrow2D::SetNewValue (G4UIcommand*, G4String newValue)
191 {                                                 198 {
192   G4VisManager::Verbosity verbosity = fpVisMan    199   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
193   G4bool warn(verbosity >= G4VisManager::warni    200   G4bool warn(verbosity >= G4VisManager::warnings);
194                                                   201 
195   G4Scene* pScene = fpVisManager->GetCurrentSc    202   G4Scene* pScene = fpVisManager->GetCurrentScene();
196   if (!pScene) {                                  203   if (!pScene) {
197     if (verbosity >= G4VisManager::errors) {      204     if (verbosity >= G4VisManager::errors) {
198       G4warn << "ERROR: No current scene.  Ple << 205       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
199     }                                             206     }
200     return;                                       207     return;
201   }                                               208   }
202                                                   209 
203   G4double x1, y1, x2, y2;                        210   G4double x1, y1, x2, y2;
204   std::istringstream is(newValue);                211   std::istringstream is(newValue);
205   is >> x1 >> y1 >> x2 >> y2;                     212   is >> x1 >> y1 >> x2 >> y2;
206                                                   213 
207   Arrow2D* arrow2D = new Arrow2D                  214   Arrow2D* arrow2D = new Arrow2D
208     (x1, y1, x2, y2, fCurrentLineWidth, fCurre    215     (x1, y1, x2, y2, fCurrentLineWidth, fCurrentColour);
209   G4VModel* model =                               216   G4VModel* model =
210     new G4CallbackModel<G4VisCommandSceneAddAr    217     new G4CallbackModel<G4VisCommandSceneAddArrow2D::Arrow2D>(arrow2D);
211   model->SetType("Arrow2D");                      218   model->SetType("Arrow2D");
212   model->SetGlobalTag("Arrow2D");                 219   model->SetGlobalTag("Arrow2D");
213   model->SetGlobalDescription("Arrow2D: " + ne    220   model->SetGlobalDescription("Arrow2D: " + newValue);
214   const G4String& currentSceneName = pScene ->    221   const G4String& currentSceneName = pScene -> GetName ();
215   G4bool successful = pScene -> AddRunDuration    222   G4bool successful = pScene -> AddRunDurationModel (model, warn);
216   if (successful) {                               223   if (successful) {
217     if (verbosity >= G4VisManager::confirmatio    224     if (verbosity >= G4VisManager::confirmations) {
218       G4cout << "A 2D arrow has been added to     225       G4cout << "A 2D arrow has been added to scene \""
219        << currentSceneName << "\"."               226        << currentSceneName << "\"."
220        << G4endl;                                 227        << G4endl;
221     }                                             228     }
222   }                                               229   }
223   else G4VisCommandsSceneAddUnsuccessful(verbo    230   else G4VisCommandsSceneAddUnsuccessful(verbosity);
224                                                << 231   UpdateVisManagerScene (currentSceneName);
225   CheckSceneAndNotifyHandlers (pScene);        << 
226 }                                                 232 }
227                                                   233 
228 G4VisCommandSceneAddArrow2D::Arrow2D::Arrow2D     234 G4VisCommandSceneAddArrow2D::Arrow2D::Arrow2D
229 (G4double x1, G4double y1,                        235 (G4double x1, G4double y1,
230  G4double x2, G4double y2,                        236  G4double x2, G4double y2,
231  G4double width, const G4Colour& colour):         237  G4double width, const G4Colour& colour):
232   fWidth(width), fColour(colour)                  238   fWidth(width), fColour(colour)
233 {                                                 239 {
234   fShaftPolyline.push_back(G4Point3D(x1,y1,0))    240   fShaftPolyline.push_back(G4Point3D(x1,y1,0));
235   fShaftPolyline.push_back(G4Point3D(x2,y2,0))    241   fShaftPolyline.push_back(G4Point3D(x2,y2,0));
236   G4Vector3D arrowDirection = G4Vector3D(x2-x1    242   G4Vector3D arrowDirection = G4Vector3D(x2-x1,y2-y1,0).unit();
237   G4Vector3D arrowPointLeftDirection(arrowDire    243   G4Vector3D arrowPointLeftDirection(arrowDirection);
238   arrowPointLeftDirection.rotateZ(150.*deg);      244   arrowPointLeftDirection.rotateZ(150.*deg);
239   G4Vector3D arrowPointRightDirection(arrowDir    245   G4Vector3D arrowPointRightDirection(arrowDirection);
240   arrowPointRightDirection.rotateZ(-150.*deg);    246   arrowPointRightDirection.rotateZ(-150.*deg);
241   fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0    247   fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0.04*arrowPointLeftDirection);
242   fHeadPolyline.push_back(G4Point3D(x2,y2,0));    248   fHeadPolyline.push_back(G4Point3D(x2,y2,0));
243   fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0    249   fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0.04*arrowPointRightDirection);
244   G4VisAttributes va;                             250   G4VisAttributes va;
245   va.SetLineWidth(fWidth);                        251   va.SetLineWidth(fWidth);
246   va.SetColour(fColour);                          252   va.SetColour(fColour);
247   fShaftPolyline.SetVisAttributes(va);            253   fShaftPolyline.SetVisAttributes(va);
248   fHeadPolyline.SetVisAttributes(va);             254   fHeadPolyline.SetVisAttributes(va);
249 }                                                 255 }
250                                                   256 
251 void G4VisCommandSceneAddArrow2D::Arrow2D::ope    257 void G4VisCommandSceneAddArrow2D::Arrow2D::operator()
252   (G4VGraphicsScene& sceneHandler, const G4Mod << 258   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
253 {                                                 259 {
254   sceneHandler.BeginPrimitives2D();               260   sceneHandler.BeginPrimitives2D();
255   sceneHandler.AddPrimitive(fShaftPolyline);      261   sceneHandler.AddPrimitive(fShaftPolyline);
256   sceneHandler.AddPrimitive(fHeadPolyline);       262   sceneHandler.AddPrimitive(fHeadPolyline);
257   sceneHandler.EndPrimitives2D();                 263   sceneHandler.EndPrimitives2D();
258 }                                                 264 }
259                                                   265 
260 ////////////// /vis/scene/add/axes ///////////    266 ////////////// /vis/scene/add/axes //////////////////////////////////
261                                                   267 
262 G4VisCommandSceneAddAxes::G4VisCommandSceneAdd    268 G4VisCommandSceneAddAxes::G4VisCommandSceneAddAxes () {
263   G4bool omitable;                                269   G4bool omitable;
264   fpCommand = new G4UIcommand ("/vis/scene/add    270   fpCommand = new G4UIcommand ("/vis/scene/add/axes", this);
265   fpCommand -> SetGuidance ("Add axes.");         271   fpCommand -> SetGuidance ("Add axes.");
266   fpCommand -> SetGuidance                        272   fpCommand -> SetGuidance
267   ("Draws axes at (x0, y0, z0) of given length    273   ("Draws axes at (x0, y0, z0) of given length and colour.");
268   fpCommand -> SetGuidance                        274   fpCommand -> SetGuidance
269   ("If \"colour-string\" is \"auto\", x, y and    275   ("If \"colour-string\" is \"auto\", x, y and z will be red, green and blue"
270    "\n  respectively.  Otherwise it can be one    276    "\n  respectively.  Otherwise it can be one of the pre-defined text-specified"
271    "\n  colours - see information printed by t    277    "\n  colours - see information printed by the vis manager at start-up or"
272    "\n  use \"/vis/list\".");                     278    "\n  use \"/vis/list\".");
273   fpCommand -> SetGuidance                        279   fpCommand -> SetGuidance
274   ("If \"length\" is negative, it is set to ab    280   ("If \"length\" is negative, it is set to about 25% of scene extent.");
275   fpCommand -> SetGuidance                        281   fpCommand -> SetGuidance
276   ("If \"showtext\" is false, annotations are     282   ("If \"showtext\" is false, annotations are suppressed.");
277   G4UIparameter* parameter;                       283   G4UIparameter* parameter;
278   parameter =  new G4UIparameter ("x0", 'd', o    284   parameter =  new G4UIparameter ("x0", 'd', omitable = true);
279   parameter->SetDefaultValue (0.);                285   parameter->SetDefaultValue (0.);
280   fpCommand->SetParameter (parameter);            286   fpCommand->SetParameter (parameter);
281   parameter =  new G4UIparameter ("y0", 'd', o    287   parameter =  new G4UIparameter ("y0", 'd', omitable = true);
282   parameter->SetDefaultValue (0.);                288   parameter->SetDefaultValue (0.);
283   fpCommand->SetParameter (parameter);            289   fpCommand->SetParameter (parameter);
284   parameter =  new G4UIparameter ("z0", 'd', o    290   parameter =  new G4UIparameter ("z0", 'd', omitable = true);
285   parameter->SetDefaultValue (0.);                291   parameter->SetDefaultValue (0.);
286   fpCommand->SetParameter (parameter);            292   fpCommand->SetParameter (parameter);
287   parameter =  new G4UIparameter ("length", 'd    293   parameter =  new G4UIparameter ("length", 'd', omitable = true);
288   parameter->SetDefaultValue (-1.);               294   parameter->SetDefaultValue (-1.);
289   fpCommand->SetParameter (parameter);            295   fpCommand->SetParameter (parameter);
290   parameter =  new G4UIparameter ("unit", 's',    296   parameter =  new G4UIparameter ("unit", 's', omitable = true);
291   parameter->SetDefaultValue ("m");               297   parameter->SetDefaultValue ("m");
292   fpCommand->SetParameter (parameter);            298   fpCommand->SetParameter (parameter);
293   parameter =  new G4UIparameter ("colour-stri    299   parameter =  new G4UIparameter ("colour-string", 's', omitable = true);
294   parameter->SetDefaultValue  ("auto");           300   parameter->SetDefaultValue  ("auto");
295   fpCommand->SetParameter (parameter);            301   fpCommand->SetParameter (parameter);
296   parameter =  new G4UIparameter ("showtext",     302   parameter =  new G4UIparameter ("showtext", 'b', omitable = true);
297   parameter->SetDefaultValue  ("true");           303   parameter->SetDefaultValue  ("true");
298   fpCommand->SetParameter (parameter);            304   fpCommand->SetParameter (parameter);
299 }                                                 305 }
300                                                   306 
301 G4VisCommandSceneAddAxes::~G4VisCommandSceneAd    307 G4VisCommandSceneAddAxes::~G4VisCommandSceneAddAxes () {
302   delete fpCommand;                               308   delete fpCommand;
303 }                                                 309 }
304                                                   310 
305 G4String G4VisCommandSceneAddAxes::GetCurrentV    311 G4String G4VisCommandSceneAddAxes::GetCurrentValue (G4UIcommand*) {
306   return "";                                      312   return "";
307 }                                                 313 }
308                                                   314 
309 void G4VisCommandSceneAddAxes::SetNewValue (G4    315 void G4VisCommandSceneAddAxes::SetNewValue (G4UIcommand*, G4String newValue) {
310                                                   316 
311   G4VisManager::Verbosity verbosity = fpVisMan    317   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
312   G4bool warn(verbosity >= G4VisManager::warni    318   G4bool warn(verbosity >= G4VisManager::warnings);
313                                                   319 
314   G4Scene* pScene = fpVisManager->GetCurrentSc    320   G4Scene* pScene = fpVisManager->GetCurrentScene();
315   if (!pScene) {                                  321   if (!pScene) {
316     if (verbosity >= G4VisManager::errors) {      322     if (verbosity >= G4VisManager::errors) {
317       G4warn << "ERROR: No current scene.  Ple << 323       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
318     }                                             324     }
319     return;                                       325     return;
320   } else {                                        326   } else {
321     if (pScene->GetExtent().GetExtentRadius()     327     if (pScene->GetExtent().GetExtentRadius() <= 0.) {
322       if (verbosity >= G4VisManager::errors) {    328       if (verbosity >= G4VisManager::errors) {
323         G4warn                                 << 329         G4cerr
324   << "ERROR: Scene has no extent. Add volumes     330   << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
325         << G4endl;                                331         << G4endl;
326       }                                           332       }
327       return;                                     333       return;
328     }                                             334     }
329   }                                               335   }
330                                                   336 
331   G4String unitString, colourString, showTextS    337   G4String unitString, colourString, showTextString;
332   G4double x0, y0, z0, length;                    338   G4double x0, y0, z0, length;
333   std::istringstream is (newValue);               339   std::istringstream is (newValue);
334   is >> x0 >> y0 >> z0 >> length >> unitString    340   is >> x0 >> y0 >> z0 >> length >> unitString
335   >> colourString >> showTextString;              341   >> colourString >> showTextString;
336   G4bool showText = G4UIcommand::ConvertToBool    342   G4bool showText = G4UIcommand::ConvertToBool(showTextString);
337                                                   343 
338                                                   344 
339   G4double unit = G4UIcommand::ValueOf(unitStr    345   G4double unit = G4UIcommand::ValueOf(unitString);
340   x0 *= unit; y0 *= unit; z0 *= unit;             346   x0 *= unit; y0 *= unit; z0 *= unit;
341   const G4VisExtent& sceneExtent = pScene->Get    347   const G4VisExtent& sceneExtent = pScene->GetExtent();  // Existing extent.
342   if (length < 0.) {                              348   if (length < 0.) {
343     const G4double lengthMax = 0.5 * sceneExte    349     const G4double lengthMax = 0.5 * sceneExtent.GetExtentRadius();
344     const G4double intLog10Length = std::floor    350     const G4double intLog10Length = std::floor(std::log10(lengthMax));
345     length = std::pow(10,intLog10Length);         351     length = std::pow(10,intLog10Length);
346     if (5.*length < lengthMax) length *= 5.;      352     if (5.*length < lengthMax) length *= 5.;
347     else if (2.*length < lengthMax) length *=     353     else if (2.*length < lengthMax) length *= 2.;
348   } else {                                        354   } else {
349     length *= unit;                               355     length *= unit;
350   }                                               356   }
351                                                   357 
352   // Consult scene for arrow width...             358   // Consult scene for arrow width...
353   G4double arrowWidth =                           359   G4double arrowWidth =
354     0.05 * fCurrentLineWidth * sceneExtent.Get << 360     0.005 * fCurrentLineWidth * sceneExtent.GetExtentRadius();
355   // ...but limit it to length/30.             << 361   // ...but limit it to length/50.
356   if (arrowWidth > length/30.) arrowWidth = le << 362   if (arrowWidth > length/50.) arrowWidth = length/50.;
357                                                   363 
358   G4VModel* model = new G4AxesModel               364   G4VModel* model = new G4AxesModel
359     (x0, y0, z0, length, arrowWidth, colourStr    365     (x0, y0, z0, length, arrowWidth, colourString, newValue,
360      showText, fCurrentTextSize);                 366      showText, fCurrentTextSize);
361                                                   367 
362   G4bool successful = pScene -> AddRunDuration    368   G4bool successful = pScene -> AddRunDurationModel (model, warn);
363   const G4String& currentSceneName = pScene ->    369   const G4String& currentSceneName = pScene -> GetName ();
364   if (successful) {                               370   if (successful) {
365     if (verbosity >= G4VisManager::confirmatio    371     if (verbosity >= G4VisManager::confirmations) {
366       G4cout << "Axes of length " << G4BestUni    372       G4cout << "Axes of length " << G4BestUnit(length,"Length")
367       << "have been added to scene \"" << curr    373       << "have been added to scene \"" << currentSceneName << "\"."
368       << G4endl;                                  374       << G4endl;
369     }                                             375     }
370   }                                               376   }
371   else G4VisCommandsSceneAddUnsuccessful(verbo    377   else G4VisCommandsSceneAddUnsuccessful(verbosity);
372                                                << 378   UpdateVisManagerScene (currentSceneName);
373   CheckSceneAndNotifyHandlers (pScene);        << 
374 }                                                 379 }
375                                                   380 
376 ////////////// /vis/scene/add/date ///////////    381 ////////////// /vis/scene/add/date ///////////////////////////////////////
377                                                   382 
378 G4VisCommandSceneAddDate::G4VisCommandSceneAdd    383 G4VisCommandSceneAddDate::G4VisCommandSceneAddDate () {
379   G4bool omitable;                                384   G4bool omitable;
380   fpCommand = new G4UIcommand ("/vis/scene/add    385   fpCommand = new G4UIcommand ("/vis/scene/add/date", this);
381   fpCommand -> SetGuidance ("Adds date to curr    386   fpCommand -> SetGuidance ("Adds date to current scene.");
382   fpCommand -> SetGuidance                        387   fpCommand -> SetGuidance
383   ("If \"date\"is omitted, the current date an    388   ("If \"date\"is omitted, the current date and time is drawn."
384    "\nOtherwise, the string, including the res    389    "\nOtherwise, the string, including the rest of the line, is drawn.");
385   G4UIparameter* parameter;                       390   G4UIparameter* parameter;
386   parameter = new G4UIparameter ("size", 'i',     391   parameter = new G4UIparameter ("size", 'i', omitable = true);
387   parameter -> SetGuidance ("Screen size of te    392   parameter -> SetGuidance ("Screen size of text in pixels.");
388   parameter -> SetDefaultValue (18);              393   parameter -> SetDefaultValue (18);
389   fpCommand -> SetParameter (parameter);          394   fpCommand -> SetParameter (parameter);
390   parameter = new G4UIparameter ("x-position",    395   parameter = new G4UIparameter ("x-position", 'd', omitable = true);
391   parameter -> SetGuidance ("x screen position    396   parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
392   parameter -> SetDefaultValue (0.95);            397   parameter -> SetDefaultValue (0.95);
393   fpCommand -> SetParameter (parameter);          398   fpCommand -> SetParameter (parameter);
394   parameter = new G4UIparameter ("y-position",    399   parameter = new G4UIparameter ("y-position", 'd', omitable = true);
395   parameter -> SetGuidance ("y screen position    400   parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
396   parameter -> SetDefaultValue (0.9);             401   parameter -> SetDefaultValue (0.9);
397   fpCommand -> SetParameter (parameter);          402   fpCommand -> SetParameter (parameter);
398   parameter = new G4UIparameter ("layout", 's'    403   parameter = new G4UIparameter ("layout", 's', omitable = true);
399   parameter -> SetGuidance ("Layout, i.e., adj    404   parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
400   parameter -> SetDefaultValue ("right");         405   parameter -> SetDefaultValue ("right");
401   fpCommand -> SetParameter (parameter);          406   fpCommand -> SetParameter (parameter);
402   parameter = new G4UIparameter ("date", 's',     407   parameter = new G4UIparameter ("date", 's', omitable = true);
403   parameter -> SetDefaultValue ("-");             408   parameter -> SetDefaultValue ("-");
404   fpCommand -> SetParameter (parameter);          409   fpCommand -> SetParameter (parameter);
405 }                                                 410 }
406                                                   411 
407 G4VisCommandSceneAddDate::~G4VisCommandSceneAd    412 G4VisCommandSceneAddDate::~G4VisCommandSceneAddDate () {
408   delete fpCommand;                               413   delete fpCommand;
409 }                                                 414 }
410                                                   415 
411 G4String G4VisCommandSceneAddDate::GetCurrentV    416 G4String G4VisCommandSceneAddDate::GetCurrentValue (G4UIcommand*) {
412   return "";                                      417   return "";
413 }                                                 418 }
414                                                   419 
415 void G4VisCommandSceneAddDate::SetNewValue (G4    420 void G4VisCommandSceneAddDate::SetNewValue (G4UIcommand*, G4String newValue)
416 {                                                 421 {
417   G4VisManager::Verbosity verbosity = fpVisMan    422   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
418   G4bool warn(verbosity >= G4VisManager::warni    423   G4bool warn(verbosity >= G4VisManager::warnings);
419                                                   424 
420   G4Scene* pScene = fpVisManager->GetCurrentSc    425   G4Scene* pScene = fpVisManager->GetCurrentScene();
421   if (!pScene) {                                  426   if (!pScene) {
422     if (verbosity >= G4VisManager::errors) {      427     if (verbosity >= G4VisManager::errors) {
423       G4warn << "ERROR: No current scene.  Ple << 428       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
424     }                                             429     }
425     return;                                       430     return;
426   }                                               431   }
427                                                   432 
428   G4int size;                                     433   G4int size;
429   G4double x, y;                                  434   G4double x, y;
430   G4String layoutString, dateString;              435   G4String layoutString, dateString;
431   std::istringstream is(newValue);                436   std::istringstream is(newValue);
432   is >> size >> x >> y >> layoutString >> date    437   is >> size >> x >> y >> layoutString >> dateString;
433   // Read rest of line, if any.                   438   // Read rest of line, if any.
434   const size_t NREMAINDER = 100;                  439   const size_t NREMAINDER = 100;
435   char remainder[NREMAINDER];                     440   char remainder[NREMAINDER];
436   remainder[0]='\0';  // In case there is noth    441   remainder[0]='\0';  // In case there is nothing remaining.
437   is.getline(remainder, NREMAINDER);              442   is.getline(remainder, NREMAINDER);
438   dateString += remainder;                        443   dateString += remainder;
439   G4Text::Layout layout = G4Text::right;          444   G4Text::Layout layout = G4Text::right;
440   if (layoutString[0] == 'l') layout = G4Text: << 445   if (layoutString(0) == 'l') layout = G4Text::left;
441   else if (layoutString[0] == 'c') layout = G4 << 446   else if (layoutString(0) == 'c') layout = G4Text::centre;
442   else if (layoutString[0] == 'r') layout = G4 << 447   else if (layoutString(0) == 'r') layout = G4Text::right;
443                                                   448 
444   Date* date = new Date(fpVisManager, size, x,    449   Date* date = new Date(fpVisManager, size, x, y, layout, dateString);
445   G4VModel* model =                               450   G4VModel* model =
446     new G4CallbackModel<G4VisCommandSceneAddDa    451     new G4CallbackModel<G4VisCommandSceneAddDate::Date>(date);
447   model->SetType("Date");                         452   model->SetType("Date");
448   model->SetGlobalTag("Date");                    453   model->SetGlobalTag("Date");
449   model->SetGlobalDescription("Date: " + newVa << 454   model->SetGlobalDescription("Date");
450   const G4String& currentSceneName = pScene ->    455   const G4String& currentSceneName = pScene -> GetName ();
451   G4bool successful = pScene -> AddEndOfEventM << 456   G4bool successful = pScene -> AddRunDurationModel (model, warn);
452   if (successful) {                               457   if (successful) {
453     if (verbosity >= G4VisManager::confirmatio    458     if (verbosity >= G4VisManager::confirmations) {
454       G4cout << "Date has been added to scene     459       G4cout << "Date has been added to scene \""
455        << currentSceneName << "\"."               460        << currentSceneName << "\"."
456        << G4endl;                                 461        << G4endl;
457     }                                             462     }
458   }                                               463   }
459   else G4VisCommandsSceneAddUnsuccessful(verbo    464   else G4VisCommandsSceneAddUnsuccessful(verbosity);
460                                                << 465   UpdateVisManagerScene (currentSceneName);
461   CheckSceneAndNotifyHandlers (pScene);        << 
462 }                                                 466 }
463                                                   467 
464 void G4VisCommandSceneAddDate::Date::operator(    468 void G4VisCommandSceneAddDate::Date::operator()
465   (G4VGraphicsScene& sceneHandler, const G4Mod << 469   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
466 {                                                 470 {
467   G4String time;                                  471   G4String time;
468   if (fDate == "-") {                             472   if (fDate == "-") {
469     time = fTimer.GetClockTime();                 473     time = fTimer.GetClockTime();
470   } else {                                        474   } else {
471     time = fDate;                                 475     time = fDate;
472   }                                               476   }
473   // Check for \n, starting from back, and era    477   // Check for \n, starting from back, and erase.
474   std::string::size_type i = time.rfind('\n');    478   std::string::size_type i = time.rfind('\n');
475   if (i != std::string::npos) time.erase(i);      479   if (i != std::string::npos) time.erase(i);
476   G4Text text(time, G4Point3D(fX, fY, 0.));       480   G4Text text(time, G4Point3D(fX, fY, 0.));
477   text.SetScreenSize(fSize);                      481   text.SetScreenSize(fSize);
478   text.SetLayout(fLayout);                        482   text.SetLayout(fLayout);
479   G4VisAttributes textAtts(G4Colour(0.,1.,1));    483   G4VisAttributes textAtts(G4Colour(0.,1.,1));
480   text.SetVisAttributes(textAtts);                484   text.SetVisAttributes(textAtts);
481   sceneHandler.BeginPrimitives2D();               485   sceneHandler.BeginPrimitives2D();
482   sceneHandler.AddPrimitive(text);                486   sceneHandler.AddPrimitive(text);
483   sceneHandler.EndPrimitives2D();                 487   sceneHandler.EndPrimitives2D();
484 }                                                 488 }
485                                                   489 
486 ////////////// /vis/scene/add/digis //////////    490 ////////////// /vis/scene/add/digis ///////////////////////////////////////
487                                                   491 
488 G4VisCommandSceneAddDigis::G4VisCommandSceneAd    492 G4VisCommandSceneAddDigis::G4VisCommandSceneAddDigis () {
489   fpCommand = new G4UIcmdWithoutParameter ("/v    493   fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/add/digis", this);
490   fpCommand -> SetGuidance ("Adds digis to cur    494   fpCommand -> SetGuidance ("Adds digis to current scene.");
491   fpCommand -> SetGuidance                        495   fpCommand -> SetGuidance
492     ("Digis are drawn at end of event when the    496     ("Digis are drawn at end of event when the scene in which"
493      "\nthey are added is current.");             497      "\nthey are added is current.");
494 }                                                 498 }
495                                                   499 
496 G4VisCommandSceneAddDigis::~G4VisCommandSceneA    500 G4VisCommandSceneAddDigis::~G4VisCommandSceneAddDigis () {
497   delete fpCommand;                               501   delete fpCommand;
498 }                                                 502 }
499                                                   503 
500 G4String G4VisCommandSceneAddDigis::GetCurrent    504 G4String G4VisCommandSceneAddDigis::GetCurrentValue (G4UIcommand*) {
501   return "";                                      505   return "";
502 }                                                 506 }
503                                                   507 
504 void G4VisCommandSceneAddDigis::SetNewValue (G    508 void G4VisCommandSceneAddDigis::SetNewValue (G4UIcommand*, G4String) {
505                                                   509 
506   G4VisManager::Verbosity verbosity = fpVisMan    510   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
507   G4bool warn(verbosity >= G4VisManager::warni    511   G4bool warn(verbosity >= G4VisManager::warnings);
508                                                   512 
509   G4Scene* pScene = fpVisManager->GetCurrentSc    513   G4Scene* pScene = fpVisManager->GetCurrentScene();
510   if (!pScene) {                                  514   if (!pScene) {
511     if (verbosity >= G4VisManager::errors) {      515     if (verbosity >= G4VisManager::errors) {
512       G4warn << "ERROR: No current scene.  Ple << 516       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
513     }                                             517     }
514     return;                                       518     return;
515   }                                               519   }
516                                                   520 
517   G4VModel* model = new G4DigiModel;              521   G4VModel* model = new G4DigiModel;
518   const G4String& currentSceneName = pScene ->    522   const G4String& currentSceneName = pScene -> GetName ();
519   G4bool successful = pScene -> AddEndOfEventM    523   G4bool successful = pScene -> AddEndOfEventModel (model, warn);
520   if (successful) {                               524   if (successful) {
521     if (verbosity >= G4VisManager::confirmatio    525     if (verbosity >= G4VisManager::confirmations) {
522       G4cout << "Digis, if any, will be drawn     526       G4cout << "Digis, if any, will be drawn at end of run in scene \""
523        << currentSceneName << "\"."               527        << currentSceneName << "\"."
524        << G4endl;                                 528        << G4endl;
525     }                                             529     }
526   }                                               530   }
527   else G4VisCommandsSceneAddUnsuccessful(verbo    531   else G4VisCommandsSceneAddUnsuccessful(verbosity);
528                                                << 532   UpdateVisManagerScene (currentSceneName);
529   CheckSceneAndNotifyHandlers (pScene);        << 
530 }                                              << 
531                                                << 
532 ////////////// /vis/scene/add/electricField // << 
533                                                << 
534 G4VisCommandSceneAddElectricField::G4VisComman << 
535   G4bool omitable;                             << 
536   fpCommand = new G4UIcommand ("/vis/scene/add << 
537   fpCommand -> SetGuidance                     << 
538   ("Adds electric field representation to curr << 
539   fpCommand -> SetGuidance                     << 
540   ("The first parameter is no. of data points  << 
541    "\nmaximum, the number of data points sampl << 
542    "\nlarge--be warned!"                       << 
543    "\nThe default value is 10, i.e., a 21x21x2 << 
544    "\nThat may swamp your view, but usually, a << 
545    "\nthe extent, so it's not a problem. But i << 
546    "\nyou can do:"                             << 
547    "\n- reduce the number of data points per h << 
548    "\n- specify \"lightArrow\" (second paramet << 
549    "\n- restrict the region sampled with \"/vi << 
550    "\n- restrict the drawing to a specific vol << 
551    "\n    \"/vis/set/volumeForField\" or \"/vi << 
552    "\nNote: you might have to deactivate exist << 
553    "\n  \"/vis/scene/activateModel Field false << 
554    "\n  \"/vis/scene/add/...Field\" command ag << 
555   fpCommand -> SetGuidance                     << 
556   ("In the arrow representation, the length of << 
557    "\nto the magnitude of the field and the co << 
558    "\nas a fraction of the maximum magnitude:  << 
559   G4UIparameter* parameter;                    << 
560   parameter = new G4UIparameter ("nDataPointsP << 
561   parameter -> SetDefaultValue (10);           << 
562   fpCommand -> SetParameter (parameter);       << 
563   parameter = new G4UIparameter ("representati << 
564   parameter -> SetParameterCandidates("fullArr << 
565   parameter -> SetDefaultValue ("fullArrow");  << 
566   fpCommand -> SetParameter (parameter);       << 
567 }                                              << 
568                                                << 
569 G4VisCommandSceneAddElectricField::~G4VisComma << 
570   delete fpCommand;                            << 
571 }                                              << 
572                                                << 
573 G4String G4VisCommandSceneAddElectricField::Ge << 
574   return "";                                   << 
575 }                                              << 
576                                                << 
577 void G4VisCommandSceneAddElectricField::SetNew << 
578 (G4UIcommand*, G4String newValue) {            << 
579                                                << 
580   G4VisManager::Verbosity verbosity = fpVisMan << 
581   G4bool warn(verbosity >= G4VisManager::warni << 
582                                                << 
583   G4Scene* pScene = fpVisManager->GetCurrentSc << 
584   if (!pScene) {                               << 
585     if (verbosity >= G4VisManager::errors) {   << 
586       G4warn <<  "ERROR: No current scene.  Pl << 
587     }                                          << 
588     return;                                    << 
589   }                                            << 
590                                                << 
591   G4int nDataPointsPerHalfExtent;              << 
592   G4String representation;                     << 
593   std::istringstream iss(newValue);            << 
594   iss >> nDataPointsPerHalfExtent >> represent << 
595   G4ElectricFieldModel::Representation         << 
596   modelRepresentation = G4ElectricFieldModel:: << 
597   if (representation == "lightArrow") {        << 
598     modelRepresentation = G4ElectricFieldModel << 
599   }                                            << 
600   G4VModel* model;                             << 
601   model = new G4ElectricFieldModel             << 
602   (nDataPointsPerHalfExtent,modelRepresentatio << 
603    fCurrentArrow3DLineSegmentsPerCircle,       << 
604    fCurrentExtentForField,                     << 
605    fCurrrentPVFindingsForField);               << 
606   const G4String& currentSceneName = pScene -> << 
607   G4bool successful = pScene -> AddRunDuration << 
608   if (successful) {                            << 
609     if (verbosity >= G4VisManager::confirmatio << 
610       G4cout                                   << 
611       << "Electric field, if any, will be draw << 
612       << currentSceneName                      << 
613       << "\"\n  with "                         << 
614       << nDataPointsPerHalfExtent              << 
615       << " data points per half extent and wit << 
616       << representation                        << 
617       << '\"'                                  << 
618       << G4endl;                               << 
619     }                                          << 
620   }                                            << 
621   else G4VisCommandsSceneAddUnsuccessful(verbo << 
622                                                << 
623   CheckSceneAndNotifyHandlers (pScene);        << 
624 }                                                 533 }
625                                                   534 
626 ////////////// /vis/scene/add/eventID ////////    535 ////////////// /vis/scene/add/eventID ///////////////////////////////////////
627                                                   536 
628 G4VisCommandSceneAddEventID::G4VisCommandScene    537 G4VisCommandSceneAddEventID::G4VisCommandSceneAddEventID () {
629   G4bool omitable;                                538   G4bool omitable;
630   fpCommand = new G4UIcommand ("/vis/scene/add    539   fpCommand = new G4UIcommand ("/vis/scene/add/eventID", this);
631   fpCommand -> SetGuidance ("Adds eventID to c    540   fpCommand -> SetGuidance ("Adds eventID to current scene.");
632   fpCommand -> SetGuidance                        541   fpCommand -> SetGuidance
633     ("Run and event numbers are drawn at end o    542     ("Run and event numbers are drawn at end of event or run when"
634      "\n the scene in which they are added is     543      "\n the scene in which they are added is current.");
635   G4UIparameter* parameter;                       544   G4UIparameter* parameter;
636   parameter = new G4UIparameter ("size", 'i',     545   parameter = new G4UIparameter ("size", 'i', omitable = true);
637   parameter -> SetGuidance ("Screen size of te    546   parameter -> SetGuidance ("Screen size of text in pixels.");
638   parameter -> SetDefaultValue (18);              547   parameter -> SetDefaultValue (18);
639   fpCommand -> SetParameter (parameter);          548   fpCommand -> SetParameter (parameter);
640   parameter = new G4UIparameter ("x-position",    549   parameter = new G4UIparameter ("x-position", 'd', omitable = true);
641   parameter -> SetGuidance ("x screen position    550   parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
642   parameter -> SetDefaultValue (-0.95);           551   parameter -> SetDefaultValue (-0.95);
643   fpCommand -> SetParameter (parameter);          552   fpCommand -> SetParameter (parameter);
644   parameter = new G4UIparameter ("y-position",    553   parameter = new G4UIparameter ("y-position", 'd', omitable = true);
645   parameter -> SetGuidance ("y screen position    554   parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
646   parameter -> SetDefaultValue (0.9);             555   parameter -> SetDefaultValue (0.9);
647   fpCommand -> SetParameter (parameter);          556   fpCommand -> SetParameter (parameter);
648   parameter = new G4UIparameter ("layout", 's'    557   parameter = new G4UIparameter ("layout", 's', omitable = true);
649   parameter -> SetGuidance ("Layout, i.e., adj    558   parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
650   parameter -> SetDefaultValue ("left");          559   parameter -> SetDefaultValue ("left");
651   fpCommand -> SetParameter (parameter);          560   fpCommand -> SetParameter (parameter);
652 }                                                 561 }
653                                                   562 
654 G4VisCommandSceneAddEventID::~G4VisCommandScen    563 G4VisCommandSceneAddEventID::~G4VisCommandSceneAddEventID () {
655   delete fpCommand;                               564   delete fpCommand;
656 }                                                 565 }
657                                                   566 
658 G4String G4VisCommandSceneAddEventID::GetCurre    567 G4String G4VisCommandSceneAddEventID::GetCurrentValue (G4UIcommand*) {
659   return "";                                      568   return "";
660 }                                                 569 }
661                                                   570 
662 void G4VisCommandSceneAddEventID::SetNewValue     571 void G4VisCommandSceneAddEventID::SetNewValue (G4UIcommand*, G4String newValue)
663 {                                                 572 {
664   G4VisManager::Verbosity verbosity = fpVisMan    573   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
665   G4bool warn(verbosity >= G4VisManager::warni    574   G4bool warn(verbosity >= G4VisManager::warnings);
666                                                   575 
667   G4Scene* pScene = fpVisManager->GetCurrentSc    576   G4Scene* pScene = fpVisManager->GetCurrentScene();
668   if (!pScene) {                                  577   if (!pScene) {
669     if (verbosity >= G4VisManager::errors) {      578     if (verbosity >= G4VisManager::errors) {
670       G4warn << "ERROR: No current scene.  Ple << 579       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
671     }                                             580     }
672     return;                                       581     return;
673   }                                               582   }
674                                                   583 
675   G4int size;                                     584   G4int size;
676   G4double x, y;                                  585   G4double x, y;
677   G4String layoutString;                          586   G4String layoutString;
678   std::istringstream is(newValue);                587   std::istringstream is(newValue);
679   is >> size >> x >> y >> layoutString;           588   is >> size >> x >> y >> layoutString;
680                                                   589 
681   G4Text::Layout layout = G4Text::right;          590   G4Text::Layout layout = G4Text::right;
682   if (layoutString[0] == 'l') layout = G4Text: << 591   if (layoutString(0) == 'l') layout = G4Text::left;
683   else if (layoutString[0] == 'c') layout = G4 << 592   else if (layoutString(0) == 'c') layout = G4Text::centre;
684   else if (layoutString[0] == 'r') layout = G4 << 593   else if (layoutString(0) == 'r') layout = G4Text::right;
685                                                << 
686   // For End of Event (only for reviewing kept << 
687   EventID* eoeEventID                          << 
688   = new EventID(forEndOfEvent, fpVisManager, s << 
689   G4VModel* eoeModel =                         << 
690     new G4CallbackModel<G4VisCommandSceneAddEv << 
691   eoeModel->SetType("EoEEventID");             << 
692   eoeModel->SetGlobalTag("EoEEventID");        << 
693   eoeModel->SetGlobalDescription("EoEEventID:  << 
694   G4bool successfulEoE = pScene -> AddEndOfEve << 
695                                                << 
696   // For End of Run                            << 
697   EventID* eorEventID                          << 
698   = new EventID(forEndOfRun, fpVisManager, siz << 
699   G4VModel* eorModel =                         << 
700   new G4CallbackModel<G4VisCommandSceneAddEven << 
701   eorModel->SetType("EoREventID");             << 
702   eorModel->SetGlobalTag("EoREventID");        << 
703   eorModel->SetGlobalDescription("EoREventID:  << 
704   G4bool successfulEoR = pScene -> AddEndOfRun << 
705                                                   594 
706   if (successfulEoE && successfulEoR) {        << 595   EventID* eventID = new EventID(fpVisManager, size, x, y, layout);
                                                   >> 596   G4VModel* model =
                                                   >> 597     new G4CallbackModel<G4VisCommandSceneAddEventID::EventID>(eventID);
                                                   >> 598   model->SetType("EventID");
                                                   >> 599   model->SetGlobalTag("EventID");
                                                   >> 600   model->SetGlobalDescription("EventID");
                                                   >> 601   const G4String& currentSceneName = pScene -> GetName ();
                                                   >> 602   G4bool successful = pScene -> AddEndOfEventModel (model, warn);
                                                   >> 603   if (successful) {
707     if (verbosity >= G4VisManager::confirmatio    604     if (verbosity >= G4VisManager::confirmations) {
708       const G4String& currentSceneName = pScen << 
709       G4cout << "EventID has been added to sce    605       G4cout << "EventID has been added to scene \""
710       << currentSceneName << "\"."             << 606        << currentSceneName << "\"."
711       << G4endl;                               << 607        << G4endl;
712     }                                             608     }
713   }                                               609   }
714   else G4VisCommandsSceneAddUnsuccessful(verbo    610   else G4VisCommandsSceneAddUnsuccessful(verbosity);
715                                                << 611   UpdateVisManagerScene (currentSceneName);
716   CheckSceneAndNotifyHandlers (pScene);        << 
717 }                                                 612 }
718                                                   613 
719 void G4VisCommandSceneAddEventID::EventID::ope    614 void G4VisCommandSceneAddEventID::EventID::operator()
720 (G4VGraphicsScene& sceneHandler, const G4Model << 615   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
721 {                                                 616 {
722   G4RunManager* runManager = G4RunManagerFacto << 617   const G4Run* currentRun = 0;
723   if(!runManager)                              << 618   G4RunManager* runManager = G4RunManager::GetRunManager();
724     return;                                    << 619 #ifdef G4MULTITHREADED
725                                                << 620   if (G4Threading::IsMultithreadedApplication()) {
726   const G4Run* currentRun = runManager->GetCur << 621     runManager = G4MTRunManager::GetMasterRunManager();
727   if (!currentRun) return;                     << 622   }
728                                                << 623 #endif
729   const G4int currentRunID = currentRun->GetRu << 624   if (runManager) currentRun = runManager->GetCurrentRun();
730                                                << 625 
731   std::ostringstream oss;                      << 626   G4VModel* model = fpVisManager->GetCurrentSceneHandler()->GetModel();
732   switch (fForWhat) {                          << 627   const G4ModelingParameters* mp = 0;
733     case forEndOfEvent:                        << 628   const G4Event* currentEvent = 0;
734     {                                          << 629   if (model) {
735       // Only use if reviewing kept events     << 630    mp = model->GetModelingParameters();
736       if (!fpVisManager->GetReviewingKeptEvent << 631    currentEvent = mp->GetEvent();
737       const G4Event* currentEvent = mp->GetEve << 632   } else {
738       if (!currentEvent) return;               << 633     G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
739       G4int eventID = currentEvent->GetEventID << 634     if (verbosity >= G4VisManager::errors) {
740       oss << "Run " << currentRunID << " Event << 635       G4cerr << "ERROR: No model defined for this SceneHandler : "
741       break;                                   << 636        << fpVisManager->GetCurrentSceneHandler()->GetName()
                                                   >> 637        << G4endl;
742     }                                             638     }
743     case forEndOfRun:                          << 639   }
744     {                                          << 640   if (currentRun && currentEvent) {
745       // Only use if NOT reviewing kept events << 641     G4int runID = currentRun->GetRunID();
746       if (fpVisManager->GetReviewingKeptEvents << 642     G4int eventID = currentEvent->GetEventID();
747       const G4int nEvents = currentRun->GetNum << 643     std::ostringstream oss;
748       size_t nKeptEvents = (size_t)(currentRun << 644     if (fpVisManager->GetCurrentScene()->GetRefreshAtEndOfEvent()) {
749       oss << "Run " << currentRunID << " (" << << 645       oss << "Run " << runID << " Event " << eventID;
                                                   >> 646     } else {
                                                   >> 647       G4int nEvents = 0;
                                                   >> 648 #ifdef G4MULTITHREADED
                                                   >> 649       if (G4Threading::G4GetThreadId() != G4Threading::MASTER_ID) {
                                                   >> 650         // Vis sub-thread - run in progress
                                                   >> 651 #else
                                                   >> 652       G4StateManager* stateManager = G4StateManager::GetStateManager();
                                                   >> 653       G4ApplicationState state = stateManager->GetCurrentState();
                                                   >> 654       if (state == G4State_EventProc) {
                                                   >> 655         // Run in progress
                                                   >> 656 #endif
                                                   >> 657         nEvents = currentRun->GetNumberOfEventToBeProcessed();
                                                   >> 658       } else {
                                                   >> 659         // Rebuilding from kept events
                                                   >> 660         const std::vector<const G4Event*>* events =
                                                   >> 661         currentRun->GetEventVector();
                                                   >> 662         if (events) nEvents = events->size();
                                                   >> 663       }
                                                   >> 664 #ifndef G4MULTITHREADED
                                                   >> 665       // In sequential mode we can recognise the last event and avoid
                                                   >> 666       // drawing the event ID.  But for MT mode there is no way of
                                                   >> 667       // knowing so we have to accept that the event ID will be drawn
                                                   >> 668       // at each event, the same characters over and over - but hey!
                                                   >> 669       if (eventID < nEvents - 1) return;  // Not last event.
                                                   >> 670 #endif
                                                   >> 671       oss << "Run " << runID << " (" << nEvents << " event";
750       if (nEvents != 1) oss << 's';               672       if (nEvents != 1) oss << 's';
751       oss << ", " << nKeptEvents << " kept)";  << 673       oss << ')';
752       break;                                   << 
753     }                                             674     }
754     default:                                   << 675     G4Text text(oss.str(), G4Point3D(fX, fY, 0.));
755       return;                                  << 676     text.SetScreenSize(fSize);
                                                   >> 677     text.SetLayout(fLayout);
                                                   >> 678     G4VisAttributes textAtts(G4Colour(0.,1.,1));
                                                   >> 679     text.SetVisAttributes(textAtts);
                                                   >> 680     sceneHandler.BeginPrimitives2D();
                                                   >> 681     sceneHandler.AddPrimitive(text);
                                                   >> 682     sceneHandler.EndPrimitives2D();
756   }                                               683   }
757                                                << 
758   G4Text text(oss.str(), G4Point3D(fX, fY, 0.) << 
759   text.SetScreenSize(fSize);                   << 
760   text.SetLayout(fLayout);                     << 
761   G4VisAttributes textAtts(G4Colour(0.,1.,1)); << 
762   text.SetVisAttributes(textAtts);             << 
763   sceneHandler.BeginPrimitives2D();            << 
764   sceneHandler.AddPrimitive(text);             << 
765   sceneHandler.EndPrimitives2D();              << 
766 }                                                 684 }
767                                                   685 
768 ////////////// /vis/scene/add/extent /////////    686 ////////////// /vis/scene/add/extent ///////////////////////////////////////
769                                                   687 
770 G4VisCommandSceneAddExtent::G4VisCommandSceneA    688 G4VisCommandSceneAddExtent::G4VisCommandSceneAddExtent () {
771   fpCommand = new G4UIcommand("/vis/scene/add/    689   fpCommand = new G4UIcommand("/vis/scene/add/extent", this);
772   fpCommand -> SetGuidance                        690   fpCommand -> SetGuidance
773   ("Adds a dummy model with given extent to th    691   ("Adds a dummy model with given extent to the current scene."
774    "\nRequires the limits: xmin, xmax, ymin, y    692    "\nRequires the limits: xmin, xmax, ymin, ymax, zmin, zmax unit."
775    "\nThis can be used to provide an extent to    693    "\nThis can be used to provide an extent to the scene even if"
776    "\nno other models with extent are availabl    694    "\nno other models with extent are available. For example,"
777    "\neven if there is no geometry.  In that c    695    "\neven if there is no geometry.  In that case, for example:"
778    "\n  /vis/open OGL"                            696    "\n  /vis/open OGL"
779    "\n  /vis/scene/create"                        697    "\n  /vis/scene/create"
780    "\n  /vis/scene/add/extent -300 300 -300 30    698    "\n  /vis/scene/add/extent -300 300 -300 300 -300 300 cm"
781    "\n  /vis/sceneHandler/attach");               699    "\n  /vis/sceneHandler/attach");
782   G4bool omitable;                                700   G4bool omitable;
783   G4UIparameter* parameter;                       701   G4UIparameter* parameter;
784   parameter = new G4UIparameter ("xmin", 'd',     702   parameter = new G4UIparameter ("xmin", 'd', omitable = true);
785   parameter -> SetDefaultValue (0.);              703   parameter -> SetDefaultValue (0.);
786   fpCommand -> SetParameter (parameter);          704   fpCommand -> SetParameter (parameter);
787   parameter = new G4UIparameter ("xmax", 'd',     705   parameter = new G4UIparameter ("xmax", 'd', omitable = true);
788   parameter -> SetDefaultValue (0.);              706   parameter -> SetDefaultValue (0.);
789   fpCommand -> SetParameter (parameter);          707   fpCommand -> SetParameter (parameter);
790   parameter = new G4UIparameter ("ymin", 'd',     708   parameter = new G4UIparameter ("ymin", 'd', omitable = true);
791   parameter -> SetDefaultValue (0.);              709   parameter -> SetDefaultValue (0.);
792   fpCommand -> SetParameter (parameter);          710   fpCommand -> SetParameter (parameter);
793   parameter = new G4UIparameter ("ymax", 'd',     711   parameter = new G4UIparameter ("ymax", 'd', omitable = true);
794   parameter -> SetDefaultValue (0.);              712   parameter -> SetDefaultValue (0.);
795   fpCommand -> SetParameter (parameter);          713   fpCommand -> SetParameter (parameter);
796   parameter = new G4UIparameter ("zmin", 'd',     714   parameter = new G4UIparameter ("zmin", 'd', omitable = true);
797   parameter -> SetDefaultValue (0.);              715   parameter -> SetDefaultValue (0.);
798   fpCommand -> SetParameter (parameter);          716   fpCommand -> SetParameter (parameter);
799   parameter = new G4UIparameter ("zmax", 'd',     717   parameter = new G4UIparameter ("zmax", 'd', omitable = true);
800   parameter -> SetDefaultValue (0.);              718   parameter -> SetDefaultValue (0.);
801   fpCommand -> SetParameter (parameter);          719   fpCommand -> SetParameter (parameter);
802   parameter =  new G4UIparameter ("unit", 's',    720   parameter =  new G4UIparameter ("unit", 's', omitable = true);
803   parameter -> SetDefaultValue ("m");             721   parameter -> SetDefaultValue ("m");
804   fpCommand -> SetParameter (parameter);          722   fpCommand -> SetParameter (parameter);
805 }                                                 723 }
806                                                   724 
807 G4VisCommandSceneAddExtent::~G4VisCommandScene    725 G4VisCommandSceneAddExtent::~G4VisCommandSceneAddExtent () {
808   delete fpCommand;                               726   delete fpCommand;
809 }                                                 727 }
810                                                   728 
811 G4String G4VisCommandSceneAddExtent::GetCurren    729 G4String G4VisCommandSceneAddExtent::GetCurrentValue (G4UIcommand*) {
812   return "";                                      730   return "";
813 }                                                 731 }
814                                                   732 
815 void G4VisCommandSceneAddExtent::SetNewValue (    733 void G4VisCommandSceneAddExtent::SetNewValue (G4UIcommand*, G4String newValue)
816 {                                                 734 {
817   G4VisManager::Verbosity verbosity = fpVisMan    735   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
818   G4bool warn(verbosity >= G4VisManager::warni    736   G4bool warn(verbosity >= G4VisManager::warnings);
819                                                   737 
820   G4Scene* pScene = fpVisManager->GetCurrentSc    738   G4Scene* pScene = fpVisManager->GetCurrentScene();
821   if (!pScene) {                                  739   if (!pScene) {
822     if (verbosity >= G4VisManager::errors) {      740     if (verbosity >= G4VisManager::errors) {
823       G4warn << "ERROR: No current scene.  Ple << 741       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
824     }                                             742     }
825     return;                                       743     return;
826   }                                               744   }
827                                                   745 
828   G4double xmin, xmax, ymin, ymax, zmin, zmax;    746   G4double xmin, xmax, ymin, ymax, zmin, zmax;
829   G4String unitString;                            747   G4String unitString;
830   std::istringstream is(newValue);                748   std::istringstream is(newValue);
831   is >> xmin >> xmax >> ymin >> ymax >> zmin >    749   is >> xmin >> xmax >> ymin >> ymax >> zmin >> zmax >> unitString;
832   G4double unit = G4UIcommand::ValueOf(unitStr    750   G4double unit = G4UIcommand::ValueOf(unitString);
833   xmin *= unit; xmax *= unit;                     751   xmin *= unit; xmax *= unit;
834   ymin *= unit; ymax *= unit;                     752   ymin *= unit; ymax *= unit;
835   zmin *= unit; zmax *= unit;                     753   zmin *= unit; zmax *= unit;
836                                                   754 
837   G4VisExtent visExtent(xmin, xmax, ymin, ymax    755   G4VisExtent visExtent(xmin, xmax, ymin, ymax, zmin, zmax);
838   Extent* extent = new Extent(xmin, xmax, ymin    756   Extent* extent = new Extent(xmin, xmax, ymin, ymax, zmin, zmax);
839   G4VModel* model =                               757   G4VModel* model =
840   new G4CallbackModel<G4VisCommandSceneAddExte    758   new G4CallbackModel<G4VisCommandSceneAddExtent::Extent>(extent);
841   model->SetType("Extent");                       759   model->SetType("Extent");
842   model->SetGlobalTag("Extent");                  760   model->SetGlobalTag("Extent");
843   model->SetGlobalDescription("Extent: " + new    761   model->SetGlobalDescription("Extent: " + newValue);
844   model->SetExtent(visExtent);                    762   model->SetExtent(visExtent);
845   const G4String& currentSceneName = pScene ->    763   const G4String& currentSceneName = pScene -> GetName ();
846   G4bool successful = pScene -> AddRunDuration    764   G4bool successful = pScene -> AddRunDurationModel (model, warn);
847   if (successful) {                               765   if (successful) {
848     if (verbosity >= G4VisManager::confirmatio    766     if (verbosity >= G4VisManager::confirmations) {
849       G4cout << "A benign model with extent "     767       G4cout << "A benign model with extent "
850       << visExtent                                768       << visExtent
851       << " has been added to scene \""            769       << " has been added to scene \""
852        << currentSceneName << "\"."               770        << currentSceneName << "\"."
853        << G4endl;                                 771        << G4endl;
854     }                                             772     }
855   }                                               773   }
856   else G4VisCommandsSceneAddUnsuccessful(verbo    774   else G4VisCommandsSceneAddUnsuccessful(verbosity);
857                                                << 775   UpdateVisManagerScene (currentSceneName);
858   CheckSceneAndNotifyHandlers (pScene);        << 
859 }                                                 776 }
860                                                   777 
861 G4VisCommandSceneAddExtent::Extent::Extent        778 G4VisCommandSceneAddExtent::Extent::Extent
862 (G4double xmin, G4double xmax,                    779 (G4double xmin, G4double xmax,
863  G4double ymin, G4double ymax,                    780  G4double ymin, G4double ymax,
864  G4double zmin, G4double zmax):                   781  G4double zmin, G4double zmax):
865 fExtent(xmin,xmax,ymin,ymax,zmin,zmax)            782 fExtent(xmin,xmax,ymin,ymax,zmin,zmax)
866 {}                                                783 {}
867                                                   784 
868 void G4VisCommandSceneAddExtent::Extent::opera    785 void G4VisCommandSceneAddExtent::Extent::operator()
869 (G4VGraphicsScene&, const G4ModelingParameters << 786 (G4VGraphicsScene&, const G4Transform3D&)
870 {}                                                787 {}
871                                                   788 
872 ////////////// /vis/scene/add/frame //////////    789 ////////////// /vis/scene/add/frame ///////////////////////////////////////
873                                                   790 
874 G4VisCommandSceneAddFrame::G4VisCommandSceneAd    791 G4VisCommandSceneAddFrame::G4VisCommandSceneAddFrame () {
875   fpCommand = new G4UIcommand("/vis/scene/add/    792   fpCommand = new G4UIcommand("/vis/scene/add/frame", this);
876   fpCommand -> SetGuidance ("Add frame to curr    793   fpCommand -> SetGuidance ("Add frame to current scene.");
877   G4bool omitable;                                794   G4bool omitable;
878   G4UIparameter* parameter;                       795   G4UIparameter* parameter;
879   parameter = new G4UIparameter ("size", 'd',     796   parameter = new G4UIparameter ("size", 'd', omitable = true);
880   parameter -> SetGuidance ("Size of frame.  1    797   parameter -> SetGuidance ("Size of frame.  1 = full window.");
881   parameter -> SetParameterRange ("size > 0 &&    798   parameter -> SetParameterRange ("size > 0 && size <=1");
882   parameter -> SetDefaultValue (0.97);            799   parameter -> SetDefaultValue (0.97);
883   fpCommand -> SetParameter (parameter);          800   fpCommand -> SetParameter (parameter);
884 }                                                 801 }
885                                                   802 
886 G4VisCommandSceneAddFrame::~G4VisCommandSceneA    803 G4VisCommandSceneAddFrame::~G4VisCommandSceneAddFrame () {
887   delete fpCommand;                               804   delete fpCommand;
888 }                                                 805 }
889                                                   806 
890 G4String G4VisCommandSceneAddFrame::GetCurrent    807 G4String G4VisCommandSceneAddFrame::GetCurrentValue (G4UIcommand*) {
891   return "";                                      808   return "";
892 }                                                 809 }
893                                                   810 
894 void G4VisCommandSceneAddFrame::SetNewValue (G    811 void G4VisCommandSceneAddFrame::SetNewValue (G4UIcommand*, G4String newValue)
895 {                                                 812 {
896   G4VisManager::Verbosity verbosity = fpVisMan    813   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
897   G4bool warn(verbosity >= G4VisManager::warni    814   G4bool warn(verbosity >= G4VisManager::warnings);
898                                                   815 
899   G4Scene* pScene = fpVisManager->GetCurrentSc    816   G4Scene* pScene = fpVisManager->GetCurrentScene();
900   if (!pScene) {                                  817   if (!pScene) {
901     if (verbosity >= G4VisManager::errors) {      818     if (verbosity >= G4VisManager::errors) {
902       G4warn << "ERROR: No current scene.  Ple << 819       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
903     }                                             820     }
904     return;                                       821     return;
905   }                                               822   }
906                                                   823 
907   G4double size;                                  824   G4double size;
908   std::istringstream is(newValue);                825   std::istringstream is(newValue);
909   is >> size;                                     826   is >> size;
910                                                   827 
911   Frame* frame = new Frame(size, fCurrentLineW    828   Frame* frame = new Frame(size, fCurrentLineWidth, fCurrentColour);
912   G4VModel* model =                               829   G4VModel* model =
913     new G4CallbackModel<G4VisCommandSceneAddFr    830     new G4CallbackModel<G4VisCommandSceneAddFrame::Frame>(frame);
914   model->SetType("Frame");                        831   model->SetType("Frame");
915   model->SetGlobalTag("Frame");                   832   model->SetGlobalTag("Frame");
916   model->SetGlobalDescription("Frame: " + newV    833   model->SetGlobalDescription("Frame: " + newValue);
917   const G4String& currentSceneName = pScene ->    834   const G4String& currentSceneName = pScene -> GetName ();
918   G4bool successful = pScene -> AddRunDuration    835   G4bool successful = pScene -> AddRunDurationModel (model, warn);
919   if (successful) {                               836   if (successful) {
920     if (verbosity >= G4VisManager::confirmatio    837     if (verbosity >= G4VisManager::confirmations) {
921       G4cout << "Frame has been added to scene    838       G4cout << "Frame has been added to scene \""
922        << currentSceneName << "\"."               839        << currentSceneName << "\"."
923        << G4endl;                                 840        << G4endl;
924     }                                             841     }
925   }                                               842   }
926   else G4VisCommandsSceneAddUnsuccessful(verbo    843   else G4VisCommandsSceneAddUnsuccessful(verbosity);
927                                                << 844   UpdateVisManagerScene (currentSceneName);
928   CheckSceneAndNotifyHandlers (pScene);        << 
929 }                                                 845 }
930                                                   846 
931 void G4VisCommandSceneAddFrame::Frame::operato    847 void G4VisCommandSceneAddFrame::Frame::operator()
932   (G4VGraphicsScene& sceneHandler, const G4Mod << 848   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
933 {                                                 849 {
934   G4Polyline frame;                               850   G4Polyline frame;
935   frame.push_back(G4Point3D( fSize,  fSize, 0.    851   frame.push_back(G4Point3D( fSize,  fSize, 0.));
936   frame.push_back(G4Point3D(-fSize,  fSize, 0.    852   frame.push_back(G4Point3D(-fSize,  fSize, 0.));
937   frame.push_back(G4Point3D(-fSize, -fSize, 0.    853   frame.push_back(G4Point3D(-fSize, -fSize, 0.));
938   frame.push_back(G4Point3D( fSize, -fSize, 0.    854   frame.push_back(G4Point3D( fSize, -fSize, 0.));
939   frame.push_back(G4Point3D( fSize,  fSize, 0.    855   frame.push_back(G4Point3D( fSize,  fSize, 0.));
940   G4VisAttributes va;                             856   G4VisAttributes va;
941   va.SetLineWidth(fWidth);                        857   va.SetLineWidth(fWidth);
942   va.SetColour(fColour);                          858   va.SetColour(fColour);
943   frame.SetVisAttributes(va);                     859   frame.SetVisAttributes(va);
944   sceneHandler.BeginPrimitives2D();               860   sceneHandler.BeginPrimitives2D();
945   sceneHandler.AddPrimitive(frame);               861   sceneHandler.AddPrimitive(frame);
946   sceneHandler.EndPrimitives2D();                 862   sceneHandler.EndPrimitives2D();
947 }                                                 863 }
948                                                   864 
949 ////////////// /vis/scene/add/gps //////////// << 865   ////////////// /vis/scene/add/gps ///////////////////////////////////////
950                                                   866 
951 G4VisCommandSceneAddGPS::G4VisCommandSceneAddG << 867   G4VisCommandSceneAddGPS::G4VisCommandSceneAddGPS () {
952   G4bool omitable;                             << 868     G4bool omitable;
953   G4UIparameter* parameter;                    << 869     G4UIparameter* parameter;
954   fpCommand = new G4UIcommand ("/vis/scene/add << 870     fpCommand = new G4UIcommand ("/vis/scene/add/gps", this);
955   fpCommand -> SetGuidance                     << 871     fpCommand -> SetGuidance
956   ("A representation of the source(s) of the G << 872     ("A representation of the source(s) of the General Particle Source"
957    "\nwill be added to current scene and drawn << 873      "\nwill be added to current scene and drawn, if applicable.");
958   fpCommand->SetGuidance(ConvertToColourGuidan << 874     fpCommand->SetGuidance(ConvertToColourGuidance());
959   fpCommand->SetGuidance("Default: red and tra << 875     fpCommand->SetGuidance("Default: red and transparent.");
960   parameter = new G4UIparameter("red_or_string << 876     parameter = new G4UIparameter("red_or_string", 's', omitable = true);
961   parameter -> SetDefaultValue ("1.");         << 877     parameter -> SetDefaultValue ("1.");
962   fpCommand -> SetParameter (parameter);       << 878     fpCommand -> SetParameter (parameter);
963   parameter = new G4UIparameter("green", 'd',  << 879     parameter = new G4UIparameter("green", 'd', omitable = true);
964   parameter -> SetDefaultValue (0.);           << 880     parameter -> SetDefaultValue (0.);
965   fpCommand -> SetParameter (parameter);       << 881     fpCommand -> SetParameter (parameter);
966   parameter = new G4UIparameter ("blue", 'd',  << 882     parameter = new G4UIparameter ("blue", 'd', omitable = true);
967   parameter -> SetDefaultValue (0.);           << 883     parameter -> SetDefaultValue (0.);
968   fpCommand -> SetParameter (parameter);       << 884     fpCommand -> SetParameter (parameter);
969   parameter = new G4UIparameter ("opacity", 'd << 885     parameter = new G4UIparameter ("opacity", 'd', omitable = true);
970   parameter -> SetDefaultValue (0.3);          << 886     parameter -> SetDefaultValue (0.3);
971   fpCommand -> SetParameter (parameter);       << 887     fpCommand -> SetParameter (parameter);
972 }                                              << 888   }
973                                                << 889 
974 G4VisCommandSceneAddGPS::~G4VisCommandSceneAdd << 890   G4VisCommandSceneAddGPS::~G4VisCommandSceneAddGPS () {
975   delete fpCommand;                            << 891     delete fpCommand;
976 }                                              << 892   }
977                                                << 893 
978 G4String G4VisCommandSceneAddGPS::GetCurrentVa << 894   G4String G4VisCommandSceneAddGPS::GetCurrentValue (G4UIcommand*) {
979   return "";                                   << 895     return "";
980 }                                              << 896   }
981                                                   897 
982 void G4VisCommandSceneAddGPS::SetNewValue (G4U << 898   void G4VisCommandSceneAddGPS::SetNewValue (G4UIcommand*, G4String newValue) {
983                                                   899 
984   G4VisManager::Verbosity verbosity = fpVisMan << 900     G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
985   G4bool warn(verbosity >= G4VisManager::warni << 901     G4bool warn(verbosity >= G4VisManager::warnings);
986                                                   902 
987   G4Scene* pScene = fpVisManager->GetCurrentSc << 903     G4Scene* pScene = fpVisManager->GetCurrentScene();
988   if (!pScene) {                               << 904     if (!pScene) {
989     if (verbosity >= G4VisManager::errors) {   << 905       if (verbosity >= G4VisManager::errors) {
990       G4warn << "ERROR: No current scene.  Ple << 906         G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
                                                   >> 907       }
                                                   >> 908       return;
991     }                                             909     }
992     return;                                    << 
993   }                                            << 
994                                                << 
995   G4String redOrString;                        << 
996   G4double green, blue, opacity;               << 
997   std::istringstream iss(newValue);            << 
998   iss >> redOrString >> green >> blue >> opaci << 
999   G4Colour colour(1.,0.,0.,0.3);  // Default r << 
1000   ConvertToColour(colour, redOrString, green, << 
1001                                                  910 
1002   G4VModel* model = new G4GPSModel(colour);   << 911     G4String redOrString;
1003   const G4String& currentSceneName = pScene - << 912     G4double green, blue, opacity;
1004   G4bool successful = pScene -> AddRunDuratio << 913     std::istringstream iss(newValue);
1005   if (successful) {                           << 914     iss >> redOrString >> green >> blue >> opacity;
1006     if (verbosity >= G4VisManager::confirmati << 915     G4Colour colour(1.,0.,0.,0.3);  // Default red and transparent.
1007       G4cout <<                               << 916     ConvertToColour(colour, redOrString, green, blue, opacity);
1008       "A representation of the source(s) of t << 917 
1009       "\n  in colour " << colour << " for sce << 918     G4VModel* model = new G4GPSModel(colour);
1010       << currentSceneName << "\" if applicabl << 919     const G4String& currentSceneName = pScene -> GetName ();
1011       << G4endl;                              << 920     G4bool successful = pScene -> AddRunDurationModel (model, warn);
                                                   >> 921     if (successful) {
                                                   >> 922       if (verbosity >= G4VisManager::confirmations) {
                                                   >> 923         G4cout <<
                                                   >> 924 "A representation of the source(s) of the General Particle Source will be drawn"
                                                   >> 925 "\n  in colour " << colour << " for scene \""
                                                   >> 926         << currentSceneName << "\" if applicable."
                                                   >> 927         << G4endl;
                                                   >> 928       }
1012     }                                            929     }
                                                   >> 930     else G4VisCommandsSceneAddUnsuccessful(verbosity);
                                                   >> 931     UpdateVisManagerScene (currentSceneName);
1013   }                                              932   }
1014   else G4VisCommandsSceneAddUnsuccessful(verb << 
1015                                               << 
1016   CheckSceneAndNotifyHandlers (pScene);       << 
1017 }                                             << 
1018                                                  933   
1019 ////////////// /vis/scene/add/hits //////////    934 ////////////// /vis/scene/add/hits ///////////////////////////////////////
1020                                                  935 
1021 G4VisCommandSceneAddHits::G4VisCommandSceneAd    936 G4VisCommandSceneAddHits::G4VisCommandSceneAddHits () {
1022   fpCommand = new G4UIcmdWithoutParameter ("/    937   fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/add/hits", this);
1023   fpCommand -> SetGuidance ("Adds hits to cur    938   fpCommand -> SetGuidance ("Adds hits to current scene.");
1024   fpCommand -> SetGuidance                       939   fpCommand -> SetGuidance
1025     ("Hits are drawn at end of event when the    940     ("Hits are drawn at end of event when the scene in which"
1026      "\nthey are added is current.");            941      "\nthey are added is current.");
1027 }                                                942 }
1028                                                  943 
1029 G4VisCommandSceneAddHits::~G4VisCommandSceneA    944 G4VisCommandSceneAddHits::~G4VisCommandSceneAddHits () {
1030   delete fpCommand;                              945   delete fpCommand;
1031 }                                                946 }
1032                                                  947 
1033 G4String G4VisCommandSceneAddHits::GetCurrent    948 G4String G4VisCommandSceneAddHits::GetCurrentValue (G4UIcommand*) {
1034   return "";                                     949   return "";
1035 }                                                950 }
1036                                                  951 
1037 void G4VisCommandSceneAddHits::SetNewValue (G    952 void G4VisCommandSceneAddHits::SetNewValue (G4UIcommand*, G4String) {
1038                                                  953 
1039   G4VisManager::Verbosity verbosity = fpVisMa    954   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1040   G4bool warn(verbosity >= G4VisManager::warn    955   G4bool warn(verbosity >= G4VisManager::warnings);
1041                                                  956 
1042   G4Scene* pScene = fpVisManager->GetCurrentS    957   G4Scene* pScene = fpVisManager->GetCurrentScene();
1043   if (!pScene) {                                 958   if (!pScene) {
1044     if (verbosity >= G4VisManager::errors) {     959     if (verbosity >= G4VisManager::errors) {
1045       G4warn << "ERROR: No current scene.  Pl << 960       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
1046     }                                            961     }
1047     return;                                      962     return;
1048   }                                              963   }
1049                                                  964 
1050   G4VModel* model = new G4HitsModel;             965   G4VModel* model = new G4HitsModel;
1051   const G4String& currentSceneName = pScene -    966   const G4String& currentSceneName = pScene -> GetName ();
1052   G4bool successful = pScene -> AddEndOfEvent    967   G4bool successful = pScene -> AddEndOfEventModel (model, warn);
1053   if (successful) {                              968   if (successful) {
1054     if (verbosity >= G4VisManager::confirmati    969     if (verbosity >= G4VisManager::confirmations) {
1055       G4cout << "Hits, if any, will be drawn     970       G4cout << "Hits, if any, will be drawn at end of run in scene \""
1056        << currentSceneName << "\"."              971        << currentSceneName << "\"."
1057        << G4endl;                                972        << G4endl;
1058     }                                            973     }
1059   }                                              974   }
1060   else G4VisCommandsSceneAddUnsuccessful(verb    975   else G4VisCommandsSceneAddUnsuccessful(verbosity);
1061                                               << 976   UpdateVisManagerScene (currentSceneName);
1062   CheckSceneAndNotifyHandlers (pScene);       << 
1063 }                                                977 }
1064                                                  978 
1065 ////////////// /vis/scene/add/line //////////    979 ////////////// /vis/scene/add/line ///////////////////////////////////////
1066                                                  980 
1067 G4VisCommandSceneAddLine::G4VisCommandSceneAd    981 G4VisCommandSceneAddLine::G4VisCommandSceneAddLine () {
1068   fpCommand = new G4UIcommand("/vis/scene/add    982   fpCommand = new G4UIcommand("/vis/scene/add/line", this);
1069   fpCommand -> SetGuidance ("Adds line to cur    983   fpCommand -> SetGuidance ("Adds line to current scene.");
1070   G4bool omitable;                               984   G4bool omitable;
1071   G4UIparameter* parameter;                      985   G4UIparameter* parameter;
1072   parameter = new G4UIparameter ("x1", 'd', o    986   parameter = new G4UIparameter ("x1", 'd', omitable = false);
1073   fpCommand -> SetParameter (parameter);         987   fpCommand -> SetParameter (parameter);
1074   parameter = new G4UIparameter ("y1", 'd', o    988   parameter = new G4UIparameter ("y1", 'd', omitable = false);
1075   fpCommand -> SetParameter (parameter);         989   fpCommand -> SetParameter (parameter);
1076   parameter = new G4UIparameter ("z1", 'd', o    990   parameter = new G4UIparameter ("z1", 'd', omitable = false);
1077   fpCommand -> SetParameter (parameter);         991   fpCommand -> SetParameter (parameter);
1078   parameter = new G4UIparameter ("x2", 'd', o    992   parameter = new G4UIparameter ("x2", 'd', omitable = false);
1079   fpCommand -> SetParameter (parameter);         993   fpCommand -> SetParameter (parameter);
1080   parameter = new G4UIparameter ("y2", 'd', o    994   parameter = new G4UIparameter ("y2", 'd', omitable = false);
1081   fpCommand -> SetParameter (parameter);         995   fpCommand -> SetParameter (parameter);
1082   parameter = new G4UIparameter ("z2", 'd', o    996   parameter = new G4UIparameter ("z2", 'd', omitable = false);
1083   fpCommand -> SetParameter (parameter);         997   fpCommand -> SetParameter (parameter);
1084   parameter =  new G4UIparameter ("unit", 's'    998   parameter =  new G4UIparameter ("unit", 's', omitable = true);
1085   parameter->SetDefaultValue ("m");              999   parameter->SetDefaultValue ("m");
1086   fpCommand->SetParameter    (parameter);        1000   fpCommand->SetParameter    (parameter);
1087 }                                                1001 }
1088                                                  1002 
1089 G4VisCommandSceneAddLine::~G4VisCommandSceneA    1003 G4VisCommandSceneAddLine::~G4VisCommandSceneAddLine () {
1090   delete fpCommand;                              1004   delete fpCommand;
1091 }                                                1005 }
1092                                                  1006 
1093 G4String G4VisCommandSceneAddLine::GetCurrent    1007 G4String G4VisCommandSceneAddLine::GetCurrentValue (G4UIcommand*) {
1094   return "";                                     1008   return "";
1095 }                                                1009 }
1096                                                  1010 
1097 void G4VisCommandSceneAddLine::SetNewValue (G    1011 void G4VisCommandSceneAddLine::SetNewValue (G4UIcommand*, G4String newValue)
1098 {                                                1012 {
1099   G4VisManager::Verbosity verbosity = fpVisMa    1013   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1100   G4bool warn(verbosity >= G4VisManager::warn    1014   G4bool warn(verbosity >= G4VisManager::warnings);
1101                                                  1015 
1102   G4Scene* pScene = fpVisManager->GetCurrentS    1016   G4Scene* pScene = fpVisManager->GetCurrentScene();
1103   if (!pScene) {                                 1017   if (!pScene) {
1104     if (verbosity >= G4VisManager::errors) {     1018     if (verbosity >= G4VisManager::errors) {
1105       G4warn << "ERROR: No current scene.  Pl << 1019       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
1106     }                                            1020     }
1107     return;                                      1021     return;
1108   }                                              1022   }
1109                                                  1023 
1110   G4String unitString;                           1024   G4String unitString;
1111   G4double x1, y1, z1, x2, y2, z2;               1025   G4double x1, y1, z1, x2, y2, z2;
1112   std::istringstream is(newValue);               1026   std::istringstream is(newValue);
1113   is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> u    1027   is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> unitString;
1114   G4double unit = G4UIcommand::ValueOf(unitSt    1028   G4double unit = G4UIcommand::ValueOf(unitString);
1115   x1 *= unit; y1 *= unit; z1 *= unit;            1029   x1 *= unit; y1 *= unit; z1 *= unit;
1116   x2 *= unit; y2 *= unit; z2 *= unit;            1030   x2 *= unit; y2 *= unit; z2 *= unit;
1117                                                  1031 
1118   Line* line = new Line(x1, y1, z1, x2, y2, z    1032   Line* line = new Line(x1, y1, z1, x2, y2, z2,
1119       fCurrentLineWidth, fCurrentColour);        1033       fCurrentLineWidth, fCurrentColour);
1120   G4VModel* model =                              1034   G4VModel* model =
1121     new G4CallbackModel<G4VisCommandSceneAddL    1035     new G4CallbackModel<G4VisCommandSceneAddLine::Line>(line);
1122   model->SetType("Line");                        1036   model->SetType("Line");
1123   model->SetGlobalTag("Line");                   1037   model->SetGlobalTag("Line");
1124   model->SetGlobalDescription("Line: " + newV    1038   model->SetGlobalDescription("Line: " + newValue);
1125   const G4String& currentSceneName = pScene -    1039   const G4String& currentSceneName = pScene -> GetName ();
1126   G4bool successful = pScene -> AddRunDuratio    1040   G4bool successful = pScene -> AddRunDurationModel (model, warn);
1127   if (successful) {                              1041   if (successful) {
1128     if (verbosity >= G4VisManager::confirmati    1042     if (verbosity >= G4VisManager::confirmations) {
1129       G4cout << "Line has been added to scene    1043       G4cout << "Line has been added to scene \""
1130        << currentSceneName << "\"."              1044        << currentSceneName << "\"."
1131        << G4endl;                                1045        << G4endl;
1132     }                                            1046     }
1133   }                                              1047   }
1134   else G4VisCommandsSceneAddUnsuccessful(verb    1048   else G4VisCommandsSceneAddUnsuccessful(verbosity);
1135                                               << 1049   UpdateVisManagerScene (currentSceneName);
1136   CheckSceneAndNotifyHandlers (pScene);       << 
1137 }                                                1050 }
1138                                                  1051 
1139 G4VisCommandSceneAddLine::Line::Line             1052 G4VisCommandSceneAddLine::Line::Line
1140 (G4double x1, G4double y1, G4double z1,          1053 (G4double x1, G4double y1, G4double z1,
1141  G4double x2, G4double y2, G4double z2,          1054  G4double x2, G4double y2, G4double z2,
1142  G4double width, const G4Colour& colour):        1055  G4double width, const G4Colour& colour):
1143   fWidth(width), fColour(colour)                 1056   fWidth(width), fColour(colour)
1144 {                                                1057 {
1145   fPolyline.push_back(G4Point3D(x1,y1,z1));      1058   fPolyline.push_back(G4Point3D(x1,y1,z1));
1146   fPolyline.push_back(G4Point3D(x2,y2,z2));      1059   fPolyline.push_back(G4Point3D(x2,y2,z2));
1147   G4VisAttributes va;                            1060   G4VisAttributes va;
1148   va.SetLineWidth(fWidth);                       1061   va.SetLineWidth(fWidth);
1149   va.SetColour(fColour);                         1062   va.SetColour(fColour);
1150   fPolyline.SetVisAttributes(va);                1063   fPolyline.SetVisAttributes(va);
1151 }                                                1064 }
1152                                                  1065 
1153 void G4VisCommandSceneAddLine::Line::operator    1066 void G4VisCommandSceneAddLine::Line::operator()
1154   (G4VGraphicsScene& sceneHandler, const G4Mo << 1067   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
1155 {                                                1068 {
1156   sceneHandler.BeginPrimitives();                1069   sceneHandler.BeginPrimitives();
1157   sceneHandler.AddPrimitive(fPolyline);          1070   sceneHandler.AddPrimitive(fPolyline);
1158   sceneHandler.EndPrimitives();                  1071   sceneHandler.EndPrimitives();
1159 }                                                1072 }
1160                                                  1073 
1161 ////////////// /vis/scene/add/line2D ////////    1074 ////////////// /vis/scene/add/line2D ///////////////////////////////////////
1162                                                  1075 
1163 G4VisCommandSceneAddLine2D::G4VisCommandScene    1076 G4VisCommandSceneAddLine2D::G4VisCommandSceneAddLine2D () {
1164   fpCommand = new G4UIcommand("/vis/scene/add    1077   fpCommand = new G4UIcommand("/vis/scene/add/line2D", this);
1165   fpCommand -> SetGuidance ("Adds 2D line to     1078   fpCommand -> SetGuidance ("Adds 2D line to current scene.");
1166   fpCommand -> SetGuidance ("x,y in range [-1 << 
1167   G4bool omitable;                               1079   G4bool omitable;
1168   G4UIparameter* parameter;                      1080   G4UIparameter* parameter;
1169   parameter = new G4UIparameter ("x1", 'd', o    1081   parameter = new G4UIparameter ("x1", 'd', omitable = false);
1170   fpCommand -> SetParameter (parameter);         1082   fpCommand -> SetParameter (parameter);
1171   parameter = new G4UIparameter ("y1", 'd', o    1083   parameter = new G4UIparameter ("y1", 'd', omitable = false);
1172   fpCommand -> SetParameter (parameter);         1084   fpCommand -> SetParameter (parameter);
1173   parameter = new G4UIparameter ("x2", 'd', o    1085   parameter = new G4UIparameter ("x2", 'd', omitable = false);
1174   fpCommand -> SetParameter (parameter);         1086   fpCommand -> SetParameter (parameter);
1175   parameter = new G4UIparameter ("y2", 'd', o    1087   parameter = new G4UIparameter ("y2", 'd', omitable = false);
1176   fpCommand -> SetParameter (parameter);         1088   fpCommand -> SetParameter (parameter);
1177 }                                                1089 }
1178                                                  1090 
1179 G4VisCommandSceneAddLine2D::~G4VisCommandScen    1091 G4VisCommandSceneAddLine2D::~G4VisCommandSceneAddLine2D () {
1180   delete fpCommand;                              1092   delete fpCommand;
1181 }                                                1093 }
1182                                                  1094 
1183 G4String G4VisCommandSceneAddLine2D::GetCurre    1095 G4String G4VisCommandSceneAddLine2D::GetCurrentValue (G4UIcommand*) {
1184   return "";                                     1096   return "";
1185 }                                                1097 }
1186                                                  1098 
1187 void G4VisCommandSceneAddLine2D::SetNewValue     1099 void G4VisCommandSceneAddLine2D::SetNewValue (G4UIcommand*, G4String newValue)
1188 {                                                1100 {
1189   G4VisManager::Verbosity verbosity = fpVisMa    1101   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1190   G4bool warn(verbosity >= G4VisManager::warn    1102   G4bool warn(verbosity >= G4VisManager::warnings);
1191                                                  1103 
1192   G4Scene* pScene = fpVisManager->GetCurrentS    1104   G4Scene* pScene = fpVisManager->GetCurrentScene();
1193   if (!pScene) {                                 1105   if (!pScene) {
1194     if (verbosity >= G4VisManager::errors) {     1106     if (verbosity >= G4VisManager::errors) {
1195       G4warn << "ERROR: No current scene.  Pl << 1107       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
1196     }                                            1108     }
1197     return;                                      1109     return;
1198   }                                              1110   }
1199                                                  1111 
1200   G4double x1, y1, x2, y2;                       1112   G4double x1, y1, x2, y2;
1201   std::istringstream is(newValue);               1113   std::istringstream is(newValue);
1202   is >> x1 >> y1 >> x2 >> y2;                    1114   is >> x1 >> y1 >> x2 >> y2;
1203                                                  1115 
1204   Line2D* line2D = new Line2D                    1116   Line2D* line2D = new Line2D
1205     (x1, y1, x2, y2, fCurrentLineWidth, fCurr    1117     (x1, y1, x2, y2, fCurrentLineWidth, fCurrentColour);
1206   G4VModel* model =                              1118   G4VModel* model =
1207     new G4CallbackModel<G4VisCommandSceneAddL    1119     new G4CallbackModel<G4VisCommandSceneAddLine2D::Line2D>(line2D);
1208   model->SetType("Line2D");                      1120   model->SetType("Line2D");
1209   model->SetGlobalTag("Line2D");                 1121   model->SetGlobalTag("Line2D");
1210   model->SetGlobalDescription("Line2D: " + ne    1122   model->SetGlobalDescription("Line2D: " + newValue);
1211   const G4String& currentSceneName = pScene -    1123   const G4String& currentSceneName = pScene -> GetName ();
1212   G4bool successful = pScene -> AddRunDuratio    1124   G4bool successful = pScene -> AddRunDurationModel (model, warn);
1213   if (successful) {                              1125   if (successful) {
1214     if (verbosity >= G4VisManager::confirmati    1126     if (verbosity >= G4VisManager::confirmations) {
1215       G4cout << "A 2D line has been added to     1127       G4cout << "A 2D line has been added to scene \""
1216        << currentSceneName << "\"."              1128        << currentSceneName << "\"."
1217        << G4endl;                                1129        << G4endl;
1218     }                                            1130     }
1219   }                                              1131   }
1220   else G4VisCommandsSceneAddUnsuccessful(verb    1132   else G4VisCommandsSceneAddUnsuccessful(verbosity);
1221                                               << 1133   UpdateVisManagerScene (currentSceneName);
1222   CheckSceneAndNotifyHandlers (pScene);       << 
1223 }                                                1134 }
1224                                                  1135 
1225 G4VisCommandSceneAddLine2D::Line2D::Line2D       1136 G4VisCommandSceneAddLine2D::Line2D::Line2D
1226 (G4double x1, G4double y1,                       1137 (G4double x1, G4double y1,
1227  G4double x2, G4double y2,                       1138  G4double x2, G4double y2,
1228  G4double width, const G4Colour& colour):        1139  G4double width, const G4Colour& colour):
1229   fWidth(width), fColour(colour)                 1140   fWidth(width), fColour(colour)
1230 {                                                1141 {
1231   fPolyline.push_back(G4Point3D(x1,y1,0));       1142   fPolyline.push_back(G4Point3D(x1,y1,0));
1232   fPolyline.push_back(G4Point3D(x2,y2,0));       1143   fPolyline.push_back(G4Point3D(x2,y2,0));
1233   G4VisAttributes va;                            1144   G4VisAttributes va;
1234   va.SetLineWidth(fWidth);                       1145   va.SetLineWidth(fWidth);
1235   va.SetColour(fColour);                         1146   va.SetColour(fColour);
1236   fPolyline.SetVisAttributes(va);                1147   fPolyline.SetVisAttributes(va);
1237 }                                                1148 }
1238                                                  1149 
1239 void G4VisCommandSceneAddLine2D::Line2D::oper    1150 void G4VisCommandSceneAddLine2D::Line2D::operator()
1240   (G4VGraphicsScene& sceneHandler, const G4Mo << 1151   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
1241 {                                                1152 {
1242   sceneHandler.BeginPrimitives2D();              1153   sceneHandler.BeginPrimitives2D();
1243   sceneHandler.AddPrimitive(fPolyline);          1154   sceneHandler.AddPrimitive(fPolyline);
1244   sceneHandler.EndPrimitives2D();                1155   sceneHandler.EndPrimitives2D();
1245 }                                                1156 }
1246                                                  1157 
1247 ////////////// /vis/scene/add/localAxes ///// << 
1248                                               << 
1249 G4VisCommandSceneAddLocalAxes::G4VisCommandSc << 
1250   G4bool omitable;                            << 
1251   fpCommand = new G4UIcommand ("/vis/scene/ad << 
1252   fpCommand -> SetGuidance                    << 
1253   ("Adds local axes to physical volume(s)."); << 
1254   G4UIparameter* parameter;                   << 
1255   parameter = new G4UIparameter ("physical-vo << 
1256   fpCommand -> SetParameter (parameter);      << 
1257   parameter = new G4UIparameter ("copy-no", ' << 
1258   parameter -> SetGuidance ("If negative, mat << 
1259   parameter -> SetDefaultValue (-1);          << 
1260   fpCommand -> SetParameter (parameter);      << 
1261 }                                             << 
1262                                               << 
1263 G4VisCommandSceneAddLocalAxes::~G4VisCommandS << 
1264   delete fpCommand;                           << 
1265 }                                             << 
1266                                               << 
1267 G4String G4VisCommandSceneAddLocalAxes::GetCu << 
1268   return "world 0 -1";                        << 
1269 }                                             << 
1270                                               << 
1271 void G4VisCommandSceneAddLocalAxes::SetNewVal << 
1272              G4String newValue) {             << 
1273                                               << 
1274   G4VisManager::Verbosity verbosity = fpVisMa << 
1275   G4bool warn = verbosity >= G4VisManager::wa << 
1276                                               << 
1277   G4Scene* pScene = fpVisManager->GetCurrentS << 
1278   if (!pScene) {                              << 
1279     if (verbosity >= G4VisManager::errors) {  << 
1280       G4warn << "ERROR: No current scene.  Pl << 
1281     }                                         << 
1282     return;                                   << 
1283   }                                           << 
1284                                               << 
1285   G4String name;                              << 
1286   G4int copyNo;                               << 
1287   std::istringstream is (newValue);           << 
1288   is >> name >> copyNo;                       << 
1289                                               << 
1290   std::vector<G4PhysicalVolumesSearchScene::F << 
1291                                               << 
1292   // Search all worlds...                     << 
1293   G4TransportationManager* transportationMana << 
1294   G4TransportationManager::GetTransportationM << 
1295   std::vector<G4VPhysicalVolume*>::iterator i << 
1296   transportationManager->GetWorldsIterator(); << 
1297   size_t nWorlds = transportationManager->Get << 
1298   for (size_t i = 0; i < nWorlds; ++i, ++iter << 
1299     G4ModelingParameters mp;  // Default - no << 
1300     G4PhysicalVolumeModel searchModel         << 
1301     (*iterWorld,                              << 
1302      G4PhysicalVolumeModel::UNLIMITED,        << 
1303      G4Transform3D(),                         << 
1304      &mp,                                     << 
1305      true);  // Use full extent (avoids initi << 
1306     G4PhysicalVolumesSearchScene searchScene  << 
1307     (&searchModel, name, copyNo);             << 
1308     searchModel.DescribeYourselfTo (searchSce << 
1309     for (const auto& findings: searchScene.Ge << 
1310       findingsVector.push_back(findings);     << 
1311     }                                         << 
1312   }                                           << 
1313                                               << 
1314   G4int id = 0;  // To distinguish axes model << 
1315   for (const auto& findings: findingsVector)  << 
1316                                               << 
1317     // Create axes model based on size and tr << 
1318     const auto& extent = findings.fpFoundPV-> << 
1319     const auto& transform = findings.fFoundOb << 
1320                                               << 
1321     const G4double lengthMax = extent.GetExte << 
1322     const G4double intLog10LengthMax = std::f << 
1323     G4double length = std::pow(10,intLog10Len << 
1324     if (5.*length < lengthMax) length *= 5.;  << 
1325     else if (2.*length < lengthMax) length *= << 
1326                                               << 
1327     const auto& axesModel = new G4AxesModel(0 << 
1328     axesModel->SetGlobalTag("LocalAxesModel") << 
1329     std::ostringstream oss; oss               << 
1330     << "Local Axes for " << findings.fpFoundP << 
1331     << ':' << findings.fFoundPVCopyNo << ':'  << 
1332     axesModel->SetGlobalDescription(oss.str() << 
1333     // ...so add it to the scene.             << 
1334     G4bool successful = pScene->AddRunDuratio << 
1335     if (successful) {                         << 
1336       if (verbosity >= G4VisManager::confirma << 
1337   G4cout << "\"" << findings.fpFoundPV->GetNa << 
1338   << "\", copy no. " << findings.fFoundPVCopy << 
1339   << ",\n  found in searched volume \""       << 
1340   << findings.fpSearchPV->GetName()           << 
1341   << "\" at depth " << findings.fFoundDepth   << 
1342   << ",\n  base path: \"" << findings.fFoundB << 
1343   << "\".\n  Local axes have been added to sc << 
1344   << pScene->GetName() << "\".";              << 
1345   if (verbosity >= G4VisManager::parameters)  << 
1346     G4cout << "  With extent " << extent      << 
1347     << "\n  at " << transform.getRotation()   << 
1348     << "  " << transform.getTranslation();    << 
1349   }                                           << 
1350   G4cout << G4endl;                           << 
1351       }                                       << 
1352     } else {                                  << 
1353       G4VisCommandsSceneAddUnsuccessful(verbo << 
1354     }                                         << 
1355   }                                           << 
1356                                               << 
1357   if (findingsVector.empty()) {               << 
1358     if (verbosity >= G4VisManager::errors) {  << 
1359       G4warn << "ERROR: Volume \"" << name << << 
1360       if (copyNo >= 0) {                      << 
1361   G4warn << ", copy no. " << copyNo << ",";   << 
1362       }                                       << 
1363       G4warn << " not found." << G4endl;      << 
1364     }                                         << 
1365     G4VisCommandsSceneAddUnsuccessful(verbosi << 
1366     return;                                   << 
1367   }                                           << 
1368                                               << 
1369   CheckSceneAndNotifyHandlers(pScene);        << 
1370 }                                             << 
1371                                               << 
1372 ////////////// /vis/scene/add/logicalVolume /    1158 ////////////// /vis/scene/add/logicalVolume //////////////////////////////////
1373                                                  1159 
1374 G4VisCommandSceneAddLogicalVolume::G4VisComma    1160 G4VisCommandSceneAddLogicalVolume::G4VisCommandSceneAddLogicalVolume () {
1375   G4bool omitable;                               1161   G4bool omitable;
1376   fpCommand = new G4UIcommand ("/vis/scene/ad    1162   fpCommand = new G4UIcommand ("/vis/scene/add/logicalVolume", this);
1377   fpCommand -> SetGuidance ("Adds a logical v    1163   fpCommand -> SetGuidance ("Adds a logical volume to the current scene,");
1378   fpCommand -> SetGuidance                       1164   fpCommand -> SetGuidance
1379   ("Shows boolean components (if any), voxels    1165   ("Shows boolean components (if any), voxels (if any), readout geometry"
1380    "\n  (if any), local axes and overlaps (if << 1166    "\n  (if any) and local axes, under control of the appropriate flag."
1381    "\n  appropriate flag."                    << 
1382    "\n  Note: voxels are not constructed unti    1167    "\n  Note: voxels are not constructed until start of run -"
1383    "\n \"/run/beamOn\".  (For voxels without     1168    "\n \"/run/beamOn\".  (For voxels without a run, \"/run/beamOn 0\".)");
1384   G4UIparameter* parameter;                      1169   G4UIparameter* parameter;
1385   parameter = new G4UIparameter ("logical-vol    1170   parameter = new G4UIparameter ("logical-volume-name", 's', omitable = false);
1386   fpCommand -> SetParameter (parameter);         1171   fpCommand -> SetParameter (parameter);
1387   parameter = new G4UIparameter ("depth-of-de    1172   parameter = new G4UIparameter ("depth-of-descent", 'i', omitable = true);
1388   parameter -> SetGuidance ("Depth of descent    1173   parameter -> SetGuidance ("Depth of descent of geometry hierarchy.");
1389   parameter -> SetDefaultValue (1);              1174   parameter -> SetDefaultValue (1);
1390   fpCommand -> SetParameter (parameter);         1175   fpCommand -> SetParameter (parameter);
1391   parameter = new G4UIparameter ("booleans-fl    1176   parameter = new G4UIparameter ("booleans-flag", 'b', omitable = true);
1392   parameter -> SetDefaultValue (true);           1177   parameter -> SetDefaultValue (true);
1393   fpCommand -> SetParameter (parameter);         1178   fpCommand -> SetParameter (parameter);
1394   parameter = new G4UIparameter ("voxels-flag    1179   parameter = new G4UIparameter ("voxels-flag", 'b', omitable = true);
1395   parameter -> SetDefaultValue (true);           1180   parameter -> SetDefaultValue (true);
1396   fpCommand -> SetParameter (parameter);         1181   fpCommand -> SetParameter (parameter);
1397   parameter = new G4UIparameter ("readout-fla    1182   parameter = new G4UIparameter ("readout-flag", 'b', omitable = true);
1398   parameter -> SetDefaultValue (true);           1183   parameter -> SetDefaultValue (true);
1399   fpCommand -> SetParameter (parameter);         1184   fpCommand -> SetParameter (parameter);
1400   parameter = new G4UIparameter ("axes-flag",    1185   parameter = new G4UIparameter ("axes-flag", 'b', omitable = true);
1401   parameter -> SetDefaultValue (true);           1186   parameter -> SetDefaultValue (true);
1402   parameter -> SetGuidance ("Set \"false\" to    1187   parameter -> SetGuidance ("Set \"false\" to suppress axes.");
1403   fpCommand -> SetParameter (parameter);         1188   fpCommand -> SetParameter (parameter);
1404   parameter = new G4UIparameter("check-overla << 
1405   parameter->SetDefaultValue(true);           << 
1406   parameter -> SetGuidance ("Set \"false\" to << 
1407   fpCommand->SetParameter(parameter);         << 
1408 }                                                1189 }
1409                                                  1190 
1410 G4VisCommandSceneAddLogicalVolume::~G4VisComm    1191 G4VisCommandSceneAddLogicalVolume::~G4VisCommandSceneAddLogicalVolume () {
1411   delete fpCommand;                              1192   delete fpCommand;
1412 }                                                1193 }
1413                                                  1194 
1414 G4String G4VisCommandSceneAddLogicalVolume::G    1195 G4String G4VisCommandSceneAddLogicalVolume::GetCurrentValue (G4UIcommand*) {
1415   return "";                                     1196   return "";
1416 }                                                1197 }
1417                                                  1198 
1418 void G4VisCommandSceneAddLogicalVolume::SetNe    1199 void G4VisCommandSceneAddLogicalVolume::SetNewValue (G4UIcommand*,
1419                  G4String newValue) {            1200                  G4String newValue) {
1420                                                  1201 
1421   G4VisManager::Verbosity verbosity = fpVisMa    1202   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1422   G4bool warn(verbosity >= G4VisManager::warn    1203   G4bool warn(verbosity >= G4VisManager::warnings);
1423                                                  1204 
1424   G4Scene* pScene = fpVisManager->GetCurrentS    1205   G4Scene* pScene = fpVisManager->GetCurrentScene();
1425   if (!pScene) {                                 1206   if (!pScene) {
1426     if (verbosity >= G4VisManager::errors) {     1207     if (verbosity >= G4VisManager::errors) {
1427       G4warn << "ERROR: No current scene.  Pl << 1208       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
1428     }                                            1209     }
1429     return;                                      1210     return;
1430   }                                              1211   }
1431                                                  1212 
1432   G4String name;                                 1213   G4String name;
1433   G4int requestedDepthOfDescent;                 1214   G4int requestedDepthOfDescent;
1434   G4String booleansString, voxelsString, read    1215   G4String booleansString, voxelsString, readoutString, axesString;
1435   G4String overlapString;                     << 
1436   std::istringstream is (newValue);              1216   std::istringstream is (newValue);
1437   is >> name >> requestedDepthOfDescent          1217   is >> name >> requestedDepthOfDescent
1438      >>  booleansString >> voxelsString >> re << 1218      >>  booleansString >> voxelsString >> readoutString >> axesString;
1439      >> overlapString;                        << 
1440   G4bool booleans = G4UIcommand::ConvertToBoo    1219   G4bool booleans = G4UIcommand::ConvertToBool(booleansString);
1441   G4bool voxels = G4UIcommand::ConvertToBool(    1220   G4bool voxels = G4UIcommand::ConvertToBool(voxelsString);
1442   G4bool readout = G4UIcommand::ConvertToBool    1221   G4bool readout = G4UIcommand::ConvertToBool(readoutString);
1443   G4bool axes = G4UIcommand::ConvertToBool(ax    1222   G4bool axes = G4UIcommand::ConvertToBool(axesString);
1444   G4bool checkOverlaps = G4UIcommand::Convert << 
1445                                                  1223 
1446   G4LogicalVolumeStore *pLVStore = G4LogicalV    1224   G4LogicalVolumeStore *pLVStore = G4LogicalVolumeStore::GetInstance();
1447   G4LogicalVolume* pLV = nullptr;             << 1225   int nLV = pLVStore -> size ();
1448   pLV = pLVStore->GetVolume(name);            << 1226   int iLV;
1449   if (pLV == nullptr) return;  // Volume not  << 1227   G4LogicalVolume* pLV = 0;
                                                   >> 1228   for (iLV = 0; iLV < nLV; iLV++ ) {
                                                   >> 1229     pLV = (*pLVStore) [iLV];
                                                   >> 1230     if (pLV -> GetName () == name) break;
                                                   >> 1231   }
                                                   >> 1232   if (iLV == nLV) {
                                                   >> 1233     if (verbosity >= G4VisManager::errors) {
                                                   >> 1234       G4cerr << "ERROR: Logical volume " << name
                                                   >> 1235        << " not found in logical volume store." << G4endl;
                                                   >> 1236     }
                                                   >> 1237     return;
                                                   >> 1238   }
1450                                                  1239 
1451   const std::vector<G4Scene::Model>& rdModelL    1240   const std::vector<G4Scene::Model>& rdModelList =
1452     pScene -> GetRunDurationModelList();         1241     pScene -> GetRunDurationModelList();
1453   std::vector<G4Scene::Model>::const_iterator    1242   std::vector<G4Scene::Model>::const_iterator i;
1454   for (i = rdModelList.begin(); i != rdModelL    1243   for (i = rdModelList.begin(); i != rdModelList.end(); ++i) {
1455     if (i->fpModel->GetGlobalDescription().fi    1244     if (i->fpModel->GetGlobalDescription().find("Volume") != std::string::npos) break;
1456   }                                              1245   }
1457   if (i != rdModelList.end()) {                  1246   if (i != rdModelList.end()) {
1458     if (verbosity >= G4VisManager::errors) {     1247     if (verbosity >= G4VisManager::errors) {
1459       G4warn << "There is already a volume, \ << 1248       G4cout << "There is already a volume, \""
1460              << i->fpModel->GetGlobalDescript    1249              << i->fpModel->GetGlobalDescription()
1461              << "\",\n in the run-duration mo    1250              << "\",\n in the run-duration model list of scene \""
1462              << pScene -> GetName()              1251              << pScene -> GetName()
1463              << "\".\n Your logical volume mu    1252              << "\".\n Your logical volume must be the only volume in the scene."
1464        << "\n Create a new scene and try agai    1253        << "\n Create a new scene and try again:"
1465        << "\n  /vis/specify " << name            1254        << "\n  /vis/specify " << name
1466        << "\n or"                                1255        << "\n or"
1467        << "\n  /vis/scene/create"                1256        << "\n  /vis/scene/create"
1468        << "\n  /vis/scene/add/logicalVolume "    1257        << "\n  /vis/scene/add/logicalVolume " << name
1469        << "\n  /vis/sceneHandler/attach"         1258        << "\n  /vis/sceneHandler/attach"
1470        << "\n (and also, if necessary, /vis/v    1259        << "\n (and also, if necessary, /vis/viewer/flush)"
1471              << G4endl;                          1260              << G4endl;
1472     }                                            1261     }
1473     return;                                      1262     return;
1474   }                                              1263   }
1475                                                  1264 
1476   G4LogicalVolumeModel* model = new G4Logical    1265   G4LogicalVolumeModel* model = new G4LogicalVolumeModel
1477     (pLV, requestedDepthOfDescent, booleans,  << 1266     (pLV, requestedDepthOfDescent, booleans, voxels, readout);
1478   const G4String& currentSceneName = pScene -    1267   const G4String& currentSceneName = pScene -> GetName ();
1479   G4bool successful = pScene -> AddRunDuratio    1268   G4bool successful = pScene -> AddRunDurationModel (model, warn);
1480                                                  1269 
1481   if (successful) {                              1270   if (successful) {
1482                                                  1271 
1483     G4bool axesSuccessful = false;               1272     G4bool axesSuccessful = false;
1484     if (axes) {                                  1273     if (axes) {
1485       const G4double radius = model->GetExten    1274       const G4double radius = model->GetExtent().GetExtentRadius();
1486       const G4double axisLengthMax = radius /    1275       const G4double axisLengthMax = radius / 2.;
1487       const G4double intLog10Length = std::fl    1276       const G4double intLog10Length = std::floor(std::log10(axisLengthMax));
1488       G4double axisLength = std::pow(10,intLo    1277       G4double axisLength = std::pow(10,intLog10Length);
1489       if (5.*axisLength < axisLengthMax) axis    1278       if (5.*axisLength < axisLengthMax) axisLength *= 5.;
1490       else if (2.*axisLength < axisLengthMax)    1279       else if (2.*axisLength < axisLengthMax) axisLength *= 2.;
1491       const G4double axisWidth = axisLength /    1280       const G4double axisWidth = axisLength / 20.;
1492       G4VModel* axesModel = new G4AxesModel(0    1281       G4VModel* axesModel = new G4AxesModel(0.,0.,0.,axisLength,axisWidth);
1493       axesSuccessful = pScene -> AddRunDurati    1282       axesSuccessful = pScene -> AddRunDurationModel (axesModel, warn);
1494     }                                            1283     }
1495                                                  1284 
1496 //    if (verbosity >= G4VisManager::warnings    1285 //    if (verbosity >= G4VisManager::warnings) {
1497 //      const std::map<G4String,G4AttDef>* at    1286 //      const std::map<G4String,G4AttDef>* attDefs = model->GetAttDefs();
1498 //      std::vector<G4AttValue>* attValues =     1287 //      std::vector<G4AttValue>* attValues = model->CreateCurrentAttValues();
1499 //      G4warn << G4AttCheck(attValues, attDe << 1288 //      G4cout << G4AttCheck(attValues, attDefs);
1500 //      delete attValues;                        1289 //      delete attValues;
1501 //    }                                          1290 //    }
1502                                                  1291 
1503     if (verbosity >= G4VisManager::confirmati    1292     if (verbosity >= G4VisManager::confirmations) {
1504       G4cout << "Logical volume \"" << pLV ->    1293       G4cout << "Logical volume \"" << pLV -> GetName ()
1505        << "\" with requested depth of descent << 1294        << " with requested depth of descent "
1506        << requestedDepthOfDescent                1295        << requestedDepthOfDescent
1507        << ",\n  with";                        << 1296        << ",\n with";
1508       if (!booleans) G4cout << "out";            1297       if (!booleans) G4cout << "out";
1509       G4cout << " boolean components, with";     1298       G4cout << " boolean components, with";
1510       if (!voxels) G4cout << "out";              1299       if (!voxels) G4cout << "out";
1511       G4cout << " voxels,\n  with";           << 1300       G4cout << " voxels and with";
1512       if (!readout) G4cout << "out";             1301       if (!readout) G4cout << "out";
1513       G4cout << " readout geometry and with"; << 1302       G4cout << " readout geometry,"
1514       if (!checkOverlaps) G4cout << "out";    << 
1515       G4cout << " overlap checking"           << 
1516        << "\n  has been added to scene \"" <<    1303        << "\n  has been added to scene \"" << currentSceneName << "\".";
1517       if (axes) {                                1304       if (axes) {
1518         if (axesSuccessful) {                    1305         if (axesSuccessful) {
1519           G4cout <<                              1306           G4cout <<
1520           "\n  Axes have also been added at t    1307           "\n  Axes have also been added at the origin of local cooordinates.";
1521         } else {                                 1308         } else {
1522           G4cout <<                              1309           G4cout <<
1523           "\n  Axes have not been added for s    1310           "\n  Axes have not been added for some reason possibly stated above.";
1524         }                                        1311         }
1525       }                                          1312       }
1526       G4cout << G4endl;                          1313       G4cout << G4endl;
1527     }                                            1314     }
1528   }                                              1315   }
1529   else {                                         1316   else {
1530     G4VisCommandsSceneAddUnsuccessful(verbosi    1317     G4VisCommandsSceneAddUnsuccessful(verbosity);
1531     return;                                      1318     return;
1532   }                                              1319   }
1533                                                  1320 
1534   CheckSceneAndNotifyHandlers (pScene);       << 1321   UpdateVisManagerScene (currentSceneName);
1535 }                                                1322 }
1536                                                  1323 
1537                                                  1324 
1538 ////////////// /vis/scene/add/logo //////////    1325 ////////////// /vis/scene/add/logo //////////////////////////////////
1539                                                  1326 
1540 G4VisCommandSceneAddLogo::G4VisCommandSceneAd    1327 G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo () {
1541   G4bool omitable;                               1328   G4bool omitable;
1542   fpCommand = new G4UIcommand ("/vis/scene/ad    1329   fpCommand = new G4UIcommand ("/vis/scene/add/logo", this);
1543   fpCommand -> SetGuidance ("Adds a G4 logo t    1330   fpCommand -> SetGuidance ("Adds a G4 logo to the current scene.");
1544   fpCommand -> SetGuidance                       1331   fpCommand -> SetGuidance
1545   ("If \"unit\" is \"auto\", height is roughl    1332   ("If \"unit\" is \"auto\", height is roughly one tenth of scene extent.");
1546   fpCommand -> SetGuidance                       1333   fpCommand -> SetGuidance
1547   ("\"direction\" is that of outward-facing n    1334   ("\"direction\" is that of outward-facing normal to front face of logo."
1548    "\nIf \"direction\" is \"auto\", logo face    1335    "\nIf \"direction\" is \"auto\", logo faces the user in the current viewer.");
1549   fpCommand -> SetGuidance                       1336   fpCommand -> SetGuidance
1550   ("\nIf \"placement\" is \"auto\", logo is p    1337   ("\nIf \"placement\" is \"auto\", logo is placed at bottom right of screen"
1551    "\n  when viewed from logo direction.");      1338    "\n  when viewed from logo direction.");
1552   G4UIparameter* parameter;                      1339   G4UIparameter* parameter;
1553   parameter = new G4UIparameter ("height", 'd    1340   parameter = new G4UIparameter ("height", 'd', omitable = true);
1554   parameter->SetDefaultValue (1.);               1341   parameter->SetDefaultValue (1.);
1555   fpCommand->SetParameter (parameter);           1342   fpCommand->SetParameter (parameter);
1556   parameter =  new G4UIparameter ("unit", 's'    1343   parameter =  new G4UIparameter ("unit", 's', omitable = true);
1557   parameter->SetDefaultValue ("auto");           1344   parameter->SetDefaultValue ("auto");
1558   fpCommand->SetParameter (parameter);           1345   fpCommand->SetParameter (parameter);
1559   parameter =  new G4UIparameter ("direction"    1346   parameter =  new G4UIparameter ("direction", 's', omitable = true);
1560   parameter->SetGuidance ("auto|[-]x|[-]y|[-]    1347   parameter->SetGuidance ("auto|[-]x|[-]y|[-]z");
1561   parameter->SetDefaultValue ("auto");           1348   parameter->SetDefaultValue ("auto");
1562   fpCommand->SetParameter (parameter);           1349   fpCommand->SetParameter (parameter);
1563   parameter =  new G4UIparameter ("red", 'd',    1350   parameter =  new G4UIparameter ("red", 'd', omitable = true);
1564   parameter->SetDefaultValue (0.);               1351   parameter->SetDefaultValue (0.);
1565   fpCommand->SetParameter (parameter);           1352   fpCommand->SetParameter (parameter);
1566   parameter =  new G4UIparameter ("green", 'd    1353   parameter =  new G4UIparameter ("green", 'd', omitable = true);
1567   parameter->SetDefaultValue (1.);               1354   parameter->SetDefaultValue (1.);
1568   fpCommand->SetParameter (parameter);           1355   fpCommand->SetParameter (parameter);
1569   parameter =  new G4UIparameter ("blue", 'd'    1356   parameter =  new G4UIparameter ("blue", 'd', omitable = true);
1570   parameter->SetDefaultValue (0.);               1357   parameter->SetDefaultValue (0.);
1571   fpCommand->SetParameter (parameter);           1358   fpCommand->SetParameter (parameter);
1572   parameter =  new G4UIparameter ("placement"    1359   parameter =  new G4UIparameter ("placement", 's', omitable = true);
1573   parameter -> SetParameterCandidates("auto m    1360   parameter -> SetParameterCandidates("auto manual");
1574   parameter->SetDefaultValue  ("auto");          1361   parameter->SetDefaultValue  ("auto");
1575   fpCommand->SetParameter     (parameter);       1362   fpCommand->SetParameter     (parameter);
1576   parameter =  new G4UIparameter ("xmid", 'd'    1363   parameter =  new G4UIparameter ("xmid", 'd', omitable = true);
1577   parameter->SetDefaultValue (0.);               1364   parameter->SetDefaultValue (0.);
1578   fpCommand->SetParameter (parameter);           1365   fpCommand->SetParameter (parameter);
1579   parameter =  new G4UIparameter ("ymid", 'd'    1366   parameter =  new G4UIparameter ("ymid", 'd', omitable = true);
1580   parameter->SetDefaultValue (0.);               1367   parameter->SetDefaultValue (0.);
1581   fpCommand->SetParameter (parameter);           1368   fpCommand->SetParameter (parameter);
1582   parameter =  new G4UIparameter ("zmid", 'd'    1369   parameter =  new G4UIparameter ("zmid", 'd', omitable = true);
1583   parameter->SetDefaultValue (0.);               1370   parameter->SetDefaultValue (0.);
1584   fpCommand->SetParameter (parameter);           1371   fpCommand->SetParameter (parameter);
1585   parameter =  new G4UIparameter ("unit", 's'    1372   parameter =  new G4UIparameter ("unit", 's', omitable = true);
1586   parameter->SetDefaultValue ("m");              1373   parameter->SetDefaultValue ("m");
1587   fpCommand->SetParameter (parameter);           1374   fpCommand->SetParameter (parameter);
1588 }                                                1375 }
1589                                                  1376 
1590 G4VisCommandSceneAddLogo::~G4VisCommandSceneA    1377 G4VisCommandSceneAddLogo::~G4VisCommandSceneAddLogo () {
1591   delete fpCommand;                              1378   delete fpCommand;
1592 }                                                1379 }
1593                                                  1380 
1594 G4String G4VisCommandSceneAddLogo::GetCurrent    1381 G4String G4VisCommandSceneAddLogo::GetCurrentValue (G4UIcommand*) {
1595   return "";                                     1382   return "";
1596 }                                                1383 }
1597                                                  1384 
1598 void G4VisCommandSceneAddLogo::SetNewValue (G    1385 void G4VisCommandSceneAddLogo::SetNewValue (G4UIcommand*, G4String newValue) {
1599                                                  1386 
1600   G4VisManager::Verbosity verbosity = fpVisMa    1387   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1601   G4bool warn = verbosity >= G4VisManager::wa    1388   G4bool warn = verbosity >= G4VisManager::warnings;
1602                                                  1389 
1603   G4Scene* pScene = fpVisManager->GetCurrentS    1390   G4Scene* pScene = fpVisManager->GetCurrentScene();
1604   if (!pScene) {                                 1391   if (!pScene) {
1605     if (verbosity >= G4VisManager::errors) {     1392     if (verbosity >= G4VisManager::errors) {
1606       G4warn << "ERROR: No current scene.  Pl << 1393       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
1607     }                                            1394     }
1608     return;                                      1395     return;
1609   } else {                                       1396   } else {
1610     if (pScene->GetExtent().GetExtentRadius()    1397     if (pScene->GetExtent().GetExtentRadius() <= 0.) {
1611       if (verbosity >= G4VisManager::errors)     1398       if (verbosity >= G4VisManager::errors) {
1612         G4warn                                << 1399         G4cerr
1613   << "ERROR: Scene has no extent. Add volumes    1400   << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
1614         << G4endl;                               1401         << G4endl;
1615       }                                          1402       }
1616       return;                                    1403       return;
1617     }                                            1404     }
1618   }                                              1405   }
1619                                                  1406 
1620   G4VViewer* pViewer = fpVisManager->GetCurre    1407   G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
1621   if (!pViewer) {                                1408   if (!pViewer) {
1622     if (verbosity >= G4VisManager::errors) {     1409     if (verbosity >= G4VisManager::errors) {
1623       G4warn <<                               << 1410       G4cerr <<
1624   "ERROR: G4VisCommandSceneAddLogo::SetNewVal    1411   "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer."
1625   "\n  Auto direction needs a viewer."           1412   "\n  Auto direction needs a viewer."
1626        << G4endl;                                1413        << G4endl;
1627     }                                            1414     }
1628     return;                                      1415     return;
1629   }                                              1416   }
1630                                                  1417 
1631   G4double userHeight, red, green, blue, xmid    1418   G4double userHeight, red, green, blue, xmid, ymid, zmid;
1632   G4String userHeightUnit, direction, placeme << 1419   G4String userHeightUnit, direction, auto_manual, positionUnit;
1633   std::istringstream is (newValue);              1420   std::istringstream is (newValue);
1634   is >> userHeight >> userHeightUnit >> direc    1421   is >> userHeight >> userHeightUnit >> direction
1635      >> red >> green >> blue                     1422      >> red >> green >> blue
1636      >> placement                             << 1423      >> auto_manual
1637      >> xmid >> ymid >> zmid >> positionUnit;    1424      >> xmid >> ymid >> zmid >> positionUnit;
1638                                                  1425 
1639   G4double height = userHeight;                  1426   G4double height = userHeight;
1640   const G4VisExtent& sceneExtent = pScene->Ge    1427   const G4VisExtent& sceneExtent = pScene->GetExtent();  // Existing extent.
1641   if (userHeightUnit == "auto") {                1428   if (userHeightUnit == "auto") {
1642     height *= 0.2 * sceneExtent.GetExtentRadi    1429     height *= 0.2 * sceneExtent.GetExtentRadius();
1643   } else {                                       1430   } else {
1644     height *= G4UIcommand::ValueOf(userHeight    1431     height *= G4UIcommand::ValueOf(userHeightUnit);
1645   }                                              1432   }
1646                                                  1433 
1647   G4double unit = G4UIcommand::ValueOf(positi    1434   G4double unit = G4UIcommand::ValueOf(positionUnit);
1648   xmid *= unit; ymid *= unit; zmid *= unit;      1435   xmid *= unit; ymid *= unit; zmid *= unit;
1649                                                  1436 
1650   Direction logoDirection = X;  // Initialise    1437   Direction logoDirection = X;  // Initialise to keep some compilers happy.
1651   if (direction == "auto") {                     1438   if (direction == "auto") {
1652     // Take cue from viewer                      1439     // Take cue from viewer
1653     const G4Vector3D& vp =                       1440     const G4Vector3D& vp =
1654       pViewer->GetViewParameters().GetViewpoi    1441       pViewer->GetViewParameters().GetViewpointDirection();
1655     if (vp.x() > vp.y() && vp.x() > vp.z()) l    1442     if (vp.x() > vp.y() && vp.x() > vp.z()) logoDirection = X;
1656     else if (vp.x() < vp.y() && vp.x() < vp.z    1443     else if (vp.x() < vp.y() && vp.x() < vp.z()) logoDirection = minusX;
1657     else if (vp.y() > vp.x() && vp.y() > vp.z    1444     else if (vp.y() > vp.x() && vp.y() > vp.z()) logoDirection = Y;
1658     else if (vp.y() < vp.x() && vp.y() < vp.z    1445     else if (vp.y() < vp.x() && vp.y() < vp.z()) logoDirection = minusY;
1659     else if (vp.z() > vp.x() && vp.z() > vp.y    1446     else if (vp.z() > vp.x() && vp.z() > vp.y()) logoDirection = Z;
1660     else if (vp.z() < vp.x() && vp.z() < vp.y    1447     else if (vp.z() < vp.x() && vp.z() < vp.y()) logoDirection = minusZ;
1661   }                                              1448   }
1662   else if (direction[0] == 'x') logoDirection << 1449   else if (direction(0) == 'x') logoDirection = X;
1663   else if (direction[0] == 'y') logoDirection << 1450   else if (direction(0) == 'y') logoDirection = Y;
1664   else if (direction[0] == 'z') logoDirection << 1451   else if (direction(0) == 'z') logoDirection = Z;
1665   else if (direction[0] == '-') {             << 1452   else if (direction(0) == '-') {
1666     if (direction[1] == 'x') logoDirection =  << 1453     if (direction(1) == 'x') logoDirection = minusX;
1667     else if (direction[1] == 'y') logoDirecti << 1454     else if (direction(1) == 'y') logoDirection = minusY;
1668     else if (direction[1] == 'z') logoDirecti << 1455     else if (direction(1) == 'z') logoDirection = minusZ;
1669   } else {                                       1456   } else {
1670     if (verbosity >= G4VisManager::errors) {     1457     if (verbosity >= G4VisManager::errors) {
1671       G4warn << "ERROR: Unrecogniseed directi << 1458       G4cerr << "ERROR: Unrecogniseed direction: \""
1672        << direction << "\"." << G4endl;          1459        << direction << "\"." << G4endl;
1673       return;                                    1460       return;
1674     }                                            1461     }
1675   }                                              1462   }
1676                                                  1463 
1677   G4bool autoPlacing = false; if (placement = << 1464   G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
1678   // Parameters read and interpreted.            1465   // Parameters read and interpreted.
1679                                                  1466 
1680   // Current scene extent                        1467   // Current scene extent
1681   const G4double xmin = sceneExtent.GetXmin()    1468   const G4double xmin = sceneExtent.GetXmin();
1682   const G4double xmax = sceneExtent.GetXmax()    1469   const G4double xmax = sceneExtent.GetXmax();
1683   const G4double ymin = sceneExtent.GetYmin()    1470   const G4double ymin = sceneExtent.GetYmin();
1684   const G4double ymax = sceneExtent.GetYmax()    1471   const G4double ymax = sceneExtent.GetYmax();
1685   const G4double zmin = sceneExtent.GetZmin()    1472   const G4double zmin = sceneExtent.GetZmin();
1686   const G4double zmax = sceneExtent.GetZmax()    1473   const G4double zmax = sceneExtent.GetZmax();
1687                                                  1474 
1688   // Test existing extent and issue warnings.    1475   // Test existing extent and issue warnings...
1689   G4bool worried = false;                        1476   G4bool worried = false;
1690   if (sceneExtent.GetExtentRadius() == 0) {      1477   if (sceneExtent.GetExtentRadius() == 0) {
1691     worried = true;                              1478     worried = true;
1692     if (verbosity >= G4VisManager::warnings)     1479     if (verbosity >= G4VisManager::warnings) {
1693       G4warn <<                               << 1480       G4cout <<
1694   "WARNING: Existing scene does not yet have     1481   "WARNING: Existing scene does not yet have any extent."
1695   "\n  Maybe you have not yet added any geome    1482   "\n  Maybe you have not yet added any geometrical object."
1696        << G4endl;                                1483        << G4endl;
1697     }                                            1484     }
1698   }                                              1485   }
1699                                                  1486 
1700   // Useful constants, etc...                    1487   // Useful constants, etc...
1701   const G4double halfHeight(height / 2.);        1488   const G4double halfHeight(height / 2.);
1702   const G4double comfort(0.01);  // 0.15 seem    1489   const G4double comfort(0.01);  // 0.15 seems too big.  0.05 might be better.
1703   const G4double freeHeightFraction (1. + 2.     1490   const G4double freeHeightFraction (1. + 2. * comfort);
1704                                                  1491 
1705   // Test existing scene for room...             1492   // Test existing scene for room...
1706   G4bool room = true;                            1493   G4bool room = true;
1707   switch (logoDirection) {                       1494   switch (logoDirection) {
1708   case X:                                        1495   case X:
1709   case minusX:                                   1496   case minusX:
1710     if (freeHeightFraction * (xmax - xmin) <     1497     if (freeHeightFraction * (xmax - xmin) < height) room = false;
1711     break;                                       1498     break;
1712   case Y:                                        1499   case Y:
1713   case minusY:                                   1500   case minusY:
1714     if (freeHeightFraction * (ymax - ymin) <     1501     if (freeHeightFraction * (ymax - ymin) < height) room = false;
1715     break;                                       1502     break;
1716   case Z:                                        1503   case Z:
1717   case minusZ:                                   1504   case minusZ:
1718     if (freeHeightFraction * (zmax - zmin) <     1505     if (freeHeightFraction * (zmax - zmin) < height) room = false;
1719     break;                                       1506     break;
1720   }                                              1507   }
1721   if (!room) {                                   1508   if (!room) {
1722     worried = true;                              1509     worried = true;
1723     if (verbosity >= G4VisManager::warnings)     1510     if (verbosity >= G4VisManager::warnings) {
1724       G4warn <<                               << 1511       G4cout <<
1725   "WARNING: Not enough room in existing scene    1512   "WARNING: Not enough room in existing scene.  Maybe logo is too large."
1726        << G4endl;                                1513        << G4endl;
1727     }                                            1514     }
1728   }                                              1515   }
1729   if (worried) {                                 1516   if (worried) {
1730     if (verbosity >= G4VisManager::warnings)     1517     if (verbosity >= G4VisManager::warnings) {
1731       G4warn <<                               << 1518       G4cout <<
1732   "WARNING: The logo you have asked for is bi    1519   "WARNING: The logo you have asked for is bigger than the existing"
1733   "\n  scene.  Maybe you have added it too so    1520   "\n  scene.  Maybe you have added it too soon.  It is recommended that"
1734   "\n  you add the logo last so that it can b    1521   "\n  you add the logo last so that it can be correctly auto-positioned"
1735   "\n  so as not to be obscured by any existi    1522   "\n  so as not to be obscured by any existing object and so that the"
1736   "\n  view parameters can be correctly recal    1523   "\n  view parameters can be correctly recalculated."
1737        << G4endl;                                1524        << G4endl;
1738     }                                            1525     }
1739   }                                              1526   }
1740                                                  1527 
1741   G4double sxmid(xmid), symid(ymid), szmid(zm    1528   G4double sxmid(xmid), symid(ymid), szmid(zmid);
1742   if (autoPlacing) {                             1529   if (autoPlacing) {
1743     // Aim to place at bottom right of screen    1530     // Aim to place at bottom right of screen when viewed from logoDirection.
1744     // Give some comfort zone.                   1531     // Give some comfort zone.
1745     const G4double xComfort = comfort * (xmax    1532     const G4double xComfort = comfort * (xmax - xmin);
1746     const G4double yComfort = comfort * (ymax    1533     const G4double yComfort = comfort * (ymax - ymin);
1747     const G4double zComfort = comfort * (zmax    1534     const G4double zComfort = comfort * (zmax - zmin);
1748     switch (logoDirection) {                     1535     switch (logoDirection) {
1749     case X:  // y-axis up, z-axis to left?       1536     case X:  // y-axis up, z-axis to left?
1750       sxmid = xmax + halfHeight + xComfort;      1537       sxmid = xmax + halfHeight + xComfort;
1751       symid = ymin - yComfort;                   1538       symid = ymin - yComfort;
1752       szmid = zmin - zComfort;                   1539       szmid = zmin - zComfort;
1753       break;                                     1540       break;
1754     case minusX:  // y-axis up, z-axis to rig    1541     case minusX:  // y-axis up, z-axis to right?
1755       sxmid = xmin - halfHeight - xComfort;      1542       sxmid = xmin - halfHeight - xComfort;
1756       symid = ymin - yComfort;                   1543       symid = ymin - yComfort;
1757       szmid = zmax + zComfort;                   1544       szmid = zmax + zComfort;
1758       break;                                     1545       break;
1759     case Y:  // z-axis up, x-axis to left?       1546     case Y:  // z-axis up, x-axis to left?
1760       sxmid = xmin - xComfort;                   1547       sxmid = xmin - xComfort;
1761       symid = ymax + halfHeight + yComfort;      1548       symid = ymax + halfHeight + yComfort;
1762       szmid = zmin - zComfort;                   1549       szmid = zmin - zComfort;
1763       break;                                     1550       break;
1764     case minusY:  // z-axis up, x-axis to rig    1551     case minusY:  // z-axis up, x-axis to right?
1765       sxmid = xmax + xComfort;                   1552       sxmid = xmax + xComfort;
1766       symid = ymin - halfHeight - yComfort;      1553       symid = ymin - halfHeight - yComfort;
1767       szmid = zmin - zComfort;                   1554       szmid = zmin - zComfort;
1768       break;                                     1555       break;
1769     case Z:  // y-axis up, x-axis to right?      1556     case Z:  // y-axis up, x-axis to right?
1770       sxmid = xmax + xComfort;                   1557       sxmid = xmax + xComfort;
1771       symid = ymin - yComfort;                   1558       symid = ymin - yComfort;
1772       szmid = zmax + halfHeight + zComfort;      1559       szmid = zmax + halfHeight + zComfort;
1773       break;                                     1560       break;
1774     case minusZ:  // y-axis up, x-axis to lef    1561     case minusZ:  // y-axis up, x-axis to left?
1775       sxmid = xmin - xComfort;                   1562       sxmid = xmin - xComfort;
1776       symid = ymin - yComfort;                   1563       symid = ymin - yComfort;
1777       szmid = zmin - halfHeight - zComfort;      1564       szmid = zmin - halfHeight - zComfort;
1778       break;                                     1565       break;
1779     }                                            1566     }
1780   }                                              1567   }
1781                                                  1568 
1782   G4Transform3D transform;                       1569   G4Transform3D transform;
1783   switch (logoDirection) {                       1570   switch (logoDirection) {
1784   case X:  // y-axis up, z-axis to left?         1571   case X:  // y-axis up, z-axis to left?
1785     transform = G4RotateY3D(halfpi);             1572     transform = G4RotateY3D(halfpi);
1786     break;                                       1573     break;
1787   case minusX:  // y-axis up, z-axis to right    1574   case minusX:  // y-axis up, z-axis to right?
1788     transform = G4RotateY3D(-halfpi);            1575     transform = G4RotateY3D(-halfpi);
1789     break;                                       1576     break;
1790   case Y:  // z-axis up, x-axis to left?         1577   case Y:  // z-axis up, x-axis to left?
1791     transform = G4RotateX3D(-halfpi) * G4Rota    1578     transform = G4RotateX3D(-halfpi) * G4RotateZ3D(pi);
1792     break;                                       1579     break;
1793   case minusY:  // z-axis up, x-axis to right    1580   case minusY:  // z-axis up, x-axis to right?
1794     transform = G4RotateX3D(halfpi);             1581     transform = G4RotateX3D(halfpi);
1795     break;                                       1582     break;
1796   case Z:  // y-axis up, x-axis to right?        1583   case Z:  // y-axis up, x-axis to right?
1797     // No transformation required.               1584     // No transformation required.
1798     break;                                       1585     break;
1799   case minusZ:  // y-axis up, x-axis to left?    1586   case minusZ:  // y-axis up, x-axis to left?
1800     transform = G4RotateY3D(pi);                 1587     transform = G4RotateY3D(pi);
1801     break;                                       1588     break;
1802   }                                              1589   }
1803   transform = G4Translate3D(sxmid,symid,szmid    1590   transform = G4Translate3D(sxmid,symid,szmid) * transform;
1804                                                  1591 
1805   G4VisAttributes visAtts(G4Colour(red, green    1592   G4VisAttributes visAtts(G4Colour(red, green, blue));
1806   visAtts.SetForceSolid(true);         // Alw    1593   visAtts.SetForceSolid(true);         // Always solid.
1807                                                  1594 
1808   G4Logo* logo = new G4Logo(height,visAtts,tr << 1595   G4Logo* logo = new G4Logo(height,visAtts);
1809   G4VModel* model =                              1596   G4VModel* model =
1810     new G4CallbackModel<G4VisCommandSceneAddL    1597     new G4CallbackModel<G4VisCommandSceneAddLogo::G4Logo>(logo);
1811   model->SetType("G4Logo");                      1598   model->SetType("G4Logo");
1812   model->SetGlobalTag("G4Logo");                 1599   model->SetGlobalTag("G4Logo");
1813   model->SetGlobalDescription("G4Logo: " + ne    1600   model->SetGlobalDescription("G4Logo: " + newValue);
                                                   >> 1601   model->SetTransformation(transform);
                                                   >> 1602   // Note: it is the responsibility of the model to act upon this, but
                                                   >> 1603   // the extent is in local coordinates...
1814   G4double& h = height;                          1604   G4double& h = height;
1815   G4double h2 = h/2.;                            1605   G4double h2 = h/2.;
1816   G4VisExtent extent(-h,h,-h2,h2,-h2,h2);        1606   G4VisExtent extent(-h,h,-h2,h2,-h2,h2);
1817   model->SetExtent(extent.Transform(transform << 1607   model->SetExtent(extent);
1818   // This extent gets "added" to existing sce    1608   // This extent gets "added" to existing scene extent in
1819   // AddRunDurationModel below.                  1609   // AddRunDurationModel below.
1820   const G4String& currentSceneName = pScene -    1610   const G4String& currentSceneName = pScene -> GetName ();
1821   G4bool successful = pScene -> AddRunDuratio    1611   G4bool successful = pScene -> AddRunDurationModel (model, warn);
1822   if (successful) {                              1612   if (successful) {
1823     if (verbosity >= G4VisManager::confirmati    1613     if (verbosity >= G4VisManager::confirmations) {
1824       G4cout << "G4 Logo of height " << userH    1614       G4cout << "G4 Logo of height " << userHeight << ' ' << userHeightUnit
1825        << ", " << direction << "-direction, a    1615        << ", " << direction << "-direction, added to scene \""
1826        << currentSceneName << "\"";              1616        << currentSceneName << "\"";
1827       if (verbosity >= G4VisManager::paramete    1617       if (verbosity >= G4VisManager::parameters) {
1828   G4cout << "\n  with extent " << extent         1618   G4cout << "\n  with extent " << extent
1829          << "\n  at " << transform.getRotatio    1619          << "\n  at " << transform.getRotation()
1830          << "  " << transform.getTranslation( << 1620          << transform.getTranslation();
1831       }                                          1621       }
1832       G4cout << G4endl;                          1622       G4cout << G4endl;
1833     }                                            1623     }
1834   }                                              1624   }
1835   else G4VisCommandsSceneAddUnsuccessful(verb    1625   else G4VisCommandsSceneAddUnsuccessful(verbosity);
1836                                               << 1626   UpdateVisManagerScene (currentSceneName);
1837   CheckSceneAndNotifyHandlers (pScene);       << 
1838 }                                                1627 }
1839                                                  1628 
1840 G4VisCommandSceneAddLogo::G4Logo::G4Logo         1629 G4VisCommandSceneAddLogo::G4Logo::G4Logo
1841 (G4double height, const G4VisAttributes& visA << 1630 (G4double height, const G4VisAttributes& visAtts):
                                                   >> 1631   fVisAtts(visAtts)
1842 {                                                1632 {
1843   const G4double& h =  height;                   1633   const G4double& h =  height;
1844   const G4double h2  = 0.5 * h;   // Half hei    1634   const G4double h2  = 0.5 * h;   // Half height.
1845   const G4double ri  = 0.25 * h;  // Inner ra    1635   const G4double ri  = 0.25 * h;  // Inner radius.
1846   const G4double ro  = 0.5 * h;   // Outer ra    1636   const G4double ro  = 0.5 * h;   // Outer radius.
1847   const G4double ro2 = 0.5 * ro;  // Half out    1637   const G4double ro2 = 0.5 * ro;  // Half outer radius.
1848   const G4double w   = ro - ri;   // Width.      1638   const G4double w   = ro - ri;   // Width.
1849   const G4double w2  = 0.5 * w;   // Half wid    1639   const G4double w2  = 0.5 * w;   // Half width.
1850   const G4double d2  = 0.2 * h;   // Half dep    1640   const G4double d2  = 0.2 * h;   // Half depth.
1851   const G4double f1  = 0.05 * h;  // left edg    1641   const G4double f1  = 0.05 * h;  // left edge of stem of "4".
1852   const G4double f2  = -0.3 * h;  // bottom e    1642   const G4double f2  = -0.3 * h;  // bottom edge of cross of "4".
1853   const G4double e = 1.e-4 * h;   // epsilon.    1643   const G4double e = 1.e-4 * h;   // epsilon.
1854   const G4double xt = f1, yt = h2;      // To    1644   const G4double xt = f1, yt = h2;      // Top of slope.
1855   const G4double xb = -h2, yb = f2 + w; // Bo    1645   const G4double xb = -h2, yb = f2 + w; // Bottom of slope.
1856   const G4double dx = xt - xb, dy = yt - yb;     1646   const G4double dx = xt - xb, dy = yt - yb;
1857   const G4double angle = std::atan2(dy,dx);      1647   const G4double angle = std::atan2(dy,dx);
1858   G4RotationMatrix rm;                           1648   G4RotationMatrix rm;
1859   rm.rotateZ(angle*rad);                         1649   rm.rotateZ(angle*rad);
1860   const G4double d = std::sqrt(dx * dx + dy *    1650   const G4double d = std::sqrt(dx * dx + dy * dy);
1861   const G4double ss = h;  // Half height of s    1651   const G4double ss = h;  // Half height of square subtractor
1862   const G4double y8 = ss; // Choose y of subt    1652   const G4double y8 = ss; // Choose y of subtractor for outer slope.
1863   const G4double x8 = ((-ss * d - dx * (yt -     1653   const G4double x8 = ((-ss * d - dx * (yt - y8)) / dy) + xt;
1864   G4double y9 = ss; // Choose y of subtractor    1654   G4double y9 = ss; // Choose y of subtractor for inner slope.
1865   G4double x9 = ((-(ss - w) * d - dx * (yt -     1655   G4double x9 = ((-(ss - w) * d - dx * (yt - y8)) / dy) + xt;
1866   // But to get inner, we make a triangle tra    1656   // But to get inner, we make a triangle translated by...
1867   const G4double xtr = ss - f1, ytr = -ss - f    1657   const G4double xtr = ss - f1, ytr = -ss - f2 -w;
1868   x9 += xtr; y9 += ytr;                          1658   x9 += xtr; y9 += ytr;
1869                                                  1659 
1870   // The idea here is to create a polyhedron     1660   // The idea here is to create a polyhedron for the G and the 4.  To do
1871   // this we use Geant4 geometry solids and m    1661   // this we use Geant4 geometry solids and make boolean operations.
1872   // Note that we do not need to keep the sol    1662   // Note that we do not need to keep the solids. We use local objects,
1873   // which, of course, are deleted on leaving    1663   // which, of course, are deleted on leaving this function. This
1874   // is contrary to the usual requirement for    1664   // is contrary to the usual requirement for solids that are part of the
1875   // detector for which solids MUST be create    1665   // detector for which solids MUST be created on the heap (with "new").
1876   // Finally we invoke CreatePolyhedron, whic    1666   // Finally we invoke CreatePolyhedron, which creates a polyhedron on the heap
1877   // and returns a pointer.  It is the user's    1667   // and returns a pointer.  It is the user's responsibility to delete,
1878   // which is done in the destructor of this     1668   // which is done in the destructor of this class. Thus the polyhedra,
1879   // created here, remain on the heap for the    1669   // created here, remain on the heap for the lifetime of the job.
1880                                                  1670 
1881   // G...                                        1671   // G...
1882   G4Tubs tG("tG",ri,ro,d2,0.15*pi,1.85*pi);      1672   G4Tubs tG("tG",ri,ro,d2,0.15*pi,1.85*pi);
1883   G4Box bG("bG",w2,ro2,d2);                      1673   G4Box bG("bG",w2,ro2,d2);
1884   G4UnionSolid logoG("logoG",&tG,&bG,G4Transl    1674   G4UnionSolid logoG("logoG",&tG,&bG,G4Translate3D(ri+w2,-ro2,0.));
1885   // Create with these vis atts (force solid) << 
1886   G4Polyhedron::SetNumberOfRotationSteps      << 
1887   (fpVisManager->GetCurrentViewer()->GetViewP << 
1888   fpG = logoG.CreatePolyhedron();                1675   fpG = logoG.CreatePolyhedron();
1889   G4Polyhedron::ResetNumberOfRotationSteps () << 1676   fpG->SetVisAttributes(&fVisAtts);
1890   fpG->SetVisAttributes(visAtts);             << 
1891   fpG->Transform(G4Translate3D(-0.55*h,0.,0.)    1677   fpG->Transform(G4Translate3D(-0.55*h,0.,0.));
1892   fpG->Transform(transform);                  << 
1893                                                  1678 
1894   // 4...                                        1679   // 4...
1895   G4Box b1("b1",h2,h2,d2);                       1680   G4Box b1("b1",h2,h2,d2);
1896   G4Box bS("bS",ss,ss,d2+e);  // Subtractor.     1681   G4Box bS("bS",ss,ss,d2+e);  // Subtractor.
1897   G4Box bS2("bS2",ss,ss,d2+2.*e);  // 2nd Sub    1682   G4Box bS2("bS2",ss,ss,d2+2.*e);  // 2nd Subtractor.
1898   G4SubtractionSolid s1("s1",&b1,&bS,G4Transl    1683   G4SubtractionSolid s1("s1",&b1,&bS,G4Translate3D(f1-ss,f2-ss,0.));
1899   G4SubtractionSolid s2("s2",&s1,&bS,G4Transl    1684   G4SubtractionSolid s2("s2",&s1,&bS,G4Translate3D(f1+ss+w,f2-ss,0.));
1900   G4SubtractionSolid s3("s3",&s2,&bS,G4Transl    1685   G4SubtractionSolid s3("s3",&s2,&bS,G4Translate3D(f1+ss+w,f2+ss+w,0.));
1901   G4SubtractionSolid s4                          1686   G4SubtractionSolid s4
1902     ("s4",&s3,&bS,G4Transform3D(rm,G4ThreeVec    1687     ("s4",&s3,&bS,G4Transform3D(rm,G4ThreeVector(x8,y8,0.)));
1903   G4SubtractionSolid s5    // Triangular hole    1688   G4SubtractionSolid s5    // Triangular hole.
1904     ("s5",&bS,&bS2,G4Transform3D(rm,G4ThreeVe    1689     ("s5",&bS,&bS2,G4Transform3D(rm,G4ThreeVector(x9,y9,0.)));
1905   G4SubtractionSolid logo4("logo4",&s4,&s5,G4    1690   G4SubtractionSolid logo4("logo4",&s4,&s5,G4Translate3D(-xtr,-ytr,0.));
1906   fp4 = logo4.CreatePolyhedron();                1691   fp4 = logo4.CreatePolyhedron();
1907   /* Experiment with creating own polyhedron.    1692   /* Experiment with creating own polyhedron...
1908   int nNodes = 4;                                1693   int nNodes = 4;
1909   int nFaces = 4;                                1694   int nFaces = 4;
1910   double xyz[][3] = {{0,0,0},{1*m,0,0},{0,1*m    1695   double xyz[][3] = {{0,0,0},{1*m,0,0},{0,1*m,0},{0,0,1*m}};
1911   int faces[][4] = {{1,3,2,0},{1,2,4,0},{1,4,    1696   int faces[][4] = {{1,3,2,0},{1,2,4,0},{1,4,3,0},{2,3,4,0}};
1912   fp4 = new G4Polyhedron();                      1697   fp4 = new G4Polyhedron();
1913   fp4->createPolyhedron(nNodes,nFaces,xyz,fac    1698   fp4->createPolyhedron(nNodes,nFaces,xyz,faces);
1914   */                                             1699   */
1915   fp4->SetVisAttributes(visAtts);             << 1700   fp4->SetVisAttributes(&fVisAtts);
1916   fp4->Transform(G4Translate3D(0.55*h,0.,0.))    1701   fp4->Transform(G4Translate3D(0.55*h,0.,0.));
1917   fp4->Transform(transform);                  << 
1918 }                                                1702 }
1919                                                  1703 
1920 G4VisCommandSceneAddLogo::G4Logo::~G4Logo() {    1704 G4VisCommandSceneAddLogo::G4Logo::~G4Logo() {
1921   delete fpG;                                    1705   delete fpG;
1922   delete fp4;                                    1706   delete fp4;
1923 }                                                1707 }
1924                                                  1708 
1925 void G4VisCommandSceneAddLogo::G4Logo::operat    1709 void G4VisCommandSceneAddLogo::G4Logo::operator()
1926   (G4VGraphicsScene& sceneHandler, const G4Mo << 1710   (G4VGraphicsScene& sceneHandler, const G4Transform3D& transform) {
1927   sceneHandler.BeginPrimitives();             << 1711   sceneHandler.BeginPrimitives(transform);
1928   sceneHandler.AddPrimitive(*fpG);               1712   sceneHandler.AddPrimitive(*fpG);
1929   sceneHandler.AddPrimitive(*fp4);               1713   sceneHandler.AddPrimitive(*fp4);
1930   sceneHandler.EndPrimitives();                  1714   sceneHandler.EndPrimitives();
1931 }                                                1715 }
1932                                                  1716 
1933 ////////////// /vis/scene/add/logo2D ////////    1717 ////////////// /vis/scene/add/logo2D ///////////////////////////////////////
1934                                                  1718 
1935 G4VisCommandSceneAddLogo2D::G4VisCommandScene    1719 G4VisCommandSceneAddLogo2D::G4VisCommandSceneAddLogo2D () {
1936   G4bool omitable;                               1720   G4bool omitable;
1937   fpCommand = new G4UIcommand ("/vis/scene/ad    1721   fpCommand = new G4UIcommand ("/vis/scene/add/logo2D", this);
1938   fpCommand -> SetGuidance ("Adds 2D logo to     1722   fpCommand -> SetGuidance ("Adds 2D logo to current scene.");
1939   G4UIparameter* parameter;                      1723   G4UIparameter* parameter;
1940   parameter = new G4UIparameter ("size", 'i',    1724   parameter = new G4UIparameter ("size", 'i', omitable = true);
1941   parameter -> SetGuidance ("Screen size of t    1725   parameter -> SetGuidance ("Screen size of text in pixels.");
1942   parameter -> SetDefaultValue (48);             1726   parameter -> SetDefaultValue (48);
1943   fpCommand -> SetParameter (parameter);         1727   fpCommand -> SetParameter (parameter);
1944   parameter = new G4UIparameter ("x-position"    1728   parameter = new G4UIparameter ("x-position", 'd', omitable = true);
1945   parameter -> SetGuidance ("x screen positio    1729   parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
1946   parameter -> SetDefaultValue (-0.9);           1730   parameter -> SetDefaultValue (-0.9);
1947   fpCommand -> SetParameter (parameter);         1731   fpCommand -> SetParameter (parameter);
1948   parameter = new G4UIparameter ("y-position"    1732   parameter = new G4UIparameter ("y-position", 'd', omitable = true);
1949   parameter -> SetGuidance ("y screen positio    1733   parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
1950   parameter -> SetDefaultValue (-0.9);           1734   parameter -> SetDefaultValue (-0.9);
1951   fpCommand -> SetParameter (parameter);         1735   fpCommand -> SetParameter (parameter);
1952   parameter = new G4UIparameter ("layout", 's    1736   parameter = new G4UIparameter ("layout", 's', omitable = true);
1953   parameter -> SetGuidance ("Layout, i.e., ad    1737   parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
1954   parameter -> SetDefaultValue ("left");         1738   parameter -> SetDefaultValue ("left");
1955   fpCommand -> SetParameter (parameter);         1739   fpCommand -> SetParameter (parameter);
1956 }                                                1740 }
1957                                                  1741 
1958 G4VisCommandSceneAddLogo2D::~G4VisCommandScen    1742 G4VisCommandSceneAddLogo2D::~G4VisCommandSceneAddLogo2D () {
1959   delete fpCommand;                              1743   delete fpCommand;
1960 }                                                1744 }
1961                                                  1745 
1962 G4String G4VisCommandSceneAddLogo2D::GetCurre    1746 G4String G4VisCommandSceneAddLogo2D::GetCurrentValue (G4UIcommand*) {
1963   return "";                                     1747   return "";
1964 }                                                1748 }
1965                                                  1749 
1966 void G4VisCommandSceneAddLogo2D::SetNewValue     1750 void G4VisCommandSceneAddLogo2D::SetNewValue (G4UIcommand*, G4String newValue)
1967 {                                                1751 {
1968   G4VisManager::Verbosity verbosity = fpVisMa    1752   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
1969   G4bool warn(verbosity >= G4VisManager::warn    1753   G4bool warn(verbosity >= G4VisManager::warnings);
1970                                                  1754 
1971   G4Scene* pScene = fpVisManager->GetCurrentS    1755   G4Scene* pScene = fpVisManager->GetCurrentScene();
1972   if (!pScene) {                                 1756   if (!pScene) {
1973     if (verbosity >= G4VisManager::errors) {     1757     if (verbosity >= G4VisManager::errors) {
1974       G4warn << "ERROR: No current scene.  Pl << 1758       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
1975     }                                            1759     }
1976     return;                                      1760     return;
1977   }                                              1761   }
1978                                                  1762 
1979   G4int size;                                    1763   G4int size;
1980   G4double x, y;                                 1764   G4double x, y;
1981   G4String layoutString;                         1765   G4String layoutString;
1982   std::istringstream is(newValue);               1766   std::istringstream is(newValue);
1983   is >> size >> x >> y >> layoutString;          1767   is >> size >> x >> y >> layoutString;
1984   G4Text::Layout layout = G4Text::right;         1768   G4Text::Layout layout = G4Text::right;
1985   if (layoutString[0] == 'l') layout = G4Text << 1769   if (layoutString(0) == 'l') layout = G4Text::left;
1986   else if (layoutString[0] == 'c') layout = G << 1770   else if (layoutString(0) == 'c') layout = G4Text::centre;
1987   else if (layoutString[0] == 'r') layout = G << 1771   else if (layoutString(0) == 'r') layout = G4Text::right;
1988                                                  1772 
1989   Logo2D* logo2D = new Logo2D(fpVisManager, s    1773   Logo2D* logo2D = new Logo2D(fpVisManager, size, x, y, layout);
1990   G4VModel* model =                              1774   G4VModel* model =
1991     new G4CallbackModel<G4VisCommandSceneAddL    1775     new G4CallbackModel<G4VisCommandSceneAddLogo2D::Logo2D>(logo2D);
1992   model->SetType("G4Logo2D");                    1776   model->SetType("G4Logo2D");
1993   model->SetGlobalTag("G4Logo2D");               1777   model->SetGlobalTag("G4Logo2D");
1994   model->SetGlobalDescription("G4Logo2D: " +     1778   model->SetGlobalDescription("G4Logo2D: " + newValue);
1995   const G4String& currentSceneName = pScene -    1779   const G4String& currentSceneName = pScene -> GetName ();
1996   G4bool successful = pScene -> AddRunDuratio    1780   G4bool successful = pScene -> AddRunDurationModel (model, warn);
1997   if (successful) {                              1781   if (successful) {
1998     if (verbosity >= G4VisManager::confirmati    1782     if (verbosity >= G4VisManager::confirmations) {
1999       G4cout << "2D logo has been added to sc    1783       G4cout << "2D logo has been added to scene \""
2000        << currentSceneName << "\"."              1784        << currentSceneName << "\"."
2001        << G4endl;                                1785        << G4endl;
2002     }                                            1786     }
2003   }                                              1787   }
2004   else G4VisCommandsSceneAddUnsuccessful(verb    1788   else G4VisCommandsSceneAddUnsuccessful(verbosity);
2005                                               << 1789   UpdateVisManagerScene (currentSceneName);
2006   CheckSceneAndNotifyHandlers (pScene);       << 
2007 }                                                1790 }
2008                                                  1791 
2009 void G4VisCommandSceneAddLogo2D::Logo2D::oper    1792 void G4VisCommandSceneAddLogo2D::Logo2D::operator()
2010   (G4VGraphicsScene& sceneHandler, const G4Mo << 1793   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
2011 {                                                1794 {
2012   G4Text text("Geant4", G4Point3D(fX, fY, 0.)    1795   G4Text text("Geant4", G4Point3D(fX, fY, 0.));
2013   text.SetScreenSize(fSize);                     1796   text.SetScreenSize(fSize);
2014   text.SetLayout(fLayout);                       1797   text.SetLayout(fLayout);
2015   G4VisAttributes textAtts(G4Colour::Brown())    1798   G4VisAttributes textAtts(G4Colour::Brown());
2016   text.SetVisAttributes(textAtts);               1799   text.SetVisAttributes(textAtts);
2017   sceneHandler.BeginPrimitives2D();              1800   sceneHandler.BeginPrimitives2D();
2018   sceneHandler.AddPrimitive(text);               1801   sceneHandler.AddPrimitive(text);
2019   sceneHandler.EndPrimitives2D();                1802   sceneHandler.EndPrimitives2D();
2020 }                                                1803 }
2021                                                  1804 
2022 ////////////// /vis/scene/add/magneticField /    1805 ////////////// /vis/scene/add/magneticField ///////////////////////////////////////
2023                                                  1806 
2024 G4VisCommandSceneAddMagneticField::G4VisComma    1807 G4VisCommandSceneAddMagneticField::G4VisCommandSceneAddMagneticField () {
                                                   >> 1808   G4bool omitable;
2025   fpCommand = new G4UIcommand ("/vis/scene/ad    1809   fpCommand = new G4UIcommand ("/vis/scene/add/magneticField", this);
2026   fpCommand -> SetGuidance                       1810   fpCommand -> SetGuidance
2027   ("Adds magnetic field representation to cur    1811   ("Adds magnetic field representation to current scene.");
2028   const G4UIcommandTree* tree = G4UImanager:: << 1812   fpCommand -> SetGuidance
2029   const G4UIcommand* addElecFieldCmd = tree-> << 1813   ("The first parameter is no. of data points per half scene.  So, possibly, at"
2030   // Pick up additional guidance from /vis/sc << 1814    "\nmaximum, the number of data points sampled is (2*n+1)^3, which can grow"
2031   CopyGuidanceFrom(addElecFieldCmd,fpCommand, << 1815    "\nlarge--be warned!"
2032   // Pick up parameters from /vis/scene/add/e << 1816    "\nYou might find that your scene is cluttered by thousands of arrows for"
2033   CopyParametersFrom(addElecFieldCmd,fpComman << 1817    "\nthe default number of data points, so try reducing to 2 or 3, e.g:"
                                                   >> 1818    "\n  /vis/scene/add/magneticField 3"
                                                   >> 1819    "\nor, if only a small part of the scene has a field:"
                                                   >> 1820    "\n  /vis/scene/add/magneticField 50 or more");
                                                   >> 1821   fpCommand -> SetGuidance
                                                   >> 1822   ("In the arrow representation, the length of the arrow is proportional"
                                                   >> 1823    "\nto the magnitude of the field and the colour is mapped onto the range"
                                                   >> 1824    "\nas a fraction of the maximum magnitude: 0->0.5->1 is blue->green->red.");
                                                   >> 1825   G4UIparameter* parameter;
                                                   >> 1826   parameter = new G4UIparameter ("nDataPointsPerHalfScene", 'i', omitable = true);
                                                   >> 1827   parameter -> SetDefaultValue (10);
                                                   >> 1828   fpCommand -> SetParameter (parameter);
                                                   >> 1829   parameter = new G4UIparameter ("representation", 's', omitable = true);
                                                   >> 1830   parameter -> SetParameterCandidates("fullArrow lightArrow");
                                                   >> 1831   parameter -> SetDefaultValue ("fullArrow");
                                                   >> 1832   fpCommand -> SetParameter (parameter);
2034 }                                                1833 }
2035                                                  1834 
2036 G4VisCommandSceneAddMagneticField::~G4VisComm    1835 G4VisCommandSceneAddMagneticField::~G4VisCommandSceneAddMagneticField () {
2037   delete fpCommand;                              1836   delete fpCommand;
2038 }                                                1837 }
2039                                                  1838 
2040 G4String G4VisCommandSceneAddMagneticField::G    1839 G4String G4VisCommandSceneAddMagneticField::GetCurrentValue (G4UIcommand*) {
2041   return "";                                     1840   return "";
2042 }                                                1841 }
2043                                                  1842 
2044 void G4VisCommandSceneAddMagneticField::SetNe    1843 void G4VisCommandSceneAddMagneticField::SetNewValue
2045 (G4UIcommand*, G4String newValue) {              1844 (G4UIcommand*, G4String newValue) {
2046                                                  1845 
2047   G4VisManager::Verbosity verbosity = fpVisMa    1846   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2048   G4bool warn(verbosity >= G4VisManager::warn    1847   G4bool warn(verbosity >= G4VisManager::warnings);
2049                                                  1848 
2050   G4Scene* pScene = fpVisManager->GetCurrentS    1849   G4Scene* pScene = fpVisManager->GetCurrentScene();
2051   if (!pScene) {                                 1850   if (!pScene) {
2052     if (verbosity >= G4VisManager::errors) {     1851     if (verbosity >= G4VisManager::errors) {
2053       G4warn <<  "ERROR: No current scene.  P << 1852       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
2054     }                                            1853     }
2055     return;                                      1854     return;
2056   }                                              1855   }
2057                                                  1856 
2058   G4int nDataPointsPerHalfScene;                 1857   G4int nDataPointsPerHalfScene;
2059   G4String representation;                       1858   G4String representation;
2060   std::istringstream iss(newValue);              1859   std::istringstream iss(newValue);
2061   iss >> nDataPointsPerHalfScene >> represent    1860   iss >> nDataPointsPerHalfScene >> representation;
2062   G4ElectricFieldModel::Representation        << 1861   G4MagneticFieldModel::Representation
2063   modelRepresentation = G4ElectricFieldModel: << 1862   modelRepresentation = G4MagneticFieldModel::fullArrow;
2064   if (representation == "lightArrow") {          1863   if (representation == "lightArrow") {
2065     modelRepresentation = G4ElectricFieldMode << 1864     modelRepresentation = G4MagneticFieldModel::lightArrow;
2066   }                                              1865   }
2067   G4VModel* model;                            << 1866   G4VModel* model =
2068   model = new G4MagneticFieldModel            << 1867   new G4MagneticFieldModel(nDataPointsPerHalfScene,modelRepresentation,
2069   (nDataPointsPerHalfScene,modelRepresentatio << 1868                            fCurrentArrow3DLineSegmentsPerCircle);
2070    fCurrentArrow3DLineSegmentsPerCircle,      << 
2071    fCurrentExtentForField,                    << 
2072    fCurrrentPVFindingsForField);              << 
2073   const G4String& currentSceneName = pScene -    1869   const G4String& currentSceneName = pScene -> GetName ();
2074   G4bool successful = pScene -> AddRunDuratio    1870   G4bool successful = pScene -> AddRunDurationModel (model, warn);
2075   if (successful) {                              1871   if (successful) {
2076     if (verbosity >= G4VisManager::confirmati    1872     if (verbosity >= G4VisManager::confirmations) {
2077       G4cout                                  << 1873       G4cout << "Magnetic field, if any, will be drawn in scene \""
2078       << "Magnetic field, if any, will be dra << 
2079       << currentSceneName                        1874       << currentSceneName
2080       << "\"\n  with "                           1875       << "\"\n  with "
2081       << nDataPointsPerHalfScene                 1876       << nDataPointsPerHalfScene
2082       << " data points per half extent and wi << 1877       << " data points per half scene and with representation \""
2083       << representation                          1878       << representation
2084       << '\"'                                    1879       << '\"'
2085       << G4endl;                                 1880       << G4endl;
2086     }                                            1881     }
2087   }                                              1882   }
2088   else G4VisCommandsSceneAddUnsuccessful(verb    1883   else G4VisCommandsSceneAddUnsuccessful(verbosity);
2089                                               << 1884   UpdateVisManagerScene (currentSceneName);
2090   CheckSceneAndNotifyHandlers (pScene);       << 
2091 }                                                1885 }
2092                                                  1886 
2093 ////////////// /vis/scene/add/psHits ////////    1887 ////////////// /vis/scene/add/psHits ///////////////////////////////////////
2094                                                  1888 
2095 G4VisCommandSceneAddPSHits::G4VisCommandScene    1889 G4VisCommandSceneAddPSHits::G4VisCommandSceneAddPSHits () {
2096   G4bool omitable;                               1890   G4bool omitable;
2097   fpCommand = new G4UIcmdWithAString ("/vis/s    1891   fpCommand = new G4UIcmdWithAString ("/vis/scene/add/psHits", this);
2098   fpCommand -> SetGuidance                       1892   fpCommand -> SetGuidance
2099     ("Adds Primitive Scorer Hits (PSHits) to     1893     ("Adds Primitive Scorer Hits (PSHits) to current scene.");
2100   fpCommand -> SetGuidance                       1894   fpCommand -> SetGuidance
2101     ("PSHits are drawn at end of run when the    1895     ("PSHits are drawn at end of run when the scene in which"
2102      "\nthey are added is current.");            1896      "\nthey are added is current.");
2103   fpCommand -> SetGuidance                       1897   fpCommand -> SetGuidance
2104     ("Optional parameter specifies name of sc    1898     ("Optional parameter specifies name of scoring map.  By default all"
2105      "\nscoring maps registered with the G4Sc    1899      "\nscoring maps registered with the G4ScoringManager are drawn.");
2106   fpCommand -> SetParameterName ("mapname", o    1900   fpCommand -> SetParameterName ("mapname", omitable = true);
2107   fpCommand -> SetDefaultValue ("all");          1901   fpCommand -> SetDefaultValue ("all");
2108 }                                                1902 }
2109                                                  1903 
2110 G4VisCommandSceneAddPSHits::~G4VisCommandScen    1904 G4VisCommandSceneAddPSHits::~G4VisCommandSceneAddPSHits () {
2111   delete fpCommand;                              1905   delete fpCommand;
2112 }                                                1906 }
2113                                                  1907 
2114 G4String G4VisCommandSceneAddPSHits::GetCurre    1908 G4String G4VisCommandSceneAddPSHits::GetCurrentValue (G4UIcommand*) {
2115   return "";                                     1909   return "";
2116 }                                                1910 }
2117                                                  1911 
2118 void G4VisCommandSceneAddPSHits::SetNewValue     1912 void G4VisCommandSceneAddPSHits::SetNewValue
2119 (G4UIcommand*, G4String newValue)                1913 (G4UIcommand*, G4String newValue)
2120 {                                                1914 {
2121   G4VisManager::Verbosity verbosity = fpVisMa    1915   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2122   G4bool warn(verbosity >= G4VisManager::warn    1916   G4bool warn(verbosity >= G4VisManager::warnings);
2123                                                  1917 
2124   G4Scene* pScene = fpVisManager->GetCurrentS    1918   G4Scene* pScene = fpVisManager->GetCurrentScene();
2125   if (!pScene) {                                 1919   if (!pScene) {
2126     if (verbosity >= G4VisManager::errors) {     1920     if (verbosity >= G4VisManager::errors) {
2127       G4warn << "ERROR: No current scene.  Pl << 1921       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
2128     }                                            1922     }
2129     return;                                      1923     return;
2130   }                                              1924   }
2131                                                  1925 
2132   G4VModel* model = new G4PSHitsModel(newValu    1926   G4VModel* model = new G4PSHitsModel(newValue);
2133   const G4String& currentSceneName = pScene -    1927   const G4String& currentSceneName = pScene -> GetName ();
2134   G4bool successful = pScene -> AddEndOfRunMo    1928   G4bool successful = pScene -> AddEndOfRunModel (model, warn);
2135   if (successful) {                              1929   if (successful) {
2136     if (verbosity >= G4VisManager::confirmati    1930     if (verbosity >= G4VisManager::confirmations) {
2137       if (newValue == "all") {                   1931       if (newValue == "all") {
2138   G4cout << "All Primitive Scorer hits";         1932   G4cout << "All Primitive Scorer hits";
2139       } else {                                   1933       } else {
2140   G4cout << "Hits of Primitive Scorer \"" <<     1934   G4cout << "Hits of Primitive Scorer \"" << newValue << '"';
2141       }                                          1935       }
2142       G4cout << " will be drawn at end of run    1936       G4cout << " will be drawn at end of run in scene \""
2143        << currentSceneName << "\"."              1937        << currentSceneName << "\"."
2144        << G4endl;                                1938        << G4endl;
2145     }                                            1939     }
2146   }                                              1940   }
2147   else G4VisCommandsSceneAddUnsuccessful(verb    1941   else G4VisCommandsSceneAddUnsuccessful(verbosity);
2148                                               << 1942   UpdateVisManagerScene (currentSceneName);
2149   CheckSceneAndNotifyHandlers (pScene);       << 
2150 }                                                1943 }
2151                                                  1944 
2152 ////////////// /vis/scene/add/scale /////////    1945 ////////////// /vis/scene/add/scale //////////////////////////////////
2153                                                  1946 
2154 G4VisCommandSceneAddScale::G4VisCommandSceneA    1947 G4VisCommandSceneAddScale::G4VisCommandSceneAddScale () {
2155   G4bool omitable;                               1948   G4bool omitable;
2156   fpCommand = new G4UIcommand ("/vis/scene/ad    1949   fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
2157   fpCommand -> SetGuidance                       1950   fpCommand -> SetGuidance
2158   ("Adds an annotated scale line to the curre    1951   ("Adds an annotated scale line to the current scene.");
2159   fpCommand -> SetGuidance                       1952   fpCommand -> SetGuidance
2160   ("If \"unit\" is \"auto\", length is roughl    1953   ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
2161   fpCommand -> SetGuidance                       1954   fpCommand -> SetGuidance
2162   ("If \"direction\" is \"auto\", scale is ro    1955   ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
2163   fpCommand -> SetGuidance                       1956   fpCommand -> SetGuidance
2164   ("If \"placement\" is \"auto\", scale is pl    1957   ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
2165    "\n  Otherwise placed at (xmid,ymid,zmid).    1958    "\n  Otherwise placed at (xmid,ymid,zmid).");
2166   fpCommand -> SetGuidance                    << 1959   fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
2167   ("An annotated line in the specified direct << 
2168    "\nend.  If autoPlacing is true it is requ << 
2169    "\nfront, right, bottom corner of the worl << 
2170    "\nthe existing bounding box/sphere so tha << 
2171    "\nobscure it.  Otherwise it is required t << 
2172    "\n(xmid, ymid, zmid)."                    << 
2173    "\n"                                       << 
2174    "\nThe auto placing algorithm is (approx): << 
2175    "\n  x = xmin + (1 + comfort) * (xmax - xm << 
2176    "\n  y = ymin - comfort * (ymax - ymin);"  << 
2177    "\n  z = zmin + (1 + comfort) * (zmax - zm << 
2178    "\n  if direction == x then (x - length,y, << 
2179    "\n  if direction == y then (x,y,z) to (x, << 
2180    "\n  if direction == z then (x,y,z - lengt << 
2181    );                                         << 
2182   G4UIparameter* parameter;                      1960   G4UIparameter* parameter;
2183   parameter = new G4UIparameter ("length", 'd    1961   parameter = new G4UIparameter ("length", 'd', omitable = true);
2184   parameter->SetDefaultValue (1.);               1962   parameter->SetDefaultValue (1.);
2185   fpCommand->SetParameter (parameter);           1963   fpCommand->SetParameter (parameter);
2186   parameter =  new G4UIparameter ("unit", 's'    1964   parameter =  new G4UIparameter ("unit", 's', omitable = true);
2187   parameter->SetDefaultValue ("auto");           1965   parameter->SetDefaultValue ("auto");
2188   fpCommand->SetParameter (parameter);           1966   fpCommand->SetParameter (parameter);
2189   parameter =  new G4UIparameter ("direction"    1967   parameter =  new G4UIparameter ("direction", 's', omitable = true);
2190   parameter->SetGuidance ("auto|x|y|z");         1968   parameter->SetGuidance ("auto|x|y|z");
2191   parameter->SetDefaultValue ("auto");           1969   parameter->SetDefaultValue ("auto");
2192   fpCommand->SetParameter (parameter);           1970   fpCommand->SetParameter (parameter);
2193   parameter =  new G4UIparameter ("red", 'd',    1971   parameter =  new G4UIparameter ("red", 'd', omitable = true);
2194   parameter->SetDefaultValue (1.);               1972   parameter->SetDefaultValue (1.);
2195   fpCommand->SetParameter (parameter);           1973   fpCommand->SetParameter (parameter);
2196   parameter =  new G4UIparameter ("green", 'd    1974   parameter =  new G4UIparameter ("green", 'd', omitable = true);
2197   parameter->SetDefaultValue (0.);               1975   parameter->SetDefaultValue (0.);
2198   fpCommand->SetParameter (parameter);           1976   fpCommand->SetParameter (parameter);
2199   parameter =  new G4UIparameter ("blue", 'd'    1977   parameter =  new G4UIparameter ("blue", 'd', omitable = true);
2200   parameter->SetDefaultValue (0.);               1978   parameter->SetDefaultValue (0.);
2201   fpCommand->SetParameter (parameter);           1979   fpCommand->SetParameter (parameter);
2202   parameter =  new G4UIparameter ("placement"    1980   parameter =  new G4UIparameter ("placement", 's', omitable = true);
2203   parameter -> SetParameterCandidates("auto m    1981   parameter -> SetParameterCandidates("auto manual");
2204   parameter->SetDefaultValue  ("auto");          1982   parameter->SetDefaultValue  ("auto");
2205   fpCommand->SetParameter     (parameter);       1983   fpCommand->SetParameter     (parameter);
2206   parameter =  new G4UIparameter ("xmid", 'd'    1984   parameter =  new G4UIparameter ("xmid", 'd', omitable = true);
2207   parameter->SetDefaultValue (0.);               1985   parameter->SetDefaultValue (0.);
2208   fpCommand->SetParameter (parameter);           1986   fpCommand->SetParameter (parameter);
2209   parameter =  new G4UIparameter ("ymid", 'd'    1987   parameter =  new G4UIparameter ("ymid", 'd', omitable = true);
2210   parameter->SetDefaultValue (0.);               1988   parameter->SetDefaultValue (0.);
2211   fpCommand->SetParameter (parameter);           1989   fpCommand->SetParameter (parameter);
2212   parameter =  new G4UIparameter ("zmid", 'd'    1990   parameter =  new G4UIparameter ("zmid", 'd', omitable = true);
2213   parameter->SetDefaultValue (0.);               1991   parameter->SetDefaultValue (0.);
2214   fpCommand->SetParameter (parameter);           1992   fpCommand->SetParameter (parameter);
2215   parameter =  new G4UIparameter ("unit", 's'    1993   parameter =  new G4UIparameter ("unit", 's', omitable = true);
2216   parameter->SetDefaultValue ("m");              1994   parameter->SetDefaultValue ("m");
2217   fpCommand->SetParameter (parameter);           1995   fpCommand->SetParameter (parameter);
2218 }                                                1996 }
2219                                                  1997 
2220 G4VisCommandSceneAddScale::~G4VisCommandScene    1998 G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale () {
2221   delete fpCommand;                              1999   delete fpCommand;
2222 }                                                2000 }
2223                                                  2001 
2224 G4String G4VisCommandSceneAddScale::GetCurren    2002 G4String G4VisCommandSceneAddScale::GetCurrentValue (G4UIcommand*) {
2225   return "";                                     2003   return "";
2226 }                                                2004 }
2227                                                  2005 
2228 void G4VisCommandSceneAddScale::SetNewValue (    2006 void G4VisCommandSceneAddScale::SetNewValue (G4UIcommand*, G4String newValue) {
2229                                                  2007 
2230   G4VisManager::Verbosity verbosity = fpVisMa    2008   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2231   G4bool warn = verbosity >= G4VisManager::wa    2009   G4bool warn = verbosity >= G4VisManager::warnings;
2232                                                  2010 
2233   G4Scene* pScene = fpVisManager->GetCurrentS    2011   G4Scene* pScene = fpVisManager->GetCurrentScene();
2234   if (!pScene) {                                 2012   if (!pScene) {
2235     if (verbosity >= G4VisManager::errors) {     2013     if (verbosity >= G4VisManager::errors) {
2236       G4warn << "ERROR: No current scene.  Pl << 2014       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
2237     }                                            2015     }
2238     return;                                      2016     return;
2239   } else {                                       2017   } else {
2240     if (pScene->GetExtent().GetExtentRadius()    2018     if (pScene->GetExtent().GetExtentRadius() <= 0.) {
2241       if (verbosity >= G4VisManager::errors)     2019       if (verbosity >= G4VisManager::errors) {
2242         G4warn                                << 2020         G4cerr
2243   << "ERROR: Scene has no extent. Add volumes    2021   << "ERROR: Scene has no extent. Add volumes or use \"/vis/scene/add/extent\"."
2244         << G4endl;                               2022         << G4endl;
2245       }                                          2023       }
2246       return;                                    2024       return;
2247     }                                            2025     }
2248   }                                              2026   }
2249                                                  2027 
2250   G4double userLength, red, green, blue, xmid    2028   G4double userLength, red, green, blue, xmid, ymid, zmid;
2251   G4String userLengthUnit, direction, placeme << 2029   G4String userLengthUnit, direction, auto_manual, positionUnit;
2252   std::istringstream is (newValue);              2030   std::istringstream is (newValue);
2253   is >> userLength >> userLengthUnit >> direc    2031   is >> userLength >> userLengthUnit >> direction
2254      >> red >> green >> blue                     2032      >> red >> green >> blue
2255      >> placement                             << 2033      >> auto_manual
2256      >> xmid >> ymid >> zmid >> positionUnit;    2034      >> xmid >> ymid >> zmid >> positionUnit;
2257                                                  2035 
2258   G4double length = userLength;                  2036   G4double length = userLength;
2259   const G4VisExtent& sceneExtent = pScene->Ge    2037   const G4VisExtent& sceneExtent = pScene->GetExtent();  // Existing extent.
2260   if (userLengthUnit == "auto") {                2038   if (userLengthUnit == "auto") {
2261     const G4double lengthMax = 0.5 * sceneExt    2039     const G4double lengthMax = 0.5 * sceneExtent.GetExtentRadius();
2262     const G4double intLog10Length = std::floo    2040     const G4double intLog10Length = std::floor(std::log10(lengthMax));
2263     length = std::pow(10,intLog10Length);        2041     length = std::pow(10,intLog10Length);
2264     if (5.*length < lengthMax) length *= 5.;     2042     if (5.*length < lengthMax) length *= 5.;
2265     else if (2.*length < lengthMax) length *=    2043     else if (2.*length < lengthMax) length *= 2.;
2266   } else {                                       2044   } else {
2267     length *= G4UIcommand::ValueOf(userLength    2045     length *= G4UIcommand::ValueOf(userLengthUnit);
2268   }                                              2046   }
2269   G4String annotation = G4BestUnit(length,"Le    2047   G4String annotation = G4BestUnit(length,"Length");
2270                                                  2048 
2271   G4double unit = G4UIcommand::ValueOf(positi    2049   G4double unit = G4UIcommand::ValueOf(positionUnit);
2272   xmid *= unit; ymid *= unit; zmid *= unit;      2050   xmid *= unit; ymid *= unit; zmid *= unit;
2273                                                  2051 
2274   Scale::Direction scaleDirection (Scale::x); << 2052   G4Scale::Direction scaleDirection (G4Scale::x);
2275   if (direction[0] == 'y') scaleDirection = S << 2053   if (direction(0) == 'y') scaleDirection = G4Scale::y;
2276   if (direction[0] == 'z') scaleDirection = S << 2054   if (direction(0) == 'z') scaleDirection = G4Scale::z;
2277                                                  2055 
2278   G4VViewer* pViewer = fpVisManager->GetCurre    2056   G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
2279   if (!pViewer) {                                2057   if (!pViewer) {
2280     if (verbosity >= G4VisManager::errors) {     2058     if (verbosity >= G4VisManager::errors) {
2281       G4warn <<                               << 2059       G4cerr <<
2282   "ERROR: G4VisCommandSceneAddScale::SetNewVa    2060   "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
2283   "\n  Auto direction needs a viewer."           2061   "\n  Auto direction needs a viewer."
2284        << G4endl;                                2062        << G4endl;
2285     }                                            2063     }
2286     return;                                      2064     return;
2287   }                                              2065   }
2288                                                  2066 
2289   const G4Vector3D& vp =                         2067   const G4Vector3D& vp =
2290     pViewer->GetViewParameters().GetViewpoint    2068     pViewer->GetViewParameters().GetViewpointDirection();
2291   const G4Vector3D& up =                         2069   const G4Vector3D& up =
2292     pViewer->GetViewParameters().GetUpVector(    2070     pViewer->GetViewParameters().GetUpVector();
2293                                                  2071 
2294   if (direction == "auto") {  // Takes cue fr    2072   if (direction == "auto") {  // Takes cue from viewer.
2295     if (std::abs(vp.x()) > std::abs(vp.y()) &    2073     if (std::abs(vp.x()) > std::abs(vp.y()) &&
2296   std::abs(vp.x()) > std::abs(vp.z())) {  //     2074   std::abs(vp.x()) > std::abs(vp.z())) {  // x viewpoint
2297       if (std::abs(up.y()) > std::abs(up.z()) << 2075       if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = G4Scale::z;
2298     else scaleDirection = Scale::y;           << 2076     else scaleDirection = G4Scale::y;
2299     }                                            2077     }
2300     else if (std::abs(vp.y()) > std::abs(vp.x    2078     else if (std::abs(vp.y()) > std::abs(vp.x()) &&
2301        std::abs(vp.y()) > std::abs(vp.z())) {    2079        std::abs(vp.y()) > std::abs(vp.z())) {  // y viewpoint
2302       if (std::abs(up.x()) > std::abs(up.z()) << 2080       if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = G4Scale::z;
2303     else scaleDirection = Scale::x;           << 2081     else scaleDirection = G4Scale::x;
2304     }                                            2082     }
2305     else if (std::abs(vp.z()) > std::abs(vp.x    2083     else if (std::abs(vp.z()) > std::abs(vp.x()) &&
2306        std::abs(vp.z()) > std::abs(vp.y())) {    2084        std::abs(vp.z()) > std::abs(vp.y())) {  // z viewpoint
2307       if (std::abs(up.y()) > std::abs(up.x()) << 2085       if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = G4Scale::x;
2308     else scaleDirection = Scale::y;           << 2086     else scaleDirection = G4Scale::y;
2309     }                                            2087     }
2310   }                                              2088   }
2311                                                  2089 
2312   G4bool autoPlacing = false; if (placement = << 2090   G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
2313   // Parameters read and interpreted.            2091   // Parameters read and interpreted.
2314                                                  2092 
2315   // Useful constants, etc...                    2093   // Useful constants, etc...
2316   const G4double halfLength(length / 2.);        2094   const G4double halfLength(length / 2.);
2317   const G4double comfort(0.01);  // 0.15 seem    2095   const G4double comfort(0.01);  // 0.15 seems too big.  0.05 might be better.
2318   const G4double freeLengthFraction (1. + 2.     2096   const G4double freeLengthFraction (1. + 2. * comfort);
2319                                                  2097 
2320   const G4double xmin = sceneExtent.GetXmin()    2098   const G4double xmin = sceneExtent.GetXmin();
2321   const G4double xmax = sceneExtent.GetXmax()    2099   const G4double xmax = sceneExtent.GetXmax();
2322   const G4double ymin = sceneExtent.GetYmin()    2100   const G4double ymin = sceneExtent.GetYmin();
2323   const G4double ymax = sceneExtent.GetYmax()    2101   const G4double ymax = sceneExtent.GetYmax();
2324   const G4double zmin = sceneExtent.GetZmin()    2102   const G4double zmin = sceneExtent.GetZmin();
2325   const G4double zmax = sceneExtent.GetZmax()    2103   const G4double zmax = sceneExtent.GetZmax();
2326                                                  2104 
2327   // Test existing extent and issue warnings.    2105   // Test existing extent and issue warnings...
2328   G4bool worried = false;                        2106   G4bool worried = false;
2329   if (sceneExtent.GetExtentRadius() == 0) {      2107   if (sceneExtent.GetExtentRadius() == 0) {
2330     worried = true;                              2108     worried = true;
2331     if (verbosity >= G4VisManager::warnings)     2109     if (verbosity >= G4VisManager::warnings) {
2332       G4warn <<                               << 2110       G4cout <<
2333   "WARNING: Existing scene does not yet have     2111   "WARNING: Existing scene does not yet have any extent."
2334   "\n  Maybe you have not yet added any geome    2112   "\n  Maybe you have not yet added any geometrical object."
2335        << G4endl;                                2113        << G4endl;
2336     }                                            2114     }
2337   }                                              2115   }
2338                                               << 
2339   // Test existing scene for room...             2116   // Test existing scene for room...
2340   G4bool room  = true;                           2117   G4bool room  = true;
2341   switch (scaleDirection) {                      2118   switch (scaleDirection) {
2342   case Scale::x:                              << 2119   case G4Scale::x:
2343     if (freeLengthFraction * (xmax - xmin) <     2120     if (freeLengthFraction * (xmax - xmin) < length) room = false;
2344     break;                                       2121     break;
2345   case Scale::y:                              << 2122   case G4Scale::y:
2346     if (freeLengthFraction * (ymax - ymin) <     2123     if (freeLengthFraction * (ymax - ymin) < length) room = false;
2347     break;                                       2124     break;
2348   case Scale::z:                              << 2125   case G4Scale::z:
2349     if (freeLengthFraction * (zmax - zmin) <     2126     if (freeLengthFraction * (zmax - zmin) < length) room = false;
2350     break;                                       2127     break;
2351   }                                              2128   }
2352   if (!room) {                                   2129   if (!room) {
2353     worried = true;                              2130     worried = true;
2354     if (verbosity >= G4VisManager::warnings)     2131     if (verbosity >= G4VisManager::warnings) {
2355       G4warn <<                               << 2132       G4cout <<
2356   "WARNING: Not enough room in existing scene    2133   "WARNING: Not enough room in existing scene.  Maybe scale is too long."
2357        << G4endl;                                2134        << G4endl;
2358     }                                            2135     }
2359   }                                              2136   }
2360   if (worried) {                                 2137   if (worried) {
2361     if (verbosity >= G4VisManager::warnings)     2138     if (verbosity >= G4VisManager::warnings) {
2362       G4warn <<                               << 2139       G4cout <<
2363   "WARNING: The scale you have asked for is b    2140   "WARNING: The scale you have asked for is bigger than the existing"
2364   "\n  scene.  Maybe you have added it too so    2141   "\n  scene.  Maybe you have added it too soon.  It is recommended that"
2365   "\n  you add the scale last so that it can     2142   "\n  you add the scale last so that it can be correctly auto-positioned"
2366   "\n  so as not to be obscured by any existi    2143   "\n  so as not to be obscured by any existing object and so that the"
2367   "\n  view parameters can be correctly recal    2144   "\n  view parameters can be correctly recalculated."
2368        << G4endl;                                2145        << G4endl;
2369     }                                            2146     }
2370   }                                              2147   }
2371                                                  2148 
                                                   >> 2149   // Let's go ahead a construct a scale and a scale model.  Since the
                                                   >> 2150   // placing is done here, this G4Scale is *not* auto-placed...
                                                   >> 2151   G4Scale scale(length, annotation, scaleDirection,
                                                   >> 2152     false, xmid, ymid, zmid,
                                                   >> 2153                 fCurrentTextSize);
                                                   >> 2154   G4VisAttributes visAttr(G4Colour(red, green, blue));
                                                   >> 2155   scale.SetVisAttributes(visAttr);
                                                   >> 2156   G4VModel* model = new G4ScaleModel(scale);
                                                   >> 2157   G4String globalDescription = model->GetGlobalDescription();
                                                   >> 2158   globalDescription += " (" + newValue + ")";
                                                   >> 2159   model->SetGlobalDescription(globalDescription);
                                                   >> 2160 
2372   // Now figure out the extent...                2161   // Now figure out the extent...
2373   //                                             2162   //
                                                   >> 2163   // From the G4Scale.hh:
                                                   >> 2164   //
2374   // This creates a representation of annotat    2165   // This creates a representation of annotated line in the specified
2375   // direction with tick marks at the end.  I    2166   // direction with tick marks at the end.  If autoPlacing is true it
2376   // is required to be centred at the front,     2167   // is required to be centred at the front, right, bottom corner of
2377   // the world space, comfortably outside the    2168   // the world space, comfortably outside the existing bounding
2378   // box/sphere so that existing objects do n    2169   // box/sphere so that existing objects do not obscure it.  Otherwise
2379   // it is required to be drawn with mid-poin    2170   // it is required to be drawn with mid-point at (xmid, ymid, zmid).
2380   //                                             2171   //
2381   // The auto placing algorithm might be:        2172   // The auto placing algorithm might be:
2382   //   x = xmin + (1 + comfort) * (xmax - xmi    2173   //   x = xmin + (1 + comfort) * (xmax - xmin)
2383   //   y = ymin - comfort * (ymax - ymin)        2174   //   y = ymin - comfort * (ymax - ymin)
2384   //   z = zmin + (1 + comfort) * (zmax - zmi    2175   //   z = zmin + (1 + comfort) * (zmax - zmin)
2385   //   if direction == x then (x - length,y,z    2176   //   if direction == x then (x - length,y,z) to (x,y,z)
2386   //   if direction == y then (x,y,z) to (x,y    2177   //   if direction == y then (x,y,z) to (x,y + length,z)
2387   //   if direction == z then (x,y,z - length    2178   //   if direction == z then (x,y,z - length) to (x,y,z)
2388   //                                             2179   //
                                                   >> 2180   // End of clip from G4Scale.hh:
                                                   >> 2181   //
2389   // Implement this in two parts.  Here, use     2182   // Implement this in two parts.  Here, use the scale's extent to
2390   // "expand" the scene's extent.  Then rende    2183   // "expand" the scene's extent.  Then rendering - in
2391   // G4VSceneHandler::AddPrimitive(const G4Sc    2184   // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
2392   // ensure it's within the new extent.          2185   // ensure it's within the new extent.
2393   //                                             2186   //
2394                                                  2187 
2395   G4double sxmid(xmid), symid(ymid), szmid(zm    2188   G4double sxmid(xmid), symid(ymid), szmid(zmid);
2396   if (autoPlacing) {                             2189   if (autoPlacing) {
2397     // Aim to place at bottom right of screen    2190     // Aim to place at bottom right of screen in current view.
2398     // Give some comfort zone.                   2191     // Give some comfort zone.
2399     const G4double xComfort = comfort * (xmax    2192     const G4double xComfort = comfort * (xmax - xmin);
2400     const G4double yComfort = comfort * (ymax    2193     const G4double yComfort = comfort * (ymax - ymin);
2401     const G4double zComfort = comfort * (zmax    2194     const G4double zComfort = comfort * (zmax - zmin);
2402     switch (scaleDirection) {                    2195     switch (scaleDirection) {
2403     case Scale::x:                            << 2196     case G4Scale::x:
2404       if (vp.z() > 0.) {                         2197       if (vp.z() > 0.) {
2405   sxmid = xmax + xComfort;                       2198   sxmid = xmax + xComfort;
2406   symid = ymin - yComfort;                       2199   symid = ymin - yComfort;
2407   szmid = zmin - zComfort;                       2200   szmid = zmin - zComfort;
2408       } else {                                   2201       } else {
2409   sxmid = xmin - xComfort;                       2202   sxmid = xmin - xComfort;
2410   symid = ymin - yComfort;                       2203   symid = ymin - yComfort;
2411   szmid = zmax + zComfort;                       2204   szmid = zmax + zComfort;
2412       }                                          2205       }
2413       break;                                     2206       break;
2414     case Scale::y:                            << 2207     case G4Scale::y:
2415       if (vp.x() > 0.) {                         2208       if (vp.x() > 0.) {
2416   sxmid = xmin - xComfort;                       2209   sxmid = xmin - xComfort;
2417   symid = ymax + yComfort;                       2210   symid = ymax + yComfort;
2418   szmid = zmin - zComfort;                       2211   szmid = zmin - zComfort;
2419       } else {                                   2212       } else {
2420   sxmid = xmax + xComfort;                       2213   sxmid = xmax + xComfort;
2421   symid = ymin - yComfort;                       2214   symid = ymin - yComfort;
2422   szmid = zmin - zComfort;                       2215   szmid = zmin - zComfort;
2423       }                                          2216       }
2424       break;                                     2217       break;
2425     case Scale::z:                            << 2218     case G4Scale::z:
2426       if (vp.x() > 0.) {                         2219       if (vp.x() > 0.) {
2427   sxmid = xmax + xComfort;                       2220   sxmid = xmax + xComfort;
2428   symid = ymin - yComfort;                       2221   symid = ymin - yComfort;
2429   szmid = zmax + zComfort;                       2222   szmid = zmax + zComfort;
2430       } else {                                   2223       } else {
2431   sxmid = xmin - xComfort;                       2224   sxmid = xmin - xComfort;
2432   symid = ymin - yComfort;                       2225   symid = ymin - yComfort;
2433   szmid = zmax + zComfort;                       2226   szmid = zmax + zComfort;
2434       }                                          2227       }
2435       break;                                     2228       break;
2436     }                                            2229     }
2437   }                                              2230   }
2438                                                  2231 
                                                   >> 2232   /* Old code - kept for future reference.
                                                   >> 2233   G4double sxmid(xmid), symid(ymid), szmid(zmid);
                                                   >> 2234   if (autoPlacing) {
                                                   >> 2235     sxmid = xmin + onePlusComfort * (xmax - xmin);
                                                   >> 2236     symid = ymin - comfort * (ymax - ymin);
                                                   >> 2237     szmid = zmin + onePlusComfort * (zmax - zmin);
                                                   >> 2238     switch (scaleDirection) {
                                                   >> 2239     case G4Scale::x:
                                                   >> 2240       sxmid -= halfLength;
                                                   >> 2241       break;
                                                   >> 2242     case G4Scale::y:
                                                   >> 2243       symid += halfLength;
                                                   >> 2244       break;
                                                   >> 2245     case G4Scale::z:
                                                   >> 2246       szmid -= halfLength;
                                                   >> 2247       break;
                                                   >> 2248     }
                                                   >> 2249   }
                                                   >> 2250   */
                                                   >> 2251 
                                                   >> 2252   /* sxmin, etc., not actually used.  Comment out to prevent compiler
                                                   >> 2253      warnings but keep in case need in future.  Extract transform and
                                                   >> 2254      scaleExtent into reduced code below.
                                                   >> 2255   G4double sxmin(sxmid), sxmax(sxmid);
                                                   >> 2256   G4double symin(symid), symax(symid);
                                                   >> 2257   G4double szmin(szmid), szmax(szmid);
2439   G4Transform3D transform;                       2258   G4Transform3D transform;
2440   const G4double h = halfLength;              << 2259   G4VisExtent scaleExtent;
2441   const G4double t = h/5.;                    << 
2442   G4VisExtent scaleExtent(-h,h,-t,t,-t,t);    << 
2443   switch (scaleDirection) {                      2260   switch (scaleDirection) {
2444   case Scale::x:                              << 2261   case G4Scale::x:
                                                   >> 2262     sxmin = sxmid - halfLength;
                                                   >> 2263     sxmax = sxmid + halfLength;
                                                   >> 2264     scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
2445     break;                                       2265     break;
2446   case Scale::y:                              << 2266   case G4Scale::y:
                                                   >> 2267     symin = symid - halfLength;
                                                   >> 2268     symax = symid + halfLength;
2447     transform = G4RotateZ3D(halfpi);             2269     transform = G4RotateZ3D(halfpi);
                                                   >> 2270     scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
2448     break;                                       2271     break;
2449   case Scale::z:                              << 2272   case G4Scale::z:
                                                   >> 2273     szmin = szmid - halfLength;
                                                   >> 2274     szmax = szmid + halfLength;
2450     transform = G4RotateY3D(halfpi);             2275     transform = G4RotateY3D(halfpi);
                                                   >> 2276     scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
                                                   >> 2277     break;
                                                   >> 2278   }
                                                   >> 2279   */
                                                   >> 2280   G4Transform3D transform;
                                                   >> 2281   G4VisExtent scaleExtent;
                                                   >> 2282   switch (scaleDirection) {
                                                   >> 2283   case G4Scale::x:
                                                   >> 2284     scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
                                                   >> 2285     break;
                                                   >> 2286   case G4Scale::y:
                                                   >> 2287     transform = G4RotateZ3D(halfpi);
                                                   >> 2288     scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
                                                   >> 2289     break;
                                                   >> 2290   case G4Scale::z:
                                                   >> 2291     transform = G4RotateY3D(halfpi);
                                                   >> 2292     scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
2451     break;                                       2293     break;
2452   }                                              2294   }
2453   transform = G4Translate3D(sxmid,symid,szmid    2295   transform = G4Translate3D(sxmid,symid,szmid) * transform;
2454   scaleExtent = scaleExtent.Transform(transfo << 2296   /////////  G4VisExtent scaleExtent(sxmin, sxmax, symin, symax, szmin, szmax);
2455                                                  2297 
2456   G4Colour colour(red, green, blue);          << 
2457   if (direction == "auto") {                  << 
2458     switch (scaleDirection) {                 << 
2459       case Scale::x:                          << 
2460   colour = G4Colour::Red();                   << 
2461   break;                                      << 
2462       case Scale::y:                          << 
2463   colour = G4Colour::Green();                 << 
2464   break;                                      << 
2465       case Scale::z:                          << 
2466   colour = G4Colour::Blue();                  << 
2467   break;                                      << 
2468     }                                         << 
2469   }                                           << 
2470   G4VisAttributes visAttr(colour);            << 
2471                                                  2298 
2472   Scale* scale = new Scale                    << 2299   model->SetTransformation(transform);
2473   (visAttr, length, transform,                << 2300   // Note: it is the responsibility of the model to act upon this, but
2474    annotation, fCurrentTextSize, colour);     << 2301   // the extent is in local coordinates...
2475   G4VModel* model = new G4CallbackModel<Scale << 
2476   model->SetType("Scale");                    << 
2477   model->SetGlobalTag("Scale");               << 
2478   model->SetGlobalDescription("Scale: " + new << 
2479   model->SetExtent(scaleExtent);                 2302   model->SetExtent(scaleExtent);
                                                   >> 2303   // This extent gets "added" to existing scene extent in
                                                   >> 2304   // AddRunDurationModel below.
2480                                                  2305 
2481   const G4String& currentSceneName = pScene -    2306   const G4String& currentSceneName = pScene -> GetName ();
2482   G4bool successful = pScene -> AddRunDuratio    2307   G4bool successful = pScene -> AddRunDurationModel (model, warn);
2483   if (successful) {                              2308   if (successful) {
2484     if (verbosity >= G4VisManager::confirmati    2309     if (verbosity >= G4VisManager::confirmations) {
2485       G4cout << "Scale of " << annotation        2310       G4cout << "Scale of " << annotation
2486        << " added to scene \"" << currentScen    2311        << " added to scene \"" << currentSceneName << "\".";
2487       if (verbosity >= G4VisManager::paramete    2312       if (verbosity >= G4VisManager::parameters) {
2488   G4cout << "\n  with extent " << scaleExtent    2313   G4cout << "\n  with extent " << scaleExtent
2489          << "\n  at " << transform.getRotatio    2314          << "\n  at " << transform.getRotation()
2490          << "  " << transform.getTranslation( << 2315          << transform.getTranslation();
2491       }                                          2316       }
2492       G4cout << G4endl;                          2317       G4cout << G4endl;
2493     }                                            2318     }
2494   }                                              2319   }
2495   else G4VisCommandsSceneAddUnsuccessful(verb    2320   else G4VisCommandsSceneAddUnsuccessful(verbosity);
2496                                               << 2321   UpdateVisManagerScene (currentSceneName);
2497   CheckSceneAndNotifyHandlers (pScene);       << 
2498 }                                             << 
2499                                               << 
2500 G4VisCommandSceneAddScale::Scale::Scale       << 
2501  (const G4VisAttributes& visAtts,             << 
2502   G4double length, const G4Transform3D& trans << 
2503   const G4String& annotation, G4double annota << 
2504   const G4Colour& annotationColour):          << 
2505 fVisAtts(visAtts)                             << 
2506 {                                             << 
2507   // Useful constants...                      << 
2508   const G4double halfLength(length / 2.);     << 
2509   const G4double tickLength(length / 20.);    << 
2510                                               << 
2511   // Create (empty) polylines having the same << 
2512   // (OK to pass address since fVisAtts is lo << 
2513   fScaleLine.SetVisAttributes(&fVisAtts);     << 
2514   fTick11.SetVisAttributes(&fVisAtts);        << 
2515   fTick12.SetVisAttributes(&fVisAtts);        << 
2516   fTick21.SetVisAttributes(&fVisAtts);        << 
2517   fTick22.SetVisAttributes(&fVisAtts);        << 
2518                                               << 
2519   // Add points to the polylines to represent << 
2520   // x-axis centred on the origin...          << 
2521   G4Point3D r1(G4Point3D(-halfLength, 0., 0.) << 
2522   G4Point3D r2(G4Point3D( halfLength, 0., 0.) << 
2523   fScaleLine.push_back(r1);                   << 
2524   fScaleLine.push_back(r2);                   << 
2525   G4Point3D ticky(0., tickLength, 0.);        << 
2526   G4Point3D tickz(0., 0., tickLength);        << 
2527   fTick11.push_back(r1 + ticky);              << 
2528   fTick11.push_back(r1 - ticky);              << 
2529   fTick12.push_back(r1 + tickz);              << 
2530   fTick12.push_back(r1 - tickz);              << 
2531   fTick21.push_back(r2 + ticky);              << 
2532   fTick21.push_back(r2 - ticky);              << 
2533   fTick22.push_back(r2 + tickz);              << 
2534   fTick22.push_back(r2 - tickz);              << 
2535   // ...and transform to chosen position and  << 
2536   fScaleLine.transform(transform);            << 
2537   fTick11.transform(transform);               << 
2538   fTick12.transform(transform);               << 
2539   fTick21.transform(transform);               << 
2540   fTick22.transform(transform);               << 
2541   // Similarly for annotation                 << 
2542   G4Point3D textPosition(0., tickLength, 0.); << 
2543   textPosition.transform(transform);          << 
2544   fText = G4Text(annotation,textPosition);    << 
2545   fText.SetVisAttributes(annotationColour);   << 
2546   fText.SetScreenSize(annotationSize);        << 
2547 }                                                2322 }
2548                                                  2323 
2549 void G4VisCommandSceneAddScale::Scale::operat << 
2550 (G4VGraphicsScene& sceneHandler,const G4Model << 
2551 {                                             << 
2552   // Draw...                                  << 
2553   sceneHandler.BeginPrimitives();             << 
2554   sceneHandler.AddPrimitive(fScaleLine);      << 
2555   sceneHandler.AddPrimitive(fTick11);         << 
2556   sceneHandler.AddPrimitive(fTick12);         << 
2557   sceneHandler.AddPrimitive(fTick21);         << 
2558   sceneHandler.AddPrimitive(fTick22);         << 
2559   sceneHandler.AddPrimitive(fText);           << 
2560   sceneHandler.EndPrimitives();               << 
2561 }                                             << 
2562                                                  2324 
2563 ////////////// /vis/scene/add/text //////////    2325 ////////////// /vis/scene/add/text //////////////////////////////////
2564                                                  2326 
2565 G4VisCommandSceneAddText::G4VisCommandSceneAd    2327 G4VisCommandSceneAddText::G4VisCommandSceneAddText () {
2566   G4bool omitable;                               2328   G4bool omitable;
2567   fpCommand = new G4UIcommand ("/vis/scene/ad    2329   fpCommand = new G4UIcommand ("/vis/scene/add/text", this);
2568   fpCommand -> SetGuidance ("Adds text to cur    2330   fpCommand -> SetGuidance ("Adds text to current scene.");
2569   fpCommand -> SetGuidance                       2331   fpCommand -> SetGuidance
2570     ("Use \"/vis/set/textColour\" to set colo    2332     ("Use \"/vis/set/textColour\" to set colour.");
2571   fpCommand -> SetGuidance                       2333   fpCommand -> SetGuidance
2572     ("Use \"/vis/set/textLayout\" to set layo    2334     ("Use \"/vis/set/textLayout\" to set layout:");
2573   G4UIparameter* parameter;                      2335   G4UIparameter* parameter;
2574   parameter = new G4UIparameter ("x", 'd', om    2336   parameter = new G4UIparameter ("x", 'd', omitable = true);
2575   parameter->SetDefaultValue (0);                2337   parameter->SetDefaultValue (0);
2576   fpCommand->SetParameter (parameter);           2338   fpCommand->SetParameter (parameter);
2577   parameter =  new G4UIparameter ("y", 'd', o    2339   parameter =  new G4UIparameter ("y", 'd', omitable = true);
2578   parameter->SetDefaultValue (0);                2340   parameter->SetDefaultValue (0);
2579   fpCommand->SetParameter (parameter);           2341   fpCommand->SetParameter (parameter);
2580   parameter =  new G4UIparameter ("z", 'd', o    2342   parameter =  new G4UIparameter ("z", 'd', omitable = true);
2581   parameter->SetDefaultValue (0);                2343   parameter->SetDefaultValue (0);
2582   fpCommand->SetParameter (parameter);           2344   fpCommand->SetParameter (parameter);
2583   parameter =  new G4UIparameter ("unit", 's'    2345   parameter =  new G4UIparameter ("unit", 's', omitable = true);
2584   parameter->SetDefaultValue ("m");              2346   parameter->SetDefaultValue ("m");
2585   fpCommand->SetParameter     (parameter);       2347   fpCommand->SetParameter     (parameter);
2586   parameter =  new G4UIparameter ("font_size"    2348   parameter =  new G4UIparameter ("font_size", 'd', omitable = true);
2587   parameter->SetDefaultValue (12);               2349   parameter->SetDefaultValue (12);
2588   parameter->SetGuidance ("pixels");             2350   parameter->SetGuidance ("pixels");
2589   fpCommand->SetParameter (parameter);           2351   fpCommand->SetParameter (parameter);
2590   parameter =  new G4UIparameter ("x_offset",    2352   parameter =  new G4UIparameter ("x_offset", 'd', omitable = true);
2591   parameter->SetDefaultValue (0);                2353   parameter->SetDefaultValue (0);
2592   parameter->SetGuidance ("pixels");             2354   parameter->SetGuidance ("pixels");
2593   fpCommand->SetParameter (parameter);           2355   fpCommand->SetParameter (parameter);
2594   parameter =  new G4UIparameter ("y_offset",    2356   parameter =  new G4UIparameter ("y_offset", 'd', omitable = true);
2595   parameter->SetDefaultValue (0);                2357   parameter->SetDefaultValue (0);
2596   parameter->SetGuidance ("pixels");             2358   parameter->SetGuidance ("pixels");
2597   fpCommand->SetParameter (parameter);           2359   fpCommand->SetParameter (parameter);
2598   parameter =  new G4UIparameter ("text", 's'    2360   parameter =  new G4UIparameter ("text", 's', omitable = true);
2599   parameter->SetGuidance ("The rest of the li    2361   parameter->SetGuidance ("The rest of the line is text.");
2600   parameter->SetDefaultValue ("Hello G4");       2362   parameter->SetDefaultValue ("Hello G4");
2601   fpCommand->SetParameter (parameter);           2363   fpCommand->SetParameter (parameter);
2602 }                                                2364 }
2603                                                  2365 
2604 G4VisCommandSceneAddText::~G4VisCommandSceneA    2366 G4VisCommandSceneAddText::~G4VisCommandSceneAddText () {
2605   delete fpCommand;                              2367   delete fpCommand;
2606 }                                                2368 }
2607                                                  2369 
2608 G4String G4VisCommandSceneAddText::GetCurrent    2370 G4String G4VisCommandSceneAddText::GetCurrentValue (G4UIcommand*) {
2609   return "";                                     2371   return "";
2610 }                                                2372 }
2611                                                  2373 
2612 void G4VisCommandSceneAddText::SetNewValue (G    2374 void G4VisCommandSceneAddText::SetNewValue (G4UIcommand*, G4String newValue) {
2613                                                  2375 
2614   G4VisManager::Verbosity verbosity = fpVisMa    2376   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2615   G4bool warn = verbosity >= G4VisManager::wa    2377   G4bool warn = verbosity >= G4VisManager::warnings;
2616                                                  2378 
2617   G4Scene* pScene = fpVisManager->GetCurrentS    2379   G4Scene* pScene = fpVisManager->GetCurrentScene();
2618   if (!pScene) {                                 2380   if (!pScene) {
2619     if (verbosity >= G4VisManager::errors) {     2381     if (verbosity >= G4VisManager::errors) {
2620       G4warn << "ERROR: No current scene.  Pl << 2382       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
2621     }                                            2383     }
2622     return;                                      2384     return;
2623   }                                              2385   }
2624                                                  2386 
2625   G4Tokenizer next(newValue);                    2387   G4Tokenizer next(newValue);
2626   G4double x = StoD(next());                     2388   G4double x = StoD(next());
2627   G4double y = StoD(next());                     2389   G4double y = StoD(next());
2628   G4double z = StoD(next());                     2390   G4double z = StoD(next());
2629   G4String unitString = next();                  2391   G4String unitString = next();
2630   G4double font_size = StoD(next());             2392   G4double font_size = StoD(next());
2631   G4double x_offset = StoD(next());              2393   G4double x_offset = StoD(next());
2632   G4double y_offset = StoD(next());              2394   G4double y_offset = StoD(next());
2633   G4String text = next("\n");                    2395   G4String text = next("\n");
2634                                                  2396 
2635   G4double unit = G4UIcommand::ValueOf(unitSt    2397   G4double unit = G4UIcommand::ValueOf(unitString);
2636   x *= unit; y *= unit; z *= unit;               2398   x *= unit; y *= unit; z *= unit;
2637                                                  2399 
2638   G4Text g4text(text, G4Point3D(x,y,z));         2400   G4Text g4text(text, G4Point3D(x,y,z));
2639   G4VisAttributes visAtts(fCurrentTextColour)    2401   G4VisAttributes visAtts(fCurrentTextColour);
2640   g4text.SetVisAttributes(visAtts);              2402   g4text.SetVisAttributes(visAtts);
2641   g4text.SetLayout(fCurrentTextLayout);          2403   g4text.SetLayout(fCurrentTextLayout);
2642   g4text.SetScreenSize(font_size);               2404   g4text.SetScreenSize(font_size);
2643   g4text.SetOffset(x_offset,y_offset);           2405   g4text.SetOffset(x_offset,y_offset);
2644   G4VModel* model = new G4TextModel(g4text);     2406   G4VModel* model = new G4TextModel(g4text);
2645   const G4String& currentSceneName = pScene -    2407   const G4String& currentSceneName = pScene -> GetName ();
2646   G4bool successful = pScene -> AddRunDuratio    2408   G4bool successful = pScene -> AddRunDurationModel (model, warn);
2647   if (successful) {                              2409   if (successful) {
2648     if (verbosity >= G4VisManager::confirmati    2410     if (verbosity >= G4VisManager::confirmations) {
2649       G4cout << "Text '" << text              << 2411       G4cout << "Text \"" << text
2650        << "' has been added to scene \"" << c << 2412        << "\" has been added to scene \"" << currentSceneName << "\"."
2651        << G4endl;                                2413        << G4endl;
2652     }                                            2414     }
2653   }                                              2415   }
2654   else G4VisCommandsSceneAddUnsuccessful(verb    2416   else G4VisCommandsSceneAddUnsuccessful(verbosity);
2655                                               << 2417   UpdateVisManagerScene (currentSceneName);
2656   CheckSceneAndNotifyHandlers (pScene);       << 
2657 }                                                2418 }
2658                                                  2419 
2659                                                  2420 
2660 ////////////// /vis/scene/add/text2D ////////    2421 ////////////// /vis/scene/add/text2D //////////////////////////////////
2661                                                  2422 
2662 G4VisCommandSceneAddText2D::G4VisCommandScene    2423 G4VisCommandSceneAddText2D::G4VisCommandSceneAddText2D () {
2663   G4bool omitable;                               2424   G4bool omitable;
2664   fpCommand = new G4UIcommand ("/vis/scene/ad    2425   fpCommand = new G4UIcommand ("/vis/scene/add/text2D", this);
2665   fpCommand -> SetGuidance ("Adds 2D text to     2426   fpCommand -> SetGuidance ("Adds 2D text to current scene.");
2666   fpCommand -> SetGuidance ("x,y in range [-1 << 
2667   fpCommand -> SetGuidance                       2427   fpCommand -> SetGuidance
2668     ("Use \"/vis/set/textColour\" to set colo    2428     ("Use \"/vis/set/textColour\" to set colour.");
2669   fpCommand -> SetGuidance                       2429   fpCommand -> SetGuidance
2670     ("Use \"/vis/set/textLayout\" to set layo    2430     ("Use \"/vis/set/textLayout\" to set layout:");
2671   G4UIparameter* parameter;                      2431   G4UIparameter* parameter;
2672   parameter = new G4UIparameter ("x", 'd', om    2432   parameter = new G4UIparameter ("x", 'd', omitable = true);
2673   parameter->SetDefaultValue (0);                2433   parameter->SetDefaultValue (0);
2674   fpCommand->SetParameter (parameter);           2434   fpCommand->SetParameter (parameter);
2675   parameter =  new G4UIparameter ("y", 'd', o    2435   parameter =  new G4UIparameter ("y", 'd', omitable = true);
2676   parameter->SetDefaultValue (0);                2436   parameter->SetDefaultValue (0);
2677   fpCommand->SetParameter (parameter);           2437   fpCommand->SetParameter (parameter);
2678   parameter =  new G4UIparameter ("font_size"    2438   parameter =  new G4UIparameter ("font_size", 'd', omitable = true);
2679   parameter->SetDefaultValue (12);               2439   parameter->SetDefaultValue (12);
2680   parameter->SetGuidance ("pixels");             2440   parameter->SetGuidance ("pixels");
2681   fpCommand->SetParameter (parameter);           2441   fpCommand->SetParameter (parameter);
2682   parameter =  new G4UIparameter ("x_offset",    2442   parameter =  new G4UIparameter ("x_offset", 'd', omitable = true);
2683   parameter->SetDefaultValue (0);                2443   parameter->SetDefaultValue (0);
2684   parameter->SetGuidance ("pixels");             2444   parameter->SetGuidance ("pixels");
2685   fpCommand->SetParameter (parameter);           2445   fpCommand->SetParameter (parameter);
2686   parameter =  new G4UIparameter ("y_offset",    2446   parameter =  new G4UIparameter ("y_offset", 'd', omitable = true);
2687   parameter->SetDefaultValue (0);                2447   parameter->SetDefaultValue (0);
2688   parameter->SetGuidance ("pixels");             2448   parameter->SetGuidance ("pixels");
2689   fpCommand->SetParameter (parameter);           2449   fpCommand->SetParameter (parameter);
2690   parameter =  new G4UIparameter ("text", 's'    2450   parameter =  new G4UIparameter ("text", 's', omitable = true);
2691   parameter->SetGuidance ("The rest of the li    2451   parameter->SetGuidance ("The rest of the line is text.");
2692   parameter->SetDefaultValue ("Hello G4");       2452   parameter->SetDefaultValue ("Hello G4");
2693   fpCommand->SetParameter (parameter);           2453   fpCommand->SetParameter (parameter);
2694 }                                                2454 }
2695                                                  2455 
2696 G4VisCommandSceneAddText2D::~G4VisCommandScen    2456 G4VisCommandSceneAddText2D::~G4VisCommandSceneAddText2D () {
2697   delete fpCommand;                              2457   delete fpCommand;
2698 }                                                2458 }
2699                                                  2459 
2700 G4String G4VisCommandSceneAddText2D::GetCurre    2460 G4String G4VisCommandSceneAddText2D::GetCurrentValue (G4UIcommand*) {
2701   return "";                                     2461   return "";
2702 }                                                2462 }
2703                                                  2463 
2704 void G4VisCommandSceneAddText2D::SetNewValue     2464 void G4VisCommandSceneAddText2D::SetNewValue (G4UIcommand*, G4String newValue) {
2705                                                  2465 
2706   G4VisManager::Verbosity verbosity = fpVisMa    2466   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2707   G4bool warn = verbosity >= G4VisManager::wa    2467   G4bool warn = verbosity >= G4VisManager::warnings;
2708                                                  2468 
2709   G4Scene* pScene = fpVisManager->GetCurrentS    2469   G4Scene* pScene = fpVisManager->GetCurrentScene();
2710   if (!pScene) {                                 2470   if (!pScene) {
2711     if (verbosity >= G4VisManager::errors) {     2471     if (verbosity >= G4VisManager::errors) {
2712       G4warn << "ERROR: No current scene.  Pl << 2472       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
2713     }                                            2473     }
2714     return;                                      2474     return;
2715   }                                              2475   }
2716                                                  2476 
2717   G4Tokenizer next(newValue);                    2477   G4Tokenizer next(newValue);
2718   G4double x = StoD(next());                     2478   G4double x = StoD(next());
2719   G4double y = StoD(next());                     2479   G4double y = StoD(next());
2720   G4double font_size = StoD(next());             2480   G4double font_size = StoD(next());
2721   G4double x_offset = StoD(next());              2481   G4double x_offset = StoD(next());
2722   G4double y_offset = StoD(next());              2482   G4double y_offset = StoD(next());
2723   G4String text = next("\n");                    2483   G4String text = next("\n");
2724                                                  2484 
2725   G4Text g4text(text, G4Point3D(x,y,0.));        2485   G4Text g4text(text, G4Point3D(x,y,0.));
2726   G4VisAttributes visAtts(fCurrentTextColour)    2486   G4VisAttributes visAtts(fCurrentTextColour);
2727   g4text.SetVisAttributes(visAtts);              2487   g4text.SetVisAttributes(visAtts);
2728   g4text.SetLayout(fCurrentTextLayout);          2488   g4text.SetLayout(fCurrentTextLayout);
2729   g4text.SetScreenSize(font_size);               2489   g4text.SetScreenSize(font_size);
2730   g4text.SetOffset(x_offset,y_offset);           2490   g4text.SetOffset(x_offset,y_offset);
2731   G4Text2D* g4text2D = new G4Text2D(g4text);     2491   G4Text2D* g4text2D = new G4Text2D(g4text);
2732   G4VModel* model =                              2492   G4VModel* model =
2733     new G4CallbackModel<G4VisCommandSceneAddT    2493     new G4CallbackModel<G4VisCommandSceneAddText2D::G4Text2D>(g4text2D);
2734   model->SetType("Text2D");                      2494   model->SetType("Text2D");
2735   model->SetGlobalTag("Text2D");                 2495   model->SetGlobalTag("Text2D");
2736   std::ostringstream oss;                     << 2496   model->SetGlobalDescription("Text2D: " + newValue);
2737   oss << "Text2D: '" << g4text.GetText()      << 
2738   << "' at " << g4text.GetPosition().x() << ' << 
2739   << " with size " << g4text.GetScreenSize()  << 
2740   << " with offsets " << g4text.GetXOffset()  << 
2741   model->SetGlobalDescription(oss.str());     << 
2742   const G4String& currentSceneName = pScene -    2497   const G4String& currentSceneName = pScene -> GetName ();
2743   G4bool successful = pScene -> AddRunDuratio    2498   G4bool successful = pScene -> AddRunDurationModel (model, warn);
2744   if (successful) {                              2499   if (successful) {
2745     if (verbosity >= G4VisManager::confirmati    2500     if (verbosity >= G4VisManager::confirmations) {
2746       G4cout << "2D text '" << text           << 2501       G4cout << "2D text \"" << text
2747        << "' has been added to scene \"" << c << 2502        << "\" has been added to scene \"" << currentSceneName << "\"."
2748        << G4endl;                                2503        << G4endl;
2749     }                                            2504     }
2750   }                                              2505   }
2751   else G4VisCommandsSceneAddUnsuccessful(verb    2506   else G4VisCommandsSceneAddUnsuccessful(verbosity);
2752                                               << 2507   UpdateVisManagerScene (currentSceneName);
2753   CheckSceneAndNotifyHandlers (pScene);       << 
2754 }                                                2508 }
2755                                                  2509 
2756 G4VisCommandSceneAddText2D::G4Text2D::G4Text2    2510 G4VisCommandSceneAddText2D::G4Text2D::G4Text2D(const G4Text& text):
2757   fText(text)                                    2511   fText(text)
2758 {}                                               2512 {}
2759                                                  2513 
2760 void G4VisCommandSceneAddText2D::G4Text2D::op    2514 void G4VisCommandSceneAddText2D::G4Text2D::operator()
2761   (G4VGraphicsScene& sceneHandler, const G4Mo << 2515   (G4VGraphicsScene& sceneHandler, const G4Transform3D& transform) {
2762   sceneHandler.BeginPrimitives2D();           << 2516   sceneHandler.BeginPrimitives2D(transform);
2763   sceneHandler.AddPrimitive(fText);              2517   sceneHandler.AddPrimitive(fText);
2764   sceneHandler.EndPrimitives2D();                2518   sceneHandler.EndPrimitives2D();
2765 }                                                2519 }
2766                                                  2520 
2767                                                  2521 
2768 ////////////// /vis/scene/add/trajectories //    2522 ////////////// /vis/scene/add/trajectories ///////////////////////////////////
2769                                                  2523 
2770 G4VisCommandSceneAddTrajectories::G4VisComman    2524 G4VisCommandSceneAddTrajectories::G4VisCommandSceneAddTrajectories () {
2771   G4bool omitable;                               2525   G4bool omitable;
2772   fpCommand = new G4UIcmdWithAString             2526   fpCommand = new G4UIcmdWithAString
2773     ("/vis/scene/add/trajectories", this);       2527     ("/vis/scene/add/trajectories", this);
2774   fpCommand -> SetGuidance                       2528   fpCommand -> SetGuidance
2775     ("Adds trajectories to current scene.");     2529     ("Adds trajectories to current scene.");
2776   fpCommand -> SetGuidance                       2530   fpCommand -> SetGuidance
2777     ("Causes trajectories, if any, to be draw    2531     ("Causes trajectories, if any, to be drawn at the end of processing an"
2778      "\nevent.  Switches on trajectory storin    2532      "\nevent.  Switches on trajectory storing and sets the"
2779      "\ndefault trajectory type.");              2533      "\ndefault trajectory type.");
2780   fpCommand -> SetGuidance                       2534   fpCommand -> SetGuidance
2781     ("The command line parameter list determi    2535     ("The command line parameter list determines the default trajectory type."
2782      "\nIf it contains the string \"smooth\",    2536      "\nIf it contains the string \"smooth\", auxiliary inter-step points will"
2783      "\nbe inserted to improve the smoothness    2537      "\nbe inserted to improve the smoothness of the drawing of a curved"
2784      "\ntrajectory."                             2538      "\ntrajectory."
2785      "\nIf it contains the string \"rich\", s    2539      "\nIf it contains the string \"rich\", significant extra information will"
2786      "\nbe stored in the trajectory (G4RichTr    2540      "\nbe stored in the trajectory (G4RichTrajectory) amenable to modeling"
2787      "\nand filtering with \"/vis/modeling/tr    2541      "\nand filtering with \"/vis/modeling/trajectories/create/drawByAttribute\""
2788      "\nand \"/vis/filtering/trajectories/cre    2542      "\nand \"/vis/filtering/trajectories/create/attributeFilter\" commands."
2789      "\nIt may contain both strings in any or    2543      "\nIt may contain both strings in any order.");
2790   fpCommand -> SetGuidance                       2544   fpCommand -> SetGuidance
2791     ("\nTo switch off trajectory storing: \"/    2545     ("\nTo switch off trajectory storing: \"/tracking/storeTrajectory 0\"."
2792      "\nSee also \"/vis/scene/endOfEventActio    2546      "\nSee also \"/vis/scene/endOfEventAction\".");
2793   fpCommand -> SetGuidance                       2547   fpCommand -> SetGuidance
2794     ("Note:  This only sets the default.  Ind    2548     ("Note:  This only sets the default.  Independently of the result of this"
2795      "\ncommand, a user may instantiate a tra    2549      "\ncommand, a user may instantiate a trajectory that overrides this default"
2796      "\nin PreUserTrackingAction.");             2550      "\nin PreUserTrackingAction.");
2797   fpCommand -> SetParameterName ("default-tra    2551   fpCommand -> SetParameterName ("default-trajectory-type", omitable = true);
2798   fpCommand -> SetDefaultValue ("");             2552   fpCommand -> SetDefaultValue ("");
2799 }                                                2553 }
2800                                                  2554 
2801 G4VisCommandSceneAddTrajectories::~G4VisComma    2555 G4VisCommandSceneAddTrajectories::~G4VisCommandSceneAddTrajectories () {
2802   delete fpCommand;                              2556   delete fpCommand;
2803 }                                                2557 }
2804                                                  2558 
2805 G4String G4VisCommandSceneAddTrajectories::Ge    2559 G4String G4VisCommandSceneAddTrajectories::GetCurrentValue (G4UIcommand*) {
2806   return "";                                     2560   return "";
2807 }                                                2561 }
2808                                                  2562 
2809 void G4VisCommandSceneAddTrajectories::SetNew    2563 void G4VisCommandSceneAddTrajectories::SetNewValue (G4UIcommand*,
2810                 G4String newValue) {             2564                 G4String newValue) {
2811                                                  2565 
2812   G4VisManager::Verbosity verbosity = fpVisMa    2566   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2813   G4bool warn = verbosity >= G4VisManager::wa    2567   G4bool warn = verbosity >= G4VisManager::warnings;
2814                                                  2568 
2815   G4Scene* pScene = fpVisManager->GetCurrentS    2569   G4Scene* pScene = fpVisManager->GetCurrentScene();
2816   if (!pScene) {                                 2570   if (!pScene) {
2817     if (verbosity >= G4VisManager::errors) {     2571     if (verbosity >= G4VisManager::errors) {
2818       G4warn << "ERROR: No current scene.  Pl << 2572       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
2819     }                                            2573     }
2820     return;                                      2574     return;
2821   }                                              2575   }
2822   const G4String& currentSceneName = pScene - << 
2823                                                  2576 
2824   G4bool smooth = false;                         2577   G4bool smooth = false;
2825   G4bool rich = false;                           2578   G4bool rich = false;
2826   if (newValue.find("smooth") != std::string:    2579   if (newValue.find("smooth") != std::string::npos) smooth = true;
2827   if (newValue.find("rich") != std::string::n    2580   if (newValue.find("rich") != std::string::npos) rich = true;
2828   if (newValue.size() && !(rich || smooth)) {    2581   if (newValue.size() && !(rich || smooth)) {
2829     if (verbosity >= G4VisManager::errors) {     2582     if (verbosity >= G4VisManager::errors) {
2830       G4warn << "ERROR: Unrecognised paramete << 2583       G4cerr << "ERROR: Unrecognised parameter \"" << newValue << "\""
2831       "\n  No action taken."                     2584       "\n  No action taken."
2832       << G4endl;                                 2585       << G4endl;
2833     }                                            2586     }
2834     return;                                      2587     return;
2835   }                                              2588   }
2836                                                  2589 
2837   G4UImanager* UImanager = G4UImanager::GetUI    2590   G4UImanager* UImanager = G4UImanager::GetUIpointer();
                                                   >> 2591   G4int keepVerbose = UImanager->GetVerboseLevel();
                                                   >> 2592   G4int newVerbose = 2;
                                                   >> 2593   UImanager->SetVerboseLevel(newVerbose);
2838   G4String defaultTrajectoryType;                2594   G4String defaultTrajectoryType;
2839   if (smooth && rich) {                          2595   if (smooth && rich) {
2840     UImanager->ApplyCommand("/tracking/storeT    2596     UImanager->ApplyCommand("/tracking/storeTrajectory 4");
2841     defaultTrajectoryType = "G4RichTrajectory    2597     defaultTrajectoryType = "G4RichTrajectory configured for smooth steps";
2842   } else if (smooth) {                           2598   } else if (smooth) {
2843     UImanager->ApplyCommand("/tracking/storeT    2599     UImanager->ApplyCommand("/tracking/storeTrajectory 2");
2844     defaultTrajectoryType = "G4SmoothTrajecto    2600     defaultTrajectoryType = "G4SmoothTrajectory";
2845   } else if (rich) {                             2601   } else if (rich) {
2846     UImanager->ApplyCommand("/tracking/storeT    2602     UImanager->ApplyCommand("/tracking/storeTrajectory 3");
2847     defaultTrajectoryType = "G4RichTrajectory    2603     defaultTrajectoryType = "G4RichTrajectory";
2848   } else {                                       2604   } else {
2849     UImanager->ApplyCommand("/tracking/storeT    2605     UImanager->ApplyCommand("/tracking/storeTrajectory 1");
2850     defaultTrajectoryType = "G4Trajectory";      2606     defaultTrajectoryType = "G4Trajectory";
2851   }                                              2607   }
                                                   >> 2608   UImanager->SetVerboseLevel(keepVerbose);
2852                                                  2609 
2853   if (verbosity >= G4VisManager::errors) {       2610   if (verbosity >= G4VisManager::errors) {
2854     G4warn <<                                 << 2611     G4cout <<
2855       "Attributes available for modeling and     2612       "Attributes available for modeling and filtering with"
2856       "\n  \"/vis/modeling/trajectories/creat    2613       "\n  \"/vis/modeling/trajectories/create/drawByAttribute\" and"
2857       "\n  \"/vis/filtering/trajectories/crea    2614       "\n  \"/vis/filtering/trajectories/create/attributeFilter\" commands:"
2858      << G4endl;                                  2615      << G4endl;
2859     G4warn << *G4TrajectoriesModel().GetAttDe << 2616     G4cout << *G4TrajectoriesModel().GetAttDefs();
2860     if (rich) {                                  2617     if (rich) {
2861       G4warn << *G4RichTrajectory().GetAttDef << 2618       G4cout << *G4RichTrajectory().GetAttDefs()
2862        << *G4RichTrajectoryPoint().GetAttDefs    2619        << *G4RichTrajectoryPoint().GetAttDefs();
2863     } else if (smooth) {                         2620     } else if (smooth) {
2864       G4warn << *G4SmoothTrajectory().GetAttD << 2621       G4cout << *G4SmoothTrajectory().GetAttDefs()
2865        << *G4SmoothTrajectoryPoint().GetAttDe    2622        << *G4SmoothTrajectoryPoint().GetAttDefs();
2866     } else {                                     2623     } else {
2867       G4warn << *G4Trajectory().GetAttDefs()  << 2624       G4cout << *G4Trajectory().GetAttDefs()
2868        << *G4TrajectoryPoint().GetAttDefs();     2625        << *G4TrajectoryPoint().GetAttDefs();
2869     }                                            2626     }
2870   }                                              2627   }
2871                                                  2628 
2872   const auto& eoeList = pScene->GetEndOfEvent << 2629   G4VModel* model = new G4TrajectoriesModel();
2873   auto eoeModel = eoeList.begin();            << 2630   const G4String& currentSceneName = pScene -> GetName ();
2874   for (; eoeModel != eoeList.end(); ++eoeMode << 2631   pScene -> AddEndOfEventModel (model, warn);
2875     const auto* actualModel = eoeModel->fpMod << 
2876     if (dynamic_cast<const G4TrajectoriesMode << 
2877   }                                           << 
2878   if (eoeModel == eoeList.end()) {            << 
2879     // No trajectories model exists in the sc << 
2880     G4VModel* model = new G4TrajectoriesModel << 
2881     pScene -> AddEndOfEventModel (model, warn << 
2882   }  // ...else it already exists and there i << 
2883   // because G4TrajectoriesModel simply descr << 
2884   // trajectories store whatever the type.    << 
2885                                                  2632 
2886   if (verbosity >= G4VisManager::confirmation    2633   if (verbosity >= G4VisManager::confirmations) {
2887     G4cout << "Default trajectory type " << d    2634     G4cout << "Default trajectory type " << defaultTrajectoryType
2888      << "\n  will be used to store trajectori    2635      << "\n  will be used to store trajectories for scene \""
2889      << currentSceneName << "\"."                2636      << currentSceneName << "\"."
2890      << G4endl;                                  2637      << G4endl;
2891   }                                              2638   }
2892                                                  2639 
2893   if (verbosity >= G4VisManager::warnings) {     2640   if (verbosity >= G4VisManager::warnings) {
2894     G4warn <<                                 << 2641     G4cout <<
2895       "WARNING: Trajectory storing has been r    2642       "WARNING: Trajectory storing has been requested.  This action may be"
2896       "\n  reversed with \"/tracking/storeTra    2643       "\n  reversed with \"/tracking/storeTrajectory 0\"."
2897      << G4endl;                                  2644      << G4endl;
2898   }                                              2645   }
2899                                               << 2646   UpdateVisManagerScene (currentSceneName);
2900   CheckSceneAndNotifyHandlers (pScene);       << 
2901 }                                                2647 }
2902                                                  2648 
2903 ////////////// /vis/scene/add/userAction ////    2649 ////////////// /vis/scene/add/userAction ///////////////////////////////////
2904                                                  2650 
2905 G4VisCommandSceneAddUserAction::G4VisCommandS    2651 G4VisCommandSceneAddUserAction::G4VisCommandSceneAddUserAction () {
2906   G4bool omitable;                               2652   G4bool omitable;
2907   fpCommand = new G4UIcmdWithAString("/vis/sc    2653   fpCommand = new G4UIcmdWithAString("/vis/scene/add/userAction",this);
2908   fpCommand -> SetGuidance                       2654   fpCommand -> SetGuidance
2909     ("Add named Vis User Action to current sc    2655     ("Add named Vis User Action to current scene.");
2910   fpCommand -> SetGuidance                       2656   fpCommand -> SetGuidance
2911     ("Attempts to match search string to name    2657     ("Attempts to match search string to name of action - use unique sub-string.");
2912   fpCommand -> SetGuidance                       2658   fpCommand -> SetGuidance
2913     ("(Use /vis/list to see names of register    2659     ("(Use /vis/list to see names of registered actions.)");
2914   fpCommand -> SetGuidance                       2660   fpCommand -> SetGuidance
2915     ("If name == \"all\" (default), all actio    2661     ("If name == \"all\" (default), all actions are added.");
2916   fpCommand -> SetParameterName("action-name"    2662   fpCommand -> SetParameterName("action-name", omitable = true);
2917   fpCommand -> SetDefaultValue("all");           2663   fpCommand -> SetDefaultValue("all");
2918 }                                                2664 }
2919                                                  2665 
2920 G4VisCommandSceneAddUserAction::~G4VisCommand    2666 G4VisCommandSceneAddUserAction::~G4VisCommandSceneAddUserAction () {
2921   delete fpCommand;                              2667   delete fpCommand;
2922 }                                                2668 }
2923                                                  2669 
2924 G4String G4VisCommandSceneAddUserAction::GetC    2670 G4String G4VisCommandSceneAddUserAction::GetCurrentValue (G4UIcommand*) {
2925   return "";                                     2671   return "";
2926 }                                                2672 }
2927                                                  2673 
2928 void G4VisCommandSceneAddUserAction::SetNewVa    2674 void G4VisCommandSceneAddUserAction::SetNewValue
2929 (G4UIcommand*, G4String newValue) {              2675 (G4UIcommand*, G4String newValue) {
2930                                                  2676 
2931   G4VisManager::Verbosity verbosity = fpVisMa    2677   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
2932                                                  2678 
2933   G4Scene* pScene = fpVisManager->GetCurrentS    2679   G4Scene* pScene = fpVisManager->GetCurrentScene();
2934   if (!pScene) {                                 2680   if (!pScene) {
2935     if (verbosity >= G4VisManager::errors) {     2681     if (verbosity >= G4VisManager::errors) {
2936       G4warn << "ERROR: No current scene.  Pl << 2682       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
2937     }                                            2683     }
2938     return;                                      2684     return;
2939   }                                              2685   }
2940                                                  2686 
2941   G4bool any = false;                            2687   G4bool any = false;
2942                                                  2688 
2943   const std::vector<G4VisManager::UserVisActi    2689   const std::vector<G4VisManager::UserVisAction>& runDurationUserVisActions =
2944     fpVisManager->GetRunDurationUserVisAction    2690     fpVisManager->GetRunDurationUserVisActions();
2945   for (size_t i = 0; i < runDurationUserVisAc    2691   for (size_t i = 0; i < runDurationUserVisActions.size(); i++) {
2946     const G4String& name = runDurationUserVis    2692     const G4String& name = runDurationUserVisActions[i].fName;
2947     G4VUserVisAction* visAction = runDuration    2693     G4VUserVisAction* visAction = runDurationUserVisActions[i].fpUserVisAction;
2948     if (newValue == "all" || name.find(newVal    2694     if (newValue == "all" || name.find(newValue) != std::string::npos) {
2949       any = true;                                2695       any = true;
2950       AddVisAction(name,visAction,pScene,runD    2696       AddVisAction(name,visAction,pScene,runDuration,verbosity);
2951     }                                            2697     }
2952   }                                              2698   }
2953                                                  2699 
2954   const std::vector<G4VisManager::UserVisActi    2700   const std::vector<G4VisManager::UserVisAction>& endOfEventUserVisActions =
2955     fpVisManager->GetEndOfEventUserVisActions    2701     fpVisManager->GetEndOfEventUserVisActions();
2956   for (size_t i = 0; i < endOfEventUserVisAct    2702   for (size_t i = 0; i < endOfEventUserVisActions.size(); i++) {
2957     const G4String& name = endOfEventUserVisA    2703     const G4String& name = endOfEventUserVisActions[i].fName;
2958     G4VUserVisAction* visAction = endOfEventU    2704     G4VUserVisAction* visAction = endOfEventUserVisActions[i].fpUserVisAction;
2959     if (newValue == "all" || name.find(newVal    2705     if (newValue == "all" || name.find(newValue) != std::string::npos) {
2960       any = true;                                2706       any = true;
2961       AddVisAction(name,visAction,pScene,endO    2707       AddVisAction(name,visAction,pScene,endOfEvent,verbosity);
2962     }                                            2708     }
2963   }                                              2709   }
2964                                                  2710 
2965   const std::vector<G4VisManager::UserVisActi    2711   const std::vector<G4VisManager::UserVisAction>& endOfRunUserVisActions =
2966     fpVisManager->GetEndOfRunUserVisActions()    2712     fpVisManager->GetEndOfRunUserVisActions();
2967   for (size_t i = 0; i < endOfRunUserVisActio    2713   for (size_t i = 0; i < endOfRunUserVisActions.size(); i++) {
2968     const G4String& name = endOfRunUserVisAct    2714     const G4String& name = endOfRunUserVisActions[i].fName;
2969     G4VUserVisAction* visAction = endOfRunUse    2715     G4VUserVisAction* visAction = endOfRunUserVisActions[i].fpUserVisAction;
2970     if (newValue == "all" || name.find(newVal    2716     if (newValue == "all" || name.find(newValue) != std::string::npos) {
2971       any = true;                                2717       any = true;
2972       AddVisAction(name,visAction,pScene,endO    2718       AddVisAction(name,visAction,pScene,endOfRun,verbosity);
2973     }                                            2719     }
2974   }                                              2720   }
2975                                                  2721 
2976   if (!any) {                                    2722   if (!any) {
2977     if (verbosity >= G4VisManager::warnings)     2723     if (verbosity >= G4VisManager::warnings) {
2978       G4warn << "WARNING: No User Vis Action  << 2724       G4cout << "WARNING: No User Vis Action registered." << G4endl;
2979     }                                            2725     }
2980     return;                                      2726     return;
2981   }                                              2727   }
2982                                                  2728 
2983   CheckSceneAndNotifyHandlers (pScene);       << 2729   const G4String& currentSceneName = pScene -> GetName ();
                                                   >> 2730   UpdateVisManagerScene (currentSceneName);
2984 }                                                2731 }
2985                                                  2732 
2986 void G4VisCommandSceneAddUserAction::AddVisAc    2733 void G4VisCommandSceneAddUserAction::AddVisAction
2987 (const G4String& name,                           2734 (const G4String& name,
2988  G4VUserVisAction* visAction,                    2735  G4VUserVisAction* visAction,
2989  G4Scene* pScene,                                2736  G4Scene* pScene,
2990  G4VisCommandSceneAddUserAction::ActionType t    2737  G4VisCommandSceneAddUserAction::ActionType type,
2991  G4VisManager::Verbosity verbosity)              2738  G4VisManager::Verbosity verbosity)
2992 {                                                2739 {
2993   G4bool warn = verbosity >= G4VisManager::wa    2740   G4bool warn = verbosity >= G4VisManager::warnings;
2994                                                  2741 
2995   const std::map<G4VUserVisAction*,G4VisExten    2742   const std::map<G4VUserVisAction*,G4VisExtent>& visExtentMap =
2996     fpVisManager->GetUserVisActionExtents();     2743     fpVisManager->GetUserVisActionExtents();
2997   G4VisExtent extent;                            2744   G4VisExtent extent;
2998   std::map<G4VUserVisAction*,G4VisExtent>::co    2745   std::map<G4VUserVisAction*,G4VisExtent>::const_iterator i =
2999     visExtentMap.find(visAction);                2746     visExtentMap.find(visAction);
3000   if (i != visExtentMap.end()) extent = i->se    2747   if (i != visExtentMap.end()) extent = i->second;
3001   if (warn) {                                    2748   if (warn) {
3002     if (extent.GetExtentRadius() <= 0.) {        2749     if (extent.GetExtentRadius() <= 0.) {
3003       G4warn                                  << 2750       G4cout << "WARNING: User Vis Action extent is null." << G4endl;
3004       << "WARNING: User Vis Action \"" << nam << 
3005       << G4endl;                              << 
3006     }                                            2751     }
3007   }                                              2752   }
3008                                                  2753 
3009   G4VModel* model = new G4CallbackModel<G4VUs    2754   G4VModel* model = new G4CallbackModel<G4VUserVisAction>(visAction);
3010   model->SetType("User Vis Action");             2755   model->SetType("User Vis Action");
3011   model->SetGlobalTag(name);                     2756   model->SetGlobalTag(name);
3012   model->SetGlobalDescription(name);             2757   model->SetGlobalDescription(name);
3013   model->SetExtent(extent);                      2758   model->SetExtent(extent);
3014   G4bool successful = false;;                    2759   G4bool successful = false;;
3015   switch (type) {                                2760   switch (type) {
3016   case runDuration:                              2761   case runDuration:
3017     successful = pScene -> AddRunDurationMode    2762     successful = pScene -> AddRunDurationModel (model, warn);
3018     break;                                       2763     break;
3019   case endOfEvent:                               2764   case endOfEvent:
3020     successful = pScene -> AddEndOfEventModel    2765     successful = pScene -> AddEndOfEventModel (model, warn);
3021     break;                                       2766     break;
3022   case endOfRun:                                 2767   case endOfRun:
3023     successful = pScene -> AddEndOfRunModel (    2768     successful = pScene -> AddEndOfRunModel (model, warn);
3024     break;                                       2769     break;
3025   }                                              2770   }
3026   if (successful) {                           << 2771   if (successful && verbosity >= G4VisManager::confirmations) {
3027     if (verbosity >= G4VisManager::confirmati << 2772     const G4String& currentSceneName = pScene -> GetName ();
3028       const G4String& currentSceneName = pSce << 2773     G4cout << "User Vis Action added to scene \""
3029       G4cout << "User Vis Action added to sce << 2774      << currentSceneName << "\"";
3030       << currentSceneName << "\"";            << 2775     if (verbosity >= G4VisManager::parameters) {
3031       if (verbosity >= G4VisManager::paramete << 2776       G4cout << "\n  with extent " << extent;
3032         G4cout << "\n  with extent " << exten << 
3033       }                                       << 
3034       G4cout << G4endl;                       << 
3035     }                                            2777     }
                                                   >> 2778     G4cout << G4endl;
3036   }                                              2779   }
3037   else G4VisCommandsSceneAddUnsuccessful(verb    2780   else G4VisCommandsSceneAddUnsuccessful(verbosity);
3038 }                                                2781 }
3039                                                  2782 
3040 ////////////// /vis/scene/add/volume ////////    2783 ////////////// /vis/scene/add/volume ///////////////////////////////////////
3041                                                  2784 
3042 G4VisCommandSceneAddVolume::G4VisCommandScene    2785 G4VisCommandSceneAddVolume::G4VisCommandSceneAddVolume () {
3043   G4bool omitable;                               2786   G4bool omitable;
3044   fpCommand = new G4UIcommand ("/vis/scene/ad    2787   fpCommand = new G4UIcommand ("/vis/scene/add/volume", this);
3045   fpCommand -> SetGuidance                       2788   fpCommand -> SetGuidance 
3046    ("Adds a physical volume to current scene,    2789    ("Adds a physical volume to current scene, with optional clipping volume.");
3047   fpCommand -> SetGuidance                       2790   fpCommand -> SetGuidance 
3048     ("If physical-volume-name is \"world\" (t    2791     ("If physical-volume-name is \"world\" (the default), the top of the"
3049      "\nmain geometry tree (material world) i << 2792      "\nmain geometry tree (material world) is added.  If \"worlds\", the"
3050      "\ntops of all worlds - material world a << 2793      "\ntop of all worlds - material world and parallel worlds, if any - are"
3051      "\nadded. Otherwise a search of all worl << 2794      "\nadded.  Otherwise a search of all worlds is made, taking the first"
3052   fpCommand -> SetGuidance                    << 2795      "\nmatching occurence only.  To see a representation of the geometry"
3053     ("In the last case the names of all volum << 2796      "\nhierarchy of the worlds, try \"/vis/drawTree [worlds]\" or one of the"
3054      "\nagainst physical-volume-name. If this << 2797      "\ndriver/browser combinations that have the required functionality, e.g., HepRep.");
3055      "\nwhere regexp is a regular expression  << 
3056      "\nthe usual rules of regular expression << 
3057      "\nmatch is required."                   << 
3058      "\nFor example, \"/Shap/\" adds \"Shape1 << 
3059   fpCommand -> SetGuidance                    << 
3060     ("It may help to see a textual representa << 
3061      "\nthe worlds. Try \"/vis/drawTree [worl << 
3062      "\ncombinations that have the required f << 
3063   fpCommand -> SetGuidance                       2798   fpCommand -> SetGuidance
3064     ("If clip-volume-type is specified, the s    2799     ("If clip-volume-type is specified, the subsequent parameters are used to"
3065      "\nto define a clipping volume. For exam << 2800      "\nto define a clipping volume.  For example,"
3066      "\n\"/vis/scene/add/volume ! ! ! -box km    2801      "\n\"/vis/scene/add/volume ! ! ! -box km 0 1 0 1 0 1\" will draw the world"
3067      "\nwith the positive octant cut away. (I << 2802      "\nwith the positive octant cut away.  (If the Boolean Processor issues"
3068      "\nwarnings try replacing 0 by 0.0000000    2803      "\nwarnings try replacing 0 by 0.000000001 or something.)");
3069   fpCommand -> SetGuidance                       2804   fpCommand -> SetGuidance
3070     ("If clip-volume-type is prepended with '    2805     ("If clip-volume-type is prepended with '-', the clip-volume is subtracted"
3071      "\n(cutaway). (This is the default if th    2806      "\n(cutaway). (This is the default if there is no prepended character.)"
3072      "\nIf '*' is prepended, the intersection    2807      "\nIf '*' is prepended, the intersection of the physical-volume and the"
3073      "\nclip-volume is made. (You can make a  << 2808      "\nclip-volume is made. (You can make a section/DCUT with a thin box, for"
3074      "\na thin box, for example).");          << 2809      "\nexample).");
3075   fpCommand -> SetGuidance                       2810   fpCommand -> SetGuidance
3076     ("For \"box\", the parameters are xmin,xm    2811     ("For \"box\", the parameters are xmin,xmax,ymin,ymax,zmin,zmax."
3077      "\nOnly \"box\" is programmed at present    2812      "\nOnly \"box\" is programmed at present.");
3078   G4UIparameter* parameter;                      2813   G4UIparameter* parameter;
3079   parameter = new G4UIparameter ("physical-vo    2814   parameter = new G4UIparameter ("physical-volume-name", 's', omitable = true);
3080   parameter -> SetDefaultValue ("world");        2815   parameter -> SetDefaultValue ("world");
3081   fpCommand -> SetParameter (parameter);         2816   fpCommand -> SetParameter (parameter);
3082   parameter = new G4UIparameter ("copy-no", '    2817   parameter = new G4UIparameter ("copy-no", 'i', omitable = true);
3083   parameter -> SetGuidance ("If negative, mat << 2818   parameter -> SetGuidance
                                                   >> 2819     ("If negative, matches any copy no.  First name match is taken.");
3084   parameter -> SetDefaultValue (-1);             2820   parameter -> SetDefaultValue (-1);
3085   fpCommand -> SetParameter (parameter);         2821   fpCommand -> SetParameter (parameter);
3086   parameter = new G4UIparameter ("depth-of-de    2822   parameter = new G4UIparameter ("depth-of-descent", 'i', omitable = true);
3087   parameter -> SetGuidance                       2823   parameter -> SetGuidance
3088     ("Depth of descent of geometry hierarchy.    2824     ("Depth of descent of geometry hierarchy. Default = unlimited depth.");
3089   parameter -> SetDefaultValue (G4PhysicalVol << 2825   parameter -> SetDefaultValue (G4Scene::UNLIMITED);
3090   fpCommand -> SetParameter (parameter);         2826   fpCommand -> SetParameter (parameter);
3091   parameter = new G4UIparameter ("clip-volume    2827   parameter = new G4UIparameter ("clip-volume-type", 's', omitable = true);
3092   parameter -> SetParameterCandidates("none b    2828   parameter -> SetParameterCandidates("none box -box *box");
3093   parameter -> SetDefaultValue ("none");         2829   parameter -> SetDefaultValue ("none");
3094   parameter -> SetGuidance("[-|*]type.  See g    2830   parameter -> SetGuidance("[-|*]type.  See general guidance.");
3095   fpCommand -> SetParameter (parameter);         2831   fpCommand -> SetParameter (parameter);
3096   parameter = new G4UIparameter ("parameter-u    2832   parameter = new G4UIparameter ("parameter-unit", 's', omitable = true);
3097   parameter -> SetDefaultValue ("m");            2833   parameter -> SetDefaultValue ("m");
3098   fpCommand -> SetParameter (parameter);         2834   fpCommand -> SetParameter (parameter);
3099   parameter = new G4UIparameter ("parameter-1    2835   parameter = new G4UIparameter ("parameter-1", 'd', omitable = true);
3100   parameter -> SetDefaultValue (0.);             2836   parameter -> SetDefaultValue (0.);
3101   fpCommand -> SetParameter (parameter);         2837   fpCommand -> SetParameter (parameter);
3102   parameter = new G4UIparameter ("parameter-2    2838   parameter = new G4UIparameter ("parameter-2", 'd', omitable = true);
3103   parameter -> SetDefaultValue (0.);             2839   parameter -> SetDefaultValue (0.);
3104   fpCommand -> SetParameter (parameter);         2840   fpCommand -> SetParameter (parameter);
3105   parameter = new G4UIparameter ("parameter-3    2841   parameter = new G4UIparameter ("parameter-3", 'd', omitable = true);
3106   parameter -> SetDefaultValue (0.);             2842   parameter -> SetDefaultValue (0.);
3107   fpCommand -> SetParameter (parameter);         2843   fpCommand -> SetParameter (parameter);
3108   parameter = new G4UIparameter ("parameter-4    2844   parameter = new G4UIparameter ("parameter-4", 'd', omitable = true);
3109   parameter -> SetDefaultValue (0.);             2845   parameter -> SetDefaultValue (0.);
3110   fpCommand -> SetParameter (parameter);         2846   fpCommand -> SetParameter (parameter);
3111   parameter = new G4UIparameter ("parameter-5    2847   parameter = new G4UIparameter ("parameter-5", 'd', omitable = true);
3112   parameter -> SetDefaultValue (0.);             2848   parameter -> SetDefaultValue (0.);
3113   fpCommand -> SetParameter (parameter);         2849   fpCommand -> SetParameter (parameter);
3114   parameter = new G4UIparameter ("parameter-6    2850   parameter = new G4UIparameter ("parameter-6", 'd', omitable = true);
3115   parameter -> SetDefaultValue (0.);             2851   parameter -> SetDefaultValue (0.);
3116   fpCommand -> SetParameter (parameter);         2852   fpCommand -> SetParameter (parameter);
3117 }                                                2853 }
3118                                                  2854 
3119 G4VisCommandSceneAddVolume::~G4VisCommandScen    2855 G4VisCommandSceneAddVolume::~G4VisCommandSceneAddVolume () {
3120   delete fpCommand;                              2856   delete fpCommand;
3121 }                                                2857 }
3122                                                  2858 
3123 G4String G4VisCommandSceneAddVolume::GetCurre    2859 G4String G4VisCommandSceneAddVolume::GetCurrentValue (G4UIcommand*) {
3124   return "world 0 -1";                           2860   return "world 0 -1";
3125 }                                                2861 }
3126                                                  2862 
3127 void G4VisCommandSceneAddVolume::SetNewValue     2863 void G4VisCommandSceneAddVolume::SetNewValue (G4UIcommand*,
3128                 G4String newValue) {             2864                 G4String newValue) {
3129                                                  2865 
3130   G4VisManager::Verbosity verbosity = fpVisMa    2866   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
3131   G4bool warn = verbosity >= G4VisManager::wa    2867   G4bool warn = verbosity >= G4VisManager::warnings;
3132                                                  2868 
3133   G4Scene* pScene = fpVisManager->GetCurrentS    2869   G4Scene* pScene = fpVisManager->GetCurrentScene();
3134   if (!pScene) {                                 2870   if (!pScene) {
3135     if (verbosity >= G4VisManager::errors) {     2871     if (verbosity >= G4VisManager::errors) {
3136       G4warn << "ERROR: No current scene.  Pl << 2872       G4cerr << "ERROR: No current scene.  Please create one." << G4endl;
3137     }                                            2873     }
3138     return;                                      2874     return;
3139   }                                              2875   }
3140                                                  2876 
3141   G4String name, clipVolumeType, parameterUni    2877   G4String name, clipVolumeType, parameterUnit;
3142   G4int copyNo, requestedDepthOfDescent;         2878   G4int copyNo, requestedDepthOfDescent;
3143   G4double param1, param2, param3, param4, pa    2879   G4double param1, param2, param3, param4, param5, param6;
3144   std::istringstream is (newValue);              2880   std::istringstream is (newValue);
3145   is >> name >> copyNo >> requestedDepthOfDes    2881   is >> name >> copyNo >> requestedDepthOfDescent
3146      >> clipVolumeType >> parameterUnit          2882      >> clipVolumeType >> parameterUnit
3147      >> param1 >> param2 >> param3 >> param4     2883      >> param1 >> param2 >> param3 >> param4 >> param5 >> param6;
3148   G4PhysicalVolumeModel::ClippingMode clippin    2884   G4PhysicalVolumeModel::ClippingMode clippingMode =
3149     G4PhysicalVolumeModel::subtraction;  // D    2885     G4PhysicalVolumeModel::subtraction;  // Default subtraction mode.
3150   if (clipVolumeType[size_t(0)] == '-') {        2886   if (clipVolumeType[size_t(0)] == '-') {
3151     clipVolumeType = clipVolumeType.substr(1)    2887     clipVolumeType = clipVolumeType.substr(1);  // Remove first character.
3152   } else if (clipVolumeType[size_t(0)] == '*'    2888   } else if (clipVolumeType[size_t(0)] == '*') {
3153     clippingMode = G4PhysicalVolumeModel::int    2889     clippingMode = G4PhysicalVolumeModel::intersection;
3154     clipVolumeType = clipVolumeType.substr(1)    2890     clipVolumeType = clipVolumeType.substr(1);
3155   }                                              2891   }
3156   G4double unit = G4UIcommand::ValueOf(parame    2892   G4double unit = G4UIcommand::ValueOf(parameterUnit);
3157   param1 *= unit; param2 *= unit; param3 *= u    2893   param1 *= unit; param2 *= unit; param3 *= unit;
3158   param4 *= unit; param5 *= unit; param6 *= u    2894   param4 *= unit; param5 *= unit; param6 *= unit;
3159                                                  2895 
3160   G4VSolid* clippingSolid = nullptr;          << 
3161   if (clipVolumeType == "box") {              << 
3162     const G4double dX = (param2 - param1) / 2 << 
3163     const G4double dY = (param4 - param3) / 2 << 
3164     const G4double dZ = (param6 - param5) / 2 << 
3165     const G4double x0 = (param2 + param1) / 2 << 
3166     const G4double y0 = (param4 + param3) / 2 << 
3167     const G4double z0 = (param6 + param5) / 2 << 
3168     clippingSolid = new G4DisplacedSolid      << 
3169     ("_displaced_clipping_box",               << 
3170      new G4Box("_clipping_box",dX,dY,dZ),     << 
3171      G4Translate3D(x0,y0,z0));                << 
3172   }                                           << 
3173                                               << 
3174   G4TransportationManager* transportationMana    2896   G4TransportationManager* transportationManager =
3175     G4TransportationManager::GetTransportatio    2897     G4TransportationManager::GetTransportationManager ();
3176                                                  2898 
3177   size_t nWorlds = transportationManager->Get    2899   size_t nWorlds = transportationManager->GetNoWorlds();
3178   if (nWorlds > 1) {  // Parallel worlds in o    2900   if (nWorlds > 1) {  // Parallel worlds in operation...
3179     if (verbosity >= G4VisManager::warnings)     2901     if (verbosity >= G4VisManager::warnings) {
3180       static G4bool warned = false;              2902       static G4bool warned = false;
3181       if (!warned && name != "worlds") {         2903       if (!warned && name != "worlds") {
3182   G4warn <<                                   << 2904   G4cout <<
3183     "WARNING: Parallel worlds in operation.      2905     "WARNING: Parallel worlds in operation.  To visualise, specify"
3184     "\n  \"worlds\" or the parallel world vol    2906     "\n  \"worlds\" or the parallel world volume or sub-volume name"
3185     "\n   and control visibility with /vis/ge    2907     "\n   and control visibility with /vis/geometry."
3186          << G4endl;                              2908          << G4endl;
3187   std::vector<G4VPhysicalVolume*>::iterator i    2909   std::vector<G4VPhysicalVolume*>::iterator iterWorld =
3188     transportationManager->GetWorldsIterator(    2910     transportationManager->GetWorldsIterator();
3189   for (size_t i = 0; i < nWorlds; ++i, ++iter    2911   for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
3190     G4warn << "  World " << i << ": " << (*it << 2912     G4cout << "  World " << i << ": " << (*iterWorld)->GetName()
3191      << G4endl;                                  2913      << G4endl;
3192     warned = true;                               2914     warned = true;
3193   }                                              2915   }
3194       }                                          2916       }
3195     }                                            2917     }
3196   }                                              2918   }
3197                                                  2919 
3198   // Get the world (the initial value of the     2920   // Get the world (the initial value of the iterator points to the mass world).
3199   G4VPhysicalVolume* world = *(transportation    2921   G4VPhysicalVolume* world = *(transportationManager->GetWorldsIterator());
3200                                                  2922 
3201   if (!world) {                                  2923   if (!world) {
3202     if (verbosity >= G4VisManager::errors) {     2924     if (verbosity >= G4VisManager::errors) {
3203       G4warn <<                               << 2925       G4cerr <<
3204   "ERROR: G4VisCommandSceneAddVolume::SetNewV    2926   "ERROR: G4VisCommandSceneAddVolume::SetNewValue:"
3205   "\n  No world.  Maybe the geometry has not     2927   "\n  No world.  Maybe the geometry has not yet been defined."
3206   "\n  Try \"/run/initialize\""                  2928   "\n  Try \"/run/initialize\""
3207        << G4endl;                                2929        << G4endl;
3208     }                                            2930     }
3209     return;                                      2931     return;
3210   }                                              2932   }
3211                                                  2933 
3212   std::vector<G4PhysicalVolumesSearchScene::F << 2934   std::vector<G4PhysicalVolumeModel*> models;
3213                                               << 2935   std::vector<G4VPhysicalVolume*> foundVolumes;
3214   // When it comes to determining the extent  << 2936   G4VPhysicalVolume* foundWorld = 0;
3215   // assume the user wishes to ignore "invisi << 2937   typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
3216   // users make the world volume invisible. S << 2938   typedef std::vector<PVNodeID> PVPath;
3217   // model to traverse the geometry hierarchy << 2939   PVPath foundFullPVPath;
3218   // volume, until it finds non-invisible one << 2940   std::vector<G4int> foundDepths;
3219   // to determine the overall extent. (Once a << 2941   std::vector<G4Transform3D> transformations;
3220   // the search is curtailed - daughters are  << 
3221   // so they have no subsequent influence on  << 
3222   // search continues at the same level until << 
3223   // volumes are found an their extents accum << 
3224   G4bool useFullExtent = false;               << 
3225   // However, the above procedure can be time << 
3226   // as a nested parameterisation whose ultim << 
3227   // visible ones, which are typical of a med << 
3228   // below that if a user specifies a name ot << 
3229   // wished the extent to be determined by th << 
3230   // or not. So we set useFullExtent true at  << 
3231                                                  2942 
3232   if (name == "world") {                         2943   if (name == "world") {
3233                                                  2944 
3234     findingsVector.push_back                  << 2945     models.push_back
3235     (G4PhysicalVolumesSearchScene::Findings(w << 2946       (new G4PhysicalVolumeModel (world, requestedDepthOfDescent));
                                                   >> 2947     foundVolumes.push_back(world);
                                                   >> 2948     foundDepths.push_back(0);
                                                   >> 2949     transformations.push_back(G4Transform3D());
3236                                                  2950 
3237   } else if (name == "worlds") {                 2951   } else if (name == "worlds") {
3238                                                  2952 
3239     if (nWorlds <= 1) {                       << 2953     if (nWorlds == 0) {
3240       if (verbosity >= G4VisManager::warnings    2954       if (verbosity >= G4VisManager::warnings) {
3241   G4warn <<                                   << 2955   G4cout <<
3242     "WARNING: G4VisCommandSceneAddVolume::Set    2956     "WARNING: G4VisCommandSceneAddVolume::SetNewValue:"
3243     "\n  Parallel worlds requested but none e    2957     "\n  Parallel worlds requested but none exist."
3244     "\n  Just adding material world."            2958     "\n  Just adding material world."
3245          << G4endl;                              2959          << G4endl;
3246       }                                          2960       }
3247     }                                            2961     }
3248     std::vector<G4VPhysicalVolume*>::iterator    2962     std::vector<G4VPhysicalVolume*>::iterator iterWorld =
3249       transportationManager->GetWorldsIterato    2963       transportationManager->GetWorldsIterator();
3250     for (size_t i = 0; i < nWorlds; ++i, ++it    2964     for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
3251       findingsVector.push_back                << 2965       models.push_back
3252       (G4PhysicalVolumesSearchScene::Findings << 2966   (new G4PhysicalVolumeModel (*iterWorld, requestedDepthOfDescent));
3253        (*iterWorld,*iterWorld));              << 2967       foundVolumes.push_back(*iterWorld);
                                                   >> 2968       foundDepths.push_back(0);
                                                   >> 2969       transformations.push_back(G4Transform3D());
3254     }                                            2970     }
3255                                                  2971 
3256   } else {  // Search all worlds...              2972   } else {  // Search all worlds...
3257                                               << 2973     
3258     // Use the model's full extent. This assu << 
3259     // volumes in the findings vector (there  << 
3260     // determine the scene's extent. Otherwis << 
3261     // re-calculate each volume's extent base << 
3262     // could be time consuming.               << 
3263     useFullExtent = true;                     << 
3264                                               << 
3265     std::vector<G4VPhysicalVolume*>::iterator    2974     std::vector<G4VPhysicalVolume*>::iterator iterWorld =
3266       transportationManager->GetWorldsIterato    2975       transportationManager->GetWorldsIterator();
3267     for (size_t i = 0; i < nWorlds; ++i, ++it    2976     for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
                                                   >> 2977       G4PhysicalVolumeModel searchModel (*iterWorld);  // Unlimited depth.
3268       G4ModelingParameters mp;  // Default -     2978       G4ModelingParameters mp;  // Default - no culling.
3269       G4PhysicalVolumeModel searchModel       << 2979       searchModel.SetModelingParameters (&mp);
3270       (*iterWorld,                            << 2980       G4PhysicalVolumeSearchScene searchScene (&searchModel, name, copyNo);
3271        requestedDepthOfDescent,               << 
3272        G4Transform3D(),                       << 
3273        &mp,                                   << 
3274        useFullExtent);                        << 
3275       G4PhysicalVolumesSearchScene searchScen << 
3276       searchModel.DescribeYourselfTo (searchS    2981       searchModel.DescribeYourselfTo (searchScene);  // Initiate search.
3277       for (const auto& findings: searchScene. << 2982       G4VPhysicalVolume* foundVolume = searchScene.GetFoundVolume ();
3278         findingsVector.push_back(findings);   << 2983       if (foundVolume) {
                                                   >> 2984   foundWorld = *iterWorld;
                                                   >> 2985   foundVolumes.push_back(foundVolume);
                                                   >> 2986         foundFullPVPath = searchScene.GetFoundFullPVPath();
                                                   >> 2987         foundDepths.push_back(searchScene.GetFoundDepth());
                                                   >> 2988   transformations.push_back(searchScene.GetFoundTransformation());
                                                   >> 2989   break;
3279       }                                          2990       }
3280     }                                            2991     }
3281   }                                           << 
3282                                                  2992 
3283   for (const auto& findings: findingsVector)  << 2993     if (foundVolumes.size()) {
3284     // Set copy number from search findings f << 2994       for (size_t i = 0; i < foundVolumes.size(); ++i) {
3285     findings.fpFoundPV->SetCopyNo(findings.fF << 2995         G4PhysicalVolumeModel* foundPVModel = new G4PhysicalVolumeModel
3286     G4PhysicalVolumeModel* foundPVModel = new << 2996         (foundVolumes[i], requestedDepthOfDescent, transformations[i]);
3287     (findings.fpFoundPV,                      << 2997         foundFullPVPath.pop_back();  // "Base" is "Found - 1".
3288      requestedDepthOfDescent,                 << 2998         foundPVModel->SetBaseFullPVPath(foundFullPVPath);
3289      findings.fFoundObjectTransformation,     << 2999   models.push_back(foundPVModel);
3290      0, // No modelling parameters (these are << 
3291      useFullExtent,                           << 
3292      findings.fFoundBasePVPath);              << 
3293     if (clippingSolid) {                      << 
3294       foundPVModel->SetClippingSolid(clipping << 
3295       foundPVModel->SetClippingMode(clippingM << 
3296     }                                         << 
3297     if (!foundPVModel->Validate(warn)) return << 
3298     // ...so add it to the scene.             << 
3299     G4bool successful = pScene->AddRunDuratio << 
3300     if (successful) {                         << 
3301       if (verbosity >= G4VisManager::confirma << 
3302         G4cout << "\"" << findings.fpFoundPV- << 
3303         << "\", copy no. " << findings.fFound << 
3304         << ",\n  found in searched volume \"" << 
3305         << findings.fpSearchPV->GetName()     << 
3306         << "\" at depth " << findings.fFoundD << 
3307         << ",\n  base path: \"" << findings.f << 
3308         << "\",\n  with a requested depth of  << 
3309         if (requestedDepthOfDescent < 0) {    << 
3310           G4cout << "<0 (unlimited)";         << 
3311         }                                     << 
3312         else {                                << 
3313           G4cout << requestedDepthOfDescent;  << 
3314         }                                     << 
3315         G4cout << ",\n  has been added to sce << 
3316         << G4endl;                            << 
3317       }                                          3000       }
3318     } else {                                     3001     } else {
3319       G4VisCommandsSceneAddUnsuccessful(verbo << 3002       if (verbosity >= G4VisManager::errors) {
3320     }                                         << 3003   G4cerr << "ERROR: Volume \"" << name << "\"";
3321   }                                           << 3004   if (copyNo >= 0) {
3322                                               << 3005     G4cerr << ", copy no. " << copyNo << ",";
3323   if (findingsVector.empty()) {               << 3006   }
3324     if (verbosity >= G4VisManager::errors) {  << 3007   G4cerr << " not found." << G4endl;
3325       G4warn << "ERROR: Volume \"" << name << << 
3326       if (copyNo >= 0) {                      << 
3327         G4warn << ", copy no. " << copyNo <<  << 
3328       }                                          3008       }
3329       G4warn << " not found." << G4endl;      << 3009       return;
3330     }                                            3010     }
3331     G4VisCommandsSceneAddUnsuccessful(verbosi << 
3332     return;                                   << 
3333   }                                              3011   }
3334                                                  3012 
3335   CheckSceneAndNotifyHandlers(pScene);        << 3013   if (clipVolumeType == "box") {
3336 }                                             << 3014     const G4double dX = (param2 - param1) / 2.;
3337                                               << 3015     const G4double dY = (param4 - param3) / 2.;
3338 ///////////////////////////////////////////// << 3016     const G4double dZ = (param6 - param5) / 2.;
3339 ////////////// /vis/scene/add/plotter /////// << 3017     const G4double x0 = (param2 + param1) / 2.;
3340 ///////////////////////////////////////////// << 3018     const G4double y0 = (param4 + param3) / 2.;
3341 G4VisCommandSceneAddPlotter::G4VisCommandScen << 3019     const G4double z0 = (param6 + param5) / 2.;
3342   fpCommand = new G4UIcommand("/vis/scene/add << 3020     G4VSolid* clippingSolid =
3343   fpCommand -> SetGuidance ("Add a plotter to << 3021       new G4DisplacedSolid
3344                                               << 3022       ("_displaced_clipping_box",
3345   G4UIparameter* parameter;                   << 3023        new G4Box("_clipping_box",dX,dY,dZ),
3346   parameter =  new G4UIparameter ("plotter",  << 3024        G4Translate3D(x0,y0,z0));
3347   fpCommand->SetParameter(parameter);         << 3025     for (size_t i = 0; i < foundVolumes.size(); ++i) {
3348 }                                             << 3026       models[i]->SetClippingSolid(clippingSolid);
3349                                               << 3027       models[i]->SetClippingMode(clippingMode);
3350 G4VisCommandSceneAddPlotter::~G4VisCommandSce << 3028     }
3351                                               << 3029   }  // If any other shape consider NumberOfRotationSides!!!!!!!!!!!
3352 G4String G4VisCommandSceneAddPlotter::GetCurr << 
3353                                               << 
3354 void G4VisCommandSceneAddPlotter::SetNewValue << 
3355 {                                             << 
3356   G4VisManager::Verbosity verbosity = fpVisMa << 
3357   G4bool warn(verbosity >= G4VisManager::warn << 
3358                                                  3030 
3359   G4Scene* pScene = fpVisManager->GetCurrentS << 3031   const G4String& currentSceneName = pScene -> GetName ();
3360   if (!pScene) {                              << 3032   G4bool failure = true;
3361     if (verbosity >= G4VisManager::errors) {  << 3033   for (size_t i = 0; i < foundVolumes.size(); ++i) {
3362       G4warn << "ERROR: No current scene.  Pl << 3034     G4bool successful = pScene -> AddRunDurationModel (models[i], warn);
                                                   >> 3035     if (successful) {
                                                   >> 3036       failure = false;
                                                   >> 3037       if (verbosity >= G4VisManager::confirmations) {
                                                   >> 3038   G4cout << "First occurrence of \""
                                                   >> 3039          << foundVolumes[i] -> GetName ()
                                                   >> 3040          << "\"";
                                                   >> 3041   if (copyNo >= 0) {
                                                   >> 3042     G4cout << ", copy no. " << copyNo << ",";
                                                   >> 3043   }
                                                   >> 3044   G4cout << "\n  found ";
                                                   >> 3045   if (foundWorld)
                                                   >> 3046     G4cout << "in world \"" << foundWorld->GetName() << "\" ";
                                                   >> 3047   G4cout << "at depth " << foundDepths[i]
                                                   >> 3048          << ",\n  with a requested depth of further descent of ";
                                                   >> 3049   if (requestedDepthOfDescent < 0) {
                                                   >> 3050     G4cout << "<0 (unlimited)";
                                                   >> 3051   }
                                                   >> 3052   else {
                                                   >> 3053     G4cout << requestedDepthOfDescent;
                                                   >> 3054   }
                                                   >> 3055   G4cout << ",\n  has been added to scene \"" << currentSceneName << "\"."
                                                   >> 3056          << G4endl;
                                                   >> 3057       }
3363     }                                            3058     }
3364     return;                                   << 
3365   }                                              3059   }
3366                                                  3060 
3367   G4Plotter& _plotter = G4PlotterManager::Get << 3061   if (failure) {
3368   G4VModel* model = new G4PlotterModel(_plott << 3062     G4VisCommandsSceneAddUnsuccessful(verbosity);
3369                                               << 3063     return;
3370   const G4String& currentSceneName = pScene - << 
3371   G4bool successful = pScene -> AddEndOfRunMo << 
3372   if (successful) {                           << 
3373     if (verbosity >= G4VisManager::confirmati << 
3374       G4cout                                  << 
3375       << "Plotter \"" << model->GetCurrentDes << 
3376       << "\" has been added to scene \"" << c << 
3377       << G4endl;                              << 
3378     }                                         << 
3379   }                                              3064   }
3380   else G4VisCommandsSceneAddUnsuccessful(verb << 
3381                                                  3065 
3382   CheckSceneAndNotifyHandlers (pScene);       << 3066   UpdateVisManagerScene (currentSceneName);
3383 }                                                3067 }
3384                                               << 
3385                                                  3068