def _update(self):
        Logger.log(
            "d", "Updating {model_class_name}.".format(
                model_class_name=self.__class__.__name__))

        # CURA-6836
        # LabelBar is a repeater that creates labels for quality layer heights. Because of an optimization in
        # UM.ListModel, the model will not remove all items and recreate new ones every time there's an update.
        # Because LabelBar uses Repeater with Labels anchoring to "undefined" in certain cases, the anchoring will be
        # kept the same as before.
        self.setItems([])

        global_stack = cura.CuraApplication.CuraApplication.getInstance(
        ).getGlobalContainerStack()
        if global_stack is None:
            self.setItems([])
            Logger.log(
                "d",
                "No active GlobalStack, set quality profile model as empty.")
            return

        if not self._layer_height_unit:
            unit = global_stack.definition.getProperty("layer_height", "unit")
            if not unit:
                unit = ""
            self._layer_height_unit = unit

        # Check for material compatibility
        if not cura.CuraApplication.CuraApplication.getInstance(
        ).getMachineManager().activeMaterialsCompatible():
            Logger.log(
                "d",
                "No active material compatibility, set quality profile model as empty."
            )
            self.setItems([])
            return

        quality_group_dict = ContainerTree.getInstance(
        ).getCurrentQualityGroups()

        item_list = []
        for quality_group in quality_group_dict.values():
            layer_height = fetchLayerHeight(quality_group)

            item = {
                "name": quality_group.name,
                "quality_type": quality_group.quality_type,
                "layer_height": layer_height,
                "layer_height_unit": self._layer_height_unit,
                "available": quality_group.is_available,
                "quality_group": quality_group,
                "is_experimental": quality_group.is_experimental
            }

            item_list.append(item)

        # Sort items based on layer_height
        item_list = sorted(item_list, key=lambda x: x["layer_height"])

        self.setItems(item_list)
コード例 #2
0
ファイル: IntentModel.py プロジェクト: zlh6630/Cura-1
    def _getIntentsForMaterial(
            self, active_material_node: "MaterialNode",
            quality_groups: Dict[str, "QualityGroup"]) -> List[Dict[str, Any]]:
        extruder_intents = []  # type: List[Dict[str, Any]]

        for quality_id, quality_node in active_material_node.qualities.items():
            if quality_node.quality_type not in quality_groups:  # Don't add the empty quality type (or anything else that would crash, defensively).
                continue
            quality_group = quality_groups[quality_node.quality_type]
            layer_height = fetchLayerHeight(quality_group)

            for intent_id, intent_node in quality_node.intents.items():
                if intent_node.intent_category != self._intent_category:
                    continue
                extruder_intents.append({
                    "name":
                    quality_group.name,
                    "quality_type":
                    quality_group.quality_type,
                    "layer_height":
                    layer_height,
                    "available":
                    quality_group.is_available,
                    "intent_category":
                    self._intent_category
                })
        return extruder_intents
コード例 #3
0
    def _update(self) -> None:
        new_items = []  # type: List[Dict[str, Any]]
        global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
        if not global_stack:
            self.setItems(new_items)
            return
        quality_groups = ContainerTree.getInstance().getCurrentQualityGroups()

        material_nodes = self._getActiveMaterials()

        added_quality_type_set = set()  # type: Set[str]
        for material_node in material_nodes:
            intents = self._getIntentsForMaterial(material_node, quality_groups)
            for intent in intents:
                if intent["quality_type"] not in added_quality_type_set:
                    new_items.append(intent)
                    added_quality_type_set.add(intent["quality_type"])

        # Now that we added all intents that we found something for, ensure that we set add ticks (and layer_heights)
        # for all groups that we don't have anything for (and set it to not available)
        for quality_type, quality_group in quality_groups.items():
            # Add the intents that are of the correct category
            if quality_type not in added_quality_type_set:
                layer_height = fetchLayerHeight(quality_group)
                new_items.append({"name": "Unavailable",
                                  "quality_type": quality_type,
                                  "layer_height": layer_height,
                                  "intent_category": self._intent_category,
                                  "available": False})
                added_quality_type_set.add(quality_type)

        new_items = sorted(new_items, key = lambda x: x["layer_height"])
        self.setItems(new_items)
コード例 #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)