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

Last change on this file since 10633 was 10626, checked in by tbretz, 15 years ago
Connected enables for trigger lines.
File size: 6.0 KB
Line 
1#include "MainWindow.h"
2
3#include <iostream>
4
5#include "dic.hxx"
6
7#include "DockWindow.h"
8#include "HtmlDelegate.h"
9#include "CheckBoxDelegate.h"
10
11using namespace std;
12
13namespace Dim
14{
15static bool SendCommand(const char *command)
16{
17 return DimClient::sendCommand(command, NULL, 0);
18}
19
20template<typename T>
21static bool SendCommand(const char *command, const T &t)
22{
23 return DimClient::sendCommand(command, (void*)&t, sizeof(t));
24}
25}
26
27MainWindow::MainWindow(QWidget *p) : QMainWindow(p)
28{
29 // setupUi MUST be called before the DimNetwork is initilized
30 // In this way it can be ensured that nothing from the
31 // DimNetwork arrives before all graphical elements are
32 // initialized. This is a simple but very powerfull trick.
33 setupUi(this);
34
35 // Now here we can do further setup which should be done
36 // before the gui is finally displayed.
37 fDimCmdServers->setItemDelegate(new CheckBoxDelegate);
38 fDimCmdCommands->setItemDelegate(new CheckBoxDelegate);
39 fDimCmdDescription->setItemDelegate(new HtmlDelegate);
40
41 fDimSvcServers->setItemDelegate(new CheckBoxDelegate);
42 fDimSvcServices->setItemDelegate(new CheckBoxDelegate);
43 fDimSvcDescription->setItemDelegate(new HtmlDelegate);
44
45 fStatusBar->showMessage(PACKAGE_STRING" | "PACKAGE_URL" | report bugs to <"PACKAGE_BUGREPORT">");
46
47 fFtuLED[0] = fFtuLEDPrototype;
48
49 for (int i=1; i<40; i++)
50 {
51 QPushButton *b = new QPushButton(static_cast<QWidget*>(fFtuLEDPrototype->parent()));
52
53 b->setEnabled(fFtuLEDPrototype->isEnabled());
54 b->setSizePolicy(fFtuLEDPrototype->sizePolicy());
55 b->setMaximumSize(fFtuLEDPrototype->maximumSize());
56 b->setIcon(fFtuLEDPrototype->icon());
57 b->setIconSize(fFtuLEDPrototype->iconSize());
58 b->setCheckable(fFtuLEDPrototype->isCheckable());
59 b->setFlat(fFtuLEDPrototype->isFlat());
60
61 fFtuLedLayout->addWidget(b, i/10+1, i%10+1, 1, 1);
62
63 fFtuLED[i] = b;
64 }
65
66 for (int i=0; i<40; i++)
67 {
68 fFtuLED[i]->setObjectName(QString::fromUtf8("fFtuLED")+QString::number(i));
69 QObject::connect(fFtuLED[i], SIGNAL(clicked()), this, SLOT(slot_fFtuLED_clicked()));
70 }
71}
72
73void MainWindow::SelectTab(const QString &name)
74{
75 for (int i=0; i<fTabWidget->count(); i++)
76 if (fTabWidget->tabText(i)==name)
77 {
78 fTabWidget->setCurrentIndex(i);
79 break;
80 }
81}
82
83
84void MainWindow::on_fShutdown_clicked()
85{
86 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
87}
88
89
90void MainWindow::on_fShutdownAll_clicked()
91{
92 Dim::SendCommand("DIS_DNS/KILL_SERVERS");
93 Dim::SendCommand("DIS_DNS/EXIT", int(1));
94}
95
96void MainWindow::on_fTabWidget_tabCloseRequested(int which)
97{
98 // To get the correct size we have to switch to this tab
99 // An alternative would be to take the size of the current tab
100 fTabWidget->setCurrentIndex(which);
101
102 QWidget *w = fTabWidget->currentWidget(); //fTabWidget->widget(which);
103 if (!w)
104 {
105 cout << "Weird... the tab requested to be closed doesn't exist!" << endl;
106 return;
107 }
108
109 QDockWidget *d = w->findChild<QDockWidget*>();
110 if (!d)
111 {
112 cout << "Sorry, tab requested to be closed contains no QDockWidget!" << endl;
113 return;
114 }
115
116 new DockWindow(d, fTabWidget->tabText(which));
117 fTabWidget->removeTab(which);
118
119 if (fTabWidget->count()==1)
120 fTabWidget->setTabsClosable(false);
121}
122
123void MainWindow::SetTriggerSequence()
124{
125 const uint8_t d[3] =
126 {
127 uint8_t(fTriggerSeqPed->value()),
128 uint8_t(fTriggerSeqLPint->value()),
129 uint8_t(fTriggerSeqLPext->value())
130 };
131
132 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_SEQUENCE", d);
133}
134
135void on_fEnableTrigger_clicked(bool b)
136{
137 Dim::SendCommand("FTM_CONTROL/ENABLE_TRIGGER", b);
138}
139
140void on_fEnableExt1_clicked(bool b)
141{
142 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT1", b);
143}
144
145void on_fEnableExt2_clicked(bool b)
146{
147 Dim::SendCommand("FTM_CONTROL/ENABLE_EXT2", b);
148}
149
150void on_fEnableVeto_clicked(bool b)
151{
152 Dim::SendCommand("FTM_CONTROL/ENABLE_VETO", b);
153}
154
155void MainWindow::SetTriggerCoincidence()
156{
157 const uint16_t d[2] =
158 {
159 uint16_t(fPhysicsCoincidence->value()),
160 uint16_t(fPhysicsWindow->value()/4-2)
161 };
162
163 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", d);
164}
165
166void MainWindow::SetCalibCoincidence()
167{
168 const uint16_t d[2] =
169 {
170 uint16_t(fCalibCoincidence->value()),
171 uint16_t(fCalibWindow->value()/4-2)
172 };
173
174 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", d);
175}
176
177void MainWindow::on_fThresholdVal_valueChanged(int v)
178{
179 fThresholdVolt->setValue(2500./4095*v);
180
181 const int32_t d[2] = { fThresholdIdx->value(), v };
182 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
183}
184
185void MainWindow::on_fTriggerInterval_valueChanged(int val)
186{
187 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
188}
189
190void MainWindow::on_fTriggerDelay_valueChanged(int val)
191{
192 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
193}
194
195void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
196{
197 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
198}
199
200void MainWindow::on_fDeadTime_valueChanged(int val)
201{
202 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
203}
204
205void MainWindow::on_fPrescalingVal_valueChanged(int val)
206{
207 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
208}
209
210void MainWindow::slot_fFtuLED_clicked()
211{
212 for (int32_t i=0; i<40; i++)
213 if (sender()==fFtuLED[i])
214 {
215 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
216 break;
217 }
218}
219
220void MainWindow::on_fPing_toggled(bool checked)
221{
222 if (checked)
223 Dim::SendCommand("FTM_CONTROL/PING");
224}
225
226void MainWindow::on_fChatSend_clicked()
227{
228 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
229 fChatMessage->clear();
230}
231
232void MainWindow::on_fStatusLoggerLed_clicked()
233{
234 SelectTab("Logger");
235}
236
237void MainWindow::on_fStatusChatLed_clicked()
238{
239 SelectTab("Chat");
240}
241
242void MainWindow::on_fStatusFTMLed_clicked()
243{
244 SelectTab("Trigger");
245}
246
247void MainWindow::on_fStatusFTULed_clicked()
248{
249 SelectTab("FTUs");
250}
251
Note: See TracBrowser for help on using the repository browser.