CURA-4461 Store buildplate compatibility in the material profile

This commit is contained in:
Diego Prado Gesto 2018-01-15 14:31:52 +01:00
parent 67ca4d25cd
commit badf5a9043

View File

@ -606,8 +606,11 @@ class XmlMaterialProfile(InstanceContainer):
if is_new_material: if is_new_material:
containers_to_add.append(new_material) containers_to_add.append(new_material)
# Find the buildplates compatibility
buildplates = machine.iterfind("./um:buildplate", self.__namespaces) buildplates = machine.iterfind("./um:buildplate", self.__namespaces)
buildplate_map = {} buildplate_map = {}
buildplate_map["buildplate_compatible"] = {}
buildplate_map["buildplate_recommended"] = {}
for buildplate in buildplates: for buildplate in buildplates:
buildplate_id = buildplate.get("id") buildplate_id = buildplate.get("id")
if buildplate_id is None: if buildplate_id is None:
@ -636,14 +639,8 @@ class XmlMaterialProfile(InstanceContainer):
else: else:
Logger.log("d", "Unsupported material setting %s", key) Logger.log("d", "Unsupported material setting %s", key)
buildplate_map[buildplate_id] = {} buildplate_map["buildplate_compatible"][buildplate_id] = buildplate_compatibility
buildplate_map[buildplate_id]["buildplate_compatible"] = buildplate_compatibility buildplate_map["buildplate_recommended"][buildplate_id] = buildplate_recommended
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}
hotends = machine.iterfind("./um:hotend", self.__namespaces) hotends = machine.iterfind("./um:hotend", self.__namespaces)
for hotend in hotends: for hotend in hotends:
@ -672,46 +669,38 @@ class XmlMaterialProfile(InstanceContainer):
else: else:
Logger.log("d", "Unsupported material setting %s", key) Logger.log("d", "Unsupported material setting %s", key)
for buildplate_id in buildplate_map: new_hotend_id = self.getId() + "_" + machine_id + "_" + hotend_id.replace(" ", "_")
new_hotend_id = self.getId() + "_" + machine_id + ("_" if buildplate_id != "" else "") + \ # Same as machine compatibility, keep the derived material containers consistent with the parent material
buildplate_id.replace(" ", "_") + "_" + hotend_id.replace(" ", "_") 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
buildplate_compatibility = buildplate_map[buildplate_id]["buildplate_compatible"] new_hotend_material.setMetaData(copy.deepcopy(self.getMetaData()))
buildplate_recommended = buildplate_map[buildplate_id]["buildplate_recommended"] 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"]
# Same as machine compatibility, keep the derived material containers consistent with the parent cached_hotend_setting_properties = cached_machine_setting_properties.copy()
# material cached_hotend_setting_properties.update(hotend_setting_values)
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.setCachedValues(cached_hotend_setting_properties)
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)
cached_hotend_setting_properties = cached_machine_setting_properties.copy() new_hotend_material._dirty = False
cached_hotend_setting_properties.update(hotend_setting_values)
new_hotend_material.setCachedValues(cached_hotend_setting_properties) if is_new_material:
containers_to_add.append(new_hotend_material)
new_hotend_material._dirty = False
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 # 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 # 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) buildplates = machine.iterfind("./um:buildplate", cls.__namespaces)
buildplate_map = {} buildplate_map = {}
buildplate_map["buildplate_compatible"] = {}
buildplate_map["buildplate_recommended"] = {}
for buildplate in buildplates: for buildplate in buildplates:
buildplate_id = buildplate.get("id") buildplate_id = buildplate.get("id")
if buildplate_id is None: if buildplate_id is None:
@ -857,8 +848,6 @@ class XmlMaterialProfile(InstanceContainer):
if not variant_containers: if not variant_containers:
continue continue
buildplate_compatibility = machine_compatibility
buildplate_recommended = machine_compatibility
settings = buildplate.iterfind("./um:setting", cls.__namespaces) settings = buildplate.iterfind("./um:setting", cls.__namespaces)
for entry in settings: for entry in settings:
key = entry.get("key") key = entry.get("key")
@ -867,14 +856,8 @@ class XmlMaterialProfile(InstanceContainer):
elif key == "hardware recommended": elif key == "hardware recommended":
buildplate_recommended = cls._parseCompatibleValue(entry.text) buildplate_recommended = cls._parseCompatibleValue(entry.text)
buildplate_map[buildplate_id] = {} buildplate_map["buildplate_compatible"][buildplate_id] = buildplate_map["buildplate_compatible"]
buildplate_map[buildplate_id]["buildplate_compatible"] = buildplate_compatibility buildplate_map["buildplate_recommended"][buildplate_id] = buildplate_map["buildplate_recommended"]
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}
for hotend in machine.iterfind("./um:hotend", cls.__namespaces): for hotend in machine.iterfind("./um:hotend", cls.__namespaces):
hotend_id = hotend.get("id") hotend_id = hotend.get("id")
@ -892,38 +875,31 @@ class XmlMaterialProfile(InstanceContainer):
if key == "hardware compatible": if key == "hardware compatible":
hotend_compatibility = cls._parseCompatibleValue(entry.text) hotend_compatibility = cls._parseCompatibleValue(entry.text)
for buildplate_id in buildplate_map: new_hotend_id = container_id + "_" + machine_id + "_" + hotend_id.replace(" ", "_")
new_hotend_id = container_id + "_" + machine_id + ("_" if buildplate_id != "" else "") + \ # Same as machine compatibility, keep the derived material containers consistent with the parent material
buildplate_id.replace(" ", "_") + "_" + hotend_id.replace(" ", "_") found_materials = ContainerRegistry.getInstance().findInstanceContainersMetadata(id = new_hotend_id)
if found_materials:
new_hotend_material_metadata = found_materials[0]
else:
new_hotend_material_metadata = {}
buildplate_compatibility = buildplate_map[buildplate_id]["buildplate_compatible"] new_hotend_material_metadata.update(base_metadata)
buildplate_recommended = buildplate_map[buildplate_id]["buildplate_recommended"] 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"]
# Same as machine compatibility, keep the derived material containers consistent with the parent material if len(found_materials) == 0:
found_materials = ContainerRegistry.getInstance().findInstanceContainersMetadata(id = new_hotend_id) result_metadata.append(new_hotend_material_metadata)
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)
# there is only one ID for a machine. Once we have reached here, it means we have already found # 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 # a workable ID for that machine, so there is no need to continue