diff --git a/GUI/Model/Sample/CoreAndShellItem.cpp b/GUI/Model/Sample/CoreAndShellItem.cpp index fc313e28cb0a88b8b10ce26d315cb3a21db12a30..097e761082634b74c18acb29861dede25d1e8a15 100644 --- a/GUI/Model/Sample/CoreAndShellItem.cpp +++ b/GUI/Model/Sample/CoreAndShellItem.cpp @@ -22,13 +22,11 @@ #include "Sample/Scattering/Rotations.h" namespace { - namespace Tag { -const QString Abundance("Abundance"); -const QString Position("Position"); const QString Core("Core"); const QString Shell("Shell"); +const QString BaseData("BaseData"); } // namespace Tag @@ -42,18 +40,74 @@ const QString position_tooltip = "Relative position of the particle's reference CoreAndShellItem::CoreAndShellItem(const MaterialModel* materials) : ItemWithParticles(abundance_tooltip, position_tooltip) - , m_materials(materials) + , m_materialModel(materials) { } void CoreAndShellItem::serialize(Streamer& s) { - s.assertVersion(0); - Serialize::rwProperty(s, Tag::Abundance, m_abundance); - m_position.rwProperty(s, Tag::Position); +// s.assertVersion(0); +// Serialize::rwProperty(s, Tag::Abundance, m_abundance); +// m_position.rwProperty(s, Tag::Position); // TODO rotation??? - Serialize::rwOptional(s, Tag::Core, m_core, m_materials); - Serialize::rwOptional(s, Tag::Shell, m_shell, m_materials); +// Serialize::rwOptional(s, Tag::Core, m_core, m_materialModel); +// Serialize::rwOptional(s, Tag::Shell, m_shell, m_materialModel); + if (s.xmlReader()) + readFrom(s.xmlReader()); + else if (s.xmlWriter()) + writeTo(s.xmlWriter()); +} + +void CoreAndShellItem::writeTo(QXmlStreamWriter *w) const +{ + XML::writeAttribute(w, XML::Attrib::version, uint(1)); + + // parameters from base class + w->writeStartElement(Tag::BaseData); + ItemWithParticles::writeTo(w); + w->writeEndElement(); + + // core + if(m_core) { + w->writeStartElement(Tag::Core); + m_core->writeTo(w); + w->writeEndElement(); + } + + // shell + if(m_shell) { + w->writeStartElement(Tag::Shell); + m_shell->writeTo(w); + w->writeEndElement(); + } +} + +void CoreAndShellItem::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) { + ItemWithParticles::readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + // core + } else if (tag == Tag::Core) { + createCore(m_materialModel)->readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + // shell + } else if (tag == Tag::Shell) { + createShell(m_materialModel)->readFrom(r); + XML::gotoEndElementOfTag(r, tag); + + } else + r->skipCurrentElement(); + } } std::unique_ptr<CoreAndShell> CoreAndShellItem::createCoreAndShell() const @@ -81,11 +135,6 @@ ParticleItem* CoreAndShellItem::core() const return m_core.get(); } -void CoreAndShellItem::clearCore() -{ - m_core.reset(); -} - ParticleItem* CoreAndShellItem::createCore(const MaterialModel* materials) { m_core.reset(new ParticleItem(materials)); @@ -98,11 +147,6 @@ ParticleItem* CoreAndShellItem::shell() const return m_shell.get(); } -void CoreAndShellItem::clearShell() -{ - m_shell.reset(); -} - ParticleItem* CoreAndShellItem::createShell(const MaterialModel* materials) { m_shell.reset(new ParticleItem(materials)); diff --git a/GUI/Model/Sample/CoreAndShellItem.h b/GUI/Model/Sample/CoreAndShellItem.h index df97e72f010b6592b0a14516d4d8b6c508e4df5e..16f231a7f3ce58b34c3994783cb55dd25d6bda65 100644 --- a/GUI/Model/Sample/CoreAndShellItem.h +++ b/GUI/Model/Sample/CoreAndShellItem.h @@ -26,15 +26,15 @@ class CoreAndShellItem : public ItemWithParticles { public: CoreAndShellItem(const MaterialModel* materials); void serialize(Streamer& s) override; + void writeTo(QXmlStreamWriter* w) const; + void readFrom(QXmlStreamReader* r); std::unique_ptr<CoreAndShell> createCoreAndShell() const; ParticleItem* core() const; - void clearCore(); ParticleItem* createCore(const MaterialModel* materials); ParticleItem* shell() const; - void clearShell(); ParticleItem* createShell(const MaterialModel* materials); QVector<ItemWithParticles*> containedItemsWithParticles() const override; @@ -42,7 +42,7 @@ public: private: std::unique_ptr<ParticleItem> m_core; std::unique_ptr<ParticleItem> m_shell; - const MaterialModel* m_materials; + const MaterialModel* m_materialModel; }; #endif // BORNAGAIN_GUI_MODEL_SAMPLE_COREANDSHELLITEM_H diff --git a/GUI/View/SampleDesigner/CoreAndShellForm.cpp b/GUI/View/SampleDesigner/CoreAndShellForm.cpp index 1943c2c1f6cecff7b34ef10a386fcca4d336b118..88a5af1963a2449dc30c67ef06bad830e4b32801 100644 --- a/GUI/View/SampleDesigner/CoreAndShellForm.cpp +++ b/GUI/View/SampleDesigner/CoreAndShellForm.cpp @@ -54,7 +54,7 @@ CoreAndShellForm::CoreAndShellForm(QWidget* parent, CoreAndShellItem* item, , m_item(item) , m_ec(ec) { - setTitle("Sim/shell particle"); + setTitle("Core/shell particle"); FormLayouter layouter(this, ec); layouter.setContentsMargins(30, 6, 0, 0); layouter.addVector(item->position(), false);