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

MaterialItem: magnetization is derived from VectorProperty

parent 2691c61f
No related branches found
No related tags found
1 merge request!1152GUI: MaterialItem: derive descriptors from properties
......@@ -29,6 +29,11 @@ void VectorProperty::init(const QString& label, const QString& tooltip,
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) && (m_persistentTag == other.m_persistentTag);
}
void Serialize::rwProperty(Streamer& s, VectorProperty& d)
{
......
......@@ -38,6 +38,8 @@ public:
VectorDescriptor descriptor() const { return m_descriptor; }
operator VectorDescriptor() const { return m_descriptor; }
operator R3() const { return m_value; }
bool operator==(const VectorProperty& other) const;
void set(const R3& d) { m_value = d; }
R3 get() const { return m_value; }
......
......@@ -51,6 +51,8 @@ MaterialItem::MaterialItem()
m_sldRe.init("SLD, real", "Real part of SLD (SLD = real - i*imag), AA^{-2}", 0.0, Unit::unitless, "sldRe");
m_sldIm.init("SLD, imaginary", "Imaginary part of SLD (SLD = real - i*imag), AA^{-2}", 0.0, Unit::unitless, "sldIm");
m_magnetization.init("Magnetization", "Magnetization (A/m)", "A/m", "magnetization");
}
MaterialItem::MaterialItem(const MaterialItem& other)
......@@ -113,36 +115,7 @@ DoubleDescriptor MaterialItem::sldIm()
VectorDescriptor MaterialItem::magnetizationVector()
{
VectorDescriptor d("Magnetization", "Magnetization (A/m)", "A/m");
d.x.set = [=](double v) {
if (m_magnetization.x() != v) {
m_magnetization.setX(v);
emit dataChanged();
}
};
d.x.get = [=]() { return m_magnetization.x(); };
d.x.path = [=] { return uidForDescriptor("mx"); };
d.y.set = [=](double v) {
if (m_magnetization.y() != v) {
m_magnetization.setY(v);
emit dataChanged();
}
};
d.y.get = [=]() { return m_magnetization.y(); };
d.y.path = [=] { return uidForDescriptor("my"); };
d.z.set = [=](double v) {
if (m_magnetization.z() != v) {
m_magnetization.setZ(v);
emit dataChanged();
}
};
d.z.get = [=]() { return m_magnetization.z(); };
d.z.path = [=] { return uidForDescriptor("mz"); };
d.uid = [=] { return uidForDescriptor("magnetization"); };
return d;
return m_magnetization;
}
bool MaterialItem::hasRefractiveIndex() const
......@@ -193,8 +166,8 @@ R3 MaterialItem::magnetization() const
void MaterialItem::setMagnetization(const R3& magnetization)
{
if (m_magnetization != magnetization) {
m_magnetization = magnetization;
if (m_magnetization.get() != magnetization) {
m_magnetization.set(magnetization);
emit dataChanged();
}
}
......@@ -215,7 +188,7 @@ void MaterialItem::serialize(Streamer& s)
Serialize::rwValue(s, Tag::Name, m_name);
Serialize::rwValue(s, Tag::Id, m_id);
Serialize::rwValue(s, Tag::Color, m_color);
Serialize::rwValue(s, Tag::Magnetization, m_magnetization);
Serialize::rwProperty(s, /*Tag::Magnetization,*/ m_magnetization);
Serialize::rwValue(s, Tag::UseRefractiveIndex, m_useRefractiveIndex);
// read m_useRefractiveIndex before moving on
......@@ -246,11 +219,6 @@ void MaterialItem::updateFrom(const MaterialItem& other)
emit dataChanged();
}
QString MaterialItem::uidForDescriptor(const QString& postfix) const
{
return "material/" + identifier() + "/" + postfix;
}
bool MaterialItem::operator==(const MaterialItem& other) const
{
if(m_useRefractiveIndex != other.m_useRefractiveIndex)
......
......@@ -16,6 +16,7 @@
#define BORNAGAIN_GUI_MODEL_SAMPLE_MATERIALITEM_H
#include "GUI/Model/Descriptor/DoubleProperty.h"
#include "GUI/Model/Descriptor/VectorProperty.h"
#include <QColor>
#include <QObject>
#include <heinz/Complex.h>
......@@ -84,10 +85,6 @@ public:
void updateFrom(const MaterialItem& other);
private:
//! Returns a unique identifier for descriptors.
//! String postfix will be appended for human convenience.
QString uidForDescriptor(const QString& postfix) const;
//! Compares all contents. The inactive contents (e.g. SLD in case of refractive) are not taken
//! into account. Only used by updateFrom.
bool operator==(const MaterialItem& other) const;
......@@ -95,10 +92,8 @@ private:
QString m_name;
QString m_id;
QColor m_color;
R3 m_magnetization;
VectorProperty m_magnetization;
bool m_useRefractiveIndex = true;
DoubleProperty m_delta;
DoubleProperty m_beta;
DoubleProperty m_sldRe;
......
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