예제 #1
0
    def _update(self) -> None:
        """Updates the list of intents."""

        available_categories = IntentManager.getInstance(
        ).currentAvailableIntentCategories()
        result = []
        for category in available_categories:
            qualities = IntentModel()
            qualities.setIntentCategory(category)
            try:
                weight = list(
                    IntentCategoryModel._get_translations().keys()).index(
                        category)
            except ValueError:
                weight = 99
            result.append({
                "name":
                IntentCategoryModel.translation(category, "name", category),
                "description":
                IntentCategoryModel.translation(category, "description", None),
                "intent_category":
                category,
                "weight":
                weight,
                "qualities":
                qualities
            })
        result.sort(key=lambda k: k["weight"])
        self.setItems(result)
예제 #2
0
def intent_manager(application, extruder_manager, machine_manager, container_registry, global_stack) -> IntentManager:
    application.getExtruderManager = MagicMock(return_value = extruder_manager)
    application.getGlobalContainerStack = MagicMock(return_value = global_stack)
    application.getMachineManager = MagicMock(return_value = machine_manager)
    machine_manager.setIntentByCategory = MagicMock()
    with patch("cura.CuraApplication.CuraApplication.getInstance", MagicMock(return_value = application)):
        with patch("UM.Settings.ContainerRegistry.ContainerRegistry.getInstance", MagicMock(return_value = container_registry)):
            manager = IntentManager()
    return manager
예제 #3
0
 def update(self) -> None:
     available_categories = IntentManager.getInstance().currentAvailableIntentCategories()
     result = []
     for category in available_categories:
         qualities = IntentModel()
         qualities.setIntentCategory(category)
         result.append({
             "name": self.name_translation.get(category, catalog.i18nc("@label", "Unknown")),
             "intent_category": category,
             "weight": list(self.name_translation.keys()).index(category),
             "qualities": qualities
         })
     result.sort(key = lambda k: k["weight"])
     self.setItems(result)
예제 #4
0
    def _update(self):
        Logger.log(
            "d", "Updating {model_class_name}.".format(
                model_class_name=self.__class__.__name__))

        global_stack = self._machine_manager.activeMachine
        if not global_stack:
            self.setItems([])
            return

        container_tree = ContainerTree.getInstance()
        quality_group_dict = container_tree.getCurrentQualityGroups()
        quality_changes_group_list = container_tree.getCurrentQualityChangesGroups(
        )

        available_quality_types = set(
            quality_type
            for quality_type, quality_group in quality_group_dict.items()
            if quality_group.is_available)
        if not available_quality_types and not quality_changes_group_list:
            # Nothing to show
            self.setItems([])
            return

        item_list = []
        # Create quality group items (intent category = "default")
        for quality_group in quality_group_dict.values():
            if not quality_group.is_available:
                continue

            layer_height = fetchLayerHeight(quality_group)

            item = {
                "name": quality_group.name,
                "is_read_only": True,
                "quality_group": quality_group,
                "quality_type": quality_group.quality_type,
                "quality_changes_group": None,
                "intent_category": "default",
                "section_name": catalog.i18nc("@label", "Default"),
                "layer_height":
                layer_height,  # layer_height is only used for sorting
            }
            item_list.append(item)

        # Sort by layer_height for built-in qualities
        item_list = sorted(item_list, key=lambda x: x["layer_height"])

        # Create intent items (non-default)
        available_intent_list = IntentManager.getInstance(
        ).getCurrentAvailableIntents()
        available_intent_list = [
            i for i in available_intent_list if i[0] != "default"
        ]
        result = []
        for intent_category, quality_type in available_intent_list:
            if not quality_group_dict[quality_type].is_available:
                continue

            result.append({
                "name":
                quality_group_dict[quality_type].
                name,  # Use the quality name as the display name
                "is_read_only":
                True,
                "quality_group":
                quality_group_dict[quality_type],
                "quality_type":
                quality_type,
                "quality_changes_group":
                None,
                "intent_category":
                intent_category,
                "section_name":
                catalog.i18nc(
                    "@label",
                    intent_translations.get(intent_category, {}).get(
                        "name", catalog.i18nc("@label", "Unknown"))),
            })
        # Sort by quality_type for each intent category

        result = sorted(result,
                        key=lambda x: (list(intent_translations).index(x[
                            "intent_category"]), x["quality_type"]))
        item_list += result

        # Create quality_changes group items
        quality_changes_item_list = []
        for quality_changes_group in quality_changes_group_list:
            # CURA-6913 Note that custom qualities can be based on "not supported", so the quality group can be None.
            quality_group = quality_group_dict.get(
                quality_changes_group.quality_type)
            quality_type = quality_changes_group.quality_type

            if not quality_changes_group.is_available:
                continue
            item = {
                "name": quality_changes_group.name,
                "is_read_only": False,
                "quality_group": quality_group,
                "quality_type": quality_type,
                "quality_changes_group": quality_changes_group,
                "intent_category": quality_changes_group.intent_category,
                "section_name": catalog.i18nc("@label", "Custom profiles"),
            }
            quality_changes_item_list.append(item)

        # Sort quality_changes items by names and append to the item list
        quality_changes_item_list = sorted(quality_changes_item_list,
                                           key=lambda x: x["name"].upper())
        item_list += quality_changes_item_list

        self.setItems(item_list)
예제 #5
0
    def _update(self):
        Logger.log(
            "d", "Updating {model_class_name}.".format(
                model_class_name=self.__class__.__name__))

        global_stack = self._machine_manager.activeMachine
        if not global_stack:
            self.setItems([])
            return

        container_tree = ContainerTree.getInstance()
        quality_group_dict = container_tree.getCurrentQualityGroups()
        quality_changes_group_list = container_tree.getCurrentQualityChangesGroups(
        )

        available_quality_types = set(
            quality_type
            for quality_type, quality_group in quality_group_dict.items()
            if quality_group.is_available)
        if not available_quality_types and not quality_changes_group_list:
            # Nothing to show
            self.setItems([])
            return

        item_list = []
        # Create quality group items (intent category = "default")
        for quality_group in quality_group_dict.values():
            if not quality_group.is_available:
                continue

            item = {
                "name": quality_group.name,
                "is_read_only": True,
                "quality_group": quality_group,
                "quality_type": quality_group.quality_type,
                "quality_changes_group": None,
                "intent_category": "default",
                "section_name": catalog.i18nc("@label", "Default"),
            }
            item_list.append(item)
        # Sort by quality names
        item_list = sorted(item_list, key=lambda x: x["name"].upper())

        # Create intent items (non-default)
        available_intent_list = IntentManager.getInstance(
        ).getCurrentAvailableIntents()
        available_intent_list = [
            i for i in available_intent_list if i[0] != "default"
        ]
        result = []
        for intent_category, quality_type in available_intent_list:
            result.append({
                "name":
                quality_group_dict[quality_type].
                name,  # Use the quality name as the display name
                "is_read_only":
                True,
                "quality_group":
                quality_group_dict[quality_type],
                "quality_type":
                quality_type,
                "quality_changes_group":
                None,
                "intent_category":
                intent_category,
                "section_name":
                catalog.i18nc("@label", intent_category.capitalize()),
            })
        # Sort by quality_type for each intent category
        result = sorted(result,
                        key=lambda x:
                        (x["intent_category"], x["quality_type"]))
        item_list += result

        # Create quality_changes group items
        quality_changes_item_list = []
        for quality_changes_group in quality_changes_group_list:
            quality_group = quality_group_dict.get(
                quality_changes_group.quality_type)
            item = {
                "name": quality_changes_group.name,
                "is_read_only": False,
                "quality_group": quality_group,
                "quality_type": quality_group.quality_type,
                "quality_changes_group": quality_changes_group,
                "intent_category": quality_changes_group.intent_category,
                "section_name": catalog.i18nc("@label", "Custom profiles"),
            }
            quality_changes_item_list.append(item)

        # Sort quality_changes items by names and append to the item list
        quality_changes_item_list = sorted(quality_changes_item_list,
                                           key=lambda x: x["name"].upper())
        item_list += quality_changes_item_list

        self.setItems(item_list)