mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-15 10:47:49 -06:00
Cleanup extruder manager
Few more unused functions removed & simplified. It also fixes a few more typing issues that I encountered.
This commit is contained in:
parent
e6d0a9cc6a
commit
5c6c299b27
3 changed files with 14 additions and 30 deletions
|
@ -20,6 +20,7 @@ from typing import Optional, TYPE_CHECKING, Dict, List, Any
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from cura.Settings.ExtruderStack import ExtruderStack
|
from cura.Settings.ExtruderStack import ExtruderStack
|
||||||
from cura.Settings.GlobalStack import GlobalStack
|
from cura.Settings.GlobalStack import GlobalStack
|
||||||
|
from UM.Scene.SceneNode import SceneNode
|
||||||
|
|
||||||
|
|
||||||
## Manages all existing extruder stacks.
|
## Manages all existing extruder stacks.
|
||||||
|
@ -38,7 +39,7 @@ class ExtruderManager(QObject):
|
||||||
self._application = cura.CuraApplication.CuraApplication.getInstance()
|
self._application = cura.CuraApplication.CuraApplication.getInstance()
|
||||||
|
|
||||||
# Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders.
|
# Per machine, a dictionary of extruder container stack IDs. Only for separately defined extruders.
|
||||||
self._extruder_trains = {} # type: Dict[str, List[ExtruderStack]]
|
self._extruder_trains = {} # type: Dict[str, Dict[str, ExtruderStack]]
|
||||||
self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack
|
self._active_extruder_index = -1 # Indicates the index of the active extruder stack. -1 means no active extruder stack
|
||||||
self._selected_object_extruders = [] # type: List[ExtruderStack]
|
self._selected_object_extruders = [] # type: List[ExtruderStack]
|
||||||
self._addCurrentMachineExtruders()
|
self._addCurrentMachineExtruders()
|
||||||
|
@ -119,7 +120,7 @@ class ExtruderManager(QObject):
|
||||||
object_extruders = set()
|
object_extruders = set()
|
||||||
|
|
||||||
# First, build a list of the actual selected objects (including children of groups, excluding group nodes)
|
# First, build a list of the actual selected objects (including children of groups, excluding group nodes)
|
||||||
selected_nodes = []
|
selected_nodes = [] # type: List["SceneNode"]
|
||||||
for node in Selection.getAllSelectedObjects():
|
for node in Selection.getAllSelectedObjects():
|
||||||
if node.callDecoration("isGroup"):
|
if node.callDecoration("isGroup"):
|
||||||
for grouped_node in BreadthFirstIterator(node): #type: ignore #Ignore type error because iter() should get called automatically by Python syntax.
|
for grouped_node in BreadthFirstIterator(node): #type: ignore #Ignore type error because iter() should get called automatically by Python syntax.
|
||||||
|
@ -131,14 +132,13 @@ class ExtruderManager(QObject):
|
||||||
selected_nodes.append(node)
|
selected_nodes.append(node)
|
||||||
|
|
||||||
# Then, figure out which nodes are used by those selected nodes.
|
# Then, figure out which nodes are used by those selected nodes.
|
||||||
global_stack = self._application.getGlobalContainerStack()
|
current_extruder_trains = self.getActiveExtruderStacks()
|
||||||
current_extruder_trains = self._extruder_trains.get(global_stack.getId())
|
|
||||||
for node in selected_nodes:
|
for node in selected_nodes:
|
||||||
extruder = node.callDecoration("getActiveExtruder")
|
extruder = node.callDecoration("getActiveExtruder")
|
||||||
if extruder:
|
if extruder:
|
||||||
object_extruders.add(extruder)
|
object_extruders.add(extruder)
|
||||||
elif current_extruder_trains:
|
elif current_extruder_trains:
|
||||||
object_extruders.add(current_extruder_trains["0"].getId())
|
object_extruders.add(current_extruder_trains[0].getId())
|
||||||
|
|
||||||
self._selected_object_extruders = list(object_extruders)
|
self._selected_object_extruders = list(object_extruders)
|
||||||
|
|
||||||
|
@ -154,14 +154,7 @@ class ExtruderManager(QObject):
|
||||||
|
|
||||||
@pyqtSlot(result = QObject)
|
@pyqtSlot(result = QObject)
|
||||||
def getActiveExtruderStack(self) -> Optional["ExtruderStack"]:
|
def getActiveExtruderStack(self) -> Optional["ExtruderStack"]:
|
||||||
global_container_stack = self._application.getGlobalContainerStack()
|
return self.getExtruderStack(self._active_extruder_index)
|
||||||
|
|
||||||
if global_container_stack:
|
|
||||||
if global_container_stack.getId() in self._extruder_trains:
|
|
||||||
if str(self._active_extruder_index) in self._extruder_trains[global_container_stack.getId()]:
|
|
||||||
return self._extruder_trains[global_container_stack.getId()][str(self._active_extruder_index)]
|
|
||||||
|
|
||||||
return None
|
|
||||||
|
|
||||||
## Get an extruder stack by index
|
## Get an extruder stack by index
|
||||||
def getExtruderStack(self, index) -> Optional["ExtruderStack"]:
|
def getExtruderStack(self, index) -> Optional["ExtruderStack"]:
|
||||||
|
@ -172,15 +165,6 @@ class ExtruderManager(QObject):
|
||||||
return self._extruder_trains[global_container_stack.getId()][str(index)]
|
return self._extruder_trains[global_container_stack.getId()][str(index)]
|
||||||
return None
|
return None
|
||||||
|
|
||||||
## Get all extruder stacks
|
|
||||||
def getExtruderStacks(self) -> List["ExtruderStack"]:
|
|
||||||
result = []
|
|
||||||
for i in range(self.extruderCount):
|
|
||||||
stack = self.getExtruderStack(i)
|
|
||||||
if stack:
|
|
||||||
result.append(stack)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def registerExtruder(self, extruder_train: "ExtruderStack", machine_id: str) -> None:
|
def registerExtruder(self, extruder_train: "ExtruderStack", machine_id: str) -> None:
|
||||||
changed = False
|
changed = False
|
||||||
|
|
||||||
|
@ -207,13 +191,13 @@ class ExtruderManager(QObject):
|
||||||
# \return \type{List} the list of results
|
# \return \type{List} the list of results
|
||||||
def getAllExtruderSettings(self, setting_key: str, prop: str) -> List:
|
def getAllExtruderSettings(self, setting_key: str, prop: str) -> List:
|
||||||
result = []
|
result = []
|
||||||
for index in self.extruderIds:
|
|
||||||
extruder_stack_id = self.extruderIds[str(index)]
|
for extruder_stack in self.getActiveExtruderStacks():
|
||||||
extruder_stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
|
|
||||||
result.append(extruder_stack.getProperty(setting_key, prop))
|
result.append(extruder_stack.getProperty(setting_key, prop))
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def extruderValueWithDefault(self, value):
|
def extruderValueWithDefault(self, value: str) -> str:
|
||||||
machine_manager = self._application.getMachineManager()
|
machine_manager = self._application.getMachineManager()
|
||||||
if value == "-1":
|
if value == "-1":
|
||||||
return machine_manager.defaultExtruderPosition
|
return machine_manager.defaultExtruderPosition
|
||||||
|
@ -392,7 +376,7 @@ class ExtruderManager(QObject):
|
||||||
# \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list.
|
# \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list.
|
||||||
# If no extruder has the value, the list will contain the global value.
|
# If no extruder has the value, the list will contain the global value.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getExtruderValues(key) -> List:
|
def getExtruderValues(key: str) -> List[Any]:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
|
@ -427,7 +411,7 @@ class ExtruderManager(QObject):
|
||||||
# \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list.
|
# \return A list of values for all extruders. If an extruder does not have a value, it will not be in the list.
|
||||||
# If no extruder has the value, the list will contain the global value.
|
# If no extruder has the value, the list will contain the global value.
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def getDefaultExtruderValues(key) -> List:
|
def getDefaultExtruderValues(key: str) -> List[Any]:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
context = PropertyEvaluationContext(global_stack)
|
context = PropertyEvaluationContext(global_stack)
|
||||||
context.context["evaluate_from_container_index"] = 1 # skip the user settings container
|
context.context["evaluate_from_container_index"] = 1 # skip the user settings container
|
||||||
|
|
|
@ -134,7 +134,7 @@ class ExtrudersModel(UM.Qt.ListModel.ListModel):
|
||||||
# Link to new extruders
|
# Link to new extruders
|
||||||
self._active_machine_extruders = []
|
self._active_machine_extruders = []
|
||||||
extruder_manager = Application.getInstance().getExtruderManager()
|
extruder_manager = Application.getInstance().getExtruderManager()
|
||||||
for extruder in extruder_manager.getExtruderStacks():
|
for extruder in extruder_manager.getActiveExtruderStacks():
|
||||||
if extruder is None: #This extruder wasn't loaded yet. This happens asynchronously while this model is constructed from QML.
|
if extruder is None: #This extruder wasn't loaded yet. This happens asynchronously while this model is constructed from QML.
|
||||||
continue
|
continue
|
||||||
extruder.containersChanged.connect(self._onExtruderStackContainersChanged)
|
extruder.containersChanged.connect(self._onExtruderStackContainersChanged)
|
||||||
|
|
|
@ -275,7 +275,7 @@ class FlavorParser:
|
||||||
## For showing correct x, y offsets for each extruder
|
## For showing correct x, y offsets for each extruder
|
||||||
def _extruderOffsets(self) -> Dict[int, List[float]]:
|
def _extruderOffsets(self) -> Dict[int, List[float]]:
|
||||||
result = {}
|
result = {}
|
||||||
for extruder in ExtruderManager.getInstance().getExtruderStacks():
|
for extruder in ExtruderManager.getInstance().getActiveExtruderStacks():
|
||||||
result[int(extruder.getMetaData().get("position", "0"))] = [
|
result[int(extruder.getMetaData().get("position", "0"))] = [
|
||||||
extruder.getProperty("machine_nozzle_offset_x", "value"),
|
extruder.getProperty("machine_nozzle_offset_x", "value"),
|
||||||
extruder.getProperty("machine_nozzle_offset_y", "value")]
|
extruder.getProperty("machine_nozzle_offset_y", "value")]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue