Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/cura
diff options
context:
space:
mode:
authorGhostkeeper <rubend@tutanota.com>2016-10-21 14:59:23 +0300
committerGhostkeeper <rubend@tutanota.com>2016-10-21 14:59:23 +0300
commitc92ccee1e43ca12f256b8086394efa333854ca74 (patch)
tree71eea30d6be2714f126107fc8bd746419d9fe92d /cura
parente02284b1f06068c321e7dcf10856b82524c4c2bb (diff)
Add layer height role to profiles model
This layer height computation is rather complex, but because the items are now computed in a separate function, we can safely overwrite that and the update is made only once in the UI. Contributes to issue CURA-2737.
Diffstat (limited to 'cura')
-rw-r--r--cura/Settings/ProfilesModel.py56
1 files changed, 54 insertions, 2 deletions
diff --git a/cura/Settings/ProfilesModel.py b/cura/Settings/ProfilesModel.py
index 0f7c8c1ae7..c84b7d3b87 100644
--- a/cura/Settings/ProfilesModel.py
+++ b/cura/Settings/ProfilesModel.py
@@ -1,18 +1,23 @@
# Copyright (c) 2016 Ultimaker B.V.
-# Uranium is released under the terms of the AGPLv3 or higher.
+# Cura is released under the terms of the AGPLv3 or higher.
+
+from PyQt5.QtCore import Qt
from UM.Application import Application
+from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel
from cura.QualityManager import QualityManager
from cura.Settings.ExtruderManager import ExtruderManager
-from cura.Settings.MachineManager import MachineManager
## QML Model for listing the current list of valid quality profiles.
#
class ProfilesModel(InstanceContainersModel):
+ LayerHeightRole = Qt.UserRole + 1001
+
def __init__(self, parent = None):
super().__init__(parent)
+ self.addRoleName(self.LayerHeightRole, "layer_height")
Application.getInstance().globalContainerStackChanged.connect(self._update)
@@ -40,3 +45,50 @@ class ProfilesModel(InstanceContainersModel):
# The actual list of quality profiles come from the first extruder in the extruder list.
return QualityManager.getInstance().findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
extruder_stacks)
+
+ ## Re-computes the items in this model, and adds the layer height role.
+ def _recomputeItems(self):
+ #Some globals that we can re-use.
+ global_container_stack = Application.getInstance().getGlobalContainerStack()
+ if global_container_stack is None:
+ return
+ container_registry = ContainerRegistry.getInstance()
+ machine_manager = Application.getInstance().getMachineManager()
+
+ for item in super()._recomputeItems():
+ profile = container_registry.findContainers(id = item["id"])
+ if not profile:
+ item["layer_height"] = "" #Can't update a profile that is unknown.
+ yield item
+ continue
+
+ #Easy case: This profile defines its own layer height.
+ profile = profile[0]
+ if profile.hasProperty("layer_height", "value"):
+ item["layer_height"] = str(profile.getProperty("layer_height", "value")) + "mm"
+ yield item
+ continue
+
+ #Quality-changes profile that has no value for layer height. Get the corresponding quality profile and ask that profile.
+ quality_type = profile.getMetaDataEntry("quality_type", None)
+ if quality_type:
+ quality_results = machine_manager.determineQualityAndQualityChangesForQualityType(quality_type)
+ for quality_result in quality_results:
+ if quality_result["stack"] is global_container_stack:
+ quality = quality_result["quality"]
+ break
+ else: #No global container stack in the results:
+ quality = quality_results[0]["quality"] #Take any of the extruders.
+ if quality and quality.hasProperty("layer_height", "value"):
+ item["layer_height"] = str(quality.getProperty("layer_height", "value")) + "mm"
+ yield item
+ continue
+
+ #Quality has no value for layer height either. Get the layer height from somewhere lower in the stack.
+ skip_until_container = global_container_stack.findContainer({"type": "material"})
+ if not skip_until_container: #No material in stack.
+ skip_until_container = global_container_stack.findContainer({"type": "variant"})
+ if not skip_until_container: #No variant in stack.
+ skip_until_container = global_container_stack.getBottom()
+ item["layer_height"] = str(global_container_stack.getRawProperty("layer_height", "value", skip_until_container = skip_until_container.getId())) + "mm" #Fall through to the currently loaded material.
+ yield item \ No newline at end of file