gtree
Loading...
Searching...
No Matches
gtree.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
4#include "gQtButtonsWidget.h" // Custom toggle button widget
5#include "g4volume.h"
6#include "gbase.h" // Provides application options/configuration
7#include "goptions.h"
8
9// qt
10#include <QWidget>
11#include <QTreeWidgetItem>
12#include <QColor>
13#include <QLabel>
14#include <QSlider>
15
16// cpp
17#include <map>
18#include <memory>
19
37{
38public:
55 explicit G4Ttree_item(G4Volume* g4volume);
56
57private:
65 std::string mother;
66
74 QColor color;
75
79 bool is_visible = true;
80
92 int representation = 1; // 0 = wireframe ; 1 = solid; 2 = cloud
93
97 double opacity = 1.0;
98
102 std::string material;
103
107 double mass = 0.0;
108
112 double volume = 0.0;
113
117 double density = 0.0;
118
126 bool recursive = false;
127
128public:
130 [[nodiscard]] std::string get_mother() const { return mother; }
131
133 [[nodiscard]] QColor get_color() const { return color; }
134
136 [[nodiscard]] bool get_visibility() const { return is_visible; }
137
139 [[nodiscard]] int get_representation() const { return representation; }
140
142 [[nodiscard]] double get_opacity() const { return opacity; }
143
145 [[nodiscard]] double get_mass() const { return mass; }
146
148 [[nodiscard]] double get_volume() const { return volume; }
149
151 [[nodiscard]] double get_density() const { return density; }
152
154 [[nodiscard]] std::string get_material() const { return material; }
155
157 [[nodiscard]] bool get_recursive() const { return recursive; }
158
163 void set_recursive(bool recursive) { this->recursive = recursive; }
164
173 void set_color(QColor& c) { color = c; }
174
179 void set_opacity(double opacity) { this->opacity = opacity; }
180
191 static std::string vname_from_v4name(std::string v4name);
192
203 static std::string system_from_v4name(std::string v4name);
204};
205
206// map for a single system
207using g4tree_map = std::map<std::string, std::unique_ptr<G4Ttree_item>>;
208
228class GTree : public QWidget, public GBase<GTree>
229{
230 Q_OBJECT
231
232public:
247 explicit GTree(const std::shared_ptr<GOptions>& gopt,
248 std::unordered_map<std::string, G4Volume*> g4volumes_map,
249 QWidget* parent = nullptr);
250
254 GTree(const GTree&) = delete;
255
259 GTree& operator=(const GTree&) = delete;
260
261private:
270 std::map<std::string, g4tree_map> g4_systems_tree; // map of systems
271
275 QTreeWidget* treeWidget = nullptr;
276
277 // right-side panel
281 QWidget* rightPanel = nullptr;
282
286 QWidget* bottomPanel = nullptr; // appears only when an item is selected
287
291 GQTButtonsWidget* styleButtons; // left bar buttons
292
293 // info labels inside bottomPanel
294 QLabel* typeLabel = nullptr;
295 QLabel* daughtersLabel = nullptr;
296 QLabel* nameLabel = nullptr;
297 QLabel* materialLabel = nullptr;
298 QLabel* massLabel = nullptr;
299 QLabel* volumeLabel = nullptr;
300 QLabel* densityLabel = nullptr;
301
305 QSlider* opacitySlider = nullptr;
306
310 QLabel* opacityLabel = nullptr; // show numeric value
311
316 void build_tree(std::unordered_map<std::string, G4Volume*> g4volumes_map);
317
327 void populateTree();
328
334 void set_visibility(const std::string& fullName, bool visible);
335
341 void set_color(const std::string& fullName, const QColor& c);
342
348 void set_opacity(const std::string& volumeName, double opacity);
349
354 QWidget* right_widget();
355
361 int get_ndaughters(QTreeWidgetItem* item) const;
362
368 G4Ttree_item* findTreeItem(const std::string& fullName);
369
377 std::string current_volume_name;
378
379private slots:
390 void onItemChanged(QTreeWidgetItem* item, int column);
391
399 void onColorButtonClicked();
400
406 void onTreeItemClicked(QTreeWidgetItem* item, int column);
407
413 void onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
414
424 void changeStyle();
425
430 void onOpacitySliderChanged(int value);
431};
Lightweight per-volume record used by GTree to populate the UI.
Definition gtree.h:37
void set_recursive(bool recursive)
Set the recursive flag.
Definition gtree.h:163
int get_representation() const
Return the cached representation mode.
Definition gtree.h:139
static std::string vname_from_v4name(std::string v4name)
Extract the "leaf" volume name from a full volume name.
Definition gtree.cc:66
double get_opacity() const
Return the cached opacity (alpha) in [0,1].
Definition gtree.h:142
G4Ttree_item(G4Volume *g4volume)
Construct a cached record for a single geometry volume.
Definition gtree.cc:27
double get_density() const
Return the cached density.
Definition gtree.h:151
void set_opacity(double opacity)
Update the cached opacity.
Definition gtree.h:179
double get_volume() const
Return the cached volume.
Definition gtree.h:148
bool get_visibility() const
Return the cached visibility state.
Definition gtree.h:136
double get_mass() const
Return the cached mass.
Definition gtree.h:145
QColor get_color() const
Return the cached RGB color.
Definition gtree.h:133
bool get_recursive() const
Return the cached recursive flag.
Definition gtree.h:157
void set_color(QColor &c)
Update the cached color.
Definition gtree.h:173
static std::string system_from_v4name(std::string v4name)
Extract the system name from a full volume name.
Definition gtree.cc:72
std::string get_material() const
Return the cached material name.
Definition gtree.h:154
std::string get_mother() const
Return the cached mother name.
Definition gtree.h:130
Qt widget that displays the geometry hierarchy and allows interactive style edits.
Definition gtree.h:229
GTree(const std::shared_ptr< GOptions > &gopt, std::unordered_map< std::string, G4Volume * > g4volumes_map, QWidget *parent=nullptr)
Construct the geometry tree widget.
Definition gtree.cc:79
GTree & operator=(const GTree &)=delete
Non-assignable: the widget owns unique model resources.
GTree(const GTree &)=delete
Non-copyable: the widget owns unique model resources.
std::map< std::string, std::unique_ptr< G4Ttree_item > > g4tree_map
Definition gtree.h:207