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

Last change on this file since 10923 was 10917, checked in by tbretz, 15 years ago
Renamed fPing to fFtuPing; added fFtuAllOn and fFtuAllOff buttons
File size: 8.5 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 toTUC to support also older Qt versions
88 fUTC->setDateTime(QDateTime::currentDateTime().toUTC());
89}
90
91void MainWindow::SelectTab(const QString &name)
92{
93 for (int i=0; i<fTabWidget->count(); i++)
94 if (fTabWidget->tabText(i)==name)
95 {
96 fTabWidget->setCurrentIndex(i);
97 break;
98 }
99}
100
101
102void MainWindow::on_fShutdown_clicked()
103{
104 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
105}
106
107
108void MainWindow::on_fShutdownAll_clicked()
109{
110 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
111 Dim::SendCommand("DIS_DNS/EXIT", int(1));
112}
113
114void MainWindow::on_fTabWidget_tabCloseRequested(int which)
115{
116 // To get the correct size we have to switch to this tab
117 // An alternative would be to take the size of the current tab
118 fTabWidget->setCurrentIndex(which);
119
120 QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
121 if (!w)
122 {
123 cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
124 return;
125 }
126
127 QDockWidget *d = w->findChild<QDockWidget*>();
128 if (!d)
129 {
130 cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
131 return;
132 }
133
134 new DockWindow(d, fTabWidget->tabText(which));
135 fTabWidget->removeTab(which);
136
137 if (fTabWidget->count()==1)
138 fTabWidget->setTabsClosable(false);
139}
140
141void MainWindow::SetTriggerSequence()
142{
143 const uint16_t d[3] =
144 {
145 uint16_t(fTriggerSeqPed->value()),
146 uint16_t(fTriggerSeqLPext->value()),
147 uint16_t(fTriggerSeqLPint->value())
148 };
149
150 if (!fInHandler)
151 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
152}
153
154void on_fEnableTrigger_clicked(bool b)
155{
156 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
157}
158
159void on_fEnableExt1_clicked(bool b)
160{
161 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
162}
163
164void on_fEnableExt2_clicked(bool b)
165{
166 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
167}
168
169void on_fEnableVeto_clicked(bool b)
170{
171 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
172}
173
174void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
175{
176 if (!fInHandler)
177 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", v);
178}
179
180void MainWindow::on_fPhysicsWindow_valueChanged(int v)
181{
182 if (!fInHandler)
183 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
184}
185
186void MainWindow::on_fCalibCoincidence_valueChanged(int v)
187{
188 if (!fInHandler)
189 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", v);
190}
191
192void MainWindow::on_fCalibWindow_valueChanged(int v)
193{
194 if (!fInHandler)
195 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
196}
197
198void MainWindow::on_fThresholdVal_valueChanged(int v)
199{
200 fThresholdVolt->setValue(2500./4095*v);
201
202 const int32_t d[2] = { fThresholdIdx->value(), v };
203
204 if (!fInHandler)
205 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
206}
207
208void MainWindow::on_fTriggerInterval_valueChanged(int val)
209{
210 if (!fInHandler)
211 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
212}
213
214void MainWindow::on_fTriggerDelay_valueChanged(int val)
215{
216 if (!fInHandler)
217 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
218}
219
220void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
221{
222 if (!fInHandler)
223 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
224}
225
226void MainWindow::on_fDeadTime_valueChanged(int val)
227{
228 if (!fInHandler)
229 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
230}
231
232void MainWindow::on_fPrescalingVal_valueChanged(int val)
233{
234 if (!fInHandler)
235 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
236}
237
238void MainWindow::on_fPixelEnable_stateChanged(int b)
239{
240 cout << "PIXEL: " << fPixelIdx->value() << " " << b << endl;
241 if (!fInHandler)
242 Dim::SendCommand(b==Qt::Unchecked ?
243 "FTM_CONTROL/DISABLE_PIXEL" : "FTM_CONTROL/ENABLE_PIXEL",
244 uint16_t(fPixelIdx->value()));
245}
246
247void MainWindow::on_fEnableTrigger_stateChanged(int b)
248{
249 if (!fInHandler)
250 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b==Qt::Checked);
251}
252
253void MainWindow::on_fEnableExt1_stateChanged(int b)
254{
255 if (!fInHandler)
256 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b==Qt::Checked);
257}
258
259void MainWindow::on_fEnableExt2_stateChanged(int b)
260{
261 if (!fInHandler)
262 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b==Qt::Checked);
263}
264
265void MainWindow::on_fEnableClockCond_stateChanged(int b)
266{
267 if (!fInHandler)
268 Dim::SendCommand("FTM_CONTROL/ENABLE_CLOCK_CONDITIONER", b==Qt::Checked);
269}
270
271void MainWindow::on_fEnableVeto_stateChanged(int b)
272{
273 if (!fInHandler)
274 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b==Qt::Checked);
275}
276
277void MainWindow::slot_fFtuLED_clicked()
278{
279 for (int32_t i=0; i<40; i++)
280 if (sender()==fFtuLED[i])
281 {
282 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
283 break;
284 }
285}
286
287void MainWindow::on_fFtuPing_toggled(bool checked)
288{
289 if (checked)
290 Dim::SendCommand("FTM_CONTROL/PING");
291}
292
293void MainWindow::on_fFtuAllOn_clicked()
294{
295 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 1 };
296 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
297}
298
299void MainWindow::on_fFtuAllOff_clicked()
300{
301 static const struct Data { int32_t id; char on; } __attribute__((__packed__)) d = { -1, 0 };
302 Dim::SendCommand("FTM_CONTROL/ENABLE_FTU", &d, sizeof(d));
303}
304
305void MainWindow::on_fChatSend_clicked()
306{
307 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
308 fChatMessage->clear();
309}
310
311void MainWindow::on_fStatusLoggerLed_clicked()
312{
313 SelectTab("Logger");
314}
315
316void MainWindow::on_fStatusChatLed_clicked()
317{
318 SelectTab("Chat");
319}
320
321void MainWindow::on_fStatusFTMLed_clicked()
322{
323 SelectTab("Trigger");
324}
325
326void MainWindow::on_fStatusFTULed_clicked()
327{
328 SelectTab("FTUs");
329}
330
331void MainWindow::on_fStatusFADLed_clicked()
332{
333 SelectTab("FAD");
334}
Note: See TracBrowser for help on using the repository browser.