Geant4  10.00.p02
G4VisCommandsSceneAdd.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4VisCommandsSceneAdd.cc 77479 2013-11-25 10:01:22Z gcosmo $
28 // /vis/scene/add commands - John Allison 9th August 1998
29 
30 #include "G4VisCommandsSceneAdd.hh"
31 
33 #include "G4LogicalVolumeStore.hh"
34 #include "G4PhysicalVolumeModel.hh"
35 #include "G4LogicalVolumeModel.hh"
36 #include "G4ModelingParameters.hh"
37 #include "G4HitsModel.hh"
38 #include "G4DigiModel.hh"
39 #include "G4MagneticFieldModel.hh"
40 #include "G4PSHitsModel.hh"
41 #include "G4TrajectoriesModel.hh"
42 #include "G4ScaleModel.hh"
43 #include "G4TextModel.hh"
44 #include "G4ArrowModel.hh"
45 #include "G4AxesModel.hh"
47 #include "G4ParticleTable.hh"
48 #include "G4ParticleDefinition.hh"
49 #include "G4ApplicationState.hh"
50 #include "G4VUserVisAction.hh"
51 #include "G4CallbackModel.hh"
52 #include "G4UnionSolid.hh"
53 #include "G4SubtractionSolid.hh"
54 #include "G4Polyhedron.hh"
55 #include "G4UImanager.hh"
56 #include "G4UIcommand.hh"
57 #include "G4UIcmdWithAString.hh"
59 #include "G4UIcmdWithAnInteger.hh"
60 #include "G4Tokenizer.hh"
61 #include "G4RunManager.hh"
62 #include "G4StateManager.hh"
63 #include "G4Run.hh"
64 #include "G4Event.hh"
65 #include "G4Trajectory.hh"
66 #include "G4TrajectoryPoint.hh"
67 #include "G4RichTrajectory.hh"
68 #include "G4RichTrajectoryPoint.hh"
69 #include "G4SmoothTrajectory.hh"
71 #include "G4AttDef.hh"
72 #include "G4Polyline.hh"
73 #include "G4UnitsTable.hh"
74 #include "G4PhysicalConstants.hh"
75 #include "G4SystemOfUnits.hh"
76 
77 #include <sstream>
78 
79 // Local function with some frequently used error printing...
82  if (verbosity >= G4VisManager::warnings) {
83  G4cout <<
84  "WARNING: For some reason, possibly mentioned above, it has not been"
85  "\n possible to add to the scene."
86  << G4endl;
87  }
88 }
89 
91 
93  fpCommand = new G4UIcommand("/vis/scene/add/arrow", this);
94  fpCommand -> SetGuidance ("Adds arrow to current scene.");
95  G4bool omitable;
96  G4UIparameter* parameter;
97  parameter = new G4UIparameter ("x1", 'd', omitable = false);
98  fpCommand -> SetParameter (parameter);
99  parameter = new G4UIparameter ("y1", 'd', omitable = false);
100  fpCommand -> SetParameter (parameter);
101  parameter = new G4UIparameter ("z1", 'd', omitable = false);
102  fpCommand -> SetParameter (parameter);
103  parameter = new G4UIparameter ("x2", 'd', omitable = false);
104  fpCommand -> SetParameter (parameter);
105  parameter = new G4UIparameter ("y2", 'd', omitable = false);
106  fpCommand -> SetParameter (parameter);
107  parameter = new G4UIparameter ("z2", 'd', omitable = false);
108  fpCommand -> SetParameter (parameter);
109  parameter = new G4UIparameter ("unit", 's', omitable = true);
110  parameter->SetDefaultValue ("m");
111  fpCommand->SetParameter (parameter);
112 }
113 
115  delete fpCommand;
116 }
117 
119  return "";
120 }
121 
123 {
125  G4bool warn(verbosity >= G4VisManager::warnings);
126 
127  G4Scene* pScene = fpVisManager->GetCurrentScene();
128  if (!pScene) {
129  if (verbosity >= G4VisManager::errors) {
130  G4cout << "ERROR: No current scene. Please create one." << G4endl;
131  }
132  return;
133  }
134 
135  G4String unitString;
136  G4double x1, y1, z1, x2, y2, z2;
137  std::istringstream is(newValue);
138  is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> unitString;
139  G4double unit = G4UIcommand::ValueOf(unitString);
140  x1 *= unit; y1 *= unit; z1 *= unit;
141  x2 *= unit; y2 *= unit; z2 *= unit;
142 
143  // Consult scene for arrow width.
144  const G4VisExtent& sceneExtent = pScene->GetExtent();
145  G4double arrowWidth =
146  0.005 * fCurrentLineWidth * sceneExtent.GetExtentRadius();
147 
148  G4VModel* model = new G4ArrowModel
149  (x1, y1, z1, x2, y2, z2,
150  arrowWidth, fCurrentColour, newValue);
151 
152  const G4String& currentSceneName = pScene -> GetName ();
153  G4bool successful = pScene -> AddRunDurationModel (model, warn);
154  if (successful) {
155  if (verbosity >= G4VisManager::confirmations) {
156  G4cout << "Arrow has been added to scene \""
157  << currentSceneName << "\"."
158  << G4endl;
159  }
160  }
161  else G4VisCommandsSceneAddUnsuccessful(verbosity);
162  UpdateVisManagerScene (currentSceneName);
163 }
164 
166 
168  fpCommand = new G4UIcommand("/vis/scene/add/arrow2D", this);
169  fpCommand -> SetGuidance ("Adds 2D arrow to current scene.");
170  G4bool omitable;
171  G4UIparameter* parameter;
172  parameter = new G4UIparameter ("x1", 'd', omitable = false);
173  fpCommand -> SetParameter (parameter);
174  parameter = new G4UIparameter ("y1", 'd', omitable = false);
175  fpCommand -> SetParameter (parameter);
176  parameter = new G4UIparameter ("x2", 'd', omitable = false);
177  fpCommand -> SetParameter (parameter);
178  parameter = new G4UIparameter ("y2", 'd', omitable = false);
179  fpCommand -> SetParameter (parameter);
180 }
181 
183  delete fpCommand;
184 }
185 
187  return "";
188 }
189 
191 {
193  G4bool warn(verbosity >= G4VisManager::warnings);
194 
195  G4Scene* pScene = fpVisManager->GetCurrentScene();
196  if (!pScene) {
197  if (verbosity >= G4VisManager::errors) {
198  G4cout << "ERROR: No current scene. Please create one." << G4endl;
199  }
200  return;
201  }
202 
203  G4double x1, y1, x2, y2;
204  std::istringstream is(newValue);
205  is >> x1 >> y1 >> x2 >> y2;
206 
207  Arrow2D* arrow2D = new Arrow2D
208  (x1, y1, x2, y2, fCurrentLineWidth, fCurrentColour);
209  G4VModel* model =
211  model->SetType("Arrow2D");
212  model->SetGlobalTag("Arrow2D");
213  model->SetGlobalDescription("Arrow2D: " + newValue);
214  const G4String& currentSceneName = pScene -> GetName ();
215  G4bool successful = pScene -> AddRunDurationModel (model, warn);
216  if (successful) {
217  if (verbosity >= G4VisManager::confirmations) {
218  G4cout << "A 2D arrow has been added to scene \""
219  << currentSceneName << "\"."
220  << G4endl;
221  }
222  }
223  else G4VisCommandsSceneAddUnsuccessful(verbosity);
224  UpdateVisManagerScene (currentSceneName);
225 }
226 
229  G4double x2, G4double y2,
230  G4double width, const G4Colour& colour):
231  fWidth(width), fColour(colour)
232 {
233  fShaftPolyline.push_back(G4Point3D(x1,y1,0));
234  fShaftPolyline.push_back(G4Point3D(x2,y2,0));
235  G4Vector3D arrowDirection = G4Vector3D(x2-x1,y2-y1,0).unit();
236  G4Vector3D arrowPointLeftDirection(arrowDirection);
237  arrowPointLeftDirection.rotateZ(150.*deg);
238  G4Vector3D arrowPointRightDirection(arrowDirection);
239  arrowPointRightDirection.rotateZ(-150.*deg);
240  fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0.04*arrowPointLeftDirection);
241  fHeadPolyline.push_back(G4Point3D(x2,y2,0));
242  fHeadPolyline.push_back(G4Point3D(x2,y2,0)+0.04*arrowPointRightDirection);
243  G4VisAttributes va;
244  va.SetLineWidth(fWidth);
245  va.SetColour(fColour);
246  fShaftPolyline.SetVisAttributes(va);
247  fHeadPolyline.SetVisAttributes(va);
248 }
249 
250 void G4VisCommandSceneAddArrow2D::Arrow2D::operator()
251  (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
252 {
253  sceneHandler.BeginPrimitives2D();
254  sceneHandler.AddPrimitive(fShaftPolyline);
255  sceneHandler.AddPrimitive(fHeadPolyline);
256  sceneHandler.EndPrimitives2D();
257 }
258 
260 
262  G4bool omitable;
263  fpCommand = new G4UIcommand ("/vis/scene/add/axes", this);
264  fpCommand -> SetGuidance ("Add axes.");
265  fpCommand -> SetGuidance
266  ("Draws axes at (x0, y0, z0) of given length and colour.");
267  fpCommand -> SetGuidance
268  ("If \"unitcolour\" is \"auto\", x, y and z will be red, green and blue"
269  "\n respectively. Otherwise choose from the pre-defined text-specified"
270  "\n colours - see information printed by the vis manager at start-up or"
271  "\n use \"/vis/list\".");
272  fpCommand -> SetGuidance
273  ("If \"length\" is negative, it is set to about 25% of scene extent.");
274  G4UIparameter* parameter;
275  parameter = new G4UIparameter ("x0", 'd', omitable = true);
276  parameter->SetDefaultValue (0.);
277  fpCommand->SetParameter (parameter);
278  parameter = new G4UIparameter ("y0", 'd', omitable = true);
279  parameter->SetDefaultValue (0.);
280  fpCommand->SetParameter (parameter);
281  parameter = new G4UIparameter ("z0", 'd', omitable = true);
282  parameter->SetDefaultValue (0.);
283  fpCommand->SetParameter (parameter);
284  parameter = new G4UIparameter ("length", 'd', omitable = true);
285  parameter->SetDefaultValue (-1.);
286  fpCommand->SetParameter (parameter);
287  parameter = new G4UIparameter ("unit", 's', omitable = true);
288  parameter->SetDefaultValue ("m");
289  fpCommand->SetParameter (parameter);
290  parameter = new G4UIparameter ("unitcolour", 's', omitable = true);
291  parameter->SetDefaultValue ("auto");
292  fpCommand->SetParameter (parameter);
293 }
294 
296  delete fpCommand;
297 }
298 
300  return "";
301 }
302 
304 
306  G4bool warn(verbosity >= G4VisManager::warnings);
307 
308  G4Scene* pScene = fpVisManager->GetCurrentScene();
309  if (!pScene) {
310  if (verbosity >= G4VisManager::errors) {
311  G4cout << "ERROR: No current scene. Please create one." << G4endl;
312  }
313  return;
314  }
315 
316  G4String unitString, colourString;
317  G4double x0, y0, z0, length;
318  std::istringstream is (newValue);
319  is >> x0 >> y0 >> z0 >> length >> unitString >> colourString;
320 
321  G4double unit = G4UIcommand::ValueOf(unitString);
322  x0 *= unit; y0 *= unit; z0 *= unit;
323  const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
324  if (length < 0.) {
325  length = 0.5 * sceneExtent.GetExtentRadius();
326  G4double intLog10Length = std::floor(std::log10(length));
327  length = std::pow(10,intLog10Length);
328  } else {
329  length *= unit;
330  }
331  G4String annotation = G4BestUnit(length,"Length");
332 
333  // Consult scene for arrow width...
334  G4double arrowWidth =
335  0.005 * fCurrentLineWidth * sceneExtent.GetExtentRadius();
336  // ...but limit it to length/50.
337  if (arrowWidth > length/50.) arrowWidth = length/50.;
338 
339  G4VModel* model = new G4AxesModel
340  (x0, y0, z0, length, arrowWidth, colourString, newValue);
341 
342  G4bool successful = pScene -> AddRunDurationModel (model, warn);
343  const G4String& currentSceneName = pScene -> GetName ();
344  if (successful) {
345  if (verbosity >= G4VisManager::confirmations) {
346  G4cout << "Axes have been added to scene \"" << currentSceneName << "\"."
347  << G4endl;
348  }
349  }
350  else G4VisCommandsSceneAddUnsuccessful(verbosity);
351  UpdateVisManagerScene (currentSceneName);
352 }
353 
355 
357  G4bool omitable;
358  fpCommand = new G4UIcommand ("/vis/scene/add/date", this);
359  fpCommand -> SetGuidance ("Adds date to current scene.");
360  fpCommand -> SetGuidance
361  ("If \"date\"is omitted, the current date and time is drawn."
362  "\nOtherwise, the string, including the rest of the line, is drawn.");
363  G4UIparameter* parameter;
364  parameter = new G4UIparameter ("size", 'i', omitable = true);
365  parameter -> SetGuidance ("Screen size of text in pixels.");
366  parameter -> SetDefaultValue (18);
367  fpCommand -> SetParameter (parameter);
368  parameter = new G4UIparameter ("x-position", 'd', omitable = true);
369  parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
370  parameter -> SetDefaultValue (0.95);
371  fpCommand -> SetParameter (parameter);
372  parameter = new G4UIparameter ("y-position", 'd', omitable = true);
373  parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
374  parameter -> SetDefaultValue (0.9);
375  fpCommand -> SetParameter (parameter);
376  parameter = new G4UIparameter ("layout", 's', omitable = true);
377  parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
378  parameter -> SetDefaultValue ("right");
379  fpCommand -> SetParameter (parameter);
380  parameter = new G4UIparameter ("date", 's', omitable = true);
381  parameter -> SetDefaultValue ("-");
382  fpCommand -> SetParameter (parameter);
383 }
384 
386  delete fpCommand;
387 }
388 
390  return "";
391 }
392 
394 {
396  G4bool warn(verbosity >= G4VisManager::warnings);
397 
398  G4Scene* pScene = fpVisManager->GetCurrentScene();
399  if (!pScene) {
400  if (verbosity >= G4VisManager::errors) {
401  G4cout << "ERROR: No current scene. Please create one." << G4endl;
402  }
403  return;
404  }
405 
406  G4int size;
407  G4double x, y;
408  G4String layoutString, dateString;
409  std::istringstream is(newValue);
410  is >> size >> x >> y >> layoutString >> dateString;
411  // Read rest of line, if any.
412  const size_t NREMAINDER = 100;
413  char remainder[NREMAINDER];
414  is.getline(remainder, NREMAINDER);
415  dateString += remainder;
416  G4Text::Layout layout = G4Text::right;
417  if (layoutString(0) == 'l') layout = G4Text::left;
418  else if (layoutString(0) == 'c') layout = G4Text::centre;
419  else if (layoutString(0) == 'r') layout = G4Text::right;
420 
421  Date* date = new Date(fpVisManager, size, x, y, layout, dateString);
422  G4VModel* model =
424  model->SetType("Date");
425  model->SetGlobalTag("Date");
426  model->SetGlobalDescription("Date");
427  const G4String& currentSceneName = pScene -> GetName ();
428  G4bool successful = pScene -> AddRunDurationModel (model, warn);
429  if (successful) {
430  if (verbosity >= G4VisManager::confirmations) {
431  G4cout << "Date has been added to scene \""
432  << currentSceneName << "\"."
433  << G4endl;
434  }
435  }
436  else G4VisCommandsSceneAddUnsuccessful(verbosity);
437  UpdateVisManagerScene (currentSceneName);
438 }
439 
440 void G4VisCommandSceneAddDate::Date::operator()
441  (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
442 {
443  G4String time;
444  if (fDate == "-") {
445  time = fTimer.GetClockTime();
446  } else {
447  time = fDate;
448  }
449  // Check for \n, starting from back, and erase.
450  std::string::size_type i = time.rfind('\n');
451  if (i != std::string::npos) time.erase(i);
452  G4Text text(time, G4Point3D(fX, fY, 0.));
453  text.SetScreenSize(fSize);
454  text.SetLayout(fLayout);
455  G4VisAttributes textAtts(G4Colour(0.,1.,1));
456  text.SetVisAttributes(textAtts);
457  sceneHandler.BeginPrimitives2D();
458  sceneHandler.AddPrimitive(text);
459  sceneHandler.EndPrimitives2D();
460 }
461 
463 
465  fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/add/digis", this);
466  fpCommand -> SetGuidance ("Adds digis to current scene.");
467  fpCommand -> SetGuidance
468  ("Digis are drawn at end of event when the scene in which"
469  "\nthey are added is current.");
470 }
471 
473  delete fpCommand;
474 }
475 
477  return "";
478 }
479 
481 
483  G4bool warn(verbosity >= G4VisManager::warnings);
484 
485  G4Scene* pScene = fpVisManager->GetCurrentScene();
486  if (!pScene) {
487  if (verbosity >= G4VisManager::errors) {
488  G4cout << "ERROR: No current scene. Please create one." << G4endl;
489  }
490  return;
491  }
492 
493  G4DigiModel* model = new G4DigiModel;
494  const G4String& currentSceneName = pScene -> GetName ();
495  G4bool successful = pScene -> AddEndOfEventModel (model, warn);
496  if (successful) {
497  if (verbosity >= G4VisManager::confirmations) {
498  G4cout << "Digis, if any, will be drawn at end of run in scene \""
499  << currentSceneName << "\"."
500  << G4endl;
501  }
502  }
503  else G4VisCommandsSceneAddUnsuccessful(verbosity);
504  UpdateVisManagerScene (currentSceneName);
505 }
506 
508 
510  G4bool omitable;
511  fpCommand = new G4UIcommand ("/vis/scene/add/eventID", this);
512  fpCommand -> SetGuidance ("Adds eventID to current scene.");
513  fpCommand -> SetGuidance
514  ("Run and event numbers are drawn at end of event or run when"
515  "\n the scene in which they are added is current.");
516  G4UIparameter* parameter;
517  parameter = new G4UIparameter ("size", 'i', omitable = true);
518  parameter -> SetGuidance ("Screen size of text in pixels.");
519  parameter -> SetDefaultValue (18);
520  fpCommand -> SetParameter (parameter);
521  parameter = new G4UIparameter ("x-position", 'd', omitable = true);
522  parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
523  parameter -> SetDefaultValue (-0.95);
524  fpCommand -> SetParameter (parameter);
525  parameter = new G4UIparameter ("y-position", 'd', omitable = true);
526  parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
527  parameter -> SetDefaultValue (0.9);
528  fpCommand -> SetParameter (parameter);
529  parameter = new G4UIparameter ("layout", 's', omitable = true);
530  parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
531  parameter -> SetDefaultValue ("left");
532  fpCommand -> SetParameter (parameter);
533 }
534 
536  delete fpCommand;
537 }
538 
540  return "";
541 }
542 
544 {
546  G4bool warn(verbosity >= G4VisManager::warnings);
547 
548  G4Scene* pScene = fpVisManager->GetCurrentScene();
549  if (!pScene) {
550  if (verbosity >= G4VisManager::errors) {
551  G4cout << "ERROR: No current scene. Please create one." << G4endl;
552  }
553  return;
554  }
555 
556  G4int size;
557  G4double x, y;
558  G4String layoutString;
559  std::istringstream is(newValue);
560  is >> size >> x >> y >> layoutString;
561 
562  G4Text::Layout layout = G4Text::right;
563  if (layoutString(0) == 'l') layout = G4Text::left;
564  else if (layoutString(0) == 'c') layout = G4Text::centre;
565  else if (layoutString(0) == 'r') layout = G4Text::right;
566 
567  EventID* eventID = new EventID(fpVisManager, size, x, y, layout);
568  G4VModel* model =
570  model->SetType("EventID");
571  model->SetGlobalTag("EventID");
572  model->SetGlobalDescription("EventID");
573  const G4String& currentSceneName = pScene -> GetName ();
574  G4bool successful = pScene -> AddEndOfEventModel (model, warn);
575  if (successful) {
576  if (verbosity >= G4VisManager::confirmations) {
577  G4cout << "EventID has been added to scene \""
578  << currentSceneName << "\"."
579  << G4endl;
580  }
581  }
582  else G4VisCommandsSceneAddUnsuccessful(verbosity);
583  UpdateVisManagerScene (currentSceneName);
584 }
585 
586 void G4VisCommandSceneAddEventID::EventID::operator()
587  (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
588 {
589  const G4Run* currentRun = 0;
591  if (runManager) currentRun = runManager->GetCurrentRun();
592 
593  G4VModel* model = fpVisManager->GetCurrentSceneHandler()->GetModel();
594  const G4ModelingParameters* mp = 0;
595  const G4Event* currentEvent = 0;
596  if (model) {
597  mp = model->GetModelingParameters();
598  currentEvent = mp->GetEvent();
599  } else {
600  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
601  if (verbosity >= G4VisManager::errors) {
602  G4cout << "ERROR: No model defined for this SceneHandler : "
603  << fpVisManager->GetCurrentSceneHandler()->GetName()
604  << G4endl;
605  }
606  }
607  if (currentRun && currentEvent) {
608  G4int runID = currentRun->GetRunID();
609  G4int eventID = currentEvent->GetEventID();
610  std::ostringstream oss;
611  if (fpVisManager->GetCurrentScene()->GetRefreshAtEndOfEvent()) {
612  oss << "Run " << runID << " Event " << eventID;
613  } else {
614  G4int nEvents = 0;
616  G4ApplicationState state = stateManager->GetCurrentState();
617  if (state == G4State_EventProc) {
618  nEvents = currentRun->GetNumberOfEventToBeProcessed();
619  } else {
620  const std::vector<const G4Event*>* events =
621  currentRun->GetEventVector();
622  if (events) nEvents = events->size();
623  }
624  if (eventID < nEvents - 1) return; // Not last event.
625  else {
626  oss << "Run " << runID << " (" << nEvents << " event";
627  if (nEvents != 1) oss << 's';
628  oss << ')';
629  }
630  }
631  G4Text text(oss.str(), G4Point3D(fX, fY, 0.));
632  text.SetScreenSize(fSize);
633  text.SetLayout(fLayout);
634  G4VisAttributes textAtts(G4Colour(0.,1.,1));
635  text.SetVisAttributes(textAtts);
636  sceneHandler.BeginPrimitives2D();
637  sceneHandler.AddPrimitive(text);
638  sceneHandler.EndPrimitives2D();
639  }
640 }
641 
643 
645  fpCommand = new G4UIcommand("/vis/scene/add/frame", this);
646  fpCommand -> SetGuidance ("Adds frame to current scene.");
647  G4bool omitable;
648  G4UIparameter* parameter;
649  parameter = new G4UIparameter ("size", 'd', omitable = true);
650  parameter -> SetGuidance ("Size of frame. 1 = full window.");
651  parameter -> SetParameterRange ("size > 0 && size <=1");
652  parameter -> SetDefaultValue (0.97);
653  fpCommand -> SetParameter (parameter);
654 }
655 
657  delete fpCommand;
658 }
659 
661  return "";
662 }
663 
665 {
667  G4bool warn(verbosity >= G4VisManager::warnings);
668 
669  G4Scene* pScene = fpVisManager->GetCurrentScene();
670  if (!pScene) {
671  if (verbosity >= G4VisManager::errors) {
672  G4cout << "ERROR: No current scene. Please create one." << G4endl;
673  }
674  return;
675  }
676 
677  G4double size;
678  std::istringstream is(newValue);
679  is >> size;
680 
681  Frame* frame = new Frame(size, fCurrentLineWidth, fCurrentColour);
682  G4VModel* model =
684  model->SetType("Frame");
685  model->SetGlobalTag("Frame");
686  model->SetGlobalDescription("Frame: " + newValue);
687  const G4String& currentSceneName = pScene -> GetName ();
688  G4bool successful = pScene -> AddRunDurationModel (model, warn);
689  if (successful) {
690  if (verbosity >= G4VisManager::confirmations) {
691  G4cout << "Frame has been added to scene \""
692  << currentSceneName << "\"."
693  << G4endl;
694  }
695  }
696  else G4VisCommandsSceneAddUnsuccessful(verbosity);
697  UpdateVisManagerScene (currentSceneName);
698 }
699 
700 void G4VisCommandSceneAddFrame::Frame::operator()
701  (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
702 {
703  G4Polyline frame;
704  frame.push_back(G4Point3D( fSize, fSize, 0.));
705  frame.push_back(G4Point3D(-fSize, fSize, 0.));
706  frame.push_back(G4Point3D(-fSize, -fSize, 0.));
707  frame.push_back(G4Point3D( fSize, -fSize, 0.));
708  frame.push_back(G4Point3D( fSize, fSize, 0.));
709  G4VisAttributes va;
710  va.SetLineWidth(fWidth);
711  va.SetColour(fColour);
712  frame.SetVisAttributes(va);
713  sceneHandler.BeginPrimitives2D();
714  sceneHandler.AddPrimitive(frame);
715  sceneHandler.EndPrimitives2D();
716 }
717 
719 
721  fpCommand = new G4UIcmdWithoutParameter ("/vis/scene/add/hits", this);
722  fpCommand -> SetGuidance ("Adds hits to current scene.");
723  fpCommand -> SetGuidance
724  ("Hits are drawn at end of event when the scene in which"
725  "\nthey are added is current.");
726 }
727 
729  delete fpCommand;
730 }
731 
733  return "";
734 }
735 
737 
739  G4bool warn(verbosity >= G4VisManager::warnings);
740 
741  G4Scene* pScene = fpVisManager->GetCurrentScene();
742  if (!pScene) {
743  if (verbosity >= G4VisManager::errors) {
744  G4cout << "ERROR: No current scene. Please create one." << G4endl;
745  }
746  return;
747  }
748 
749  G4HitsModel* model = new G4HitsModel;
750  const G4String& currentSceneName = pScene -> GetName ();
751  G4bool successful = pScene -> AddEndOfEventModel (model, warn);
752  if (successful) {
753  if (verbosity >= G4VisManager::confirmations) {
754  G4cout << "Hits, if any, will be drawn at end of run in scene \""
755  << currentSceneName << "\"."
756  << G4endl;
757  }
758  }
759  else G4VisCommandsSceneAddUnsuccessful(verbosity);
760  UpdateVisManagerScene (currentSceneName);
761 }
762 
764 
766  fpCommand = new G4UIcommand("/vis/scene/add/line", this);
767  fpCommand -> SetGuidance ("Adds line to current scene.");
768  G4bool omitable;
769  G4UIparameter* parameter;
770  parameter = new G4UIparameter ("x1", 'd', omitable = false);
771  fpCommand -> SetParameter (parameter);
772  parameter = new G4UIparameter ("y1", 'd', omitable = false);
773  fpCommand -> SetParameter (parameter);
774  parameter = new G4UIparameter ("z1", 'd', omitable = false);
775  fpCommand -> SetParameter (parameter);
776  parameter = new G4UIparameter ("x2", 'd', omitable = false);
777  fpCommand -> SetParameter (parameter);
778  parameter = new G4UIparameter ("y2", 'd', omitable = false);
779  fpCommand -> SetParameter (parameter);
780  parameter = new G4UIparameter ("z2", 'd', omitable = false);
781  fpCommand -> SetParameter (parameter);
782  parameter = new G4UIparameter ("unit", 's', omitable = true);
783  parameter->SetDefaultValue ("m");
784  fpCommand->SetParameter (parameter);
785 }
786 
788  delete fpCommand;
789 }
790 
792  return "";
793 }
794 
796 {
798  G4bool warn(verbosity >= G4VisManager::warnings);
799 
800  G4Scene* pScene = fpVisManager->GetCurrentScene();
801  if (!pScene) {
802  if (verbosity >= G4VisManager::errors) {
803  G4cout << "ERROR: No current scene. Please create one." << G4endl;
804  }
805  return;
806  }
807 
808  G4String unitString;
809  G4double x1, y1, z1, x2, y2, z2;
810  std::istringstream is(newValue);
811  is >> x1 >> y1 >> z1 >> x2 >> y2 >> z2 >> unitString;
812  G4double unit = G4UIcommand::ValueOf(unitString);
813  x1 *= unit; y1 *= unit; z1 *= unit;
814  x2 *= unit; y2 *= unit; z2 *= unit;
815 
816  Line* line = new Line(x1, y1, z1, x2, y2, z2,
818  G4VModel* model =
820  model->SetType("Line");
821  model->SetGlobalTag("Line");
822  model->SetGlobalDescription("Line: " + newValue);
823  const G4String& currentSceneName = pScene -> GetName ();
824  G4bool successful = pScene -> AddRunDurationModel (model, warn);
825  if (successful) {
826  if (verbosity >= G4VisManager::confirmations) {
827  G4cout << "Line has been added to scene \""
828  << currentSceneName << "\"."
829  << G4endl;
830  }
831  }
832  else G4VisCommandsSceneAddUnsuccessful(verbosity);
833  UpdateVisManagerScene (currentSceneName);
834 }
835 
838  G4double x2, G4double y2, G4double z2,
839  G4double width, const G4Colour& colour):
840  fWidth(width), fColour(colour)
841 {
842  fPolyline.push_back(G4Point3D(x1,y1,z1));
843  fPolyline.push_back(G4Point3D(x2,y2,z2));
844  G4VisAttributes va;
845  va.SetLineWidth(fWidth);
846  va.SetColour(fColour);
847  fPolyline.SetVisAttributes(va);
848 }
849 
850 void G4VisCommandSceneAddLine::Line::operator()
851  (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
852 {
853  sceneHandler.BeginPrimitives();
854  sceneHandler.AddPrimitive(fPolyline);
855  sceneHandler.EndPrimitives();
856 }
857 
859 
861  fpCommand = new G4UIcommand("/vis/scene/add/line2D", this);
862  fpCommand -> SetGuidance ("Adds 2D line to current scene.");
863  G4bool omitable;
864  G4UIparameter* parameter;
865  parameter = new G4UIparameter ("x1", 'd', omitable = false);
866  fpCommand -> SetParameter (parameter);
867  parameter = new G4UIparameter ("y1", 'd', omitable = false);
868  fpCommand -> SetParameter (parameter);
869  parameter = new G4UIparameter ("x2", 'd', omitable = false);
870  fpCommand -> SetParameter (parameter);
871  parameter = new G4UIparameter ("y2", 'd', omitable = false);
872  fpCommand -> SetParameter (parameter);
873 }
874 
876  delete fpCommand;
877 }
878 
880  return "";
881 }
882 
884 {
886  G4bool warn(verbosity >= G4VisManager::warnings);
887 
888  G4Scene* pScene = fpVisManager->GetCurrentScene();
889  if (!pScene) {
890  if (verbosity >= G4VisManager::errors) {
891  G4cout << "ERROR: No current scene. Please create one." << G4endl;
892  }
893  return;
894  }
895 
896  G4double x1, y1, x2, y2;
897  std::istringstream is(newValue);
898  is >> x1 >> y1 >> x2 >> y2;
899 
900  Line2D* line2D = new Line2D
901  (x1, y1, x2, y2, fCurrentLineWidth, fCurrentColour);
902  G4VModel* model =
904  model->SetType("Line2D");
905  model->SetGlobalTag("Line2D");
906  model->SetGlobalDescription("Line2D: " + newValue);
907  const G4String& currentSceneName = pScene -> GetName ();
908  G4bool successful = pScene -> AddRunDurationModel (model, warn);
909  if (successful) {
910  if (verbosity >= G4VisManager::confirmations) {
911  G4cout << "A 2D line has been added to scene \""
912  << currentSceneName << "\"."
913  << G4endl;
914  }
915  }
916  else G4VisCommandsSceneAddUnsuccessful(verbosity);
917  UpdateVisManagerScene (currentSceneName);
918 }
919 
922  G4double x2, G4double y2,
923  G4double width, const G4Colour& colour):
924  fWidth(width), fColour(colour)
925 {
926  fPolyline.push_back(G4Point3D(x1,y1,0));
927  fPolyline.push_back(G4Point3D(x2,y2,0));
928  G4VisAttributes va;
929  va.SetLineWidth(fWidth);
930  va.SetColour(fColour);
931  fPolyline.SetVisAttributes(va);
932 }
933 
934 void G4VisCommandSceneAddLine2D::Line2D::operator()
935  (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
936 {
937  sceneHandler.BeginPrimitives2D();
938  sceneHandler.AddPrimitive(fPolyline);
939  sceneHandler.EndPrimitives2D();
940 }
941 
943 
945  G4bool omitable;
946  fpCommand = new G4UIcommand ("/vis/scene/add/logicalVolume", this);
947  fpCommand -> SetGuidance ("Adds a logical volume to the current scene,");
948  fpCommand -> SetGuidance
949  ("Shows boolean components (if any), voxels (if any) and readout geometry"
950  "\n(if any). Note: voxels are not constructed until start of run -"
951  "\n \"/run/beamOn\".");
952  G4UIparameter* parameter;
953  parameter = new G4UIparameter ("logical-volume-name", 's', omitable = false);
954  fpCommand -> SetParameter (parameter);
955  parameter = new G4UIparameter ("depth-of-descent", 'i', omitable = true);
956  parameter -> SetGuidance ("Depth of descent of geometry hierarchy.");
957  parameter -> SetDefaultValue (1);
958  fpCommand -> SetParameter (parameter);
959  parameter = new G4UIparameter ("booleans-flag", 'b', omitable = true);
960  parameter -> SetDefaultValue (true);
961  fpCommand -> SetParameter (parameter);
962  parameter = new G4UIparameter ("voxels-flag", 'b', omitable = true);
963  parameter -> SetDefaultValue (true);
964  fpCommand -> SetParameter (parameter);
965  parameter = new G4UIparameter ("readout-flag", 'b', omitable = true);
966  parameter -> SetDefaultValue (true);
967  fpCommand -> SetParameter (parameter);
968 }
969 
971  delete fpCommand;
972 }
973 
975  return "";
976 }
977 
979  G4String newValue) {
980 
982  G4bool warn(verbosity >= G4VisManager::warnings);
983 
984  G4Scene* pScene = fpVisManager->GetCurrentScene();
985  if (!pScene) {
986  if (verbosity >= G4VisManager::errors) {
987  G4cout << "ERROR: No current scene. Please create one." << G4endl;
988  }
989  return;
990  }
991 
992  G4String name;
993  G4int requestedDepthOfDescent;
994  G4String booleansString, voxelsString, readoutString;
995  std::istringstream is (newValue);
996  is >> name >> requestedDepthOfDescent
997  >> booleansString >> voxelsString >> readoutString;
998  G4bool booleans = G4UIcommand::ConvertToBool(booleansString);
999  G4bool voxels = G4UIcommand::ConvertToBool(voxelsString);
1000  G4bool readout = G4UIcommand::ConvertToBool(readoutString);
1001 
1003  int nLV = pLVStore -> size ();
1004  int iLV;
1005  G4LogicalVolume* pLV = 0;
1006  for (iLV = 0; iLV < nLV; iLV++ ) {
1007  pLV = (*pLVStore) [iLV];
1008  if (pLV -> GetName () == name) break;
1009  }
1010  if (iLV == nLV) {
1011  if (verbosity >= G4VisManager::errors) {
1012  G4cout << "ERROR: Logical volume " << name
1013  << " not found in logical volume store." << G4endl;
1014  }
1015  return;
1016  }
1017 
1018  const std::vector<G4Scene::Model>& rdModelList = pScene -> GetRunDurationModelList();
1019  std::vector<G4Scene::Model>::const_iterator i;
1020  for (i = rdModelList.begin(); i != rdModelList.end(); ++i) {
1021  if (i->fpModel->GetGlobalDescription().find("Volume") != std::string::npos) break;
1022  }
1023  if (i != rdModelList.end()) {
1024  if (verbosity >= G4VisManager::errors) {
1025  G4cout << "There is already a volume, \""
1026  << i->fpModel->GetGlobalDescription()
1027  << "\",\n in the run-duration model list of scene \""
1028  << pScene -> GetName()
1029  << "\".\n Your logical volume must be the only volume in the scene."
1030  << "\n Create a new scene and try again:"
1031  << "\n /vis/specify " << name
1032  << "\n or"
1033  << "\n /vis/scene/create"
1034  << "\n /vis/scene/add/logicalVolume " << name
1035  << "\n /vis/sceneHandler/attach"
1036  << "\n (and also, if necessary, /vis/viewer/flush)"
1037  << G4endl;
1038  }
1039  }
1040 
1041  G4VModel* model = new G4LogicalVolumeModel
1042  (pLV, requestedDepthOfDescent, booleans, voxels, readout);
1043  const G4String& currentSceneName = pScene -> GetName ();
1044  G4bool successful = pScene -> AddRunDurationModel (model, warn);
1045  if (successful) {
1046  if (verbosity >= G4VisManager::confirmations) {
1047  G4cout << "Logical volume \"" << pLV -> GetName ()
1048  << " with requested depth of descent "
1049  << requestedDepthOfDescent
1050  << ",\n with";
1051  if (!booleans) G4cout << "out";
1052  G4cout << " boolean components, with";
1053  if (!voxels) G4cout << "out";
1054  G4cout << " voxels and with";
1055  if (!readout) G4cout << "out";
1056  G4cout << " readout geometry,"
1057  << "\n has been added to scene \"" << currentSceneName << "\"."
1058  << G4endl;
1059  }
1060  }
1061  else {
1063  return;
1064  }
1065 
1066  UpdateVisManagerScene (currentSceneName);
1067 }
1068 
1069 
1071 
1073  G4bool omitable;
1074  fpCommand = new G4UIcommand ("/vis/scene/add/logo", this);
1075  fpCommand -> SetGuidance ("Adds a G4 logo to the current scene.");
1076  fpCommand -> SetGuidance
1077  ("If \"unit\" is \"auto\", height is roughly one tenth of scene extent.");
1078  fpCommand -> SetGuidance
1079  ("\"direction\" is that of outward-facing normal to front face of logo."
1080  "\nIf \"direction\" is \"auto\", logo faces the user in the current viewer.");
1081  fpCommand -> SetGuidance
1082  ("\nIf \"placement\" is \"auto\", logo is placed at bottom right of screen"
1083  "\n when viewed from logo direction.");
1084  G4UIparameter* parameter;
1085  parameter = new G4UIparameter ("height", 'd', omitable = true);
1086  parameter->SetDefaultValue (1.);
1087  fpCommand->SetParameter (parameter);
1088  parameter = new G4UIparameter ("unit", 's', omitable = true);
1089  parameter->SetDefaultValue ("auto");
1090  fpCommand->SetParameter (parameter);
1091  parameter = new G4UIparameter ("direction", 's', omitable = true);
1092  parameter->SetGuidance ("auto|[-]x|[-]y|[-]z");
1093  parameter->SetDefaultValue ("auto");
1094  fpCommand->SetParameter (parameter);
1095  parameter = new G4UIparameter ("red", 'd', omitable = true);
1096  parameter->SetDefaultValue (0.);
1097  fpCommand->SetParameter (parameter);
1098  parameter = new G4UIparameter ("green", 'd', omitable = true);
1099  parameter->SetDefaultValue (1.);
1100  fpCommand->SetParameter (parameter);
1101  parameter = new G4UIparameter ("blue", 'd', omitable = true);
1102  parameter->SetDefaultValue (0.);
1103  fpCommand->SetParameter (parameter);
1104  parameter = new G4UIparameter ("placement", 's', omitable = true);
1105  parameter -> SetParameterCandidates("auto manual");
1106  parameter->SetDefaultValue ("auto");
1107  fpCommand->SetParameter (parameter);
1108  parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1109  parameter->SetDefaultValue (0.);
1110  fpCommand->SetParameter (parameter);
1111  parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1112  parameter->SetDefaultValue (0.);
1113  fpCommand->SetParameter (parameter);
1114  parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1115  parameter->SetDefaultValue (0.);
1116  fpCommand->SetParameter (parameter);
1117  parameter = new G4UIparameter ("unit", 's', omitable = true);
1118  parameter->SetDefaultValue ("m");
1119  fpCommand->SetParameter (parameter);
1120 }
1121 
1123  delete fpCommand;
1124 }
1125 
1127  return "";
1128 }
1129 
1131 
1133  G4bool warn = verbosity >= G4VisManager::warnings;
1134 
1135  G4Scene* pScene = fpVisManager->GetCurrentScene();
1136  if (!pScene) {
1137  if (verbosity >= G4VisManager::errors) {
1138  G4cout << "ERROR: No current scene. Please create one." << G4endl;
1139  }
1140  return;
1141  }
1142 
1143  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
1144  if (!pViewer) {
1145  if (verbosity >= G4VisManager::errors) {
1146  G4cout <<
1147  "ERROR: G4VisCommandSceneAddLogo::SetNewValue: no viewer."
1148  "\n Auto direction needs a viewer."
1149  << G4endl;
1150  }
1151  return;
1152  }
1153 
1154  G4double userHeight, red, green, blue, xmid, ymid, zmid;
1155  G4String userHeightUnit, direction, auto_manual, positionUnit;
1156  std::istringstream is (newValue);
1157  is >> userHeight >> userHeightUnit >> direction
1158  >> red >> green >> blue
1159  >> auto_manual
1160  >> xmid >> ymid >> zmid >> positionUnit;
1161 
1162  G4double height = userHeight;
1163  const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1164  if (userHeightUnit == "auto") {
1165  height *= 0.2 * sceneExtent.GetExtentRadius();
1166  } else {
1167  height *= G4UIcommand::ValueOf(userHeightUnit);
1168  }
1169 
1170  G4double unit = G4UIcommand::ValueOf(positionUnit);
1171  xmid *= unit; ymid *= unit; zmid *= unit;
1172 
1173  Direction logoDirection = X; // Initialise to keep some compilers happy.
1174  if (direction == "auto") {
1175  // Take cue from viewer
1176  const G4Vector3D& vp =
1178  if (vp.x() > vp.y() && vp.x() > vp.z()) logoDirection = X;
1179  else if (vp.x() < vp.y() && vp.x() < vp.z()) logoDirection = minusX;
1180  else if (vp.y() > vp.x() && vp.y() > vp.z()) logoDirection = Y;
1181  else if (vp.y() < vp.x() && vp.y() < vp.z()) logoDirection = minusY;
1182  else if (vp.z() > vp.x() && vp.z() > vp.y()) logoDirection = Z;
1183  else if (vp.z() < vp.x() && vp.z() < vp.y()) logoDirection = minusZ;
1184  }
1185  else if (direction(0) == 'x') logoDirection = X;
1186  else if (direction(0) == 'y') logoDirection = Y;
1187  else if (direction(0) == 'z') logoDirection = Z;
1188  else if (direction(0) == '-') {
1189  if (direction(1) == 'x') logoDirection = minusX;
1190  else if (direction(1) == 'y') logoDirection = minusY;
1191  else if (direction(1) == 'z') logoDirection = minusZ;
1192  } else {
1193  if (verbosity >= G4VisManager::errors) {
1194  G4cout << "ERROR: Unrecogniseed direction: \""
1195  << direction << "\"." << G4endl;
1196  return;
1197  }
1198  }
1199 
1200  G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
1201  // Parameters read and interpreted.
1202 
1203  // Current scene extent
1204  const G4double xmin = sceneExtent.GetXmin();
1205  const G4double xmax = sceneExtent.GetXmax();
1206  const G4double ymin = sceneExtent.GetYmin();
1207  const G4double ymax = sceneExtent.GetYmax();
1208  const G4double zmin = sceneExtent.GetZmin();
1209  const G4double zmax = sceneExtent.GetZmax();
1210 
1211  // Test existing extent and issue warnings...
1212  G4bool worried = false;
1213  if (sceneExtent.GetExtentRadius() == 0) {
1214  worried = true;
1215  if (verbosity >= G4VisManager::warnings) {
1216  G4cout <<
1217  "WARNING: Existing scene does not yet have any extent."
1218  "\n Maybe you have not yet added any geometrical object."
1219  << G4endl;
1220  }
1221  }
1222 
1223  // Useful constants, etc...
1224  const G4double halfHeight(height / 2.);
1225  const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
1226  const G4double freeHeightFraction (1. + 2. * comfort);
1227 
1228  // Test existing scene for room...
1229  G4bool room = true;
1230  switch (logoDirection) {
1231  case X:
1232  case minusX:
1233  if (freeHeightFraction * (xmax - xmin) < height) room = false; break;
1234  case Y:
1235  case minusY:
1236  if (freeHeightFraction * (ymax - ymin) < height) room = false; break;
1237  case Z:
1238  case minusZ:
1239  if (freeHeightFraction * (zmax - zmin) < height) room = false; break;
1240  }
1241  if (!room) {
1242  worried = true;
1243  if (verbosity >= G4VisManager::warnings) {
1244  G4cout <<
1245  "WARNING: Not enough room in existing scene. Maybe logo is too large."
1246  << G4endl;
1247  }
1248  }
1249  if (worried) {
1250  if (verbosity >= G4VisManager::warnings) {
1251  G4cout <<
1252  "WARNING: The logo you have asked for is bigger than the existing"
1253  "\n scene. Maybe you have added it too soon. It is recommended that"
1254  "\n you add the logo last so that it can be correctly auto-positioned"
1255  "\n so as not to be obscured by any existing object and so that the"
1256  "\n view parameters can be correctly recalculated."
1257  << G4endl;
1258  }
1259  }
1260 
1261  G4double sxmid(xmid), symid(ymid), szmid(zmid);
1262  if (autoPlacing) {
1263  // Aim to place at bottom right of screen when viewed from logoDirection.
1264  // Give some comfort zone.
1265  const G4double xComfort = comfort * (xmax - xmin);
1266  const G4double yComfort = comfort * (ymax - ymin);
1267  const G4double zComfort = comfort * (zmax - zmin);
1268  switch (logoDirection) {
1269  case X: // y-axis up, z-axis to left?
1270  sxmid = xmax + halfHeight + xComfort;
1271  symid = ymin - yComfort;
1272  szmid = zmin - zComfort;
1273  break;
1274  case minusX: // y-axis up, z-axis to right?
1275  sxmid = xmin - halfHeight - xComfort;
1276  symid = ymin - yComfort;
1277  szmid = zmax + zComfort;
1278  break;
1279  case Y: // z-axis up, x-axis to left?
1280  sxmid = xmin - xComfort;
1281  symid = ymax + halfHeight + yComfort;
1282  szmid = zmin - zComfort;
1283  break;
1284  case minusY: // z-axis up, x-axis to right?
1285  sxmid = xmax + xComfort;
1286  symid = ymin - halfHeight - yComfort;
1287  szmid = zmin - zComfort;
1288  break;
1289  case Z: // y-axis up, x-axis to right?
1290  sxmid = xmax + xComfort;
1291  symid = ymin - yComfort;
1292  szmid = zmax + halfHeight + zComfort;
1293  break;
1294  case minusZ: // y-axis up, x-axis to left?
1295  sxmid = xmin - xComfort;
1296  symid = ymin - yComfort;
1297  szmid = zmin - halfHeight - zComfort;
1298  break;
1299  }
1300  }
1301 
1302  G4Transform3D transform;
1303  switch (logoDirection) {
1304  case X: // y-axis up, z-axis to left?
1305  transform = G4RotateY3D(halfpi);
1306  break;
1307  case minusX: // y-axis up, z-axis to right?
1308  transform = G4RotateY3D(-halfpi);
1309  break;
1310  case Y: // z-axis up, x-axis to left?
1311  transform = G4RotateX3D(-halfpi) * G4RotateZ3D(pi);
1312  break;
1313  case minusY: // z-axis up, x-axis to right?
1314  transform = G4RotateX3D(halfpi);
1315  break;
1316  case Z: // y-axis up, x-axis to right?
1317  // No transformation required.
1318  break;
1319  case minusZ: // y-axis up, x-axis to left?
1320  transform = G4RotateY3D(pi);
1321  break;
1322  }
1323  transform = G4Translate3D(sxmid,symid,szmid) * transform;
1324 
1325  G4VisAttributes visAtts(G4Colour(red, green, blue));
1326  visAtts.SetForceSolid(true); // Always solid.
1327 
1328  G4Logo* logo = new G4Logo(height,visAtts);
1329  G4VModel* model =
1331  model->SetType("G4Logo");
1332  model->SetGlobalTag("G4Logo");
1333  model->SetGlobalDescription("G4Logo: " + newValue);
1334  model->SetTransformation(transform);
1335  // Note: it is the responsibility of the model to act upon this, but
1336  // the extent is in local coordinates...
1337  G4double& h = height;
1338  G4double h2 = h/2.;
1339  G4VisExtent extent(-h,h,-h2,h2,-h2,h2);
1340  model->SetExtent(extent);
1341  // This extent gets "added" to existing scene extent in
1342  // AddRunDurationModel below.
1343  const G4String& currentSceneName = pScene -> GetName ();
1344  G4bool successful = pScene -> AddRunDurationModel (model, warn);
1345  if (successful) {
1346  if (verbosity >= G4VisManager::confirmations) {
1347  G4cout << "G4 Logo of height " << userHeight << ' ' << userHeightUnit
1348  << ", " << direction << "-direction, added to scene \""
1349  << currentSceneName << "\"";
1350  if (verbosity >= G4VisManager::parameters) {
1351  G4cout << "\n with extent " << extent
1352  << "\n at " << transform.getRotation()
1353  << transform.getTranslation();
1354  }
1355  G4cout << G4endl;
1356  }
1357  }
1358  else G4VisCommandsSceneAddUnsuccessful(verbosity);
1359  UpdateVisManagerScene (currentSceneName);
1360 }
1361 
1363 (G4double height, const G4VisAttributes& visAtts):
1364  fVisAtts(visAtts)
1365  {
1366  const G4double& h = height;
1367  const G4double h2 = 0.5 * h; // Half height.
1368  const G4double ri = 0.25 * h; // Inner radius.
1369  const G4double ro = 0.5 * h; // Outer radius.
1370  const G4double ro2 = 0.5 * ro; // Half outer radius.
1371  const G4double w = ro - ri; // Width.
1372  const G4double w2 = 0.5 * w; // Half width.
1373  const G4double d2 = 0.2 * h; // Half depth.
1374  const G4double f1 = 0.05 * h; // left edge of stem of "4".
1375  const G4double f2 = -0.3 * h; // bottom edge of cross of "4".
1376  const G4double e = 1.e-4 * h; // epsilon.
1377  const G4double xt = f1, yt = h2; // Top of slope.
1378  const G4double xb = -h2, yb = f2 + w; // Bottom of slope.
1379  const G4double dx = xt - xb, dy = yt - yb;
1380  const G4double angle = std::atan2(dy,dx);
1381  G4RotationMatrix rm;
1382  rm.rotateZ(angle*rad);
1383  const G4double d = std::sqrt(dx * dx + dy * dy);
1384  const G4double ss = h; // Half height of square subtractor
1385  const G4double y8 = ss; // Choose y of subtractor for outer slope.
1386  const G4double x8 = ((-ss * d - dx * (yt - y8)) / dy) + xt;
1387  G4double y9 = ss; // Choose y of subtractor for inner slope.
1388  G4double x9 = ((-(ss - w) * d - dx * (yt - y8)) / dy) + xt;
1389  // But to get inner, we make a triangle translated by...
1390  const G4double xtr = ss - f1, ytr = -ss - f2 -w;
1391  x9 += xtr; y9 += ytr;
1392 
1393  // G...
1394  G4Tubs tG("tG",ri,ro,d2,0.15*pi,1.85*pi);
1395  G4Box bG("bG",w2,ro2,d2);
1396  G4UnionSolid logoG("logoG",&tG,&bG,G4Translate3D(ri+w2,-ro2,0.));
1397  fpG = logoG.CreatePolyhedron();
1398  fpG->SetVisAttributes(&fVisAtts);
1399  fpG->Transform(G4Translate3D(-0.55*h,0.,0.));
1400 
1401  // 4...
1402  G4Box b1("b1",h2,h2,d2);
1403  G4Box bS("bS",ss,ss,d2+e); // Subtractor.
1404  G4Box bS2("bS2",ss,ss,d2+2.*e); // 2nd Subtractor.
1405  G4SubtractionSolid s1("s1",&b1,&bS,G4Translate3D(f1-ss,f2-ss,0.));
1406  G4SubtractionSolid s2("s2",&s1,&bS,G4Translate3D(f1+ss+w,f2-ss,0.));
1407  G4SubtractionSolid s3("s3",&s2,&bS,G4Translate3D(f1+ss+w,f2+ss+w,0.));
1409  ("s4",&s3,&bS,G4Transform3D(rm,G4ThreeVector(x8,y8,0.)));
1410  G4SubtractionSolid s5 // Triangular hole.
1411  ("s5",&bS,&bS2,G4Transform3D(rm,G4ThreeVector(x9,y9,0.)));
1412  G4SubtractionSolid logo4("logo4",&s4,&s5,G4Translate3D(-xtr,-ytr,0.));
1413  fp4 = logo4.CreatePolyhedron();
1414  /* Experiment with creating own polyhedron...
1415  int nNodes = 4;
1416  int nFaces = 4;
1417  double xyz[][3] = {{0,0,0},{1*m,0,0},{0,1*m,0},{0,0,1*m}};
1418  int faces[][4] = {{1,3,2,0},{1,2,4,0},{1,4,3,0},{2,3,4,0}};
1419  fp4 = new G4Polyhedron();
1420  fp4->createPolyhedron(nNodes,nFaces,xyz,faces);
1421  */
1422  fp4->SetVisAttributes(&fVisAtts);
1423  fp4->Transform(G4Translate3D(0.55*h,0.,0.));
1424 }
1425 
1427  delete fpG;
1428  delete fp4;
1429 }
1430 
1431 void G4VisCommandSceneAddLogo::G4Logo::operator()
1432  (G4VGraphicsScene& sceneHandler, const G4Transform3D& transform) {
1433  sceneHandler.BeginPrimitives(transform);
1434  sceneHandler.AddPrimitive(*fpG);
1435  sceneHandler.AddPrimitive(*fp4);
1436  sceneHandler.EndPrimitives();
1437 }
1438 
1440 
1442  G4bool omitable;
1443  fpCommand = new G4UIcommand ("/vis/scene/add/logo2D", this);
1444  fpCommand -> SetGuidance ("Adds 2D logo to current scene.");
1445  G4UIparameter* parameter;
1446  parameter = new G4UIparameter ("size", 'i', omitable = true);
1447  parameter -> SetGuidance ("Screen size of text in pixels.");
1448  parameter -> SetDefaultValue (48);
1449  fpCommand -> SetParameter (parameter);
1450  parameter = new G4UIparameter ("x-position", 'd', omitable = true);
1451  parameter -> SetGuidance ("x screen position in range -1 < x < 1.");
1452  parameter -> SetDefaultValue (-0.9);
1453  fpCommand -> SetParameter (parameter);
1454  parameter = new G4UIparameter ("y-position", 'd', omitable = true);
1455  parameter -> SetGuidance ("y screen position in range -1 < y < 1.");
1456  parameter -> SetDefaultValue (-0.9);
1457  fpCommand -> SetParameter (parameter);
1458  parameter = new G4UIparameter ("layout", 's', omitable = true);
1459  parameter -> SetGuidance ("Layout, i.e., adjustment: left|centre|right.");
1460  parameter -> SetDefaultValue ("left");
1461  fpCommand -> SetParameter (parameter);
1462 }
1463 
1465  delete fpCommand;
1466 }
1467 
1469  return "";
1470 }
1471 
1473 {
1475  G4bool warn(verbosity >= G4VisManager::warnings);
1476 
1477  G4Scene* pScene = fpVisManager->GetCurrentScene();
1478  if (!pScene) {
1479  if (verbosity >= G4VisManager::errors) {
1480  G4cout << "ERROR: No current scene. Please create one." << G4endl;
1481  }
1482  return;
1483  }
1484 
1485  G4int size;
1486  G4double x, y;
1487  G4String layoutString;
1488  std::istringstream is(newValue);
1489  is >> size >> x >> y >> layoutString;
1490  G4Text::Layout layout = G4Text::right;
1491  if (layoutString(0) == 'l') layout = G4Text::left;
1492  else if (layoutString(0) == 'c') layout = G4Text::centre;
1493  else if (layoutString(0) == 'r') layout = G4Text::right;
1494 
1495  Logo2D* logo2D = new Logo2D(fpVisManager, size, x, y, layout);
1496  G4VModel* model =
1498  model->SetType("G4Logo2D");
1499  model->SetGlobalTag("G4Logo2D");
1500  model->SetGlobalDescription("G4Logo2D: " + newValue);
1501  const G4String& currentSceneName = pScene -> GetName ();
1502  G4bool successful = pScene -> AddRunDurationModel (model, warn);
1503  if (successful) {
1504  if (verbosity >= G4VisManager::confirmations) {
1505  G4cout << "2D logo has been added to scene \""
1506  << currentSceneName << "\"."
1507  << G4endl;
1508  }
1509  }
1510  else G4VisCommandsSceneAddUnsuccessful(verbosity);
1511  UpdateVisManagerScene (currentSceneName);
1512 }
1513 
1514 void G4VisCommandSceneAddLogo2D::Logo2D::operator()
1515  (G4VGraphicsScene& sceneHandler, const G4Transform3D&)
1516 {
1517  G4Text text("Geant4", G4Point3D(fX, fY, 0.));
1518  text.SetScreenSize(fSize);
1519  text.SetLayout(fLayout);
1520  G4VisAttributes textAtts(G4Colour::Brown());
1521  text.SetVisAttributes(textAtts);
1522  sceneHandler.BeginPrimitives2D();
1523  sceneHandler.AddPrimitive(text);
1524  sceneHandler.EndPrimitives2D();
1525 }
1526 
1528 
1530  G4bool ommitable;
1531  fpCommand = new G4UIcmdWithAnInteger ("/vis/scene/add/magneticField", this);
1532  fpCommand->SetParameterName("nDataPointsPerHalfScene",ommitable=true);
1533  fpCommand->SetDefaultValue(10);
1534  fpCommand -> SetGuidance
1535  ("Adds magnetic field representation to current scene.");
1536  fpCommand -> SetGuidance
1537  ("The parameter is no. of data points per half scene. So, possibly, at"
1538  "\nmaximum, the number of data points sampled is (2*n+1)^3, which can grow"
1539  "\nlarge--be warned!"
1540  "\nYou might find that your scene is cluttered by thousands of arrows for"
1541  "\nthe default number of data points, so try reducing to 2 or 3, e.g:"
1542  "\n /vis/scene/add/magneticField 3"
1543  "\nor, if only a small part of the scene has a field:"
1544  "\n /vis/scene/add/magneticField 50 # or more");
1545  fpCommand -> SetGuidance
1546  ("In the arrow representation, the length of the arrow is proporational"
1547  "\nto the magnitude of the field and the colour is mapped onto the range"
1548  "\nas a fraction of the maximum magnitude: 0->0.5->1 is blue->green->red.");
1549 }
1550 
1552  delete fpCommand;
1553 }
1554 
1556  return "";
1557 }
1558 
1560 (G4UIcommand*, G4String newValue) {
1561 
1563  G4bool warn(verbosity >= G4VisManager::warnings);
1564 
1565  G4Scene* pScene = fpVisManager->GetCurrentScene();
1566  if (!pScene) {
1567  if (verbosity >= G4VisManager::errors) {
1568  G4cout << "ERROR: No current scene. Please create one." << G4endl;
1569  }
1570  return;
1571  }
1572 
1573  G4int nDataPointsPerHalfScene = fpCommand->GetNewIntValue(newValue);
1574 
1575  G4MagneticFieldModel* model =
1576  new G4MagneticFieldModel(nDataPointsPerHalfScene);
1577  const G4String& currentSceneName = pScene -> GetName ();
1578  G4bool successful = pScene -> AddRunDurationModel (model, warn);
1579  if (successful) {
1580  if (verbosity >= G4VisManager::confirmations) {
1581  G4cout << "Magnetic field, if any, will be drawn in scene \""
1582  << currentSceneName
1583  << "\"\n with "
1584  << nDataPointsPerHalfScene << " data points per half scene."
1585  << G4endl;
1586  }
1587  }
1588  else G4VisCommandsSceneAddUnsuccessful(verbosity);
1589  UpdateVisManagerScene (currentSceneName);
1590 }
1591 
1593 
1595  G4bool omitable;
1596  fpCommand = new G4UIcmdWithAString ("/vis/scene/add/psHits", this);
1597  fpCommand -> SetGuidance
1598  ("Adds Primitive Scorer Hits (PSHits) to current scene.");
1599  fpCommand -> SetGuidance
1600  ("PSHits are drawn at end of run when the scene in which"
1601  "\nthey are added is current.");
1602  fpCommand -> SetGuidance
1603  ("Optional parameter specifies name of scoring map. By default all"
1604  "\nscoring maps registered with the G4ScoringManager are drawn.");
1605  fpCommand -> SetParameterName ("mapname", omitable = true);
1606  fpCommand -> SetDefaultValue ("all");
1607 }
1608 
1610  delete fpCommand;
1611 }
1612 
1614  return "";
1615 }
1616 
1618 (G4UIcommand*, G4String newValue)
1619 {
1621  G4bool warn(verbosity >= G4VisManager::warnings);
1622 
1623  G4Scene* pScene = fpVisManager->GetCurrentScene();
1624  if (!pScene) {
1625  if (verbosity >= G4VisManager::errors) {
1626  G4cout << "ERROR: No current scene. Please create one." << G4endl;
1627  }
1628  return;
1629  }
1630 
1631  G4PSHitsModel* model = new G4PSHitsModel(newValue);
1632  const G4String& currentSceneName = pScene -> GetName ();
1633  G4bool successful = pScene -> AddEndOfRunModel (model, warn);
1634  if (successful) {
1635  if (verbosity >= G4VisManager::confirmations) {
1636  if (newValue == "all") {
1637  G4cout << "All Primitive Scorer hits";
1638  } else {
1639  G4cout << "Hits of Primitive Scorer \"" << newValue << '"';
1640  }
1641  G4cout << " will be drawn at end of run in scene \""
1642  << currentSceneName << "\"."
1643  << G4endl;
1644  }
1645  }
1646  else G4VisCommandsSceneAddUnsuccessful(verbosity);
1647  UpdateVisManagerScene (currentSceneName);
1648 }
1649 
1651 
1653  G4bool omitable;
1654  fpCommand = new G4UIcommand ("/vis/scene/add/scale", this);
1655  fpCommand -> SetGuidance
1656  ("Adds an annotated scale line to the current scene.");
1657  fpCommand -> SetGuidance
1658  ("If \"unit\" is \"auto\", length is roughly one tenth of the scene extent.");
1659  fpCommand -> SetGuidance
1660  ("If \"direction\" is \"auto\", scale is roughly in the plane of the current view.");
1661  fpCommand -> SetGuidance
1662  ("If \"placement\" is \"auto\", scale is placed at bottom left of current view."
1663  "\n Otherwise placed at (xmid,ymid,zmid).");
1664  fpCommand -> SetGuidance (G4Scale::GetGuidanceString());
1665  G4UIparameter* parameter;
1666  parameter = new G4UIparameter ("length", 'd', omitable = true);
1667  parameter->SetDefaultValue (1.);
1668  fpCommand->SetParameter (parameter);
1669  parameter = new G4UIparameter ("unit", 's', omitable = true);
1670  parameter->SetDefaultValue ("auto");
1671  fpCommand->SetParameter (parameter);
1672  parameter = new G4UIparameter ("direction", 's', omitable = true);
1673  parameter->SetGuidance ("auto|x|y|z");
1674  parameter->SetDefaultValue ("auto");
1675  fpCommand->SetParameter (parameter);
1676  parameter = new G4UIparameter ("red", 'd', omitable = true);
1677  parameter->SetDefaultValue (1.);
1678  fpCommand->SetParameter (parameter);
1679  parameter = new G4UIparameter ("green", 'd', omitable = true);
1680  parameter->SetDefaultValue (0.);
1681  fpCommand->SetParameter (parameter);
1682  parameter = new G4UIparameter ("blue", 'd', omitable = true);
1683  parameter->SetDefaultValue (0.);
1684  fpCommand->SetParameter (parameter);
1685  parameter = new G4UIparameter ("placement", 's', omitable = true);
1686  parameter -> SetParameterCandidates("auto manual");
1687  parameter->SetDefaultValue ("auto");
1688  fpCommand->SetParameter (parameter);
1689  parameter = new G4UIparameter ("xmid", 'd', omitable = true);
1690  parameter->SetDefaultValue (0.);
1691  fpCommand->SetParameter (parameter);
1692  parameter = new G4UIparameter ("ymid", 'd', omitable = true);
1693  parameter->SetDefaultValue (0.);
1694  fpCommand->SetParameter (parameter);
1695  parameter = new G4UIparameter ("zmid", 'd', omitable = true);
1696  parameter->SetDefaultValue (0.);
1697  fpCommand->SetParameter (parameter);
1698  parameter = new G4UIparameter ("unit", 's', omitable = true);
1699  parameter->SetDefaultValue ("m");
1700  fpCommand->SetParameter (parameter);
1701 }
1702 
1704  delete fpCommand;
1705 }
1706 
1708  return "";
1709 }
1710 
1712 
1714  G4bool warn = verbosity >= G4VisManager::warnings;
1715 
1716  G4Scene* pScene = fpVisManager->GetCurrentScene();
1717  if (!pScene) {
1718  if (verbosity >= G4VisManager::errors) {
1719  G4cout << "ERROR: No current scene. Please create one." << G4endl;
1720  }
1721  return;
1722  }
1723 
1724  G4double userLength, red, green, blue, xmid, ymid, zmid;
1725  G4String userLengthUnit, direction, auto_manual, positionUnit;
1726  std::istringstream is (newValue);
1727  is >> userLength >> userLengthUnit >> direction
1728  >> red >> green >> blue
1729  >> auto_manual
1730  >> xmid >> ymid >> zmid >> positionUnit;
1731 
1732  G4double length = userLength;
1733  const G4VisExtent& sceneExtent = pScene->GetExtent(); // Existing extent.
1734  if (userLengthUnit == "auto") {
1735  length *= sceneExtent.GetExtentRadius();
1736  G4double intLog10Length = std::floor(std::log10(length));
1737  length = std::pow(10,intLog10Length);
1738  } else {
1739  length *= G4UIcommand::ValueOf(userLengthUnit);
1740  }
1741  G4String annotation = G4BestUnit(length,"Length");
1742 
1743  G4double unit = G4UIcommand::ValueOf(positionUnit);
1744  xmid *= unit; ymid *= unit; zmid *= unit;
1745 
1746  G4Scale::Direction scaleDirection (G4Scale::x);
1747  if (direction(0) == 'y') scaleDirection = G4Scale::y;
1748  if (direction(0) == 'z') scaleDirection = G4Scale::z;
1749 
1750  G4VViewer* pViewer = fpVisManager->GetCurrentViewer();
1751  if (!pViewer) {
1752  if (verbosity >= G4VisManager::errors) {
1753  G4cout <<
1754  "ERROR: G4VisCommandSceneAddScale::SetNewValue: no viewer."
1755  "\n Auto direction needs a viewer."
1756  << G4endl;
1757  }
1758  return;
1759  }
1760 
1761  const G4Vector3D& vp =
1763  const G4Vector3D& up =
1764  pViewer->GetViewParameters().GetUpVector();
1765 
1766  if (direction == "auto") { // Takes cue from viewer.
1767  if (std::abs(vp.x()) > std::abs(vp.y()) &&
1768  std::abs(vp.x()) > std::abs(vp.z())) { // x viewpoint
1769  if (std::abs(up.y()) > std::abs(up.z())) scaleDirection = G4Scale::z;
1770  else scaleDirection = G4Scale::y;
1771  }
1772  else if (std::abs(vp.y()) > std::abs(vp.x()) &&
1773  std::abs(vp.y()) > std::abs(vp.z())) { // y viewpoint
1774  if (std::abs(up.x()) > std::abs(up.z())) scaleDirection = G4Scale::z;
1775  else scaleDirection = G4Scale::x;
1776  }
1777  else if (std::abs(vp.z()) > std::abs(vp.x()) &&
1778  std::abs(vp.z()) > std::abs(vp.y())) { // z viewpoint
1779  if (std::abs(up.y()) > std::abs(up.x())) scaleDirection = G4Scale::x;
1780  else scaleDirection = G4Scale::y;
1781  }
1782  }
1783 
1784  G4bool autoPlacing = false; if (auto_manual == "auto") autoPlacing = true;
1785  // Parameters read and interpreted.
1786 
1787  // Useful constants, etc...
1788  const G4double halfLength(length / 2.);
1789  const G4double comfort(0.01); // 0.15 seems too big. 0.05 might be better.
1790  const G4double freeLengthFraction (1. + 2. * comfort);
1791 
1792  const G4double xmin = sceneExtent.GetXmin();
1793  const G4double xmax = sceneExtent.GetXmax();
1794  const G4double ymin = sceneExtent.GetYmin();
1795  const G4double ymax = sceneExtent.GetYmax();
1796  const G4double zmin = sceneExtent.GetZmin();
1797  const G4double zmax = sceneExtent.GetZmax();
1798 
1799  // Test existing extent and issue warnings...
1800  G4bool worried = false;
1801  if (sceneExtent.GetExtentRadius() == 0) {
1802  worried = true;
1803  if (verbosity >= G4VisManager::warnings) {
1804  G4cout <<
1805  "WARNING: Existing scene does not yet have any extent."
1806  "\n Maybe you have not yet added any geometrical object."
1807  << G4endl;
1808  }
1809  }
1810  // Test existing scene for room...
1811  G4bool room = true;
1812  switch (scaleDirection) {
1813  case G4Scale::x:
1814  if (freeLengthFraction * (xmax - xmin) < length) room = false; break;
1815  case G4Scale::y:
1816  if (freeLengthFraction * (ymax - ymin) < length) room = false; break;
1817  case G4Scale::z:
1818  if (freeLengthFraction * (zmax - zmin) < length) room = false; break;
1819  }
1820  if (!room) {
1821  worried = true;
1822  if (verbosity >= G4VisManager::warnings) {
1823  G4cout <<
1824  "WARNING: Not enough room in existing scene. Maybe scale is too long."
1825  << G4endl;
1826  }
1827  }
1828  if (worried) {
1829  if (verbosity >= G4VisManager::warnings) {
1830  G4cout <<
1831  "WARNING: The scale you have asked for is bigger than the existing"
1832  "\n scene. Maybe you have added it too soon. It is recommended that"
1833  "\n you add the scale last so that it can be correctly auto-positioned"
1834  "\n so as not to be obscured by any existing object and so that the"
1835  "\n view parameters can be correctly recalculated."
1836  << G4endl;
1837  }
1838  }
1839 
1840  // Let's go ahead a construct a scale and a scale model. Since the
1841  // placing is done here, this G4Scale is *not* auto-placed...
1842  G4Scale scale(length, annotation, scaleDirection,
1843  false, xmid, ymid, zmid);
1844  G4VisAttributes* pVisAttr = new G4VisAttributes(G4Colour(red, green, blue));
1845  // Created of the heap because it needs a long lifetime. This is a
1846  // mess. The model determines the life but the vis atttributes are
1847  // associated with the scale. There's no way of knowing when to
1848  // delete the vis atttributes!!!
1849  scale.SetVisAttributes(pVisAttr);
1850  G4VModel* model = new G4ScaleModel(scale);
1851 
1852  // Now figure out the extent...
1853  //
1854  // From the G4Scale.hh:
1855  //
1856  // This creates a representation of annotated line in the specified
1857  // direction with tick marks at the end. If autoPlacing is true it
1858  // is required to be centred at the front, right, bottom corner of
1859  // the world space, comfortably outside the existing bounding
1860  // box/sphere so that existing objects do not obscure it. Otherwise
1861  // it is required to be drawn with mid-point at (xmid, ymid, zmid).
1862  //
1863  // The auto placing algorithm might be:
1864  // x = xmin + (1 + comfort) * (xmax - xmin)
1865  // y = ymin - comfort * (ymax - ymin)
1866  // z = zmin + (1 + comfort) * (zmax - zmin)
1867  // if direction == x then (x - length,y,z) to (x,y,z)
1868  // if direction == y then (x,y,z) to (x,y + length,z)
1869  // if direction == z then (x,y,z - length) to (x,y,z)
1870  //
1871  // End of clip from G4Scale.hh:
1872  //
1873  // Implement this in two parts. Here, use the scale's extent to
1874  // "expand" the scene's extent. Then rendering - in
1875  // G4VSceneHandler::AddPrimitive(const G4Scale&) - simply has to
1876  // ensure it's within the new extent.
1877  //
1878 
1879  G4double sxmid(xmid), symid(ymid), szmid(zmid);
1880  if (autoPlacing) {
1881  // Aim to place at bottom right of screen in current view.
1882  // Give some comfort zone.
1883  const G4double xComfort = comfort * (xmax - xmin);
1884  const G4double yComfort = comfort * (ymax - ymin);
1885  const G4double zComfort = comfort * (zmax - zmin);
1886  switch (scaleDirection) {
1887  case G4Scale::x:
1888  if (vp.z() > 0.) {
1889  sxmid = xmax + xComfort;
1890  symid = ymin - yComfort;
1891  szmid = zmin - zComfort;
1892  } else {
1893  sxmid = xmin - xComfort;
1894  symid = ymin - yComfort;
1895  szmid = zmax + zComfort;
1896  }
1897  break;
1898  case G4Scale::y:
1899  if (vp.x() > 0.) {
1900  sxmid = xmin - xComfort;
1901  symid = ymax + yComfort;
1902  szmid = zmin - zComfort;
1903  } else {
1904  sxmid = xmax + xComfort;
1905  symid = ymin - yComfort;
1906  szmid = zmin - zComfort;
1907  }
1908  break;
1909  case G4Scale::z:
1910  if (vp.x() > 0.) {
1911  sxmid = xmax + xComfort;
1912  symid = ymin - yComfort;
1913  szmid = zmax + zComfort;
1914  } else {
1915  sxmid = xmin - xComfort;
1916  symid = ymin - yComfort;
1917  szmid = zmax + zComfort;
1918  }
1919  break;
1920  }
1921  }
1922 
1923  /* Old code - kept for future reference.
1924  G4double sxmid(xmid), symid(ymid), szmid(zmid);
1925  if (autoPlacing) {
1926  sxmid = xmin + onePlusComfort * (xmax - xmin);
1927  symid = ymin - comfort * (ymax - ymin);
1928  szmid = zmin + onePlusComfort * (zmax - zmin);
1929  switch (scaleDirection) {
1930  case G4Scale::x:
1931  sxmid -= halfLength;
1932  break;
1933  case G4Scale::y:
1934  symid += halfLength;
1935  break;
1936  case G4Scale::z:
1937  szmid -= halfLength;
1938  break;
1939  }
1940  }
1941  */
1942 
1943  /* sxmin, etc., not actually used. Comment out to prevent compiler
1944  warnings but keep in case need in future. Extract transform and
1945  scaleExtent into reduced code below.
1946  G4double sxmin(sxmid), sxmax(sxmid);
1947  G4double symin(symid), symax(symid);
1948  G4double szmin(szmid), szmax(szmid);
1949  G4Transform3D transform;
1950  G4VisExtent scaleExtent;
1951  switch (scaleDirection) {
1952  case G4Scale::x:
1953  sxmin = sxmid - halfLength;
1954  sxmax = sxmid + halfLength;
1955  scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
1956  break;
1957  case G4Scale::y:
1958  symin = symid - halfLength;
1959  symax = symid + halfLength;
1960  transform = G4RotateZ3D(halfpi);
1961  scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
1962  break;
1963  case G4Scale::z:
1964  szmin = szmid - halfLength;
1965  szmax = szmid + halfLength;
1966  transform = G4RotateY3D(halfpi);
1967  scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
1968  break;
1969  }
1970  */
1971  G4Transform3D transform;
1972  G4VisExtent scaleExtent;
1973  switch (scaleDirection) {
1974  case G4Scale::x:
1975  scaleExtent = G4VisExtent(-halfLength,halfLength,0,0,0,0);
1976  break;
1977  case G4Scale::y:
1978  transform = G4RotateZ3D(halfpi);
1979  scaleExtent = G4VisExtent(0,0,-halfLength,halfLength,0,0);
1980  break;
1981  case G4Scale::z:
1982  transform = G4RotateY3D(halfpi);
1983  scaleExtent = G4VisExtent(0,0,0,0,-halfLength,halfLength);
1984  break;
1985  }
1986  transform = G4Translate3D(sxmid,symid,szmid) * transform;
1988 
1989 
1990  model->SetTransformation(transform);
1991  // Note: it is the responsibility of the model to act upon this, but
1992  // the extent is in local coordinates...
1993  model->SetExtent(scaleExtent);
1994  // This extent gets "added" to existing scene extent in
1995  // AddRunDurationModel below.
1996 
1997  const G4String& currentSceneName = pScene -> GetName ();
1998  G4bool successful = pScene -> AddRunDurationModel (model, warn);
1999  if (successful) {
2000  if (verbosity >= G4VisManager::confirmations) {
2001  G4cout << "Scale of " << annotation
2002  << " added to scene \"" << currentSceneName << "\".";
2003  if (verbosity >= G4VisManager::parameters) {
2004  G4cout << "\n with extent " << scaleExtent
2005  << "\n at " << transform.getRotation()
2006  << transform.getTranslation();
2007  }
2008  G4cout << G4endl;
2009  }
2010  }
2011  else G4VisCommandsSceneAddUnsuccessful(verbosity);
2012  UpdateVisManagerScene (currentSceneName);
2013 }
2014 
2015 
2017 
2019  G4bool omitable;
2020  fpCommand = new G4UIcommand ("/vis/scene/add/text", this);
2021  fpCommand -> SetGuidance ("Adds text to current scene.");
2022  fpCommand -> SetGuidance
2023  ("Use \"/vis/set/textColour\" to set colour.");
2024  fpCommand -> SetGuidance
2025  ("Use \"/vis/set/textLayout\" to set layout:");
2026  G4UIparameter* parameter;
2027  parameter = new G4UIparameter ("x", 'd', omitable = true);
2028  parameter->SetDefaultValue (0);
2029  fpCommand->SetParameter (parameter);
2030  parameter = new G4UIparameter ("y", 'd', omitable = true);
2031  parameter->SetDefaultValue (0);
2032  fpCommand->SetParameter (parameter);
2033  parameter = new G4UIparameter ("z", 'd', omitable = true);
2034  parameter->SetDefaultValue (0);
2035  fpCommand->SetParameter (parameter);
2036  parameter = new G4UIparameter ("unit", 's', omitable = true);
2037  parameter->SetDefaultValue ("m");
2038  fpCommand->SetParameter (parameter);
2039  parameter = new G4UIparameter ("font_size", 'd', omitable = true);
2040  parameter->SetDefaultValue (12);
2041  parameter->SetGuidance ("pixels");
2042  fpCommand->SetParameter (parameter);
2043  parameter = new G4UIparameter ("x_offset", 'd', omitable = true);
2044  parameter->SetDefaultValue (0);
2045  parameter->SetGuidance ("pixels");
2046  fpCommand->SetParameter (parameter);
2047  parameter = new G4UIparameter ("y_offset", 'd', omitable = true);
2048  parameter->SetDefaultValue (0);
2049  parameter->SetGuidance ("pixels");
2050  fpCommand->SetParameter (parameter);
2051  parameter = new G4UIparameter ("text", 's', omitable = true);
2052  parameter->SetGuidance ("The rest of the line is text.");
2053  parameter->SetDefaultValue ("Hello G4");
2054  fpCommand->SetParameter (parameter);
2055 }
2056 
2058  delete fpCommand;
2059 }
2060 
2062  return "";
2063 }
2064 
2066 
2068  G4bool warn = verbosity >= G4VisManager::warnings;
2069 
2070  G4Scene* pScene = fpVisManager->GetCurrentScene();
2071  if (!pScene) {
2072  if (verbosity >= G4VisManager::errors) {
2073  G4cout << "ERROR: No current scene. Please create one." << G4endl;
2074  }
2075  return;
2076  }
2077 
2078  G4Tokenizer next(newValue);
2079  G4double x = StoD(next());
2080  G4double y = StoD(next());
2081  G4double z = StoD(next());
2082  G4String unitString = next();
2083  G4double font_size = StoD(next());
2084  G4double x_offset = StoD(next());
2085  G4double y_offset = StoD(next());
2086  G4String text = next("\n");
2087 
2088  G4double unit = G4UIcommand::ValueOf(unitString);
2089  x *= unit; y *= unit; z *= unit;
2090 
2091  G4Text g4text(text, G4Point3D(x,y,z));
2093  g4text.SetVisAttributes(visAtts);
2094  g4text.SetLayout(fCurrentTextLayout);
2095  g4text.SetScreenSize(font_size);
2096  g4text.SetOffset(x_offset,y_offset);
2097  G4VModel* model = new G4TextModel(g4text);
2098  const G4String& currentSceneName = pScene -> GetName ();
2099  G4bool successful = pScene -> AddRunDurationModel (model, warn);
2100  if (successful) {
2101  if (verbosity >= G4VisManager::confirmations) {
2102  G4cout << "Text \"" << text
2103  << "\" has been added to scene \"" << currentSceneName << "\"."
2104  << G4endl;
2105  }
2106  }
2107  else G4VisCommandsSceneAddUnsuccessful(verbosity);
2108  UpdateVisManagerScene (currentSceneName);
2109 }
2110 
2111 
2113 
2115  G4bool omitable;
2116  fpCommand = new G4UIcommand ("/vis/scene/add/text2D", this);
2117  fpCommand -> SetGuidance ("Adds 2D text to current scene.");
2118  fpCommand -> SetGuidance
2119  ("Use \"/vis/set/textColour\" to set colour.");
2120  fpCommand -> SetGuidance
2121  ("Use \"/vis/set/textLayout\" to set layout:");
2122  G4UIparameter* parameter;
2123  parameter = new G4UIparameter ("x", 'd', omitable = true);
2124  parameter->SetDefaultValue (0);
2125  fpCommand->SetParameter (parameter);
2126  parameter = new G4UIparameter ("y", 'd', omitable = true);
2127  parameter->SetDefaultValue (0);
2128  fpCommand->SetParameter (parameter);
2129  parameter = new G4UIparameter ("font_size", 'd', omitable = true);
2130  parameter->SetDefaultValue (12);
2131  parameter->SetGuidance ("pixels");
2132  fpCommand->SetParameter (parameter);
2133  parameter = new G4UIparameter ("x_offset", 'd', omitable = true);
2134  parameter->SetDefaultValue (0);
2135  parameter->SetGuidance ("pixels");
2136  fpCommand->SetParameter (parameter);
2137  parameter = new G4UIparameter ("y_offset", 'd', omitable = true);
2138  parameter->SetDefaultValue (0);
2139  parameter->SetGuidance ("pixels");
2140  fpCommand->SetParameter (parameter);
2141  parameter = new G4UIparameter ("text", 's', omitable = true);
2142  parameter->SetGuidance ("The rest of the line is text.");
2143  parameter->SetDefaultValue ("Hello G4");
2144  fpCommand->SetParameter (parameter);
2145 }
2146 
2148  delete fpCommand;
2149 }
2150 
2152  return "";
2153 }
2154 
2156 
2158  G4bool warn = verbosity >= G4VisManager::warnings;
2159 
2160  G4Scene* pScene = fpVisManager->GetCurrentScene();
2161  if (!pScene) {
2162  if (verbosity >= G4VisManager::errors) {
2163  G4cout << "ERROR: No current scene. Please create one." << G4endl;
2164  }
2165  return;
2166  }
2167 
2168  G4Tokenizer next(newValue);
2169  G4double x = StoD(next());
2170  G4double y = StoD(next());
2171  G4double font_size = StoD(next());
2172  G4double x_offset = StoD(next());
2173  G4double y_offset = StoD(next());
2174  G4String text = next("\n");
2175 
2176  G4Text g4text(text, G4Point3D(x,y,0.));
2178  g4text.SetVisAttributes(visAtts);
2179  g4text.SetLayout(fCurrentTextLayout);
2180  g4text.SetScreenSize(font_size);
2181  g4text.SetOffset(x_offset,y_offset);
2182  G4Text2D* g4text2D = new G4Text2D(g4text);
2183  G4VModel* model =
2185  model->SetType("Text2D");
2186  model->SetGlobalTag("Text2D");
2187  model->SetGlobalDescription("Text2D: " + newValue);
2188  const G4String& currentSceneName = pScene -> GetName ();
2189  G4bool successful = pScene -> AddRunDurationModel (model, warn);
2190  if (successful) {
2191  if (verbosity >= G4VisManager::confirmations) {
2192  G4cout << "2D text \"" << text
2193  << "\" has been added to scene \"" << currentSceneName << "\"."
2194  << G4endl;
2195  }
2196  }
2197  else G4VisCommandsSceneAddUnsuccessful(verbosity);
2198  UpdateVisManagerScene (currentSceneName);
2199 }
2200 
2202  fText(text)
2203 {}
2204 
2205 void G4VisCommandSceneAddText2D::G4Text2D::operator()
2206  (G4VGraphicsScene& sceneHandler, const G4Transform3D& transform) {
2207  sceneHandler.BeginPrimitives2D(transform);
2208  sceneHandler.AddPrimitive(fText);
2209  sceneHandler.EndPrimitives2D();
2210 }
2211 
2212 
2214 
2216  G4bool omitable;
2218  ("/vis/scene/add/trajectories", this);
2219  fpCommand -> SetGuidance
2220  ("Adds trajectories to current scene.");
2221  fpCommand -> SetGuidance
2222  ("Causes trajectories, if any, to be drawn at the end of processing an"
2223  "\nevent. Switches on trajectory storing and sets the"
2224  "\ndefault trajectory type.");
2225  fpCommand -> SetGuidance
2226  ("The command line parameter list determines the default trajectory type."
2227  "\nIf it contains the string \"smooth\", auxiliary inter-step points will"
2228  "\nbe inserted to improve the smoothness of the drawing of a curved"
2229  "\ntrajectory."
2230  "\nIf it contains the string \"rich\", significant extra information will"
2231  "\nbe stored in the trajectory (G4RichTrajectory) amenable to modeling"
2232  "\nand filtering with \"/vis/modeling/trajectories/create/drawByAttribute\""
2233  "\nand \"/vis/filtering/trajectories/create/attributeFilter\" commands."
2234  "\nIt may contain both strings in any order.");
2235  fpCommand -> SetGuidance
2236  ("\nTo switch off trajectory storing: \"/tracking/storeTrajectory 0\"."
2237  "\nSee also \"/vis/scene/endOfEventAction\".");
2238  fpCommand -> SetGuidance
2239  ("Note: This only sets the default. Independently of the result of this"
2240  "\ncommand, a user may instantiate a trajectory that overrides this default"
2241  "\nin PreUserTrackingAction.");
2242  fpCommand -> SetParameterName ("default-trajectory-type", omitable = true);
2243  fpCommand -> SetDefaultValue ("");
2244 }
2245 
2247  delete fpCommand;
2248 }
2249 
2251  return "";
2252 }
2253 
2255  G4String newValue) {
2256 
2258  G4bool warn = verbosity >= G4VisManager::warnings;
2259 
2260  G4Scene* pScene = fpVisManager->GetCurrentScene();
2261  if (!pScene) {
2262  if (verbosity >= G4VisManager::errors) {
2263  G4cout << "ERROR: No current scene. Please create one." << G4endl;
2264  }
2265  return;
2266  }
2267 
2268  G4bool smooth = false;
2269  G4bool rich = false;
2270  if (newValue.find("smooth") != std::string::npos) smooth = true;
2271  if (newValue.find("rich") != std::string::npos) rich = true;
2272  if (newValue.size() && !(rich || smooth)) {
2273  if (verbosity >= G4VisManager::errors) {
2274  G4cout << "ERROR: Unrecognised parameter \"" << newValue << "\""
2275  "\n No action taken."
2276  << G4endl;
2277  }
2278  return;
2279  }
2280 
2281  G4UImanager* UImanager = G4UImanager::GetUIpointer();
2282  G4int keepVerbose = UImanager->GetVerboseLevel();
2283  G4int newVerbose = 2;
2284  UImanager->SetVerboseLevel(newVerbose);
2285  G4String defaultTrajectoryType;
2286  if (smooth && rich) {
2287  UImanager->ApplyCommand("/tracking/storeTrajectory 4");
2288  defaultTrajectoryType = "G4RichTrajectory configured for smooth steps";
2289  } else if (smooth) {
2290  UImanager->ApplyCommand("/tracking/storeTrajectory 2");
2291  defaultTrajectoryType = "G4SmoothTrajectory";
2292  } else if (rich) {
2293  UImanager->ApplyCommand("/tracking/storeTrajectory 3");
2294  defaultTrajectoryType = "G4RichTrajectory";
2295  } else {
2296  UImanager->ApplyCommand("/tracking/storeTrajectory 1");
2297  defaultTrajectoryType = "G4Trajectory";
2298  }
2299  UImanager->SetVerboseLevel(keepVerbose);
2300 
2301  if (verbosity >= G4VisManager::errors) {
2302  G4cout <<
2303  "Attributes available for modeling and filtering with"
2304  "\n \"/vis/modeling/trajectories/create/drawByAttribute\" and"
2305  "\n \"/vis/filtering/trajectories/create/attributeFilter\" commands:"
2306  << G4endl;
2308  if (rich) {
2311  } else if (smooth) {
2314  } else {
2317  }
2318  }
2319 
2321  const G4String& currentSceneName = pScene -> GetName ();
2322  pScene -> AddEndOfEventModel (model, warn);
2323 
2324  if (verbosity >= G4VisManager::confirmations) {
2325  G4cout << "Default trajectory type " << defaultTrajectoryType
2326  << "\n will be used to store trajectories for scene \""
2327  << currentSceneName << "\"."
2328  << G4endl;
2329  }
2330 
2331  if (verbosity >= G4VisManager::warnings) {
2332  G4cout <<
2333  "WARNING: Trajectory storing has been requested. This action may be"
2334  "\n reversed with \"/tracking/storeTrajectory 0\"."
2335  << G4endl;
2336  }
2337  UpdateVisManagerScene (currentSceneName);
2338 }
2339 
2341 
2343  G4bool omitable;
2344  fpCommand = new G4UIcmdWithAString("/vis/scene/add/userAction",this);
2345  fpCommand -> SetGuidance
2346  ("Add named Vis User Action to current scene.");
2347  fpCommand -> SetGuidance
2348  ("Attempts to match search string to name of action - use unique sub-string.");
2349  fpCommand -> SetGuidance
2350  ("(Use /vis/list to see names of registered actions.)");
2351  fpCommand -> SetGuidance
2352  ("If name == \"all\" (default), all actions are added.");
2353  fpCommand -> SetParameterName("action-name", omitable = true);
2354  fpCommand -> SetDefaultValue("all");
2355 }
2356 
2358  delete fpCommand;
2359 }
2360 
2362  return "";
2363 }
2364 
2366 (G4UIcommand*, G4String newValue) {
2367 
2369 
2370  G4Scene* pScene = fpVisManager->GetCurrentScene();
2371  if (!pScene) {
2372  if (verbosity >= G4VisManager::errors) {
2373  G4cout << "ERROR: No current scene. Please create one." << G4endl;
2374  }
2375  return;
2376  }
2377 
2378  G4bool any = false;
2379 
2380  const std::vector<G4VisManager::UserVisAction>& runDurationUserVisActions =
2382  for (size_t i = 0; i < runDurationUserVisActions.size(); i++) {
2383  const G4String& name = runDurationUserVisActions[i].fName;
2384  G4VUserVisAction* visAction = runDurationUserVisActions[i].fpUserVisAction;
2385  if (newValue == "all" || name.find(newValue) != std::string::npos) {
2386  any = true;
2387  AddVisAction(name,visAction,pScene,runDuration,verbosity);
2388  }
2389  }
2390 
2391  const std::vector<G4VisManager::UserVisAction>& endOfEventUserVisActions =
2393  for (size_t i = 0; i < endOfEventUserVisActions.size(); i++) {
2394  const G4String& name = endOfEventUserVisActions[i].fName;
2395  G4VUserVisAction* visAction = endOfEventUserVisActions[i].fpUserVisAction;
2396  if (newValue == "all" || name.find(newValue) != std::string::npos) {
2397  any = true;
2398  AddVisAction(name,visAction,pScene,endOfEvent,verbosity);
2399  }
2400  }
2401 
2402  const std::vector<G4VisManager::UserVisAction>& endOfRunUserVisActions =
2404  for (size_t i = 0; i < endOfRunUserVisActions.size(); i++) {
2405  const G4String& name = endOfRunUserVisActions[i].fName;
2406  G4VUserVisAction* visAction = endOfRunUserVisActions[i].fpUserVisAction;
2407  if (newValue == "all" || name.find(newValue) != std::string::npos) {
2408  any = true;
2409  AddVisAction(name,visAction,pScene,endOfRun,verbosity);
2410  }
2411  }
2412 
2413  if (!any) {
2414  if (verbosity >= G4VisManager::warnings) {
2415  G4cout << "WARNING: No User Vis Action registered." << G4endl;
2416  }
2417  return;
2418  }
2419 
2420  const G4String& currentSceneName = pScene -> GetName ();
2421  UpdateVisManagerScene (currentSceneName);
2422 }
2423 
2425 (const G4String& name,
2426  G4VUserVisAction* visAction,
2427  G4Scene* pScene,
2429  G4VisManager::Verbosity verbosity)
2430 {
2431  G4bool warn = verbosity >= G4VisManager::warnings;
2432 
2433  const std::map<G4VUserVisAction*,G4VisExtent>& visExtentMap =
2435  G4VisExtent extent;
2436  std::map<G4VUserVisAction*,G4VisExtent>::const_iterator i =
2437  visExtentMap.find(visAction);
2438  if (i != visExtentMap.end()) extent = i->second;
2439  if (warn) {
2440  if (extent.GetExtentRadius() <= 0.) {
2441  G4cout << "WARNING: User Vis Action extent is null." << G4endl;
2442  }
2443  }
2444 
2445  G4VModel* model = new G4CallbackModel<G4VUserVisAction>(visAction);
2446  model->SetType("User Vis Action");
2447  model->SetGlobalTag(name);
2448  model->SetGlobalDescription(name);
2449  model->SetExtent(extent);
2450  G4bool successful = false;;
2451  switch (type) {
2452  case runDuration:
2453  successful = pScene -> AddRunDurationModel (model, warn);
2454  break;
2455  case endOfEvent:
2456  successful = pScene -> AddEndOfEventModel (model, warn);
2457  break;
2458  case endOfRun:
2459  successful = pScene -> AddEndOfRunModel (model, warn);
2460  break;
2461  }
2462  if (successful && verbosity >= G4VisManager::confirmations) {
2463  const G4String& currentSceneName = pScene -> GetName ();
2464  G4cout << "User Vis Action added to scene \""
2465  << currentSceneName << "\"";
2466  if (verbosity >= G4VisManager::parameters) {
2467  G4cout << "\n with extent " << extent;
2468  }
2469  G4cout << G4endl;
2470  }
2471 }
2472 
2474 
2476  G4bool omitable;
2477  fpCommand = new G4UIcommand ("/vis/scene/add/volume", this);
2478  fpCommand -> SetGuidance
2479  ("Adds a physical volume to current scene, with optional clipping volume.");
2480  fpCommand -> SetGuidance
2481  ("If physical-volume-name is \"world\" (the default), the top of the"
2482  "\nmain geometry tree (material world) is added. If \"worlds\", the"
2483  "\ntop of all worlds - material world and parallel worlds, if any - are"
2484  "\nadded. Otherwise a search of all worlds is made, taking the first"
2485  "\nmatching occurence only. To see a representation of the geometry"
2486  "\nhierarchy of the worlds, try \"/vis/drawTree [worlds]\" or one of the"
2487  "\ndriver/browser combinations that have the required functionality, e.g., HepRep.");
2488  fpCommand -> SetGuidance
2489  ("If clip-volume-type is specified, the subsequent parameters are used to"
2490  "\nto define a clipping volume. For example,"
2491  "\n\"vis/scene/add/volume ! ! ! -box km 0 1 0 1 0 1\" will draw the world"
2492  "\nwith the positive octant cut away.");
2493  fpCommand -> SetGuidance
2494  ("If clip-volume-type is prepended with '-', the clip-volume is subtracted"
2495  "\n(cutaway). (This is the default if there is no prepended character.)"
2496  "\nIf '*' is prepended, the intersection of the physical-volume and the"
2497  "\nclip-volume is made. (You can make a section/DCUT with a thin box, for"
2498  "\nexample).");
2499  fpCommand -> SetGuidance
2500  ("For \"box\", the parameters are xmin,xmax,ymin,ymax,zmin,zmax."
2501  "\nOnly \"box\" is programmed at present.");
2502  G4UIparameter* parameter;
2503  parameter = new G4UIparameter ("physical-volume-name", 's', omitable = true);
2504  parameter -> SetDefaultValue ("world");
2505  fpCommand -> SetParameter (parameter);
2506  parameter = new G4UIparameter ("copy-no", 'i', omitable = true);
2507  parameter -> SetGuidance
2508  ("If negative, matches any copy no. First name match is taken.");
2509  parameter -> SetDefaultValue (-1);
2510  fpCommand -> SetParameter (parameter);
2511  parameter = new G4UIparameter ("depth-of-descent", 'i', omitable = true);
2512  parameter -> SetGuidance
2513  ("Depth of descent of geometry hierarchy. Default = unlimited depth.");
2514  parameter -> SetDefaultValue (G4Scene::UNLIMITED);
2515  fpCommand -> SetParameter (parameter);
2516  parameter = new G4UIparameter ("clip-volume-type", 's', omitable = true);
2517  parameter -> SetParameterCandidates("none box -box *box");
2518  parameter -> SetDefaultValue ("none");
2519  parameter -> SetGuidance("[-|*]type. See general guidance.");
2520  fpCommand -> SetParameter (parameter);
2521  parameter = new G4UIparameter ("parameter-unit", 's', omitable = true);
2522  parameter -> SetDefaultValue ("m");
2523  fpCommand -> SetParameter (parameter);
2524  parameter = new G4UIparameter ("parameter-1", 'd', omitable = true);
2525  parameter -> SetDefaultValue (0.);
2526  fpCommand -> SetParameter (parameter);
2527  parameter = new G4UIparameter ("parameter-2", 'd', omitable = true);
2528  parameter -> SetDefaultValue (0.);
2529  fpCommand -> SetParameter (parameter);
2530  parameter = new G4UIparameter ("parameter-3", 'd', omitable = true);
2531  parameter -> SetDefaultValue (0.);
2532  fpCommand -> SetParameter (parameter);
2533  parameter = new G4UIparameter ("parameter-4", 'd', omitable = true);
2534  parameter -> SetDefaultValue (0.);
2535  fpCommand -> SetParameter (parameter);
2536  parameter = new G4UIparameter ("parameter-5", 'd', omitable = true);
2537  parameter -> SetDefaultValue (0.);
2538  fpCommand -> SetParameter (parameter);
2539  parameter = new G4UIparameter ("parameter-6", 'd', omitable = true);
2540  parameter -> SetDefaultValue (0.);
2541  fpCommand -> SetParameter (parameter);
2542 }
2543 
2545  delete fpCommand;
2546 }
2547 
2549  return "world 0 -1";
2550 }
2551 
2553  G4String newValue) {
2554 
2556  G4bool warn = verbosity >= G4VisManager::warnings;
2557 
2558  G4Scene* pScene = fpVisManager->GetCurrentScene();
2559  if (!pScene) {
2560  if (verbosity >= G4VisManager::errors) {
2561  G4cout << "ERROR: No current scene. Please create one." << G4endl;
2562  }
2563  return;
2564  }
2565 
2566  G4String name, clipVolumeType, parameterUnit;
2567  G4int copyNo, requestedDepthOfDescent;
2568  G4double param1, param2, param3, param4, param5, param6;
2569  std::istringstream is (newValue);
2570  is >> name >> copyNo >> requestedDepthOfDescent
2571  >> clipVolumeType >> parameterUnit
2572  >> param1 >> param2 >> param3 >> param4 >> param5 >> param6;
2574  G4PhysicalVolumeModel::subtraction; // Default subtraction mode.
2575  if (clipVolumeType[size_t(0)] == '-') {
2576  clipVolumeType = clipVolumeType.substr(1); // Remove first character.
2577  } else if (clipVolumeType[size_t(0)] == '*') {
2578  clippingMode = G4PhysicalVolumeModel::intersection;
2579  clipVolumeType = clipVolumeType.substr(1);
2580  }
2581  G4double unit = G4UIcommand::ValueOf(parameterUnit);
2582  param1 *= unit; param2 *= unit; param3 *= unit;
2583  param4 *= unit; param5 *= unit; param6 *= unit;
2584 
2585  G4TransportationManager* transportationManager =
2587 
2588  size_t nWorlds = transportationManager->GetNoWorlds();
2589  if (nWorlds > 1) { // Parallel worlds in operation...
2590  if (verbosity >= G4VisManager::warnings) {
2591  static G4bool warned = false;
2592  if (!warned && name != "worlds") {
2593  G4cout <<
2594  "WARNING: Parallel worlds in operation. To visualise, specify"
2595  "\n \"worlds\" or the parallel world volume or sub-volume name"
2596  "\n and control visibility with /vis/geometry."
2597  << G4endl;
2598  std::vector<G4VPhysicalVolume*>::iterator iterWorld =
2599  transportationManager->GetWorldsIterator();
2600  for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
2601  G4cout << " World " << i << ": " << (*iterWorld)->GetName()
2602  << G4endl;
2603  warned = true;
2604  }
2605  }
2606  }
2607  }
2608 
2609  G4VPhysicalVolume* world = *(transportationManager->GetWorldsIterator());
2610 
2611  if (!world) {
2612  if (verbosity >= G4VisManager::errors) {
2613  G4cout <<
2614  "ERROR: G4VisCommandSceneAddVolume::SetNewValue:"
2615  "\n No world. Maybe the geometry has not yet been defined."
2616  "\n Try \"/run/initialize\""
2617  << G4endl;
2618  }
2619  return;
2620  }
2621 
2622  const std::vector<G4Scene::Model>& rdModelList = pScene -> GetRunDurationModelList();
2623  std::vector<G4Scene::Model>::const_iterator it;
2624  for (it = rdModelList.begin(); it != rdModelList.end(); ++it) {
2625  if (it->fpModel->GetGlobalDescription().find("G4PhysicalVolumeModel")
2626  != std::string::npos) {
2627  if (((G4PhysicalVolumeModel*)(it->fpModel))->GetTopPhysicalVolume () == world) break;
2628  }
2629  }
2630  if (it != rdModelList.end()) {
2631  if (verbosity >= G4VisManager::warnings) {
2632  G4cout << "WARNING: There is already a volume, \""
2633  << it -> fpModel -> GetGlobalDescription()
2634  << "\",\n in the run-duration model list of scene \""
2635  << pScene -> GetName()
2636  << "\".\n To get a clean scene:"
2637  << "\n /vis/drawVolume " << name
2638  << "\n or"
2639  << "\n /vis/scene/create"
2640  << "\n /vis/scene/add/volume " << name
2641  << "\n /vis/sceneHandler/attach"
2642  << "\n (and also, if necessary, /vis/viewer/flush)"
2643  << G4endl;
2644  }
2645  return;
2646  }
2647 
2648  std::vector<G4PhysicalVolumeModel*> models;
2649  std::vector<G4VPhysicalVolume*> foundVolumes;
2650  G4VPhysicalVolume* foundWorld = 0;
2652  typedef std::vector<PVNodeID> PVPath;
2653  PVPath foundFullPVPath;
2654  std::vector<G4int> foundDepths;
2655  std::vector<G4Transform3D> transformations;
2656 
2657  if (name == "world") {
2658 
2659  models.push_back
2660  (new G4PhysicalVolumeModel (world, requestedDepthOfDescent));
2661  foundVolumes.push_back(world);
2662  foundDepths.push_back(0);
2663  transformations.push_back(G4Transform3D());
2664 
2665  } else if (name == "worlds") {
2666 
2667  if (nWorlds == 0) {
2668  if (verbosity >= G4VisManager::warnings) {
2669  G4cout <<
2670  "WARNING: G4VisCommandSceneAddVolume::SetNewValue:"
2671  "\n Parallel worlds requested but none exist."
2672  "\n Just adding material world."
2673  << G4endl;
2674  }
2675  }
2676  std::vector<G4VPhysicalVolume*>::iterator iterWorld =
2677  transportationManager->GetWorldsIterator();
2678  for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
2679  models.push_back
2680  (new G4PhysicalVolumeModel (*iterWorld, requestedDepthOfDescent));
2681  foundVolumes.push_back(*iterWorld);
2682  foundDepths.push_back(0);
2683  transformations.push_back(G4Transform3D());
2684  }
2685 
2686  } else { // Search all worlds...
2687 
2688  std::vector<G4VPhysicalVolume*>::iterator iterWorld =
2689  transportationManager->GetWorldsIterator();
2690  for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
2691  G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth.
2692  G4ModelingParameters mp; // Default - no culling.
2693  searchModel.SetModelingParameters (&mp);
2694  G4PhysicalVolumeSearchScene searchScene (&searchModel, name, copyNo);
2695  searchModel.DescribeYourselfTo (searchScene); // Initiate search.
2696  G4VPhysicalVolume* foundVolume = searchScene.GetFoundVolume ();
2697  if (foundVolume) {
2698  foundWorld = *iterWorld;
2699  foundVolumes.push_back(foundVolume);
2700  foundFullPVPath = searchScene.GetFoundFullPVPath();
2701  foundDepths.push_back(searchScene.GetFoundDepth());
2702  transformations.push_back(searchScene.GetFoundTransformation());
2703  break;
2704  }
2705  }
2706 
2707  if (foundVolumes.size()) {
2708  for (size_t i = 0; i < foundVolumes.size(); ++i) {
2709  G4PhysicalVolumeModel* foundPVModel = new G4PhysicalVolumeModel
2710  (foundVolumes[i], requestedDepthOfDescent, transformations[i]);
2711  foundFullPVPath.pop_back(); // "Base" is "Found - 1".
2712  foundPVModel->SetBaseFullPVPath(foundFullPVPath);
2713  models.push_back(foundPVModel);
2714  }
2715  } else {
2716  if (verbosity >= G4VisManager::errors) {
2717  G4cout << "ERROR: Volume \"" << name << "\"";
2718  if (copyNo >= 0) {
2719  G4cout << ", copy no. " << copyNo << ",";
2720  }
2721  G4cout << " not found." << G4endl;
2722  }
2723  return;
2724  }
2725  }
2726 
2727  if (clipVolumeType == "box") {
2728  const G4double dX = (param2 - param1) / 2.;
2729  const G4double dY = (param4 - param3) / 2.;
2730  const G4double dZ = (param6 - param5) / 2.;
2731  const G4double x0 = (param2 + param1) / 2.;
2732  const G4double y0 = (param4 + param3) / 2.;
2733  const G4double z0 = (param6 + param5) / 2.;
2734  G4VSolid* clippingSolid =
2735  new G4DisplacedSolid
2736  ("_displaced_clipping_box",
2737  new G4Box("_clipping_box",dX,dY,dZ),
2738  G4Translate3D(x0,y0,z0));
2739  for (size_t i = 0; i < foundVolumes.size(); ++i) {
2740  models[i]->SetClippingSolid(clippingSolid);
2741  models[i]->SetClippingMode(clippingMode);
2742  }
2743  } // If any other shape consider NumberOfRotationSides!!!!!!!!!!!
2744 
2745  const G4String& currentSceneName = pScene -> GetName ();
2746  G4bool failure = true;
2747  for (size_t i = 0; i < foundVolumes.size(); ++i) {
2748  G4bool successful = pScene -> AddRunDurationModel (models[i], warn);
2749  if (successful) {
2750  failure = false;
2751  if (verbosity >= G4VisManager::confirmations) {
2752  G4cout << "First occurrence of \""
2753  << foundVolumes[i] -> GetName ()
2754  << "\"";
2755  if (copyNo >= 0) {
2756  G4cout << ", copy no. " << copyNo << ",";
2757  }
2758  G4cout << "\n found ";
2759  if (foundWorld)
2760  G4cout << "in world \"" << foundWorld->GetName() << "\" ";
2761  G4cout << "at depth " << foundDepths[i]
2762  << ",\n with a requested depth of further descent of ";
2763  if (requestedDepthOfDescent < 0) {
2764  G4cout << "<0 (unlimited)";
2765  }
2766  else {
2767  G4cout << requestedDepthOfDescent;
2768  }
2769  G4cout << ",\n has been added to scene \"" << currentSceneName << "\"."
2770  << G4endl;
2771  }
2772  }
2773  }
2774 
2775  if (failure) {
2777  return;
2778  }
2779 
2780  UpdateVisManagerScene (currentSceneName);
2781 }
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4String GetCurrentValue(G4UIcommand *command)
void SetColour(const G4Colour &)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4Logo(G4double height, const G4VisAttributes &)
void SetGlobalTag(const G4String &)
void SetNewValue(G4UIcommand *command, G4String newValue)
HepGeom::RotateX3D G4RotateX3D
Definition: G4Text.hh:73
G4String GetCurrentValue(G4UIcommand *command)
HepGeom::RotateY3D G4RotateY3D
Definition: test07.cc:36
G4double GetXmin() const
Definition: G4VisExtent.hh:89
static const G4double f2
CLHEP::Hep3Vector G4ThreeVector
CLHEP::HepRotation G4RotationMatrix
static G4Colour fCurrentColour
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetLayout(Layout)
G4String GetCurrentValue(G4UIcommand *command)
G4double z
Definition: TRTMaterials.hh:39
Definition: G4Box.hh:64
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void UpdateVisManagerScene(const G4String &sceneName="")
G4String name
Definition: TRTMaterials.hh:40
G4String GetCurrentValue(G4UIcommand *command)
const G4double pi
void SetLineWidth(G4double)
Definition: G4Tubs.hh:85
static G4Text::Layout fCurrentTextLayout
Line(G4double x1, G4double y1, G4double z1, G4double x2, G4double y2, G4double z2, G4double width, const G4Colour &colour)
const G4ViewParameters & GetViewParameters() const
G4double GetXmax() const
Definition: G4VisExtent.hh:90
const G4ModelingParameters * GetModelingParameters() const
void SetDefaultValue(const char *theDefaultValue)
virtual void BeginPrimitives(const G4Transform3D &objectTransformation=G4Transform3D())=0
#define width
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:115
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
HepGeom::Point3D< G4double > G4Point3D
Definition: G4Point3D.hh:35
HepGeom::Vector3D< G4double > G4Vector3D
Definition: G4Vector3D.hh:35
#define G4BestUnit(a, b)
#define G4_USE_G4BESTUNIT_FOR_VERBOSE 1
static G4Colour Brown()
Definition: G4Colour.hh:147
void SetForceSolid(G4bool)
Direction
Definition: G4Scale.hh:42
void SetExtent(const G4VisExtent &)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
void SetModelingParameters(const G4ModelingParameters *)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
HepGeom::RotateZ3D G4RotateZ3D
const G4Run * GetCurrentRun() const
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:225
void SetTransformation(const G4Transform3D &)
static void G4VisCommandsSceneAddUnsuccessful(G4VisManager::Verbosity verbosity)
virtual void AddPrimitive(const G4Polyline &)=0
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4int GetEventID() const
Definition: G4Event.hh:140
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
Line2D(G4double x1, G4double y1, G4double x2, G4double y2, G4double width, const G4Colour &colour)
G4String GetCurrentValue(G4UIcommand *command)
static G4StateManager * GetStateManager()
void AddVisAction(const G4String &name, G4VUserVisAction *, G4Scene *, ActionType, G4VisManager::Verbosity)
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
const G4Vector3D & GetViewpointDirection() const
void SetNewValue(G4UIcommand *command, G4String newValue)
G4GLOB_DLL std::ostream G4cout
const G4Event * GetEvent() const
void SetNewValue(G4UIcommand *command, G4String newValue)
const G4VisExtent & GetExtent() const
const G4String & GetName() const
void SetNewValue(G4UIcommand *command, G4String newValue)
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:411
void SetNewValue(G4UIcommand *command, G4String newValue)
static const double deg
Definition: G4SIunits.hh:133
G4double GetYmax() const
Definition: G4VisExtent.hh:92
bool G4bool
Definition: G4Types.hh:79
G4PhysicalVolumeModel::G4PhysicalVolumeNodeID PVNodeID
G4Polyhedron * CreatePolyhedron() const
G4int GetFoundDepth() const
G4String GetCurrentValue(G4UIcommand *command)
void SetType(const G4String &)
G4int GetRunID() const
Definition: G4Run.hh:76
Definition: G4Run.hh:46
static const G4String & GetGuidanceString()
Definition: G4Scale.cc:64
static G4LogicalVolumeStore * GetInstance()
const std::vector< UserVisAction > & GetEndOfEventUserVisActions() const
HepGeom::Transform3D G4Transform3D
std::vector< PVNodeID > PVPath
G4double GetZmax() const
Definition: G4VisExtent.hh:94
G4ApplicationState GetCurrentState() const
const std::map< G4VUserVisAction *, G4VisExtent > & GetUserVisActionExtents() const
void SetBaseFullPVPath(const std::vector< G4PhysicalVolumeNodeID > &baseFullPVPath)
void SetNewValue(G4UIcommand *command, G4String newValue)
static const G4double f1
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
static const double rad
Definition: G4SIunits.hh:130
void SetVisAttributes(const G4VisAttributes *)
Definition: G4Visible.cc:80
const std::vector< UserVisAction > & GetRunDurationUserVisActions() const
static G4TransportationManager * GetTransportationManager()
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
const std::vector< G4PhysicalVolumeModel::G4PhysicalVolumeNodeID > & GetFoundFullPVPath() const
virtual void EndPrimitives2D()=0
G4String GetCurrentValue(G4UIcommand *command)
void SetOffset(double dx, double dy)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void BeginPrimitives2D(const G4Transform3D &objectTransformation=G4Transform3D())=0
G4double StoD(G4String s)
static G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:294
Layout
Definition: G4Text.hh:77
G4VPhysicalVolume * GetFoundVolume() const
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4String GetCurrentValue(G4UIcommand *command)
static G4double fCurrentLineWidth
G4double GetZmin() const
Definition: G4VisExtent.hh:93
static G4Colour fCurrentTextColour
static Verbosity GetVerbosity()
static const G4double b1
HepGeom::Translate3D G4Translate3D
G4double GetYmin() const
Definition: G4VisExtent.hh:91
G4UIcmdWithoutParameter * fpCommand
G4int GetNumberOfEventToBeProcessed() const
Definition: G4Run.hh:83
size_t GetNoWorlds() const
G4String GetCurrentValue(G4UIcommand *command)
#define G4endl
Definition: G4ios.hh:61
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithoutParameter * fpCommand
void SetNewValue(G4UIcommand *command, G4String newValue)
G4VViewer * GetCurrentViewer() const
virtual void EndPrimitives()=0
const G4Transform3D & GetFoundTransformation() const
const std::vector< UserVisAction > & GetEndOfRunUserVisActions() const
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
double G4double
Definition: G4Types.hh:76
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetGuidance(const char *theGuidance)
const G4Vector3D & GetUpVector() const
static const G4double d2
G4String GetCurrentValue(G4UIcommand *command)
Arrow2D(G4double x1, G4double y1, G4double x2, G4double y2, G4double width, const G4Colour &colour)
G4ApplicationState
void SetGlobalDescription(const G4String &)
G4String GetCurrentValue(G4UIcommand *command)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
G4Scene * GetCurrentScene() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetScreenSize(G4double)
void DescribeYourselfTo(G4VGraphicsScene &)
static G4VisManager * fpVisManager
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const