Skip to content
Snippets Groups Projects
Commit 4a6088a4 authored by Mikhail Svechnikov's avatar Mikhail Svechnikov
Browse files

VectorProperty: replace R3 member by 3 DoubleProperties

parent 1746e64b
No related branches found
No related tags found
1 merge request!1154rm VectorDescriptor
...@@ -48,6 +48,7 @@ void DoubleProperty::init(const QString& label, const QString& tooltip, double v ...@@ -48,6 +48,7 @@ void DoubleProperty::init(const QString& label, const QString& tooltip, double v
else else
m_uid = QUuid::createUuid().toString(); m_uid = QUuid::createUuid().toString();
// temporary
m_descriptor.label = label; m_descriptor.label = label;
m_descriptor.tooltip = tooltip; m_descriptor.tooltip = tooltip;
m_descriptor.decimals = decimals; m_descriptor.decimals = decimals;
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include "GUI/Model/Descriptor/DoubleDescriptor.h" #include "GUI/Model/Descriptor/DoubleDescriptor.h"
#include "GUI/Model/Descriptor/DoubleProperty.h"
#include <heinz/Vectors3D.h> #include <heinz/Vectors3D.h>
//! Describes properties of a 3D vector, consisting of three double values. //! Describes properties of a 3D vector, consisting of three double values.
...@@ -73,7 +74,7 @@ public: ...@@ -73,7 +74,7 @@ public:
z.label = "z"; 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) const std::variant<QString, Unit>& _unit)
{ {
label = _label; label = _label;
...@@ -93,18 +94,17 @@ public: ...@@ -93,18 +94,17 @@ public:
x.label = "x"; x.label = "x";
y.label = "y"; y.label = "y";
z.label = "z"; z.label = "z";
x.set = [=](double v) { const_cast<R3*>(vec)->setX(v); }; x.set = [=](double v) { const_cast<DoubleProperty*>(xDP)->set(v); };
x.get = [=]() { return vec->x(); }; x.get = [=]() { return xDP->get(); };
x.path = [=] { return uid() + "x"; }; x.path = [=] { return uid() + "x"; };
y.set = [=](double v) { const_cast<R3*>(vec)->setY(v); }; y.set = [=](double v) { const_cast<DoubleProperty*>(yDP)->set(v); };
y.get = [=]() { return vec->y(); }; y.get = [=]() { return yDP->get(); };
y.path = [=] { return uid() + "y"; }; y.path = [=] { return uid() + "y"; };
z.set = [=](double v) { const_cast<R3*>(vec)->setZ(v); }; z.set = [=](double v) { const_cast<DoubleProperty*>(zDP)->set(v); };
z.get = [=]() { return vec->z(); }; z.get = [=]() { return zDP->get(); };
z.path = [=] { return uid() + "z"; }; z.path = [=] { return uid() + "z"; };
} }
QString label; //!< A label text (short, no trailing colon) QString label; //!< A label text (short, no trailing colon)
QString tooltip; //!< Tooltip text QString tooltip; //!< Tooltip text
DoubleDescriptor x; DoubleDescriptor x;
......
...@@ -25,17 +25,16 @@ void VectorProperty::init(const QString& label, const QString& tooltip, ...@@ -25,17 +25,16 @@ void VectorProperty::init(const QString& label, const QString& tooltip,
m_persistentTag = persistentTag; m_persistentTag = persistentTag;
m_uid = QUuid::createUuid().toString(); 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; }; m_descriptor.uid = [this] { return m_uid; };
} }
bool VectorProperty::operator==(const VectorProperty& other) const 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); && (m_persistentTag == other.m_persistentTag);
} }
void Serialize::rwProperty(Streamer& s, VectorProperty& d) void Serialize::rwProperty(Streamer& s, VectorProperty& d)
{ {
if (QXmlStreamWriter* w = s.xmlWriter()) { if (QXmlStreamWriter* w = s.xmlWriter()) {
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#define BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORPROPERTY_H #define BORNAGAIN_GUI_MODEL_DESCRIPTOR_VECTORPROPERTY_H
#include "GUI/Model/Descriptor/VectorDescriptor.h" #include "GUI/Model/Descriptor/VectorDescriptor.h"
#include "GUI/Model/Descriptor/DoubleProperty.h"
#include <heinz/Vectors3D.h> #include <heinz/Vectors3D.h>
class Streamer; class Streamer;
...@@ -37,23 +38,27 @@ public: ...@@ -37,23 +38,27 @@ public:
VectorDescriptor descriptor() const { return m_descriptor; } VectorDescriptor descriptor() const { return m_descriptor; }
operator VectorDescriptor() 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; bool operator==(const VectorProperty& other) const;
void set(const R3& d) { m_value = d; } void setX(double _x) { x.set(_x); }
R3 get() const { return m_value; } 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 persistentTag() const { return m_persistentTag; }
QString uid() const { return m_uid; } QString uid() const { return m_uid; }
void setUid(const QString& uid) { m_uid = uid; } void setUid(const QString& uid) { m_uid = uid; }
R3& r3() { return m_value; }
private: private:
R3 m_value;
QString m_persistentTag; QString m_persistentTag;
QString m_uid; QString m_uid;
DoubleProperty x;
DoubleProperty y;
DoubleProperty z;
VectorDescriptor m_descriptor; VectorDescriptor m_descriptor;
}; };
......
...@@ -93,11 +93,11 @@ RectangularDetectorItem::RectangularDetectorItem() ...@@ -93,11 +93,11 @@ RectangularDetectorItem::RectangularDetectorItem()
"Normal vector", "Normal vector",
"Normal of the detector plane with length equal to the sample detector distance", "Normal of the detector plane with length equal to the sample detector distance",
Unit::unitless, "normalVector"); Unit::unitless, "normalVector");
m_normalVector.r3().setX(default_detector_distance); m_normalVector.setX(default_detector_distance);
m_directionVector.init("Direction vector", m_directionVector.init("Direction vector",
"Detector axis direction vector w.r.t. the sample coordinate system", "Detector axis direction vector w.r.t. the sample coordinate system",
Unit::unitless, "directionVector"); 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_u0.init("u0", "", default_detector_width / 2., "mm", 3, RealLimits::limitless(), "u0");
m_v0.init("v0", "", 0.0, "mm", 3, RealLimits::limitless(), "v0"); m_v0.init("v0", "", 0.0, "mm", 3, RealLimits::limitless(), "v0");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment