23#include "qboxlayout.h"
32using Mantid::Types::Core::DateAndTime;
40 ~LiveDataAlgInputHistoryImpl()
override =
default;
56 ~LiveDataPostProcessingAlgInputHistoryImpl()
override =
default;
67using LiveDataPostProcessingAlgInputHistory =
83 :
AlgorithmDialog(parent), m_scrollbars(this), m_useProcessAlgo(false), m_useProcessScript(false),
84 m_usePostProcessAlgo(false), m_usePostProcessScript(false) {
86 LiveDataAlgInputHistory::Instance();
92 LiveDataAlgInputHistory::Instance().save();
93 LiveDataPostProcessingAlgInputHistory::Instance().save();
107 ui.processingAlgo->setInputHistory(history1);
109 ui.postAlgo->setInputHistory(history2);
116 tie(
ui.edtUpdateEvery,
"UpdateEvery",
ui.layoutUpdateEvery);
119 tie(
ui.radNow,
"FromNow");
120 tie(
ui.radStartOfRun,
"FromStartOfRun");
121 tie(
ui.radAbsoluteTime,
"FromTime");
124 tie(
ui.chkPreserveEvents,
"PreserveEvents");
127 tie(
ui.cmbRunTransitionBehavior,
"RunTransitionBehavior");
130 tie(
ui.editAccumulationWorkspace,
"AccumulationWorkspace",
ui.gridLayout);
131 tie(
ui.editOutputWorkspace,
"OutputWorkspace",
ui.gridLayout);
134 ui.processingAlgo->update();
135 ui.postAlgo->update();
138 ui.tabWidget->setCurrentIndex(0);
139 ui.splitterMain->setStretchFactor(0, 0);
140 ui.splitterMain->setStretchFactor(1, 1);
143 for (
int i = 0; i < 2; i++) {
145 QString prefix =
"Processing";
148 prefix =
"PostProcessing";
149 QString algo = AlgorithmInputHistory::Instance().previousInput(
"StartLiveData", prefix +
"Algorithm");
150 QString script = AlgorithmInputHistory::Instance().previousInput(
"StartLiveData", prefix +
"Script");
154 ui.radProcessAlgorithm->setChecked(
true);
155 else if (!script.isEmpty())
156 ui.radProcessScript->setChecked(
true);
158 ui.radProcessNone->setChecked(
true);
161 ui.processingAlgo->setScriptText(script);
162 ui.processingAlgo->setSelectedAlgorithm(algo);
166 ui.radPostProcessAlgorithm->setChecked(
true);
167 else if (!script.isEmpty())
168 ui.radPostProcessScript->setChecked(
true);
170 ui.radPostProcessNone->setChecked(
true);
173 ui.postAlgo->setScriptText(script);
174 ui.postAlgo->setSelectedAlgorithm(algo);
181 ui.cmbConnListener->clear();
182 std::vector<std::string> listeners = Mantid::API::LiveListenerFactory::Instance().getKeys();
183 for (
const auto &listener : listeners) {
184 ui.cmbConnListener->addItem(QString::fromStdString(listener));
213 connect(
ui.cmbConnListener, SIGNAL(currentTextChanged(
const QString &)),
this,
215 connect(
ui.cmbConnListener, SIGNAL(currentTextChanged(
const QString &)),
this,
217 connect(
ui.cmbInstrument, SIGNAL(currentTextChanged(
const QString &)),
this, SLOT(
updateUiElements(
const QString &)));
218 connect(
ui.cmbInstrument, SIGNAL(currentTextChanged(
const QString &)),
this,
221 connect(
ui.cmbConnection, SIGNAL(currentTextChanged(
const QString &)),
this,
225 ui.mainLayout->addLayout(buttonLayout);
268 ui.processingAlgo->saveInput();
269 ui.postAlgo->saveInput();
299 ui.lblPreserveEventsWarning->setVisible(
ui.chkPreserveEvents->isChecked());
306 Algorithm_sptr alg =
ui.processingAlgo->getAlgorithm();
316 Algorithm_sptr alg =
ui.postAlgo->getAlgorithm();
328 if (listener.isEmpty())
332 int addIndex =
ui.cmbAccumulationMethod->findText(
"Add");
333 ui.cmbAccumulationMethod->setItemData(addIndex, QVariant(Qt::ItemIsSelectable | Qt::ItemIsEnabled),
340 if (!Mantid::API::LiveListenerFactory::Instance().create(info,
false)->buffersEvents()) {
342 if (
ui.cmbAccumulationMethod->currentIndex() == addIndex) {
343 int replaceIndex =
ui.cmbAccumulationMethod->findText(
"Replace");
344 ui.cmbAccumulationMethod->setCurrentIndex(replaceIndex);
347 ui.cmbAccumulationMethod->setItemData(addIndex,
false, Qt::UserRole - 1);
368 if (inst ==
"TOPAZ") {
369 ui.groupBox->setEnabled(
false);
370 ui.radNow->setChecked(
true);
372 ui.groupBox->setEnabled(
true);
384 DateAndTime startTime = DateAndTime::getCurrentTime() -
ui.dateTimeEdit->value() * 60.0;
385 std::string starttime = startTime.toISO8601String();
388 QString propertyname = QString::fromStdString(
"StartTime");
389 QString propertyvalue = QString::fromStdString(starttime);
402 auto props =
m_algorithm->getPropertiesInGroup(
"ListenerProperties");
403 for (
const auto &prop : props) {
404 QString propName = QString::fromStdString((*prop).name());
411 if (
ui.cmbInstrument->currentText().toStdString() !=
"") {
413 QLayout *layout =
ui.listenerProps->layout();
415 QGridLayout *listenerPropLayout =
new QGridLayout(
ui.listenerProps);
416 layout = listenerPropLayout;
419 while ((child = layout->takeAt(0)) !=
nullptr) {
420 child->widget()->close();
427 m_algorithm->setPropertyValue(
"Instrument",
ui.cmbInstrument->currentText().toStdString());
428 m_algorithm->setPropertyValue(
"Listener", listener.toStdString());
430 props =
m_algorithm->getPropertiesInGroup(
"ListenerProperties");
434 ui.listenerProps->setVisible(
false);
438 auto gridLayout =
static_cast<QGridLayout *
>(layout);
440 for (
auto prop = props.begin(); prop != props.end(); ++prop) {
441 int row =
static_cast<int>(std::distance(props.begin(), prop));
442 QString propName = QString::fromStdString((**prop).name());
443 gridLayout->addWidget(
new QLabel(propName), row, 0);
444 QLineEdit *propWidget =
new QLineEdit();
445 gridLayout->addWidget(propWidget, row, 1);
449 tie(propWidget, propName, gridLayout);
451 ui.listenerProps->setVisible(
true);
460 ui.cmbInstrument->clear();
465 std::vector<std::string> instruments;
467 const auto &facility = ConfigService::Instance().getFacility();
468 for (
const auto &instrument : facility.instruments()) {
469 if (instrument.hasLiveListenerInfo()) {
470 instruments.emplace_back(instrument.name());
473 }
catch (
const std::runtime_error &e) {
475 g_log.
warning() <<
"Cannot list live-data instruments: " << e.what() <<
"\n";
478 std::sort(instruments.begin(), instruments.end());
480 for (
const auto &instrument : instruments) {
481 ui.cmbInstrument->addItem(QString::fromStdString(instrument));
484 const auto previous = AlgorithmInputHistory::Instance().previousInput(
"StartLiveData",
"Instrument");
485 const auto index =
ui.cmbInstrument->findText(previous);
487 ui.cmbInstrument->setCurrentIndex(
index);
498 ui.cmbConnection->clear();
502 const auto &inst = ConfigService::Instance().getInstrument(inst_name.toStdString());
503 for (
const auto &listener : inst.liveListenerInfoList()) {
504 ui.cmbConnection->addItem(QString::fromStdString(listener.name()));
509 auto selectName = QString::fromStdString(inst.liveListenerInfo().name());
510 auto index =
ui.cmbConnection->findText(selectName);
511 ui.cmbConnection->setCurrentIndex(
index);
512 }
catch (std::runtime_error &) {
525 ui.cmbConnListener->setEnabled(
true);
526 ui.edtConnAddress->setEnabled(
true);
531 ui.cmbConnListener->setEnabled(
false);
532 ui.edtConnAddress->setEnabled(
false);
535 const auto &inst = ConfigService::Instance().getInstrument(
ui.cmbInstrument->currentText().toStdString());
536 const auto &info = inst.liveListenerInfo(connection.toStdString());
539 auto listener = QString::fromStdString(info.listener());
540 auto index =
ui.cmbConnListener->findText(listener);
541 ui.cmbConnListener->setCurrentIndex(
index);
544 auto address = QString::fromStdString(info.address());
545 ui.edtConnAddress->setText(address);
546 ui.edtConnAddress->home(
false);
#define DECLARE_DIALOG(classname)
std::map< DeltaEMode::Type, std::string > index
This abstract class deals with the loading and saving of previous algorithm property values to/from M...
This class should be the basis for all customised algorithm dialogs.
void fillAndSetComboBox(const QString &propName, QComboBox *optionsBox) const
Fill a combo box for the named algorithm's allowed values.
Mantid::API::IAlgorithm_sptr m_algorithm
The algorithm associated with this dialog.
QLayout * createDefaultButtonLayout(const QString &helpText=QString("?"), const QString &loadText=QString("Run"), const QString &cancelText=QString("Close"), const QString &keepOpenText=QString("Keep Open"))
Create a row layout of buttons with specified text.
void storePropertyValue(const QString &name, const QString &value)
Adds a property (name,value) pair to the stored map.
QWidget * tie(QWidget *widget, const QString &property, QLayout *parent_layout=nullptr, bool readHistory=true)
Tie a widget to a property.
QStringList m_algProperties
The properties associated with this dialog.
void accept() override
A default slot that can be used for an OK button.
Ui::StartLiveDataDialog ui
The form generated by Qt Designer.
bool m_usePostProcessScript
void chkPreserveEventsToggled()
Slot called when the preserve events checkbox changes.
void initListenerPropLayout(const QString &listener)
Update the Listener Properties group box for the current LiveListener.
void parseInput() override
Parse the input from the dialog when it has been accepted.
Mantid::API::Algorithm_sptr m_postProcessingAlg
The algorithm for processing the accumulated workspace.
static const QString CUSTOM_CONNECTION
Constant used for custom listener connection setups.
void radioTimeClicked()
Slot called when one of the radio buttons in "starting time" are picked.
StartLiveDataDialog(QWidget *parent=nullptr)
Default Constructor.
~StartLiveDataDialog() override
Destructor.
void changePostProcessingAlgorithm()
Slot called when picking a different algorithm in the AlgorithmSelectorWidget.
void initLayout() override
Initialize the layout.
void fillInstrumentComboBox()
Fill the instrument combo box from the default facility's live-data instruments.
void updateConnectionChoices(const QString &inst_name)
Slot to update list of available connections when instrument is changed.
void radioPostProcessClicked()
Slot called when one of the radio buttons in "processing" are picked.
Mantid::API::Algorithm_sptr m_processingAlg
The algorithm for processing chunks.
void changeProcessingAlgorithm()
Slot called when picking a different algorithm in the AlgorithmSelectorWidget.
void radioProcessClicked()
Slot called when one of the radio buttons in "processing" are picked.
void updateUiElements(const QString &)
Another slot called when picking a different instrument.
void updateConnectionDetails(const QString &connection)
Slot to update connection parameters when connection selected.
API::WidgetScrollbarDecorator m_scrollbars
This dialog needs scrollbars on small screens.
bool m_usePostProcessAlgo
void setDefaultAccumulationMethod(const QString &)
Slot called when picking a different instrument.
Exception for when an item is not found in a collection.
A class that holds information about a LiveListener connection.
The Logger class is in charge of the publishing messages from the framework through various channels.
void warning(const std::string &msg)
Logs at warning level.
Manage the lifetime of a class intended to be a singleton.
Mantid::Kernel::SingletonHolder< AlgorithmManagerImpl > AlgorithmManager
std::shared_ptr< Algorithm > Algorithm_sptr
Typedef for a shared pointer to an Algorithm.
Kernel::Logger g_log("DetermineSpinStateOrder")
Mantid::Kernel::SingletonHolder< ConfigServiceImpl > ConfigService
Policy class controlling creation of the singleton Implementation classes should mark their default c...