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
382720b82e
commit
592406a328
@@ -47,7 +47,7 @@ std::string MaterialManagerPy::representation() const
|
||||
PyObject* MaterialManagerPy::PyMake(struct _typeobject*, PyObject*, PyObject*) // Python wrapper
|
||||
{
|
||||
// never create such objects with the constructor
|
||||
return new MaterialManagerPy(new MaterialManager());
|
||||
return new MaterialManagerPy(&(MaterialManager::getManager()));
|
||||
}
|
||||
|
||||
// constructor method
|
||||
@@ -136,15 +136,25 @@ PyObject* MaterialManagerPy::inheritMaterial(PyObject* args)
|
||||
|
||||
Py::List MaterialManagerPy::getMaterialLibraries() const
|
||||
{
|
||||
auto libraries = getMaterialManagerPtr()->getMaterialLibraries();
|
||||
auto libraries = getMaterialManagerPtr()->getLibraries();
|
||||
Py::List list;
|
||||
|
||||
for (auto it = libraries->begin(); it != libraries->end(); it++) {
|
||||
auto lib = *it;
|
||||
Py::Tuple libTuple(3);
|
||||
libTuple.setItem(0, Py::String(lib->getName().toStdString()));
|
||||
libTuple.setItem(1, Py::String(lib->getDirectoryPath().toStdString()));
|
||||
libTuple.setItem(2, Py::String(lib->getIconPath().toStdString()));
|
||||
if (lib->isLocal()) {
|
||||
auto materialLibrary =
|
||||
reinterpret_cast<const std::shared_ptr<Materials::MaterialLibraryLocal>&>(lib);
|
||||
libTuple.setItem(0, Py::String(materialLibrary->getName().toStdString()));
|
||||
libTuple.setItem(1, Py::String(materialLibrary->getDirectoryPath().toStdString()));
|
||||
libTuple.setItem(2, Py::String(materialLibrary->getIconPath().toStdString()));
|
||||
}
|
||||
else
|
||||
{
|
||||
libTuple.setItem(0, Py::String());
|
||||
libTuple.setItem(1, Py::String());
|
||||
libTuple.setItem(2, Py::String());
|
||||
}
|
||||
|
||||
list.append(libTuple);
|
||||
}
|
||||
@@ -156,7 +166,7 @@ Py::Dict MaterialManagerPy::getMaterials() const
|
||||
{
|
||||
Py::Dict dict;
|
||||
|
||||
auto materials = getMaterialManagerPtr()->getMaterials();
|
||||
auto materials = getMaterialManagerPtr()->getLocalMaterials();
|
||||
|
||||
for (auto it = materials->begin(); it != materials->end(); it++) {
|
||||
QString key = it->first;
|
||||
@@ -284,17 +294,19 @@ PyObject* MaterialManagerPy::save(PyObject* args, PyObject* kwds)
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
void addMaterials(Py::List& list,
|
||||
void addMaterials(MaterialManager *manager,
|
||||
Py::List& list,
|
||||
const std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>& tree)
|
||||
{
|
||||
for (auto& node : *tree) {
|
||||
if (node.second->getType() == MaterialTreeNode::DataNode) {
|
||||
auto material = node.second->getData();
|
||||
if (node.second->getType() == MaterialTreeNode::NodeType::DataNode) {
|
||||
auto uuid = node.second->getUUID();
|
||||
auto material = manager->getMaterial(uuid);
|
||||
PyObject* materialPy = new MaterialPy(new Material(*material));
|
||||
list.append(Py::Object(materialPy, true));
|
||||
}
|
||||
else {
|
||||
addMaterials(list, node.second->getFolder());
|
||||
addMaterials(manager, list, node.second->getFolder());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,13 +339,13 @@ PyObject* MaterialManagerPy::filterMaterials(PyObject* args, PyObject* kwds)
|
||||
|
||||
auto filter = std::make_shared<MaterialFilter>(*(static_cast<MaterialFilterPy*>(filterPy)->getMaterialFilterPtr()));
|
||||
|
||||
auto libraries = getMaterialManagerPtr()->getMaterialLibraries();
|
||||
auto libraries = getMaterialManagerPtr()->getLibraries();
|
||||
Py::List list;
|
||||
|
||||
for (auto lib : *libraries) {
|
||||
auto tree = getMaterialManagerPtr()->getMaterialTree(lib, filter, options);
|
||||
if (tree->size() > 0) {
|
||||
addMaterials(list, tree);
|
||||
addMaterials(getMaterialManagerPtr(), list, tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user