CURA-4606 fix material names for 1.75mm materials

This commit is contained in:
Jack Ha 2018-02-15 11:17:25 +01:00 committed by Lipu Fei
parent 6dc53eb741
commit 8275e506ce
12 changed files with 33 additions and 16 deletions

View File

@ -38,11 +38,17 @@ class MaterialManager(QObject):
self._fallback_materials_map = dict() # material_type -> generic material metadata self._fallback_materials_map = dict() # material_type -> generic material metadata
self._material_group_map = dict() # root_material_id -> MaterialGroup self._material_group_map = dict() # root_material_id -> MaterialGroup
self._diameter_machine_variant_material_map = dict() # diameter -> dict(machine_definition_id -> MaterialNode) self._diameter_machine_variant_material_map = dict() # diameter -> dict(machine_definition_id -> MaterialNode)
# We're using these two maps to convert between the specific diameter material id and the generic material id
# because the generic material ids are used in qualities and definitions, while the specific diameter material is meant
# i.e. generic_pla -> generic_pla_175
self._material_diameter_map = defaultdict() # root_material_id -> diameter -> root_material_id for that diameter self._material_diameter_map = defaultdict() # root_material_id -> diameter -> root_material_id for that diameter
self._diameter_material_map = dict() # material id including diameter (generic_pla_175) -> material root id (generic_pla)
# The machine definition ID for the non-machine-specific materials. # The machine definition ID for the non-machine-specific materials.
# This is used as the last fallback option if the given machine-specific material(s) cannot be found. # This is used as the last fallback option if the given machine-specific material(s) cannot be found.
self._default_machine_definition_id = "fdmprinter" self._default_machine_definition_id = "fdmprinter"
self._default_approximate_diameter_for_quality_search = "3"
self._update_timer = QTimer(self) self._update_timer = QTimer(self)
self._update_timer.setInterval(300) self._update_timer.setInterval(300)
@ -99,6 +105,7 @@ class MaterialManager(QObject):
# be for either "generic_pla" or "generic_pla_175", but not both. This map helps to get the correct material ID # be for either "generic_pla" or "generic_pla_175", but not both. This map helps to get the correct material ID
# for quality search. # for quality search.
self._material_diameter_map = defaultdict(defaultdict) self._material_diameter_map = defaultdict(defaultdict)
self._diameter_material_map = dict()
# Group the material IDs by the same name, material, brand, and color but with different diameters. # Group the material IDs by the same name, material, brand, and color but with different diameters.
material_group_dict = dict() material_group_dict = dict()
@ -116,10 +123,17 @@ class MaterialManager(QObject):
approximate_diameter = root_material_metadata.get("approximate_diameter") approximate_diameter = root_material_metadata.get("approximate_diameter")
material_group_dict[key_data][approximate_diameter] = root_material_metadata["id"] material_group_dict[key_data][approximate_diameter] = root_material_metadata["id"]
# Map [root_material_id][diameter] -> root_material_id for this diameter
for data_dict in material_group_dict.values(): for data_dict in material_group_dict.values():
for rmid1 in data_dict.values(): for root_material_id1 in data_dict.values():
for ad2, rmid2 in data_dict.items(): for approximate_diameter2, root_material_id2 in data_dict.items():
self._material_diameter_map[rmid1][ad2] = rmid2 self._material_diameter_map[root_material_id1][approximate_diameter2] = root_material_id2
default_root_material_id = data_dict.get(self._default_approximate_diameter_for_quality_search)
if default_root_material_id is None:
default_root_material_id = list(data_dict.values())[0] # no default diameter present, just take "the" only one
for root_material_id in data_dict.values():
self._diameter_material_map[root_material_id] = default_root_material_id
# Map #4 # Map #4
# "machine" -> "variant_name" -> "root material ID" -> specific material InstanceContainer # "machine" -> "variant_name" -> "root material ID" -> specific material InstanceContainer
@ -181,6 +195,9 @@ class MaterialManager(QObject):
def getRootMaterialIDForDiameter(self, root_material_id: str, approximate_diameter: str) -> str: def getRootMaterialIDForDiameter(self, root_material_id: str, approximate_diameter: str) -> str:
return self._material_diameter_map.get(root_material_id).get(approximate_diameter, root_material_id) return self._material_diameter_map.get(root_material_id).get(approximate_diameter, root_material_id)
def getRootMaterialIDWithoutDiameter(self, root_material_id: str) -> str:
return self._diameter_material_map.get(root_material_id)
# #
# Return a dict with all root material IDs (k) and ContainerNodes (v) that's suitable for the given setup. # Return a dict with all root material IDs (k) and ContainerNodes (v) that's suitable for the given setup.
# #
@ -264,8 +281,12 @@ class MaterialManager(QObject):
# This function returns the generic root material ID for the given material type, where material types are "PLA", # This function returns the generic root material ID for the given material type, where material types are "PLA",
# "ABS", etc. # "ABS", etc.
# #
def getFallbackMaterialForType(self, material_type: str) -> dict: def getFallbackMaterialId(self, material_type: str) -> str:
# For safety # For safety
if material_type not in self._fallback_materials_map: if material_type not in self._fallback_materials_map:
raise RuntimeError("Material type [%s] is not in the fallback materials table." % material_type) raise RuntimeError("Material type [%s] is not in the fallback materials table." % material_type)
return self._fallback_materials_map[material_type] fallback_material = self._fallback_materials_map[material_type]
if fallback_material:
return self.getRootMaterialIDWithoutDiameter(fallback_material["id"])
else:
return None

View File

@ -286,13 +286,15 @@ class QualityManager(QObject):
if extruder.material.getId() != "empty_material": if extruder.material.getId() != "empty_material":
has_material = True has_material = True
root_material_id = extruder.material.getMetaDataEntry("base_file") root_material_id = extruder.material.getMetaDataEntry("base_file")
# Convert possible generic_pla_175 -> generic_pla
root_material_id = self._material_manager.getRootMaterialIDWithoutDiameter(root_material_id)
root_material_id_list.append(root_material_id) root_material_id_list.append(root_material_id)
# Also try to get the fallback material # Also try to get the fallback material
material_type = extruder.material.getMetaDataEntry("material") material_type = extruder.material.getMetaDataEntry("material")
fallback_root_material_metadata = self._material_manager.getFallbackMaterialForType(material_type) fallback_root_material_id = self._material_manager.getFallbackMaterialId(material_type)
if fallback_root_material_metadata: if fallback_root_material_id:
root_material_id_list.append(fallback_root_material_metadata["id"]) root_material_id_list.append(fallback_root_material_id)
nodes_to_check = [] nodes_to_check = []

View File

@ -10,6 +10,7 @@
"category": "Other", "category": "Other",
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"platform": "gmax_1-5_xt-plus_s3d_full model_150707.stl", "platform": "gmax_1-5_xt-plus_s3d_full model_150707.stl",
"has_machine_quality": true,
"has_variants": true, "has_variants": true,
"variants_name": "Hotend", "variants_name": "Hotend",
"preferred_variant_name": "0.5mm E3D (Default)" "preferred_variant_name": "0.5mm E3D (Default)"

View File

@ -11,6 +11,7 @@
"file_formats": "text/x-gcode", "file_formats": "text/x-gcode",
"platform": "gmax_1-5_xt-plus_s3d_full model_150707.stl", "platform": "gmax_1-5_xt-plus_s3d_full model_150707.stl",
"has_variants": true, "has_variants": true,
"has_machine_quality": true,
"variants_name": "Hotend", "variants_name": "Hotend",
"preferred_variant_name": "0.5mm E3D (Default)", "preferred_variant_name": "0.5mm E3D (Default)",
"machine_extruder_trains": { "machine_extruder_trains": {

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = normal quality_type = normal
weight = -1 weight = -1
global_quality = True
[values] [values]
layer_height = 0.2 layer_height = 0.2

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = course quality_type = course
weight = -2 weight = -2
global_quality = True
[values] [values]
layer_height = 0.28 layer_height = 0.28

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = high quality_type = high
weight = 0 weight = 0
global_quality = True
[values] [values]
layer_height = 0.16 layer_height = 0.16

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = extra_course quality_type = extra_course
weight = -3 weight = -3
global_quality = True
[values] [values]
layer_height = 0.32 layer_height = 0.32

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = normal quality_type = normal
weight = -1 weight = -1
global_quality = True
[values] [values]
layer_height = 0.2 layer_height = 0.2

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = course quality_type = course
weight = -2 weight = -2
global_quality = True
[values] [values]
layer_height = 0.28 layer_height = 0.28

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = high quality_type = high
weight = 0 weight = 0
global_quality = True
[values] [values]
layer_height = 0.16 layer_height = 0.16

View File

@ -8,7 +8,6 @@ setting_version = 4
type = quality type = quality
quality_type = extra_course quality_type = extra_course
weight = -3 weight = -3
global_quality = True
[values] [values]
layer_height = 0.32 layer_height = 0.32