Split code into separate class files

This commit is contained in:
Elod Csirmaz 2024-11-30 22:11:59 +00:00
parent ffbee53da3
commit 9d24a2c85f
24 changed files with 1062 additions and 830 deletions

26
openscad_py/collection.py Normal file
View file

@ -0,0 +1,26 @@
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])