mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-20 13:17:51 -06:00
WIP: Cleanup MachineManager
This commit is contained in:
parent
495fc8bbd7
commit
6124729f01
1 changed files with 0 additions and 106 deletions
|
@ -609,112 +609,6 @@ class MachineManager(QObject):
|
|||
if extruder_stack != self._active_container_stack and extruder_stack.getProperty(key, "value") != new_value:
|
||||
extruder_stack.userChanges.setProperty(key, "value", new_value) # TODO: nested property access, should be improved
|
||||
|
||||
## Set the active material by switching out a container
|
||||
# Depending on from/to material+current variant, a quality profile is chosen and set.
|
||||
@pyqtSlot(str)
|
||||
def setActiveMaterial(self, material_id: str, always_discard_changes = False):
|
||||
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(id = material_id)
|
||||
if not containers or not self._active_container_stack:
|
||||
return
|
||||
material_container = containers[0]
|
||||
|
||||
Logger.log("d", "Attempting to change the active material to %s", material_id)
|
||||
|
||||
old_material = self._active_container_stack.material
|
||||
old_quality = self._active_container_stack.quality
|
||||
old_quality_type = None
|
||||
if old_quality and old_quality.getId() != self._empty_quality_container.getId():
|
||||
old_quality_type = old_quality.getMetaDataEntry("quality_type")
|
||||
old_quality_changes = self._active_container_stack.qualityChanges
|
||||
if not old_material:
|
||||
Logger.log("w", "While trying to set the active material, no material was found to replace it.")
|
||||
return
|
||||
|
||||
if old_quality_changes and isinstance(old_quality_changes, type(self._empty_quality_changes_container)):
|
||||
old_quality_changes = None
|
||||
|
||||
self.blurSettings.emit()
|
||||
old_material.nameChanged.disconnect(self._onMaterialNameChanged)
|
||||
|
||||
self._new_material_container = material_container # self._active_container_stack will be updated with a delay
|
||||
Logger.log("d", "Active material changed")
|
||||
|
||||
material_container.nameChanged.connect(self._onMaterialNameChanged)
|
||||
|
||||
if material_container.getMetaDataEntry("compatible") == False:
|
||||
self._material_incompatible_message.show()
|
||||
else:
|
||||
self._material_incompatible_message.hide()
|
||||
|
||||
quality_type = None
|
||||
new_quality_id = None
|
||||
if old_quality:
|
||||
new_quality_id = old_quality.getId()
|
||||
quality_type = old_quality.getMetaDataEntry("quality_type")
|
||||
if old_quality_changes:
|
||||
quality_type = old_quality_changes.getMetaDataEntry("quality_type")
|
||||
new_quality_id = old_quality_changes.getId()
|
||||
|
||||
global_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_stack:
|
||||
quality_manager = QualityManager.getInstance()
|
||||
|
||||
candidate_quality = None
|
||||
if quality_type:
|
||||
candidate_quality = quality_manager.findQualityByQualityType(quality_type,
|
||||
quality_manager.getWholeMachineDefinition(global_stack.definition),
|
||||
[material_container.getMetaData()])
|
||||
|
||||
if not candidate_quality or candidate_quality.getId() == self._empty_quality_changes_container:
|
||||
Logger.log("d", "Attempting to find fallback quality")
|
||||
# Fall back to a quality (which must be compatible with all other extruders)
|
||||
new_qualities = quality_manager.findAllUsableQualitiesForMachineAndExtruders(
|
||||
self._global_container_stack, ExtruderManager.getInstance().getExtruderStacks())
|
||||
|
||||
quality_types = sorted([q.getMetaDataEntry("quality_type") for q in new_qualities], reverse = True)
|
||||
quality_type_to_use = None
|
||||
if quality_types:
|
||||
# try to use the same quality as before, otherwise the first one in the quality_types
|
||||
quality_type_to_use = quality_types[0]
|
||||
if old_quality_type is not None and old_quality_type in quality_type_to_use:
|
||||
quality_type_to_use = old_quality_type
|
||||
|
||||
new_quality = None
|
||||
for q in new_qualities:
|
||||
if quality_type_to_use is not None and q.getMetaDataEntry("quality_type") == quality_type_to_use:
|
||||
new_quality = q
|
||||
break
|
||||
|
||||
if new_quality is not None:
|
||||
new_quality_id = new_quality.getId() # Just pick the first available one
|
||||
else:
|
||||
Logger.log("w", "No quality profile found that matches the current machine and extruders.")
|
||||
else:
|
||||
if not old_quality_changes:
|
||||
new_quality_id = candidate_quality.getId()
|
||||
|
||||
self.setActiveQuality(new_quality_id, always_discard_changes = always_discard_changes)
|
||||
|
||||
# TODO: refactor this
|
||||
@pyqtSlot(str)
|
||||
def setActiveVariantBuildplate(self, variant_buildplate_id: str):
|
||||
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
|
||||
containers = ContainerRegistry.getInstance().findInstanceContainers(id = variant_buildplate_id)
|
||||
if not containers or not self._global_container_stack:
|
||||
return
|
||||
Logger.log("d", "Attempting to change the active buildplate to %s", variant_buildplate_id)
|
||||
old_buildplate = self._global_container_stack.variant
|
||||
if old_buildplate:
|
||||
self.blurSettings.emit()
|
||||
self._new_buildplate_container = containers[0] # self._active_container_stack will be updated with a delay
|
||||
Logger.log("d", "Active buildplate changed to {active_variant_buildplate_id}".format(active_variant_buildplate_id = containers[0].getId()))
|
||||
|
||||
# Force set the active quality as it is so the values are updated
|
||||
self.setActiveMaterial(self._active_container_stack.material.getId())
|
||||
else:
|
||||
Logger.log("w", "While trying to set the active buildplate, no buildplate was found to replace.")
|
||||
|
||||
## set the active quality
|
||||
# \param quality_id The quality_id of either a quality or a quality_changes
|
||||
@pyqtSlot(str)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue