25#include <Poco/ActiveResult.h>
27#include <QCoreApplication>
29#include <QInputDialog>
40namespace MantidWidgets {
46 : MantidDialog(fitBrowser), m_fitBrowser(fitBrowser) {
49 connect(
ui.btnAddFile, SIGNAL(clicked()),
this, SLOT(
addFile()));
50 connect(
ui.btnAddWorkspace, SIGNAL(clicked()),
this, SLOT(
addWorkspace()));
51 connect(
ui.btnDelete, SIGNAL(clicked()),
this, SLOT(
removeItem()));
53 connect(
ui.btnFit, SIGNAL(clicked()),
this, SLOT(
accept()));
54 connect(
ui.btnCancel, SIGNAL(clicked()),
this, SLOT(reject()));
55 connect(
ui.btnHelp, SIGNAL(clicked()),
this, SLOT(
helpClicked()));
56 connect(
ui.ckbLogPlot, SIGNAL(toggled(
bool)),
this, SLOT(
plotAgainstLog(
bool)));
57 connect(
ui.ckCreateOutput, SIGNAL(toggled(
bool)),
ui.ckOutputCompMembers, SLOT(setEnabled(
bool)));
58 connect(
ui.ckCreateOutput, SIGNAL(toggled(
bool)),
ui.ckConvolveMembers, SLOT(setEnabled(
bool)));
59 connect(
ui.ckCreateOutput, SIGNAL(toggled(
bool)),
ui.ckOutputSpecParams, SLOT(setEnabled(
bool)));
61 ui.cbLogValue->setEditable(
true);
62 ui.ckbLogPlot->setChecked(
true);
63 ui.sbPeriod->setValue(1);
70 if (mantidui !=
nullptr) {
75 connect(
ui.tWorkspaces, SIGNAL(cellChanged(
int,
int)),
this, SLOT(
spectraChanged(
int,
int)));
76 connect(
ui.tWorkspaces, SIGNAL(itemSelectionChanged()),
this, SLOT(
selectionChanged()));
83 if (dlg->exec() == QDialog::Accepted) {
89 if (wsNames.isEmpty())
91 int row =
ui.tWorkspaces->rowCount();
92 ui.tWorkspaces->model()->insertRows(row, wsNames.size());
94 QAbstractItemModel *model =
ui.tWorkspaces->model();
95 foreach (QString wsName, wsNames) {
96 model->setData(model->index(row, 0, QModelIndex()), wsName);
103 model->setData(model->index(row, 1, QModelIndex()),
"");
104 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 1);
106 item->setBackground(QColor(Qt::lightGray));
107 item->setFlags(Qt::NoItemFlags);
110 if (
ui.ckbLogPlot->isChecked()) {
113 Mantid::API::AnalysisDataService::Instance().retrieve(wsName.toStdString()));
116 const auto y = ws->getAxis(1);
117 if (
y->isSpectra()) {
118 spec =
y->spectraNo(wi);
124 ui.sbSpectrum->setValue(spec);
133 ui.tWorkspaces->resizeRowsToContents();
134 ui.tWorkspaces->resizeColumnsToContents();
139 QFileDialog dlg(
this);
140 dlg.setFileMode(QFileDialog::ExistingFiles);
141 const std::vector<std::string> &searchDirs = Mantid::Kernel::ConfigService::Instance().getDataSearchDirs();
143 if (searchDirs.empty()) {
146 dir = QString::fromStdString(searchDirs.front());
148 dlg.setDirectory(dir);
150 QStringList fileNames;
151 fileNames = dlg.selectedFiles();
152 if (fileNames.isEmpty())
156 int row =
ui.tWorkspaces->rowCount();
157 ui.tWorkspaces->model()->insertRows(row, fileNames.size());
159 QAbstractItemModel *model =
ui.tWorkspaces->model();
160 foreach (QString fileName, fileNames) {
161 model->setData(model->index(row, 0, QModelIndex()), fileName);
162 model->setData(model->index(row, 1, QModelIndex()),
163 ui.sbPeriod->value());
164 model->setData(model->index(row, 2, QModelIndex()),
165 ui.sbSpectrum->value());
166 model->setData(model->index(row, 3, QModelIndex()),
"");
167 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 3);
169 item->setBackground(QColor(Qt::lightGray));
170 item->setFlags(Qt::NoItemFlags);
174 ui.tWorkspaces->resizeRowsToContents();
175 ui.tWorkspaces->resizeColumnsToContents();
181 while (!ranges.empty()) {
182 ui.tWorkspaces->model()->removeRows(ranges[0].topRow(), ranges[0].
rowCount());
183 ranges =
ui.tWorkspaces->selectedRanges();
189 Mantid::API::AnalysisDataService::Instance().retrieve(wsName.toStdString()));
191 const std::vector<Mantid::Kernel::Property *> logs = ws->run().getLogData();
192 QStringList logNames;
194 logNames <<
"SourceName";
195 for (
auto log : logs) {
200 logNames << QString::fromStdString(log->name());
202 int n =
ui.cbLogValue->count();
204 if (logNames.empty()) {
209 ui.cbLogValue->insertItems(0, logNames);
212 QStringList namesToRemove;
213 for (
int i = 0; i <
n; ++i) {
214 QString logName =
ui.cbLogValue->itemText(i);
215 if (!logNames.contains(logName)) {
216 namesToRemove << logName;
219 foreach (QString logName, namesToRemove) {
220 int i =
ui.cbLogValue->findText(logName);
222 ui.cbLogValue->removeItem(i);
225 if (
ui.cbLogValue->count() == 0) {
226 QMessageBox::warning(
m_fitBrowser, QCoreApplication::applicationName() +
" Warning",
227 "The list of the log names is empty:\n"
228 "The selected workspaces do not have common logs");
237 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 3);
238 return !item || item->flags().testFlag(Qt::ItemIsEnabled) ==
false;
243 int colonCount = range.count(
':');
244 if (colonCount != 1) {
249 QStringList parts = range.split(
':');
250 if (parts.size() != 2) {
254 QString start = parts[0].trimmed();
255 QString end = parts[1].trimmed();
258 if (start.isEmpty() || end.isEmpty()) {
264 double startVal = start.toDouble(&startOk);
265 double endVal = end.toDouble(&endOk);
267 if (!startOk || !endOk) {
272 if (startVal > endVal) {
286 QString spectrum =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 2)).toString();
287 QString wsIndex =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 3)).toString();
288 QString range =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 4)).toString();
291 g_log.
error() <<
"Invaild range please use the format start:end." << std::endl;
298 if (!range.isEmpty()) {
301 index =
"sp" + spectrum;
305 Mantid::API::AnalysisDataService::Instance().retrieve(
name(row).toStdString()));
310 if (
rowCount() == 1 && range.isEmpty()) {
311 index = QString(
"v%1:%2").arg((*
y)(0)).arg((*
y)(
y->length() - 1));
313 if (!range.isEmpty()) {
316 index =
"i" + wsIndex;
325 QStringList inputStr;
326 for (
int i = 0; i <
ui.tWorkspaces->rowCount(); ++i) {
327 QString wsName =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(i, 0)).toString();
331 QString parStr = wsName +
"," +
index;
333 parStr += QString(
",") +
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(i, 1)).toString();
351 std::string inputStdStr = inputStr.join(
";").toStdString();
352 alg->setPropertyValue(
"Input", inputStdStr);
361 alg->setProperty(
"StartX", std::vector<double>(nInputs, startX));
362 alg->setProperty(
"EndX", std::vector<double>(nInputs, endX));
364 alg->setPropertyValue(
"Function", funStr);
365 alg->setProperty(
"CreateOutput",
ui.ckCreateOutput->isChecked());
366 alg->setProperty(
"OutputCompositeMembers",
ui.ckOutputCompMembers->isChecked());
367 alg->setProperty(
"ConvolveMembers",
ui.ckConvolveMembers->isChecked());
368 alg->setProperty(
"Output2D",
ui.ckOutputSpecParams->isChecked());
369 alg->setProperty(
"AppendIdxToOutputName",
true);
370 if (
ui.ckbLogPlot->isChecked()) {
371 std::string logName =
ui.cbLogValue->currentText().toStdString();
372 alg->setPropertyValue(
"LogValue", logName);
374 }
else if (nInputs > 1) {
375 alg->setPropertyValue(
"LogValue",
"SourceName");
382 if (
ui.rbIndividual->isChecked()) {
383 alg->setPropertyValue(
"FitType",
"Individual");
386 alg->setProperty(
"EvaluationType",
"Histogram");
389 bool passWSIndexToFunction =
ui.ckbPassWS->isChecked();
390 alg->setProperty(
"PassWSIndexToFunction", passWSIndexToFunction);
392 auto errors = alg->validateInputs();
394 if (!errors.empty()) {
395 for (
const auto &[key,
error] : errors) {
410 ui.cbParameter->clear();
411 ui.cbParameter->insertItems(0, names);
428 if (!Mantid::API::AnalysisDataService::Instance().doesExist(wsName)) {
432 Mantid::API::AnalysisDataService::Instance().retrieve(wsName));
436 auto columnNames = ws->getColumnNames();
439 if (
rowCount() > 1 && columnNames[0] ==
"SourceName") {
443 auto firstColumn = ws->getColumn(0);
444 for (
size_t i = 0; i < ws->rowCount(); ++i) {
462 for (
size_t col = 1; col < columnNames.size() - 1; col += 2) {
465 auto paramName = columnNames[col];
468 paramName.insert(0,
"f0.");
491 if (!
ui.ckbLogPlot->isChecked())
493 QTableWidgetItem *item =
ui.tWorkspaces->item(row, 3);
496 if ((col == 2 || col == 3) && item->flags().testFlag(Qt::ItemIsEnabled) ==
true) {
497 QString wsName =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 0)).toString();
500 ws = std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(
501 Mantid::API::AnalysisDataService::Instance().retrieve(wsName.toStdString()));
507 int wi =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 3)).toInt();
508 int spec =
ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 2)).toInt();
510 if (wi >= 0 && wi <
static_cast<int>(ws->getNumberHistograms())) {
512 if (!
y->isSpectra() ||
y->spectraNo(wi) == spec)
531 for (
int i = 0; i < static_cast<int>(
y->length()); ++i) {
532 if ((*
y)(i) == spec) {
548 ui.tWorkspaces->model()->setData(
ui.tWorkspaces->model()->index(row, 2), spec);
552 ui.tWorkspaces->model()->setData(
ui.tWorkspaces->model()->index(row, 3), wi);
560 return ui.tWorkspaces->model()->data(
ui.tWorkspaces->model()->index(row, 0)).toString();
564 QString range = QString::number(from) +
":" + QString::number(to);
565 ui.tWorkspaces->model()->setData(
ui.tWorkspaces->model()->index(row, 3), range);
572 ui.lblLogValue->setVisible(yes);
573 ui.cbLogValue->setVisible(yes);
574 ui.lblPeriod->setVisible(yes);
575 ui.sbPeriod->setVisible(yes);
576 ui.lblSpectrum->setVisible(yes);
577 ui.sbSpectrum->setVisible(yes);
608 ui.btnDelete->setEnabled(
ui.tWorkspaces->selectionModel()->hasSelection());
double value
The value of the point.
std::map< DeltaEMode::Type, std::string > index
static void showAlgorithm(const std::string &name=std::string(), const int version=-1)
void observeFinish(const IAlgorithm_const_sptr &alg)
Connect to algorithm alg and observe its finish notification.
Class to represent the axis of a workspace.
virtual specnum_t spectraNo(const std::size_t &index) const
Get the spectrum number.
IAlgorithm is the interface implemented by the Algorithm base class.
TableRow represents a row in a TableWorkspace.
double & Double(size_t col)
Returns a reference to the element in position col if its type is double.
The Logger class is in charge of the publishing messages from the framework through various channels.
void error(const std::string &msg)
Logs at error level.
A specialised Property class for holding a series of time-value pairs.
The AlgorithmProgressDialogPresenter keeps track of the running algorithms and displays a progress ba...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< ITableWorkspace > ITableWorkspace_sptr
shared pointer to Mantid::API::ITableWorkspace
Kernel::Logger g_log("ExperimentInfo")
static logger object
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class
Kernel::Logger g_log("DetermineSpinStateOrder")