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
@@ -63,7 +63,7 @@ Array2D::Array2D(const QString& propertyName,
|
||||
}
|
||||
if (_property) {
|
||||
_value =
|
||||
std::static_pointer_cast<Materials::Material2DArray>(_property->getMaterialValue());
|
||||
std::static_pointer_cast<Materials::Array2D>(_property->getMaterialValue());
|
||||
setWindowTitle(_property->getDisplayName());
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -64,7 +64,7 @@ private:
|
||||
std::unique_ptr<Ui_Array2D> ui;
|
||||
std::shared_ptr<Materials::Material> _material;
|
||||
std::shared_ptr<Materials::MaterialProperty> _property;
|
||||
std::shared_ptr<Materials::Material2DArray> _value;
|
||||
std::shared_ptr<Materials::Array2D> _value;
|
||||
|
||||
QAction _deleteAction;
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ Array3D::Array3D(const QString& propertyName,
|
||||
}
|
||||
if (_property) {
|
||||
_value =
|
||||
std::static_pointer_cast<Materials::Material3DArray>(_property->getMaterialValue());
|
||||
std::static_pointer_cast<Materials::Array3D>(_property->getMaterialValue());
|
||||
}
|
||||
else {
|
||||
_value = nullptr;
|
||||
|
||||
@@ -67,7 +67,7 @@ private:
|
||||
std::unique_ptr<Ui_Array3D> ui;
|
||||
std::shared_ptr<Materials::Material> _material;
|
||||
std::shared_ptr<Materials::MaterialProperty> _property;
|
||||
std::shared_ptr<Materials::Material3DArray> _value;
|
||||
std::shared_ptr<Materials::Array3D> _value;
|
||||
|
||||
QAction _deleteDepthAction;
|
||||
QAction _delete2DAction;
|
||||
|
||||
@@ -47,7 +47,7 @@ AbstractArrayModel::AbstractArrayModel(QObject* parent)
|
||||
|
||||
|
||||
Array2DModel::Array2DModel(const std::shared_ptr<Materials::MaterialProperty>& property,
|
||||
const std::shared_ptr<Materials::Material2DArray>& value,
|
||||
const std::shared_ptr<Materials::Array2D>& value,
|
||||
QObject* parent)
|
||||
: AbstractArrayModel(parent)
|
||||
, _property(property)
|
||||
@@ -199,7 +199,7 @@ bool Array2DModel::removeColumns(int column, int count, const QModelIndex& paren
|
||||
//===
|
||||
|
||||
Array3DDepthModel::Array3DDepthModel(const std::shared_ptr<Materials::MaterialProperty>& property,
|
||||
const std::shared_ptr<Materials::Material3DArray>& value,
|
||||
const std::shared_ptr<Materials::Array3D>& value,
|
||||
QObject* parent)
|
||||
: AbstractArrayModel(parent)
|
||||
, _property(property)
|
||||
@@ -337,7 +337,7 @@ bool Array3DDepthModel::removeColumns(int column, int count, const QModelIndex&
|
||||
//===
|
||||
|
||||
Array3DModel::Array3DModel(const std::shared_ptr<Materials::MaterialProperty>& property,
|
||||
const std::shared_ptr<Materials::Material3DArray>& value,
|
||||
const std::shared_ptr<Materials::Array3D>& value,
|
||||
QObject* parent)
|
||||
: AbstractArrayModel(parent)
|
||||
, _property(property)
|
||||
|
||||
@@ -48,7 +48,7 @@ class Array2DModel: public AbstractArrayModel
|
||||
{
|
||||
public:
|
||||
explicit Array2DModel(const std::shared_ptr<Materials::MaterialProperty>& property = nullptr,
|
||||
const std::shared_ptr<Materials::Material2DArray>& value = nullptr,
|
||||
const std::shared_ptr<Materials::Array2D>& value = nullptr,
|
||||
QObject* parent = nullptr);
|
||||
~Array2DModel() override = default;
|
||||
|
||||
@@ -71,7 +71,7 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Materials::MaterialProperty> _property;
|
||||
std::shared_ptr<Materials::Material2DArray> _value;
|
||||
std::shared_ptr<Materials::Array2D> _value;
|
||||
};
|
||||
|
||||
class Array3DDepthModel: public AbstractArrayModel
|
||||
@@ -79,7 +79,7 @@ class Array3DDepthModel: public AbstractArrayModel
|
||||
public:
|
||||
explicit Array3DDepthModel(
|
||||
const std::shared_ptr<Materials::MaterialProperty>& property = nullptr,
|
||||
const std::shared_ptr<Materials::Material3DArray>& value = nullptr,
|
||||
const std::shared_ptr<Materials::Array3D>& value = nullptr,
|
||||
QObject* parent = nullptr);
|
||||
~Array3DDepthModel() override = default;
|
||||
|
||||
@@ -106,14 +106,14 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Materials::MaterialProperty> _property;
|
||||
std::shared_ptr<Materials::Material3DArray> _value;
|
||||
std::shared_ptr<Materials::Array3D> _value;
|
||||
};
|
||||
|
||||
class Array3DModel: public AbstractArrayModel
|
||||
{
|
||||
public:
|
||||
explicit Array3DModel(const std::shared_ptr<Materials::MaterialProperty>& property = nullptr,
|
||||
const std::shared_ptr<Materials::Material3DArray>& value = nullptr,
|
||||
const std::shared_ptr<Materials::Array3D>& value = nullptr,
|
||||
QObject* parent = nullptr);
|
||||
~Array3DModel() override = default;
|
||||
|
||||
@@ -138,7 +138,7 @@ public:
|
||||
|
||||
private:
|
||||
std::shared_ptr<Materials::MaterialProperty> _property;
|
||||
std::shared_ptr<Materials::Material3DArray> _value;
|
||||
std::shared_ptr<Materials::Array3D> _value;
|
||||
};
|
||||
|
||||
} // namespace MatGui
|
||||
|
||||
@@ -61,8 +61,6 @@ void CmdMaterialEdit::activated(int iMsg)
|
||||
{
|
||||
Q_UNUSED(iMsg);
|
||||
|
||||
Base::Console().Log("Material_Edit\n");
|
||||
|
||||
static QPointer<QDialog> dlg = nullptr;
|
||||
if (!dlg) {
|
||||
dlg = new MatGui::MaterialsEditor(Gui::getMainWindow());
|
||||
|
||||
@@ -151,7 +151,7 @@ void DlgInspectAppearance::update(std::vector<Gui::ViewProvider*>& views)
|
||||
ui->editObjectLabel->setText(QString::fromUtf8(labelProp->getValue()));
|
||||
}
|
||||
else {
|
||||
ui->editObjectLabel->setText(QLatin1String(""));
|
||||
ui->editObjectLabel->setText(QStringLiteral(""));
|
||||
}
|
||||
ui->editObjectName->setText(QLatin1String(obj->getNameInDocument()));
|
||||
|
||||
@@ -162,15 +162,15 @@ void DlgInspectAppearance::update(std::vector<Gui::ViewProvider*>& views)
|
||||
ui->editSubShape->setText(QString::fromStdString(subObject.getSubNames()[0]));
|
||||
}
|
||||
else {
|
||||
ui->editSubShape->setText(QLatin1String(""));
|
||||
ui->editSubShape->setText(QStringLiteral(""));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->editSubShape->setText(QLatin1String(""));
|
||||
ui->editSubShape->setText(QStringLiteral(""));
|
||||
}
|
||||
|
||||
auto subShapeType = QString::fromUtf8(obj->getTypeId().getName());
|
||||
subShapeType.remove(subShapeType.indexOf(QLatin1String("::")), subShapeType.size());
|
||||
subShapeType.remove(subShapeType.indexOf(QStringLiteral("::")), subShapeType.size());
|
||||
ui->editSubShapeType->setText(subShapeType);
|
||||
ui->editShapeType->setText(QString::fromUtf8(obj->getTypeId().getName()));
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ void DlgInspectMaterial::appendClip(QString text)
|
||||
{
|
||||
// Need to add indent
|
||||
QString indent(clipboardIndent * 4, QLatin1Char(' '));
|
||||
clipboardText += indent + text + QLatin1String("\n");
|
||||
clipboardText += indent + text + QStringLiteral("\n");
|
||||
}
|
||||
|
||||
QStandardItem* DlgInspectMaterial::clipItem(QString text)
|
||||
@@ -144,7 +144,7 @@ void DlgInspectMaterial::unindent()
|
||||
|
||||
void DlgInspectMaterial::update(std::vector<Gui::ViewProvider*>& views)
|
||||
{
|
||||
clipboardText = QLatin1String("");
|
||||
clipboardText = QStringLiteral("");
|
||||
clipboardIndent = 0;
|
||||
App::Document* doc = App::GetApplication().getActiveDocument();
|
||||
if (doc) {
|
||||
@@ -166,7 +166,7 @@ void DlgInspectMaterial::update(std::vector<Gui::ViewProvider*>& views)
|
||||
appendClip(tr("Label: ") + QString::fromUtf8(labelProp->getValue()));
|
||||
}
|
||||
else {
|
||||
ui->editObjectLabel->setText(QLatin1String(""));
|
||||
ui->editObjectLabel->setText(QStringLiteral(""));
|
||||
}
|
||||
ui->editObjectName->setText(QLatin1String(obj->getNameInDocument()));
|
||||
appendClip(tr("Internal Name: ") + QString::fromUtf8(obj->getNameInDocument()));
|
||||
@@ -178,15 +178,15 @@ void DlgInspectMaterial::update(std::vector<Gui::ViewProvider*>& views)
|
||||
ui->editSubShape->setText(QString::fromStdString(subObject.getSubNames()[0]));
|
||||
}
|
||||
else {
|
||||
ui->editSubShape->setText(QLatin1String(""));
|
||||
ui->editSubShape->setText(QStringLiteral(""));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ui->editSubShape->setText(QLatin1String(""));
|
||||
ui->editSubShape->setText(QStringLiteral(""));
|
||||
}
|
||||
|
||||
auto subShapeType = QString::fromUtf8(obj->getTypeId().getName());
|
||||
subShapeType.remove(subShapeType.indexOf(QLatin1String("::")), subShapeType.size());
|
||||
subShapeType.remove(subShapeType.indexOf(QStringLiteral("::")), subShapeType.size());
|
||||
appendClip(tr("Type: ") + subShapeType);
|
||||
ui->editSubShapeType->setText(subShapeType);
|
||||
appendClip(tr("TypeID: ") + QString::fromUtf8(obj->getTypeId().getName()));
|
||||
@@ -248,7 +248,7 @@ void DlgInspectMaterial::addModels(QTreeView* tree,
|
||||
}
|
||||
else {
|
||||
for (const QString& uuid : *models) {
|
||||
auto model = modelManager.getModel(uuid);
|
||||
auto model = Materials::ModelManager::getManager().getModel(uuid);
|
||||
auto name = clipItem(tr("Name: ") + model->getName());
|
||||
addExpanded(tree, parent, name);
|
||||
|
||||
@@ -287,7 +287,7 @@ void DlgInspectMaterial::addModelDetails(QTreeView* tree,
|
||||
}
|
||||
else {
|
||||
for (const QString& inherited : inheritedUuids) {
|
||||
auto inheritedModel = modelManager.getModel(inherited);
|
||||
auto inheritedModel = Materials::ModelManager::getManager().getModel(inherited);
|
||||
|
||||
auto name = clipItem(tr("Name: ") + inheritedModel->getName());
|
||||
addExpanded(tree, inherits, name);
|
||||
@@ -340,10 +340,10 @@ void DlgInspectMaterial::addMaterialDetails(QTreeView* tree,
|
||||
{
|
||||
auto uuid = clipItem(tr("UUID: ") + material.getUUID());
|
||||
addExpanded(tree, parent, uuid);
|
||||
auto library = clipItem(tr("Library: ") + material.getLibrary()->getName());
|
||||
auto library =
|
||||
clipItem(tr("Library: ") + material.getLibrary()->getName());
|
||||
addExpanded(tree, parent, library);
|
||||
auto libraryPath =
|
||||
clipItem(tr("Library Directory: ") + material.getLibrary()->getDirectoryPath());
|
||||
auto libraryPath = clipItem(tr("Library Directory: ") + material.getLibrary()->getDirectoryPath());
|
||||
addExpanded(tree, parent, libraryPath);
|
||||
auto directory = clipItem(tr("Sub Directory: ") + material.getDirectory());
|
||||
addExpanded(tree, parent, directory);
|
||||
@@ -353,7 +353,7 @@ void DlgInspectMaterial::addMaterialDetails(QTreeView* tree,
|
||||
indent();
|
||||
auto parentUUID = material.getParentUUID();
|
||||
if (!parentUUID.isEmpty()) {
|
||||
auto parentMaterial = materialManager.getMaterial(material.getParentUUID());
|
||||
auto parentMaterial = Materials::MaterialManager::getManager().getMaterial(material.getParentUUID());
|
||||
addMaterial(tree, inherits, *parentMaterial);
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -60,8 +60,6 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_DlgInspectMaterial> ui;
|
||||
Materials::MaterialManager materialManager;
|
||||
Materials::ModelManager modelManager;
|
||||
QString clipboardText;
|
||||
int clipboardIndent;
|
||||
|
||||
|
||||
@@ -137,22 +137,23 @@ void MaterialSave::onOk(bool checked)
|
||||
QFileInfo filepath(_selectedPath + QStringLiteral("/") + name
|
||||
+ QStringLiteral(".FCMat"));
|
||||
|
||||
if (library->fileExists(filepath.filePath())) {
|
||||
/*if (library->fileExists(filepath.filePath()))*/ {
|
||||
// confirm overwrite
|
||||
auto res = confirmOverwrite(_filename);
|
||||
if (res == QMessageBox::Cancel) {
|
||||
return;
|
||||
}
|
||||
|
||||
_manager.saveMaterial(library, _material, filepath.filePath(), true, false, _saveInherited);
|
||||
Materials::MaterialManager::getManager()
|
||||
.saveMaterial(library, _material, filepath.filePath(), true, false, _saveInherited);
|
||||
accept();
|
||||
return;
|
||||
}
|
||||
|
||||
bool saveAsCopy = false;
|
||||
if (_manager.exists(_material->getUUID())) {
|
||||
if (Materials::MaterialManager::getManager().exists(_material->getUUID())) {
|
||||
// Does it already exist in this library?
|
||||
if (_manager.exists(library, _material->getUUID())) {
|
||||
if (Materials::MaterialManager::getManager().exists(library, _material->getUUID())) {
|
||||
// Confirm saving a new material
|
||||
auto res = confirmNewMaterial();
|
||||
if (res == QMessageBox::Cancel) {
|
||||
@@ -174,7 +175,7 @@ void MaterialSave::onOk(bool checked)
|
||||
}
|
||||
}
|
||||
|
||||
_manager
|
||||
Materials::MaterialManager::getManager()
|
||||
.saveMaterial(library, _material, filepath.filePath(), false, saveAsCopy, _saveInherited);
|
||||
|
||||
accept();
|
||||
@@ -287,12 +288,16 @@ void MaterialSave::reject()
|
||||
|
||||
void MaterialSave::setLibraries()
|
||||
{
|
||||
auto libraries = _manager.getMaterialLibraries();
|
||||
auto libraries = Materials::MaterialManager::getManager().getLibraries();
|
||||
for (auto& library : *libraries) {
|
||||
if (!library->isReadOnly()) {
|
||||
QVariant libraryVariant;
|
||||
libraryVariant.setValue(library);
|
||||
ui->comboLibrary->addItem(library->getName(), libraryVariant);
|
||||
if (library->isLocal()) {
|
||||
auto materialLibrary =
|
||||
reinterpret_cast<const std::shared_ptr<Materials::MaterialLibraryLocal>&>(library);
|
||||
if (!materialLibrary->isReadOnly()) {
|
||||
QVariant libraryVariant;
|
||||
libraryVariant.setValue(materialLibrary);
|
||||
ui->comboLibrary->addItem(materialLibrary->getName(), libraryVariant);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -327,7 +332,7 @@ void MaterialSave::addMaterials(
|
||||
auto tree = ui->treeMaterials;
|
||||
for (auto& mat : *modelTree) {
|
||||
std::shared_ptr<Materials::MaterialTreeNode> nodePtr = mat.second;
|
||||
if (nodePtr->getType() == Materials::MaterialTreeNode::DataNode) {
|
||||
if (nodePtr->getType() == Materials::MaterialTreeNode::NodeType::DataNode) {
|
||||
std::shared_ptr<Materials::Material> material = nodePtr->getData();
|
||||
QString uuid = material->getUUID();
|
||||
|
||||
@@ -368,7 +373,7 @@ void MaterialSave::showSelectedTree()
|
||||
lib->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||
addExpanded(tree, model, lib);
|
||||
|
||||
auto modelTree = _manager.getMaterialTree(library);
|
||||
auto modelTree = Materials::MaterialManager::getManager().getMaterialTree(library);
|
||||
addMaterials(*lib, modelTree, folderIcon, icon);
|
||||
}
|
||||
else {
|
||||
@@ -444,14 +449,14 @@ void MaterialSave::createFolder(const QString& path)
|
||||
{
|
||||
auto library = currentLibrary();
|
||||
|
||||
_manager.createFolder(library, path);
|
||||
Materials::MaterialManager::getManager().createFolder(library, path);
|
||||
}
|
||||
|
||||
void MaterialSave::renameFolder(const QString& oldPath, const QString& newPath)
|
||||
{
|
||||
auto library = currentLibrary();
|
||||
|
||||
_manager.renameFolder(library, oldPath, newPath);
|
||||
Materials::MaterialManager::getManager().renameFolder(library, oldPath, newPath);
|
||||
}
|
||||
|
||||
void MaterialSave::deleteRecursive(const QString& path)
|
||||
@@ -459,7 +464,7 @@ void MaterialSave::deleteRecursive(const QString& path)
|
||||
// This will delete files, folders, and any children
|
||||
auto library = currentLibrary();
|
||||
|
||||
_manager.deleteRecursive(library, path);
|
||||
Materials::MaterialManager::getManager().deleteRecursive(library, path);
|
||||
}
|
||||
|
||||
void MaterialSave::onNewFolder(bool checked)
|
||||
@@ -552,9 +557,9 @@ int MaterialSave::confirmDelete(QWidget* parent)
|
||||
{
|
||||
auto library = currentLibrary();
|
||||
|
||||
if (library->isRoot(_selectedFull)) {
|
||||
return QMessageBox::Cancel;
|
||||
}
|
||||
// if (library->isRoot(_selectedFull)) {
|
||||
// return QMessageBox::Cancel;
|
||||
// }
|
||||
|
||||
QMessageBox box(parent ? parent : this);
|
||||
box.setIcon(QMessageBox::Question);
|
||||
@@ -600,10 +605,10 @@ void MaterialSave::deleteSelected()
|
||||
{
|
||||
auto library = currentLibrary();
|
||||
|
||||
if (!library->isRoot(_selectedFull)) {
|
||||
_manager.deleteRecursive(library, _selectedFull);
|
||||
removeSelectedFromTree();
|
||||
}
|
||||
// if (!library->isRoot(_selectedFull)) {
|
||||
// Materials::MaterialManager::getManager().deleteRecursive(library, _selectedFull);
|
||||
// removeSelectedFromTree();
|
||||
// }
|
||||
}
|
||||
|
||||
void MaterialSave::removeChildren(QStandardItem* item)
|
||||
|
||||
@@ -35,6 +35,8 @@
|
||||
namespace MatGui
|
||||
{
|
||||
|
||||
class MaterialLibrary;
|
||||
|
||||
class Ui_MaterialSave;
|
||||
|
||||
class MaterialSave: public QDialog
|
||||
@@ -76,7 +78,6 @@ public:
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_MaterialSave> ui;
|
||||
Materials::MaterialManager _manager;
|
||||
std::shared_ptr<Materials::Material> _material;
|
||||
bool _saveInherited;
|
||||
QString _selectedPath;
|
||||
|
||||
@@ -487,7 +487,7 @@ void MaterialTreeWidget::addRecent(const QString& uuid)
|
||||
}
|
||||
// Ensure it is a material. New, unsaved materials will not be
|
||||
try {
|
||||
auto material = _materialManager.getMaterial(uuid);
|
||||
auto material = Materials::MaterialManager::getManager().getMaterial(uuid);
|
||||
Q_UNUSED(material)
|
||||
}
|
||||
catch (const Materials::MaterialNotFound&) {
|
||||
@@ -555,12 +555,15 @@ void MaterialTreeWidget::fillMaterialTree()
|
||||
addRecents(lib);
|
||||
}
|
||||
|
||||
auto libraries = _materialManager.getMaterialLibraries();
|
||||
auto libraries = Materials::MaterialManager::getManager().getLibraries();
|
||||
for (const auto& library : *libraries) {
|
||||
auto modelTree = _materialManager.getMaterialTree(library, _filter, _filterOptions);
|
||||
auto materialTree =
|
||||
Materials::MaterialManager::getManager().getMaterialTree(library,
|
||||
_filter,
|
||||
_filterOptions);
|
||||
|
||||
bool showLibraries = _filterOptions.includeEmptyLibraries();
|
||||
if (!_filterOptions.includeEmptyLibraries() && modelTree->size() > 0) {
|
||||
if (!_filterOptions.includeEmptyLibraries() && materialTree->size() > 0) {
|
||||
showLibraries = true;
|
||||
}
|
||||
|
||||
@@ -572,7 +575,7 @@ void MaterialTreeWidget::fillMaterialTree()
|
||||
QIcon icon(library->getIconPath());
|
||||
QIcon folderIcon(QStringLiteral(":/icons/folder.svg"));
|
||||
|
||||
addMaterials(*lib, modelTree, folderIcon, icon, param);
|
||||
addMaterials(*lib, materialTree, folderIcon, icon, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -616,8 +619,7 @@ void MaterialTreeWidget::addRecents(QStandardItem* parent)
|
||||
for (auto& uuid : _recents) {
|
||||
try {
|
||||
auto material = getMaterialManager().getMaterial(uuid);
|
||||
|
||||
QIcon icon = QIcon(material->getLibrary()->getIconPath());
|
||||
QIcon icon(material->getLibrary()->getIconPath());
|
||||
auto card = new QStandardItem(icon, material->getName());
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
card->setData(QVariant(uuid), Qt::UserRole);
|
||||
@@ -634,8 +636,7 @@ void MaterialTreeWidget::addFavorites(QStandardItem* parent)
|
||||
for (auto& uuid : _favorites) {
|
||||
try {
|
||||
auto material = getMaterialManager().getMaterial(uuid);
|
||||
|
||||
QIcon icon = QIcon(material->getLibrary()->getIconPath());
|
||||
QIcon icon(material->getLibrary()->getIconPath());
|
||||
auto card = new QStandardItem(icon, material->getName());
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
card->setData(QVariant(uuid), Qt::UserRole);
|
||||
@@ -657,9 +658,8 @@ void MaterialTreeWidget::addMaterials(
|
||||
auto childParam = param->GetGroup(parent.text().toStdString().c_str());
|
||||
for (auto& mat : *modelTree) {
|
||||
auto nodePtr = mat.second;
|
||||
if (nodePtr->getType() == Materials::MaterialTreeNode::DataNode) {
|
||||
auto material = nodePtr->getData();
|
||||
QString uuid = material->getUUID();
|
||||
if (nodePtr->getType() == Materials::MaterialTreeNode::NodeType::DataNode) {
|
||||
QString uuid = nodePtr->getUUID();
|
||||
|
||||
auto card = new QStandardItem(icon, mat.first);
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled);
|
||||
|
||||
@@ -48,7 +48,6 @@
|
||||
|
||||
namespace MatGui
|
||||
{
|
||||
class CommandManager;
|
||||
class WidgetFactoryInst;
|
||||
class MaterialTreeWidgetPy;
|
||||
|
||||
@@ -207,17 +206,13 @@ private:
|
||||
int _recentMax;
|
||||
MaterialTreeWidgetPy* pyTreeWidget {nullptr};
|
||||
|
||||
Materials::MaterialManager _materialManager;
|
||||
|
||||
// friends
|
||||
friend class Gui::WidgetFactoryInst;
|
||||
|
||||
protected:
|
||||
// bool m_Restored = false;
|
||||
|
||||
Materials::MaterialManager& getMaterialManager()
|
||||
{
|
||||
return _materialManager;
|
||||
return Materials::MaterialManager::getManager();
|
||||
}
|
||||
|
||||
void getFavorites();
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
#include <Gui/WaitCursor.h>
|
||||
|
||||
#include <Mod/Material/App/Exceptions.h>
|
||||
#include <Mod/Material/App/MaterialLibrary.h>
|
||||
#include <Mod/Material/App/ModelManager.h>
|
||||
#include <Mod/Material/App/ModelUuids.h>
|
||||
|
||||
@@ -89,7 +90,7 @@ void MaterialsEditor::setup()
|
||||
Gui::WaitCursor wc;
|
||||
ui->setupUi(this);
|
||||
|
||||
_warningIcon = QIcon(QLatin1String(":/icons/Warning.svg"));
|
||||
_warningIcon = QIcon(QStringLiteral(":/icons/Warning.svg"));
|
||||
|
||||
getFavorites();
|
||||
getRecents();
|
||||
@@ -108,7 +109,7 @@ void MaterialsEditor::setup()
|
||||
|
||||
resize(width, height);
|
||||
|
||||
ui->buttonURL->setIcon(QIcon(QLatin1String(":/icons/internet-web-browser.svg")));
|
||||
ui->buttonURL->setIcon(QIcon(QStringLiteral(":/icons/internet-web-browser.svg")));
|
||||
|
||||
connect(ui->standardButtons->button(QDialogButtonBox::Ok),
|
||||
&QPushButton::clicked,
|
||||
@@ -214,7 +215,7 @@ void MaterialsEditor::addFavorite(const QString& uuid)
|
||||
{
|
||||
// Ensure it is a material. New, unsaved materials will not be
|
||||
try {
|
||||
auto material = _materialManager.getMaterial(uuid);
|
||||
auto material = Materials::MaterialManager::getManager().getMaterial(uuid);
|
||||
Q_UNUSED(material)
|
||||
}
|
||||
catch (const Materials::MaterialNotFound&) {
|
||||
@@ -299,7 +300,7 @@ void MaterialsEditor::addRecent(const QString& uuid)
|
||||
{
|
||||
// Ensure it is a material. New, unsaved materials will not be
|
||||
try {
|
||||
auto material = _materialManager.getMaterial(uuid);
|
||||
auto material = Materials::MaterialManager::getManager().getMaterial(uuid);
|
||||
Q_UNUSED(material)
|
||||
}
|
||||
catch (const Materials::MaterialNotFound&) {
|
||||
@@ -429,7 +430,7 @@ void MaterialsEditor::onAppearanceAdd(bool checked)
|
||||
if (dialog.exec() == QDialog::Accepted) {
|
||||
QString selected = dialog.selectedModel();
|
||||
_material->addAppearance(selected);
|
||||
auto model = getModelManager().getModel(selected);
|
||||
auto model = Materials::ModelManager::getManager().getModel(selected);
|
||||
if (selected == Materials::ModelUUIDs::ModelUUID_Rendering_Basic
|
||||
|| model->inherits(Materials::ModelUUIDs::ModelUUID_Rendering_Basic)) {
|
||||
// Add default appearance properties
|
||||
@@ -497,7 +498,7 @@ void MaterialsEditor::setMaterialDefaults()
|
||||
_material->setLicense(QLatin1String(name));
|
||||
|
||||
// Empty materials will have no parent
|
||||
_materialManager.dereference(_material);
|
||||
Materials::MaterialManager::getManager().dereference(_material);
|
||||
|
||||
updateMaterial();
|
||||
_material->resetEditState();
|
||||
@@ -665,18 +666,22 @@ void MaterialsEditor::saveMaterialTree(const Base::Reference<ParameterGrp>& para
|
||||
void MaterialsEditor::addMaterials(
|
||||
QStandardItem& parent,
|
||||
const std::shared_ptr<std::map<QString, std::shared_ptr<Materials::MaterialTreeNode>>>
|
||||
modelTree,
|
||||
materialTree,
|
||||
const QIcon& folderIcon,
|
||||
const QIcon& icon,
|
||||
const Base::Reference<ParameterGrp>& param)
|
||||
{
|
||||
auto childParam = param->GetGroup(parent.text().toStdString().c_str());
|
||||
auto tree = ui->treeMaterials;
|
||||
for (auto& mat : *modelTree) {
|
||||
for (auto& mat : *materialTree) {
|
||||
std::shared_ptr<Materials::MaterialTreeNode> nodePtr = mat.second;
|
||||
if (nodePtr->getType() == Materials::MaterialTreeNode::DataNode) {
|
||||
if (nodePtr->getType() == Materials::MaterialTreeNode::NodeType::DataNode) {
|
||||
QString uuid = nodePtr->getUUID();
|
||||
auto material = nodePtr->getData();
|
||||
QString uuid = material->getUUID();
|
||||
if (!material) {
|
||||
material = Materials::MaterialManager::getManager().getMaterial(uuid);
|
||||
nodePtr->setData(material);
|
||||
}
|
||||
|
||||
QIcon matIcon = icon;
|
||||
if (material->isOldFormat()) {
|
||||
@@ -697,7 +702,9 @@ void MaterialsEditor::addMaterials(
|
||||
addExpanded(tree, &parent, node, childParam);
|
||||
node->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||
auto treeMap = nodePtr->getFolder();
|
||||
addMaterials(*node, treeMap, folderIcon, icon, childParam);
|
||||
// if (treeMap) {
|
||||
addMaterials(*node, treeMap, folderIcon, icon, childParam);
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -800,14 +807,15 @@ void MaterialsEditor::addRecents(QStandardItem* parent)
|
||||
for (auto& uuid : _recents) {
|
||||
try {
|
||||
auto material = getMaterialManager().getMaterial(uuid);
|
||||
// if (material->getLibrary()->isLocal()) {
|
||||
QIcon icon = QIcon(material->getLibrary()->getIconPath());
|
||||
auto card = new QStandardItem(icon, libraryPath(material));
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled
|
||||
| Qt::ItemIsDropEnabled);
|
||||
card->setData(QVariant(uuid), Qt::UserRole);
|
||||
|
||||
QIcon icon = QIcon(material->getLibrary()->getIconPath());
|
||||
auto card = new QStandardItem(icon, libraryPath(material));
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled
|
||||
| Qt::ItemIsDropEnabled);
|
||||
card->setData(QVariant(uuid), Qt::UserRole);
|
||||
|
||||
addExpanded(tree, parent, card);
|
||||
addExpanded(tree, parent, card);
|
||||
// }
|
||||
}
|
||||
catch (const Materials::MaterialNotFound&) {
|
||||
}
|
||||
@@ -820,11 +828,10 @@ void MaterialsEditor::addFavorites(QStandardItem* parent)
|
||||
for (auto& uuid : _favorites) {
|
||||
try {
|
||||
auto material = getMaterialManager().getMaterial(uuid);
|
||||
|
||||
QIcon icon = QIcon(material->getLibrary()->getIconPath());
|
||||
auto card = new QStandardItem(icon, libraryPath(material));
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled
|
||||
| Qt::ItemIsDropEnabled);
|
||||
| Qt::ItemIsDropEnabled);
|
||||
card->setData(QVariant(uuid), Qt::UserRole);
|
||||
|
||||
addExpanded(tree, parent, card);
|
||||
@@ -856,12 +863,12 @@ void MaterialsEditor::fillMaterialTree()
|
||||
addRecents(lib);
|
||||
}
|
||||
|
||||
auto libraries = getMaterialManager().getMaterialLibraries();
|
||||
auto libraries = getMaterialManager().getLibraries();
|
||||
for (const auto& library : *libraries) {
|
||||
auto modelTree = getMaterialManager().getMaterialTree(library);
|
||||
auto materialTree = getMaterialManager().getMaterialTree(library);
|
||||
|
||||
bool showLibraries = _filterOptions.includeEmptyLibraries();
|
||||
if (!_filterOptions.includeEmptyLibraries() && modelTree->size() > 0) {
|
||||
if (!_filterOptions.includeEmptyLibraries() && materialTree->size() > 0) {
|
||||
showLibraries = true;
|
||||
}
|
||||
|
||||
@@ -873,7 +880,7 @@ void MaterialsEditor::fillMaterialTree()
|
||||
QIcon icon(library->getIconPath());
|
||||
QIcon folderIcon(QStringLiteral(":/icons/folder.svg"));
|
||||
|
||||
addMaterials(*lib, modelTree, folderIcon, icon, param);
|
||||
addMaterials(*lib, materialTree, folderIcon, icon, param);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -901,11 +908,11 @@ bool MaterialsEditor::updateTexturePreview() const
|
||||
{
|
||||
bool hasImage = false;
|
||||
QImage image;
|
||||
//double scaling = 99.0;
|
||||
// double scaling = 99.0;
|
||||
if (_material->hasModel(Materials::ModelUUIDs::ModelUUID_Rendering_Texture)) {
|
||||
// First try loading an embedded image
|
||||
try {
|
||||
auto property = _material->getAppearanceProperty(QLatin1String("TextureImage"));
|
||||
auto property = _material->getAppearanceProperty(QStringLiteral("TextureImage"));
|
||||
if (!property->isNull()) {
|
||||
// Base::Console().Log("Has 'TextureImage'\n");
|
||||
auto propertyValue = property->getString();
|
||||
@@ -922,7 +929,7 @@ bool MaterialsEditor::updateTexturePreview() const
|
||||
// If no embedded image, load from a path
|
||||
if (!hasImage) {
|
||||
try {
|
||||
auto property = _material->getAppearanceProperty(QLatin1String("TexturePath"));
|
||||
auto property = _material->getAppearanceProperty(QStringLiteral("TexturePath"));
|
||||
if (!property->isNull()) {
|
||||
// Base::Console().Log("Has 'TexturePath'\n");
|
||||
auto filePath = property->getString();
|
||||
@@ -940,10 +947,10 @@ bool MaterialsEditor::updateTexturePreview() const
|
||||
|
||||
// Apply any scaling
|
||||
try {
|
||||
auto property = _material->getAppearanceProperty(QLatin1String("TextureScaling"));
|
||||
auto property = _material->getAppearanceProperty(QStringLiteral("TextureScaling"));
|
||||
if (!property->isNull()) {
|
||||
//scaling = property->getFloat();
|
||||
// Base::Console().Log("Has 'TextureScaling' = %g\n", scaling);
|
||||
// scaling = property->getFloat();
|
||||
// Base::Console().Log("Has 'TextureScaling' = %g\n", scaling);
|
||||
}
|
||||
}
|
||||
catch (const Materials::PropertyNotFound&) {
|
||||
@@ -959,43 +966,43 @@ bool MaterialsEditor::updateTexturePreview() const
|
||||
|
||||
bool MaterialsEditor::updateMaterialPreview() const
|
||||
{
|
||||
if (_material->hasAppearanceProperty(QLatin1String("AmbientColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("AmbientColor"));
|
||||
if (_material->hasAppearanceProperty(QStringLiteral("AmbientColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QStringLiteral("AmbientColor"));
|
||||
_rendered->setAmbientColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetAmbientColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QLatin1String("DiffuseColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("DiffuseColor"));
|
||||
if (_material->hasAppearanceProperty(QStringLiteral("DiffuseColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QStringLiteral("DiffuseColor"));
|
||||
_rendered->setDiffuseColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetDiffuseColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QLatin1String("SpecularColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("SpecularColor"));
|
||||
if (_material->hasAppearanceProperty(QStringLiteral("SpecularColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QStringLiteral("SpecularColor"));
|
||||
_rendered->setSpecularColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetSpecularColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QLatin1String("EmissiveColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QLatin1String("EmissiveColor"));
|
||||
if (_material->hasAppearanceProperty(QStringLiteral("EmissiveColor"))) {
|
||||
QString color = _material->getAppearanceValueString(QStringLiteral("EmissiveColor"));
|
||||
_rendered->setEmissiveColor(getColorHash(color, 255));
|
||||
}
|
||||
else {
|
||||
_rendered->resetEmissiveColor();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QLatin1String("Shininess"))) {
|
||||
double value = _material->getAppearanceValue(QLatin1String("Shininess")).toDouble();
|
||||
if (_material->hasAppearanceProperty(QStringLiteral("Shininess"))) {
|
||||
double value = _material->getAppearanceValue(QStringLiteral("Shininess")).toDouble();
|
||||
_rendered->setShininess(value);
|
||||
}
|
||||
else {
|
||||
_rendered->resetShininess();
|
||||
}
|
||||
if (_material->hasAppearanceProperty(QLatin1String("Transparency"))) {
|
||||
double value = _material->getAppearanceValue(QLatin1String("Transparency")).toDouble();
|
||||
if (_material->hasAppearanceProperty(QStringLiteral("Transparency"))) {
|
||||
double value = _material->getAppearanceValue(QStringLiteral("Transparency")).toDouble();
|
||||
_rendered->setTransparency(value);
|
||||
}
|
||||
else {
|
||||
@@ -1065,7 +1072,7 @@ void MaterialsEditor::updateMaterialAppearance()
|
||||
for (auto it = models->begin(); it != models->end(); it++) {
|
||||
QString uuid = *it;
|
||||
try {
|
||||
auto model = getModelManager().getModel(uuid);
|
||||
auto model = Materials::ModelManager::getManager().getModel(uuid);
|
||||
QString name = model->getName();
|
||||
|
||||
auto modelRoot = new QStandardItem(name);
|
||||
@@ -1129,7 +1136,7 @@ void MaterialsEditor::updateMaterialProperties()
|
||||
for (auto it = models->begin(); it != models->end(); it++) {
|
||||
QString uuid = *it;
|
||||
try {
|
||||
auto model = getModelManager().getModel(uuid);
|
||||
auto model = Materials::ModelManager::getManager().getModel(uuid);
|
||||
QString name = model->getName();
|
||||
|
||||
auto modelRoot = new QStandardItem(name);
|
||||
@@ -1177,14 +1184,14 @@ QString MaterialsEditor::libraryPath(const std::shared_ptr<Materials::Material>&
|
||||
QString path;
|
||||
auto library = material->getLibrary();
|
||||
if (library) {
|
||||
path = QStringLiteral("/%1/%2")
|
||||
.arg(material->getLibrary()->getName())
|
||||
.arg(material->getDirectory());
|
||||
}
|
||||
else {
|
||||
path = QStringLiteral("%1").arg(material->getDirectory());
|
||||
path = QStringLiteral("/%1/%2/%3")
|
||||
.arg(library->getName())
|
||||
.arg(material->getDirectory())
|
||||
.arg(material->getName());
|
||||
return path;
|
||||
}
|
||||
|
||||
path = QStringLiteral("%1/%2").arg(material->getDirectory()).arg(material->getName());
|
||||
return path;
|
||||
}
|
||||
|
||||
@@ -1192,7 +1199,7 @@ void MaterialsEditor::updateMaterialGeneral()
|
||||
{
|
||||
QString parentString;
|
||||
try {
|
||||
auto parent = _materialManager.getParent(_material);
|
||||
auto parent = Materials::MaterialManager::getManager().getParent(_material);
|
||||
parentString = libraryPath(parent);
|
||||
}
|
||||
catch (const Materials::MaterialNotFound&) {
|
||||
|
||||
@@ -82,11 +82,7 @@ public:
|
||||
|
||||
Materials::MaterialManager& getMaterialManager()
|
||||
{
|
||||
return _materialManager;
|
||||
}
|
||||
Materials::ModelManager& getModelManager()
|
||||
{
|
||||
return _modelManager;
|
||||
return Materials::MaterialManager::getManager();
|
||||
}
|
||||
|
||||
static QString libraryPath(const std::shared_ptr<Materials::Material>& material);
|
||||
@@ -114,8 +110,6 @@ protected:
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_MaterialsEditor> ui;
|
||||
Materials::MaterialManager _materialManager;
|
||||
Materials::ModelManager _modelManager;
|
||||
std::shared_ptr<Materials::Material> _material;
|
||||
AppearancePreview* _rendered;
|
||||
bool _materialSelected;
|
||||
|
||||
@@ -239,7 +239,7 @@ void ModelSelect::addModels(
|
||||
auto tree = ui->treeModels;
|
||||
for (auto& mod : *modelTree) {
|
||||
std::shared_ptr<Materials::ModelTreeNode> nodePtr = mod.second;
|
||||
if (nodePtr->getType() == Materials::ModelTreeNode::DataNode) {
|
||||
if (nodePtr->getType() == Materials::ModelTreeNode::NodeType::DataNode) {
|
||||
auto model = nodePtr->getData();
|
||||
QString uuid = model->getUUID();
|
||||
|
||||
@@ -265,9 +265,9 @@ void ModelSelect::addRecents(QStandardItem* parent)
|
||||
auto tree = ui->treeModels;
|
||||
for (auto& uuid : _recents) {
|
||||
try {
|
||||
auto model = getModelManager().getModel(uuid);
|
||||
auto model = Materials::ModelManager::getManager().getModel(uuid);
|
||||
|
||||
if (getModelManager().passFilter(_filter, model->getType())) {
|
||||
if (Materials::ModelManager::getManager().passFilter(_filter, model->getType())) {
|
||||
QIcon icon = QIcon(model->getLibrary()->getIconPath());
|
||||
auto card = new QStandardItem(icon, model->getName());
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled
|
||||
@@ -287,9 +287,9 @@ void ModelSelect::addFavorites(QStandardItem* parent)
|
||||
auto tree = ui->treeModels;
|
||||
for (auto& uuid : _favorites) {
|
||||
try {
|
||||
auto model = getModelManager().getModel(uuid);
|
||||
auto model = Materials::ModelManager::getManager().getModel(uuid);
|
||||
|
||||
if (getModelManager().passFilter(_filter, model->getType())) {
|
||||
if (Materials::ModelManager::getManager().passFilter(_filter, model->getType())) {
|
||||
QIcon icon = QIcon(model->getLibrary()->getIconPath());
|
||||
auto card = new QStandardItem(icon, model->getName());
|
||||
card->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled
|
||||
@@ -339,13 +339,13 @@ void ModelSelect::fillTree()
|
||||
addExpanded(tree, model, lib);
|
||||
addRecents(lib);
|
||||
|
||||
auto libraries = getModelManager().getModelLibraries();
|
||||
auto libraries = Materials::ModelManager::getManager().getLibraries();
|
||||
for (auto& library : *libraries) {
|
||||
lib = new QStandardItem(library->getName());
|
||||
lib->setFlags(Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled);
|
||||
addExpanded(tree, model, lib);
|
||||
|
||||
auto modelTree = getModelManager().getModelTree(library, _filter);
|
||||
auto modelTree = Materials::ModelManager::getManager().getModelTree(library, _filter);
|
||||
addModels(*lib, modelTree, QIcon(library->getIconPath()));
|
||||
}
|
||||
}
|
||||
@@ -426,7 +426,7 @@ void ModelSelect::updateModelProperties(std::shared_ptr<Materials::Model> model)
|
||||
|
||||
void ModelSelect::updateMaterialModel(const QString& uuid)
|
||||
{
|
||||
auto model = getModelManager().getModel(uuid);
|
||||
auto model = Materials::ModelManager::getManager().getModel(uuid);
|
||||
|
||||
// Update the general information
|
||||
ui->editName->setText(model->getName());
|
||||
|
||||
@@ -91,14 +91,9 @@ private:
|
||||
void setColumnWidths(QTableView* table);
|
||||
void updateModelProperties(std::shared_ptr<Materials::Model> model);
|
||||
void createModelProperties();
|
||||
Materials::ModelManager& getModelManager()
|
||||
{
|
||||
return _modelManager;
|
||||
}
|
||||
|
||||
Materials::ModelFilter _filter;
|
||||
std::unique_ptr<Ui_ModelSelect> ui;
|
||||
Materials::ModelManager _modelManager;
|
||||
QString _selected;
|
||||
std::list<QString> _favorites;
|
||||
std::list<QString> _recents;
|
||||
|
||||
Reference in New Issue
Block a user