Commit 0416169c authored by Whitfield, Ross's avatar Whitfield, Ross
Browse files

Fix InstrumentWidget Encoder/Decoder for new rotation property

parent f8b9e0ad
...@@ -174,20 +174,14 @@ public: ...@@ -174,20 +174,14 @@ public:
/// Return bounding rotation of the currently selected shape in the "original" /// Return bounding rotation of the currently selected shape in the "original"
/// coord system. /// coord system.
/// It doesn't depend on the zooming of the surface /// It doesn't depend on the zooming of the surface
double getCurrentBoundingRotation() const { double getCurrentBoundingRotation() const { return m_maskShapes.getCurrentBoundingRotation(); }
return m_maskShapes.getCurrentBoundingRotation();
}
/// Set new bounding rect of the currently selected shape in the "original" /// Set new bounding rect of the currently selected shape in the "original"
/// coord system. /// coord system.
/// This method resizes the shape to fit into the new rectangle. /// This method resizes the shape to fit into the new rectangle.
void setCurrentBoundingRotation(const double rotation) { void setCurrentBoundingRotation(const double rotation) { m_maskShapes.setCurrentBoundingRotation(rotation); }
m_maskShapes.setCurrentBoundingRotation(rotation);
}
std::string getCurrentShapeType() const { std::string getCurrentShapeType() const { return m_maskShapes.getCurrentShapeType(); }
return m_maskShapes.getCurrentShapeType();
}
/// Initialize interactive shape creation. /// Initialize interactive shape creation.
/// @param type :: Type of the shape. For available types see code of /// @param type :: Type of the shape. For available types see code of
......
...@@ -99,8 +99,7 @@ public: ...@@ -99,8 +99,7 @@ public:
/// Save shape collection to a Table workspace /// Save shape collection to a Table workspace
void saveToTableWorkspace(); void saveToTableWorkspace();
/// Load shape collectio from a Table workspace /// Load shape collectio from a Table workspace
void void loadFromTableWorkspace(const Mantid::API::ITableWorkspace_const_sptr &ws);
loadFromTableWorkspace(const Mantid::API::ITableWorkspace_const_sptr &ws);
/// Load settings for the shape 2D collection from a project file /// Load settings for the shape 2D collection from a project file
virtual void loadFromProject(const std::string &lines); virtual void loadFromProject(const std::string &lines);
/// Save settings for the shape 2D collection to a project file /// Save settings for the shape 2D collection to a project file
...@@ -117,10 +116,8 @@ signals: ...@@ -117,10 +116,8 @@ signals:
void cleared(); void cleared();
public slots: public slots:
void addShape(const QString &type, int x, int y, const QColor &borderColor, void addShape(const QString &type, int x, int y, const QColor &borderColor, const QColor &fillColor);
const QColor &fillColor); void addFreeShape(const QPolygonF & /*poly*/, const QColor &borderColor, const QColor &fillColor);
void addFreeShape(const QPolygonF & /*poly*/, const QColor &borderColor,
const QColor &fillColor);
void deselectAll(); void deselectAll();
void moveRightBottomTo(int /*x*/, int /*y*/); void moveRightBottomTo(int /*x*/, int /*y*/);
void selectShapeOrControlPointAt(int x, int y); void selectShapeOrControlPointAt(int x, int y);
...@@ -152,8 +149,7 @@ protected: ...@@ -152,8 +149,7 @@ protected:
QList<Shape2D *> getSelectedShapes() const { return m_selectedShapes; } QList<Shape2D *> getSelectedShapes() const { return m_selectedShapes; }
QList<Shape2D *> m_shapes; QList<Shape2D *> m_shapes;
mutable RectF mutable RectF m_surfaceRect; ///< original surface window in "real" coordinates
m_surfaceRect; ///< original surface window in "real" coordinates
mutable double m_wx, m_wy; mutable double m_wx, m_wy;
mutable int m_h; ///< original screen viewport height mutable int m_h; ///< original screen viewport height
mutable QRect m_viewport; ///< current screen viewport mutable QRect m_viewport; ///< current screen viewport
...@@ -161,10 +157,8 @@ protected: ...@@ -161,10 +157,8 @@ protected:
Shape2D *m_currentShape; ///< shape selected to edit (change size/shape) Shape2D *m_currentShape; ///< shape selected to edit (change size/shape)
size_t m_currentCP; ///< control point of m_currentShape selected to edit size_t m_currentCP; ///< control point of m_currentShape selected to edit
QList<Shape2D *> QList<Shape2D *> m_selectedShapes; ///< A list of selected shapes (can be moved or deleted)
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
QList<Shape2D *>
m_copiedShapes; ///< A list of shapes to be pasted if requiered
bool m_overridingCursor; bool m_overridingCursor;
friend class InstrumentWidgetEncoder; friend class InstrumentWidgetEncoder;
friend class InstrumentWidgetDecoder; friend class InstrumentWidgetDecoder;
......
...@@ -307,8 +307,11 @@ InstrumentWidgetDecoder::decodeEllipse(const QMap<QString, QVariant> &map) { ...@@ -307,8 +307,11 @@ InstrumentWidgetDecoder::decodeEllipse(const QMap<QString, QVariant> &map) {
const auto radius2 = map[QString("radius2")].toDouble(); const auto radius2 = map[QString("radius2")].toDouble();
const auto x = map[QString("x")].toDouble(); const auto x = map[QString("x")].toDouble();
const auto y = map[QString("y")].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 * Shape2D *
...@@ -317,10 +320,13 @@ InstrumentWidgetDecoder::decodeRectangle(const QMap<QString, QVariant> &map) { ...@@ -317,10 +320,13 @@ InstrumentWidgetDecoder::decodeRectangle(const QMap<QString, QVariant> &map) {
const auto y0 = map[QString("y0")].toDouble(); const auto y0 = map[QString("y0")].toDouble();
const auto x1 = map[QString("x1")].toDouble(); const auto x1 = map[QString("x1")].toDouble();
const auto y1 = map[QString("y1")].toDouble(); const auto y1 = map[QString("y1")].toDouble();
const auto rot = map[QString("rotation")].toDouble();
const QPointF point1(x0, y0); const QPointF point1(x0, y0);
const QPointF point2(x1, y1); const QPointF point2(x1, y1);
return new Shape2DRectangle(point1, point2); auto shape = new Shape2DRectangle(point1, point2);
shape->setBoundingRotation(rot);
return shape;
} }
Shape2D * Shape2D *
......
...@@ -368,6 +368,7 @@ InstrumentWidgetEncoder::encodeEllipse(const Shape2DEllipse *obj) { ...@@ -368,6 +368,7 @@ InstrumentWidgetEncoder::encodeEllipse(const Shape2DEllipse *obj) {
const double radius1 = obj->getDouble("radius1"); const double radius1 = obj->getDouble("radius1");
const double radius2 = obj->getDouble("radius2"); const double radius2 = obj->getDouble("radius2");
const auto centre = obj->getPoint("centre"); const auto centre = obj->getPoint("centre");
const auto rot = obj->getBoundingRotation();
QMap<QString, QVariant> map; QMap<QString, QVariant> map;
...@@ -375,6 +376,7 @@ InstrumentWidgetEncoder::encodeEllipse(const Shape2DEllipse *obj) { ...@@ -375,6 +376,7 @@ InstrumentWidgetEncoder::encodeEllipse(const Shape2DEllipse *obj) {
map.insert(QString("radius2"), QVariant(radius2)); map.insert(QString("radius2"), QVariant(radius2));
map.insert(QString("x"), QVariant(centre.x())); map.insert(QString("x"), QVariant(centre.x()));
map.insert(QString("y"), QVariant(centre.y())); map.insert(QString("y"), QVariant(centre.y()));
map.insert(QString("rotation"), QVariant(rot));
return map; return map;
} }
...@@ -385,6 +387,7 @@ InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) { ...@@ -385,6 +387,7 @@ InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) {
const auto x1 = obj->m_boundingRect.x1(); const auto x1 = obj->m_boundingRect.x1();
const auto y0 = obj->m_boundingRect.y0(); const auto y0 = obj->m_boundingRect.y0();
const auto y1 = obj->m_boundingRect.y1(); const auto y1 = obj->m_boundingRect.y1();
const auto rot = obj->getBoundingRotation();
QMap<QString, QVariant> map; QMap<QString, QVariant> map;
...@@ -392,6 +395,7 @@ InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) { ...@@ -392,6 +395,7 @@ InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) {
map.insert(QString("y0"), QVariant(y0)); map.insert(QString("y0"), QVariant(y0));
map.insert(QString("x1"), QVariant(x1)); map.insert(QString("x1"), QVariant(x1));
map.insert(QString("y1"), QVariant(y1)); map.insert(QString("y1"), QVariant(y1));
map.insert(QString("rotation"), QVariant(rot));
return map; return map;
} }
......
...@@ -74,11 +74,9 @@ using Mantid::API::AlgorithmManager; ...@@ -74,11 +74,9 @@ using Mantid::API::AlgorithmManager;
namespace MantidQt { namespace MantidQt {
namespace MantidWidgets { namespace MantidWidgets {
InstrumentWidgetMaskTab::InstrumentWidgetMaskTab(InstrumentWidget *instrWidget) InstrumentWidgetMaskTab::InstrumentWidgetMaskTab(InstrumentWidget *instrWidget)
: InstrumentWidgetTab(instrWidget), m_activity(Select), : InstrumentWidgetTab(instrWidget), m_activity(Select), m_hasMaskToApply(false), m_maskBins(false),
m_hasMaskToApply(false), m_maskBins(false), m_userEditing(true), m_userEditing(true), m_groupManager(nullptr), m_stringManager(nullptr), m_doubleManager(nullptr),
m_groupManager(nullptr), m_stringManager(nullptr), m_browser(nullptr), m_left(nullptr), m_top(nullptr), m_right(nullptr), m_bottom(nullptr), m_rotation(nullptr) {
m_doubleManager(nullptr), m_browser(nullptr), m_left(nullptr),
m_top(nullptr), m_right(nullptr), m_bottom(nullptr) {
// main layout // main layout
QVBoxLayout *layout = new QVBoxLayout(this); QVBoxLayout *layout = new QVBoxLayout(this);
...@@ -628,10 +626,9 @@ void InstrumentWidgetMaskTab::shapeChanged() { ...@@ -628,10 +626,9 @@ void InstrumentWidgetMaskTab::shapeChanged() {
m_doubleManager->setValue(m_top, std::max(rect.y0(), rect.y1())); 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_right, std::max(rect.x0(), rect.x1()));
m_doubleManager->setValue(m_bottom, std::min(rect.y0(), rect.y1())); 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) { for (QMap<QtProperty *, QString>::iterator it = m_doublePropertyMap.begin(); it != m_doublePropertyMap.end(); ++it) {
m_doubleManager->setValue( m_doubleManager->setValue(it.key(), m_instrWidget->getSurface()->getCurrentDouble(it.value()));
it.key(), m_instrWidget->getSurface()->getCurrentDouble(it.value()));
} }
for (QMap<QString, QtProperty *>::iterator it = m_pointPropertyMap.begin(); for (QMap<QString, QtProperty *>::iterator it = m_pointPropertyMap.begin();
it != m_pointPropertyMap.end(); ++it) { it != m_pointPropertyMap.end(); ++it) {
...@@ -696,7 +693,7 @@ void InstrumentWidgetMaskTab::setProperties() { ...@@ -696,7 +693,7 @@ void InstrumentWidgetMaskTab::setProperties() {
boundingRectGroup->addSubProperty(m_right); boundingRectGroup->addSubProperty(m_right);
boundingRectGroup->addSubProperty(m_bottom); boundingRectGroup->addSubProperty(m_bottom);
if(isRotationSupported()) { if (isRotationSupported()) {
m_rotation = addDoubleProperty("rotation"); m_rotation = addDoubleProperty("rotation");
boundingRectGroup->addSubProperty(m_rotation); boundingRectGroup->addSubProperty(m_rotation);
} }
...@@ -725,8 +722,8 @@ void InstrumentWidgetMaskTab::setProperties() { ...@@ -725,8 +722,8 @@ void InstrumentWidgetMaskTab::setProperties() {
m_doublePropertyMap[prop] = name; m_doublePropertyMap[prop] = name;
} }
//rotation property // rotation property
if(isRotationSupported()) if (isRotationSupported())
m_doubleManager->setValue(m_rotation, m_instrWidget->getSurface()->getCurrentBoundingRotation()); m_doubleManager->setValue(m_rotation, m_instrWidget->getSurface()->getCurrentBoundingRotation());
shapeChanged(); shapeChanged();
...@@ -757,7 +754,7 @@ void InstrumentWidgetMaskTab::doubleChanged(QtProperty *prop) { ...@@ -757,7 +754,7 @@ void InstrumentWidgetMaskTab::doubleChanged(QtProperty *prop) {
QRectF rect(QPointF(x0, y0), QPointF(x1, y1)); QRectF rect(QPointF(x0, y0), QPointF(x1, y1));
m_instrWidget->getSurface()->setCurrentBoundingRect(RectF(rect)); m_instrWidget->getSurface()->setCurrentBoundingRect(RectF(rect));
if(isRotationSupported()) if (isRotationSupported())
m_instrWidget->getSurface()->setCurrentBoundingRotation(m_doubleManager->value(m_rotation)); m_instrWidget->getSurface()->setCurrentBoundingRotation(m_doubleManager->value(m_rotation));
} else { } else {
...@@ -1562,8 +1559,7 @@ bool InstrumentWidgetMaskTab::saveMaskViewToProject( ...@@ -1562,8 +1559,7 @@ bool InstrumentWidgetMaskTab::saveMaskViewToProject(
return true; return true;
} }
bool InstrumentWidgetMaskTab::isRotationSupported() {
bool InstrumentWidgetMaskTab::isRotationSupported(){
const auto shapeType = m_instrWidget->getSurface()->getCurrentShapeType(); const auto shapeType = m_instrWidget->getSurface()->getCurrentShapeType();
return shapeType == "rectangle" || shapeType == "ellipse"; return shapeType == "rectangle" || shapeType == "ellipse";
} }
......
...@@ -289,7 +289,8 @@ void Shape2DEllipse::addToPath(QPainterPath &path) const { ...@@ -289,7 +289,8 @@ void Shape2DEllipse::addToPath(QPainterPath &path) const {
bool Shape2DEllipse::selectAt(const QPointF &p) const { bool Shape2DEllipse::selectAt(const QPointF &p) const {
if (m_fill_color != QColor()) { // filled ellipse 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; double a = m_boundingRect.xSpan() / 2;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment