mirror of
https://github.com/csirmaz/openscad-py.git
synced 2025-06-21 10:25:41 +02:00
26 lines
645 B
Python
26 lines
645 B
Python
|
|
from typing import Union as TUnion
|
|
from typing import List
|
|
|
|
from openscad_py.object_ import Object
|
|
|
|
|
|
class Collection(Object):
|
|
"""Represents a collection of objects"""
|
|
|
|
def __init__(self, coll: list):
|
|
self.collection = coll
|
|
|
|
@classmethod
|
|
def c(cls, coll: TUnion[list, Object]) -> Object:
|
|
"""Ensure the list of objects is a Collection (idempotent)"""
|
|
if isinstance(coll, Object):
|
|
return coll
|
|
return cls(coll)
|
|
|
|
def _add(self, obj):
|
|
return self.__class__(self.collection + [obj])
|
|
|
|
def render(self) -> str:
|
|
return "\n".join([o.render() for o in self.collection])
|
|
|