From a6acf4a4af1dfd6bd6f4537891754d3b9612482b Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Fri, 19 Jan 2018 10:34:04 +0100 Subject: [PATCH] CURA-4829 Do not save the quality changes profile in the GCode if the containers are empty. Change the message when trying to import a GCode as a profile, but not profile was stored. --- cura/Settings/CuraContainerRegistry.py | 4 ++++ plugins/GCodeWriter/GCodeWriter.py | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index b945ec0609..b73bec11a7 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -205,6 +205,7 @@ class CuraContainerRegistry(ContainerRegistry): profile_reader = plugin_registry.getPluginObject(plugin_id) try: profile_or_list = profile_reader.read(file_name) # Try to open the file with the profile reader. + print except Exception as e: # Note that this will fail quickly. That is, if any profile reader throws an exception, it will stop reading. It will only continue reading if the reader returned None. Logger.log("e", "Failed to import profile from %s: %s while using profile reader. Got exception %s", file_name,profile_reader.getPluginId(), str(e)) @@ -245,6 +246,9 @@ class CuraContainerRegistry(ContainerRegistry): return {"status": "ok", "message": catalog.i18nc("@info:status", "Successfully imported profile {0}", profile_or_list[0].getName())} + # This message is throw when the profile reader doesn't find any profile in the file + return {"status": "error", "message": catalog.i18nc("@info:status", "File {0} does not contain any valid profile.", file_name)} + # If it hasn't returned by now, none of the plugins loaded the profile successfully. return {"status": "error", "message": catalog.i18nc("@info:status", "Profile {0} has an unknown file type or is corrupted.", file_name)} diff --git a/plugins/GCodeWriter/GCodeWriter.py b/plugins/GCodeWriter/GCodeWriter.py index 95c48c4d9e..2dfaf5aef7 100644 --- a/plugins/GCodeWriter/GCodeWriter.py +++ b/plugins/GCodeWriter/GCodeWriter.py @@ -107,7 +107,7 @@ class GCodeWriter(MeshWriter): prefix_length = len(prefix) container_with_profile = stack.qualityChanges - if not container_with_profile: + if container_with_profile.getId() == "empty_quality_changes": Logger.log("e", "No valid quality profile found, not writing settings to GCode!") return "" @@ -123,9 +123,9 @@ class GCodeWriter(MeshWriter): serialized = flat_global_container.serialize() data = {"global_quality": serialized} - for extruder in sorted(ExtruderManager.getInstance().getMachineExtruders(stack.getId()), key = lambda k: k.getMetaDataEntry("position")): + for extruder in sorted(stack.extruders.values(), key = lambda k: k.getMetaDataEntry("position")): extruder_quality = extruder.qualityChanges - if not extruder_quality: + if extruder_quality.getId() == "empty_quality_changes": Logger.log("w", "No extruder quality profile found, not writing quality for extruder %s to file!", extruder.getId()) continue flat_extruder_quality = self._createFlattenedContainerInstance(extruder.getTop(), extruder_quality)