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