16 #include "Base/Util/Assert.h"
25 QColor suggestMaterialColor(
const QString&
name)
27 if (
name.contains(
"Vacuum"))
28 return QColor(179, 242, 255);
29 if (
name.contains(
"Substrate"))
30 return QColor(205, 102, 0);
31 if (
name.contains(
"Default"))
32 return QColor(Qt::green);
33 if (
name.contains(
"Particle"))
34 return QColor(146, 198, 255);
37 static std::random_device r;
38 std::default_random_engine re(r());
39 std::uniform_int_distribution<int> ru(0, 255);
41 return QColor(ru(re), ru(re), ru(re));
71 material->disconnect(
this);
92 materialItem->setMatItemName(
name);
93 materialItem->setColor(suggestMaterialColor(
name));
94 materialItem->setRefractiveIndex(delta, beta);
103 materialItem->setMatItemName(
name);
104 materialItem->setColor(suggestMaterialColor(
name));
105 materialItem->setScatteringLengthDensity(complex_t(sld, abs_term));
114 if (materialItem->matItemName() ==
name)
123 if (materialItem->identifier() == identifier)
132 newMaterial->createNewIdentifier();
133 newMaterial->setMatItemName(material.
matItemName() +
" (copy)");
175 destItem->updateFrom(*fromItem);
177 bool anyAddedOrRemoved =
false;
185 anyAddedOrRemoved =
true;
193 anyAddedOrRemoved =
true;
197 QVector<MaterialItem*> tmp;
202 if (anyAddedOrRemoved)
Defines class MaterialItem.
Defines class MaterialItems.
@ other
The unit has no enum value defined in here (e.g. when defined as an explicit string)
QString matItemName() const
void addMaterial(MaterialItem *material)
Add the material and take ownership of it.
MaterialItem * addRefractiveMaterial(const QString &name, double delta, double beta)
MaterialItem * materialFromIdentifier(const QString &identifier) const
MaterialItem * defaultMaterial() const
void materialAddedOrRemoved()
void initFrom(const MaterialItems &from)
Copies the complete content, emitting signals for existing and changed materials.
MaterialItem * addSLDMaterial(const QString &name, double sld, double abs_term)
QVector< MaterialItem * > m_materialItems
all materials (owned by this class)
void removeMaterial(const QString &identifier)
MaterialItems(QObject *parent=nullptr)
MaterialItems * createCopy() const
MaterialItem * insertCopy(const MaterialItem &material)
Inserts a copy of the given material and returns the newly inserted item.
bool operator==(const MaterialItems &other) const
Compares for complete equality (same material identifiers, same order of materials,...
const QVector< MaterialItem * > & materialItems() const
void materialChanged(MaterialItem *materialItem)
MaterialItem * materialFromName(const QString &name) const
bool operator!=(const MaterialItems &other) const
void serialize(Streamer &s)
Supports serialization to or deserialization from QXmlStream.
QXmlStreamReader * xmlReader()
Returns stream reader or nullptr.
void assertVersion(unsigned expectedVersion) const
As reader, throws DeserializationException unless the expected version is read. As writer,...
QString const & name(EShape k)
void rwVector(Streamer &s, const QString &tag, QVector< T > &vec, Args... argsForConstructor)
Serializes a list of items of known and fixed type. Passes optional arguments to the constructor.