Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • c.trageser/bornagain
  • mlz/bornagain
2 results
Show changes
Commits on Source (14)
Showing
with 307 additions and 176 deletions
......@@ -15,6 +15,21 @@
#include "GUI/Model/Fit/ParameterTreeItems.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/Model/Session/ModelPath.h"
#include "GUI/Model/Session/SessionXML.h"
#include "GUI/Util/DeserializationException.h"
#include <QXmlStreamReader>
#include <QXmlStreamWriter>
using namespace GUI::Session::XML;
namespace {
namespace Tags {
const QString BackupValues("BackupValues");
const QString BackupValue("BackupValue");
const QString Link("Link");
const QString Value("Value");
} // namespace Tags
} // namespace
// ----------------------------------------------------------------------------
......@@ -27,13 +42,7 @@ ParameterLabelItem::ParameterLabelItem() : SessionItem(M_TYPE)
// ----------------------------------------------------------------------------
ParameterItem::ParameterItem() : SessionItem(M_TYPE)
{
// Link to original PropertyItem in one of components of MultiLayerItem or InstrumentItem
addProperty(P_LINK, QString());
// The back up value of PropertyItem to be able to reset parameter tuning tree to initial state
addProperty(P_BACKUP, 0.0);
}
ParameterItem::ParameterItem() : SessionItem(M_TYPE) {}
//! Sets current value to the original PropertyItem of MultiLayerItem/InstrumentItem.
......@@ -51,26 +60,18 @@ SessionItem* ParameterItem::linkedItem()
{
const SessionItem* jobItem = GUI::Model::Path::ancestor(this, JobItem::M_TYPE);
ASSERT(jobItem);
QString link = jobItem->itemName() + "/" + getItemValue(P_LINK).toString();
QString link = jobItem->itemName() + "/" + m_link;
return model()->itemForIndex(GUI::Model::Path::getIndexFromPath(model(), link));
}
void ParameterItem::setLink(const QString& link)
{
setItemValue(P_LINK, link);
m_link = link;
}
//! Restore the value from backup and propagate it to the linked item.
void ParameterItem::restoreFromBackup()
QString ParameterItem::link() const
{
double newValue = getItemValue(P_BACKUP).toDouble();
propagateValueToLink(newValue);
}
void ParameterItem::setBackup(double value)
{
setItemValue(P_BACKUP, value);
return m_link;
}
// ----------------------------------------------------------------------------
......@@ -81,3 +82,72 @@ ParameterContainerItem::ParameterContainerItem() : SessionItem(M_TYPE)
registerTag(T_CHILDREN, 0, -1, {ParameterLabelItem::M_TYPE});
setDefaultTag(T_CHILDREN);
}
void ParameterContainerItem::writeNonSessionItems(QXmlStreamWriter* writer) const
{
writeAttribute(writer, GUI::Session::XML::Version, int(1));
writer->writeStartElement(Tags::BackupValues);
for (auto v = m_backupValues.cbegin(); v != m_backupValues.cend(); v++) {
writer->writeEmptyElement(Tags::BackupValue);
writeAttribute(writer, Tags::Link, v.key());
writeAttribute(writer, Tags::Value, v.value());
}
writer->writeEndElement();
}
void ParameterContainerItem::readNonSessionItems(QXmlStreamReader* reader)
{
m_backupValues.clear();
const int version = reader->attributes().value(GUI::Session::XML::Version).toInt();
if (version < 1)
throw DeserializationException::tooOld();
if (version > 1)
throw DeserializationException::tooNew();
while (reader->readNextStartElement()) {
if (reader->name().toString() == Tags::BackupValues) {
while (reader->readNextStartElement()) {
ASSERT(reader->name().toString() == Tags::BackupValue);
QString link;
double d;
readAttribute(reader, Tags::Link, &link);
readAttribute(reader, Tags::Value, &d);
m_backupValues[link] = d;
reader->skipCurrentElement();
}
}
}
}
bool ParameterContainerItem::allowWritingChildToXml(SessionItem* /*child*/) const
{
// no children are written. The contained tree is always generated
return false;
}
void ParameterContainerItem::setBackupValue(const QString& link, double d)
{
m_backupValues[link] = d;
}
void ParameterContainerItem::restoreBackupValue(SessionItem* item)
{
ASSERT(item);
if (auto* parameter = dynamic_cast<ParameterItem*>(item))
if (m_backupValues.contains(parameter->link()))
parameter->propagateValueToLink(m_backupValues[parameter->link()]);
for (auto* child : item->children())
restoreBackupValue(child);
}
void ParameterContainerItem::restoreBackupValues()
{
for (auto* child : children())
restoreBackupValue(child);
}
......@@ -33,10 +33,6 @@ public:
//! The ParameterItem class represent a tuning value in a parameter tuning tree.
class ParameterItem : public SessionItem {
private:
static constexpr auto P_LINK{"Link"};
static constexpr auto P_BACKUP{"Backup"};
public:
static constexpr auto M_TYPE{"Parameter"};
......@@ -45,9 +41,10 @@ public:
void propagateValueToLink(double newValue);
SessionItem* linkedItem();
void setLink(const QString& link);
QString link() const;
void restoreFromBackup();
void setBackup(double value);
private:
QString m_link; //!< Link to original PropertyItem
};
//! The ParameterContainerItem is a top item to hold all ParameterItem, represents an entry
......@@ -58,6 +55,18 @@ public:
static constexpr auto M_TYPE{"Parameter Container"};
ParameterContainerItem();
void writeNonSessionItems(QXmlStreamWriter* writer) const override;
void readNonSessionItems(QXmlStreamReader* reader) override;
bool allowWritingChildToXml(SessionItem* child) const override;
void setBackupValue(const QString& link, double d);
void restoreBackupValues();
private:
void restoreBackupValue(SessionItem* item);
QMap<QString, double> m_backupValues;
};
#endif // BORNAGAIN_GUI_MODEL_FIT_PARAMETERTREEITEMS_H
......@@ -26,9 +26,13 @@
#include "GUI/Model/Material/MaterialItemContainer.h"
#include "GUI/Model/Sample/ItemWithMaterial.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/Session/SessionXML.h"
#include "GUI/Model/Session/SimulationOptionsItem.h"
#include "GUI/Util/DeserializationException.h"
#include "GUI/Util/Error.h"
using namespace GUI::Session::XML;
namespace {
const QString SimulationOptionsTag("SimulationOptions");
} // namespace
......@@ -392,6 +396,8 @@ void JobItem::setPresentationType(const QString& type)
void JobItem::writeNonSessionItems(QXmlStreamWriter* writer) const
{
writeAttribute(writer, GUI::Session::XML::Version, int(1));
writer->writeStartElement(SimulationOptionsTag);
m_simulationOptionsItem.writeContentTo(writer);
writer->writeEndElement();
......@@ -399,10 +405,19 @@ void JobItem::writeNonSessionItems(QXmlStreamWriter* writer) const
void JobItem::readNonSessionItems(QXmlStreamReader* reader)
{
reader->readNextStartElement();
if (reader->name() == SimulationOptionsTag) {
m_simulationOptionsItem.readContentFrom(reader);
reader->skipCurrentElement();
const int version = reader->attributes().value(GUI::Session::XML::Version).toInt();
if (version < 1)
throw DeserializationException::tooOld();
if (version > 1)
throw DeserializationException::tooNew();
while (reader->readNextStartElement()) {
if (reader->name() == SimulationOptionsTag) {
m_simulationOptionsItem.readContentFrom(reader);
reader->skipCurrentElement();
}
}
}
......
......@@ -90,7 +90,7 @@ JobItem* JobModel::addJob(const MultiLayerItem* multiLayerItem,
jobItem->setSampleName(multiLayerItem->itemName());
GUI::Model::ParameterTreeUtils::createParameterTree(jobItem);
GUI::Model::ParameterTreeUtils::createParameterTree(jobItem, true);
GUI::Model::JobFunctions::setupJobItemOutput(jobItem);
......@@ -108,7 +108,7 @@ QVector<JobItem*> JobModel::jobItems() const
//! restore instrument and sample model from backup for given JobItem
void JobModel::restore(JobItem* jobItem)
{
restoreItem(jobItem->parameterContainerItem());
jobItem->parameterContainerItem()->restoreBackupValues();
}
bool JobModel::hasUnfinishedJobs()
......@@ -172,6 +172,9 @@ void JobModel::readFrom(QXmlStreamReader* reader, MessageService* messageService
itemWithMaterial->setMaterialFinder([=](const QString& id) {
return jobItem->materialContainerItem()->findMaterialById(id);
});
// Create the not stored parameter tuning tree
GUI::Model::ParameterTreeUtils::createParameterTree(jobItem, false);
}
}
......@@ -221,13 +224,3 @@ QString JobModel::generateJobName()
}
return QString("job") + QString::number(++glob_index);
}
void JobModel::restoreItem(SessionItem* item)
{
ASSERT(item);
if (auto* parameter = dynamic_cast<ParameterItem*>(item))
parameter->restoreFromBackup();
for (auto* child : item->children())
restoreItem(child);
}
......@@ -61,7 +61,6 @@ public slots:
private:
QString generateJobName();
void restoreItem(SessionItem* item);
JobQueueData* m_queue_data;
};
......
......@@ -18,9 +18,9 @@
#include "GUI/Model/Group/PropertyItem.h"
#include "GUI/Model/Instrument/InstrumentItems.h"
#include "GUI/Model/Job/JobItem.h"
#include "GUI/Model/Session/ModelPath.h"
#include "GUI/Model/Material/MaterialItemContainer.h"
#include "GUI/Model/Sample/MultiLayerItem.h"
#include "GUI/Model/Session/ModelPath.h"
#include "GUI/Util/Error.h"
#include <QStack>
......@@ -29,7 +29,8 @@ using boost::polymorphic_downcast;
namespace {
void handleItem(SessionItem* tree, const SessionItem* source)
void handleItem(ParameterContainerItem* container, SessionItem* tree, const SessionItem* source,
bool recreateBackupValues)
{
if (tree->hasModelType<ParameterLabelItem>())
tree->setDisplayName(source->itemName());
......@@ -44,7 +45,8 @@ void handleItem(SessionItem* tree, const SessionItem* source)
path = path.mid(firstSlash + 1);
auto* parItem = polymorphic_downcast<ParameterItem*>(tree);
parItem->setLink(path);
parItem->setBackup(sourceValue);
if (recreateBackupValues)
container->setBackupValue(parItem->link(), sourceValue);
return;
}
......@@ -56,18 +58,18 @@ void handleItem(SessionItem* tree, const SessionItem* source)
if (child->hasModelType<PropertyItem>()) {
if (child->value().type() == QVariant::Double) {
auto* branch = tree->model()->insertItem<ParameterItem>(tree);
handleItem(branch, child);
handleItem(container, branch, child, recreateBackupValues);
}
} else if (child->hasModelType<GroupItem>()) {
SessionItem* currentItem = dynamic_cast<GroupItem*>(child)->currentItem();
if (currentItem && currentItem->numberOfChildren() > 0) {
auto* branch = tree->model()->insertItem<ParameterLabelItem>(tree);
handleItem(branch, currentItem);
handleItem(container, branch, currentItem, recreateBackupValues);
}
} else {
auto* branch = tree->model()->insertItem<ParameterLabelItem>(tree);
handleItem(branch, child);
handleItem(container, branch, child, recreateBackupValues);
}
}
}
......@@ -76,25 +78,25 @@ void handleItem(SessionItem* tree, const SessionItem* source)
//! Populates ParameterContainer with ParameterItem's corresponding to all properties found
//! in a source item.
void populateParameterContainer(SessionItem* container, const SessionItem* source)
void populateParameterContainer(ParameterContainerItem* container, const SessionItem* source,
bool recreateBackupValues)
{
if (!container->hasModelType<ParameterContainerItem>())
throw Error("GUI::Model::ParameterTreeUtils::populateParameterContainer() -> Error. "
"Not a ParameterContainerType.");
auto* sourceLabel = container->model()->insertItem<ParameterLabelItem>(container);
handleItem(sourceLabel, source);
handleItem(container, sourceLabel, source, recreateBackupValues);
}
} // namespace
void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem)
void GUI::Model::ParameterTreeUtils::createParameterTree(JobItem* jobItem,
bool recreateBackupValues)
{
auto* container = jobItem->createParameterContainerItem();
auto* container = jobItem->parameterContainerItem();
if (!container)
container = jobItem->createParameterContainerItem();
populateParameterContainer(container, jobItem->materialContainerItem());
populateParameterContainer(container, jobItem->materialContainerItem(), recreateBackupValues);
populateParameterContainer(container, jobItem->sampleItem());
populateParameterContainer(container, jobItem->sampleItem(), recreateBackupValues);
populateParameterContainer(container, jobItem->instrumentItem());
populateParameterContainer(container, jobItem->instrumentItem(), recreateBackupValues);
}
......@@ -29,7 +29,7 @@ class ParameterItem;
namespace GUI::Model::ParameterTreeUtils {
void createParameterTree(JobItem* jobItem);
void createParameterTree(JobItem* jobItem, bool recreateBackupValues);
} // namespace GUI::Model::ParameterTreeUtils
......
......@@ -543,6 +543,11 @@ void SessionItem::writeNonSessionItems(QXmlStreamWriter*) const {}
void SessionItem::readNonSessionItems(QXmlStreamReader*) {}
bool SessionItem::allowWritingChildToXml(SessionItem* /*child*/) const
{
return true;
}
void SessionItem::childDeleted(SessionItem* child)
{
int index = rowOfChild(child);
......
......@@ -314,6 +314,7 @@ public:
virtual void writeNonSessionItems(QXmlStreamWriter* writer) const;
virtual void readNonSessionItems(QXmlStreamReader* reader);
virtual bool allowWritingChildToXml(SessionItem* child) const;
private:
void childDeleted(SessionItem* child);
......
......@@ -44,10 +44,7 @@ QVariant toolTipRole(const SessionItem& item, int ncol)
} // namespace
SessionModel::SessionModel(QString model_tag, QObject* parent)
: QAbstractItemModel(parent)
, m_root_item(nullptr)
, m_name("DefaultName")
, m_model_tag(std::move(model_tag))
: QAbstractItemModel(parent), m_root_item(nullptr), m_model_tag(std::move(model_tag))
{
createRootItem();
}
......@@ -324,37 +321,6 @@ void SessionModel::clear()
endResetModel();
}
void SessionModel::load(const QString& filename)
{
beginResetModel();
QFile file(filename);
if (!file.open(QIODevice::ReadOnly))
throw Error(file.errorString());
clear();
m_root_item = GUI::Model::ItemFactory::CreateEmptyItem();
QXmlStreamReader reader(&file);
GUI::Session::XML::readItems(&reader, m_root_item);
if (reader.hasError())
throw Error(reader.errorString());
endResetModel();
}
void SessionModel::save(const QString& filename)
{
QFile file(filename);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
throw Error(file.errorString());
QXmlStreamWriter writer(&file);
writer.setAutoFormatting(true);
writer.writeStartDocument();
writer.writeStartElement("BornAgain");
writer.writeAttribute("Version", GUI::Util::Path::getBornAgainVersionString());
GUI::Session::XML::writeItemAndChildItems(&writer, m_root_item);
writer.writeEndElement(); // BornAgain
writer.writeEndDocument();
}
SessionItem* SessionModel::itemForIndex(const QModelIndex& index) const
{
if (index.isValid())
......@@ -374,8 +340,6 @@ void SessionModel::readFrom(QXmlStreamReader* reader, MessageService* messageSer
beginResetModel();
clear();
m_name = reader->attributes().value(GUI::Session::XML::ModelNameAttribute).toString();
GUI::Session::XML::readItems(reader, m_root_item, QString(), messageService);
if (reader->hasError())
throw Error(reader->errorString());
......@@ -384,7 +348,7 @@ void SessionModel::readFrom(QXmlStreamReader* reader, MessageService* messageSer
void SessionModel::writeTo(QXmlStreamWriter* writer)
{
GUI::Session::XML::writeTo(writer, m_root_item);
GUI::Session::XML::writeModel(writer, m_root_item);
}
//! Move given parameterized item to the new_parent at given row. If new_parent is not defined,
......
......@@ -84,13 +84,10 @@ public:
void removeItem(SessionItem* item);
QString getModelTag() const;
QString getModelName() const;
QVector<QString> acceptableDefaultItemTypes(const QModelIndex& parent) const;
virtual void clear();
void load(const QString& filename = "");
void save(const QString& filename = "");
// Sets mimedata pointer of item being dragged
void setDraggedItemType(const QString& type);
......@@ -132,7 +129,6 @@ protected:
private:
SessionItem* m_root_item;
QString m_dragged_item_type;
QString m_name; //!< model name
QString m_model_tag; //!< model tag (SampleModel, InstrumentModel)
};
......@@ -207,11 +203,6 @@ inline QString SessionModel::getModelTag() const
return m_model_tag;
}
inline QString SessionModel::getModelName() const
{
return m_name;
}
inline void SessionModel::setDraggedItemType(const QString& type)
{
m_dragged_item_type = type;
......
......@@ -54,14 +54,13 @@ SessionItem* createItem(SessionItem* parent, const QString& modelType, const QSt
} // namespace
void GUI::Session::XML::writeTo(QXmlStreamWriter* writer, SessionItem* parent)
void GUI::Session::XML::writeModel(QXmlStreamWriter* writer, SessionItem* modelRootItem)
{
ASSERT(writer);
ASSERT(parent);
writer->writeStartElement(parent->model()->getModelTag());
writer->writeAttribute(GUI::Session::XML::ModelNameAttribute, parent->model()->getModelName());
ASSERT(modelRootItem);
writer->writeStartElement(modelRootItem->model()->getModelTag());
writeItemAndChildItems(writer, parent);
writeItemAndChildItems(writer, modelRootItem);
writer->writeEndElement(); // m_model_tag
}
......@@ -83,7 +82,8 @@ void GUI::Session::XML::writeItemAndChildItems(QXmlStreamWriter* writer, const S
}
for (auto* child : item->children())
writeItemAndChildItems(writer, child);
if (item->allowWritingChildToXml(child))
writeItemAndChildItems(writer, child);
QByteArray a = item->serializeBinaryData();
if (!a.isEmpty()) {
......@@ -95,10 +95,12 @@ void GUI::Session::XML::writeItemAndChildItems(QXmlStreamWriter* writer, const S
QString nonSessionItemContent;
QXmlStreamWriter nonSessionItemStream(&nonSessionItemContent);
nonSessionItemStream.writeStartElement(
GUI::Session::XML::NonSessionItemData); // for following writeAttrib
const auto sizeBefore = nonSessionItemContent.size();
item->writeNonSessionItems(&nonSessionItemStream);
if (!nonSessionItemContent.isEmpty()) {
if (sizeBefore != nonSessionItemContent.size()) {
writer->writeStartElement(GUI::Session::XML::NonSessionItemData);
writer->writeAttribute(GUI::Session::XML::Version, "1");
item->writeNonSessionItems(writer);
writer->writeEndElement();
}
......@@ -114,11 +116,11 @@ void GUI::Session::XML::writeAttribute(QXmlStreamWriter* writer, const QString&
ASSERT(variant.isValid());
if (variant.type() == QVariant::Double) {
writer->writeAttribute(attributeName, QString::number(variant.toDouble(), 'e', 12));
writeAttribute(writer, attributeName, variant.toDouble());
} else if (variant.type() == QVariant::Int) {
writer->writeAttribute(attributeName, QString::number(variant.toInt()));
writeAttribute(writer, attributeName, variant.toInt());
} else if (variant.type() == QVariant::UInt) {
writer->writeAttribute(attributeName, QString::number(variant.toUInt()));
writeAttribute(writer, attributeName, variant.toUInt());
} else if (variant.type() == QVariant::Bool) {
writer->writeAttribute(attributeName, QString::number(variant.toBool()));
} else if (variant.type() == QVariant::String) {
......@@ -137,6 +139,39 @@ void GUI::Session::XML::writeAttribute(QXmlStreamWriter* writer, const QString&
+ QString(variant.typeName()));
}
void GUI::Session::XML::writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName,
const R3& vec)
{
writeAttribute(writer, attributeBaseName + "X", vec.x());
writeAttribute(writer, attributeBaseName + "Y", vec.y());
writeAttribute(writer, attributeBaseName + "Z", vec.z());
}
void GUI::Session::XML::writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName,
const complex_t& c)
{
writeAttribute(writer, attributeBaseName + "Re", c.real());
writeAttribute(writer, attributeBaseName + "Im", c.imag());
}
void GUI::Session::XML::writeAttribute(QXmlStreamWriter* writer, const QString& attributeName,
double d)
{
writer->writeAttribute(attributeName, QString::number(d, 'e', 12));
}
void GUI::Session::XML::writeAttribute(QXmlStreamWriter* writer, const QString& attributeName,
int d)
{
writer->writeAttribute(attributeName, QString::number(d));
}
void GUI::Session::XML::writeAttribute(QXmlStreamWriter* writer, const QString& attributeName,
unsigned d)
{
writer->writeAttribute(attributeName, QString::number(d));
}
void GUI::Session::XML::writeVariant(QXmlStreamWriter* writer, QVariant variant, int role)
{
ASSERT(writer);
......@@ -199,8 +234,10 @@ void GUI::Session::XML::readItems(QXmlStreamReader* reader, SessionItem* parent,
parent = newItem;
parent->setDisplayName(displayName);
}
ASSERT(reader->name() == GUI::Session::XML::ItemTag);
} else if (reader->name() == GUI::Session::XML::ParameterTag) {
GUI::Session::XML::readProperty(reader, parent, messageService);
ASSERT(reader->name() == GUI::Session::XML::ParameterTag);
} else if (reader->name() == GUI::Session::XML::BinaryData) {
if (reader->attributes().value(GUI::Session::XML::Version).toInt() == 1) {
QString valueAsBase64 =
......@@ -210,11 +247,10 @@ void GUI::Session::XML::readItems(QXmlStreamReader* reader, SessionItem* parent,
parent->deserializeBinaryData(data);
} else
throw DeserializationException::tooNew();
ASSERT(reader->name() == GUI::Session::XML::BinaryData);
} else if (reader->name() == GUI::Session::XML::NonSessionItemData) {
if (reader->attributes().value(GUI::Session::XML::Version).toInt() == 1)
parent->readNonSessionItems(reader);
else
throw DeserializationException::tooNew();
parent->readNonSessionItems(reader);
ASSERT(reader->name() == GUI::Session::XML::NonSessionItemData);
}
} else if (reader->isEndElement()) {
if (reader->name() == GUI::Session::XML::ItemTag && parent)
......@@ -325,3 +361,42 @@ unsigned GUI::Session::XML::readUIntAttribute(QXmlStreamReader* reader,
{
return reader->attributes().value(attributeName).toUInt();
}
void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& attributeName,
QString* s)
{
*s = reader->attributes().value(attributeName).toString();
}
void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& attributeName,
QColor* c)
{
QString parameter_value = reader->attributes().value(attributeName).toString();
*c = QColor(parameter_value);
}
void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& attributeBaseName,
R3* vec)
{
double x, y, z;
readAttribute(reader, attributeBaseName + "X", &x);
readAttribute(reader, attributeBaseName + "Y", &y);
readAttribute(reader, attributeBaseName + "Z", &z);
*vec = {x, y, z};
}
void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& attributeBaseName,
complex_t* c)
{
double r, i;
readAttribute(reader, attributeBaseName + "Re", &r);
readAttribute(reader, attributeBaseName + "Im", &i);
c->real(r);
c->imag(i);
}
void GUI::Session::XML::readAttribute(QXmlStreamReader* reader, const QString& attributeName,
double* d)
{
*d = reader->attributes().value(attributeName).toDouble();
}
......@@ -15,6 +15,8 @@
#ifndef BORNAGAIN_GUI_MODEL_SESSION_SESSIONXML_H
#define BORNAGAIN_GUI_MODEL_SESSION_SESSIONXML_H
#include <heinz/Complex.h>
#include <heinz/Vectors3D.h>
#include <QVariant>
class QXmlStreamWriter;
......@@ -36,7 +38,6 @@ const QString RealDataModelTag("RealDataModel");
const QString TagAttribute("Tag");
const QString ModelNameAttribute("Name");
const QString ItemTag("Item");
const QString ModelTypeAttribute("ModelType");
const QString DisplayNameAttribute("DisplayName");
......@@ -53,7 +54,7 @@ const QString ParameterExtAttribute("ParExt");
const QString ExternalPropertyColorAtt("Color");
const QString ExternalPropertyIdentifierAtt("Identifier");
void writeTo(QXmlStreamWriter* writer, SessionItem* parent);
void writeModel(QXmlStreamWriter* writer, SessionItem* modelRootItem);
void writeItemAndChildItems(QXmlStreamWriter* writer, const SessionItem* item);
//! Write the variant as a complete tag, including the given role
......@@ -63,6 +64,12 @@ void writeVariant(QXmlStreamWriter* writer, QVariant variant, int role);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName,
const QVariant& variant);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, int d);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, unsigned d);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeName, double d);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const R3& vec);
void writeAttribute(QXmlStreamWriter* writer, const QString& attributeBaseName, const complex_t& c);
void readItems(QXmlStreamReader* reader, SessionItem* parent, QString topTag = "",
MessageService* messageService = nullptr);
QString readProperty(QXmlStreamReader* reader, SessionItem* item,
......@@ -71,6 +78,12 @@ QString readProperty(QXmlStreamReader* reader, SessionItem* item,
bool readBoolAttribute(QXmlStreamReader* reader, const QString& attributeName);
unsigned readUIntAttribute(QXmlStreamReader* reader, const QString& attributeName);
void readAttribute(QXmlStreamReader* reader, const QString& attributeName, double* d);
void readAttribute(QXmlStreamReader* reader, const QString& attributeName, QString* s);
void readAttribute(QXmlStreamReader* reader, const QString& attributeName, QColor* c);
void readAttribute(QXmlStreamReader* reader, const QString& attributeBaseName, R3* vec);
void readAttribute(QXmlStreamReader* reader, const QString& attributeBaseName, complex_t* c);
} // namespace GUI::Session::XML
#endif // BORNAGAIN_GUI_MODEL_SESSION_SESSIONXML_H
......@@ -14,7 +14,7 @@ QString itemToXML(SessionItem* item)
{
QString result;
QXmlStreamWriter writer(&result);
GUI::Session::XML::writeTo(&writer, item);
GUI::Session::XML::writeModel(&writer, item);
return result;
}
......@@ -37,7 +37,7 @@ TEST_F(TestSessionXML, sessionItem)
SessionModel source("TestModel");
source.insertItem<PropertyItem>();
expected = "<TestModel Name=\"DefaultName\">"
expected = "<TestModel>"
"<Item ModelType=\"Property\" Tag=\"rootTag\" DisplayName=\"Property\"/>"
"</TestModel>";
EXPECT_EQ(itemToXML(source.rootItem()), expected);
......
......@@ -1911,8 +1911,8 @@ class R3(object):
def __init__(self, *args):
r"""
__init__(R3 self, double const x_, double const y_, double const z_) -> R3
__init__(R3 self) -> R3
__init__(R3 self, double const x, double const y, double const z) -> R3
"""
_libBornAgainSample.R3_swiginit(self, _libBornAgainSample.new_R3(*args))
......@@ -2207,8 +2207,8 @@ class C3(object):
def __init__(self, *args):
r"""
__init__(C3 self, std::complex< double > const x_, std::complex< double > const y_, std::complex< double > const z_) -> C3
__init__(C3 self) -> C3
__init__(C3 self, std::complex< double > const x, std::complex< double > const y, std::complex< double > const z) -> C3
"""
_libBornAgainSample.C3_swiginit(self, _libBornAgainSample.new_C3(*args))
......
......@@ -28116,20 +28116,7 @@ SWIGINTERN PyObject *vector_pvacuum_double_t_swiginit(PyObject *SWIGUNUSEDPARM(s
return SWIG_Python_InitShadowInstance(args);
}
 
SWIGINTERN PyObject *_wrap_new_R3__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {
PyObject *resultobj = 0;
Vec3< double > *result = 0 ;
if ((nobjs < 0) || (nobjs > 0)) SWIG_fail;
result = (Vec3< double > *)new Vec3< double >();
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Vec3T_double_t, SWIG_POINTER_NEW | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_new_R3__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
SWIGINTERN PyObject *_wrap_new_R3__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
double arg1 ;
double arg2 ;
......@@ -28166,6 +28153,19 @@ fail:
}
 
 
SWIGINTERN PyObject *_wrap_new_R3__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {
PyObject *resultobj = 0;
Vec3< double > *result = 0 ;
if ((nobjs < 0) || (nobjs > 0)) SWIG_fail;
result = (Vec3< double > *)new Vec3< double >();
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Vec3T_double_t, SWIG_POINTER_NEW | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_new_R3(PyObject *self, PyObject *args) {
Py_ssize_t argc;
PyObject *argv[4] = {
......@@ -28175,7 +28175,7 @@ SWIGINTERN PyObject *_wrap_new_R3(PyObject *self, PyObject *args) {
if (!(argc = SWIG_Python_UnpackTuple(args, "new_R3", 0, 3, argv))) SWIG_fail;
--argc;
if (argc == 0) {
return _wrap_new_R3__SWIG_0(self, argc, argv);
return _wrap_new_R3__SWIG_1(self, argc, argv);
}
if (argc == 3) {
int _v;
......@@ -28194,7 +28194,7 @@ SWIGINTERN PyObject *_wrap_new_R3(PyObject *self, PyObject *args) {
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_R3__SWIG_1(self, argc, argv);
return _wrap_new_R3__SWIG_0(self, argc, argv);
}
}
}
......@@ -28203,8 +28203,8 @@ SWIGINTERN PyObject *_wrap_new_R3(PyObject *self, PyObject *args) {
fail:
SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_R3'.\n"
" Possible C/C++ prototypes are:\n"
" Vec3< double >::Vec3()\n"
" Vec3< double >::Vec3(double const,double const,double const)\n");
" Vec3< double >::Vec3(double const,double const,double const)\n"
" Vec3< double >::Vec3()\n");
return 0;
}
 
......@@ -30828,20 +30828,7 @@ SWIGINTERN PyObject *vector_R3_swiginit(PyObject *SWIGUNUSEDPARM(self), PyObject
return SWIG_Python_InitShadowInstance(args);
}
 
SWIGINTERN PyObject *_wrap_new_C3__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {
PyObject *resultobj = 0;
Vec3< std::complex< double > > *result = 0 ;
if ((nobjs < 0) || (nobjs > 0)) SWIG_fail;
result = (Vec3< std::complex< double > > *)new Vec3< std::complex< double > >();
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Vec3T_std__complexT_double_t_t, SWIG_POINTER_NEW | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_new_C3__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
SWIGINTERN PyObject *_wrap_new_C3__SWIG_0(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **swig_obj) {
PyObject *resultobj = 0;
std::complex< double > arg1 ;
std::complex< double > arg2 ;
......@@ -30878,6 +30865,19 @@ fail:
}
 
 
SWIGINTERN PyObject *_wrap_new_C3__SWIG_1(PyObject *SWIGUNUSEDPARM(self), Py_ssize_t nobjs, PyObject **SWIGUNUSEDPARM(swig_obj)) {
PyObject *resultobj = 0;
Vec3< std::complex< double > > *result = 0 ;
if ((nobjs < 0) || (nobjs > 0)) SWIG_fail;
result = (Vec3< std::complex< double > > *)new Vec3< std::complex< double > >();
resultobj = SWIG_NewPointerObj(SWIG_as_voidptr(result), SWIGTYPE_p_Vec3T_std__complexT_double_t_t, SWIG_POINTER_NEW | 0 );
return resultobj;
fail:
return NULL;
}
SWIGINTERN PyObject *_wrap_new_C3(PyObject *self, PyObject *args) {
Py_ssize_t argc;
PyObject *argv[4] = {
......@@ -30887,7 +30887,7 @@ SWIGINTERN PyObject *_wrap_new_C3(PyObject *self, PyObject *args) {
if (!(argc = SWIG_Python_UnpackTuple(args, "new_C3", 0, 3, argv))) SWIG_fail;
--argc;
if (argc == 0) {
return _wrap_new_C3__SWIG_0(self, argc, argv);
return _wrap_new_C3__SWIG_1(self, argc, argv);
}
if (argc == 3) {
int _v;
......@@ -30906,7 +30906,7 @@ SWIGINTERN PyObject *_wrap_new_C3(PyObject *self, PyObject *args) {
_v = SWIG_CheckState(res);
}
if (_v) {
return _wrap_new_C3__SWIG_1(self, argc, argv);
return _wrap_new_C3__SWIG_0(self, argc, argv);
}
}
}
......@@ -30915,8 +30915,8 @@ SWIGINTERN PyObject *_wrap_new_C3(PyObject *self, PyObject *args) {
fail:
SWIG_Python_RaiseOrModifyTypeError("Wrong number or type of arguments for overloaded function 'new_C3'.\n"
" Possible C/C++ prototypes are:\n"
" Vec3< std::complex< double > >::Vec3()\n"
" Vec3< std::complex< double > >::Vec3(std::complex< double > const,std::complex< double > const,std::complex< double > const)\n");
" Vec3< std::complex< double > >::Vec3(std::complex< double > const,std::complex< double > const,std::complex< double > const)\n"
" Vec3< std::complex< double > >::Vec3()\n");
return 0;
}
 
......@@ -71572,8 +71572,8 @@ static PyMethodDef SwigMethods[] = {
{ "vector_pvacuum_double_t_swigregister", vector_pvacuum_double_t_swigregister, METH_O, NULL},
{ "vector_pvacuum_double_t_swiginit", vector_pvacuum_double_t_swiginit, METH_VARARGS, NULL},
{ "new_R3", _wrap_new_R3, METH_VARARGS, "\n"
"R3()\n"
"new_R3(double const x, double const y, double const z) -> R3\n"
"R3(double const x_, double const y_, double const z_)\n"
"new_R3() -> R3\n"
""},
{ "R3_x", _wrap_R3_x, METH_O, "R3_x(R3 self) -> double"},
{ "R3_y", _wrap_R3_y, METH_O, "R3_y(R3 self) -> double"},
......@@ -71669,8 +71669,8 @@ static PyMethodDef SwigMethods[] = {
{ "vector_R3_swigregister", vector_R3_swigregister, METH_O, NULL},
{ "vector_R3_swiginit", vector_R3_swiginit, METH_VARARGS, NULL},
{ "new_C3", _wrap_new_C3, METH_VARARGS, "\n"
"C3()\n"
"new_C3(std::complex< double > const x, std::complex< double > const y, std::complex< double > const z) -> C3\n"
"C3(std::complex< double > const x_, std::complex< double > const y_, std::complex< double > const z_)\n"
"new_C3() -> C3\n"
""},
{ "C3_x", _wrap_C3_x, METH_O, "C3_x(C3 self) -> std::complex< double >"},
{ "C3_y", _wrap_C3_y, METH_O, "C3_y(C3 self) -> std::complex< double >"},
......@@ -78031,9 +78031,6 @@ static void *_p_FTDistribution1DTriangleTo_p_ICloneable(void *x, int *SWIGUNUSED
static void *_p_RotationEulerTo_p_ICloneable(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((ICloneable *) (IRotation *) ((RotationEuler *) x));
}
static void *_p_Vec3T_double_tTo_p_std__arrayT_double_3_t(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((std::array< double,3 > *) ((Vec3< double > *) x));
}
static void *_p_FormFactorCosineRippleLorentzTo_p_ICosineRipple(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((ICosineRipple *) ((FormFactorCosineRippleLorentz *) x));
}
......@@ -78508,9 +78505,6 @@ static void *_p_FormFactorAnisoPyramidTo_p_IBornFF(void *x, int *SWIGUNUSEDPARM(
static void *_p_FormFactorPrism3To_p_IBornFF(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((IBornFF *) (IFormFactorPrism *) ((FormFactorPrism3 *) x));
}
static void *_p_Vec3T_std__complexT_double_t_tTo_p_std__arrayT_std__complexT_double_t_3_t(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((std::array< std::complex< double >,3 > *) ((Vec3< std::complex< double > > *) x));
}
static void *_p_FTDecayFunction1DCauchyTo_p_IFTDecayFunction1D(void *x, int *SWIGUNUSEDPARM(newmemory)) {
return (void *)((IFTDecayFunction1D *) ((FTDecayFunction1DCauchy *) x));
}
......@@ -79090,8 +79084,8 @@ static swig_cast_info _swigc__p_std__allocatorT_std__string_t[] = { {&_swigt__p
static swig_cast_info _swigc__p_std__allocatorT_std__vectorT_double_std__allocatorT_double_t_t_t[] = { {&_swigt__p_std__allocatorT_std__vectorT_double_std__allocatorT_double_t_t_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__allocatorT_std__vectorT_int_std__allocatorT_int_t_t_t[] = { {&_swigt__p_std__allocatorT_std__vectorT_int_std__allocatorT_int_t_t_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__allocatorT_unsigned_long_t[] = { {&_swigt__p_std__allocatorT_unsigned_long_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__arrayT_double_3_t[] = { {&_swigt__p_Vec3T_double_t, _p_Vec3T_double_tTo_p_std__arrayT_double_3_t, 0, 0}, {&_swigt__p_std__arrayT_double_3_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__arrayT_std__complexT_double_t_3_t[] = { {&_swigt__p_std__arrayT_std__complexT_double_t_3_t, 0, 0, 0}, {&_swigt__p_Vec3T_std__complexT_double_t_t, _p_Vec3T_std__complexT_double_t_tTo_p_std__arrayT_std__complexT_double_t_3_t, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__arrayT_double_3_t[] = { {&_swigt__p_std__arrayT_double_3_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__arrayT_std__complexT_double_t_3_t[] = { {&_swigt__p_std__arrayT_std__complexT_double_t_3_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__complexT_double_t[] = { {&_swigt__p_std__complexT_double_t, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__invalid_argument[] = { {&_swigt__p_std__invalid_argument, 0, 0, 0},{0, 0, 0, 0}};
static swig_cast_info _swigc__p_std__lessT_std__string_t[] = { {&_swigt__p_std__lessT_std__string_t, 0, 0, 0},{0, 0, 0, 0}};