mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 10:47:49 -06:00
Move getAvailableMaterials() into MaterialManager
This commit is contained in:
parent
c21174eea8
commit
b4c3536999
5 changed files with 31 additions and 45 deletions
|
@ -260,6 +260,20 @@ class MaterialManager(QObject):
|
||||||
|
|
||||||
return material_id_metadata_dict
|
return material_id_metadata_dict
|
||||||
|
|
||||||
|
#
|
||||||
|
# A convenience function to get available materials for the given machine with the extruder position.
|
||||||
|
#
|
||||||
|
def getAvailableMaterialsForMachineExtruder(self, machine: "GlobalStack",
|
||||||
|
extruder_stack: "ExtruderStack") -> Optional[dict]:
|
||||||
|
machine_definition_id = machine.definition.getId()
|
||||||
|
variant_name = None
|
||||||
|
if extruder_stack.variant.getId() != "empty_variant":
|
||||||
|
variant_name = extruder_stack.variant.getName()
|
||||||
|
diameter = extruder_stack.approximateMaterialDiameter
|
||||||
|
|
||||||
|
# Fetch the available materials (ContainerNode) for the current active machine and extruder setup.
|
||||||
|
return self.getAvailableMaterials(machine_definition_id, variant_name, diameter)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Gets MaterialNode for the given extruder and machine with the given material name.
|
# Gets MaterialNode for the given extruder and machine with the given material name.
|
||||||
# Returns None if:
|
# Returns None if:
|
||||||
|
|
|
@ -1,41 +1,11 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Optional
|
|
||||||
from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
|
from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
|
||||||
|
|
||||||
from UM.Logger import Logger
|
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
|
|
||||||
def getAvailableMaterials(extruder_position: Optional[int] = None):
|
|
||||||
from cura.CuraApplication import CuraApplication
|
|
||||||
machine_manager = CuraApplication.getInstance().getMachineManager()
|
|
||||||
extruder_manager = CuraApplication.getInstance().getExtruderManager()
|
|
||||||
material_manager = CuraApplication.getInstance().getMaterialManager()
|
|
||||||
|
|
||||||
active_global_stack = machine_manager.activeMachine
|
|
||||||
extruder_stack = extruder_manager.getActiveExtruderStack()
|
|
||||||
if extruder_position is not None:
|
|
||||||
if active_global_stack is not None:
|
|
||||||
extruder_stack = active_global_stack.extruders.get(str(extruder_position))
|
|
||||||
|
|
||||||
if active_global_stack is None or extruder_stack is None:
|
|
||||||
Logger.log("d", "Active global stack [%s] or extruder stack [%s] is None, setting material list to empty.",
|
|
||||||
active_global_stack, extruder_stack)
|
|
||||||
return
|
|
||||||
|
|
||||||
machine_definition_id = active_global_stack.definition.getId()
|
|
||||||
variant_name = None
|
|
||||||
if extruder_stack.variant.getId() != "empty_variant":
|
|
||||||
variant_name = extruder_stack.variant.getName()
|
|
||||||
diameter = extruder_stack.approximateMaterialDiameter
|
|
||||||
|
|
||||||
# Fetch the available materials (ContainerNode) for the current active machine and extruder setup.
|
|
||||||
result_dict = material_manager.getAvailableMaterials(machine_definition_id, variant_name, diameter)
|
|
||||||
return result_dict
|
|
||||||
|
|
||||||
|
|
||||||
class BaseMaterialsModel(ListModel):
|
class BaseMaterialsModel(ListModel):
|
||||||
RootMaterialIdRole = Qt.UserRole + 1
|
RootMaterialIdRole = Qt.UserRole + 1
|
||||||
IdRole = Qt.UserRole + 2
|
IdRole = Qt.UserRole + 2
|
||||||
|
|
|
@ -5,7 +5,7 @@ from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
|
||||||
|
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
from .BaseMaterialsModel import BaseMaterialsModel, getAvailableMaterials
|
from .BaseMaterialsModel import BaseMaterialsModel
|
||||||
|
|
||||||
|
|
||||||
class MaterialsModelGroupedByType(ListModel):
|
class MaterialsModelGroupedByType(ListModel):
|
||||||
|
@ -36,12 +36,12 @@ class BrandMaterialsModel(ListModel):
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
self._machine_manager = CuraApplication.getInstance().getMachineManager()
|
self._machine_manager = CuraApplication.getInstance().getMachineManager()
|
||||||
extruder_manager = CuraApplication.getInstance().getExtruderManager()
|
self._extruder_manager = CuraApplication.getInstance().getExtruderManager()
|
||||||
material_manager = CuraApplication.getInstance().getMaterialManager()
|
self._material_manager = CuraApplication.getInstance().getMaterialManager()
|
||||||
|
|
||||||
self._machine_manager.globalContainerChanged.connect(self._update)
|
self._machine_manager.globalContainerChanged.connect(self._update)
|
||||||
extruder_manager.activeExtruderChanged.connect(self._update)
|
self._extruder_manager.activeExtruderChanged.connect(self._update)
|
||||||
material_manager.materialsUpdated.connect(self._update)
|
self._material_manager.materialsUpdated.connect(self._update)
|
||||||
|
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
|
@ -59,8 +59,9 @@ class BrandMaterialsModel(ListModel):
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
extruder_stack = global_stack.extruders[str(self._extruder_position)]
|
||||||
|
|
||||||
result_dict = getAvailableMaterials(self._extruder_position)
|
result_dict = self._material_manager.getAvailableMaterialsForMachineExtruder(global_stack, extruder_stack)
|
||||||
if result_dict is None:
|
if result_dict is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# Copyright (c) 2018 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from .BaseMaterialsModel import BaseMaterialsModel, getAvailableMaterials
|
from .BaseMaterialsModel import BaseMaterialsModel
|
||||||
|
|
||||||
|
|
||||||
class GenericMaterialsModel(BaseMaterialsModel):
|
class GenericMaterialsModel(BaseMaterialsModel):
|
||||||
|
@ -25,8 +25,9 @@ class GenericMaterialsModel(BaseMaterialsModel):
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
extruder_stack = global_stack.extruders[str(self._extruder_position)]
|
||||||
|
|
||||||
result_dict = getAvailableMaterials(self._extruder_position)
|
result_dict = self._material_manager.getAvailableMaterialsForMachineExtruder(global_stack, extruder_stack)
|
||||||
if result_dict is None:
|
if result_dict is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
|
|
@ -5,8 +5,6 @@ from PyQt5.QtCore import Qt, pyqtProperty
|
||||||
|
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
from .BaseMaterialsModel import getAvailableMaterials
|
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# This model is for the Material management page.
|
# This model is for the Material management page.
|
||||||
|
@ -52,12 +50,12 @@ class MaterialManagementModel(ListModel):
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
self._container_registry = CuraApplication.getInstance().getContainerRegistry()
|
self._container_registry = CuraApplication.getInstance().getContainerRegistry()
|
||||||
self._machine_manager = CuraApplication.getInstance().getMachineManager()
|
self._machine_manager = CuraApplication.getInstance().getMachineManager()
|
||||||
extruder_manager = CuraApplication.getInstance().getExtruderManager()
|
self._extruder_manager = CuraApplication.getInstance().getExtruderManager()
|
||||||
material_manager = CuraApplication.getInstance().getMaterialManager()
|
self._material_manager = CuraApplication.getInstance().getMaterialManager()
|
||||||
|
|
||||||
self._machine_manager.globalContainerChanged.connect(self._update)
|
self._machine_manager.globalContainerChanged.connect(self._update)
|
||||||
extruder_manager.activeExtruderChanged.connect(self._update)
|
self._extruder_manager.activeExtruderChanged.connect(self._update)
|
||||||
material_manager.materialsUpdated.connect(self._update)
|
self._material_manager.materialsUpdated.connect(self._update)
|
||||||
|
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
|
@ -66,8 +64,10 @@ class MaterialManagementModel(ListModel):
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
active_extruder_stack = self._machine_manager.activeStack
|
||||||
|
|
||||||
result_dict = getAvailableMaterials()
|
result_dict = self._material_manager.getAvailableMaterialsForMachineExtruder(global_stack,
|
||||||
|
active_extruder_stack)
|
||||||
if result_dict is None:
|
if result_dict is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue