gui
Loading...
Searching...
No Matches
topLayout.cc
Go to the documentation of this file.
1// gui
2#include "gui.h"
3#include "physicsView.h"
4#ifdef GEMC_HAS_QTCHARTS
5#include "gAnalysisView.h"
6#endif
7
8
9// qt
10#include <QString>
11#include <QCoreApplication>
12
13
14void GemcGUI::createTopButtons(QHBoxLayout* topLayout) {
15 // Build the top run-control row:
16 // - number-of-events field
17 // - run/cycle/stop/exit buttons
18 // - current event counter label
19 topLayout->setContentsMargins(0, 0, 0, 0);
20 topLayout->setSpacing(6);
21
22 auto* nEventsLabel = new QLabel(tr("N. Events:"));
23
24 auto* runButton = new QPushButton(tr("Run"));
25 runButton->setObjectName("gemcRun");
26 runButton->setToolTip(tr("Run events"));
27 runButton->setIcon(style()->standardIcon(QStyle::SP_MediaPlay));
28
29 // getting the number of events from eventDispenser, which
30 // in turns gets it from options if no grun file is provided
31 auto grunNumberOfEvents = std::to_string(eventDispenser->getTotalNumberOfEvents());
32 nEvents = new QLineEdit(QString::fromStdString(grunNumberOfEvents));
33 nEvents->setObjectName("gemcNumberOfEvents");
34 nEvents->setMaximumWidth(50);
35
36 auto* cycleButton = new QPushButton(tr("Cycle"));
37 cycleButton->setToolTip(tr("Run 1 event every 2 seconds"));
38 cycleButton->setIcon(style()->standardIcon(QStyle::SP_BrowserReload));
39
40 auto* stopButton = new QPushButton(tr("Stop"));
41 stopButton->setToolTip(tr("Stops running events"));
42 stopButton->setIcon(style()->standardIcon(QStyle::SP_MediaStop));
43
44 auto* closeButton = new QPushButton(tr("Exit"));
45 closeButton->setToolTip(tr("Quit GEMC"));
46 closeButton->setIcon(style()->standardIcon(QStyle::SP_TitleBarCloseButton));
47
48 // The label stores the cumulative number of processed events (as displayed to the user).
49 eventNumberLabel = new QLabel(tr("Event Number: %1").arg(displayedEventCount));
50 eventNumberLabel->setObjectName("gemcEventNumber");
51
52 topLayout->addWidget(nEventsLabel);
53 topLayout->addWidget(nEvents);
54 topLayout->addWidget(runButton);
55 topLayout->addWidget(cycleButton);
56 topLayout->addWidget(stopButton);
57 topLayout->addStretch(1);
58 topLayout->addWidget(eventNumberLabel);
59 topLayout->addStretch(40);
60 topLayout->addWidget(closeButton);
61
62 // Wire UI events to slots:
63 // - text edits update the backend event count
64 // - buttons trigger run/cycle/stop/quit behavior
65 connect(nEvents, &QLineEdit::textChanged, this, &GemcGUI::neventsChanged);
66 connect(closeButton, &QPushButton::clicked, this, &GemcGUI::gquit);
67 connect(runButton, &QPushButton::clicked, this, &GemcGUI::beamOn);
68 connect(cycleButton, &QPushButton::clicked, this, &GemcGUI::cycleBeamOn);
69 connect(stopButton, &QPushButton::clicked, this, &GemcGUI::stopCycleBeamOn);
70}
71
72
73void GemcGUI::gquit() {
74 // Request application shutdown through Qt's application object.
75 qApp->quit();
76}
77
78
79void GemcGUI::neventsChanged() {
80 // Push the new event count into the backend so the next run uses the updated value.
81 int newNevents = nEvents->text().toInt();
82 eventDispenser->setNumberOfEvents(newNevents);
83}
84
85void GemcGUI::beamOn() {
86 // Run a batch once, then update the GUI counter label.
87 if (physicsView && !physicsView->applyPending()) { return; }
88 prepareGeometryForBeamOn();
89 if (analysisAccumulator != nullptr) {
90#ifdef GEMC_HAS_QTCHARTS
91 analysisAccumulator->beginBeamOn(analysisView != nullptr && analysisView->accumulateEnabled());
92#else
93 analysisAccumulator->beginBeamOn(false);
94#endif
95 }
96 eventDispenser->processEvents();
97 if (physicsView) { physicsView->refreshProcesses(); }
98#ifdef GEMC_HAS_QTCHARTS
99 if (analysisView != nullptr) { analysisView->refresh(); }
100#endif
101 updateGui();
102}
103
104
105void GemcGUI::cycleBeamOn() {
106 // Enable periodic processing (2 seconds interval) and process events for this cycle.
107 if (!gtimer->isActive()) {
108 gtimer->start(2000);
109 }
110 if (physicsView && !physicsView->applyPending()) { gtimer->stop(); return; }
111 prepareGeometryForBeamOn();
112 if (analysisAccumulator != nullptr) {
113#ifdef GEMC_HAS_QTCHARTS
114 analysisAccumulator->beginBeamOn(analysisView != nullptr && analysisView->accumulateEnabled());
115#else
116 analysisAccumulator->beginBeamOn(false);
117#endif
118 }
119 eventDispenser->processEvents();
120 if (physicsView) { physicsView->refreshProcesses(); }
121#ifdef GEMC_HAS_QTCHARTS
122 if (analysisView != nullptr) { analysisView->refresh(); }
123#endif
124}
125
126
127void GemcGUI::stopCycleBeamOn() { gtimer->stop(); }