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
120 mutable double mass = 0.0;
121
125 mutable double volume = 0.0;
126
130 mutable double density = 0.0;
131
133 mutable bool physics_computed = false;
134
136 G4LogicalVolume* logical_ptr = nullptr;
137
139 G4VSolid* solid_ptr = nullptr;
140
148 void compute_physics_quantities() const;
149
157 bool recursive = false;
158
159 // pygemc descriptor fields (empty when no GVolume descriptor is available)
160 std::string solidType;
161 std::string parameters;
162 std::string position;
163 std::string rotation;
164 std::string motherVolume;
165 std::string solidsOpr;
166 std::string volDescription;
167
168public:
170 [[nodiscard]] std::string get_mother() const { return mother; }
171
173 [[nodiscard]] QColor get_color() const { return color; }
174
176 [[nodiscard]] bool get_visibility() const { return is_visible; }
177
179 [[nodiscard]] int get_representation() const { return representation; }
180
182 [[nodiscard]] double get_opacity() const { return opacity; }
183
185 [[nodiscard]] double get_mass() const {
186 compute_physics_quantities();
187 return mass;
188 }
189
191 [[nodiscard]] double get_volume() const {
192 compute_physics_quantities();
193 return volume;
194 }
195
197 [[nodiscard]] double get_density() const {
198 compute_physics_quantities();
199 return density;
200 }
201
203 [[nodiscard]] std::string get_material() const { return material; }
204
206 [[nodiscard]] bool get_recursive() const { return recursive; }
207
209 [[nodiscard]] std::string get_solidType() const { return solidType; }
211 [[nodiscard]] std::string get_parameters() const { return parameters; }
213 [[nodiscard]] std::string get_position() const { return position; }
215 [[nodiscard]] std::string get_rotation() const { return rotation; }
217 [[nodiscard]] std::string get_motherVolume() const { return motherVolume; }
219 [[nodiscard]] std::string get_solidsOpr() const { return solidsOpr; }
221 [[nodiscard]] std::string get_volDescription() const { return volDescription; }
222
227 void set_recursive(bool recursive) { this->recursive = recursive; }
228
237 void set_color(const QColor& c) { color = c; }
238
243 void set_opacity(double opacity) { this->opacity = opacity; }
244
255 static std::string vname_from_v4name(std::string v4name);
256
267 static std::string system_from_v4name(std::string v4name);
268};
269
270// map for a single system
271using g4tree_map = std::map<std::string, std::unique_ptr<G4Ttree_item>>;
272
292class GTree : public QWidget, public GBase<GTree>
293{
294 Q_OBJECT
295
296public:
312 explicit GTree(const std::shared_ptr<GOptions>& gopt,
313 std::unordered_map<std::string, G4Volume*> g4volumes_map,
314 std::unordered_map<std::string, const GVolume*> gvolumes_map = {},
315 QWidget* parent = nullptr);
316
320 GTree(const GTree&) = delete;
321
325 GTree& operator=(const GTree&) = delete;
326
327private:
336 std::map<std::string, g4tree_map> g4_systems_tree; // map of systems
337
344 std::unordered_map<std::string, const GVolume*> gvolumes_map;
345
349 QTreeWidget* treeWidget = nullptr;
350
351 // right-side panel
355 QWidget* rightPanel = nullptr;
356
360 QWidget* bottomPanel = nullptr; // appears only when an item is selected
361
365 GQTButtonsWidget* styleButtons; // left bar buttons
366
367 // info labels inside bottomPanel
368 QLabel* typeLabel = nullptr;
369 QLabel* daughtersLabel = nullptr;
370 QLabel* nameLabel = nullptr;
371 QLabel* materialLabel = nullptr;
372 QLabel* massLabel = nullptr;
373 QLabel* volumeLabel = nullptr;
374 QLabel* densityLabel = nullptr;
375 QLabel* solidTypeLabel = nullptr;
376 QTextEdit* parametersLabel = nullptr;
377 QLabel* positionLabel = nullptr;
378 QLabel* rotationLabel = nullptr;
379 QLabel* motherLabel = nullptr;
380 QLabel* descriptionLabel = nullptr;
381
385 QSlider* opacitySlider = nullptr;
386
390 QLabel* opacityLabel = nullptr;
391
398 QPushButton* inspectButton = nullptr;
399
409 QPushButton* drawOverlapsButton = nullptr;
410
415 void build_tree(std::unordered_map<std::string, G4Volume*> g4volumes_map);
416
426 void populateTree();
427
433 void set_visibility(const std::string& fullName, bool visible);
434
440 void set_color(const std::string& fullName, const QColor& c);
441
447 void set_opacity(const std::string& volumeName, double opacity);
448
453 QWidget* right_widget();
454
460 int get_ndaughters(QTreeWidgetItem* item) const;
461
467 G4Ttree_item* findTreeItem(const std::string& fullName);
468
476 std::string current_volume_name;
477
478 // Twinkle animation state
479 QTimer* twinkleTimer = nullptr;
480 int twinkleTick = 0;
481 QColor twinkleSavedColor;
482 double twinkleSavedOpacity = 1.0;
483 std::string twinkleVolumeName;
484
488 void centreTwinkle();
489
490private slots:
501 void onItemChanged(QTreeWidgetItem* item, int column);
502
510 void onColorButtonClicked();
511
517 void onTreeItemClicked(QTreeWidgetItem* item, int column);
518
524 void onCurrentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);
525
536 void changeStyle();
537
542 void onOpacitySliderChanged(int value);
543
552 void inspectVolume();
553
561 void drawOverlapsWarning();
562
566 void onTwinkleStep();
567};
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:227
int get_representation() const
Return the cached representation mode.
Definition gtree.h:179
std::string get_solidsOpr() const
Return the boolean solid operation descriptor.
Definition gtree.h:219
std::string get_motherVolume() const
Return the mother volume name.
Definition gtree.h:217
static std::string vname_from_v4name(std::string v4name)
Extract the "leaf" volume name from a full volume name.
Definition gtree.cc:355
double get_opacity() const
Return the cached opacity (alpha) in [0,1].
Definition gtree.h:182
std::string get_volDescription() const
Return the volume description.
Definition gtree.h:221
std::string get_rotation() const
Return the placement rotation string with units.
Definition gtree.h:215
double get_density() const
Return the density, computing it on first request.
Definition gtree.h:197
void set_color(const QColor &c)
Update the cached color.
Definition gtree.h:237
void set_opacity(double opacity)
Update the cached opacity.
Definition gtree.h:243
double get_volume() const
Return the volume, computing it on first request.
Definition gtree.h:191
bool get_visibility() const
Return the cached visibility state.
Definition gtree.h:176
double get_mass() const
Return the mass, computing it on first request.
Definition gtree.h:185
QColor get_color() const
Return the cached RGB color.
Definition gtree.h:173
bool get_recursive() const
Return the cached recursive flag.
Definition gtree.h:206
std::string get_solidType() const
Return the solid type string (e.g. "G4Box").
Definition gtree.h:209
static std::string system_from_v4name(std::string v4name)
Extract the system name from a full volume name.
Definition gtree.cc:361
std::string get_position() const
Return the placement position string with units.
Definition gtree.h:213
std::string get_parameters() const
Return the solid parameters string with units.
Definition gtree.h:211
std::string get_material() const
Return the cached material name.
Definition gtree.h:203
G4Ttree_item(G4Volume *g4volume, const GVolume *gvolume=nullptr)
Construct a cached record for a single geometry volume.
Definition gtree.cc:274
std::string get_mother() const
Return the cached mother name.
Definition gtree.h:170
GBase(const std::shared_ptr< GOptions > &gopt, std::string logger_name="")
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:368
std::map< std::string, std::unique_ptr< G4Ttree_item > > g4tree_map
Definition gtree.h:271