1 | #include "MainWindow.h"
|
---|
2 |
|
---|
3 | #include <iostream>
|
---|
4 | #include <sstream>
|
---|
5 |
|
---|
6 | #include <QTimer>
|
---|
7 |
|
---|
8 | #include "src/Dim.h"
|
---|
9 |
|
---|
10 | #include "DockWindow.h"
|
---|
11 | #include "HtmlDelegate.h"
|
---|
12 | #include "CheckBoxDelegate.h"
|
---|
13 |
|
---|
14 | using namespace std;
|
---|
15 |
|
---|
16 | MainWindow::MainWindow(QWidget *p) : QMainWindow(p)
|
---|
17 | {
|
---|
18 | // setupUi MUST be called before the DimNetwork is initilized
|
---|
19 | // In this way it can be ensured that nothing from the
|
---|
20 | // DimNetwork arrives before all graphical elements are
|
---|
21 | // initialized. This is a simple but very powerfull trick.
|
---|
22 | setupUi(this);
|
---|
23 |
|
---|
24 | // Now here we can do further setup which should be done
|
---|
25 | // before the gui is finally displayed.
|
---|
26 | fDimCmdServers->setItemDelegate(new CheckBoxDelegate);
|
---|
27 | fDimCmdCommands->setItemDelegate(new CheckBoxDelegate);
|
---|
28 | fDimCmdDescription->setItemDelegate(new HtmlDelegate);
|
---|
29 |
|
---|
30 | fDimSvcServers->setItemDelegate(new CheckBoxDelegate);
|
---|
31 | fDimSvcServices->setItemDelegate(new CheckBoxDelegate);
|
---|
32 | fDimSvcDescription->setItemDelegate(new HtmlDelegate);
|
---|
33 |
|
---|
34 | // Set a default string to be displayed in a the status bar at startup
|
---|
35 | fStatusBar->showMessage(PACKAGE_STRING" | "PACKAGE_URL" | report bugs to <"PACKAGE_BUGREPORT">");
|
---|
36 |
|
---|
37 | // Initialize the 40 FTU Leds as a copy of the prototype LED
|
---|
38 | fFtuLED[0] = fFtuLEDPrototype;
|
---|
39 | fFtuLED[0]->setToolTip("Crate 0, Board 0, Index 0");
|
---|
40 |
|
---|
41 | for (int i=1; i<40; i++)
|
---|
42 | {
|
---|
43 | QPushButton *b = new QPushButton(static_cast<QWidget*>(fFtuLEDPrototype->parent()));
|
---|
44 |
|
---|
45 | b->setEnabled(fFtuLEDPrototype->isEnabled());
|
---|
46 | b->setSizePolicy(fFtuLEDPrototype->sizePolicy());
|
---|
47 | b->setMaximumSize(fFtuLEDPrototype->maximumSize());
|
---|
48 | b->setIcon(fFtuLEDPrototype->icon());
|
---|
49 | b->setIconSize(fFtuLEDPrototype->iconSize());
|
---|
50 | b->setCheckable(fFtuLEDPrototype->isCheckable());
|
---|
51 | b->setFlat(fFtuLEDPrototype->isFlat());
|
---|
52 |
|
---|
53 | ostringstream str;
|
---|
54 | str << "Crate " << i/10 << ", Board " << i%10 << ", Index " << i;
|
---|
55 | b->setToolTip(str.str().c_str());
|
---|
56 |
|
---|
57 | fFtuLedLayout->addWidget(b, i/10+1, i%10+1, 1, 1);
|
---|
58 |
|
---|
59 | fFtuLED[i] = b;
|
---|
60 | }
|
---|
61 |
|
---|
62 | for (int i=0; i<40; i++)
|
---|
63 | {
|
---|
64 | fFtuLED[i]->setObjectName(QString::fromUtf8("fFtuLED")+QString::number(i));
|
---|
65 | QObject::connect(fFtuLED[i], SIGNAL(clicked()), this, SLOT(slot_fFtuLED_clicked()));
|
---|
66 | }
|
---|
67 |
|
---|
68 | // Initialize a timer to update the displayed UTC time
|
---|
69 | QTimer *timer = new QTimer(this);
|
---|
70 | connect(timer, SIGNAL(timeout()), this, SLOT(slot_TimeUpdate()));
|
---|
71 | timer->start(100);
|
---|
72 | }
|
---|
73 |
|
---|
74 | void MainWindow::slot_TimeUpdate()
|
---|
75 | {
|
---|
76 | // Used toTUC to support also older Qt versions
|
---|
77 | fUTC->setDateTime(QDateTime::currentDateTime().toUTC());
|
---|
78 | }
|
---|
79 |
|
---|
80 | void MainWindow::SelectTab(const QString &name)
|
---|
81 | {
|
---|
82 | for (int i=0; i<fTabWidget->count(); i++)
|
---|
83 | if (fTabWidget->tabText(i)==name)
|
---|
84 | {
|
---|
85 | fTabWidget->setCurrentIndex(i);
|
---|
86 | break;
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | void MainWindow::on_fShutdown_clicked()
|
---|
92 | {
|
---|
93 | Dim::SendCommand("DIS_DNS/KILL_SERVERS");
|
---|
94 | }
|
---|
95 |
|
---|
96 |
|
---|
97 | void MainWindow::on_fShutdownAll_clicked()
|
---|
98 | {
|
---|
99 | Dim::SendCommand("DIS_DNS/KILL_SERVERS");
|
---|
100 | Dim::SendCommand("DIS_DNS/EXIT", int(1));
|
---|
101 | }
|
---|
102 |
|
---|
103 | void MainWindow::on_fTabWidget_tabCloseRequested(int which)
|
---|
104 | {
|
---|
105 | // To get the correct size we have to switch to this tab
|
---|
106 | // An alternative would be to take the size of the current tab
|
---|
107 | fTabWidget->setCurrentIndex(which);
|
---|
108 |
|
---|
109 | QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
|
---|
110 | if (!w)
|
---|
111 | {
|
---|
112 | cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
|
---|
113 | return;
|
---|
114 | }
|
---|
115 |
|
---|
116 | QDockWidget *d = w->findChild<QDockWidget*>();
|
---|
117 | if (!d)
|
---|
118 | {
|
---|
119 | cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
|
---|
120 | return;
|
---|
121 | }
|
---|
122 |
|
---|
123 | new DockWindow(d, fTabWidget->tabText(which));
|
---|
124 | fTabWidget->removeTab(which);
|
---|
125 |
|
---|
126 | if (fTabWidget->count()==1)
|
---|
127 | fTabWidget->setTabsClosable(false);
|
---|
128 | }
|
---|
129 |
|
---|
130 | void MainWindow::SetTriggerSequence()
|
---|
131 | {
|
---|
132 | const uint8_t d[3] =
|
---|
133 | {
|
---|
134 | uint8_t(fTriggerSeqPed->value()),
|
---|
135 | uint8_t(fTriggerSeqLPext->value()),
|
---|
136 | uint8_t(fTriggerSeqLPint->value())
|
---|
137 | };
|
---|
138 |
|
---|
139 | if (!fInHandler)
|
---|
140 | Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
|
---|
141 | }
|
---|
142 |
|
---|
143 | void on_fEnableTrigger_clicked(bool b)
|
---|
144 | {
|
---|
145 | Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
|
---|
146 | }
|
---|
147 |
|
---|
148 | void on_fEnableExt1_clicked(bool b)
|
---|
149 | {
|
---|
150 | Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
|
---|
151 | }
|
---|
152 |
|
---|
153 | void on_fEnableExt2_clicked(bool b)
|
---|
154 | {
|
---|
155 | Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
|
---|
156 | }
|
---|
157 |
|
---|
158 | void on_fEnableVeto_clicked(bool b)
|
---|
159 | {
|
---|
160 | Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
|
---|
161 | }
|
---|
162 |
|
---|
163 | void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
|
---|
164 | {
|
---|
165 | if (!fInHandler)
|
---|
166 | Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", v);
|
---|
167 | }
|
---|
168 |
|
---|
169 | void MainWindow::on_fPhysicsWindow_valueChanged(int v)
|
---|
170 | {
|
---|
171 | if (!fInHandler)
|
---|
172 | Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
|
---|
173 | }
|
---|
174 |
|
---|
175 | void MainWindow::on_fCalibCoincidence_valueChanged(int v)
|
---|
176 | {
|
---|
177 | if (!fInHandler)
|
---|
178 | Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", v);
|
---|
179 | }
|
---|
180 |
|
---|
181 | void MainWindow::on_fCalibWindow_valueChanged(int v)
|
---|
182 | {
|
---|
183 | if (!fInHandler)
|
---|
184 | Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
|
---|
185 | }
|
---|
186 |
|
---|
187 | void MainWindow::on_fThresholdVal_valueChanged(int v)
|
---|
188 | {
|
---|
189 | fThresholdVolt->setValue(2500./4095*v);
|
---|
190 |
|
---|
191 | const int32_t d[2] = { fThresholdIdx->value(), v };
|
---|
192 |
|
---|
193 | if (!fInHandler)
|
---|
194 | Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
|
---|
195 | }
|
---|
196 |
|
---|
197 | void MainWindow::on_fTriggerInterval_valueChanged(int val)
|
---|
198 | {
|
---|
199 | if (!fInHandler)
|
---|
200 | Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
|
---|
201 | }
|
---|
202 |
|
---|
203 | void MainWindow::on_fTriggerDelay_valueChanged(int val)
|
---|
204 | {
|
---|
205 | if (!fInHandler)
|
---|
206 | Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
|
---|
207 | }
|
---|
208 |
|
---|
209 | void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
|
---|
210 | {
|
---|
211 | if (!fInHandler)
|
---|
212 | Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
|
---|
213 | }
|
---|
214 |
|
---|
215 | void MainWindow::on_fDeadTime_valueChanged(int val)
|
---|
216 | {
|
---|
217 | if (!fInHandler)
|
---|
218 | Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
|
---|
219 | }
|
---|
220 |
|
---|
221 | void MainWindow::on_fPrescalingVal_valueChanged(int val)
|
---|
222 | {
|
---|
223 | if (!fInHandler)
|
---|
224 | Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
|
---|
225 | }
|
---|
226 |
|
---|
227 | void MainWindow::on_fPixelEnable_stateChanged(int b)
|
---|
228 | {
|
---|
229 | cout << "PIXEL: " << fPixelIdx->value() << " " << b << endl;
|
---|
230 | if (!fInHandler)
|
---|
231 | Dim::SendCommand(b==Qt::Unchecked ?
|
---|
232 | "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
|
---|
233 | uint16_t(fPixelIdx->value()));
|
---|
234 | }
|
---|
235 |
|
---|
236 | void MainWindow::on_fEnableTrigger_stateChanged(int b)
|
---|
237 | {
|
---|
238 | if (!fInHandler)
|
---|
239 | Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b==Qt::Checked);
|
---|
240 | }
|
---|
241 |
|
---|
242 | void MainWindow::on_fEnableExt1_stateChanged(int b)
|
---|
243 | {
|
---|
244 | if (!fInHandler)
|
---|
245 | Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b==Qt::Checked);
|
---|
246 | }
|
---|
247 |
|
---|
248 | void MainWindow::on_fEnableExt2_stateChanged(int b)
|
---|
249 | {
|
---|
250 | if (!fInHandler)
|
---|
251 | Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b==Qt::Checked);
|
---|
252 | }
|
---|
253 |
|
---|
254 | void MainWindow::on_fEnableClockCond_stateChanged(int b)
|
---|
255 | {
|
---|
256 | if (!fInHandler)
|
---|
257 | Dim::SendCommand("FTM_CONTROL/ENABLE_CLOCK_CONDITIONER", b==Qt::Checked);
|
---|
258 | }
|
---|
259 |
|
---|
260 | void MainWindow::on_fEnableVeto_stateChanged(int b)
|
---|
261 | {
|
---|
262 | if (!fInHandler)
|
---|
263 | Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b==Qt::Checked);
|
---|
264 | }
|
---|
265 |
|
---|
266 | void MainWindow::slot_fFtuLED_clicked()
|
---|
267 | {
|
---|
268 | for (int32_t i=0; i<40; i++)
|
---|
269 | if (sender()==fFtuLED[i])
|
---|
270 | {
|
---|
271 | Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
|
---|
272 | break;
|
---|
273 | }
|
---|
274 | }
|
---|
275 |
|
---|
276 | void MainWindow::on_fPing_toggled(bool checked)
|
---|
277 | {
|
---|
278 | if (checked)
|
---|
279 | Dim::SendCommand("FTM_CONTROL/PING");
|
---|
280 | }
|
---|
281 |
|
---|
282 | void MainWindow::on_fChatSend_clicked()
|
---|
283 | {
|
---|
284 | if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
|
---|
285 | fChatMessage->clear();
|
---|
286 | }
|
---|
287 |
|
---|
288 | void MainWindow::on_fStatusLoggerLed_clicked()
|
---|
289 | {
|
---|
290 | SelectTab("Logger");
|
---|
291 | }
|
---|
292 |
|
---|
293 | void MainWindow::on_fStatusChatLed_clicked()
|
---|
294 | {
|
---|
295 | SelectTab("Chat");
|
---|
296 | }
|
---|
297 |
|
---|
298 | void MainWindow::on_fStatusFTMLed_clicked()
|
---|
299 | {
|
---|
300 | SelectTab("Trigger");
|
---|
301 | }
|
---|
302 |
|
---|
303 | void MainWindow::on_fStatusFTULed_clicked()
|
---|
304 | {
|
---|
305 | SelectTab("FTUs");
|
---|
306 | }
|
---|
307 |
|
---|
308 | void MainWindow::on_fStatusFADLed_clicked()
|
---|
309 | {
|
---|
310 | SelectTab("FAD");
|
---|
311 | }
|
---|