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