Load product_id_map from file

For now this file is hard-coded. We should eventually try to generate this in the build system.

Contributes to issue CURA-4243.
This commit is contained in:
Ghostkeeper 2017-11-01 14:52:03 +01:00
parent a08875c5eb
commit 74bd527b03
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A
2 changed files with 29 additions and 7 deletions

View file

@ -3,7 +3,10 @@
import copy import copy
import io import io
from typing import List, Optional import json #To parse the product-to-id mapping file.
import os.path #To find the product-to-id mapping.
import sys
from typing import Dict, Optional
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from UM.Resources import Resources from UM.Resources import Resources
@ -11,6 +14,7 @@ from UM.Logger import Logger
from cura.CuraApplication import CuraApplication from cura.CuraApplication import CuraApplication
import UM.Dictionary import UM.Dictionary
from UM.PluginRegistry import PluginRegistry
from UM.Settings.InstanceContainer import InstanceContainer from UM.Settings.InstanceContainer import InstanceContainer
from UM.Settings.ContainerRegistry import ContainerRegistry from UM.Settings.ContainerRegistry import ContainerRegistry
@ -211,9 +215,7 @@ class XmlMaterialProfile(InstanceContainer):
machine_container_map[definition_id] = container machine_container_map[definition_id] = container
# Map machine human-readable names to IDs # Map machine human-readable names to IDs
product_id_map = {} product_id_map = self.getProductIdMap()
for container in registry.findDefinitionContainersMetadata(type = "machine"):
product_id_map[container["name"]] = container["id"]
for definition_id, container in machine_container_map.items(): for definition_id, container in machine_container_map.items():
definition = container.getDefinition() definition = container.getDefinition()
@ -513,9 +515,7 @@ class XmlMaterialProfile(InstanceContainer):
self._dirty = False self._dirty = False
# Map machine human-readable names to IDs # Map machine human-readable names to IDs
product_id_map = {} product_id_map = self.getProductIdMap()
for container in ContainerRegistry.getInstance().findDefinitionContainersMetadata(type = "machine"):
product_id_map[container["name"]] = container["id"]
machines = data.iterfind("./um:settings/um:machine", self.__namespaces) machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
for machine in machines: for machine in machines:
@ -656,6 +656,16 @@ class XmlMaterialProfile(InstanceContainer):
else: else:
return material_name return material_name
## Gets a mapping from product names in the XML files to their definition
# IDs.
#
# This loads the mapping from a file.
@classmethod
def getProductIdMap(cls) -> Dict[str, str]:
product_to_id_file = os.path.join(os.path.dirname(sys.modules[cls.__module__].__file__), "product_to_id.json")
with open(product_to_id_file) as f:
return json.load(f)
## Parse the value of the "material compatible" property. ## Parse the value of the "material compatible" property.
def _parseCompatibleValue(self, value: str): def _parseCompatibleValue(self, value: str):
return value in {"yes", "unknown"} return value in {"yes", "unknown"}

View file

@ -0,0 +1,12 @@
{
"Ultimaker 2": "ultimaker2",
"Ultimaker 2 Extended": "ultimaker2_extended",
"Ultimaker 2 Extended+": "ultimaker2_extended_plus",
"Ultimaker 2 Go": "ultimaker2_go",
"Ultimaker 2+": "ultimaker2_plus",
"Ultimaker 3": "ultimaker3",
"Ultimaker 3 Extended": "ultimaker3_extended",
"Ultimaker Original": "ultimaker_original",
"Ultimaker Original+": "ultimaker_original_plus",
"IMADE3D JellyBOX": "imade3d_jellybox"
}