From 4a6088a4ae9d18428479b2424bd77f03c53c262c Mon Sep 17 00:00:00 2001 From: Mikhail Svechnikov <m.svechnikov@fz-juelich.de> Date: Fri, 25 Nov 2022 19:04:04 +0100 Subject: [PATCH] VectorProperty: replace R3 member by 3 DoubleProperties --- GUI/Model/Descriptor/DoubleProperty.cpp | 1 + GUI/Model/Descriptor/VectorDescriptor.h | 16 ++++++++-------- GUI/Model/Descriptor/VectorProperty.cpp | 5 ++--- GUI/Model/Descriptor/VectorProperty.h | 17 +++++++++++------ GUI/Model/Device/RectangularDetectorItem.cpp | 4 ++-- 5 files changed, 24 insertions(+), 19 deletions(-) diff --git a/GUI/Model/Descriptor/DoubleProperty.cpp b/GUI/Model/Descriptor/DoubleProperty.cpp index af005f17da5..a2bc611b73e 100644 --- a/GUI/Model/Descriptor/DoubleProperty.cpp +++ b/GUI/Model/Descriptor/DoubleProperty.cpp @@ -48,6 +48,7 @@ void DoubleProperty::init(const QString& label, const QString& tooltip, double v else m_uid = QUuid::createUuid().toString(); + // temporary m_descriptor.label = label; m_descriptor.tooltip = tooltip; m_descriptor.decimals = decimals; diff --git a/GUI/Model/Descriptor/VectorDescriptor.h b/GUI/Model/Descriptor/VectorDescriptor.h index f2a2930577f..a6f54bb7c2f 100644 --- a/GUI/Model/Descriptor/VectorDescriptor.h +++ b/GUI/Model/Descriptor/VectorDescriptor.h @@ -17,6 +17,7 @@ #include "GUI/Model/Descriptor/DoubleDescriptor.h" +#include "GUI/Model/Descriptor/DoubleProperty.h" #include <heinz/Vectors3D.h> //! Describes properties of a 3D vector, consisting of three double values. @@ -73,7 +74,7 @@ public: z.label = "z"; } - void init(const QString& _label, const QString& _tooltip, const R3* vec, + void init(const QString& _label, const QString& _tooltip, const DoubleProperty* xDP, const DoubleProperty* yDP, const DoubleProperty* zDP, const std::variant<QString, Unit>& _unit) { label = _label; @@ -93,18 +94,17 @@ public: x.label = "x"; y.label = "y"; z.label = "z"; - x.set = [=](double v) { const_cast<R3*>(vec)->setX(v); }; - x.get = [=]() { return vec->x(); }; + x.set = [=](double v) { const_cast<DoubleProperty*>(xDP)->set(v); }; + x.get = [=]() { return xDP->get(); }; x.path = [=] { return uid() + "x"; }; - y.set = [=](double v) { const_cast<R3*>(vec)->setY(v); }; - y.get = [=]() { return vec->y(); }; + y.set = [=](double v) { const_cast<DoubleProperty*>(yDP)->set(v); }; + y.get = [=]() { return yDP->get(); }; y.path = [=] { return uid() + "y"; }; - z.set = [=](double v) { const_cast<R3*>(vec)->setZ(v); }; - z.get = [=]() { return vec->z(); }; + z.set = [=](double v) { const_cast<DoubleProperty*>(zDP)->set(v); }; + z.get = [=]() { return zDP->get(); }; z.path = [=] { return uid() + "z"; }; } - QString label; //!< A label text (short, no trailing colon) QString tooltip; //!< Tooltip text DoubleDescriptor x; diff --git a/GUI/Model/Descriptor/VectorProperty.cpp b/GUI/Model/Descriptor/VectorProperty.cpp index 02265a3dd89..a464032716e 100644 --- a/GUI/Model/Descriptor/VectorProperty.cpp +++ b/GUI/Model/Descriptor/VectorProperty.cpp @@ -25,17 +25,16 @@ void VectorProperty::init(const QString& label, const QString& tooltip, m_persistentTag = persistentTag; m_uid = QUuid::createUuid().toString(); - m_descriptor.init(label, tooltip, &m_value, unit); + m_descriptor.init(label, tooltip, &x, &y, &z, unit); m_descriptor.uid = [this] { return m_uid; }; } bool VectorProperty::operator==(const VectorProperty& other) const { - return (m_value == other.m_value) && (m_uid == other.m_uid) + return (get() == other.get()) && (m_uid == other.m_uid) && (m_persistentTag == other.m_persistentTag); } - void Serialize::rwProperty(Streamer& s, VectorProperty& d) { if (QXmlStreamWriter* w = s.xmlWriter()) { diff --git a/GUI/Model/Descriptor/VectorProperty.h b/GUI/Model/Descriptor/VectorProperty.h index a0bf9016212..b539e73c19e 100644 --- a/GUI/Model/Descriptor/VectorProperty.h +++ b/GUI/Model/Descriptor/VectorProperty.h @@ -16,6 +16,7 @@ #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORPROPERTY_H #include "GUI/Model/Descriptor/VectorDescriptor.h" +#include "GUI/Model/Descriptor/DoubleProperty.h" #include <heinz/Vectors3D.h> class Streamer; @@ -37,23 +38,27 @@ public: VectorDescriptor descriptor() const { return m_descriptor; } operator VectorDescriptor() const { return m_descriptor; } - operator R3() const { return m_value; } + operator R3() const { return R3(x.get(), y.get(), z.get()); } bool operator==(const VectorProperty& other) const; - void set(const R3& d) { m_value = d; } - R3 get() const { return m_value; } + void setX(double _x) { x.set(_x); } + void setY(double _y) { y.set(_y); } + void setZ(double _z) { z.set(_z); } + void set(const R3& d) { setX(d.x()); setY(d.y()); setZ(d.z());} + R3 get() const { return *this; } QString persistentTag() const { return m_persistentTag; } QString uid() const { return m_uid; } void setUid(const QString& uid) { m_uid = uid; } - R3& r3() { return m_value; } - private: - R3 m_value; QString m_persistentTag; QString m_uid; + DoubleProperty x; + DoubleProperty y; + DoubleProperty z; + VectorDescriptor m_descriptor; }; diff --git a/GUI/Model/Device/RectangularDetectorItem.cpp b/GUI/Model/Device/RectangularDetectorItem.cpp index 12fbfcc2baf..cdc4701dd26 100644 --- a/GUI/Model/Device/RectangularDetectorItem.cpp +++ b/GUI/Model/Device/RectangularDetectorItem.cpp @@ -93,11 +93,11 @@ RectangularDetectorItem::RectangularDetectorItem() "Normal vector", "Normal of the detector plane with length equal to the sample detector distance", Unit::unitless, "normalVector"); - m_normalVector.r3().setX(default_detector_distance); + m_normalVector.setX(default_detector_distance); m_directionVector.init("Direction vector", "Detector axis direction vector w.r.t. the sample coordinate system", Unit::unitless, "directionVector"); - m_directionVector.r3().setY(-1.0); + m_directionVector.setY(-1.0); m_u0.init("u0", "", default_detector_width / 2., "mm", 3, RealLimits::limitless(), "u0"); m_v0.init("v0", "", 0.0, "mm", 3, RealLimits::limitless(), "v0"); -- GitLab