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

Last change on this file since 10727 was 10678, checked in by tbretz, 14 years ago
Implemented a fix which should avoid that the GUI is playing ping-pong with e.g. the ftmctrl. This is done through a wrapper around all infoHandlers. In ceratin circumstances (mainly when signals of the kind valueChanged are emitted) it is advicable to not send the values back to the emitter if their origin is the handler.
File size: 6.7 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 fUTC->setDateTime(QDateTime::currentDateTimeUtc());
77}
78
79void MainWindow::SelectTab(const QString &name)
80{
81 for (int i=0; i<fTabWidget->count(); i++)
82 if (fTabWidget->tabText(i)==name)
83 {
84 fTabWidget->setCurrentIndex(i);
85 break;
86 }
87}
88
89
90void MainWindow::on_fShutdown_clicked()
91{
92 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
93}
94
95
96void MainWindow::on_fShutdownAll_clicked()
97{
98 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
99 Dim::SendCommand("DIS_DNS/EXIT", int(1));
100}
101
102void MainWindow::on_fTabWidget_tabCloseRequested(int which)
103{
104 // To get the correct size we have to switch to this tab
105 // An alternative would be to take the size of the current tab
106 fTabWidget->setCurrentIndex(which);
107
108 QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
109 if (!w)
110 {
111 cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
112 return;
113 }
114
115 QDockWidget *d = w->findChild<QDockWidget*>();
116 if (!d)
117 {
118 cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
119 return;
120 }
121
122 new DockWindow(d, fTabWidget->tabText(which));
123 fTabWidget->removeTab(which);
124
125 if (fTabWidget->count()==1)
126 fTabWidget->setTabsClosable(false);
127}
128
129void MainWindow::SetTriggerSequence()
130{
131 const uint8_t d[3] =
132 {
133 uint8_t(fTriggerSeqPed->value()),
134 uint8_t(fTriggerSeqLPext->value()),
135 uint8_t(fTriggerSeqLPint->value())
136 };
137
138 if (!fInHandler)
139 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
140}
141
142void on_fEnableTrigger_clicked(bool b)
143{
144 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
145}
146
147void on_fEnableExt1_clicked(bool b)
148{
149 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
150}
151
152void on_fEnableExt2_clicked(bool b)
153{
154 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
155}
156
157void on_fEnableVeto_clicked(bool b)
158{
159 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
160}
161
162void MainWindow::on_fPhysicsCoincidence_valueChanged(int v)
163{
164 if (!fInHandler)
165 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", v);
166}
167
168void MainWindow::on_fPhysicsWindow_valueChanged(int v)
169{
170 if (!fInHandler)
171 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_WINDOW", v/4-2);
172}
173
174void MainWindow::on_fCalibCoincidence_valueChanged(int v)
175{
176 if (!fInHandler)
177 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", v);
178}
179
180void MainWindow::on_fCalibWindow_valueChanged(int v)
181{
182 if (!fInHandler)
183 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_WINDOW", v/4-2);
184}
185
186void MainWindow::on_fThresholdVal_valueChanged(int v)
187{
188 fThresholdVolt->setValue(2500./4095*v);
189
190 const int32_t d[2] = { fThresholdIdx->value(), v };
191
192 if (!fInHandler)
193 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
194}
195
196void MainWindow::on_fTriggerInterval_valueChanged(int val)
197{
198 if (!fInHandler)
199 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
200}
201
202void MainWindow::on_fTriggerDelay_valueChanged(int val)
203{
204 if (!fInHandler)
205 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
206}
207
208void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
209{
210 if (!fInHandler)
211 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
212}
213
214void MainWindow::on_fDeadTime_valueChanged(int val)
215{
216 if (!fInHandler)
217 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
218}
219
220void MainWindow::on_fPrescalingVal_valueChanged(int val)
221{
222 if (!fInHandler)
223 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
224}
225
226void MainWindow::slot_fFtuLED_clicked()
227{
228 for (int32_t i=0; i<40; i++)
229 if (sender()==fFtuLED[i])
230 {
231 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
232 break;
233 }
234}
235
236void MainWindow::on_fPing_toggled(bool checked)
237{
238 if (checked)
239 Dim::SendCommand("FTM_CONTROL/PING");
240}
241
242void MainWindow::on_fChatSend_clicked()
243{
244 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
245 fChatMessage->clear();
246}
247
248void MainWindow::on_fStatusLoggerLed_clicked()
249{
250 SelectTab("Logger");
251}
252
253void MainWindow::on_fStatusChatLed_clicked()
254{
255 SelectTab("Chat");
256}
257
258void MainWindow::on_fStatusFTMLed_clicked()
259{
260 SelectTab("Trigger");
261}
262
263void MainWindow::on_fStatusFTULed_clicked()
264{
265 SelectTab("FTUs");
266}
Note: See TracBrowser for help on using the repository browser.