Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
a514007b
Commit
a514007b
authored
Dec 09, 2016
by
Samuel Jackson
Browse files
Refs #18240 Add a way to export mask shapes from the instrument view.
parent
fce10fa7
Changes
7
Hide whitespace changes
Inline
Side-by-side
MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/InstrumentView/InstrumentWidgetMaskTab.h
View file @
a514007b
...
...
@@ -95,6 +95,7 @@ protected slots:
void
storeBinMask
();
void
storeMask
();
void
clearMask
();
void
saveShapesToTable
()
const
;
void
saveInvertedMaskToWorkspace
();
void
saveInvertedMaskToFile
();
void
saveMaskToWorkspace
();
...
...
@@ -165,6 +166,7 @@ protected:
QPushButton
*
m_applyToData
;
QPushButton
*
m_applyToView
;
QPushButton
*
m_saveShapesToTable
;
QPushButton
*
m_clearAll
;
QPushButton
*
m_saveButton
;
bool
m_maskBins
;
...
...
MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/InstrumentView/ProjectionSurface.h
View file @
a514007b
...
...
@@ -227,6 +227,10 @@ public:
void
changeBorderColor
(
const
QColor
&
color
)
{
m_maskShapes
.
changeBorderColor
(
color
);
}
/// Save masks to a table workspace
void
saveShapesToTableWorkspace
();
/// Load masks from a table workspace
void
loadShapesFromTableWorkspace
(
Mantid
::
API
::
ITableWorkspace_const_sptr
ws
);
//-----------------------------------
// Peaks overlay methods
...
...
MantidQt/MantidWidgets/inc/MantidQtMantidWidgets/InstrumentView/Shape2DCollection.h
View file @
a514007b
#ifndef MANTIDPLOT_SHAPE2DCOLLECTION_H_
#define MANTIDPLOT_SHAPE2DCOLLECTION_H_
#include
"MantidAPI/ITableWorkspace.h"
#include
"Shape2D.h"
#include
"RectF.h"
...
...
@@ -85,6 +87,10 @@ public:
/// Change border color of all shapes.
void
changeBorderColor
(
const
QColor
&
color
);
/// Save shape collection to a Table workspace
void
saveToTableWorkspace
();
/// Load shape collectio from a Table workspace
void
loadFromTableWorkspace
(
Mantid
::
API
::
ITableWorkspace_const_sptr
ws
);
/// Load settings for the shape 2D collection from a project file
virtual
void
loadFromProject
(
const
std
::
string
&
lines
);
/// Save settings for the shape 2D collection to a project file
...
...
MantidQt/MantidWidgets/src/InstrumentView/InstrumentWidget.cpp
View file @
a514007b
...
...
@@ -945,7 +945,8 @@ bool InstrumentWidget::overlay(const QString &wsName) {
}
auto
pws
=
boost
::
dynamic_pointer_cast
<
IPeaksWorkspace
>
(
workspace
);
if
(
!
pws
)
{
auto
table
=
boost
::
dynamic_pointer_cast
<
ITableWorkspace
>
(
workspace
);
if
(
!
pws
&&
!
table
)
{
QMessageBox
::
warning
(
this
,
"MantidPlot - Warning"
,
"Work space called '"
+
wsName
+
"' is not suitable."
...
...
@@ -965,7 +966,12 @@ bool InstrumentWidget::overlay(const QString &wsName) {
surface
->
setPeaksWorkspace
(
pws
);
updateInstrumentView
();
success
=
true
;
}
else
if
(
table
&&
surface
)
{
surface
->
loadShapesFromTableWorkspace
(
table
);
updateInstrumentView
();
success
=
true
;
}
return
success
;
}
...
...
MantidQt/MantidWidgets/src/InstrumentView/InstrumentWidgetMaskTab.cpp
View file @
a514007b
...
...
@@ -200,6 +200,12 @@ InstrumentWidgetMaskTab::InstrumentWidgetMaskTab(InstrumentWidget *instrWidget)
m_applyToView
->
setToolTip
(
"Apply current mask to the view."
);
connect
(
m_applyToView
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
applyMaskToView
()));
m_saveShapesToTable
=
new
QPushButton
(
"Save Shapes to Table"
);
m_saveShapesToTable
->
setToolTip
(
"Store the current Mask/ROI/Group shapes as a table"
);
connect
(
m_saveShapesToTable
,
SIGNAL
(
clicked
()),
this
,
SLOT
(
saveShapesToTable
()));
m_clearAll
=
new
QPushButton
(
"Clear All"
);
m_clearAll
->
setToolTip
(
"Clear all masking that have not been applied to the data."
);
...
...
@@ -313,8 +319,9 @@ InstrumentWidgetMaskTab::InstrumentWidgetMaskTab(InstrumentWidget *instrWidget)
QGroupBox
*
box
=
new
QGroupBox
(
"View"
);
QGridLayout
*
buttons
=
new
QGridLayout
();
buttons
->
addWidget
(
m_applyToView
,
0
,
0
,
1
,
2
);
buttons
->
addWidget
(
m_saveButton
,
1
,
0
);
buttons
->
addWidget
(
m_clearAll
,
1
,
1
);
buttons
->
addWidget
(
m_saveShapesToTable
,
1
,
0
,
1
,
2
);
buttons
->
addWidget
(
m_saveButton
,
2
,
0
);
buttons
->
addWidget
(
m_clearAll
,
2
,
1
);
box
->
setLayout
(
buttons
);
layout
->
addWidget
(
box
);
...
...
@@ -578,6 +585,13 @@ void InstrumentWidgetMaskTab::setProperties() {
shapeChanged
();
}
/**
* Save shapes to a table workspace
*/
void
InstrumentWidgetMaskTab
::
saveShapesToTable
()
const
{
m_instrWidget
->
getSurface
()
->
saveShapesToTableWorkspace
();
}
void
InstrumentWidgetMaskTab
::
doubleChanged
(
QtProperty
*
prop
)
{
if
(
!
m_userEditing
)
return
;
...
...
MantidQt/MantidWidgets/src/InstrumentView/ProjectionSurface.cpp
View file @
a514007b
...
...
@@ -593,6 +593,22 @@ void ProjectionSurface::startCreatingFreeShape(const QColor &borderColor,
emit
signalToStartCreatingFreeShape
(
borderColor
,
fillColor
);
}
/**
* Save shapes drawn on the view to a table workspace
*/
void
ProjectionSurface
::
saveShapesToTableWorkspace
()
{
m_maskShapes
.
saveToTableWorkspace
();
}
/**
* Load shapes from a table workspace on to the view.
* @param ws :: table workspace to load shapes from
*/
void
ProjectionSurface
::
loadShapesFromTableWorkspace
(
Mantid
::
API
::
ITableWorkspace_const_sptr
ws
)
{
m_maskShapes
.
loadFromTableWorkspace
(
ws
);
}
/**
* Return a combined list of peak parkers from all overlays
* @param detID :: The detector ID of interest
...
...
MantidQt/MantidWidgets/src/InstrumentView/Shape2DCollection.cpp
View file @
a514007b
#include
"MantidQtMantidWidgets/InstrumentView/Shape2DCollection.h"
#include
"MantidAPI/AnalysisDataService.h"
#include
"MantidAPI/ITableWorkspace.h"
#include
"MantidAPI/TableRow.h"
#include
"MantidAPI/WorkspaceFactory.h"
#include
<QPainter>
#include
<QMouseEvent>
...
...
@@ -621,6 +625,56 @@ void Shape2DCollection::changeBorderColor(const QColor &color) {
foreach
(
Shape2D
*
shape
,
m_shapes
)
{
shape
->
setColor
(
color
);
}
}
/**
* Save this shape collection to a table workspace
*
* This will create a table workspace called MaskShapes with one column for the
* index of the shape and one containing the serialised parameters of the shape
*/
void
Shape2DCollection
::
saveToTableWorkspace
()
{
using
namespace
Mantid
::
API
;
auto
table
=
WorkspaceFactory
::
Instance
().
createTable
();
table
->
addColumn
(
"str"
,
"Index"
);
table
->
addColumn
(
"str"
,
"Parameters"
);
size_t
count
=
0
;
for
(
auto
shape
:
m_shapes
)
{
auto
shapeStr
=
shape
->
saveToProject
();
TableRow
row
=
table
->
appendRow
();
row
<<
std
::
to_string
(
count
)
<<
shapeStr
;
++
count
;
}
AnalysisDataService
::
Instance
().
addOrReplace
(
"MaskShapes"
,
table
);
}
/**
* Load a collection of shapes from a table workspace
*
* This expects a table workspace with a column called parameters from which to
* load collection of shapes from.
*
* @param ws :: table workspace to load shapes from.
*/
void
Shape2DCollection
::
loadFromTableWorkspace
(
Mantid
::
API
::
ITableWorkspace_const_sptr
ws
)
{
using
namespace
Mantid
::
API
;
auto
columnNames
=
ws
->
getColumnNames
();
// Check if the column exists
if
(
std
::
find
(
columnNames
.
cbegin
(),
columnNames
.
cend
(),
"Parameters"
)
==
columnNames
.
cend
())
return
;
ConstColumnVector
<
std
::
string
>
col
=
ws
->
getVector
(
"Parameters"
);
for
(
size_t
i
=
0
;
i
<
ws
->
rowCount
();
++
i
)
{
const
auto
params
=
col
[
i
];
auto
shape
=
Shape2D
::
loadFromProject
(
params
);
m_shapes
.
append
(
shape
);
}
emit
shapeCreated
();
}
/**
* Add a Shape2D object allowing free drawing.
* @param poly :: Initial shape.
...
...
@@ -672,7 +726,8 @@ void Shape2DCollection::loadFromProject(const std::string &lines) {
API
::
TSVSerialiser
tsv
(
lines
);
for
(
auto
shapeLines
:
tsv
.
sections
(
"shape"
))
{
Shape2D
*
shape
=
Shape2D
::
loadFromProject
(
shapeLines
);
addShape
(
shape
,
false
);
m_shapes
.
push_back
(
shape
);
emit
shapeCreated
();
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment