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
7141f9cf
Commit
7141f9cf
authored
Sep 14, 2021
by
Whitfield, Ross
Browse files
Fix InstrumentWidget Encoder/Decoder for new rotation property
parent
89a714f3
Changes
6
Hide whitespace changes
Inline
Side-by-side
qt/widgets/instrumentview/inc/MantidQtWidgets/InstrumentView/ProjectionSurface.h
View file @
7141f9cf
...
...
@@ -170,20 +170,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 @
7141f9cf
...
...
@@ -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 @
7141f9cf
...
...
@@ -282,8 +282,11 @@ Shape2D *InstrumentWidgetDecoder::decodeEllipse(const QMap<QString, QVariant> &m
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
*
InstrumentWidgetDecoder
::
decodeRectangle
(
const
QMap
<
QString
,
QVariant
>
&
map
)
{
...
...
@@ -291,10 +294,13 @@ Shape2D *InstrumentWidgetDecoder::decodeRectangle(const QMap<QString, QVariant>
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
*
InstrumentWidgetDecoder
::
decodeRing
(
const
QMap
<
QString
,
QVariant
>
&
map
)
{
...
...
qt/widgets/instrumentview/src/InstrumentWidgetEncoder.cpp
View file @
7141f9cf
...
...
@@ -323,6 +323,7 @@ QMap<QString, QVariant> InstrumentWidgetEncoder::encodeEllipse(const Shape2DElli
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
;
...
...
@@ -330,6 +331,7 @@ QMap<QString, QVariant> InstrumentWidgetEncoder::encodeEllipse(const Shape2DElli
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
;
}
...
...
@@ -339,6 +341,7 @@ QMap<QString, QVariant> InstrumentWidgetEncoder::encodeRectangle(const Shape2DRe
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
;
...
...
@@ -346,6 +349,7 @@ QMap<QString, QVariant> InstrumentWidgetEncoder::encodeRectangle(const Shape2DRe
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 @
7141f9cf
...
...
@@ -75,7 +75,7 @@ namespace MantidQt::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
)
{
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
);
...
...
@@ -564,6 +564,7 @@ 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
()));
}
...
...
@@ -628,8 +629,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
);
}
...
...
@@ -656,8 +657,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
();
...
...
@@ -682,8 +683,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
];
...
...
@@ -1436,7 +1437,7 @@ bool InstrumentWidgetMaskTab::saveMaskViewToProject(const std::string &name, con
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 @
7141f9cf
...
...
@@ -281,7 +281,8 @@ void Shape2DEllipse::addToPath(QPainterPath &path) const { path.addEllipse(m_bou
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
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