Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
mantidproject
mantid
Commits
0416169c
Commit
0416169c
authored
Sep 14, 2021
by
Whitfield, Ross
Browse files
Fix InstrumentWidget Encoder/Decoder for new rotation property
parent
f8b9e0ad
Changes
6
Hide whitespace changes
Inline
Side-by-side
qt/widgets/instrumentview/inc/MantidQtWidgets/InstrumentView/ProjectionSurface.h
View file @
0416169c
...
...
@@ -174,20 +174,14 @@ public:
/// Return bounding rotation of the currently selected shape in the "original"
/// coord system.
/// It doesn't depend on the zooming of the surface
double
getCurrentBoundingRotation
()
const
{
return
m_maskShapes
.
getCurrentBoundingRotation
();
}
double
getCurrentBoundingRotation
()
const
{
return
m_maskShapes
.
getCurrentBoundingRotation
();
}
/// Set new bounding rect of the currently selected shape in the "original"
/// coord system.
/// This method resizes the shape to fit into the new rectangle.
void
setCurrentBoundingRotation
(
const
double
rotation
)
{
m_maskShapes
.
setCurrentBoundingRotation
(
rotation
);
}
void
setCurrentBoundingRotation
(
const
double
rotation
)
{
m_maskShapes
.
setCurrentBoundingRotation
(
rotation
);
}
std
::
string
getCurrentShapeType
()
const
{
return
m_maskShapes
.
getCurrentShapeType
();
}
std
::
string
getCurrentShapeType
()
const
{
return
m_maskShapes
.
getCurrentShapeType
();
}
/// Initialize interactive shape creation.
/// @param type :: Type of the shape. For available types see code of
...
...
qt/widgets/instrumentview/inc/MantidQtWidgets/InstrumentView/Shape2DCollection.h
View file @
0416169c
...
...
@@ -99,8 +99,7 @@ public:
/// Save shape collection to a Table workspace
void
saveToTableWorkspace
();
/// Load shape collectio from a Table workspace
void
loadFromTableWorkspace
(
const
Mantid
::
API
::
ITableWorkspace_const_sptr
&
ws
);
void
loadFromTableWorkspace
(
const
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
...
...
@@ -117,10 +116,8 @@ signals:
void
cleared
();
public
slots
:
void
addShape
(
const
QString
&
type
,
int
x
,
int
y
,
const
QColor
&
borderColor
,
const
QColor
&
fillColor
);
void
addFreeShape
(
const
QPolygonF
&
/*poly*/
,
const
QColor
&
borderColor
,
const
QColor
&
fillColor
);
void
addShape
(
const
QString
&
type
,
int
x
,
int
y
,
const
QColor
&
borderColor
,
const
QColor
&
fillColor
);
void
addFreeShape
(
const
QPolygonF
&
/*poly*/
,
const
QColor
&
borderColor
,
const
QColor
&
fillColor
);
void
deselectAll
();
void
moveRightBottomTo
(
int
/*x*/
,
int
/*y*/
);
void
selectShapeOrControlPointAt
(
int
x
,
int
y
);
...
...
@@ -152,19 +149,16 @@ protected:
QList
<
Shape2D
*>
getSelectedShapes
()
const
{
return
m_selectedShapes
;
}
QList
<
Shape2D
*>
m_shapes
;
mutable
RectF
m_surfaceRect
;
///< original surface window in "real" coordinates
mutable
RectF
m_surfaceRect
;
///< original surface window in "real" coordinates
mutable
double
m_wx
,
m_wy
;
mutable
int
m_h
;
///< original screen viewport height
mutable
QRect
m_viewport
;
///< current screen viewport
mutable
QTransform
m_transform
;
///< current transform
Shape2D
*
m_currentShape
;
///< shape selected to edit (change size/shape)
size_t
m_currentCP
;
///< control point of m_currentShape selected to edit
QList
<
Shape2D
*>
m_selectedShapes
;
///< A list of selected shapes (can be moved or deleted)
QList
<
Shape2D
*>
m_copiedShapes
;
///< A list of shapes to be pasted if requiered
Shape2D
*
m_currentShape
;
///< shape selected to edit (change size/shape)
size_t
m_currentCP
;
///< control point of m_currentShape selected to edit
QList
<
Shape2D
*>
m_selectedShapes
;
///< A list of selected shapes (can be moved or deleted)
QList
<
Shape2D
*>
m_copiedShapes
;
///< A list of shapes to be pasted if requiered
bool
m_overridingCursor
;
friend
class
InstrumentWidgetEncoder
;
friend
class
InstrumentWidgetDecoder
;
...
...
qt/widgets/instrumentview/src/InstrumentWidgetDecoder.cpp
View file @
0416169c
...
...
@@ -307,8 +307,11 @@ InstrumentWidgetDecoder::decodeEllipse(const QMap<QString, QVariant> &map) {
const
auto
radius2
=
map
[
QString
(
"radius2"
)].
toDouble
();
const
auto
x
=
map
[
QString
(
"x"
)].
toDouble
();
const
auto
y
=
map
[
QString
(
"y"
)].
toDouble
();
const
auto
rot
=
map
[
QString
(
"rotation"
)].
toDouble
();
return
new
Shape2DEllipse
(
QPointF
(
x
,
y
),
radius1
,
radius2
);
auto
shape
=
new
Shape2DEllipse
(
QPointF
(
x
,
y
),
radius1
,
radius2
);
shape
->
setBoundingRotation
(
rot
);
return
shape
;
}
Shape2D
*
...
...
@@ -317,10 +320,13 @@ InstrumentWidgetDecoder::decodeRectangle(const QMap<QString, QVariant> &map) {
const
auto
y0
=
map
[
QString
(
"y0"
)].
toDouble
();
const
auto
x1
=
map
[
QString
(
"x1"
)].
toDouble
();
const
auto
y1
=
map
[
QString
(
"y1"
)].
toDouble
();
const
auto
rot
=
map
[
QString
(
"rotation"
)].
toDouble
();
const
QPointF
point1
(
x0
,
y0
);
const
QPointF
point2
(
x1
,
y1
);
return
new
Shape2DRectangle
(
point1
,
point2
);
auto
shape
=
new
Shape2DRectangle
(
point1
,
point2
);
shape
->
setBoundingRotation
(
rot
);
return
shape
;
}
Shape2D
*
...
...
qt/widgets/instrumentview/src/InstrumentWidgetEncoder.cpp
View file @
0416169c
...
...
@@ -368,6 +368,7 @@ InstrumentWidgetEncoder::encodeEllipse(const Shape2DEllipse *obj) {
const
double
radius1
=
obj
->
getDouble
(
"radius1"
);
const
double
radius2
=
obj
->
getDouble
(
"radius2"
);
const
auto
centre
=
obj
->
getPoint
(
"centre"
);
const
auto
rot
=
obj
->
getBoundingRotation
();
QMap
<
QString
,
QVariant
>
map
;
...
...
@@ -375,6 +376,7 @@ InstrumentWidgetEncoder::encodeEllipse(const Shape2DEllipse *obj) {
map
.
insert
(
QString
(
"radius2"
),
QVariant
(
radius2
));
map
.
insert
(
QString
(
"x"
),
QVariant
(
centre
.
x
()));
map
.
insert
(
QString
(
"y"
),
QVariant
(
centre
.
y
()));
map
.
insert
(
QString
(
"rotation"
),
QVariant
(
rot
));
return
map
;
}
...
...
@@ -385,6 +387,7 @@ InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) {
const
auto
x1
=
obj
->
m_boundingRect
.
x1
();
const
auto
y0
=
obj
->
m_boundingRect
.
y0
();
const
auto
y1
=
obj
->
m_boundingRect
.
y1
();
const
auto
rot
=
obj
->
getBoundingRotation
();
QMap
<
QString
,
QVariant
>
map
;
...
...
@@ -392,6 +395,7 @@ InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) {
map
.
insert
(
QString
(
"y0"
),
QVariant
(
y0
));
map
.
insert
(
QString
(
"x1"
),
QVariant
(
x1
));
map
.
insert
(
QString
(
"y1"
),
QVariant
(
y1
));
map
.
insert
(
QString
(
"rotation"
),
QVariant
(
rot
));
return
map
;
}
...
...
qt/widgets/instrumentview/src/InstrumentWidgetMaskTab.cpp
View file @
0416169c
...
...
@@ -74,11 +74,9 @@ using Mantid::API::AlgorithmManager;
namespace
MantidQt
{
namespace
MantidWidgets
{
InstrumentWidgetMaskTab
::
InstrumentWidgetMaskTab
(
InstrumentWidget
*
instrWidget
)
:
InstrumentWidgetTab
(
instrWidget
),
m_activity
(
Select
),
m_hasMaskToApply
(
false
),
m_maskBins
(
false
),
m_userEditing
(
true
),
m_groupManager
(
nullptr
),
m_stringManager
(
nullptr
),
m_doubleManager
(
nullptr
),
m_browser
(
nullptr
),
m_left
(
nullptr
),
m_top
(
nullptr
),
m_right
(
nullptr
),
m_bottom
(
nullptr
)
{
:
InstrumentWidgetTab
(
instrWidget
),
m_activity
(
Select
),
m_hasMaskToApply
(
false
),
m_maskBins
(
false
),
m_userEditing
(
true
),
m_groupManager
(
nullptr
),
m_stringManager
(
nullptr
),
m_doubleManager
(
nullptr
),
m_browser
(
nullptr
),
m_left
(
nullptr
),
m_top
(
nullptr
),
m_right
(
nullptr
),
m_bottom
(
nullptr
),
m_rotation
(
nullptr
)
{
// main layout
QVBoxLayout
*
layout
=
new
QVBoxLayout
(
this
);
...
...
@@ -628,10 +626,9 @@ void InstrumentWidgetMaskTab::shapeChanged() {
m_doubleManager
->
setValue
(
m_top
,
std
::
max
(
rect
.
y0
(),
rect
.
y1
()));
m_doubleManager
->
setValue
(
m_right
,
std
::
max
(
rect
.
x0
(),
rect
.
x1
()));
m_doubleManager
->
setValue
(
m_bottom
,
std
::
min
(
rect
.
y0
(),
rect
.
y1
()));
for
(
QMap
<
QtProperty
*
,
QString
>::
iterator
it
=
m_doublePropertyMap
.
begin
();
it
!=
m_doublePropertyMap
.
end
();
++
it
)
{
m_doubleManager
->
setValue
(
it
.
key
(),
m_instrWidget
->
getSurface
()
->
getCurrentDouble
(
it
.
value
()));
for
(
QMap
<
QtProperty
*
,
QString
>::
iterator
it
=
m_doublePropertyMap
.
begin
();
it
!=
m_doublePropertyMap
.
end
();
++
it
)
{
m_doubleManager
->
setValue
(
it
.
key
(),
m_instrWidget
->
getSurface
()
->
getCurrentDouble
(
it
.
value
()));
}
for
(
QMap
<
QString
,
QtProperty
*>::
iterator
it
=
m_pointPropertyMap
.
begin
();
it
!=
m_pointPropertyMap
.
end
();
++
it
)
{
...
...
@@ -695,8 +692,8 @@ void InstrumentWidgetMaskTab::setProperties() {
boundingRectGroup
->
addSubProperty
(
m_top
);
boundingRectGroup
->
addSubProperty
(
m_right
);
boundingRectGroup
->
addSubProperty
(
m_bottom
);
if
(
isRotationSupported
())
{
if
(
isRotationSupported
())
{
m_rotation
=
addDoubleProperty
(
"rotation"
);
boundingRectGroup
->
addSubProperty
(
m_rotation
);
}
...
...
@@ -725,8 +722,8 @@ void InstrumentWidgetMaskTab::setProperties() {
m_doublePropertyMap
[
prop
]
=
name
;
}
//rotation property
if
(
isRotationSupported
())
//
rotation property
if
(
isRotationSupported
())
m_doubleManager
->
setValue
(
m_rotation
,
m_instrWidget
->
getSurface
()
->
getCurrentBoundingRotation
());
shapeChanged
();
...
...
@@ -757,8 +754,8 @@ void InstrumentWidgetMaskTab::doubleChanged(QtProperty *prop) {
QRectF
rect
(
QPointF
(
x0
,
y0
),
QPointF
(
x1
,
y1
));
m_instrWidget
->
getSurface
()
->
setCurrentBoundingRect
(
RectF
(
rect
));
if
(
isRotationSupported
())
m_instrWidget
->
getSurface
()
->
setCurrentBoundingRotation
(
m_doubleManager
->
value
(
m_rotation
));
if
(
isRotationSupported
())
m_instrWidget
->
getSurface
()
->
setCurrentBoundingRotation
(
m_doubleManager
->
value
(
m_rotation
));
}
else
{
QString
name
=
m_doublePropertyMap
[
prop
];
...
...
@@ -1562,8 +1559,7 @@ bool InstrumentWidgetMaskTab::saveMaskViewToProject(
return
true
;
}
bool
InstrumentWidgetMaskTab
::
isRotationSupported
(){
bool
InstrumentWidgetMaskTab
::
isRotationSupported
()
{
const
auto
shapeType
=
m_instrWidget
->
getSurface
()
->
getCurrentShapeType
();
return
shapeType
==
"rectangle"
||
shapeType
==
"ellipse"
;
}
...
...
qt/widgets/instrumentview/src/Shape2D.cpp
View file @
0416169c
...
...
@@ -289,7 +289,8 @@ void Shape2DEllipse::addToPath(QPainterPath &path) const {
bool
Shape2DEllipse
::
selectAt
(
const
QPointF
&
p
)
const
{
if
(
m_fill_color
!=
QColor
())
{
// filled ellipse
return
contains
(
p
);
return
contains
(
QTransform
().
rotate
(
-
m_boundingRotation
).
map
(
p
-
m_boundingRect
.
center
())
+
m_boundingRect
.
center
());
}
double
a
=
m_boundingRect
.
xSpan
()
/
2
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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