FormatMaps.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. # Copyright (c) 2024 UltiMaker
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Resources import Resources
  4. import json
  5. from typing import Dict, List, Optional
  6. class FormatMaps:
  7. # A map from the printer-type in their native file-formats to the internal name we use.
  8. PRINTER_TYPE_NAME = {
  9. "fire_e": "ultimaker_method",
  10. "lava_f": "ultimaker_methodx",
  11. "magma_10": "ultimaker_methodxl",
  12. "sketch": "ultimaker_sketch"
  13. }
  14. # A map from the extruder-name in their native file-formats to the internal name we use.
  15. EXTRUDER_NAME_MAP = {
  16. "mk14_hot": "1XA",
  17. "mk14_hot_s": "2XA",
  18. "mk14_c": "1C",
  19. "mk14": "1A",
  20. "mk14_s": "2A",
  21. "mk14_e": "LABS"
  22. }
  23. # A map from the material-name in their native file-formats to some info, including the internal name we use.
  24. MATERIAL_MAP = {
  25. "abs": {"name": "ABS", "guid": "e0f1d581-cc6b-4e36-8f3c-3f5601ecba5f"},
  26. "abs-cf10": {"name": "ABS-CF", "guid": "495a0ce5-9daf-4a16-b7b2-06856d82394d"},
  27. "abs-wss1": {"name": "ABS-R", "guid": "88c8919c-6a09-471a-b7b6-e801263d862d"},
  28. "asa": {"name": "ASA", "guid": "f79bc612-21eb-482e-ad6c-87d75bdde066"},
  29. "nylon12-cf": {"name": "Nylon 12 CF", "guid": "3c6f2877-71cc-4760-84e6-4b89ab243e3b"},
  30. "nylon-cf": {"name": "Nylon CF", "guid": "17abb865-ca73-4ccd-aeda-38e294c9c60b"},
  31. "pet": {"name": "PETG", "guid": "2d004bbd-d1bb-47f8-beac-b066702d5273"},
  32. "pla": {"name": "PLA", "guid": "abb9c58e-1f56-48d1-bd8f-055fde3a5b56"},
  33. "pva": {"name": "PVA", "guid": "add51ef2-86eb-4c39-afd5-5586564f0715"},
  34. "wss1": {"name": "RapidRinse", "guid": "a140ef8f-4f26-4e73-abe0-cfc29d6d1024"},
  35. "sr30": {"name": "SR-30", "guid": "77873465-83a9-4283-bc44-4e542b8eb3eb"},
  36. "im-pla": {"name": "Tough", "guid": "de031137-a8ca-4a72-bd1b-17bb964033ad"}
  37. # /!\ When changing this list, make sure the changes are reported accordingly on Digital Factory
  38. }
  39. __inverse_printer_name: Optional[Dict[str, str]] = None
  40. __inverse_extruder_type: Optional[Dict[str, str]] = None
  41. __inverse_material_map: Optional[Dict[str, str]] = None
  42. __product_to_id_map: Optional[Dict[str, List[str]]] = None
  43. @classmethod
  44. def getInversePrinterNameMap(cls) -> Dict[str, str]:
  45. """Returns the inverse of the printer name map, that is, from the internal name to the name used in output."""
  46. if cls.__inverse_printer_name is not None:
  47. return cls.__inverse_printer_name
  48. cls.__inverse_printer_name = {}
  49. for key, value in cls.PRINTER_TYPE_NAME.items():
  50. cls.__inverse_printer_name[value] = key
  51. return cls.__inverse_printer_name
  52. @classmethod
  53. def getInverseExtruderTypeMap(cls) -> Dict[str, str]:
  54. """Returns the inverse of the extruder type map, that is, from the internal name to the name used in output."""
  55. if cls.__inverse_extruder_type is not None:
  56. return cls.__inverse_extruder_type
  57. cls.__inverse_extruder_type = {}
  58. for key, value in cls.EXTRUDER_NAME_MAP.items():
  59. cls.__inverse_extruder_type[value] = key
  60. return cls.__inverse_extruder_type
  61. @classmethod
  62. def getInverseMaterialMap(cls) -> Dict[str, str]:
  63. """Returns the inverse of the material map, that is, from the internal name to the name used in output.
  64. Note that this drops the extra info saved in the non-inverse material map, use that if you need it.
  65. """
  66. if cls.__inverse_material_map is not None:
  67. return cls.__inverse_material_map
  68. cls.__inverse_material_map = {}
  69. for key, value in cls.MATERIAL_MAP.items():
  70. cls.__inverse_material_map[value["name"]] = key
  71. return cls.__inverse_material_map
  72. @classmethod
  73. def getProductIdMap(cls) -> Dict[str, List[str]]:
  74. """Gets a mapping from product names (for example, in the XML files) to their definition IDs.
  75. This loads the mapping from a file.
  76. """
  77. if cls.__product_to_id_map is not None:
  78. return cls.__product_to_id_map
  79. product_to_id_file = Resources.getPath(Resources.Texts, "product_to_id.json")
  80. with open(product_to_id_file, encoding = "utf-8") as f:
  81. contents = ""
  82. for line in f:
  83. contents += line if "#" not in line else "".join([line.replace("#", str(n)) for n in range(1, 12)])
  84. cls.__product_to_id_map = json.loads(contents)
  85. cls.__product_to_id_map = {key: [value] for key, value in cls.__product_to_id_map.items()}
  86. #This also loads "Ultimaker S5" -> "ultimaker_s5" even though that is not strictly necessary with the default to change spaces into underscores.
  87. #However it is not always loaded with that default; this mapping is also used in serialize() without that default.
  88. return cls.__product_to_id_map