Skip to content
Snippets Groups Projects
Commit c2e3051e authored by Hock, Benedikt's avatar Hock, Benedikt
Browse files

add ability to add lists of components and assemblies

parent ac2c2d23
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,6 @@ import copy
# - Erlaube Clone bei Assembly (jedes child muss durch durch Klon ersetzt werden)
# - Änderungen an Beispiel umsetzen
# - Erlaube Listen bei add_component und add_assembly (-> Nä Semester)
# - Gute String Darstellung -> Ist so schon ok bisher? -> Nä Semester
# - Export als GraphViz -> Nä Semeseter
......@@ -87,12 +86,18 @@ class LegoAssembly:
self.components: List[LegoComponent] = []
self.assemblies: List[LegoAssembly] = []
def add_component(self, component: LegoComponent) -> None:
def add_component(self, component: LegoComponent | List[LegoComponent]) -> None:
if isinstance(component, list):
for c in component:
self.add_component(c)
return
if not isinstance(component, LegoComponent):
raise TypeError(
f"Argument should be of type {LegoComponent.__name__}, "
f"got {type(component).__name__} instead."
)
if self.get_root_assembly().contains_uuid(component.uuid):
raise AssertionError(
f"This assembly or a subassembly already contains the component with ID "
......@@ -101,12 +106,18 @@ class LegoAssembly:
component.parent = self
self.components.append(component)
def add_assembly(self, assembly: LegoAssembly) -> None:
def add_assembly(self, assembly: LegoAssembly | List[LegoAssembly]) -> None:
if isinstance(assembly, list):
for a in assembly:
self.add_assembly(a)
return
if not isinstance(assembly, LegoAssembly):
raise TypeError(
f"Argument should be of type {LegoAssembly.__name__}, "
f"got {type(assembly).__name__} instead."
)
if self.get_root_assembly().contains_uuid(assembly.uuid):
raise AssertionError(
f"This assembly or a subassembly already contains the assembly with ID "
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment