File size: 5,152 Bytes
985c397 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | /***************************************************************************
* Copyright (c) 2023 David Carter <dcarter@david.carter.ca> *
* *
* This file is part of FreeCAD. *
* *
* FreeCAD is free software: you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as *
* published by the Free Software Foundation, either version 2.1 of the *
* License, or (at your option) any later version. *
* *
* FreeCAD is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
* Lesser General Public License for more details. *
* *
* You should have received a copy of the GNU Lesser General Public *
* License along with FreeCAD. If not, see *
* <https://www.gnu.org/licenses/>. *
* *
**************************************************************************/
#ifndef MATERIAL_MATERIALLIBRARY_H
#define MATERIAL_MATERIALLIBRARY_H
#include <memory>
#include <QDir>
#include <QString>
#include <QVariant>
#include <Base/BaseClass.h>
#include <Mod/Material/MaterialGlobal.h>
#include "Library.h"
#include "Materials.h"
#include "Model.h"
#include "ModelLibrary.h"
namespace Materials
{
class Material;
class MaterialManager;
class MaterialFilter;
class MaterialFilterOptions;
class MaterialsExport MaterialLibrary
: public Library,
public std::enable_shared_from_this<MaterialLibrary>
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
MaterialLibrary() = default;
MaterialLibrary(const QString& libraryName, const QString& icon, bool readOnly = true);
MaterialLibrary(const QString& libraryName,
const QString& dir,
const QString& iconPath,
bool readOnly = true);
MaterialLibrary(const Library& library);
MaterialLibrary(const MaterialLibrary&) = delete;
~MaterialLibrary() override = default;
virtual std::shared_ptr<std::map<QString, std::shared_ptr<MaterialTreeNode>>>
getMaterialTree(const Materials::MaterialFilter& filter,
const Materials::MaterialFilterOptions& options) const;
// Use this to get a shared_ptr for *this
std::shared_ptr<MaterialLibrary> getptr()
{
return shared_from_this();
}
};
class MaterialsExport MaterialLibraryLocal: public MaterialLibrary
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
MaterialLibraryLocal() = default;
MaterialLibraryLocal(const QString& libraryName,
const QString& dir,
const QString& iconPath,
bool readOnly = true);
~MaterialLibraryLocal() override = default;
void createFolder(const QString& path);
void renameFolder(const QString& oldPath, const QString& newPath);
void deleteRecursive(const QString& path);
std::shared_ptr<Material> saveMaterial(const std::shared_ptr<Material>& material,
const QString& path,
bool overwrite,
bool saveAsCopy,
bool saveInherited);
bool fileExists(const QString& path) const;
std::shared_ptr<Material> addMaterial(const std::shared_ptr<Material>& material,
const QString& path);
std::shared_ptr<Material> getMaterialByPath(const QString& path) const;
bool operator==(const MaterialLibrary& library) const
{
return library.isLocal() ? Library::operator==(library) : false;
}
bool operator!=(const MaterialLibrary& library) const
{
return !operator==(library);
}
bool operator==(const MaterialLibraryLocal& library) const
{
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;
std::unique_ptr<std::map<QString, std::shared_ptr<Material>>> _materialPathMap;
};
} // namespace Materials
Q_DECLARE_METATYPE(std::shared_ptr<Materials::MaterialLibrary>)
Q_DECLARE_METATYPE(std::shared_ptr<Materials::MaterialLibraryLocal>)
#endif // MATERIAL_MATERIALLIBRARY_H
|