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

Last change on this file since 10621 was 10620, checked in by tbretz, 14 years ago
Implemented trigger sequence and trigger coincidences.
File size: 5.7 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 MainWindow::SetTriggerCoincidence()
136{
137 const uint16_t d[2] =
138 {
139 uint16_t(fPhysicsCoincidence->value()),
140 uint16_t(fPhysicsWindow->value()/4-2)
141 };
142
143 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_COINCIDENCE", d);
144}
145
146void MainWindow::SetCalibCoincidence()
147{
148 const uint16_t d[2] =
149 {
150 uint16_t(fCalibCoincidence->value()),
151 uint16_t(fCalibWindow->value()/4-2)
152 };
153
154 Dim::SendCommand("FTM_CONTROL/SET_CALIBRATION_COINCIDENCE", d);
155}
156
157void MainWindow::on_fThresholdVal_valueChanged(int v)
158{
159 fThresholdVolt->setValue(2500./4095*v);
160
161 const int32_t d[2] = { fThresholdIdx->value(), v };
162 Dim::SendCommand("FTM_CONTROL/SET_THRESHOLD", d);
163}
164
165void MainWindow::on_fTriggerInterval_valueChanged(int val)
166{
167 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_INTERVAL", val);
168}
169
170void MainWindow::on_fTriggerDelay_valueChanged(int val)
171{
172 Dim::SendCommand("FTM_CONTROL/SET_TRIGGER_DELAY", val/4-2);
173}
174
175void MainWindow::on_fTimeMarkerDelay_valueChanged(int val)
176{
177 Dim::SendCommand("FTM_CONTROL/SET_TIME_MARKER_DELAY", val/4-2);
178}
179
180void MainWindow::on_fDeadTime_valueChanged(int val)
181{
182 Dim::SendCommand("FTM_CONTROL/SET_DEAD_TIME", val/4-2);
183}
184
185void MainWindow::on_fPrescalingVal_valueChanged(int val)
186{
187 Dim::SendCommand("FTM_CONTROL/SET_PRESCALING", val);
188}
189
190void MainWindow::slot_fFtuLED_clicked()
191{
192 for (int32_t i=0; i<40; i++)
193 if (sender()==fFtuLED[i])
194 {
195 Dim::SendCommand("FTM_CONTROL/TOGGLE_FTU", i);
196 break;
197 }
198}
199
200void MainWindow::on_fPing_toggled(bool checked)
201{
202 if (checked)
203 Dim::SendCommand("FTM_CONTROL/PING");
204}
205
206void MainWindow::on_fChatSend_clicked()
207{
208 if (Dim::SendCommand("CHAT/MSG", fChatMessage->displayText().constData()))
209 fChatMessage->clear();
210}
211
212void MainWindow::on_fStatusLoggerLed_clicked()
213{
214 SelectTab("Logger");
215}
216
217void MainWindow::on_fStatusChatLed_clicked()
218{
219 SelectTab("Chat");
220}
221
222void MainWindow::on_fStatusFTMLed_clicked()
223{
224 SelectTab("Trigger");
225}
226
227void MainWindow::on_fStatusFTULed_clicked()
228{
229 SelectTab("FTUs");
230}
231
Note: See TracBrowser for help on using the repository browser.