mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
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:
parent
a08875c5eb
commit
74bd527b03
2 changed files with 29 additions and 7 deletions
|
@ -3,7 +3,10 @@
|
|||
|
||||
import copy
|
||||
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
|
||||
|
||||
from UM.Resources import Resources
|
||||
|
@ -11,6 +14,7 @@ from UM.Logger import Logger
|
|||
from cura.CuraApplication import CuraApplication
|
||||
|
||||
import UM.Dictionary
|
||||
from UM.PluginRegistry import PluginRegistry
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
|
||||
|
@ -211,9 +215,7 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
machine_container_map[definition_id] = container
|
||||
|
||||
# Map machine human-readable names to IDs
|
||||
product_id_map = {}
|
||||
for container in registry.findDefinitionContainersMetadata(type = "machine"):
|
||||
product_id_map[container["name"]] = container["id"]
|
||||
product_id_map = self.getProductIdMap()
|
||||
|
||||
for definition_id, container in machine_container_map.items():
|
||||
definition = container.getDefinition()
|
||||
|
@ -513,9 +515,7 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
self._dirty = False
|
||||
|
||||
# Map machine human-readable names to IDs
|
||||
product_id_map = {}
|
||||
for container in ContainerRegistry.getInstance().findDefinitionContainersMetadata(type = "machine"):
|
||||
product_id_map[container["name"]] = container["id"]
|
||||
product_id_map = self.getProductIdMap()
|
||||
|
||||
machines = data.iterfind("./um:settings/um:machine", self.__namespaces)
|
||||
for machine in machines:
|
||||
|
@ -656,6 +656,16 @@ class XmlMaterialProfile(InstanceContainer):
|
|||
else:
|
||||
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.
|
||||
def _parseCompatibleValue(self, value: str):
|
||||
return value in {"yes", "unknown"}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue