Materials: Model Manager External Interface (#20825)

* Materials: Model Manager External Interface

Implement the ModelManagerExternal class for the external Materials
interface.

This is part of the ongoing merges of code to support external material
interfaces. In this PR the ModelManagerExternal class is implemented,
along with changes to supporting classes required for this class.

* Apply reviewer feedback
This commit is contained in:
David Carter
2025-04-28 08:29:04 -07:00
committed by GitHub
parent 56d3ca7b72
commit a6ffcf63b6
14 changed files with 676 additions and 110 deletions

View File

@@ -34,7 +34,7 @@
using namespace Materials;
std::shared_ptr<std::list<std::shared_ptr<ModelLibrary>>> ModelManagerLocal::_libraryList = nullptr;
std::shared_ptr<std::list<std::shared_ptr<ModelLibraryLocal>>> ModelManagerLocal::_libraryList = nullptr;
std::shared_ptr<std::map<QString, std::shared_ptr<Model>>> ModelManagerLocal::_modelMap = nullptr;
QMutex ModelManagerLocal::_mutex;
@@ -53,7 +53,7 @@ void ModelManagerLocal::initLibraries()
if (_modelMap == nullptr) {
_modelMap = std::make_shared<std::map<QString, std::shared_ptr<Model>>>();
if (_libraryList == nullptr) {
_libraryList = std::make_shared<std::list<std::shared_ptr<ModelLibrary>>>();
_libraryList = std::make_shared<std::list<std::shared_ptr<ModelLibraryLocal>>>();
}
// Load the libraries
@@ -98,7 +98,8 @@ void ModelManagerLocal::refresh()
std::shared_ptr<std::list<std::shared_ptr<ModelLibrary>>> ModelManagerLocal::getLibraries()
{
return _libraryList;
return reinterpret_cast<std::shared_ptr<std::list<std::shared_ptr<ModelLibrary>>>&>(
_libraryList);
}
void ModelManagerLocal::createLibrary(const QString& libraryName,
@@ -113,10 +114,8 @@ void ModelManagerLocal::createLibrary(const QString& libraryName,
}
}
auto modelLibrary = std::make_shared<ModelLibrary>(libraryName, directory, icon, readOnly);
auto modelLibrary = std::make_shared<ModelLibraryLocal>(libraryName, directory, icon, readOnly);
_libraryList->push_back(modelLibrary);
// This needs to be persisted somehow
}
void ModelManagerLocal::renameLibrary(const QString& libraryName, const QString& newName)
@@ -192,19 +191,27 @@ std::shared_ptr<Model> ModelManagerLocal::getModelByPath(const QString& path) co
QString cleanPath = QDir::cleanPath(path);
for (auto& library : *_libraryList) {
if (cleanPath.startsWith(library->getDirectory())) {
return library->getModelByPath(cleanPath);
if (library->isLocal()) {
auto localLibrary = std::static_pointer_cast<Materials::ModelLibraryLocal> (library);
if (cleanPath.startsWith(localLibrary->getDirectory())) {
return localLibrary->getModelByPath(cleanPath);
}
}
}
throw MaterialNotFound();
throw ModelNotFound();
}
std::shared_ptr<Model> ModelManagerLocal::getModelByPath(const QString& path,
const QString& lib) const
{
auto library = getLibrary(lib); // May throw LibraryNotFound
return library->getModelByPath(path); // May throw ModelNotFound
if (library->isLocal()) {
auto localLibrary = std::static_pointer_cast<Materials::ModelLibraryLocal>(library);
return localLibrary->getModelByPath(path); // May throw ModelNotFound
}
throw ModelNotFound();
}
std::shared_ptr<ModelLibrary> ModelManagerLocal::getLibrary(const QString& name) const