g4display
Loading...
Searching...
No Matches
g4Text.cc
Go to the documentation of this file.
1// g4Text.cc
2//
3// Implementation of g4display scene-text option parsing.
4// Doxygen documentation is authoritative in g4Text.h (see rule 7).
5
6#include "g4Text.h"
7
8// c++
9using namespace std;
10
11namespace g4display {
12// Return a vector of G4SceneText parsed from the "g4text" structured option node.
13vector<G4SceneText> getSceneTexts(const std::shared_ptr<GOptions>& gopts) {
14 vector<G4SceneText> st;
15
16 auto g4t_node = gopts->getOptionNode("g4text");
17
18 // Each node entry becomes one text annotation.
19 for (auto g4t_item : g4t_node) {
20 G4SceneText st_item;
21
22 st_item.text = gopts->get_variable_in_option<string>(g4t_item, "text", goptions::NODFLT);
23 if (st_item.text == goptions::NODFLT || st_item.text.empty()) { continue; }
24
25 st_item.color = gopts->get_variable_in_option<string>(g4t_item, "color", "black");
26 st_item.kind = gopts->get_variable_in_option<string>(g4t_item, "kind", "2D");
27 st_item.layout = gopts->get_variable_in_option<string>(g4t_item, "layout", "");
28 st_item.x = gopts->get_variable_in_option<double>(g4t_item, "x", 0);
29 st_item.y = gopts->get_variable_in_option<double>(g4t_item, "y", 0);
30 st_item.z = gopts->get_variable_in_option<double>(g4t_item, "z", GNOT_SPECIFIED_SCENE_TEXT_Z);
31 st_item.unit = gopts->get_variable_in_option<string>(g4t_item, "unit", "cm");
32 st_item.size = gopts->get_variable_in_option<double>(g4t_item, "size", 24.0);
33 st_item.dx = gopts->get_variable_in_option<double>(g4t_item, "dx", 4.0);
34 st_item.dy = gopts->get_variable_in_option<double>(g4t_item, "dy", 4.0);
35
36 st.push_back(st_item);
37 }
38
39 return st;
40}
41
42// Define the g4text option schema and help string.
45 string help;
46
47 // g4text
48 help = "Adds 2D or 3D text to the current scene. \n \n";
49 help += "Example to add two texts: \n \n";
50 help += "-g4text=\"[{kind: 2D, text: hello, x: 0.9, y: -0.9, layout: right}, {kind: 3D, text: Shape1, x: 0, y: 6, z: -4}]\"\n";
51
52 vector<GVariable> g4text = {
53 {"text", goptions::NODFLT, "string with the text to be displayed"},
54 {"color", "black", "color of the text"},
55 {"kind", "2D", "text kind: 2D or 3D"},
56 {"layout", "", "optional text layout, for example right"},
57 {"x", 0, "x position of the text"},
58 {"y", 0, "y position of the text"},
59 {"z", GNOT_SPECIFIED_SCENE_TEXT_Z, "z position of the text"},
60 {"unit", "cm", "unit for 3D text positions"},
61 {"size", 24.0, "size of the text"},
62 {"dx", 4.0, "3D text x offset"},
63 {"dy", 4.0, "3D text y offset"},
64 };
65
66 goptions.defineOption("g4text", "Insert texts in the current scene", g4text, help);
67
68 return goptions;
69}
70} // namespace g4display
Scene text option structures and helpers for the g4display module.
#define GNOT_SPECIFIED_SCENE_TEXT_Z
GOptions addSceneTextsOptions()
Define the g4text structured option schema.
Definition g4Text.cc:43
vector< G4SceneText > getSceneTexts(const std::shared_ptr< GOptions > &gopts)
Extract scene text entries from the g4text option node.
Definition g4Text.cc:13
const std::string NODFLT
One text annotation to be inserted into the Geant4 scene.
Definition g4Text.h:31
std::string layout
Optional text layout such as "right"; empty keeps Geant4 default layout.
Definition g4Text.h:42
std::string color
Text color name understood by Geant4 (e.g. "black", "red").
Definition g4Text.h:36
std::string kind
Text kind: "2D" for text2D or "3D" for text attached in scene coordinates.
Definition g4Text.h:39
double z
Z position used by 3D text.
Definition g4Text.h:51
std::string text
Text string to be displayed.
Definition g4Text.h:33
int size
Text size parameter passed to Geant4 visualization command.
Definition g4Text.h:57
std::string unit
Unit used by 3D text positions.
Definition g4Text.h:54
double x
X position.
Definition g4Text.h:45
double dy
3D text Y offset.
Definition g4Text.h:63
double y
Y position.
Definition g4Text.h:48
double dx
3D text X offset.
Definition g4Text.h:60