diff --git a/GUI/Model/Device/BeamItems.cpp b/GUI/Model/Device/BeamItems.cpp index 3d2593853cfc8de0a8ce732bbc740651768fa35d..42364cbd94d3e6875e0bb0b054b23875c0994dc1 100644 --- a/GUI/Model/Device/BeamItems.cpp +++ b/GUI/Model/Device/BeamItems.cpp @@ -32,6 +32,7 @@ const QString Wavelength("Wavelength"); const QString AzimuthalAngle("AzimuthalAngle"); const QString InclinationAngle("InclinationAngle"); const QString Footprint("Footprint"); +const QString BaseData("BaseData"); } // namespace Tag @@ -57,11 +58,79 @@ BeamItem::BeamItem() void BeamItem::serialize(Streamer& s) { - s.assertVersion(0); - Serialize::rwProperty(s, Tag::Intensity, m_intensity); - Serialize::rwClass(s, Tag::Wavelength, *m_wavelengthItem); - Serialize::rwClass(s, Tag::AzimuthalAngle, *m_azimuthalAngleItem); - Serialize::rwClass(s, Tag::InclinationAngle, *m_inclinationAngleItem); +// s.assertVersion(0); +// Serialize::rwProperty(s, Tag::Intensity, m_intensity); +// Serialize::rwClass(s, Tag::Wavelength, *m_wavelengthItem); +// Serialize::rwClass(s, Tag::AzimuthalAngle, *m_azimuthalAngleItem); +// Serialize::rwClass(s, Tag::InclinationAngle, *m_inclinationAngleItem); + if (s.xmlReader()) + readFrom(s.xmlReader()); + else if (s.xmlWriter()) + writeTo(s.xmlWriter()); +} + +void BeamItem::writeTo(QXmlStreamWriter *w) const +{ + ASSERT(m_wavelengthItem); + ASSERT(m_inclinationAngleItem); + + XML::writeAttribute(w, XML::Attrib::version, uint(1)); + + // intensity + w->writeStartElement(Tag::Intensity); + m_intensity.writeTo(w); + w->writeEndElement(); + + // wavelength + w->writeStartElement(Tag::Wavelength); + m_wavelengthItem->writeTo(w); + w->writeEndElement(); + + // azimuthal angle + w->writeStartElement(Tag::AzimuthalAngle); + m_azimuthalAngleItem->writeTo(w); + w->writeEndElement(); + + // inclination angle + w->writeStartElement(Tag::InclinationAngle); + m_inclinationAngleItem->writeTo(w); + w->writeEndElement(); +} + +void BeamItem::readFrom(QXmlStreamReader *r) +{ + ASSERT(m_wavelengthItem); + ASSERT(m_inclinationAngleItem); + + const uint version = XML::readUIntAttribute(r, XML::Attrib::version); + Q_UNUSED(version) + + while (r->readNextStartElement()) { + QString tag = r->name().toString(); + + // intensity + if (tag == Tag::Intensity) { + m_intensity.readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + // wavelength + } else if (tag == Tag::Wavelength) { + m_wavelengthItem->readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + // azimuthal angle + } else if (tag == Tag::AzimuthalAngle) { + m_azimuthalAngleItem->readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + // inclination angle + } else if (tag == Tag::InclinationAngle) { + m_inclinationAngleItem->readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + } else + r->skipCurrentElement(); + } } double BeamItem::wavelength() const @@ -141,9 +210,51 @@ SpecularBeamItem::SpecularBeamItem(const InstrumentItem* owningInstrument) void SpecularBeamItem::serialize(Streamer& s) { - s.assertVersion(0); - Serialize::rwBaseClass<BeamItem>(s, "BeamItem", this); - m_footprint.rwSelected(s, Tag::Footprint); +// s.assertVersion(0); +// Serialize::rwBaseClass<BeamItem>(s, "BeamItem", this); +// m_footprint.rwSelected(s, Tag::Footprint); + if (s.xmlReader()) + readFrom(s.xmlReader()); + else if (s.xmlWriter()) + writeTo(s.xmlWriter()); +} + +void SpecularBeamItem::writeTo(QXmlStreamWriter *w) const +{ + XML::writeAttribute(w, XML::Attrib::version, uint(1)); + + // parameters from base class + w->writeStartElement(Tag::BaseData); + BeamItem::writeTo(w); + w->writeEndElement(); + + // footprint + w->writeStartElement(Tag::Footprint); + m_footprint.writeTo(w); + w->writeEndElement(); +} + +void SpecularBeamItem::readFrom(QXmlStreamReader *r) +{ + const uint version = XML::readUIntAttribute(r, XML::Attrib::version); + Q_UNUSED(version) + + while (r->readNextStartElement()) { + QString tag = r->name().toString(); + + // parameters from base class + if (tag == Tag::BaseData) { + BeamItem::readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + // footprint + } else if (tag == Tag::Footprint) { + m_footprint.readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + } else + r->skipCurrentElement(); + } } double SpecularBeamItem::getInclinationAngle() const diff --git a/GUI/Model/Device/BeamItems.h b/GUI/Model/Device/BeamItems.h index 8e893fa249d101114eddd08543087e72b951938e..d5936454cd05316de2510bd2b57ad3ab20974c0a 100644 --- a/GUI/Model/Device/BeamItems.h +++ b/GUI/Model/Device/BeamItems.h @@ -35,6 +35,8 @@ public: virtual ~BeamItem() = default; virtual void serialize(Streamer& s); + virtual void writeTo(QXmlStreamWriter* w) const; + virtual void readFrom(QXmlStreamReader* r); DoubleProperty& intensity() { return m_intensity; } const DoubleProperty& intensity() const { return m_intensity; } @@ -73,6 +75,8 @@ class SpecularBeamItem : public BeamItem { public: explicit SpecularBeamItem(const InstrumentItem* owningInstrument); void serialize(Streamer& s) override; + void writeTo(QXmlStreamWriter* w) const override; + void readFrom(QXmlStreamReader* r) override; double getInclinationAngle() const override; void setInclinationAngle(double value) override;