diff --git a/Code/Mantid/Images/images.qrc b/Code/Mantid/Images/images.qrc index ea165a279b523e88d264589dbbe00c9827656c48..ff93a66fa5294897a77f4c261a0269e69343fdfc 100644 --- a/Code/Mantid/Images/images.qrc +++ b/Code/Mantid/Images/images.qrc @@ -11,20 +11,21 @@ <file>Mantid_Logo_Transparent.png</file> <file>data_replace.png</file> <file>panning.png</file> - </qresource> + </qresource> <qresource prefix="/win"> - <file>folder-remote.png</file> - <file>folder.png</file> - <file>document.png</file> - <file>office-document.png</file> - <file>txt_file.png</file> - <file>text-x-python.png</file> - <file>unknown.png</file> - <file>download.png</file> - <file>upload.png</file> - <file>system-software-update.png</file> - <file>dialog-ok.png</file> - <file>file_pdf.png</file> + <file>folder-remote.png</file> + <file>folder.png</file> + <file>document.png</file> + <file>office-document.png</file> + <file>txt_file.png</file> + <file>text-x-python.png</file> + <file>unknown.png</file> + <file>download.png</file> + <file>upload.png</file> + <file>system-software-update.png</file> + <file>dialog-ok.png</file> + <file>file_pdf.png</file> + <file>selection-circle-ring.png</file> </qresource> <qresource prefix="/Icons"> <file>LoadFile.png</file> @@ -43,5 +44,7 @@ <file>selection-pointer.png</file> <file>selection-circle.png</file> <file>selection-box.png</file> + <file>selection-box-ring.png</file> + <file>selection-circle-ring.png</file> </qresource> </RCC> diff --git a/Code/Mantid/Images/selection-box-ring.png b/Code/Mantid/Images/selection-box-ring.png new file mode 100644 index 0000000000000000000000000000000000000000..1e31d0f6c1c570eecea397ea66d87c284dbf4f97 Binary files /dev/null and b/Code/Mantid/Images/selection-box-ring.png differ diff --git a/Code/Mantid/Images/selection-circle-ring.png b/Code/Mantid/Images/selection-circle-ring.png new file mode 100644 index 0000000000000000000000000000000000000000..2bfd7e7f690194f874f85ded0dd750df14df9b37 Binary files /dev/null and b/Code/Mantid/Images/selection-circle-ring.png differ diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp index 399b639d47421b5ae3d25e3ad911f602a2e2c053..d2dfc7b556d0ee830cbad7de9f874cfb89077344 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp @@ -42,6 +42,7 @@ #include <QMessageBox> #include <QApplication> #include <QFileDialog> +#include <QToolTip> #include "MantidQtAPI/FileDialogHandler.h" @@ -88,13 +89,13 @@ m_userEditing(true) m_ring_ellipse = new QPushButton(); m_ring_ellipse->setCheckable(true); m_ring_ellipse->setAutoExclusive(true); - m_ring_ellipse->setIcon(QIcon(":/MaskTools/selection-circle.png")); + m_ring_ellipse->setIcon(QIcon(":/MaskTools/selection-circle-ring.png")); m_ring_ellipse->setToolTip("Draw an elliptical ring"); m_ring_rectangle = new QPushButton(); m_ring_rectangle->setCheckable(true); m_ring_rectangle->setAutoExclusive(true); - m_ring_rectangle->setIcon(QIcon(":/MaskTools/selection-box.png")); + m_ring_rectangle->setIcon(QIcon(":/MaskTools/selection-box-ring.png")); m_ring_rectangle->setToolTip("Draw a rectangular ring "); QHBoxLayout* toolBox = new QHBoxLayout(); @@ -136,7 +137,7 @@ m_userEditing(true) // Algorithm buttons - m_apply = new QPushButton("Apply"); + m_apply = new QPushButton("Apply Mask(s) to Workspace(data)"); m_apply->setToolTip("Apply current mask to the data workspace. Cannot be reverted."); connect(m_apply,SIGNAL(clicked()),this,SLOT(applyMask())); @@ -145,30 +146,47 @@ m_userEditing(true) connect(m_clear_all,SIGNAL(clicked()),this,SLOT(clearMask())); m_save_as_workspace_exclude = new QAction("As Mask to workspace",this); + m_save_as_workspace_exclude->setToolTip("Save current mask to mask workspace."); connect(m_save_as_workspace_exclude,SIGNAL(activated()),this,SLOT(saveMaskToWorkspace())); m_save_as_workspace_include = new QAction("As ROI to workspace",this); + m_save_as_workspace_include->setToolTip("Save current mask as ROI to mask workspace."); connect(m_save_as_workspace_include,SIGNAL(activated()),this,SLOT(saveInvertedMaskToWorkspace())); m_save_as_file_exclude = new QAction("As Mask to file",this); + m_save_as_file_exclude->setToolTip("Save current mask to mask file."); connect(m_save_as_file_exclude,SIGNAL(activated()),this,SLOT(saveMaskToFile())); m_save_as_file_include = new QAction("As ROI to file",this); + m_save_as_file_include->setToolTip("Save current mask as ROI to mask file."); connect(m_save_as_file_include,SIGNAL(activated()),this,SLOT(saveInvertedMaskToFile())); + m_save_as_cal_file_exclude = new QAction("As Mask to cal file",this); + m_save_as_cal_file_exclude->setToolTip("Save current mask to cal file."); + connect(m_save_as_cal_file_exclude,SIGNAL(activated()),this,SLOT(saveMaskToCalFile())); + + m_save_as_cal_file_include = new QAction("As ROI to cal file",this); + m_save_as_cal_file_include->setToolTip("Save current mask as ROI to cal file."); + connect(m_save_as_cal_file_include,SIGNAL(activated()),this,SLOT(saveInvertedMaskToCalFile())); + m_saveButton = new QPushButton("Save"); m_saveButton->setToolTip("Save current masking to a file or a workspace."); QMenu* saveMenu = new QMenu(this); saveMenu->addAction(m_save_as_workspace_include); saveMenu->addAction(m_save_as_workspace_exclude); + saveMenu->addSeparator(); saveMenu->addAction(m_save_as_file_include); saveMenu->addAction(m_save_as_file_exclude); + saveMenu->addSeparator(); + saveMenu->addAction(m_save_as_cal_file_include); + saveMenu->addAction(m_save_as_cal_file_exclude); + connect(saveMenu,SIGNAL(hovered(QAction*)),this,SLOT(showSaveMenuTooltip(QAction*))); m_saveButton->setMenu(saveMenu); QGridLayout* buttons = new QGridLayout(); - buttons->addWidget(m_apply,0,0); - buttons->addWidget(m_clear_all,0,1); - buttons->addWidget(m_saveButton,1,0,1,2); + buttons->addWidget(m_apply,0,0,1,2); + buttons->addWidget(m_saveButton,1,0); + buttons->addWidget(m_clear_all,1,1); layout->addLayout(buttons); @@ -453,7 +471,22 @@ void InstrumentWindowMaskTab::saveInvertedMaskToFile() void InstrumentWindowMaskTab::saveMaskToFile() { - saveMaskingToFile(false); + saveMaskingToFile(false); +} + +void InstrumentWindowMaskTab::saveMaskToCalFile() +{ + saveMaskingToCalFile(false); +} + +void InstrumentWindowMaskTab::saveInvertedMaskToCalFile() +{ + saveMaskingToCalFile(true); +} + +void InstrumentWindowMaskTab::showSaveMenuTooltip(QAction *action) +{ + QToolTip::showText(QCursor::pos(),action->toolTip(),this); } /** @@ -507,6 +540,41 @@ void InstrumentWindowMaskTab::saveMaskingToFile(bool invertMask) QApplication::restoreOverrideCursor(); } +/** + * Save the constructed mask to a cal file. + * The mask is not applied to the data workspace being displayed. + * @param invertMask :: if true, the selected mask will be inverted; if false, the mask will be used as is + */ +void InstrumentWindowMaskTab::saveMaskingToCalFile(bool invertMask) +{ + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); + + // Make sure we have stored the Mask in the helper MaskWorkspace + storeMask(); + + setSelectActivity(); + Mantid::API::MatrixWorkspace_sptr outputWS = createMaskWorkspace(false,true); + if (outputWS) + { + clearShapes(); + QString saveDir = QString::fromStdString(Mantid::Kernel::ConfigService::Instance().getString("defaultsave.directory")); + QString fileName = QFileDialog::getSaveFileName(m_instrWindow,"Select location and name for the mask file",saveDir,"cal files (*.cal)"); + + std::cerr << "File " << fileName.toStdString() << std::endl; + + if (!fileName.isEmpty()) + { + Mantid::API::IAlgorithm_sptr alg = Mantid::API::AlgorithmManager::Instance().create("MaskWorkspaceToCalFile",-1); + alg->setPropertyValue("InputWorkspace",outputWS->name()); + alg->setPropertyValue("OutputFile",fileName.toStdString()); + alg->setProperty("Invert",invertMask); + alg->execute(); + } + Mantid::API::AnalysisDataService::Instance().remove( outputWS->name() ); + } + QApplication::restoreOverrideCursor(); +} + /** * Generate a unique name for the mask worspace which will be saved in the ADS. * It will have a form MaskWorkspace[_#] diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.h index cc6f79bbc5ba0f9dae1e75ee05fdacf8c4eed713..be27b529557c6ced6e11cc8f0135b99d2f96d56f 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.h @@ -65,6 +65,9 @@ protected slots: void saveInvertedMaskToFile(); void saveMaskToWorkspace(); void saveMaskToFile(); + void saveMaskToCalFile(); + void saveInvertedMaskToCalFile(); + void showSaveMenuTooltip(QAction*); void doubleChanged(QtProperty*); protected: @@ -75,6 +78,7 @@ protected: boost::shared_ptr<Mantid::API::MatrixWorkspace> createMaskWorkspace(bool invertMask, bool temp = false); void saveMaskingToWorkspace(bool invertMask = false); void saveMaskingToFile(bool invertMask = false); + void saveMaskingToCalFile(bool invertMask = false); std::string generateMaskWorkspaceName(bool temp = false) const; void enableApply(bool on); void enableClear(bool on); @@ -101,6 +105,8 @@ protected: QAction* m_save_as_workspace_exclude; QAction* m_save_as_file_include; QAction* m_save_as_file_exclude; + QAction* m_save_as_cal_file_include; + QAction* m_save_as_cal_file_exclude; // properties bool m_userEditing;