mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 11:17:49 -06:00
WIP: Refactor quality model files
This commit is contained in:
parent
171a05ae6a
commit
236bd09d08
7 changed files with 172 additions and 166 deletions
|
@ -52,8 +52,11 @@ from UM.Settings.SettingDefinition import SettingDefinition, DefinitionPropertyT
|
|||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.SettingFunction import SettingFunction
|
||||
from cura.Settings.MachineNameValidator import MachineNameValidator
|
||||
|
||||
from cura.Machines.Models.NozzleModel import NozzleModel
|
||||
from cura.Settings.ProfilesModel import NewQualityProfilesModel, NewCustomQualityProfilesModel
|
||||
from cura.Machines.Models.QualityProfilesModel import QualityProfilesModel
|
||||
from cura.Machines.Models.CustomQualityProfilesModel import CustomQualityProfilesModel
|
||||
|
||||
from cura.Settings.MaterialsModel import MaterialsModel, BrandMaterialsModel, GenericMaterialsModel, NewMaterialsModel
|
||||
from cura.Settings.SettingInheritanceManager import SettingInheritanceManager
|
||||
from cura.Settings.SimpleModeSettingsManager import SimpleModeSettingsManager
|
||||
|
@ -390,8 +393,8 @@ class CuraApplication(QtApplication):
|
|||
|
||||
self.getCuraSceneController().setActiveBuildPlate(0) # Initialize
|
||||
|
||||
self._new_quality_profile_model = None
|
||||
self._new_custom_quality_profile_model = None
|
||||
self._quality_profile_model = None
|
||||
self._custom_quality_profile_model = None
|
||||
|
||||
CuraApplication.Created = True
|
||||
|
||||
|
@ -896,15 +899,15 @@ class CuraApplication(QtApplication):
|
|||
def getPrintInformation(self):
|
||||
return self._print_information
|
||||
|
||||
def getNewQualityProfileModel(self, *args, **kwargs):
|
||||
if self._new_quality_profile_model is None:
|
||||
self._new_quality_profile_model = NewQualityProfilesModel(self)
|
||||
return self._new_quality_profile_model
|
||||
def getQualityProfileModel(self, *args, **kwargs):
|
||||
if self._quality_profile_model is None:
|
||||
self._quality_profile_model = QualityProfilesModel(self)
|
||||
return self._quality_profile_model
|
||||
|
||||
def getNewCustomQualityProfilesModel(self, *args, **kwargs):
|
||||
if self._new_custom_quality_profile_model is None:
|
||||
self._new_custom_quality_profile_model = NewCustomQualityProfilesModel(self)
|
||||
return self._new_custom_quality_profile_model
|
||||
def getCustomQualityProfilesModel(self, *args, **kwargs):
|
||||
if self._custom_quality_profile_model is None:
|
||||
self._custom_quality_profile_model = CustomQualityProfilesModel(self)
|
||||
return self._custom_quality_profile_model
|
||||
|
||||
## Registers objects for the QML engine to use.
|
||||
#
|
||||
|
@ -940,8 +943,8 @@ class CuraApplication(QtApplication):
|
|||
# TODO: make this singleton?
|
||||
qmlRegisterType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel")
|
||||
|
||||
qmlRegisterSingletonType(NewQualityProfilesModel, "Cura", 1, 0, "NewQualityProfilesModel", self.getNewQualityProfileModel)
|
||||
qmlRegisterSingletonType(NewCustomQualityProfilesModel, "Cura", 1, 0, "NewCustomQualityProfilesModel", self.getNewCustomQualityProfilesModel)
|
||||
qmlRegisterSingletonType(QualityProfilesModel, "Cura", 1, 0, "QualityProfilesModel", self.getQualityProfileModel)
|
||||
qmlRegisterSingletonType(CustomQualityProfilesModel, "Cura", 1, 0, "CustomQualityProfilesModel", self.getCustomQualityProfilesModel)
|
||||
qmlRegisterType(NozzleModel, "Cura", 1, 0, "NozzleModel")
|
||||
|
||||
qmlRegisterType(MaterialsModel, "Cura", 1, 0, "MaterialsModel")
|
||||
|
|
36
cura/Machines/Models/CustomQualityProfilesModel.py
Normal file
36
cura/Machines/Models/CustomQualityProfilesModel.py
Normal file
|
@ -0,0 +1,36 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from UM.Application import Application
|
||||
from UM.Logger import Logger
|
||||
|
||||
from cura.Machines.Models.QualityProfilesModel import QualityProfilesModel
|
||||
|
||||
|
||||
class CustomQualityProfilesModel(QualityProfilesModel):
|
||||
|
||||
def _update(self):
|
||||
Logger.log("d", "Updating %s ...", self.__class__.__name__)
|
||||
|
||||
active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
|
||||
if active_global_stack is None:
|
||||
self.setItems([])
|
||||
Logger.log("d", "No active GlobalStack, set %s as empty.", self.__class__.__name__)
|
||||
return
|
||||
|
||||
quality_changes_group_dict = self._quality_manager.getQualityChangesGroups(active_global_stack)
|
||||
|
||||
item_list = []
|
||||
for key in sorted(quality_changes_group_dict):
|
||||
quality_changes_group = quality_changes_group_dict[key]
|
||||
|
||||
item = {"id": "TODO", # TODO: probably will be removed
|
||||
"name": quality_changes_group.name,
|
||||
"layer_height": "",
|
||||
"layer_height_without_unit": "",
|
||||
"available": quality_changes_group.is_available,
|
||||
"quality_changes_group": quality_changes_group}
|
||||
|
||||
item_list.append(item)
|
||||
|
||||
self.setItems(item_list)
|
|
@ -1,3 +1,6 @@
|
|||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
from UM.Application import Application
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
|
||||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
|
|
|
@ -1,135 +1,98 @@
|
|||
# Copyright (c) 2017 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from collections import OrderedDict
|
||||
from typing import List, TYPE_CHECKING
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
from UM.Application import Application
|
||||
from UM.Logger import Logger
|
||||
from UM.Qt.ListModel import ListModel
|
||||
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.Machines.QualityManager import QualityGroup
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from cura.Settings.ExtruderStack import ExtruderStack
|
||||
|
||||
|
||||
class NewQualityProfilesModel(ListModel):
|
||||
IdRole = Qt.UserRole + 1
|
||||
NameRole = Qt.UserRole + 2
|
||||
QualityTypeRole = Qt.UserRole + 3
|
||||
LayerHeightRole = Qt.UserRole + 4
|
||||
AvailableRole = Qt.UserRole + 5
|
||||
QualityGroupRole = Qt.UserRole + 6
|
||||
QualityChangesGroupRole = Qt.UserRole + 7
|
||||
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.addRoleName(self.IdRole, "id")
|
||||
self.addRoleName(self.NameRole, "name")
|
||||
self.addRoleName(self.QualityTypeRole, "quality_type")
|
||||
self.addRoleName(self.LayerHeightRole, "layer_height")
|
||||
self.addRoleName(self.AvailableRole, "available")
|
||||
self.addRoleName(self.QualityGroupRole, "quality_group")
|
||||
self.addRoleName(self.QualityChangesGroupRole, "quality_changes_group")
|
||||
|
||||
# connect signals
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._update)
|
||||
Application.getInstance().getMachineManager().activeQualityGroupChanged.connect(self._update)
|
||||
|
||||
self._quality_manager = Application.getInstance()._quality_manager
|
||||
|
||||
self._layer_height_unit = "" # This is cached
|
||||
|
||||
def _update(self):
|
||||
Logger.log("d", "Updating quality profile model ...")
|
||||
|
||||
active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
|
||||
if active_global_stack is None:
|
||||
self.setItems([])
|
||||
Logger.log("d", "No active GlobalStack, set quality profile model as empty.")
|
||||
return
|
||||
|
||||
quality_group_dict = self._quality_manager.getQualityGroups(active_global_stack)
|
||||
|
||||
item_list = []
|
||||
for key in sorted(quality_group_dict):
|
||||
quality_group = quality_group_dict[key]
|
||||
|
||||
layer_height = self._fetchLayerHeight(quality_group)
|
||||
|
||||
item = {"id": "TODO", # TODO: probably will be removed
|
||||
"name": quality_group.name,
|
||||
"quality_type": quality_group.quality_type,
|
||||
"layer_height": layer_height + self._layer_height_unit,
|
||||
"layer_height_without_unit": layer_height,
|
||||
"available": quality_group.is_available,
|
||||
"quality_group": quality_group}
|
||||
|
||||
item_list.append(item)
|
||||
|
||||
# Sort items based on layer_height
|
||||
item_list = sorted(item_list, key = lambda x: float(x["layer_height_without_unit"]))
|
||||
|
||||
self.setItems(item_list)
|
||||
|
||||
def _fetchLayerHeight(self, quality_group: "QualityGroup"):
|
||||
active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
|
||||
if not self._layer_height_unit:
|
||||
unit = active_global_stack.definition.getProperty("layer_height", "unit")
|
||||
if not unit:
|
||||
unit = ""
|
||||
self._layer_height_unit = unit
|
||||
|
||||
default_layer_height = active_global_stack.definition.getProperty("layer_height", "value")
|
||||
|
||||
# Get layer_height from the quality profile for the GlobalStack
|
||||
container = quality_group.node_for_global.getContainer()
|
||||
|
||||
layer_height = default_layer_height
|
||||
if container.hasProperty("layer_height", "value"):
|
||||
layer_height = str(container.getProperty("layer_height", "value"))
|
||||
else:
|
||||
# Look for layer_height in the GlobalStack from material -> definition
|
||||
for idx in range(4):
|
||||
container = active_global_stack.getContainer(idx)
|
||||
if container.hasProperty("layer_height", "value"):
|
||||
layer_height = container.getProperty("layer_height", "value")
|
||||
break
|
||||
return str(layer_height)
|
||||
|
||||
|
||||
class NewCustomQualityProfilesModel(NewQualityProfilesModel):
|
||||
|
||||
def _update(self):
|
||||
Logger.log("d", "Updating %s ...", self.__class__.__name__)
|
||||
|
||||
active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
|
||||
if active_global_stack is None:
|
||||
self.setItems([])
|
||||
Logger.log("d", "No active GlobalStack, set %s as empty.", self.__class__.__name__)
|
||||
return
|
||||
|
||||
quality_changes_group_dict = self._quality_manager.getQualityChangesGroups(active_global_stack)
|
||||
|
||||
item_list = []
|
||||
for key in sorted(quality_changes_group_dict):
|
||||
quality_changes_group = quality_changes_group_dict[key]
|
||||
|
||||
item = {"id": "TODO", # TODO: probably will be removed
|
||||
"name": quality_changes_group.name,
|
||||
"layer_height": "",
|
||||
"layer_height_without_unit": "",
|
||||
"available": quality_changes_group.is_available,
|
||||
"quality_changes_group": quality_changes_group}
|
||||
|
||||
item_list.append(item)
|
||||
|
||||
self.setItems(item_list)
|
||||
# Copyright (c) 2018 Ultimaker B.V.
|
||||
# Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
|
||||
from UM.Application import Application
|
||||
from UM.Logger import Logger
|
||||
from UM.Qt.ListModel import ListModel
|
||||
from cura.Machines.QualityManager import QualityGroup
|
||||
|
||||
|
||||
#
|
||||
# QML Model for all built-in quality profiles.
|
||||
#
|
||||
class QualityProfilesModel(ListModel):
|
||||
IdRole = Qt.UserRole + 1
|
||||
NameRole = Qt.UserRole + 2
|
||||
QualityTypeRole = Qt.UserRole + 3
|
||||
LayerHeightRole = Qt.UserRole + 4
|
||||
AvailableRole = Qt.UserRole + 5
|
||||
QualityGroupRole = Qt.UserRole + 6
|
||||
QualityChangesGroupRole = Qt.UserRole + 7
|
||||
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
|
||||
self.addRoleName(self.IdRole, "id")
|
||||
self.addRoleName(self.NameRole, "name")
|
||||
self.addRoleName(self.QualityTypeRole, "quality_type")
|
||||
self.addRoleName(self.LayerHeightRole, "layer_height")
|
||||
self.addRoleName(self.AvailableRole, "available")
|
||||
self.addRoleName(self.QualityGroupRole, "quality_group")
|
||||
self.addRoleName(self.QualityChangesGroupRole, "quality_changes_group")
|
||||
|
||||
# connect signals
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._update)
|
||||
Application.getInstance().getMachineManager().activeQualityGroupChanged.connect(self._update)
|
||||
|
||||
self._quality_manager = Application.getInstance()._quality_manager
|
||||
|
||||
self._layer_height_unit = "" # This is cached
|
||||
|
||||
def _update(self):
|
||||
Logger.log("d", "Updating quality profile model ...")
|
||||
|
||||
active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
|
||||
if active_global_stack is None:
|
||||
self.setItems([])
|
||||
Logger.log("d", "No active GlobalStack, set quality profile model as empty.")
|
||||
return
|
||||
|
||||
quality_group_dict = self._quality_manager.getQualityGroups(active_global_stack)
|
||||
|
||||
item_list = []
|
||||
for key in sorted(quality_group_dict):
|
||||
quality_group = quality_group_dict[key]
|
||||
|
||||
layer_height = self._fetchLayerHeight(quality_group)
|
||||
|
||||
item = {"id": "TODO", # TODO: probably will be removed
|
||||
"name": quality_group.name,
|
||||
"quality_type": quality_group.quality_type,
|
||||
"layer_height": layer_height + self._layer_height_unit,
|
||||
"layer_height_without_unit": layer_height,
|
||||
"available": quality_group.is_available,
|
||||
"quality_group": quality_group}
|
||||
|
||||
item_list.append(item)
|
||||
|
||||
# Sort items based on layer_height
|
||||
item_list = sorted(item_list, key = lambda x: float(x["layer_height_without_unit"]))
|
||||
|
||||
self.setItems(item_list)
|
||||
|
||||
def _fetchLayerHeight(self, quality_group: "QualityGroup"):
|
||||
active_global_stack = Application.getInstance().getMachineManager()._global_container_stack
|
||||
if not self._layer_height_unit:
|
||||
unit = active_global_stack.definition.getProperty("layer_height", "unit")
|
||||
if not unit:
|
||||
unit = ""
|
||||
self._layer_height_unit = unit
|
||||
|
||||
default_layer_height = active_global_stack.definition.getProperty("layer_height", "value")
|
||||
|
||||
# Get layer_height from the quality profile for the GlobalStack
|
||||
container = quality_group.node_for_global.getContainer()
|
||||
|
||||
layer_height = default_layer_height
|
||||
if container.hasProperty("layer_height", "value"):
|
||||
layer_height = str(container.getProperty("layer_height", "value"))
|
||||
else:
|
||||
# Look for layer_height in the GlobalStack from material -> definition
|
||||
for idx in range(4):
|
||||
container = active_global_stack.getContainer(idx)
|
||||
if container.hasProperty("layer_height", "value"):
|
||||
layer_height = container.getProperty("layer_height", "value")
|
||||
break
|
||||
return str(layer_height)
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright (c) 2016 Ultimaker B.V.
|
||||
// Copyright (c) 2018 Ultimaker B.V.
|
||||
// Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import QtQuick 2.8
|
||||
|
@ -13,7 +13,7 @@ Menu
|
|||
|
||||
Instantiator
|
||||
{
|
||||
model: Cura.NewQualityProfilesModel
|
||||
model: Cura.QualityProfilesModel
|
||||
|
||||
MenuItem
|
||||
{
|
||||
|
@ -34,18 +34,18 @@ Menu
|
|||
MenuSeparator
|
||||
{
|
||||
id: customSeparator
|
||||
visible: Cura.NewCustomQualityProfilesModel.rowCount > 0
|
||||
visible: Cura.CustomQualityProfilesModel.rowCount > 0
|
||||
}
|
||||
|
||||
Instantiator
|
||||
{
|
||||
id: customProfileInstantiator
|
||||
model: Cura.NewCustomQualityProfilesModel
|
||||
model: Cura.CustomQualityProfilesModel
|
||||
|
||||
Connections
|
||||
{
|
||||
target: Cura.NewCustomQualityProfilesModel
|
||||
onModelReset: customSeparator.visible = Cura.NewCustomQualityProfilesModel.rowCount() > 0
|
||||
target: Cura.CustomQualityProfilesModel
|
||||
onModelReset: customSeparator.visible = Cura.CustomQualityProfilesModel.rowCount() > 0
|
||||
}
|
||||
|
||||
MenuItem
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
// Copyright (c) 2017 Ultimaker B.V.
|
||||
// Copyright (c) 2018 Ultimaker B.V.
|
||||
// Cura is released under the terms of the LGPLv3 or higher.
|
||||
|
||||
import QtQuick 2.7
|
||||
import QtQuick 2.8
|
||||
import QtQuick.Controls 1.4
|
||||
import QtQuick.Controls.Styles 1.4
|
||||
import QtQuick.Layouts 1.3
|
||||
|
@ -58,7 +58,7 @@ Item
|
|||
running: false
|
||||
repeat: false
|
||||
onTriggered: {
|
||||
var item = Cura.NewQualityProfilesModel.getItem(qualitySlider.value);
|
||||
var item = Cura.QualityProfilesModel.getItem(qualitySlider.value);
|
||||
Cura.MachineManager.activeQualityGroup = item.quality_group;
|
||||
}
|
||||
}
|
||||
|
@ -105,8 +105,8 @@ Item
|
|||
var availableMin = -1
|
||||
var availableMax = -1
|
||||
|
||||
for (var i = 0; i < Cura.NewQualityProfilesModel.rowCount(); i++) {
|
||||
var qualityItem = Cura.NewQualityProfilesModel.getItem(i)
|
||||
for (var i = 0; i < Cura.QualityProfilesModel.rowCount(); i++) {
|
||||
var qualityItem = Cura.QualityProfilesModel.getItem(i)
|
||||
|
||||
// Add each quality item to the UI quality model
|
||||
qualityModel.append(qualityItem)
|
||||
|
@ -168,7 +168,7 @@ Item
|
|||
qualityModel.existingQualityProfile = 0
|
||||
|
||||
// check, the ticks count cannot be less than zero
|
||||
qualityModel.totalTicks = Math.max(0, Cura.NewQualityProfilesModel.rowCount() - 1)
|
||||
qualityModel.totalTicks = Math.max(0, Cura.QualityProfilesModel.rowCount() - 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,13 +194,13 @@ Item
|
|||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.top: parent.top
|
||||
anchors.topMargin: Math.round(UM.Theme.getSize("sidebar_margin").height / 2)
|
||||
color: (Cura.MachineManager.activeMachine != null && Cura.NewQualityProfilesModel.getItem(index).available) ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
|
||||
color: (Cura.MachineManager.activeMachine != null && Cura.QualityProfilesModel.getItem(index).available) ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
|
||||
text:
|
||||
{
|
||||
var result = ""
|
||||
if(Cura.MachineManager.activeMachine != null)
|
||||
{
|
||||
result = Cura.NewQualityProfilesModel.getItem(index).layer_height_without_unit
|
||||
result = Cura.QualityProfilesModel.getItem(index).layer_height_without_unit
|
||||
|
||||
if(result == undefined)
|
||||
{
|
||||
|
@ -265,7 +265,7 @@ Item
|
|||
Rectangle
|
||||
{
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
color: Cura.NewQualityProfilesModel.getItem(index).available ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
|
||||
color: Cura.QualityProfilesModel.getItem(index).available ? UM.Theme.getColor("quality_slider_available") : UM.Theme.getColor("quality_slider_unavailable")
|
||||
width: 1 * screenScaleFactor
|
||||
height: 6 * screenScaleFactor
|
||||
y: 0
|
||||
|
@ -411,9 +411,9 @@ Item
|
|||
// if the current profile is user-created, switch to a built-in quality
|
||||
if (Cura.SimpleModeSettingsManager.isProfileUserCreated)
|
||||
{
|
||||
if (Cura.NewQualityProfilesModel.rowCount() > 0)
|
||||
if (Cura.QualityProfilesModel.rowCount() > 0)
|
||||
{
|
||||
var item = Cura.NewQualityProfilesModel.getItem(0);
|
||||
var item = Cura.QualityProfilesModel.getItem(0);
|
||||
Cura.MachineManager.activeQualityGroup = item.quality_group;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue