source: trunk/FACT++/gui/MainWindow.cc@ 11705

Last change on this file since 11705 was 11698, checked in by tbretz, 13 years ago
Fixed a bug in the name of the slots for the light pulse intensity.
File size: 14.0 KB
Line 
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
14using namespace std;
15
16void MainWindow::MakeLEDs(QPushButton **arr, QGridLayout *lay, const char *slot) const
17{
18 arr[0]->setToolTip("Crate 0, Board 0, Index 0");
19
20 for (int i=1; i<40; i++)
21 {
22 QPushButton *b = new QPushButton(static_cast<QWidget*>(arr[0]->parent()));
23
24 b->setEnabled(arr[0]->isEnabled());
25 b->setSizePolicy(arr[0]->sizePolicy());
26 b->setMaximumSize(arr[0]->maximumSize());
27 b->setIcon(arr[0]->icon());
28 b->setIconSize(arr[0]->iconSize());
29 b->setCheckable(arr[0]->isCheckable());
30 b->setFlat(arr[0]->isFlat());
31
32 ostringstream str;
33 str << "Crate " << i/10 << ", Board " << i%10 << ", Index " << i;
34 b->setToolTip(str.str().c_str());
35
36 lay->addWidget(b, i/10+1, i%10+1, 1, 1);
37
38 arr[i] = b;
39 }
40
41 const QString name = arr[0]->objectName();
42
43 for (int i=0; i<40; i++)
44 {
45 arr[i]->setObjectName(name+QString::number(i));
46 QObject::connect(arr[i], SIGNAL(clicked()), this, slot);
47 }
48}
49
50MainWindow::MainWindow(QWidget *p) : QMainWindow(p)
51{
52 // setupUi MUST be called before the DimNetwork is initilized
53 // In this way it can be ensured that nothing from the
54 // DimNetwork arrives before all graphical elements are
55 // initialized. This is a simple but very powerfull trick.
56 setupUi(this);
57
58 // Now here we can do further setup which should be done
59 // before the gui is finally displayed.
60 fDimCmdServers->setItemDelegate(new CheckBoxDelegate);
61 fDimCmdCommands->setItemDelegate(new CheckBoxDelegate);
62 fDimCmdDescription->setItemDelegate(new HtmlDelegate);
63
64 fDimSvcServers->setItemDelegate(new CheckBoxDelegate);
65 fDimSvcServices->setItemDelegate(new CheckBoxDelegate);
66 fDimSvcDescription->setItemDelegate(new HtmlDelegate);
67
68 // Set a default string to be displayed in a the status bar at startup
69 fStatusBar->showMessage(PACKAGE_STRING" | "PACKAGE_URL" | report bugs to <"PACKAGE_BUGREPORT">");
70
71 // Initialize the 40 FTU Leds as a copy of the prototype LED
72 fFtuLED[0] = fFtuLEDPrototype;
73 MakeLEDs(fFtuLED, fFtuLedLayout, SLOT(slot_fFtuLED_clicked()));
74
75 // Initialize the 40 FAD Leds as a copy of the prototype LED
76 fFadLED[0] = fFadLEDPrototype;
77 MakeLEDs(fFadLED, fFadLedLayout, SLOT(slot_fFadLED_clicked()));
78
79 // Initialize a timer to update the displayed UTC time
80 QTimer *timer = new QTimer(this);
81 connect(timer, SIGNAL(timeout()), this, SLOT(slot_TimeUpdate()));
82 timer->start(100);
83}
84
85void MainWindow::slot_TimeUpdate()
86{
87 // Used toUTC to support also older Qt versions
88 // toTime_t() always returns the datetime converted to UTC
89 // dateTime() unfortunately returns our UTC always as LocalTime
90 QDateTime now = QDateTime::currentDateTime().toUTC();
91 now.setTimeSpec(Qt::LocalTime);
92
93 if (now.toTime_t()==fUTC->dateTime().toTime_t())
94 return;
95
96 fUTC->setDateTime(now);
97}
98
99
100void MainWindow::SelectTab(const QString &name)
101{
102 for (int i=0; i<fTabWidget->count(); i++)
103 if (fTabWidget->tabText(i)==name)
104 {
105 fTabWidget->setCurrentIndex(i);
106 break;
107 }
108}
109
110
111void MainWindow::on_fShutdown_clicked()
112{
113 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
114}
115
116
117void MainWindow::on_fShutdownAll_clicked()
118{
119 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
120 Dim::SendCommand("DIS_DNS/EXIT", int(1));
121}
122
123void MainWindow::on_fTabWidget_tabCloseRequested(int which)
124{
125 // To get the correct size we have to switch to this tab
126 // An alternative would be to take the size of the current tab
127 fTabWidget->setCurrentIndex(which);
128
129 QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
130 if (!w)
131 {
132 cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
133 return;
134 }
135
136 QDockWidget *d = w->findChild<QDockWidget*>();
137 if (!d)
138 {
139 cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
140 return;
141 }
142
143 new DockWindow(d, fTabWidget->tabText(which));
144 fTabWidget->removeTab(which);
145
146 if (fTabWidget->count()==1)
147 fTabWidget->setTabsClosable(false);
148}
149
150void MainWindow::on_fMcpStartRun_clicked()
151{
152 struct Value
153 {
154 uint64_t time;
155 uint64_t nevts;
156 char type[];
157 };
158
159 const int idx1 = fMcpRunType->currentIndex();
160 const int idx2 = fMcpTime->currentIndex();
161 const int idx3 = fMcpNumEvents->currentIndex();
162
163 const int64_t v2 = fMcpTime->itemData(idx2).toInt();
164 const int64_t v3 = fMcpNumEvents->itemData(idx3).toInt();
165
166 const QString rt = fMcpRunType->itemData(idx1).toString();
167
168 const size_t len = sizeof(Value)+rt.length()+1;
169
170 char *buf = new char[len];
171
172 Value *val = reinterpret_cast<Value*>(buf);
173
174 val->time = v2;
175 val->nevts = v3;
176
177 strcpy(val->type, rt.toStdString().c_str());
178
179 Dim::SendCommand("MCP/START", buf, len);
180
181 delete [] buf;
182
183}
184void MainWindow::on_fMcpStopRun_clicked()
185{
186 Dim::SendCommand("MCP/STOP");
187}
188
189void MainWindow::on_fMcpReset_clicked()
190{
191 Dim::SendCommand("MCP/RESET");
192}
193
194void MainWindow::on_fLoggerStart_clicked()
195{
196 Dim::SendCommand("DATA_LOGGER/WAIT_FOR_RUN_NUMBER");
197}
198
199void MainWindow::on_fLoggerStop_clicked()
200{
201 Dim::SendCommand("DATA_LOGGER/BACK_TO_NIGHTLY_OPEN");
202}
203
204void MainWindow::on_fFtmStartRun_clicked()
205{
206 Dim::SendCommand("FTM_CONTROL/START_RUN");
207}
208
209void MainWindow::on_fFtmStopRun_clicked()
210{
211 Dim::SendCommand("FTM_CONTROL/STOP_RUN");
212}
213
214void MainWindow::on_fFadStartRun_clicked()
215{
216 Dim::SendCommand("FAD_CONTROL/START_RUN");
217}
218
219void MainWindow::on_fFadStopRun_clicked()
220{
221 Dim::SendCommand("FAD_CONTROL/STOP_RUN");
222}
223
224void MainWindow::on_fFadDrsOn_clicked()
225{
226 Dim::SendCommand("FAD_CONTROL/ENABLE_DRS", uint8_t(true));
227}
228
229void MainWindow::on_fFadDrsOff_clicked()
230{
231 Dim::SendCommand("FAD_CONTROL/ENABLE_DRS", uint8_t(false));
232}
233
234void MainWindow::on_fFadDwriteOn_clicked()
235{
236 Dim::SendCommand("FAD_CONTROL/ENABLE_DWRITE", uint8_t(true));
237}
238
239void MainWindow::on_fFadDwriteOff_clicked()
240{
241 Dim::SendCommand("FAD_CONTROL/ENABLE_DWRITE", uint8_t(false));
242}
243
244void MainWindow::on_fFadSingleTrigger_clicked()
245{
246 Dim::SendCommand("FAD_CONTROL/SEND_SINGLE_TRIGGER");
247}
248
249void MainWindow::on_fFadTriggerLineOn_clicked()
250{
251 Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", uint8_t(true));
252}
253
254void MainWindow::on_fFadTriggerLineOff_clicked()
255{
256 Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER_LINE", uint8_t(false));
257}
258
259void MainWindow::on_fFadContTriggerOn_clicked()
260{
261 Dim::SendCommand("FAD_CONTROL/ENABLE_CONTINOUS_TRIGGER", uint8_t(true));
262}
263
264void MainWindow::on_fFadContTriggerOff_clicked()
265{
266 Dim::SendCommand("FAD_CONTROL/ENABLE_CONTINOUS_TRIGGER", uint8_t(false));
267}
268
269void MainWindow::on_fFadBusyOnOn_clicked()
270{
271 Dim::SendCommand("FAD_CONTROL/ENABLE_BUSY_ON", uint8_t(true));
272}
273
274void MainWindow::on_fFadBusyOnOff_clicked()
275{
276 Dim::SendCommand("FAD_CONTROL/ENABLE_BUSY_ON", uint8_t(false));
277}
278
279void MainWindow::on_fFadBusyOffOn_clicked()
280{
281 Dim::SendCommand("FAD_CONTROL/ENABLE_BUSY_OFF", uint8_t(true));
282}
283
284void MainWindow::on_fFadBusyOffOff_clicked()
285{
286 Dim::SendCommand("FAD_CONTROL/ENABLE_BUSY_OFF", uint8_t(false));
287}
288
289void MainWindow::on_fFadSocket0_clicked()
290{
291 Dim::SendCommand("FAD_CONTROL/ENABLE_COMMAND_SOCKET_MODE", uint8_t(true));
292}
293
294void MainWindow::on_fFadSocket17_clicked()
295{
296 Dim::SendCommand("FAD_CONTROL/ENABLE_COMMAND_SOCKET_MODE", uint8_t(false));
297}
298
299void MainWindow::on_fFadResetTriggerId_clicked()
300{
301 Dim::SendCommand("FAD_CONTROL/RESET_EVENT_COUNTER");
302}
303
304void MainWindow::on_fFadStart_clicked()
305{
306 Dim::SendCommand("FAD_CONTROL/START");
307}
308
309void MainWindow::on_fFadStop_clicked()
310{
311 Dim::SendCommand("FAD_CONTROL/STOP");
312}
313
314void MainWindow::on_fFadAbort_clicked()
315{
316 Dim::SendCommand("FAD_CONTROL/ABORT");
317}
318
319void MainWindow::on_fFadSoftReset_clicked()
320{
321 Dim::SendCommand("FAD_CONTROL/SOFT_RESET");
322}
323
324void MainWindow::on_fFadHardReset_clicked()
325{
326 Dim::SendCommand("FAD_CONTROL/HARD_RESET");
327}
328
329void MainWindow::slot_fFadLED_clicked()
330{
331 for (int32_t i=0; i<40; i++)
332 if (sender()==fFadLED[i])
333 {
334 Dim::SendCommand("FAD_CONTROL/TOGGLE", i);
335 break;
336 }
337}
338
339void MainWindow::on_fFadPrescalerCmd_valueChanged(int val)
340{
341 Dim::SendCommand("FAD_CONTROL/SET_TRIGGER_RATE", uint32_t(val));
342}
343
344void MainWindow::on_fFadRunNumberCmd_valueChanged(int val)
345{
346 Dim::SendCommand("FAD_CONTROL/SET_RUN_NUMBER", uint64_t(val));
347}
348
349void MainWindow::on_fFadRoiCmd_valueChanged(int val)
350{
351 const int32_t vals[2] = { -1, val };
352 Dim::SendCommand("FAD_CONTROL/SET_REGION_OF_INTEREST", vals);
353}
354
355void MainWindow::FadDacCmd_valueChanged(uint16_t val, uint16_t idx)
356{
357 const uint32_t cmd[2] = { idx, val };
358 Dim::SendCommand("FAD_CONTROL/SET_DAC_VALUE", cmd);
359}
360
361void MainWindow::SetTriggerSequence()
362{
363 const uint16_t d[3] =
364 {
365 uint16_t(fTriggerSeqPed->value()),
366 uint16_t(fTriggerSeqLPext->value()),
367 uint16_t(fTriggerSeqLPint->value())
368 };
369
370 if (!fInHandler)
371 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
372}
373
374void on_fEnableTrigger_clicked(bool b)
375{
376 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
377}
378
379void on_fEnableExt1_clicked(bool b)
380{
381 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
382}
383
384void on_fEnableExt2_clicked(bool b)
385{
386 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
387}
388
389void on_fEnableVeto_clicked(bool b)
390{
391 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
392}
393
394void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
395{
396 if (!fInHandler)
397 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_MULTIPLICITY", v);
398}
399
400void MainWindow::on_fPhysicsWindow_valueChanged(int v)
401{
402 if (!fInHandler)
403 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
404}
405
406void MainWindow::on_fCalibCoincidence_valueChanged(int v)
407{
408 if (!fInHandler)
409 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_MULTIPLICITY", v);
410}
411
412void MainWindow::on_fCalibWindow_valueChanged(int v)
413{
414 if (!fInHandler)
415 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
416}
417
418void MainWindow::on_fTriggerInterval_valueChanged(int val)
419{
420 if (!fInHandler)
421 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
422}
423
424void MainWindow::on_fTriggerDelay_valueChanged(int val)
425{
426 if (!fInHandler)
427 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
428}
429
430void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
431{
432 if (!fInHandler)
433 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
434}
435
436void MainWindow::on_fDeadTime_valueChanged(int val)
437{
438 if (!fInHandler)
439 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
440}
441
442void MainWindow::on_fPrescalingVal_valueChanged(int val)
443{
444 if (!fInHandler)
445 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
446}
447
448void MainWindow::on_fPixelEnableAll_clicked()
449{
450 Dim::SendCommand("FTM_CONTROL/ENABLE_PIXEL", int16_t(-1));
451}
452
453void MainWindow::on_fPixelDisableAll_clicked()
454{
455 Dim::SendCommand("FTM_CONTROL/DISABLE_PIXEL", int16_t(-1));
456}
457
458void MainWindow::on_fEnableTrigger_stateChanged(int b)
459{
460 if (!fInHandler)
461 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b==Qt::Checked);
462}
463
464void MainWindow::on_fEnableExt1_stateChanged(int b)
465{
466 if (!fInHandler)
467 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b==Qt::Checked);
468}
469
470void MainWindow::on_fEnableExt2_stateChanged(int b)
471{
472 if (!fInHandler)
473 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b==Qt::Checked);
474}
475
476void MainWindow::on_fEnableClockCond_stateChanged(int b)
477{
478 if (!fInHandler)
479 Dim::SendCommand("FTM_CONTROL/ENABLE_CLOCK_CONDITIONER", b==Qt::Checked);
480}
481
482void MainWindow::on_fEnableVeto_stateChanged(int b)
483{
484 if (!fInHandler)
485 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b==Qt::Checked);
486}
487
488void MainWindow::on_fClockCondFreq_activated(int idx)
489{
490 if (!fInHandler)
491 Dim::SendCommand("FTM_CONTROL/SET_CLOCK_FREQUENCY", fClockCondFreq->itemData(idx).toInt());
492}
493
494void MainWindow::slot_fFtuLED_clicked()
495{
496 for (int32_t i=0; i<40; i++)
497 if (sender()==fFtuLED[i])
498 {
499 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
500 break;
501 }
502}
503
504void MainWindow::on_fFtuPing_toggled(bool checked)
505{
506 if (checked)
507 Dim::SendCommand("FTM_CONTROL/PING");
508}
509
510void MainWindow::on_fFtuAllOn_clicked()
511{
512 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 1 };
513 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
514}
515
516void MainWindow::on_fFtuAllOff_clicked()
517{
518 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 0 };
519 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
520}
521
522void MainWindow::on_fFadLpIntIntensity_valueChanged(int val)
523{
524 Dim::SendCommand("SET_INTENSITY_LPINT", uint16_t(val));
525}
526
527void MainWindow::on_fFadLpExtIntensity_valueChanged(int val)
528{
529 Dim::SendCommand("SET_INTENSITY_LPEXT", uint16_t(val));
530}
531
532void MainWindow::on_fFadLpIntGroup1_stateChanged(int b)
533{
534 Dim::SendCommand("FTM_CONTROL/ENABLE_GROUP1_LPINT", uint8_t(b));
535}
536
537void MainWindow::on_fFadLpExtGroup1_stateChanged(int b)
538{
539 Dim::SendCommand("FTM_CONTROL/ENABLE_GROUP1_LPEXT", uint8_t(b));
540}
541
542void MainWindow::on_fFadLpIntGroup2_stateChanged(int b)
543{
544 Dim::SendCommand("FTM_CONTROL/ENABLE_GROUP2_LPINT", uint8_t(b));
545}
546
547void MainWindow::on_fFadLpExtGroup2_stateChanged(int b)
548{
549 Dim::SendCommand("FTM_CONTROL/ENABLE_GROUP2_LPEXT", uint8_t(b));
550}
551
552void MainWindow::on_fChatSend_clicked()
553{
554 const string msg = fChatMessage->text().toStdString();
555 if (Dim::SendCommand("CHAT/MSG", msg.c_str(), msg.length()+1))
556 fChatMessage->clear();
557}
558
559void MainWindow::on_fStatusLoggerLed_clicked()
560{
561 SelectTab("Logger");
562}
563
564void MainWindow::on_fStatusChatLed_clicked()
565{
566 SelectTab("Chat");
567}
568
569void MainWindow::on_fStatusFTMLed_clicked()
570{
571 SelectTab("Trigger");
572}
573
574void MainWindow::on_fStatusFTULed_clicked()
575{
576 SelectTab("FTUs");
577}
578
579void MainWindow::on_fStatusFADLed_clicked()
580{
581 SelectTab("FAD");
582}
Note: See TracBrowser for help on using the repository browser.