Download src/Mod/Material/App/MaterialAPI/MaterialManagerExternal.py from AbdulElahGwaith/FreeCAD: direct link, hf CLI and curl.
- Browser
- Download file 9.59 kB
-
https://huggingface.co/AbdulElahGwaith/FreeCAD/resolve/main/src/Mod/Material/App/MaterialAPI/MaterialManagerExternal.py
- Command line
-
hf download hf://AbdulElahGwaith/FreeCAD/src/Mod/Material/App/MaterialAPI/MaterialManagerExternal.py
-
curl -L -o MaterialManagerExternal.py https://huggingface.co/AbdulElahGwaith/FreeCAD/resolve/main/src/Mod/Material/App/MaterialAPI/MaterialManagerExternal.py
9.59 kB
| # SPDX-License-Identifier: LGPL-2.1-or-later | |
| # *************************************************************************** | |
| # * Copyright (c) 2024 David Carter <dcarter@davidcarter.ca> * | |
| # * * | |
| # * This program is free software; you can redistribute it and/or modify * | |
| # * it under the terms of the GNU Lesser General Public License (LGPL) * | |
| # * as published by the Free Software Foundation; either version 2 of * | |
| # * the License, or (at your option) any later version. * | |
| # * for detail see the LICENCE text file. * | |
| # * * | |
| # * This program 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 Library General Public License for more details. * | |
| # * * | |
| # * You should have received a copy of the GNU Library General Public * | |
| # * License along with this program; if not, write to the Free Software * | |
| # * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * | |
| # * USA * | |
| # * * | |
| # *************************************************************************** | |
| __author__ = "David Carter" | |
| __url__ = "https://www.davesrocketshop.com" | |
| from abc import ABC, abstractmethod | |
| from dataclasses import dataclass | |
| import Materials | |
| class MaterialLibraryType: | |
| name: str | |
| icon: bytes | |
| readOnly: bool | |
| class MaterialLibraryObjectType: | |
| UUID: str | |
| path: str | |
| name: str | |
| class ModelObjectType: | |
| libraryName: str | |
| model: Materials.Model | |
| class MaterialObjectType: | |
| libraryName: str | |
| material: Materials.Material | |
| class MaterialManagerExternal(ABC): | |
| """Abstract base class for all external material managers | |
| Any external interface should be derivedfrom this base class.""" | |
| def APIVersion(cls) -> tuple: | |
| """Returns a tuple of 3 integers describing the API version | |
| The version returned should be the latest supported version. This method | |
| allows the interface to use older modules.""" | |
| return (1, 0, 0) | |
| # | |
| # Library methods | |
| # | |
| def libraries(self) -> list[MaterialLibraryType]: | |
| """Returns a list of libraries managed by this interface | |
| The list contains a series of tuples describing all libraries managed by | |
| this module. Each tuple contains the library name, icon, a boolean to indicate | |
| if it is a read only library.""" | |
| def modelLibraries(self) -> list[MaterialLibraryType]: | |
| """Returns a list of libraries managed by this interface | |
| The list contains a series of tuples describing all libraries managed by | |
| this module. Each tuple contains the library name, icon, and a boolean to indicate | |
| if it is a read only library. | |
| This differs from the libraries() function in that it only returns libraries | |
| containing model objects.""" | |
| def materialLibraries(self) -> list[MaterialLibraryType]: | |
| """Returns a list of libraries managed by this interface | |
| The list contains a series of tuples describing all libraries managed by | |
| this module. Each tuple contains the library name, icon, and a boolean to indicate | |
| if it is a read only library. | |
| This differs from the libraries() function in that it only returns libraries | |
| containing material objects.""" | |
| def getLibrary(self, libraryName: str) -> MaterialLibraryType: | |
| """Get the library | |
| Retrieve the library with the given name""" | |
| def createLibrary(self, libraryName: str, icon: bytes, readOnly: bool) -> None: | |
| """Create a new library | |
| Create a new library with the given name.""" | |
| def renameLibrary(self, oldName: str, newName: str) -> None: | |
| """Rename an existing library | |
| Change the name of an existing library""" | |
| def changeIcon(self, libraryName: str, icon: bytes) -> None: | |
| """Change the library icon | |
| Change the library icon""" | |
| def removeLibrary(self, libraryName: str) -> None: | |
| """Delete a library and its contents | |
| Deletes the library and any models or materials it contains""" | |
| def libraryModels(self, libraryName: str) -> list[MaterialLibraryObjectType]: | |
| """Returns a list of models managed by this library | |
| Each list entry is a tuple containing the UUID, path, and name of the model""" | |
| def libraryMaterials(self, libraryName: str, | |
| materialFilter: Materials.MaterialFilter = None, | |
| options: Materials.MaterialFilterOptions = None) -> \ | |
| list[MaterialLibraryObjectType]: | |
| """Returns a list of materials managed by this library | |
| Each list entry is a tuple containing the UUID, path, and name of the material""" | |
| def libraryFolders(self, libraryName: str) -> list[str]: | |
| """Returns a list of folders managed by this library | |
| This will return a list of all folders in the library including empty folders""" | |
| # | |
| # Folder methods | |
| # | |
| def createFolder(self, libraryName: str, path: str) -> None: | |
| """Create a new folder in the given library""" | |
| def renameFolder(self, libraryName: str, oldPath: str, newPath: str) -> None: | |
| """Rename the folder""" | |
| def deleteRecursive(self, libraryName: str, path: str) -> None: | |
| """Delete the folder and all of its contents""" | |
| # | |
| # Model methods | |
| # | |
| def getModel(self, uuid: str) -> ModelObjectType: | |
| """Retrieve a model given its UUID""" | |
| def addModel(self, libraryName: str, path: str, model: Materials.Model) -> None: | |
| """Add a model to a library in the given folder. The folder path is relative to | |
| the library and will be created if it doesn't already exist. | |
| This will throw a DatabaseModelExistsError exception if the model already exists.""" | |
| def migrateModel(self, libraryName: str, path: str, model: Materials.Model) -> None: | |
| """Add the model to the library. | |
| If the model already exists, then no action is performed.""" | |
| def updateModel(self, libraryName: str, path: str, model: Materials.Model) -> None: | |
| """Update the given model""" | |
| def setModelPath(self, libraryName: str, path: str, uuid: str) -> None: | |
| """Change the model path within the library""" | |
| def renameModel(self, libraryName: str, name: str, uuid: str) -> None: | |
| """Change the model name""" | |
| def moveModel(self, libraryName: str, path: str, uuid: str) -> None: | |
| """Move a model across libraries | |
| Move the model to the desired path in a different library. This should also | |
| remove the model from the old library if that library is managed by this | |
| interface""" | |
| def removeModel(self, uuid: str) -> None: | |
| """Remove the model from the library""" | |
| # | |
| # Material methods | |
| # | |
| def getMaterial(self, uuid: str) -> MaterialObjectType: | |
| """ Retrieve a material given its UUID """ | |
| def addMaterial(self, libraryName: str, path: str, material: Materials.Material) -> None: | |
| """Add a material to a library in the given folder. The folder path is relative to | |
| the library and will be created if it doesn't already exist. | |
| This will throw a DatabaseMaterialExistsError exception if the model already exists.""" | |
| def migrateMaterial(self, libraryName: str, path: str, material: Materials.Material) -> None: | |
| """Add the material to the library in the given folder. The folder path is relative to | |
| the library and will be created if it doesn't already exist. | |
| If the material already exists, then no action is performed.""" | |
| def updateMaterial(self, libraryName: str, path: str, material: Materials.Material) -> None: | |
| """Update the given material""" | |
| def setMaterialPath(self, libraryName: str, path: str, uuid: str) -> None: | |
| """Change the material path within the library""" | |
| def renameMaterial(self, libraryName: str, name: str, uuid: str) -> None: | |
| """Change the material name""" | |
| def moveMaterial(self, libraryName: str, path: str, uuid: str) -> None: | |
| """Move a material across libraries | |
| Move the material to the desired path in a different library. This should also | |
| remove the material from the old library if that library is managed by this | |
| interface""" | |
| def removeMaterial(self, uuid: str) -> None: | |
| """Remove the material from the library""" | |