From 19f500834b20b167fc3e172c3193eb2235cfadb3 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 2 Jun 2020 11:48:11 +0200 Subject: [PATCH 1/4] Remove use of deprecated extruders property Still had this one uncommitted from last Friday. I tested it and it works the same way. --- cura/UI/MachineSettingsManager.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cura/UI/MachineSettingsManager.py b/cura/UI/MachineSettingsManager.py index 671bb0ece0..1d2604c3c9 100644 --- a/cura/UI/MachineSettingsManager.py +++ b/cura/UI/MachineSettingsManager.py @@ -60,7 +60,6 @@ class MachineSettingsManager(QObject): # In other words: only continue for the UM2 (extended), but not for the UM2+ return - extruder_positions = list(global_stack.extruders.keys()) has_materials = global_stack.getProperty("machine_gcode_flavor", "value") != "UltiGCode" material_node = None @@ -73,12 +72,11 @@ class MachineSettingsManager(QObject): global_stack.removeMetaDataEntry("has_materials") # set materials - for position in extruder_positions: + for position, extruder in enumerate(global_stack.extruderList): if has_materials: - extruder = global_stack.extruderList[int(position)] approximate_diameter = extruder.getApproximateMaterialDiameter() variant_node = ContainerTree.getInstance().machines[global_stack.definition.getId()].variants[extruder.variant.getName()] material_node = variant_node.preferredMaterial(approximate_diameter) - machine_manager.setMaterial(position, material_node) + machine_manager.setMaterial(str(position), material_node) self.forceUpdate() From be814535e979c28734460a697da879dbe2b41a07 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 2 Jun 2020 11:53:52 +0200 Subject: [PATCH 2/4] Avoid hitting the prime blob when Z hop is enabled If Z hop is enabled, it would move to the height of the Z hop at the start of the print, in order to hop for the initial travel move. Cura sort of assumes that this hop is going up and so it's safe to do, but in reality this hop is going down due to the starting process in the firmware. As a hotfix, we'll just move away from that blob so that we don't hit it even if you enable Z hops. --- resources/definitions/ultimaker2.def.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/definitions/ultimaker2.def.json b/resources/definitions/ultimaker2.def.json index 68b41feeb0..3980baba31 100644 --- a/resources/definitions/ultimaker2.def.json +++ b/resources/definitions/ultimaker2.def.json @@ -23,7 +23,7 @@ "overrides": { "machine_name": { "default_value": "Ultimaker 2" }, "machine_start_gcode" : { - "value": "\"\" if machine_gcode_flavor == \"UltiGCode\" else \"G21 ;metric values\\nG90 ;absolute positioning\\nM82 ;set extruder to absolute mode\\nM107 ;start with the fan off\\nG28 Z0 ;move Z to bottom endstops\\nG28 X0 Y0 ;move X/Y to endstops\\nG1 X15 Y0 F4000 ;move X/Y to front of printer\\nG1 Z15.0 F9000 ;move the platform to 15mm\\nG92 E0 ;zero the extruded length\\nG1 F200 E10 ;extrude 10 mm of feed stock\\nG92 E0 ;zero the extruded length again\\nG1 F9000\\n;Put printing message on LCD screen\\nM117 Printing...\"" + "value": "\"G0 F3000 Y50 ;avoid prime blob\" if machine_gcode_flavor == \"UltiGCode\" else \"G21 ;metric values\\nG90 ;absolute positioning\\nM82 ;set extruder to absolute mode\\nM107 ;start with the fan off\\nG28 Z0 ;move Z to bottom endstops\\nG28 X0 Y0 ;move X/Y to endstops\\nG1 X15 Y0 F4000 ;move X/Y to front of printer\\nG1 Z15.0 F9000 ;move the platform to 15mm\\nG92 E0 ;zero the extruded length\\nG1 F200 E10 ;extrude 10 mm of feed stock\\nG92 E0 ;zero the extruded length again\\nG1 Y50 F9000\\n;Put printing message on LCD screen\\nM117 Printing...\"" }, "machine_end_gcode" : { "value": "\";Version _2.6 of the firmware can abort the print too early if the file ends\\n;too soon. However if the file hasn't ended yet because there are comments at\\n;the end of the file, it won't abort yet. Therefore we have to put at least 512\\n;bytes at the end of the g-code so that the file is not yet finished by the\\n;time that the motion planner gets flushed. With firmware version _3.3 this\\n;should be fixed, so this comment wouldn't be necessary any more. Now we have\\n;to pad this text to make precisely 512 bytes.\" if machine_gcode_flavor == \"UltiGCode\" else \"M104 S0 ;extruder heater off\\nM140 S0 ;heated bed heater off (if you have it)\\nG91 ;relative positioning\\nG1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure\\nG1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more\\nG28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way\\nM84 ;steppers off\\nG90 ;absolute positioning\\n;Version _2.6 of the firmware can abort the print too early if the file ends\\n;too soon. However if the file hasn't ended yet because there are comments at\\n;the end of the file, it won't abort yet. Therefore we have to put at least 512\\n;bytes at the end of the g-code so that the file is not yet finished by the\\n;time that the motion planner gets flushed. With firmware version _3.3 this\\n;should be fixed, so this comment wouldn't be necessary any more. Now we have\\n;to pad this text to make precisely 512 bytes.\"" From 825a34d41844236cf65d16aaea5435490b300346 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 2 Jun 2020 13:46:17 +0200 Subject: [PATCH 3/4] Mock the extruderList Otherwise the list of extruders becomes a MagicMock. Adding a list to a MagicMock is again a MagicMock, and when iterating over that it doesn't result in any iterations. As a result, the for loop that clears all user containers didn't clear anything and the test failed. --- tests/Settings/TestContainerManager.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Settings/TestContainerManager.py b/tests/Settings/TestContainerManager.py index ff23b727e6..19ade68f68 100644 --- a/tests/Settings/TestContainerManager.py +++ b/tests/Settings/TestContainerManager.py @@ -14,6 +14,7 @@ class TestContainerManager(TestCase): self._application = MagicMock() self._container_registry = MagicMock() self._machine_manager = MagicMock() + self._machine_manager.activeMachine.extruderList = [MagicMock(name="Left Extruder Mock"), MagicMock(name="Right Extruder Mock")] self._mocked_mime = MagicMock() self._mocked_mime.preferredSuffix = "omg" From 93c84d5bc053bd091f007ed77542833b91f195dc Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Tue, 2 Jun 2020 14:01:09 +0200 Subject: [PATCH 4/4] Mock the limit_to_extruder property with an actual value This is necessary because our code now converts this to an integer. Mocks can't be converted to an integer, so the sub-magic-mock here can't be used. We need to provide something that can be cast to an integer. --- tests/Settings/TestSettingOverrideDecorator.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/Settings/TestSettingOverrideDecorator.py b/tests/Settings/TestSettingOverrideDecorator.py index 50c23c409f..4976ce81a7 100644 --- a/tests/Settings/TestSettingOverrideDecorator.py +++ b/tests/Settings/TestSettingOverrideDecorator.py @@ -24,6 +24,11 @@ def setting_override_decorator(): def test_onSettingValueChanged(setting_override_decorator): + def mock_getRawProperty(key, property_name, *args, **kwargs): + if property_name == "limit_to_extruder": + return "-1" + return MagicMock(name="rawProperty") + container_registry.findContainerStacks().__getitem__().getRawProperty = mock_getRawProperty # On creation the needs slicing should be called once (as it being added should trigger a reslice) assert application.getBackend().needsSlicing.call_count == 1 with patch("UM.Application.Application.getInstance", MagicMock(return_value=application)):