diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index a395329552..9293a7e07b 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -725,7 +725,7 @@ class CuraApplication(QtApplication): self.exec_() - def getMachineManager(self, *args): + def getMachineManager(self, *args) -> MachineManager: if self._machine_manager is None: self._machine_manager = MachineManager.createMachineManager() return self._machine_manager diff --git a/cura/Settings/ContainerManager.py b/cura/Settings/ContainerManager.py index 2c98030cfd..6ef722e976 100644 --- a/cura/Settings/ContainerManager.py +++ b/cura/Settings/ContainerManager.py @@ -789,7 +789,8 @@ class ContainerManager(QObject): if container_to_copy.getMetaDataEntry("definition") != "fdmprinter": new_id += "_" + container_to_copy.getMetaDataEntry("definition") if container_to_copy.getMetaDataEntry("variant"): - new_id += "_" + container_to_copy.getMetaDataEntry("variant") + variant = self._container_registry.findContainers(id = container_to_copy.getMetaDataEntry("variant"))[0] + new_id += "_" + variant.getName().replace(" ", "_") if current_id == material_id: clone_of_original = new_id diff --git a/cura/Settings/UserProfilesModel.py b/cura/Settings/UserProfilesModel.py index 2db07942a7..f69c0ff7d1 100644 --- a/cura/Settings/UserProfilesModel.py +++ b/cura/Settings/UserProfilesModel.py @@ -1,7 +1,7 @@ # Copyright (c) 2017 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. -from UM.Application import Application +from UM.Application import Application from cura.QualityManager import QualityManager from cura.Settings.ProfilesModel import ProfilesModel from cura.Settings.ExtruderManager import ExtruderManager @@ -12,6 +12,16 @@ class UserProfilesModel(ProfilesModel): def __init__(self, parent = None): super().__init__(parent) + #Need to connect to the metaDataChanged signal of the active materials. + self.__current_extruders = [] + self.__current_materials = [] + + Application.getInstance().getExtruderManager().extrudersChanged.connect(self.__onExtrudersChanged) + self.__onExtrudersChanged() + self.__current_materials = [extruder.material for extruder in self.__current_extruders] + for material in self.__current_materials: + material.metaDataChanged.connect(self._onContainerChanged) + ## Fetch the list of containers to display. # # See UM.Settings.Models.InstanceContainersModel._fetchInstanceContainers(). @@ -43,3 +53,28 @@ class UserProfilesModel(ProfilesModel): qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())} return filtered_quality_changes, {} + + ## Called when a container changed on an extruder stack. + # + # If it's the material we need to connect to the metaDataChanged signal of + # that. + def __onContainerChanged(self, new_container): + #Careful not to update when a quality or quality changes profile changed! + #If you then update you're going to have an infinite recursion because the update may change the container. + if new_container.getMetaDataEntry("type") == "material": + for material in self.__current_materials: + material.metaDataChanged.disconnect(self._onContainerChanged) + self.__current_materials = [extruder.material for extruder in self.__current_extruders] + for material in self.__current_materials: + material.metaDataChanged.connect(self._onContainerChanged) + + ## Called when the current set of extruders change. + # + # This makes sure that we are listening to the signal for when the + # materials change. + def __onExtrudersChanged(self): + for extruder in self.__current_extruders: + extruder.containersChanged.disconnect(self.__onContainerChanged) + self.__current_extruders = Application.getInstance().getExtruderManager().getExtruderStacks() + for extruder in self.__current_extruders: + extruder.containersChanged.connect(self.__onContainerChanged) \ No newline at end of file