Skip to content
Snippets Groups Projects
Commit 9de23c20 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

[j.0] rm file/class Attributes (#1012) ()

Merging branch 'j.0'  into 'main'.

See merge request !2676
parents 2d6c67e6 3cdb2275
No related branches found
No related tags found
1 merge request!2676rm file/class Attributes (#1012)
Pipeline #152113 passed
...@@ -18,13 +18,13 @@ ...@@ -18,13 +18,13 @@
AttLimits::AttLimits() AttLimits::AttLimits()
: m_limits(RealLimits::limitless()) : m_limits(RealLimits::limitless())
, m_att_fixed(Attributes::free()) , m_fixed(false)
{ {
} }
AttLimits::AttLimits(const RealLimits& limits, const Attributes& fixedAttr) AttLimits::AttLimits(const RealLimits& limits, bool fixed)
: m_limits(limits) : m_limits(limits)
, m_att_fixed(fixedAttr) , m_fixed(fixed)
{ {
} }
...@@ -35,57 +35,57 @@ AttLimits AttLimits::limitless() ...@@ -35,57 +35,57 @@ AttLimits AttLimits::limitless()
AttLimits AttLimits::lowerLimited(double bound_value) AttLimits AttLimits::lowerLimited(double bound_value)
{ {
return AttLimits(RealLimits::lowerLimited(bound_value), Attributes::free()); return AttLimits(RealLimits::lowerLimited(bound_value), false);
} }
AttLimits AttLimits::positive() AttLimits AttLimits::positive()
{ {
return AttLimits(RealLimits::positive(), Attributes::free()); return AttLimits(RealLimits::positive(), false);
} }
AttLimits AttLimits::nonnegative() AttLimits AttLimits::nonnegative()
{ {
return AttLimits(RealLimits::nonnegative(), Attributes::free()); return AttLimits(RealLimits::nonnegative(), false);
} }
AttLimits AttLimits::upperLimited(double bound_value) AttLimits AttLimits::upperLimited(double bound_value)
{ {
return AttLimits(RealLimits::upperLimited(bound_value), Attributes::free()); return AttLimits(RealLimits::upperLimited(bound_value), false);
} }
AttLimits AttLimits::limited(double left_bound_value, double right_bound_value) AttLimits AttLimits::limited(double left_bound_value, double right_bound_value)
{ {
return AttLimits(RealLimits::limited(left_bound_value, right_bound_value), Attributes::free()); return AttLimits(RealLimits::limited(left_bound_value, right_bound_value), false);
} }
AttLimits AttLimits::fixed() AttLimits AttLimits::fixed()
{ {
return AttLimits(RealLimits::limitless(), Attributes::fixed()); return AttLimits(RealLimits::limitless(), true);
} }
bool AttLimits::isFixed() const bool AttLimits::isFixed() const
{ {
return m_att_fixed.isFixed(); return m_fixed;
} }
bool AttLimits::isLimited() const bool AttLimits::isLimited() const
{ {
return m_att_fixed.isFree() && m_limits.isLimited(); return !m_fixed && m_limits.isLimited();
} }
bool AttLimits::isUpperLimited() const bool AttLimits::isUpperLimited() const
{ {
return m_att_fixed.isFree() && !m_limits.hasLowerLimit() && m_limits.hasUpperLimit(); return !m_fixed && !m_limits.hasLowerLimit() && m_limits.hasUpperLimit();
} }
bool AttLimits::isLowerLimited() const bool AttLimits::isLowerLimited() const
{ {
return m_att_fixed.isFree() && m_limits.hasLowerLimit() && !m_limits.hasUpperLimit(); return !m_fixed && m_limits.hasLowerLimit() && !m_limits.hasUpperLimit();
} }
bool AttLimits::isLimitless() const bool AttLimits::isLimitless() const
{ {
return m_att_fixed.isFree() && !m_limits.hasLowerLimit() && !m_limits.hasUpperLimit(); return !m_fixed && !m_limits.hasLowerLimit() && !m_limits.hasUpperLimit();
} }
double AttLimits::min() const double AttLimits::min() const
...@@ -100,7 +100,7 @@ double AttLimits::max() const ...@@ -100,7 +100,7 @@ double AttLimits::max() const
bool AttLimits::operator==(const AttLimits& other) const bool AttLimits::operator==(const AttLimits& other) const
{ {
return m_limits == other.m_limits && m_att_fixed == other.m_att_fixed; return m_limits == other.m_limits && m_fixed == other.m_fixed;
} }
bool AttLimits::operator!=(const AttLimits& other) const bool AttLimits::operator!=(const AttLimits& other) const
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#ifndef BORNAGAIN_FIT_PARAM_ATTLIMITS_H #ifndef BORNAGAIN_FIT_PARAM_ATTLIMITS_H
#define BORNAGAIN_FIT_PARAM_ATTLIMITS_H #define BORNAGAIN_FIT_PARAM_ATTLIMITS_H
#include "Fit/Param/Attributes.h"
#include "Fit/Param/RealLimits.h" #include "Fit/Param/RealLimits.h"
#include <string> #include <string>
...@@ -54,10 +53,10 @@ public: ...@@ -54,10 +53,10 @@ public:
} }
private: private:
AttLimits(const RealLimits& limits, const Attributes& fixedAttr); AttLimits(const RealLimits& limits, bool fixed);
RealLimits m_limits; RealLimits m_limits;
Attributes m_att_fixed; bool m_fixed;
}; };
#endif // BORNAGAIN_FIT_PARAM_ATTLIMITS_H #endif // BORNAGAIN_FIT_PARAM_ATTLIMITS_H
// ************************************************************************************************
//
// BornAgain: simulate and fit reflection and scattering
//
//! @file Fit/Param/Attributes.h
//! @brief Defines and implements class Attributes.
//!
//! @homepage http://www.bornagainproject.org
//! @license GNU General Public License v3 or higher (see COPYING)
//! @copyright Forschungszentrum Jülich GmbH 2018
//! @authors Scientific Computing Group at MLZ (see CITATION, AUTHORS)
//
// ************************************************************************************************
// Swig: not %include'd, but #include'd
#ifndef BORNAGAIN_FIT_PARAM_ATTRIBUTES_H
#define BORNAGAIN_FIT_PARAM_ATTRIBUTES_H
#include <ostream>
//! %Attributes for a fit parameter. Currently, the only attribute is fixed/free.
class Attributes {
public:
Attributes() = default;
//! Creates a fixed value object
static Attributes fixed() { return Attributes(true); }
static Attributes free() { return Attributes(false); }
void setFixed(bool is_fixed) { m_is_fixed = is_fixed; }
bool isFixed() const { return m_is_fixed; }
bool isFree() const { return !isFixed(); }
friend std::ostream& operator<<(std::ostream& ostr, const Attributes& m)
{
m.print(ostr);
return ostr;
}
bool operator==(const Attributes& other) const { return isFixed() == other.isFixed(); }
bool operator!=(const Attributes& other) const { return !(*this == other); }
protected:
explicit Attributes(bool is_fixed)
: m_is_fixed(is_fixed)
{
}
bool m_is_fixed{false}; //! parameter is fixed
void print(std::ostream& ostr) const;
};
//! Prints class
inline void Attributes::print(std::ostream& ostr) const
{
if (isFixed())
ostr << "fixed";
else
ostr << "free";
}
#endif // BORNAGAIN_FIT_PARAM_ATTRIBUTES_H
...@@ -44,11 +44,9 @@ const QString position_tooltip = "Relative position of the particle's reference ...@@ -44,11 +44,9 @@ const QString position_tooltip = "Relative position of the particle's reference
} // namespace } // namespace
CompoundItem::CompoundItem(const MaterialsSet* materials) CompoundItem::CompoundItem(const MaterialsSet*)
: ItemWithParticles(abundance_tooltip, position_tooltip) : ItemWithParticles(abundance_tooltip, position_tooltip)
, m_materials(materials)
{ {
ASSERT(m_materials);
} }
void CompoundItem::addItemWithParticleSelection(ItemWithParticles* particle) void CompoundItem::addItemWithParticleSelection(ItemWithParticles* particle)
...@@ -87,7 +85,8 @@ void CompoundItem::readFrom(QXmlStreamReader* r) ...@@ -87,7 +85,8 @@ void CompoundItem::readFrom(QXmlStreamReader* r)
if (tag == Tag::BaseData) if (tag == Tag::BaseData)
XML::readBaseElement<ItemWithParticles>(r, tag, this); XML::readBaseElement<ItemWithParticles>(r, tag, this);
else if (tag == Tag::Particle) { else if (tag == Tag::Particle) {
m_particles.push_back(PolyItem<ParticlesCatalog>().readItemFrom(r, m_materials)); MaterialsSet* dummy = nullptr;
m_particles.push_back(PolyItem<ParticlesCatalog>().readItemFrom(r, dummy)); // TODO
XML::gotoEndElementOfTag(r, tag); XML::gotoEndElementOfTag(r, tag);
} else if (tag == Tag::ExpandCompoundGroupbox) } else if (tag == Tag::ExpandCompoundGroupbox)
expandCompound = XML::readTaggedBool(r, tag); expandCompound = XML::readTaggedBool(r, tag);
......
...@@ -41,7 +41,6 @@ public: ...@@ -41,7 +41,6 @@ public:
private: private:
OwningVector<ItemWithParticles> m_particles; OwningVector<ItemWithParticles> m_particles;
const MaterialsSet* m_materials;
}; };
#endif // BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H #endif // BORNAGAIN_GUI_MODEL_SAMPLE_COMPOUNDITEM_H
...@@ -29,7 +29,6 @@ const QString MaterialId("MaterialId"); ...@@ -29,7 +29,6 @@ const QString MaterialId("MaterialId");
ItemWithMaterial::ItemWithMaterial(const MaterialsSet* materialModel) ItemWithMaterial::ItemWithMaterial(const MaterialsSet* materialModel)
: m_materials(materialModel) : m_materials(materialModel)
{ {
ASSERT(m_materials);
} }
void ItemWithMaterial::setMaterial(const MaterialItem* materialItem) void ItemWithMaterial::setMaterial(const MaterialItem* materialItem)
......
...@@ -47,9 +47,8 @@ const QString position_tooltip = "Relative position of the mesocrystal's referen ...@@ -47,9 +47,8 @@ const QString position_tooltip = "Relative position of the mesocrystal's referen
} // namespace } // namespace
MesocrystalItem::MesocrystalItem(const MaterialsSet* materials) MesocrystalItem::MesocrystalItem(const MaterialsSet*)
: ItemWithParticles(abundance_tooltip, position_tooltip) : ItemWithParticles(abundance_tooltip, position_tooltip)
, m_materials(materials)
{ {
m_vectorA.init("First lattice vector (nm)", "Coordinates of the first lattice vector", m_vectorA.init("First lattice vector (nm)", "Coordinates of the first lattice vector",
"vectorA"); "vectorA");
...@@ -59,7 +58,7 @@ MesocrystalItem::MesocrystalItem(const MaterialsSet* materials) ...@@ -59,7 +58,7 @@ MesocrystalItem::MesocrystalItem(const MaterialsSet* materials)
"vectorC"); "vectorC");
m_outer_shape.initWithArgs("Outer Shape", "", FormfactorsCatalog::Type::Box); m_outer_shape.initWithArgs("Outer Shape", "", FormfactorsCatalog::Type::Box);
m_basis_particle.initWithArgs("Basis", "", ParticlesCatalog::Type::Particle, materials); m_basis_particle.initWithArgs("Basis", "", ParticlesCatalog::Type::Particle, nullptr);
} }
void MesocrystalItem::writeTo(QXmlStreamWriter* w) const void MesocrystalItem::writeTo(QXmlStreamWriter* w) const
...@@ -92,7 +91,8 @@ void MesocrystalItem::readFrom(QXmlStreamReader* r) ...@@ -92,7 +91,8 @@ void MesocrystalItem::readFrom(QXmlStreamReader* r)
else if (tag == Tag::OuterShape) else if (tag == Tag::OuterShape)
XML::readTaggedElement(r, tag, m_outer_shape); XML::readTaggedElement(r, tag, m_outer_shape);
else if (tag == Tag::BasisParticle) { else if (tag == Tag::BasisParticle) {
m_basis_particle.readFrom(r, m_materials); MaterialsSet* dummy = nullptr;
m_basis_particle.readFrom(r, dummy); // TODO rm dummy arg
XML::gotoEndElementOfTag(r, tag); XML::gotoEndElementOfTag(r, tag);
} else if (tag == Tag::ExpandMesocrystalGroupbox) } else if (tag == Tag::ExpandMesocrystalGroupbox)
expandMesocrystal = XML::readTaggedBool(r, tag); expandMesocrystal = XML::readTaggedBool(r, tag);
......
...@@ -72,7 +72,6 @@ private: ...@@ -72,7 +72,6 @@ private:
VectorProperty m_vectorC; VectorProperty m_vectorC;
PolyItem<FormfactorsCatalog> m_outer_shape; PolyItem<FormfactorsCatalog> m_outer_shape;
PolyItem<ParticlesCatalog> m_basis_particle; PolyItem<ParticlesCatalog> m_basis_particle;
const MaterialsSet* m_materials;
}; };
template <typename T> T* MesocrystalItem::setOuterShapeType() template <typename T> T* MesocrystalItem::setOuterShapeType()
......
...@@ -42,7 +42,6 @@ ...@@ -42,7 +42,6 @@
%} %}
%import(module="libBornAgainFit") "Fit/Param/AttLimits.h" %import(module="libBornAgainFit") "Fit/Param/AttLimits.h"
%import(module="libBornAgainFit") "Fit/Param/Attributes.h"
%import(module="libBornAgainFit") "Fit/Param/Parameters.h" %import(module="libBornAgainFit") "Fit/Param/Parameters.h"
%import(module="libBornAgainFit") "Fit/Param/Parameter.h" %import(module="libBornAgainFit") "Fit/Param/Parameter.h"
......
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