From 6744362acf7d36ddcec6e8416f34bda13c98381c Mon Sep 17 00:00:00 2001
From: Anton Piccardo-Selg <anton.piccardo-selg@tessella.com>
Date: Fri, 24 Jun 2016 10:03:16 +0100
Subject: [PATCH] Refs #16705 Add support for new cansas features in SANSGUI

---
 .../MantidQtCustomInterfaces/SANSRunWindow.h  |  4 +++
 .../CustomInterfaces/src/SANSRunWindow.cpp    | 31 ++++++++++++++++++-
 .../MantidQtMantidWidgets/SaveWorkspaces.h    |  8 +++++
 MantidQt/MantidWidgets/src/SaveWorkspaces.cpp | 23 ++++++++++++--
 4 files changed, 63 insertions(+), 3 deletions(-)

diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h
index 24b9ee880f8..e43f04ae1a7 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/SANSRunWindow.h
@@ -89,6 +89,8 @@ signals:
   void dataReadyToProcess(bool state);
   // signal  to notify mask file loaded
   void userfileLoaded();
+  /// signal to send gemoetry information
+  void sendGeometryInformation(QString &, QString &, QString &, QString &);
 
 private:
   /// Stores the batch or single run mode selection
@@ -315,6 +317,8 @@ private slots:
   void onUpDownCheckboxChanged();
   /// Handle a change of the aperture geometry for QResolution
   void handleQResolutionApertureChange(int aperture);
+  ///
+  void onUpdateGeometryRequest();
 
 private:
   /// used to specify the range of validation to do
diff --git a/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp b/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
index 2fa029192f6..fd593e73846 100644
--- a/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
+++ b/MantidQt/CustomInterfaces/src/SANSRunWindow.cpp
@@ -479,6 +479,13 @@ void SANSRunWindow::saveWorkspacesDialog() {
   // Connect to change in the zero-error removal checkbox
   connect(m_uiForm.zeroErrorCheckBox, SIGNAL(stateChanged(int)),
           m_saveWorkspaces, SLOT(onSaveAsZeroErrorFreeChanged(int)));
+  // Connect the transfer of geometry inforamtion
+  connect(m_saveWorkspaces, SIGNAL(updateGeometryInformation()), this,
+          SLOT(onUpdateGeometryRequest()));
+  connect(this, SIGNAL(sendGeometryInformation(QString &, QString &, QString &,
+                                               QString &)),
+          m_saveWorkspaces, SLOT(onUpdateGeomtryInformation(
+                                QString &, QString &, QString &, QString &)));
 
   m_uiForm.saveSel_btn->setEnabled(false);
   m_saveWorkspaces->show();
@@ -2943,7 +2950,17 @@ void SANSRunWindow::handleDefSaveClick() {
           }
         }
       }
-      // finish the saveCommand for SaveCanSAS1D
+
+      // Add the sample information to the output
+      auto sampleWidth =m_uiForm.sample_width->text();
+      auto sampleHeight = m_uiForm.sample_height->text();
+      auto sampleThickness = m_uiForm.sample_thick->text();
+      auto geometryID = m_uiForm.sample_geomid->currentText();
+      // Remove the first three characters, since they are unwanted
+      auto geometryName = geometryID.mid(3);
+      saveCommand += ", Geometry='" + geometryName + "', SampleHeight=" +
+                     sampleHeight + ", SampleWidth=" + sampleWidth +
+                     ", SampleThickness=" + sampleThickness;
       saveCommand += ")\n";
     } else
       saveCommand += (*alg) + "('" + m_outputWS + "','" + fname + "')\n";
@@ -5070,5 +5087,17 @@ void SANSRunWindow::updateIDFFilePath() {
     m_uiForm.current_idf_path->setText(resultIdf);
   }
 }
+
+void SANSRunWindow::onUpdateGeometryRequest() {
+  auto sampleWidth = m_uiForm.sample_width->text();
+  auto sampleHeight = m_uiForm.sample_height->text();
+  auto sampleThickness = m_uiForm.sample_thick->text();
+  auto geometryID = m_uiForm.sample_geomid->currentText();
+  auto geometryName = geometryID.mid(3);
+
+  emit sendGeometryInformation(geometryName, sampleHeight, sampleWidth,
+                               sampleThickness);
+}
+
 } // namespace CustomInterfaces
 } // namespace MantidQt
diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h
index 9b68deccae2..973c217eaee 100644
--- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h
+++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SaveWorkspaces.h
@@ -54,12 +54,16 @@ public:
   static QString getSaveAlgExt(const QString &algName);
 public slots:
   void onSaveAsZeroErrorFreeChanged(int state);
+  void onUpdateGeomtryInformation(QString &geometryID, QString &sampleHeight,
+                                  QString &sampleWidth,
+                                  QString &sampleThickness);
 
 signals:
   void closing();
   void createZeroErrorFreeWorkspace(QString &originalWorkspace,
                                     QString &zeroFreeWorkspace);
   void deleteZeroErrorFreeWorkspace(QString &zeroFreeWorkspace);
+  void updateGeometryInformation();
 
 private:
   QLineEdit *m_fNameEdit;
@@ -67,6 +71,10 @@ private:
   QCheckBox *m_append;
   QString m_lastName;
   bool m_saveAsZeroErrorFree;
+  QString m_geometryID;
+  QString m_sampleHeight;
+  QString m_sampleWidth;
+  QString m_sampleThickness;
 
   QHash<QCheckBox *const, QString> m_savFormats;
   typedef QHash<QCheckBox *const, QString>::const_iterator SavFormatsConstIt;
diff --git a/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp b/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp
index c58cb747d67..dc090712e2a 100644
--- a/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp
+++ b/MantidQt/MantidWidgets/src/SaveWorkspaces.cpp
@@ -39,7 +39,8 @@ using namespace Mantid::API;
 SaveWorkspaces::SaveWorkspaces(QWidget *parent, const QString &suggFname,
                                QHash<const QCheckBox *const, QString> &defSavs,
                                bool saveAsZeroErrorFree)
-    : API::MantidDialog(parent), m_saveAsZeroErrorFree(saveAsZeroErrorFree) {
+    : API::MantidDialog(parent), m_saveAsZeroErrorFree(saveAsZeroErrorFree), m_geometryID("),
+                            m_sampleHeight(""), m_sampleWidth(""), m_sampleThickness(""){
   setAttribute(Qt::WA_DeleteOnClose);
   setWindowTitle("Save Workspaces");
 
@@ -271,7 +272,12 @@ QString SaveWorkspaces::saveList(const QList<QListWidgetItem *> &wspaces,
         // g_log.wa
       }
     }
-    // finally finish the algorithm call
+    // Add the geometry information
+    emit updateGeometryInformation();
+    // Remove the first three characters, since they are unwanted
+    saveCommands += ", Geometry='" + m_geometryID + "', SampleHeight=" +
+      m_sampleHeight + ", SampleWidth=" + m_sampleWidth +
+      ", SampleThickness=" + m_sampleThickness;
     saveCommands += ")\n";
   }
   return saveCommands;
@@ -431,3 +437,16 @@ void SaveWorkspaces::onSaveAsZeroErrorFreeChanged(int state) {
     m_saveAsZeroErrorFree = true;
   }
 }
+
+/**
+ * Recieves an update for the geometry information
+ */
+void SaveWorkspaces::onUpdateGeomtryInformation(QString &geometryID,
+                                                QString &sampleHeight,
+                                                QString &sampleWidth,
+                                                QString &sampleThickness) {
+  m_geometryID = geometryID;
+  m_sampleHeight = sampleHeight;
+  m_sampleWidth = sampleWidth;
+  m_sampleThickness = sampleThickness;
+}
-- 
GitLab