Material: Continued Material enahncements

Continues the work of the material subsystem improvements.

Several important items are included in this merge. In terms of new
capabilities, this merge adds List and MultiLineString as valid
property types, complete with editing dialogs. This will help with
backwards compatibility for external workbenches, such as Render.

Stability has been a big focus. New unit tests help to verify features
work as expected. Bugs have been fixed and crashes avoided.

Material cards have had a renaming to their tree structure. For
example, 'StandardMeterials' is redundant, so this was renamed to
'Standard'. The cards themselves are more compliant fully passing the
yamllint tests.

More soon.
This commit is contained in:
David Carter
2023-11-06 20:06:58 -05:00
committed by Chris Hennes
parent c81bd982b5
commit 332bf7ed08
195 changed files with 2198 additions and 700 deletions

View File

@@ -42,9 +42,6 @@ using namespace Materials;
TYPESYSTEM_SOURCE(Materials::MaterialLibrary, LibraryBase)
MaterialLibrary::MaterialLibrary()
{}
MaterialLibrary::MaterialLibrary(const QString& libraryName,
const QString& dir,
const QString& icon,
@@ -232,15 +229,16 @@ std::shared_ptr<Material> MaterialLibrary::saveMaterial(std::shared_ptr<Material
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream stream(&file);
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
stream.setCodec("UTF-8");
#endif
stream.setGenerateByteOrderMark(true);
// Write the contents
material->setName(info.baseName());
material->setLibrary(getptr());
material->setDirectory(getRelativePath(path));
material->save(stream, saveAsCopy, saveInherited);
material->save(stream, overwrite, saveAsCopy, saveInherited);
}
return addMaterial(material, path);
@@ -338,7 +336,7 @@ MaterialLibrary::getMaterialTree() const
// Empty folders aren't included in _materialPathMap, so we add them by looking at the file
// system
auto folderList = MaterialLoader::getMaterialFolders(*this);
for (auto folder : *folderList) {
for (auto& folder : *folderList) {
QStringList list = folder.split(QString::fromStdString("/"));
// Start at the root
@@ -364,9 +362,6 @@ MaterialLibrary::getMaterialTree() const
TYPESYSTEM_SOURCE(Materials::MaterialExternalLibrary, MaterialLibrary::MaterialLibrary)
MaterialExternalLibrary::MaterialExternalLibrary()
{}
MaterialExternalLibrary::MaterialExternalLibrary(const QString& libraryName,
const QString& dir,
const QString& icon,

View File

@@ -31,7 +31,6 @@
#include <Base/BaseClass.h>
#include <Mod/Material/MaterialGlobal.h>
#include "Materials.h"
#include "Model.h"
#include "ModelLibrary.h"
@@ -48,7 +47,7 @@ class MaterialsExport MaterialLibrary: public LibraryBase,
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
MaterialLibrary();
MaterialLibrary() = default;
MaterialLibrary(const MaterialLibrary&) = delete;
MaterialLibrary(const QString& libraryName,
const QString& dir,
@@ -106,7 +105,7 @@ class MaterialsExport MaterialExternalLibrary: public MaterialLibrary
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
MaterialExternalLibrary();
MaterialExternalLibrary() = default;
MaterialExternalLibrary(const QString& libraryName,
const QString& dir,
const QString& icon,

View File

@@ -43,10 +43,7 @@
using namespace Materials;
MaterialEntry::MaterialEntry()
{}
MaterialEntry::MaterialEntry(std::shared_ptr<MaterialLibrary> library,
MaterialEntry::MaterialEntry(const std::shared_ptr<MaterialLibrary>& library,
const QString& modelName,
const QString& dir,
const QString& modelUuid)
@@ -56,7 +53,7 @@ MaterialEntry::MaterialEntry(std::shared_ptr<MaterialLibrary> library,
, _uuid(modelUuid)
{}
MaterialYamlEntry::MaterialYamlEntry(std::shared_ptr<MaterialLibrary> library,
MaterialYamlEntry::MaterialYamlEntry(const std::shared_ptr<MaterialLibrary>& library,
const QString& modelName,
const QString& dir,
const QString& modelUuid,
@@ -78,6 +75,17 @@ QString MaterialYamlEntry::yamlValue(const YAML::Node& node,
return QString::fromStdString(defaultValue);
}
std::shared_ptr<QList<QVariant>> MaterialYamlEntry::readList(const YAML::Node& node)
{
auto list = std::make_shared<QList<QVariant>>();
for (auto it = node.begin(); it != node.end(); it++) {
QVariant nodeName = QString::fromStdString(it->as<std::string>());
list->append(nodeName);
}
return list;
}
std::shared_ptr<Material2DArray> MaterialYamlEntry::read2DArray(const YAML::Node& node)
{
// Base::Console().Log("Read 2D Array\n");
@@ -86,8 +94,8 @@ std::shared_ptr<Material2DArray> MaterialYamlEntry::read2DArray(const YAML::Node
if (node.size() == 2) {
// Get the default
Base::Quantity defaultValue =
Base::Quantity::parse(QString::fromStdString(node[0].as<std::string>()));
Base::Quantity defaultValue(
Base::Quantity::parse(QString::fromStdString(node[0].as<std::string>())));
array2d->setDefault(QVariant::fromValue(defaultValue));
auto yamlArray = node[1];
@@ -115,8 +123,8 @@ std::shared_ptr<Material3DArray> MaterialYamlEntry::read3DArray(const YAML::Node
if (node.size() == 2) {
// Get the default
Base::Quantity defaultValue =
Base::Quantity::parse(QString::fromStdString(node[0].as<std::string>()));
Base::Quantity defaultValue(
Base::Quantity::parse(QString::fromStdString(node[0].as<std::string>())));
array3d->setDefault(QVariant::fromValue(defaultValue));
auto yamlArray = node[1];
@@ -207,7 +215,12 @@ void MaterialYamlEntry::addToTree(
auto type = prop->getType();
try {
if (type == MaterialValue::Array2D) {
if (type == MaterialValue::List) {
auto list = readList(itp->second);
finalModel->setPhysicalValue(QString::fromStdString(propertyName),
list);
}
else if (type == MaterialValue::Array2D) {
auto array2d = read2DArray(itp->second);
finalModel->setPhysicalValue(QString::fromStdString(propertyName),
array2d);
@@ -259,7 +272,12 @@ void MaterialYamlEntry::addToTree(
auto type = prop->getType();
try {
if (type == MaterialValue::Array2D) {
if (type == MaterialValue::List) {
auto list = readList(itp->second);
finalModel->setAppearanceValue(QString::fromStdString(propertyName),
list);
}
else if (type == MaterialValue::Array2D) {
auto array2d = read2DArray(itp->second);
finalModel->setAppearanceValue(QString::fromStdString(propertyName),
array2d);
@@ -305,12 +323,6 @@ MaterialLoader::MaterialLoader(
loadLibraries();
}
/*
* Destroys the object and frees any allocated resources
*/
MaterialLoader::~MaterialLoader()
{}
void MaterialLoader::addLibrary(std::shared_ptr<MaterialLibrary> model)
{
_libraryList->push_back(model);
@@ -483,8 +495,6 @@ void MaterialLoader::loadLibrary(std::shared_ptr<MaterialLibrary> library)
QFileInfo file(pathname);
if (file.isFile()) {
if (file.suffix().toStdString() == "FCMat") {
QString libraryName = file.baseName();
auto model = getMaterialFromPath(library, file.canonicalFilePath());
if (model) {
(*_materialEntryMap)[model->getUUID()] = model;

View File

@@ -37,8 +37,8 @@ namespace Materials
class MaterialEntry
{
public:
MaterialEntry();
MaterialEntry(std::shared_ptr<MaterialLibrary> library,
MaterialEntry() = default;
MaterialEntry(const std::shared_ptr<MaterialLibrary>& library,
const QString& modelName,
const QString& dir,
const QString& modelUuid);
@@ -74,7 +74,7 @@ protected:
class MaterialYamlEntry: public MaterialEntry
{
public:
MaterialYamlEntry(std::shared_ptr<MaterialLibrary> library,
MaterialYamlEntry(const std::shared_ptr<MaterialLibrary>& library,
const QString& modelName,
const QString& dir,
const QString& modelUuid,
@@ -98,6 +98,7 @@ private:
QString
yamlValue(const YAML::Node& node, const std::string& key, const std::string& defaultValue);
std::shared_ptr<QList<QVariant>> readList(const YAML::Node& node);
std::shared_ptr<Material2DArray> read2DArray(const YAML::Node& node);
std::shared_ptr<Material3DArray> read3DArray(const YAML::Node& node);
@@ -109,7 +110,7 @@ class MaterialLoader
public:
MaterialLoader(std::shared_ptr<std::map<QString, std::shared_ptr<Material>>> materialMap,
std::shared_ptr<std::list<std::shared_ptr<MaterialLibrary>>> libraryList);
virtual ~MaterialLoader();
~MaterialLoader() = default;
std::shared_ptr<std::list<std::shared_ptr<MaterialLibrary>>> getMaterialLibraries();
static std::shared_ptr<std::list<QString>> getMaterialFolders(const MaterialLibrary& library);

View File

@@ -123,7 +123,7 @@ std::shared_ptr<Material> MaterialManager::getMaterialByPath(const QString& path
{
QString cleanPath = QDir::cleanPath(path);
for (auto library : *_libraryList) {
for (auto& library : *_libraryList) {
// Base::Console().Log("MaterialManager::getMaterialByPath() Checking library '%s'->'%s'\n",
// library->getName().toStdString().c_str(),
// library->getDirectory().toStdString().c_str());
@@ -189,7 +189,7 @@ bool MaterialManager::exists(std::shared_ptr<MaterialLibrary> library, const QSt
std::shared_ptr<MaterialLibrary> MaterialManager::getLibrary(const QString& name) const
{
for (auto library : *_libraryList) {
for (auto& library : *_libraryList) {
if (library->getName() == name) {
return library;
}

View File

@@ -360,22 +360,22 @@ static PyObject* _pyObjectFromVariant(const QVariant& value)
if (value.userType() == qMetaTypeId<Base::Quantity>()) {
return new Base::QuantityPy(new Base::Quantity(value.value<Base::Quantity>()));
}
else if (value.userType() == QMetaType::Double) {
if (value.userType() == QMetaType::Double) {
return PyFloat_FromDouble(value.toDouble());
}
else if (value.userType() == QMetaType::Float) {
if (value.userType() == QMetaType::Float) {
return PyFloat_FromDouble(value.toFloat());
}
else if (value.userType() == QMetaType::Int) {
if (value.userType() == QMetaType::Int) {
return PyLong_FromLong(value.toInt());
}
else if (value.userType() == QMetaType::Long) {
if (value.userType() == QMetaType::Long) {
return PyLong_FromLong(value.toInt());
}
else if (value.userType() == QMetaType::Bool) {
if (value.userType() == QMetaType::Bool) {
return Py::new_reference_to(Py::Boolean(value.toBool()));
}
else if (value.userType() == QMetaType::QString) {
if (value.userType() == QMetaType::QString) {
return PyUnicode_FromString(value.toString().toStdString().c_str());
}

View File

@@ -26,6 +26,7 @@
#include <QMetaType>
#include <App/Application.h>
#include <Base/QtTools.h>
#include <Base/Quantity.h>
#include <Gui/MetaTypes.h>
@@ -83,10 +84,18 @@ bool MaterialValue::operator==(const MaterialValue& other) const
return (_valueType == other._valueType) && (_value == other._value);
}
QString MaterialValue::escapeString(const QString& source)
{
QString res = source;
res.replace(QString::fromStdString("\\"), QString::fromStdString("\\\\"));
res.replace(QString::fromStdString("\""), QString::fromStdString("\\\""));
return res;
}
void MaterialValue::setInitialValue(ValueType inherited)
{
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
if (_valueType == String) {
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
if (_valueType == String || _valueType == MultiLineString) {
_value = QVariant(static_cast<QVariant::Type>(QMetaType::QString));
}
else if (_valueType == Boolean) {
@@ -110,11 +119,8 @@ void MaterialValue::setInitialValue(ValueType inherited)
else if (_valueType == Image) {
_value = QVariant(static_cast<QVariant::Type>(QMetaType::QString));
}
else if (_valueType == List) {
_value = QVariant(static_cast<QVariant::Type>(QMetaType::QString));
}
#else
if (_valueType == String) {
if (_valueType == String || _valueType == MultiLineString) {
_value = QVariant(QMetaType(QMetaType::QString));
}
else if (_valueType == Boolean) {
@@ -138,15 +144,16 @@ void MaterialValue::setInitialValue(ValueType inherited)
else if (_valueType == Image) {
_value = QVariant(QMetaType(QMetaType::QString));
}
else if (_valueType == List) {
_value = QVariant(QMetaType(QMetaType::QString));
}
#endif
else if (_valueType == Quantity) {
Base::Quantity qu;
qu.setInvalid();
_value = QVariant::fromValue(qu);
}
else if (_valueType == List) {
auto list = QList<QVariant>();
_value = QVariant::fromValue(list);
}
else if (_valueType == Array2D) {
if (_valueType != inherited) {
throw InvalidMaterialType("Initializing a regular material value as a 2D Array");
@@ -168,6 +175,11 @@ void MaterialValue::setInitialValue(ValueType inherited)
}
}
void MaterialValue::setList(const QList<QVariant>& value)
{
_value = QVariant::fromValue(value);
}
bool MaterialValue::isNull() const
{
if (_value.isNull()) {
@@ -178,12 +190,16 @@ bool MaterialValue::isNull() const
return !_value.value<Base::Quantity>().isValid();
}
if (_valueType == List) {
return _value.value<QList<QVariant>>().isEmpty();
}
return false;
}
const QString MaterialValue::getYAMLString() const
{
QString yaml = QString::fromStdString("\"");
QString yaml;
if (!isNull()) {
if (getType() == MaterialValue::Quantity) {
Base::Quantity quantity = getValue().value<Base::Quantity>();
@@ -195,11 +211,27 @@ const QString MaterialValue::getYAMLString() const
yaml += QString(QString::fromStdString("%1")).arg(value.toFloat(), 0, 'g', 6);
}
}
else if (getType() == MaterialValue::MultiLineString) {
yaml = QString::fromStdString(">2");
auto list = getValue().toString().split(QRegExp(QString::fromStdString("[\r\n]")),
Qt::SkipEmptyParts);
for (auto& it : list) {
yaml += QString::fromStdString("\n ") + it;
}
return yaml;
}
else if (getType() == MaterialValue::List) {
for (auto& it : getList()) {
yaml += QString::fromStdString("\n - \"") + escapeString(it.toString())
+ QString::fromStdString("\"");
}
return yaml;
}
else {
yaml += getValue().toString();
}
}
yaml += QString::fromStdString("\"");
yaml = QString::fromStdString("\"") + escapeString(yaml) + QString::fromStdString("\"");
return yaml;
}
@@ -239,9 +271,9 @@ Material2DArray& Material2DArray::operator=(const Material2DArray& other)
void Material2DArray::deepCopy(const Material2DArray& other)
{
// Deep copy
for (auto row : other._rows) {
for (auto& row : other._rows) {
std::vector<QVariant> v;
for (auto col : *row) {
for (auto& col : *row) {
QVariant newVariant(col);
v.push_back(newVariant);
}
@@ -335,7 +367,7 @@ const QVariant Material2DArray::getValue(int row, int column) const
void Material2DArray::dumpRow(std::shared_ptr<std::vector<QVariant>> row) const
{
Base::Console().Log("row: ");
for (auto column : *row) {
for (auto& column : *row) {
Base::Console().Log("'%s' ", column.toString().toStdString().c_str());
}
Base::Console().Log("\n");
@@ -343,7 +375,7 @@ void Material2DArray::dumpRow(std::shared_ptr<std::vector<QVariant>> row) const
void Material2DArray::dump() const
{
for (auto row : _rows) {
for (auto& row : _rows) {
dumpRow(row);
}
}
@@ -367,7 +399,7 @@ const QString Material2DArray::getYAMLString() const
// Next the array contents
yaml += QString::fromStdString(" - [");
bool firstRow = true;
for (auto row : _rows) {
for (auto& row : _rows) {
if (!firstRow) {
// Each row is on its own line, padded for correct indentation
yaml += QString::fromStdString(",\n") + pad;
@@ -378,7 +410,7 @@ const QString Material2DArray::getYAMLString() const
yaml += QString::fromStdString("[");
bool first = true;
for (auto column : *row) {
for (auto& column : *row) {
if (!first) {
// TODO: Fix for arrays with too many columns to fit on a single line
yaml += QString::fromStdString(", ");
@@ -698,7 +730,7 @@ const QString Material3DArray::getYAMLString() const
bool firstRow = true;
auto rows = getTable(depth);
for (auto row : *rows) {
for (auto& row : *rows) {
if (!firstRow) {
// Each row is on its own line, padded for correct indentation
yaml += QString::fromStdString(",\n") + pad2;
@@ -709,7 +741,7 @@ const QString Material3DArray::getYAMLString() const
yaml += QString::fromStdString("[");
bool first = true;
for (auto column : *row) {
for (auto& column : *row) {
if (!first) {
// TODO: Fix for arrays with too many columns to fit on a single line
yaml += QString::fromStdString(", ");

View File

@@ -54,10 +54,11 @@ public:
Color = 10,
Image = 11,
File = 12,
URL = 13
URL = 13,
MultiLineString = 14
};
MaterialValue();
MaterialValue(const MaterialValue& other);
explicit MaterialValue(const MaterialValue& other);
explicit MaterialValue(ValueType type);
virtual ~MaterialValue() = default;
@@ -73,10 +74,18 @@ public:
return _valueType;
}
const QVariant getValue() const
QVariant getValue() const
{
return _value;
}
QList<QVariant> getList()
{
return _value.value<QList<QVariant>>();
}
const QList<QVariant> getList() const
{
return _value.value<QList<QVariant>>();
}
virtual bool isNull() const;
virtual const QVariant getValueAt(const QVariant& value) const
@@ -88,8 +97,10 @@ public:
{
_value = value;
}
void setList(const QList<QVariant>& value);
virtual const QString getYAMLString() const;
static QString escapeString(const QString& source);
protected:
MaterialValue(ValueType type, ValueType inherited);

View File

@@ -42,20 +42,21 @@ using namespace Materials;
TYPESYSTEM_SOURCE(Materials::MaterialProperty, Materials::ModelProperty)
int const MaterialProperty::PRECISION = 6;
MaterialProperty::MaterialProperty()
{
_valuePtr = std::make_shared<MaterialValue>(MaterialValue::None);
}
MaterialProperty::MaterialProperty(const ModelProperty& property)
: ModelProperty(property)
MaterialProperty::MaterialProperty(const ModelProperty& other)
: ModelProperty(other)
, _valuePtr(nullptr)
{
setType(getPropertyType());
auto columns = property.getColumns();
for (std::vector<ModelProperty>::const_iterator it = columns.begin(); it != columns.end();
it++) {
MaterialProperty prop(*it);
auto columns = other.getColumns();
for (auto& it : columns) {
MaterialProperty prop(it);
addColumn(prop);
}
@@ -67,7 +68,7 @@ MaterialProperty::MaterialProperty(const ModelProperty& property)
}
}
void MaterialProperty::copyValuePtr(std::shared_ptr<MaterialValue> value)
void MaterialProperty::copyValuePtr(const std::shared_ptr<MaterialValue>& value)
{
if (value->getType() == MaterialValue::Array2D) {
_valuePtr =
@@ -84,16 +85,16 @@ void MaterialProperty::copyValuePtr(std::shared_ptr<MaterialValue> value)
MaterialProperty::MaterialProperty(const MaterialProperty& other)
: ModelProperty(other)
, _modelUUID(other._modelUUID)
{
_modelUUID = other._modelUUID;
copyValuePtr(other._valuePtr);
for (auto it = other._columns.begin(); it != other._columns.end(); it++) {
_columns.push_back(*it);
for (auto& it : other._columns) {
_columns.push_back(it);
}
}
MaterialProperty::MaterialProperty(std::shared_ptr<MaterialProperty> other)
MaterialProperty::MaterialProperty(const std::shared_ptr<MaterialProperty>& other)
: MaterialProperty(*other)
{}
@@ -102,7 +103,12 @@ void MaterialProperty::setModelUUID(const QString& uuid)
_modelUUID = uuid;
}
const QVariant MaterialProperty::getValue() const
QVariant MaterialProperty::getValue()
{
return _valuePtr->getValue();
}
QVariant MaterialProperty::getValue() const
{
return _valuePtr->getValue();
}
@@ -112,31 +118,31 @@ std::shared_ptr<MaterialValue> MaterialProperty::getMaterialValue()
return _valuePtr;
}
const std::shared_ptr<MaterialValue> MaterialProperty::getMaterialValue() const
std::shared_ptr<MaterialValue> MaterialProperty::getMaterialValue() const
{
return _valuePtr;
}
const QString MaterialProperty::getString() const
QString MaterialProperty::getString() const
{
if (isNull()) {
return QString();
return {};
}
if (getType() == MaterialValue::Quantity) {
Base::Quantity quantity = getValue().value<Base::Quantity>();
auto quantity = getValue().value<Base::Quantity>();
return quantity.getUserString();
}
else if (getType() == MaterialValue::Float) {
if (getType() == MaterialValue::Float) {
auto value = getValue();
if (value.isNull()) {
return QString();
return {};
}
return QString(QString::fromStdString("%1")).arg(value.toFloat(), 0, 'g', 6);
return QString(QString::fromStdString("%1")).arg(value.toFloat(), 0, 'g', PRECISION);
}
return getValue().toString();
}
const QString MaterialProperty::getYAMLString() const
QString MaterialProperty::getYAMLString() const
{
return _valuePtr->getYAMLString();
}
@@ -179,6 +185,9 @@ void MaterialProperty::setType(const QString& type)
else if (type == QString::fromStdString("List")) {
_valuePtr = std::make_shared<MaterialValue>(MaterialValue::List);
}
else if (type == QString::fromStdString("MultiLineString")) {
_valuePtr = std::make_shared<MaterialValue>(MaterialValue::MultiLineString);
}
else if (type == QString::fromStdString("2DArray")) {
_valuePtr = std::make_shared<Material2DArray>();
}
@@ -188,8 +197,8 @@ void MaterialProperty::setType(const QString& type)
else {
// Error. Throw something
_valuePtr = std::make_shared<MaterialValue>(MaterialValue::None);
std::string stringType = type.toStdString();
std::string name = getName().toStdString();
// std::string stringType = type.toStdString(); - useful for debugging since we can't see
// std::string name = getName().toStdString();
throw UnknownValueType();
}
}
@@ -240,19 +249,19 @@ QVariant MaterialProperty::getColumnNull(int column) const
switch (valueType) {
case MaterialValue::Quantity: {
Base::Quantity q = Base::Quantity(0, getColumnUnits(column));
return QVariant::fromValue(q);
Base::Quantity quant = Base::Quantity(0, getColumnUnits(column));
return QVariant::fromValue(quant);
}
case MaterialValue::Float:
case MaterialValue::Integer:
return QVariant(0);
return 0;
default:
break;
}
return QVariant(QString());
return QString();
}
void MaterialProperty::setValue(const QVariant& value)
@@ -274,11 +283,9 @@ void MaterialProperty::setValue(const QString& value)
else if (_valuePtr->getType() == MaterialValue::URL) {
setURL(value);
}
else if (_valuePtr->getType() == MaterialValue::Array2D) {
//_valuePtr->setValue(QVariant(std::make_shared<Material2DArray>()));
}
else if (_valuePtr->getType() == MaterialValue::Array3D) {
//_valuePtr = std::make_shared<Material3DArray>();
else if (_valuePtr->getType() == MaterialValue::Array2D
|| _valuePtr->getType() == MaterialValue::Array3D) {
// This value can't be directly assigned
}
else if (_valuePtr->getType() == MaterialValue::Quantity) {
// Base::Console().Log("\tParse quantity '%s'\n", value.toStdString().c_str());
@@ -298,7 +305,7 @@ void MaterialProperty::setValue(const QString& value)
}
}
void MaterialProperty::setValue(std::shared_ptr<MaterialValue> value)
void MaterialProperty::setValue(const std::shared_ptr<MaterialValue>& value)
{
_valuePtr = value;
}
@@ -323,8 +330,7 @@ void MaterialProperty::setBoolean(int value)
void MaterialProperty::setBoolean(const QString& value)
{
// _valueType = MaterialValue::Boolean;
bool boolean;
bool boolean = false;
std::string val = value.toStdString();
if ((val == "true") || (val == "True")) {
boolean = true;
@@ -374,6 +380,11 @@ void MaterialProperty::setQuantity(const QString& value)
setQuantity(Base::Quantity::parse(value));
}
void MaterialProperty::setList(const QList<QVariant>& value)
{
_valuePtr->setList(value);
}
void MaterialProperty::setURL(const QString& value)
{
_valuePtr->setValue(QVariant(value));
@@ -391,8 +402,8 @@ MaterialProperty& MaterialProperty::operator=(const MaterialProperty& other)
copyValuePtr(other._valuePtr);
_columns.clear();
for (auto it = other._columns.begin(); it != other._columns.end(); it++) {
_columns.push_back(*it);
for (auto& it : other._columns) {
_columns.push_back(it);
}
return *this;
@@ -417,7 +428,7 @@ Material::Material()
, _editState(ModelEdit_None)
{}
Material::Material(std::shared_ptr<MaterialLibrary> library,
Material::Material(const std::shared_ptr<MaterialLibrary>& library,
const QString& directory,
const QString& uuid,
const QString& name)
@@ -444,29 +455,29 @@ Material::Material(const Material& other)
, _dereferenced(other._dereferenced)
, _editState(other._editState)
{
for (auto it = other._tags.begin(); it != other._tags.end(); it++) {
_tags.push_back(*it);
for (auto& it : other._tags) {
_tags.push_back(it);
}
for (auto it = other._physicalUuids.begin(); it != other._physicalUuids.end(); it++) {
_physicalUuids.push_back(*it);
for (auto& it : other._physicalUuids) {
_physicalUuids.push_back(it);
}
for (auto it = other._appearanceUuids.begin(); it != other._appearanceUuids.end(); it++) {
_appearanceUuids.push_back(*it);
for (auto& it : other._appearanceUuids) {
_appearanceUuids.push_back(it);
}
for (auto it = other._allUuids.begin(); it != other._allUuids.end(); it++) {
_allUuids.push_back(*it);
for (auto& it : other._allUuids) {
_allUuids.push_back(it);
}
for (auto it = other._physical.begin(); it != other._physical.end(); it++) {
MaterialProperty prop(it->second);
_physical[it->first] = std::make_shared<MaterialProperty>(prop);
for (auto& it : other._physical) {
MaterialProperty prop(it.second);
_physical[it.first] = std::make_shared<MaterialProperty>(prop);
}
for (auto it = other._appearance.begin(); it != other._appearance.end(); it++) {
MaterialProperty prop(it->second);
_appearance[it->first] = std::make_shared<MaterialProperty>(prop);
for (auto& it : other._appearance) {
MaterialProperty prop(it.second);
_appearance[it.first] = std::make_shared<MaterialProperty>(prop);
}
}
const QString Material::getAuthorAndLicense() const
QString Material::getAuthorAndLicense() const
{
QString authorAndLicense;
@@ -486,7 +497,7 @@ const QString Material::getAuthorAndLicense() const
void Material::addModel(const QString& uuid)
{
for (QString modelUUID : _allUuids) {
for (QString& modelUUID : _allUuids) {
if (modelUUID == uuid) {
return;
}
@@ -499,19 +510,14 @@ void Material::addModel(const QString& uuid)
try {
auto model = manager.getModel(uuid);
auto inheritance = model->getInheritance();
for (auto inherits = inheritance.begin(); inherits != inheritance.end(); inherits++) {
addModel(*inherits);
for (auto& inherits : inheritance) {
addModel(inherits);
}
}
catch (ModelNotFound const&) {
}
}
void Material::removeModel(const QString& uuid)
{
Q_UNUSED(uuid);
}
void Material::clearModels()
{
_physicalUuids.clear();
@@ -592,20 +598,20 @@ void Material::addPhysical(const QString& uuid)
auto model = manager.getModel(uuid);
auto& inheritance = model->getInheritance();
for (auto it = inheritance.begin(); it != inheritance.end(); it++) {
for (auto& it : inheritance) {
// Inherited models may already have the properties, so just
// remove the uuid
removeUUID(_physicalUuids, *it);
removeUUID(_physicalUuids, it);
}
_physicalUuids.push_back(uuid);
addModel(uuid);
setEditStateExtend();
for (auto it = model->begin(); it != model->end(); it++) {
QString propertyName = it->first;
for (auto& it : *model) {
QString propertyName = it.first;
if (!hasPhysicalProperty(propertyName)) {
ModelProperty property = static_cast<ModelProperty>(it->second);
ModelProperty property = static_cast<ModelProperty>(it.second);
try {
_physical[propertyName] = std::make_shared<MaterialProperty>(property);
@@ -630,8 +636,8 @@ void Material::removePhysical(const QString& uuid)
// If it's an inherited model, do nothing
bool inherited = true;
for (auto it = _physicalUuids.begin(); it != _physicalUuids.end(); it++) {
if (*it == uuid) {
for (auto& it : _physicalUuids) {
if (it == uuid) {
inherited = false;
break;
}
@@ -646,15 +652,15 @@ void Material::removePhysical(const QString& uuid)
auto model = manager.getModel(uuid);
auto& inheritance = model->getInheritance();
for (auto it = inheritance.begin(); it != inheritance.end(); it++) {
removeUUID(_physicalUuids, *it);
removeUUID(_allUuids, *it);
for (auto& it : inheritance) {
removeUUID(_physicalUuids, it);
removeUUID(_allUuids, it);
}
removeUUID(_physicalUuids, uuid);
removeUUID(_allUuids, uuid);
for (auto it = model->begin(); it != model->end(); it++) {
_physical.erase(it->first);
for (auto& it : *model) {
_physical.erase(it.first);
}
setEditStateAlter();
@@ -675,20 +681,20 @@ void Material::addAppearance(const QString& uuid)
auto model = manager.getModel(uuid);
auto& inheritance = model->getInheritance();
for (auto it = inheritance.begin(); it != inheritance.end(); it++) {
for (auto& it : inheritance) {
// Inherited models may already have the properties, so just
// remove the uuid
removeUUID(_appearanceUuids, *it);
removeUUID(_appearanceUuids, it);
}
_appearanceUuids.push_back(uuid);
addModel(uuid);
setEditStateExtend();
for (auto it = model->begin(); it != model->end(); it++) {
QString propertyName = it->first;
for (auto& it : *model) {
QString propertyName = it.first;
if (!hasAppearanceProperty(propertyName)) {
ModelProperty property = static_cast<ModelProperty>(it->second);
ModelProperty property = static_cast<ModelProperty>(it.second);
_appearance[propertyName] = std::make_shared<MaterialProperty>(property);
}
@@ -706,8 +712,8 @@ void Material::removeAppearance(const QString& uuid)
// If it's an inherited model, do nothing
bool inherited = true;
for (auto it = _appearanceUuids.begin(); it != _appearanceUuids.end(); it++) {
if (*it == uuid) {
for (auto& it : _appearanceUuids) {
if (it == uuid) {
inherited = false;
break;
}
@@ -722,15 +728,15 @@ void Material::removeAppearance(const QString& uuid)
auto model = manager.getModel(uuid);
auto& inheritance = model->getInheritance();
for (auto it = inheritance.begin(); it != inheritance.end(); it++) {
removeUUID(_appearanceUuids, *it);
removeUUID(_allUuids, *it);
for (auto& it : inheritance) {
removeUUID(_appearanceUuids, it);
removeUUID(_allUuids, it);
}
removeUUID(_appearanceUuids, uuid);
removeUUID(_allUuids, uuid);
for (auto it = model->begin(); it != model->end(); it++) {
_appearance.erase(it->first);
for (auto& it : *model) {
_appearance.erase(it.first);
}
setEditStateAlter();
@@ -790,20 +796,27 @@ void Material::setPhysicalValue(const QString& name, double value)
_physical[name]->setFloat(value);
}
void Material::setPhysicalValue(const QString& name, const Base::Quantity value)
void Material::setPhysicalValue(const QString& name, const Base::Quantity& value)
{
setPhysicalEditState(name);
_physical[name]->setQuantity(value);
}
void Material::setPhysicalValue(const QString& name, std::shared_ptr<MaterialValue> value)
void Material::setPhysicalValue(const QString& name, const std::shared_ptr<MaterialValue>& value)
{
setPhysicalEditState(name);
_physical[name]->setValue(value);
}
void Material::setPhysicalValue(const QString& name, const std::shared_ptr<QList<QVariant>>& value)
{
setPhysicalEditState(name);
_physical[name]->setList(*value);
}
void Material::setAppearanceValue(const QString& name, const QString& value)
{
setAppearanceEditState(name);
@@ -811,13 +824,21 @@ void Material::setAppearanceValue(const QString& name, const QString& value)
_appearance[name]->setValue(value); // may not be a string type, conversion may be required
}
void Material::setAppearanceValue(const QString& name, std::shared_ptr<MaterialValue> value)
void Material::setAppearanceValue(const QString& name, const std::shared_ptr<MaterialValue>& value)
{
setAppearanceEditState(name);
_appearance[name]->setValue(value);
}
void Material::setAppearanceValue(const QString& name,
const std::shared_ptr<QList<QVariant>>& value)
{
setPhysicalEditState(name);
_appearance[name]->setList(*value);
}
std::shared_ptr<MaterialProperty> Material::getPhysicalProperty(const QString& name)
{
try {
@@ -828,7 +849,7 @@ std::shared_ptr<MaterialProperty> Material::getPhysicalProperty(const QString& n
}
}
const std::shared_ptr<MaterialProperty> Material::getPhysicalProperty(const QString& name) const
std::shared_ptr<MaterialProperty> Material::getPhysicalProperty(const QString& name) const
{
try {
return _physical.at(name);
@@ -848,7 +869,7 @@ std::shared_ptr<MaterialProperty> Material::getAppearanceProperty(const QString&
}
}
const std::shared_ptr<MaterialProperty> Material::getAppearanceProperty(const QString& name) const
std::shared_ptr<MaterialProperty> Material::getAppearanceProperty(const QString& name) const
{
try {
return _appearance.at(name);
@@ -858,9 +879,9 @@ const std::shared_ptr<MaterialProperty> Material::getAppearanceProperty(const QS
}
}
const QVariant
QVariant
Material::getValue(const std::map<QString, std::shared_ptr<MaterialProperty>>& propertyList,
const QString& name) const
const QString& name)
{
try {
return propertyList.at(name)->getValue();
@@ -870,28 +891,29 @@ Material::getValue(const std::map<QString, std::shared_ptr<MaterialProperty>>& p
}
}
const QString
QString
Material::getValueString(const std::map<QString, std::shared_ptr<MaterialProperty>>& propertyList,
const QString& name) const
const QString& name)
{
try {
auto property = propertyList.at(name);
const auto& property = propertyList.at(name);
if (property->isNull()) {
return QString();
return {};
}
if (property->getType() == MaterialValue::Quantity) {
auto value = property->getValue();
if (value.isNull()) {
return QString();
return {};
}
return value.value<Base::Quantity>().getUserString();
}
else if (property->getType() == MaterialValue::Float) {
if (property->getType() == MaterialValue::Float) {
auto value = property->getValue();
if (value.isNull()) {
return QString();
return {};
}
return QString(QString::fromStdString("%1")).arg(value.toFloat(), 0, 'g', 6);
return QString(QString::fromStdString("%1"))
.arg(value.toFloat(), 0, 'g', MaterialProperty::PRECISION);
}
return property->getValue().toString();
}
@@ -900,32 +922,32 @@ Material::getValueString(const std::map<QString, std::shared_ptr<MaterialPropert
}
}
const QVariant Material::getPhysicalValue(const QString& name) const
QVariant Material::getPhysicalValue(const QString& name) const
{
return getValue(_physical, name);
}
const Base::Quantity Material::getPhysicalQuantity(const QString& name) const
Base::Quantity Material::getPhysicalQuantity(const QString& name) const
{
return getValue(_physical, name).value<Base::Quantity>();
}
const QString Material::getPhysicalValueString(const QString& name) const
QString Material::getPhysicalValueString(const QString& name) const
{
return getValueString(_physical, name);
}
const QVariant Material::getAppearanceValue(const QString& name) const
QVariant Material::getAppearanceValue(const QString& name) const
{
return getValue(_appearance, name);
}
const Base::Quantity Material::getAppearanceQuantity(const QString& name) const
Base::Quantity Material::getAppearanceQuantity(const QString& name) const
{
return getValue(_appearance, name).value<Base::Quantity>();
}
const QString Material::getAppearanceValueString(const QString& name) const
QString Material::getAppearanceValueString(const QString& name) const
{
return getValueString(_appearance, name);
}
@@ -1007,8 +1029,8 @@ bool Material::isPhysicalModelComplete(const QString& uuid) const
try {
auto model = manager.getModel(uuid);
for (auto it = model->begin(); it != model->end(); it++) {
QString propertyName = it->first;
for (auto& it : *model) {
QString propertyName = it.first;
auto property = getPhysicalProperty(propertyName);
if (property->isNull()) {
@@ -1033,8 +1055,8 @@ bool Material::isAppearanceModelComplete(const QString& uuid) const
try {
auto model = manager.getModel(uuid);
for (auto it = model->begin(); it != model->end(); it++) {
QString propertyName = it->first;
for (auto& it : *model) {
QString propertyName = it.first;
auto property = getAppearanceProperty(propertyName);
if (property->isNull()) {
@@ -1053,21 +1075,21 @@ void Material::saveGeneral(QTextStream& stream) const
{
stream << "General:\n";
stream << " UUID: \"" << _uuid << "\"\n";
stream << " Name: \"" << _name << "\"\n";
stream << " Name: \"" << MaterialValue::escapeString(_name) << "\"\n";
if (!_author.isEmpty()) {
stream << " Author: \"" << _author << "\"\n";
stream << " Author: \"" << MaterialValue::escapeString(_author) << "\"\n";
}
if (!_license.isEmpty()) {
stream << " License: \"" << _license << "\"\n";
stream << " License: \"" << MaterialValue::escapeString(_license) << "\"\n";
}
if (!_description.isEmpty()) {
stream << " Description: \"" << _description << "\"\n";
stream << " Description: \"" << MaterialValue::escapeString(_description) << "\"\n";
}
if (!_url.isEmpty()) {
stream << " SourceURL: \"" << _url << "\"\n";
stream << " SourceURL: \"" << MaterialValue::escapeString(_url) << "\"\n";
}
if (!_reference.isEmpty()) {
stream << " ReferenceSource: \"" << _reference << "\"\n";
stream << " ReferenceSource: \"" << MaterialValue::escapeString(_reference) << "\"\n";
}
}
@@ -1088,11 +1110,11 @@ void Material::saveInherits(QTextStream& stream) const
}
}
bool Material::modelChanged(const std::shared_ptr<Material> parent,
const std::shared_ptr<Model> model) const
bool Material::modelChanged(const std::shared_ptr<Material>& parent,
const std::shared_ptr<Model>& model) const
{
for (auto itp = model->begin(); itp != model->end(); itp++) {
QString propertyName = itp->first;
for (auto& it : *model) {
QString propertyName = it.first;
auto property = getPhysicalProperty(propertyName);
try {
auto parentProperty = parent->getPhysicalProperty(propertyName);
@@ -1109,11 +1131,11 @@ bool Material::modelChanged(const std::shared_ptr<Material> parent,
return false;
}
bool Material::modelAppearanceChanged(const std::shared_ptr<Material> parent,
const std::shared_ptr<Model> model) const
bool Material::modelAppearanceChanged(const std::shared_ptr<Material>& parent,
const std::shared_ptr<Model>& model) const
{
for (auto itp = model->begin(); itp != model->end(); itp++) {
QString propertyName = itp->first;
for (auto& it : *model) {
QString propertyName = it.first;
auto property = getAppearanceProperty(propertyName);
try {
auto parentProperty = parent->getAppearanceProperty(propertyName);
@@ -1132,49 +1154,51 @@ bool Material::modelAppearanceChanged(const std::shared_ptr<Material> parent,
void Material::saveModels(QTextStream& stream, bool saveInherited) const
{
if (!_physical.empty()) {
ModelManager modelManager;
MaterialManager materialManager;
if (_physical.empty()) {
return;
}
bool inherited = saveInherited && (_parentUuid.size() > 0);
std::shared_ptr<Material> parent;
if (inherited) {
try {
parent = materialManager.getMaterial(_parentUuid);
}
catch (const MaterialNotFound&) {
inherited = false;
}
ModelManager modelManager;
MaterialManager materialManager;
bool inherited = saveInherited && (_parentUuid.size() > 0);
std::shared_ptr<Material> parent;
if (inherited) {
try {
parent = materialManager.getMaterial(_parentUuid);
}
catch (const MaterialNotFound&) {
inherited = false;
}
}
bool headerPrinted = false;
for (auto itm = _physicalUuids.begin(); itm != _physicalUuids.end(); itm++) {
auto model = modelManager.getModel(*itm);
if (!inherited || modelChanged(parent, model)) {
if (!headerPrinted) {
stream << "Models:\n";
headerPrinted = true;
bool headerPrinted = false;
for (auto& itm : _physicalUuids) {
auto model = modelManager.getModel(itm);
if (!inherited || modelChanged(parent, model)) {
if (!headerPrinted) {
stream << "Models:\n";
headerPrinted = true;
}
stream << " " << MaterialValue::escapeString(model->getName()) << ":\n";
stream << " UUID: \"" << model->getUUID() << "\"\n";
for (const auto& it : *model) {
QString propertyName = it.first;
std::shared_ptr<MaterialProperty> property = getPhysicalProperty(propertyName);
std::shared_ptr<MaterialProperty> parentProperty;
try {
if (inherited) {
parentProperty = parent->getPhysicalProperty(propertyName);
}
}
catch (const PropertyNotFound&) {
Base::Console().Log("Material::saveModels Property not found '%s'\n",
propertyName.toStdString().c_str());
}
stream << " " << model->getName() << ":\n";
stream << " UUID: \"" << model->getUUID() << "\"\n";
for (auto itp = model->begin(); itp != model->end(); itp++) {
QString propertyName = itp->first;
std::shared_ptr<MaterialProperty> property = getPhysicalProperty(propertyName);
std::shared_ptr<MaterialProperty> parentProperty;
try {
if (inherited) {
parentProperty = parent->getPhysicalProperty(propertyName);
}
}
catch (const PropertyNotFound&) {
Base::Console().Log("Material::saveModels Property not found '%s'\n",
propertyName.toStdString().c_str());
}
if (!inherited || (*property != *parentProperty)) {
if (!property->isNull()) {
stream << " " << *property << "\n";
}
if (!inherited || !parentProperty || (*property != *parentProperty)) {
if (!property->isNull()) {
stream << " " << *property << "\n";
}
}
}
@@ -1184,48 +1208,49 @@ void Material::saveModels(QTextStream& stream, bool saveInherited) const
void Material::saveAppearanceModels(QTextStream& stream, bool saveInherited) const
{
if (!_appearance.empty()) {
ModelManager modelManager;
MaterialManager materialManager;
if (_appearance.empty()) {
return;
}
bool inherited = saveInherited && (_parentUuid.size() > 0);
std::shared_ptr<Material> parent;
if (inherited) {
try {
parent = materialManager.getMaterial(_parentUuid);
}
catch (const MaterialNotFound&) {
inherited = false;
}
ModelManager modelManager;
MaterialManager materialManager;
bool inherited = saveInherited && (_parentUuid.size() > 0);
std::shared_ptr<Material> parent;
if (inherited) {
try {
parent = materialManager.getMaterial(_parentUuid);
}
catch (const MaterialNotFound&) {
inherited = false;
}
}
bool headerPrinted = false;
for (auto itm = _appearanceUuids.begin(); itm != _appearanceUuids.end(); itm++) {
auto model = modelManager.getModel(*itm);
if (!inherited || modelAppearanceChanged(parent, model)) {
if (!headerPrinted) {
stream << "AppearanceModels:\n";
headerPrinted = true;
bool headerPrinted = false;
for (auto& itm : _appearanceUuids) {
auto model = modelManager.getModel(itm);
if (!inherited || modelAppearanceChanged(parent, model)) {
if (!headerPrinted) {
stream << "AppearanceModels:\n";
headerPrinted = true;
}
stream << " " << MaterialValue::escapeString(model->getName()) << ":\n";
stream << " UUID: \"" << model->getUUID() << "\"\n";
for (const auto& it : *model) {
QString propertyName = it.first;
std::shared_ptr<MaterialProperty> property = getAppearanceProperty(propertyName);
std::shared_ptr<MaterialProperty> parentProperty;
try {
if (inherited) {
parentProperty = parent->getAppearanceProperty(propertyName);
}
}
catch (const PropertyNotFound&) {
}
stream << " " << model->getName() << ":\n";
stream << " UUID: \"" << model->getUUID() << "\"\n";
for (auto itp = model->begin(); itp != model->end(); itp++) {
QString propertyName = itp->first;
std::shared_ptr<MaterialProperty> property =
getAppearanceProperty(propertyName);
std::shared_ptr<MaterialProperty> parentProperty;
try {
if (inherited) {
parentProperty = parent->getAppearanceProperty(propertyName);
}
}
catch (const PropertyNotFound&) {
}
if (!inherited || (*property != *parentProperty)) {
if (!property->isNull()) {
stream << " " << *property << "\n";
}
if (!inherited || !parentProperty || (*property != *parentProperty)) {
if (!property->isNull()) {
stream << " " << *property << "\n";
}
}
}
@@ -1242,29 +1267,29 @@ QString Material::getModelByName(const QString& name) const
{
ModelManager manager;
for (auto it = _allUuids.begin(); it != _allUuids.end(); it++) {
for (auto& it : _allUuids) {
try {
auto model = manager.getModel(*it);
auto model = manager.getModel(it);
if (model->getName() == name) {
return *it;
return it;
}
}
catch (ModelNotFound const&) {
}
}
return QString();
return {};
}
void Material::save(QTextStream& stream, bool saveAsCopy, bool saveInherited)
void Material::save(QTextStream& stream, bool overwrite, bool saveAsCopy, bool saveInherited)
{
if (saveInherited && !saveAsCopy) {
// Check to see if we're an original or if we're already in the list of models
MaterialManager materialManager;
if (materialManager.exists(_uuid)) {
if (materialManager.exists(_uuid) && !overwrite) {
// Make a new version based on the current
setParentUUID(_uuid);
newUuid();
// newUuid();
}
}
@@ -1277,6 +1302,13 @@ void Material::save(QTextStream& stream, bool saveAsCopy, bool saveInherited)
saveInherited = true;
}
}
else {
if (!overwrite) {
// Creating a new derived model when overwriting sets itself as a parent,
// that will no longer exist because it's been overwritten
newUuid();
}
}
stream << "---\n";
stream << "# File created by " << QString::fromStdString(App::Application::Config()["ExeName"])
@@ -1311,32 +1343,32 @@ Material& Material::operator=(const Material& other)
_editState = other._editState;
_tags.clear();
for (auto it = other._tags.begin(); it != other._tags.end(); it++) {
_tags.push_back(*it);
for (auto& it : other._tags) {
_tags.push_back(it);
}
_physicalUuids.clear();
for (auto it = other._physicalUuids.begin(); it != other._physicalUuids.end(); it++) {
_physicalUuids.push_back(*it);
for (auto& it : other._physicalUuids) {
_physicalUuids.push_back(it);
}
_appearanceUuids.clear();
for (auto it = other._appearanceUuids.begin(); it != other._appearanceUuids.end(); it++) {
_appearanceUuids.push_back(*it);
for (auto& it : other._appearanceUuids) {
_appearanceUuids.push_back(it);
}
_allUuids.clear();
for (auto it = other._allUuids.begin(); it != other._allUuids.end(); it++) {
_allUuids.push_back(*it);
for (auto& it : other._allUuids) {
_allUuids.push_back(it);
}
// Create copies of the properties rather than modify the originals
_physical.clear();
for (auto it = other._physical.begin(); it != other._physical.end(); it++) {
MaterialProperty prop(it->second);
_physical[it->first] = std::make_shared<MaterialProperty>(prop);
for (auto& it : other._physical) {
MaterialProperty prop(it.second);
_physical[it.first] = std::make_shared<MaterialProperty>(prop);
}
_appearance.clear();
for (auto it = other._appearance.begin(); it != other._appearance.end(); it++) {
MaterialProperty prop(it->second);
_appearance[it->first] = std::make_shared<MaterialProperty>(prop);
for (auto& it : other._appearance) {
MaterialProperty prop(it.second);
_appearance[it.first] = std::make_shared<MaterialProperty>(prop);
}
return *this;
@@ -1351,11 +1383,11 @@ QStringList Material::normalizeModels(const QStringList& models)
ModelManager manager;
for (auto uuid : models) {
for (auto& uuid : models) {
auto model = manager.getModel(uuid);
bool found = false;
for (auto childUuid : models) {
for (auto& childUuid : models) {
if (uuid != childUuid) {
auto childModel = manager.getModel(childUuid);
if (childModel->inherits(childUuid)) {
@@ -1377,16 +1409,16 @@ QStringList Material::normalizeModels(const QStringList& models)
* Set or change the base material for the current material, updating the properties as
* required.
*/
void Material::updateInheritance([[maybe_unused]]const QString& parent)
void Material::updateInheritance([[maybe_unused]] const QString& parent)
{}
/*
* Return a list of models that are defined in the parent material but not in this one
*/
QStringList Material::inheritedMissingModels(const Material& parent)
QStringList Material::inheritedMissingModels(const Material& parent) const
{
QStringList missing;
for (auto uuid : parent._allUuids) {
for (auto& uuid : parent._allUuids) {
if (!hasModel(uuid)) {
missing << uuid;
}
@@ -1398,10 +1430,10 @@ QStringList Material::inheritedMissingModels(const Material& parent)
/*
* Return a list of models that are defined in this model but not the parent
*/
QStringList Material::inheritedAddedModels(const Material& parent)
QStringList Material::inheritedAddedModels(const Material& parent) const
{
QStringList added;
for (auto uuid : _allUuids) {
for (auto& uuid : _allUuids) {
if (!parent.hasModel(uuid)) {
added << uuid;
}
@@ -1413,5 +1445,5 @@ QStringList Material::inheritedAddedModels(const Material& parent)
/*
* Return a list of properties that have different values from the parent material
*/
void Material::inheritedPropertyDiff([[maybe_unused]]const QString& parent)
void Material::inheritedPropertyDiff([[maybe_unused]] const QString& parent)
{}

View File

@@ -34,6 +34,7 @@
#include <Mod/Material/MaterialGlobal.h>
#include "MaterialValue.h"
#include "Model.h"
namespace Materials
@@ -47,9 +48,9 @@ class MaterialsExport MaterialProperty: public ModelProperty
public:
MaterialProperty();
MaterialProperty(const MaterialProperty& property);
explicit MaterialProperty(const ModelProperty& property);
explicit MaterialProperty(std::shared_ptr<MaterialProperty> property);
MaterialProperty(const MaterialProperty& other);
explicit MaterialProperty(const ModelProperty& other);
explicit MaterialProperty(const std::shared_ptr<MaterialProperty>& other);
~MaterialProperty() override = default;
MaterialValue::ValueType getType() const
@@ -58,15 +59,24 @@ public:
}
const QString getModelUUID() const;
const QVariant getValue() const;
QVariant getValue();
QVariant getValue() const;
QList<QVariant> getList()
{
return _valuePtr->getList();
}
QList<QVariant> getList() const
{
return _valuePtr->getList();
}
bool isNull() const
{
return _valuePtr->isNull();
}
std::shared_ptr<MaterialValue> getMaterialValue();
const std::shared_ptr<MaterialValue> getMaterialValue() const;
const QString getString() const;
const QString getYAMLString() const;
std::shared_ptr<MaterialValue> getMaterialValue() const;
QString getString() const;
QString getYAMLString() const;
bool getBoolean() const;
int getInt() const;
double getFloat() const;
@@ -83,7 +93,7 @@ public:
void setPropertyType(const QString& type) override;
void setValue(const QVariant& value);
void setValue(const QString& value);
void setValue(std::shared_ptr<MaterialValue> value);
void setValue(const std::shared_ptr<MaterialValue>& value);
void setString(const QString& value);
void setBoolean(bool value);
void setBoolean(int value);
@@ -95,14 +105,12 @@ public:
void setQuantity(const Base::Quantity& value);
void setQuantity(double value, const QString& units);
void setQuantity(const QString& value);
void setList(const QList<QVariant>& value);
void setURL(const QString& value);
MaterialProperty& operator=(const MaterialProperty& other);
friend QTextStream& operator<<(QTextStream& output, const MaterialProperty& property)
{
output << property.getName() << ": " << property.getYAMLString();
return output;
}
friend QTextStream& operator<<(QTextStream& output, const MaterialProperty& property);
bool operator==(const MaterialProperty& other) const;
bool operator!=(const MaterialProperty& other) const
{
@@ -111,10 +119,13 @@ public:
// void save(QTextStream& stream);
// Define precision for displaying floating point values
static int const PRECISION;
protected:
void setType(const QString& type);
// void setType(MaterialValue::ValueType type) { _valueType = type; }
void copyValuePtr(std::shared_ptr<MaterialValue> value);
void copyValuePtr(const std::shared_ptr<MaterialValue>& value);
void addColumn(MaterialProperty& column)
{
@@ -140,7 +151,7 @@ public:
};
Material();
Material(std::shared_ptr<MaterialLibrary> library,
Material(const std::shared_ptr<MaterialLibrary>& library,
const QString& directory,
const QString& uuid,
const QString& name);
@@ -151,40 +162,40 @@ public:
{
return _library;
}
const QString getDirectory() const
QString getDirectory() const
{
return _directory;
}
const QString getUUID() const
QString getUUID() const
{
return _uuid;
}
const QString getName() const
QString getName() const
{
return _name;
}
const QString getAuthorAndLicense() const;
const QString getAuthor() const
QString getAuthorAndLicense() const;
QString getAuthor() const
{
return _author;
}
const QString getLicense() const
QString getLicense() const
{
return _license;
}
const QString getParentUUID() const
QString getParentUUID() const
{
return _parentUuid;
}
const QString getDescription() const
QString getDescription() const
{
return _description;
}
const QString getURL() const
QString getURL() const
{
return _url;
}
const QString getReference() const
QString getReference() const
{
return _reference;
}
@@ -205,7 +216,7 @@ public:
return &_appearanceUuids;
}
void setLibrary(std::shared_ptr<MaterialLibrary> library)
void setLibrary(const std::shared_ptr<MaterialLibrary>& library)
{
_library = library;
}
@@ -259,22 +270,24 @@ public:
void setPhysicalValue(const QString& name, const QString& value);
void setPhysicalValue(const QString& name, int value);
void setPhysicalValue(const QString& name, double value);
void setPhysicalValue(const QString& name, const Base::Quantity value);
void setPhysicalValue(const QString& name, std::shared_ptr<MaterialValue> value);
void setPhysicalValue(const QString& name, const Base::Quantity& value);
void setPhysicalValue(const QString& name, const std::shared_ptr<MaterialValue>& value);
void setPhysicalValue(const QString& name, const std::shared_ptr<QList<QVariant>>& value);
void setAppearanceValue(const QString& name, const QString& value);
void setAppearanceValue(const QString& name, std::shared_ptr<MaterialValue> value);
void setAppearanceValue(const QString& name, const std::shared_ptr<MaterialValue>& value);
void setAppearanceValue(const QString& name, const std::shared_ptr<QList<QVariant>>& value);
std::shared_ptr<MaterialProperty> getPhysicalProperty(const QString& name);
const std::shared_ptr<MaterialProperty> getPhysicalProperty(const QString& name) const;
std::shared_ptr<MaterialProperty> getPhysicalProperty(const QString& name) const;
std::shared_ptr<MaterialProperty> getAppearanceProperty(const QString& name);
const std::shared_ptr<MaterialProperty> getAppearanceProperty(const QString& name) const;
const QVariant getPhysicalValue(const QString& name) const;
const Base::Quantity getPhysicalQuantity(const QString& name) const;
const QString getPhysicalValueString(const QString& name) const;
const QVariant getAppearanceValue(const QString& name) const;
const Base::Quantity getAppearanceQuantity(const QString& name) const;
const QString getAppearanceValueString(const QString& name) const;
std::shared_ptr<MaterialProperty> getAppearanceProperty(const QString& name) const;
QVariant getPhysicalValue(const QString& name) const;
Base::Quantity getPhysicalQuantity(const QString& name) const;
QString getPhysicalValueString(const QString& name) const;
QVariant getAppearanceValue(const QString& name) const;
Base::Quantity getAppearanceQuantity(const QString& name) const;
QString getAppearanceValueString(const QString& name) const;
bool hasPhysicalProperty(const QString& name) const;
bool hasAppearanceProperty(const QString& name) const;
@@ -312,7 +325,7 @@ public:
/*
* Normalize models by removing any inherited models
*/
QStringList normalizeModels(const QStringList& models);
static QStringList normalizeModels(const QStringList& models);
/*
* Set or change the base material for the current material, updating the properties as
@@ -322,36 +335,35 @@ public:
/*
* Return a list of models that are defined in the parent material but not in this one
*/
QStringList inheritedMissingModels(const Material& parent);
QStringList inheritedMissingModels(const Material& parent) const;
/*
* Return a list of models that are defined in this model but not the parent
*/
QStringList inheritedAddedModels(const Material& parent);
QStringList inheritedAddedModels(const Material& parent) const;
/*
* Return a list of properties that have different values from the parent material
*/
void inheritedPropertyDiff(const QString& parent);
void save(QTextStream& stream, bool saveAsCopy, bool saveInherited);
void save(QTextStream& stream, bool overwrite, bool saveAsCopy, bool saveInherited);
Material& operator=(const Material& other);
protected:
void addModel(const QString& uuid);
void removeModel(const QString& uuid);
void removeUUID(QStringList& uuidList, const QString& uuid);
static void removeUUID(QStringList& uuidList, const QString& uuid);
const QVariant
static QVariant
getValue(const std::map<QString, std::shared_ptr<MaterialProperty>>& propertyList,
const QString& name) const;
const QString
const QString& name);
static QString
getValueString(const std::map<QString, std::shared_ptr<MaterialProperty>>& propertyList,
const QString& name) const;
const QString& name);
bool modelChanged(const std::shared_ptr<Material> parent,
const std::shared_ptr<Model> model) const;
bool modelAppearanceChanged(const std::shared_ptr<Material> parent,
const std::shared_ptr<Model> model) const;
bool modelChanged(const std::shared_ptr<Material>& parent,
const std::shared_ptr<Model>& model) const;
bool modelAppearanceChanged(const std::shared_ptr<Material>& parent,
const std::shared_ptr<Model>& model) const;
void saveGeneral(QTextStream& stream) const;
void saveInherits(QTextStream& stream) const;
void saveModels(QTextStream& stream, bool saveInherited) const;
@@ -378,7 +390,13 @@ private:
ModelEdit _editState;
};
typedef FolderTreeNode<Material> MaterialTreeNode;
inline QTextStream& operator<<(QTextStream& output, const MaterialProperty& property)
{
output << MaterialValue::escapeString(property.getName()) << ": " << property.getYAMLString();
return output;
}
using MaterialTreeNode = FolderTreeNode<Material>;
} // namespace Materials

View File

@@ -37,7 +37,7 @@
using namespace Materials;
ModelEntry::ModelEntry(std::shared_ptr<ModelLibrary> library,
ModelEntry::ModelEntry(const std::shared_ptr<ModelLibrary>& library,
const QString& baseName,
const QString& modelName,
const QString& dir,
@@ -228,8 +228,6 @@ void ModelLoader::addToTree(std::shared_ptr<ModelEntry> model,
auto directory = model->getDirectory();
auto uuid = model->getUUID();
QString version = yamlValue(yamlModel["General"], "Version", "");
QString description = yamlValue(yamlModel[base], "Description", "");
QString url = yamlValue(yamlModel[base], "URL", "");
QString doi = yamlValue(yamlModel[base], "DOI", "");
@@ -273,7 +271,7 @@ void ModelLoader::addToTree(std::shared_ptr<ModelEntry> model,
// Base::Console().Log("Reading columns\n");
// Read the columns
auto cols = yamlProp["Columns"];
for (auto col : cols) {
for (const auto& col : cols) {
std::string colName = col.first.as<std::string>();
// Base::Console().Log("\tColumns '%s'\n", colName.c_str());
@@ -316,8 +314,6 @@ void ModelLoader::loadLibrary(std::shared_ptr<ModelLibrary> library)
QFileInfo file(pathname);
if (file.isFile()) {
if (file.suffix().toStdString() == "yml") {
QString libraryName = file.baseName();
try {
auto model = getModelFromPath(library, file.canonicalFilePath());
(*_modelEntryMap)[model->getUUID()] = model;

View File

@@ -36,7 +36,7 @@ namespace Materials
class ModelEntry
{
public:
ModelEntry(std::shared_ptr<ModelLibrary> library,
ModelEntry(const std::shared_ptr<ModelLibrary>& library,
const QString& baseName,
const QString& modelName,
const QString& dir,

View File

@@ -99,7 +99,7 @@ std::shared_ptr<Model> ModelManager::getModelByPath(const QString& path) const
{
QString cleanPath = QDir::cleanPath(path);
for (auto library : *_libraryList) {
for (auto& library : *_libraryList) {
// Base::Console().Log("ModelManager::getModelByPath() Checking library '%s'->'%s'\n",
// library->getName().toStdString().c_str(),
// library->getDirectory().toStdString().c_str());
@@ -127,7 +127,7 @@ std::shared_ptr<Model> ModelManager::getModelByPath(const QString& path, const Q
std::shared_ptr<ModelLibrary> ModelManager::getLibrary(const QString& name) const
{
for (auto library : *_libraryList) {
for (auto& library : *_libraryList) {
if (library->getName() == name) {
return library;
}

View File

@@ -33,7 +33,6 @@
#include "Model.h"
#include "ModelLibrary.h"
namespace Materials
{

View File

@@ -68,3 +68,6 @@ const QString ModelUUIDs::ModelUUID_Rendering_Advanced =
QString::fromStdString("c880f092-cdae-43d6-a24b-55e884aacbbf");
const QString ModelUUIDs::ModelUUID_Rendering_Vector =
QString::fromStdString("fdf5a80e-de50-4157-b2e5-b6e5f88b680e");
const QString ModelUUIDs::ModelUUID_Test_Material =
QString::fromStdString("c6c64159-19c1-40b5-859c-10561f20f979");

View File

@@ -65,6 +65,8 @@ public:
static const QString ModelUUID_Rendering_Texture;
static const QString ModelUUID_Rendering_Advanced;
static const QString ModelUUID_Rendering_Vector;
static const QString ModelUUID_Test_Material;
};
} // namespace Materials

View File

@@ -32,133 +32,133 @@ SET(Material_Icon_Files
# collect all the material cards:
# FILE( GLOB MaterialLib_Files ./StandardMaterial/*.FCMat ./StandardMaterial/*.txt )
SET(MaterialLib_Files
Resources/Materials/StandardMaterial/Aggregate/Concrete-EN-C35_45.FCMat
Resources/Materials/StandardMaterial/Aggregate/Concrete-Generic.FCMat
Resources/Materials/StandardMaterial/Aggregate/Reinforcement-FIB-B500.FCMat
Resources/Materials/StandardMaterial/Carbon/Graphite.FCMat
Resources/Materials/StandardMaterial/Glass/Glass-E-GlassFibre.FCMat
Resources/Materials/StandardMaterial/Glass/Glass-Generic.FCMat
Resources/Materials/StandardMaterial/Glass/Glass-S2-GlassFibre.FCMat
Resources/Materials/StandardMaterial/Metal/Alloys/Invar-Generic.FCMat
Resources/Materials/StandardMaterial/Metal/Aluminum/AlMg3F24.FCMat
Resources/Materials/StandardMaterial/Metal/Aluminum/AlMgSi1F31.FCMat
Resources/Materials/StandardMaterial/Metal/Aluminum/Aluminum-6061-T6.FCMat
Resources/Materials/StandardMaterial/Metal/Aluminum/Aluminum-Generic.FCMat
Resources/Materials/StandardMaterial/Metal/Aluminum/AlZn4-5Mg1F35.FCMat
Resources/Materials/StandardMaterial/Metal/Copper/Copper-Generic.FCMat
Resources/Materials/StandardMaterial/Metal/Iron/Iron-Generic.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/CalculiX-Steel.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-15CrNi6.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-17CrNiMo6.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-1C22.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-1C35.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-1C45.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-1C60.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-20NiCrMo2.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-28Mn6.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-2C10.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-30CrNiMo8.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-34CrNiMo6.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-36CrNiMo4.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-36NiCrMo16.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-3C15.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-3C22.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-3C35.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-3V45.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C10.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C15.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C22E.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C25E.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C30E.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C40E.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C50E.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C55E.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-C60E.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-E295-GC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-E295.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-E335-GC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-E335.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-E360-GC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-E360.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJL-100.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJL-150.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJL-200.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJL-250.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJL-300.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJL-350.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJMB-350-10.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJMB-550-4.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJMB-650-2.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJMW-350-4.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJMW-360-12.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJMW-400-5.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJMW-450-7.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJS-400-15.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJS-500-7.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJS-600-3.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJS-700-2.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-EN-GJS-800-1.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-G16Mn5.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-G200.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-G20Mn5.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-G230.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-G260.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-G300.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-G30Mn5.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-Generic.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S185.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S235JO.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S235JR.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S235JRG1.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S260NC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S275JO.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S275JR.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S275N.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S335JO.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S335JR.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S335N.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S340MC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S355J2G3.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S380MC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S420MC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S420N.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S460MC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S460N.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S500MC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S550MC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-S690MC.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-St-37-2K.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-St-E-255.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-St-E-315.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-St-E-380.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-St-E-460.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-St-E-500.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-X2CrNiMoN17-13-3.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-X2CrNiN24-4.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-X39CrMo17-1.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-X3CrNiMo13-14.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-X5CrNi18-10.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-X5CrNiMo17-12-2.FCMat
Resources/Materials/StandardMaterial/Metal/Steel/Steel-X6CrNiTi18-10.FCMat
Resources/Materials/StandardMaterial/Metal/Titanium/Ti-6Al-4V.FCMat
Resources/Materials/StandardMaterial/Thermoplast/ABS-Generic.FCMat
Resources/Materials/StandardMaterial/Thermoplast/Acrylic-Glass-Generic.FCMat
Resources/Materials/StandardMaterial/Thermoplast/PA6-Generic.FCMat
Resources/Materials/StandardMaterial/Thermoplast/PET-Generic.FCMat
Resources/Materials/StandardMaterial/Thermoplast/PLA-Generic.FCMat
Resources/Materials/StandardMaterial/Thermoplast/PP-Generic.FCMat
Resources/Materials/StandardMaterial/Thermoplast/PTFE-Generic.FCMat
Resources/Materials/StandardMaterial/Thermoplast/PVC-Generic.FCMat
Resources/Materials/StandardMaterial/Wood/Wood-Generic.FCMat
Resources/Materials/Standard/Aggregate/Concrete-EN-C35_45.FCMat
Resources/Materials/Standard/Aggregate/Concrete-Generic.FCMat
Resources/Materials/Standard/Aggregate/Reinforcement-FIB-B500.FCMat
Resources/Materials/Standard/Carbon/Graphite.FCMat
Resources/Materials/Standard/Glass/Glass-E-GlassFibre.FCMat
Resources/Materials/Standard/Glass/Glass-Generic.FCMat
Resources/Materials/Standard/Glass/Glass-S2-GlassFibre.FCMat
Resources/Materials/Standard/Metal/Alloys/Invar-Generic.FCMat
Resources/Materials/Standard/Metal/Aluminum/AlMg3F24.FCMat
Resources/Materials/Standard/Metal/Aluminum/AlMgSi1F31.FCMat
Resources/Materials/Standard/Metal/Aluminum/Aluminum-6061-T6.FCMat
Resources/Materials/Standard/Metal/Aluminum/Aluminum-Generic.FCMat
Resources/Materials/Standard/Metal/Aluminum/AlZn4-5Mg1F35.FCMat
Resources/Materials/Standard/Metal/Copper/Copper-Generic.FCMat
Resources/Materials/Standard/Metal/Iron/Iron-Generic.FCMat
Resources/Materials/Standard/Metal/Steel/CalculiX-Steel.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-15CrNi6.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-17CrNiMo6.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-1C22.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-1C35.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-1C45.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-1C60.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-20NiCrMo2.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-28Mn6.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-2C10.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-30CrNiMo8.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-34CrNiMo6.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-36CrNiMo4.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-36NiCrMo16.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-3C15.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-3C22.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-3C35.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-3V45.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C10.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C15.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C22E.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C25E.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C30E.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C40E.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C50E.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C55E.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-C60E.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-E295-GC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-E295.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-E335-GC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-E335.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-E360-GC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-E360.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJL-100.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJL-150.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJL-200.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJL-250.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJL-300.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJL-350.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJMB-350-10.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJMB-550-4.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJMB-650-2.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJMW-350-4.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJMW-360-12.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJMW-400-5.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJMW-450-7.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJS-400-15.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJS-500-7.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJS-600-3.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJS-700-2.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-EN-GJS-800-1.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-G16Mn5.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-G200.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-G20Mn5.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-G230.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-G260.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-G300.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-G30Mn5.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-Generic.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S185.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S235JO.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S235JR.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S235JRG1.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S260NC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S275JO.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S275JR.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S275N.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S335JO.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S335JR.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S335N.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S340MC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S355J2G3.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S380MC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S420MC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S420N.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S460MC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S460N.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S500MC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S550MC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-S690MC.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-St-37-2K.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-St-E-255.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-St-E-315.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-St-E-380.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-St-E-460.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-St-E-500.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-X2CrNiMoN17-13-3.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-X2CrNiN24-4.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-X39CrMo17-1.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-X3CrNiMo13-14.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-X5CrNi18-10.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-X5CrNiMo17-12-2.FCMat
Resources/Materials/Standard/Metal/Steel/Steel-X6CrNiTi18-10.FCMat
Resources/Materials/Standard/Metal/Titanium/Ti-6Al-4V.FCMat
Resources/Materials/Standard/Thermoplast/ABS-Generic.FCMat
Resources/Materials/Standard/Thermoplast/Acrylic-Glass-Generic.FCMat
Resources/Materials/Standard/Thermoplast/PA6-Generic.FCMat
Resources/Materials/Standard/Thermoplast/PET-Generic.FCMat
Resources/Materials/Standard/Thermoplast/PLA-Generic.FCMat
Resources/Materials/Standard/Thermoplast/PP-Generic.FCMat
Resources/Materials/Standard/Thermoplast/PTFE-Generic.FCMat
Resources/Materials/Standard/Thermoplast/PVC-Generic.FCMat
Resources/Materials/Standard/Wood/Wood-Generic.FCMat
)
SET(FluidMaterial_Files
Resources/Materials/FluidMaterial/None.FCMat
Resources/Materials/FluidMaterial/Air.FCMat
Resources/Materials/FluidMaterial/Argon.FCMat
Resources/Materials/FluidMaterial/Carbon_dioxide.FCMat
Resources/Materials/FluidMaterial/Nitrogen.FCMat
Resources/Materials/FluidMaterial/Water.FCMat
Resources/Materials/Fluid/None.FCMat
Resources/Materials/Fluid/Air.FCMat
Resources/Materials/Fluid/Argon.FCMat
Resources/Materials/Fluid/Carbon_dioxide.FCMat
Resources/Materials/Fluid/Nitrogen.FCMat
Resources/Materials/Fluid/Water.FCMat
)
SET(AppearanceLib_Files
@@ -186,6 +186,10 @@ SET(AppearanceLib_Files
Resources/Materials/Appearance/Stone.FCMat
)
SET(MaterialTestLib_Files
"Resources/Materials/Test/Test Material.FCMat"
)
SET(MaterialModel_Files
Resources/Models/Architectural/Architectural.yml
Resources/Models/Costs/Costs.yml
@@ -202,6 +206,7 @@ SET(MaterialModel_Files
Resources/Models/Rendering/BasicRendering.yml
Resources/Models/Rendering/TextureRendering.yml
Resources/Models/Rendering/VectorRendering.yml
"Resources/Models/Test/Test Model.yml"
Resources/Models/Thermal/Thermal.yml
)
@@ -261,6 +266,9 @@ ADD_CUSTOM_TARGET(FluidMaterialLib ALL
ADD_CUSTOM_TARGET(AppearanceLib ALL
SOURCES ${AppearanceLib_Files}
)
ADD_CUSTOM_TARGET(MaterialTestLib ALL
SOURCES ${MaterialTestLib_Files}
)
ADD_CUSTOM_TARGET(MaterialModelLib ALL
SOURCES ${MaterialModel_Files}
)
@@ -279,6 +287,10 @@ fc_target_copy_resource(AppearanceLib
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Material/
${AppearanceLib_Files})
fc_target_copy_resource(MaterialTestLib
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Material/
${MaterialTestLib_Files})
fc_target_copy_resource(MaterialModelLib
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_BINARY_DIR}/${CMAKE_INSTALL_DATADIR}/Mod/Material/
@@ -294,7 +306,7 @@ INSTALL(
DESTINATION Mod/Material/materialtests
)
foreach(file ${MaterialLib_Files} ${FluidMaterial_Files} ${AppearanceLib_Files} ${MaterialModel_Files})
foreach(file ${MaterialLib_Files} ${FluidMaterial_Files} ${AppearanceLib_Files} ${MaterialTestLib_Files} ${MaterialModel_Files})
get_filename_component(filepath ${file} DIRECTORY)
INSTALL(
FILES ${file}

View File

@@ -56,8 +56,7 @@ public:
initialize("This module is the MatGui module."); // register with Python
}
~Module() override
{}
~Module() = default;
private:
};

View File

@@ -99,7 +99,7 @@ void Array2D::setupDefault()
try {
const Materials::MaterialProperty& column1 = _property->getColumn(0);
QString label = tr("Default ") + column1.getName();
QString label(tr("Default ") + column1.getName());
ui->labelDefault->setText(label);
if (column1.getPropertyType() == QString::fromStdString("Quantity")) {
ui->editDefault->setMinimum(std::numeric_limits<double>::min());

View File

@@ -26,6 +26,7 @@
#include <QDialog>
#include <QStandardItem>
#include <QTableView>
#include <Mod/Material/App/Materials.h>
namespace MatGui

View File

@@ -21,7 +21,6 @@
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QMessageBox>
#endif
#include <QMetaType>

View File

@@ -40,9 +40,11 @@ set(MatGui_UIC_SRCS
Array2D.ui
Array3D.ui
DlgSettingsMaterial.ui
ListEdit.ui
MaterialSave.ui
MaterialsEditor.ui
ModelSelect.ui
TextEdit.ui
)
SET(MatGui_SRCS
@@ -63,6 +65,11 @@ SET(MatGui_SRCS
DlgSettingsMaterial.cpp
DlgSettingsMaterial.h
DlgSettingsMaterial.ui
ListModel.cpp
ListModel.h
ListEdit.cpp
ListEdit.h
ListEdit.ui
MaterialDelegate.cpp
MaterialDelegate.h
MaterialSave.cpp
@@ -76,6 +83,9 @@ SET(MatGui_SRCS
ModelSelect.ui
PreCompiled.cpp
PreCompiled.h
TextEdit.cpp
TextEdit.h
TextEdit.ui
Workbench.cpp
Workbench.h
)
@@ -87,8 +97,10 @@ if(FREECAD_USE_PCH)
endif(FREECAD_USE_PCH)
SET(MatGuiIcon_SVG
Resources/icons/list.svg
Resources/icons/Materials_Edit.svg
Resources/icons/MaterialWorkbench.svg
Resources/icons/multiline.svg
Resources/icons/preferences-material.svg
Resources/icons/preview-rendered.svg
Resources/icons/preview-vector.svg

View File

@@ -0,0 +1,196 @@
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QMessageBox>
#endif
#include <QMenu>
#include <Gui/MainWindow.h>
#include <Mod/Material/App/Exceptions.h>
#include <Mod/Material/App/Materials.h>
#include "ArrayDelegate.h"
#include "ArrayModel.h"
#include "ListEdit.h"
#include "ListModel.h"
#include "ui_ListEdit.h"
using namespace MatGui;
/* TRANSLATOR MatGui::ListEdit */
ListEdit::ListEdit(const QString& propertyName,
std::shared_ptr<Materials::Material> material,
QWidget* parent)
: QDialog(parent)
, ui(new Ui_ListEdit)
, _material(material)
{
ui->setupUi(this);
if (material->hasPhysicalProperty(propertyName)) {
_property = material->getPhysicalProperty(propertyName);
}
else if (material->hasAppearanceProperty(propertyName)) {
_property = material->getAppearanceProperty(propertyName);
}
else {
Base::Console().Log("Property '%s' not found\n", propertyName.toStdString().c_str());
_property = nullptr;
}
if (_property) {
Base::Console().Log("Value type %d\n",
static_cast<int>(_property->getMaterialValue()->getType()));
_value = _property->getList();
}
else {
Base::Console().Log("No value loaded\n");
}
// if (_value) {
// Base::Console().Log("Value type %d\n", static_cast<int>(_value->getType()));
// }
setupListView();
// ui->listView->setContextMenuPolicy(Qt::CustomContextMenu);
// connect(ui->listView, &QWidget::customContextMenuRequested, this, &ListEdit::onContextMenu);
// _deleteAction.setText(tr("Delete row"));
// _deleteAction.setShortcut(Qt::Key_Delete);
// connect(&_deleteAction, &QAction::triggered, this, &ListEdit::onDelete);
// ui->listView->addAction(&_deleteAction);
connect(ui->standardButtons, &QDialogButtonBox::accepted, this, &ListEdit::accept);
connect(ui->standardButtons, &QDialogButtonBox::rejected, this, &ListEdit::reject);
}
void ListEdit::setColumnDelegates(QListView* list)
{
int length = _property->columns();
for (int i = 0; i < length; i++) {
const Materials::MaterialProperty& column = _property->getColumn(i);
list->setItemDelegateForColumn(
i,
new ArrayDelegate(column.getType(), column.getUnits(), this));
}
}
void ListEdit::setupListView()
{
if (_property == nullptr) {
return;
}
auto list = ui->listView;
auto model = new ListModel(_property, _value, this);
list->setModel(model);
// table->setEditTriggers(QAbstractItemView::AllEditTriggers);
list->setSelectionMode(QAbstractItemView::SingleSelection);
// setColumnWidths(list);
// setColumnDelegates(list);
connect(model, &QAbstractItemModel::dataChanged, this, &ListEdit::onDataChanged);
}
void ListEdit::onDataChanged(const QModelIndex& topLeft,
const QModelIndex& bottomRight,
const QVector<int>& roles)
{
Q_UNUSED(topLeft)
Q_UNUSED(bottomRight)
Q_UNUSED(roles)
_material->setEditStateAlter();
}
bool ListEdit::newRow(const QModelIndex& index)
{
ListModel* model = static_cast<ListModel*>(ui->listView->model());
return model->newRow(index);
}
void ListEdit::onDelete(bool checked)
{
Q_UNUSED(checked)
Base::Console().Log("ListEdit::onDelete()\n");
QItemSelectionModel* selectionModel = ui->listView->selectionModel();
if (!selectionModel->hasSelection() || newRow(selectionModel->currentIndex())) {
Base::Console().Log("\tNothing selected\n");
return;
}
int res = confirmDelete();
if (res == QMessageBox::Cancel) {
return;
}
}
int ListEdit::confirmDelete()
{
QMessageBox box(this);
box.setIcon(QMessageBox::Question);
box.setWindowTitle(QObject::tr("Confirm Delete"));
QString prompt = QObject::tr("Are you sure you want to delete the row?");
box.setText(prompt);
box.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
box.setDefaultButton(QMessageBox::Cancel);
box.setEscapeButton(QMessageBox::Cancel);
int res = QMessageBox::Cancel;
box.adjustSize(); // Silence warnings from Qt on Windows
switch (box.exec()) {
case QMessageBox::Ok:
deleteSelected();
res = QMessageBox::Ok;
break;
}
return res;
}
void ListEdit::deleteSelected()
{
ListModel* model = static_cast<ListModel*>(ui->listView->model());
QItemSelectionModel* selectionModel = ui->listView->selectionModel();
auto index = selectionModel->currentIndex();
model->deleteRow(index);
}
void ListEdit::accept()
{
_property->setList(_value);
QDialog::accept();
}
void ListEdit::reject()
{
QDialog::reject();
}
#include "moc_ListEdit.cpp"

View File

@@ -0,0 +1,82 @@
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef MATGUI_LISTEDIT_H
#define MATGUI_LISTEDIT_H
#include <memory>
#include <QAction>
#include <QDialog>
#include <QList>
#include <QListView>
#include <QPoint>
#include <QStandardItem>
#include <QStandardItemModel>
#include <Mod/Material/App/Model.h>
#include "ListModel.h"
namespace MatGui
{
class Ui_ListEdit;
class ListEdit: public QDialog
{
Q_OBJECT
public:
ListEdit(const QString& propertyName,
std::shared_ptr<Materials::Material> material,
QWidget* parent = nullptr);
~ListEdit() override = default;
void onDataChanged(const QModelIndex& topLeft,
const QModelIndex& bottomRight,
const QVector<int>& roles = QVector<int>());
void defaultValueChanged(const Base::Quantity& value);
void onDelete(bool checked);
void onContextMenu(const QPoint& pos);
void accept() override;
void reject() override;
private:
std::unique_ptr<Ui_ListEdit> ui;
std::shared_ptr<Materials::Material> _material;
std::shared_ptr<Materials::MaterialProperty> _property;
QList<QVariant> _value;
QAction _deleteAction;
void setColumnDelegates(QListView* list);
void setupListView();
bool newRow(const QModelIndex& index);
int confirmDelete();
void deleteSelected();
};
} // namespace MatGui
#endif // MATGUI_LISTEDIT_H

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MatGui::ListEdit</class>
<widget class="QDialog" name="MatGui::ListEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>List Edit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="listView"/>
</item>
<item>
<widget class="QDialogButtonBox" name="standardButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>standardButtons</sender>
<signal>accepted()</signal>
<receiver>MatGui::ListEdit</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>standardButtons</sender>
<signal>rejected()</signal>
<receiver>MatGui::ListEdit</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -0,0 +1,142 @@
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#endif
#include <QMetaType>
#include <Base/Console.h>
#include <Gui/MainWindow.h>
#include <Gui/MetaTypes.h>
#include <Mod/Material/App/Exceptions.h>
#include <Mod/Material/App/Materials.h>
#include "ListModel.h"
using namespace MatGui;
/* TRANSLATOR MatGui::ArrayModel */
ListModel::ListModel()
{}
ListModel::ListModel(std::shared_ptr<Materials::MaterialProperty> property,
QList<QVariant>& value,
QObject* parent)
: QAbstractListModel(parent)
, _property(property)
, _valuePtr(&value)
{}
int ListModel::rowCount(const QModelIndex& parent) const
{
if (parent.isValid()) {
return 0; // No children
}
return _valuePtr->size() + 1; // Will always have 1 empty row
}
bool ListModel::newRow(const QModelIndex& index) const
{
return (index.row() == _valuePtr->size());
}
void ListModel::deleteRow(const QModelIndex& index)
{
removeRows(index.row(), 1);
Q_EMIT dataChanged(index, index);
}
QVariant ListModel::data(const QModelIndex& index, int role) const
{
if (role == Qt::DisplayRole) {
if (index.row() < _valuePtr->size()) {
return _valuePtr->at(index.row());
}
}
return QVariant();
}
QVariant ListModel::headerData(int section, Qt::Orientation orientation, int role) const
{
// if (role == Qt::DisplayRole) {
// if (orientation == Qt::Horizontal) {
// const Materials::MaterialProperty& column = _property->getColumn(section);
// return QVariant(column.getName());
// }
// else if (orientation == Qt::Vertical) {
// // Vertical header
// if (section == (rowCount() - 1)) {
// return QVariant(QString::fromStdString("*"));
// }
// return QVariant(section + 1);
// }
// }
return QAbstractListModel::headerData(section, orientation, role);
}
bool ListModel::setData(const QModelIndex& index, const QVariant& value, int role)
{
Q_UNUSED(role);
if (index.row() == _valuePtr->size()) {
insertRows(index.row(), 1);
}
(*_valuePtr)[index.row()] = value;
Q_EMIT dataChanged(index, index);
return true;
}
Qt::ItemFlags ListModel::flags(const QModelIndex& index) const
{
return (QAbstractListModel::flags(index) | Qt::ItemIsEditable);
}
// Resizing functions
bool ListModel::insertRows(int row, int count, const QModelIndex& parent)
{
beginInsertRows(parent, row, row + count - 1);
QVariant newRow = QString();
_valuePtr->insert(row, newRow);
endInsertRows();
return false;
}
bool ListModel::removeRows(int row, int count, const QModelIndex& parent)
{
beginRemoveRows(parent, row, row + count - 1);
_valuePtr->removeAt(row);
return false;
}

View File

@@ -0,0 +1,69 @@
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef MATGUI_LISTMODEL_H
#define MATGUI_LISTMODEL_H
#include <memory>
#include <QAbstractListModel>
#include <QDialog>
#include <QList>
#include <QStandardItem>
#include <QVariant>
#include <Mod/Material/App/Materials.h>
#include <Mod/Material/App/Model.h>
namespace MatGui
{
class ListModel: public QAbstractListModel
{
public:
ListModel();
ListModel(std::shared_ptr<Materials::MaterialProperty> property,
QList<QVariant>& value,
QObject* parent = nullptr);
~ListModel() override = default;
// Overridden virtual functions
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
bool newRow(const QModelIndex& index) const;
void deleteRow(const QModelIndex& index);
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
QVariant
headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
// Resizing functions
bool insertRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
bool removeRows(int row, int count, const QModelIndex& parent = QModelIndex()) override;
private:
std::shared_ptr<Materials::MaterialProperty> _property;
QList<QVariant>* _valuePtr;
};
} // namespace MatGui
#endif // MATGUI_LISTMODEL_H

View File

@@ -49,8 +49,10 @@
#include "Array2D.h"
#include "Array3D.h"
#include "ListEdit.h"
#include "MaterialDelegate.h"
#include "MaterialSave.h"
#include "TextEdit.h"
using namespace MatGui;
@@ -92,6 +94,18 @@ bool MaterialDelegate::editorEvent(QEvent* event,
// Mark as handled
return true;
}
else if (type == "MultiLineString") {
Base::Console().Log("Edit List\n");
showMultiLineString(propertyName, item);
// Mark as handled
return true;
}
else if (type == "List") {
Base::Console().Log("Edit List\n");
showListModal(propertyName, item);
// Mark as handled
return true;
}
else if (type == "2DArray") {
Base::Console().Log("Edit 2DArray\n");
showArray2DModal(propertyName, item);
@@ -145,6 +159,43 @@ void MaterialDelegate::showColorModal(QStandardItem* item, QString propertyName)
dlg->exec();
}
void MaterialDelegate::showListModal(const QString& propertyName, QStandardItem* item)
{
auto material = item->data().value<std::shared_ptr<Materials::Material>>();
auto dlg = new ListEdit(propertyName, material);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->adjustSize();
connect(dlg, &QDialog::finished, this, [&](int result) {
if (result == QDialog::Accepted) {
Base::Console().Log("Accepted\n");
}
});
dlg->exec();
}
void MaterialDelegate::showMultiLineString(const QString& propertyName, QStandardItem* item)
{
auto material = item->data().value<std::shared_ptr<Materials::Material>>();
TextEdit* dlg = new TextEdit(propertyName, material);
dlg->setAttribute(Qt::WA_DeleteOnClose);
dlg->adjustSize();
connect(dlg, &QDialog::finished, this, [&](int result) {
if (result == QDialog::Accepted) {
Base::Console().Log("Accepted\n");
}
});
dlg->exec();
}
void MaterialDelegate::showArray2DModal(const QString& propertyName, QStandardItem* item)
{
auto material = item->data().value<std::shared_ptr<Materials::Material>>();
@@ -234,6 +285,38 @@ void MaterialDelegate::paint(QPainter* painter,
painter->restore();
return;
}
else if (type == "MultiLineString") {
painter->save();
QImage table(QString::fromStdString(":/icons/multiline.svg"));
QRect target(option.rect);
if (target.width() > target.height()) {
target.setWidth(target.height());
}
else {
target.setHeight(target.width());
}
painter->drawImage(target, table, table.rect());
painter->restore();
return;
}
else if (type == "List") {
painter->save();
QImage table(QString::fromStdString(":/icons/list.svg"));
QRect target(option.rect);
if (target.width() > target.height()) {
target.setWidth(target.height());
}
else {
target.setHeight(target.width());
}
painter->drawImage(target, table, table.rect());
painter->restore();
return;
}
else if (type == "2DArray" || type == "3DArray") {
// painter->save();
@@ -280,7 +363,8 @@ QSize MaterialDelegate::sizeHint(const QStyleOptionViewItem& option, const QMode
if (type == "Color") {
return QSize(75, 23); // Standard QPushButton size
}
else if (type == "2DArray" || type == "3DArray") {
else if (type == "2DArray" || type == "3DArray" || type == "MultiLineString"
|| type == "List") {
return QSize(23, 23);
}
@@ -387,14 +471,14 @@ QWidget* MaterialDelegate::createWidget(QWidget* parent,
QWidget* widget = nullptr;
std::string type = propertyType.toStdString();
if (type == "String" || type == "URL" || type == "Vector") {
if (type == "String" || type == "URL" || type == "List") {
widget = new Gui::PrefLineEdit(parent);
}
else if ((type == "Integer") || (type == "Int")) {
Gui::UIntSpinBox* spinner = new Gui::UIntSpinBox(parent);
Gui::IntSpinBox* spinner = new Gui::IntSpinBox(parent);
spinner->setMinimum(0);
spinner->setMaximum(UINT_MAX);
spinner->setValue(propertyValue.toUInt());
spinner->setMaximum(INT_MAX);
spinner->setValue(propertyValue.toInt());
widget = spinner;
}
else if (type == "Float") {

View File

@@ -73,6 +73,8 @@ private:
const QString& propertyUnits) const;
QRgb parseColor(const QString& color) const;
void showColorModal(QStandardItem* item, QString propertyName);
void showListModal(const QString& propertyName, QStandardItem* item);
void showMultiLineString(const QString& propertyName, QStandardItem* item);
void showArray2DModal(const QString& propertyName, QStandardItem* item);
void showArray3DModal(const QString& propertyName, QStandardItem* item);
};

View File

@@ -287,7 +287,7 @@ void MaterialSave::reject()
void MaterialSave::setLibraries()
{
auto libraries = _manager.getMaterialLibraries();
for (auto library : *libraries) {
for (auto& library : *libraries) {
if (!library->isReadOnly()) {
QVariant libraryVariant;
libraryVariant.setValue(library);
@@ -345,7 +345,6 @@ void MaterialSave::addMaterials(
node->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled
| Qt::ItemIsDropEnabled | Qt::ItemIsEditable);
addExpanded(tree, &parent, node);
auto treeMap = nodePtr->getFolder();
addMaterials(*node, treeMap, folderIcon, icon);
}

View File

@@ -77,6 +77,14 @@ MaterialsEditor::MaterialsEditor(QWidget* parent)
createPreviews();
setMaterialDefaults();
// Reset to previous size
auto param = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Material/Editor");
auto width = param->GetInt("EditorWidth", 835);
auto height = param->GetInt("EditorHeight", 542);
resize(width, height);
ui->buttonURL->setIcon(QIcon(QString::fromStdString(":/icons/internet-web-browser.svg")));
connect(ui->standardButtons->button(QDialogButtonBox::Ok),
@@ -166,7 +174,7 @@ void MaterialsEditor::saveFavorites()
// Add the current values
param->SetInt("Favorites", _favorites.size());
int j = 0;
for (auto favorite : _favorites) {
for (auto& favorite : _favorites) {
QString key = QString::fromLatin1("FAV%1").arg(j);
param->SetASCII(key.toStdString().c_str(), favorite.toStdString());
@@ -203,7 +211,7 @@ void MaterialsEditor::removeFavorite(const QString& uuid)
bool MaterialsEditor::isFavorite(const QString& uuid) const
{
for (auto it : _favorites) {
for (auto& it : _favorites) {
if (it == uuid) {
return true;
}
@@ -246,7 +254,7 @@ void MaterialsEditor::saveRecents()
}
param->SetInt("Recent", size);
int j = 0;
for (auto recent : _recents) {
for (auto& recent : _recents) {
QString key = QString::fromLatin1("MRU%1").arg(j);
param->SetASCII(key.toStdString().c_str(), recent.toStdString());
@@ -283,7 +291,7 @@ void MaterialsEditor::addRecent(const QString& uuid)
bool MaterialsEditor::isRecent(const QString& uuid) const
{
for (auto it : _recents) {
for (auto& it : _recents) {
if (it == uuid) {
return true;
}
@@ -546,14 +554,42 @@ void MaterialsEditor::saveMaterial()
void MaterialsEditor::accept()
{
addRecent(_material->getUUID());
saveWindow();
QDialog::accept();
}
void MaterialsEditor::reject()
{
saveWindow();
QDialog::reject();
}
void MaterialsEditor::saveWindow()
{
auto param = App::GetApplication().GetParameterGroupByPath(
"User parameter:BaseApp/Preferences/Mod/Material/Editor");
param->SetInt("EditorWidth", width());
param->SetInt("EditorHeight", height());
// int count = param->GetInt("Favorites", 0);
// for (int i = 0; i < count; i++) {
// QString key = QString::fromLatin1("FAV%1").arg(i);
// QString uuid = QString::fromStdString(param->GetASCII(key.toStdString().c_str(), ""));
// _favorites.push_back(uuid);
// }
}
// def storeSize(self):
// "stores the widget size"
// #store widths
// p = FreeCAD.ParamGet("User parameter:BaseApp/Preferences/Mod/Material")
// p.SetInt("MaterialEditorWidth", self.widget.width())
// p.SetInt("MaterialEditorHeight", self.widget.height())
// root = self.widget.treeView.model().invisibleRootItem()
// for gg in range(root.rowCount()):
// group = root.child(gg)
// p.SetBool("TreeExpand"+group.text(), self.widget.treeView.isExpanded(group.index()))
// QIcon MaterialsEditor::errorIcon(const QIcon &icon) const {
// auto pixmap = icon.pixmap();
// }
@@ -631,7 +667,6 @@ void MaterialsEditor::createPhysicalTree()
// connect(selectionModel,
// &QItemSelectionModel::selectionChanged,
// this,
// &MaterialsEditor::onSelectPhysicalProperty);
}
void MaterialsEditor::createPreviews()

View File

@@ -106,6 +106,8 @@ private:
std::list<QString> _recents;
int _recentMax;
void saveWindow();
void getFavorites();
void saveFavorites();
void addFavorite(const QString& uuid);

View File

@@ -104,7 +104,7 @@ void ModelSelect::saveFavorites()
// Add the current values
param->SetInt("Favorites", _favorites.size());
int j = 0;
for (auto favorite : _favorites) {
for (auto& favorite : _favorites) {
QString key = QString::fromLatin1("FAV%1").arg(j);
param->SetASCII(key.toStdString().c_str(), favorite.toStdString());
@@ -132,7 +132,7 @@ void ModelSelect::removeFavorite(const QString& uuid)
bool ModelSelect::isFavorite(const QString& uuid) const
{
for (auto it : _favorites) {
for (auto& it : _favorites) {
if (it == uuid) {
return true;
}
@@ -175,7 +175,7 @@ void ModelSelect::saveRecents()
}
param->SetInt("Recent", size);
int j = 0;
for (auto recent : _recents) {
for (auto& recent : _recents) {
QString key = QString::fromLatin1("MRU%1").arg(j);
param->SetASCII(key.toStdString().c_str(), recent.toStdString());
@@ -203,7 +203,7 @@ void ModelSelect::addRecent(const QString& uuid)
bool ModelSelect::isRecent(const QString& uuid) const
{
for (auto it : _recents) {
for (auto& it : _recents) {
if (it == uuid) {
return true;
}
@@ -340,7 +340,7 @@ void ModelSelect::fillTree()
addRecents(lib);
auto libraries = getModelManager().getModelLibraries();
for (auto library : *libraries) {
for (auto& library : *libraries) {
lib = new QStandardItem(library->getName());
lib->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
addExpanded(tree, model, lib);

View File

@@ -1,7 +1,9 @@
<RCC>
<qresource>
<file>icons/list.svg</file>
<file>icons/MaterialWorkbench.svg</file>
<file>icons/Materials_Edit.svg</file>
<file>icons/multiline.svg</file>
<file>icons/preferences-material.svg</file>
<file>icons/preview-rendered.svg</file>
<file>icons/preview-vector.svg</file>

View File

@@ -0,0 +1,68 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="64"
height="64"
viewBox="0 0 16.933333 16.933333"
version="1.1"
id="svg5"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs2">
<linearGradient
id="linearGradient992">
<stop
style="stop-color:#ff0000;stop-opacity:1;"
offset="0"
id="stop990" />
</linearGradient>
</defs>
<g
id="g7308">
<rect
style="fill:none;stroke:#000000;stroke-width:0.529167;stroke-dasharray:none;stroke-opacity:1"
id="rect434"
width="14.684375"
height="14.122135"
x="1.1244792"
y="1.3559896" />
<path
style="fill:none;stroke:#0000ff;stroke-width:0.834455;stroke-dasharray:none;stroke-opacity:1"
d="m 12.353105,3.987194 -0.007,9.255733 v 0"
id="path2181-5-5-7" />
<path
style="fill:#00ffff;fill-opacity:1;stroke:#0000ff;stroke-width:0.834456;stroke-dasharray:none;stroke-opacity:1"
d="m 4.389357,3.9624617 -0.00702,9.2557323 v 0"
id="path2181-5-5-7-3" />
<rect
style="fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.529167;stroke-opacity:1"
id="rect5783"
width="2.8689387"
height="0.29678676"
x="9.6455698"
y="4.2539434" />
<rect
style="fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.529167;stroke-opacity:1"
id="rect5783-0"
width="2.8689387"
height="0.29678676"
x="4.2704315"
y="4.2209668" />
<rect
style="fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.529167;stroke-opacity:1"
id="rect5783-8"
width="2.8689387"
height="0.29678676"
x="4.2209673"
y="12.662901" />
<rect
style="fill:none;fill-opacity:1;stroke:#0000ff;stroke-width:0.529167;stroke-opacity:1"
id="rect5783-06"
width="2.8689387"
height="0.29678676"
x="9.6455688"
y="12.695878" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
width="64"
height="64"
viewBox="0 0 16.933333 16.933333"
version="1.1"
id="svg5"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg">
<defs
id="defs2">
<linearGradient
id="linearGradient992">
<stop
style="stop-color:#ff0000;stop-opacity:1;"
offset="0"
id="stop990" />
</linearGradient>
</defs>
<g
id="g299">
<rect
style="fill:none;stroke:#000000;stroke-width:0.529167;stroke-dasharray:none;stroke-opacity:1"
id="rect434"
width="14.684375"
height="14.122135"
x="1.1244792"
y="1.3559896" />
<path
style="fill:none;stroke:#000000;stroke-width:0.982451;stroke-dasharray:none;stroke-opacity:1"
d="M 1.9182291,7.3752603 H 14.344339 v 0"
id="path2181" />
<path
style="fill:none;stroke:#000000;stroke-width:0.785398;stroke-dasharray:none;stroke-opacity:1"
d="m 1.8800515,4.7867171 h 7.9413322 v 0"
id="path2181-5" />
<path
style="fill:none;stroke:#000000;stroke-width:0.855638;stroke-dasharray:none;stroke-opacity:1"
d="m 1.9099611,12.567709 h 9.4252659 v 0"
id="path2181-2" />
<path
style="fill:none;stroke:#000000;stroke-width:0.878532;stroke-dasharray:none;stroke-opacity:1"
d="M 1.8935214,10.021094 H 11.82992 v 0"
id="path2181-46" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

View File

@@ -0,0 +1,94 @@
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#include "PreCompiled.h"
#ifndef _PreComp_
#include <QMessageBox>
#endif
#include <QMenu>
#include <Gui/MainWindow.h>
#include <Mod/Material/App/Exceptions.h>
#include <Mod/Material/App/Materials.h>
#include "TextEdit.h"
#include "ui_TextEdit.h"
using namespace MatGui;
/* TRANSLATOR MatGui::TextEdit */
TextEdit::TextEdit(const QString& propertyName,
std::shared_ptr<Materials::Material> material,
QWidget* parent)
: QDialog(parent)
, ui(new Ui_TextEdit)
, _material(material)
{
ui->setupUi(this);
if (material->hasPhysicalProperty(propertyName)) {
_property = material->getPhysicalProperty(propertyName);
}
else if (material->hasAppearanceProperty(propertyName)) {
_property = material->getAppearanceProperty(propertyName);
}
else {
Base::Console().Log("Property '%s' not found\n", propertyName.toStdString().c_str());
_property = nullptr;
}
if (_property) {
Base::Console().Log("Value type %d\n",
static_cast<int>(_property->getMaterialValue()->getType()));
_value = _property->getString();
}
else {
Base::Console().Log("No value loaded\n");
_value = QString();
}
ui->textEdit->setText(_value);
ui->textEdit->setAcceptRichText(false);
ui->textEdit->setWordWrapMode(QTextOption::NoWrap);
connect(ui->standardButtons, &QDialogButtonBox::accepted, this, &TextEdit::accept);
connect(ui->standardButtons, &QDialogButtonBox::rejected, this, &TextEdit::reject);
}
void TextEdit::accept()
{
QString newText = ui->textEdit->toPlainText();
if (newText != _value) {
_property->setValue(ui->textEdit->toPlainText());
_material->setEditStateAlter();
}
QDialog::accept();
}
void TextEdit::reject()
{
QDialog::reject();
}
#include "moc_TextEdit.cpp"

View File

@@ -0,0 +1,66 @@
/***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef MATGUI_TEXTEDIT_H
#define MATGUI_TEXTEDIT_H
#include <memory>
#include <QAbstractTableModel>
#include <QAction>
#include <QDialog>
#include <QPoint>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QTableView>
#include <Mod/Material/App/Model.h>
#include "ArrayModel.h"
namespace MatGui
{
class Ui_TextEdit;
class TextEdit: public QDialog
{
Q_OBJECT
public:
TextEdit(const QString& propertyName,
std::shared_ptr<Materials::Material> material,
QWidget* parent = nullptr);
~TextEdit() override = default;
void accept() override;
void reject() override;
private:
std::unique_ptr<Ui_TextEdit> ui;
std::shared_ptr<Materials::Material> _material;
std::shared_ptr<Materials::MaterialProperty> _property;
QString _value;
};
} // namespace MatGui
#endif // MATGUI_TEXTEDIT_H

View File

@@ -0,0 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MatGui::TextEdit</class>
<widget class="QDialog" name="MatGui::TextEdit">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Text Edit</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTextEdit" name="textEdit"/>
</item>
<item>
<widget class="QDialogButtonBox" name="standardButtons">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>standardButtons</sender>
<signal>accepted()</signal>
<receiver>MatGui::TextEdit</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>standardButtons</sender>
<signal>rejected()</signal>
<receiver>MatGui::TextEdit</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "d1f317f0-5ffa-4798-8ab3-af2ff0b5182c"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "4151e19c-fd6a-4ca4-83d4-d5e17d76cb9c"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "ae194589-02d4-4e9b-98a7-f523f660d510"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a9544b88-dde7-4d05-9bdb-c008a4e88dc1"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "524cad9b-b841-4037-9851-badeca7dcee2"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "5dbb7be6-8b63-479b-ab4c-87be02ead973"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "54def35f-a6bf-472e-8410-dc9fb4b143cf"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "85257e2c-be3f-40a1-b03f-0bd4ba58ca08"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "cddfa21f-0715-49dd-b35b-951c076fa52c"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "d149a177-07f1-4e53-9bad-0b5bf0663600"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "c0341eef-0897-4fcf-a7f7-eddf1a2600a5"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "add2d6b2-c8fb-4777-a80a-52bae97300ae"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a004c270-7d2c-4898-bec6-b1120edacea9"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a61853b9-ec9f-403e-9726-0a938731aecd"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "569dccb6-c64b-4dd0-9d3c-1b78f40ad1a5"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a74622cd-0e2d-4a96-b8c4-fefcc82ac694"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "953261a0-cc48-41f8-a3f9-7b20ae3f9b56"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "951b54ae-86b6-46d2-b452-60bd6a3ba1bb"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "591c4c4a-22ba-4a9a-869d-e5610107d69a"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "62839fb0-d854-4b44-92df-b7249213de49"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "4b849c55-6b3a-4f75-a055-40c0d0324596"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a9f54d61-cc98-46df-8734-b0543ceb4e45"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "94370b96-c97e-4a3f-83b2-11d7461f7da7"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "e359c5b5-eae2-42b1-9ef6-edde21d706ee"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "ef0e4040-a498-48c3-a87b-e996bfd89195"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "8d02a797-5e0a-4e40-803a-75fc66de8de6"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "944a8018-09bf-48f6-a7b3-aa8f6a00a310"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "7e5559d5-be15-4571-a72f-20c39edd41cf"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "dba76940-a910-4a3b-ab73-a9f412ac69d9"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "26042aa5-56e6-4d99-8b63-dd8b9ea5a37a"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "57507cd4-d22f-4d86-9794-fdb1ec8cd098"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "5c67b675-69a2-4782-902a-bb90c3952f07"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a02bf9d7-6e3e-4e36-881b-10779ee9f706"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "3e3a3e13-04a4-410e-8e36-bbd83ca66847"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "0c4943e0-248b-4df9-88d9-3b4dd84dfc68"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "27745e16-2a10-4c8e-bd22-59971806909c"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "0051bddf-6f62-4406-b8c9-569322880564"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "460e02a3-b6cd-4662-b2f6-8c9d44146c66"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "05f8f1b2-b92b-4e41-8de9-1e064e78a165"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "68b152b2-fd5e-4f10-8db0-1a2df3fe0fda"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "9bf060e9-1663-44a2-88e2-2ff6ee858efe"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "6c03899d-496e-4c60-a41b-3d66f2337fb9"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "1826c364-d26a-43fb-8f61-288281236836"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "92589471-a6cb-4bbc-b748-d425a17dea7d"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "6822df30-db32-4a68-a8d7-aaddcb9649d1"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "e4c76f15-00af-4498-ac57-beaf49c150e9"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "c424fe3d-5f49-4c39-9467-8a2a800076aa"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "cd932bad-4085-459f-aea6-1da737ae38ae"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "958b7a5c-4764-4a2f-a450-2153a41fb5ec"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "9717f953-1cfc-41a6-8974-3ad45188ad48"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "1c759697-7aef-4a14-92c5-5bf84b99a4f0"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "6894c597-5771-4b56-825f-ce7d5e4689f4"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a7be39a1-1686-4fee-a1d5-81ef73b82d16"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "a6d96264-affc-4406-9816-75099c1fa0d9"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "e69448d5-2517-4c00-9e70-ebeb11ca017f"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "3e78b767-5530-4d69-a541-cf33a5a2ad19"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "3fdf729c-bec4-4bfa-ba94-b0c9e51a2040"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "605fd7b6-caa3-400d-b6d7-ed52c0f5da21"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "7313f076-faf4-41dd-8dae-1b9a586990dc"

View File

@@ -1,3 +1,4 @@
---
# File created by ConvertFCMat.py
General:
UUID: "251cc54e-4a5a-4cd3-9c9e-006c416d7ce9"

Some files were not shown because too many files have changed in this diff Show More