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/gmirror.h>
7#include <gemc/gsystem/gvolume.h>
8#include <gemc/gbase/gbase.h> // Provides application options/configuration
9#include <gemc/goptions/goptions.h>
10
11// qt
12#include <QWidget>
13#include <QTreeWidgetItem>
14#include <QColor>
15#include <QLabel>
16#include <QTextEdit>
17#include <QPushButton>
18#include <QSlider>
19
20class QTimer;
21
22// cpp
23#include <map>
24#include <memory>
25
44{
45public:
64 explicit G4Ttree_item(G4Volume* g4volume, const GVolume* gvolume = nullptr);
65
66private:
74 std::string mother;
75
83 QColor color;
84
88 bool is_visible = true;
89
101 int representation = 1; // 0 = wireframe ; 1 = solid; 2 = cloud
102
106 double opacity = 1.0;
107
111 std::string material;
112
121 mutable double mass = 0.0;
122
126 mutable double volume = 0.0;
127
131 mutable double density = 0.0;
132
134 mutable bool physics_computed = false;
135
137 G4LogicalVolume* logical_ptr = nullptr;
138
140 G4VSolid* solid_ptr = nullptr;
141
149 void compute_physics_quantities() const;
150
158 bool recursive = false;
159
160 // pygemc descriptor fields (empty when no GVolume descriptor is available)
161 std::string solidType;
162 std::string parameters;
163 std::string position;
164 std::string rotation;
165 std::string motherVolume;
166 std::string solidsOpr;
167 std::string volDescription;
168 std::string mirrorName;
169
170public:
172 [[nodiscard]] std::string get_mother() const { return mother; }
173
175 [[nodiscard]] QColor get_color() const { return color; }
176
178 [[nodiscard]] bool get_visibility() const { return is_visible; }
179
181 [[nodiscard]] int get_representation() const { return representation; }
182
184 [[nodiscard]] double get_opacity() const { return opacity; }
185
187 [[nodiscard]] double get_mass() const {
188 compute_physics_quantities();
189 return mass;
190 }
191
193 [[nodiscard]] double get_volume() const {
194 compute_physics_quantities();
195 return volume;
196 }
197
199 [[nodiscard]] double get_density() const {
200 compute_physics_quantities();
201 return density;
202 }
203
205 [[nodiscard]] std::string get_material() const { return material; }
206
208 [[nodiscard]] bool get_recursive() const { return recursive; }
209
211 [[nodiscard]] std::string get_solidType() const { return solidType; }
213 [[nodiscard]] std::string get_parameters() const { return parameters; }
215 [[nodiscard]] std::string get_position() const { return position; }
217 [[nodiscard]] std::string get_rotation() const { return rotation; }
219 [[nodiscard]] std::string get_motherVolume() const { return motherVolume; }
221 [[nodiscard]] std::string get_solidsOpr() const { return solidsOpr; }
223 [[nodiscard]] std::string get_volDescription() const { return volDescription; }
225 [[nodiscard]] std::string get_mirrorName() const { return mirrorName; }
226
231 void set_recursive(bool recursive) { this->recursive = recursive; }
232
241 void set_color(const QColor& c) { color = c; }
242
247 void set_opacity(double opacity) { this->opacity = opacity; }
248
259 static std::string vname_from_v4name(std::string v4name);
260
271 static std::string system_from_v4name(std::string v4name);
272};
273
274// map for a single system
275using g4tree_map = std::map<std::string, std::unique_ptr<G4Ttree_item>>;
276
296class GTree : public QWidget, public GBase<GTree>
297{
298 Q_OBJECT
299
300public:
317 explicit GTree(const std::shared_ptr<GOptions>& gopt,
318 std::unordered_map<std::string, G4Volume*> g4volumes_map,
319 std::unordered_map<std::string, const GVolume*> gvolumes_map = {},
320 QWidget* parent = nullptr,
321 std::unordered_map<std::string, const GMirror*> gmirrors_map = {});
322
326 GTree(const GTree&) = delete;
327
331 GTree& operator=(const GTree&) = delete;
332
333private:
342 std::map<std::string, g4tree_map> g4_systems_tree; // map of systems
343
350 std::unordered_map<std::string, const GVolume*> gvolumes_map;
351
355 std::unordered_map<std::string, const GMirror*> gmirrors_map;
356
360 QTreeWidget* treeWidget = nullptr;
361
362 // right-side panel
366 QWidget* rightPanel = nullptr;
367
371 QWidget* bottomPanel = nullptr; // appears only when an item is selected
372
376 GQTButtonsWidget* styleButtons; // left bar buttons
377
378 // info labels inside bottomPanel
379 QLabel* typeLabel = nullptr;
380 QLabel* daughtersLabel = nullptr;
381 QLabel* nameLabel = nullptr;
382 QLabel* materialLabel = nullptr;
383 QLabel* massLabel = nullptr;
384 QLabel* volumeLabel = nullptr;
385 QLabel* densityLabel = nullptr;
386 QLabel* solidTypeLabel = nullptr;
387 QTextEdit* parametersLabel = nullptr;
388 QLabel* positionLabel = nullptr;
389 QLabel* rotationLabel = nullptr;
390 QLabel* motherLabel = nullptr;
391 QLabel* descriptionLabel = nullptr;
392
399 QPushButton* mirrorButton = nullptr;
400
404 QSlider* opacitySlider = nullptr;
405
409 QLabel* opacityLabel = nullptr;
410
417 QPushButton* inspectButton = nullptr;
418
428 QPushButton* drawOverlapsButton = nullptr;
429
434 void build_tree(std::unordered_map<std::string, G4Volume*> g4volumes_map);
435
445 void populateTree();
446
452 void set_visibility(const std::string& fullName, bool visible);
453
459 void set_color(const std::string& fullName, const QColor& c);
460
466 void set_opacity(const std::string& volumeName, double opacity);
467
472 QWidget* right_widget();
473
479 int get_ndaughters(QTreeWidgetItem* item) const;
480
486 G4Ttree_item* findTreeItem(const std::string& fullName);
487
495 std::string current_volume_name;
496
497 // Twinkle animation state
498 QTimer* twinkleTimer = nullptr;
499 int twinkleTick = 0;
500 QColor twinkleSavedColor;
501 double twinkleSavedOpacity = 1.0;
502 std::string twinkleVolumeName;
503
507 void centreTwinkle();
508
509private slots:
520 void onItemChanged(QTreeWidgetItem* item, int column);
521
529 void onColorButtonClicked();
530
536 void onTreeItemClicked(QTreeWidgetItem* item, int column);
537
543 void onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
544
555 void changeStyle();
556
561 void onOpacitySliderChanged(int value);
562
571 void inspectVolume();
572
576 void showMirrorProperties();
577
585 void drawOverlapsWarning();
586
590 void onTwinkleStep();
591};
Lightweight per-volume record used by GTree to populate the UI.
Definition gtree.h:44
std::string get_mirrorName() const
Return the associated mirror name.
Definition gtree.h:225
void set_recursive(bool recursive)
Set the recursive flag.
Definition gtree.h:231
int get_representation() const
Return the cached representation mode.
Definition gtree.h:181
std::string get_solidsOpr() const
Return the boolean solid operation descriptor.
Definition gtree.h:221
std::string get_motherVolume() const
Return the mother volume name.
Definition gtree.h:219
static std::string vname_from_v4name(std::string v4name)
Extract the "leaf" volume name from a full volume name.
Definition gtree.cc:401
double get_opacity() const
Return the cached opacity (alpha) in [0,1].
Definition gtree.h:184
std::string get_volDescription() const
Return the volume description.
Definition gtree.h:223
std::string get_rotation() const
Return the placement rotation string with units.
Definition gtree.h:217
double get_density() const
Return the density, computing it on first request.
Definition gtree.h:199
void set_color(const QColor &c)
Update the cached color.
Definition gtree.h:241
void set_opacity(double opacity)
Update the cached opacity.
Definition gtree.h:247
double get_volume() const
Return the volume, computing it on first request.
Definition gtree.h:193
bool get_visibility() const
Return the cached visibility state.
Definition gtree.h:178
double get_mass() const
Return the mass, computing it on first request.
Definition gtree.h:187
QColor get_color() const
Return the cached RGB color.
Definition gtree.h:175
bool get_recursive() const
Return the cached recursive flag.
Definition gtree.h:208
std::string get_solidType() const
Return the solid type string (e.g. "G4Box").
Definition gtree.h:211
static std::string system_from_v4name(std::string v4name)
Extract the system name from a full volume name.
Definition gtree.cc:407
std::string get_position() const
Return the placement position string with units.
Definition gtree.h:215
std::string get_parameters() const
Return the solid parameters string with units.
Definition gtree.h:213
std::string get_material() const
Return the cached material name.
Definition gtree.h:205
G4Ttree_item(G4Volume *g4volume, const GVolume *gvolume=nullptr)
Construct a cached record for a single geometry volume.
Definition gtree.cc:319
std::string get_mother() const
Return the cached mother name.
Definition gtree.h:172
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
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, std::unordered_map< std::string, const GMirror * > gmirrors_map={})
Construct the geometry tree widget.
Definition gtree.cc:414
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:275