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

Last change on this file since 10824 was 10786, checked in by tbretz, 14 years ago
Adapted to change in SET_TRIGGER_SEQUENCE
File size: 7.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
16MainWindow::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
74void MainWindow::slot_TimeUpdate()
75{
76 // Used toTUC to support also older Qt versions
77 fUTC->setDateTime(QDateTime::currentDateTime().toUTC());
78}
79
80void 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
91void MainWindow::on_fShutdown_clicked()
92{
93 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
94}
95
96
97void MainWindow::on_fShutdownAll_clicked()
98{
99 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
100 Dim::SendCommand("DIS_DNS/EXIT", int(1));
101}
102
103void 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
130void MainWindow::SetTriggerSequence()
131{
132 const uint16_t d[3] =
133 {
134 uint16_t(fTriggerSeqPed->value()),
135 uint16_t(fTriggerSeqLPext->value()),
136 uint16_t(fTriggerSeqLPint->value())
137 };
138
139 if (!fInHandler)
140 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
141}
142
143void on_fEnableTrigger_clicked(bool b)
144{
145 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
146}
147
148void on_fEnableExt1_clicked(bool b)
149{
150 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
151}
152
153void on_fEnableExt2_clicked(bool b)
154{
155 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
156}
157
158void on_fEnableVeto_clicked(bool b)
159{
160 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
161}
162
163void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
164{
165 if (!fInHandler)
166 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", v);
167}
168
169void MainWindow::on_fPhysicsWindow_valueChanged(int v)
170{
171 if (!fInHandler)
172 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
173}
174
175void MainWindow::on_fCalibCoincidence_valueChanged(int v)
176{
177 if (!fInHandler)
178 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", v);
179}
180
181void MainWindow::on_fCalibWindow_valueChanged(int v)
182{
183 if (!fInHandler)
184 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
185}
186
187void 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
197void MainWindow::on_fTriggerInterval_valueChanged(int val)
198{
199 if (!fInHandler)
200 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
201}
202
203void MainWindow::on_fTriggerDelay_valueChanged(int val)
204{
205 if (!fInHandler)
206 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
207}
208
209void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
210{
211 if (!fInHandler)
212 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
213}
214
215void MainWindow::on_fDeadTime_valueChanged(int val)
216{
217 if (!fInHandler)
218 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
219}
220
221void MainWindow::on_fPrescalingVal_valueChanged(int val)
222{
223 if (!fInHandler)
224 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
225}
226
227void 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
236void MainWindow::on_fEnableTrigger_stateChanged(int b)
237{
238 if (!fInHandler)
239 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b==Qt::Checked);
240}
241
242void MainWindow::on_fEnableExt1_stateChanged(int b)
243{
244 if (!fInHandler)
245 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b==Qt::Checked);
246}
247
248void MainWindow::on_fEnableExt2_stateChanged(int b)
249{
250 if (!fInHandler)
251 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b==Qt::Checked);
252}
253
254void MainWindow::on_fEnableClockCond_stateChanged(int b)
255{
256 if (!fInHandler)
257 Dim::SendCommand("FTM_CONTROL/ENABLE_CLOCK_CONDITIONER", b==Qt::Checked);
258}
259
260void MainWindow::on_fEnableVeto_stateChanged(int b)
261{
262 if (!fInHandler)
263 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b==Qt::Checked);
264}
265
266void 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
276void MainWindow::on_fPing_toggled(bool checked)
277{
278 if (checked)
279 Dim::SendCommand("FTM_CONTROL/PING");
280}
281
282void MainWindow::on_fChatSend_clicked()
283{
284 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
285 fChatMessage->clear();
286}
287
288void MainWindow::on_fStatusLoggerLed_clicked()
289{
290 SelectTab("Logger");
291}
292
293void MainWindow::on_fStatusChatLed_clicked()
294{
295 SelectTab("Chat");
296}
297
298void MainWindow::on_fStatusFTMLed_clicked()
299{
300 SelectTab("Trigger");
301}
302
303void MainWindow::on_fStatusFTULed_clicked()
304{
305 SelectTab("FTUs");
306}
307
308void MainWindow::on_fStatusFADLed_clicked()
309{
310 SelectTab("FAD");
311}
Note: See TracBrowser for help on using the repository browser.