20#include <QDoubleValidator>
33 saveCommands +=
", DetectorNames=";
37 std::dynamic_pointer_cast<Mantid::API::MatrixWorkspace>(workspace_ptr);
38 if (matrix_workspace) {
39 if (matrix_workspace->getInstrument()->getName() ==
"SANS2D")
40 saveCommands +=
"'front-detector, rear-detector'";
41 if (matrix_workspace->getInstrument()->getName() ==
"LOQ")
42 saveCommands +=
"'HAB, main-detector-bank'";
63 :
API::
MantidDialog(parent), m_saveAsZeroErrorFree(saveAsZeroErrorFree), m_geometryID(
""), m_sampleHeight(
""),
64 m_sampleWidth(
""), m_sampleThickness(
"") {
65 setAttribute(Qt::WA_DeleteOnClose);
66 setWindowTitle(
"Save Workspaces");
69 auto *lineOne =
new QHBoxLayout;
71 auto *lineTwo =
new QHBoxLayout;
74 auto *dialogLayout =
new QVBoxLayout;
75 dialogLayout->addLayout(lineOne);
76 dialogLayout->addLayout(lineTwo);
78 setLayout(dialogLayout);
90 auto *fNameLabel =
new QLabel(
"Filename:");
92 auto *fNameButton =
new QPushButton(
"Browse");
93 connect(fNameButton, SIGNAL(clicked()),
this, SLOT(
saveFileBrowse()));
95 lineOne->addWidget(fNameLabel);
97 lineOne->addWidget(fNameButton);
99 fNameLabel->setToolTip(
"Filename to save under");
101 fNameButton->setToolTip(
"Filename to save under");
111 auto it = ws.begin(), wsEnd = ws.end();
112 for (; it != wsEnd; ++it) {
119 m_workspaces->setSelectionMode(QAbstractItemView::ExtendedSelection);
122 auto *save =
new QPushButton(
"Save");
123 connect(save, SIGNAL(clicked()),
this, SLOT(
saveSel()));
124 auto *cancel =
new QPushButton(
"Cancel");
125 connect(cancel, SIGNAL(clicked()),
this, SLOT(close()));
127 auto *saveRKH =
new QCheckBox(
"RKH (1D/2D)");
128 auto *saveNXcanSAS =
new QCheckBox(
"NXcanSAS (1D/2D)");
129 auto *saveCan =
new QCheckBox(
"CanSAS (1D)");
141 auto *ly_saveConts =
new QVBoxLayout;
142 ly_saveConts->addWidget(save);
143 ly_saveConts->addWidget(cancel);
145 ly_saveConts->addStretch();
147 auto *ly_saveFormats =
new QVBoxLayout;
148 ly_saveFormats->addWidget(saveRKH);
149 ly_saveFormats->addWidget(saveNXcanSAS);
150 ly_saveFormats->addWidget(saveCan);
151 auto *gb_saveForms =
new QGroupBox(tr(
"Save Formats"));
152 gb_saveForms->setLayout(ly_saveFormats);
153 ly_saveConts->addWidget(gb_saveForms);
156 lineTwo->addLayout(ly_saveConts);
158 m_workspaces->setToolTip(
"Select one or more workspaces");
159 const QString formatsTip =
"Some formats support appending multiple workspaces in one file";
160 gb_saveForms->setToolTip(formatsTip);
161 save->setToolTip(formatsTip);
162 cancel->setToolTip(formatsTip);
163 saveNXcanSAS->setToolTip(formatsTip);
164 saveCan->setToolTip(formatsTip);
165 saveRKH->setToolTip(formatsTip);
171 QSettings prevValues;
172 prevValues.beginGroup(
"CustomInterfaces/SANSRunWindow/SaveWorkspaces");
173 m_lastName = prevValues.value(
"out_name",
"").toString();
174 m_append->setChecked(prevValues.value(
"append",
false).toBool());
180 if ((!
m_append->isChecked()) && (!newName.isEmpty())) {
195 for (; j != defSavs.end(); ++j) {
197 if (j.value() == i.value()) {
198 i.key()->setChecked(j.key()->isChecked());
206 QSettings prevValues;
207 prevValues.beginGroup(
"CustomInterfaces/SANSRunWindow/SaveWorkspaces");
209 prevValues.setValue(
"append",
m_append->isChecked());
222 if (wspaces.count() < 1) {
223 throw std::logic_error(
"");
226 if (toAppend && fileBase.isEmpty()) {
228 fileBase = wspaces[0]->text();
232 QString saveCommands;
233 for (
int j = 0; j < wspaces.count(); ++j) {
234 if (workspaceMap.count(wspaces[j]->text())) {
235 saveCommands += algorithm +
"('" + workspaceMap[wspaces[j]->text()] +
"','";
237 saveCommands += algorithm +
"('" + wspaces[j]->text() +
"','";
240 QString outFile = fileBase;
241 if (outFile.isEmpty()) {
242 outFile = wspaces[j]->text();
244 if ((wspaces.count() > 1) && (!toAppend)) {
245 if (outFile.endsWith(exten)) {
246 outFile = outFile.split(exten)[0];
248 outFile +=
"-" + QString::number(j + 1);
252 if (!outFile.endsWith(exten)) {
257 saveCommands += outFile +
"'";
258 if (algorithm !=
"SaveNXcanSAS") {
259 saveCommands +=
", Append=";
260 saveCommands += toAppend ?
"True" :
"False";
262 if (algorithm ==
"SaveCanSAS1D") {
263 setDetectorNamesOnCanSasFormat(saveCommands, wspaces, j);
271 if (algorithm ==
"SaveNXcanSAS") {
272 setDetectorNamesOnCanSasFormat(saveCommands, wspaces, j);
274 saveCommands +=
")\n";
286 Property *prop = alg->getProperty(
"Filename");
307 QString saveCommands;
310 if (i.key()->isChecked()) {
312 bool toAppend =
m_append->isChecked();
316 }
catch (std::logic_error &) {
317 QMessageBox::information(
this,
"No workspace to save",
"You must select at least one workspace to save");
323 saveCommands +=
"print('success')";
330 if (status !=
"success") {
331 QMessageBox::critical(
this,
"Error saving workspace",
332 "One of the workspaces could not be saved in one of "
333 "the selected formats");
347 for (
auto &it : workspacesList) {
348 auto wsName = it->text();
350 if (
workspace->getNumberHistograms() != 1) {
356 auto isCanSAS =
false;
359 if (i.key()->isChecked()) {
360 if (i.value() ==
"SaveCanSAS1D") {
368 auto isValidOption =
true;
370 if (is2D && isCanSAS) {
371 isValidOption =
false;
372 message +=
"Save option issue: Cannot save in CanSAS format for 2D data.\n";
376 if (!message.isEmpty()) {
377 QString warning =
"Please correct these save settings before proceeding:\n";
379 QMessageBox::warning(
this,
"Inconsistent input", warning);
382 return isValidOption;
393 QString title =
"Save output workspace as";
395 QSettings prevValues;
396 prevValues.beginGroup(
"CustomInterfaces/SANSRunWindow/SaveWorkspaces");
402 QString filter =
";;AllFiles (*)";
403 QFileDialog::Option userCon =
404 m_append->isChecked() ? QFileDialog::DontConfirmOverwrite :
static_cast<QFileDialog::Option
>(0);
405 QString oFile = QFileDialog::getSaveFileName(
this, title, prevPath, filter,
nullptr, userCon);
407 if (!oFile.isEmpty()) {
410 QString directory = QFileInfo(oFile).path();
411 prevValues.setValue(
"dir", directory);
425 auto wsList = workspaces->selectedItems();
427 for (
auto &it : wsList) {
428 auto wsName = it->text();
429 auto cloneName = wsName;
431 cloneName +=
"_clone_temp";
436 workspaceMap.insert(wsName, cloneName);
449 auto zeroFreeWorkspaceNames = workspaces.values();
450 for (
auto &zeroFreeWorkspaceName : zeroFreeWorkspaceNames) {
473 QString &sampleThickness) {
IPeaksWorkspace_sptr workspace
QString runPythonCode(const QString &code, bool no_output=false)
Run python code that is passed to it and, optionally, return anything it wrote to standard output as ...
A specialized class for dealing with file properties.
std::string getDefaultExt() const
Returns the main file extension that's used.
Base MatrixWorkspace Abstract Class.
Base Workspace Abstract Class.
Base class for properties.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< IAlgorithm > IAlgorithm_sptr
shared pointer to Mantid::API::IAlgorithm
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
std::shared_ptr< MatrixWorkspace > MatrixWorkspace_sptr
shared pointer to the matrix workspace base class