WIP: Refactor BuildPlateModel and split MultiBuildPlateModel

This commit is contained in:
Lipu Fei 2018-02-17 22:23:49 +01:00
parent 1c8f63e47f
commit 495fc8bbd7
27 changed files with 172 additions and 111 deletions

View file

@ -53,10 +53,13 @@ from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.SettingFunction import SettingFunction from UM.Settings.SettingFunction import SettingFunction
from cura.Settings.MachineNameValidator import MachineNameValidator from cura.Settings.MachineNameValidator import MachineNameValidator
from cura.Machines.Models.BuildPlateModel import BuildPlateModel
from cura.Machines.Models.NozzleModel import NozzleModel from cura.Machines.Models.NozzleModel import NozzleModel
from cura.Machines.Models.QualityProfilesModel import QualityProfilesModel from cura.Machines.Models.QualityProfilesModel import QualityProfilesModel
from cura.Machines.Models.CustomQualityProfilesModel import CustomQualityProfilesModel from cura.Machines.Models.CustomQualityProfilesModel import CustomQualityProfilesModel
from cura.Machines.Models.Other.MultiBuildPlateModel import MultiBuildPlateModel
from cura.Settings.MaterialsModel import MaterialsModel, BrandMaterialsModel, GenericMaterialsModel, NewMaterialsModel from cura.Settings.MaterialsModel import MaterialsModel, BrandMaterialsModel, GenericMaterialsModel, NewMaterialsModel
from cura.Settings.SettingInheritanceManager import SettingInheritanceManager from cura.Settings.SettingInheritanceManager import SettingInheritanceManager
from cura.Settings.SimpleModeSettingsManager import SimpleModeSettingsManager from cura.Settings.SimpleModeSettingsManager import SimpleModeSettingsManager
@ -84,7 +87,6 @@ from cura.Settings.QualitySettingsModel import QualitySettingsModel
from cura.Settings.ContainerManager import ContainerManager from cura.Settings.ContainerManager import ContainerManager
from cura.ObjectsModel import ObjectsModel from cura.ObjectsModel import ObjectsModel
from cura.BuildPlateModel import BuildPlateModel
from PyQt5.QtCore import QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS from PyQt5.QtCore import QUrl, pyqtSignal, pyqtProperty, QEvent, Q_ENUMS
from UM.FlameProfiler import pyqtSlot from UM.FlameProfiler import pyqtSlot
@ -219,6 +221,7 @@ class CuraApplication(QtApplication):
self._material_manager = None self._material_manager = None
self._object_manager = None self._object_manager = None
self._build_plate_model = None self._build_plate_model = None
self._multi_build_plate_model = None
self._setting_inheritance_manager = None self._setting_inheritance_manager = None
self._simple_mode_settings_manager = None self._simple_mode_settings_manager = None
self._cura_scene_controller = None self._cura_scene_controller = None
@ -858,10 +861,14 @@ class CuraApplication(QtApplication):
self._object_manager = ObjectsModel.createObjectsModel() self._object_manager = ObjectsModel.createObjectsModel()
return self._object_manager return self._object_manager
def getMultiBuildPlateModel(self, *args):
if self._multi_build_plate_model is None:
self._multi_build_plate_model = MultiBuildPlateModel(self)
return self._multi_build_plate_model
def getBuildPlateModel(self, *args): def getBuildPlateModel(self, *args):
if self._build_plate_model is None: if self._build_plate_model is None:
self._build_plate_model = BuildPlateModel.createBuildPlateModel() self._build_plate_model = BuildPlateModel(self)
return self._build_plate_model return self._build_plate_model
def getCuraSceneController(self, *args): def getCuraSceneController(self, *args):
@ -923,15 +930,16 @@ class CuraApplication(QtApplication):
qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type") qmlRegisterUncreatableType(CuraApplication, "Cura", 1, 0, "ResourceTypes", "Just an Enum type")
qmlRegisterSingletonType(CuraSceneController, "Cura", 1, 2, "SceneController", self.getCuraSceneController) qmlRegisterSingletonType(CuraSceneController, "Cura", 1, 0, "SceneController", self.getCuraSceneController)
qmlRegisterSingletonType(ExtruderManager, "Cura", 1, 0, "ExtruderManager", self.getExtruderManager) qmlRegisterSingletonType(ExtruderManager, "Cura", 1, 0, "ExtruderManager", self.getExtruderManager)
qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager) qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager", self.getSettingInheritanceManager) qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager", self.getSettingInheritanceManager)
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 2, "SimpleModeSettingsManager", self.getSimpleModeSettingsManager) qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 0, "SimpleModeSettingsManager", self.getSimpleModeSettingsManager)
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager) qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
qmlRegisterSingletonType(ObjectsModel, "Cura", 1, 2, "ObjectsModel", self.getObjectsModel) qmlRegisterSingletonType(ObjectsModel, "Cura", 1, 0, "ObjectsModel", self.getObjectsModel)
qmlRegisterSingletonType(BuildPlateModel, "Cura", 1, 2, "BuildPlateModel", self.getBuildPlateModel) qmlRegisterSingletonType(BuildPlateModel, "Cura", 1, 0, "BuildPlateModel", self.getBuildPlateModel)
qmlRegisterSingletonType(MultiBuildPlateModel, "Cura", 1, 0, "MultiBuildPlateModel", self.getMultiBuildPlateModel)
qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer") qmlRegisterType(InstanceContainer, "Cura", 1, 0, "InstanceContainer")
qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel") qmlRegisterType(ExtrudersModel, "Cura", 1, 0, "ExtrudersModel")
qmlRegisterType(ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel") qmlRegisterType(ContainerSettingsModel, "Cura", 1, 0, "ContainerSettingsModel")
@ -951,7 +959,7 @@ class CuraApplication(QtApplication):
qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler") qmlRegisterType(MaterialSettingsVisibilityHandler, "Cura", 1, 0, "MaterialSettingsVisibilityHandler")
qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel") qmlRegisterType(QualitySettingsModel, "Cura", 1, 0, "QualitySettingsModel")
qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator") qmlRegisterType(MachineNameValidator, "Cura", 1, 0, "MachineNameValidator")
qmlRegisterType(UserChangesModel, "Cura", 1, 1, "UserChangesModel") qmlRegisterType(UserChangesModel, "Cura", 1, 0, "UserChangesModel")
qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager) qmlRegisterSingletonType(ContainerManager, "Cura", 1, 0, "ContainerManager", ContainerManager.createContainerManager)
# As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work. # As of Qt5.7, it is necessary to get rid of any ".." in the path for the singleton to work.
@ -1033,7 +1041,7 @@ class CuraApplication(QtApplication):
count = 0 count = 0
scene_bounding_box = None scene_bounding_box = None
is_block_slicing_node = False is_block_slicing_node = False
active_build_plate = self.getBuildPlateModel().activeBuildPlate active_build_plate = self._multi_build_plate_model.activeBuildPlate
for node in DepthFirstIterator(self.getController().getScene().getRoot()): for node in DepthFirstIterator(self.getController().getScene().getRoot()):
if ( if (
not issubclass(type(node), CuraSceneNode) or not issubclass(type(node), CuraSceneNode) or
@ -1282,7 +1290,7 @@ class CuraApplication(QtApplication):
@pyqtSlot() @pyqtSlot()
def arrangeAll(self): def arrangeAll(self):
nodes = [] nodes = []
active_build_plate = self.getBuildPlateModel().activeBuildPlate active_build_plate = self._multi_build_plate_model.activeBuildPlate
for node in DepthFirstIterator(self.getController().getScene().getRoot()): for node in DepthFirstIterator(self.getController().getScene().getRoot()):
if not isinstance(node, SceneNode): if not isinstance(node, SceneNode):
continue continue
@ -1431,7 +1439,7 @@ class CuraApplication(QtApplication):
group_decorator = GroupDecorator() group_decorator = GroupDecorator()
group_node.addDecorator(group_decorator) group_node.addDecorator(group_decorator)
group_node.addDecorator(ConvexHullDecorator()) group_node.addDecorator(ConvexHullDecorator())
group_node.addDecorator(BuildPlateDecorator(self.getBuildPlateModel().activeBuildPlate)) group_node.addDecorator(BuildPlateDecorator(self._multi_build_plate_model.activeBuildPlate))
group_node.setParent(self.getController().getScene().getRoot()) group_node.setParent(self.getController().getScene().getRoot())
group_node.setSelectable(True) group_node.setSelectable(True)
center = Selection.getSelectionCenter() center = Selection.getSelectionCenter()
@ -1576,7 +1584,7 @@ class CuraApplication(QtApplication):
arrange_objects_on_load = ( arrange_objects_on_load = (
not Preferences.getInstance().getValue("cura/use_multi_build_plate") or not Preferences.getInstance().getValue("cura/use_multi_build_plate") or
not Preferences.getInstance().getValue("cura/not_arrange_objects_on_load")) not Preferences.getInstance().getValue("cura/not_arrange_objects_on_load"))
target_build_plate = self.getBuildPlateModel().activeBuildPlate if arrange_objects_on_load else -1 target_build_plate = self._multi_build_plate_model.activeBuildPlate if arrange_objects_on_load else -1
root = self.getController().getScene().getRoot() root = self.getController().getScene().getRoot()
fixed_nodes = [] fixed_nodes = []

View file

@ -0,0 +1,40 @@
from PyQt5.QtCore import Qt
from UM.Application import Application
from UM.Qt.ListModel import ListModel
from cura.Machines.VariantManager import VariantType
class BuildPlateModel(ListModel):
NameRole = Qt.UserRole + 1
ContainerNodeRole = Qt.UserRole + 2
def __init__(self, parent = None):
super().__init__(parent)
self.addRoleName(self.NameRole, "name")
self.addRoleName(self.ContainerNodeRole, "container_node")
self._application = Application.getInstance()
self._variant_manager = self._application._variant_manager
self._machine_manager = self._application.getMachineManager()
self._machine_manager.globalContainerChanged.connect(self._update)
self._update()
def _update(self):
global_stack = self._machine_manager._global_container_stack
if not global_stack:
self.setItems([])
return
variant_dict = self._variant_manager.getVariantNodes(global_stack, variant_type = VariantType.BUILD_PLATE)
item_list = []
for name, variant_node in variant_dict.items():
item = {"name": name,
"container_node": variant_node}
item_list.append(item)
self.setItems(item_list)

View file

@ -1,24 +1,25 @@
from PyQt5.QtCore import pyqtSignal, pyqtProperty, pyqtSlot from PyQt5.QtCore import pyqtSignal, pyqtProperty
from UM.Qt.ListModel import ListModel
from UM.Scene.Selection import Selection
from UM.Logger import Logger
from UM.Application import Application from UM.Application import Application
from UM.Scene.Selection import Selection
from UM.Qt.ListModel import ListModel
class BuildPlateModel(ListModel): class MultiBuildPlateModel(ListModel):
maxBuildPlateChanged = pyqtSignal() maxBuildPlateChanged = pyqtSignal()
activeBuildPlateChanged = pyqtSignal() activeBuildPlateChanged = pyqtSignal()
selectionChanged = pyqtSignal() selectionChanged = pyqtSignal()
def __init__(self): def __init__(self, parent = None):
super().__init__() super().__init__(parent)
Application.getInstance().getController().getScene().sceneChanged.connect(self._updateSelectedObjectBuildPlateNumbers)
self._application = Application.getInstance()
self._application.getController().getScene().sceneChanged.connect(self._updateSelectedObjectBuildPlateNumbers)
Selection.selectionChanged.connect(self._updateSelectedObjectBuildPlateNumbers) Selection.selectionChanged.connect(self._updateSelectedObjectBuildPlateNumbers)
self._max_build_plate = 1 # default self._max_build_plate = 1 # default
self._active_build_plate = -1 self._active_build_plate = -1
self._selection_build_plates = []
def setMaxBuildPlate(self, max_build_plate): def setMaxBuildPlate(self, max_build_plate):
self._max_build_plate = max_build_plate self._max_build_plate = max_build_plate
@ -37,10 +38,6 @@ class BuildPlateModel(ListModel):
def activeBuildPlate(self): def activeBuildPlate(self):
return self._active_build_plate return self._active_build_plate
@staticmethod
def createBuildPlateModel():
return BuildPlateModel()
def _updateSelectedObjectBuildPlateNumbers(self, *args): def _updateSelectedObjectBuildPlateNumbers(self, *args):
result = set() result = set()
for node in Selection.getAllSelectedObjects(): for node in Selection.getAllSelectedObjects():

View file

View file

@ -76,15 +76,18 @@ class PrintInformation(QObject):
self._active_build_plate = 0 self._active_build_plate = 0
self._initVariablesWithBuildPlate(self._active_build_plate) self._initVariablesWithBuildPlate(self._active_build_plate)
Application.getInstance().globalContainerStackChanged.connect(self._updateJobName) self._application = Application.getInstance()
Application.getInstance().fileLoaded.connect(self.setBaseName) self._multi_build_plate_model = self._application.getMultiBuildPlateModel()
Application.getInstance().getBuildPlateModel().activeBuildPlateChanged.connect(self._onActiveBuildPlateChanged)
Application.getInstance().workspaceLoaded.connect(self.setProjectName) self._application.globalContainerStackChanged.connect(self._updateJobName)
self._application.fileLoaded.connect(self.setBaseName)
self._application.workspaceLoaded.connect(self.setProjectName)
self._multi_build_plate_model.activeBuildPlateChanged.connect(self._onActiveBuildPlateChanged)
Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged) Preferences.getInstance().preferenceChanged.connect(self._onPreferencesChanged)
self._active_material_container = None self._active_material_container = None
Application.getInstance().getMachineManager().activeMaterialChanged.connect(self._onActiveMaterialChanged) self._application.getMachineManager().activeMaterialChanged.connect(self._onActiveMaterialChanged)
self._onActiveMaterialChanged() self._onActiveMaterialChanged()
self._material_amounts = [] self._material_amounts = []
@ -260,7 +263,7 @@ class PrintInformation(QObject):
if preference != "cura/material_settings": if preference != "cura/material_settings":
return return
for build_plate_number in range(Application.getInstance().getBuildPlateModel().maxBuildPlate + 1): for build_plate_number in range(self._multi_build_plate_model.maxBuildPlate + 1):
self._calculateInformation(build_plate_number) self._calculateInformation(build_plate_number)
def _onActiveMaterialChanged(self): def _onActiveMaterialChanged(self):
@ -278,7 +281,7 @@ class PrintInformation(QObject):
self._active_material_container.metaDataChanged.connect(self._onMaterialMetaDataChanged) self._active_material_container.metaDataChanged.connect(self._onMaterialMetaDataChanged)
def _onActiveBuildPlateChanged(self): def _onActiveBuildPlateChanged(self):
new_active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate new_active_build_plate = self._multi_build_plate_model.activeBuildPlate
if new_active_build_plate != self._active_build_plate: if new_active_build_plate != self._active_build_plate:
self._active_build_plate = new_active_build_plate self._active_build_plate = new_active_build_plate
@ -291,7 +294,7 @@ class PrintInformation(QObject):
self.currentPrintTimeChanged.emit() self.currentPrintTimeChanged.emit()
def _onMaterialMetaDataChanged(self, *args, **kwargs): def _onMaterialMetaDataChanged(self, *args, **kwargs):
for build_plate_number in range(Application.getInstance().getBuildPlateModel().maxBuildPlate + 1): for build_plate_number in range(self._multi_build_plate_model.maxBuildPlate + 1):
self._calculateInformation(build_plate_number) self._calculateInformation(build_plate_number)
@pyqtSlot(str) @pyqtSlot(str)

View file

@ -68,7 +68,7 @@ class ConvexHullNode(SceneNode):
ConvexHullNode.shader.setUniformValue("u_opacity", 0.6) ConvexHullNode.shader.setUniformValue("u_opacity", 0.6)
if self.getParent(): if self.getParent():
if self.getMeshData() and isinstance(self._node, SceneNode) and self._node.callDecoration("getBuildPlateNumber") == Application.getInstance().getBuildPlateModel().activeBuildPlate: if self.getMeshData() and isinstance(self._node, SceneNode) and self._node.callDecoration("getBuildPlateNumber") == Application.getInstance().getMultiBuildPlateModel().activeBuildPlate:
renderer.queueNode(self, transparent = True, shader = ConvexHullNode.shader, backface_cull = True, sort = -8) renderer.queueNode(self, transparent = True, shader = ConvexHullNode.shader, backface_cull = True, sort = -8)
if self._convex_hull_head_mesh: if self._convex_hull_head_mesh:
renderer.queueNode(self, shader = ConvexHullNode.shader, transparent = True, mesh = self._convex_hull_head_mesh, backface_cull = True, sort = -8) renderer.queueNode(self, shader = ConvexHullNode.shader, transparent = True, mesh = self._convex_hull_head_mesh, backface_cull = True, sort = -8)

View file

@ -4,7 +4,7 @@ from PyQt5.QtCore import Qt, pyqtSlot, QObject
from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QApplication
from cura.ObjectsModel import ObjectsModel from cura.ObjectsModel import ObjectsModel
from cura.BuildPlateModel import BuildPlateModel from cura.Machines.Models.Other.MultiBuildPlateModel import MultiBuildPlateModel
from UM.Application import Application from UM.Application import Application
from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator from UM.Scene.Iterator.DepthFirstIterator import DepthFirstIterator
@ -16,11 +16,11 @@ from UM.Signal import Signal
class CuraSceneController(QObject): class CuraSceneController(QObject):
activeBuildPlateChanged = Signal() activeBuildPlateChanged = Signal()
def __init__(self, objects_model: ObjectsModel, build_plate_model: BuildPlateModel): def __init__(self, objects_model: ObjectsModel, multi_build_plate_model: MultiBuildPlateModel):
super().__init__() super().__init__()
self._objects_model = objects_model self._objects_model = objects_model
self._build_plate_model = build_plate_model self._multi_build_plate_model = multi_build_plate_model
self._active_build_plate = -1 self._active_build_plate = -1
self._last_selected_index = 0 self._last_selected_index = 0
@ -41,9 +41,9 @@ class CuraSceneController(QObject):
self._max_build_plate = max_build_plate self._max_build_plate = max_build_plate
changed = True changed = True
if changed: if changed:
self._build_plate_model.setMaxBuildPlate(self._max_build_plate) self._multi_build_plate_model.setMaxBuildPlate(self._max_build_plate)
build_plates = [{"name": "Build Plate %d" % (i + 1), "buildPlateNumber": i} for i in range(self._max_build_plate + 1)] build_plates = [{"name": "Build Plate %d" % (i + 1), "buildPlateNumber": i} for i in range(self._max_build_plate + 1)]
self._build_plate_model.setItems(build_plates) self._multi_build_plate_model.setItems(build_plates)
if self._active_build_plate > self._max_build_plate: if self._active_build_plate > self._max_build_plate:
build_plate_number = 0 build_plate_number = 0
if self._last_selected_index >= 0: # go to the buildplate of the item you last selected if self._last_selected_index >= 0: # go to the buildplate of the item you last selected
@ -104,12 +104,12 @@ class CuraSceneController(QObject):
self._active_build_plate = nr self._active_build_plate = nr
Selection.clear() Selection.clear()
self._build_plate_model.setActiveBuildPlate(nr) self._multi_build_plate_model.setActiveBuildPlate(nr)
self._objects_model.setActiveBuildPlate(nr) self._objects_model.setActiveBuildPlate(nr)
self.activeBuildPlateChanged.emit() self.activeBuildPlateChanged.emit()
@staticmethod @staticmethod
def createCuraSceneController(): def createCuraSceneController():
objects_model = Application.getInstance().getObjectsModel() objects_model = Application.getInstance().getObjectsModel()
build_plate_model = Application.getInstance().getBuildPlateModel() multi_build_plate_model = Application.getInstance().getMultiBuildPlateModel()
return CuraSceneController(objects_model = objects_model, build_plate_model = build_plate_model) return CuraSceneController(objects_model = objects_model, multi_build_plate_model = multi_build_plate_model)

View file

@ -20,10 +20,10 @@ class CuraSceneNode(SceneNode):
return self._outside_buildarea or self.callDecoration("getBuildPlateNumber") < 0 return self._outside_buildarea or self.callDecoration("getBuildPlateNumber") < 0
def isVisible(self): def isVisible(self):
return super().isVisible() and self.callDecoration("getBuildPlateNumber") == Application.getInstance().getBuildPlateModel().activeBuildPlate return super().isVisible() and self.callDecoration("getBuildPlateNumber") == Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
def isSelectable(self) -> bool: def isSelectable(self) -> bool:
return super().isSelectable() and self.callDecoration("getBuildPlateNumber") == Application.getInstance().getBuildPlateModel().activeBuildPlate return super().isSelectable() and self.callDecoration("getBuildPlateNumber") == Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
## Get the extruder used to print this node. If there is no active node, then the extruder in position zero is returned ## Get the extruder used to print this node. If there is no active node, then the extruder in position zero is returned
# TODO The best way to do it is by adding the setActiveExtruder decorator to every node when is loaded # TODO The best way to do it is by adding the setActiveExtruder decorator to every node when is loaded

View file

@ -545,11 +545,11 @@ class MachineManager(QObject):
return "" return ""
@pyqtProperty(str, notify=activeVariantChanged) @pyqtProperty(str, notify=activeVariantChanged)
def globalVariantId(self) -> str: def globalVariantName(self) -> str:
if self._global_container_stack: if self._global_container_stack:
variant = self._global_container_stack.variant variant = self._global_container_stack.variant
if variant and not isinstance(variant, type(self._empty_variant_container)): if variant and not isinstance(variant, type(self._empty_variant_container)):
return variant.getId() return variant.getName()
return "" return ""
@pyqtProperty(str, notify = activeQualityChanged) @pyqtProperty(str, notify = activeQualityChanged)
@ -1319,6 +1319,9 @@ class MachineManager(QObject):
def _setVariantNode(self, position, container_node): def _setVariantNode(self, position, container_node):
self._global_container_stack.extruders[position].variant = container_node.getContainer() self._global_container_stack.extruders[position].variant = container_node.getContainer()
def _setGlobalVariant(self, container_node):
self._global_container_stack.variant = container_node.getContainer()
def _setMaterial(self, position, container_node = None): def _setMaterial(self, position, container_node = None):
if container_node: if container_node:
self._global_container_stack.extruders[position].material = container_node.getContainer() self._global_container_stack.extruders[position].material = container_node.getContainer()
@ -1354,22 +1357,33 @@ class MachineManager(QObject):
self._setQualityGroup(candidate_quality_groups[quality_type], empty_quality_changes = False) self._setQualityGroup(candidate_quality_groups[quality_type], empty_quality_changes = False)
def _updateMaterialWithVariant(self, position, current_material_base_name, current_variant_name): def _updateMaterialWithVariant(self, position: Optional[str]):
material_manager = Application.getInstance()._material_manager if position is None:
material_diameter = self._global_container_stack.getProperty("material_diameter", "value") position_list = list(self._global_container_stack.extruders.keys())
candidate_materials = material_manager.getAvailableMaterials( else:
self._global_container_stack.getId(), position_list = [position]
current_variant_name,
material_diameter)
if not candidate_materials: for position in position_list:
self._setMaterial(position, container_node = None) extruder = self._global_container_stack.extruders[position]
return
if current_material_base_name in candidate_materials: current_material_base_name = extruder.material.getMetaDataEntry("base_file")
new_material = candidate_materials[current_material_base_name] current_variant_name = extruder.variant.getMetaDataEntry("name")
self._setMaterial(position, new_material)
return material_manager = Application.getInstance()._material_manager
material_diameter = self._global_container_stack.getProperty("material_diameter", "value")
candidate_materials = material_manager.getAvailableMaterials(
self._global_container_stack.getId(),
current_variant_name,
material_diameter)
if not candidate_materials:
self._setMaterial(position, container_node = None)
continue
if current_material_base_name in candidate_materials:
new_material = candidate_materials[current_material_base_name]
self._setMaterial(position, new_material)
continue
# # Find a fallback material # # Find a fallback material
# preferred_material_query = self._global_container_stack.getMetaDataEntry("preferred_material") # preferred_material_query = self._global_container_stack.getMetaDataEntry("preferred_material")
@ -1378,6 +1392,15 @@ class MachineManager(QObject):
# self._setMaterial(position, candidate_materials[preferred_material_key]) # self._setMaterial(position, candidate_materials[preferred_material_key])
# return # return
@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)
self._updateMaterialWithVariant(None) # Update all materials
self._updateQualityWithMaterial()
@pyqtSlot(str, "QVariant") @pyqtSlot(str, "QVariant")
def setMaterial(self, position, container_node): def setMaterial(self, position, container_node):
Logger.log("d", "---------------- container = [%s]", container_node) Logger.log("d", "---------------- container = [%s]", container_node)
@ -1394,9 +1417,7 @@ class MachineManager(QObject):
self.blurSettings.emit() self.blurSettings.emit()
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue): with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
self._setVariantNode(position, container_node) self._setVariantNode(position, container_node)
current_variant_name = container_node.metadata["name"] self._updateMaterialWithVariant(position)
current_material_base_name = self._global_container_stack.extruders[position].material.getMetaDataEntry("base_file")
self._updateMaterialWithVariant(position, current_material_base_name, current_variant_name)
self._updateQualityWithMaterial() self._updateQualityWithMaterial()
@pyqtSlot("QVariant") @pyqtSlot("QVariant")

View file

@ -77,7 +77,7 @@ class ThreeMFReader(MeshReader):
self._object_count += 1 self._object_count += 1
node_name = "Object %s" % self._object_count node_name = "Object %s" % self._object_count
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
um_node = CuraSceneNode() um_node = CuraSceneNode()
um_node.addDecorator(BuildPlateDecorator(active_build_plate)) um_node.addDecorator(BuildPlateDecorator(active_build_plate))

View file

@ -68,7 +68,7 @@ class ThreeMFWriter(MeshWriter):
if not isinstance(um_node, SceneNode): if not isinstance(um_node, SceneNode):
return None return None
active_build_plate_nr = CuraApplication.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate_nr = CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate
if um_node.callDecoration("getBuildPlateNumber") != active_build_plate_nr: if um_node.callDecoration("getBuildPlateNumber") != active_build_plate_nr:
return return

View file

@ -70,7 +70,7 @@ class CuraEngineBackend(QObject, Backend):
# Workaround to disable layer view processing if layer view is not active. # Workaround to disable layer view processing if layer view is not active.
self._layer_view_active = False self._layer_view_active = False
Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged) Application.getInstance().getController().activeViewChanged.connect(self._onActiveViewChanged)
Application.getInstance().getBuildPlateModel().activeBuildPlateChanged.connect(self._onActiveViewChanged) Application.getInstance().getMultiBuildPlateModel().activeBuildPlateChanged.connect(self._onActiveViewChanged)
self._onActiveViewChanged() self._onActiveViewChanged()
self._stored_layer_data = [] self._stored_layer_data = []
self._stored_optimized_layer_data = {} # key is build plate number, then arrays are stored until they go to the ProcessSlicesLayersJob self._stored_optimized_layer_data = {} # key is build plate number, then arrays are stored until they go to the ProcessSlicesLayersJob
@ -207,7 +207,7 @@ class CuraEngineBackend(QObject, Backend):
self._scene.gcode_dict = {} self._scene.gcode_dict = {}
# see if we really have to slice # see if we really have to slice
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
build_plate_to_be_sliced = self._build_plates_to_be_sliced.pop(0) build_plate_to_be_sliced = self._build_plates_to_be_sliced.pop(0)
Logger.log("d", "Going to slice build plate [%s]!" % build_plate_to_be_sliced) Logger.log("d", "Going to slice build plate [%s]!" % build_plate_to_be_sliced)
num_objects = self._numObjects() num_objects = self._numObjects()
@ -497,7 +497,7 @@ class CuraEngineBackend(QObject, Backend):
node.getParent().removeChild(node) node.getParent().removeChild(node)
def markSliceAll(self): def markSliceAll(self):
for build_plate_number in range(Application.getInstance().getBuildPlateModel().maxBuildPlate + 1): for build_plate_number in range(Application.getInstance().getMultiBuildPlateModel().maxBuildPlate + 1):
if build_plate_number not in self._build_plates_to_be_sliced: if build_plate_number not in self._build_plates_to_be_sliced:
self._build_plates_to_be_sliced.append(build_plate_number) self._build_plates_to_be_sliced.append(build_plate_number)
@ -582,7 +582,7 @@ class CuraEngineBackend(QObject, Backend):
Logger.log("d", "Slicing took %s seconds", time() - self._slice_start_time ) Logger.log("d", "Slicing took %s seconds", time() - self._slice_start_time )
# See if we need to process the sliced layers job. # See if we need to process the sliced layers job.
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
if self._layer_view_active and (self._process_layers_job is None or not self._process_layers_job.isRunning()) and active_build_plate == self._start_slice_job_build_plate: if self._layer_view_active and (self._process_layers_job is None or not self._process_layers_job.isRunning()) and active_build_plate == self._start_slice_job_build_plate:
self._startProcessSlicedLayersJob(active_build_plate) self._startProcessSlicedLayersJob(active_build_plate)
# self._onActiveViewChanged() # self._onActiveViewChanged()
@ -702,7 +702,7 @@ class CuraEngineBackend(QObject, Backend):
application = Application.getInstance() application = Application.getInstance()
view = application.getController().getActiveView() view = application.getController().getActiveView()
if view: if view:
active_build_plate = application.getBuildPlateModel().activeBuildPlate active_build_plate = application.getMultiBuildPlateModel().activeBuildPlate
if view.getPluginId() == "SimulationView": # If switching to layer view, we should process the layers if that hasn't been done yet. if view.getPluginId() == "SimulationView": # If switching to layer view, we should process the layers if that hasn't been done yet.
self._layer_view_active = True self._layer_view_active = True
# There is data and we're not slicing at the moment # There is data and we're not slicing at the moment

View file

@ -12,6 +12,6 @@ class ProcessGCodeLayerJob(Job):
self._message = message self._message = message
def run(self): def run(self):
active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
gcode_list = self._scene.gcode_dict[active_build_plate_id] gcode_list = self._scene.gcode_dict[active_build_plate_id]
gcode_list.append(self._message.data.decode("utf-8", "replace")) gcode_list.append(self._message.data.decode("utf-8", "replace"))

View file

@ -437,7 +437,7 @@ class FlavorParser:
scene_node.addDecorator(gcode_list_decorator) scene_node.addDecorator(gcode_list_decorator)
# gcode_dict stores gcode_lists for a number of build plates. # gcode_dict stores gcode_lists for a number of build plates.
active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
gcode_dict = {active_build_plate_id: gcode_list} gcode_dict = {active_build_plate_id: gcode_list}
Application.getInstance().getController().getScene().gcode_dict = gcode_dict Application.getInstance().getController().getScene().gcode_dict = gcode_dict

View file

@ -60,7 +60,7 @@ class GCodeWriter(MeshWriter):
Logger.log("e", "GCodeWriter does not support non-text mode.") Logger.log("e", "GCodeWriter does not support non-text mode.")
return False return False
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
scene = Application.getInstance().getController().getScene() scene = Application.getInstance().getController().getScene()
gcode_dict = getattr(scene, "gcode_dict") gcode_dict = getattr(scene, "gcode_dict")
if not gcode_dict: if not gcode_dict:

View file

@ -62,7 +62,7 @@ class PostProcessingPlugin(QObject, Extension):
return return
# get gcode list for the active build plate # get gcode list for the active build plate
active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
gcode_list = gcode_dict[active_build_plate_id] gcode_list = gcode_dict[active_build_plate_id]
if not gcode_list: if not gcode_list:
return return

View file

@ -93,7 +93,7 @@ class SimulationPass(RenderPass):
self.bind() self.bind()
tool_handle_batch = RenderBatch(self._tool_handle_shader, type = RenderBatch.RenderType.Overlay, backface_cull = True) tool_handle_batch = RenderBatch(self._tool_handle_shader, type = RenderBatch.RenderType.Overlay, backface_cull = True)
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
head_position = None # Indicates the current position of the print head head_position = None # Indicates the current position of the print head
nozzle_node = None nozzle_node = None

View file

@ -42,7 +42,7 @@ class SupportEraser(Tool):
mesh.addCube(10,10,10) mesh.addCube(10,10,10)
node.setMeshData(mesh.build()) node.setMeshData(mesh.build())
active_build_plate = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
node.addDecorator(SettingOverrideDecorator()) node.addDecorator(SettingOverrideDecorator())
node.addDecorator(BuildPlateDecorator(active_build_plate)) node.addDecorator(BuildPlateDecorator(active_build_plate))

View file

@ -81,7 +81,7 @@ class ClusterUM3OutputDevice(NetworkedPrinterOutputDevice):
self.writeStarted.emit(self) self.writeStarted.emit(self)
gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict", []) gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict", [])
active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
gcode_list = gcode_dict[active_build_plate_id] gcode_list = gcode_dict[active_build_plate_id]
if not gcode_list: if not gcode_list:

View file

@ -184,7 +184,7 @@ class LegacyUM3OutputDevice(NetworkedPrinterOutputDevice):
self.writeStarted.emit(self) self.writeStarted.emit(self)
gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict", []) gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict", [])
active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
gcode_list = gcode_dict[active_build_plate_id] gcode_list = gcode_dict[active_build_plate_id]
if not gcode_list: if not gcode_list:

View file

@ -99,7 +99,7 @@ class USBPrinterOutputDevice(PrinterOutputDevice):
Application.getInstance().getController().setActiveStage("MonitorStage") Application.getInstance().getController().setActiveStage("MonitorStage")
# find the G-code for the active build plate to print # find the G-code for the active build plate to print
active_build_plate_id = Application.getInstance().getBuildPlateModel().activeBuildPlate active_build_plate_id = Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict") gcode_dict = getattr(Application.getInstance().getController().getScene(), "gcode_dict")
gcode_list = gcode_dict[active_build_plate_id] gcode_list = gcode_dict[active_build_plate_id]

View file

@ -7,7 +7,7 @@ import QtQuick.Dialogs 1.2
import QtQuick.Window 2.1 import QtQuick.Window 2.1
import UM 1.2 as UM import UM 1.2 as UM
import Cura 1.1 as Cura import Cura 1.0 as Cura
UM.Dialog UM.Dialog
{ {

View file

@ -14,26 +14,18 @@ Menu
Instantiator Instantiator
{ {
id: buildplateInstantiator model: Cura.BuildPlateModel
model: UM.InstanceContainersModel
{
filter:
{
"type": "variant",
"hardware_type": "buildplate",
"definition": Cura.MachineManager.activeDefinitionId //Only show variants of this machine
}
}
MenuItem { MenuItem {
text: model.name text: model.name
checkable: true checkable: true
checked: model.id == Cura.MachineManager.globalVariantId checked: model.name == Cura.MachineManager.globalVariantName // TODO
exclusiveGroup: group exclusiveGroup: group
onTriggered: onTriggered: {
{ Cura.MachineManager.setGlobalVariant(model.container_node); // TODO
Cura.MachineManager.setActiveVariantBuildplate(model.id);
} }
} }
onObjectAdded: menu.insertItem(index, object) onObjectAdded: menu.insertItem(index, object)
onObjectRemoved: menu.removeItem(object) onObjectRemoved: menu.removeItem(object)
} }

View file

@ -7,7 +7,7 @@ import QtQuick.Dialogs 1.2
import QtQuick.Window 2.1 import QtQuick.Window 2.1
import UM 1.2 as UM import UM 1.2 as UM
import Cura 1.2 as Cura import Cura 1.0 as Cura
Menu Menu
{ {
@ -45,13 +45,13 @@ Menu
Instantiator Instantiator
{ {
model: Cura.BuildPlateModel model: Cura.MultiBuildPlateModel
MenuItem { MenuItem {
enabled: UM.Selection.hasSelection enabled: UM.Selection.hasSelection
text: Cura.BuildPlateModel.getItem(index).name; text: Cura.MultiBuildPlateModel.getItem(index).name;
onTriggered: CuraActions.setBuildPlateForSelection(Cura.BuildPlateModel.getItem(index).buildPlateNumber); onTriggered: CuraActions.setBuildPlateForSelection(Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber);
checkable: true checkable: true
checked: Cura.BuildPlateModel.selectionBuildPlates.indexOf(Cura.BuildPlateModel.getItem(index).buildPlateNumber) != -1; checked: Cura.MultiBuildPlateModel.selectionBuildPlates.indexOf(Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber) != -1;
visible: UM.Preferences.getValue("cura/use_multi_build_plate") visible: UM.Preferences.getValue("cura/use_multi_build_plate")
} }
onObjectAdded: base.insertItem(index, object); onObjectAdded: base.insertItem(index, object);
@ -62,7 +62,7 @@ Menu
enabled: UM.Selection.hasSelection enabled: UM.Selection.hasSelection
text: "New build plate"; text: "New build plate";
onTriggered: { onTriggered: {
CuraActions.setBuildPlateForSelection(Cura.BuildPlateModel.maxBuildPlate + 1); CuraActions.setBuildPlateForSelection(Cura.MultiBuildPlateModel.maxBuildPlate + 1);
checked = false; checked = false;
} }
checkable: true checkable: true

View file

@ -5,7 +5,7 @@ import QtQuick 2.2
import QtQuick.Controls 1.1 import QtQuick.Controls 1.1
import UM 1.2 as UM import UM 1.2 as UM
import Cura 1.2 as Cura import Cura 1.0 as Cura
Menu Menu
{ {
@ -53,12 +53,12 @@ Menu
visible: UM.Preferences.getValue("cura/use_multi_build_plate") visible: UM.Preferences.getValue("cura/use_multi_build_plate")
Instantiator Instantiator
{ {
model: Cura.BuildPlateModel model: Cura.MultiBuildPlateModel
MenuItem { MenuItem {
text: Cura.BuildPlateModel.getItem(index).name; text: Cura.MultiBuildPlateModel.getItem(index).name;
onTriggered: Cura.SceneController.setActiveBuildPlate(Cura.BuildPlateModel.getItem(index).buildPlateNumber); onTriggered: Cura.SceneController.setActiveBuildPlate(Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber);
checkable: true; checkable: true;
checked: Cura.BuildPlateModel.getItem(index).buildPlateNumber == Cura.BuildPlateModel.activeBuildPlate; checked: Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber == Cura.MultiBuildPlateModel.activeBuildPlate;
exclusiveGroup: buildPlateGroup; exclusiveGroup: buildPlateGroup;
visible: UM.Preferences.getValue("cura/use_multi_build_plate") visible: UM.Preferences.getValue("cura/use_multi_build_plate")
} }

View file

@ -8,7 +8,7 @@ import QtQuick.Layouts 1.1
import QtQuick.Dialogs 1.1 import QtQuick.Dialogs 1.1
import UM 1.3 as UM import UM 1.3 as UM
import Cura 1.2 as Cura import Cura 1.0 as Cura
import "Menus" import "Menus"
@ -67,7 +67,7 @@ Rectangle
Rectangle Rectangle
{ {
height: childrenRect.height height: childrenRect.height
color: Cura.BuildPlateModel.getItem(index).buildPlateNumber == Cura.BuildPlateModel.activeBuildPlate ? palette.highlight : index % 2 ? palette.base : palette.alternateBase color: Cura.MultiBuildPlateModel.getItem(index).buildPlateNumber == Cura.MultiBuildPlateModel.activeBuildPlate ? palette.highlight : index % 2 ? palette.base : palette.alternateBase
width: parent.width width: parent.width
Label Label
{ {
@ -75,8 +75,8 @@ Rectangle
anchors.left: parent.left anchors.left: parent.left
anchors.leftMargin: UM.Theme.getSize("default_margin").width anchors.leftMargin: UM.Theme.getSize("default_margin").width
width: parent.width - 2 * UM.Theme.getSize("default_margin").width - 30 width: parent.width - 2 * UM.Theme.getSize("default_margin").width - 30
text: Cura.BuildPlateModel.getItem(index) ? Cura.BuildPlateModel.getItem(index).name : ""; text: Cura.MultiBuildPlateModel.getItem(index) ? Cura.MultiBuildPlateModel.getItem(index).name : "";
color: Cura.BuildPlateModel.activeBuildPlate == index ? palette.highlightedText : palette.text color: Cura.MultiBuildPlateModel.activeBuildPlate == index ? palette.highlightedText : palette.text
elide: Text.ElideRight elide: Text.ElideRight
} }
@ -118,7 +118,7 @@ Rectangle
ListView ListView
{ {
id: buildPlateListView id: buildPlateListView
model: Cura.BuildPlateModel model: Cura.MultiBuildPlateModel
width: parent.width width: parent.width
delegate: buildPlateDelegate delegate: buildPlateDelegate
} }

View file

@ -7,7 +7,7 @@ import QtQuick.Controls.Styles 1.4
import QtQuick.Layouts 1.3 import QtQuick.Layouts 1.3
import UM 1.2 as UM import UM 1.2 as UM
import Cura 1.2 as Cura import Cura 1.0 as Cura
Item Item
{ {