Merge branch 'refactoring_machine_manager' of github.com:Ultimaker/Cura into refactoring_machine_manager

This commit is contained in:
Jack Ha 2018-02-26 09:30:33 +01:00
commit 11be94c735
10 changed files with 77 additions and 110 deletions

View file

@ -955,8 +955,6 @@ class CuraApplication(QtApplication):
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
qmlRegisterType(BrandMaterialsModel, "Cura", 1, 0, "BrandMaterialsModel")
qmlRegisterType(MaterialsModel, "Cura", 1, 0, "MaterialsModel")
# TODO: make this singleton?
qmlRegisterType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel")
qmlRegisterSingletonType(QualityProfilesModel, "Cura", 1, 0, "QualityProfilesModel", self.getQualityProfileModel)

View file

@ -1,13 +1,11 @@
# Copyright (c) 2017 Ultimaker B.V.
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv3 or higher.
from typing import Any, List, Optional
from PyQt5.QtCore import Qt
from typing import Optional
from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
from UM.Logger import Logger
from UM.Qt.ListModel import ListModel
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel
def getAvailableMaterials(extruder_position: Optional[int] = None):
@ -48,6 +46,8 @@ class BaseMaterialsModel(ListModel):
ColorRole = Qt.UserRole + 6
ContainerNodeRole = Qt.UserRole + 7
extruderPositionChanged = pyqtSignal()
def __init__(self, parent = None):
super().__init__(parent)
@ -59,6 +59,17 @@ class BaseMaterialsModel(ListModel):
self.addRoleName(self.ColorRole, "color_name")
self.addRoleName(self.ContainerNodeRole, "container_node")
self._extruder_position = 0
def setExtruderPosition(self, position: int):
if self._extruder_position != position:
self._extruder_position = position
self.extruderPositionChanged.emit()
@pyqtProperty(int, fset = setExtruderPosition, notify = extruderPositionChanged)
def extruderPosition(self) -> int:
return self._extruder_positoin
class GenericMaterialsModel(BaseMaterialsModel):
@ -82,7 +93,7 @@ class GenericMaterialsModel(BaseMaterialsModel):
self.setItems([])
return
result_dict = getAvailableMaterials()
result_dict = getAvailableMaterials(self._extruder_position)
if result_dict is None:
self.setItems([])
return
@ -126,12 +137,16 @@ class BrandMaterialsModel(ListModel):
NameRole = Qt.UserRole + 1
MaterialsRole = Qt.UserRole + 2
extruderPositionChanged = pyqtSignal()
def __init__(self, parent = None):
super().__init__(parent)
self.addRoleName(self.NameRole, "name")
self.addRoleName(self.MaterialsRole, "materials")
self._extruder_position = 0
from cura.CuraApplication import CuraApplication
self._machine_manager = CuraApplication.getInstance().getMachineManager()
extruder_manager = CuraApplication.getInstance().getExtruderManager()
@ -141,13 +156,24 @@ class BrandMaterialsModel(ListModel):
extruder_manager.activeExtruderChanged.connect(self._update)
material_manager.materialsUpdated.connect(self._update)
self._update()
def setExtruderPosition(self, position: int):
if self._extruder_position != position:
self._extruder_position = position
self.extruderPositionChanged.emit()
@pyqtProperty(int, fset = setExtruderPosition, notify = extruderPositionChanged)
def extruderPosition(self) -> int:
return self._extruder_position
def _update(self):
global_stack = self._machine_manager.activeMachine
if global_stack is None:
self.setItems([])
return
result_dict = getAvailableMaterials()
result_dict = getAvailableMaterials(self._extruder_position)
if result_dict is None:
self.setItems([])
return
@ -180,7 +206,7 @@ class BrandMaterialsModel(ListModel):
for brand, material_dict in brand_group_dict.items():
brand_item = {"name": brand,
"materials": MaterialsModelGroupedByType(self)} # TODO
"materials": MaterialsModelGroupedByType(self)}
material_type_item_list = []
for material_type, material_list in material_dict.items():

View file

@ -89,7 +89,11 @@ class QualitySettingsModel(ListModel):
else:
quality_changes_node = quality_changes_group.nodes_for_extruders.get(self._extruder_position)
if quality_changes_node is not None: # it can be None if number of extruders are changed during runtime
quality_containers.insert(0, quality_changes_node.getContainer())
try:
quality_containers.insert(0, quality_changes_node.getContainer())
except:
# FIXME: This is to prevent incomplete update of QualityManager
return
settings_keys.update(quality_changes_group.getAllKeys())
current_category = ""

View file

@ -404,24 +404,17 @@ class ContainerManager(QObject):
for node in quality_changes_group.getAllNodes():
self._container_registry.removeContainer(node.metadata["id"])
## Rename a set of quality changes containers.
#
# This will search for quality_changes containers matching the supplied name and rename them.
# Note that if the machine specifies that qualities should be filtered by machine and/or material
# only the containers related to the active machine/material are renamed.
# Rename a set of quality changes containers. Returns the new name.
#
# \param quality_name The name of the quality changes containers to rename.
# \param new_name The new name of the quality changes.
#
# \return True if successful, False if not.
@pyqtSlot(QObject, str)
def renameQualityChangesGroup(self, quality_changes_group, new_name):
@pyqtSlot(QObject, str, result = str)
def renameQualityChangesGroup(self, quality_changes_group, new_name) -> str:
Logger.log("i", "Renaming QualityChangesGroup[%s] to [%s]", quality_changes_group.name, new_name)
self._machine_manager.blurSettings.emit()
if new_name == quality_changes_group.name:
Logger.log("i", "QualityChangesGroup name [%s] unchanged.", quality_changes_group.name)
return
return new_name
new_name = self._container_registry.uniqueName(new_name)
for node in quality_changes_group.getAllNodes():
@ -430,6 +423,8 @@ class ContainerManager(QObject):
self._machine_manager.activeQualityChanged.emit()
self._machine_manager.activeQualityGroupChanged.emit()
return new_name
@pyqtSlot(str, "QVariantMap")
def duplicateQualityChanges(self, quality_changes_name, quality_model_item):
global_stack = Application.getInstance().getGlobalContainerStack()

View file

@ -989,7 +989,6 @@ class MachineManager(QObject):
@pyqtSlot("QVariant")
def setGlobalVariant(self, container_node):
Logger.log("d", "---------------- container = [%s]", container_node)
self.blurSettings.emit()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
self._setGlobalVariant(container_node)
@ -998,7 +997,6 @@ class MachineManager(QObject):
@pyqtSlot(str, "QVariant")
def setMaterial(self, position, container_node):
Logger.log("d", "---------------- container = [%s]", container_node)
position = str(position)
self.blurSettings.emit()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
@ -1007,7 +1005,6 @@ class MachineManager(QObject):
@pyqtSlot(str, "QVariant")
def setVariantGroup(self, position, container_node):
Logger.log("d", "---------------- container = [%s]", container_node)
position = str(position)
self.blurSettings.emit()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
@ -1015,32 +1012,27 @@ class MachineManager(QObject):
self._updateMaterialWithVariant(position)
self._updateQualityWithMaterial()
@pyqtSlot("QVariant")
@pyqtSlot(QObject)
def setQualityGroup(self, quality_group):
Logger.log("d", "---------------- qg = [%s]", quality_group.name)
self.blurSettings.emit()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
self._setQualityGroup(quality_group)
Logger.log("d", "Quality set!")
# See if we need to show the Discard or Keep changes screen
if self.hasUserSettings and Preferences.getInstance().getValue("cura/active_mode") == 1:
Application.getInstance().discardOrKeepProfileChanges()
@pyqtProperty("QVariant", fset = setQualityGroup, notify = activeQualityGroupChanged)
@pyqtProperty(QObject, fset = setQualityGroup, notify = activeQualityGroupChanged)
def activeQualityGroup(self):
return self._current_quality_group
@pyqtSlot("QVariant")
@pyqtSlot(QObject)
def setQualityChangesGroup(self, quality_changes_group):
Logger.log("d", "---------------- qcg = [%s]", quality_changes_group.name)
self.blurSettings.emit()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
self._setQualityChangesGroup(quality_changes_group)
Logger.log("d", "Quality changes set!")
@pyqtProperty("QVariant", fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
@pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
def activeQualityChangesGroup(self):
return self._current_quality_changes_group

View file

@ -1,38 +0,0 @@
# Copyright (c) 2018 Ultimaker B.V.
# Cura is released under the terms of the LGPLv2 or higher.
from UM.Extension import Extension
from PyQt5.QtCore import QObject
class TestTool(Extension, QObject):
def __init__(self, parent = None):
QObject.__init__(self, parent)
Extension.__init__(self)
self.addMenuItem("Test material manager", self._testMaterialManager)
self.addMenuItem("Test get quality", self._testGetQuality)
self.addMenuItem("Test get quality changes", self.testGetQualityChanges)
def _testMaterialManager(self):
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
from cura.CuraApplication import CuraApplication
CuraApplication.getInstance()._material_manager._test_metadata()
def _testGetQuality(self):
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
from cura.CuraApplication import CuraApplication
result_dict = {}
global_stack = CuraApplication.getInstance().getMachineManager()._global_container_stack
result = CuraApplication.getInstance()._quality_manager.getQualityGroups(global_stack)
print("!!!!!!!!!!!!!!!!!!!")
def testGetQualityChanges(self):
print("!!!!!!!!!!!!!!!!!!!")
from cura.CuraApplication import CuraApplication
result_dict = {}
global_stack = CuraApplication.getInstance().getMachineManager()._global_container_stack
result = CuraApplication.getInstance()._quality_manager.getQualityChangesGroups(global_stack)
for name, r in result.items():
print("!!!!!!!!!! [%s] - %s" % (name, r))

View file

@ -1,13 +0,0 @@
# Copyright (c) 2016 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
from . import TestTool
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
def getMetaData():
return {}
def register(app):
return {"extension": TestTool.TestTool()}

View file

@ -1,7 +0,0 @@
{
"name": "Test Tools",
"author": "Ultimaker",
"version": "1.0",
"description": "Dump the contents of all settings to a HTML file.",
"api": 4
}

View file

@ -82,12 +82,13 @@ Menu
Cura.GenericMaterialsModel
{
id: genericMaterialsModel
//Component.onCompleted: populateMenuModels()
extruderPosition: menu.extruderIndex
}
Cura.BrandMaterialsModel
{
id: brandModel
extruderPosition: menu.extruderIndex
}
ExclusiveGroup { id: group }

View file

@ -171,36 +171,46 @@ Item
object: "<new name>"
onAccepted:
{
base.newQualityChangesNameToSwitchTo = newName; // We want to switch to the new profile once it's created
base.newQualityNameToSelect = newName; // We want to switch to the new profile once it's created
base.toActivateNewQuality = true;
Cura.ContainerManager.createQualityChanges(newName);
}
}
property string newQualityChangesNameToSwitchTo: ""
property string newQualityNameToSelect: ""
property bool toActivateNewQuality: false
// This connection makes sure that we will switch to the new
// This connection makes sure that we will switch to the correct quality after the model gets updated
Connections
{
target: qualitiesModel
onItemsChanged: {
var currentItemName = base.currentItem == null ? "" : base.currentItem.name;
var toSelectItemName = base.currentItem == null ? "" : base.currentItem.name;
if (newQualityNameToSelect != "") {
toSelectItemName = newQualityNameToSelect;
}
for (var idx = 0; idx < qualitiesModel.rowCount(); ++idx) {
var item = qualitiesModel.getItem(idx);
if (base.newQualityChangesNameToSwitchTo != "") {
if (item.name == base.newQualityChangesNameToSwitchTo) {
var newIdx = -1; // Default to nothing if nothing can be found
if (toSelectItemName != "") {
// Select the required quality name if given
for (var idx = 0; idx < qualitiesModel.rowCount(); ++idx) {
var item = qualitiesModel.getItem(idx);
if (item.name == toSelectItemName) {
// Switch to the newly created profile if needed
qualityListView.currentIndex = idx;
if (item.is_read_only) {
Cura.MachineManager.setQualityGroup(item.quality_group);
} else {
newIdx = idx;
if (base.toActivateNewQuality) {
// Activate this custom quality if required
Cura.MachineManager.setQualityChangesGroup(item.quality_changes_group);
}
base.newQualityChangesNameToSwitchTo = "";
break;
}
break;
}
}
qualityListView.currentIndex = newIdx;
// Reset states
base.newQualityNameToSelect = "";
base.toActivateNewQuality = false;
}
}
@ -213,7 +223,6 @@ Item
onAccepted:
{
Cura.ContainerManager.duplicateQualityChanges(newName, base.currentItem);
qualityListView.currentIndex = -1; // TODO: Reset selection.
}
}
@ -244,8 +253,8 @@ Item
object: "<new name>"
onAccepted:
{
Cura.ContainerManager.renameQualityChangesGroup(base.currentItem.quality_changes_group, newName);
qualityListView.currentIndex = -1; // TODO: Reset selection.
var actualNewName = Cura.ContainerManager.renameQualityChangesGroup(base.currentItem.quality_changes_group, newName);
base.newQualityNameToSelect = actualNewName; // Select the new name after the model gets updated
}
}