Просмотр исходного кода

CURA-4461 Store buildplate compatibility in the material profile

Diego Prado Gesto 7 лет назад
Родитель
Сommit
badf5a9043
1 измененных файлов с 58 добавлено и 82 удалено
  1. 58 82
      plugins/XmlMaterialProfile/XmlMaterialProfile.py

+ 58 - 82
plugins/XmlMaterialProfile/XmlMaterialProfile.py

@@ -606,8 +606,11 @@ class XmlMaterialProfile(InstanceContainer):
                         if is_new_material:
                             containers_to_add.append(new_material)
 
+                    # Find the buildplates compatibility
                     buildplates = machine.iterfind("./um:buildplate", self.__namespaces)
                     buildplate_map = {}
+                    buildplate_map["buildplate_compatible"] = {}
+                    buildplate_map["buildplate_recommended"] = {}
                     for buildplate in buildplates:
                         buildplate_id = buildplate.get("id")
                         if buildplate_id is None:
@@ -636,14 +639,8 @@ class XmlMaterialProfile(InstanceContainer):
                             else:
                                 Logger.log("d", "Unsupported material setting %s", key)
 
-                        buildplate_map[buildplate_id] = {}
-                        buildplate_map[buildplate_id]["buildplate_compatible"] = buildplate_compatibility
-                        buildplate_map[buildplate_id]["buildplate_recommended"] = buildplate_recommended
-
-                    # If no buildplate was found, then the material is created without buildplate information
-                    if not buildplate_map:
-                        buildplate_map[""] = {"buildplate_compatible" : machine_compatibility,
-                                              "buildplate_recommended" : machine_compatibility}
+                        buildplate_map["buildplate_compatible"][buildplate_id] = buildplate_compatibility
+                        buildplate_map["buildplate_recommended"][buildplate_id] = buildplate_recommended
 
                     hotends = machine.iterfind("./um:hotend", self.__namespaces)
                     for hotend in hotends:
@@ -672,46 +669,38 @@ class XmlMaterialProfile(InstanceContainer):
                             else:
                                 Logger.log("d", "Unsupported material setting %s", key)
 
-                        for buildplate_id in buildplate_map:
-
-                            new_hotend_id = self.getId() + "_" + machine_id + ("_" if buildplate_id != "" else "") + \
-                                            buildplate_id.replace(" ", "_") + "_" + hotend_id.replace(" ", "_")
-
-                            buildplate_compatibility = buildplate_map[buildplate_id]["buildplate_compatible"]
-                            buildplate_recommended = buildplate_map[buildplate_id]["buildplate_recommended"]
+                        new_hotend_id = self.getId() + "_" + machine_id + "_" + hotend_id.replace(" ", "_")
 
-                            # Same as machine compatibility, keep the derived material containers consistent with the parent
-                            # material
-                            if ContainerRegistry.getInstance().isLoaded(new_hotend_id):
-                                new_hotend_material = ContainerRegistry.getInstance().findContainers(id = new_hotend_id)[0]
-                                is_new_material = False
-                            else:
-                                new_hotend_material = XmlMaterialProfile(new_hotend_id)
-                                is_new_material = True
+                        # Same as machine compatibility, keep the derived material containers consistent with the parent material
+                        if ContainerRegistry.getInstance().isLoaded(new_hotend_id):
+                            new_hotend_material = ContainerRegistry.getInstance().findContainers(id = new_hotend_id)[0]
+                            is_new_material = False
+                        else:
+                            new_hotend_material = XmlMaterialProfile(new_hotend_id)
+                            is_new_material = True
 
-                            new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
-                            new_hotend_material.getMetaData()["id"] = new_hotend_id
-                            new_hotend_material.getMetaData()["name"] = self.getName()
-                            new_hotend_material.getMetaData()["variant"] = variant_containers[0]["id"]
-                            new_hotend_material.setDefinition(machine_id)
-                            # Don't use setMetadata, as that overrides it for all materials with same base file
-                            new_hotend_material.getMetaData()["compatible"] = hotend_compatibility
-                            new_hotend_material.getMetaData()["buildplate_compatible"] = buildplate_compatibility
-                            new_hotend_material.getMetaData()["buildplate_recommended"] = buildplate_recommended
-                            new_hotend_material.getMetaData()["machine_manufacturer"] = machine_manufacturer
-                            new_hotend_material.getMetaData()["definition"] = machine_id
-                            # if machine_id == "ultimaker3_xl" and self.getId() == "generic_abs":
-                            #     print("&&&&&&&&&&&& HotendID", new_hotend_id)
+                        new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
+                        new_hotend_material.getMetaData()["id"] = new_hotend_id
+                        new_hotend_material.getMetaData()["name"] = self.getName()
+                        new_hotend_material.getMetaData()["variant"] = variant_containers[0]["id"]
+                        new_hotend_material.setDefinition(machine_id)
+                        # Don't use setMetadata, as that overrides it for all materials with same base file
+                        new_hotend_material.getMetaData()["compatible"] = hotend_compatibility
+                        new_hotend_material.getMetaData()["machine_manufacturer"] = machine_manufacturer
+                        new_hotend_material.getMetaData()["definition"] = machine_id
+                        if buildplate_map["buildplate_compatible"]:
+                            new_hotend_material.getMetaData()["buildplate_compatible"] = buildplate_map["buildplate_compatible"]
+                            new_hotend_material.getMetaData()["buildplate_recommended"] = buildplate_map["buildplate_recommended"]
 
-                            cached_hotend_setting_properties = cached_machine_setting_properties.copy()
-                            cached_hotend_setting_properties.update(hotend_setting_values)
+                        cached_hotend_setting_properties = cached_machine_setting_properties.copy()
+                        cached_hotend_setting_properties.update(hotend_setting_values)
 
-                            new_hotend_material.setCachedValues(cached_hotend_setting_properties)
+                        new_hotend_material.setCachedValues(cached_hotend_setting_properties)
 
-                            new_hotend_material._dirty = False
+                        new_hotend_material._dirty = False
 
-                            if is_new_material:
-                                containers_to_add.append(new_hotend_material)
+                        if is_new_material:
+                            containers_to_add.append(new_hotend_material)
 
                     # there is only one ID for a machine. Once we have reached here, it means we have already found
                     # a workable ID for that machine, so there is no need to continue
@@ -844,6 +833,8 @@ class XmlMaterialProfile(InstanceContainer):
 
                     buildplates = machine.iterfind("./um:buildplate", cls.__namespaces)
                     buildplate_map = {}
+                    buildplate_map["buildplate_compatible"] = {}
+                    buildplate_map["buildplate_recommended"] = {}
                     for buildplate in buildplates:
                         buildplate_id = buildplate.get("id")
                         if buildplate_id is None:
@@ -857,8 +848,6 @@ class XmlMaterialProfile(InstanceContainer):
                         if not variant_containers:
                             continue
 
-                        buildplate_compatibility = machine_compatibility
-                        buildplate_recommended = machine_compatibility
                         settings = buildplate.iterfind("./um:setting", cls.__namespaces)
                         for entry in settings:
                             key = entry.get("key")
@@ -867,14 +856,8 @@ class XmlMaterialProfile(InstanceContainer):
                             elif key == "hardware recommended":
                                 buildplate_recommended = cls._parseCompatibleValue(entry.text)
 
-                        buildplate_map[buildplate_id] = {}
-                        buildplate_map[buildplate_id]["buildplate_compatible"] = buildplate_compatibility
-                        buildplate_map[buildplate_id]["buildplate_recommended"] = buildplate_recommended
-
-                    # If no buildplate was found, then the material is created without buildplate information
-                    if not buildplate_map:
-                        buildplate_map[""] = {"buildplate_compatible": machine_compatibility,
-                                              "buildplate_recommended": machine_compatibility}
+                        buildplate_map["buildplate_compatible"][buildplate_id] = buildplate_map["buildplate_compatible"]
+                        buildplate_map["buildplate_recommended"][buildplate_id] = buildplate_map["buildplate_recommended"]
 
                     for hotend in machine.iterfind("./um:hotend", cls.__namespaces):
                         hotend_id = hotend.get("id")
@@ -892,38 +875,31 @@ class XmlMaterialProfile(InstanceContainer):
                             if key == "hardware compatible":
                                 hotend_compatibility = cls._parseCompatibleValue(entry.text)
 
-                        for buildplate_id in buildplate_map:
-
-                            new_hotend_id = container_id + "_" + machine_id + ("_" if buildplate_id != "" else "") + \
-                                            buildplate_id.replace(" ", "_") + "_" + hotend_id.replace(" ", "_")
+                        new_hotend_id = container_id + "_" + machine_id + "_" + hotend_id.replace(" ", "_")
 
-                            buildplate_compatibility = buildplate_map[buildplate_id]["buildplate_compatible"]
-                            buildplate_recommended = buildplate_map[buildplate_id]["buildplate_recommended"]
-
-                            # Same as machine compatibility, keep the derived material containers consistent with the parent material
-                            found_materials = ContainerRegistry.getInstance().findInstanceContainersMetadata(id = new_hotend_id)
-                            if found_materials:
-                                new_hotend_material_metadata = found_materials[0]
-                            else:
-                                new_hotend_material_metadata = {}
+                        # Same as machine compatibility, keep the derived material containers consistent with the parent material
+                        found_materials = ContainerRegistry.getInstance().findInstanceContainersMetadata(id = new_hotend_id)
+                        if found_materials:
+                            new_hotend_material_metadata = found_materials[0]
+                        else:
+                            new_hotend_material_metadata = {}
 
-                            new_hotend_material_metadata.update(base_metadata)
-                            if variant_containers:
-                                new_hotend_material_metadata["variant"] = variant_containers[0]["id"]
-                            else:
-                                new_hotend_material_metadata["variant"] = hotend_id
-                                _with_missing_variants.append(new_hotend_material_metadata)
-                            new_hotend_material_metadata["compatible"] = hotend_compatibility
-                            new_hotend_material_metadata["buildplate_compatible"] = buildplate_compatibility
-                            new_hotend_material_metadata["buildplate_recommended"] = buildplate_recommended
-                            new_hotend_material_metadata["machine_manufacturer"] = machine_manufacturer
-                            new_hotend_material_metadata["id"] = new_hotend_id
-                            new_hotend_material_metadata["definition"] = machine_id
-                            # if machine_id == "ultimaker3_xl" and container_id == "generic_abs":
-                            #     print("############# HotendID", new_hotend_id)
-
-                            if len(found_materials) == 0:
-                                result_metadata.append(new_hotend_material_metadata)
+                        new_hotend_material_metadata.update(base_metadata)
+                        if variant_containers:
+                            new_hotend_material_metadata["variant"] = variant_containers[0]["id"]
+                        else:
+                            new_hotend_material_metadata["variant"] = hotend_id
+                            _with_missing_variants.append(new_hotend_material_metadata)
+                        new_hotend_material_metadata["compatible"] = hotend_compatibility
+                        new_hotend_material_metadata["machine_manufacturer"] = machine_manufacturer
+                        new_hotend_material_metadata["id"] = new_hotend_id
+                        new_hotend_material_metadata["definition"] = machine_id
+                        if buildplate_map["buildplate_compatible"]:
+                            new_hotend_material_metadata["buildplate_compatible"] = buildplate_map["buildplate_compatible"]
+                            new_hotend_material_metadata["buildplate_recommended"] = buildplate_map["buildplate_recommended"]
+
+                        if len(found_materials) == 0:
+                            result_metadata.append(new_hotend_material_metadata)
 
                     # there is only one ID for a machine. Once we have reached here, it means we have already found
                     # a workable ID for that machine, so there is no need to continue