mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-13 17:19:00 +08:00
Use implementation from MaterialManagementModel
The material manager is deprecated now. Contributes to issue CURA-6600.
This commit is contained in:
parent
0eb3c5c0d6
commit
9392a3553c
@ -311,38 +311,16 @@ class MaterialManager(QObject):
|
|||||||
return "ERROR"
|
return "ERROR"
|
||||||
return result
|
return result
|
||||||
|
|
||||||
# Create a new material by cloning Generic PLA for the current material diameter and generate a new GUID.
|
## Create a new material by cloning the preferred material for the current
|
||||||
# Returns the ID of the newly created material.
|
# material diameter and generate a new GUID.
|
||||||
|
#
|
||||||
|
# The material type is explicitly left to be the one from the preferred
|
||||||
|
# material, since this allows the user to still have SOME profiles to work
|
||||||
|
# with.
|
||||||
|
# \return The ID of the newly created material.
|
||||||
@pyqtSlot(result = str)
|
@pyqtSlot(result = str)
|
||||||
def createMaterial(self) -> str:
|
def createMaterial(self) -> str:
|
||||||
from UM.i18n import i18nCatalog
|
return cura.CuraApplication.CuraApplication.getMaterialManagementModel().createMaterial()
|
||||||
catalog = i18nCatalog("cura")
|
|
||||||
# Ensure all settings are saved.
|
|
||||||
application = cura.CuraApplication.CuraApplication.getInstance()
|
|
||||||
application.saveSettings()
|
|
||||||
|
|
||||||
machine_manager = application.getMachineManager()
|
|
||||||
extruder_stack = machine_manager.activeStack
|
|
||||||
|
|
||||||
global_stack = application.getGlobalContainerStack()
|
|
||||||
if global_stack is None:
|
|
||||||
Logger.log("e", "Global stack not present!")
|
|
||||||
return "ERROR"
|
|
||||||
machine_definition = global_stack.definition
|
|
||||||
root_material_id = machine_definition.getMetaDataEntry("preferred_material", default = "generic_pla")
|
|
||||||
|
|
||||||
approximate_diameter = str(extruder_stack.approximateMaterialDiameter)
|
|
||||||
root_material_id = self.getRootMaterialIDForDiameter(root_material_id, approximate_diameter)
|
|
||||||
|
|
||||||
# Create a new ID & container to hold the data.
|
|
||||||
new_id = CuraContainerRegistry.getInstance().uniqueName("custom_material")
|
|
||||||
new_metadata = {"name": catalog.i18nc("@label", "Custom Material"),
|
|
||||||
"brand": catalog.i18nc("@label", "Custom"),
|
|
||||||
"GUID": str(uuid.uuid4()),
|
|
||||||
}
|
|
||||||
|
|
||||||
self.duplicateMaterialByRootId(root_material_id, new_base_id = new_id, new_metadata = new_metadata)
|
|
||||||
return new_id
|
|
||||||
|
|
||||||
@pyqtSlot(str)
|
@pyqtSlot(str)
|
||||||
def addFavorite(self, root_material_id: str) -> None:
|
def addFavorite(self, root_material_id: str) -> None:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user