FormatMaps.py 5.3 KB

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