From 6869d820023a7386bc240dc103a2ad3ad9d33c3a Mon Sep 17 00:00:00 2001
From: Federico Montesino Pouzols <federico.montesino-pouzols@stfc.ac.uk>
Date: Wed, 18 May 2016 17:42:51 +0100
Subject: [PATCH] show non-modal pop-up when RB number needed, re #16252

---
 .../EnggDiffractionPresenter.h                |  4 ++
 .../EnggDiffractionViewQtGUI.h                |  8 ++++
 .../EnggDiffraction/IEnggDiffractionView.h    | 17 ++++++++-
 .../EnggDiffractionPresenter.cpp              | 18 ++++++++-
 .../EnggDiffractionViewQtGUI.cpp              | 38 ++++++++++++++++++-
 .../test/EnggDiffractionViewMock.h            |  5 +++
 .../interfaces/Engineering_Diffraction.rst    |  7 ++--
 7 files changed, 89 insertions(+), 8 deletions(-)

diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h
index 60e00060918..cb71369d4c3 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h
@@ -336,6 +336,10 @@ private:
   /// string to use for ENGINX file names (as a prefix, etc.)
   const static std::string g_enginxStr;
 
+  /// The message to tell the user that an RB number is needed
+  const static std::string g_shortMsgRBNumberRequired;
+  const static std::string g_msgRBNumberRequired;
+
   /// string to use for invalid run number error message
   const static std::string g_runNumberErrorStr;
 
diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
index c8d440ea101..220406484ba 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionViewQtGUI.h
@@ -19,6 +19,7 @@
 #include <qwt_plot_zoomer.h>
 
 // Qt classes forward declarations
+class QMessageBox;
 class QMutex;
 
 namespace MantidQt {
@@ -69,6 +70,9 @@ public:
   /// This interface's categories.
   static QString categoryInfo() { return "Diffraction"; }
 
+  void splashMessage(bool visible, const std::string &shortMsg,
+                     const std::string &description) override;
+
   void userWarning(const std::string &warn,
                    const std::string &description) override;
 
@@ -289,6 +293,7 @@ private:
   /// Setup the interface (tab UI)
   void initLayout() override;
   void doSetupGeneralWidgets();
+  void doSetupSplashMsg();
   void doSetupTabCalib();
   void doSetupTabFocus();
   void doSetupTabPreproc();
@@ -357,6 +362,9 @@ private:
   EnggDiffCalibSettings m_calibSettings;
   std::string m_outCalibFilename;
 
+  /// To show important non-modal messages
+  QMessageBox *m_splashMsg;
+
   /// This is in principle the only settings for 'focus'
   std::string m_focusDir;
 
diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h
index 319bc7073bd..76da500db95 100644
--- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h
+++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/EnggDiffraction/IEnggDiffractionView.h
@@ -47,8 +47,23 @@ public:
   IEnggDiffractionView(){};
   virtual ~IEnggDiffractionView(){};
 
-  /// @name Direct (and usually modal) user interaction
+  /// @name Direct (and usually modal, or at least top/pop-up level) user
+  /// interaction
   //@{
+  /**
+   * To display important messages that need maximum visibility
+   * (normally a dialog on top of the interface). This can be used to
+   * control the visibility and content of the message. An example use
+   * case is to inform the user that certain inputs are absolutely
+   * needed to use the interface functionality.
+   *
+   * @param visible whether the "splash"/important message should be visible
+   * @param shortMsg short/one line message summary
+   * @param description message with full details
+   */
+  virtual void splashMessage(bool visible, const std::string &shortMsg,
+                             const std::string &description) = 0;
+
   /**
    * Display a warning to the user (for example as a pop-up window).
    *
diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp
index fb236de9161..22e63b70ea0 100644
--- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp
+++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionPresenter.cpp
@@ -29,6 +29,15 @@ Mantid::Kernel::Logger g_log("EngineeringDiffractionGUI");
 
 const std::string EnggDiffractionPresenter::g_enginxStr = "ENGINX";
 
+const std::string EnggDiffractionPresenter::g_shortMsgRBNumberRequired =
+    "A valid RB Number is required";
+const std::string EnggDiffractionPresenter::g_msgRBNumberRequired =
+    std::string("An experiment reference number (or so called \"RB "
+                "number\" at ISIS) is "
+                "required to effectively use this interface. \n") +
+    "The output calibration, focusing and fitting results will be "
+    "saved in directories named using the RB number entered.";
+
 const std::string EnggDiffractionPresenter::g_runNumberErrorStr =
     " cannot be empty, must be an integer number, valid ENGINX run number/s "
     "or "
@@ -1153,7 +1162,10 @@ void EnggDiffractionPresenter::processInstChange() {
 
 void EnggDiffractionPresenter::processRBNumberChange() {
   const std::string rbn = m_view->getRBNumber();
-  m_view->enableTabs(validateRBNumber(rbn));
+  auto valid = validateRBNumber(rbn);
+  m_view->enableTabs(valid);
+  m_view->splashMessage(!valid, g_shortMsgRBNumberRequired,
+                        g_msgRBNumberRequired);
 }
 
 void EnggDiffractionPresenter::processShutDown() {
@@ -1177,7 +1189,9 @@ void EnggDiffractionPresenter::processStopFocus() {
 
 /**
 * Check if an RB number is valid to work with it (retrieve data,
-* calibrate, focus, etc.).
+* calibrate, focus, etc.). For now this will accept any non-empty
+* string. Later on we might be more strict about valid RB numbers /
+* experiment IDs.
 *
 * @param rbn RB number as given by the user
 */
diff --git a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp
index 14b1412d26e..c85e24dc562 100644
--- a/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp
+++ b/MantidQt/CustomInterfaces/src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp
@@ -69,8 +69,9 @@ const std::string EnggDiffractionViewQtGUI::m_settingsGroup =
 */
 EnggDiffractionViewQtGUI::EnggDiffractionViewQtGUI(QWidget *parent)
     : UserSubWindow(parent), IEnggDiffractionView(), m_currentInst("ENGINX"),
-      m_currentCalibFilename(""), m_focusedDataVector(), m_fittedDataVector(),
-      m_peakPicker(NULL), m_zoomTool(NULL), m_presenter(NULL) {}
+      m_currentCalibFilename(""), m_splashMsg(nullptr), m_focusedDataVector(),
+      m_fittedDataVector(), m_peakPicker(nullptr), m_zoomTool(nullptr),
+      m_presenter(nullptr) {}
 
 EnggDiffractionViewQtGUI::~EnggDiffractionViewQtGUI() {
   for (auto curves : m_focusedDataVector) {
@@ -319,6 +320,8 @@ void EnggDiffractionViewQtGUI::doSetupTabSettings() {
 }
 
 void EnggDiffractionViewQtGUI::doSetupGeneralWidgets() {
+  doSetupSplashMsg();
+
   // change instrument
   connect(m_ui.comboBox_instrument, SIGNAL(currentIndexChanged(int)), this,
           SLOT(instrumentChanged(int)));
@@ -332,6 +335,21 @@ void EnggDiffractionViewQtGUI::doSetupGeneralWidgets() {
           SLOT(RBNumberChanged()));
 }
 
+void EnggDiffractionViewQtGUI::doSetupSplashMsg() {
+  if (m_splashMsg)
+    delete m_splashMsg;
+
+  m_splashMsg = new QMessageBox(this);
+  m_splashMsg->setIcon(QMessageBox::Information);
+  m_splashMsg->setStandardButtons(QMessageBox::NoButton);
+  m_splashMsg->setWindowTitle("Setting up");
+  m_splashMsg->setText("Setting up the interface!");
+  m_splashMsg->setWindowFlags(Qt::SplashScreen | Qt::FramelessWindowHint |
+                              Qt::X11BypassWindowManagerHint);
+  m_splashMsg->setWindowModality(Qt::NonModal);
+  // we don't want to show now: m_splashMsg->show();
+}
+
 void EnggDiffractionViewQtGUI::readSettings() {
   QSettings qs;
   qs.beginGroup(QString::fromStdString(m_settingsGroup));
@@ -599,6 +617,21 @@ std::string EnggDiffractionViewQtGUI::guessDefaultFullCalibrationPath() const {
   templ.append("ENGINX_full_pixel_calibration_vana194547_ceria193749.csv");
   return templ.toString();
 }
+
+void EnggDiffractionViewQtGUI::splashMessage(bool visible,
+                                             const std::string &shortMsg,
+                                             const std::string &description) {
+  m_splashMsg->setWindowTitle(QString::fromStdString(shortMsg));
+  m_splashMsg->setText(QString::fromStdString(description));
+  // when showing the message, force it to show up centered
+  if (visible) {
+    const auto pos = this->mapToGlobal(rect().center());
+    m_splashMsg->move(pos.x() - m_splashMsg->width() / 2,
+                      pos.y() - m_splashMsg->height() / 2);
+  }
+  m_splashMsg->setVisible(visible);
+}
+
 void EnggDiffractionViewQtGUI::userWarning(const std::string &err,
                                            const std::string &description) {
   QMessageBox::warning(this, QString::fromStdString(err),
@@ -1703,6 +1736,7 @@ void EnggDiffractionViewQtGUI::closeEvent(QCloseEvent *event) {
 
   if (answer == QMessageBox::AcceptRole && m_ui.pushButton_close->isEnabled()) {
     m_presenter->notify(IEnggDiffractionPresenter::ShutDown);
+    delete m_splashMsg;
     event->accept();
   } else {
     event->ignore();
diff --git a/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h b/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h
index 904cedfd50c..e042bc9bce6 100644
--- a/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h
+++ b/MantidQt/CustomInterfaces/test/EnggDiffractionViewMock.h
@@ -10,6 +10,11 @@ class MockEnggDiffractionView
     : public MantidQt::CustomInterfaces::IEnggDiffractionView {
 
 public:
+  // virtual void splashMessage(bool visible, const std::string &shortMsg,
+  // const std::string &description);
+  MOCK_METHOD3(splashMessage, void(bool visible, const std::string &shortMsg,
+                                   const std::string &description));
+
   // virtual void userWarning(const std::string &warn, const std::string
   // &description);
   MOCK_METHOD2(userWarning,
diff --git a/docs/source/interfaces/Engineering_Diffraction.rst b/docs/source/interfaces/Engineering_Diffraction.rst
index a7183ed6add..1c0c451eef3 100644
--- a/docs/source/interfaces/Engineering_Diffraction.rst
+++ b/docs/source/interfaces/Engineering_Diffraction.rst
@@ -30,9 +30,10 @@ Close
   Close the interface
 
 RB Number
-  To enable the GUI specify a RB Number, the RB number will be used for the
-  output paths, so that files from different users and/or experiments can
-  be kept separate.
+  To enable the GUI specify a RB Number (where "RB Number" usually
+  denotes the experiment reference number at ISIS). This reference
+  will be used for the output paths, so that files from different
+  users and/or experiments can be kept separate.
 
 * Red Star Sign
   If a red star sign is displayed next to the Browse Button, it is mostly
-- 
GitLab