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

Last change on this file since 10657 was 10657, checked in by tbretz, 9 years ago
Added or improved documentation.
File size: 6.2 KB
Line 
1#include "MainWindow.h"
2
3#include <iostream>
4
5#include <QTimer>
6
7#include "src/Dim.h"
8
9#include "DockWindow.h"
10#include "HtmlDelegate.h"
11#include "CheckBoxDelegate.h"
12
13using namespace std;
14
15MainWindow::MainWindow(QWidget *p) : QMainWindow(p)
16{
17    // setupUi MUST be called before the DimNetwork is initilized
18    // In this way it can be ensured that nothing from the
19    // DimNetwork arrives before all graphical elements are
20    // initialized. This is a simple but very powerfull trick.
21    setupUi(this);
22
23    // Now here we can do further setup which should be done
24    // before the gui is finally displayed.
25    fDimCmdServers->setItemDelegate(new CheckBoxDelegate);
26    fDimCmdCommands->setItemDelegate(new CheckBoxDelegate);
27    fDimCmdDescription->setItemDelegate(new HtmlDelegate);
28
29    fDimSvcServers->setItemDelegate(new CheckBoxDelegate);
30    fDimSvcServices->setItemDelegate(new CheckBoxDelegate);
31    fDimSvcDescription->setItemDelegate(new HtmlDelegate);
32
33    // Set a default string to be displayed in a the status bar at startup
34    fStatusBar->showMessage(PACKAGE_STRING"   |   "PACKAGE_URL"   |   report bugs to <"PACKAGE_BUGREPORT">");
35
36    // Initialize the 40 FTU Leds as a copy of the prototype LED
37    fFtuLED[0] = fFtuLEDPrototype;
38
39    for (int i=1; i<40; i++)
40    {
41        QPushButton *b = new QPushButton(static_cast<QWidget*>(fFtuLEDPrototype->parent()));
42
43        b->setEnabled(fFtuLEDPrototype->isEnabled());
44        b->setSizePolicy(fFtuLEDPrototype->sizePolicy());
45        b->setMaximumSize(fFtuLEDPrototype->maximumSize());
46        b->setIcon(fFtuLEDPrototype->icon());
47        b->setIconSize(fFtuLEDPrototype->iconSize());
48        b->setCheckable(fFtuLEDPrototype->isCheckable());
49        b->setFlat(fFtuLEDPrototype->isFlat());
50
51        fFtuLedLayout->addWidget(b, i/10+1, i%10+1, 1, 1);
52
53        fFtuLED[i] = b;
54    }
55
56    for (int i=0; i<40; i++)
57    {
58        fFtuLED[i]->setObjectName(QString::fromUtf8("fFtuLED")+QString::number(i));
59        QObject::connect(fFtuLED[i], SIGNAL(clicked()), this, SLOT(slot_fFtuLED_clicked()));
60    }
61
62    // Initialize a timer to update the displayed UTC time
63    QTimer *timer = new QTimer(this);
64    connect(timer, SIGNAL(timeout()), this, SLOT(slot_TimeUpdate()));
65    timer->start(100);
66}
67
68void MainWindow::slot_TimeUpdate()
69{
70    fUTC->setDateTime(QDateTime::currentDateTimeUtc());
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}
Note: See TracBrowser for help on using the repository browser.