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 st_item.color = gopts->get_variable_in_option<string>(g4t_item, "color", "black");
24 st_item.x = gopts->get_variable_in_option<double>(g4t_item, "x", 0);
25 st_item.y = gopts->get_variable_in_option<double>(g4t_item, "y", 0);
26 st_item.z = gopts->get_variable_in_option<double>(g4t_item, "z", GNOT_SPECIFIED_SCENE_TEXT_Z);
27 st_item.size = gopts->get_variable_in_option<double>(g4t_item, "size", 24.0);
28
29 st.push_back(st_item);
30 }
31
32 return st;
33}
34
35// Define the g4text option schema and help string.
38 string help;
39
40 // g4text
41 help = "If the z coordinate is specified, the text is considered 2D. \n \n";
42 help += "Example to add two texts: \n \n";
43 help += "-g4text=\"[{text: hello, x: -100}, {text: there, x: 100}]\"\n";
44
45 vector<GVariable> g4text = {
46 {"text", goptions::NODFLT, "string with the text to be displayed"},
47 {"color", "black", "color of the text"},
48 {"x", 0, "x position of the text"},
49 {"y", 0, "y position of the text"},
50 {"z", GNOT_SPECIFIED_SCENE_TEXT_Z, "z position of the text"},
51 {"size", 24.0, "size of the text"},
52 };
53
54 goptions.defineOption("g4text", "Insert texts in the current scene", g4text, help);
55
56 return goptions;
57}
58} // 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:36
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 color
Text color name understood by Geant4 (e.g. "black", "red").
Definition g4Text.h:36
double z
Z position; if left at default sentinel, Z is treated as “not specified”.
Definition g4Text.h:45
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:48
double x
X position.
Definition g4Text.h:39
double y
Y position.
Definition g4Text.h:42