diff --git a/MantidQt/CustomInterfaces/CMakeLists.txt b/MantidQt/CustomInterfaces/CMakeLists.txt index 167b56d2670c0cc17f5409a2b9545ef347a84f41..e6aaebd245886489596294736963162cc8feeda1 100644 --- a/MantidQt/CustomInterfaces/CMakeLists.txt +++ b/MantidQt/CustomInterfaces/CMakeLists.txt @@ -1,6 +1,8 @@ set ( SRC_FILES src/DataComparison.cpp src/DirectConvertToEnergy.cpp + src/DynamicPDF/SliceSelector.cpp + src/DynamicPDF/BackgroundRemover.cpp src/EnggDiffraction/EnggDiffractionPresenter.cpp src/EnggDiffraction/EnggDiffractionViewQtGUI.cpp src/Homer.cpp @@ -120,6 +122,8 @@ set ( INC_FILES inc/MantidQtCustomInterfaces/DataComparison.h inc/MantidQtCustomInterfaces/DirectConvertToEnergy.h inc/MantidQtCustomInterfaces/DllConfig.h + inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h + inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffCalibSettings.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresWorker.h inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionPresenter.h @@ -349,6 +353,8 @@ set ( MOC_FILES inc/MantidQtCustomInterfaces/Background.h set ( UI_FILES inc/MantidQtCustomInterfaces/DataComparison.ui inc/MantidQtCustomInterfaces/DirectConvertToEnergy.ui + inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.ui + inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.ui inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionQtGUI.ui inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionQtTabCalib.ui inc/MantidQtCustomInterfaces/EnggDiffraction/EnggDiffractionQtTabFocus.ui diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.h new file mode 100644 index 0000000000000000000000000000000000000000..11ca6ab7419aa248441c7abdb9012a319ab40fdd --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.h @@ -0,0 +1,36 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_DYNAMICPDF_BACKGROUNDREMOVER_H_ +#define MANTIDQTCUSTOMINTERFACES_DYNAMICPDF_BACKGROUNDREMOVER_H_ + +#include <QDialog> +#include "ui_BackgroundRemover.h" +#include <boost/shared_ptr.hpp> + +namespace MantidQt { +namespace CustomInterfaces { +namespace DynamicPDF { + +// Forward declaration +class WorkspaceRecord; +class SliceSelector; + +class BackgroundRemover: public QDialog +{ + Q_OBJECT + +public: + + BackgroundRemover(SliceSelector *parent); + + +public: + + void refreshSlice(const boost::shared_ptr<WorkspaceRecord> loadedWorkspace, + const size_t &workspaceIndex); + +}; + +} +} +} + +#endif // MANTIDQTCUSTOMINTERFACES_DYNAMICPDF_BACKGROUNDREMOVER_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.ui b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.ui new file mode 100644 index 0000000000000000000000000000000000000000..d0bfcc4ed5ce4a1a189934036da2568f0cc907a5 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.ui @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>BackgroundRemover</class> + <widget class="QDialog" name="BackgroundRemover"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>349</width> + <height>177</height> + </rect> + </property> + <property name="windowTitle"> + <string>Background remover tool</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <widget class="QDialogButtonBox" name="buttonBox"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="standardButtons"> + <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> + </property> + </widget> + </item> + </layout> + </widget> + <resources/> + <connections> + <connection> + <sender>buttonBox</sender> + <signal>accepted()</signal> + <receiver>BackgroundRemover</receiver> + <slot>accept()</slot> + <hints> + <hint type="sourcelabel"> + <x>248</x> + <y>254</y> + </hint> + <hint type="destinationlabel"> + <x>157</x> + <y>274</y> + </hint> + </hints> + </connection> + <connection> + <sender>buttonBox</sender> + <signal>rejected()</signal> + <receiver>BackgroundRemover</receiver> + <slot>reject()</slot> + <hints> + <hint type="sourcelabel"> + <x>316</x> + <y>260</y> + </hint> + <hint type="destinationlabel"> + <x>286</x> + <y>274</y> + </hint> + </hints> + </connection> + </connections> +</ui> diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h new file mode 100644 index 0000000000000000000000000000000000000000..b7461ce472f6e2df03f224d4230a1f46f1fdc016 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h @@ -0,0 +1,71 @@ +#ifndef MANTIDQTCUSTOMINTERFACES_DYNAMICPDF_SLICESELECTOR_H_ +#define MANTIDQTCUSTOMINTERFACES_DYNAMICPDF_SLICESELECTOR_H_ + +#include "MantidQtCustomInterfaces/DllConfig.h" +#include "MantidQtAPI/UserSubWindow.h" +#include "ui_SliceSelector.h" + +namespace MantidQt { +namespace CustomInterfaces { +namespace DynamicPDF { + +using workspacePtr = boost::shared_ptr<Mantid::API::MatrixWorkspace>; + +// Forward Declarations +class BackgroundRemover; + +/// Helper class containing pointer and some metadata for the loaded workspace +class WorkspaceRecord{ + +public: + /// Default Constructor + WorkspaceRecord(const std::string &workspaceName); + void updateMetadata(const size_t &newIndex); + + workspacePtr ws; + const std::string name; + double energy; + std::string label; +}; + + +class MANTIDQT_CUSTOMINTERFACES_DLL SliceSelector + : public MantidQt::API::UserSubWindow { + Q_OBJECT + +public: + /// The name of the interface as registered into the factory + static std::string name() { return "Dynamic PDF Slice Selector"; } + // This interface's categories. + static QString categoryInfo() { return "DynamicPDF"; } + +public: + /// Default Constructor + SliceSelector(QWidget *parent = NULL); + +private slots: + /// Opens the Qt help page for the interface + void showHelp(); + /// Load file or workspace containing energy slices + void loadedSlices(const QString &workspaceName); + /// Update all child widgets + void updateSelectedSlice(const int &newSelectedIndex); + void updatePlotSelectedSlice(); + /// Launch (initialize and/or update) the background removal tool + void launchBackgroundRemover(); + +private: + /// Initialize the ui form and connect SIGNALS to SLOTS + void initLayout(); + /// The form generated by Qt Designer + Ui::SliceSelector m_uiForm; + boost::shared_ptr<WorkspaceRecord> m_loadedWorkspace; + size_t m_selectedWorkspaceIndex; + /// The child dialog to remove the multiphonon background + boost::shared_ptr<BackgroundRemover> m_BackgroundRemover; +}; + +} +} +} +#endif // MANTIDQTCUSTOMINTERFACES_DYNAMICPDF_SLICESELECTOR_H_ diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.ui b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.ui new file mode 100644 index 0000000000000000000000000000000000000000..4e0ad8b978ff4cc9edc702a81b972f9af10d4486 --- /dev/null +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/DynamicPDF/SliceSelector.ui @@ -0,0 +1,195 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>SliceSelector</class> + <widget class="QMainWindow" name="SliceSelector"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>432</width> + <height>654</height> + </rect> + </property> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="windowTitle"> + <string>Dynamic PDF Slice Selector</string> + </property> + <widget class="QWidget" name="centralwidget"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + <item> + <widget class="QGroupBox" name="groupLoadSlices"> + <property name="title"> + <string>Loads Slices</string> + </property> + <layout class="QGridLayout" name="loRangeBinning"> + <property name="topMargin"> + <number>0</number> + </property> + <property name="bottomMargin"> + <number>0</number> + </property> + <item row="0" column="0"> + <widget class="MantidQt::MantidWidgets::DataSelector" name="dataSelector" native="true"/> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="layoutSliceSelector"> + <item> + <widget class="QLabel" name="labelWorkspaceIndex"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Workspace Index</string> + </property> + </widget> + </item> + <item> + <widget class="QSpinBox" name="spinboxSliceSelector"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + </widget> + </item> + <item> + <widget class="QLabel" name="labelSliceEnergy"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Energy = NAN</string> + </property> + </widget> + </item> + </layout> + </item> + <item> + <widget class="QGroupBox" name="groupPlotSelectedSlice"> + <property name="title"> + <string>Plots Selected Slice</string> + </property> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="MantidQt::MantidWidgets::PreviewPlot" name="previewPlotSelectedSlice" native="true"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="showLegend" stdset="0"> + <bool>false</bool> + </property> + <property name="canvasColour" stdset="0"> + <color> + <red>255</red> + <green>255</green> + <blue>255</blue> + </color> + </property> + </widget> + </item> + </layout> + </widget> + </item> + <item> + <layout class="QHBoxLayout" name="layoutActionButtons"> + <item> + <widget class="QPushButton" name="pushHelp"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Fixed" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>25</width> + <height>25</height> + </size> + </property> + <property name="maximumSize"> + <size> + <width>25</width> + <height>25</height> + </size> + </property> + <property name="toolTip"> + <string><html><head/><body><p>Opens the help page for the interface.</p></body></html></string> + </property> + <property name="text"> + <string>?</string> + </property> + </widget> + </item> + <item> + <spacer name="sActionButtons"> + <property name="orientation"> + <enum>Qt::Horizontal</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>40</width> + <height>20</height> + </size> + </property> + </spacer> + </item> + <item> + <widget class="QPushButton" name="pushLaunchBackgroundRemover"> + <property name="toolTip"> + <string><html><head/><body><p>Launch the background removal tool.</p></body></html></string> + </property> + <property name="text"> + <string>Launch Background Remover</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> + </widget> + </widget> + <customwidgets> + <customwidget> + <class>MantidQt::MantidWidgets::DataSelector</class> + <extends>QWidget</extends> + <header>MantidQtMantidWidgets/DataSelector.h</header> + </customwidget> + <customwidget> + <class>MantidQt::MantidWidgets::PreviewPlot</class> + <extends>QWidget</extends> + <header>MantidQtMantidWidgets/PreviewPlot.h</header> + <container>1</container> + </customwidget> + </customwidgets> + <tabstops> + <tabstop>spinboxSliceSelector</tabstop> + <tabstop>pushLaunchBackgroundRemover</tabstop> + <tabstop>pushHelp</tabstop> + </tabstops> + <resources/> + <connections/> +</ui> diff --git a/MantidQt/CustomInterfaces/src/DynamicPDF/BackgroundRemover.cpp b/MantidQt/CustomInterfaces/src/DynamicPDF/BackgroundRemover.cpp new file mode 100644 index 0000000000000000000000000000000000000000..834ee05f1756785d4e06aa2d9326d81cfb160afb --- /dev/null +++ b/MantidQt/CustomInterfaces/src/DynamicPDF/BackgroundRemover.cpp @@ -0,0 +1,27 @@ +#include "MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.h" +#include "MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h" + +namespace +{ + Mantid::Kernel::Logger g_log("DynamicPDF"); +} + +namespace MantidQt +{ +namespace CustomInterfaces +{ +namespace DynamicPDF +{ + + BackgroundRemover::BackgroundRemover(SliceSelector *parent){ + m_uiForm.setupUi(this); + } + + void BackgroundRemover::refreshSlice(const boost::shared_ptr<WorkspaceRecord> loadedWorkspace, + const size_t &workspaceIndex){ + std::cout << "hello world"; + } + +} +} +} diff --git a/MantidQt/CustomInterfaces/src/DynamicPDF/SliceSelector.cpp b/MantidQt/CustomInterfaces/src/DynamicPDF/SliceSelector.cpp new file mode 100644 index 0000000000000000000000000000000000000000..22f7e772a649097c9f63c47572d0a082ce663157 --- /dev/null +++ b/MantidQt/CustomInterfaces/src/DynamicPDF/SliceSelector.cpp @@ -0,0 +1,109 @@ +#include <iostream> +#include <iomanip> +#include "MantidQtCustomInterfaces/DynamicPDF/SliceSelector.h" +#include "MantidQtCustomInterfaces/DynamicPDF/BackgroundRemover.h" + +#include "MantidQtAPI/HelpWindow.h" + +namespace +{ + Mantid::Kernel::Logger g_log("DynamicPDF"); +} + + +namespace MantidQt +{ +namespace CustomInterfaces +{ +namespace DynamicPDF +{ + + WorkspaceRecord::WorkspaceRecord(const std::string &workspaceName):name(workspaceName){ + ws = Mantid::API::AnalysisDataService::Instance().retrieveWS<Mantid::API::MatrixWorkspace>(workspaceName); + } + + void WorkspaceRecord::updateMetadata(const size_t &newIndex){ + energy = ws->getAxis(1)->getValue(newIndex); + std::stringstream stream = "Energy = " << std::fixed << std::setprecision(2) << energy << " meV"; + std::string label = stream.str(); + } + + //Add this class to the list of specialised dialogs in this namespace + DECLARE_SUBWINDOW(SliceSelector) + + ///Constructor + SliceSelector::SliceSelector(QWidget *parent) : UserSubWindow(parent), m_loadedWorkspace(NULL), m_BackgroundRemover(NULL) + { + } + + /// Initialize the ui form and connect SIGNALS to SLOTS + void SliceSelector::initLayout() + { + m_uiForm.setupUi(this); + connect(m_uiForm.dataSelector, SIGNAL(dataReady(const QString&)), + this, SLOT(loadedSlices(const QString&))); + connect(m_uiForm.pushHelp, SIGNAL(clicked()), this, SLOT(showHelp())); + connect(m_uiForm.spinboxSliceSelector, SIGNAL(valueChanged(int)), + this, SLOT(updateSelectedSlice(int))); + connect(m_uiForm.pushLaunchBackgroundRemover, SIGNAL(clicked()), + this, SLOT(launchBackgroundRemover())); + } + + /// + void SliceSelector::loadedSlices(const QString &workspaceName){ + m_loadedWorkspace = boost::make_shared<WorkspaceRecord>(workspaceName); + m_selectedWorkspaceIndex = 0; + m_loadedWorkspace->updateMetadata(m_selectedWorkspaceIndex); + size_t maximumWorkspaceIndex = m_loadedWorkspace->ws->getNumberHistograms() - 1; + + /// initialize the label displaying the energy + m_uiForm.labelSliceEnergy->setText(QString(m_loadedWorkspace->label)); + + /// initialize the spin box that selects the energy slice + m_uiForm.spinBoxSliceSelector->setMinimum(0); + m_uiForm.spinBoxSliceSelector->setMaximum(maximumWorkspaceIndex); + m_uiForm.spinBoxSliceSelector->setValue(m_selectedWorkspaceIndex); + + /// initialize the preview plot + updatePlotSelectedSlice(); + } + + /// + void SliceSelector::updatePlotSelectedSlice(){ + m_uiForm.previewPlotSelectedSlice->clear(); + m_uiForm.previewPlotSelectedSlice->addSpectrum(m_loadedWorkspace->label, + m_loadedWorkspace->ws, + m_selectedWorkspaceIndex); + } + + /// Update all widgets in the form with the new selected index + void SliceSelector::updateSelectedSlice(const int &newSelectedIndex){ + m_selectedWorkspaceIndex = newSelectedIndex; + m_loadedWorkspace->updateMetadata(m_selectedWorkspaceIndex); + m_uiForm.labelSliceEnergy->setText(m_loadedWorkspace->label); + updatePlotSelectedSlice(); + } + + /// Initialize and/or update the dialog to remove the multiphonon background + void SliceSelector::launchBackgroundRemover(){ + /// parent of BackgroundRemover is this main window + if (!m_BackgroundRemover){ + m_BackgroundRemover = boost::make_shared<BackgroundRemover>(this); + } + m_BackgroundRemover->refreshSlice(m_loadedWorkspace, m_selectedWorkspaceIndex); + } + + /// Qt-help page + void SliceSelector::showHelp() + { + MantidQt::API::HelpWindow::showCustomInterface(NULL, QString("Dynamic PDF Calculator")); + } + +} +} +} + + + + +