From 3e2e1336823f85a3f6cb3b23c10b898153cafb88 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 6 Dec 2017 10:37:06 +0100 Subject: [PATCH 1/3] Add type hinting for getMachineManager I like it when my IDE can give me hints, so return types are important. Contributes to issue CURA-4243. --- cura/CuraApplication.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From 80f4c9181d87c39cb7417ff32d05bf4cbbcf4701 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 6 Dec 2017 10:40:58 +0100 Subject: [PATCH 2/3] Correct variant name when duplicating materials It needs to be the variant name (swapping spaces for underscores) to be consistent with the deserialize functions. Contributes to issue CURA-4243. --- cura/Settings/ContainerManager.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cura/Settings/ContainerManager.py b/cura/Settings/ContainerManager.py index c552a6fe8c..e3b14bf210 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 From ec36424a4d2a3ea6721e741f33404d5a824a28b4 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 6 Dec 2017 10:42:02 +0100 Subject: [PATCH 3/3] Update UserProfilesModel when metadata of materials changes The metadata may influence which profiles are being shown. Contributes to issue CURA-4243. --- cura/Settings/UserProfilesModel.py | 37 +++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) 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