diff --git a/Framework/Algorithms/src/CalculateSlits.cpp b/Framework/Algorithms/src/CalculateSlits.cpp index e8905f9ca467aa9c4478ea566aa3b79598d9d604..1014251fc3ca599756530d3ee06c457b5dbdcef1 100644 --- a/Framework/Algorithms/src/CalculateSlits.cpp +++ b/Framework/Algorithms/src/CalculateSlits.cpp @@ -39,7 +39,7 @@ const std::string CalculateSlits::category() const { /// Algorithm's summary for use in the GUI and help. @see Algorithm::summary const std::string CalculateSlits::summary() const { return "Calculates appropriate slit widths for reflectometry instruments " - "based on the instrument setup and desired resolution and footprint of the experiment."; + "based on the instrument setup, desired resolution, and desired footprint of the experiment."; } //---------------------------------------------------------------------------------------------- diff --git a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h index 1306417ed5c84ffd9139390a259a08e08a250d6d..ab2f48dfa2db8daac520f43ab82517c3a5325e67 100644 --- a/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h +++ b/MantidQt/CustomInterfaces/inc/MantidQtCustomInterfaces/QtReflMainView.h @@ -12,136 +12,138 @@ #include <QSignalMapper> #include "ui_ReflMainWidget.h" -namespace MantidQt -{ - namespace CustomInterfaces - { - - /** QtReflMainView : Provides an interface for processing reflectometry data. - - Copyright © 2014 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - 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://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class DLLExport QtReflMainView : public MantidQt::API::UserSubWindow, public ReflMainView - { - Q_OBJECT - public: - QtReflMainView(QWidget *parent = 0); - virtual ~QtReflMainView(); - - /// Name of the interface - static std::string name() { return "ISIS Reflectometry (Polref)"; } - // This interface's categories. - static QString categoryInfo() { return "Reflectometry"; } - - //Connect the model - virtual void showTable(QReflTableModel_sptr model); - virtual void showSearch(ReflSearchModel_sptr model); - - //Dialog/Prompt methods - virtual std::string askUserString(const std::string& prompt, const std::string& title, const std::string& defaultValue); - virtual bool askUserYesNo(std::string prompt, std::string title); - virtual void giveUserInfo(std::string prompt, std::string title); - virtual void giveUserWarning(std::string prompt, std::string title); - virtual void giveUserCritical(std::string prompt, std::string title); - virtual void showAlgorithmDialog(const std::string& algorithm); - virtual std::string requestNotebookPath(); - - //Plotting - virtual void plotWorkspaces(const std::set<std::string>& workspaces); - - //Set the status of the progress bar - virtual void setProgressRange(int min, int max); - virtual void setProgress(int progress); - - //Get status of the checkbox which dictates whether an ipython notebook is produced - virtual bool getEnableNotebook(); - - //Settor methods - virtual void setSelection(const std::set<int>& rows); - virtual void setTableList(const std::set<std::string>& tables); - virtual void setInstrumentList(const std::vector<std::string>& instruments, const std::string& defaultInstrument); - virtual void setOptionsHintStrategy(MantidQt::MantidWidgets::HintStrategy* hintStrategy); - virtual void setClipboard(const std::string& text); - - //Accessor methods - virtual std::set<int> getSelectedRows() const; - virtual std::set<int> getSelectedSearchRows() const; - virtual std::string getSearchInstrument() const; - virtual std::string getProcessInstrument() const; - virtual std::string getWorkspaceToOpen() const; - virtual std::string getClipboard() const; - virtual std::string getSearchString() const; - - virtual boost::shared_ptr<IReflPresenter> getPresenter() const; - - private: - //initialise the interface - virtual void initLayout(); - //the presenter - boost::shared_ptr<IReflPresenter> m_presenter; - //the models - QReflTableModel_sptr m_model; - ReflSearchModel_sptr m_searchModel; - //the interface - Ui::reflMainWidget ui; - //the workspace the user selected to open - std::string m_toOpen; - QSignalMapper* m_openMap; - MantidWidgets::SlitCalculator* m_calculator; - - private slots: - void on_actionNewTable_triggered(); - void on_actionSaveTable_triggered(); - void on_actionSaveTableAs_triggered(); - void on_actionAppendRow_triggered(); - void on_actionPrependRow_triggered(); - void on_actionDeleteRow_triggered(); - void on_actionProcess_triggered(); - void on_actionGroupRows_triggered(); - void on_actionClearSelected_triggered(); - void on_actionCopySelected_triggered(); - void on_actionCutSelected_triggered(); - void on_actionPasteSelected_triggered(); - void on_actionExpandSelection_triggered(); - void on_actionOptionsDialog_triggered(); - void on_actionSearch_triggered(); - void on_actionTransfer_triggered(); - void on_actionImportTable_triggered(); - void on_actionExportTable_triggered(); - void on_actionHelp_triggered(); - void on_actionPlotRow_triggered(); - void on_actionPlotGroup_triggered(); - void on_actionSlitCalculator_triggered(); - - void on_comboSearchInstrument_currentIndexChanged(int index); - void on_comboProcessInstrument_currentIndexChanged(int index); - - void setModel(QString name); - void tableUpdated(const QModelIndex& topLeft, const QModelIndex& bottomRight); - void showContextMenu(const QPoint& pos); - void showSearchContextMenu(const QPoint& pos); - }; - - - } // namespace CustomInterfaces +namespace MantidQt { +namespace CustomInterfaces { + +/** QtReflMainView : Provides an interface for processing reflectometry data. + +Copyright © 2014 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +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://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class DLLExport QtReflMainView : public MantidQt::API::UserSubWindow, + public ReflMainView { + Q_OBJECT +public: + QtReflMainView(QWidget *parent = 0); + virtual ~QtReflMainView(); + + /// Name of the interface + static std::string name() { return "ISIS Reflectometry (Polref)"; } + // This interface's categories. + static QString categoryInfo() { return "Reflectometry"; } + + // Connect the model + virtual void showTable(QReflTableModel_sptr model); + virtual void showSearch(ReflSearchModel_sptr model); + + // Dialog/Prompt methods + virtual std::string askUserString(const std::string &prompt, + const std::string &title, + const std::string &defaultValue); + virtual bool askUserYesNo(std::string prompt, std::string title); + virtual void giveUserInfo(std::string prompt, std::string title); + virtual void giveUserWarning(std::string prompt, std::string title); + virtual void giveUserCritical(std::string prompt, std::string title); + virtual void showAlgorithmDialog(const std::string &algorithm); + virtual std::string requestNotebookPath(); + + // Plotting + virtual void plotWorkspaces(const std::set<std::string> &workspaces); + + // Set the status of the progress bar + virtual void setProgressRange(int min, int max); + virtual void setProgress(int progress); + + // Get status of the checkbox which dictates whether an ipython notebook is + // produced + virtual bool getEnableNotebook(); + + // Settor methods + virtual void setSelection(const std::set<int> &rows); + virtual void setTableList(const std::set<std::string> &tables); + virtual void setInstrumentList(const std::vector<std::string> &instruments, + const std::string &defaultInstrument); + virtual void + setOptionsHintStrategy(MantidQt::MantidWidgets::HintStrategy *hintStrategy); + virtual void setClipboard(const std::string &text); + + // Accessor methods + virtual std::set<int> getSelectedRows() const; + virtual std::set<int> getSelectedSearchRows() const; + virtual std::string getSearchInstrument() const; + virtual std::string getProcessInstrument() const; + virtual std::string getWorkspaceToOpen() const; + virtual std::string getClipboard() const; + virtual std::string getSearchString() const; + + virtual boost::shared_ptr<IReflPresenter> getPresenter() const; +private: + // initialise the interface + virtual void initLayout(); + // the presenter + boost::shared_ptr<IReflPresenter> m_presenter; + // the models + QReflTableModel_sptr m_model; + ReflSearchModel_sptr m_searchModel; + // the interface + Ui::reflMainWidget ui; + // the workspace the user selected to open + std::string m_toOpen; + QSignalMapper *m_openMap; + MantidWidgets::SlitCalculator *m_calculator; + +private slots: + void on_actionNewTable_triggered(); + void on_actionSaveTable_triggered(); + void on_actionSaveTableAs_triggered(); + void on_actionAppendRow_triggered(); + void on_actionPrependRow_triggered(); + void on_actionDeleteRow_triggered(); + void on_actionProcess_triggered(); + void on_actionGroupRows_triggered(); + void on_actionClearSelected_triggered(); + void on_actionCopySelected_triggered(); + void on_actionCutSelected_triggered(); + void on_actionPasteSelected_triggered(); + void on_actionExpandSelection_triggered(); + void on_actionOptionsDialog_triggered(); + void on_actionSearch_triggered(); + void on_actionTransfer_triggered(); + void on_actionImportTable_triggered(); + void on_actionExportTable_triggered(); + void on_actionHelp_triggered(); + void on_actionPlotRow_triggered(); + void on_actionPlotGroup_triggered(); + void on_actionSlitCalculator_triggered(); + + void on_comboSearchInstrument_currentIndexChanged(int index); + void on_comboProcessInstrument_currentIndexChanged(int index); + + void setModel(QString name); + void tableUpdated(const QModelIndex &topLeft, const QModelIndex &bottomRight); + void showContextMenu(const QPoint &pos); + void showSearchContextMenu(const QPoint &pos); +}; + +} // namespace CustomInterfaces } // namespace Mantid -#endif /* MANTID_CUSTOMINTERFACES_QTREFLMAINVIEW_H_ */ +#endif /* MANTID_CUSTOMINTERFACES_QTREFLMAINVIEW_H_ */ diff --git a/MantidQt/CustomInterfaces/src/QtReflMainView.cpp b/MantidQt/CustomInterfaces/src/QtReflMainView.cpp index 6f599771e4f4ffc5b63452900b01485518c834b5..f3632eaf125e82c4d98e20af56f2a998ad70bcea 100644 --- a/MantidQt/CustomInterfaces/src/QtReflMainView.cpp +++ b/MantidQt/CustomInterfaces/src/QtReflMainView.cpp @@ -262,12 +262,16 @@ namespace MantidQt void QtReflMainView::on_comboProcessInstrument_currentIndexChanged(int index) { ui.comboSearchInstrument->setCurrentIndex(index); + m_calculator->setCurrentInstrumentName(ui.comboProcessInstrument->currentText().toStdString()); + m_calculator->emitInstrumentChangedSignal(); } /** This slot is used to syncrhonise the two instrument selection widgets */ void QtReflMainView::on_comboSearchInstrument_currentIndexChanged(int index) { ui.comboProcessInstrument->setCurrentIndex(index); + m_calculator->setCurrentInstrumentName(ui.comboProcessInstrument->currentText().toStdString()); + m_calculator->emitInstrumentChangedSignal(); } /** @@ -299,6 +303,7 @@ namespace MantidQt */ void QtReflMainView::on_actionSlitCalculator_triggered() { + m_calculator->setCurrentInstrumentName(ui.comboProcessInstrument->currentText().toStdString()); m_calculator->show(); } diff --git a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlitCalculator.h b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlitCalculator.h index 199550efb76f7309a1956f1c946d82bbbd561e29..f88271b88c5cc957ba55b5add0fc6073772d8bf0 100644 --- a/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlitCalculator.h +++ b/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlitCalculator.h @@ -4,49 +4,62 @@ //---------------------------------- // Includes //---------------------------------- +#include "MantidAPI/InstrumentDataService.h" + #include "WidgetDllOption.h" #include "ui_SlitCalculator.h" - #include <QDialog> -namespace MantidQt -{ - namespace MantidWidgets - { - /** SlitCalculator : A calculator for Reflectometry instrument slits - - Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source - - 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://github.com/mantidproject/mantid> - Code Documentation is available at: <http://doxygen.mantidproject.org> - */ - class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SlitCalculator : public QDialog - { - Q_OBJECT - public: - SlitCalculator(QWidget* parent); - virtual ~SlitCalculator(); - protected: - Ui::SlitCalculator ui; - private slots: - void on_recalculate_triggered(); - }; - } +namespace MantidQt { +namespace MantidWidgets { +/** SlitCalculator : A calculator for Reflectometry instrument slits + +Copyright © 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge +National Laboratory & European Spallation Source + +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://github.com/mantidproject/mantid> +Code Documentation is available at: <http://doxygen.mantidproject.org> +*/ +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SlitCalculator : public QDialog { + Q_OBJECT +public: + SlitCalculator(QWidget *parent); + virtual ~SlitCalculator(); + void setInstrument(std::string instrumentName); + Mantid::Geometry::Instrument_sptr getInstrument(); + void setCurrentInstrumentName(std::string instrumentName); + std::string getCurrentInstrumentName(); + void emitInstrumentChangedSignal(); + +protected: + Ui::SlitCalculator ui; + +private: + Mantid::Geometry::Instrument_sptr instrument; + std::string currentInstrumentName; + void setupSlitCalculatorWithInstrumentValues( + Mantid::Geometry::Instrument_const_sptr); +signals: + void instrumentChanged(); +private slots: + void on_recalculate_triggered(); +}; +} } #endif /* MANTID_MANTIDWIDGETS_SLITCALCULATOR_H */ diff --git a/MantidQt/MantidWidgets/src/SlitCalculator.cpp b/MantidQt/MantidWidgets/src/SlitCalculator.cpp index 08255d1a7e14fbf4cb8e17e50e13a3c4ff2ce317..7a456a5ec653b37ba6886ab59128920a81182a6d 100644 --- a/MantidQt/MantidWidgets/src/SlitCalculator.cpp +++ b/MantidQt/MantidWidgets/src/SlitCalculator.cpp @@ -1,48 +1,106 @@ #include "MantidQtMantidWidgets/SlitCalculator.h" #include "MantidAPI/AlgorithmManager.h" -#include <math.h> +#include "MantidAPI/Progress.h" +#include "MantidGeometry/Instrument/InstrumentDefinitionParser.h" + -namespace MantidQt -{ - namespace MantidWidgets - { - SlitCalculator::SlitCalculator(QWidget *parent) - { - Q_UNUSED(parent); - ui.setupUi(this); - on_recalculate_triggered(); - } +#include <math.h> - SlitCalculator::~SlitCalculator() - { - } +namespace MantidQt { +namespace MantidWidgets { +SlitCalculator::SlitCalculator(QWidget *parent) { + Q_UNUSED(parent); + ui.setupUi(this); + if (currentInstrumentName == ""){ + currentInstrumentName = "INTER"; + setInstrument(currentInstrumentName); + } + on_recalculate_triggered(); +} +void SlitCalculator::emitInstrumentChangedSignal(){ + on_recalculate_triggered(); +} +SlitCalculator::~SlitCalculator() {} +void SlitCalculator::setInstrument(std::string instrumentName) { + // we want to get the most up-to-date definition, so we use the current + // date/time + auto date = Mantid::Kernel::DateAndTime::getCurrentTime().toISO8601String(); + // find the full path to the definition file + auto filename = + Mantid::API::ExperimentInfo::getInstrumentFilename(instrumentName, date); + // parse the XML that we have found for the definition + Mantid::Geometry::InstrumentDefinitionParser parser = + Mantid::Geometry::InstrumentDefinitionParser( + filename, instrumentName, + Mantid::Kernel::Strings::loadFile(filename)); + // retrieving the mangled name of the instrument + std::string instrumentNameMangled = parser.getMangledName(); + // See if we have a definition already in the InstrumentDataService + if (Mantid::API::InstrumentDataService::Instance().doesExist( + instrumentNameMangled)) { + // If it does, set the associated instrument to the one we have found. + this->instrument = Mantid::API::InstrumentDataService::Instance().retrieve( + instrumentNameMangled); + } else { + // We set the XML that we have found for the instrument. + Mantid::API::Progress *prog = new Mantid::API::Progress(); + this->instrument = parser.parseXML(prog); + delete prog; + } + setupSlitCalculatorWithInstrumentValues(instrument); +} - void SlitCalculator::on_recalculate_triggered() - { - //Gather input - const double s1s2 = ui.spinSlit1Slit2->value(); - const double s2sa = ui.spinSlit2Sample->value(); - const double res = ui.spinResolution->value(); - const double footprint = ui.spinFootprint->value(); - const double angle = ui.spinAngle->value(); +void SlitCalculator::setupSlitCalculatorWithInstrumentValues( + Mantid::Geometry::Instrument_const_sptr instrument) { + auto slit1Component = instrument->getComponentByName("slit1"); + auto slit2Component = instrument->getComponentByName("slit2"); + auto sampleComponent = instrument->getComponentByName("some-surface-holder"); + // convert between metres and millimetres + const double s1s2 = 1e3 * slit1Component->getDistance(*slit2Component); + ui.spinSlit1Slit2->setValue(s1s2); + const double s2sa = 1e3 * slit2Component->getDistance(*sampleComponent); + ui.spinSlit2Sample->setValue(s2sa); + +} +Mantid::Geometry::Instrument_sptr SlitCalculator::getInstrument() { + return this->instrument; +} +void SlitCalculator::setCurrentInstrumentName(std::string instrumentName){ + this->currentInstrumentName = instrumentName; +} +std::string SlitCalculator::getCurrentInstrumentName(){ + return this->currentInstrumentName; +} +void SlitCalculator::on_recalculate_triggered() { + const auto currentInstrument = getInstrument(); + if (currentInstrument->getName() != currentInstrumentName){ + setInstrument(currentInstrumentName); + } + // Gather input + const double s1s2 = ui.spinSlit1Slit2->value(); + const double s2sa = ui.spinSlit2Sample->value(); + const double res = ui.spinResolution->value(); + const double footprint = ui.spinFootprint->value(); + const double angle = ui.spinAngle->value(); - //Calculate values - Mantid::API::IAlgorithm_sptr algSlit = Mantid::API::AlgorithmManager::Instance().create("CalculateSlits"); - algSlit->initialize(); - algSlit->setChild(true); - algSlit->setProperty("Slit1Slit2", s1s2); - algSlit->setProperty("Slit2SA", s2sa); - algSlit->setProperty("Resolution", res); - algSlit->setProperty("Footprint", footprint); - algSlit->setProperty("Angle", angle); - algSlit->execute(); + // Calculate values + Mantid::API::IAlgorithm_sptr algSlit = + Mantid::API::AlgorithmManager::Instance().create("CalculateSlits"); + algSlit->initialize(); + algSlit->setChild(true); + algSlit->setProperty("Slit1Slit2", s1s2); + algSlit->setProperty("Slit2SA", s2sa); + algSlit->setProperty("Resolution", res); + algSlit->setProperty("Footprint", footprint); + algSlit->setProperty("Angle", angle); + algSlit->execute(); - const double s1 = algSlit->getProperty("Slit1"); - const double s2 = algSlit->getProperty("Slit2"); + const double s1 = algSlit->getProperty("Slit1"); + const double s2 = algSlit->getProperty("Slit2"); - //Update output - ui.slit1Text->setText(QString::number(s1,'f',3)); - ui.slit2Text->setText(QString::number(s2,'f',3)); - } - } + // Update output + ui.slit1Text->setText(QString::number(s1, 'f', 3)); + ui.slit2Text->setText(QString::number(s2, 'f', 3)); +} +} }