Merge branch 'fix_create_material' of https://github.com/fieldOfView/Cura into fieldOfView-fix_create_material

This commit is contained in:
Ghostkeeper 2017-05-17 16:28:17 +02:00
commit e64e7daec5
No known key found for this signature in database
GPG Key ID: C5F96EE2BC0F7E75

View File

@ -700,7 +700,7 @@ class ContainerManager(QObject):
self._container_registry.addContainer(duplicated_container) self._container_registry.addContainer(duplicated_container)
return self._getMaterialContainerIdForActiveMachine(new_id) return self._getMaterialContainerIdForActiveMachine(new_id)
## Create a new material by cloning Generic PLA and setting the GUID to something unqiue ## Create a new material by cloning Generic PLA for the current material diameter and setting the GUID to something unqiue
# #
# \return \type{str} the id of the newly created container. # \return \type{str} the id of the newly created container.
@pyqtSlot(result = str) @pyqtSlot(result = str)
@ -708,14 +708,25 @@ class ContainerManager(QObject):
# Ensure all settings are saved. # Ensure all settings are saved.
Application.getInstance().saveSettings() Application.getInstance().saveSettings()
containers = self._container_registry.findInstanceContainers(id="generic_pla") global_stack = Application.getInstance().getGlobalContainerStack()
if not global_stack:
return ""
approximate_diameter = round(global_stack.getProperty("material_diameter", "value"))
containers = self._container_registry.findInstanceContainers(id = "generic_pla*", approximate_diameter = approximate_diameter)
if not containers: if not containers:
Logger.log("d", "Unable to create a new material by cloning generic_pla, because it doesn't exist.") Logger.log("d", "Unable to create a new material by cloning Generic PLA, because it cannot be found for the material diameter for this machine.")
return ""
base_file = containers[0].getMetaDataEntry("base_file")
containers = self._container_registry.findInstanceContainers(id = base_file)
if not containers:
Logger.log("d", "Unable to create a new material by cloning Generic PLA, because the base file for Generic PLA for this machine can not be found.")
return "" return ""
# Create a new ID & container to hold the data. # Create a new ID & container to hold the data.
new_id = self._container_registry.uniqueName("custom_material") new_id = self._container_registry.uniqueName("custom_material")
container_type = type(containers[0]) # Could be either a XMLMaterialProfile or a InstanceContainer container_type = type(containers[0]) # Always XMLMaterialProfile, since we specifically clone the base_file
duplicated_container = container_type(new_id) duplicated_container = container_type(new_id)
# Instead of duplicating we load the data from the basefile again. # Instead of duplicating we load the data from the basefile again.