Commit b70a5d19 authored by Samuel Jones's avatar Samuel Jones
Browse files

Re #24350 Review changes finalised and rotation and 3D fixes

parent ec9f761d
......@@ -72,8 +72,14 @@ class ProjectLoader(object):
decoder = self.decoder_factory.find_decoder(interface["tag"])
# Decode and Show the interface
decoded_interface = decoder.decode(interface, directory)
decoded_interface.show()
try:
decoded_interface = decoder.decode(interface, directory)
decoded_interface.show()
except Exception as e:
# Catch any exception and log it for the encoder
if isinstance(e, KeyboardInterrupt):
raise KeyboardInterrupt(e)
logger.warning("Project Loader: An interface could not be loaded error: " + str(e))
class ProjectReader(object):
......@@ -95,5 +101,7 @@ class ProjectReader(object):
self.workspace_names = json_data["workspaces"]
self.plot_list = json_data["plots"]
self.interface_list = json_data["interfaces"]
except Exception:
except Exception as e:
if isinstance(e, KeyboardInterrupt):
raise KeyboardInterrupt(e)
logger.warning("JSON project file unable to be loaded/read")
......@@ -54,7 +54,7 @@ else:
u'freeDrawButton': False, u'ringEllipseButton': False},
u'maskWorkspaceSaved': False},
u'renderTab': {u'displayWireframe': False, u'displayLighting': False,
u'labelPrecision': 1, u'useUCorrection': False, u'autoScaling': True,
u'labelPrecision': 1, u'useUCorrection': False, u'autoScaling': False,
u'colorBar': {u'max': u'40', u'scaleType': 0, u'power': u'2',
u'min': u'40'},
u'showLabels': True, u'flipView': False, u'displayDetectorsOnly': True,
......
......@@ -16,9 +16,11 @@
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetRenderTab.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetTreeTab.h"
#include "MantidQtWidgets/InstrumentView/MaskBinsData.h"
#include "MantidQtWidgets/InstrumentView/Projection3D.h"
#include "MantidQtWidgets/InstrumentView/ProjectionSurface.h"
#include "MantidQtWidgets/InstrumentView/Shape2D.h"
#include "MantidQtWidgets/InstrumentView/Shape2DCollection.h"
#include "MantidQtWidgets/InstrumentView/Viewport.h"
#include <QList>
#include <QMap>
......@@ -60,6 +62,8 @@ private:
void decodeBinMasks(const QList<QVariant> &list, MaskBinsData &obj);
void decodeSurface(const QMap<QString, QVariant> &map,
boost::shared_ptr<ProjectionSurface> obj);
void decodeProjection3D(const QMap<QString, QVariant> &map, Projection3D &obj);
void decodeViewPort(const QMap<QString, QVariant> &map, Viewport &obj);
void decodeMaskShapes(const QList<QVariant> &list, Shape2DCollection &obj);
Shape2D *decodeShape(const QMap<QString, QVariant> &map);
......
......@@ -15,9 +15,9 @@
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetTab.h"
#include "MantidQtWidgets/InstrumentView/InstrumentWidgetTreeTab.h"
#include "MantidQtWidgets/InstrumentView/MaskBinsData.h"
#include "MantidQtWidgets/InstrumentView/Projection3D.h"
#include "MantidQtWidgets/InstrumentView/ProjectionSurface.h"
#include "MantidQtWidgets/InstrumentView/Shape2D.h"
#include "MantidQtWidgets/InstrumentView/Projection3D.h"
#include "MantidQtWidgets/InstrumentView/Viewport.h"
namespace MantidQt {
......
......@@ -71,7 +71,6 @@ void InstrumentWidgetDecoder::decodeTabs(const QMap<QString, QVariant> &map,
void InstrumentWidgetDecoder::decodeMaskTab(const QMap<QString, QVariant> &map,
InstrumentWidgetMaskTab *obj) {
connect(this, SIGNAL(shapeCreated()), obj, SLOT(shapeCreated()));
const auto activeTools = map[QString("activeTools")].toMap();
const auto activeType = map[QString("activeType")].toMap();
......@@ -156,7 +155,6 @@ void InstrumentWidgetDecoder::decodeTreeTab(const QMap<QString, QVariant> &map,
void InstrumentWidgetDecoder::decodePickTab(const QMap<QString, QVariant> &map,
InstrumentWidgetPickTab *obj) {
connect(this, SIGNAL(shapeCreated()), obj, SLOT(shapeCreated()));
obj->m_zoom->setChecked(map[QString("zoom")].toBool());
obj->m_edit->setChecked(map[QString("edit")].toBool());
obj->m_ellipse->setChecked(map[QString("ellipse")].toBool());
......@@ -197,6 +195,13 @@ void InstrumentWidgetDecoder::decodeBinMasks(const QList<QVariant> &list,
void InstrumentWidgetDecoder::decodeSurface(
const QMap<QString, QVariant> &map,
boost::shared_ptr<ProjectionSurface> obj) {
auto projection3D = boost::dynamic_pointer_cast<Projection3D>(obj);
// Decide Projection3D stuff
if (map[QString("projection3DSuccess")].toBool() && projection3D) {
this->decodeProjection3D(map[QString("projection3D")].toMap(), *projection3D);
}
QMap<QString, QVariant> color = map[QString("backgroundColor")].toMap();
QColor qColor(color[QString("red")].toInt(), color[QString("green")].toInt(),
color[QString("blue")].toInt(),
......@@ -208,15 +213,38 @@ void InstrumentWidgetDecoder::decodeSurface(
this->decodeAlignmentInfo(map[QString("alignmentInfo")].toList(), obj);
}
void InstrumentWidgetDecoder::decodeProjection3D(
const QMap<QString, QVariant> &map, Projection3D &obj) {
this->decodeViewPort(map[QString("viewport")].toMap(), obj.m_viewport);
}
void InstrumentWidgetDecoder::decodeViewPort(const QMap<QString, QVariant> &map,
Viewport &obj) {
auto translationMap = map[QString("translation")].toMap();
auto rotationList = map[QString("rotation")].toList();
obj.m_xTrans = translationMap[QString("xTrans")].toDouble();
obj.m_yTrans = translationMap[QString("yTrans")].toDouble();
obj.m_zoomFactor = map[QString("zoom")].toDouble();
// Sort out the rotation
double w, a, b, c;
w = rotationList[0].toDouble();
a = rotationList[1].toDouble();
b = rotationList[2].toDouble();
c = rotationList[3].toDouble();
Mantid::Kernel::Quat quat(w, a, b, c);
obj.setRotation(quat);
}
void InstrumentWidgetDecoder::decodeMaskShapes(const QList<QVariant> &list,
Shape2DCollection &obj) {
connect(this, SIGNAL(shapeCreated()), &obj, SIGNAL(shapeCreated()));
for (const auto &shape : list) {
auto created_shape = this->decodeShape(shape.toMap());
obj.m_shapes.push_back(created_shape);
emit shapeCreated();
}
std::cout << list.size() << " " << obj.m_shapes.size() << "/n";
}
Shape2D *
......@@ -237,10 +265,12 @@ InstrumentWidgetDecoder::decodeShape(const QMap<QString, QVariant> &map) {
}
}();
shape->setScalable(map[QString("scalable")].toBool());
shape->edit(map[QString("editing")].toBool());
shape->setSelected(map[QString("selected")].toBool());
shape->setVisible(map[QString("visible")].toBool());
// Set the properties of the overall shape object from the properties map.
auto properties = map[QString("properties")].toMap();
shape->setScalable(properties[QString("visible")].toBool());
shape->setVisible(properties[QString("scalable")].toBool());
shape->edit(properties[QString("editing")].toBool());
shape->setSelected(properties[QString("selected")].toBool());
QMap<QString, QVariant> color1 = map[QString("color")].toMap();
QColor qColor(
......
......@@ -248,6 +248,14 @@ QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeSurface(const ProjectionSurface_sptr &obj) {
QMap<QString, QVariant> map;
auto projection3D = boost::dynamic_pointer_cast<Projection3D>(obj);
if (projection3D){
map.insert(QString("projection3DSuccess"), QVariant(true));
map.insert(QString("projection3D"), QVariant(this->encodeProjection3D(*projection3D)));
} else {
map.insert(QString("projection3DSuccess"), QVariant(false));
}
map.insert(QString("backgroundColor"), QVariant(obj->m_backgroundColor));
map.insert(QString("shapes"),
QVariant(this->encodeMaskShapes(obj->m_maskShapes)));
......@@ -257,28 +265,31 @@ InstrumentWidgetEncoder::encodeSurface(const ProjectionSurface_sptr &obj) {
return map;
}
QMap<QString, QVariant> InstrumentWidgetEncoder::encodeProjection3D(const Projection3D &obj){
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeProjection3D(const Projection3D &obj) {
QMap<QString, QVariant> map;
map.insert(QString("viewport"), QVariant(this->encodeViewPort(obj.m_viewport)));
map.insert(QString("viewport"),
QVariant(this->encodeViewPort(obj.m_viewport)));
return map;
}
QMap<QString, QVariant> InstrumentWidgetEncoder::encodeViewPort(const Viewport &obj){
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeViewPort(const Viewport &obj) {
QMap<QString, QVariant> map;
QMap<QString, QVariant> translationMap;
translationMap.insert(QString("xTrans"), QVariant(obj.m_xTrans));
translationMap.insert(QString("yTrans"), QVariant(obj.m_yTrans));
map.insert(QString("translation"), QVariant(translationMap));
map.insert(QString("Zoom"), QVariant(obj.m_zoomFactor));
map.insert(QString("zoom"), QVariant(obj.m_zoomFactor));
QList<QVariant> rotation;
for(auto i = 0; i < 4; i++){
for (auto i = 0; i < 4; ++i) {
rotation.append(obj.m_quaternion[i]);
}
map.insert(QString("rotation"), QVariant(rotation));
return map;
}
......@@ -293,7 +304,8 @@ InstrumentWidgetEncoder::encodeMaskShapes(const Shape2DCollection &obj) {
return list;
}
QMap<QString, QVariant> InstrumentWidgetEncoder::encodeShape(const Shape2D *obj) {
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeShape(const Shape2D *obj) {
QMap<QString, QVariant> map;
map.insert(QString("properties"), QVariant(this->encodeShapeProperties(obj)));
......@@ -316,10 +328,12 @@ QMap<QString, QVariant> InstrumentWidgetEncoder::encodeShape(const Shape2D *obj)
QMap<QString, QVariant> subShapeMap;
if (obj->type() == "ellipse") {
subShapeMap = this->encodeEllipse(reinterpret_cast<const Shape2DEllipse *>(obj));
subShapeMap =
this->encodeEllipse(reinterpret_cast<const Shape2DEllipse *>(obj));
map.insert(QString("type"), QVariant(QString("ellipse")));
} else if (obj->type() == "rectangle") {
subShapeMap = this->encodeRectangle(reinterpret_cast<const Shape2DRectangle *>(obj));
subShapeMap =
this->encodeRectangle(reinterpret_cast<const Shape2DRectangle *>(obj));
map.insert(QString("type"), QVariant(QString("rectangle")));
} else if (obj->type() == "ring") {
subShapeMap = this->encodeRing(reinterpret_cast<const Shape2DRing *>(obj));
......@@ -369,7 +383,8 @@ InstrumentWidgetEncoder::encodeRectangle(const Shape2DRectangle *obj) {
return map;
}
QMap<QString, QVariant> InstrumentWidgetEncoder::encodeRing(const Shape2DRing *obj) {
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeRing(const Shape2DRing *obj) {
const auto xWidth = obj->getDouble("xwidth");
const auto yWidth = obj->getDouble("ywidth");
auto baseShape = obj->getOuterShape()->clone();
......@@ -382,7 +397,8 @@ QMap<QString, QVariant> InstrumentWidgetEncoder::encodeRing(const Shape2DRing *o
return map;
}
QMap<QString, QVariant> InstrumentWidgetEncoder::encodeFree(const Shape2DFree *obj) {
QMap<QString, QVariant>
InstrumentWidgetEncoder::encodeFree(const Shape2DFree *obj) {
const auto polygon = obj->m_polygon;
QList<QVariant> parameters;
......
......@@ -53,7 +53,7 @@ void Shape2DCollection::draw(QPainter &painter) const {
nonscalable << shape;
}
}
// first draw the scalable ones
painter.save();
painter.setTransform(m_transform);
......@@ -74,8 +74,6 @@ void Shape2DCollection::draw(QPainter &painter) const {
shape->draw(painter);
painter.restore();
}
// std::cerr << m_transform.m11() << ' ' << m_transform.m22() << ' ' <<
// m_transform.m33() << '\n';
}
/**
......
Supports Markdown
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