G4VisCommandsSceneAdd.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 // /vis/scene/add commands - John Allison  9th August 1998
00029 
00030 #include "G4VisCommandsSceneAdd.hh"
00031 
00032 #include "G4TransportationManager.hh"
00033 #include "G4LogicalVolumeStore.hh"
00034 #include "G4PhysicalVolumeModel.hh"
00035 #include "G4LogicalVolumeModel.hh"
00036 #include "G4ModelingParameters.hh"
00037 #include "G4HitsModel.hh"
00038 #include "G4DigiModel.hh"
00039 #include "G4PSHitsModel.hh"
00040 #include "G4TrajectoriesModel.hh"
00041 #include "G4ScaleModel.hh"
00042 #include "G4TextModel.hh"
00043 #include "G4ArrowModel.hh"
00044 #include "G4AxesModel.hh"
00045 #include "G4PhysicalVolumeSearchScene.hh"
00046 #include "G4VGlobalFastSimulationManager.hh"
00047 #include "G4ParticleTable.hh"
00048 #include "G4ParticleDefinition.hh"
00049 #include "G4FlavoredParallelWorldModel.hh"
00050 #include "G4ApplicationState.hh"
00051 #include "G4VUserVisAction.hh"
00052 #include "G4CallbackModel.hh"
00053 #include "G4UnionSolid.hh"
00054 #include "G4SubtractionSolid.hh"
00055 #include "G4Polyhedron.hh"
00056 #include "G4UImanager.hh"
00057 #include "G4UIcommand.hh"
00058 #include "G4UIcmdWithAString.hh"
00059 #include "G4UIcmdWithoutParameter.hh"
00060 #include "G4Tokenizer.hh"
00061 #include "G4RunManager.hh"
00062 #include "G4StateManager.hh"
00063 #include "G4Run.hh"
00064 #include "G4Event.hh"
00065 #include "G4IdentityTrajectoryFilter.hh"
00066 #include "G4TransportationManager.hh"
00067 #include "G4PropagatorInField.hh"
00068 #include "G4Trajectory.hh"
00069 #include "G4TrajectoryPoint.hh"
00070 #include "G4RichTrajectory.hh"
00071 #include "G4RichTrajectoryPoint.hh"
00072 #include "G4SmoothTrajectory.hh"
00073 #include "G4SmoothTrajectoryPoint.hh"
00074 #include "G4AttDef.hh"
00075 #include "G4Polyline.hh"
00076 #include "G4UnitsTable.hh"
00077 #include "G4PhysicalConstants.hh"
00078 #include "G4SystemOfUnits.hh"
00079 
00080 #include <sstream>
00081 
00082 // Local function with some frequently used error printing...
00083 static void G4VisCommandsSceneAddUnsuccessful
00084 (G4VisManager::Verbosity verbosity) {
00085   if (verbosity >= G4VisManager::warnings) {
00086     G4cout <<
00087       "WARNING: For some reason, possibly mentioned above, it has not been"
00088       "\n  possible to add to the scene."
00089            << G4endl;
00090   }
00091 }
00092 
00094 
00095 G4VisCommandSceneAddArrow::G4VisCommandSceneAddArrow () {
00096   fpCommand = new G4UIcommand("/vis/scene/add/arrow", this);
00097   fpCommand -> SetGuidance ("Adds arrow to current scene.");
00098   G4bool omitable;
00099   G4UIparameter* parameter;
00100   parameter = new G4UIparameter ("x1", 'd', omitable = false);
00101   fpCommand -> SetParameter (parameter);
00102   parameter = new G4UIparameter ("y1", 'd', omitable = false);
00103   fpCommand -> SetParameter (parameter);
00104   parameter = new G4UIparameter ("z1", 'd', omitable = false);
00105   fpCommand -> SetParameter (parameter);
00106   parameter = new G4UIparameter ("x2", 'd', omitable = false);
00107   fpCommand -> SetParameter (parameter);
00108   parameter = new G4UIparameter ("y2", 'd', omitable = false);
00109   fpCommand -> SetParameter (parameter);
00110   parameter = new G4UIparameter ("z2", 'd', omitable = false);
00111   fpCommand -> SetParameter (parameter);
00112   parameter =  new G4UIparameter ("unit", 's', omitable = true);
00113   parameter->SetDefaultValue ("m");
00114   fpCommand->SetParameter    (parameter);
00115 }
00116 
00117 G4VisCommandSceneAddArrow::~G4VisCommandSceneAddArrow () {
00118   delete fpCommand;
00119 }
00120 
00121 G4String G4VisCommandSceneAddArrow::GetCurrentValue (G4UIcommand*) {
00122   return "";
00123 }
00124 
00125 void G4VisCommandSceneAddArrow::SetNewValue (G4UIcommand*, G4String newValue)
00126 {
00127   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00128   G4bool warn(verbosity >= G4VisManager::warnings);
00129 
00130   G4Scene* pScene = fpVisManager->GetCurrentScene();
00131   if (!pScene) {
00132     if (verbosity >= G4VisManager::errors) {
00133       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00134     }
00135     return;
00136   }
00137 
00138   G4String unitString;
00139   G4double x1, y1, z1, x2, y2, z2;
00140   std::istringstream is(newValue);
00141   is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> unitString;
00142   G4double unit = G4UIcommand::ValueOf(unitString);
00143   x1 *= unit; y1 *= unit; z1 *= unit;
00144   x2 *= unit; y2 *= unit; z2 *= unit;
00145 
00146   // Consult scene for arrow width.
00147   const G4VisExtent& sceneExtent = pScene->GetExtent();
00148   G4double arrowWidth =
00149     0.005 * fCurrentLineWidth * sceneExtent.GetExtentRadius();
00150 
00151   G4VModel* model = new G4ArrowModel
00152     (x1, y1, z1, x2, y2, z2,
00153      arrowWidth, fCurrentColour, newValue);
00154 
00155   const G4String& currentSceneName = pScene -> GetName ();
00156   G4bool successful = pScene -> AddRunDurationModel (model, warn);
00157   if (successful) {
00158     if (verbosity >= G4VisManager::confirmations) {
00159       G4cout << "Arrow has been added to scene \""
00160              << currentSceneName << "\"."
00161              << G4endl;
00162     }
00163   }
00164   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00165   UpdateVisManagerScene (currentSceneName);
00166 }
00167 
00169 
00170 G4VisCommandSceneAddArrow2D::G4VisCommandSceneAddArrow2D () {
00171   fpCommand = new G4UIcommand("/vis/scene/add/arrow2D", this);
00172   fpCommand -> SetGuidance ("Adds 2D arrow to current scene.");
00173   G4bool omitable;
00174   G4UIparameter* parameter;
00175   parameter = new G4UIparameter ("x1", 'd', omitable = false);
00176   fpCommand -> SetParameter (parameter);
00177   parameter = new G4UIparameter ("y1", 'd', omitable = false);
00178   fpCommand -> SetParameter (parameter);
00179   parameter = new G4UIparameter ("x2", 'd', omitable = false);
00180   fpCommand -> SetParameter (parameter);
00181   parameter = new G4UIparameter ("y2", 'd', omitable = false);
00182   fpCommand -> SetParameter (parameter);
00183 }
00184 
00185 G4VisCommandSceneAddArrow2D::~G4VisCommandSceneAddArrow2D () {
00186   delete fpCommand;
00187 }
00188 
00189 G4String G4VisCommandSceneAddArrow2D::GetCurrentValue (G4UIcommand*) {
00190   return "";
00191 }
00192 
00193 void G4VisCommandSceneAddArrow2D::SetNewValue (G4UIcommand*, G4String newValue)
00194 {
00195   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00196   G4bool warn(verbosity >= G4VisManager::warnings);
00197 
00198   G4Scene* pScene = fpVisManager->GetCurrentScene();
00199   if (!pScene) {
00200     if (verbosity >= G4VisManager::errors) {
00201       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00202     }
00203     return;
00204   }
00205 
00206   G4double x1, y1, x2, y2;
00207   std::istringstream is(newValue);
00208   is >> x1 >> y1 >> x2 >> y2;
00209 
00210   Arrow2D* arrow2D = new Arrow2D
00211     (x1, y1, x2, y2, fCurrentLineWidth, fCurrentColour);
00212   G4VModel* model =
00213     new G4CallbackModel<G4VisCommandSceneAddArrow2D::Arrow2D>(arrow2D);
00214   model->SetType("Arrow2D");
00215   model->SetGlobalTag("Arrow2D");
00216   model->SetGlobalDescription("Arrow2D: " + newValue);
00217   const G4String& currentSceneName = pScene -> GetName ();
00218   G4bool successful = pScene -> AddRunDurationModel (model, warn);
00219   if (successful) {
00220     if (verbosity >= G4VisManager::confirmations) {
00221       G4cout << "A 2D arrow has been added to scene \""
00222              << currentSceneName << "\"."
00223              << G4endl;
00224     }
00225   }
00226   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00227   UpdateVisManagerScene (currentSceneName);
00228 }
00229 
00230 G4VisCommandSceneAddArrow2D::Arrow2D::Arrow2D
00231 (G4double x1, G4double y1,
00232  G4double x2, G4double y2,
00233  G4double width, const G4Colour& colour):
00234   fWidth(width), fColour(colour)
00235 {
00236   fShaftPolyline.push_back(G4Point3D(x1,y1,0));
00237   fShaftPolyline.push_back(G4Point3D(x2,y2,0));
00238   G4Vector3D arrowDirection = G4Vector3D(x2-x1,y2-y1,0).unit();
00239   G4Vector3D arrowPointLeftDirection(arrowDirection);
00240   arrowPointLeftDirection.rotateZ(150.*deg);
00241   G4Vector3D arrowPointRightDirection(arrowDirection);
00242   arrowPointRightDirection.rotateZ(-150.*deg);
00243   fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0.04*arrowPointLeftDirection);
00244   fHeadPolyline.push_back(G4Point3D(x2,y2,0));
00245   fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0.04*arrowPointRightDirection);
00246   G4VisAttributes va;
00247   va.SetLineWidth(fWidth);
00248   va.SetColour(fColour);
00249   fShaftPolyline.SetVisAttributes(va);
00250   fHeadPolyline.SetVisAttributes(va);
00251 }
00252 
00253 void G4VisCommandSceneAddArrow2D::Arrow2D::operator()
00254   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
00255 {
00256   sceneHandler.BeginPrimitives2D();
00257   sceneHandler.AddPrimitive(fShaftPolyline);
00258   sceneHandler.AddPrimitive(fHeadPolyline);
00259   sceneHandler.EndPrimitives2D();
00260 }
00261 
00263 
00264 G4VisCommandSceneAddAxes::G4VisCommandSceneAddAxes () {
00265   G4bool omitable;
00266   fpCommand = new G4UIcommand ("/vis/scene/add/axes", this);
00267   fpCommand -> SetGuidance ("Add axes.");
00268   fpCommand -> SetGuidance
00269     ("Draws axes at (x0, y0, z0) of given length and colour.");
00270   G4UIparameter* parameter;
00271   parameter =  new G4UIparameter ("x0", 'd', omitable = true);
00272   parameter->SetDefaultValue (0.);
00273   fpCommand->SetParameter (parameter);
00274   parameter =  new G4UIparameter ("y0", 'd', omitable = true);
00275   parameter->SetDefaultValue (0.);
00276   fpCommand->SetParameter (parameter);
00277   parameter =  new G4UIparameter ("z0", 'd', omitable = true);
00278   parameter->SetDefaultValue (0.);
00279   fpCommand->SetParameter (parameter);
00280   parameter =  new G4UIparameter ("length", 'd', omitable = true);
00281   parameter->SetDefaultValue (-1.);
00282   parameter->SetGuidance
00283     ("If negative, length automatic, about 25% of scene extent.");
00284   fpCommand->SetParameter (parameter);
00285   parameter =  new G4UIparameter ("unit", 's', omitable = true);
00286   parameter->SetDefaultValue ("m");
00287   fpCommand->SetParameter (parameter);
00288   parameter =  new G4UIparameter ("unitcolour", 's', omitable = true);
00289   parameter->SetDefaultValue  ("auto");
00290   parameter->SetGuidance
00291     ("If \"auto\", x, y and z will be red, green and blue respectively.");
00292   parameter->SetGuidance
00293     ("Otherwise choose from the pre-defined text-specified colours - "
00294      "\n  see information printed by the vis manager at start-up or"
00295      "\n  use \"/vis/list\".");
00296   fpCommand->SetParameter (parameter);
00297 }
00298 
00299 G4VisCommandSceneAddAxes::~G4VisCommandSceneAddAxes () {
00300   delete fpCommand;
00301 }
00302 
00303 G4String G4VisCommandSceneAddAxes::GetCurrentValue (G4UIcommand*) {
00304   return "";
00305 }
00306 
00307 void G4VisCommandSceneAddAxes::SetNewValue (G4UIcommand*, G4String newValue) {
00308 
00309   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00310   G4bool warn(verbosity >= G4VisManager::warnings);
00311 
00312   G4Scene* pScene = fpVisManager->GetCurrentScene();
00313   if (!pScene) {
00314     if (verbosity >= G4VisManager::errors) {
00315       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00316     }
00317     return;
00318   }
00319 
00320   G4String unitString, colourString;
00321   G4double x0, y0, z0, length;
00322   std::istringstream is (newValue);
00323   is >> x0 >> y0 >> z0 >> length >> unitString  >> colourString;
00324 
00325   G4double unit = G4UIcommand::ValueOf(unitString);
00326   x0 *= unit; y0 *= unit; z0 *= unit;
00327   const G4VisExtent& sceneExtent = pScene->GetExtent();  // Existing extent.
00328   if (length < 0.) {
00329     length = 0.5 * sceneExtent.GetExtentRadius();
00330     G4double intLog10Length = std::floor(std::log10(length));
00331     length = std::pow(10,intLog10Length);
00332   } else {
00333     length *= unit;
00334   }
00335   G4String annotation = G4BestUnit(length,"Length");
00336 
00337   // Consult scene for arrow width...
00338   G4double arrowWidth =
00339     0.005 * fCurrentLineWidth * sceneExtent.GetExtentRadius();
00340   // ...but limit it to length/50.
00341   if (arrowWidth > length/50.) arrowWidth = length/50.;
00342 
00343   G4VModel* model = new G4AxesModel
00344     (x0, y0, z0, length, arrowWidth, colourString, newValue);
00345 
00346   G4bool successful = pScene -> AddRunDurationModel (model, warn);
00347   const G4String& currentSceneName = pScene -> GetName ();
00348   if (successful) {
00349     if (verbosity >= G4VisManager::confirmations) {
00350       G4cout << "Axes have been added to scene \"" << currentSceneName << "\"."
00351              << G4endl;
00352     }
00353   }
00354   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00355   UpdateVisManagerScene (currentSceneName);
00356 }
00357 
00359 
00360 G4VisCommandSceneAddDate::G4VisCommandSceneAddDate () {
00361   G4bool omitable;
00362   fpCommand = new G4UIcommand ("/vis/scene/add/date", this);
00363   fpCommand -> SetGuidance ("Adds date to current scene.");
00364   G4UIparameter* parameter;
00365   parameter = new G4UIparameter ("size", 'i', omitable = true);
00366   parameter -> SetGuidance ("Screen size of text in pixels.");
00367   parameter -> SetDefaultValue (18);
00368   fpCommand -> SetParameter (parameter);
00369   parameter = new G4UIparameter ("x-position", 'd', omitable = true);
00370   parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
00371   parameter -> SetDefaultValue (0.0);  // Would prefer 0.95 right.
00372   fpCommand -> SetParameter (parameter);
00373   parameter = new G4UIparameter ("y-position", 'd', omitable = true);
00374   parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
00375   parameter -> SetDefaultValue (0.9);
00376   fpCommand -> SetParameter (parameter);
00377   parameter = new G4UIparameter ("layout", 's', omitable = true);
00378   parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
00379   parameter -> SetDefaultValue ("left");  // Would prefer right.
00380   fpCommand -> SetParameter (parameter);
00381   parameter = new G4UIparameter ("date", 's', omitable = true);
00382   parameter -> SetGuidance
00383   ("The date you want to appear on the view of the scene (this includes the"
00384    "\nrest of the line, including spaces).  The default, \'-\', writes the"
00385    "\ndate and time of the moment of drawing.");
00386   parameter -> SetDefaultValue ("-");
00387   fpCommand -> SetParameter (parameter);
00388 }
00389 
00390 G4VisCommandSceneAddDate::~G4VisCommandSceneAddDate () {
00391   delete fpCommand;
00392 }
00393 
00394 G4String G4VisCommandSceneAddDate::GetCurrentValue (G4UIcommand*) {
00395   return "";
00396 }
00397 
00398 void G4VisCommandSceneAddDate::SetNewValue (G4UIcommand*, G4String newValue)
00399 {
00400   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00401   G4bool warn(verbosity >= G4VisManager::warnings);
00402 
00403   G4Scene* pScene = fpVisManager->GetCurrentScene();
00404   if (!pScene) {
00405     if (verbosity >= G4VisManager::errors) {
00406       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00407     }
00408     return;
00409   }
00410 
00411   G4int size;
00412   G4double x, y;
00413   G4String layoutString, dateString;
00414   std::istringstream is(newValue);
00415   is >> size >> x >> y >> layoutString >> dateString;
00416   // Read rest of line, if any.
00417   const size_t NREMAINDER = 100;
00418   char remainder[NREMAINDER];
00419   is.getline(remainder, NREMAINDER);
00420   dateString += remainder;
00421   G4Text::Layout layout = G4Text::right;
00422   if (layoutString(0) == 'l') layout = G4Text::left;
00423   else if (layoutString(0) == 'c') layout = G4Text::centre;
00424   else if (layoutString(0) == 'r') layout = G4Text::right;
00425 
00426   Date* date = new Date(fpVisManager, size, x, y, layout, dateString);
00427   G4VModel* model =
00428     new G4CallbackModel<G4VisCommandSceneAddDate::Date>(date);
00429   model->SetType("Date");
00430   model->SetGlobalTag("Date");
00431   model->SetGlobalDescription("Date");
00432   const G4String& currentSceneName = pScene -> GetName ();
00433   G4bool successful = pScene -> AddRunDurationModel (model, warn);
00434   if (successful) {
00435     if (verbosity >= G4VisManager::confirmations) {
00436       G4cout << "Date has been added to scene \""
00437              << currentSceneName << "\"."
00438              << G4endl;
00439     }
00440   }
00441   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00442   UpdateVisManagerScene (currentSceneName);
00443 }
00444 
00445 void G4VisCommandSceneAddDate::Date::operator()
00446   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
00447 {
00448   G4String time;
00449   if (fDate == "-") {
00450     time = fTimer.GetClockTime();
00451   } else {
00452     time = fDate;
00453   }
00454   // Check for \n, starting from back, and erase.
00455   std::string::size_type i = time.rfind('\n');
00456   if (i != std::string::npos) time.erase(i);
00457   G4Text text(time, G4Point3D(fX, fY, 0.));
00458   text.SetScreenSize(fSize);
00459   text.SetLayout(fLayout);
00460   G4VisAttributes textAtts(G4Colour(0.,1.,1));
00461   text.SetVisAttributes(textAtts);
00462   sceneHandler.BeginPrimitives2D();
00463   sceneHandler.AddPrimitive(text);
00464   sceneHandler.EndPrimitives2D();
00465 }
00466 
00468 
00469 G4VisCommandSceneAddDigis::G4VisCommandSceneAddDigis () {
00470   fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/add/digis", this);
00471   fpCommand -> SetGuidance ("Adds digis to current scene.");
00472   fpCommand -> SetGuidance
00473     ("Digis are drawn at end of event when the scene in which"
00474      "\nthey are added is current.");
00475 }
00476 
00477 G4VisCommandSceneAddDigis::~G4VisCommandSceneAddDigis () {
00478   delete fpCommand;
00479 }
00480 
00481 G4String G4VisCommandSceneAddDigis::GetCurrentValue (G4UIcommand*) {
00482   return "";
00483 }
00484 
00485 void G4VisCommandSceneAddDigis::SetNewValue (G4UIcommand*, G4String) {
00486 
00487   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00488   G4bool warn(verbosity >= G4VisManager::warnings);
00489 
00490   G4Scene* pScene = fpVisManager->GetCurrentScene();
00491   if (!pScene) {
00492     if (verbosity >= G4VisManager::errors) {
00493       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00494     }
00495     return;
00496   }
00497 
00498   G4DigiModel* model = new G4DigiModel;
00499   const G4String& currentSceneName = pScene -> GetName ();
00500   G4bool successful = pScene -> AddEndOfEventModel (model, warn);
00501   if (successful) {
00502     if (verbosity >= G4VisManager::confirmations) {
00503       G4cout << "Digis, if any, will be drawn at end of run in scene \""
00504              << currentSceneName << "\"."
00505              << G4endl;
00506     }
00507   }
00508   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00509   UpdateVisManagerScene (currentSceneName);
00510 }
00511 
00513 
00514 G4VisCommandSceneAddEventID::G4VisCommandSceneAddEventID () {
00515   G4bool omitable;
00516   fpCommand = new G4UIcommand ("/vis/scene/add/eventID", this);
00517   fpCommand -> SetGuidance ("Adds eventID to current scene.");
00518   fpCommand -> SetGuidance
00519     ("Run and event numbers are drawn at end of event or run when"
00520      "\n the scene in which they are added is current.");
00521   G4UIparameter* parameter;
00522   parameter = new G4UIparameter ("size", 'i', omitable = true);
00523   parameter -> SetGuidance ("Screen size of text in pixels.");
00524   parameter -> SetDefaultValue (18);
00525   fpCommand -> SetParameter (parameter);
00526   parameter = new G4UIparameter ("x-position", 'd', omitable = true);
00527   parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
00528   parameter -> SetDefaultValue (-0.95);
00529   fpCommand -> SetParameter (parameter);
00530   parameter = new G4UIparameter ("y-position", 'd', omitable = true);
00531   parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
00532   parameter -> SetDefaultValue (0.9);
00533   fpCommand -> SetParameter (parameter);
00534   parameter = new G4UIparameter ("layout", 's', omitable = true);
00535   parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
00536   parameter -> SetDefaultValue ("left");
00537   fpCommand -> SetParameter (parameter);
00538 }
00539 
00540 G4VisCommandSceneAddEventID::~G4VisCommandSceneAddEventID () {
00541   delete fpCommand;
00542 }
00543 
00544 G4String G4VisCommandSceneAddEventID::GetCurrentValue (G4UIcommand*) {
00545   return "";
00546 }
00547 
00548 void G4VisCommandSceneAddEventID::SetNewValue (G4UIcommand*, G4String newValue)
00549 {
00550   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00551   G4bool warn(verbosity >= G4VisManager::warnings);
00552 
00553   G4Scene* pScene = fpVisManager->GetCurrentScene();
00554   if (!pScene) {
00555     if (verbosity >= G4VisManager::errors) {
00556       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00557     }
00558     return;
00559   }
00560 
00561   G4int size;
00562   G4double x, y;
00563   G4String layoutString;
00564   std::istringstream is(newValue);
00565   is >> size >> x >> y >> layoutString;
00566 
00567   G4Text::Layout layout = G4Text::right;
00568   if (layoutString(0) == 'l') layout = G4Text::left;
00569   else if (layoutString(0) == 'c') layout = G4Text::centre;
00570   else if (layoutString(0) == 'r') layout = G4Text::right;
00571 
00572   EventID* eventID = new EventID(fpVisManager, size, x, y, layout);
00573   G4VModel* model =
00574     new G4CallbackModel<G4VisCommandSceneAddEventID::EventID>(eventID);
00575   model->SetType("EventID");
00576   model->SetGlobalTag("EventID");
00577   model->SetGlobalDescription("EventID");
00578   const G4String& currentSceneName = pScene -> GetName ();
00579   G4bool successful = pScene -> AddEndOfEventModel (model, warn);
00580   if (successful) {
00581     if (verbosity >= G4VisManager::confirmations) {
00582       G4cout << "EventID has been added to scene \""
00583              << currentSceneName << "\"."
00584              << G4endl;
00585     }
00586   }
00587   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00588   UpdateVisManagerScene (currentSceneName);
00589 }
00590 
00591 void G4VisCommandSceneAddEventID::EventID::operator()
00592   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
00593 {
00594   const G4Run* currentRun = 0;
00595   G4RunManager* runManager = G4RunManager::GetRunManager();
00596   if (runManager) currentRun = runManager->GetCurrentRun();
00597 
00598   G4VModel* model = fpVisManager->GetCurrentSceneHandler()->GetModel();
00599   const G4ModelingParameters* mp = 0;
00600   const G4Event* currentEvent = 0;
00601   if (model) {
00602    mp = model->GetModelingParameters();
00603    currentEvent = mp->GetEvent();
00604   } else {
00605     G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00606     if (verbosity >= G4VisManager::errors) {
00607       G4cout << "ERROR: No model defined for this SceneHandler : "
00608              << fpVisManager->GetCurrentSceneHandler()->GetName()
00609              << G4endl;
00610     }
00611   }
00612   if (currentRun && currentEvent) {
00613     G4int runID = currentRun->GetRunID();
00614     G4int eventID = currentEvent->GetEventID();
00615     std::ostringstream oss;
00616     if (fpVisManager->GetCurrentScene()->GetRefreshAtEndOfEvent()) {
00617       oss << "Run " << runID << " Event " << eventID;
00618     } else {
00619       G4int nEvents = 0;
00620       G4StateManager* stateManager = G4StateManager::GetStateManager();
00621       G4ApplicationState state = stateManager->GetCurrentState();
00622       if (state == G4State_EventProc) {
00623         nEvents = currentRun->GetNumberOfEventToBeProcessed();
00624       } else {
00625         const std::vector<const G4Event*>* events =
00626           currentRun->GetEventVector();
00627         if (events) nEvents = events->size();
00628       }
00629       if (eventID < nEvents - 1) return;  // Not last event.
00630       else {
00631         oss << "Run " << runID << " (" << nEvents << " event";
00632         if (nEvents != 1) oss << 's';
00633         oss << ')';
00634       }
00635     }
00636     G4Text text(oss.str(), G4Point3D(fX, fY, 0.));
00637     text.SetScreenSize(fSize);
00638     text.SetLayout(fLayout);
00639     G4VisAttributes textAtts(G4Colour(0.,1.,1));
00640     text.SetVisAttributes(textAtts);
00641     sceneHandler.BeginPrimitives2D();
00642     sceneHandler.AddPrimitive(text);
00643     sceneHandler.EndPrimitives2D();
00644   }
00645 }
00646 
00648 
00649 G4VisCommandSceneAddFrame::G4VisCommandSceneAddFrame () {
00650   fpCommand = new G4UIcommand("/vis/scene/add/frame", this);
00651   fpCommand -> SetGuidance ("Adds frame to current scene.");
00652   G4bool omitable;
00653   G4UIparameter* parameter;
00654   parameter = new G4UIparameter ("size", 'd', omitable = true);
00655   parameter -> SetGuidance ("Size of frame.  1 = full window.");
00656   parameter -> SetParameterRange ("size > 0 && size <=1");
00657   parameter -> SetDefaultValue (0.97);
00658   fpCommand -> SetParameter (parameter);
00659 }
00660 
00661 G4VisCommandSceneAddFrame::~G4VisCommandSceneAddFrame () {
00662   delete fpCommand;
00663 }
00664 
00665 G4String G4VisCommandSceneAddFrame::GetCurrentValue (G4UIcommand*) {
00666   return "";
00667 }
00668 
00669 void G4VisCommandSceneAddFrame::SetNewValue (G4UIcommand*, G4String newValue)
00670 {
00671   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00672   G4bool warn(verbosity >= G4VisManager::warnings);
00673 
00674   G4Scene* pScene = fpVisManager->GetCurrentScene();
00675   if (!pScene) {
00676     if (verbosity >= G4VisManager::errors) {
00677       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00678     }
00679     return;
00680   }
00681 
00682   G4double size;
00683   std::istringstream is(newValue);
00684   is >> size;
00685 
00686   Frame* frame = new Frame(size, fCurrentLineWidth, fCurrentColour);
00687   G4VModel* model =
00688     new G4CallbackModel<G4VisCommandSceneAddFrame::Frame>(frame);
00689   model->SetType("Frame");
00690   model->SetGlobalTag("Frame");
00691   model->SetGlobalDescription("Frame: " + newValue);
00692   const G4String& currentSceneName = pScene -> GetName ();
00693   G4bool successful = pScene -> AddRunDurationModel (model, warn);
00694   if (successful) {
00695     if (verbosity >= G4VisManager::confirmations) {
00696       G4cout << "Frame has been added to scene \""
00697              << currentSceneName << "\"."
00698              << G4endl;
00699     }
00700   }
00701   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00702   UpdateVisManagerScene (currentSceneName);
00703 }
00704 
00705 void G4VisCommandSceneAddFrame::Frame::operator()
00706   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
00707 {
00708   G4Polyline frame;
00709   frame.push_back(G4Point3D( fSize,  fSize, 0.));
00710   frame.push_back(G4Point3D(-fSize,  fSize, 0.));
00711   frame.push_back(G4Point3D(-fSize, -fSize, 0.));
00712   frame.push_back(G4Point3D( fSize, -fSize, 0.));
00713   frame.push_back(G4Point3D( fSize,  fSize, 0.));
00714   G4VisAttributes va;
00715   va.SetLineWidth(fWidth);
00716   va.SetColour(fColour);
00717   frame.SetVisAttributes(va);
00718   sceneHandler.BeginPrimitives2D();
00719   sceneHandler.AddPrimitive(frame);
00720   sceneHandler.EndPrimitives2D();
00721 }
00722 
00724 
00725 G4VisCommandSceneAddGhosts::G4VisCommandSceneAddGhosts () {
00726   G4bool omitable;
00727   fpCommand = new G4UIcmdWithAString ("/vis/scene/add/ghosts", this);
00728   fpCommand -> SetGuidance
00729     ("Adds ghost volumes (G4FlavoredParallelWorld) to the current scene.");
00730   fpCommand -> SetGuidance ("Selects by particle.");
00731   fpCommand -> SetParameterName ("particle", omitable = true);
00732   fpCommand -> SetDefaultValue ("all");
00733 }
00734 
00735 G4VisCommandSceneAddGhosts::~G4VisCommandSceneAddGhosts () {
00736   delete fpCommand;
00737 }
00738 
00739 G4String G4VisCommandSceneAddGhosts::GetCurrentValue (G4UIcommand*) {
00740   return "";
00741 }
00742 
00743 void G4VisCommandSceneAddGhosts::SetNewValue(G4UIcommand*, G4String newValue) {
00744 
00745   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00746   G4bool warn(verbosity >= G4VisManager::warnings);
00747 
00748   G4Scene* pScene = fpVisManager->GetCurrentScene();
00749   if (!pScene) {
00750     if (verbosity >= G4VisManager::errors) {
00751       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00752     }
00753     return;
00754   }
00755   const G4String& currentSceneName = pScene -> GetName ();
00756 
00757   // Gets the G4GlobalFastSimulationManager pointer if any.
00758   G4VGlobalFastSimulationManager* theGlobalFastSimulationManager;
00759   if(!(theGlobalFastSimulationManager = 
00760        G4VGlobalFastSimulationManager::GetConcreteInstance ())){
00761     if (verbosity >= G4VisManager::errors) {
00762       G4cout << "ERROR: no G4GlobalFastSimulationManager" << G4endl;
00763     }
00764     return;
00765   }
00766   
00767   // Gets the G4ParticleTable pointer.
00768   G4ParticleTable* theParticleTable=G4ParticleTable::GetParticleTable();
00769   
00770   // If "all" (the default) loops on all known particles
00771   if(newValue=="all") 
00772     {
00773       G4VFlavoredParallelWorld* CurrentFlavoredWorld = 0;
00774       G4bool successful = false;
00775       for (G4int iParticle=0; iParticle<theParticleTable->entries(); 
00776            iParticle++)
00777         {
00778           CurrentFlavoredWorld = theGlobalFastSimulationManager->
00779             GetFlavoredWorldForThis(theParticleTable->GetParticle(iParticle));
00780           
00781           if(CurrentFlavoredWorld)
00782             successful = successful || pScene -> 
00783               AddRunDurationModel(new G4FlavoredParallelWorldModel 
00784                                   (CurrentFlavoredWorld), warn);
00785         }
00786       if (successful) 
00787         {
00788           if (verbosity >= G4VisManager::confirmations) 
00789             G4cout << "Ghosts have been added to scene \""
00790                    << currentSceneName << "\"."
00791                    << G4endl;
00792           UpdateVisManagerScene (currentSceneName);
00793         }
00794       else 
00795         {
00796           G4cout << "ERROR: There are no ghosts."<<G4endl;
00797           G4VisCommandsSceneAddUnsuccessful(verbosity);
00798         }
00799       return;
00800     }
00801   
00802   // Given a particle name looks just for the concerned Ghosts, if any.
00803   G4ParticleDefinition* currentParticle = 
00804     theParticleTable->FindParticle(newValue);
00805   
00806   if (currentParticle == NULL) 
00807     {
00808       if (verbosity >= G4VisManager::errors) 
00809         G4cout << "ERROR: \"" << newValue
00810                << "\": not found this particle name!" << G4endl;
00811       return;
00812     }
00813   
00814   G4VFlavoredParallelWorld* worldForThis =
00815     theGlobalFastSimulationManager->GetFlavoredWorldForThis(currentParticle);
00816   if(worldForThis) 
00817     {
00818       G4bool successful = pScene -> AddRunDurationModel
00819         (new G4FlavoredParallelWorldModel (worldForThis), warn);
00820       if (successful) {
00821         if (verbosity >= G4VisManager::confirmations) 
00822           G4cout << "Ghosts have been added to scene \""
00823                  << currentSceneName << "\"."
00824                  << G4endl;
00825         UpdateVisManagerScene (currentSceneName);
00826       }
00827     }
00828   else 
00829     if (verbosity >= G4VisManager::errors) 
00830       {
00831         G4cout << "ERROR: There are no ghosts for \""<<newValue<<"\""<<G4endl;
00832         G4VisCommandsSceneAddUnsuccessful(verbosity);
00833       }
00834 }
00835 
00836 
00838 
00839 G4VisCommandSceneAddHits::G4VisCommandSceneAddHits () {
00840   fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/add/hits", this);
00841   fpCommand -> SetGuidance ("Adds hits to current scene.");
00842   fpCommand -> SetGuidance
00843     ("Hits are drawn at end of event when the scene in which"
00844      "\nthey are added is current.");
00845 }
00846 
00847 G4VisCommandSceneAddHits::~G4VisCommandSceneAddHits () {
00848   delete fpCommand;
00849 }
00850 
00851 G4String G4VisCommandSceneAddHits::GetCurrentValue (G4UIcommand*) {
00852   return "";
00853 }
00854 
00855 void G4VisCommandSceneAddHits::SetNewValue (G4UIcommand*, G4String) {
00856 
00857   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00858   G4bool warn(verbosity >= G4VisManager::warnings);
00859 
00860   G4Scene* pScene = fpVisManager->GetCurrentScene();
00861   if (!pScene) {
00862     if (verbosity >= G4VisManager::errors) {
00863       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00864     }
00865     return;
00866   }
00867 
00868   G4HitsModel* model = new G4HitsModel;
00869   const G4String& currentSceneName = pScene -> GetName ();
00870   G4bool successful = pScene -> AddEndOfEventModel (model, warn);
00871   if (successful) {
00872     if (verbosity >= G4VisManager::confirmations) {
00873       G4cout << "Hits, if any, will be drawn at end of run in scene \""
00874              << currentSceneName << "\"."
00875              << G4endl;
00876     }
00877   }
00878   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00879   UpdateVisManagerScene (currentSceneName);
00880 }
00881 
00883 
00884 G4VisCommandSceneAddLine::G4VisCommandSceneAddLine () {
00885   fpCommand = new G4UIcommand("/vis/scene/add/line", this);
00886   fpCommand -> SetGuidance ("Adds line to current scene.");
00887   G4bool omitable;
00888   G4UIparameter* parameter;
00889   parameter = new G4UIparameter ("x1", 'd', omitable = false);
00890   fpCommand -> SetParameter (parameter);
00891   parameter = new G4UIparameter ("y1", 'd', omitable = false);
00892   fpCommand -> SetParameter (parameter);
00893   parameter = new G4UIparameter ("z1", 'd', omitable = false);
00894   fpCommand -> SetParameter (parameter);
00895   parameter = new G4UIparameter ("x2", 'd', omitable = false);
00896   fpCommand -> SetParameter (parameter);
00897   parameter = new G4UIparameter ("y2", 'd', omitable = false);
00898   fpCommand -> SetParameter (parameter);
00899   parameter = new G4UIparameter ("z2", 'd', omitable = false);
00900   fpCommand -> SetParameter (parameter);
00901   parameter =  new G4UIparameter ("unit", 's', omitable = true);
00902   parameter->SetDefaultValue ("m");
00903   fpCommand->SetParameter    (parameter);
00904 }
00905 
00906 G4VisCommandSceneAddLine::~G4VisCommandSceneAddLine () {
00907   delete fpCommand;
00908 }
00909 
00910 G4String G4VisCommandSceneAddLine::GetCurrentValue (G4UIcommand*) {
00911   return "";
00912 }
00913 
00914 void G4VisCommandSceneAddLine::SetNewValue (G4UIcommand*, G4String newValue)
00915 {
00916   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
00917   G4bool warn(verbosity >= G4VisManager::warnings);
00918 
00919   G4Scene* pScene = fpVisManager->GetCurrentScene();
00920   if (!pScene) {
00921     if (verbosity >= G4VisManager::errors) {
00922       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
00923     }
00924     return;
00925   }
00926 
00927   G4String unitString;
00928   G4double x1, y1, z1, x2, y2, z2;
00929   std::istringstream is(newValue);
00930   is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> unitString;
00931   G4double unit = G4UIcommand::ValueOf(unitString);
00932   x1 *= unit; y1 *= unit; z1 *= unit;
00933   x2 *= unit; y2 *= unit; z2 *= unit;
00934 
00935   Line* line = new Line(x1, y1, z1, x2, y2, z2,
00936                         fCurrentLineWidth, fCurrentColour);
00937   G4VModel* model =
00938     new G4CallbackModel<G4VisCommandSceneAddLine::Line>(line);
00939   model->SetType("Line");
00940   model->SetGlobalTag("Line");
00941   model->SetGlobalDescription("Line: " + newValue);
00942   const G4String& currentSceneName = pScene -> GetName ();
00943   G4bool successful = pScene -> AddRunDurationModel (model, warn);
00944   if (successful) {
00945     if (verbosity >= G4VisManager::confirmations) {
00946       G4cout << "Line has been added to scene \""
00947              << currentSceneName << "\"."
00948              << G4endl;
00949     }
00950   }
00951   else G4VisCommandsSceneAddUnsuccessful(verbosity);
00952   UpdateVisManagerScene (currentSceneName);
00953 }
00954 
00955 G4VisCommandSceneAddLine::Line::Line
00956 (G4double x1, G4double y1, G4double z1,
00957  G4double x2, G4double y2, G4double z2,
00958  G4double width, const G4Colour& colour):
00959   fWidth(width), fColour(colour)
00960 {
00961   fPolyline.push_back(G4Point3D(x1,y1,z1));
00962   fPolyline.push_back(G4Point3D(x2,y2,z2));
00963   G4VisAttributes va;
00964   va.SetLineWidth(fWidth);
00965   va.SetColour(fColour);
00966   fPolyline.SetVisAttributes(va);
00967 }
00968 
00969 void G4VisCommandSceneAddLine::Line::operator()
00970   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
00971 {
00972   sceneHandler.BeginPrimitives();
00973   sceneHandler.AddPrimitive(fPolyline);
00974   sceneHandler.EndPrimitives();
00975 }
00976 
00978 
00979 G4VisCommandSceneAddLine2D::G4VisCommandSceneAddLine2D () {
00980   fpCommand = new G4UIcommand("/vis/scene/add/line2D", this);
00981   fpCommand -> SetGuidance ("Adds 2D line to current scene.");
00982   G4bool omitable;
00983   G4UIparameter* parameter;
00984   parameter = new G4UIparameter ("x1", 'd', omitable = false);
00985   fpCommand -> SetParameter (parameter);
00986   parameter = new G4UIparameter ("y1", 'd', omitable = false);
00987   fpCommand -> SetParameter (parameter);
00988   parameter = new G4UIparameter ("x2", 'd', omitable = false);
00989   fpCommand -> SetParameter (parameter);
00990   parameter = new G4UIparameter ("y2", 'd', omitable = false);
00991   fpCommand -> SetParameter (parameter);
00992 }
00993 
00994 G4VisCommandSceneAddLine2D::~G4VisCommandSceneAddLine2D () {
00995   delete fpCommand;
00996 }
00997 
00998 G4String G4VisCommandSceneAddLine2D::GetCurrentValue (G4UIcommand*) {
00999   return "";
01000 }
01001 
01002 void G4VisCommandSceneAddLine2D::SetNewValue (G4UIcommand*, G4String newValue)
01003 {
01004   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01005   G4bool warn(verbosity >= G4VisManager::warnings);
01006 
01007   G4Scene* pScene = fpVisManager->GetCurrentScene();
01008   if (!pScene) {
01009     if (verbosity >= G4VisManager::errors) {
01010       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
01011     }
01012     return;
01013   }
01014 
01015   G4double x1, y1, x2, y2;
01016   std::istringstream is(newValue);
01017   is >> x1 >> y1 >> x2 >> y2;
01018 
01019   Line2D* line2D = new Line2D
01020     (x1, y1, x2, y2, fCurrentLineWidth, fCurrentColour);
01021   G4VModel* model =
01022     new G4CallbackModel<G4VisCommandSceneAddLine2D::Line2D>(line2D);
01023   model->SetType("Line2D");
01024   model->SetGlobalTag("Line2D");
01025   model->SetGlobalDescription("Line2D: " + newValue);
01026   const G4String& currentSceneName = pScene -> GetName ();
01027   G4bool successful = pScene -> AddRunDurationModel (model, warn);
01028   if (successful) {
01029     if (verbosity >= G4VisManager::confirmations) {
01030       G4cout << "A 2D line has been added to scene \""
01031              << currentSceneName << "\"."
01032              << G4endl;
01033     }
01034   }
01035   else G4VisCommandsSceneAddUnsuccessful(verbosity);
01036   UpdateVisManagerScene (currentSceneName);
01037 }
01038 
01039 G4VisCommandSceneAddLine2D::Line2D::Line2D
01040 (G4double x1, G4double y1,
01041  G4double x2, G4double y2,
01042  G4double width, const G4Colour& colour):
01043   fWidth(width), fColour(colour)
01044 {
01045   fPolyline.push_back(G4Point3D(x1,y1,0));
01046   fPolyline.push_back(G4Point3D(x2,y2,0));
01047   G4VisAttributes va;
01048   va.SetLineWidth(fWidth);
01049   va.SetColour(fColour);
01050   fPolyline.SetVisAttributes(va);
01051 }
01052 
01053 void G4VisCommandSceneAddLine2D::Line2D::operator()
01054   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
01055 {
01056   sceneHandler.BeginPrimitives2D();
01057   sceneHandler.AddPrimitive(fPolyline);
01058   sceneHandler.EndPrimitives2D();
01059 }
01060 
01062 
01063 G4VisCommandSceneAddLogicalVolume::G4VisCommandSceneAddLogicalVolume () {
01064   G4bool omitable;
01065   fpCommand = new G4UIcommand ("/vis/scene/add/logicalVolume", this);
01066   fpCommand -> SetGuidance ("Adds a logical volume to the current scene,");
01067   fpCommand -> SetGuidance
01068     ("Shows boolean components (if any), voxels (if any) and readout geometry"
01069      "\n(if any).  Note: voxels are not constructed until start of run -"
01070      "\n \"/run/beamOn\".");
01071   G4UIparameter* parameter;
01072   parameter = new G4UIparameter ("logical-volume-name", 's', omitable = false);
01073   fpCommand -> SetParameter (parameter);
01074   parameter = new G4UIparameter ("depth-of-descent", 'i', omitable = true);
01075   parameter -> SetGuidance ("Depth of descent of geometry hierarchy.");
01076   parameter -> SetDefaultValue (1);
01077   fpCommand -> SetParameter (parameter);
01078   parameter = new G4UIparameter ("booleans-flag", 'b', omitable = true);
01079   parameter -> SetDefaultValue (true);
01080   fpCommand -> SetParameter (parameter);
01081   parameter = new G4UIparameter ("voxels-flag", 'b', omitable = true);
01082   parameter -> SetDefaultValue (true);
01083   fpCommand -> SetParameter (parameter);
01084   parameter = new G4UIparameter ("readout-flag", 'b', omitable = true);
01085   parameter -> SetDefaultValue (true);
01086   fpCommand -> SetParameter (parameter);
01087 }
01088 
01089 G4VisCommandSceneAddLogicalVolume::~G4VisCommandSceneAddLogicalVolume () {
01090   delete fpCommand;
01091 }
01092 
01093 G4String G4VisCommandSceneAddLogicalVolume::GetCurrentValue (G4UIcommand*) {
01094   return "";
01095 }
01096 
01097 void G4VisCommandSceneAddLogicalVolume::SetNewValue (G4UIcommand*,
01098                                                      G4String newValue) {
01099 
01100   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01101   G4bool warn(verbosity >= G4VisManager::warnings);
01102 
01103   G4Scene* pScene = fpVisManager->GetCurrentScene();
01104   if (!pScene) {
01105     if (verbosity >= G4VisManager::errors) {
01106       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
01107     }
01108     return;
01109   }
01110 
01111   G4String name;
01112   G4int requestedDepthOfDescent;
01113   G4String booleansString, voxelsString, readoutString;
01114   std::istringstream is (newValue);
01115   is >> name >> requestedDepthOfDescent
01116      >>  booleansString >> voxelsString >> readoutString;
01117   G4bool booleans = G4UIcommand::ConvertToBool(booleansString);
01118   G4bool voxels = G4UIcommand::ConvertToBool(voxelsString);
01119   G4bool readout = G4UIcommand::ConvertToBool(readoutString);
01120 
01121   G4LogicalVolumeStore *pLVStore = G4LogicalVolumeStore::GetInstance();
01122   int nLV = pLVStore -> size ();
01123   int iLV;
01124   G4LogicalVolume* pLV = 0;
01125   for (iLV = 0; iLV < nLV; iLV++ ) {
01126     pLV = (*pLVStore) [iLV];
01127     if (pLV -> GetName () == name) break;
01128   }
01129   if (iLV == nLV) {
01130     if (verbosity >= G4VisManager::errors) {
01131       G4cout << "ERROR: Logical volume " << name
01132              << " not found in logical volume store." << G4endl;
01133     }
01134     return;
01135   }
01136 
01137   const std::vector<G4Scene::Model>& rdModelList = pScene -> GetRunDurationModelList();
01138   std::vector<G4Scene::Model>::const_iterator i;
01139   for (i = rdModelList.begin(); i != rdModelList.end(); ++i) {
01140     if (i->fpModel->GetGlobalDescription().find("Volume") != std::string::npos) break;
01141   }
01142   if (i != rdModelList.end()) {
01143     if (verbosity >= G4VisManager::errors) {
01144       G4cout << "There is already a volume, \""
01145              << i->fpModel->GetGlobalDescription()
01146              << "\",\n in the run-duration model list of scene \""
01147              << pScene -> GetName()
01148              << "\".\n Your logical volume must be the only volume in the scene."
01149              << "\n Create a new scene and try again:"
01150              << "\n  /vis/specify " << name
01151              << "\n or"
01152              << "\n  /vis/scene/create"
01153              << "\n  /vis/scene/add/logicalVolume " << name
01154              << "\n  /vis/sceneHandler/attach"
01155              << "\n (and also, if necessary, /vis/viewer/flush)"
01156              << G4endl;
01157     }
01158   }
01159 
01160   G4VModel* model = new G4LogicalVolumeModel
01161     (pLV, requestedDepthOfDescent, booleans, voxels, readout);
01162   const G4String& currentSceneName = pScene -> GetName ();
01163   G4bool successful = pScene -> AddRunDurationModel (model, warn);
01164   if (successful) {
01165     if (verbosity >= G4VisManager::confirmations) {
01166       G4cout << "Logical volume \"" << pLV -> GetName ()
01167              << " with requested depth of descent "
01168              << requestedDepthOfDescent
01169              << ",\n with";
01170       if (!booleans) G4cout << "out";
01171       G4cout << " boolean components, with";
01172       if (!voxels) G4cout << "out";
01173       G4cout << " voxels and with";
01174       if (!readout) G4cout << "out";
01175       G4cout << " readout geometry,"
01176              << "\n  has been added to scene \"" << currentSceneName << "\"."
01177              << G4endl;
01178     }
01179   }
01180   else {
01181     G4VisCommandsSceneAddUnsuccessful(verbosity);
01182     return;
01183   }
01184 
01185   UpdateVisManagerScene (currentSceneName);
01186 }
01187 
01188 
01190 
01191 G4VisCommandSceneAddLogo::G4VisCommandSceneAddLogo () {
01192   G4bool omitable;
01193   fpCommand = new G4UIcommand ("/vis/scene/add/logo", this);
01194   fpCommand -> SetGuidance ("Adds a G4 logo to the current scene.");
01195   G4UIparameter* parameter;
01196   parameter = new G4UIparameter ("height", 'd', omitable = true);
01197   parameter->SetDefaultValue (1.);
01198   fpCommand->SetParameter (parameter);
01199   parameter =  new G4UIparameter ("unit", 's', omitable = true);
01200   parameter->SetGuidance
01201     ("auto or valid length unit - defaults to auto."
01202      "\nIf auto, height is roughly one tenth of scene extent.");
01203   parameter->SetDefaultValue ("auto");
01204   fpCommand->SetParameter (parameter);
01205   parameter =  new G4UIparameter ("direction", 's', omitable = true);
01206   parameter->SetGuidance
01207     ("auto|[-]x|[-]y|[-]z - defaults to auto."
01208      "\nDirection of outward-facing normal to front face of logo."
01209      "\nIf automatic, logo faces the user in the current viewer.");
01210   parameter->SetDefaultValue ("auto");
01211   fpCommand->SetParameter (parameter);
01212   parameter =  new G4UIparameter ("red", 'd', omitable = true);
01213   parameter->SetDefaultValue (0.);
01214   fpCommand->SetParameter (parameter);
01215   parameter =  new G4UIparameter ("green", 'd', omitable = true);
01216   parameter->SetDefaultValue (1.);
01217   fpCommand->SetParameter (parameter);
01218   parameter =  new G4UIparameter ("blue", 'd', omitable = true);
01219   parameter->SetDefaultValue (0.);
01220   fpCommand->SetParameter (parameter);
01221   parameter =  new G4UIparameter ("auto|manual", 's', omitable = true);
01222   parameter->SetGuidance
01223     ("Automatic placement or manual placement at (xmid,ymid,zmid).");
01224   parameter->SetGuidance
01225     ("If automatic, placed at bottom right of screen when viewed from");
01226   parameter->SetGuidance
01227     ("logo direction.");
01228   parameter -> SetParameterCandidates("auto manual");
01229   parameter->SetDefaultValue  ("auto");
01230   fpCommand->SetParameter     (parameter);
01231   parameter =  new G4UIparameter ("xmid", 'd', omitable = true);
01232   parameter->SetDefaultValue (0.);
01233   fpCommand->SetParameter (parameter);
01234   parameter =  new G4UIparameter ("ymid", 'd', omitable = true);
01235   parameter->SetDefaultValue (0.);
01236   fpCommand->SetParameter (parameter);
01237   parameter =  new G4UIparameter ("zmid", 'd', omitable = true);
01238   parameter->SetDefaultValue (0.);
01239   fpCommand->SetParameter (parameter);
01240   parameter =  new G4UIparameter ("unit", 's', omitable = true);
01241   parameter->SetDefaultValue ("m");
01242   fpCommand->SetParameter (parameter);
01243 }
01244 
01245 G4VisCommandSceneAddLogo::~G4VisCommandSceneAddLogo () {
01246   delete fpCommand;
01247 }
01248 
01249 G4String G4VisCommandSceneAddLogo::GetCurrentValue (G4UIcommand*) {
01250   return "";
01251 }
01252 
01253 void G4VisCommandSceneAddLogo::SetNewValue (G4UIcommand*, G4String newValue) {
01254 
01255   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01256   G4bool warn = verbosity >= G4VisManager::warnings;
01257 
01258   G4Scene* pScene = fpVisManager->GetCurrentScene();
01259   if (!pScene) {
01260     if (verbosity >= G4VisManager::errors) {
01261       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
01262     }
01263     return;
01264   }
01265 
01266   G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
01267   if (!pViewer) {
01268     if (verbosity >= G4VisManager::errors) {
01269       G4cout << 
01270         "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer."
01271         "\n  Auto direction needs a viewer."
01272              << G4endl;
01273     }
01274     return;
01275   }
01276 
01277   G4double userHeight, red, green, blue, xmid, ymid, zmid;
01278   G4String userHeightUnit, direction, auto_manual, positionUnit;
01279   std::istringstream is (newValue);
01280   is >> userHeight >> userHeightUnit >> direction
01281      >> red >> green >> blue
01282      >> auto_manual
01283      >> xmid >> ymid >> zmid >> positionUnit;
01284 
01285   G4double height = userHeight;
01286   const G4VisExtent& sceneExtent = pScene->GetExtent();  // Existing extent.
01287   if (userHeightUnit == "auto") {
01288     height *= 0.2 * sceneExtent.GetExtentRadius();
01289   } else {
01290     height *= G4UIcommand::ValueOf(userHeightUnit);
01291   }
01292 
01293   G4double unit = G4UIcommand::ValueOf(positionUnit);
01294   xmid *= unit; ymid *= unit; zmid *= unit;
01295 
01296   Direction logoDirection = X;  // Initialise to keep some compilers happy.
01297   if (direction == "auto") {
01298     // Take cue from viewer
01299     const G4Vector3D& vp =
01300       pViewer->GetViewParameters().GetViewpointDirection();
01301     if (vp.x() > vp.y() && vp.x() > vp.z()) logoDirection = X;
01302     else if (vp.x() < vp.y() && vp.x() < vp.z()) logoDirection = minusX;
01303     else if (vp.y() > vp.x() && vp.y() > vp.z()) logoDirection = Y;
01304     else if (vp.y() < vp.x() && vp.y() < vp.z()) logoDirection = minusY;
01305     else if (vp.z() > vp.x() && vp.z() > vp.y()) logoDirection = Z;
01306     else if (vp.z() < vp.x() && vp.z() < vp.y()) logoDirection = minusZ;
01307   }
01308   else if (direction(0) == 'x') logoDirection = X;
01309   else if (direction(0) == 'y') logoDirection = Y;
01310   else if (direction(0) == 'z') logoDirection = Z;
01311   else if (direction(0) == '-') {
01312     if (direction(1) == 'x') logoDirection = minusX;
01313     else if (direction(1) == 'y') logoDirection = minusY;
01314     else if (direction(1) == 'z') logoDirection = minusZ;
01315   } else {
01316     if (verbosity >= G4VisManager::errors) {
01317       G4cout << "ERROR: Unrecogniseed direction: \""
01318              << direction << "\"." << G4endl;
01319       return;
01320     }
01321   }
01322 
01323   G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
01324   // Parameters read and interpreted.
01325 
01326   // Current scene extent
01327   const G4double xmin = sceneExtent.GetXmin();
01328   const G4double xmax = sceneExtent.GetXmax();
01329   const G4double ymin = sceneExtent.GetYmin();
01330   const G4double ymax = sceneExtent.GetYmax();
01331   const G4double zmin = sceneExtent.GetZmin();
01332   const G4double zmax = sceneExtent.GetZmax();
01333 
01334   // Test existing extent and issue warnings...
01335   G4bool worried = false;
01336   if (sceneExtent.GetExtentRadius() == 0) {
01337     worried = true;
01338     if (verbosity >= G4VisManager::warnings) {
01339       G4cout <<
01340         "WARNING: Existing scene does not yet have any extent."
01341         "\n  Maybe you have not yet added any geometrical object."
01342              << G4endl;
01343     }
01344   }
01345 
01346   // Useful constants, etc...
01347   const G4double halfHeight(height / 2.);
01348   const G4double comfort(0.01);  // 0.15 seems too big.  0.05 might be better.
01349   const G4double freeHeightFraction (1. + 2. * comfort);
01350 
01351   // Test existing scene for room...
01352   G4bool room = true;
01353   switch (logoDirection) {
01354   case X:
01355   case minusX:
01356     if (freeHeightFraction * (xmax - xmin) < height) room = false; break;
01357   case Y:
01358   case minusY:
01359     if (freeHeightFraction * (ymax - ymin) < height) room = false; break;
01360   case Z:
01361   case minusZ:
01362     if (freeHeightFraction * (zmax - zmin) < height) room = false; break;
01363   }
01364   if (!room) {
01365     worried = true;
01366     if (verbosity >= G4VisManager::warnings) {
01367       G4cout <<
01368         "WARNING: Not enough room in existing scene.  Maybe logo is too large."
01369              << G4endl;
01370     }
01371   }
01372   if (worried) {
01373     if (verbosity >= G4VisManager::warnings) {
01374       G4cout <<
01375         "WARNING: The logo you have asked for is bigger than the existing"
01376         "\n  scene.  Maybe you have added it too soon.  It is recommended that"
01377         "\n  you add the logo last so that it can be correctly auto-positioned"
01378         "\n  so as not to be obscured by any existing object and so that the"
01379         "\n  view parameters can be correctly recalculated."
01380              << G4endl;
01381     }
01382   }
01383 
01384   G4double sxmid(xmid), symid(ymid), szmid(zmid);
01385   if (autoPlacing) {
01386     // Aim to place at bottom right of screen when viewed from logoDirection.
01387     // Give some comfort zone.
01388     const G4double xComfort = comfort * (xmax - xmin);
01389     const G4double yComfort = comfort * (ymax - ymin);
01390     const G4double zComfort = comfort * (zmax - zmin);
01391     switch (logoDirection) {
01392     case X:  // y-axis up, z-axis to left?
01393       sxmid = xmax + halfHeight + xComfort;
01394       symid = ymin - yComfort;
01395       szmid = zmin - zComfort;
01396       break;
01397     case minusX:  // y-axis up, z-axis to right?
01398       sxmid = xmin - halfHeight - xComfort;
01399       symid = ymin - yComfort;
01400       szmid = zmax + zComfort;
01401       break;
01402     case Y:  // z-axis up, x-axis to left?
01403       sxmid = xmin - xComfort;
01404       symid = ymax + halfHeight + yComfort;
01405       szmid = zmin - zComfort;
01406       break;
01407     case minusY:  // z-axis up, x-axis to right?
01408       sxmid = xmax + xComfort;
01409       symid = ymin - halfHeight - yComfort;
01410       szmid = zmin - zComfort;
01411       break;
01412     case Z:  // y-axis up, x-axis to right?
01413       sxmid = xmax + xComfort;
01414       symid = ymin - yComfort;
01415       szmid = zmax + halfHeight + zComfort;
01416       break;
01417     case minusZ:  // y-axis up, x-axis to left?
01418       sxmid = xmin - xComfort;
01419       symid = ymin - yComfort;
01420       szmid = zmin - halfHeight - zComfort;
01421       break;
01422     }
01423   }
01424 
01425   G4Transform3D transform;
01426   switch (logoDirection) {
01427   case X:  // y-axis up, z-axis to left?
01428     transform = G4RotateY3D(halfpi);
01429     break;
01430   case minusX:  // y-axis up, z-axis to right?
01431     transform = G4RotateY3D(-halfpi);
01432     break;
01433   case Y:  // z-axis up, x-axis to left?
01434     transform = G4RotateX3D(-halfpi) * G4RotateZ3D(pi);
01435     break;
01436   case minusY:  // z-axis up, x-axis to right?
01437     transform = G4RotateX3D(halfpi);
01438     break;
01439   case Z:  // y-axis up, x-axis to right?
01440     // No transformation required.
01441     break;
01442   case minusZ:  // y-axis up, x-axis to left?
01443     transform = G4RotateY3D(pi);
01444     break;
01445   }
01446   transform = G4Translate3D(sxmid,symid,szmid) * transform;
01447 
01448   G4VisAttributes visAtts(G4Colour(red, green, blue));
01449   visAtts.SetForceSolid(true);         // Always solid.
01450 
01451   G4Logo* logo = new G4Logo(height,visAtts);
01452   G4VModel* model =
01453     new G4CallbackModel<G4VisCommandSceneAddLogo::G4Logo>(logo);
01454   model->SetType("G4Logo");
01455   model->SetGlobalTag("G4Logo");
01456   model->SetGlobalDescription("G4Logo: " + newValue);
01457   model->SetTransformation(transform);
01458   // Note: it is the responsibility of the model to act upon this, but
01459   // the extent is in local coordinates...
01460   G4double& h = height;
01461   G4double h2 = h/2.;
01462   G4VisExtent extent(-h,h,-h2,h2,-h2,h2);
01463   model->SetExtent(extent);
01464   // This extent gets "added" to existing scene extent in
01465   // AddRunDurationModel below.
01466   const G4String& currentSceneName = pScene -> GetName ();
01467   G4bool successful = pScene -> AddRunDurationModel (model, warn);
01468   if (successful) {
01469     if (verbosity >= G4VisManager::confirmations) {
01470       G4cout << "G4 Logo of height " << userHeight << ' ' << userHeightUnit
01471              << ", " << direction << "-direction, added to scene \""
01472              << currentSceneName << "\"";
01473       if (verbosity >= G4VisManager::parameters) {
01474         G4cout << "\n  with extent " << extent
01475                << "\n  at " << transform.getRotation()
01476                << transform.getTranslation();
01477       }
01478       G4cout << G4endl;
01479     }
01480   }
01481   else G4VisCommandsSceneAddUnsuccessful(verbosity);
01482   UpdateVisManagerScene (currentSceneName);
01483 }
01484 
01485 G4VisCommandSceneAddLogo::G4Logo::G4Logo
01486 (G4double height, const G4VisAttributes& visAtts):
01487   fHeight(height),
01488   fVisAtts(visAtts)
01489  {
01490   const G4double& h =  height;
01491   const G4double h2  = 0.5 * h;   // Half height.
01492   const G4double ri  = 0.25 * h;  // Inner radius.
01493   const G4double ro  = 0.5 * h;   // Outer radius.
01494   const G4double ro2 = 0.5 * ro;  // Half outer radius.
01495   const G4double w   = ro - ri;   // Width.
01496   const G4double w2  = 0.5 * w;   // Half width.
01497   const G4double d2  = 0.2 * h;   // Half depth.
01498   const G4double f1  = 0.05 * h;  // left edge of stem of "4".
01499   const G4double f2  = -0.3 * h;  // bottom edge of cross of "4".
01500   const G4double e = 1.e-4 * h;   // epsilon.
01501   const G4double xt = f1, yt = h2;      // Top of slope.
01502   const G4double xb = -h2, yb = f2 + w; // Bottom of slope.
01503   const G4double dx = xt - xb, dy = yt - yb;
01504   const G4double angle = std::atan2(dy,dx);
01505   G4RotationMatrix rm;
01506   rm.rotateZ(angle*rad);
01507   const G4double d = std::sqrt(dx * dx + dy * dy);
01508   const G4double ss = h;  // Half height of square subtractor
01509   const G4double y8 = ss; // Choose y of subtractor for outer slope.
01510   const G4double x8 = ((-ss * d - dx * (yt - y8)) / dy) + xt;
01511   G4double y9 = ss; // Choose y of subtractor for inner slope.
01512   G4double x9 = ((-(ss - w) * d - dx * (yt - y8)) / dy) + xt;
01513   // But to get inner, we make a triangle translated by...
01514   const G4double xtr = ss - f1, ytr = -ss - f2 -w;
01515   x9 += xtr; y9 += ytr;
01516 
01517   // G...
01518   G4Tubs tG("tG",ri,ro,d2,0.15*pi,1.85*pi);
01519   G4Box bG("bG",w2,ro2,d2);
01520   G4UnionSolid logoG("logoG",&tG,&bG,G4Translate3D(ri+w2,-ro2,0.));
01521   fpG = logoG.CreatePolyhedron();
01522   fpG->SetVisAttributes(&fVisAtts);
01523   fpG->Transform(G4Translate3D(-0.55*h,0.,0.));
01524 
01525   // 4...
01526   G4Box b1("b1",h2,h2,d2);
01527   G4Box bS("bS",ss,ss,d2+e);  // Subtractor.
01528   G4Box bS2("bS2",ss,ss,d2+2.*e);  // 2nd Subtractor.
01529   G4SubtractionSolid s1("s1",&b1,&bS,G4Translate3D(f1-ss,f2-ss,0.));
01530   G4SubtractionSolid s2("s2",&s1,&bS,G4Translate3D(f1+ss+w,f2-ss,0.));
01531   G4SubtractionSolid s3("s3",&s2,&bS,G4Translate3D(f1+ss+w,f2+ss+w,0.));
01532   G4SubtractionSolid s4
01533     ("s4",&s3,&bS,G4Transform3D(rm,G4ThreeVector(x8,y8,0.)));
01534   G4SubtractionSolid s5    // Triangular hole.
01535     ("s5",&bS,&bS2,G4Transform3D(rm,G4ThreeVector(x9,y9,0.)));
01536   G4SubtractionSolid logo4("logo4",&s4,&s5,G4Translate3D(-xtr,-ytr,0.));
01537   fp4 = logo4.CreatePolyhedron();
01538   /* Experiment with creating own polyhedron...
01539   int nNodes = 4;
01540   int nFaces = 4;
01541   double xyz[][3] = {{0,0,0},{1*m,0,0},{0,1*m,0},{0,0,1*m}};
01542   int faces[][4] = {{1,3,2,0},{1,2,4,0},{1,4,3,0},{2,3,4,0}};
01543   fp4 = new G4Polyhedron();
01544   fp4->createPolyhedron(nNodes,nFaces,xyz,faces);
01545   */
01546   fp4->SetVisAttributes(&fVisAtts);
01547   fp4->Transform(G4Translate3D(0.55*h,0.,0.));
01548 }
01549 
01550 G4VisCommandSceneAddLogo::G4Logo::~G4Logo() {
01551   delete fpG;
01552   delete fp4;
01553 }
01554 
01555 void G4VisCommandSceneAddLogo::G4Logo::operator()
01556   (G4VGraphicsScene& sceneHandler, const G4Transform3D& transform) {
01557   sceneHandler.BeginPrimitives(transform);
01558   sceneHandler.AddPrimitive(*fpG);
01559   sceneHandler.AddPrimitive(*fp4);
01560   sceneHandler.EndPrimitives();
01561 }
01562 
01564 
01565 G4VisCommandSceneAddLogo2D::G4VisCommandSceneAddLogo2D () {
01566   G4bool omitable;
01567   fpCommand = new G4UIcommand ("/vis/scene/add/logo2D", this);
01568   fpCommand -> SetGuidance ("Adds 2D logo to current scene.");
01569   G4UIparameter* parameter;
01570   parameter = new G4UIparameter ("size", 'i', omitable = true);
01571   parameter -> SetGuidance ("Screen size of text in pixels.");
01572   parameter -> SetDefaultValue (48);
01573   fpCommand -> SetParameter (parameter);
01574   parameter = new G4UIparameter ("x-position", 'd', omitable = true);
01575   parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
01576   parameter -> SetDefaultValue (-0.9);
01577   fpCommand -> SetParameter (parameter);
01578   parameter = new G4UIparameter ("y-position", 'd', omitable = true);
01579   parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
01580   parameter -> SetDefaultValue (-0.9);
01581   fpCommand -> SetParameter (parameter);
01582   parameter = new G4UIparameter ("layout", 's', omitable = true);
01583   parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
01584   parameter -> SetDefaultValue ("left");
01585   fpCommand -> SetParameter (parameter);
01586 }
01587 
01588 G4VisCommandSceneAddLogo2D::~G4VisCommandSceneAddLogo2D () {
01589   delete fpCommand;
01590 }
01591 
01592 G4String G4VisCommandSceneAddLogo2D::GetCurrentValue (G4UIcommand*) {
01593   return "";
01594 }
01595 
01596 void G4VisCommandSceneAddLogo2D::SetNewValue (G4UIcommand*, G4String newValue)
01597 {
01598   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01599   G4bool warn(verbosity >= G4VisManager::warnings);
01600 
01601   G4Scene* pScene = fpVisManager->GetCurrentScene();
01602   if (!pScene) {
01603     if (verbosity >= G4VisManager::errors) {
01604       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
01605     }
01606     return;
01607   }
01608 
01609   G4int size;
01610   G4double x, y;
01611   G4String layoutString;
01612   std::istringstream is(newValue);
01613   is >> size >> x >> y >> layoutString;
01614   G4Text::Layout layout = G4Text::right;
01615   if (layoutString(0) == 'l') layout = G4Text::left;
01616   else if (layoutString(0) == 'c') layout = G4Text::centre;
01617   else if (layoutString(0) == 'r') layout = G4Text::right;
01618 
01619   Logo2D* logo2D = new Logo2D(fpVisManager, size, x, y, layout);
01620   G4VModel* model =
01621     new G4CallbackModel<G4VisCommandSceneAddLogo2D::Logo2D>(logo2D);
01622   model->SetType("G4Logo2D");
01623   model->SetGlobalTag("G4Logo2D");
01624   model->SetGlobalDescription("G4Logo2D: " + newValue);
01625   const G4String& currentSceneName = pScene -> GetName ();
01626   G4bool successful = pScene -> AddRunDurationModel (model, warn);
01627   if (successful) {
01628     if (verbosity >= G4VisManager::confirmations) {
01629       G4cout << "2D logo has been added to scene \""
01630              << currentSceneName << "\"."
01631              << G4endl;
01632     }
01633   }
01634   else G4VisCommandsSceneAddUnsuccessful(verbosity);
01635   UpdateVisManagerScene (currentSceneName);
01636 }
01637 
01638 void G4VisCommandSceneAddLogo2D::Logo2D::operator()
01639   (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
01640 {
01641   G4Text text("Geant4", G4Point3D(fX, fY, 0.));
01642   text.SetScreenSize(fSize);
01643   text.SetLayout(fLayout);
01644   G4VisAttributes textAtts(G4Colour::Brown());
01645   text.SetVisAttributes(textAtts);
01646   sceneHandler.BeginPrimitives2D();
01647   sceneHandler.AddPrimitive(text);
01648   sceneHandler.EndPrimitives2D();
01649 }
01650 
01652 
01653 G4VisCommandSceneAddPSHits::G4VisCommandSceneAddPSHits () {
01654   G4bool omitable;
01655   fpCommand = new G4UIcmdWithAString ("/vis/scene/add/psHits", this);
01656   fpCommand -> SetGuidance
01657     ("Adds Primitive Scorer Hits (PSHits) to current scene.");
01658   fpCommand -> SetGuidance
01659     ("PSHits are drawn at end of run when the scene in which"
01660      "\nthey are added is current.");
01661   fpCommand -> SetGuidance
01662     ("Optional parameter specifies name of scoring map.  By default all"
01663      "\nscoring maps registered with the G4ScoringManager are drawn.");
01664   fpCommand -> SetParameterName ("mapname", omitable = true);
01665   fpCommand -> SetDefaultValue ("all");
01666 }
01667 
01668 G4VisCommandSceneAddPSHits::~G4VisCommandSceneAddPSHits () {
01669   delete fpCommand;
01670 }
01671 
01672 G4String G4VisCommandSceneAddPSHits::GetCurrentValue (G4UIcommand*) {
01673   return "";
01674 }
01675 
01676 void G4VisCommandSceneAddPSHits::SetNewValue
01677 (G4UIcommand*, G4String newValue)
01678 {
01679   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01680   G4bool warn(verbosity >= G4VisManager::warnings);
01681 
01682   G4Scene* pScene = fpVisManager->GetCurrentScene();
01683   if (!pScene) {
01684     if (verbosity >= G4VisManager::errors) {
01685       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
01686     }
01687     return;
01688   }
01689 
01690   G4PSHitsModel* model = new G4PSHitsModel(newValue);
01691   const G4String& currentSceneName = pScene -> GetName ();
01692   G4bool successful = pScene -> AddEndOfRunModel (model, warn);
01693   if (successful) {
01694     if (verbosity >= G4VisManager::confirmations) {
01695       if (newValue == "all") {
01696         G4cout << "All Primitive Scorer hits";
01697       } else {
01698         G4cout << "Hits of Primitive Scorer \"" << newValue << '"';
01699       }
01700       G4cout << " will be drawn at end of run in scene \""
01701              << currentSceneName << "\"."
01702              << G4endl;
01703     }
01704   }
01705   else G4VisCommandsSceneAddUnsuccessful(verbosity);
01706   UpdateVisManagerScene (currentSceneName);
01707 }
01708 
01710 
01711 G4VisCommandSceneAddScale::G4VisCommandSceneAddScale () {
01712   G4bool omitable;
01713   fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
01714   fpCommand -> SetGuidance 
01715     ("Adds an annotated scale line to the current scene.");
01716   fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
01717   G4UIparameter* parameter;
01718   parameter = new G4UIparameter ("length", 'd', omitable = true);
01719   parameter->SetDefaultValue (1.);
01720   fpCommand->SetParameter (parameter);
01721   parameter =  new G4UIparameter ("unit", 's', omitable = true);
01722   parameter->SetGuidance
01723   ("auto or valid length unit - defaults to auto."
01724    "\nIf auto, length is roughly one tenth of the scene extent.");
01725   parameter->SetDefaultValue ("auto");
01726   fpCommand->SetParameter (parameter);
01727   parameter =  new G4UIparameter ("direction", 's', omitable = true);
01728   parameter->SetGuidance
01729   ("auto|x|y|z - defaults to auto."
01730    "\nIf auto, scale is roughly in the plane of the current view.");
01731   parameter->SetDefaultValue ("auto");
01732   fpCommand->SetParameter (parameter);
01733   parameter =  new G4UIparameter ("red", 'd', omitable = true);
01734   parameter->SetDefaultValue (1.);
01735   fpCommand->SetParameter (parameter);
01736   parameter =  new G4UIparameter ("green", 'd', omitable = true);
01737   parameter->SetDefaultValue (0.);
01738   fpCommand->SetParameter (parameter);
01739   parameter =  new G4UIparameter ("blue", 'd', omitable = true);
01740   parameter->SetDefaultValue (0.);
01741   fpCommand->SetParameter (parameter);
01742   parameter =  new G4UIparameter ("auto|manual", 's', omitable = true);
01743   parameter->SetGuidance
01744   ("Automatic placement or manual placement at (xmid,ymid,zmid)."
01745    "\nIf automatic, scale is placed at bottom left of current view.");
01746   parameter -> SetParameterCandidates("auto manual");
01747   parameter->SetDefaultValue  ("auto");
01748   fpCommand->SetParameter     (parameter);
01749   parameter =  new G4UIparameter ("xmid", 'd', omitable = true);
01750   parameter->SetDefaultValue (0.);
01751   fpCommand->SetParameter (parameter);
01752   parameter =  new G4UIparameter ("ymid", 'd', omitable = true);
01753   parameter->SetDefaultValue (0.);
01754   fpCommand->SetParameter (parameter);
01755   parameter =  new G4UIparameter ("zmid", 'd', omitable = true);
01756   parameter->SetDefaultValue (0.);
01757   fpCommand->SetParameter (parameter);
01758   parameter =  new G4UIparameter ("unit", 's', omitable = true);
01759   parameter->SetDefaultValue ("m");
01760   fpCommand->SetParameter (parameter);
01761 }
01762 
01763 G4VisCommandSceneAddScale::~G4VisCommandSceneAddScale () {
01764   delete fpCommand;
01765 }
01766 
01767 G4String G4VisCommandSceneAddScale::GetCurrentValue (G4UIcommand*) {
01768   return "";
01769 }
01770 
01771 void G4VisCommandSceneAddScale::SetNewValue (G4UIcommand*, G4String newValue) {
01772 
01773   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
01774   G4bool warn = verbosity >= G4VisManager::warnings;
01775 
01776   G4Scene* pScene = fpVisManager->GetCurrentScene();
01777   if (!pScene) {
01778     if (verbosity >= G4VisManager::errors) {
01779       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
01780     }
01781     return;
01782   }
01783 
01784   G4double userLength, red, green, blue, xmid, ymid, zmid;
01785   G4String userLengthUnit, direction, auto_manual, positionUnit;
01786   std::istringstream is (newValue);
01787   is >> userLength >> userLengthUnit >> direction
01788      >> red >> green >> blue
01789      >> auto_manual
01790      >> xmid >> ymid >> zmid >> positionUnit;
01791 
01792   G4double length = userLength;
01793   const G4VisExtent& sceneExtent = pScene->GetExtent();  // Existing extent.
01794   if (userLengthUnit == "auto") {
01795     length *= sceneExtent.GetExtentRadius();
01796     G4double intLog10Length = std::floor(std::log10(length));
01797     length = std::pow(10,intLog10Length);
01798   } else {
01799     length *= G4UIcommand::ValueOf(userLengthUnit);
01800   }
01801   G4String annotation = G4BestUnit(length,"Length");
01802 
01803   G4double unit = G4UIcommand::ValueOf(positionUnit);
01804   xmid *= unit; ymid *= unit; zmid *= unit;
01805 
01806   G4Scale::Direction scaleDirection (G4Scale::x);
01807   if (direction(0) == 'y') scaleDirection = G4Scale::y;
01808   if (direction(0) == 'z') scaleDirection = G4Scale::z;
01809 
01810   G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
01811   if (!pViewer) {
01812     if (verbosity >= G4VisManager::errors) {
01813       G4cout << 
01814         "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
01815         "\n  Auto direction needs a viewer."
01816              << G4endl;
01817     }
01818     return;
01819   }
01820 
01821   const G4Vector3D& vp =
01822     pViewer->GetViewParameters().GetViewpointDirection();
01823   const G4Vector3D& up =
01824     pViewer->GetViewParameters().GetUpVector();
01825 
01826   if (direction == "auto") {  // Takes cue from viewer.
01827     if (std::abs(vp.x()) > std::abs(vp.y()) &&
01828         std::abs(vp.x()) > std::abs(vp.z())) {  // x viewpoint
01829       if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = G4Scale::z;
01830           else scaleDirection = G4Scale::y;
01831     }
01832     else if (std::abs(vp.y()) > std::abs(vp.x()) &&
01833              std::abs(vp.y()) > std::abs(vp.z())) {  // y viewpoint
01834       if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = G4Scale::z;
01835           else scaleDirection = G4Scale::x;
01836     }
01837     else if (std::abs(vp.z()) > std::abs(vp.x()) &&
01838              std::abs(vp.z()) > std::abs(vp.y())) {  // z viewpoint
01839       if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = G4Scale::x;
01840           else scaleDirection = G4Scale::y;
01841     }
01842   }
01843 
01844   G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
01845   // Parameters read and interpreted.
01846 
01847   // Useful constants, etc...
01848   const G4double halfLength(length / 2.);
01849   const G4double comfort(0.01);  // 0.15 seems too big.  0.05 might be better.
01850   const G4double freeLengthFraction (1. + 2. * comfort);
01851 
01852   const G4double xmin = sceneExtent.GetXmin();
01853   const G4double xmax = sceneExtent.GetXmax();
01854   const G4double ymin = sceneExtent.GetYmin();
01855   const G4double ymax = sceneExtent.GetYmax();
01856   const G4double zmin = sceneExtent.GetZmin();
01857   const G4double zmax = sceneExtent.GetZmax();
01858 
01859   // Test existing extent and issue warnings...
01860   G4bool worried = false;
01861   if (sceneExtent.GetExtentRadius() == 0) {
01862     worried = true;
01863     if (verbosity >= G4VisManager::warnings) {
01864       G4cout <<
01865         "WARNING: Existing scene does not yet have any extent."
01866         "\n  Maybe you have not yet added any geometrical object."
01867              << G4endl;
01868     }
01869   }
01870   // Test existing scene for room...
01871   G4bool room  = true;
01872   switch (scaleDirection) {
01873   case G4Scale::x:
01874     if (freeLengthFraction * (xmax - xmin) < length) room = false; break;
01875   case G4Scale::y:
01876     if (freeLengthFraction * (ymax - ymin) < length) room = false; break;
01877   case G4Scale::z:
01878     if (freeLengthFraction * (zmax - zmin) < length) room = false; break;
01879   }
01880   if (!room) {
01881     worried = true;
01882     if (verbosity >= G4VisManager::warnings) {
01883       G4cout <<
01884         "WARNING: Not enough room in existing scene.  Maybe scale is too long."
01885              << G4endl;
01886     }
01887   }
01888   if (worried) {
01889     if (verbosity >= G4VisManager::warnings) {
01890       G4cout <<
01891         "WARNING: The scale you have asked for is bigger than the existing"
01892         "\n  scene.  Maybe you have added it too soon.  It is recommended that"
01893         "\n  you add the scale last so that it can be correctly auto-positioned"
01894         "\n  so as not to be obscured by any existing object and so that the"
01895         "\n  view parameters can be correctly recalculated."
01896              << G4endl;
01897     }
01898   }
01899 
01900   // Let's go ahead a construct a scale and a scale model.  Since the
01901   // placing is done here, this G4Scale is *not* auto-placed...
01902   G4Scale scale(length, annotation, scaleDirection,
01903                 false, xmid, ymid, zmid);
01904   G4VisAttributes* pVisAttr = new G4VisAttributes(G4Colour(red, green, blue));
01905   // Created of the heap because it needs a long lifetime.  This is a
01906   // mess.  The model determines the life but the vis atttributes are
01907   // associated with the scale.  There's no way of knowing when to
01908   // delete the vis atttributes!!!
01909   scale.SetVisAttributes(pVisAttr);
01910   G4VModel* model = new G4ScaleModel(scale);
01911 
01912   // Now figure out the extent...
01913   //
01914   // From the G4Scale.hh:
01915   //
01916   // This creates a representation of annotated line in the specified
01917   // direction with tick marks at the end.  If autoPlacing is true it
01918   // is required to be centred at the front, right, bottom corner of
01919   // the world space, comfortably outside the existing bounding
01920   // box/sphere so that existing objects do not obscure it.  Otherwise
01921   // it is required to be drawn with mid-point at (xmid, ymid, zmid).
01922   //
01923   // The auto placing algorithm might be:
01924   //   x = xmin + (1 + comfort) * (xmax - xmin)
01925   //   y = ymin - comfort * (ymax - ymin)
01926   //   z = zmin + (1 + comfort) * (zmax - zmin)
01927   //   if direction == x then (x - length,y,z) to (x,y,z)
01928   //   if direction == y then (x,y,z) to (x,y + length,z)
01929   //   if direction == z then (x,y,z - length) to (x,y,z)
01930   //
01931   // End of clip from G4Scale.hh:
01932   //
01933   // Implement this in two parts.  Here, use the scale's extent to
01934   // "expand" the scene's extent.  Then rendering - in
01935   // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
01936   // ensure it's within the new extent.
01937   //
01938 
01939   G4double sxmid(xmid), symid(ymid), szmid(zmid);
01940   if (autoPlacing) {
01941     // Aim to place at bottom right of screen in current view.
01942     // Give some comfort zone.
01943     const G4double xComfort = comfort * (xmax - xmin);
01944     const G4double yComfort = comfort * (ymax - ymin);
01945     const G4double zComfort = comfort * (zmax - zmin);
01946     switch (scaleDirection) {
01947     case G4Scale::x:
01948       if (vp.z() > 0.) {
01949         sxmid = xmax + xComfort;
01950         symid = ymin - yComfort;
01951         szmid = zmin - zComfort;
01952       } else {
01953         sxmid = xmin - xComfort;
01954         symid = ymin - yComfort;
01955         szmid = zmax + zComfort;
01956       }
01957       break;
01958     case G4Scale::y:
01959       if (vp.x() > 0.) {
01960         sxmid = xmin - xComfort;
01961         symid = ymax + yComfort;
01962         szmid = zmin - zComfort;
01963       } else {
01964         sxmid = xmax + xComfort;
01965         symid = ymin - yComfort;
01966         szmid = zmin - zComfort;
01967       }
01968       break;
01969     case G4Scale::z:
01970       if (vp.x() > 0.) {
01971         sxmid = xmax + xComfort;
01972         symid = ymin - yComfort;
01973         szmid = zmax + zComfort;
01974       } else {
01975         sxmid = xmin - xComfort;
01976         symid = ymin - yComfort;
01977         szmid = zmax + zComfort;
01978       }
01979       break;
01980     }
01981   }
01982 
01983   /* Old code - kept for future reference.
01984   G4double sxmid(xmid), symid(ymid), szmid(zmid);
01985   if (autoPlacing) {
01986     sxmid = xmin + onePlusComfort * (xmax - xmin);
01987     symid = ymin - comfort * (ymax - ymin);
01988     szmid = zmin + onePlusComfort * (zmax - zmin);
01989     switch (scaleDirection) {
01990     case G4Scale::x:
01991       sxmid -= halfLength;
01992       break;
01993     case G4Scale::y:
01994       symid += halfLength;
01995       break;
01996     case G4Scale::z:
01997       szmid -= halfLength;
01998       break;
01999     }
02000   }
02001   */
02002 
02003   /* sxmin, etc., not actually used.  Comment out to prevent compiler
02004      warnings but keep in case need in future.  Extract transform and
02005      scaleExtent into reduced code below.
02006   G4double sxmin(sxmid), sxmax(sxmid);
02007   G4double symin(symid), symax(symid);
02008   G4double szmin(szmid), szmax(szmid);
02009   G4Transform3D transform;
02010   G4VisExtent scaleExtent;
02011   switch (scaleDirection) {
02012   case G4Scale::x:
02013     sxmin = sxmid - halfLength;
02014     sxmax = sxmid + halfLength;
02015     scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
02016     break;
02017   case G4Scale::y:
02018     symin = symid - halfLength;
02019     symax = symid + halfLength;
02020     transform = G4RotateZ3D(halfpi);
02021     scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
02022     break;
02023   case G4Scale::z:
02024     szmin = szmid - halfLength;
02025     szmax = szmid + halfLength;
02026     transform = G4RotateY3D(halfpi);
02027     scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
02028     break;
02029   }
02030   */
02031   G4Transform3D transform;
02032   G4VisExtent scaleExtent;
02033   switch (scaleDirection) {
02034   case G4Scale::x:
02035     scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
02036     break;
02037   case G4Scale::y:
02038     transform = G4RotateZ3D(halfpi);
02039     scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
02040     break;
02041   case G4Scale::z:
02042     transform = G4RotateY3D(halfpi);
02043     scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
02044     break;
02045   }
02046   transform = G4Translate3D(sxmid,symid,szmid) * transform;
02048 
02049 
02050   model->SetTransformation(transform);
02051   // Note: it is the responsibility of the model to act upon this, but
02052   // the extent is in local coordinates...
02053   model->SetExtent(scaleExtent);
02054   // This extent gets "added" to existing scene extent in
02055   // AddRunDurationModel below.
02056 
02057   const G4String& currentSceneName = pScene -> GetName ();
02058   G4bool successful = pScene -> AddRunDurationModel (model, warn);
02059   if (successful) {
02060     if (verbosity >= G4VisManager::confirmations) {
02061       G4cout << "Scale of " << annotation
02062              << " added to scene \"" << currentSceneName << "\".";
02063       if (verbosity >= G4VisManager::parameters) {
02064         G4cout << "\n  with extent " << scaleExtent
02065                << "\n  at " << transform.getRotation()
02066                << transform.getTranslation();
02067       }
02068       G4cout << G4endl;
02069     }
02070   }
02071   else G4VisCommandsSceneAddUnsuccessful(verbosity);
02072   UpdateVisManagerScene (currentSceneName);
02073 }
02074 
02075 
02077 
02078 G4VisCommandSceneAddText::G4VisCommandSceneAddText () {
02079   G4bool omitable;
02080   fpCommand = new G4UIcommand ("/vis/scene/add/text", this);
02081   fpCommand -> SetGuidance ("Adds text to current scene.");
02082   fpCommand -> SetGuidance
02083     ("Use \"/vis/set/textColour\" to set colour.");
02084   fpCommand -> SetGuidance
02085     ("Use \"/vis/set/textLayout\" to set layout:");
02086   G4UIparameter* parameter;
02087   parameter = new G4UIparameter ("x", 'd', omitable = true);
02088   parameter->SetDefaultValue (0);
02089   parameter->SetGuidance ("x");
02090   fpCommand->SetParameter (parameter);
02091   parameter =  new G4UIparameter ("y", 'd', omitable = true);
02092   parameter->SetDefaultValue (0);
02093   parameter->SetGuidance ("y");
02094   fpCommand->SetParameter (parameter);
02095   parameter =  new G4UIparameter ("z", 'd', omitable = true);
02096   parameter->SetDefaultValue (0);
02097   parameter->SetGuidance ("z");
02098   fpCommand->SetParameter (parameter);
02099   parameter =  new G4UIparameter ("unit", 's', omitable = true);
02100   parameter->SetDefaultValue ("m");
02101   fpCommand->SetParameter     (parameter);
02102   parameter =  new G4UIparameter ("font_size", 'd', omitable = true);
02103   parameter->SetDefaultValue (12);
02104   parameter->SetGuidance ("pixels");
02105   fpCommand->SetParameter (parameter);
02106   parameter =  new G4UIparameter ("x_offset", 'd', omitable = true);
02107   parameter->SetDefaultValue (0);
02108   parameter->SetGuidance ("pixels");
02109   fpCommand->SetParameter (parameter);
02110   parameter =  new G4UIparameter ("y_offset", 'd', omitable = true);
02111   parameter->SetDefaultValue (0);
02112   parameter->SetGuidance ("pixels");
02113   fpCommand->SetParameter (parameter);
02114   parameter =  new G4UIparameter ("text", 's', omitable = true);
02115   parameter->SetGuidance ("The rest of the line is text.");
02116   parameter->SetDefaultValue ("Hello G4");
02117   fpCommand->SetParameter (parameter);
02118 }
02119 
02120 G4VisCommandSceneAddText::~G4VisCommandSceneAddText () {
02121   delete fpCommand;
02122 }
02123 
02124 G4String G4VisCommandSceneAddText::GetCurrentValue (G4UIcommand*) {
02125   return "";
02126 }
02127 
02128 void G4VisCommandSceneAddText::SetNewValue (G4UIcommand*, G4String newValue) {
02129 
02130   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
02131   G4bool warn = verbosity >= G4VisManager::warnings;
02132 
02133   G4Scene* pScene = fpVisManager->GetCurrentScene();
02134   if (!pScene) {
02135     if (verbosity >= G4VisManager::errors) {
02136       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
02137     }
02138     return;
02139   }
02140 
02141   G4Tokenizer next(newValue);
02142   G4double x = StoD(next());
02143   G4double y = StoD(next());
02144   G4double z = StoD(next());
02145   G4String unitString = next();
02146   G4double font_size = StoD(next());
02147   G4double x_offset = StoD(next());
02148   G4double y_offset = StoD(next());
02149   G4String text = next("\n");
02150 
02151   G4double unit = G4UIcommand::ValueOf(unitString);
02152   x *= unit; y *= unit; z *= unit;
02153 
02154   G4Text g4text(text, G4Point3D(x,y,z));
02155   G4VisAttributes visAtts(fCurrentTextColour);
02156   g4text.SetVisAttributes(visAtts);
02157   g4text.SetLayout(fCurrentTextLayout);
02158   g4text.SetScreenSize(font_size);
02159   g4text.SetOffset(x_offset,y_offset);
02160   G4VModel* model = new G4TextModel(g4text);
02161   const G4String& currentSceneName = pScene -> GetName ();
02162   G4bool successful = pScene -> AddRunDurationModel (model, warn);
02163   if (successful) {
02164     if (verbosity >= G4VisManager::confirmations) {
02165       G4cout << "Text \"" << text
02166              << "\" has been added to scene \"" << currentSceneName << "\"."
02167              << G4endl;
02168     }
02169   }
02170   else G4VisCommandsSceneAddUnsuccessful(verbosity);
02171   UpdateVisManagerScene (currentSceneName);
02172 }
02173 
02174 
02176 
02177 G4VisCommandSceneAddText2D::G4VisCommandSceneAddText2D () {
02178   G4bool omitable;
02179   fpCommand = new G4UIcommand ("/vis/scene/add/text2D", this);
02180   fpCommand -> SetGuidance ("Adds 2D text to current scene.");
02181   fpCommand -> SetGuidance
02182     ("Use \"/vis/set/textColour\" to set colour.");
02183   fpCommand -> SetGuidance
02184     ("Use \"/vis/set/textLayout\" to set layout:");
02185   G4UIparameter* parameter;
02186   parameter = new G4UIparameter ("x", 'd', omitable = true);
02187   parameter->SetDefaultValue (0);
02188   parameter->SetGuidance ("x");
02189   fpCommand->SetParameter (parameter);
02190   parameter =  new G4UIparameter ("y", 'd', omitable = true);
02191   parameter->SetDefaultValue (0);
02192   parameter->SetGuidance ("y");
02193   fpCommand->SetParameter (parameter);
02194   parameter =  new G4UIparameter ("font_size", 'd', omitable = true);
02195   parameter->SetDefaultValue (12);
02196   parameter->SetGuidance ("pixels");
02197   fpCommand->SetParameter (parameter);
02198   parameter =  new G4UIparameter ("x_offset", 'd', omitable = true);
02199   parameter->SetDefaultValue (0);
02200   parameter->SetGuidance ("pixels");
02201   fpCommand->SetParameter (parameter);
02202   parameter =  new G4UIparameter ("y_offset", 'd', omitable = true);
02203   parameter->SetDefaultValue (0);
02204   parameter->SetGuidance ("pixels");
02205   fpCommand->SetParameter (parameter);
02206   parameter =  new G4UIparameter ("text", 's', omitable = true);
02207   parameter->SetGuidance ("The rest of the line is text.");
02208   parameter->SetDefaultValue ("Hello G4");
02209   fpCommand->SetParameter (parameter);
02210 }
02211 
02212 G4VisCommandSceneAddText2D::~G4VisCommandSceneAddText2D () {
02213   delete fpCommand;
02214 }
02215 
02216 G4String G4VisCommandSceneAddText2D::GetCurrentValue (G4UIcommand*) {
02217   return "";
02218 }
02219 
02220 void G4VisCommandSceneAddText2D::SetNewValue (G4UIcommand*, G4String newValue) {
02221 
02222   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
02223   G4bool warn = verbosity >= G4VisManager::warnings;
02224 
02225   G4Scene* pScene = fpVisManager->GetCurrentScene();
02226   if (!pScene) {
02227     if (verbosity >= G4VisManager::errors) {
02228       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
02229     }
02230     return;
02231   }
02232 
02233   G4Tokenizer next(newValue);
02234   G4double x = StoD(next());
02235   G4double y = StoD(next());
02236   G4double font_size = StoD(next());
02237   G4double x_offset = StoD(next());
02238   G4double y_offset = StoD(next());
02239   G4String text = next("\n");
02240 
02241   G4Text g4text(text, G4Point3D(x,y,0.));
02242   G4VisAttributes visAtts(fCurrentTextColour);
02243   g4text.SetVisAttributes(visAtts);
02244   g4text.SetLayout(fCurrentTextLayout);
02245   g4text.SetScreenSize(font_size);
02246   g4text.SetOffset(x_offset,y_offset);
02247   G4Text2D* g4text2D = new G4Text2D(g4text);
02248   G4VModel* model =
02249     new G4CallbackModel<G4VisCommandSceneAddText2D::G4Text2D>(g4text2D);
02250   model->SetType("Text2D");
02251   model->SetGlobalTag("Text2D");
02252   model->SetGlobalDescription("Text2D: " + newValue);
02253   const G4String& currentSceneName = pScene -> GetName ();
02254   G4bool successful = pScene -> AddRunDurationModel (model, warn);
02255   if (successful) {
02256     if (verbosity >= G4VisManager::confirmations) {
02257       G4cout << "2D text \"" << text
02258              << "\" has been added to scene \"" << currentSceneName << "\"."
02259              << G4endl;
02260     }
02261   }
02262   else G4VisCommandsSceneAddUnsuccessful(verbosity);
02263   UpdateVisManagerScene (currentSceneName);
02264 }
02265 
02266 G4VisCommandSceneAddText2D::G4Text2D::G4Text2D(const G4Text& text):
02267   fText(text)
02268 {}
02269 
02270 void G4VisCommandSceneAddText2D::G4Text2D::operator()
02271   (G4VGraphicsScene& sceneHandler, const G4Transform3D& transform) {
02272   sceneHandler.BeginPrimitives2D(transform);
02273   sceneHandler.AddPrimitive(fText);
02274   sceneHandler.EndPrimitives2D();
02275 }
02276 
02277 
02279 
02280 G4VisCommandSceneAddTrajectories::G4VisCommandSceneAddTrajectories () {
02281   G4bool omitable;
02282   fpCommand = new G4UIcmdWithAString
02283     ("/vis/scene/add/trajectories", this);
02284   fpCommand -> SetGuidance
02285     ("Adds trajectories to current scene.");
02286   fpCommand -> SetGuidance
02287     ("Causes trajectories, if any, to be drawn at the end of processing an"
02288      "\nevent.  Switches on trajectory storing and sets the"
02289      "\ndefault trajectory type.");
02290   fpCommand -> SetGuidance
02291     ("The command line parameter list determines the default trajectory type."
02292      "\nIf it contains the string \"smooth\", auxiliary inter-step points will"
02293      "\nbe inserted to improve the smoothness of the drawing of a curved"
02294      "\ntrajectory."
02295      "\nIf it contains the string \"rich\", significant extra information will"
02296      "\nbe stored in the trajectory (G4RichTrajectory) amenable to modeling"
02297      "\nand filtering with \"/vis/modeling/trajectories/create/drawByAttribute\""
02298      "\nand \"/vis/filtering/trajectories/create/attributeFilter\" commands."
02299      "\nIt may contain both strings in any order.");
02300   fpCommand -> SetGuidance
02301     ("\nTo switch off trajectory storing: \"/tracking/storeTrajectory 0\"."
02302      "\nSee also \"/vis/scene/endOfEventAction\".");
02303   fpCommand -> SetGuidance
02304     ("Note:  This only sets the default.  Independently of the result of this"
02305      "\ncommand, a user may instantiate a trajectory that overrides this default"
02306      "\nin PreUserTrackingAction.");
02307   fpCommand -> SetParameterName ("default-trajectory-type", omitable = true);
02308   fpCommand -> SetDefaultValue ("");
02309 }
02310 
02311 G4VisCommandSceneAddTrajectories::~G4VisCommandSceneAddTrajectories () {
02312   delete fpCommand;
02313 }
02314 
02315 G4String G4VisCommandSceneAddTrajectories::GetCurrentValue (G4UIcommand*) {
02316   return "";
02317 }
02318 
02319 void G4VisCommandSceneAddTrajectories::SetNewValue (G4UIcommand*,
02320                                                     G4String newValue) {
02321 
02322   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
02323   G4bool warn = verbosity >= G4VisManager::warnings;
02324 
02325   G4Scene* pScene = fpVisManager->GetCurrentScene();
02326   if (!pScene) {
02327     if (verbosity >= G4VisManager::errors) {
02328       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
02329     }
02330     return;
02331   }
02332 
02333   G4bool smooth = false, rich = false;
02334   if (newValue.find("smooth") != std::string::npos) smooth = true;
02335   if (newValue.find("rich") != std::string::npos) rich = true;
02336 
02337   G4UImanager* UImanager = G4UImanager::GetUIpointer();
02338   G4int keepVerbose = UImanager->GetVerboseLevel();
02339   G4int newVerbose = 2;
02340   UImanager->SetVerboseLevel(newVerbose);
02341   G4PropagatorInField* propagatorInField =
02342     G4TransportationManager::GetTransportationManager()->
02343     GetPropagatorInField();
02344   propagatorInField->SetTrajectoryFilter(0); // Switch off smooth trajectories.
02345   static G4IdentityTrajectoryFilter auxiliaryPointsFilter;
02346   G4String defaultTrajectoryType;
02347   G4bool i_mode_found = false;
02348   G4int i_mode = 0;
02349   if (smooth && rich) {
02350     UImanager->ApplyCommand("/tracking/storeTrajectory 3");
02351     propagatorInField->SetTrajectoryFilter(&auxiliaryPointsFilter);
02352     defaultTrajectoryType = "G4RichTrajectory configured for smooth steps";
02353   } else if (smooth) {
02354     UImanager->ApplyCommand("/tracking/storeTrajectory 2");
02355     propagatorInField->SetTrajectoryFilter(&auxiliaryPointsFilter);
02356     defaultTrajectoryType = "G4SmoothTrajectory";
02357   } else if (rich) {
02358     UImanager->ApplyCommand("/tracking/storeTrajectory 3");
02359     defaultTrajectoryType = "G4RichTrajectory";
02360   } else {
02361     if (!newValue.empty()) {
02362       std::istringstream iss(newValue);
02363       iss >> i_mode;
02364       if (iss) {
02365         i_mode_found = true;
02366         if (verbosity >= G4VisManager::warnings) {
02367           G4cout <<
02368   "WARNING: Integer parameter " << i_mode << " found."
02369   "\n  DEPRECATED - its use in this command will be removed at a future major"
02370   "\n  release.  Use \"/vis/modeling/trajectories\" commands."
02371                  << G4endl;
02372         }
02373       } else {
02374         if (verbosity >= G4VisManager::errors) {
02375           G4cout << "ERROR: Unrecognised parameter \"" << newValue << "\""
02376             "\n  No action taken."
02377                  << G4endl;
02378         }
02379         return;
02380       }
02381     }
02382     UImanager->ApplyCommand("/tracking/storeTrajectory 1");
02383     defaultTrajectoryType = "G4Trajectory";
02384   }
02385   UImanager->SetVerboseLevel(keepVerbose);
02386 
02387   if (verbosity >= G4VisManager::errors) {
02388     G4cout <<
02389       "Attributes available for modeling and filtering with"
02390       "\n  \"/vis/modeling/trajectories/create/drawByAttribute\" and"
02391       "\n  \"/vis/filtering/trajectories/create/attributeFilter\" commands:"
02392            << G4endl;
02393     G4cout << G4TrajectoriesModel().GetAttDefs();
02394     if (rich) {
02395       G4cout << G4RichTrajectory().GetAttDefs()
02396              << G4RichTrajectoryPoint().GetAttDefs();
02397     } else if (smooth) {
02398       G4cout << G4SmoothTrajectory().GetAttDefs()
02399              << G4SmoothTrajectoryPoint().GetAttDefs();
02400     } else {
02401       G4cout << G4Trajectory().GetAttDefs()
02402              << G4TrajectoryPoint().GetAttDefs();
02403     }
02404   }
02405 
02406   G4TrajectoriesModel* model = 0;
02407   if (i_mode_found) {
02408     model = new G4TrajectoriesModel(i_mode);
02409   } else {
02410     model = new G4TrajectoriesModel();
02411   }
02412   const G4String& currentSceneName = pScene -> GetName ();
02413   pScene -> AddEndOfEventModel (model, warn);
02414 
02415   if (verbosity >= G4VisManager::confirmations) {
02416     G4cout << "Default trajectory type " << defaultTrajectoryType
02417            << "\n  will be used to store trajectories for scene \""
02418            << currentSceneName << "\"."
02419            << G4endl;
02420   }
02421 
02422   if (verbosity >= G4VisManager::warnings) {
02423     G4cout <<
02424       "WARNING: Trajectory storing has been requested.  This action may be"
02425       "\n  reversed with \"/tracking/storeTrajectory 0\"."
02426            << G4endl;
02427   }
02428   UpdateVisManagerScene (currentSceneName);
02429 }
02430 
02432 
02433 G4VisCommandSceneAddUserAction::G4VisCommandSceneAddUserAction () {
02434   G4bool omitable;
02435   fpCommand = new G4UIcmdWithAString("/vis/scene/add/userAction",this);
02436   fpCommand -> SetGuidance
02437     ("Add named Vis User Action to current scene.");
02438   fpCommand -> SetGuidance
02439     ("Attempts to match search string to name of action - use unique sub-string.");
02440   fpCommand -> SetGuidance
02441     ("(Use /vis/list to see names of registered actions.)");
02442   fpCommand -> SetGuidance
02443     ("If name == \"all\" (default), all actions are added.");
02444   fpCommand -> SetParameterName("action-name", omitable = true);
02445   fpCommand -> SetDefaultValue("all");
02446 }
02447 
02448 G4VisCommandSceneAddUserAction::~G4VisCommandSceneAddUserAction () {
02449   delete fpCommand;
02450 }
02451 
02452 G4String G4VisCommandSceneAddUserAction::GetCurrentValue (G4UIcommand*) {
02453   return "";
02454 }
02455 
02456 void G4VisCommandSceneAddUserAction::SetNewValue
02457 (G4UIcommand*, G4String newValue) {
02458 
02459   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
02460 
02461   G4Scene* pScene = fpVisManager->GetCurrentScene();
02462   if (!pScene) {
02463     if (verbosity >= G4VisManager::errors) {
02464       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
02465     }
02466     return;
02467   }
02468 
02469   G4bool any = false;
02470 
02471   const std::vector<G4VisManager::UserVisAction>& runDurationUserVisActions =
02472     fpVisManager->GetRunDurationUserVisActions();
02473   for (size_t i = 0; i < runDurationUserVisActions.size(); i++) {
02474     const G4String& name = runDurationUserVisActions[i].fName;
02475     G4VUserVisAction* visAction = runDurationUserVisActions[i].fpUserVisAction;
02476     if (newValue == "all" || name.find(newValue) != std::string::npos) {
02477       any = true;
02478       AddVisAction(name,visAction,pScene,runDuration,verbosity);
02479     }
02480   }
02481 
02482   const std::vector<G4VisManager::UserVisAction>& endOfEventUserVisActions =
02483     fpVisManager->GetEndOfEventUserVisActions();
02484   for (size_t i = 0; i < endOfEventUserVisActions.size(); i++) {
02485     const G4String& name = endOfEventUserVisActions[i].fName;
02486     G4VUserVisAction* visAction = endOfEventUserVisActions[i].fpUserVisAction;
02487     if (newValue == "all" || name.find(newValue) != std::string::npos) {
02488       any = true;
02489       AddVisAction(name,visAction,pScene,endOfEvent,verbosity);
02490     }
02491   }
02492 
02493   const std::vector<G4VisManager::UserVisAction>& endOfRunUserVisActions =
02494     fpVisManager->GetEndOfRunUserVisActions();
02495   for (size_t i = 0; i < endOfRunUserVisActions.size(); i++) {
02496     const G4String& name = endOfRunUserVisActions[i].fName;
02497     G4VUserVisAction* visAction = endOfRunUserVisActions[i].fpUserVisAction;
02498     if (newValue == "all" || name.find(newValue) != std::string::npos) {
02499       any = true;
02500       AddVisAction(name,visAction,pScene,endOfRun,verbosity);
02501     }
02502   }
02503 
02504   if (!any) {
02505     if (verbosity >= G4VisManager::warnings) {
02506       G4cout << "WARNING: No User Vis Action registered." << G4endl;
02507     }
02508     return;
02509   }
02510 
02511   const G4String& currentSceneName = pScene -> GetName ();
02512   UpdateVisManagerScene (currentSceneName);
02513 }
02514 
02515 void G4VisCommandSceneAddUserAction::AddVisAction
02516 (const G4String& name,
02517  G4VUserVisAction* visAction,
02518  G4Scene* pScene,
02519  G4VisCommandSceneAddUserAction::ActionType type,
02520  G4VisManager::Verbosity verbosity)
02521 {
02522   G4bool warn = verbosity >= G4VisManager::warnings;
02523 
02524   const std::map<G4VUserVisAction*,G4VisExtent>& visExtentMap =
02525     fpVisManager->GetUserVisActionExtents();
02526   G4VisExtent extent;
02527   std::map<G4VUserVisAction*,G4VisExtent>::const_iterator i =
02528     visExtentMap.find(visAction);
02529   if (i != visExtentMap.end()) extent = i->second;
02530   if (warn) {
02531     if (extent.GetExtentRadius() <= 0.) {
02532       G4cout << "WARNING: User Vis Action extent is null." << G4endl;
02533     }
02534   }
02535 
02536   G4VModel* model = new G4CallbackModel<G4VUserVisAction>(visAction);
02537   model->SetType("User Vis Action");
02538   model->SetGlobalTag(name);
02539   model->SetGlobalDescription(name);
02540   model->SetExtent(extent);
02541   G4bool successful = false;;
02542   switch (type) {
02543   case runDuration:
02544     successful = pScene -> AddRunDurationModel (model, warn);
02545     break;
02546   case endOfEvent:
02547     successful = pScene -> AddEndOfEventModel (model, warn);
02548     break;
02549   case endOfRun:
02550     successful = pScene -> AddEndOfRunModel (model, warn);
02551     break;
02552   }
02553   if (successful && verbosity >= G4VisManager::confirmations) {
02554     const G4String& currentSceneName = pScene -> GetName ();
02555     G4cout << "User Vis Action added to scene \""
02556            << currentSceneName << "\"";
02557     if (verbosity >= G4VisManager::parameters) {
02558       G4cout << "\n  with extent " << extent;
02559     }
02560     G4cout << G4endl;
02561   }
02562 }
02563 
02565 
02566 G4VisCommandSceneAddVolume::G4VisCommandSceneAddVolume () {
02567   G4bool omitable;
02568   fpCommand = new G4UIcommand ("/vis/scene/add/volume", this);
02569   fpCommand -> SetGuidance 
02570    ("Adds a physical volume to current scene, with optional clipping volume.");
02571   fpCommand -> SetGuidance 
02572     ("If physical-volume-name is \"world\" (the default), the top of the"
02573      "\nmain geometry tree (material world) is added.  If \"worlds\", the"
02574      "\ntop of all worlds - material world and parallel worlds, if any - are"
02575      "\nadded.  Otherwise a search of all worlds is made, taking the first"
02576      "\nmatching occurence only.  To see a representation of the geometry"
02577      "\nhierarchy of the worlds, try \"/vis/drawTree [worlds]\" or one of the"
02578      "\ndriver/browser combinations that have the required functionality, e.g., HepRep.");
02579   fpCommand -> SetGuidance
02580     ("If clip-volume-type is specified, the subsequent parameters are used to"
02581      "\nto define a clipping volume.  For example,"
02582      "\n\"vis/scene/add/volume ! ! ! -box km 0 1 0 1 0 1\" will draw the world"
02583      "\nwith the positive octant cut away."); 
02584   fpCommand -> SetGuidance
02585     ("If clip-volume-type is prepended with '-', the clip-volume is subtracted"
02586      "\n(cutaway). (This is the default if there is no prepended character.)"
02587      "\nIf '*' is prepended, the intersection of the physical-volume and the"
02588      "\nclip-volume is made. (You can make a section/DCUT with a thin box, for"
02589      "\nexample).");
02590   fpCommand -> SetGuidance
02591     ("For \"box\", the parameters are xmin,xmax,ymin,ymax,zmin,zmax."
02592      "\nOnly \"box\" is programmed at present.");
02593   G4UIparameter* parameter;
02594   parameter = new G4UIparameter ("physical-volume-name", 's', omitable = true);
02595   parameter -> SetDefaultValue ("world");
02596   fpCommand -> SetParameter (parameter);
02597   parameter = new G4UIparameter ("copy-no", 'i', omitable = true);
02598   parameter -> SetGuidance
02599     ("If negative, matches any copy no.  First name match is taken.");
02600   parameter -> SetDefaultValue (-1);
02601   fpCommand -> SetParameter (parameter);
02602   parameter = new G4UIparameter ("depth-of-descent", 'i', omitable = true);
02603   parameter -> SetGuidance
02604     ("Depth of descent of geometry hierarchy. Default = unlimited depth.");
02605   parameter -> SetDefaultValue (G4Scene::UNLIMITED);
02606   fpCommand -> SetParameter (parameter);
02607   parameter = new G4UIparameter ("clip-volume-type", 's', omitable = true);
02608   parameter -> SetParameterCandidates("none box -box *box");
02609   parameter -> SetDefaultValue ("none");
02610   parameter -> SetGuidance("[-|*]type.  See general guidance.");
02611   fpCommand -> SetParameter (parameter);
02612   parameter = new G4UIparameter ("parameter-unit", 's', omitable = true);
02613   parameter -> SetDefaultValue ("m");
02614   fpCommand -> SetParameter (parameter);
02615   parameter = new G4UIparameter ("parameter-1", 'd', omitable = true);
02616   parameter -> SetDefaultValue (0.);
02617   fpCommand -> SetParameter (parameter);
02618   parameter = new G4UIparameter ("parameter-2", 'd', omitable = true);
02619   parameter -> SetDefaultValue (0.);
02620   fpCommand -> SetParameter (parameter);
02621   parameter = new G4UIparameter ("parameter-3", 'd', omitable = true);
02622   parameter -> SetDefaultValue (0.);
02623   fpCommand -> SetParameter (parameter);
02624   parameter = new G4UIparameter ("parameter-4", 'd', omitable = true);
02625   parameter -> SetDefaultValue (0.);
02626   fpCommand -> SetParameter (parameter);
02627   parameter = new G4UIparameter ("parameter-5", 'd', omitable = true);
02628   parameter -> SetDefaultValue (0.);
02629   fpCommand -> SetParameter (parameter);
02630   parameter = new G4UIparameter ("parameter-6", 'd', omitable = true);
02631   parameter -> SetDefaultValue (0.);
02632   fpCommand -> SetParameter (parameter);
02633 }
02634 
02635 G4VisCommandSceneAddVolume::~G4VisCommandSceneAddVolume () {
02636   delete fpCommand;
02637 }
02638 
02639 G4String G4VisCommandSceneAddVolume::GetCurrentValue (G4UIcommand*) {
02640   return "world 0 -1";
02641 }
02642 
02643 void G4VisCommandSceneAddVolume::SetNewValue (G4UIcommand*,
02644                                               G4String newValue) {
02645 
02646   G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
02647   G4bool warn = verbosity >= G4VisManager::warnings;
02648 
02649   G4Scene* pScene = fpVisManager->GetCurrentScene();
02650   if (!pScene) {
02651     if (verbosity >= G4VisManager::errors) {
02652       G4cout << "ERROR: No current scene.  Please create one." << G4endl;
02653     }
02654     return;
02655   }
02656 
02657   G4String name, clipVolumeType, parameterUnit;
02658   G4int copyNo, requestedDepthOfDescent;
02659   G4double param1, param2, param3, param4, param5, param6;
02660   std::istringstream is (newValue);
02661   is >> name >> copyNo >> requestedDepthOfDescent
02662      >> clipVolumeType >> parameterUnit
02663      >> param1 >> param2 >> param3 >> param4 >> param5 >> param6;
02664   G4PhysicalVolumeModel::ClippingMode clippingMode =
02665     G4PhysicalVolumeModel::subtraction;  // Default subtraction mode.
02666   if (clipVolumeType[size_t(0)] == '-') {
02667     clipVolumeType = clipVolumeType.substr(1);  // Remove first character.
02668   } else if (clipVolumeType[size_t(0)] == '*') {
02669     clippingMode = G4PhysicalVolumeModel::intersection;
02670     clipVolumeType = clipVolumeType.substr(1);
02671   }
02672   G4double unit = G4UIcommand::ValueOf(parameterUnit);
02673   param1 *= unit; param2 *= unit; param3 *= unit;
02674   param4 *= unit; param5 *= unit; param6 *= unit;
02675 
02676   G4TransportationManager* transportationManager =
02677     G4TransportationManager::GetTransportationManager ();
02678 
02679   size_t nWorlds = transportationManager->GetNoWorlds();
02680   if (nWorlds > 1) {  // Parallel worlds in operation...
02681     if (verbosity >= G4VisManager::warnings) {
02682       static G4bool warned = false;
02683       if (!warned && name != "worlds") {
02684         G4cout <<
02685           "WARNING: Parallel worlds in operation.  To visualise, specify"
02686           "\n  \"worlds\" or the parallel world volume or sub-volume name"
02687           "\n   and control visibility with /vis/geometry."
02688                << G4endl;
02689         std::vector<G4VPhysicalVolume*>::iterator iterWorld =
02690           transportationManager->GetWorldsIterator();
02691         for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
02692           G4cout << "  World " << i << ": " << (*iterWorld)->GetName()
02693                  << G4endl;
02694           warned = true;
02695         }
02696       }
02697     }
02698   }
02699 
02700   G4VPhysicalVolume* world = *(transportationManager->GetWorldsIterator());
02701 
02702   if (!world) {
02703     if (verbosity >= G4VisManager::errors) {
02704       G4cout <<
02705         "ERROR: G4VisCommandSceneAddVolume::SetNewValue:"
02706         "\n  No world.  Maybe the geometry has not yet been defined."
02707         "\n  Try \"/run/initialize\""
02708              << G4endl;
02709     }
02710     return;
02711   }
02712 
02713   const std::vector<G4Scene::Model>& rdModelList = pScene -> GetRunDurationModelList();
02714   std::vector<G4Scene::Model>::const_iterator it;
02715   for (it = rdModelList.begin(); it != rdModelList.end(); ++it) {
02716     if (it->fpModel->GetGlobalDescription().find("G4PhysicalVolumeModel")
02717         != std::string::npos) {
02718       if (((G4PhysicalVolumeModel*)(it->fpModel))->GetTopPhysicalVolume () == world) break;
02719     }
02720   }
02721   if (it != rdModelList.end()) {
02722     if (verbosity >= G4VisManager::warnings) {
02723       G4cout << "WARNING: There is already a volume, \""
02724              << it -> fpModel -> GetGlobalDescription()
02725              << "\",\n in the run-duration model list of scene \""
02726              << pScene -> GetName()
02727              << "\".\n To get a clean scene:"
02728              << "\n  /vis/drawVolume " << name
02729              << "\n or"
02730              << "\n  /vis/scene/create"
02731              << "\n  /vis/scene/add/volume " << name
02732              << "\n  /vis/sceneHandler/attach"
02733              << "\n (and also, if necessary, /vis/viewer/flush)"
02734              << G4endl;
02735     }
02736     return;
02737   }
02738 
02739   std::vector<G4PhysicalVolumeModel*> models;
02740   std::vector<G4VPhysicalVolume*> foundVolumes;
02741   G4VPhysicalVolume* foundWorld = 0;
02742   typedef G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID;
02743   typedef std::vector<PVNodeID> PVPath;
02744   PVPath foundFullPVPath;
02745   std::vector<G4int> foundDepths;
02746   std::vector<G4Transform3D> transformations;
02747 
02748   if (name == "world") {
02749 
02750     models.push_back
02751       (new G4PhysicalVolumeModel (world, requestedDepthOfDescent));
02752     foundVolumes.push_back(world);
02753     foundDepths.push_back(0);
02754     transformations.push_back(G4Transform3D());
02755 
02756   } else if (name == "worlds") {
02757 
02758     if (nWorlds == 0) {
02759       if (verbosity >= G4VisManager::warnings) {
02760         G4cout <<
02761           "WARNING: G4VisCommandSceneAddVolume::SetNewValue:"
02762           "\n  Parallel worlds requested but none exist."
02763           "\n  Just adding material world."
02764                << G4endl;
02765       }
02766     }
02767     std::vector<G4VPhysicalVolume*>::iterator iterWorld =
02768       transportationManager->GetWorldsIterator();
02769     for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
02770       models.push_back
02771         (new G4PhysicalVolumeModel (*iterWorld, requestedDepthOfDescent));
02772       foundVolumes.push_back(*iterWorld);
02773       foundDepths.push_back(0);
02774       transformations.push_back(G4Transform3D());
02775     }
02776 
02777   } else {  // Search all worlds...
02778     
02779     std::vector<G4VPhysicalVolume*>::iterator iterWorld =
02780       transportationManager->GetWorldsIterator();
02781     for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
02782       G4PhysicalVolumeModel searchModel (*iterWorld);  // Unlimited depth.
02783       G4ModelingParameters mp;  // Default - no culling.
02784       searchModel.SetModelingParameters (&mp);
02785       G4PhysicalVolumeSearchScene searchScene (&searchModel, name, copyNo);
02786       searchModel.DescribeYourselfTo (searchScene);  // Initiate search.
02787       G4VPhysicalVolume* foundVolume = searchScene.GetFoundVolume ();
02788       if (foundVolume) {
02789         foundWorld = *iterWorld;
02790         foundVolumes.push_back(foundVolume);
02791         foundFullPVPath = searchScene.GetFoundFullPVPath();
02792         foundDepths.push_back(searchScene.GetFoundDepth());
02793         transformations.push_back(searchScene.GetFoundTransformation());
02794         break;
02795       }
02796     }
02797 
02798     if (foundVolumes.size()) {
02799       for (size_t i = 0; i < foundVolumes.size(); ++i) {
02800         G4PhysicalVolumeModel* foundPVModel = new G4PhysicalVolumeModel
02801         (foundVolumes[i], requestedDepthOfDescent, transformations[i]);
02802         foundFullPVPath.pop_back();  // "Base" is "Found - 1".
02803         foundPVModel->SetBaseFullPVPath(foundFullPVPath);
02804         models.push_back(foundPVModel);
02805       }
02806     } else {
02807       if (verbosity >= G4VisManager::errors) {
02808         G4cout << "ERROR: Volume \"" << name << "\"";
02809         if (copyNo >= 0) {
02810           G4cout << ", copy no. " << copyNo << ",";
02811         }
02812         G4cout << " not found." << G4endl;
02813       }
02814       return;
02815     }
02816   }
02817 
02818   if (clipVolumeType == "box") {
02819     const G4double dX = (param2 - param1) / 2.;
02820     const G4double dY = (param4 - param3) / 2.;
02821     const G4double dZ = (param6 - param5) / 2.;
02822     const G4double x0 = (param2 + param1) / 2.;
02823     const G4double y0 = (param4 + param3) / 2.;
02824     const G4double z0 = (param6 + param5) / 2.;
02825     G4VSolid* clippingSolid =
02826       new G4DisplacedSolid
02827       ("_displaced_clipping_box",
02828        new G4Box("_clipping_box",dX,dY,dZ),
02829        G4Translate3D(x0,y0,z0));
02830     for (size_t i = 0; i < foundVolumes.size(); ++i) {
02831       models[i]->SetClippingSolid(clippingSolid);
02832       models[i]->SetClippingMode(clippingMode);
02833     }
02834   }  // If any other shape consider NumberOfRotationSides!!!!!!!!!!!
02835 
02836   const G4String& currentSceneName = pScene -> GetName ();
02837   G4bool failure = true;
02838   for (size_t i = 0; i < foundVolumes.size(); ++i) {
02839     G4bool successful = pScene -> AddRunDurationModel (models[i], warn);
02840     if (successful) {
02841       failure = false;
02842       if (verbosity >= G4VisManager::confirmations) {
02843         G4cout << "First occurrence of \""
02844                << foundVolumes[i] -> GetName ()
02845                << "\"";
02846         if (copyNo >= 0) {
02847           G4cout << ", copy no. " << copyNo << ",";
02848         }
02849         G4cout << "\n  found ";
02850         if (foundWorld)
02851           G4cout << "in world \"" << foundWorld->GetName() << "\" ";
02852         G4cout << "at depth " << foundDepths[i]
02853                << ",\n  with a requested depth of further descent of ";
02854         if (requestedDepthOfDescent < 0) {
02855           G4cout << "<0 (unlimited)";
02856         }
02857         else {
02858           G4cout << requestedDepthOfDescent;
02859         }
02860         G4cout << ",\n  has been added to scene \"" << currentSceneName << "\"."
02861                << G4endl;
02862       }
02863     }
02864   }
02865 
02866   if (failure) {
02867     G4VisCommandsSceneAddUnsuccessful(verbosity);
02868     return;
02869   }
02870 
02871   UpdateVisManagerScene (currentSceneName);
02872 }

Generated on Mon May 27 17:50:15 2013 for Geant4 by  doxygen 1.4.7