From dadcf45f45b9b777d1d18d2a878be9b66a68a6fa Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 6 Oct 2016 10:44:38 +0200 Subject: [PATCH 1/2] Added extra checks & logging to 3mf reader CURA-382 --- plugins/3MFReader/ThreeMFReader.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/3MFReader/ThreeMFReader.py b/plugins/3MFReader/ThreeMFReader.py index d24845d8a1..52c45652c6 100644 --- a/plugins/3MFReader/ThreeMFReader.py +++ b/plugins/3MFReader/ThreeMFReader.py @@ -77,6 +77,7 @@ class ThreeMFReader(MeshReader): mesh_data = mesh_builder.build().getTransformed(rotation) if not len(mesh_data.getVertices()): + Logger.log("d", "One of the objects does not have vertices. Skipping it.") continue # This object doesn't have data, so skip it. node.setMeshData(mesh_data) @@ -114,6 +115,7 @@ class ThreeMFReader(MeshReader): try: node.getBoundingBox() # Selftest - There might be more functions that should fail except: + Logger.log("w", "Bounding box test for object failed. Skipping this object") continue result.addChild(node) @@ -125,7 +127,10 @@ class ThreeMFReader(MeshReader): group_decorator = GroupDecorator() result.addDecorator(group_decorator) elif len(objects) == 1: - result = result.getChildren()[0] # Only one object found, return that. + if result.getChildren(): + result = result.getChildren()[0] # Only one object found, return that. + else: # we failed to load any data + return None except Exception as e: Logger.log("e", "exception occured in 3mf reader: %s", e) try: # Selftest - There might be more functions that should fail From fb24e552680d557be223b53f7461a5fe91dbe414 Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 6 Oct 2016 13:49:43 +0200 Subject: [PATCH 2/2] _getBasicMaterial now correctly filters on variants as well CURA-2248 --- cura/QualityManager.py | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/cura/QualityManager.py b/cura/QualityManager.py index fc3b9b4f53..64b01aaa31 100644 --- a/cura/QualityManager.py +++ b/cura/QualityManager.py @@ -93,8 +93,8 @@ class QualityManager: # Fall back to using generic materials and qualities if nothing could be found. if not result and material_containers and len(material_containers) == 1: - basic_material = self._getBasicMaterial(material_containers[0]) - result = self._getFilteredContainersForStack(machine_definition, [basic_material], **criteria) + basic_materials = self._getBasicMaterials(material_containers[0]) + result = self._getFilteredContainersForStack(machine_definition, basic_materials, **criteria) return result[0] if result else None ## Find all suitable qualities for a combination of machine and material. @@ -106,8 +106,8 @@ class QualityManager: criteria = {"type": "quality" } result = self._getFilteredContainersForStack(machine_definition, [material_container], **criteria) if not result: - basic_material = self._getBasicMaterial(material_container) - result = self._getFilteredContainersForStack(machine_definition, [basic_material], **criteria) + basic_materials = self._getBasicMaterials(material_container) + result = self._getFilteredContainersForStack(machine_definition, basic_materials, **criteria) return result ## Find all quality changes for a machine. @@ -157,16 +157,24 @@ class QualityManager: # # This tries to find a generic or basic version of the given material. # \param material_container \type{InstanceContainer} the material - # \return \type{Option[InstanceContainer]} the basic material or None if one could not be found. - def _getBasicMaterial(self, material_container): + # \return \type{List[InstanceContainer]} the basic material or None if one could not be found. + def _getBasicMaterials(self, material_container): base_material = material_container.getMetaDataEntry("material") + if material_container.getDefinition().getMetaDataEntry("has_machine_quality"): + definition_id = material_container.getDefinition().getMetaDataEntry("quality_definition", material_container.getDefinition().getId()) + else: + definition_id = "fdmprinter" + if base_material: # There is a basic material specified - criteria = { "type": "material", "name": base_material, "definition": "fdmprinter" } + criteria = { "type": "material", "name": base_material, "definition": definition_id } containers = UM.Settings.ContainerRegistry.getInstance().findInstanceContainers(**criteria) - return containers[0] if containers else None + containers = [basic_material for basic_material in containers if + basic_material.getMetaDataEntry("variant") == material_container.getMetaDataEntry( + "variant")] + return containers - return None + return [] def _getFilteredContainers(self, **kwargs): return self._getFilteredContainersForStack(None, None, **kwargs)