QualityChangesGroup.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from UM.Application import Application
  4. from .QualityGroup import QualityGroup
  5. class QualityChangesGroup(QualityGroup):
  6. ## The file format version of quality changes.
  7. Version = 3
  8. def __init__(self, name: str, quality_type: str, parent = None):
  9. super().__init__(name, quality_type, parent)
  10. self._container_registry = Application.getInstance().getContainerRegistry()
  11. def addNode(self, node: "QualityNode"):
  12. # TODO: in 3.2 and earlier, a quality_changes container may have a field called "extruder" which contains the
  13. # extruder definition ID it belongs to. But, in fact, we only need to know the following things:
  14. # 1. which machine a custom profile is suitable for,
  15. # 2. if this profile is for the GlobalStack,
  16. # 3. if this profile is for an ExtruderStack and which one (the position).
  17. #
  18. # So, it is preferred to have a field like this:
  19. # extruder_position = 1
  20. # instead of this:
  21. # extruder = custom_extruder_1
  22. #
  23. # An upgrade needs to be done if we want to do it this way. Before that, we use the extruder's definition
  24. # to figure out its position.
  25. #
  26. extruder_definition_id = node.metadata.get("extruder")
  27. if extruder_definition_id:
  28. metadata_list = self._container_registry.findDefinitionContainersMetadata(id = extruder_definition_id)
  29. if not metadata_list:
  30. raise RuntimeError("%s cannot get metadata for extruder definition [%s]" %
  31. (self, extruder_definition_id))
  32. extruder_definition_metadata = metadata_list[0]
  33. extruder_position = str(extruder_definition_metadata["position"])
  34. if extruder_position in self.nodes_for_extruders:
  35. raise RuntimeError("%s tries to overwrite the existing nodes_for_extruders position [%s] %s with %s" %
  36. (self, extruder_position, self.node_for_global, node))
  37. self.nodes_for_extruders[extruder_position] = node
  38. else:
  39. # This is a quality_changes for the GlobalStack
  40. if self.node_for_global is not None:
  41. raise RuntimeError("%s tries to overwrite the existing node_for_global %s with %s" %
  42. (self, self.node_for_global, node))
  43. self.node_for_global = node
  44. def __str__(self) -> str:
  45. return "%s[<%s>, available = %s]" % (self.__class__.__name__, self.name, self.is_available)