From a1a751831708804d3e94fbb6824be9749f84d3a2 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 4 Jul 2016 11:49:27 +0200 Subject: [PATCH 1/5] Switch materials/nozzle when the printer signals a material/nozzle change CURA-491 --- cura/MachineManagerModel.py | 50 ++++++++++++++++++++++++++++++++++--- cura/PrinterOutputDevice.py | 36 ++++++++++++++++++++++++++ 2 files changed, 83 insertions(+), 3 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index 76786efe61..aa8b08cf7b 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -4,6 +4,7 @@ from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty, pyqtSignal from UM.Application import Application from UM.Preferences import Preferences +from UM.Logger import Logger import UM.Settings from UM.Settings.Validator import ValidatorState @@ -51,6 +52,7 @@ class MachineManagerModel(QObject): active_machine_id = Preferences.getInstance().getValue("cura/active_machine") + self._printer_output_devices = [] Application.getInstance().getOutputDeviceManager().outputDevicesChanged.connect(self._onOutputDevicesChanged) if active_machine_id != "": @@ -72,8 +74,53 @@ class MachineManagerModel(QObject): outputDevicesChanged = pyqtSignal() def _onOutputDevicesChanged(self): + for printer_output_device in self._printer_output_devices: + printer_output_device.HotendIdChanged.disconnect(self._onHotendIdChanged) + printer_output_device.MaterialIdChanged.disconnect(self._onMaterialIdChanged) + + self._printer_output_devices.clear() + + for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices(): + if isinstance(printer_output_device, PrinterOutputDevice): + self._printer_output_devices.append(printer_output_device) + printer_output_device.HotendIdChanged.connect(self._onHotendIdChanged) + printer_output_device.MaterialIdChanged.connect(self._onMaterialIdChanged) + self.outputDevicesChanged.emit() + @pyqtProperty("QVariantList", notify = outputDevicesChanged) + def printerOutputDevices(self): + return self._printer_output_devices + + def _onHotendIdChanged(self, index, hotend_id): + if not self._global_container_stack: + return + + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = self._global_container_stack.getBottom().getId(), name = hotend_id) + if containers: + ExtruderManager.ExtruderManager.getInstance().setActiveExtruderIndex(index) + Logger.log("d", "Setting hotend variant of hotend %d to %s" % (index, containers[0].getId())) + self._updateVariantContainer(containers[0]) + + def _onMaterialIdChanged(self, index, material_id): + # TODO: fix this + if not self._global_container_stack: + return + + if self._global_container_stack.getMetaDataEntry("has_machine_materials", False): + definition_id = "fdmprinter" + else: + definition_id = self._global_container_stack.getBottom().getId() + + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "material", defintion = definition_id, GUID = material_id) + if containers: + ExtruderManager.ExtruderManager.getInstance().setActiveExtruderIndex(index) + Logger.log("d", "Setting material of hotend %d to %s" % (index, containers[0].getId())) + self._updateMaterialContainer(containers[0]) + else: + Logger.log("w", "No material definition found for printer definition %s and GUID %s" % (definition_id, material_id)) + + def _onGlobalPropertyChanged(self, key, property_name): if property_name == "value": self.globalValueChanged.emit() @@ -165,9 +212,6 @@ class MachineManagerModel(QObject): Application.getInstance().setGlobalContainerStack(new_global_stack) - @pyqtProperty("QVariantList", notify = outputDevicesChanged) - def printerOutputDevices(self): - return [printer_output_device for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices() if isinstance(printer_output_device, PrinterOutputDevice)] ## Create a name that is not empty and unique # \param container_type \type{string} Type of the container (machine, quality, ...) diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 7f6e51e1fd..6504de9cdd 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -24,6 +24,8 @@ class PrinterOutputDevice(QObject, OutputDevice): self._num_extruders = 1 self._hotend_temperatures = [0] * self._num_extruders self._target_hotend_temperatures = [0] * self._num_extruders + self._material_ids = [""] * self._num_extruders + self._hotend_ids = [""] * self._num_extruders self._progress = 0 self._head_x = 0 self._head_y = 0 @@ -57,6 +59,12 @@ class PrinterOutputDevice(QObject, OutputDevice): # Signal to be emitted when head position is changed (x,y,z) headPositionChanged = pyqtSignal() + # Signal to be emitted when either of the material ids is changed + MaterialIdChanged = pyqtSignal(int, str, arguments = ["index", "id"]) + + # Signal to be emitted when either of the hotend ids is changed + HotendIdChanged = pyqtSignal(int, str, arguments = ["index", "id"]) + # Signal that is emitted every time connection state is changed. # it also sends it's own device_id (for convenience sake) connectionStateChanged = pyqtSignal(str) @@ -212,6 +220,34 @@ class PrinterOutputDevice(QObject, OutputDevice): self._hotend_temperatures[index] = temperature self.hotendTemperaturesChanged.emit() + @pyqtProperty("QVariantList", notify = MaterialIdChanged) + def materialIds(self): + return self._material_ids + + ## Protected setter for the current material id. + # /param index Index of the extruder + # /param material_id id of the material + def _setMaterialId(self, index, material_id): + if material_id and material_id != "" and material_id != self._material_ids[index]: + Logger.log("d", "Setting material id of hotend %d to %s" % (index, material_id)) + self._material_ids[index] = material_id + self.MaterialIdChanged.emit(index, material_id) + + + @pyqtProperty("QVariantList", notify = HotendIdChanged) + def hotendIds(self): + return self._hotend_ids + + ## Protected setter for the current hotend id. + # /param index Index of the extruder + # /param hotend_id id of the hotend + def _setHotendId(self, index, hotend_id): + if hotend_id and hotend_id != "" and hotend_id != self._hotend_ids[index]: + Logger.log("d", "Setting hotend id of hotend %d to %s" % (index, hotend_id)) + self._hotend_ids[index] = hotend_id + self.HotendIdChanged.emit(index, hotend_id) + + ## Attempt to establish connection def connect(self): raise NotImplementedError("connect needs to be implemented") From 8e58e88511057e11fb92556edb47bbeb0cba69cf Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 4 Jul 2016 11:50:15 +0200 Subject: [PATCH 2/5] Update GUIDs to match the GUIDs in the official repository CURA-491 --- resources/materials/generic_abs.xml.fdm_material | 2 +- resources/materials/generic_cpe.xml.fdm_material | 2 +- resources/materials/generic_pla.xml.fdm_material | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/resources/materials/generic_abs.xml.fdm_material b/resources/materials/generic_abs.xml.fdm_material index 654b06d221..82b2f1f963 100644 --- a/resources/materials/generic_abs.xml.fdm_material +++ b/resources/materials/generic_abs.xml.fdm_material @@ -9,7 +9,7 @@ Generic PLA profile. Serves as an example file, data in this file is not correct ABS Generic - 506c9f0d-e3aa-4bd4-b2d2-23e2425b1aa9 + 60636bb4-518f-42e7-8237-fe77b194ebe0 0 #FF0000 diff --git a/resources/materials/generic_cpe.xml.fdm_material b/resources/materials/generic_cpe.xml.fdm_material index bbe6e328d2..8ac4dd8c71 100644 --- a/resources/materials/generic_cpe.xml.fdm_material +++ b/resources/materials/generic_cpe.xml.fdm_material @@ -9,7 +9,7 @@ Generic PLA profile. Serves as an example file, data in this file is not correct CPE Generic - 506c9f0d-e3aa-4bd4-b2d2-23e2425b1aa9 + 12f41353-1a33-415e-8b4f-a775a6c70cc6 0 #0000FF diff --git a/resources/materials/generic_pla.xml.fdm_material b/resources/materials/generic_pla.xml.fdm_material index 40432d5849..2f8fa165cf 100644 --- a/resources/materials/generic_pla.xml.fdm_material +++ b/resources/materials/generic_pla.xml.fdm_material @@ -9,7 +9,7 @@ Generic PLA profile. Serves as an example file, data in this file is not correct PLA Generic - 506c9f0d-e3aa-4bd4-b2d2-23e2425b1aa9 + 86a89ceb-4159-47f6-ab97-e9953803d70f 0 #00FF00 From 24c5a39962d369eca85f37c1ac481d9c0e9c3358 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 4 Jul 2016 13:43:13 +0200 Subject: [PATCH 3/5] Fix logic and typo for material container filtering CURA-491 --- cura/MachineManagerModel.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index aa8b08cf7b..9a08aaa348 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -107,12 +107,11 @@ class MachineManagerModel(QObject): if not self._global_container_stack: return + definition_id = "fdmprinter" if self._global_container_stack.getMetaDataEntry("has_machine_materials", False): - definition_id = "fdmprinter" - else: definition_id = self._global_container_stack.getBottom().getId() - containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "material", defintion = definition_id, GUID = material_id) + containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "material", definition = definition_id, GUID = material_id) if containers: ExtruderManager.ExtruderManager.getInstance().setActiveExtruderIndex(index) Logger.log("d", "Setting material of hotend %d to %s" % (index, containers[0].getId())) From 3d86ffd57542afa863778dc408e6b446224f4258 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 4 Jul 2016 15:14:36 +0200 Subject: [PATCH 4/5] Fix switching materials/nozzles in Cura when the materials/nozzles in the printer change CURA-491 --- cura/MachineManagerModel.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index 9a08aaa348..d9903744ee 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -98,9 +98,9 @@ class MachineManagerModel(QObject): containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "variant", definition = self._global_container_stack.getBottom().getId(), name = hotend_id) if containers: - ExtruderManager.ExtruderManager.getInstance().setActiveExtruderIndex(index) Logger.log("d", "Setting hotend variant of hotend %d to %s" % (index, containers[0].getId())) - self._updateVariantContainer(containers[0]) + ExtruderManager.ExtruderManager.getInstance().setActiveExtruderIndex(index) + self.setActiveVariant(containers[0].getId()) def _onMaterialIdChanged(self, index, material_id): # TODO: fix this @@ -113,9 +113,9 @@ class MachineManagerModel(QObject): containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(type = "material", definition = definition_id, GUID = material_id) if containers: - ExtruderManager.ExtruderManager.getInstance().setActiveExtruderIndex(index) Logger.log("d", "Setting material of hotend %d to %s" % (index, containers[0].getId())) - self._updateMaterialContainer(containers[0]) + ExtruderManager.ExtruderManager.getInstance().setActiveExtruderIndex(index) + self.setActiveMaterial(containers[0].getId()) else: Logger.log("w", "No material definition found for printer definition %s and GUID %s" % (definition_id, material_id)) From dd249206ac15db31eda2cd0fc5990c6871619387 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Mon, 4 Jul 2016 16:33:32 +0200 Subject: [PATCH 5/5] Fix codestyle CURA-491 --- cura/MachineManagerModel.py | 8 ++++---- cura/PrinterOutputDevice.py | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/cura/MachineManagerModel.py b/cura/MachineManagerModel.py index d9903744ee..92ce86804d 100644 --- a/cura/MachineManagerModel.py +++ b/cura/MachineManagerModel.py @@ -75,16 +75,16 @@ class MachineManagerModel(QObject): def _onOutputDevicesChanged(self): for printer_output_device in self._printer_output_devices: - printer_output_device.HotendIdChanged.disconnect(self._onHotendIdChanged) - printer_output_device.MaterialIdChanged.disconnect(self._onMaterialIdChanged) + printer_output_device.hotendIdChanged.disconnect(self._onHotendIdChanged) + printer_output_device.materialIdChanged.disconnect(self._onMaterialIdChanged) self._printer_output_devices.clear() for printer_output_device in Application.getInstance().getOutputDeviceManager().getOutputDevices(): if isinstance(printer_output_device, PrinterOutputDevice): self._printer_output_devices.append(printer_output_device) - printer_output_device.HotendIdChanged.connect(self._onHotendIdChanged) - printer_output_device.MaterialIdChanged.connect(self._onMaterialIdChanged) + printer_output_device.hotendIdChanged.connect(self._onHotendIdChanged) + printer_output_device.materialIdChanged.connect(self._onMaterialIdChanged) self.outputDevicesChanged.emit() diff --git a/cura/PrinterOutputDevice.py b/cura/PrinterOutputDevice.py index 6504de9cdd..212ed86ab3 100644 --- a/cura/PrinterOutputDevice.py +++ b/cura/PrinterOutputDevice.py @@ -60,10 +60,10 @@ class PrinterOutputDevice(QObject, OutputDevice): headPositionChanged = pyqtSignal() # Signal to be emitted when either of the material ids is changed - MaterialIdChanged = pyqtSignal(int, str, arguments = ["index", "id"]) + materialIdChanged = pyqtSignal(int, str, arguments = ["index", "id"]) # Signal to be emitted when either of the hotend ids is changed - HotendIdChanged = pyqtSignal(int, str, arguments = ["index", "id"]) + hotendIdChanged = pyqtSignal(int, str, arguments = ["index", "id"]) # Signal that is emitted every time connection state is changed. # it also sends it's own device_id (for convenience sake) @@ -220,7 +220,7 @@ class PrinterOutputDevice(QObject, OutputDevice): self._hotend_temperatures[index] = temperature self.hotendTemperaturesChanged.emit() - @pyqtProperty("QVariantList", notify = MaterialIdChanged) + @pyqtProperty("QVariantList", notify = materialIdChanged) def materialIds(self): return self._material_ids @@ -231,10 +231,10 @@ class PrinterOutputDevice(QObject, OutputDevice): if material_id and material_id != "" and material_id != self._material_ids[index]: Logger.log("d", "Setting material id of hotend %d to %s" % (index, material_id)) self._material_ids[index] = material_id - self.MaterialIdChanged.emit(index, material_id) + self.materialIdChanged.emit(index, material_id) - @pyqtProperty("QVariantList", notify = HotendIdChanged) + @pyqtProperty("QVariantList", notify = hotendIdChanged) def hotendIds(self): return self._hotend_ids @@ -245,7 +245,7 @@ class PrinterOutputDevice(QObject, OutputDevice): if hotend_id and hotend_id != "" and hotend_id != self._hotend_ids[index]: Logger.log("d", "Setting hotend id of hotend %d to %s" % (index, hotend_id)) self._hotend_ids[index] = hotend_id - self.HotendIdChanged.emit(index, hotend_id) + self.hotendIdChanged.emit(index, hotend_id) ## Attempt to establish connection