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