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