mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-07 23:17:32 -06:00
Split MaterialGroup and MaterialNode
This commit is contained in:
parent
615b20aa5b
commit
c5d443109b
3 changed files with 48 additions and 22 deletions
25
cura/Machines/MaterialGroup.py
Normal file
25
cura/Machines/MaterialGroup.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
#
|
||||||
|
# A MaterialGroup represents a group of material InstanceContainers that are derived from a single material profile.
|
||||||
|
# The main InstanceContainer which has the ID of the material profile file name is called the "root_material". For
|
||||||
|
# example: "generic_abs" is the root material (ID) of "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4",
|
||||||
|
# and "generic_abs_ultimaker3" and "generic_abs_ultimaker3_AA_0.4" are derived materials of "generic_abs".
|
||||||
|
#
|
||||||
|
# Using "generic_abs" as an example, the MaterialGroup for "generic_abs" will contain the following information:
|
||||||
|
# - name: "generic_abs", root_material_id
|
||||||
|
# - root_material_node: MaterialNode of "generic_abs"
|
||||||
|
# - derived_material_node_list: A list of MaterialNodes that are derived from "generic_abs",
|
||||||
|
# so "generic_abs_ultimaker3", "generic_abs_ultimaker3_AA_0.4", etc.
|
||||||
|
#
|
||||||
|
class MaterialGroup:
|
||||||
|
__slots__ = ("name", "root_material_node", "derived_material_node_list")
|
||||||
|
|
||||||
|
def __init__(self, name: str):
|
||||||
|
self.name = name
|
||||||
|
self.root_material_node = None
|
||||||
|
self.derived_material_node_list = []
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return "%s[%s]" % (self.__class__.__name__, self.name)
|
|
@ -6,28 +6,8 @@ from PyQt5.Qt import QTimer, QObject, pyqtSignal
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Settings import ContainerRegistry
|
from UM.Settings import ContainerRegistry
|
||||||
|
|
||||||
from cura.Machines.ContainerNode import ContainerNode
|
from .MaterialNode import MaterialNode
|
||||||
|
from .MaterialGroup import MaterialGroup
|
||||||
|
|
||||||
class MaterialGroup:
|
|
||||||
__slots__ = ("name", "root_material_node", "derived_material_node_list")
|
|
||||||
|
|
||||||
def __init__(self, name: str):
|
|
||||||
self.name = name
|
|
||||||
self.root_material_node = None
|
|
||||||
self.derived_material_node_list = []
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
|
||||||
return "%s[%s]" % (self.__class__.__name__, self.name)
|
|
||||||
|
|
||||||
|
|
||||||
class MaterialNode(ContainerNode):
|
|
||||||
__slots__ = ("material_map", "children_map")
|
|
||||||
|
|
||||||
def __init__(self, metadata: Optional[dict] = None):
|
|
||||||
super().__init__(metadata = metadata)
|
|
||||||
self.material_map = {}
|
|
||||||
self.children_map = {}
|
|
||||||
|
|
||||||
|
|
||||||
class MaterialManager(QObject):
|
class MaterialManager(QObject):
|
||||||
|
|
21
cura/Machines/MaterialNode.py
Normal file
21
cura/Machines/MaterialNode.py
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from typing import Optional
|
||||||
|
|
||||||
|
from .ContainerNode import ContainerNode
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# A MaterialNode is a node in the material lookup tree/map/table. It contains 2 (extra) fields:
|
||||||
|
# - material_map: a one-to-one map of "material_root_id" to material_node.
|
||||||
|
# - children_map: the key-value map for child nodes of this node. This is used in a lookup tree.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
class MaterialNode(ContainerNode):
|
||||||
|
__slots__ = ("material_map", "children_map")
|
||||||
|
|
||||||
|
def __init__(self, metadata: Optional[dict] = None):
|
||||||
|
super().__init__(metadata = metadata)
|
||||||
|
self.material_map = {} # material_root_id -> material_node
|
||||||
|
self.children_map = {} # mapping for the child nodes
|
Loading…
Add table
Add a link
Reference in a new issue