Skip to content
Snippets Groups Projects
Commit 7b261947 authored by Steve Williams's avatar Steve Williams
Browse files

There is a new dialog that allows saving multiple workspaces in multiple...

There is a new dialog that allows saving multiple workspaces in multiple formats. It's accessible from the SANS GUI under "Save Other". Other controls have been added to the SANS GUI to aid loading files and the interface has been rearranged a little. re #1263
parent ca398c1f
No related branches found
No related tags found
No related merge requests found
...@@ -97,6 +97,7 @@ def setCurInst(name) : ...@@ -97,6 +97,7 @@ def setCurInst(name) :
_curInst = allInsts[name] _curInst = allInsts[name]
def setDetector(detName) : def setDetector(detName) :
global _curInst
if _curInst.setDetector(detName) : if _curInst.setDetector(detName) :
global curDetector global curDetector
curDetector = _curInst.curDetector() curDetector = _curInst.curDetector()
......
...@@ -7,8 +7,10 @@ ...@@ -7,8 +7,10 @@
#include "MantidQtCustomInterfaces/ui_SANSRunWindow.h" #include "MantidQtCustomInterfaces/ui_SANSRunWindow.h"
#include "MantidQtAPI/UserSubWindow.h" #include "MantidQtAPI/UserSubWindow.h"
#include "MantidQtCustomInterfaces/SANSAddFiles.h" #include "MantidQtCustomInterfaces/SANSAddFiles.h"
#include "MantidQtMantidWidgets/SaveWorkspaces.h"
#include <QHash> #include <QHash>
#include <QSettings>
#include <QStringList> #include <QStringList>
#include "Poco/NObserver.h" #include "Poco/NObserver.h"
#include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/AnalysisDataService.h"
...@@ -26,23 +28,37 @@ namespace Mantid ...@@ -26,23 +28,37 @@ namespace Mantid
} }
} }
//---------------------------
// Qt Forward Declarations
//---------------------------
class QLineEdit;
class QSignalMapper;
class QLabel;
class QAction; class QAction;
namespace MantidQt namespace MantidQt
{ {
namespace CustomInterfaces namespace CustomInterfaces
{ {
//----------------------------- /**
// Forward declaration Implements the SANS, small angle nuetron scattering, dialog box
//-----------------------------
@author Martyn Gigg
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class SANSRunWindow : public MantidQt::API::UserSubWindow class SANSRunWindow : public MantidQt::API::UserSubWindow
{ {
Q_OBJECT Q_OBJECT
...@@ -69,14 +85,22 @@ private: ...@@ -69,14 +85,22 @@ private:
virtual void initLocalPython(); virtual void initLocalPython();
/**@name Utility functions */ /**@name Utility functions */
//@{ //@{
/// Initialise some of the data and signal connections in the save box
void setupSaveBox();
/// connect the buttons click events to signals /// connect the buttons click events to signals
void connectButtonSignals(); void connectButtonSignals();
/// connect signals from the textChanged() signal from text boxes, index changed on ComboBoxes etc.
void connectChangeSignals();
/// Create the necessary widget maps /// Create the necessary widget maps
void initWidgetMaps(); void initWidgetMaps();
///Read previous settings ///Read previous settings
void readSettings(); void readSettings();
/// Sets the states of the save box controls to the states read from the QSettings object
void readSaveSettings(QSettings & valueStore);
///Save settings ///Save settings
void saveSettings(); void saveSettings();
///Stores the state of the save box controls in QSettings
void saveSaveSettings(QSettings & valueStore);
/// Run a reduce function /// Run a reduce function
QString runReduceScriptFunction(const QString & pycode); QString runReduceScriptFunction(const QString & pycode);
/// Trim python print markers /// Trim python print markers
...@@ -116,6 +140,8 @@ private: ...@@ -116,6 +140,8 @@ private:
void setLOQGeometry(boost::shared_ptr<Mantid::API::MatrixWorkspace> workspace, int wscode); void setLOQGeometry(boost::shared_ptr<Mantid::API::MatrixWorkspace> workspace, int wscode);
/// Mark an error on a label /// Mark an error on a label
void markError(QLabel* label); void markError(QLabel* label);
/// set the name of the output workspace, empty means there is no output
void resetDefaultOutput(const QString & wsName="");
/// Run an assign command /// Run an assign command
bool runAssign(int key, QString & logs); bool runAssign(int key, QString & logs);
/// Get the detectors' names /// Get the detectors' names
...@@ -153,6 +179,12 @@ private slots: ...@@ -153,6 +179,12 @@ private slots:
void selectUserFile(); void selectUserFile();
/// Select a CSV file /// Select a CSV file
void selectCSVFile(); void selectCSVFile();
/// Raises a browse dialog to select the filename used to save the output
void saveFileBrowse();
/// Raises a dialog that allows people to save multiple workspaces
void saveWorkspacesDialog();
///deals with the save workspaces dialog box closing
void saveWorkspacesClosed();
/// A run number has changed /// A run number has changed
void runChanged(); void runChanged();
/// Receive a load button click /// Receive a load button click
...@@ -163,16 +195,20 @@ private slots: ...@@ -163,16 +195,20 @@ private slots:
void handlePlotButtonClick(); void handlePlotButtonClick();
/// Find centre button click handler /// Find centre button click handler
void handleRunFindCentre(); void handleRunFindCentre();
///Handle save button click ///Save the output from a single run reduction in the user selected formats
void handleSaveButtonClick(); void handleDefSaveClick();
/// A ComboBox option change /// A ComboBox option change
void handleStepComboChange(int new_index); void handleStepComboChange(int new_index);
/// Called when the show mask button has been clicked /// Called when the show mask button has been clicked
void handleShowMaskButtonClick(); void handleShowMaskButtonClick();
///Handle the change in instrument ///Handle the change in instrument
void handleInstrumentChange(int); void handleInstrumentChange(int);
///Record if that user has changed the default filename
void setUserFname();
/// Update the centre finding progress /// Update the centre finding progress
void updateCentreFindingStatus(const QString & msg); void updateCentreFindingStatus(const QString & msg);
/// Enable the default save button only if there an output workspace and a filename to save it to
void enableOrDisableDefaultSave();
/// Append log message to log window /// Append log message to log window
void updateLogWindow(const QString & msg); void updateLogWindow(const QString & msg);
/// Switch mode /// Switch mode
...@@ -193,6 +229,8 @@ private: ...@@ -193,6 +229,8 @@ private:
Ui::SANSRunWindow m_uiForm; Ui::SANSRunWindow m_uiForm;
/// this object holds the functionality in the Add Files tab /// this object holds the functionality in the Add Files tab
SANSAddFiles *m_addFilesTab; SANSAddFiles *m_addFilesTab;
/// this points to a saveWorkspaces, which allows users to save any workspace, when one is opened
MantidWidgets::SaveWorkspaces *m_saveWorkspaces;
/// The data directory (as an absolute path) /// The data directory (as an absolute path)
QString m_data_dir; QString m_data_dir;
/// The instrument definition directory /// The instrument definition directory
...@@ -201,6 +239,8 @@ private: ...@@ -201,6 +239,8 @@ private:
QString m_last_dir; QString m_last_dir;
/// Is the user file loaded /// Is the user file loaded
bool m_cfg_loaded; bool m_cfg_loaded;
///True if the user cahnged the default filename text, false otherwise
bool m_userFname;
/// The sample that was loaded /// The sample that was loaded
QString m_sample_no; QString m_sample_no;
/// A map for quickly retrieving the different line edits /// A map for quickly retrieving the different line edits
...@@ -209,12 +249,17 @@ private: ...@@ -209,12 +249,17 @@ private:
QHash<int, QLabel*> m_period_lbls; QHash<int, QLabel*> m_period_lbls;
/// A list of the full workspace names /// A list of the full workspace names
QHash<int, QString> m_workspace_names; QHash<int, QString> m_workspace_names;
// A signal mapper to pick up various button clicks /// Stores the last output workspace from single run mode, should be emptied when run in batch mode
QString m_outputWS;
/// A signal mapper to pick up various button clicks
QSignalMapper *m_reducemapper; QSignalMapper *m_reducemapper;
// A flag to mark that warnings have been issued about geometry issues /// A flag to mark that warnings have been issued about geometry issues
bool m_warnings_issued; bool m_warnings_issued;
// A flag that causes the reload of the data /// A flag that causes the reload of the data
bool m_force_reload; bool m_force_reload;
/// Holds pointers to the check box for each supported save format with the name of its save algorithm
QHash<const QCheckBox * const, QString> m_savFormats;
typedef QHash<const QCheckBox * const, QString>::const_iterator SavFormatsConstIt;
/// A flag indicating there were warning messsages in the log /// A flag indicating there were warning messsages in the log
bool m_log_warnings; bool m_log_warnings;
// An observer for a delete notification from Mantid // An observer for a delete notification from Mantid
......
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>713</width> <width>716</width>
<height>415</height> <height>443</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy" > <property name="sizePolicy" >
...@@ -73,8 +73,8 @@ ...@@ -73,8 +73,8 @@
<attribute name="title" > <attribute name="title" >
<string>Run Numbers</string> <string>Run Numbers</string>
</attribute> </attribute>
<layout class="QVBoxLayout" name="verticalLayout_4" > <layout class="QGridLayout" name="gridLayout_21" >
<item> <item row="0" column="0" colspan="2" >
<layout class="QHBoxLayout" name="horizontalLayout_12" > <layout class="QHBoxLayout" name="horizontalLayout_12" >
<item> <item>
<widget class="QLabel" name="label_7" > <widget class="QLabel" name="label_7" >
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
</item> </item>
</layout> </layout>
</item> </item>
<item> <item row="1" column="0" colspan="2" >
<layout class="QHBoxLayout" name="horizontalLayout_8" > <layout class="QHBoxLayout" name="horizontalLayout_8" >
<item> <item>
<widget class="QRadioButton" name="single_mode_btn" > <widget class="QRadioButton" name="single_mode_btn" >
...@@ -225,16 +225,122 @@ ...@@ -225,16 +225,122 @@
</property> </property>
</spacer> </spacer>
</item> </item>
<item>
<widget class="QGroupBox" name="groupBox_12" >
<property name="title" >
<string/>
</property>
<property name="flat" >
<bool>false</bool>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_16" >
<item>
<widget class="QLabel" name="label_34" >
<property name="text" >
<string>Instrument:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="inst_opt" >
<item>
<property name="text" >
<string>LOQ</string>
</property>
</item>
<item>
<property name="text" >
<string>SANS2D</string>
</property>
</item>
</widget>
</item>
<item>
<widget class="QLabel" name="label_26" >
<property name="text" >
<string>File type:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="file_opt" />
</item>
</layout>
</widget>
</item>
</layout> </layout>
</item> </item>
<item> <item row="4" column="0" >
<widget class="QGroupBox" name="groupBox_4" >
<property name="title" >
<string>Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_20" >
<item row="0" column="1" >
<widget class="QCheckBox" name="verbose_check" >
<property name="text" >
<string>Verbose</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QCheckBox" name="log_colette" >
<property name="text" >
<string>Log Colette cmds</string>
</property>
</widget>
</item>
<item row="0" column="0" >
<widget class="QCheckBox" name="plot_check" >
<property name="text" >
<string>Plot result</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="5" column="0" >
<widget class="QGroupBox" name="groupBox_7" >
<property name="title" >
<string>Reduce</string>
</property>
<property name="flat" >
<bool>false</bool>
</property>
<layout class="QGridLayout" name="gridLayout_19" >
<item row="0" column="0" >
<widget class="QPushButton" name="load_dataBtn" >
<property name="text" >
<string>Load Data</string>
</property>
</widget>
</item>
<item row="0" column="1" >
<widget class="QPushButton" name="oneDBtn" >
<property name="text" >
<string>1D Reduce</string>
</property>
</widget>
</item>
<item row="0" column="2" >
<widget class="QPushButton" name="twoDBtn" >
<property name="text" >
<string>2D Reduce</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="2" >
<widget class="Line" name="line_2" > <widget class="Line" name="line_2" >
<property name="orientation" > <property name="orientation" >
<enum>Qt::Horizontal</enum> <enum>Qt::Horizontal</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item> <item row="3" column="0" colspan="2" >
<widget class="QStackedWidget" name="mode_stack" > <widget class="QStackedWidget" name="mode_stack" >
<property name="currentIndex" > <property name="currentIndex" >
<number>1</number> <number>1</number>
...@@ -927,179 +1033,119 @@ ...@@ -927,179 +1033,119 @@
</widget> </widget>
</widget> </widget>
</item> </item>
<item> <item rowspan="2" row="4" column="1" >
<layout class="QHBoxLayout" name="horizontalLayout_10" > <widget class="QGroupBox" name="groupBox_5" >
<item> <property name="title" >
<widget class="QGroupBox" name="groupBox_4" > <string>Save</string>
<property name="title" >
<string>Options</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2" >
<property name="topMargin" >
<number>2</number>
</property>
<item>
<widget class="QCheckBox" name="plot_check" >
<property name="text" >
<string>Plot result</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="verbose_check" >
<property name="text" >
<string>Verbose</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="log_colette" >
<property name="text" >
<string>Log Colette cmds</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4" >
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer_5" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0" >
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_15" >
<property name="spacing" >
<number>6</number>
</property>
<property name="topMargin" >
<number>0</number>
</property> </property>
<item> <layout class="QGridLayout" name="gridLayout" >
<widget class="QGroupBox" name="groupBox_7" > <item rowspan="2" row="0" column="4" >
<property name="title" > <widget class="QPushButton" name="saveFilename_btn" >
<string>Reduce</string> <property name="minimumSize" >
</property> <size>
<property name="flat" > <width>0</width>
<bool>false</bool> <height>0</height>
</property> </size>
<layout class="QGridLayout" name="gridLayout" > </property>
<item row="0" column="0" > <property name="toolTip" >
<widget class="QPushButton" name="load_dataBtn" > <string>Save the output workspace to this file</string>
<property name="text" > </property>
<string>Load Data</string> <property name="text" >
</property> <string>Browse</string>
</widget> </property>
</item> </widget>
<item row="0" column="1" colspan="2" > </item>
<widget class="QPushButton" name="oneDBtn" > <item row="3" column="4" >
<property name="text" > <widget class="QCheckBox" name="saveCSV_check" >
<string>1D Reduce</string> <property name="toolTip" >
</property> <string>Select one or more file formats</string>
</widget> </property>
</item> <property name="text" >
<item row="0" column="3" > <string>CSV</string>
<widget class="QPushButton" name="twoDBtn" > </property>
<property name="text" > </widget>
<string>2D Reduce</string> </item>
</property> <item row="3" column="3" >
</widget> <widget class="QCheckBox" name="saveRKH_check" >
</item> <property name="toolTip" >
<item row="0" column="4" > <string>Select one or more file formats</string>
<widget class="QPushButton" name="saveBtn" > </property>
<property name="text" > <property name="text" >
<string>Save</string> <string>RKH</string>
</property> </property>
</widget> </widget>
</item> </item>
</layout> <item row="3" column="2" >
</widget> <widget class="QCheckBox" name="saveCan_check" >
</item> <property name="toolTip" >
<item> <string>Select one or more file formats</string>
<spacer name="horizontalSpacer_8" > </property>
<property name="orientation" > <property name="text" >
<enum>Qt::Horizontal</enum> <string>CanSAS</string>
</property> </property>
<property name="sizeHint" stdset="0" > </widget>
<size> </item>
<width>40</width> <item row="3" column="1" >
<height>20</height> <widget class="QCheckBox" name="saveNex_check" >
</size> <property name="toolTip" >
</property> <string>Select one or more file formats</string>
</spacer> </property>
</item> <property name="text" >
<item> <string>Nexus</string>
<widget class="QGroupBox" name="groupBox_12" > </property>
<property name="title" > </widget>
<string/> </item>
</property> <item rowspan="2" row="0" column="0" >
<property name="flat" > <widget class="QLabel" name="label_58" >
<bool>false</bool> <property name="toolTip" >
</property> <string>Save the output workspace to this file</string>
<layout class="QHBoxLayout" name="horizontalLayout_16" > </property>
<item> <property name="text" >
<widget class="QLabel" name="label_34" > <string>Filename:</string>
<property name="text" > </property>
<string>Instrument:</string> </widget>
</property> </item>
</widget> <item rowspan="2" row="2" column="0" >
</item> <widget class="QLabel" name="label_64" >
<item> <property name="toolTip" >
<widget class="QComboBox" name="inst_opt" > <string>Select one or more file formats</string>
<item> </property>
<property name="text" > <property name="text" >
<string>LOQ</string> <string>Formats:</string>
</property> </property>
</item> </widget>
<item> </item>
<property name="text" > <item row="4" column="1" colspan="2" >
<string>SANS2D</string> <widget class="QPushButton" name="saveDefault_btn" >
</property> <property name="toolTip" >
</item> <string>Save the workspace from a single run file reduction</string>
</widget> </property>
</item> <property name="text" >
<item> <string>Save Result</string>
<widget class="QLabel" name="label_26" > </property>
<property name="text" > </widget>
<string>File type:</string> </item>
</property> <item row="1" column="1" colspan="3" >
</widget> <widget class="QLineEdit" name="outfile_edit" >
</item> <property name="toolTip" >
<item> <string>Save the output workspace to this file</string>
<widget class="QComboBox" name="file_opt" /> </property>
</item> </widget>
</layout> </item>
</widget> <item row="4" column="3" colspan="2" >
</item> <widget class="QPushButton" name="saveSel_btn" >
</layout> <property name="toolTip" >
<string>Save multiple workspaces</string>
</property>
<property name="text" >
<string>Save Other</string>
</property>
</widget>
</item>
</layout>
</widget>
</item> </item>
</layout> </layout>
<zorder>line_2</zorder>
<zorder>mode_stack</zorder>
<zorder></zorder>
</widget> </widget>
<widget class="QWidget" name="tab_2" > <widget class="QWidget" name="tab_2" >
<attribute name="title" > <attribute name="title" >
......
...@@ -29,7 +29,8 @@ SOURCES = \ ...@@ -29,7 +29,8 @@ SOURCES = \
$$SRCDIR/pythonCalc.cpp \ $$SRCDIR/pythonCalc.cpp \
$$SRCDIR/DiagResults.cpp \ $$SRCDIR/DiagResults.cpp \
$$SRCDIR/MWDiag.cpp \ $$SRCDIR/MWDiag.cpp \
$$SRCDIR/MWDiagCalcs.cpp $$SRCDIR/MWDiagCalcs.cpp \
$$SRCDIR/SaveWorkspaces.cpp
HEADERS = \ HEADERS = \
$$HEADERDIR/MantidWidget.h \ $$HEADERDIR/MantidWidget.h \
...@@ -38,7 +39,8 @@ HEADERS = \ ...@@ -38,7 +39,8 @@ HEADERS = \
$$HEADERDIR/WidgetDllOption.h \ $$HEADERDIR/WidgetDllOption.h \
$$HEADERDIR/DiagResults.h \ $$HEADERDIR/DiagResults.h \
$$HEADERDIR/MWDiag.h \ $$HEADERDIR/MWDiag.h \
$$HEADERDIR/MWDiagCalcs.h $$HEADERDIR/MWDiagCalcs.h \
$$HEADERDIR/SaveWorkspaces.h
UI_DIR = $$HEADERDIR UI_DIR = $$HEADERDIR
......
#ifndef MANTIDQTMANTIDWIDGETS_SAVEWORKSPACES_H_
#define MANTIDQTMANTIDWIDGETS_SAVEWORKSPACES_H_
#include "MantidQtAPI/MantidQtDialog.h"
#include "WidgetDllOption.h"
#include <QHash>
#include <QSignalMapper>
#include <QGridLayout>
#include <QListWidget>
#include <QLineEdit>
#include <QCheckBox>
#include <QString>
#include "MantidAPI/FrameworkManager.h"
namespace MantidQt
{
namespace MantidWidgets
{
/**
Implements a dialog box that allows users to save multiple Mantid workspaces
@author Steve Williams
Copyright &copy; 2010 ISIS Rutherford Appleton Laboratory & NScD Oak Ridge National Laboratory
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://svn.mantidproject.org/mantid/trunk/Code/Mantid>
Code Documentation is available at: <http://doxygen.mantidproject.org>
*/
class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SaveWorkspaces : public API::MantidQtDialog
{
Q_OBJECT
public:
SaveWorkspaces(QWidget *parent, const QString & suggFname = "",
const QHash<const QCheckBox * const, QString> & defSavs =
QHash<const QCheckBox * const, QString>());
void initLayout();
///Returns the save extension expected the name algorithm
static QString getSaveAlgExt(const QString & algName);
signals:
void closing();
void runAsPythonScript(const QString&);
private:
QLineEdit *m_fNameEdit;
QListWidget *m_workspaces;
QCheckBox *m_append;
QHash<QCheckBox * const, QString> m_savFormats;
typedef QHash<QCheckBox * const, QString>::const_iterator SavFormatsConstIt;
void setupLine1(QHBoxLayout * const lineOne, const QString defName);
void setupLine2(QHBoxLayout * const lineTwo, const QHash<const QCheckBox * const, QString> & defSavs);
void setupFormatTicks(const QHash<const QCheckBox * const, QString> & defSavs);
void addButtonsDisab(int row);
void setupButtons(int row, QString test);
void updateRow(int row, QString firstColumn, int secondColumn);
void closeEvent(QCloseEvent *event);
QString saveList(const QList<QListWidgetItem*> & list, const QString & algorithm, QString fileBase, bool toAppend);
private slots:
void saveSel();
void saveFileBrowse();
};
}
}
#endif //MANTIDQTMANTIDWIDGETS_SAVEWORKSPACES_H_
//----------------------
// Includes
//----------------------
#include "MantidQtMantidWidgets/SaveWorkspaces.h"
#include "MantidAPI/AnalysisDataService.h"
#include "MantidAPI/FrameworkManager.h"
#include "MantidAPI/AlgorithmManager.h"
#include "MantidAPI/MatrixWorkspace.h"
#include "MantidKernel/ConfigService.h"
#include "MantidKernel/FileProperty.h"
#include <QLabel>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QPushButton>
#include <QDoubleValidator>
#include <QCloseEvent>
#include <QShowEvent>
#include <QGroupBox>
#include <QSettings>
#include <QFileDialog>
#include <QMessageBox>
using namespace MantidQt::MantidWidgets;
using namespace Mantid::Kernel;
using namespace Mantid::API;
//----------------------
// Public member functions
//----------------------
/**
* @param parent used by QT
* @param suggFname sets the initial entry in the filename box
* @param defSavs sets which boxes are ticked
*/
SaveWorkspaces::SaveWorkspaces(QWidget *parent, const QString & suggFname, const QHash<const QCheckBox * const, QString> & defSavs) :
API::MantidQtDialog(parent)
{
setWindowTitle("Save Workspaces");
//the form is split into 3 lines of controls in horizontal layouts
QHBoxLayout *lineOne = new QHBoxLayout;
setupLine1(lineOne, suggFname);
QHBoxLayout *lineTwo = new QHBoxLayout;
setupLine2(lineTwo, defSavs);
QVBoxLayout *dialogLayout = new QVBoxLayout;
dialogLayout->addLayout(lineOne);
dialogLayout->addLayout(lineTwo);
setLayout(dialogLayout);
setAttribute(Qt::WA_DeleteOnClose);
}
/// Set up the dialog layout
void SaveWorkspaces::initLayout()
{
}
/** Puts the controls that go on the first line, the output
* filename commands, on to the layout that's passed to it
* @param lineOne the layout on to which the controls will be placed
*/
void SaveWorkspaces::setupLine1(QHBoxLayout * const lineOne, const QString defName)
{
QLabel* fNameLabel = new QLabel("Filename:");
m_fNameEdit = new QLineEdit();
m_fNameEdit->setText(defName);
QPushButton *fNameButton = new QPushButton("Browse");
connect(fNameButton, SIGNAL(clicked()), this, SLOT(saveFileBrowse()));
lineOne->addWidget(fNameLabel);
lineOne->addWidget(m_fNameEdit);
lineOne->addWidget(fNameButton);
fNameLabel->setToolTip("Filename to save under");
m_fNameEdit->setToolTip("Filename to save under");
fNameButton->setToolTip("Filename to save under");
}
/** Puts the controls that go on the second line, the workspace
* list and save commands, on to the layout that's passed to it
* @param lineTwo the layout on to which the controls will be placed
*/
void SaveWorkspaces::setupLine2(QHBoxLayout * const lineTwo, const QHash<const QCheckBox * const, QString> & defSavs)
{
m_workspaces = new QListWidget();
std::set<std::string> ws = AnalysisDataService::Instance().getObjectNames();
std::set<std::string>::const_iterator it = ws.begin(), wsEnd = ws.end();
for( ; it != wsEnd; ++it)
{
Workspace *wksp = FrameworkManager::Instance().getWorkspace(*it);
if( dynamic_cast<MatrixWorkspace*>(wksp) )
{//only include matrix workspaces, not groups or tables
m_workspaces->addItem(QString::fromStdString(*it));
}
}
//allow users to select more than one workspace in the list
m_workspaces->setSelectionMode(QAbstractItemView::ExtendedSelection);
QPushButton *save = new QPushButton("Save");
connect(save, SIGNAL(clicked()), this, SLOT(saveSel()));
QPushButton *cancel = new QPushButton("Cancel");
connect(cancel, SIGNAL(clicked()), this, SLOT(close()));
QCheckBox *saveNex = new QCheckBox("Nexus");
QCheckBox *saveCan = new QCheckBox("CanSAS");
QCheckBox *saveRKH = new QCheckBox("RKH");
QCheckBox *saveCSV = new QCheckBox("CSV");
//link the save option tick boxes to their save algorithm
m_savFormats.insert(saveNex, "SaveNexus");
m_savFormats.insert(saveCan, "SaveCanSAS1D");
m_savFormats.insert(saveRKH, "SaveRKH");
m_savFormats.insert(saveCSV, "SaveCSV");
setupFormatTicks(defSavs);
m_append = new QCheckBox("Append");
// place controls into the layout, which places them on the form and takes care of deleting them
QVBoxLayout *ly_saveConts = new QVBoxLayout;
ly_saveConts->addWidget(save);
ly_saveConts->addWidget(cancel);
ly_saveConts->addWidget(m_append);
ly_saveConts->addStretch();
QVBoxLayout *ly_saveFormats = new QVBoxLayout;
ly_saveFormats->addWidget(saveNex);
ly_saveFormats->addWidget(saveCan);
ly_saveFormats->addWidget(saveRKH);
ly_saveFormats->addWidget(saveCSV);
QGroupBox *gb_saveForms = new QGroupBox(tr("Save Formats"));
gb_saveForms->setLayout(ly_saveFormats);
ly_saveConts->addWidget(gb_saveForms);
lineTwo->addWidget(m_workspaces);
lineTwo->addLayout(ly_saveConts);
m_workspaces->setToolTip("Select one or more workspaces");
const QString formatsTip = "Some formats support appending multiple workspaces in one file";
gb_saveForms->setToolTip(formatsTip);
save->setToolTip(formatsTip);
cancel->setToolTip(formatsTip);
saveNex->setToolTip(formatsTip);
saveCan->setToolTip(formatsTip);
saveRKH->setToolTip(formatsTip);
saveCSV->setToolTip(formatsTip);
m_append->setToolTip(formatsTip);
}
/** For each save format tick box take the user setting from the
* main form
*/
void SaveWorkspaces::setupFormatTicks(const QHash<const QCheckBox * const, QString> & defSavs)
{
for(SavFormatsConstIt i=m_savFormats.begin(); i != m_savFormats.end(); ++i)
{
//find the setting that has been passed for this save format
QHash<const QCheckBox * const, QString>::const_iterator j = defSavs.begin();
for ( ; j != defSavs.end(); ++j )
{
//the values are the algorithm names
if ( j.value() == i.value() )
{//copy over the checked status of the check box
i.key()->setChecked(j.key()->isChecked());
}
}
}
}
/**
* Called in response to a close event
* @parma event The event object
*/
void SaveWorkspaces::closeEvent(QCloseEvent* event)
{
emit closing();
event->accept();
}
QString SaveWorkspaces::saveList(const QList<QListWidgetItem*> & wspaces, const QString & algorithm, QString fileBase, bool toAppend)
{
if ( wspaces.count() < 1 )
{
throw std::logic_error("");
}
if (toAppend && fileBase.isEmpty())
{//no file name was given, use the name of the first workspace
fileBase = wspaces[0]->text();
}
QString exten = getSaveAlgExt(algorithm);
QString saveCommands;
for (int j =0; j < wspaces.count(); ++j)
{
saveCommands += algorithm + "('"+wspaces[j]->text()+"','";
QString outFile = fileBase;
if (outFile.isEmpty())
{//if no filename was given use the workspace names
outFile = wspaces[j]->text();
}
else
{//we have a file name
if( ( wspaces.count() > 1 ) && ( ! toAppend ) )
{//but multiple output files, number the files
if (outFile.endsWith(exten))
{//put the number before the extension
outFile = outFile.split(exten)[0];
}
outFile += "-"+QString::number(j+1);
}
}
if ( ! outFile.endsWith(exten) )
{//code above sometimes removes the extension and the possiblity that one just wasn't added needs dealing with too
outFile += exten;
}
saveCommands += outFile + "'";
if (toAppend)
{
saveCommands += ", Append=True";
}
//finally finish the algorithm call
saveCommands += ")\n";
}
return saveCommands;
}
/** Gets the first extension that the algorithm passed algorithm has in it's
* FileProperty (the FileProperty must have the name "Filename"
* @param algName name of the Mantid save algorithm
* @return the first extension, if the algorithm's Filename property has an extension list or ""
*/
QString SaveWorkspaces::getSaveAlgExt(const QString & algName)
{
IAlgorithm_sptr alg = AlgorithmManager::Instance().create(
algName.toStdString());
Property *prop = alg->getProperty("Filename");
FileProperty *fProp = dynamic_cast<FileProperty*>(prop);
if (fProp)
{
return QString::fromStdString(fProp->getDefaultExt());
}
else
{// the algorithm doesn't have a "Filename" file property which may indicate an error later on or maybe OK
return "";
}
}
/** Excutes the selected save algorithms on the workspaces that
* have been selected to be saved
*/
void SaveWorkspaces::saveSel()
{
QString saveCommands;
for(SavFormatsConstIt i = m_savFormats.begin(); i != m_savFormats.end(); ++i)
{//the key a pointer to the check box that the user may have clicked
if (i.key()->isChecked())
{//we need to save in this format
bool toAppend = m_append->isChecked();
if (toAppend)
{//there are two algorithms that don't support appending, check for those
if ( i.value() == "SaveCanSAS1D" || i.value() == "SaveCSV" )
{
toAppend = false;
}
}
try
{
saveCommands += saveList(m_workspaces->selectedItems(), i.value(),
m_fNameEdit->text(), toAppend);
}
catch(std::logic_error)
{
QMessageBox::information(this, "No workspace to save", "You must select at least one workspace to save");
return;
}
}//end if save in this format
}//end loop over formats
emit runAsPythonScript(saveCommands);
}
/** Raises a browse dialog and inserts the selected file into the
* save text edit box, outfile_edit
*/
void SaveWorkspaces::saveFileBrowse()
{
QString title = "Save output workspace as";
QSettings prevValues;
prevValues.beginGroup("CustomInterfaces/SANSRunWindow/SaveWorkspaces");
//use their previous directory first and go to their default if that fails
QString prevPath = prevValues.value("dir", QString::fromStdString(
ConfigService::Instance().getString("defaultsave.directory"))).toString();
QString filter = ";;AllFiles (*.*)";
QString oFile = QFileDialog::getSaveFileName(this, title, prevPath, filter);
if( ! oFile.isEmpty() )
{
m_fNameEdit->setText(oFile);
QString directory = QFileInfo(oFile).path();
prevValues.setValue("dir", directory);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment