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