gtree
Loading...
Searching...
No Matches
gtree.h
Go to the documentation of this file.
1#pragma once
2
3// gemc
4#include <gemc/gqtbuttonswidget/gQtButtonsWidget.h> // Custom toggle button widget
5#include <gemc/g4system/g4volume.h>
6#include <gemc/gsystem/gvolume.h>
7#include <gemc/gbase/gbase.h> // Provides application options/configuration
8#include <gemc/goptions/goptions.h>
9
10// qt
11#include <QWidget>
12#include <QTreeWidgetItem>
13#include <QColor>
14#include <QLabel>
15#include <QTextEdit>
16#include <QPushButton>
17#include <QSlider>
18
19class QTimer;
20
21// cpp
22#include <map>
23#include <memory>
24
43{
44public:
63 explicit G4Ttree_item(G4Volume* g4volume, const GVolume* gvolume = nullptr);
64
65private:
73 std::string mother;
74
82 QColor color;
83
87 bool is_visible = true;
88
100 int representation = 1; // 0 = wireframe ; 1 = solid; 2 = cloud
101
105 double opacity = 1.0;
106
110 std::string material;
111
115 double mass = 0.0;
116
120 double volume = 0.0;
121
125 double density = 0.0;
126
134 bool recursive = false;
135
136 // pygemc descriptor fields (empty when no GVolume descriptor is available)
137 std::string solidType;
138 std::string parameters;
139 std::string position;
140 std::string rotation;
141 std::string motherVolume;
142 std::string volDescription;
143
144public:
146 [[nodiscard]] std::string get_mother() const { return mother; }
147
149 [[nodiscard]] QColor get_color() const { return color; }
150
152 [[nodiscard]] bool get_visibility() const { return is_visible; }
153
155 [[nodiscard]] int get_representation() const { return representation; }
156
158 [[nodiscard]] double get_opacity() const { return opacity; }
159
161 [[nodiscard]] double get_mass() const { return mass; }
162
164 [[nodiscard]] double get_volume() const { return volume; }
165
167 [[nodiscard]] double get_density() const { return density; }
168
170 [[nodiscard]] std::string get_material() const { return material; }
171
173 [[nodiscard]] bool get_recursive() const { return recursive; }
174
176 [[nodiscard]] std::string get_solidType() const { return solidType; }
178 [[nodiscard]] std::string get_parameters() const { return parameters; }
180 [[nodiscard]] std::string get_position() const { return position; }
182 [[nodiscard]] std::string get_rotation() const { return rotation; }
184 [[nodiscard]] std::string get_motherVolume() const { return motherVolume; }
186 [[nodiscard]] std::string get_volDescription() const { return volDescription; }
187
192 void set_recursive(bool recursive) { this->recursive = recursive; }
193
202 void set_color(const QColor& c) { color = c; }
203
208 void set_opacity(double opacity) { this->opacity = opacity; }
209
220 static std::string vname_from_v4name(std::string v4name);
221
232 static std::string system_from_v4name(std::string v4name);
233};
234
235// map for a single system
236using g4tree_map = std::map<std::string, std::unique_ptr<G4Ttree_item>>;
237
257class GTree : public QWidget, public GBase<GTree>
258{
259 Q_OBJECT
260
261public:
276 explicit GTree(const std::shared_ptr<GOptions>& gopt,
277 std::unordered_map<std::string, G4Volume*> g4volumes_map,
278 std::unordered_map<std::string, const GVolume*> gvolumes_map = {},
279 QWidget* parent = nullptr);
280
284 GTree(const GTree&) = delete;
285
289 GTree& operator=(const GTree&) = delete;
290
291private:
300 std::map<std::string, g4tree_map> g4_systems_tree; // map of systems
301
308 std::unordered_map<std::string, const GVolume*> gvolumes_map;
309
313 QTreeWidget* treeWidget = nullptr;
314
315 // right-side panel
319 QWidget* rightPanel = nullptr;
320
324 QWidget* bottomPanel = nullptr; // appears only when an item is selected
325
329 GQTButtonsWidget* styleButtons; // left bar buttons
330
331 // info labels inside bottomPanel
332 QLabel* typeLabel = nullptr;
333 QLabel* daughtersLabel = nullptr;
334 QLabel* nameLabel = nullptr;
335 QLabel* materialLabel = nullptr;
336 QLabel* massLabel = nullptr;
337 QLabel* volumeLabel = nullptr;
338 QLabel* densityLabel = nullptr;
339 QLabel* solidTypeLabel = nullptr;
340 QTextEdit* parametersLabel = nullptr;
341 QLabel* positionLabel = nullptr;
342 QLabel* rotationLabel = nullptr;
343 QLabel* motherLabel = nullptr;
344 QLabel* descriptionLabel = nullptr;
345
349 QSlider* opacitySlider = nullptr;
350
354 QLabel* opacityLabel = nullptr;
355
362 QPushButton* inspectButton = nullptr;
363
373 QPushButton* drawOverlapsButton = nullptr;
374
379 void build_tree(std::unordered_map<std::string, G4Volume*> g4volumes_map);
380
390 void populateTree();
391
397 void set_visibility(const std::string& fullName, bool visible);
398
404 void set_color(const std::string& fullName, const QColor& c);
405
411 void set_opacity(const std::string& volumeName, double opacity);
412
417 QWidget* right_widget();
418
424 int get_ndaughters(QTreeWidgetItem* item) const;
425
431 G4Ttree_item* findTreeItem(const std::string& fullName);
432
440 std::string current_volume_name;
441
442 // Twinkle animation state
443 QTimer* twinkleTimer = nullptr;
444 int twinkleTick = 0;
445 QColor twinkleSavedColor;
446 double twinkleSavedOpacity = 1.0;
447 std::string twinkleVolumeName;
448
452 void centreTwinkle();
453
454private slots:
465 void onItemChanged(QTreeWidgetItem* item, int column);
466
474 void onColorButtonClicked();
475
481 void onTreeItemClicked(QTreeWidgetItem* item, int column);
482
488 void onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
489
500 void changeStyle();
501
506 void onOpacitySliderChanged(int value);
507
516 void inspectVolume();
517
525 void drawOverlapsWarning();
526
530 void onTwinkleStep();
531};
Lightweight per-volume record used by GTree to populate the UI.
Definition gtree.h:43
void set_recursive(bool recursive)
Set the recursive flag.
Definition gtree.h:192
int get_representation() const
Return the cached representation mode.
Definition gtree.h:155
std::string get_motherVolume() const
Return the mother volume name.
Definition gtree.h:184
static std::string vname_from_v4name(std::string v4name)
Extract the "leaf" volume name from a full volume name.
Definition gtree.cc:230
double get_opacity() const
Return the cached opacity (alpha) in [0,1].
Definition gtree.h:158
std::string get_volDescription() const
Return the volume description.
Definition gtree.h:186
std::string get_rotation() const
Return the placement rotation string with units.
Definition gtree.h:182
double get_density() const
Return the cached density.
Definition gtree.h:167
void set_color(const QColor &c)
Update the cached color.
Definition gtree.h:202
void set_opacity(double opacity)
Update the cached opacity.
Definition gtree.h:208
double get_volume() const
Return the cached volume.
Definition gtree.h:164
bool get_visibility() const
Return the cached visibility state.
Definition gtree.h:152
double get_mass() const
Return the cached mass.
Definition gtree.h:161
QColor get_color() const
Return the cached RGB color.
Definition gtree.h:149
bool get_recursive() const
Return the cached recursive flag.
Definition gtree.h:173
std::string get_solidType() const
Return the solid type string (e.g. "G4Box").
Definition gtree.h:176
static std::string system_from_v4name(std::string v4name)
Extract the system name from a full volume name.
Definition gtree.cc:236
std::string get_position() const
Return the placement position string with units.
Definition gtree.h:180
std::string get_parameters() const
Return the solid parameters string with units.
Definition gtree.h:178
std::string get_material() const
Return the cached material name.
Definition gtree.h:170
G4Ttree_item(G4Volume *g4volume, const GVolume *gvolume=nullptr)
Construct a cached record for a single geometry volume.
Definition gtree.cc:182
std::string get_mother() const
Return the cached mother name.
Definition gtree.h:146
Qt widget that displays the geometry hierarchy and allows interactive style edits.
Definition gtree.h:258
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.
GTree(const std::shared_ptr< GOptions > &gopt, std::unordered_map< std::string, G4Volume * > g4volumes_map, std::unordered_map< std::string, const GVolume * > gvolumes_map={}, QWidget *parent=nullptr)
Construct the geometry tree widget.
Definition gtree.cc:243
double position[3]
std::map< std::string, std::unique_ptr< G4Ttree_item > > g4tree_map
Definition gtree.h:236