|
1 |
| -# Copyright (c) 2017 Ultimaker B.V. |
2 |
| -# Cura is released under the terms of the LGPLv3 or higher. |
3 |
| - |
4 |
| -from collections import OrderedDict |
5 |
| -from typing import List, TYPE_CHECKING |
6 |
| - |
7 |
| -from PyQt5.QtCore import Qt |
8 |
| - |
9 |
| -from UM.Application import Application |
10 |
| -from UM.Logger import Logger |
11 |
| -from UM.Qt.ListModel import ListModel |
12 |
| -from UM.Settings.ContainerRegistry import ContainerRegistry |
13 |
| -from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel |
14 |
| - |
15 |
| -from cura.QualityManager import QualityManager |
16 |
| -from cura.Settings.ExtruderManager import ExtruderManager |
17 |
| -from cura.Machines.QualityManager import QualityGroup |
18 |
| - |
19 |
| -if TYPE_CHECKING: |
20 |
| - from cura.Settings.ExtruderStack import ExtruderStack |
21 |
| - |
22 |
| - |
23 |
| -class NewQualityProfilesModel(ListModel): |
24 |
| - IdRole = Qt.UserRole + 1 |
25 |
| - NameRole = Qt.UserRole + 2 |
26 |
| - QualityTypeRole = Qt.UserRole + 3 |
27 |
| - LayerHeightRole = Qt.UserRole + 4 |
28 |
| - AvailableRole = Qt.UserRole + 5 |
29 |
| - QualityGroupRole = Qt.UserRole + 6 |
30 |
| - QualityChangesGroupRole = Qt.UserRole + 7 |
31 |
| - |
32 |
| - def __init__(self, parent = None): |
33 |
| - super().__init__(parent) |
34 |
| - |
35 |
| - self.addRoleName(self.IdRole, "id") |
36 |
| - self.addRoleName(self.NameRole, "name") |
37 |
| - self.addRoleName(self.QualityTypeRole, "quality_type") |
38 |
| - self.addRoleName(self.LayerHeightRole, "layer_height") |
39 |
| - self.addRoleName(self.AvailableRole, "available") |
40 |
| - self.addRoleName(self.QualityGroupRole, "quality_group") |
41 |
| - self.addRoleName(self.QualityChangesGroupRole, "quality_changes_group") |
42 |
| - |
43 |
| - # connect signals |
44 |
| - Application.getInstance().globalContainerStackChanged.connect(self._update) |
45 |
| - Application.getInstance().getMachineManager().activeQualityGroupChanged.connect(self._update) |
46 |
| - |
47 |
| - self._quality_manager = Application.getInstance()._quality_manager |
48 |
| - |
49 |
| - self._layer_height_unit = "" # This is cached |
50 |
| - |
51 |
| - def _update(self): |
52 |
| - Logger.log("d", "Updating quality profile model ...") |
53 |
| - |
54 |
| - active_global_stack = Application.getInstance().getMachineManager()._global_container_stack |
55 |
| - if active_global_stack is None: |
56 |
| - self.setItems([]) |
57 |
| - Logger.log("d", "No active GlobalStack, set quality profile model as empty.") |
58 |
| - return |
59 |
| - |
60 |
| - quality_group_dict = self._quality_manager.getQualityGroups(active_global_stack) |
61 |
| - |
62 |
| - item_list = [] |
63 |
| - for key in sorted(quality_group_dict): |
64 |
| - quality_group = quality_group_dict[key] |
65 |
| - |
66 |
| - layer_height = self._fetchLayerHeight(quality_group) |
67 |
| - |
68 |
| - item = {"id": "TODO", # TODO: probably will be removed |
69 |
| - "name": quality_group.name, |
70 |
| - "quality_type": quality_group.quality_type, |
71 |
| - "layer_height": layer_height + self._layer_height_unit, |
72 |
| - "layer_height_without_unit": layer_height, |
73 |
| - "available": quality_group.is_available, |
74 |
| - "quality_group": quality_group} |
75 |
| - |
76 |
| - item_list.append(item) |
77 |
| - |
78 |
| - # Sort items based on layer_height |
79 |
| - item_list = sorted(item_list, key = lambda x: float(x["layer_height_without_unit"])) |
80 |
| - |
81 |
| - self.setItems(item_list) |
82 |
| - |
83 |
| - def _fetchLayerHeight(self, quality_group: "QualityGroup"): |
84 |
| - active_global_stack = Application.getInstance().getMachineManager()._global_container_stack |
85 |
| - if not self._layer_height_unit: |
86 |
| - unit = active_global_stack.definition.getProperty("layer_height", "unit") |
87 |
| - if not unit: |
88 |
| - unit = "" |
89 |
| - self._layer_height_unit = unit |
90 |
| - |
91 |
| - default_layer_height = active_global_stack.definition.getProperty("layer_height", "value") |
92 |
| - |
93 |
| - # Get layer_height from the quality profile for the GlobalStack |
94 |
| - container = quality_group.node_for_global.getContainer() |
95 |
| - |
96 |
| - layer_height = default_layer_height |
97 |
| - if container.hasProperty("layer_height", "value"): |
98 |
| - layer_height = str(container.getProperty("layer_height", "value")) |
99 |
| - else: |
100 |
| - # Look for layer_height in the GlobalStack from material -> definition |
101 |
| - for idx in range(4): |
102 |
| - container = active_global_stack.getContainer(idx) |
103 |
| - if container.hasProperty("layer_height", "value"): |
104 |
| - layer_height = container.getProperty("layer_height", "value") |
105 |
| - break |
106 |
| - return str(layer_height) |
107 |
| - |
108 |
| - |
109 |
| -class NewCustomQualityProfilesModel(NewQualityProfilesModel): |
110 |
| - |
111 |
| - def _update(self): |
112 |
| - Logger.log("d", "Updating %s ...", self.__class__.__name__) |
113 |
| - |
114 |
| - active_global_stack = Application.getInstance().getMachineManager()._global_container_stack |
115 |
| - if active_global_stack is None: |
116 |
| - self.setItems([]) |
117 |
| - Logger.log("d", "No active GlobalStack, set %s as empty.", self.__class__.__name__) |
118 |
| - return |
119 |
| - |
120 |
| - quality_changes_group_dict = self._quality_manager.getQualityChangesGroups(active_global_stack) |
121 |
| - |
122 |
| - item_list = [] |
123 |
| - for key in sorted(quality_changes_group_dict): |
124 |
| - quality_changes_group = quality_changes_group_dict[key] |
125 |
| - |
126 |
| - item = {"id": "TODO", # TODO: probably will be removed |
127 |
| - "name": quality_changes_group.name, |
128 |
| - "layer_height": "", |
129 |
| - "layer_height_without_unit": "", |
130 |
| - "available": quality_changes_group.is_available, |
131 |
| - "quality_changes_group": quality_changes_group} |
132 |
| - |
133 |
| - item_list.append(item) |
134 |
| - |
135 |
| - self.setItems(item_list) |
| 1 | +# Copyright (c) 2018 Ultimaker B.V. |
| 2 | +# Cura is released under the terms of the LGPLv3 or higher. |
| 3 | + |
| 4 | +from PyQt5.QtCore import Qt |
| 5 | + |
| 6 | +from UM.Application import Application |
| 7 | +from UM.Logger import Logger |
| 8 | +from UM.Qt.ListModel import ListModel |
| 9 | +from cura.Machines.QualityManager import QualityGroup |
| 10 | + |
| 11 | + |
| 12 | +# |
| 13 | +# QML Model for all built-in quality profiles. |
| 14 | +# |
| 15 | +class QualityProfilesModel(ListModel): |
| 16 | + IdRole = Qt.UserRole + 1 |
| 17 | + NameRole = Qt.UserRole + 2 |
| 18 | + QualityTypeRole = Qt.UserRole + 3 |
| 19 | + LayerHeightRole = Qt.UserRole + 4 |
| 20 | + AvailableRole = Qt.UserRole + 5 |
| 21 | + QualityGroupRole = Qt.UserRole + 6 |
| 22 | + QualityChangesGroupRole = Qt.UserRole + 7 |
| 23 | + |
| 24 | + def __init__(self, parent = None): |
| 25 | + super().__init__(parent) |
| 26 | + |
| 27 | + self.addRoleName(self.IdRole, "id") |
| 28 | + self.addRoleName(self.NameRole, "name") |
| 29 | + self.addRoleName(self.QualityTypeRole, "quality_type") |
| 30 | + self.addRoleName(self.LayerHeightRole, "layer_height") |
| 31 | + self.addRoleName(self.AvailableRole, "available") |
| 32 | + self.addRoleName(self.QualityGroupRole, "quality_group") |
| 33 | + self.addRoleName(self.QualityChangesGroupRole, "quality_changes_group") |
| 34 | + |
| 35 | + # connect signals |
| 36 | + Application.getInstance().globalContainerStackChanged.connect(self._update) |
| 37 | + Application.getInstance().getMachineManager().activeQualityGroupChanged.connect(self._update) |
| 38 | + |
| 39 | + self._quality_manager = Application.getInstance()._quality_manager |
| 40 | + |
| 41 | + self._layer_height_unit = "" # This is cached |
| 42 | + |
| 43 | + def _update(self): |
| 44 | + Logger.log("d", "Updating quality profile model ...") |
| 45 | + |
| 46 | + active_global_stack = Application.getInstance().getMachineManager()._global_container_stack |
| 47 | + if active_global_stack is None: |
| 48 | + self.setItems([]) |
| 49 | + Logger.log("d", "No active GlobalStack, set quality profile model as empty.") |
| 50 | + return |
| 51 | + |
| 52 | + quality_group_dict = self._quality_manager.getQualityGroups(active_global_stack) |
| 53 | + |
| 54 | + item_list = [] |
| 55 | + for key in sorted(quality_group_dict): |
| 56 | + quality_group = quality_group_dict[key] |
| 57 | + |
| 58 | + layer_height = self._fetchLayerHeight(quality_group) |
| 59 | + |
| 60 | + item = {"id": "TODO", # TODO: probably will be removed |
| 61 | + "name": quality_group.name, |
| 62 | + "quality_type": quality_group.quality_type, |
| 63 | + "layer_height": layer_height + self._layer_height_unit, |
| 64 | + "layer_height_without_unit": layer_height, |
| 65 | + "available": quality_group.is_available, |
| 66 | + "quality_group": quality_group} |
| 67 | + |
| 68 | + item_list.append(item) |
| 69 | + |
| 70 | + # Sort items based on layer_height |
| 71 | + item_list = sorted(item_list, key = lambda x: float(x["layer_height_without_unit"])) |
| 72 | + |
| 73 | + self.setItems(item_list) |
| 74 | + |
| 75 | + def _fetchLayerHeight(self, quality_group: "QualityGroup"): |
| 76 | + active_global_stack = Application.getInstance().getMachineManager()._global_container_stack |
| 77 | + if not self._layer_height_unit: |
| 78 | + unit = active_global_stack.definition.getProperty("layer_height", "unit") |
| 79 | + if not unit: |
| 80 | + unit = "" |
| 81 | + self._layer_height_unit = unit |
| 82 | + |
| 83 | + default_layer_height = active_global_stack.definition.getProperty("layer_height", "value") |
| 84 | + |
| 85 | + # Get layer_height from the quality profile for the GlobalStack |
| 86 | + container = quality_group.node_for_global.getContainer() |
| 87 | + |
| 88 | + layer_height = default_layer_height |
| 89 | + if container.hasProperty("layer_height", "value"): |
| 90 | + layer_height = str(container.getProperty("layer_height", "value")) |
| 91 | + else: |
| 92 | + # Look for layer_height in the GlobalStack from material -> definition |
| 93 | + for idx in range(4): |
| 94 | + container = active_global_stack.getContainer(idx) |
| 95 | + if container.hasProperty("layer_height", "value"): |
| 96 | + layer_height = container.getProperty("layer_height", "value") |
| 97 | + break |
| 98 | + return str(layer_height) |
0 commit comments