mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-29 23:34:32 +08:00
WIP: Create ContainerNode and ContainerGroup
This commit is contained in:
parent
e65adc7258
commit
d99bacb2d2
@ -1,10 +1,13 @@
|
|||||||
|
from typing import Optional
|
||||||
|
|
||||||
from PyQt5.Qt import QObject
|
from PyQt5.Qt import QObject
|
||||||
|
|
||||||
from cura.Machines.ContainerNode import ContainerNode
|
from cura.Machines.ContainerNode import ContainerNode
|
||||||
|
|
||||||
|
|
||||||
class ContainerGroup(QObject):
|
class ContainerGroup(QObject):
|
||||||
|
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.node_for_global = None # type: ContainerNode
|
self.node_for_global = None # type: Optional[ContainerNode]
|
||||||
self.nodes_for_extruders = dict()
|
self.nodes_for_extruders = dict()
|
||||||
|
@ -3,25 +3,37 @@ from typing import Optional
|
|||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
from UM.Settings.InstanceContainer import InstanceContainer
|
||||||
|
|
||||||
|
|
||||||
## A metadata / container combination. Use getContainer to get the container corresponding to the metadata
|
##
|
||||||
|
# A metadata / container combination. Use getContainer() to get the container corresponding to the metadata.
|
||||||
|
#
|
||||||
|
# ContainerNode is a multi-purpose class. It has two main purposes:
|
||||||
|
# 1. It encapsulates an InstanceContainer. It contains that InstanceContainer's
|
||||||
|
# - metadata (Always)
|
||||||
|
# - container (lazy-loaded when needed)
|
||||||
|
# 2. It also serves as a node in a hierarchical InstanceContainer lookup table/tree.
|
||||||
|
# This is used in Variant, Material, and Quality Managers.
|
||||||
|
#
|
||||||
class ContainerNode:
|
class ContainerNode:
|
||||||
def __init__(self, metadata = None):
|
__slots__ = ("metadata", "container", "children_map")
|
||||||
|
|
||||||
|
def __init__(self, metadata: Optional[dict] = None):
|
||||||
self.metadata = metadata
|
self.metadata = metadata
|
||||||
self.container = None
|
self.container = None
|
||||||
self.children_map = OrderedDict()
|
self.children_map = OrderedDict()
|
||||||
|
|
||||||
def getChildNode(self, child_key: str) -> Optional["QualityNode"]:
|
def getChildNode(self, child_key: str) -> Optional["ContainerNode"]:
|
||||||
return self.children_map.get(child_key)
|
return self.children_map.get(child_key)
|
||||||
|
|
||||||
def getContainer(self) -> "InstanceContainer":
|
def getContainer(self) -> "InstanceContainer":
|
||||||
if self.metadata is None:
|
if self.metadata is None:
|
||||||
raise RuntimeError("Cannot get container for a QualityNode without metadata")
|
raise RuntimeError("Cannot get container for a ContainerNode without metadata")
|
||||||
|
|
||||||
if self.container is None:
|
if self.container is None:
|
||||||
container_id = self.metadata["id"]
|
container_id = self.metadata["id"]
|
||||||
Logger.log("d", "Lazy-loading container [%s]", container_id)
|
Logger.log("i", "Lazy-loading container [%s]", container_id)
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
from UM.Settings.ContainerRegistry import ContainerRegistry
|
||||||
container_list = ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
container_list = ContainerRegistry.getInstance().findInstanceContainers(id = container_id)
|
||||||
if not container_list:
|
if not container_list:
|
||||||
@ -30,5 +42,5 @@ class ContainerNode:
|
|||||||
|
|
||||||
return self.container
|
return self.container
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self) -> str:
|
||||||
return "ContainerNode[%s]" % self.metadata.get("id")
|
return "ContainerNode[%s]" % self.metadata.get("id")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user