File size: 5,300 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 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | // SPDX-License-Identifier: LGPL-2.1-or-later
/***************************************************************************
* 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_LIBRARY_H
#define MATERIAL_LIBRARY_H
#include <QDir>
#include <QByteArray>
#include <QString>
#include <Base/BaseClass.h>
#include <Mod/Material/MaterialGlobal.h>
namespace Materials
{
class MaterialsExport Library: public Base::BaseClass
{
TYPESYSTEM_HEADER_WITH_OVERRIDE();
public:
Library() = default;
Library(const Library &other) = default;
Library(const QString& libraryName, const QString& icon, bool readOnly = true);
Library(const QString& libraryName, const QByteArray& icon, bool readOnly);
Library(const QString& libraryName,
const QString& dir,
const QString& iconPath,
bool readOnly = true);
~Library() override = default;
bool isLocal() const;
void setLocal(bool local);
QString getName() const
{
return _name;
}
void setName(const QString& newName)
{
_name = newName;
}
bool isName(const QString& name)
{
return (_name == name);
}
QByteArray getIcon() const
{
return _icon;
}
static QByteArray getIcon(const QString& iconPath);
void setIcon(const QByteArray& icon)
{
_icon = icon;
}
void setIcon(const QString& iconPath);
bool hasIcon() const
{
return !_icon.isEmpty();
}
bool isReadOnly() const
{
return _readOnly;
}
void setReadOnly(bool readOnly)
{
_readOnly = readOnly;
}
QString getDirectory() const
{
return _directory;
}
void setDirectory(const QString& directory)
{
_directory = directory;
}
QString getDirectoryPath() const
{
return QDir(_directory).absolutePath();
}
bool operator==(const Library& library) const;
bool operator!=(const Library& library) const
{
return !operator==(library);
}
QString getLocalPath(const QString& path) const;
QString getRelativePath(const QString& path) const;
QString getLibraryPath(const QString& path, const QString& filename) const;
bool isRoot(const QString& path) const;
// Validate a remote library against this one (a local library)
void validate(const Library& remote) const;
private:
QString _name;
QString _directory;
QByteArray _icon;
bool _readOnly;
bool _local;
QByteArray loadByteArrayFromFile(const QString& filePath) const;
};
class MaterialsExport LibraryObject
{
public:
LibraryObject(const QString& uuid, const QString& path, const QString& name)
: _uuid(uuid)
, _path(path)
, _name(name)
{}
LibraryObject(const std::string& uuid, const std::string& path, const std::string& name)
: _uuid(QString::fromStdString(uuid))
, _path(QString::fromStdString(path))
, _name(QString::fromStdString(name))
{}
~LibraryObject() = default;
void setUUID(const QString& uuid)
{
_uuid = uuid;
}
void setUUID(const std::string& uuid)
{
_uuid = QString::fromStdString(uuid);
}
QString getUUID() const
{
return _uuid;
}
void setPath(const QString& path)
{
_path = path;
}
void setPath(const std::string& path)
{
_path = QString::fromStdString(path);
}
QString getPath() const
{
return _path;
}
void setName(const QString& name)
{
_name = name;
}
void setName(const std::string& name)
{
_name = QString::fromStdString(name);
}
QString getName() const
{
return _name;
}
private:
QString _uuid;
QString _path;
QString _name;
};
} // namespace Materials
#endif // MATERIAL_LIBRARY_H
|