Ejemplo n.º 1
0
    def getQualityChangesGroups(self, variant_names: List[str], material_bases: List[str], extruder_enabled: List[bool]) -> List[QualityChangesGroup]:
        machine_quality_changes = ContainerRegistry.getInstance().findContainersMetadata(type = "quality_changes", definition = self.quality_definition)  # All quality changes for each extruder.

        groups_by_name = {}  #type: Dict[str, QualityChangesGroup]  # Group quality changes profiles by their display name. The display name must be unique for quality changes. This finds profiles that belong together in a group.
        for quality_changes in machine_quality_changes:
            name = quality_changes["name"]
            if name not in groups_by_name:
                # CURA-6599
                # For some reason, QML will get null or fail to convert type for MachineManager.activeQualityChangesGroup() to
                # a QObject. Setting the object ownership to QQmlEngine.CppOwnership doesn't work, but setting the object
                # parent to application seems to work.
                from cura.CuraApplication import CuraApplication
                groups_by_name[name] = QualityChangesGroup(name, quality_type = quality_changes["quality_type"],
                                                           intent_category = quality_changes.get("intent_category", "default"),
                                                           parent = CuraApplication.getInstance())
            elif groups_by_name[name].intent_category == "default":  # Intent category should be stored as "default" if everything is default or as the intent if any of the extruder have an actual intent.
                groups_by_name[name].intent_category = quality_changes.get("intent_category", "default")

            if "position" in quality_changes:  # An extruder profile.
                groups_by_name[name].metadata_per_extruder[int(quality_changes["position"])] = quality_changes
            else:  # Global profile.
                groups_by_name[name].metadata_for_global = quality_changes

        quality_groups = self.getQualityGroups(variant_names, material_bases, extruder_enabled)
        for quality_changes_group in groups_by_name.values():
            if quality_changes_group.quality_type not in quality_groups:
                quality_changes_group.is_available = False
            else:
                # Quality changes group is available iff the quality group it depends on is available. Irrespective of whether the intent category is available.
                quality_changes_group.is_available = quality_groups[quality_changes_group.quality_type].is_available

        return list(groups_by_name.values())
Ejemplo n.º 2
0
    def getQualityChangesGroups(self, variant_names: List[str], material_bases: List[str], extruder_enabled: List[bool]) -> List[QualityChangesGroup]:
        """Returns all of the quality changes groups available to this printer.

        The quality changes groups store which quality type and intent category they were made for, but not which
        material and nozzle. Instead for the quality type and intent category, the quality changes will always be
        available but change the quality type and intent category when activated.

        The quality changes group does depend on the printer: Which quality definition is used.

        The quality changes groups that are available do depend on the quality types that are available, so it must
        still be known which extruders are enabled and which materials and variants are loaded in them. This allows
        setting the correct is_available flag.

        :param variant_names: The names of the variants loaded in each extruder.
        :param material_bases: The base file names of the materials loaded in each extruder.
        :param extruder_enabled: For each extruder whether or not they are enabled.

        :return: List of all quality changes groups for the printer.
        """

        machine_quality_changes = ContainerRegistry.getInstance().findContainersMetadata(type = "quality_changes", definition = self.quality_definition)  # All quality changes for each extruder.

        groups_by_name = {}  #type: Dict[str, QualityChangesGroup]  # Group quality changes profiles by their display name. The display name must be unique for quality changes. This finds profiles that belong together in a group.
        for quality_changes in machine_quality_changes:
            name = quality_changes["name"]
            if name not in groups_by_name:
                # CURA-6599
                # For some reason, QML will get null or fail to convert type for MachineManager.activeQualityChangesGroup() to
                # a QObject. Setting the object ownership to QQmlEngine.CppOwnership doesn't work, but setting the object
                # parent to application seems to work.
                from cura.CuraApplication import CuraApplication
                groups_by_name[name] = QualityChangesGroup(name, quality_type = quality_changes["quality_type"],
                                                           intent_category = quality_changes.get("intent_category", "default"),
                                                           parent = CuraApplication.getInstance())

            elif groups_by_name[name].intent_category == "default":  # Intent category should be stored as "default" if everything is default or as the intent if any of the extruder have an actual intent.
                groups_by_name[name].intent_category = quality_changes.get("intent_category", "default")

            if quality_changes.get("position") is not None and quality_changes.get("position") != "None":  # An extruder profile.
                groups_by_name[name].metadata_per_extruder[int(quality_changes["position"])] = quality_changes
            else:  # Global profile.
                groups_by_name[name].metadata_for_global = quality_changes

        quality_groups = self.getQualityGroups(variant_names, material_bases, extruder_enabled)
        for quality_changes_group in groups_by_name.values():
            if quality_changes_group.quality_type not in quality_groups:
                if quality_changes_group.quality_type == "not_supported":
                    # Quality changes based on an empty profile are always available. 
                    quality_changes_group.is_available = True
                else:
                    quality_changes_group.is_available = False
            else:
                # Quality changes group is available iff the quality group it depends on is available. Irrespective of whether the intent category is available.
                quality_changes_group.is_available = quality_groups[quality_changes_group.quality_type].is_available

        return list(groups_by_name.values())
Ejemplo n.º 3
0
def test_renameQualityChangesGroup(quality_mocked_application):
    manager = QualityManager(quality_mocked_application)
    manager.initialize()

    mocked_container = MagicMock()

    quality_changes_group = QualityChangesGroup("zomg", "beep")
    quality_changes_group.getAllNodes = MagicMock(return_value = [mocked_container])

    # We need to check for "uniqueName" instead of "NEWRANDOMNAMEYAY" because the mocked registry always returns
    # "uniqueName" when attempting to generate an unique name.
    assert manager.renameQualityChangesGroup(quality_changes_group, "NEWRANDOMNAMEYAY") == "uniqueName"
    assert mocked_container.setName.called_once_with("uniqueName")