diff --git a/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt b/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt index b27d919b32bdcad0d04392026abaf1bb34b758a6..cd1fcd58f96e929ac67bde4fd9983e7fd744cf1e 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt +++ b/Code/Mantid/MantidQt/CustomDialogs/CMakeLists.txt @@ -12,7 +12,6 @@ set ( SRC_FILES src/CatalogPublishDialog.cpp src/MantidGLWidget.cpp src/PlotAsymmetryByLogValueDialog.cpp src/SampleShapeHelpers.cpp - src/SlicingAlgorithmDialog.cpp src/SmoothNeighboursDialog.cpp src/SortTableWorkspaceDialog.cpp ) @@ -34,7 +33,6 @@ set ( MOC_FILES inc/MantidQtCustomDialogs/CatalogPublishDialog.h inc/MantidQtCustomDialogs/MantidGLWidget.h inc/MantidQtCustomDialogs/PlotAsymmetryByLogValueDialog.h inc/MantidQtCustomDialogs/SampleShapeHelpers.h - inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.h inc/MantidQtCustomDialogs/SmoothNeighboursDialog.h inc/MantidQtCustomDialogs/SortTableWorkspaceDialog.h ) @@ -53,7 +51,6 @@ set ( UI_FILES inc/MantidQtCustomDialogs/CatalogPublishDialog.ui inc/MantidQtCustomDialogs/LoadDialog.ui inc/MantidQtCustomDialogs/LoadInstrumentDialog.ui inc/MantidQtCustomDialogs/StartLiveDataDialog.ui - inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.ui inc/MantidQtCustomDialogs/FitDialog.ui inc/MantidQtCustomDialogs/SortTableWorkspaceDialog.ui ) diff --git a/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt b/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt index d81e332cfdc21f380f59996da1427b0b5a751d01..b3864b458e3028fca302228e90ffd453a4f85f8d 100644 --- a/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt +++ b/Code/Mantid/MantidQt/MantidWidgets/CMakeLists.txt @@ -14,7 +14,7 @@ set ( SRC_FILES src/FunctionBrowser.cpp src/HintingLineEdit.cpp src/InstrumentSelector.cpp - src/MantidHelpWindow.cpp + src/MantidHelpWindow.cpp src/MWDiag.cpp src/MWRunFiles.cpp src/MessageDisplay.cpp @@ -32,6 +32,7 @@ set ( SRC_FILES src/SelectFunctionDialog.cpp src/SelectWorkspacesDialog.cpp src/SequentialFitDialog.cpp + src/SlicingAlgorithmDialog.cpp src/StringDialogEditor.cpp src/StringEditorFactory.cpp src/UserFunctionDialog.cpp @@ -78,6 +79,7 @@ set ( MOC_FILES inc/MantidQtMantidWidgets/SelectFunctionDialog.h inc/MantidQtMantidWidgets/SelectWorkspacesDialog.h inc/MantidQtMantidWidgets/SequentialFitDialog.h + inc/MantidQtMantidWidgets/SlicingAlgorithmDialog.h inc/MantidQtMantidWidgets/StringDialogEditor.h inc/MantidQtMantidWidgets/StringEditorFactory.h inc/MantidQtMantidWidgets/UserFunctionDialog.h @@ -108,6 +110,7 @@ set ( UI_FILES inc/MantidQtMantidWidgets/RenameParDialog.ui inc/MantidQtMantidWidgets/SelectFunctionDialog.ui inc/MantidQtMantidWidgets/SequentialFitDialog.ui + inc/MantidQtMantidWidgets/SlicingAlgorithmDialog.ui inc/MantidQtMantidWidgets/UserFunctionDialog.ui inc/MantidQtMantidWidgets/pqHelpWindow.ui ) @@ -125,7 +128,6 @@ find_package (Qt4 REQUIRED QtHelp QtWebKit QtNetwork QUIET) include(${QT_USE_FILE}) include_directories ( ../../QtPropertyBrowser/src ) - qt4_wrap_cpp ( MOCCED_FILES ${MOC_FILES} ) set ( ALL_SRC ${SRC_FILES} ${MOCCED_FILES} ) diff --git a/Code/Mantid/MantidQt/CustomDialogs/inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.h b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlicingAlgorithmDialog.h similarity index 87% rename from Code/Mantid/MantidQt/CustomDialogs/inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.h rename to Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlicingAlgorithmDialog.h index cbf45bd91840f22387adb4f1cdb5e5390584b58c..e7b1ee3f8214728a4420c6a74f46ee183725def8 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.h +++ b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlicingAlgorithmDialog.h @@ -8,10 +8,11 @@ #include "MantidQtAPI/AlgorithmDialog.h" #include "MantidAPI/IAlgorithm.h" #include "MantidAPI/Algorithm.h" +#include "WidgetDllOption.h" namespace MantidQt { -namespace CustomDialogs +namespace MantidWidgets { typedef QMap<QString, QString> PropertyDimensionMap; @@ -26,7 +27,7 @@ This custom dialog provides two advantages over the default custom generated one 2) It pre-populates those dimension input controls based on existing values. */ -class SlicingAlgorithmDialog : public MantidQt::API::AlgorithmDialog +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SlicingAlgorithmDialog : public MantidQt::API::AlgorithmDialog { Q_OBJECT public: @@ -45,6 +46,9 @@ protected: /// Common slice md setup void commonSliceMDSetup(const bool); + /// Build dimension inputs. + void buildDimensionInputs(const bool bForceForget=false); + protected slots: void onWorkspaceChanged(); @@ -80,9 +84,6 @@ private: /// Gets the output workspace name provided QString getCurrentOutputWorkspaceName() const; - /// Build dimension inputs. - void buildDimensionInputs(const bool bForceForget=false); - /// Build dimension inputs. void makeDimensionInputs(const QString& propertyPrefix, QLayout* owningLayout, QString(*format)(Mantid::Geometry::IMDDimension_const_sptr), History history); @@ -116,13 +117,14 @@ private: Class SliceMDDialog Concrete SlicingAlgorithm Dialog geared for SliceMD */ -class SliceMDDialog : public SlicingAlgorithmDialog +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS SliceMDDialog : public SlicingAlgorithmDialog { Q_OBJECT public: SliceMDDialog(QWidget* parent=NULL) : SlicingAlgorithmDialog(parent) { } + ~SliceMDDialog(){} void customiseInitLayout(); @@ -132,7 +134,7 @@ public: Class BinMDDialog Concrete BinMDDialog Dialog geared for BinMD */ -class BinMDDialog : public SlicingAlgorithmDialog +class EXPORT_OPT_MANTIDQT_MANTIDWIDGETS BinMDDialog : public SlicingAlgorithmDialog { Q_OBJECT public: @@ -141,6 +143,10 @@ public: } ~BinMDDialog(){} void customiseInitLayout(); + + void customiseLayoutForVsi(std::string inputWorkspace); + + void resestAlignedDimProperty(size_t index, QString propertyValue); }; } diff --git a/Code/Mantid/MantidQt/CustomDialogs/inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.ui b/Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlicingAlgorithmDialog.ui similarity index 100% rename from Code/Mantid/MantidQt/CustomDialogs/inc/MantidQtCustomDialogs/SlicingAlgorithmDialog.ui rename to Code/Mantid/MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/SlicingAlgorithmDialog.ui diff --git a/Code/Mantid/MantidQt/CustomDialogs/src/SlicingAlgorithmDialog.cpp b/Code/Mantid/MantidQt/MantidWidgets/src/SlicingAlgorithmDialog.cpp similarity index 91% rename from Code/Mantid/MantidQt/CustomDialogs/src/SlicingAlgorithmDialog.cpp rename to Code/Mantid/MantidQt/MantidWidgets/src/SlicingAlgorithmDialog.cpp index e36a785d03a416d8915ceb12208f0add442ba659..b321e9c7499567c6b0b75eaa7b5a38d338180e50 100644 --- a/Code/Mantid/MantidQt/CustomDialogs/src/SlicingAlgorithmDialog.cpp +++ b/Code/Mantid/MantidQt/MantidWidgets/src/SlicingAlgorithmDialog.cpp @@ -1,4 +1,4 @@ -#include "MantidQtCustomDialogs/SlicingAlgorithmDialog.h" +#include "MantidQtMantidWidgets/SlicingAlgorithmDialog.h" #include "MantidAPI/AnalysisDataService.h" #include "MantidAPI/IMDEventWorkspace.h" #include "MantidAPI/AlgorithmManager.h" @@ -14,7 +14,7 @@ using namespace Mantid::Geometry; namespace MantidQt { - namespace CustomDialogs + namespace MantidWidgets { DECLARE_DIALOG(SliceMDDialog); DECLARE_DIALOG(BinMDDialog); @@ -448,6 +448,64 @@ namespace MantidQt tie(ui.ck_parallel, "Parallel"); } + /** + *Customise the layout for usage in the Vsi + */ + void BinMDDialog::customiseLayoutForVsi(std::string initialWorkspace) + { + // File back-end + ui.file_backend_layout->setVisible(false); + + // Output workspace + ui.lbl_workspace_output->setVisible(false); + ui.txt_output->setVisible(false); + + // Input workspace + ui.workspace_selector->setVisible(false); + ui.lbl_workspace_input->setVisible(false); + + // Reset the input workspace + ui.workspace_selector->clear(); + ui.workspace_selector->addItem(initialWorkspace.c_str()); + + // Turn off history of the aligned dimension fields; + buildDimensionInputs(true); + } + + /** + * Resets the axis dimensions externally. + * @param propertyName The name of the axis dimension. + * @param propertyValue The new value of the axis dimension. + */ + void BinMDDialog::resestAlignedDimProperty(size_t index, QString propertyValue) + { + QString alignedDim = "AlignedDim"; + + const QString propertyName = alignedDim.copy().append(QString().number(index)); + + if (!m_tied_properties.contains(propertyName)) + { + return; + } + + QWidget* widget = m_tied_properties[propertyName]; + + if (!widget) + { + return; + } + + QLineEdit* edit = dynamic_cast<QLineEdit*>(widget); + + if (!edit) + { + return; + } + + edit->setText(propertyValue); + } + + /*--------------------------------------------------------------------------------------------- End BinMDDialog Methods ---------------------------------------------------------------------------------------------*/ diff --git a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt b/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt index 59ea51e7b8a26db95370c87b376714b5de508831..df8c97093ef22ed2dc198101c6b771b943592233 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/CMakeLists.txt @@ -5,7 +5,6 @@ set( INCLUDE_FILES inc/MantidVatesSimpleGuiQtWidgets/AxisInformation.h inc/MantidVatesSimpleGuiQtWidgets/GeometryParser.h inc/MantidVatesSimpleGuiQtWidgets/ModeControlWidget.h - inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.h inc/MantidVatesSimpleGuiQtWidgets/RotationPointDialog.h inc/MantidVatesSimpleGuiQtWidgets/WidgetDllOption.h ) @@ -14,14 +13,12 @@ set( SOURCE_FILES src/AxisInformation.cpp src/GeometryParser.cpp src/ModeControlWidget.cpp - src/RebinDialog.cpp src/RotationPointDialog.cpp ) # These are the headers to be preprocessed using Qt's moc preprocessor. qt4_wrap_cpp( MOC_SOURCES inc/MantidVatesSimpleGuiQtWidgets/ModeControlWidget.h - inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.h inc/MantidVatesSimpleGuiQtWidgets/RotationPointDialog.h ) @@ -32,7 +29,6 @@ qt4_add_resources( RES_FILES icons/QtWidgetsIcons.qrc ) # Qt's ui file processor. qt4_wrap_ui( UI_BUILT_SOURCES inc/MantidVatesSimpleGuiQtWidgets/ModeControlWidget.ui - inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.ui inc/MantidVatesSimpleGuiQtWidgets/RotationPointDialog.ui ) diff --git a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.h b/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.h deleted file mode 100644 index 0dce583811ac8ff069d90906e87c1cbf6d8b9bb5..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.h +++ /dev/null @@ -1,78 +0,0 @@ -#ifndef REBINDIALOG_H_ -#define REBINDIALOG_H_ - -#include "ui_RebinDialog.h" -#include <QDialog> -#include "MantidVatesSimpleGuiQtWidgets/WidgetDllOption.h" -#include <QLabel> -#include <QSpinBox> - -namespace Mantid -{ - namespace Vates - { - namespace SimpleGui - { - /** - * - This class provides a dialog to perform rebinning. - - @date 15/01/2015 - - Copyright © 2011 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_MANTIDVATES_SIMPLEGUI_QTWIDGETS RebinDialog : public QDialog - { - Q_OBJECT - - public: - RebinDialog(QWidget *parent = 0); - - ~RebinDialog(); - - - public slots: - void onUpdateDialog(QStringList algorithms, std::vector<QString> binNames, std::vector<int> bins); - - signals: - void performRebinning(QString algorithm, std::vector<QString> binNames, std::vector<int> bins); - - private slots: - void onAccept(); - - private: - Ui::RebinDialog ui; - - void setBins(std::vector<QString> binNames, std::vector<int> bins); - void setAlgorithms(QStringList algorithms); - - bool m_validBins; - - QLabel *lblBin1, *lblBin2, *lblBin3; - QSpinBox *boxBin1, *boxBin2, *boxBin3; - - }; - } - } -} - -#endif // MULTISLICEVIEW_H_ diff --git a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.ui b/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.ui deleted file mode 100644 index 88bd6b67f2fd3d668549875bd6126e3ff017f938..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/inc/MantidVatesSimpleGuiQtWidgets/RebinDialog.ui +++ /dev/null @@ -1,115 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>RebinDialog</class> - <widget class="QDialog" name="RebinDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>327</width> - <height>271</height> - </rect> - </property> - <property name="windowTitle"> - <string>Rebin the workspace</string> - </property> - <layout class="QVBoxLayout" name="verticalLayout"> - <property name="sizeConstraint"> - <enum>QLayout::SetDefaultConstraint</enum> - </property> - <item> - <layout class="QVBoxLayout" name="verticalLayout_2" stretch="1,2"> - <item> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Algorithm</string> - </property> - <widget class="QWidget" name="horizontalLayoutWidget"> - <property name="geometry"> - <rect> - <x>9</x> - <y>9</y> - <width>291</width> - <height>51</height> - </rect> - </property> - <layout class="QHBoxLayout" name="horizontalLayout_2" stretch="1,2"> - <item> - <widget class="QLabel" name="lblAlgorithms"> - <property name="text"> - <string>Choose an algorithm:</string> - </property> - </widget> - </item> - <item> - <widget class="QComboBox" name="comboBoxAlgorithms"/> - </item> - </layout> - </widget> - </widget> - </item> - <item> - <widget class="QGroupBox" name="groupBox_2"> - <property name="title"> - <string>Bins</string> - </property> - <widget class="QWidget" name="gridLayoutWidget"> - <property name="geometry"> - <rect> - <x>9</x> - <y>9</y> - <width>291</width> - <height>131</height> - </rect> - </property> - <layout class="QGridLayout" name="layoutBins" columnstretch="0"/> - </widget> - </widget> - </item> - </layout> - </item> - <item> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>RebinDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>163</x> - <y>250</y> - </hint> - <hint type="destinationlabel"> - <x>163</x> - <y>135</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>RebinDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>163</x> - <y>250</y> - </hint> - <hint type="destinationlabel"> - <x>163</x> - <y>135</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/src/RebinDialog.cpp b/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/src/RebinDialog.cpp deleted file mode 100644 index 81c838cf6b2b140d55cc253adef0018526c8db42..0000000000000000000000000000000000000000 --- a/Code/Mantid/Vates/VatesSimpleGui/QtWidgets/src/RebinDialog.cpp +++ /dev/null @@ -1,147 +0,0 @@ -#include "MantidVatesSimpleGuiQtWidgets/RebinDialog.h" -#include <QDialog> -#include <QLayoutItem> -#include <vector> -#include <QStringList> -#include <QSpinBox> -#include <QLabel> - - - -namespace Mantid -{ - namespace Vates - { - namespace SimpleGui - { - RebinDialog::RebinDialog(QWidget* parent) : QDialog(parent), m_validBins(false) - { - this->ui.setupUi(this); - - QObject::connect(this->ui.buttonBox, SIGNAL(accepted()), - this, SLOT(onAccept())); - } - - RebinDialog::~RebinDialog() - { - } - /** - * Sets the list of algorithms for the user to select - * @param algorithms The list of algorithms - */ - void RebinDialog::setAlgorithms(QStringList algorithms) - { - this->ui.comboBoxAlgorithms->clear(); - - this->ui.comboBoxAlgorithms->addItems(algorithms); - } - - void RebinDialog::setBins(std::vector<QString> binNames, std::vector<int> bins) - { - // Remove existing bins from Layout - QLayoutItem* child; - while ((child = this->ui.layoutBins->takeAt(0)) != 0) - { - child->widget()->deleteLater(); - delete child; - } - - // Set the bins - int minimum = 1; - int maximum = 1000; - - // Add bin 1 - lblBin1 = new QLabel(); - - boxBin1 = new QSpinBox(); - boxBin1->setMaximum(maximum); - boxBin1->setMinimum(minimum); - boxBin1->setButtonSymbols(QAbstractSpinBox::ButtonSymbols::NoButtons); - - ui.layoutBins->addWidget(lblBin1, 0, 0); - ui.layoutBins->addWidget(boxBin1, 0, 1); - - // Add bin 2 - lblBin2 = new QLabel(); - - boxBin2 = new QSpinBox(); - boxBin2->setMaximum(maximum); - boxBin2->setMinimum(minimum); - boxBin2->setButtonSymbols(QAbstractSpinBox::ButtonSymbols::NoButtons); - - ui.layoutBins->addWidget(lblBin2, 1, 0); - ui.layoutBins->addWidget(boxBin2, 1, 1); - - // Add bin 3 - lblBin3 = new QLabel(); - - boxBin3 = new QSpinBox(); - boxBin3->setMaximum(maximum); - boxBin3->setMinimum(minimum); - boxBin3->setButtonSymbols(QAbstractSpinBox::ButtonSymbols::NoButtons); - - ui.layoutBins->addWidget(lblBin3, 2, 0); - ui.layoutBins->addWidget(boxBin3, 2, 1); - - // Set the value - if((bins.size() == binNames.size()) && bins.size() == 3) - { - boxBin1->setVisible(true); - boxBin2->setVisible(true); - boxBin3->setVisible(true); - - - lblBin1->setText(binNames[0]); - boxBin1->setValue(bins[0]); - - lblBin2->setText(binNames[1]); - boxBin2->setValue(bins[1]); - - lblBin3->setText(binNames[2]); - boxBin3->setValue(bins[2]); - - m_validBins = true; - } - else - { - boxBin1->setVisible(false); - boxBin2->setVisible(false); - boxBin3->setVisible(false); - - m_validBins = false; - } - } - - void RebinDialog::onUpdateDialog(QStringList algorithms,std::vector<QString> binNames, std::vector<int> bins) - { - this->setAlgorithms(algorithms); - this->setBins(binNames, bins); - } - - void RebinDialog::onAccept() - { - // Get the selected algorithm - QString algorithm = this->ui.comboBoxAlgorithms->currentText(); - - // Get the bin information - std::vector<int> bins; - bins.push_back(boxBin1->value()); - bins.push_back(boxBin2->value()); - bins.push_back(boxBin3->value()); - - std::vector<QString> binNames; - binNames.push_back(lblBin1->text()); - binNames.push_back(lblBin2->text()); - binNames.push_back(lblBin3->text()); - - - // Send the request for rebinning only if all options are availble. - if (m_validBins) - { - emit performRebinning(algorithm, binNames, bins); - } - } - - } // SimpleGui - } // Vates -} // Mantid diff --git a/Code/Mantid/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt b/Code/Mantid/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt index 974b1551cf307373aba13725f2278ff96b4d0010..7b6fc013c18369e74568df6d1bf1f7d0aa317c8d 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesSimpleGui/StandAloneExec/CMakeLists.txt @@ -9,6 +9,8 @@ include_directories( ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR}/../QtWidgets ${CMAKE_CURRENT_BINARY_DIR}/../ViewWidgets + ${CMAKE_SOURCE_DIR}/MantidQt/MantidWidgets/inc + ${CMAKE_BINARY_DIR}/MantidQt/MantidWidgets ) # These are the C++ files to be compiled. diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt index 581b60cd17742d65b8df8b3b2ea5550a5cc3ca34..0fb73ee2735552d15aae739bbce28dd0f6243642 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/CMakeLists.txt @@ -9,6 +9,7 @@ set( INCLUDE_FILES inc/MantidVatesSimpleGuiViewWidgets/MultisliceView.h inc/MantidVatesSimpleGuiViewWidgets/RebinManager.h inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h + inc/MantidVatesSimpleGuiViewWidgets/SourcesManager.h inc/MantidVatesSimpleGuiViewWidgets/StandardView.h inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h inc/MantidVatesSimpleGuiViewWidgets/ThreesliceView.h @@ -24,6 +25,7 @@ set( SOURCE_FILES src/MultisliceView.cpp src/RebinManager.cpp src/SaveScreenshotReaction.cpp + src/SourcesManager.cpp src/StandardView.cpp src/SplatterPlotView.cpp src/ThreesliceView.cpp @@ -39,6 +41,7 @@ qt4_wrap_cpp( MOC_SOURCES inc/MantidVatesSimpleGuiViewWidgets/MultisliceView.h inc/MantidVatesSimpleGuiViewWidgets/RebinManager.h inc/MantidVatesSimpleGuiViewWidgets/SaveScreenshotReaction.h + inc/MantidVatesSimpleGuiViewWidgets/SourcesManager.h inc/MantidVatesSimpleGuiViewWidgets/StandardView.h inc/MantidVatesSimpleGuiViewWidgets/SplatterPlotView.h inc/MantidVatesSimpleGuiViewWidgets/ThreesliceView.h @@ -66,6 +69,7 @@ include_directories( inc ${CMAKE_SOURCE_DIR}/MantidQt/API/inc ${CMAKE_SOURCE_DIR}/MantidQt/MantidWidgets/inc + ${CMAKE_BINARY_DIR}/MantidQt/MantidWidgets ${CMAKE_SOURCE_DIR}/MantidQt/SliceViewer/inc ${CMAKE_BINARY_DIR}/MantidQt/SliceViewer ${CMAKE_SOURCE_DIR}/MantidQt/Factory/inc @@ -106,6 +110,7 @@ VatesAPI ${MANTID_SUBPROJECT_LIBS} MantidQtSliceViewer MantidQtFactory +MantidWidgets ) configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/inc/MantidVatesSimpleGuiViewWidgets/LibHelper.h.in diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h index a3bc4212929806deb2198a4f2e8527a28359a902..67f14567033d149717170eb8f76f532462e3f2be 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/MdViewerWidget.h @@ -4,6 +4,7 @@ #include "ui_MdViewerWidget.h" #include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h" #include "MantidVatesSimpleGuiViewWidgets/RebinManager.h" +#include "MantidVatesSimpleGuiViewWidgets/SourcesManager.h" #include "MantidQtAPI/VatesViewerInterface.h" #include "MantidQtAPI/WorkspaceObserver.h" @@ -103,7 +104,11 @@ protected slots: /// Execute view switch. void switchViews(ModeControlWidget::Views v); /// On rebin - void onRebin(RebinDialog* rebinDialog); + void onRebin(); + /// On unbin + void onUnbin(); + /// On switching an MDEvent source to a temporary MDHisto source. + void onSwitchSourcesFromEventToHisto(std::string histoWorkspaceName, std::string eventWorkspaceName); protected: /// Handle workspace preDeletion tasks. @@ -131,6 +136,7 @@ private: bool viewSwitched; ModeControlWidget::Views initialView; ///< Holds the initial view RebinManager m_rebinManager; ///<Holds the rebin manager + SourcesManager m_temporarySourcesManager; ///<Holds the sources manager /// Check the environmental variables. void checkEnvSetup(); @@ -178,6 +184,16 @@ private: bool checkIfTechniqueContainsKeyword(const std::set<std::string>& techniques, const std::string& keyword) const; /// Reset the current view to the appropriate initial view. void resetCurrentView(int workspaceType, const std::string& instrumentName); + /// Render temporary workspace + void renderTemporaryWorkspace(const std::string temporaryWorkspaceName); + /// Render the original workspace + void renderOriginalWorkspace(const std::string originalWorkspaceName); + /// Delete a specific workspace + void deleteSpecificSource(std::string workspaceName); + /// Remove the rebinning when switching views or otherwise. + void removeRebinning(pqPipelineSource* source, bool forced, ModeControlWidget::Views view = ModeControlWidget::STANDARD); + /// Remove all rebinned sources + void removeAllRebinning(ModeControlWidget::Views view); }; } // SimpleGui diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinManager.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinManager.h index 9e08a6d0e37621fce5e5592fe1b2ffee9ccd4fbb..c8bc8b29fce63ca70c00705312b50c6de8663f71 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinManager.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/RebinManager.h @@ -2,9 +2,15 @@ #define REBINMANAGER_H_ #include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h" -#include <QObject> -#include <vector> -#include <QStringList> +#include "MantidVatesAPI/ADSWorkspaceProvider.h" +#include "MantidAPI/IMDEventWorkspace.h" +#include "MantidAPI/Algorithm.h" +#include "MantidQtAPI/AlgorithmDialog.h" +#include "MantidQtMantidWidgets/SlicingAlgorithmDialog.h" + +#include <pqPipelineSource.h> +#include <QWidget> + namespace Mantid { @@ -12,8 +18,6 @@ namespace Mantid { namespace SimpleGui { - class RebinDialog; - /** * This class coordinates the rebinning of a workspace and updates the pipeline and view to make the changes of the @@ -41,26 +45,34 @@ namespace Mantid File change history is stored at: <https://github.com/mantidproject/mantid> Code Documentation is available at: <http://doxygen.mantidproject.org> */ - class EXPORT_OPT_MANTIDVATES_SIMPLEGUI_VIEWWIDGETS RebinManager :public QObject + class EXPORT_OPT_MANTIDVATES_SIMPLEGUI_VIEWWIDGETS RebinManager : public QWidget { Q_OBJECT public: - RebinManager(QObject* parent = 0); + RebinManager(QWidget* parent = 0); ~RebinManager(); - void sendUpdate(); + void showDialog(std::string inputWorkspace, std::string outputWorkspace); + + private: + MantidQt::API::AlgorithmDialog* createDialog(Mantid::API::IAlgorithm_sptr algorithm, std::string inputWorkspace, std::string outputWorkspace); - void connectDialog(RebinDialog* rebinDialog); + void getPresetsForBinMD( std::string inputWorkspace, std::string outputWorkspace, QHash<QString, QString>& presets); - signals: - void udpateDialog(QStringList algorithms,std::vector<QString> binNames, std::vector<int> bins); + void setAxisDimensions(MantidQt::MantidWidgets::BinMDDialog* dialog, std::string inputWorkspace); - public slots: - void onPerformRebinning(QString algorithm,std::vector<QString> binNames, std::vector<int> bins); + Mantid::API::IMDEventWorkspace_sptr getWorkspace(std::string workspaceName); - private: - RebinDialog* m_rebinDialog; + Mantid::API::IAlgorithm_sptr createAlgorithm(const QString& algName, int version); + + Mantid::VATES::ADSWorkspaceProvider<Mantid::API::IMDEventWorkspace> m_adsWorkspaceProvider; + + int m_binMdVersion; + QString m_binMdName; + QString m_lblInputWorkspace; + QString m_lblOutputWorkspace; + size_t m_binCutOffValue; }; } // SimpleGui diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SourcesManager.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SourcesManager.h new file mode 100644 index 0000000000000000000000000000000000000000..91ea0fb7df55fbfcf2690c86c1ad628230d4d332 --- /dev/null +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/SourcesManager.h @@ -0,0 +1,101 @@ +#ifndef SOURCESMANAGER_H_ +#define SOURCESMANAGER_H_ + +#include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h" +#include "MantidQtAPI/WorkspaceObserver.h" + +#include <pqPipelineSource.h> +#include <QWidget> +#include <map> + +namespace Mantid +{ + namespace Vates + { + namespace SimpleGui + { + /** + * + This class keeps track of the MDEvent workspaces and associated temporary MDHisto workspaces. Rebinning requires temporary MDHisto workspaces instead of + the MDEvent workspaces. This class switches between these types of sources. + + @date 21/01/2015 + + Copyright © 2011 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_MANTIDVATES_SIMPLEGUI_VIEWWIDGETS SourcesManager :public QWidget, MantidQt::API::WorkspaceObserver + { + Q_OBJECT + public: + SourcesManager(QWidget* parent = 0); + + ~SourcesManager(); + + void checkSource(pqPipelineSource* source, std::string& inputWorkspace, std::string& outputWorkspace); + + void repipeTemporarySource(std::string temporarySource, std::string originalSource); + + void repipeOriginalSource(std::string temporarySource, std::string originalSource); + + void getStoredWorkspaceNames(pqPipelineSource* source, std::string& originalWorkspaceName, std::string& temporaryWorkspaceName); + + void registerTemporarySource(pqPipelineSource* source); + + signals: + void switchSourcesFromEventToHisto(std::string histoWorkspaceName, std::string eventWorkspaceName); + + protected: + void addHandle(const std::string &workspaceName, const boost::shared_ptr<Mantid::API::Workspace> workspace); + + private slots: + void onTemporarySourceDestroyed(); + + private: + std::map<std::string, std::string> m_eventWorkspaceToHistoWorkspace; ///< Holds the mapping from the Event workspace name to the temporary Histo workspace name + + std::map<std::string, std::string> m_histoWorkspaceToEventWorkspace; ///< Holds the mapping from temporary Histo workspace name to the Event workspace name + + std::string m_tempPostfix; + + pqPipelineSource* getSourceForWorkspace(std::string workspaceName); + + void swapSources(std::string source1, std::string source2); + + void setSourceVisibility(pqPipelineSource* source, bool visibile); + + void processMDHistoWorkspace(std::string& inputWorkspace, std::string& outputWorkspace, std::string workspaceName); + + void processMDEventWorkspace(std::string& inputWorkspace, std::string& outputWorkspace, std::string workspaceName); + + void removeUnusedTemporaryWorkspaces(); + + void untrackWorkspaces(std::string temporarySource); + + void removeTemporaryWorkspace(std::string temporaryWorkspace); + + void compareToSources(std::string workspaceName); + }; + + } // SimpleGui + } // Vates +} // Mantid + +#endif diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h index e3507ad51bb15ca6408764521fbc393fb45d1253..470c3159019f7e46bc3a0fc00eefc2e427fcacfb 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.h @@ -18,7 +18,6 @@ namespace Vates { namespace SimpleGui { -class RebinDialog; /** * This class represents the initial view for the main program. It is meant to @@ -82,8 +81,6 @@ protected slots: void onRenderDone(); /// Invoke the ScaleWorkspace on the current dataset. void onScaleButtonClicked(); - /// Invoke the rebin dialog - void onRebinButtonClicked(); private: Q_DISABLE_COPY(StandardView) @@ -92,7 +89,6 @@ private: QPointer<pqPipelineSource> scaler; ///< Holder for the ScaleWorkspace Ui::StandardView ui; ///< The standard view's UI form QPointer<pqRenderView> view; ///< The main view - RebinDialog* m_rebinDialog; ///< Handle to the rebin dialog. }; } // SimpleGui diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.ui b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.ui index 49d62acfdab029cc18b7e4627ca9ed08df3a551a..b1e83cc76a47aa6bf7ce1c1ce0ca67a681cbda9e 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.ui +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/StandardView.ui @@ -29,16 +29,23 @@ </property> </spacer> </item> - <item> + <item> <widget class="QPushButton" name="rebinButton"> - <property name="toolTip"> - <string>Invoke plugin to rebin the current dataset.</string> - </property> - <property name="text"> - <string>Rebin</string> - </property> + <property name="toolTip"> + <string>Invoke plugin to rebin the current dataset.</string> + </property> + <property name="text"> + <string>Rebin</string> + </property> </widget> - </item> + </item> + <item> + <widget class="QPushButton" name="unbinButton"> + <property name="text"> + <string>Unbin</string> + </property> + </widget> + </item> <item> <widget class="QPushButton" name="scaleButton"> <property name="toolTip"> diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h index ff66c20d0262c7b3b001b46f4ef26a6442422f64..46c6777156bcc10725e12d84a62bfe6b1a908886 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/inc/MantidVatesSimpleGuiViewWidgets/ViewBase.h @@ -3,7 +3,6 @@ #include "MantidVatesSimpleGuiViewWidgets/ColorUpdater.h" #include "MantidVatesSimpleGuiViewWidgets/WidgetDllOption.h" -#include "MantidVatesSimpleGuiQtWidgets/RebinDialog.h" #include "MantidVatesSimpleGuiQtWidgets/ModeControlWidget.h" #include <QPointer> @@ -111,9 +110,13 @@ public: /// Set the current color scale state virtual void setColorScaleState(ColorSelectionWidget *cs); /// Create source for plugin mode. - virtual void setPluginSource(QString pluginName, QString wsName); + virtual pqPipelineSource* setPluginSource(QString pluginName, QString wsName); /// Determines if source has timesteps (4D). virtual bool srcHasTimeSteps(pqPipelineSource *src); + /// Sets the splatterplot button to the desired visibility. + virtual void setSplatterplot(bool visibility); + /// Sets the standard veiw button to the desired visibility. + virtual void setStandard(bool visibility); /// Enumeration for Cartesian coordinates enum Direction {X, Y, Z}; @@ -181,15 +184,19 @@ signals: void setViewStatus(ModeControlWidget::Views mode, bool state); /** * Signal to set the status of the view mode buttons. - * @param view The initial view. + * @param view The initial view. * @param state Whether or not to enable to view mode buttons. */ void setViewsStatus(ModeControlWidget::Views view, bool state); /** * Signal to perform a possible rebin. - * @param rebinDialog Pointer to a rebin dialog */ - void rebin(RebinDialog* rebinDialog); + void rebin(); + /** + * Signal to perform a possible unbin on a sources which has been + * rebinned in the VSI. + */ + void unbin(); private: Q_DISABLE_COPY(ViewBase) diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp index f1bcc70af656b4f140cd8d0a14632cf27228e7e7..58233bb06b9cafd170221afe79f0a0ef501553b8 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/MdViewerWidget.cpp @@ -30,9 +30,12 @@ #include <pqObjectInspectorWidget.h> #include <pqParaViewBehaviors.h> #include <pqPipelineSource.h> +#include <pqPipelineFilter.h> #include <pqPVApplicationCore.h> #include <pqRenderView.h> #include <pqSettings.h> +#include <pqServer.h> +#include <pqServerManagerModel.h> #include <pqStatusBar.h> #include <pqViewSettingsReaction.h> #include <vtkSMDoubleVectorProperty.h> @@ -122,8 +125,9 @@ MdViewerWidget::MdViewerWidget() : VatesViewerInterface(), currentView(NULL), this->internalSetup(true); - // Create the mapping from the measurement technique to the view - + // Connect the temporary sources manager + QObject::connect(&m_temporarySourcesManager, SIGNAL(switchSourcesFromEventToHisto(std::string, std::string)), + this, SLOT(onSwitchSourcesFromEventToHisto(std::string, std::string))); } /** @@ -450,18 +454,164 @@ void MdViewerWidget::setParaViewComponentsForView() SLOT(onParallelProjection(bool))); // Start listening to a rebinning event - QObject::connect(this->currentView, SIGNAL(rebin(RebinDialog*)), - this, SLOT(onRebin(RebinDialog*)), Qt::UniqueConnection); + QObject::connect(this->currentView, SIGNAL(rebin()), + this, SLOT(onRebin()), Qt::UniqueConnection); + + // Start listening to an unbinning event + QObject::connect(this->currentView, SIGNAL(unbin()), + this, SLOT(onUnbin()), Qt::UniqueConnection); + } /** * Reaction for a rebin event */ -void MdViewerWidget::onRebin(RebinDialog* rebinDialog) +void MdViewerWidget::onRebin() +{ + pqPipelineSource* source = pqActiveObjects::instance().activeSource(); + + std::string inputWorkspaceName; + std::string outputWorkspaceName; + + m_temporarySourcesManager.checkSource(source, inputWorkspaceName, outputWorkspaceName); + + m_rebinManager.showDialog(inputWorkspaceName, outputWorkspaceName); +} + +/** + * Switch a source from an MDEvent source to a temporary MDHisto source. + * @param histoWorkspaceName The name of the temporary histo workspace. + * @param eventWorkspaceName The name of the event workspace. + */ +void MdViewerWidget::onSwitchSourcesFromEventToHisto(std::string histoWorkspaceName, std::string eventWorkspaceName) +{ + // Create a new MDHisto source and display it + renderTemporaryWorkspace(histoWorkspaceName); + + // Repipe the filters to the temporary source + try + { + m_temporarySourcesManager.repipeTemporarySource(histoWorkspaceName, eventWorkspaceName); + } + catch (const std::runtime_error& error) + { + g_log.warning() << error.what(); + } + + // Remove the MDEvent source + deleteSpecificSource(eventWorkspaceName); + + // Set the splatterplot button explicitly + this->currentView->setSplatterplot(true); +} + + +/** + * Creates and renders a temporary workspace source + * @param temporaryWorkspaceName The name of the temporary workspace + */ +void MdViewerWidget::renderTemporaryWorkspace(const std::string temporaryWorkspaceName) { - m_rebinManager.connectDialog(rebinDialog); + // Load a new source plugin + QString sourcePlugin = "MDHW Source"; + pqPipelineSource* newTemporarySource = this->currentView->setPluginSource(sourcePlugin, QString::fromStdString(temporaryWorkspaceName)); + + m_temporarySourcesManager.registerTemporarySource(newTemporarySource); - m_rebinManager.sendUpdate(); + this->renderAndFinalSetup(); +} + +/** + * Creates and renders back to the original source + * @param originalWorkspaceName The name of the original workspace + */ +void MdViewerWidget::renderOriginalWorkspace(const std::string originalWorkspaceName) +{ + // Load a new source plugin + QString sourcePlugin = "MDEW Source"; + this->currentView->setPluginSource(sourcePlugin, QString::fromStdString(originalWorkspaceName)); + + this->renderAndFinalSetup(); +} + + +/** + * Gets triggered by an unbin event. It removes the rebinning on a workspace + * which has been rebinned from within the VSI. + */ +void MdViewerWidget::onUnbin() +{ + // Force the removal of the rebinning + pqPipelineSource *activeSource = pqActiveObjects::instance().activeSource(); + + removeRebinning(activeSource, true); +} + +/** + * Remove the rebinning. + * @param source The pipeline source for which the rebinning will be removed. + * @param forced If it should be removed under all circumstances. + * @param view If switched, to which view is it being switched + */ +void MdViewerWidget::removeRebinning(pqPipelineSource* source, bool forced, ModeControlWidget::Views view) +{ + if (forced || view == ModeControlWidget::SPLATTERPLOT) + { + std::string originalWorkspaceName; + std::string temporaryWorkspaceName; + m_temporarySourcesManager.getStoredWorkspaceNames(source, originalWorkspaceName, temporaryWorkspaceName); + + // If there is nothing to remove then we are done + if (originalWorkspaceName.empty() || temporaryWorkspaceName.empty()) + { + return; + } + + // Create the original source + renderOriginalWorkspace(originalWorkspaceName); + + // Repipe the filters to the original source + try + { + m_temporarySourcesManager.repipeOriginalSource(temporaryWorkspaceName, originalWorkspaceName); + } + catch (const std::runtime_error& error) + { + g_log.warning() << error.what(); + } + + // Remove the MDHisto source + deleteSpecificSource(temporaryWorkspaceName); + + // Set the buttons correctly if we switch to splatterplot + if ( view == ModeControlWidget::SPLATTERPLOT) + { + this->currentView->setSplatterplot(false); + this->currentView->setStandard(true); + } + } +} + +/** + * Remove rebinning from all rebinned sources + * @param view The view mode. + */ +void MdViewerWidget::removeAllRebinning(ModeControlWidget::Views view) +{ + // Iterate over all temporary sources and remove them + pqServer *server = pqActiveObjects::instance().activeServer(); + pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel(); + QList<pqPipelineSource *> sources = smModel->findItems<pqPipelineSource *>(server); + + for (QList<pqPipelineSource *>::Iterator source = sources.begin(); source != sources.end(); ++source) + { + const QString srcProxyName = (*source)->getProxy()->GetXMLGroup(); + + if (srcProxyName == QString("sources")) + { + removeRebinning(*source, false, view); + } + } } /** @@ -746,13 +896,6 @@ void MdViewerWidget::checkForUpdates() } vtkSMProxy *proxy = src->getProxy(); - if (strcmp(proxy->GetXMLName(), "MDEWRebinningCutter") == 0) - { - this->currentView->onAutoScale(); - this->currentView->updateAnimationControls(); - this->currentView->updateView(); - this->currentView->updateUI(); - } if (QString(proxy->GetXMLName()).contains("Threshold")) { this->ui.colorSelectionWidget->enableControls(true); @@ -775,6 +918,7 @@ void MdViewerWidget::checkForUpdates() */ void MdViewerWidget::switchViews(ModeControlWidget::Views v) { + this->removeAllRebinning(v); this->viewSwitched = true; this->currentView->closeSubWindows(); this->disconnectDialogs(); @@ -1107,6 +1251,40 @@ void MdViewerWidget::preDeleteHandle(const std::string &wsName, } } +/** + * Delete a specific source and all of its filters. This assumes a linear filter system + * @param workspaceName The workspaceName associated with the source which is to be deleted + */ +void MdViewerWidget::deleteSpecificSource(std::string workspaceName) +{ + pqPipelineSource *source = this->currentView->hasWorkspace(workspaceName.c_str()); + if (NULL != source) + { + // Go to the end of the source and work your way back + pqPipelineSource* tempSource = source; + + while ((tempSource->getAllConsumers()).size() > 0) + { + tempSource = tempSource->getConsumer(0); + } + + // Now delete all filters and the source + pqObjectBuilder *builder = pqApplicationCore::instance()->getObjectBuilder(); + + // Crawl up to the source level + pqPipelineFilter* filter = qobject_cast<pqPipelineFilter*>(tempSource); + + while (filter) + { + source = filter->getInput(0); + builder->destroy(filter); + filter = qobject_cast<pqPipelineFilter*>(source); + } + + builder->destroy(source); + } +} + } // namespace SimpleGui } // namespace Vates } // namespace Mantid diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinManager.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinManager.cpp index 70152210af7cc11b044bec018248f8b4e3978558..206e8d64823ead6b2c9f09eebd8d91c6cb99ff24 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinManager.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/RebinManager.cpp @@ -1,9 +1,20 @@ #include "MantidVatesSimpleGuiViewWidgets/RebinManager.h" -#include "MantidVatesSimpleGuiQtWidgets/RebinDialog.h" #include "MantidVatesAPI/ADSWorkspaceProvider.h" -#include <QStringList> +#include "MantidAPI/Algorithm.h" +#include "MantidQtAPI/InterfaceManager.h" +#include "MantidQtMantidWidgets/SlicingAlgorithmDialog.h" +#include "MantidAPI/IMDEventWorkspace.h" +#include "MantidAPI/IMDWorkspace.h" +#include "boost/shared_ptr.hpp" +#include "MantidKernel/Logger.h" + +#include <string> #include <vector> +#include <QString> +#include <QVariant> +#include <QHash> + #include <pqActiveObjects.h> #include <pqPipelineSource.h> #include <vtkSMPropertyHelper.h> @@ -19,7 +30,18 @@ namespace Mantid { namespace SimpleGui { - RebinManager::RebinManager(QObject* parent) : QObject(parent) + + namespace + { + Mantid::Kernel::Logger g_log("RebinManager"); + } + + RebinManager::RebinManager(QWidget* parent) : QWidget(parent), + m_binMdVersion(1), + m_binMdName("BinMD"), + m_lblInputWorkspace("InputWorkspace"), + m_lblOutputWorkspace("OutputWorkspace"), + m_binCutOffValue(50) { } @@ -27,45 +49,186 @@ namespace Mantid { } - void RebinManager::sendUpdate() + /** + * Show a Bin MD dialog for rebinning in the VSI + * @param inputWorkspace The name of the input workspace. + * @param outputWorkspace The name of the output workspace. + */ + void RebinManager::showDialog(std::string inputWorkspace, std::string outputWorkspace) { - // Get the workspace information for the active source - pqPipelineSource* activeSource = pqActiveObjects::instance().activeSource(); + if (inputWorkspace.empty() || outputWorkspace.empty()) + { + return; + } - std::string workspaceName(vtkSMPropertyHelper((activeSource)->getProxy(), - "WorkspaceName", true).GetAsString()); + // Create the algorithm + Mantid::API::IAlgorithm_sptr algorithm = createAlgorithm(m_binMdName, m_binMdVersion); - std::vector<int> bins; - bins.push_back(50); - bins.push_back(50); - bins.push_back(50); + if (!algorithm) + { + return; + } - std::vector<QString> binNames; - binNames.push_back(QString("Bin1")); - binNames.push_back(QString("Bin2")); - binNames.push_back(QString("Bin3")); + MantidQt::API::AlgorithmDialog* rebinDialog = createDialog(algorithm, inputWorkspace, outputWorkspace); + + rebinDialog->show(); + rebinDialog->raise(); + rebinDialog->activateWindow(); + } + + /** + * Gets the event workspace + * @param workspaceName The name of the input workspace. + * @returns A pointer to the current event workspace + */ + Mantid::API::IMDEventWorkspace_sptr RebinManager::getWorkspace(std::string workspaceName) + { + Mantid::API::IMDEventWorkspace_sptr eventWorkspace; - QStringList list; - list.append("Alg1"); - list.append("Alg2"); - emit this->udpateDialog(list, binNames, bins); + if (!m_adsWorkspaceProvider.canProvideWorkspace(workspaceName)) + { + return eventWorkspace; + } + + Mantid::API::Workspace_sptr workspace = m_adsWorkspaceProvider.fetchWorkspace(workspaceName); + + // Make sure it is a and MDEvent + eventWorkspace = boost::dynamic_pointer_cast<Mantid::API::IMDEventWorkspace>(workspace); + + return eventWorkspace; } - void RebinManager::onPerformRebinning(QString algorithm,std::vector<QString> binNames, std::vector<int> bins) + /** + * Creates an algorithm + * @param algorithmName The name of the algorithm. + * @param version The version of the algorithm + * @returns A pointer to the newly created algorithm. + */ + Mantid::API::IAlgorithm_sptr RebinManager::createAlgorithm(const QString& algorithmName, int version) { - int a = 1; + Mantid::API::IAlgorithm_sptr alg; + try + { + alg = Mantid::API::AlgorithmManager::Instance().create(algorithmName.toStdString(),version); + } + catch(...) + { + g_log.warning() << "Error: " << algorithmName.toStdString() << " was not created. Version number is " << version; + } + return alg; } - void RebinManager::connectDialog(RebinDialog* rebinDialog) + /** + * Creates the dialog for the algorithm (see InterfaceManager). + * @param algorithm The algorithm which is to be used. + * @param inputWorkspace The name of the input workspace. + * @param outputWorkspace The name of the output workspace. + * @returns The algorithm dialog + */ + MantidQt::API::AlgorithmDialog* RebinManager::createDialog( Mantid::API::IAlgorithm_sptr algorithm, std::string inputWorkspace, std::string outputWorkspace) { - // Establish connection between Rebinmanager and RebinDialog - QObject::connect(this, SIGNAL(udpateDialog(QStringList, std::vector<QString>, std::vector<int>)), - rebinDialog, SLOT(onUpdateDialog(QStringList,std::vector<QString>, std::vector<int>)), Qt::UniqueConnection); + QHash<QString, QString> presets; + getPresetsForBinMD(inputWorkspace, outputWorkspace, presets); + + //Check if a workspace is selected in the dock and set this as a preference for the input workspace + //This is an optional message displayed at the top of the GUI. + QString optional_msg(algorithm->summary().c_str()); + + + MantidQt::MantidWidgets::BinMDDialog* dialog = new MantidQt::MantidWidgets::BinMDDialog(this); + // The parent so that the dialog appears on top of it + dialog->setParent(this); + dialog->setAttribute(Qt::WA_DeleteOnClose, true); + + // Set the QDialog window flags to ensure the dialog ends up on top + Qt::WindowFlags flags = 0; + flags |= Qt::Dialog; + flags |= Qt::WindowContextHelpButtonHint; + dialog->setWindowFlags(flags); + + // Set the content + dialog->setAlgorithm(algorithm); + dialog->setPresetValues(presets); + dialog->setOptionalMessage(QString(algorithm->summary().c_str())); + + // Setup the layout + dialog->initializeLayout(); + dialog->customiseLayoutForVsi(inputWorkspace); + + // Setup the values of the axis dimensions + setAxisDimensions(dialog, inputWorkspace); + + return dialog; + } + + /** + * Determine the preset values + * @param inputWorkspace The name of the input workspace. + * @param outputWorkspace The name of the output workspace. + * @param presets A container for the preset values. + */ + void RebinManager::getPresetsForBinMD(std::string inputWorkspace, std::string outputWorkspace, QHash<QString, QString>& presets) + { + // Set the input workspace + presets.insert(QString(m_lblInputWorkspace),QString::fromStdString(inputWorkspace)); + + // Set the output workspace + presets.insert(QString(m_lblOutputWorkspace),QString::fromStdString(outputWorkspace)); + } + + /** + * Resets the aligned dimensions properties + * @param dialog A pointer to the BinMD dialog + * @param inputWorkspace The name of the input workspace. + */ + void RebinManager::setAxisDimensions(MantidQt::MantidWidgets::BinMDDialog* dialog, std::string inputWorkspace) + { + Mantid::API::IMDEventWorkspace_sptr eventWorkspace = getWorkspace(inputWorkspace); + + size_t nDimensions = eventWorkspace->getNumDims(); + + for (size_t index = 0; index < nDimensions; ++index) + { + Mantid::Geometry::IMDDimension_const_sptr dim = eventWorkspace->getDimension(index); + + std::string name = dim->getName(); + std::string dimensionId = dim->getDimensionId(); + coord_t minimum = dim->getMinimum(); + coord_t maximum = dim->getMaximum(); + size_t numberOfBins = dim->getNBins(); + + // Check the bins size + QString newNumberOfBins; + if (numberOfBins < m_binCutOffValue) + { + newNumberOfBins = QString::number(static_cast<unsigned long long>(m_binCutOffValue)); + } + else + { + newNumberOfBins = QString::number(static_cast<unsigned long long>(numberOfBins)); + } + + // If Id exists use it as the identifier otherwise use the name + std::string identifier; + if (dimensionId.empty()) + { + identifier = name; + } + else + { + identifier = dimensionId; + } + + // Check here if the set bins are OK + QString propertyValue = QString::fromStdString(identifier) + "," + + QString::number(static_cast<float>(minimum)) + "," + + QString::number(static_cast<float>(maximum)) + "," + + newNumberOfBins; - QObject::connect(rebinDialog, SIGNAL(performRebinning(QString, std::vector<QString>, std::vector<int>)), - this, SLOT(onPerformRebinning(QString, std::vector<QString> , std::vector<int>)), Qt::UniqueConnection); + dialog->resestAlignedDimProperty(index, propertyValue); + } } - } // SimpleGui - } // Vates -} // Mantid + } + } +} diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SourcesManager.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SourcesManager.cpp new file mode 100644 index 0000000000000000000000000000000000000000..17fe148056a508e355014a49ae757d34b1566a0d --- /dev/null +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/SourcesManager.cpp @@ -0,0 +1,414 @@ +#include "MantidVatesSimpleGuiViewWidgets/SourcesManager.h" +#include "MantidVatesAPI/ADSWorkspaceProvider.h" +#include "MantidQtAPI/WorkspaceObserver.h" +#include "MantidAPI/AnalysisDataService.h" +#include "MantidAPI/IMDHistoWorkspace.h" +#include "MantidKernel/Logger.h" + +#include "boost/shared_ptr.hpp" + +#include <pqActiveObjects.h> +#include <pqApplicationCore.h> +#include <pqPipelineFilter.h> +#include <pqPipelineSource.h> +#include <pqServer.h> +#include <pqServerManagerModel.h> +#include <vtkSMPropertyHelper.h> +#include <pqServerManagerModel.h> +#include <vtkSMSourceProxy.h> +#include <vtkSMProxy.h> + +#include <QList> + +#include <Poco/ActiveResult.h> + +// Have to deal with ParaView warnings and Intel compiler the hard way. +#if defined(__INTEL_COMPILER) + #pragma warning disable 1170 +#endif + +namespace Mantid +{ + namespace Vates + { + namespace SimpleGui + { + + namespace + { + Mantid::Kernel::Logger g_log("SourcesManager"); + } + + SourcesManager::SourcesManager(QWidget* parent) : QWidget(parent), m_tempPostfix("_tempvsi") + { + observeAdd(); + } + + SourcesManager::~SourcesManager() + { + } + + /** + * Checks if a temporary MDHisto workspace was added and invokes a replacement procedure + * @param workspaceName Name of the workspace. + * @param workspace A pointer to the added workspace. + */ + void SourcesManager::addHandle(const std::string &workspaceName, Mantid::API::Workspace_sptr workspace) + { + if (m_histoWorkspaceToEventWorkspace.count(workspaceName) > 0) + { + emit switchSourcesFromEventToHisto(workspaceName, m_histoWorkspaceToEventWorkspace[workspaceName]); + } + } + + /** + * Check if the sources are valid. + * @param source The pipeline source. + * @param inputWorkspace Reference for the name of the input workspace. + * @param outputWorkspace Reference for the name of the output workspace. + */ + void SourcesManager::checkSource(pqPipelineSource* source, std::string& inputWorkspace, std::string& outputWorkspace) + { + // Make sure that the input source exists. Note that this can happen when there is no active view + if (!source) + { + return; + } + + // Update the source/filter + vtkSMProxy* proxy = source->getProxy(); + proxy->UpdateVTKObjects(); + proxy->UpdatePropertyInformation(); + source->updatePipeline(); + + // Crawl up to the source level + pqPipelineFilter* filter = qobject_cast<pqPipelineFilter*>(source); + + while (filter) + { + source = filter->getInput(0); + filter = qobject_cast<pqPipelineFilter*>(source); + } + + proxy = source->getProxy(); + + // Ensure that the source is either an MDEvent source or an MDHisto source + if (!QString(proxy->GetXMLName()).contains("MDEW Source") && + !QString(proxy->GetXMLName()).contains("MDHW Source")) + { + return; + } + + // Check if the source has an underlying event workspace or histo workspace + std::string workspaceName(vtkSMPropertyHelper(source->getProxy(), + "WorkspaceName", true).GetAsString()); + + QString workspaceType(vtkSMPropertyHelper(source->getProxy(), + "WorkspaceTypeName", true).GetAsString()); + + bool isHistoWorkspace = workspaceType.contains("MDHistoWorkspace"); + bool isEventWorkspace = workspaceType.contains("MDEventWorkspace"); + + // Check if it is a Histo or Event workspace, if it is neither, then don't do anything + if (isHistoWorkspace) + { + processMDHistoWorkspace(inputWorkspace, outputWorkspace, workspaceName); + } + else if (isEventWorkspace) + { + processMDEventWorkspace(inputWorkspace, outputWorkspace, workspaceName); + } + } + + /** + * Creates the pipeline for the temporary source. + * @param temporarySource The name of the temporary source. + * @param originalSource The name of the original source. + */ + void SourcesManager::repipeTemporarySource(std::string temporarySource, std::string originalSource) + { + // Swap source from original source to temporary source + swapSources(originalSource, temporarySource); + } + + /** + * Creates the pipeline for the original source. + * @param temporarySource The name of the temporary source. + * @param originalSource The name of the original source. + */ + void SourcesManager::repipeOriginalSource(std::string temporarySource, std::string originalSource) + { + // Swap source from temporary source to original source. + swapSources(temporarySource, originalSource); + } + + /** + * Swap the sources at the bottom level of the pipeline. + * @param source1 First source. + * @param source2 Second source. + */ + void SourcesManager::swapSources(std::string source1, std::string source2) + { + pqPipelineSource* src1= getSourceForWorkspace(source1); + pqPipelineSource* src2 = getSourceForWorkspace(source2); + + if (!src1 || !src2) + { + throw std::runtime_error("VSI error: Either the original or temporary source don't seem to exist."); + } + + // Check if the original source has a filter if such then repipe otherwise we are done + if ((src1->getAllConsumers()).size() <= 0) + { + return; + } + + // Cast to the filter and reset the connection + pqPipelineFilter* filter = qobject_cast<pqPipelineFilter*>(src1->getConsumer(0)); + + if (!filter) + { + throw std::runtime_error("VSI error: There is no filter in the pipeline."); + } + + vtkSMPropertyHelper(filter->getProxy(), "Input").Set(src2->getProxy()); + + // Update the pipeline + vtkSMProxy* proxy = filter->getProxy(); + proxy->UpdateVTKObjects(); + proxy->UpdatePropertyInformation(); + filter->updateHelperProxies(); + filter->updatePipeline(); + + // Set the visibility of the source. Paraview doesn't automatically set it to false, so we need to force it. + setSourceVisibility(src2, false); + + // Render the active view to make the changes visible. + pqActiveObjects::instance().activeView()->render(); + } + + /** + * Removes the temporary source and reverts to the original source + * @param source The name of the source. + * @param originalWorkspaceName The name of the original workspace. + * @param temporaryWorkspaceName The name of the temporary workspace. + */ + void SourcesManager::getStoredWorkspaceNames(pqPipelineSource* source, std::string& originalWorkspaceName, std::string& temporaryWorkspaceName) + { + if (!source) + { + return; + } + + // Get to the underlying source + std::string originalSource; + std::string temporarySource; // not really used here + checkSource(source, originalSource, temporarySource); + + // Make sure that the sources exist + pqPipelineSource* tempsrc = getSourceForWorkspace(temporarySource); + + if (!tempsrc) + { + return; + } + + // The input source can be either an MDEvent source or an MDHisto source. + if (m_histoWorkspaceToEventWorkspace.count(originalSource) > 0) + { + originalWorkspaceName = m_histoWorkspaceToEventWorkspace[originalSource]; + temporaryWorkspaceName = originalSource; + } else if (m_eventWorkspaceToHistoWorkspace.count(originalSource) > 0) + { + + originalWorkspaceName = originalSource; + temporaryWorkspaceName = m_eventWorkspaceToHistoWorkspace[originalSource]; + } + } + + /** + * Set the visibility of the underlying source + * @param source The source which is to be manipulated. + * @param visible The state of the source's visibility. + */ + void SourcesManager::setSourceVisibility(pqPipelineSource* source, bool visible) + { + pqRepresentation* representation = qobject_cast<pqRepresentation* >(source->getRepresentation(pqActiveObjects::instance().activeView())); + + if(!representation) + { + throw std::runtime_error("VSI error: Casting to pqRepresentation failed."); + } + + representation->setVisible(visible); + } + + /** + * Get the desired source + * @param workspaceName The workspace name associated with the source. + */ + pqPipelineSource* SourcesManager::getSourceForWorkspace(std::string workspaceName) + { + pqServer *server = pqActiveObjects::instance().activeServer(); + pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel(); + QList<pqPipelineSource *> sources; + QList<pqPipelineSource *>::Iterator source; + sources = smModel->findItems<pqPipelineSource *>(server); + + for (source = sources.begin(); source != sources.end(); ++source) + { + + pqPipelineFilter* filter = qobject_cast<pqPipelineFilter*>(*source); + + if (!filter) + { + std::string wsName(vtkSMPropertyHelper((*source)->getProxy(), + "WorkspaceName", true).GetAsString()); + if (!wsName.empty()) + { + if (wsName == workspaceName) + { + return (*source); + } + } + } + } + return NULL; + } + + /** + * If sources which are derived of temporary MDHisto workspaces, the input workpspace is the + * original MDEvent workspace and the output is the temporary MDHisto workspace. + * @param inputWorkspace Reference to the input workpspace. + * @param outputWorkspace Reference to the output workspace. + * @param workspaceName The name of the workspace of the current source. + */ + void SourcesManager::processMDHistoWorkspace(std::string& inputWorkspace, std::string& outputWorkspace, std::string workspaceName) + { + if (m_histoWorkspaceToEventWorkspace.count(workspaceName) > 0) + { + inputWorkspace = m_histoWorkspaceToEventWorkspace[workspaceName]; + outputWorkspace = workspaceName; + } + } + + /** + * If sources which are derived of temporary MDHisto workspaces, the input workpspace is the + * original MDEvent workspace and the output is the temporary MDHisto workspace. + * @param inputWorkspace Reference to the input workpspace. + * @param outputWorkspace Reference to the output workspace. + * @param workspaceName The name of the workspace of the current source. + */ + void SourcesManager::processMDEventWorkspace(std::string& inputWorkspace, std::string& outputWorkspace, std::string workspaceName) + { + inputWorkspace = workspaceName; + outputWorkspace = workspaceName + m_tempPostfix; + + // Record the workspace + m_eventWorkspaceToHistoWorkspace.insert(std::pair<std::string, std::string>(inputWorkspace, outputWorkspace)); + m_histoWorkspaceToEventWorkspace.insert(std::pair<std::string, std::string>(outputWorkspace, inputWorkspace)); + } + + /** + * Stop keeping tabs on the specific workspace pair + * @param temporaryWorspace The name of the temporary workspace. + * @param originalWorksapce The name of the original workspace. + */ + void SourcesManager::untrackWorkspaces(std::string temporaryWorkspace) + { + std::string originalWorkspace = m_histoWorkspaceToEventWorkspace[temporaryWorkspace]; + + m_histoWorkspaceToEventWorkspace.erase(temporaryWorkspace); + m_eventWorkspaceToHistoWorkspace.erase(originalWorkspace); + } + + /** + * Removes the temporary workspace from memory. + * @param temporaryWorkspace The name of the temporary workspace. + */ + void SourcesManager::removeTemporaryWorkspace(std::string temporaryWorkspace) + { + Mantid::VATES::ADSWorkspaceProvider<Mantid::API::IMDHistoWorkspace> adsWorkspaceProvider; + + if (adsWorkspaceProvider.canProvideWorkspace(temporaryWorkspace)) + { + adsWorkspaceProvider.disposeWorkspace(temporaryWorkspace); + } + } + + /** + * Register the temporary source. Specifically, connect to the destroyed signal of the temporary source. + * @param source The temporary source. + */ + void SourcesManager::registerTemporarySource(pqPipelineSource* source) + { + if (!source) + { + return; + } + + QObject::connect(source, SIGNAL(destroyed()), + this, SLOT(onTemporarySourceDestroyed())); + } + + /** + * React to the deletion of a temporary source. + */ + void SourcesManager::onTemporarySourceDestroyed() + { + removeUnusedTemporaryWorkspaces(); + } + + /** + * Remove unused temporary workspaces, by comparing the workspaces against the sources. + */ + void SourcesManager::removeUnusedTemporaryWorkspaces() + { + // Iterate through all workspaces and check for ones ending with the tempIdentifier + std::set<std::string> workspaceNames = Mantid::API::AnalysisDataService::Instance().getObjectNames(); + + for (std::set<std::string>::iterator it = workspaceNames.begin(); it != workspaceNames.end(); ++it) + { + // Only look at the temporary files + if (it->find(m_tempPostfix) != std::string::npos) + { + compareToSources(*it); + } + } + } + + /** + * Compare if the workspace name exists among the sources. If it doesnt't exist, remove it. + * @param workspaceName The name of the workspace + */ + void SourcesManager::compareToSources(std::string workspaceName) + { + pqServer *server = pqActiveObjects::instance().activeServer(); + pqServerManagerModel *smModel = pqApplicationCore::instance()->getServerManagerModel(); + QList<pqPipelineSource *> sources = smModel->findItems<pqPipelineSource *>(server); + + for (QList<pqPipelineSource *>::Iterator source = sources.begin(); source != sources.end(); ++source) + { + const QString srcProxyName = (*source)->getProxy()->GetXMLGroup(); + + if (srcProxyName == QString("sources")) + { + std::string name(vtkSMPropertyHelper((*source)->getProxy(), + "WorkspaceName", true).GetAsString()); + + // If the temporary workspace has a source equivalent, then exit + if (name==workspaceName) + { + return; + } + } + } + + // There is no source which corresponds to the workspace, hence delete and unregister the workspace. + removeTemporaryWorkspace(workspaceName); + untrackWorkspaces(workspaceName); + } + + } + } +} diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp index bc6af39f75e3d219f4e0d44521020f55f10e3632..5cf86af8d7f2a9beb3ac975fe20744975a7fdecb 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/StandardView.cpp @@ -1,5 +1,4 @@ #include "MantidVatesSimpleGuiViewWidgets/StandardView.h" -#include "MantidVatesSimpleGuiQtWidgets/RebinDialog.h" // Have to deal with ParaView warnings and Intel compiler the hard way. #if defined(__INTEL_COMPILER) #pragma warning disable 1170 @@ -36,14 +35,20 @@ namespace SimpleGui * buttons and creates the rendering view. * @param parent the parent widget for the standard view */ - StandardView::StandardView(QWidget *parent) : ViewBase(parent), m_rebinDialog(NULL) + StandardView::StandardView(QWidget *parent) : ViewBase(parent) { this->ui.setupUi(this); this->cameraReset = false; // Set the rebin button to open a rebin dialog QObject::connect(this->ui.rebinButton, SIGNAL(clicked()), - this, SLOT(onRebinButtonClicked())); + this, SIGNAL(rebin()), Qt::QueuedConnection); + + // Set the unbinbutton to remove the rebinning on a workspace + // which was binned in the VSI + QObject::connect(this->ui.unbinButton, SIGNAL(clicked()), + this, SIGNAL(unbin()), Qt::QueuedConnection); + // Set the cut button to create a slice on the data QObject::connect(this->ui.cutButton, SIGNAL(clicked()), this, @@ -84,8 +89,14 @@ void StandardView::render() } pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder(); + if (this->isMDHistoWorkspace(this->origSrc)) + { + this->ui.rebinButton->setEnabled(false); + } + if (this->isPeaksWorkspace(this->origSrc)) { + this->ui.rebinButton->setEnabled(false); this->ui.cutButton->setEnabled(false); } @@ -121,18 +132,6 @@ void StandardView::onScaleButtonClicked() this->getPvActiveSrc()); } -void StandardView::onRebinButtonClicked() -{ - // Open the Rebin dialog - if (NULL == this->m_rebinDialog) - { - this->m_rebinDialog = new RebinDialog(this); - } - - emit rebin(m_rebinDialog); - this->m_rebinDialog->show(); -} - /** * This function is responsible for calling resetCamera if the internal * variable cameraReset has been set to true. diff --git a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp index a88b3b1010ab351315e16f8dcab85d01a0ce700e..f8437d0f9cbe2680644d1cb9e9dcc29a53922ee5 100644 --- a/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp +++ b/Code/Mantid/Vates/VatesSimpleGui/ViewWidgets/src/ViewBase.cpp @@ -258,7 +258,7 @@ pqPipelineRepresentation *ViewBase::getPvActiveRep() * @param pluginName name of the ParaView plugin * @param wsName name of the Mantid workspace to pass to the plugin */ -void ViewBase::setPluginSource(QString pluginName, QString wsName) +pqPipelineSource* ViewBase::setPluginSource(QString pluginName, QString wsName) { // Create the source from the plugin pqObjectBuilder* builder = pqApplicationCore::instance()->getObjectBuilder(); @@ -274,6 +274,8 @@ void ViewBase::setPluginSource(QString pluginName, QString wsName) srcProxy->Modified(); srcProxy->UpdatePipelineInformation(); src->updatePipeline(); + + return src; } /** @@ -309,6 +311,24 @@ void ViewBase::checkView(ModeControlWidget::Views initialView) } } +/** + * This metod sets the status of the splatterplot button explictly to a desired value + * @param visiblity The state of the the splatterplot view button. + */ +void ViewBase::setSplatterplot(bool visibility) +{ + emit this->setViewStatus(ModeControlWidget::SPLATTERPLOT, visibility); +} + +/** + * This metod sets the status of the standard view button explictly to a desired value + * @param visiblity The state of the the standard view button. + */ +void ViewBase::setStandard(bool visibility) +{ + emit this->setViewStatus(ModeControlWidget::STANDARD, visibility); +} + /** * This function sets the status for the view mode control buttons when the * view switches.