diff options
author | Kostas Karmas <konskarm@gmail.com> | 2020-08-03 15:34:45 +0300 |
---|---|---|
committer | Kostas Karmas <konskarm@gmail.com> | 2020-08-03 15:34:45 +0300 |
commit | 9f6b4f025526dd2de365e564360b110f352a6058 (patch) | |
tree | 70a6dcead6b2bbce0229ae97f0c639a52c8beece /plugins/3MFReader | |
parent | f80dbefad3c55df22cf7336dffe8cb3ee451be70 (diff) |
Sort materials based on extruder position in the open project dialog
From eCCB
Diffstat (limited to 'plugins/3MFReader')
-rwxr-xr-x | plugins/3MFReader/ThreeMFWorkspaceReader.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/plugins/3MFReader/ThreeMFWorkspaceReader.py b/plugins/3MFReader/ThreeMFWorkspaceReader.py index 664b14afa1..ec457e0a4b 100755 --- a/plugins/3MFReader/ThreeMFWorkspaceReader.py +++ b/plugins/3MFReader/ThreeMFWorkspaceReader.py @@ -260,7 +260,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader): if machine_definition_container_count != 1: return WorkspaceReader.PreReadResult.failed # Not a workspace file but ordinary 3MF. - material_labels = [] + material_ids_to_names_map = {} material_conflict = False xml_material_profile = self._getXmlProfileClass() reverse_material_id_dict = {} @@ -276,7 +276,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader): reverse_map = {metadata["id"]: container_id for metadata in metadata_list} reverse_material_id_dict.update(reverse_map) - material_labels.append(self._getMaterialLabelFromSerialized(serialized)) + material_ids_to_names_map[container_id] = self._getMaterialLabelFromSerialized(serialized) if self._container_registry.findContainersMetadata(id = container_id): #This material already exists. containers_found_dict["material"] = True if not self._container_registry.isReadOnly(container_id): # Only non readonly materials can be in conflict @@ -443,6 +443,8 @@ class ThreeMFWorkspaceReader(WorkspaceReader): QCoreApplication.processEvents() # Ensure that the GUI does not freeze. Job.yieldThread() + materials_in_extruders_dict = {} # Which material is in which extruder + # if the global stack is found, we check if there are conflicts in the extruder stacks for extruder_stack_file in extruder_stack_files: serialized = archive.open(extruder_stack_file).read().decode("utf-8") @@ -456,6 +458,7 @@ class ThreeMFWorkspaceReader(WorkspaceReader): position = parser["metadata"]["position"] variant_id = parser["containers"][str(_ContainerIndexes.Variant)] material_id = parser["containers"][str(_ContainerIndexes.Material)] + materials_in_extruders_dict[position] = material_ids_to_names_map[reverse_material_id_dict[material_id]] extruder_info = ExtruderInfo() extruder_info.position = position @@ -496,6 +499,10 @@ class ThreeMFWorkspaceReader(WorkspaceReader): machine_conflict = True break + # Now we know which material is in which extruder. Let's use that to sort the material_labels according to + # their extruder position + material_labels = [material_name for pos, material_name in sorted(materials_in_extruders_dict.items())] + num_visible_settings = 0 try: temp_preferences = Preferences() |