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

VectorProperty: serialization uses DoubleProperties

parent a0445fa1
No related branches found
No related tags found
1 merge request!1154rm VectorDescriptor
......@@ -85,14 +85,12 @@ void Serialize::rwProperty(Streamer& s, const QString& tag, DoubleProperty& d)
w->writeStartElement(tag);
GUI::Session::XML::writeAttribute(w, XML::Tags::Value, d.get());
w->writeAttribute(XML::Tags::Id, d.uid());
GUI::Session::XML::writeAttribute(w, XML::Tags::Decimals, d.decimals());
w->writeEndElement();
} else if (QXmlStreamReader* r = s.xmlReader()) {
r->readNextStartElement();
s.assertCurrentTag(tag);
d.set(r->attributes().value(XML::Tags::Value).toDouble());
d.setUid(r->attributes().value(XML::Tags::Id).toString());
d.setDecimals(r->attributes().value(XML::Tags::Decimals).toUInt());
s.gotoEndElementOfTag(tag);
} else
ASSERT(0);
......
......@@ -29,9 +29,22 @@ void VectorProperty::init(const QString &label, const QString &tooltip, const R3
const std::variant<QString, Unit> &unit, uint decimals, double step,
const RealLimits &limits, const QString &uidPrefix)
{
m_uid = QUuid::createUuid().toString();
m_descriptor.init(label, tooltip, &x, &y, &z, unit);
m_x.init(label, tooltip, value.x(), unit, decimals, step, limits, uidPrefix);
m_y.init(label, tooltip, value.y(), unit, decimals, step, limits, uidPrefix);
m_z.init(label, tooltip, value.z(), unit, decimals, step, limits, uidPrefix);
if(uidPrefix.size()>0)
m_uid = uidPrefix + "/" + QUuid::createUuid().toString();
else
m_uid = QUuid::createUuid().toString();
m_x.setUid(m_uid+"/x");
m_y.setUid(m_uid+"/y");
m_z.setUid(m_uid+"/z");
// temporary
m_descriptor.init(label, tooltip, &m_x, &m_y, &m_z, unit);
m_descriptor.uid = [this] { return m_uid; };
}
......@@ -40,22 +53,20 @@ bool VectorProperty::operator==(const VectorProperty& other) const
return (r3() == other.r3()) && (m_uid == other.m_uid);
}
void Serialize::rwProperty(Streamer& s, const QString& tag, VectorProperty& d)
void VectorProperty::rwProperty(Streamer& s, const QString& tag)
{
if (QXmlStreamWriter* w = s.xmlWriter()) {
w->writeStartElement(tag);
GUI::Session::XML::writeAttribute(w, XML::Tags::Value, d.r3());
GUI::Session::XML::writeUid(w, d.uid());
Serialize::rwProperty(s, "X", m_x);
Serialize::rwProperty(s, "Y", m_y);
Serialize::rwProperty(s, "Z", m_z);
w->writeEndElement();
} else if (QXmlStreamReader* r = s.xmlReader()) {
r->readNextStartElement();
s.assertCurrentTag(tag);
R3 vec;
QString uid;
GUI::Session::XML::readAttribute(r, XML::Tags::Value, &vec);
GUI::Session::XML::readAttribute(r, XML::Tags::Id, &uid);
d.set(vec);
d.setUid(uid);
Serialize::rwProperty(s, "X", m_x);
Serialize::rwProperty(s, "Y", m_y);
Serialize::rwProperty(s, "Z", m_z);
s.gotoEndElementOfTag(tag);
} else
ASSERT(0);
......
......@@ -40,32 +40,31 @@ public:
VectorDescriptor descriptor() const { return m_descriptor; }
operator VectorDescriptor() const { return m_descriptor; }
operator R3() const { return R3(x.get(), y.get(), z.get()); }
operator R3() const { return R3(m_x.get(), m_y.get(), m_z.get()); }
bool operator==(const VectorProperty& other) const;
void setX(double _x) { x.set(_x); }
void setY(double _y) { y.set(_y); }
void setZ(double _z) { z.set(_z); }
void setX(double _x) { m_x.set(_x); }
void setY(double _y) { m_y.set(_y); }
void setZ(double _z) { m_z.set(_z); }
void set(const R3& d) { setX(d.x()); setY(d.y()); setZ(d.z());}
R3 r3() const { return *this; }
QString uid() const { return m_uid; }
void setUid(const QString& uid) { m_uid = uid; }
void rwProperty(Streamer &s, const QString &tag);
private:
QString m_uid;
QString m_uid; //!< Unique id of this vector property.
DoubleProperty x;
DoubleProperty y;
DoubleProperty z;
DoubleProperty m_x;
DoubleProperty m_y;
DoubleProperty m_z;
// temporary
VectorDescriptor m_descriptor;
};
namespace Serialize {
void rwProperty(Streamer& s, const QString &tag, VectorProperty& d);
} // namespace Serialize
// clang-format off
//! Add a member, a getter and a setter for a VectorProperty
......
......@@ -168,8 +168,8 @@ void InstrumentItem::serialize(Streamer& s)
Serialize::rwValue(s, Tag::Name, m_name);
Serialize::rwValue(s, Tag::Description, m_description);
Serialize::rwValue(s, Tag::WithPolarizerAnalyzer, m_withPolarizerAnalyzer);
Serialize::rwProperty(s, Tag::Polarization, m_polarization);
Serialize::rwProperty(s, Tag::AnalyzerDirection, m_analyzerDirection);
m_polarization.rwProperty(s, Tag::Polarization);
m_analyzerDirection.rwProperty(s, Tag::AnalyzerDirection);
Serialize::rwProperty(s, Tag::AnalyzerEfficiency, m_analyzerEfficiency);
Serialize::rwProperty(s, Tag::AnalyzerTotalTransmission, m_analyzerTotalTransmission);
Serialize::rwSelected<BackgroundItemCatalog>(s, m_backgroundItem);
......
......@@ -126,8 +126,8 @@ void RectangularDetectorItem::serialize(Streamer& s)
Serialize::rwProperty(s, Tag::Width, m_width);
Serialize::rwProperty(s, Tag::Height, m_height);
Serialize::rwValue(s, Tag::Alignment, alignment);
Serialize::rwProperty(s, Tag::NormalVector, m_normalVector);
Serialize::rwProperty(s, Tag::DirectionVector, m_directionVector);
m_normalVector.rwProperty(s, Tag::NormalVector);
m_directionVector.rwProperty(s, Tag::DirectionVector);
Serialize::rwProperty(s, Tag::u0, m_u0);
Serialize::rwProperty(s, Tag::v0, m_v0);
Serialize::rwProperty(s, Tag::Distance, m_distance);
......
......@@ -54,7 +54,7 @@ void CompoundItem::serialize(Streamer& s)
{
s.assertVersion(0);
Serialize::rwProperty(s, Tag::Abundance, m_abundance);
Serialize::rwProperty(s, Tag::Position, m_position);
m_position.rwProperty(s, Tag::Position);
Serialize::rwSelected<RotationItemCatalog>(s, m_rotation);
Serialize::rwCatalogized<ItemWithParticlesCatalog>(s, Tag::Particles, m_particles, m_materials);
}
......
......@@ -51,7 +51,7 @@ void CoreAndShellItem::serialize(Streamer& s)
{
s.assertVersion(0);
Serialize::rwProperty(s, Tag::Abundance, m_abundance);
Serialize::rwProperty(s, Tag::Position, m_position);
m_position.rwProperty(s, Tag::Position);
Serialize::rwOptional(s, Tag::Core, m_core, m_materials);
Serialize::rwOptional(s, Tag::Shell, m_shell, m_materials);
}
......
......@@ -194,7 +194,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::rwProperty(s, Tag::Magnetization, m_magnetization);
m_magnetization.rwProperty(s, Tag::Magnetization);
Serialize::rwValue(s, Tag::UseRefractiveIndex, m_useRefractiveIndex);
// read m_useRefractiveIndex before moving on
......
......@@ -68,11 +68,11 @@ void MesocrystalItem::serialize(Streamer& s)
{
s.assertVersion(0);
Serialize::rwProperty(s, Tag::Abundance, m_abundance);
Serialize::rwProperty(s, Tag::Position, m_position);
m_position.rwProperty(s, Tag::Position);
Serialize::rwSelected<RotationItemCatalog>(s, m_rotation);
Serialize::rwProperty(s, Tag::VectorA, m_vectorA);
Serialize::rwProperty(s, Tag::VectorB, m_vectorB);
Serialize::rwProperty(s, Tag::VectorC, m_vectorC);
m_vectorA.rwProperty(s, Tag::VectorA);
m_vectorB.rwProperty(s, Tag::VectorB);
m_vectorC.rwProperty(s, Tag::VectorC);
Serialize::rwSelected<FormFactorItemCatalog>(s, m_outerShape);
Serialize::rwSelected<ItemWithParticlesCatalog>(s, m_basisParticle, m_materials);
}
......
......@@ -160,7 +160,7 @@ void MultiLayerItem::serialize(Streamer& s)
Serialize::rwValue(s, Tag::Name, m_name);
Serialize::rwValue(s, Tag::Description, m_description);
Serialize::rwProperty(s, Tag::CrossCorrelationLength, m_crossCorrelationLength);
Serialize::rwProperty(s, Tag::ExternalField, m_externalField);
m_externalField.rwProperty(s, Tag::ExternalField);
Serialize::rwClass(s, Tag::Materials, m_materials);
Serialize::rwVector(s, Tag::Layers, m_layers, &m_materials);
......
......@@ -53,7 +53,7 @@ void ParticleItem::serialize(Streamer& s)
s.assertVersion(0);
Serialize::rwValue(s, "MaterialIdentifier", m_materialIdentifier);
Serialize::rwProperty(s, Tag::Abundance, m_abundance);
Serialize::rwProperty(s, Tag::Position, m_position);
m_position.rwProperty(s, Tag::Position);
Serialize::rwSelected<RotationItemCatalog>(s, m_rotation);
Serialize::rwSelected<FormFactorItemCatalog>(s, m_formFactor);
}
......
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