mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-12 07:48:59 +08:00
Remove extruder creation logic from manager
This logic is now in cura/Extruder.py. Contributes to issues CURA-1278 and CURA-351.
This commit is contained in:
parent
48eb8de9a1
commit
377fed206c
@ -3,6 +3,7 @@
|
||||
|
||||
import re
|
||||
|
||||
from cura.Extruder import Extruder #The individual extruders managed by this manager.
|
||||
from UM.Application import Application #To get the global container stack to find the current machine.
|
||||
from UM.Logger import Logger
|
||||
from UM.Settings.ContainerStack import ContainerStack #To create container stacks for each extruder.
|
||||
@ -26,72 +27,21 @@ class ExtruderManager:
|
||||
## (Re)loads all extruders of the currently active machine.
|
||||
#
|
||||
# This looks at the global container stack to see which machine is active.
|
||||
# Then it loads the extruder definitions for that machine and the variants
|
||||
# of those definitions. Then it puts the new extruder definitions in the
|
||||
# appropriate place in the container stacks.
|
||||
# Then it loads the extruders for that machine and loads each of them in a
|
||||
# list of extruders.
|
||||
def _reloadExtruders(self):
|
||||
self._extruderDefinitions = []
|
||||
self._nozzles = {}
|
||||
self._extruderTrains = []
|
||||
self._extruders = []
|
||||
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
||||
if not global_container_stack: #No machine has been added yet.
|
||||
return #Then leave them empty!
|
||||
|
||||
#Fill the list of extruder trains.
|
||||
#Get the extruder definitions belonging to the current machine.
|
||||
machine = global_container_stack.getBottom()
|
||||
extruder_train_ids = machine.getMetaData("machine_extruder_trains")
|
||||
for extruder_train_id in extruder_train_ids:
|
||||
extruders = ContainerRegistry.getInstance().findDefinitionContainers(id = extruder_train_id) #Should be only 1 definition if IDs are unique, but add the whole list anyway.
|
||||
if not extruders: #Empty list or error.
|
||||
extruder_definitions = ContainerRegistry.getInstance().findDefinitionContainers(id = extruder_train_id) #Should be only 1 definition if IDs are unique, but add the whole list anyway.
|
||||
if not extruder_definitions: #Empty list or error.
|
||||
Logger.log("w", "Machine definition %s refers to an extruder train \"%s\", but no such extruder was found.", machine.getId(), extruder_train_id)
|
||||
continue
|
||||
self._extruderDefinitions += extruders
|
||||
|
||||
#Fill the nozzles for each of the extruder trains.
|
||||
for extruder in self._extruderDefinitions:
|
||||
self._nozzles[extruder.id] = []
|
||||
all_nozzles = ContainerRegistry.getInstance().findInstanceContainers(type="nozzle")
|
||||
for nozzle in all_nozzles:
|
||||
extruders = nozzle.getMetaDataEntry("definitions").split(",").strip()
|
||||
for extruder_id in extruders:
|
||||
self._nozzles[extruder_id] = nozzle
|
||||
|
||||
#Create the extruder train container stacks.
|
||||
for extruder in self._extruderDefinitions:
|
||||
self._extruderTrains.append(self._createContainerStack(extruder))
|
||||
|
||||
## Creates a container stack for the specified extruder.
|
||||
#
|
||||
# This fills in the specified extruder as base definition, then a nozzle
|
||||
# that fits in that extruder train, then a material that fits through that
|
||||
# nozzle, then a quality profile that can be used with that material, and
|
||||
# finally an empty user profile.
|
||||
#
|
||||
# \param extruder The extruder to create the container stack for.
|
||||
# \return A container stack with the specified extruder as base.
|
||||
def _createContainerStack(self, extruder):
|
||||
container_stack = ContainerStack(self._uniqueName(extruder))
|
||||
#TODO: Fill the container stack.
|
||||
return container_stack
|
||||
|
||||
## Finds a unique name for an extruder stack.
|
||||
#
|
||||
# \param extruder Extruder to design a name for.
|
||||
# \return A name for an extruder stack that is unique and reasonably
|
||||
# human-readable.
|
||||
def _uniqueName(self, extruder):
|
||||
container_registry = ContainerRegistry.getInstance()
|
||||
|
||||
name = extruder.getName().strip()
|
||||
num_check = re.compile("(.*?)\s*#\d$").match(name)
|
||||
if(num_check): #There is a number in the name.
|
||||
name = num_check.group(1) #Filter out the number.
|
||||
if name == "": #Wait, that deleted everything!
|
||||
name = "Extruder"
|
||||
unique_name = name
|
||||
|
||||
i = 1
|
||||
while(container_registry.findContainers(id = unique_name) or container_registry.findContainers(name = unique_name)): #A container already has this name.
|
||||
i += 1 #Try next numbering.
|
||||
unique_name = "%s #%d" % (name, i) #Fill name like this: "Extruder #2".
|
||||
return unique_name
|
||||
for extruder_definition in extruder_definitions:
|
||||
self._extruders.append(Extruder(extruder_definition))
|
Loading…
x
Reference in New Issue
Block a user