diff --git a/src/clientgui.cpp b/src/clientgui.cpp index 63218e05b2460c2c0dec4222da7faeecb9038051..0c7b4d24ef19ca525807f72c8ab20b0498ab0a28 100644 --- a/src/clientgui.cpp +++ b/src/clientgui.cpp @@ -66,6 +66,7 @@ ClientGui::ClientGui(const QString& name, const QString& token, std::unique_ptr< connect(_ui.cmdStopAdc, &QPushButton::clicked, std::bind(&ClientGui::sendSimpleActiontoServer, this, Protocol::Action::stopAdc)); connect(_ui.cmdSaveData, &QPushButton::clicked, this, &ClientGui::saveRootFile); connect(_ui.cmdClearHisto, &QPushButton::clicked, this, &ClientGui::clearHistogram); + connect(_ui.cmdUpdateHisto, &QPushButton::clicked, std::bind(&ClientGui::sendSimpleActiontoServer, this, Protocol::Action::sendHistogramUpdate)); connect(_ui.cmdAdcThresholdUp, &QPushButton::clicked, std::bind(&ClientGui::sendSimpleActiontoServer, this, Protocol::Action::adcThresholdUp)); connect(_ui.cmdAdcThresholdDown, &QPushButton::clicked, std::bind(&ClientGui::sendSimpleActiontoServer, this, Protocol::Action::adcThresholdDown)); @@ -119,6 +120,7 @@ void ClientGui::handleMessageFromServer(const QString& message) displayExperimentState(); break; case Protocol::Action::updateHistogram: + updateHistogram(command.arguments[QStringLiteral("bincontents")]); break; case Protocol::Action::fillHistogram: fillEventsIntoHistogram(command.arguments[QStringLiteral("adcchannels")]); @@ -259,6 +261,31 @@ void ClientGui::fillEventsIntoHistogram(const QString& adcchannels) _rootcanvas.getCanvas()->Update(); } +void Fp311Online::ClientGui::updateHistogram(const QString& bincontents) +{ + if (_state.adcState == ExperimentState::AdcState::Running) + return; + + const QStringList binlist = bincontents.split(QChar(';'), QString::SkipEmptyParts, Qt::CaseInsensitive); + if (binlist.size() != ExperimentState::NumberOfAdcChannels) + { + logError("The number of bins in the “bincontents†argument of the â€updateHistogram†command does not match ExperimentState::NumberOfAdcChannels."); + return; + } + for(int i = 1; i <= ExperimentState::NumberOfAdcChannels; i++) + { + bool ok = false; + double content = binlist[i-1].toDouble(&ok); + if (ok) + _histo->SetBinContent(i, content); + else + logWarning(QStringLiteral("Cannot convert bin content string ") + binlist[i] + QStringLiteral(" to double.")); + } + _histo->ResetStats(); + _rootcanvas.getCanvas()->Modified(); + _rootcanvas.getCanvas()->Update(); +} + void ClientGui::clearHistogram(const bool fromServer) { for (int i = 0; i < ExperimentState::NumberOfAdcChannels - 1; i++) diff --git a/src/clientgui.h b/src/clientgui.h index 334a3f7fd02724cccc469e8315ba782074b7c7ce..77ad320a69a5ef983f3720b0c04fddcca1216b53 100644 --- a/src/clientgui.h +++ b/src/clientgui.h @@ -88,6 +88,7 @@ private: void displayExperimentState(); void fillEventsIntoHistogram(const QString& adcchannels); + void updateHistogram(const QString& bincontents); void clearHistogram(const bool fromServer = false); void saveRootFile();