mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-12 09:17:50 -06:00
Move towards making extruder manager a first class citizen - CURA-4482
This commit is contained in:
parent
723f6ce226
commit
b91824aab1
9 changed files with 121 additions and 108 deletions
|
@ -917,24 +917,23 @@ class BuildVolume(SceneNode):
|
||||||
# which extruder to get the setting, if there are multiple extruders.
|
# which extruder to get the setting, if there are multiple extruders.
|
||||||
# \param property The property to get from the setting.
|
# \param property The property to get from the setting.
|
||||||
# \return The property of the specified setting in the specified extruder.
|
# \return The property of the specified setting in the specified extruder.
|
||||||
def _getSettingFromExtruder(self, setting_key, extruder_setting_key, property = "value"):
|
def _getSettingFromExtruder(self, setting_key, extruder_setting_key, prop = "value"):
|
||||||
multi_extrusion = self._global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
extruder_index = self._global_container_stack.getProperty(extruder_setting_key, "value")
|
||||||
|
|
||||||
if not multi_extrusion:
|
# TODO: remove this - CURA-4482
|
||||||
stack = self._global_container_stack
|
if str(extruder_index) == "-1": # If extruder index is -1 use global instead
|
||||||
|
extruder_stack = self._global_container_stack
|
||||||
else:
|
else:
|
||||||
extruder_index = self._global_container_stack.getProperty(extruder_setting_key, "value")
|
extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)]
|
||||||
|
extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
||||||
|
|
||||||
if str(extruder_index) == "-1": # If extruder index is -1 use global instead
|
value = extruder_stack.getProperty(setting_key, prop)
|
||||||
stack = self._global_container_stack
|
setting_type = extruder_stack.getProperty(setting_key, "type")
|
||||||
else:
|
|
||||||
extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)]
|
|
||||||
stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
|
||||||
|
|
||||||
value = stack.getProperty(setting_key, property)
|
# default 0 for numerical values
|
||||||
setting_type = stack.getProperty(setting_key, "type")
|
|
||||||
if not value and (setting_type == "int" or setting_type == "float"):
|
if not value and (setting_type == "int" or setting_type == "float"):
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
## Convenience function to calculate the disallowed radius around the edge.
|
## Convenience function to calculate the disallowed radius around the edge.
|
||||||
|
@ -945,6 +944,7 @@ class BuildVolume(SceneNode):
|
||||||
def _getEdgeDisallowedSize(self):
|
def _getEdgeDisallowedSize(self):
|
||||||
if not self._global_container_stack:
|
if not self._global_container_stack:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
container_stack = self._global_container_stack
|
container_stack = self._global_container_stack
|
||||||
used_extruders = ExtruderManager.getInstance().getUsedExtruderStacks()
|
used_extruders = ExtruderManager.getInstance().getUsedExtruderStacks()
|
||||||
|
|
||||||
|
@ -953,26 +953,33 @@ class BuildVolume(SceneNode):
|
||||||
return 0.1 # Return a very small value, so we do draw disallowed area's near the edges.
|
return 0.1 # Return a very small value, so we do draw disallowed area's near the edges.
|
||||||
|
|
||||||
adhesion_type = container_stack.getProperty("adhesion_type", "value")
|
adhesion_type = container_stack.getProperty("adhesion_type", "value")
|
||||||
|
|
||||||
if adhesion_type == "skirt":
|
if adhesion_type == "skirt":
|
||||||
skirt_distance = self._getSettingFromAdhesionExtruder("skirt_gap")
|
skirt_distance = self._getSettingFromAdhesionExtruder("skirt_gap")
|
||||||
skirt_line_count = self._getSettingFromAdhesionExtruder("skirt_line_count")
|
skirt_line_count = self._getSettingFromAdhesionExtruder("skirt_line_count")
|
||||||
bed_adhesion_size = skirt_distance + (self._getSettingFromAdhesionExtruder("skirt_brim_line_width") * skirt_line_count) * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
|
bed_adhesion_size = skirt_distance + (self._getSettingFromAdhesionExtruder("skirt_brim_line_width") * skirt_line_count) * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
|
||||||
if len(used_extruders) > 1:
|
|
||||||
for extruder_stack in used_extruders:
|
for extruder_stack in used_extruders:
|
||||||
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
||||||
#We don't create an additional line for the extruder we're printing the skirt with.
|
|
||||||
bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
|
# We don't create an additional line for the extruder we're printing the skirt with.
|
||||||
|
bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
|
||||||
|
|
||||||
elif adhesion_type == "brim":
|
elif adhesion_type == "brim":
|
||||||
bed_adhesion_size = self._getSettingFromAdhesionExtruder("skirt_brim_line_width") * self._getSettingFromAdhesionExtruder("brim_line_count") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
|
bed_adhesion_size = self._getSettingFromAdhesionExtruder("skirt_brim_line_width") * self._getSettingFromAdhesionExtruder("brim_line_count") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
|
||||||
if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
|
|
||||||
for extruder_stack in used_extruders:
|
for extruder_stack in used_extruders:
|
||||||
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
|
||||||
#We don't create an additional line for the extruder we're printing the brim with.
|
|
||||||
bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
|
# We don't create an additional line for the extruder we're printing the brim with.
|
||||||
|
bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
|
||||||
|
|
||||||
elif adhesion_type == "raft":
|
elif adhesion_type == "raft":
|
||||||
bed_adhesion_size = self._getSettingFromAdhesionExtruder("raft_margin")
|
bed_adhesion_size = self._getSettingFromAdhesionExtruder("raft_margin")
|
||||||
|
|
||||||
elif adhesion_type == "none":
|
elif adhesion_type == "none":
|
||||||
bed_adhesion_size = 0
|
bed_adhesion_size = 0
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise Exception("Unknown bed adhesion type. Did you forget to update the build volume calculations for your new bed adhesion type?")
|
raise Exception("Unknown bed adhesion type. Did you forget to update the build volume calculations for your new bed adhesion type?")
|
||||||
|
|
||||||
|
|
|
@ -302,24 +302,23 @@ class ConvexHullDecorator(SceneNodeDecorator):
|
||||||
self._onChanged()
|
self._onChanged()
|
||||||
|
|
||||||
## Private convenience function to get a setting from the correct extruder (as defined by limit_to_extruder property).
|
## Private convenience function to get a setting from the correct extruder (as defined by limit_to_extruder property).
|
||||||
def _getSettingProperty(self, setting_key, property = "value"):
|
def _getSettingProperty(self, setting_key, prop = "value"):
|
||||||
per_mesh_stack = self._node.callDecoration("getStack")
|
per_mesh_stack = self._node.callDecoration("getStack")
|
||||||
if per_mesh_stack:
|
if per_mesh_stack:
|
||||||
return per_mesh_stack.getProperty(setting_key, property)
|
return per_mesh_stack.getProperty(setting_key, prop)
|
||||||
|
|
||||||
multi_extrusion = self._global_stack.getProperty("machine_extruder_count", "value") > 1
|
|
||||||
if not multi_extrusion:
|
|
||||||
return self._global_stack.getProperty(setting_key, property)
|
|
||||||
|
|
||||||
extruder_index = self._global_stack.getProperty(setting_key, "limit_to_extruder")
|
extruder_index = self._global_stack.getProperty(setting_key, "limit_to_extruder")
|
||||||
if extruder_index == "-1": #No limit_to_extruder.
|
if extruder_index == "-1":
|
||||||
|
# No limit_to_extruder
|
||||||
extruder_stack_id = self._node.callDecoration("getActiveExtruder")
|
extruder_stack_id = self._node.callDecoration("getActiveExtruder")
|
||||||
if not extruder_stack_id: #Decoration doesn't exist.
|
if not extruder_stack_id:
|
||||||
|
# Decoration doesn't exist
|
||||||
extruder_stack_id = ExtruderManager.getInstance().extruderIds["0"]
|
extruder_stack_id = ExtruderManager.getInstance().extruderIds["0"]
|
||||||
extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
||||||
return extruder_stack.getProperty(setting_key, property)
|
return extruder_stack.getProperty(setting_key, prop)
|
||||||
else: #Limit_to_extruder is set. The global stack handles this then.
|
else:
|
||||||
return self._global_stack.getProperty(setting_key, property)
|
# Limit_to_extruder is set. The global stack handles this then
|
||||||
|
return self._global_stack.getProperty(setting_key, prop)
|
||||||
|
|
||||||
## Returns true if node is a descendant or the same as the root node.
|
## Returns true if node is a descendant or the same as the root node.
|
||||||
def __isDescendant(self, root, node):
|
def __isDescendant(self, root, node):
|
||||||
|
|
|
@ -200,6 +200,7 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
self._machine_action_manager = MachineActionManager.MachineActionManager()
|
self._machine_action_manager = MachineActionManager.MachineActionManager()
|
||||||
self._machine_manager = None # This is initialized on demand.
|
self._machine_manager = None # This is initialized on demand.
|
||||||
|
self._extruder_manager = None
|
||||||
self._material_manager = None
|
self._material_manager = None
|
||||||
self._setting_inheritance_manager = None
|
self._setting_inheritance_manager = None
|
||||||
self._simple_mode_settings_manager = None
|
self._simple_mode_settings_manager = None
|
||||||
|
@ -259,20 +260,24 @@ class CuraApplication(QtApplication):
|
||||||
# Since they are empty, they should never be serialized and instead just programmatically created.
|
# Since they are empty, they should never be serialized and instead just programmatically created.
|
||||||
# We need them to simplify the switching between materials.
|
# We need them to simplify the switching between materials.
|
||||||
empty_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
empty_container = ContainerRegistry.getInstance().getEmptyInstanceContainer()
|
||||||
|
|
||||||
empty_variant_container = copy.deepcopy(empty_container)
|
empty_variant_container = copy.deepcopy(empty_container)
|
||||||
empty_variant_container._id = "empty_variant"
|
empty_variant_container._id = "empty_variant"
|
||||||
empty_variant_container.addMetaDataEntry("type", "variant")
|
empty_variant_container.addMetaDataEntry("type", "variant")
|
||||||
ContainerRegistry.getInstance().addContainer(empty_variant_container)
|
ContainerRegistry.getInstance().addContainer(empty_variant_container)
|
||||||
|
|
||||||
empty_material_container = copy.deepcopy(empty_container)
|
empty_material_container = copy.deepcopy(empty_container)
|
||||||
empty_material_container._id = "empty_material"
|
empty_material_container._id = "empty_material"
|
||||||
empty_material_container.addMetaDataEntry("type", "material")
|
empty_material_container.addMetaDataEntry("type", "material")
|
||||||
ContainerRegistry.getInstance().addContainer(empty_material_container)
|
ContainerRegistry.getInstance().addContainer(empty_material_container)
|
||||||
|
|
||||||
empty_quality_container = copy.deepcopy(empty_container)
|
empty_quality_container = copy.deepcopy(empty_container)
|
||||||
empty_quality_container._id = "empty_quality"
|
empty_quality_container._id = "empty_quality"
|
||||||
empty_quality_container.setName("Not Supported")
|
empty_quality_container.setName("Not Supported")
|
||||||
empty_quality_container.addMetaDataEntry("quality_type", "normal")
|
empty_quality_container.addMetaDataEntry("quality_type", "normal")
|
||||||
empty_quality_container.addMetaDataEntry("type", "quality")
|
empty_quality_container.addMetaDataEntry("type", "quality")
|
||||||
ContainerRegistry.getInstance().addContainer(empty_quality_container)
|
ContainerRegistry.getInstance().addContainer(empty_quality_container)
|
||||||
|
|
||||||
empty_quality_changes_container = copy.deepcopy(empty_container)
|
empty_quality_changes_container = copy.deepcopy(empty_container)
|
||||||
empty_quality_changes_container._id = "empty_quality_changes"
|
empty_quality_changes_container._id = "empty_quality_changes"
|
||||||
empty_quality_changes_container.addMetaDataEntry("type", "quality_changes")
|
empty_quality_changes_container.addMetaDataEntry("type", "quality_changes")
|
||||||
|
@ -413,7 +418,7 @@ class CuraApplication(QtApplication):
|
||||||
def discardOrKeepProfileChangesClosed(self, option):
|
def discardOrKeepProfileChangesClosed(self, option):
|
||||||
if option == "discard":
|
if option == "discard":
|
||||||
global_stack = self.getGlobalContainerStack()
|
global_stack = self.getGlobalContainerStack()
|
||||||
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
|
for extruder in self._extruder_manager.getMachineExtruders(global_stack.getId()):
|
||||||
extruder.getTop().clear()
|
extruder.getTop().clear()
|
||||||
global_stack.getTop().clear()
|
global_stack.getTop().clear()
|
||||||
|
|
||||||
|
@ -421,7 +426,7 @@ class CuraApplication(QtApplication):
|
||||||
# before slicing. To ensure that slicer uses right settings values
|
# before slicing. To ensure that slicer uses right settings values
|
||||||
elif option == "keep":
|
elif option == "keep":
|
||||||
global_stack = self.getGlobalContainerStack()
|
global_stack = self.getGlobalContainerStack()
|
||||||
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
|
for extruder in self._extruder_manager.getMachineExtruders(global_stack.getId()):
|
||||||
user_extruder_container = extruder.getTop()
|
user_extruder_container = extruder.getTop()
|
||||||
if user_extruder_container:
|
if user_extruder_container:
|
||||||
user_extruder_container.update()
|
user_extruder_container.update()
|
||||||
|
@ -686,16 +691,13 @@ class CuraApplication(QtApplication):
|
||||||
|
|
||||||
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading interface..."))
|
self.showSplashMessage(self._i18n_catalog.i18nc("@info:progress", "Loading interface..."))
|
||||||
|
|
||||||
# Initialise extruder so as to listen to global container stack changes before the first global container stack is set.
|
qmlRegisterSingletonType(ExtruderManager, "Cura", 1, 0, "ExtruderManager", self.getExtruderManager)
|
||||||
ExtruderManager.getInstance()
|
|
||||||
qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
|
qmlRegisterSingletonType(MachineManager, "Cura", 1, 0, "MachineManager", self.getMachineManager)
|
||||||
qmlRegisterSingletonType(MaterialManager, "Cura", 1, 0, "MaterialManager", self.getMaterialManager)
|
qmlRegisterSingletonType(MaterialManager, "Cura", 1, 0, "MaterialManager", self.getMaterialManager)
|
||||||
qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager",
|
qmlRegisterSingletonType(SettingInheritanceManager, "Cura", 1, 0, "SettingInheritanceManager", self.getSettingInheritanceManager)
|
||||||
self.getSettingInheritanceManager)
|
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 2, "SimpleModeSettingsManager", self.getSimpleModeSettingsManager)
|
||||||
qmlRegisterSingletonType(SimpleModeSettingsManager, "Cura", 1, 2, "SimpleModeSettingsManager",
|
|
||||||
self.getSimpleModeSettingsManager)
|
|
||||||
|
|
||||||
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
qmlRegisterSingletonType(MachineActionManager.MachineActionManager, "Cura", 1, 0, "MachineActionManager", self.getMachineActionManager)
|
||||||
|
|
||||||
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
self.setMainQml(Resources.getPath(self.ResourceTypes.QmlFiles, "Cura.qml"))
|
||||||
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
self._qml_import_paths.append(Resources.getPath(self.ResourceTypes.QmlFiles))
|
||||||
self.initializeEngine()
|
self.initializeEngine()
|
||||||
|
@ -717,6 +719,11 @@ class CuraApplication(QtApplication):
|
||||||
self._machine_manager = MachineManager.createMachineManager()
|
self._machine_manager = MachineManager.createMachineManager()
|
||||||
return self._machine_manager
|
return self._machine_manager
|
||||||
|
|
||||||
|
def getExtruderManager(self, *args):
|
||||||
|
if self._extruder_manager is None:
|
||||||
|
self._extruder_manager = ExtruderManager.createExtruderManager()
|
||||||
|
return self._extruder_manager
|
||||||
|
|
||||||
def getMaterialManager(self, *args):
|
def getMaterialManager(self, *args):
|
||||||
if self._material_manager is None:
|
if self._material_manager is None:
|
||||||
self._material_manager = MaterialManager.createMaterialManager()
|
self._material_manager = MaterialManager.createMaterialManager()
|
||||||
|
@ -784,7 +791,7 @@ class CuraApplication(QtApplication):
|
||||||
actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
|
actions_url = QUrl.fromLocalFile(os.path.abspath(Resources.getPath(CuraApplication.ResourceTypes.QmlFiles, "Actions.qml")))
|
||||||
qmlRegisterSingletonType(actions_url, "Cura", 1, 0, "Actions")
|
qmlRegisterSingletonType(actions_url, "Cura", 1, 0, "Actions")
|
||||||
|
|
||||||
engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.getInstance())
|
# engine.rootContext().setContextProperty("ExtruderManager", ExtruderManager.getInstance())
|
||||||
|
|
||||||
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
for path in Resources.getAllResourcesOfType(CuraApplication.ResourceTypes.QmlFiles):
|
||||||
type_name = os.path.splitext(os.path.basename(path))[0]
|
type_name = os.path.splitext(os.path.basename(path))[0]
|
||||||
|
|
|
@ -62,6 +62,7 @@ class CuraStackBuilder:
|
||||||
variant = "default",
|
variant = "default",
|
||||||
next_stack = new_global_stack
|
next_stack = new_global_stack
|
||||||
)
|
)
|
||||||
|
new_global_stack.addExtruder(new_extruder)
|
||||||
|
|
||||||
return new_global_stack
|
return new_global_stack
|
||||||
|
|
||||||
|
@ -79,7 +80,9 @@ class CuraStackBuilder:
|
||||||
stack.setName(definition.getName())
|
stack.setName(definition.getName())
|
||||||
stack.setDefinition(definition)
|
stack.setDefinition(definition)
|
||||||
stack.addMetaDataEntry("position", definition.getMetaDataEntry("position"))
|
stack.addMetaDataEntry("position", definition.getMetaDataEntry("position"))
|
||||||
if "next_stack" in kwargs: #Add stacks before containers are added, since they may trigger a setting update.
|
|
||||||
|
if "next_stack" in kwargs:
|
||||||
|
# Add stacks before containers are added, since they may trigger a setting update.
|
||||||
stack.setNextStack(kwargs["next_stack"])
|
stack.setNextStack(kwargs["next_stack"])
|
||||||
|
|
||||||
user_container = InstanceContainer(new_stack_id + "_user")
|
user_container = InstanceContainer(new_stack_id + "_user")
|
||||||
|
|
|
@ -83,18 +83,23 @@ class ExtruderManager(QObject):
|
||||||
@pyqtProperty("QVariantMap", notify = extrudersChanged)
|
@pyqtProperty("QVariantMap", notify = extrudersChanged)
|
||||||
def extruderIds(self):
|
def extruderIds(self):
|
||||||
extruder_stack_ids = {}
|
extruder_stack_ids = {}
|
||||||
|
|
||||||
global_stack_id = Application.getInstance().getGlobalContainerStack().getId()
|
global_stack_id = Application.getInstance().getGlobalContainerStack().getId()
|
||||||
extruder_stack_ids["-1"] = global_stack_id
|
|
||||||
|
# TODO: remove this? - CURA-4482
|
||||||
|
# extruder_stack_ids["-1"] = global_stack_id
|
||||||
|
|
||||||
if global_stack_id in self._extruder_trains:
|
if global_stack_id in self._extruder_trains:
|
||||||
for position in self._extruder_trains[global_stack_id]:
|
for position in self._extruder_trains[global_stack_id]:
|
||||||
extruder_stack_ids[position] = self._extruder_trains[global_stack_id][position].getId()
|
extruder_stack_ids[position] = self._extruder_trains[global_stack_id][position].getId()
|
||||||
|
|
||||||
return extruder_stack_ids
|
return extruder_stack_ids
|
||||||
|
|
||||||
@pyqtSlot(str, result = str)
|
@pyqtSlot(str, result = str)
|
||||||
def getQualityChangesIdByExtruderStackId(self, id: str) -> str:
|
def getQualityChangesIdByExtruderStackId(self, extruder_stack_id: str) -> str:
|
||||||
for position in self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()]:
|
for position in self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()]:
|
||||||
extruder = self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][position]
|
extruder = self._extruder_trains[Application.getInstance().getGlobalContainerStack().getId()][position]
|
||||||
if extruder.getId() == id:
|
if extruder.getId() == extruder_stack_id:
|
||||||
return extruder.qualityChanges.getId()
|
return extruder.qualityChanges.getId()
|
||||||
|
|
||||||
## The instance of the singleton pattern.
|
## The instance of the singleton pattern.
|
||||||
|
@ -102,6 +107,10 @@ class ExtruderManager(QObject):
|
||||||
# It's None if the extruder manager hasn't been created yet.
|
# It's None if the extruder manager hasn't been created yet.
|
||||||
__instance = None
|
__instance = None
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def createExtruderManager():
|
||||||
|
return ExtruderManager()
|
||||||
|
|
||||||
## Gets an instance of the extruder manager, or creates one if no instance
|
## Gets an instance of the extruder manager, or creates one if no instance
|
||||||
# exists yet.
|
# exists yet.
|
||||||
#
|
#
|
||||||
|
@ -420,20 +429,21 @@ class ExtruderManager(QObject):
|
||||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
|
|
||||||
if global_stack.getProperty("machine_extruder_count", "value") <= 1: #For single extrusion.
|
|
||||||
return [global_stack]
|
|
||||||
|
|
||||||
used_extruder_stack_ids = set()
|
used_extruder_stack_ids = set()
|
||||||
|
|
||||||
#Get the extruders of all meshes in the scene.
|
# Get the extruders of all meshes in the scene
|
||||||
support_enabled = False
|
support_enabled = False
|
||||||
support_bottom_enabled = False
|
support_bottom_enabled = False
|
||||||
support_roof_enabled = False
|
support_roof_enabled = False
|
||||||
|
|
||||||
scene_root = Application.getInstance().getController().getScene().getRoot()
|
scene_root = Application.getInstance().getController().getScene().getRoot()
|
||||||
meshes = [node for node in DepthFirstIterator(scene_root) if type(node) is SceneNode and node.isSelectable()] #Only use the nodes that will be printed.
|
|
||||||
|
# Get the extruders of all printable meshes in the scene
|
||||||
|
meshes = [node for node in DepthFirstIterator(scene_root) if type(node) is SceneNode and node.isSelectable()]
|
||||||
for mesh in meshes:
|
for mesh in meshes:
|
||||||
extruder_stack_id = mesh.callDecoration("getActiveExtruder")
|
extruder_stack_id = mesh.callDecoration("getActiveExtruder")
|
||||||
if not extruder_stack_id: #No per-object settings for this node.
|
if not extruder_stack_id:
|
||||||
|
# No per-object settings for this node
|
||||||
extruder_stack_id = self.extruderIds["0"]
|
extruder_stack_id = self.extruderIds["0"]
|
||||||
used_extruder_stack_ids.add(extruder_stack_id)
|
used_extruder_stack_ids.add(extruder_stack_id)
|
||||||
|
|
||||||
|
@ -469,9 +479,10 @@ class ExtruderManager(QObject):
|
||||||
if support_roof_enabled:
|
if support_roof_enabled:
|
||||||
used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("support_roof_extruder_nr", "value"))])
|
used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("support_roof_extruder_nr", "value"))])
|
||||||
|
|
||||||
#The platform adhesion extruder. Not used if using none.
|
# The platform adhesion extruder. Not used if using none.
|
||||||
if global_stack.getProperty("adhesion_type", "value") != "none":
|
if global_stack.getProperty("adhesion_type", "value") != "none":
|
||||||
used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("adhesion_extruder_nr", "value"))])
|
used_extruder_stack_ids.add(self.extruderIds[str(global_stack.getProperty("adhesion_extruder_nr", "value"))])
|
||||||
|
|
||||||
try:
|
try:
|
||||||
return [container_registry.findContainerStacks(id = stack_id)[0] for stack_id in used_extruder_stack_ids]
|
return [container_registry.findContainerStacks(id = stack_id)[0] for stack_id in used_extruder_stack_ids]
|
||||||
except IndexError: # One or more of the extruders was not found.
|
except IndexError: # One or more of the extruders was not found.
|
||||||
|
@ -518,10 +529,6 @@ class ExtruderManager(QObject):
|
||||||
result = []
|
result = []
|
||||||
machine_extruder_count = global_stack.getProperty("machine_extruder_count", "value")
|
machine_extruder_count = global_stack.getProperty("machine_extruder_count", "value")
|
||||||
|
|
||||||
# In case the printer is using one extruder, shouldn't exist active extruder stacks
|
|
||||||
# if machine_extruder_count == 1:
|
|
||||||
# return result
|
|
||||||
|
|
||||||
if global_stack and global_stack.getId() in self._extruder_trains:
|
if global_stack and global_stack.getId() in self._extruder_trains:
|
||||||
for extruder in sorted(self._extruder_trains[global_stack.getId()]):
|
for extruder in sorted(self._extruder_trains[global_stack.getId()]):
|
||||||
result.append(self._extruder_trains[global_stack.getId()][extruder])
|
result.append(self._extruder_trains[global_stack.getId()][extruder])
|
||||||
|
@ -544,8 +551,23 @@ class ExtruderManager(QObject):
|
||||||
## Adds the extruders of the currently active machine.
|
## Adds the extruders of the currently active machine.
|
||||||
def _addCurrentMachineExtruders(self) -> None:
|
def _addCurrentMachineExtruders(self) -> None:
|
||||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
extruders_changed = False
|
||||||
|
|
||||||
if global_stack and global_stack.getBottom():
|
if global_stack and global_stack.getBottom():
|
||||||
self.addMachineExtruders(global_stack.getBottom(), global_stack.getId())
|
container_registry = ContainerRegistry.getInstance()
|
||||||
|
machine_id = global_stack.getBottom().getId()
|
||||||
|
|
||||||
|
# Gets the extruder trains that we just created as well as any that still existed.
|
||||||
|
extruder_trains = container_registry.findContainerStacks(type = "extruder_train", machine = machine_id)
|
||||||
|
for extruder_train in extruder_trains:
|
||||||
|
self._extruder_trains[machine_id][extruder_train.getMetaDataEntry("position")] = extruder_train
|
||||||
|
|
||||||
|
# regardless of what the next stack is, we have to set it again, because of signal routing.
|
||||||
|
extruder_train.setNextStack(global_stack)
|
||||||
|
extruders_changed = True
|
||||||
|
|
||||||
|
if extruders_changed:
|
||||||
|
self.extrudersChanged.emit(machine_id)
|
||||||
|
|
||||||
## Get all extruder values for a certain setting.
|
## Get all extruder values for a certain setting.
|
||||||
#
|
#
|
||||||
|
@ -560,7 +582,7 @@ class ExtruderManager(QObject):
|
||||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
|
for extruder in ExtruderManager.getMachineExtruders(global_stack.getId()):
|
||||||
# only include values from extruders that are "active" for the current machine instance
|
# only include values from extruders that are "active" for the current machine instance
|
||||||
if int(extruder.getMetaDataEntry("position")) >= global_stack.getProperty("machine_extruder_count", "value"):
|
if int(extruder.getMetaDataEntry("position")) >= global_stack.getProperty("machine_extruder_count", "value"):
|
||||||
continue
|
continue
|
||||||
|
@ -600,7 +622,7 @@ class ExtruderManager(QObject):
|
||||||
}
|
}
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
for extruder in ExtruderManager.getInstance().getMachineExtruders(global_stack.getId()):
|
for extruder in ExtruderManager.getMachineExtruders(global_stack.getId()):
|
||||||
# only include values from extruders that are "active" for the current machine instance
|
# only include values from extruders that are "active" for the current machine instance
|
||||||
if int(extruder.getMetaDataEntry("position")) >= global_stack.getProperty("machine_extruder_count", "value", context = context):
|
if int(extruder.getMetaDataEntry("position")) >= global_stack.getProperty("machine_extruder_count", "value", context = context):
|
||||||
continue
|
continue
|
||||||
|
@ -624,7 +646,7 @@ class ExtruderManager(QObject):
|
||||||
#
|
#
|
||||||
# This is exposed to qml for display purposes
|
# This is exposed to qml for display purposes
|
||||||
#
|
#
|
||||||
# \param key The key of the setting to retieve values for.
|
# \param key The key of the setting to retrieve values for.
|
||||||
#
|
#
|
||||||
# \return String representing the extruder values
|
# \return String representing the extruder values
|
||||||
@pyqtSlot(str, result="QVariant")
|
@pyqtSlot(str, result="QVariant")
|
||||||
|
|
|
@ -66,7 +66,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
||||||
self._update_extruder_timer = QTimer()
|
self._update_extruder_timer = QTimer()
|
||||||
self._update_extruder_timer.setInterval(100)
|
self._update_extruder_timer.setInterval(100)
|
||||||
self._update_extruder_timer.setSingleShot(True)
|
self._update_extruder_timer.setSingleShot(True)
|
||||||
self._update_extruder_timer.connect(self.__updateExtruders)
|
self._update_extruder_timer.timeout.connect(self.__updateExtruders)
|
||||||
|
|
||||||
self._add_global = False
|
self._add_global = False
|
||||||
self._simple_names = False
|
self._simple_names = False
|
||||||
|
|
|
@ -1173,7 +1173,7 @@ class MachineManager(QObject):
|
||||||
return containers[0].getBottom().getId()
|
return containers[0].getBottom().getId()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def createMachineManager(engine=None, script_engine=None):
|
def createMachineManager():
|
||||||
return MachineManager()
|
return MachineManager()
|
||||||
|
|
||||||
@deprecated("Use ExtruderStack.material = ... and it won't be necessary", "2.7")
|
@deprecated("Use ExtruderStack.material = ... and it won't be necessary", "2.7")
|
||||||
|
|
|
@ -22,47 +22,23 @@ class QualityAndUserProfilesModel(ProfilesModel):
|
||||||
|
|
||||||
# Fetch the list of quality changes.
|
# Fetch the list of quality changes.
|
||||||
quality_manager = QualityManager.getInstance()
|
quality_manager = QualityManager.getInstance()
|
||||||
machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.getBottom())
|
machine_definition = quality_manager.getParentMachineDefinition(global_container_stack.definition)
|
||||||
quality_changes_list = quality_manager.findAllQualityChangesForMachine(machine_definition)
|
quality_changes_list = quality_manager.findAllQualityChangesForMachine(machine_definition)
|
||||||
|
|
||||||
# Detecting if the machine has multiple extrusion
|
|
||||||
multiple_extrusion = global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
|
||||||
# Get the list of extruders
|
|
||||||
extruder_manager = ExtruderManager.getInstance()
|
extruder_manager = ExtruderManager.getInstance()
|
||||||
active_extruder = extruder_manager.getActiveExtruderStack()
|
active_extruder = extruder_manager.getActiveExtruderStack()
|
||||||
extruder_stacks = extruder_manager.getActiveExtruderStacks()
|
extruder_stacks = self._getOrderedExtruderStacksList()
|
||||||
if multiple_extrusion:
|
|
||||||
# Place the active extruder at the front of the list.
|
|
||||||
# This is a workaround checking if there is an active_extruder or not before moving it to the front of the list.
|
|
||||||
# Actually, when a printer has multiple extruders, should exist always an active_extruder. However, in some
|
|
||||||
# cases the active_extruder is still None.
|
|
||||||
if active_extruder in extruder_stacks:
|
|
||||||
extruder_stacks.remove(active_extruder)
|
|
||||||
new_extruder_stacks = []
|
|
||||||
if active_extruder is not None:
|
|
||||||
new_extruder_stacks = [active_extruder]
|
|
||||||
else:
|
|
||||||
# if there is no active extruder, use the first one in the active extruder stacks
|
|
||||||
active_extruder = extruder_stacks[0]
|
|
||||||
extruder_stacks = new_extruder_stacks + extruder_stacks
|
|
||||||
|
|
||||||
# Fetch the list of useable qualities across all extruders.
|
# Fetch the list of usable qualities across all extruders.
|
||||||
# The actual list of quality profiles come from the first extruder in the extruder list.
|
# The actual list of quality profiles come from the first extruder in the extruder list.
|
||||||
quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack,
|
quality_list = quality_manager.findAllUsableQualitiesForMachineAndExtruders(global_container_stack, extruder_stacks)
|
||||||
extruder_stacks)
|
|
||||||
|
|
||||||
# Filter the quality_change by the list of available quality_types
|
# Filter the quality_change by the list of available quality_types
|
||||||
quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
|
quality_type_set = set([x.getMetaDataEntry("quality_type") for x in quality_list])
|
||||||
|
filtered_quality_changes = [qc for qc in quality_changes_list if
|
||||||
if multiple_extrusion:
|
qc.getMetaDataEntry("quality_type") in quality_type_set and
|
||||||
# If the printer has multiple extruders then quality changes related to the current extruder are kept
|
qc.getMetaDataEntry("extruder") is not None and
|
||||||
filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
|
(qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
|
||||||
qc.getMetaDataEntry("extruder") is not None and
|
qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())]
|
||||||
(qc.getMetaDataEntry("extruder") == active_extruder.definition.getMetaDataEntry("quality_definition") or
|
|
||||||
qc.getMetaDataEntry("extruder") == active_extruder.definition.getId())]
|
|
||||||
else:
|
|
||||||
# If not, the quality changes of the global stack are selected
|
|
||||||
filtered_quality_changes = [qc for qc in quality_changes_list if qc.getMetaDataEntry("quality_type") in quality_type_set and
|
|
||||||
qc.getMetaDataEntry("extruder") is None]
|
|
||||||
|
|
||||||
return quality_list + filtered_quality_changes
|
return quality_list + filtered_quality_changes
|
||||||
|
|
|
@ -47,21 +47,20 @@ class SettingInheritanceManager(QObject):
|
||||||
|
|
||||||
@pyqtSlot(str, str, result = "QStringList")
|
@pyqtSlot(str, str, result = "QStringList")
|
||||||
def getOverridesForExtruder(self, key, extruder_index):
|
def getOverridesForExtruder(self, key, extruder_index):
|
||||||
multi_extrusion = self._global_container_stack.getProperty("machine_extruder_count", "value") > 1
|
result = []
|
||||||
if not multi_extrusion:
|
|
||||||
return self._settings_with_inheritance_warning
|
|
||||||
extruder = ExtruderManager.getInstance().getExtruderStack(extruder_index)
|
|
||||||
if not extruder:
|
|
||||||
Logger.log("w", "Unable to find extruder for current machine with index %s", extruder_index)
|
|
||||||
return []
|
|
||||||
|
|
||||||
definitions = self._global_container_stack.definition.findDefinitions(key=key)
|
extruder_stack = ExtruderManager.getInstance().getExtruderStack(extruder_index)
|
||||||
|
if not extruder_stack:
|
||||||
|
Logger.log("w", "Unable to find extruder for current machine with index %s", extruder_index)
|
||||||
|
return result
|
||||||
|
|
||||||
|
definitions = self._global_container_stack.definition.findDefinitions(key = key)
|
||||||
if not definitions:
|
if not definitions:
|
||||||
Logger.log("w", "Could not find definition for key [%s] (2)", key)
|
Logger.log("w", "Could not find definition for key [%s] (2)", key)
|
||||||
return []
|
return result
|
||||||
result = []
|
|
||||||
for key in definitions[0].getAllKeys():
|
for key in definitions[0].getAllKeys():
|
||||||
if self._settingIsOverwritingInheritance(key, extruder):
|
if self._settingIsOverwritingInheritance(key, extruder_stack):
|
||||||
result.append(key)
|
result.append(key)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue