Skip to content

Commit

Permalink
Added drawing buttons to Pick tab. Rubber band shape selection.
Browse files Browse the repository at this point in the history
Re #7222.
  • Loading branch information
mantid-roman committed Jun 27, 2013
1 parent 208b9d8 commit f5493d3
Show file tree
Hide file tree
Showing 12 changed files with 178 additions and 28 deletions.
1 change: 1 addition & 0 deletions Code/Mantid/Images/images.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<file>selection-text.png</file>
<file>selection-peak.png</file>
<file>selection-peaks.png</file>
<file>selection-edit.png</file>
<file>eraser.png</file>
</qresource>
<qresource prefix="/MaskTools">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ void InputControllerDrawShape::mousePressEvent(QMouseEvent *event)
}
m_x = event->x();
m_y = event->y();
m_rect.setRect( event->x(), event->y(), 1, 1 );
}
}

Expand All @@ -189,8 +190,13 @@ void InputControllerDrawShape::mouseMoveEvent(QMouseEvent *event)
else
{
emit moveBy( event->x() - m_x, event->y() - m_y );
m_rect.setBottomRight(QPoint( event->x(), event->y() ));
m_x = event->x();
m_y = event->y();
if ( m_rect.width() > 1 || m_rect.height() > 1 )
{
emit setSelection( m_rect );
}
}
}
else
Expand All @@ -207,6 +213,10 @@ void InputControllerDrawShape::mouseReleaseEvent(QMouseEvent *)
m_isButtonPressed = false;
m_creating = false;
m_shapeType = "";
if ( m_rect.width() > 1 || m_rect.height() > 1 )
{
emit finishSelection( m_rect );
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ class InputControllerDrawShape: public InputController
void removeSelectedShapes();
/// Restore the cursor to its default image
void restoreOverrideCursor();
/// Update the rubber band selection
void setSelection(const QRect&);
/// Rubber band selection is done
void finishSelection(const QRect&);

public slots:
void startCreatingShape2D(const QString& type,const QColor& borderColor,const QColor& fillColor);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ void InstrumentWindow::setSurfaceType(int type)
tab->initSurface();
}

connect(surface,SIGNAL(multipleDetectorsSelected(QList<int>&)),this,SLOT(multipleDetectorsSelected(QList<int>&)));
//connect(surface,SIGNAL(multipleDetectorsSelected(QList<int>&)),this,SLOT(multipleDetectorsSelected(QList<int>&)));
connect(surface,SIGNAL(executeAlgorithm(Mantid::API::IAlgorithm_sptr)),this,SIGNAL(execMantidAlgorithm(Mantid::API::IAlgorithm_sptr)));
connect(surface,SIGNAL(updateInfoText()),this,SLOT(updateInfoText()),Qt::QueuedConnection);
QApplication::restoreOverrideCursor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,15 @@ m_userEditing(true)
// main layout
QVBoxLayout* layout=new QVBoxLayout(this);

m_masking_on = new QRadioButton("Mask");
m_grouping_on = new QRadioButton("Group");
m_masking_on->setChecked(true);
connect(m_masking_on,SIGNAL(toggled(bool)),this,SLOT(toggleMaskGroup(bool)));
QHBoxLayout* radioLayout = new QHBoxLayout();
radioLayout->addWidget(m_masking_on);
radioLayout->addWidget(m_grouping_on);
radioLayout->setMargin(0);
QWidget* radioGroup = new QWidget();
radioGroup->setLayout(radioLayout);

layout->addWidget(radioGroup);
m_activeTool = new QLabel(this);
layout->addWidget(m_activeTool);

// Create the tool buttons

m_move = new QPushButton();
m_move->setCheckable(true);
m_move->setAutoExclusive(true);
m_move->setIcon(QIcon(":/PickTools/selection-tube.png"));
m_move->setIcon(QIcon(":/PickTools/zoom.png"));
m_move->setToolTip("Move the instrument (Ctrl+Alt+M)");
m_move->setShortcut(QKeySequence("Ctrl+Alt+M"));

Expand Down Expand Up @@ -148,6 +138,20 @@ m_userEditing(true)

layout->addWidget(toolGroup);

// create mask/group switch
m_masking_on = new QRadioButton("Mask");
m_grouping_on = new QRadioButton("Group");
m_masking_on->setChecked(true);
connect(m_masking_on,SIGNAL(toggled(bool)),this,SLOT(toggleMaskGroup(bool)));
QHBoxLayout* radioLayout = new QHBoxLayout();
radioLayout->addWidget(m_masking_on);
radioLayout->addWidget(m_grouping_on);
radioLayout->setMargin(0);
QWidget* radioGroup = new QWidget();
radioGroup->setLayout(radioLayout);

layout->addWidget(radioGroup);

// Create property browser

/* Create property managers: they create, own properties, get and set values */
Expand Down Expand Up @@ -340,35 +344,41 @@ void InstrumentWindowMaskTab::setActivity()
{
m_activity = Move;
m_instrWindow->getSurface()->setInteractionMode(ProjectionSurface::MoveMode);
m_activeTool->setText("Tool: Navigation");
}
else if (m_pointer->isChecked())
{
m_activity = Select;
m_instrWindow->getSurface()->setInteractionMode(ProjectionSurface::DrawMode);
m_activeTool->setText("Tool: Selection");
}
else if (m_ellipse->isChecked())
{
m_activity = DrawEllipse;
m_instrWindow->getSurface()->startCreatingShape2D("ellipse",borderColor,fillColor);
m_instrWindow->getSurface()->setInteractionMode(ProjectionSurface::DrawMode);
m_activeTool->setText("Tool: Ellipse");
}
else if (m_rectangle->isChecked())
{
m_activity = DrawRectangle;
m_instrWindow->getSurface()->startCreatingShape2D("rectangle",borderColor,fillColor);
m_instrWindow->getSurface()->setInteractionMode(ProjectionSurface::DrawMode);
m_activeTool->setText("Tool: Rectangle");
}
else if (m_ring_ellipse->isChecked())
{
m_activity = DrawEllipticalRing;
m_instrWindow->getSurface()->startCreatingShape2D("ring ellipse",borderColor,fillColor);
m_instrWindow->getSurface()->setInteractionMode(ProjectionSurface::DrawMode);
m_activeTool->setText("Tool: Elliptical ring");
}
else if (m_ring_rectangle->isChecked())
{
m_activity = DrawRectangularRing;
m_instrWindow->getSurface()->startCreatingShape2D("ring rectangle",borderColor,fillColor);
m_instrWindow->getSurface()->setInteractionMode(ProjectionSurface::DrawMode);
m_activeTool->setText("Tool: Rectangular ring");
}
m_instrWindow->updateInfoText();
}
Expand Down Expand Up @@ -448,6 +458,7 @@ void InstrumentWindowMaskTab::showEvent (QShowEvent *)
m_instrWindow->setMouseTracking(true);
enableApplyButtons();
m_instrWindow->updateInstrumentView(true);
m_instrWindow->getSurface()->changeBorderColor( getShapeBorderColor() );
}

void InstrumentWindowMaskTab::clearProperties()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ protected slots:
QRadioButton* m_masking_on;
QRadioButton* m_grouping_on;

QLabel *m_activeTool; ///< Displays a tip on which tool is currently selected

// buttons
QPushButton* m_move;
QPushButton* m_pointer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,24 @@ m_freezePlot(false)
m_tube->setIcon(QIcon(":/PickTools/selection-tube.png"));
m_tube->setToolTip("Select whole tube");

m_rectangle = new QPushButton();
m_rectangle->setCheckable(true);
m_rectangle->setAutoExclusive(true);
m_rectangle->setIcon(QIcon(":/PickTools/selection-box.png"));
m_rectangle->setToolTip("Draw a rectangle");

m_ellipse = new QPushButton();
m_ellipse->setCheckable(true);
m_ellipse->setAutoExclusive(true);
m_ellipse->setIcon(QIcon(":/PickTools/selection-circle.png"));
m_ellipse->setToolTip("Draw a ellipse");

m_edit = new QPushButton();
m_edit->setCheckable(true);
m_edit->setAutoExclusive(true);
m_edit->setIcon(QIcon(":/PickTools/selection-edit.png"));
m_edit->setToolTip("Edit a shape");

m_peak = new QPushButton();
m_peak->setCheckable(true);
m_peak->setAutoExclusive(true);
Expand All @@ -172,19 +190,25 @@ m_freezePlot(false)
m_peakSelect->setIcon(QIcon(":/PickTools/eraser.png"));
m_peakSelect->setToolTip("Erase single crystal peak(s)");

QHBoxLayout* toolBox = new QHBoxLayout();
toolBox->addWidget(m_zoom);
toolBox->addWidget(m_one);
toolBox->addWidget(m_tube);
toolBox->addWidget(m_peak);
toolBox->addWidget(m_peakSelect);
toolBox->addStretch();
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->setSpacing(2);
connect(m_zoom,SIGNAL(clicked()),this,SLOT(setSelectionType()));
connect(m_one,SIGNAL(clicked()),this,SLOT(setSelectionType()));
connect(m_tube,SIGNAL(clicked()),this,SLOT(setSelectionType()));
connect(m_peak,SIGNAL(clicked()),this,SLOT(setSelectionType()));
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_edit,SIGNAL(clicked()),this,SLOT(setSelectionType()));
setSelectionType();

// lay out the widgets
Expand Down Expand Up @@ -652,6 +676,26 @@ void InstrumentWindowPickTab::setSelectionType()
m_activeTool->setText("Tool: Erase crystal peak(s)");
surfaceMode = ProjectionSurface::EraseMode;
}
else if (m_rectangle->isChecked())
{
m_selectionType = Draw;
m_activeTool->setText("Tool: Rectangle");
surfaceMode = ProjectionSurface::DrawMode;
m_instrWindow->getSurface()->startCreatingShape2D("rectangle",Qt::green,QColor(255,255,255,80));
}
else if (m_ellipse->isChecked())
{
m_selectionType = Draw;
m_activeTool->setText("Tool: Ellipse");
surfaceMode = ProjectionSurface::DrawMode;
m_instrWindow->getSurface()->startCreatingShape2D("ellipse",Qt::green,QColor(255,255,255,80));
}
else if (m_edit->isChecked())
{
m_selectionType = Draw;
m_activeTool->setText("Tool: Shape editing");
surfaceMode = ProjectionSurface::DrawMode;
}
auto surface = m_instrWindow->getSurface();
if ( surface )
{
Expand Down Expand Up @@ -757,6 +801,7 @@ void InstrumentWindowPickTab::showEvent (QShowEvent *)
setSelectionType();
// make sure picking updated
m_instrWindow->updateInstrumentView(true);
m_instrWindow->getSurface()->changeBorderColor( getShapeBorderColor() );
}

/**
Expand Down Expand Up @@ -1069,6 +1114,15 @@ QString InstrumentWindowPickTab::getNonDetectorInfo()
return text;
}

/**
* Get the color of the overlay shapes in this tab.
* @return
*/
QColor InstrumentWindowPickTab::getShapeBorderColor() const
{
return QColor( Qt::green );
}


/**
* Save data plotted on the miniplot into a MatrixWorkspace.
Expand Down Expand Up @@ -1213,6 +1267,7 @@ void InstrumentWindowPickTab::initSurface()
connect(surface,SIGNAL(singleDetectorPicked(int)),this,SLOT(singleDetectorPicked(int)));
connect(surface,SIGNAL(peaksWorkspaceAdded()),this,SLOT(updateSelectionInfoDisplay()));
connect(surface,SIGNAL(peaksWorkspaceDeleted()),this,SLOT(updateSelectionInfoDisplay()));
connect(surface,SIGNAL(shapeCreated()),this,SLOT(shapeCreated()));
}

/**
Expand Down Expand Up @@ -1271,6 +1326,12 @@ void InstrumentWindowPickTab::selectTool(const ToolType tool)
break;
case PeakErase: m_peakSelect->setChecked(true);
break;
case DrawRectangle: m_rectangle->setChecked(true);
break;
case DrawEllipse: m_ellipse->setChecked(true);
break;
case EditShape: m_edit->setChecked(true);
break;
default: throw std::invalid_argument("Invalid tool type.");
}
setSelectionType();
Expand Down Expand Up @@ -1300,3 +1361,11 @@ void InstrumentWindowPickTab::updateSelectionInfoDisplay()
updateSelectionInfo(m_currentDetID);
}

/**
* Respond to the shapeCreated signal from the surface.
*/
void InstrumentWindowPickTab::shapeCreated()
{
selectTool( EditShape );
}

Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ class InstrumentWindowPickTab: public InstrumentWindowTab
/// a peak to the attached peaks workspace
/// SelectPeak: click on a peak marker or draw a rubber-band selector to select peak
/// markers. Selected peaks can be deleted by pressing the Delete key.
enum SelectionType {Single=0,AddPeak,ErasePeak,SingleDetectorSelection,Tube};
enum ToolType {Zoom,PixelSelect,TubeSelect,PeakSelect,PeakErase};
enum SelectionType {Single=0,AddPeak,ErasePeak,SingleDetectorSelection,Tube, Draw};
enum ToolType {Zoom,PixelSelect,TubeSelect,PeakSelect,PeakErase, DrawEllipse, DrawRectangle, EditShape};
enum TubeXUnits {DETECTOR_ID = 0,LENGTH,PHI,NUMBER_OF_UNITS};

InstrumentWindowPickTab(InstrumentWindow* instrWindow);
Expand Down Expand Up @@ -73,6 +73,7 @@ private slots:
void singleDetectorTouched(int detid);
void singleDetectorPicked(int detid);
void updateSelectionInfoDisplay();
void shapeCreated();
private:
void showEvent (QShowEvent *);
void updatePlot(int detid);
Expand Down Expand Up @@ -101,6 +102,7 @@ private slots:
TubeXUnits getTubeXUnits(const QString& name) const;
QString getTubeXUnitsName(TubeXUnits unit) const;
QString getNonDetectorInfo();
QColor getShapeBorderColor() const;

/* Pick tab controls */
OneCurvePlot* m_plot; ///< Miniplot to display data in the detectors
Expand All @@ -110,6 +112,9 @@ private slots:
QPushButton *m_tube; ///< Button switching on detector's parent selection mode
QPushButton *m_peak; ///< Button switching on peak creation mode
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
bool m_plotSum;

// Actions to set integration option for the detector's parent selection mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ ProjectionSurface::ProjectionSurface(const InstrumentActor* rootActor,const Mant
connect(drawController,SIGNAL(removeSelectedShapes()),&m_maskShapes,SLOT(removeSelectedShapes()));
connect(drawController,SIGNAL(deselectAll()),&m_maskShapes,SLOT(deselectAll()));
connect(drawController,SIGNAL(restoreOverrideCursor()),&m_maskShapes,SLOT(restoreOverrideCursor()));
connect(drawController,SIGNAL(setSelection(QRect)),this,SLOT(setSelectionRect(QRect)));
connect(drawController,SIGNAL(finishSelection(QRect)),this,SLOT(selectMultipleMasks(QRect)));

// create and connect the peak eraser controller
InputControllerErase* eraseController = new InputControllerErase(this);
Expand Down Expand Up @@ -699,7 +701,10 @@ void ProjectionSurface::setShowPeakLabelsFlag(bool on)
*/
void ProjectionSurface::setSelectionRect(const QRect &rect)
{
m_selectRect = rect;
if ( m_interactionMode != DrawMode || !m_maskShapes.hasSelection() )
{
m_selectRect = rect;
}
}

/**
Expand All @@ -721,6 +726,19 @@ void ProjectionSurface::selectMultipleDetectors()
emptySelectionRect();
}

/**
* Select multiple mask shapes as a result of a rubber-band selection
* @param rect :: The rubber band rect.
*/
void ProjectionSurface::selectMultipleMasks(const QRect &rect)
{
if ( !m_maskShapes.hasSelection() )
{
m_maskShapes.selectIn( rect );
}
emptySelectionRect();
}

/**
* Pick a detector at a pointe on the screen.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ protected slots:
void setSelectionRect(const QRect& rect);
void emptySelectionRect();
void selectMultipleDetectors();
void selectMultipleMasks(const QRect& rect);
void pickDetectorAt(int x,int y);
void touchDetectorAt(int x,int y);
void erasePeaks(const QRect& rect);
Expand Down

0 comments on commit f5493d3

Please sign in to comment.