mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 07:03:56 -06:00
Create extruder stack for single extruder machines on start - CURA-4482
This commit is contained in:
parent
b91824aab1
commit
d718e6e36c
20 changed files with 268 additions and 224 deletions
|
@ -12,6 +12,7 @@ from PyQt5.QtWidgets import QMessageBox
|
|||
from UM.Decorators import override
|
||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||
from UM.Settings.ContainerStack import ContainerStack
|
||||
from UM.Settings.DefinitionContainer import DefinitionContainer
|
||||
from UM.Settings.InstanceContainer import InstanceContainer
|
||||
from UM.Application import Application
|
||||
from UM.Logger import Logger
|
||||
|
@ -42,12 +43,13 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
# Global stack based on metadata information.
|
||||
@override(ContainerRegistry)
|
||||
def addContainer(self, container):
|
||||
|
||||
# Note: Intentional check with type() because we want to ignore subclasses
|
||||
if type(container) == ContainerStack:
|
||||
container = self._convertContainerStack(container)
|
||||
|
||||
if isinstance(container, InstanceContainer) and type(container) != type(self.getEmptyInstanceContainer()):
|
||||
#Check against setting version of the definition.
|
||||
# Check against setting version of the definition.
|
||||
required_setting_version = CuraApplication.SettingVersion
|
||||
actual_setting_version = int(container.getMetaDataEntry("setting_version", default = 0))
|
||||
if required_setting_version != actual_setting_version:
|
||||
|
@ -256,7 +258,8 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
@override(ContainerRegistry)
|
||||
def load(self):
|
||||
super().load()
|
||||
self._fixupExtruders()
|
||||
self._registerSingleExtrusionMachinesExtruderStacks()
|
||||
self._connectUpgradedExtruderStacksToMachines()
|
||||
|
||||
## Update an imported profile to match the current machine configuration.
|
||||
#
|
||||
|
@ -357,8 +360,8 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
return global_container_stack.material.getId()
|
||||
return ""
|
||||
|
||||
## Returns true if the current machien requires its own quality profiles
|
||||
# \return true if the current machien requires its own quality profiles
|
||||
## Returns true if the current machine requires its own quality profiles
|
||||
# \return true if the current machine requires its own quality profiles
|
||||
def _machineHasOwnQualities(self):
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if global_container_stack:
|
||||
|
@ -391,12 +394,59 @@ class CuraContainerRegistry(ContainerRegistry):
|
|||
|
||||
return new_stack
|
||||
|
||||
def _registerSingleExtrusionMachinesExtruderStacks(self):
|
||||
machines = ContainerRegistry.getInstance().findContainerStacks(machine_extruder_trains = {"0": "fdmextruder"})
|
||||
for machine in machines:
|
||||
self._addExtruderStackForSingleExtrusionMachine(machine, "fdmextruder")
|
||||
|
||||
def _addExtruderStackForSingleExtrusionMachine(self, machine, extruder_id):
|
||||
new_extruder_id = extruder_id
|
||||
|
||||
if machine.extruders and len(machine.extruders) > 0:
|
||||
new_extruder_id = machine.extruders["0"].getId()
|
||||
|
||||
extruder_definitions = self.findDefinitionContainers(id = new_extruder_id)
|
||||
|
||||
if not extruder_definitions:
|
||||
Logger.log("w", "Could not find definition containers for extruder %s", new_extruder_id)
|
||||
return
|
||||
|
||||
extruder_definition = extruder_definitions[0]
|
||||
unique_name = self.uniqueName(machine.getId() + " " + new_extruder_id)
|
||||
|
||||
extruder_stack = ExtruderStack.ExtruderStack(unique_name)
|
||||
extruder_stack.setName(extruder_definition.getName())
|
||||
extruder_stack.setDefinition(extruder_definition)
|
||||
extruder_stack.addMetaDataEntry("machine", machine.getId())
|
||||
extruder_stack.addMetaDataEntry("position", "0")
|
||||
extruder_stack.setNextStack(machine)
|
||||
|
||||
# if machine.userChanges:
|
||||
# # set existing user changes if found
|
||||
# extruder_stack.setUserChanges(machine.userChanges)
|
||||
# else:
|
||||
# # create empty user changes container otherwise
|
||||
# user_container = InstanceContainer(extruder_stack.getId() + "_user")
|
||||
# user_container.addMetaDataEntry("type", "user")
|
||||
# user_container.addMetaDataEntry("machine", extruder_stack.getId())
|
||||
# from cura.CuraApplication import CuraApplication
|
||||
# user_container.addMetaDataEntry("setting_version", CuraApplication.SettingVersion)
|
||||
# user_container.setDefinition(extruder_definition)
|
||||
# extruder_stack.setUserChanges(user_container)
|
||||
# self.addContainer(user_container)
|
||||
|
||||
# extruder_stack.setVariantById("default")
|
||||
# extruder_stack.setMaterialById("default")
|
||||
# extruder_stack.setQualityById("default")
|
||||
|
||||
self.addContainer(extruder_stack)
|
||||
|
||||
# Fix the extruders that were upgraded to ExtruderStack instances during addContainer.
|
||||
# The stacks are now responsible for setting the next stack on deserialize. However,
|
||||
# due to problems with loading order, some stacks may not have the proper next stack
|
||||
# set after upgrading, because the proper global stack was not yet loaded. This method
|
||||
# makes sure those extruders also get the right stack set.
|
||||
def _fixupExtruders(self):
|
||||
def _connectUpgradedExtruderStacksToMachines(self):
|
||||
extruder_stacks = self.findContainers(ExtruderStack.ExtruderStack)
|
||||
for extruder_stack in extruder_stacks:
|
||||
if extruder_stack.getNextStack():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue