7#include "G4UImanager.hh"
14void resetSceneBeforeGeometryReload(G4UImanager* g4uim) {
15 if (!g4uim) {
return; }
17 g4uim->ApplyCommand(
"/vis/viewer/set/autoRefresh false");
18 g4uim->ApplyCommand(
"/vis/scene/endOfEventAction accumulate 0");
19 g4uim->ApplyCommand(
"/vis/scene/endOfRunAction refresh");
20 g4uim->ApplyCommand(
"/vis/scene/removeModel all");
21 g4uim->ApplyCommand(
"/vis/viewer/clearTransients");
22 g4uim->ApplyCommand(
"/vis/viewer/clear");
23 g4uim->ApplyCommand(
"/vis/viewer/set/autoRefresh true");
24 g4uim->ApplyCommand(
"/vis/viewer/flush");
25 g4uim->ApplyCommand(
"/vis/viewer/clearTransients");
28void resetEventDrawingBeforeRun(G4UImanager* g4uim) {
29 if (!g4uim) {
return; }
31 g4uim->ApplyCommand(
"/vis/viewer/set/autoRefresh false");
32 g4uim->ApplyCommand(
"/vis/scene/endOfEventAction accumulate 0");
33 g4uim->ApplyCommand(
"/vis/scene/endOfRunAction refresh");
34 g4uim->ApplyCommand(
"/vis/viewer/clearTransients");
35 g4uim->ApplyCommand(
"/vis/viewer/clear");
36 g4uim->ApplyCommand(
"/vis/viewer/flush");
37 g4uim->ApplyCommand(
"/vis/viewer/clearTransients");
40void restoreSceneModels(G4UImanager* g4uim,
const std::shared_ptr<GOptions>& gopts,
bool includeEventModels) {
41 if (!g4uim) {
return; }
46 g4uim->ApplyCommand(
"/vis/viewer/set/autoRefresh false");
47 g4uim->ApplyCommand(
"/vis/scene/removeModel all");
48 g4uim->ApplyCommand(
"/vis/viewer/clearTransients");
49 g4uim->ApplyCommand(
"/vis/viewer/clear");
50 g4uim->ApplyCommand(
"/vis/drawVolume");
51 g4uim->ApplyCommand(
"/vis/viewer/set/background " + g4view.background);
52 g4uim->ApplyCommand(
"/vis/viewer/set/numberOfCloudPoints " + std::to_string(g4view.cloudPoints));
53 for (
const auto& command : g4SceneProperties.addSceneDecorations(gopts)) { g4uim->ApplyCommand(command); }
54 for (
const auto& command : g4SceneProperties.addSceneTexts(gopts)) { g4uim->ApplyCommand(command); }
55 if (includeEventModels) {
57 g4uim->ApplyCommand(
"/vis/scene/add/trajectories smooth");
58 g4uim->ApplyCommand(
"/vis/modeling/trajectories/create/drawByCharge");
59 g4uim->ApplyCommand(
"/vis/modeling/trajectories/drawByCharge-0/default/setDrawStepPts true");
60 g4uim->ApplyCommand(
"/vis/modeling/trajectories/drawByCharge-0/default/setStepPtsSize 2");
61 g4uim->ApplyCommand(
"/vis/scene/add/hits");
62 g4uim->ApplyCommand(
"/vis/scene/endOfEventAction accumulate 10000");
63 if (decorations.eventID) {
64 g4uim->ApplyCommand(
"/vis/scene/add/eventID " + std::to_string(decorations.eventIDSize));
67 g4uim->ApplyCommand(
"/vis/viewer/set/autoRefresh true");
68 g4uim->ApplyCommand(
"/vis/viewer/flush");
74 std::shared_ptr<EventDispenser> ed,
76 bool viewerAlreadyInitialized,
81 detectorConstruction(dc),
82 viewerInitialized(viewerAlreadyInitialized) {
91 guiSession = std::make_unique<GUI_Session>(gopts,
gboard);
94 createRightContent(gopts, dc,
gboard);
97 auto* topLayout =
new QHBoxLayout;
98 createTopButtons(topLayout);
101 auto* bottomLayout =
new QHBoxLayout;
102 bottomLayout->setContentsMargins(0, 0, 0, 0);
103 bottomLayout->setSpacing(6);
105 bottomLayout->addWidget(leftButtons, 1);
106 bottomLayout->addWidget(rightContent, 10);
109 auto* mainLayout =
new QVBoxLayout;
110 mainLayout->setContentsMargins(6, 6, 6, 6);
111 mainLayout->setSpacing(6);
112 mainLayout->addLayout(topLayout);
113 mainLayout->addLayout(bottomLayout, 1);
114 mainLayout->addWidget(
gboard, 0);
116 setLayout(mainLayout);
117 setWindowTitle(tr(
"GEMC: Geant4 Monte-Carlo"));
119 setMinimumHeight(760);
120 resize(1000, std::max(sizeHint().height(), 760));
121 QTimer::singleShot(0,
this, [
this]() {
123 const int preferredHeight = std::max(sizeHint().height(), 760);
124 setMinimumHeight(preferredHeight);
125 resize(1000, preferredHeight);
129 gtimer =
new QTimer(
this);
130 connect(gtimer, SIGNAL(timeout()),
this, SLOT(cycleBeamOn()));
134 SIGNAL(currentItemChanged(QListWidgetItem *, QListWidgetItem*)),
135 this, SLOT(change_page(QListWidgetItem *, QListWidgetItem*)));
139void GemcGUI::updateGui() {
143 int nThatWasRun = nEvents->text().toInt();
144 int nBefore = stoi(sBefore[2]);
146 QString newNEvents(
"Event Number: ");
147 newNEvents.append(std::to_string(nBefore + nThatWasRun).c_str());
149 eventNumberLabel->setText(newNEvents);
153void GemcGUI::resetVisualizationBeforeGeometryReload() {
154 resetSceneBeforeGeometryReload(G4UImanager::GetUIpointer());
157void GemcGUI::refreshVisualizationFromOptions() {
160 auto* g4uim = G4UImanager::GetUIpointer();
161 if (!g4uim) {
return; }
163 restoreSceneModels(g4uim, guiOptions,
false);
164 visualizationNeedsRunRestore =
true;
167void GemcGUI::refreshGeometryTree() {
168 if (!rightContent || !detectorConstruction || !guiOptions || !geometryTree) {
return; }
170 geometryReloadedSinceRun =
true;
172 const int treeIndex = rightContent->indexOf(geometryTree);
173 if (treeIndex < 0) {
return; }
175 const int currentIndex = rightContent->currentIndex();
176 auto* g4uim = G4UImanager::GetUIpointer();
177 if (!g4uim) {
return; }
181 : std::unordered_map<std::string, G4Volume*>{};
184 : std::unordered_map<std::string, const GVolume*>{};
185 auto* refreshedTree =
new GTree(guiOptions, g4volumes, gvolumes);
187 rightContent->removeWidget(geometryTree);
188 geometryTree->deleteLater();
189 geometryTree = refreshedTree;
190 rightContent->insertWidget(treeIndex, geometryTree);
191 rightContent->setCurrentIndex(currentIndex == treeIndex ? treeIndex : currentIndex);
193 if (g4volumes.size() > 1) {
194 if (!viewerInitialized) {
197 auto commands = g4SceneProperties.scene_commands(guiOptions);
198 for (
const auto& command : commands) { g4uim->ApplyCommand(command); }
199 viewerInitialized =
true;
202 restoreSceneModels(g4uim, guiOptions,
false);
206void GemcGUI::prepareGeometryForBeamOn() {
207 if ((!geometryReloadedSinceRun && !visualizationNeedsRunRestore) || !detectorConstruction) {
return; }
210 auto* g4uim = G4UImanager::GetUIpointer();
211 resetEventDrawingBeforeRun(g4uim);
213 if (geometryReloadedSinceRun) {
223 restoreSceneModels(g4uim, guiOptions,
true);
225 geometryReloadedSinceRun =
false;
226 visualizationNeedsRunRestore =
false;
236void GemcGUI::change_page(QListWidgetItem* current, QListWidgetItem* previous) {
244 rightContent->setCurrentIndex(thisIndex);
std::unordered_map< std::string, const GVolume * > get_gvolumes_flat_map() const
std::unordered_map< std::string, G4Volume * > get_g4volumes_map() const
void prepare_geometry_for_run()
bool has_built_geometry() const
GemcGUI(std::shared_ptr< GOptions > gopts, std::shared_ptr< EventDispenser > ed, GDetectorConstruction *dc, bool viewerAlreadyInitialized=false, QWidget *parent=nullptr)
Construct the main GUI widget.
~GemcGUI() override
Destroy the GUI widget and release explicitly owned resources.
G4View getG4View(const std::shared_ptr< GOptions > &gopts)
G4Decorations getG4Decorations(const std::shared_ptr< GOptions > &gopts)
vector< std::string > getStringVectorFromString(const std::string &input)