16#include "G4UImanager.hh"
22bool is3DTextKind(
const std::string& kind) {
23 return kind ==
"3D" || kind ==
"3d" || kind ==
"text" || kind ==
"Text";
26std::string colourToRGB(
const std::string& colour) {
27 if (colour.find(
' ') != std::string::npos) {
return colour; }
28 if (colour ==
"black") {
return "0 0 0"; }
29 if (colour ==
"blue") {
return "0 0 1"; }
30 if (colour ==
"cyan") {
return "0 1 1"; }
31 if (colour ==
"green") {
return "0 1 0"; }
32 if (colour ==
"grey" || colour ==
"gray") {
return "0.9 0.9 0.9"; }
33 if (colour ==
"red") {
return "1 0 0"; }
34 if (colour ==
"yellow") {
return "1 1 0"; }
40 std::vector<std::string> cmds;
42 const bool gui = gopts->getSwitch(
"gui");
43 const bool use_dawn = gopts->getSwitch(
"useDawn");
50 const bool open_configured_viewer = gui || g4view.driver ==
"TOOLSSG_OFFSCREEN";
51 if (!use_dawn && !open_configured_viewer) {
return cmds; }
54 cmds.emplace_back(
"/vis/open DAWNFILE");
56 if (open_configured_viewer) {
58 std::string openArg = g4view.driver +
" " + g4view.dimension;
59 if (g4view.driver !=
"TOOLSSG_OFFSCREEN") openArg += g4view.position;
60 cmds.emplace_back(
"/vis/open " + openArg);
65 cmds.emplace_back(
"/vis/viewer/set/autoRefresh false");
66 cmds.emplace_back(
"/vis/scene/create gemc");
67 cmds.emplace_back(
"/vis/sceneHandler/attach");
68 cmds.emplace_back(
"/vis/scene/add/volume root -1");
70 if (use_dawn && !open_configured_viewer) {
71 cmds.emplace_back(
"/vis/geometry/set/visibility World 0 false");
72 cmds.emplace_back(
"/vis/viewer/set/style surface");
74 if (open_configured_viewer) {
76 const double toDegrees = 180.0 / std::numbers::pi;
81 if (lightThetaValue == 0.0 && lightPhiValue == 0.0) {
82 lightThetaValue = thetaValue;
83 lightPhiValue = phiValue;
86 cmds.emplace_back(
"/vis/viewer/set/viewpointThetaPhi " + std::to_string(thetaValue) +
" " + std::to_string(phiValue));
87 cmds.emplace_back(
"/vis/viewer/set/lightsThetaPhi " + std::to_string(lightThetaValue) +
" " + std::to_string(lightPhiValue));
88 cmds.emplace_back(
"/vis/viewer/set/lineSegmentsPerCircle " + std::to_string(g4view.segsPerCircle));
89 cmds.emplace_back(
"/vis/viewer/set/background " + g4view.background);
90 cmds.emplace_back(
"/vis/viewer/set/numberOfCloudPoints " + std::to_string(g4view.cloudPoints));
92 cmds.emplace_back(
"/vis/viewer/set/autoRefresh true");
98 std::vector<std::string> commands;
101 if (decorations.scale) {
102 commands.emplace_back(
"/vis/scene/add/scale " +
103 std::to_string(decorations.scaleLength) +
" " +
104 decorations.scaleUnit +
" " +
105 decorations.scaleDirection +
" " +
106 colourToRGB(decorations.scaleColor));
108 if (decorations.axes) { commands.emplace_back(
"/vis/scene/add/axes"); }
109 if (decorations.date) {
110 commands.emplace_back(
"/vis/scene/add/date " + std::to_string(decorations.dateSize));
112 if (decorations.logo2D) { commands.emplace_back(
"/vis/scene/add/logo2D"); }
113 if (decorations.logo) { commands.emplace_back(
"/vis/scene/add/logo"); }
114 if (decorations.frame) {
115 commands.emplace_back(
"/vis/set/colour " + decorations.frameColor);
116 commands.emplace_back(
"/vis/set/lineWidth " + std::to_string(decorations.frameLineWidth));
117 commands.emplace_back(
"/vis/scene/add/frame");
118 commands.emplace_back(
"/vis/set/colour");
119 commands.emplace_back(
"/vis/set/lineWidth");
126 std::vector<std::string> commands;
131 for (
const auto &text: text_to_add) {
132 commands.emplace_back(
"/vis/set/textColour " + text.color);
133 if (!text.layout.empty()) {
134 commands.emplace_back(
"/vis/set/textLayout " + text.layout);
137 if (is3DTextKind(text.kind)) {
141 commands.emplace_back(
142 "/vis/scene/add/text " +
143 std::to_string(text.x) +
" " +
144 std::to_string(text.y) +
" " +
145 std::to_string(*text.z) +
" " +
147 std::to_string(text.size) +
" " +
148 std::to_string(text.dx) +
" " +
149 std::to_string(text.dy) +
" " +
152 commands.emplace_back(
153 "/vis/scene/add/text2D " +
154 std::to_string(text.x) +
" " +
155 std::to_string(text.y) +
" " +
156 std::to_string(text.size) +
" ! ! " +
160 if (!text.layout.empty()) {
161 commands.emplace_back(
"/vis/set/textLayout left");
165 commands.emplace_back(
"/vis/set/textColour");
std::vector< std::string > addSceneTexts(const std::shared_ptr< GOptions > &gopts)
Build commands that insert configured text annotations into the scene.
std::vector< std::string > addSceneDecorations(const std::shared_ptr< GOptions > &gopts)
Build commands for optional scene decorations such as scale, axes, logos, and frame.
std::vector< std::string > scene_commands(const std::shared_ptr< GOptions > &gopts)
Build the full command sequence for scene initialization.
std::shared_ptr< GLogger > log
Declaration of the G4SceneProperties helper used to initialize Geant4 scene visualization.
Scene text option structures and helpers for the g4display module.
G4Light getG4Light(const std::shared_ptr< GOptions > &gopts)
Read the g4light option node and return a projected G4Light struct.
G4View getG4View(const std::shared_ptr< GOptions > &gopts)
Read the g4view option node and return a projected G4View struct.
vector< G4SceneText > getSceneTexts(const std::shared_ptr< GOptions > &gopts)
Extract scene text entries from the g4text option node.
G4Camera getG4Camera(const std::shared_ptr< GOptions > &gopts)
Read the g4camera option node and return a projected G4Camera struct.
G4Decorations getG4Decorations(const std::shared_ptr< GOptions > &gopts)
Read the g4decoration option node and return scene decoration settings.
constexpr int EC__MANDATORY_NOT_FILLED
double getG4Number(const string &v, bool warnIfNotUnit=false)