mirror of
https://github.com/csirmaz/openscad-py.git
synced 2025-06-23 02:58:33 +02:00
Split code into separate class files
This commit is contained in:
parent
ffbee53da3
commit
9d24a2c85f
24 changed files with 1062 additions and 830 deletions
26
openscad_py/collection.py
Normal file
26
openscad_py/collection.py
Normal 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])
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue