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

Last change on this file since 11111 was 11111, checked in by tbretz, 14 years ago
Added more FAD control buttons; implemented button events
File size: 9.9 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::slot_fFadStartRun_clicked()
151{
152 Dim::SendCommand("FAD_CONTROL/START_RUN");
153}
154
155void MainWindow::slot_fFadStopRun_clicked()
156{
157 Dim::SendCommand("FAD_CONTROL/STOP_RUN");
158}
159
160void MainWindow::slot_fFadSingleTrigger_clicked()
161{
162 Dim::SendCommand("FAD_CONTROL/SEND_SINGLE_TRIGGER");
163}
164
165void MainWindow::slot_fFadTriggerLineOn_clicked()
166{
167 Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER", uint8_t(true));
168}
169
170void MainWindow::slot_fFadTriggerLineOff_clicked()
171{
172 Dim::SendCommand("FAD_CONTROL/ENABLE_TRIGGER", uint8_t(false));
173}
174
175void MainWindow::slot_fFadContTriggerOn_clicked()
176{
177 Dim::SendCommand("FAD_CONTROL/CONTINOUS_TRIGGER_ON");
178}
179
180void MainWindow::slot_fFadContTriggerOff_clicked()
181{
182 Dim::SendCommand("FAD_CONTROL/CONTINOUS_TRIGGER_OFF");
183}
184
185void MainWindow::slot_fFadStart_clicked()
186{
187 Dim::SendCommand("FAD_CONTROL/START");
188}
189
190void MainWindow::slot_fFadStop_clicked()
191{
192 Dim::SendCommand("FAD_CONTROL/STOP");
193}
194
195void MainWindow::slot_fFadAbort_clicked()
196{
197 Dim::SendCommand("FAD_CONTROL/ABORT");
198}
199
200void MainWindow::slot_fFadConnect_clicked()
201{
202 Dim::SendCommand("FAD_CONTROL/CONNECT");
203}
204
205void MainWindow::slot_fFadDisconnect_clicked()
206{
207 Dim::SendCommand("FAD_CONTROL/DISCONNECT");
208}
209
210void MainWindow::SetTriggerSequence()
211{
212 const uint16_t d[3] =
213 {
214 uint16_t(fTriggerSeqPed->value()),
215 uint16_t(fTriggerSeqLPext->value()),
216 uint16_t(fTriggerSeqLPint->value())
217 };
218
219 if (!fInHandler)
220 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
221}
222
223void on_fEnableTrigger_clicked(bool b)
224{
225 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
226}
227
228void on_fEnableExt1_clicked(bool b)
229{
230 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
231}
232
233void on_fEnableExt2_clicked(bool b)
234{
235 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
236}
237
238void on_fEnableVeto_clicked(bool b)
239{
240 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
241}
242
243void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
244{
245 if (!fInHandler)
246 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_MULTIPLICITY", v);
247}
248
249void MainWindow::on_fPhysicsWindow_valueChanged(int v)
250{
251 if (!fInHandler)
252 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
253}
254
255void MainWindow::on_fCalibCoincidence_valueChanged(int v)
256{
257 if (!fInHandler)
258 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_MULTIPLICITY", v);
259}
260
261void MainWindow::on_fCalibWindow_valueChanged(int v)
262{
263 if (!fInHandler)
264 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
265}
266
267void MainWindow::on_fTriggerInterval_valueChanged(int val)
268{
269 if (!fInHandler)
270 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
271}
272
273void MainWindow::on_fTriggerDelay_valueChanged(int val)
274{
275 if (!fInHandler)
276 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
277}
278
279void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
280{
281 if (!fInHandler)
282 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
283}
284
285void MainWindow::on_fDeadTime_valueChanged(int val)
286{
287 if (!fInHandler)
288 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
289}
290
291void MainWindow::on_fPrescalingVal_valueChanged(int val)
292{
293 if (!fInHandler)
294 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
295}
296
297void MainWindow::on_fPixelEnableAll_clicked()
298{
299 Dim::SendCommand("FTM_CONTROL/ENABLE_PIXEL", int16_t(-1));
300}
301
302void MainWindow::on_fPixelDisableAll_clicked()
303{
304 Dim::SendCommand("FTM_CONTROL/DISABLE_PIXEL", int16_t(-1));
305}
306
307void MainWindow::on_fEnableTrigger_stateChanged(int b)
308{
309 if (!fInHandler)
310 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b==Qt::Checked);
311}
312
313void MainWindow::on_fEnableExt1_stateChanged(int b)
314{
315 if (!fInHandler)
316 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b==Qt::Checked);
317}
318
319void MainWindow::on_fEnableExt2_stateChanged(int b)
320{
321 if (!fInHandler)
322 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b==Qt::Checked);
323}
324
325void MainWindow::on_fEnableClockCond_stateChanged(int b)
326{
327 if (!fInHandler)
328 Dim::SendCommand("FTM_CONTROL/ENABLE_CLOCK_CONDITIONER", b==Qt::Checked);
329}
330
331void MainWindow::on_fEnableVeto_stateChanged(int b)
332{
333 if (!fInHandler)
334 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b==Qt::Checked);
335}
336
337void MainWindow::on_fClockCondFreq_activated(int idx)
338{
339 if (!fInHandler)
340 Dim::SendCommand("FTM_CONTROL/SET_CLOCK_FREQUENCY", fClockCondFreq->itemData(idx).toInt());
341}
342
343void MainWindow::slot_fFtuLED_clicked()
344{
345 for (int32_t i=0; i<40; i++)
346 if (sender()==fFtuLED[i])
347 {
348 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
349 break;
350 }
351}
352
353void MainWindow::on_fFtuPing_toggled(bool checked)
354{
355 if (checked)
356 Dim::SendCommand("FTM_CONTROL/PING");
357}
358
359void MainWindow::on_fFtuAllOn_clicked()
360{
361 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 1 };
362 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
363}
364
365void MainWindow::on_fFtuAllOff_clicked()
366{
367 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 0 };
368 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
369}
370
371void MainWindow::on_fChatSend_clicked()
372{
373 const string msg = fChatMessage->text().toStdString();
374 if (Dim::SendCommand("CHAT/MSG", msg.c_str(), msg.length()+1))
375 fChatMessage->clear();
376}
377
378void MainWindow::on_fStatusLoggerLed_clicked()
379{
380 SelectTab("Logger");
381}
382
383void MainWindow::on_fStatusChatLed_clicked()
384{
385 SelectTab("Chat");
386}
387
388void MainWindow::on_fStatusFTMLed_clicked()
389{
390 SelectTab("Trigger");
391}
392
393void MainWindow::on_fStatusFTULed_clicked()
394{
395 SelectTab("FTUs");
396}
397
398void MainWindow::on_fStatusFADLed_clicked()
399{
400 SelectTab("FAD");
401}
Note: See TracBrowser for help on using the repository browser.