Materials: Pass by reference instead of pointers

Refactoring topass by reference instead of using existing pointers.
This commit is contained in:
David Carter
2025-05-29 10:22:58 -04:00
committed by Chris Hennes
parent 670a85de97
commit db1b5a8773
28 changed files with 211 additions and 238 deletions

View File

@@ -519,7 +519,7 @@ ExternalManager::libraryMaterials(const QString& libraryName)
std::shared_ptr<std::vector<LibraryObject>>
ExternalManager::libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options)
{
auto materialList = std::make_shared<std::vector<LibraryObject>>();
@@ -532,13 +532,7 @@ ExternalManager::libraryMaterials(const QString& libraryName,
Py::Callable libraries(_managerObject.getAttr("libraryMaterials"));
Py::Tuple args(3);
args.setItem(0, Py::String(libraryName.toStdString()));
if (filter) {
args.setItem(1,
Py::Object(new MaterialFilterPy(new MaterialFilter(*filter)), true));
}
else {
args.setItem(1, Py::None());
}
args.setItem(1, Py::Object(new MaterialFilterPy(new MaterialFilter(filter)), true));
args.setItem(
2,
Py::Object(new MaterialFilterOptionsPy(new MaterialFilterOptions(options)), true));
@@ -750,7 +744,7 @@ std::shared_ptr<Model> ExternalManager::getModel(const QString& uuid)
void ExternalManager::addModel(const QString& libraryName,
const QString& path,
const std::shared_ptr<Model>& model)
const Model& model)
{
connect();
@@ -761,7 +755,7 @@ void ExternalManager::addModel(const QString& libraryName,
Py::Tuple args(3);
args.setItem(0, Py::String(libraryName.toStdString()));
args.setItem(1, Py::String(path.toStdString()));
args.setItem(2, Py::Object(new ModelPy(new Model(*model)), true));
args.setItem(2, Py::Object(new ModelPy(new Model(model)), true));
libraries.apply(args); // No return expected
}
else {
@@ -777,7 +771,7 @@ void ExternalManager::addModel(const QString& libraryName,
void ExternalManager::migrateModel(const QString& libraryName,
const QString& path,
const std::shared_ptr<Model>& model)
const Model& model)
{
connect();
@@ -788,7 +782,7 @@ void ExternalManager::migrateModel(const QString& libraryName,
Py::Tuple args(3);
args.setItem(0, Py::String(libraryName.toStdString()));
args.setItem(1, Py::String(path.toStdString()));
args.setItem(2, Py::Object(new ModelPy(new Model(*model)), true));
args.setItem(2, Py::Object(new ModelPy(new Model(model)), true));
libraries.apply(args); // No return expected
}
else {
@@ -804,7 +798,7 @@ void ExternalManager::migrateModel(const QString& libraryName,
void ExternalManager::updateModel(const QString& libraryName,
const QString& path,
const std::shared_ptr<Model>& model)
const Model& model)
{
connect();
@@ -815,7 +809,7 @@ void ExternalManager::updateModel(const QString& libraryName,
Py::Tuple args(3);
args.setItem(0, Py::String(libraryName.toStdString()));
args.setItem(1, Py::String(path.toStdString()));
args.setItem(2, Py::Object(new ModelPy(new Model(*model)), true));
args.setItem(2, Py::Object(new ModelPy(new Model(model)), true));
libraries.apply(args); // No return expected
}
else {
@@ -999,7 +993,7 @@ std::shared_ptr<Material> ExternalManager::getMaterial(const QString& uuid)
void ExternalManager::addMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material)
const Material& material)
{
connect();
@@ -1010,7 +1004,7 @@ void ExternalManager::addMaterial(const QString& libraryName,
Py::Tuple args(3);
args.setItem(0, Py::String(libraryName.toStdString()));
args.setItem(1, Py::String(path.toStdString()));
args.setItem(2, Py::Object(new MaterialPy(new Material(*material)), true));
args.setItem(2, Py::Object(new MaterialPy(new Material(material)), true));
libraries.apply(args); // No return expected
}
else {
@@ -1026,7 +1020,7 @@ void ExternalManager::addMaterial(const QString& libraryName,
void ExternalManager::migrateMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material)
const Material& material)
{
connect();
@@ -1037,7 +1031,7 @@ void ExternalManager::migrateMaterial(const QString& libraryName,
Py::Tuple args(3);
args.setItem(0, Py::String(libraryName.toStdString()));
args.setItem(1, Py::String(path.toStdString()));
auto mat = new Material(*material);
auto mat = new Material(material);
args.setItem(2, Py::Object(new MaterialPy(mat), true));
libraries.apply(args); // No return expected
}
@@ -1054,7 +1048,7 @@ void ExternalManager::migrateMaterial(const QString& libraryName,
void ExternalManager::updateMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material)
const Material& material)
{
connect();
@@ -1065,7 +1059,7 @@ void ExternalManager::updateMaterial(const QString& libraryName,
Py::Tuple args(3);
args.setItem(0, Py::String(libraryName.toStdString()));
args.setItem(1, Py::String(path.toStdString()));
args.setItem(2, Py::Object(new MaterialPy(new Material(*material)), true));
args.setItem(2, Py::Object(new MaterialPy(new Material(material)), true));
libraries.apply(args); // No return expected
}
else {

View File

@@ -65,7 +65,7 @@ public:
std::shared_ptr<std::vector<LibraryObject>> libraryMaterials(const QString& libraryName);
std::shared_ptr<std::vector<LibraryObject>>
libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options);
std::shared_ptr<std::vector<QString>> libraryFolders(const QString& libraryName);
@@ -79,12 +79,12 @@ public:
// Model management
std::shared_ptr<Model> getModel(const QString& uuid);
void
addModel(const QString& libraryName, const QString& path, const std::shared_ptr<Model>& model);
addModel(const QString& libraryName, const QString& path, const Model& model);
void
migrateModel(const QString& libraryName, const QString& path, const std::shared_ptr<Model>& model);
migrateModel(const QString& libraryName, const QString& path, const Model& model);
void updateModel(const QString& libraryName,
const QString& path,
const std::shared_ptr<Model>& model);
const Model& model);
void setModelPath(const QString& libraryName, const QString& path, const QString& uuid);
void renameModel(const QString& libraryName, const QString& name, const QString& uuid);
void moveModel(const QString& libraryName, const QString& path, const QString& uuid);
@@ -94,13 +94,13 @@ public:
std::shared_ptr<Material> getMaterial(const QString& uuid);
void addMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material);
const Material& material);
void migrateMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material);
const Material& material);
void updateMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material);
const Material& material);
void setMaterialPath(const QString& libraryName, const QString& path, const QString& uuid);
void renameMaterial(const QString& libraryName, const QString& name, const QString& uuid);
void moveMaterial(const QString& libraryName, const QString& path, const QString& uuid);

View File

@@ -68,25 +68,25 @@ MaterialFilter::MaterialFilter()
, _requireAppearance(false)
{}
bool MaterialFilter::modelIncluded(const std::shared_ptr<Material>& material) const
bool MaterialFilter::modelIncluded(const Material& material) const
{
if (_requirePhysical) {
if (!material->hasPhysicalProperties()) {
if (!material.hasPhysicalProperties()) {
return false;
}
}
if (_requireAppearance) {
if (!material->hasAppearanceProperties()) {
if (!material.hasAppearanceProperties()) {
return false;
}
}
for (const auto& complete : _requiredComplete) {
if (!material->isModelComplete(complete)) {
if (!material.isModelComplete(complete)) {
return false;
}
}
for (const auto& required : _required) {
if (!material->hasModel(required)) {
if (!material.hasModel(required)) {
return false;
}
}
@@ -98,7 +98,7 @@ bool MaterialFilter::modelIncluded(const QString& uuid) const
{
try {
auto material = MaterialManager::getManager().getMaterial(uuid);
return modelIncluded(material);
return modelIncluded(*material);
}
catch (const MaterialNotFound&) {
}

View File

@@ -164,7 +164,7 @@ public:
*
* Models only need to be included in one set.
*/
bool modelIncluded(const std::shared_ptr<Material>& material) const;
bool modelIncluded(const Material& material) const;
bool modelIncluded(const QString& uuid) const;
/* Add model UUIDs for required models, or models that are both required

View File

@@ -59,7 +59,7 @@ MaterialLibrary::MaterialLibrary(const Library& library)
{}
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
MaterialLibrary::getMaterialTree(const std::shared_ptr<Materials::MaterialFilter>& filter,
MaterialLibrary::getMaterialTree(const Materials::MaterialFilter& filter,
const Materials::MaterialFilterOptions& options) const
{
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>> materialTree =

View File

@@ -62,7 +62,7 @@ public:
~MaterialLibrary() override = default;
virtual std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
getMaterialTree(const std::shared_ptr<Materials::MaterialFilter>& filter,
getMaterialTree(const Materials::MaterialFilter& filter,
const Materials::MaterialFilterOptions& options) const;
// Use this to get a shared_ptr for *this

View File

@@ -344,7 +344,7 @@ MaterialManager::libraryMaterials(const QString& libraryName, bool local)
std::shared_ptr<std::vector<LibraryObject>>
MaterialManager::libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options,
bool local)
{
@@ -415,7 +415,7 @@ void MaterialManager::createFolder(const std::shared_ptr<MaterialLibrary>& libra
}
#if defined(BUILD_MATERIAL_EXTERNAL)
else if (_useExternal) {
_externalManager->createFolder(library, path);
_externalManager->createFolder(*library, path);
}
else {
throw Materials::CreationError("External materials are not enabled");
@@ -435,7 +435,7 @@ void MaterialManager::renameFolder(const std::shared_ptr<MaterialLibrary>& libra
}
#if defined(BUILD_MATERIAL_EXTERNAL)
else if (_useExternal) {
_externalManager->renameFolder(library, oldPath, newPath);
_externalManager->renameFolder(*library, oldPath, newPath);
}
else {
throw Materials::RenameError("External materials are not enabled");
@@ -454,7 +454,7 @@ void MaterialManager::deleteRecursive(const std::shared_ptr<MaterialLibrary>& li
}
#if defined(BUILD_MATERIAL_EXTERNAL)
else if (_useExternal) {
_externalManager->deleteRecursive(library, path);
_externalManager->deleteRecursive(*library, path);
}
else {
throw Materials::DeleteError("External materials are not enabled");
@@ -469,27 +469,27 @@ void MaterialManager::deleteRecursive(const std::shared_ptr<MaterialLibrary>& li
//=====
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
MaterialManager::getMaterialTree(const std::shared_ptr<MaterialLibrary>& library,
const std::shared_ptr<Materials::MaterialFilter>& filter) const
MaterialManager::getMaterialTree(const MaterialLibrary& library,
const Materials::MaterialFilter& filter) const
{
MaterialFilterOptions options;
return library->getMaterialTree(filter, options);
return library.getMaterialTree(filter, options);
}
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
MaterialManager::getMaterialTree(const std::shared_ptr<MaterialLibrary>& library,
const std::shared_ptr<Materials::MaterialFilter>& filter,
MaterialManager::getMaterialTree(const MaterialLibrary& library,
const Materials::MaterialFilter& filter,
const MaterialFilterOptions& options) const
{
return library->getMaterialTree(filter, options);
return library.getMaterialTree(filter, options);
}
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
MaterialManager::getMaterialTree(const std::shared_ptr<MaterialLibrary>& library) const
MaterialManager::getMaterialTree(const MaterialLibrary& library) const
{
std::shared_ptr<Materials::MaterialFilter> filter;
Materials::MaterialFilter filter;
MaterialFilterOptions options;
return library->getMaterialTree(filter, options);
return library.getMaterialTree(filter, options);
}
//=====
@@ -551,14 +551,11 @@ bool MaterialManager::exists(const QString& uuid) const
return _localManager->exists(uuid);
}
bool MaterialManager::exists(const std::shared_ptr<MaterialLibrary>& library,
bool MaterialManager::exists(const MaterialLibrary& library,
const QString& uuid) const
{
if (library->isLocal()) {
auto materialLibrary =
reinterpret_cast<const std::shared_ptr<Materials::MaterialLibraryLocal>&>(library);
return _localManager->exists(materialLibrary, uuid);
if (library.isLocal()) {
return _localManager->exists(library, uuid);
}
return false;
}
@@ -638,7 +635,7 @@ void MaterialManager::migrateToExternal(const std::shared_ptr<Materials::Materia
auto material = _localManager->getMaterial(uuid);
if (!material->isOldFormat()) {
_externalManager->migrateMaterial(library->getName(), path, material);
_externalManager->migrateMaterial(library->getName(), path, *material);
}
}
}
@@ -659,7 +656,7 @@ void MaterialManager::validateMigration(const std::shared_ptr<Materials::Materia
auto material = _localManager->getMaterial(uuid);
if (!material->isOldFormat()) {
auto externalMaterial = _externalManager->getMaterial(uuid);
material->validate(externalMaterial);
material->validate(*externalMaterial);
}
}
}

View File

@@ -87,7 +87,7 @@ public:
libraryMaterials(const QString& libraryName, bool local = false);
std::shared_ptr<std::vector<LibraryObject>>
libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options,
bool local = false);
bool isLocalLibrary(const QString& libraryName);
@@ -103,14 +103,14 @@ public:
// Tree management
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
getMaterialTree(const std::shared_ptr<MaterialLibrary>& library,
const std::shared_ptr<Materials::MaterialFilter>& filter) const;
getMaterialTree(const MaterialLibrary& library,
const Materials::MaterialFilter& filter) const;
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
getMaterialTree(const std::shared_ptr<MaterialLibrary>& library,
const std::shared_ptr<Materials::MaterialFilter>& filter,
getMaterialTree(const MaterialLibrary& library,
const Materials::MaterialFilter& filter,
const MaterialFilterOptions& options) const;
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
getMaterialTree(const std::shared_ptr<MaterialLibrary>& library) const;
getMaterialTree(const MaterialLibrary& library) const;
// Material management
std::shared_ptr<std::map<QString, std::shared_ptr<Material>>> getLocalMaterials() const;
@@ -120,7 +120,7 @@ public:
std::shared_ptr<Material> getMaterialByPath(const QString& path, const QString& library) const;
std::shared_ptr<Material> getParent(const std::shared_ptr<Material>& material) const;
bool exists(const QString& uuid) const;
bool exists(const std::shared_ptr<MaterialLibrary>& library, const QString& uuid) const;
bool exists(const MaterialLibrary& library, const QString& uuid) const;
void remove(const QString& uuid) const;
void saveMaterial(const std::shared_ptr<MaterialLibrary>& library,

View File

@@ -159,7 +159,7 @@ MaterialManagerExternal::libraryMaterials(const QString& libraryName)
std::shared_ptr<std::vector<LibraryObject>>
MaterialManagerExternal::libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options)
{
return ExternalManager::getManager()->libraryMaterials(libraryName, filter, options);
@@ -171,23 +171,23 @@ MaterialManagerExternal::libraryMaterials(const QString& libraryName,
//
//=====
void MaterialManagerExternal::createFolder(const std::shared_ptr<MaterialLibrary>& library,
void MaterialManagerExternal::createFolder(const MaterialLibrary& library,
const QString& path)
{
ExternalManager::getManager()->createFolder(library->getName(), path);
ExternalManager::getManager()->createFolder(library.getName(), path);
}
void MaterialManagerExternal::renameFolder(const std::shared_ptr<MaterialLibrary>& library,
void MaterialManagerExternal::renameFolder(const MaterialLibrary& library,
const QString& oldPath,
const QString& newPath)
{
ExternalManager::getManager()->renameFolder(library->getName(), oldPath, newPath);
ExternalManager::getManager()->renameFolder(library.getName(), oldPath, newPath);
}
void MaterialManagerExternal::deleteRecursive(const std::shared_ptr<MaterialLibrary>& library,
void MaterialManagerExternal::deleteRecursive(const MaterialLibrary& library,
const QString& path)
{
ExternalManager::getManager()->deleteRecursive(library->getName(), path);
ExternalManager::getManager()->deleteRecursive(library.getName(), path);
}
//=====
@@ -226,17 +226,17 @@ std::shared_ptr<Material> MaterialManagerExternal::getMaterial(const QString& uu
void MaterialManagerExternal::addMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material)
const Material& material)
{
_cache.erase(material->getUUID().toStdString());
_cache.erase(material.getUUID().toStdString());
ExternalManager::getManager()->addMaterial(libraryName, path, material);
}
void MaterialManagerExternal::migrateMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material)
const Material& material)
{
_cache.erase(material->getUUID().toStdString());
_cache.erase(material.getUUID().toStdString());
ExternalManager::getManager()->migrateMaterial(libraryName, path, material);
}

View File

@@ -75,24 +75,23 @@ public:
libraryMaterials(const QString& libraryName);
std::shared_ptr<std::vector<LibraryObject>>
libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options);
// Folder management
void createFolder(const std::shared_ptr<MaterialLibrary>& library, const QString& path);
void renameFolder(const std::shared_ptr<MaterialLibrary>& library,
const QString& oldPath,
const QString& newPath);
void deleteRecursive(const std::shared_ptr<MaterialLibrary>& library, const QString& path);
void createFolder(const MaterialLibrary& library, const QString& path);
void
renameFolder(const MaterialLibrary& library, const QString& oldPath, const QString& newPath);
void deleteRecursive(const MaterialLibrary& library, const QString& path);
// Material management
std::shared_ptr<Material> getMaterial(const QString& uuid) const;
void addMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material);
const Material& material);
void migrateMaterial(const QString& libraryName,
const QString& path,
const std::shared_ptr<Material>& material);
const Material& material);
// Cache functions
void resetCache();

View File

@@ -216,27 +216,22 @@ MaterialManagerLocal::libraryMaterials(const QString& libraryName)
return materials;
}
bool MaterialManagerLocal::passFilter(const std::shared_ptr<Material>& material,
const std::shared_ptr<Materials::MaterialFilter>& filter,
bool MaterialManagerLocal::passFilter(const Material& material,
const Materials::MaterialFilter& filter,
const Materials::MaterialFilterOptions& options) const
{
if (!filter) {
// If there's no filter we always include
return true;
}
// filter out old format files
if (material->isOldFormat() && !options.includeLegacy()) {
if (material.isOldFormat() && !options.includeLegacy()) {
return false;
}
// filter based on models
return filter->modelIncluded(material);
return filter.modelIncluded(material);
}
std::shared_ptr<std::vector<LibraryObject>>
MaterialManagerLocal::libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options)
{
auto materials = std::make_shared<std::vector<LibraryObject>>();
@@ -245,7 +240,7 @@ MaterialManagerLocal::libraryMaterials(const QString& libraryName,
// This is needed to resolve cyclic dependencies
auto library = it.second->getLibrary();
if (library->isName(libraryName)) {
if (passFilter(it.second, filter, options)) {
if (passFilter(*it.second, filter, options)) {
materials->push_back(
LibraryObject(it.first, it.second->getDirectory(), it.second->getName()));
}
@@ -386,7 +381,7 @@ bool MaterialManagerLocal::exists(const QString& uuid) const
return false;
}
bool MaterialManagerLocal::exists(const std::shared_ptr<MaterialLibrary>& library,
bool MaterialManagerLocal::exists(const MaterialLibrary& library,
const QString& uuid) const
{
try {
@@ -395,7 +390,7 @@ bool MaterialManagerLocal::exists(const std::shared_ptr<MaterialLibrary>& librar
auto materialLibrary =
reinterpret_cast<const std::shared_ptr<Materials::MaterialLibraryLocal>&>(
*(material->getLibrary()));
return (*materialLibrary == *library);
return (*materialLibrary == library);
}
}
catch (const MaterialNotFound&) {

View File

@@ -75,7 +75,7 @@ public:
libraryMaterials(const QString& libraryName);
std::shared_ptr<std::vector<LibraryObject>>
libraryMaterials(const QString& libraryName,
const std::shared_ptr<MaterialFilter>& filter,
const MaterialFilter& filter,
const MaterialFilterOptions& options);
// Folder management
@@ -93,7 +93,7 @@ public:
std::shared_ptr<Material> getMaterialByPath(const QString& path) const;
std::shared_ptr<Material> getMaterialByPath(const QString& path, const QString& library) const;
bool exists(const QString& uuid) const;
bool exists(const std::shared_ptr<MaterialLibrary>& library, const QString& uuid) const;
bool exists(const MaterialLibrary& library, const QString& uuid) const;
void remove(const QString& uuid);
void saveMaterial(const std::shared_ptr<MaterialLibraryLocal>& library,
@@ -115,8 +115,8 @@ public:
protected:
static std::shared_ptr<std::list<std::shared_ptr<MaterialLibrary>>> getConfiguredLibraries();
bool passFilter(const std::shared_ptr<Material>& material,
const std::shared_ptr<Materials::MaterialFilter>& filter,
bool passFilter(const Material& material,
const Materials::MaterialFilter& filter,
const Materials::MaterialFilterOptions& options) const;
private:

View File

@@ -345,7 +345,7 @@ PyObject* MaterialManagerPy::filterMaterials(PyObject* args, PyObject* kwds)
Py::List list;
for (auto lib : *libraries) {
auto tree = getMaterialManagerPtr()->getMaterialTree(lib, filter, options);
auto tree = getMaterialManagerPtr()->getMaterialTree(*lib, *filter, options);
if (tree->size() > 0) {
addMaterials(getMaterialManagerPtr(), list, tree);
}

View File

@@ -1344,14 +1344,14 @@ 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 Material& parent,
const Model& model) const
{
for (auto& it : *model) {
for (auto& it : model) {
QString propertyName = it.first;
auto property = getPhysicalProperty(propertyName);
try {
auto parentProperty = parent->getPhysicalProperty(propertyName);
auto parentProperty = parent.getPhysicalProperty(propertyName);
if (*property != *parentProperty) {
return true;
@@ -1365,14 +1365,14 @@ 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 Material& parent,
const Model& model) const
{
for (auto& it : *model) {
for (auto& it : model) {
QString propertyName = it.first;
auto property = getAppearanceProperty(propertyName);
try {
auto parentProperty = parent->getAppearanceProperty(propertyName);
auto parentProperty = parent.getAppearanceProperty(propertyName);
if (*property != *parentProperty) {
return true;
@@ -1409,7 +1409,7 @@ void Material::saveModels(QTextStream& stream, bool saveInherited) const
bool headerPrinted = false;
for (auto& itm : _physicalUuids) {
auto model = modelManager.getModel(itm);
if (!inherited || modelChanged(parent, model)) {
if (!inherited || modelChanged(*parent, *model)) {
if (!headerPrinted) {
stream << "Models:\n";
headerPrinted = true;
@@ -1463,7 +1463,7 @@ void Material::saveAppearanceModels(QTextStream& stream, bool saveInherited) con
bool headerPrinted = false;
for (auto& itm : _appearanceUuids) {
auto model = modelManager.getModel(itm);
if (!inherited || modelAppearanceChanged(parent, model)) {
if (!inherited || modelAppearanceChanged(*parent, *model)) {
if (!headerPrinted) {
stream << "AppearanceModels:\n";
headerPrinted = true;
@@ -1781,97 +1781,97 @@ App::Material Material::getMaterialAppearance() const
return material;
}
void Material::validate(const std::shared_ptr<Material>& other) const
void Material::validate(Material& other) const
{
try {
_library->validate(*(other->_library));
_library->validate(*other._library);
}
catch (const InvalidLibrary& e) {
throw InvalidMaterial(e.what());
}
if (_directory != other->_directory) {
if (_directory != other._directory) {
throw InvalidMaterial("Model directories don't match");
}
if (!other->_filename.isEmpty()) {
if (!other._filename.isEmpty()) {
throw InvalidMaterial("Remote filename is not empty");
}
if (_uuid != other->_uuid) {
if (_uuid != other._uuid) {
throw InvalidMaterial("Model UUIDs don't match");
}
if (_name != other->_name) {
if (_name != other._name) {
throw InvalidMaterial("Model names don't match");
}
if (_author != other->_author) {
if (_author != other._author) {
throw InvalidMaterial("Model authors don't match");
}
if (_license != other->_license) {
if (_license != other._license) {
throw InvalidMaterial("Model licenses don't match");
}
if (_parentUuid != other->_parentUuid) {
if (_parentUuid != other._parentUuid) {
throw InvalidMaterial("Model parents don't match");
}
if (_description != other->_description) {
if (_description != other._description) {
throw InvalidMaterial("Model descriptions don't match");
}
if (_url != other->_url) {
if (_url != other._url) {
throw InvalidMaterial("Model URLs don't match");
}
if (_reference != other->_reference) {
if (_reference != other._reference) {
throw InvalidMaterial("Model references don't match");
}
if (_tags.size() != other->_tags.size()) {
if (_tags.size() != other._tags.size()) {
Base::Console().log("Local tags count %d\n", _tags.size());
Base::Console().log("Remote tags count %d\n", other->_tags.size());
Base::Console().log("Remote tags count %d\n", other._tags.size());
throw InvalidMaterial("Material tags counts don't match");
}
if (!other->_tags.contains(_tags)) {
if (!other._tags.contains(_tags)) {
throw InvalidMaterial("Material tags don't match");
}
if (_physicalUuids.size() != other->_physicalUuids.size()) {
if (_physicalUuids.size() != other._physicalUuids.size()) {
Base::Console().log("Local physical model count %d\n", _physicalUuids.size());
Base::Console().log("Remote physical model count %d\n", other->_physicalUuids.size());
Base::Console().log("Remote physical model count %d\n", other._physicalUuids.size());
throw InvalidMaterial("Material physical model counts don't match");
}
if (!other->_physicalUuids.contains(_physicalUuids)) {
if (!other._physicalUuids.contains(_physicalUuids)) {
throw InvalidMaterial("Material physical models don't match");
}
if (_physicalUuids.size() != other->_physicalUuids.size()) {
if (_physicalUuids.size() != other._physicalUuids.size()) {
Base::Console().log("Local appearance model count %d\n", _physicalUuids.size());
Base::Console().log("Remote appearance model count %d\n", other->_physicalUuids.size());
Base::Console().log("Remote appearance model count %d\n", other._physicalUuids.size());
throw InvalidMaterial("Material appearance model counts don't match");
}
if (!other->_physicalUuids.contains(_physicalUuids)) {
if (!other._physicalUuids.contains(_physicalUuids)) {
throw InvalidMaterial("Material appearance models don't match");
}
if (_allUuids.size() != other->_allUuids.size()) {
if (_allUuids.size() != other._allUuids.size()) {
Base::Console().log("Local model count %d\n", _allUuids.size());
Base::Console().log("Remote model count %d\n", other->_allUuids.size());
Base::Console().log("Remote model count %d\n", other._allUuids.size());
throw InvalidMaterial("Material model counts don't match");
}
if (!other->_allUuids.contains(_allUuids)) {
if (!other._allUuids.contains(_allUuids)) {
throw InvalidMaterial("Material models don't match");
}
// Need to compare properties
if (_physical.size() != other->_physical.size()) {
if (_physical.size() != other._physical.size()) {
throw InvalidMaterial("Material physical property counts don't match");
}
for (auto& property : _physical) {
auto& remote = other->_physical[property.first];
auto& remote = other._physical[property.first];
property.second->validate(*remote);
}
if (_appearance.size() != other->_appearance.size()) {
if (_appearance.size() != other._appearance.size()) {
throw InvalidMaterial("Material appearance property counts don't match");
}
for (auto& property : _appearance) {
auto& remote = other->_appearance[property.first];
auto& remote = other._appearance[property.first];
property.second->validate(*remote);
}
}

View File

@@ -443,7 +443,7 @@ public:
return getTypeId() == other.getTypeId() && _uuid == other._uuid;
}
void validate(const std::shared_ptr<Material>& other) const;
void validate(Material& other) const;
protected:
void addModel(const QString& uuid);
@@ -456,10 +456,10 @@ protected:
getValueString(const std::map<QString, std::shared_ptr<MaterialProperty>>& propertyList,
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 Material& parent,
const Model& model) const;
bool modelAppearanceChanged(const Material& parent,
const Model& model) const;
void saveGeneral(QTextStream& stream) const;
void saveInherits(QTextStream& stream) const;
void saveModels(QTextStream& stream, bool saveInherited) const;

View File

@@ -202,10 +202,10 @@ ModelProperty& Model::operator[](const QString& key)
}
}
void Model::validate(const std::shared_ptr<Model>& other) const
void Model::validate(Model& other) const
{
try {
_library->validate(*(other->_library));
_library->validate(*(other._library));
}
catch (const InvalidLibrary& e)
{
@@ -213,42 +213,40 @@ void Model::validate(const std::shared_ptr<Model>& other) const
}
// std::map<QString, ModelProperty> _properties;
if (_type != other->_type) {
if (_type != other._type) {
throw InvalidModel("Model types don't match");
}
if (_name != other->_name) {
if (_name != other._name) {
throw InvalidModel("Model names don't match");
}
if (_directory != other->_directory) {
if (_directory != other._directory) {
throw InvalidModel("Model directories don't match");
}
if (!other->_filename.isEmpty()) {
if (!other._filename.isEmpty()) {
throw InvalidModel("Remote filename is not empty");
}
if (_uuid != other->_uuid) {
if (_uuid != other._uuid) {
throw InvalidModel("Model UUIDs don't match");
}
if (_description != other->_description) {
if (_description != other._description) {
throw InvalidModel("Model descriptions don't match");
}
if (_url != other->_url) {
if (_url != other._url) {
throw InvalidModel("Model URLs don't match");
}
if (_doi != other->_doi) {
if (_doi != other._doi) {
throw InvalidModel("Model DOIs don't match");
}
if (_inheritedUuids != other->_inheritedUuids) {
if (_inheritedUuids != other._inheritedUuids) {
throw InvalidModel("Model inherited UUIDs don't match");
}
// Need to compare properties
if (_properties.size() != other->_properties.size()) {
// Base::Console().log("Local property count %d\n", _properties.size());
// Base::Console().log("Remote property count %d\n", other->_properties.size());
if (_properties.size() != other._properties.size()) {
throw InvalidModel("Model property counts don't match");
}
for (auto& property : _properties) {
auto& remote = other->_properties[property.first];
auto& remote = other._properties[property.first];
property.second.validate(remote);
}
}

View File

@@ -301,7 +301,7 @@ public:
return _properties.cend();
}
void validate(const std::shared_ptr<Model>& other) const;
void validate(Model& other) const;
private:
std::shared_ptr<ModelLibrary> _library;

View File

@@ -342,7 +342,7 @@ void ModelManager::migrateToExternal(const std::shared_ptr<Materials::ModelLibra
name.toStdString().c_str());
auto model = _localManager->getModel(uuid);
_externalManager->migrateModel(library->getName(), path, model);
_externalManager->migrateModel(library->getName(), path, *model);
}
}
@@ -360,7 +360,7 @@ void ModelManager::validateMigration(const std::shared_ptr<Materials::ModelLibra
auto model = _localManager->getModel(uuid);
auto externalModel = _externalManager->getModel(uuid);
model->validate(externalModel);
model->validate(*externalModel);
}
}

View File

@@ -163,17 +163,17 @@ std::shared_ptr<std::map<QString, std::shared_ptr<Model>>> ModelManagerExternal:
void ModelManagerExternal::addModel(const QString& libraryName,
const QString& path,
const std::shared_ptr<Model>& model)
const Model& model)
{
_cache.erase(model->getUUID().toStdString());
_cache.erase(model.getUUID().toStdString());
ExternalManager::getManager()->addModel(libraryName, path, model);
}
void ModelManagerExternal::migrateModel(const QString& libraryName,
const QString& path,
const std::shared_ptr<Model>& model)
const Model& model)
{
_cache.erase(model->getUUID().toStdString());
_cache.erase(model.getUUID().toStdString());
ExternalManager::getManager()->migrateModel(libraryName, path, model);
}

View File

@@ -63,9 +63,9 @@ public:
std::shared_ptr<Model> getModel(const QString& uuid);
std::shared_ptr<std::map<QString, std::shared_ptr<Model>>> getModels();
void
addModel(const QString& libraryName, const QString& path, const std::shared_ptr<Model>& model);
addModel(const QString& libraryName, const QString& path, const Model& model);
void
migrateModel(const QString& libraryName, const QString& path, const std::shared_ptr<Model>& model);
migrateModel(const QString& libraryName, const QString& path, const Model& model);
// Cache functions
void resetCache();

View File

@@ -85,8 +85,8 @@ DlgMaterialImp::DlgMaterialImp(bool floating, QWidget* parent, Qt::WindowFlags f
// Create a filter to only include current format materials
// that contain physical properties.
auto filter = std::make_shared<Materials::MaterialFilter>();
filter->requirePhysical(true);
Materials::MaterialFilter filter;
filter.requirePhysical(true);
d->ui.widgetMaterial->setFilter(filter);
std::vector<App::DocumentObject*> objects = getSelectionObjects();

View File

@@ -154,7 +154,7 @@ void MaterialSave::onOk(bool checked)
bool saveAsCopy = false;
if (Materials::MaterialManager::getManager().exists(_material->getUUID())) {
// Does it already exist in this library?
if (Materials::MaterialManager::getManager().exists(library, _material->getUUID())) {
if (Materials::MaterialManager::getManager().exists(*library, _material->getUUID())) {
// Confirm saving a new material
auto res = confirmNewMaterial();
if (res == QMessageBox::Cancel) {
@@ -371,7 +371,7 @@ void MaterialSave::showSelectedTree()
lib->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
addExpanded(tree, model, lib);
auto modelTree = Materials::MaterialManager::getManager().getMaterialTree(library);
auto modelTree = Materials::MaterialManager::getManager().getMaterialTree(*library);
addMaterials(*lib, modelTree, folderIcon, icon);
}
else {

View File

@@ -55,7 +55,7 @@ using namespace MatGui;
TYPESYSTEM_SOURCE(MatGui::MaterialTreeWidget, Base::BaseClass)
MaterialTreeWidget::MaterialTreeWidget(const std::shared_ptr<Materials::MaterialFilter>& filter,
MaterialTreeWidget::MaterialTreeWidget(const Materials::MaterialFilter& filter,
QWidget* parent)
: QWidget(parent)
, m_expanded(false)
@@ -72,7 +72,6 @@ MaterialTreeWidget::MaterialTreeWidget(
: QWidget(parent)
, m_expanded(false)
, m_treeSizeHint(minimumTreeWidth, minimumTreeHeight)
, _filter(std::make_shared<Materials::MaterialFilter>())
, _filterList(filterList)
, _recentMax(defaultRecents)
{
@@ -83,7 +82,6 @@ MaterialTreeWidget::MaterialTreeWidget(QWidget* parent)
: QWidget(parent)
, m_expanded(false)
, m_treeSizeHint(minimumTreeWidth, minimumTreeHeight)
, _filter(std::make_shared<Materials::MaterialFilter>())
, _recentMax(defaultRecents)
{
setup();
@@ -170,7 +168,7 @@ void MaterialTreeWidget::createLayout()
// Set the filter if using a filter list
if (hasMultipleFilters()) {
_filter = _filterList->front();
_filter = *_filterList->front();
}
fillFilterCombo();
@@ -349,11 +347,8 @@ QString MaterialTreeWidget::getMaterialUUID() const
return m_uuid;
}
void MaterialTreeWidget::setFilter(const std::shared_ptr<Materials::MaterialFilter>& filter)
void MaterialTreeWidget::setFilter(const Materials::MaterialFilter& filter)
{
if (_filter) {
_filter.reset();
}
if (_filterList) {
_filterList.reset();
}
@@ -369,14 +364,13 @@ void MaterialTreeWidget::setFilter(const std::shared_ptr<Materials::MaterialFilt
void MaterialTreeWidget::setFilter(
const std::shared_ptr<std::list<std::shared_ptr<Materials::MaterialFilter>>>& filterList)
{
_filter.reset();
if (_filterList) {
_filterList.reset();
}
_filterList = filterList;
if (hasMultipleFilters()) {
_filter = _filterList->front();
_filter = *_filterList->front();
}
fillFilterCombo();
@@ -390,9 +384,7 @@ void MaterialTreeWidget::setActiveFilter(const QString& name)
if (_filterList) {
for (auto const& filter : *_filterList) {
if (filter->name() == name) {
_filter.reset();
_filter = filter;
_filter = *filter;
// Save the library/folder expansion state
saveMaterialTree();
@@ -427,7 +419,7 @@ void MaterialTreeWidget::getFavorites()
for (int i = 0; static_cast<long>(i) < count; i++) {
QString key = QStringLiteral("FAV%1").arg(i);
QString uuid = QString::fromStdString(param->GetASCII(key.toStdString().c_str(), ""));
if (!_filter || _filter->modelIncluded(uuid)) {
if (_filter.modelIncluded(uuid)) {
_favorites.push_back(uuid);
}
}
@@ -444,7 +436,7 @@ void MaterialTreeWidget::getRecents()
for (int i = 0; static_cast<long>(i) < count; i++) {
QString key = QStringLiteral("MRU%1").arg(i);
QString uuid = QString::fromStdString(param->GetASCII(key.toStdString().c_str(), ""));
if (!_filter || _filter->modelIncluded(uuid)) {
if (_filter.modelIncluded(uuid)) {
_recents.push_back(uuid);
}
}
@@ -558,7 +550,7 @@ void MaterialTreeWidget::fillMaterialTree()
auto libraries = Materials::MaterialManager::getManager().getLibraries();
for (const auto& library : *libraries) {
auto materialTree =
Materials::MaterialManager::getManager().getMaterialTree(library,
Materials::MaterialManager::getManager().getMaterialTree(*library,
_filter,
_filterOptions);

View File

@@ -76,7 +76,7 @@ class MatGuiExport MaterialTreeWidget: public QWidget, public Base::BaseClass
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
explicit MaterialTreeWidget(const std::shared_ptr<Materials::MaterialFilter>& filter,
explicit MaterialTreeWidget(const Materials::MaterialFilter& filter,
QWidget* parent = nullptr);
explicit MaterialTreeWidget(
const std::shared_ptr<std::list<std::shared_ptr<Materials::MaterialFilter>>>& filterList,
@@ -92,7 +92,7 @@ public:
QString getMaterialUUID() const;
/** Set the material filter
*/
void setFilter(const std::shared_ptr<Materials::MaterialFilter>& filter);
void setFilter(const Materials::MaterialFilter& filter);
void setFilter(
const std::shared_ptr<std::list<std::shared_ptr<Materials::MaterialFilter>>>& filterList);
void setActiveFilter(const QString& name);
@@ -200,7 +200,7 @@ private:
std::list<QString> _favorites;
std::list<QString> _recents;
std::shared_ptr<Materials::MaterialFilter> _filter;
Materials::MaterialFilter _filter;
Materials::MaterialFilterTreeWidgetOptions _filterOptions;
std::shared_ptr<std::list<std::shared_ptr<Materials::MaterialFilter>>> _filterList;
int _recentMax;

View File

@@ -170,8 +170,7 @@ PyObject* MaterialTreeWidgetPy::setFilter(PyObject* args)
}
if (PyObject_TypeCheck(obj, &(Materials::MaterialFilterPy::Type))) {
auto filter = static_cast<Materials::MaterialFilterPy*>(obj)->getMaterialFilterPtr();
auto filterPtr = std::make_shared<Materials::MaterialFilter>(*filter);
getMaterialTreeWidgetPtr()->setFilter(filterPtr);
getMaterialTreeWidgetPtr()->setFilter(*filter);
}
else if (PyList_Check(obj)) {
// The argument is a list of filters

View File

@@ -61,7 +61,7 @@ using namespace MatGui;
/* TRANSLATOR MatGui::MaterialsEditor */
MaterialsEditor::MaterialsEditor(std::shared_ptr<Materials::MaterialFilter> filter, QWidget* parent)
MaterialsEditor::MaterialsEditor(Materials::MaterialFilter filter, QWidget* parent)
: QDialog(parent)
, ui(new Ui_MaterialsEditor)
, _material(std::make_shared<Materials::Material>())
@@ -80,7 +80,6 @@ MaterialsEditor::MaterialsEditor(QWidget* parent)
, _rendered(nullptr)
, _materialSelected(false)
, _recentMax(0)
, _filter(nullptr)
{
setup();
}
@@ -182,7 +181,7 @@ void MaterialsEditor::getFavorites()
for (int i = 0; static_cast<long>(i) < count; i++) {
QString key = QStringLiteral("FAV%1").arg(i);
QString uuid = QString::fromStdString(param->GetASCII(key.toStdString().c_str(), ""));
if (!_filter || _filter->modelIncluded(uuid)) {
if (_filter.modelIncluded(uuid)) {
_favorites.push_back(uuid);
}
}
@@ -260,7 +259,7 @@ void MaterialsEditor::getRecents()
for (int i = 0; static_cast<long>(i) < count; i++) {
QString key = QStringLiteral("MRU%1").arg(i);
QString uuid = QString::fromStdString(param->GetASCII(key.toStdString().c_str(), ""));
if (!_filter || _filter->modelIncluded(uuid)) {
if (_filter.modelIncluded(uuid)) {
_recents.push_back(uuid);
}
}
@@ -892,7 +891,7 @@ void MaterialsEditor::fillMaterialTree()
auto libraries = getMaterialManager().getLibraries();
for (const auto& library : *libraries) {
auto materialTree = getMaterialManager().getMaterialTree(library);
auto materialTree = getMaterialManager().getMaterialTree(*library);
bool showLibraries = _filterOptions.includeEmptyLibraries();
if (!_filterOptions.includeEmptyLibraries() && materialTree->size() > 0) {

View File

@@ -53,7 +53,7 @@ class MaterialsEditor: public QDialog
Q_OBJECT
public:
explicit MaterialsEditor(std::shared_ptr<Materials::MaterialFilter> filter,
explicit MaterialsEditor(Materials::MaterialFilter filter,
QWidget* parent = nullptr);
explicit MaterialsEditor(QWidget* parent = nullptr);
~MaterialsEditor() override = default;
@@ -121,7 +121,7 @@ private:
std::list<QString> _recents;
int _recentMax;
QIcon _warningIcon;
std::shared_ptr<Materials::MaterialFilter> _filter;
Materials::MaterialFilter _filter;
Materials::MaterialFilterOptions _filterOptions;
void setup();

View File

@@ -141,104 +141,104 @@ TEST_F(TestMaterialFilter, TestFilters)
ASSERT_EQ(material->getUUID().size(), 36); // We don't know the UUID
// Create an empty filter
auto filter = std::make_shared<Materials::MaterialFilter>();
Materials::MaterialFilter filter;
Materials::MaterialFilterOptions options;
ASSERT_TRUE(_library);
auto tree = _materialManager->getMaterialTree(_library, filter, options);
auto tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 4);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 5);
// Create a basic rendering filter
filter->setName(QStringLiteral("Basic Appearance"));
filter->addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
filter.setName(QStringLiteral("Basic Appearance"));
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
options.setIncludeLegacy(false);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 3);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 3);
// Create an advanced rendering filter
filter->clear();
filter->setName(QStringLiteral("Advanced Appearance"));
filter->addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Advanced);
filter.clear();
filter.setName(QStringLiteral("Advanced Appearance"));
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Advanced);
options.setIncludeLegacy(false);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 0);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 0);
// Create a Density filter
filter->clear();
filter->setName(QStringLiteral("Density"));
filter->addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density);
filter.clear();
filter.setName(QStringLiteral("Density"));
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density);
options.setIncludeLegacy(false);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 2);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 3);
// Create a Hardness filter
filter->clear();
filter->setName(QStringLiteral("Hardness"));
filter->addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Hardness);
filter.clear();
filter.setName(QStringLiteral("Hardness"));
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Hardness);
options.setIncludeLegacy(false);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 0);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 0);
// Create a Density and Basic Rendering filter
filter->clear();
filter->setName(QStringLiteral("Density and Basic Rendering"));
filter->addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
filter->addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density);
filter.clear();
filter.setName(QStringLiteral("Density and Basic Rendering"));
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Rendering_Basic);
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_Density);
options.setIncludeLegacy(false);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 1);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 1);
// Create a Linear Elastic filter
filter->clear();
filter->setName(QStringLiteral("Linear Elastic"));
filter->addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
filter.clear();
filter.setName(QStringLiteral("Linear Elastic"));
filter.addRequiredComplete(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
options.setIncludeLegacy(false);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 0);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 0);
filter->clear();
filter->setName(QStringLiteral("Linear Elastic"));
filter->addRequired(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
filter.clear();
filter.setName(QStringLiteral("Linear Elastic"));
filter.addRequired(Materials::ModelUUIDs::ModelUUID_Mechanical_LinearElastic);
options.setIncludeLegacy(false);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 2);
options.setIncludeLegacy(true);
tree = _materialManager->getMaterialTree(_library, filter, options);
tree = _materialManager->getMaterialTree(*_library, filter, options);
ASSERT_EQ(tree->size(), 2);
}