Materials: External Modules Part 1
Refactored code to support local and external material sources This is the first PR in a series to support external modules. External modules allow materials to be stored in external data sources such as databases or web services. No new functionality is introduced in this PR, rather it is a refactoring of code that will allow for changes to be introduced in future PRs. Minor performance improvements have also been made in the model and material managers. The Python API has been enhanced for many data types to allow for modification within Python.
This commit is contained in:
committed by
Chris Hennes
parent
3c4977a2d4
commit
00c57a9d08
@@ -31,6 +31,7 @@
|
||||
#include <Base/BaseClass.h>
|
||||
#include <Mod/Material/MaterialGlobal.h>
|
||||
|
||||
#include "Library.h"
|
||||
#include "Materials.h"
|
||||
#include "Model.h"
|
||||
#include "ModelLibrary.h"
|
||||
@@ -43,29 +44,50 @@ class MaterialManager;
|
||||
class MaterialFilter;
|
||||
class MaterialFilterOptions;
|
||||
|
||||
class MaterialsExport MaterialLibrary: public LibraryBase,
|
||||
public std::enable_shared_from_this<MaterialLibrary>
|
||||
class MaterialsExport MaterialLibrary
|
||||
: public Library,
|
||||
public std::enable_shared_from_this<MaterialLibrary>
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
MaterialLibrary() = default;
|
||||
MaterialLibrary(const MaterialLibrary&) = delete;
|
||||
MaterialLibrary(const QString& libraryName, const QString& icon, bool readOnly = true);
|
||||
MaterialLibrary(const QString& libraryName,
|
||||
const QString& dir,
|
||||
const QString& icon,
|
||||
bool readOnly = true);
|
||||
MaterialLibrary(const MaterialLibrary&) = delete;
|
||||
~MaterialLibrary() override = default;
|
||||
|
||||
bool operator==(const MaterialLibrary& library) const
|
||||
bool isLocal() const;
|
||||
void setLocal(bool local);
|
||||
|
||||
virtual std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
|
||||
getMaterialTree(const std::shared_ptr<Materials::MaterialFilter>& filter,
|
||||
const Materials::MaterialFilterOptions& options) const;
|
||||
|
||||
// Use this to get a shared_ptr for *this
|
||||
std::shared_ptr<MaterialLibrary> getptr()
|
||||
{
|
||||
return LibraryBase::operator==(library);
|
||||
return shared_from_this();
|
||||
}
|
||||
bool operator!=(const MaterialLibrary& library) const
|
||||
{
|
||||
return !operator==(library);
|
||||
}
|
||||
std::shared_ptr<Material> getMaterialByPath(const QString& path) const;
|
||||
|
||||
protected:
|
||||
bool _local;
|
||||
};
|
||||
|
||||
class MaterialsExport MaterialLibraryLocal: public MaterialLibrary
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
MaterialLibraryLocal() = default;
|
||||
MaterialLibraryLocal(const QString& libraryName,
|
||||
const QString& dir,
|
||||
const QString& icon,
|
||||
bool readOnly = true);
|
||||
~MaterialLibraryLocal() override = default;
|
||||
|
||||
void createFolder(const QString& path);
|
||||
void renameFolder(const QString& oldPath, const QString& newPath);
|
||||
@@ -79,50 +101,39 @@ public:
|
||||
bool fileExists(const QString& path) const;
|
||||
std::shared_ptr<Material> addMaterial(const std::shared_ptr<Material>& material,
|
||||
const QString& path);
|
||||
std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
|
||||
getMaterialTree(const std::shared_ptr<Materials::MaterialFilter>& filter,
|
||||
const Materials::MaterialFilterOptions& options) const;
|
||||
std::shared_ptr<Material> getMaterialByPath(const QString& path) const;
|
||||
|
||||
bool isReadOnly() const
|
||||
bool operator==(const MaterialLibrary& library) const
|
||||
{
|
||||
return _readOnly;
|
||||
return library.isLocal() ? Library::operator==(library) : false;
|
||||
}
|
||||
bool operator!=(const MaterialLibrary& library) const
|
||||
{
|
||||
return !operator==(library);
|
||||
}
|
||||
|
||||
// Use this to get a shared_ptr for *this
|
||||
std::shared_ptr<MaterialLibrary> getptr()
|
||||
bool operator==(const MaterialLibraryLocal& library) const
|
||||
{
|
||||
return shared_from_this();
|
||||
return Library::operator==(library);
|
||||
}
|
||||
bool operator!=(const MaterialLibraryLocal& library) const
|
||||
{
|
||||
return !operator==(library);
|
||||
}
|
||||
|
||||
protected:
|
||||
void deleteDir(MaterialManager& manager, const QString& path);
|
||||
void deleteFile(MaterialManager& manager, const QString& path);
|
||||
|
||||
void updatePaths(const QString& oldPath, const QString& newPath);
|
||||
|
||||
QString getUUIDFromPath(const QString& path) const;
|
||||
bool materialInTree(const std::shared_ptr<Material>& material,
|
||||
const std::shared_ptr<Materials::MaterialFilter>& filter,
|
||||
const Materials::MaterialFilterOptions& options) const;
|
||||
|
||||
bool _readOnly;
|
||||
std::unique_ptr<std::map<QString, std::shared_ptr<Material>>> _materialPathMap;
|
||||
};
|
||||
|
||||
class MaterialsExport MaterialExternalLibrary: public MaterialLibrary
|
||||
{
|
||||
TYPESYSTEM_HEADER_WITH_OVERRIDE();
|
||||
|
||||
public:
|
||||
MaterialExternalLibrary() = default;
|
||||
MaterialExternalLibrary(const QString& libraryName,
|
||||
const QString& dir,
|
||||
const QString& icon,
|
||||
bool readOnly = true);
|
||||
~MaterialExternalLibrary() override = default;
|
||||
};
|
||||
|
||||
} // namespace Materials
|
||||
|
||||
Q_DECLARE_METATYPE(std::shared_ptr<Materials::MaterialLibrary>)
|
||||
Q_DECLARE_METATYPE(std::shared_ptr<Materials::MaterialLibraryLocal>)
|
||||
|
||||
#endif // MATERIAL_MATERIALLIBRARY_H
|
||||
|
||||
Reference in New Issue
Block a user