Skip to content
Snippets Groups Projects
Commit e1547b11 authored by Matt King's avatar Matt King
Browse files

Grabbing some values from IDF

Still need to make it work when the instrument is changed
and slitCalculator is still open

Refs #13758
parent d7d1530e
No related branches found
No related tags found
No related merge requests found
...@@ -39,7 +39,7 @@ const std::string CalculateSlits::category() const { ...@@ -39,7 +39,7 @@ const std::string CalculateSlits::category() const {
/// Algorithm's summary for use in the GUI and help. @see Algorithm::summary /// Algorithm's summary for use in the GUI and help. @see Algorithm::summary
const std::string CalculateSlits::summary() const { const std::string CalculateSlits::summary() const {
return "Calculates appropriate slit widths for reflectometry instruments " 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.";
} }
//---------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------
......
...@@ -12,136 +12,138 @@ ...@@ -12,136 +12,138 @@
#include <QSignalMapper> #include <QSignalMapper>
#include "ui_ReflMainWidget.h" #include "ui_ReflMainWidget.h"
namespace MantidQt namespace MantidQt {
{ namespace CustomInterfaces {
namespace CustomInterfaces
{ /** QtReflMainView : Provides an interface for processing reflectometry data.
/** QtReflMainView : Provides an interface for processing reflectometry data. Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Copyright &copy; 2014 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
Mantid is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or
the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
Mantid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org>
Code Documentation is available at: <http://doxygen.mantidproject.org> */
*/ class DLLExport QtReflMainView : public MantidQt::API::UserSubWindow,
class DLLExport QtReflMainView : public MantidQt::API::UserSubWindow, public ReflMainView public ReflMainView {
{ Q_OBJECT
Q_OBJECT public:
public: QtReflMainView(QWidget *parent = 0);
QtReflMainView(QWidget *parent = 0); virtual ~QtReflMainView();
virtual ~QtReflMainView();
/// Name of the interface
/// Name of the interface static std::string name() { return "ISIS Reflectometry (Polref)"; }
static std::string name() { return "ISIS Reflectometry (Polref)"; } // This interface's categories.
// This interface's categories. static QString categoryInfo() { return "Reflectometry"; }
static QString categoryInfo() { return "Reflectometry"; }
// Connect the model
//Connect the model virtual void showTable(QReflTableModel_sptr model);
virtual void showTable(QReflTableModel_sptr model); virtual void showSearch(ReflSearchModel_sptr model);
virtual void showSearch(ReflSearchModel_sptr model);
// Dialog/Prompt methods
//Dialog/Prompt methods virtual std::string askUserString(const std::string &prompt,
virtual std::string askUserString(const std::string& prompt, const std::string& title, const std::string& defaultValue); const std::string &title,
virtual bool askUserYesNo(std::string prompt, std::string title); const std::string &defaultValue);
virtual void giveUserInfo(std::string prompt, std::string title); virtual bool askUserYesNo(std::string prompt, std::string title);
virtual void giveUserWarning(std::string prompt, std::string title); virtual void giveUserInfo(std::string prompt, std::string title);
virtual void giveUserCritical(std::string prompt, std::string title); virtual void giveUserWarning(std::string prompt, std::string title);
virtual void showAlgorithmDialog(const std::string& algorithm); virtual void giveUserCritical(std::string prompt, std::string title);
virtual std::string requestNotebookPath(); virtual void showAlgorithmDialog(const std::string &algorithm);
virtual std::string requestNotebookPath();
//Plotting
virtual void plotWorkspaces(const std::set<std::string>& workspaces); // Plotting
virtual void plotWorkspaces(const std::set<std::string> &workspaces);
//Set the status of the progress bar
virtual void setProgressRange(int min, int max); // Set the status of the progress bar
virtual void setProgress(int progress); 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(); // Get status of the checkbox which dictates whether an ipython notebook is
// produced
//Settor methods virtual bool getEnableNotebook();
virtual void setSelection(const std::set<int>& rows);
virtual void setTableList(const std::set<std::string>& tables); // Settor methods
virtual void setInstrumentList(const std::vector<std::string>& instruments, const std::string& defaultInstrument); virtual void setSelection(const std::set<int> &rows);
virtual void setOptionsHintStrategy(MantidQt::MantidWidgets::HintStrategy* hintStrategy); virtual void setTableList(const std::set<std::string> &tables);
virtual void setClipboard(const std::string& text); virtual void setInstrumentList(const std::vector<std::string> &instruments,
const std::string &defaultInstrument);
//Accessor methods virtual void
virtual std::set<int> getSelectedRows() const; setOptionsHintStrategy(MantidQt::MantidWidgets::HintStrategy *hintStrategy);
virtual std::set<int> getSelectedSearchRows() const; virtual void setClipboard(const std::string &text);
virtual std::string getSearchInstrument() const;
virtual std::string getProcessInstrument() const; // Accessor methods
virtual std::string getWorkspaceToOpen() const; virtual std::set<int> getSelectedRows() const;
virtual std::string getClipboard() const; virtual std::set<int> getSelectedSearchRows() const;
virtual std::string getSearchString() const; virtual std::string getSearchInstrument() const;
virtual std::string getProcessInstrument() const;
virtual boost::shared_ptr<IReflPresenter> getPresenter() const; virtual std::string getWorkspaceToOpen() const;
virtual std::string getClipboard() const;
private: virtual std::string getSearchString() const;
//initialise the interface
virtual void initLayout(); virtual boost::shared_ptr<IReflPresenter> getPresenter() const;
//the presenter private:
boost::shared_ptr<IReflPresenter> m_presenter; // initialise the interface
//the models virtual void initLayout();
QReflTableModel_sptr m_model; // the presenter
ReflSearchModel_sptr m_searchModel; boost::shared_ptr<IReflPresenter> m_presenter;
//the interface // the models
Ui::reflMainWidget ui; QReflTableModel_sptr m_model;
//the workspace the user selected to open ReflSearchModel_sptr m_searchModel;
std::string m_toOpen; // the interface
QSignalMapper* m_openMap; Ui::reflMainWidget ui;
MantidWidgets::SlitCalculator* m_calculator; // the workspace the user selected to open
std::string m_toOpen;
private slots: QSignalMapper *m_openMap;
void on_actionNewTable_triggered(); MantidWidgets::SlitCalculator *m_calculator;
void on_actionSaveTable_triggered();
void on_actionSaveTableAs_triggered(); private slots:
void on_actionAppendRow_triggered(); void on_actionNewTable_triggered();
void on_actionPrependRow_triggered(); void on_actionSaveTable_triggered();
void on_actionDeleteRow_triggered(); void on_actionSaveTableAs_triggered();
void on_actionProcess_triggered(); void on_actionAppendRow_triggered();
void on_actionGroupRows_triggered(); void on_actionPrependRow_triggered();
void on_actionClearSelected_triggered(); void on_actionDeleteRow_triggered();
void on_actionCopySelected_triggered(); void on_actionProcess_triggered();
void on_actionCutSelected_triggered(); void on_actionGroupRows_triggered();
void on_actionPasteSelected_triggered(); void on_actionClearSelected_triggered();
void on_actionExpandSelection_triggered(); void on_actionCopySelected_triggered();
void on_actionOptionsDialog_triggered(); void on_actionCutSelected_triggered();
void on_actionSearch_triggered(); void on_actionPasteSelected_triggered();
void on_actionTransfer_triggered(); void on_actionExpandSelection_triggered();
void on_actionImportTable_triggered(); void on_actionOptionsDialog_triggered();
void on_actionExportTable_triggered(); void on_actionSearch_triggered();
void on_actionHelp_triggered(); void on_actionTransfer_triggered();
void on_actionPlotRow_triggered(); void on_actionImportTable_triggered();
void on_actionPlotGroup_triggered(); void on_actionExportTable_triggered();
void on_actionSlitCalculator_triggered(); void on_actionHelp_triggered();
void on_actionPlotRow_triggered();
void on_comboSearchInstrument_currentIndexChanged(int index); void on_actionPlotGroup_triggered();
void on_comboProcessInstrument_currentIndexChanged(int index); void on_actionSlitCalculator_triggered();
void setModel(QString name); void on_comboSearchInstrument_currentIndexChanged(int index);
void tableUpdated(const QModelIndex& topLeft, const QModelIndex& bottomRight); void on_comboProcessInstrument_currentIndexChanged(int index);
void showContextMenu(const QPoint& pos);
void showSearchContextMenu(const QPoint& pos); 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 CustomInterfaces
} // namespace Mantid } // namespace Mantid
#endif /* MANTID_CUSTOMINTERFACES_QTREFLMAINVIEW_H_ */ #endif /* MANTID_CUSTOMINTERFACES_QTREFLMAINVIEW_H_ */
...@@ -262,12 +262,16 @@ namespace MantidQt ...@@ -262,12 +262,16 @@ namespace MantidQt
void QtReflMainView::on_comboProcessInstrument_currentIndexChanged(int index) void QtReflMainView::on_comboProcessInstrument_currentIndexChanged(int index)
{ {
ui.comboSearchInstrument->setCurrentIndex(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 */ /** This slot is used to syncrhonise the two instrument selection widgets */
void QtReflMainView::on_comboSearchInstrument_currentIndexChanged(int index) void QtReflMainView::on_comboSearchInstrument_currentIndexChanged(int index)
{ {
ui.comboProcessInstrument->setCurrentIndex(index); ui.comboProcessInstrument->setCurrentIndex(index);
m_calculator->setCurrentInstrumentName(ui.comboProcessInstrument->currentText().toStdString());
m_calculator->emitInstrumentChangedSignal();
} }
/** /**
...@@ -299,6 +303,7 @@ namespace MantidQt ...@@ -299,6 +303,7 @@ namespace MantidQt
*/ */
void QtReflMainView::on_actionSlitCalculator_triggered() void QtReflMainView::on_actionSlitCalculator_triggered()
{ {
m_calculator->setCurrentInstrumentName(ui.comboProcessInstrument->currentText().toStdString());
m_calculator->show(); m_calculator->show();
} }
......
...@@ -4,49 +4,62 @@ ...@@ -4,49 +4,62 @@
//---------------------------------- //----------------------------------
// Includes // Includes
//---------------------------------- //----------------------------------
#include "MantidAPI/InstrumentDataService.h"
#include "WidgetDllOption.h" #include "WidgetDllOption.h"
#include "ui_SlitCalculator.h" #include "ui_SlitCalculator.h"
#include <QDialog> #include <QDialog>
namespace MantidQt namespace MantidQt {
{ namespace MantidWidgets {
namespace MantidWidgets /** SlitCalculator : A calculator for Reflectometry instrument slits
{
/** SlitCalculator : A calculator for Reflectometry instrument slits Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge
National Laboratory & European Spallation Source
Copyright &copy; 2015 ISIS Rutherford Appleton Laboratory, NScD Oak Ridge National Laboratory & European Spallation Source
This file is part of Mantid.
This file is part of Mantid.
Mantid is free software; you can redistribute it and/or modify
Mantid is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or
the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
(at your option) any later version.
Mantid is distributed in the hope that it will be useful,
Mantid is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
along with this program. If not, see <http://www.gnu.org/licenses/>.
File change history is stored at: <https://github.com/mantidproject/mantid>
File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org>
Code Documentation is available at: <http://doxygen.mantidproject.org> */
*/ class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SlitCalculator : public QDialog {
class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SlitCalculator : public QDialog Q_OBJECT
{ public:
Q_OBJECT SlitCalculator(QWidget *parent);
public: virtual ~SlitCalculator();
SlitCalculator(QWidget* parent); void setInstrument(std::string instrumentName);
virtual ~SlitCalculator(); Mantid::Geometry::Instrument_sptr getInstrument();
protected: void setCurrentInstrumentName(std::string instrumentName);
Ui::SlitCalculator ui; std::string getCurrentInstrumentName();
private slots: void emitInstrumentChangedSignal();
void on_recalculate_triggered();
}; 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 */ #endif /* MANTID_MANTIDWIDGETS_SLITCALCULATOR_H */
#include "MantidQtMantidWidgets/SlitCalculator.h" #include "MantidQtMantidWidgets/SlitCalculator.h"
#include "MantidAPI/AlgorithmManager.h" #include "MantidAPI/AlgorithmManager.h"
#include <math.h> #include "MantidAPI/Progress.h"
#include "MantidGeometry/Instrument/InstrumentDefinitionParser.h"
namespace MantidQt #include <math.h>
{
namespace MantidWidgets
{
SlitCalculator::SlitCalculator(QWidget *parent)
{
Q_UNUSED(parent);
ui.setupUi(this);
on_recalculate_triggered();
}
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() void SlitCalculator::setupSlitCalculatorWithInstrumentValues(
{ Mantid::Geometry::Instrument_const_sptr instrument) {
//Gather input auto slit1Component = instrument->getComponentByName("slit1");
const double s1s2 = ui.spinSlit1Slit2->value(); auto slit2Component = instrument->getComponentByName("slit2");
const double s2sa = ui.spinSlit2Sample->value(); auto sampleComponent = instrument->getComponentByName("some-surface-holder");
const double res = ui.spinResolution->value(); // convert between metres and millimetres
const double footprint = ui.spinFootprint->value(); const double s1s2 = 1e3 * slit1Component->getDistance(*slit2Component);
const double angle = ui.spinAngle->value(); 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 // Calculate values
Mantid::API::IAlgorithm_sptr algSlit = Mantid::API::AlgorithmManager::Instance().create("CalculateSlits"); Mantid::API::IAlgorithm_sptr algSlit =
algSlit->initialize(); Mantid::API::AlgorithmManager::Instance().create("CalculateSlits");
algSlit->setChild(true); algSlit->initialize();
algSlit->setProperty("Slit1Slit2", s1s2); algSlit->setChild(true);
algSlit->setProperty("Slit2SA", s2sa); algSlit->setProperty("Slit1Slit2", s1s2);
algSlit->setProperty("Resolution", res); algSlit->setProperty("Slit2SA", s2sa);
algSlit->setProperty("Footprint", footprint); algSlit->setProperty("Resolution", res);
algSlit->setProperty("Angle", angle); algSlit->setProperty("Footprint", footprint);
algSlit->execute(); algSlit->setProperty("Angle", angle);
algSlit->execute();
const double s1 = algSlit->getProperty("Slit1"); const double s1 = algSlit->getProperty("Slit1");
const double s2 = algSlit->getProperty("Slit2"); const double s2 = algSlit->getProperty("Slit2");
//Update output // Update output
ui.slit1Text->setText(QString::number(s1,'f',3)); ui.slit1Text->setText(QString::number(s1, 'f', 3));
ui.slit2Text->setText(QString::number(s2,'f',3)); ui.slit2Text->setText(QString::number(s2, 'f', 3));
} }
} }
} }
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