From c6936e90120fcd525ccb4cfe8392f48ce12f17b6 Mon Sep 17 00:00:00 2001 From: Roman Tolchenov <roman.tolchenov@stfc.ac.uk> Date: Tue, 2 Jul 2013 16:56:26 +0100 Subject: [PATCH] Added the ring shapes. Fixed ellipse's contains method. Re #7222 --- Code/Mantid/Images/images.qrc | 6 +- .../InstrumentWindowMaskTab.cpp | 4 +- .../InstrumentWindowPickTab.cpp | 84 +++++++++++++++---- .../InstrumentWindowPickTab.h | 4 +- .../src/Mantid/InstrumentWidget/Shape2D.cpp | 1 + 5 files changed, 80 insertions(+), 19 deletions(-) diff --git a/Code/Mantid/Images/images.qrc b/Code/Mantid/Images/images.qrc index 31d6235c605..c2dd9c350dc 100644 --- a/Code/Mantid/Images/images.qrc +++ b/Code/Mantid/Images/images.qrc @@ -24,7 +24,7 @@ <file>upload.png</file> <file>system-software-update.png</file> <file>dialog-ok.png</file> - <file>running_process.png</file> + <file>running_process.png</file> <file>file_pdf.png</file> <file>selection-circle-ring.png</file> </qresource> @@ -42,12 +42,14 @@ <file>selection-peaks.png</file> <file>selection-edit.png</file> <file>eraser.png</file> + <file>selection-box-ring.png</file> + <file>selection-circle-ring.png</file> </qresource> <qresource prefix="/MaskTools"> - <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> + <file>selection-edit.png</file> </qresource> </RCC> diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp index 43451d4f2f1..ef2c5b6ff12 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowMaskTab.cpp @@ -83,7 +83,7 @@ m_userEditing(true) m_pointer = new QPushButton(); m_pointer->setCheckable(true); m_pointer->setAutoExclusive(true); - m_pointer->setIcon(QIcon(":/MaskTools/selection-pointer.png")); + m_pointer->setIcon(QIcon(":/MaskTools/selection-edit.png")); m_pointer->setToolTip("Select and edit shapes (Ctrl+Alt+P)"); m_pointer->setShortcut(QKeySequence("Ctrl+Alt+P")); @@ -350,7 +350,7 @@ void InstrumentWindowMaskTab::setActivity() { m_activity = Select; m_instrWindow->getSurface()->setInteractionMode(ProjectionSurface::DrawMode); - m_activeTool->setText("Tool: Selection"); + m_activeTool->setText("Tool: Shape editing"); } else if (m_ellipse->isChecked()) { diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp index 667de3c210a..23ab082c1a4 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.cpp @@ -39,6 +39,7 @@ #include <QSignalMapper> #include <QPixmap> #include <QSettings> +#include <QApplication> #include <numeric> #include <cfloat> @@ -172,6 +173,18 @@ m_freezePlot(false) m_ellipse->setIcon(QIcon(":/PickTools/selection-circle.png")); m_ellipse->setToolTip("Draw a ellipse"); + m_ring_ellipse = new QPushButton(); + m_ring_ellipse->setCheckable(true); + m_ring_ellipse->setAutoExclusive(true); + m_ring_ellipse->setIcon(QIcon(":/PickTools/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(":/PickTools/selection-box-ring.png")); + m_ring_rectangle->setToolTip("Draw a rectangular ring"); + m_edit = new QPushButton(); m_edit->setCheckable(true); m_edit->setAutoExclusive(true); @@ -192,14 +205,16 @@ m_freezePlot(false) QGridLayout* toolBox = new QGridLayout(); toolBox->addWidget(m_zoom,0,0); - toolBox->addWidget(m_one,0,1); - toolBox->addWidget(m_tube,0,2); - toolBox->addWidget(m_peak,0,3); - toolBox->addWidget(m_peakSelect,0,4); - toolBox->addWidget(m_edit,1,0); - toolBox->addWidget(m_ellipse,1,1); - toolBox->addWidget(m_rectangle,1,2); - toolBox->setColStretch(5,1); + toolBox->addWidget(m_edit,0,1); + toolBox->addWidget(m_ellipse,0,2); + toolBox->addWidget(m_rectangle,0,3); + toolBox->addWidget(m_ring_ellipse,0,4); + toolBox->addWidget(m_ring_rectangle,0,5); + toolBox->addWidget(m_one,1,0); + toolBox->addWidget(m_tube,1,1); + toolBox->addWidget(m_peak,1,2); + toolBox->addWidget(m_peakSelect,1,3); + toolBox->setColStretch(6,1); toolBox->setSpacing(2); connect(m_zoom,SIGNAL(clicked()),this,SLOT(setSelectionType())); connect(m_one,SIGNAL(clicked()),this,SLOT(setSelectionType())); @@ -208,6 +223,8 @@ m_freezePlot(false) connect(m_peakSelect,SIGNAL(clicked()),this,SLOT(setSelectionType())); connect(m_rectangle,SIGNAL(clicked()),this,SLOT(setSelectionType())); connect(m_ellipse,SIGNAL(clicked()),this,SLOT(setSelectionType())); + connect(m_ring_ellipse,SIGNAL(clicked()),this,SLOT(setSelectionType())); + connect(m_ring_rectangle,SIGNAL(clicked()),this,SLOT(setSelectionType())); connect(m_edit,SIGNAL(clicked()),this,SLOT(setSelectionType())); setSelectionType(); @@ -371,7 +388,16 @@ void InstrumentWindowPickTab::plotContextMenu() if (m_selectionType > SingleDetectorSelection) {// only for multiple detector selectors context.addActions(m_summationType->actions()); - m_sumDetectors->setChecked(m_plotSum); + if ( m_selectionType == Draw ) + { + m_sumDetectors->setChecked(true); + m_integrateTimeBins->setEnabled(false); + } + else + { + m_sumDetectors->setChecked(m_plotSum); + m_integrateTimeBins->setEnabled(true); + } context.addSeparator(); } @@ -641,6 +667,20 @@ void InstrumentWindowPickTab::setSelectionType() surfaceMode = ProjectionSurface::DrawMode; m_instrWindow->getSurface()->startCreatingShape2D("ellipse",Qt::green,QColor(255,255,255,80)); } + else if (m_ring_ellipse->isChecked()) + { + m_selectionType = Draw; + m_activeTool->setText("Tool: Elliptical ring"); + surfaceMode = ProjectionSurface::DrawMode; + m_instrWindow->getSurface()->startCreatingShape2D("ring ellipse",Qt::green,QColor(255,255,255,80)); + } + else if (m_ring_rectangle->isChecked()) + { + m_selectionType = Draw; + m_activeTool->setText("Tool: Rectangular ring"); + surfaceMode = ProjectionSurface::DrawMode; + m_instrWindow->getSurface()->startCreatingShape2D("ring rectangle",Qt::green,QColor(255,255,255,80)); + } else if (m_edit->isChecked()) { m_selectionType = Draw; @@ -652,9 +692,16 @@ void InstrumentWindowPickTab::setSelectionType() { surface->setInteractionMode( surfaceMode ); } - m_plot->clearAll(); - m_plot->replot(); - setPlotCaption(); + if ( m_selectionType != Draw ) + { + m_plot->clearAll(); + m_plot->replot(); + setPlotCaption(); + } + else + { + updatePlotMultipleDetectors(); + } m_instrWindow->updateInfoText(); } @@ -1104,7 +1151,14 @@ void InstrumentWindowPickTab::savePlotToWorkspace() std::vector<double> x,y,e; // split the label to get the detector id and selection type QStringList parts = label.split(QRegExp("[()]")); - if (parts.size() == 3) + if ( label == "multiple" ) + { + QList<int> dets; + getSurface()->getMaskedDetectors( dets ); + m_instrWindow->getInstrumentActor()->sumDetectors( dets, x, y ); + unitX = parentWorkspace->getAxis(0)->unit()->unitID(); + } + else if (parts.size() == 3) { int detid = parts[1].toInt(); QString SumOrIntegral = parts[2].trimmed(); @@ -1285,7 +1339,6 @@ void InstrumentWindowPickTab::selectTool(const ToolType tool) case DrawEllipse: m_ellipse->setChecked(true); break; case EditShape: m_edit->setChecked(true); - updatePlotMultipleDetectors(); break; default: throw std::invalid_argument("Invalid tool type."); } @@ -1332,12 +1385,15 @@ void InstrumentWindowPickTab::updatePlotMultipleDetectors() QList<int> dets; getSurface()->getMaskedDetectors( dets ); std::vector<double> x,y; + QApplication::setOverrideCursor(QCursor(Qt::WaitCursor)); m_instrWindow->getInstrumentActor()->sumDetectors( dets, x, y ); + QApplication::restoreOverrideCursor(); m_plot->clearAll(); if ( !x.empty() ) { m_plot->setData(&x[0],&y[0],static_cast<int>(y.size()), m_instrWindow->getInstrumentActor()->getWorkspace()->getAxis(0)->unit()->unitID()); } + m_plot->setLabel("multiple"); m_plot->replot(); } diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h index cc9823023d3..14f78c7b215 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/InstrumentWindowPickTab.h @@ -113,7 +113,9 @@ private: QPushButton *m_peakSelect; ///< Button switching on peak selection mode QPushButton *m_rectangle; ///< Button switching on drawing a rectangular selection region QPushButton *m_ellipse; ///< Button switching on drawing a elliptical selection region - QPushButton *m_edit; ///< Button switching on edditing the selection region + QPushButton *m_ring_ellipse; ///< Button switching on drawing a elliptical ring selection region + QPushButton *m_ring_rectangle; ///< Button switching on drawing a rectangular ring selection region + QPushButton *m_edit; ///< Button switching on edditing the selection region bool m_plotSum; // Actions to set integration option for the detector's parent selection mode diff --git a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2D.cpp b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2D.cpp index accfcfe3df7..9543dcdaf28 100644 --- a/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2D.cpp +++ b/Code/Mantid/MantidPlot/src/Mantid/InstrumentWidget/Shape2D.cpp @@ -219,6 +219,7 @@ bool Shape2DEllipse::selectAt(const QPointF& p)const bool Shape2DEllipse::contains(const QPointF& p)const { + if ( m_boundingRect.isEmpty() ) return false; QPointF pp = m_boundingRect.center() - p; double a = m_boundingRect.xSpan() / 2; if (a == 0.0) a = 1.0; -- GitLab