From e6f61f3bbc9c863e36126c277d461bd3a3d39c69 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Wed, 24 May 2017 11:38:38 +0200 Subject: [PATCH 1/3] When trying to convert None to RGBA, log it and return a usable default contributes to #1869 --- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index f7be2edc04..afd4739ecf 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -31,6 +31,9 @@ catalog = i18nCatalog("cura") # # \param color_code html color code, i.e. "#FF0000" -> red def colorCodeToRGBA(color_code): + if color_code is None: + Logger.log("w", "Unable to convert color code, returning default") + return [0, 0, 0, 1] return [ int(color_code[1:3], 16) / 255, int(color_code[3:5], 16) / 255, From ce6814d45d585bead366d6a768a62e2be3dcb749 Mon Sep 17 00:00:00 2001 From: Ghostkeeper Date: Wed, 24 May 2017 15:19:12 +0200 Subject: [PATCH 2/3] Add default for colour code of material Otherwise you get an error that the colour code could not be found. Fixes #1869. --- plugins/CuraEngineBackend/ProcessSlicedLayersJob.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py index afd4739ecf..ecaebb816d 100644 --- a/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py +++ b/plugins/CuraEngineBackend/ProcessSlicedLayersJob.py @@ -175,7 +175,7 @@ class ProcessSlicedLayersJob(Job): for extruder in extruders: material = extruder.findContainer({"type": "material"}) position = int(extruder.getMetaDataEntry("position", default="0")) # Get the position - color_code = material.getMetaDataEntry("color_code") + color_code = material.getMetaDataEntry("color_code", default="#e0e000") color = colorCodeToRGBA(color_code) material_color_map[position, :] = color else: From 9bda7dbaae87468b6e165d48333a430f91295987 Mon Sep 17 00:00:00 2001 From: Arjen Hiemstra Date: Wed, 24 May 2017 15:43:02 +0200 Subject: [PATCH 3/3] Error out when trying to import a profile witha quality_type we dont have Rather than successfully importing the profile and then not showing anything, we now display an error. Not the perfect solution but the easiest for now. Contributes to #1873 --- cura/Settings/CuraContainerRegistry.py | 43 +++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/cura/Settings/CuraContainerRegistry.py b/cura/Settings/CuraContainerRegistry.py index 7961e8db31..b159183241 100644 --- a/cura/Settings/CuraContainerRegistry.py +++ b/cura/Settings/CuraContainerRegistry.py @@ -4,6 +4,9 @@ import os import os.path import re + +from typing import Optional + from PyQt5.QtWidgets import QMessageBox from UM.Decorators import override @@ -199,8 +202,12 @@ class CuraContainerRegistry(ContainerRegistry): new_name = self.uniqueName(name_seed) if type(profile_or_list) is not list: profile = profile_or_list - self._configureProfile(profile, name_seed, new_name) - return { "status": "ok", "message": catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName()) } + + result = self._configureProfile(profile, name_seed, new_name) + if result is not None: + return {"status": "error", "message": catalog.i18nc("@info:status", "Failed to import profile from {0}: {1}", file_name, result)} + + return {"status": "ok", "message": catalog.i18nc("@info:status", "Successfully imported profile {0}", profile.getName())} else: profile_index = -1 global_profile = None @@ -230,7 +237,9 @@ class CuraContainerRegistry(ContainerRegistry): global_profile = profile profile_id = (global_container_stack.getBottom().getId() + "_" + name_seed).lower().replace(" ", "_") - self._configureProfile(profile, profile_id, new_name) + result = self._configureProfile(profile, profile_id, new_name) + if result is not None: + return {"status": "error", "message": catalog.i18nc("@info:status", "Failed to import profile from {0}: {1}", file_name, result)} profile_index += 1 @@ -244,7 +253,14 @@ class CuraContainerRegistry(ContainerRegistry): super().load() self._fixupExtruders() - def _configureProfile(self, profile, id_seed, new_name): + ## Update an imported profile to match the current machine configuration. + # + # \param profile The profile to configure. + # \param id_seed The base ID for the profile. May be changed so it does not conflict with existing containers. + # \param new_name The new name for the profile. + # + # \return None if configuring was successful or an error message if an error occurred. + def _configureProfile(self, profile: InstanceContainer, id_seed: str, new_name: str) -> Optional[str]: profile.setReadOnly(False) profile.setDirty(True) # Ensure the profiles are correctly saved @@ -257,15 +273,34 @@ class CuraContainerRegistry(ContainerRegistry): else: profile.addMetaDataEntry("type", "quality_changes") + quality_type = profile.getMetaDataEntry("quality_type") + if not quality_type: + return catalog.i18nc("@info:status", "Profile is missing a quality type.") + + quality_type_criteria = {"quality_type": quality_type} if self._machineHasOwnQualities(): profile.setDefinition(self._activeQualityDefinition()) if self._machineHasOwnMaterials(): profile.addMetaDataEntry("material", self._activeMaterialId()) + quality_type_criteria["material"] = self._activeMaterialId() + + quality_type_criteria["definition"] = profile.getDefinition().getId() + else: profile.setDefinition(ContainerRegistry.getInstance().findDefinitionContainers(id="fdmprinter")[0]) + quality_type_criteria["definition"] = "fdmprinter" + + # Check to make sure the imported profile actually makes sense in context of the current configuration. + # This prevents issues where importing a "draft" profile for a machine without "draft" qualities would report as + # successfully imported but then fail to show up. + qualities = self.findInstanceContainers(**quality_type_criteria) + if not qualities: + return catalog.i18nc("@info:status", "Could not find a quality type {0} for the current configuration.", quality_type) ContainerRegistry.getInstance().addContainer(profile) + return None + ## Gets a list of profile writer plugins # \return List of tuples of (plugin_id, meta_data). def _getIOPlugins(self, io_type):