FormatMaps.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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": "2780b345-577b-4a24-a2c5-12e6aad3e690"},
  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": {"name": "Nylon", "guid": "283d439a-3490-4481-920c-c51d8cdecf9c"},
  31. "pc": {"name": "PC", "guid": "62414577-94d1-490d-b1e4-7ef3ec40db02"},
  32. "petg": {"name": "PETG", "guid": "69386c85-5b6c-421a-bec5-aeb1fb33f060"},
  33. "pla": {"name": "PLA", "guid": "abb9c58e-1f56-48d1-bd8f-055fde3a5b56"},
  34. "pva": {"name": "PVA", "guid": "add51ef2-86eb-4c39-afd5-5586564f0715"},
  35. "wss1": {"name": "RapidRinse", "guid": "a140ef8f-4f26-4e73-abe0-cfc29d6d1024"},
  36. "sr30": {"name": "SR-30", "guid": "77873465-83a9-4283-bc44-4e542b8eb3eb"},
  37. "bvoh": {"name": "BVOH", "guid": "923e604c-8432-4b09-96aa-9bbbd42207f4"},
  38. "cpe": {"name": "CPE", "guid": "da1872c1-b991-4795-80ad-bdac0f131726"},
  39. "hips": {"name": "HIPS", "guid": "a468d86a-220c-47eb-99a5-bbb47e514eb0"},
  40. "tpu": {"name": "TPU 95A", "guid": "19baa6a9-94ff-478b-b4a1-8157b74358d2"},
  41. "im-pla": {"name": "Tough", "guid": "de031137-a8ca-4a72-bd1b-17bb964033ad"}
  42. }
  43. __inverse_printer_name: Optional[Dict[str, str]] = None
  44. __inverse_extruder_type: Optional[Dict[str, str]] = None
  45. __inverse_material_map: Optional[Dict[str, str]] = None
  46. __product_to_id_map: Optional[Dict[str, List[str]]] = None
  47. @classmethod
  48. def getInversePrinterNameMap(cls) -> Dict[str, str]:
  49. """Returns the inverse of the printer name map, that is, from the internal name to the name used in output."""
  50. if cls.__inverse_printer_name is not None:
  51. return cls.__inverse_printer_name
  52. cls.__inverse_printer_name = {}
  53. for key, value in cls.PRINTER_TYPE_NAME.items():
  54. cls.__inverse_printer_name[value] = key
  55. return cls.__inverse_printer_name
  56. @classmethod
  57. def getInverseExtruderTypeMap(cls) -> Dict[str, str]:
  58. """Returns the inverse of the extruder type map, that is, from the internal name to the name used in output."""
  59. if cls.__inverse_extruder_type is not None:
  60. return cls.__inverse_extruder_type
  61. cls.__inverse_extruder_type = {}
  62. for key, value in cls.EXTRUDER_NAME_MAP.items():
  63. cls.__inverse_extruder_type[value] = key
  64. return cls.__inverse_extruder_type
  65. @classmethod
  66. def getInverseMaterialMap(cls) -> Dict[str, str]:
  67. """Returns the inverse of the material map, that is, from the internal name to the name used in output.
  68. Note that this drops the extra info saved in the non-inverse material map, use that if you need it.
  69. """
  70. if cls.__inverse_material_map is not None:
  71. return cls.__inverse_material_map
  72. cls.__inverse_material_map = {}
  73. for key, value in cls.MATERIAL_MAP.items():
  74. cls.__inverse_material_map[value["name"]] = key
  75. return cls.__inverse_material_map
  76. @classmethod
  77. def getProductIdMap(cls) -> Dict[str, List[str]]:
  78. """Gets a mapping from product names (for example, in the XML files) to their definition IDs.
  79. This loads the mapping from a file.
  80. """
  81. if cls.__product_to_id_map is not None:
  82. return cls.__product_to_id_map
  83. product_to_id_file = Resources.getPath(Resources.Texts, "product_to_id.json")
  84. with open(product_to_id_file, encoding = "utf-8") as f:
  85. contents = ""
  86. for line in f:
  87. contents += line if "#" not in line else "".join([line.replace("#", str(n)) for n in range(1, 12)])
  88. cls.__product_to_id_map = json.loads(contents)
  89. cls.__product_to_id_map = {key: [value] for key, value in cls.__product_to_id_map.items()}
  90. #This also loads "Ultimaker S5" -> "ultimaker_s5" even though that is not strictly necessary with the default to change spaces into underscores.
  91. #However it is not always loaded with that default; this mapping is also used in serialize() without that default.
  92. return cls.__product_to_id_map