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

Last change on this file since 10953 was 10953, checked in by tbretz, 10 years ago
Added the possibility to disable all patches/pixels except one.
File size: 9.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::SetTriggerSequence()
151{
152 const uint16_t d[3] =
153 {
154 uint16_t(fTriggerSeqPed->value()),
155 uint16_t(fTriggerSeqLPext->value()),
156 uint16_t(fTriggerSeqLPint->value())
157 };
158
159 if (!fInHandler)
160 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
161}
162
163void on_fEnableTrigger_clicked(bool b)
164{
165 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
166}
167
168void on_fEnableExt1_clicked(bool b)
169{
170 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
171}
172
173void on_fEnableExt2_clicked(bool b)
174{
175 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
176}
177
178void on_fEnableVeto_clicked(bool b)
179{
180 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
181}
182
183void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
184{
185 if (!fInHandler)
186 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", v);
187}
188
189void MainWindow::on_fPhysicsWindow_valueChanged(int v)
190{
191 if (!fInHandler)
192 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
193}
194
195void MainWindow::on_fCalibCoincidence_valueChanged(int v)
196{
197 if (!fInHandler)
198 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", v);
199}
200
201void MainWindow::on_fCalibWindow_valueChanged(int v)
202{
203 if (!fInHandler)
204 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
205}
206
207void MainWindow::on_fThresholdVal_valueChanged(int v)
208{
209 fThresholdVolt->setValue(2500./4095*v);
210
211 const int32_t d[2] = { fThresholdIdx->value(), v };
212
213 if (!fInHandler)
214 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
215}
216
217void MainWindow::on_fTriggerInterval_valueChanged(int val)
218{
219 if (!fInHandler)
220 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
221}
222
223void MainWindow::on_fTriggerDelay_valueChanged(int val)
224{
225 if (!fInHandler)
226 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
227}
228
229void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
230{
231 if (!fInHandler)
232 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
233}
234
235void MainWindow::on_fDeadTime_valueChanged(int val)
236{
237 if (!fInHandler)
238 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
239}
240
241void MainWindow::on_fPrescalingVal_valueChanged(int val)
242{
243 if (!fInHandler)
244 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
245}
246
247void MainWindow::on_fPixelEnable_stateChanged(int b)
248{
249 if (!fInHandler)
250 Dim::SendCommand(b==Qt::Unchecked ?
251 "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
252 uint16_t(fPixelIdx->value()));
253}
254
255void MainWindow::on_fPixelDisableOthers_clicked()
256{
257 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PIXELS_EXCEPT",
258 uint16_t(fPixelIdx->value()));
259}
260
261void MainWindow::on_fThresholdDisableOthers_clicked()
262{
263 Dim::SendCommand("FTM_CONTROL/DISABLE_ALL_PATCHES_EXCEPT",
264 uint16_t(fThresholdIdx->value()));
265}
266
267void MainWindow::on_fEnableTrigger_stateChanged(int b)
268{
269 if (!fInHandler)
270 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b==Qt::Checked);
271}
272
273void MainWindow::on_fEnableExt1_stateChanged(int b)
274{
275 if (!fInHandler)
276 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b==Qt::Checked);
277}
278
279void MainWindow::on_fEnableExt2_stateChanged(int b)
280{
281 if (!fInHandler)
282 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b==Qt::Checked);
283}
284
285void MainWindow::on_fEnableClockCond_stateChanged(int b)
286{
287 if (!fInHandler)
288 Dim::SendCommand("FTM_CONTROL/ENABLE_CLOCK_CONDITIONER", b==Qt::Checked);
289}
290
291void MainWindow::on_fEnableVeto_stateChanged(int b)
292{
293 if (!fInHandler)
294 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b==Qt::Checked);
295}
296
297void MainWindow::slot_fFtuLED_clicked()
298{
299 for (int32_t i=0; i<40; i++)
300 if (sender()==fFtuLED[i])
301 {
302 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
303 break;
304 }
305}
306
307void MainWindow::on_fFtuPing_toggled(bool checked)
308{
309 if (checked)
310 Dim::SendCommand("FTM_CONTROL/PING");
311}
312
313void MainWindow::on_fFtuAllOn_clicked()
314{
315 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 1 };
316 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
317}
318
319void MainWindow::on_fFtuAllOff_clicked()
320{
321 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 0 };
322 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
323}
324
325void MainWindow::on_fChatSend_clicked()
326{
327 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
328 fChatMessage->clear();
329}
330
331void MainWindow::on_fStatusLoggerLed_clicked()
332{
333 SelectTab("Logger");
334}
335
336void MainWindow::on_fStatusChatLed_clicked()
337{
338 SelectTab("Chat");
339}
340
341void MainWindow::on_fStatusFTMLed_clicked()
342{
343 SelectTab("Trigger");
344}
345
346void MainWindow::on_fStatusFTULed_clicked()
347{
348 SelectTab("FTUs");
349}
350
351void MainWindow::on_fStatusFADLed_clicked()
352{
353 SelectTab("FAD");
354}
Note: See TracBrowser for help on using the repository browser.