mirror of
https://github.com/csirmaz/openscad-py.git
synced 2025-06-22 10:43:28 +02:00
Documentation
This commit is contained in:
parent
9d24a2c85f
commit
bb7155a5fd
25 changed files with 88 additions and 21 deletions
|
@ -29,6 +29,7 @@ class Circle(Object):
|
|||
return cls(r=r, fn=sides)
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
fnstr = '' if self.fn is None else f", $fn={self.fn}"
|
||||
return f"circle(r={self.r}{fnstr});"
|
||||
|
||||
|
|
|
@ -22,5 +22,6 @@ class Collection(Object):
|
|||
return self.__class__(self.collection + [obj])
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return "\n".join([o.render() for o in self.collection])
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ class Color(Object):
|
|||
self.child = child
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"color(c=[{','.join([str(c) for c in self.color])}]){{ {self.child.render()} }}"
|
||||
|
||||
|
||||
|
|
|
@ -20,5 +20,6 @@ class Cube(Object):
|
|||
self.center = center
|
||||
|
||||
def render(self):
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"cube(size={self.size.render()}, center={self._center()});"
|
||||
|
||||
|
|
|
@ -22,6 +22,7 @@ class Cylinder(Object):
|
|||
# $fa, $fs, $fn
|
||||
|
||||
def render(self):
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"cylinder(h={self.height}, r1={self.r1}, r2={self.r2}, center={self._center()});"
|
||||
|
||||
@classmethod
|
||||
|
|
|
@ -19,5 +19,6 @@ class DeltaOffset(Object):
|
|||
self.chamfer = chamfer
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"offset(delta={delta}, chamfer={'true' if self.chamfer else 'false'}){{\n{self.child.render()}\n}}"
|
||||
|
||||
|
|
|
@ -15,5 +15,6 @@ class Difference(Object):
|
|||
self.tool = Collection.c(tool) # what to remove
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"difference(){{ {self.subject.render()}\n{self.tool.render()} }}"
|
||||
|
||||
|
|
|
@ -8,11 +8,12 @@ class Header:
|
|||
|
||||
|
||||
def __init__(self, quality: str = 'draft'):
|
||||
# See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Circle_resolution:_$fa,_$fs,_and_$fn
|
||||
self.quality = quality
|
||||
|
||||
|
||||
def render(self):
|
||||
# See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Other_Language_Features#Circle_resolution:_$fa,_$fs,_and_$fn
|
||||
"""Return OpenSCAD code"""
|
||||
if self.quality == 'draft':
|
||||
return ""
|
||||
if self.quality == 'mid':
|
||||
|
|
|
@ -14,6 +14,7 @@ class Intersection(Object):
|
|||
self.child = Collection.c(child)
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"intersection(){{ {self.child.render()} }}"
|
||||
|
||||
|
||||
|
|
|
@ -20,6 +20,7 @@ class LinearExtrude(Object):
|
|||
# twist, slices, scale (float/vector), $fn
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"linear_extrude(height={self.height}, center={self._center()}, convexity={self.convexity}){{\n{self.child.render()}\n}}"
|
||||
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ class Object:
|
|||
return Collection([self, obj])
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
raise Exception("abstract method")
|
||||
|
||||
def translate(self, v: TUnion[list, Point]) -> 'Object':
|
||||
|
|
|
@ -119,6 +119,7 @@ class PathTube(Object):
|
|||
return Polyhedron.tube(points=points_rows, convexity=self.convexity, make_torus=self.make_torus)
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return self.process().render()
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ class Point:
|
|||
return Point(coords)
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the point into a SCAD script"""
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return "[" + (",".join([str(c) for c in self.c])) + "]"
|
||||
|
||||
def render_stl(self) -> str:
|
||||
|
|
|
@ -16,5 +16,6 @@ class Polygon(Object):
|
|||
self.convexity = convexity
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"polygon(points=[{','.join([p.render() for p in self.points])}], convexity={self.convexity});"
|
||||
|
||||
|
|
|
@ -176,6 +176,7 @@ class Polyhedron(Object):
|
|||
return cls(points=point_list, faces=faces, convexity=convexity)
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
faces_list = [f"[{','.join([str(x) for x in face])}]" for face in self.faces]
|
||||
return f"polyhedron(points=[{','.join([p.render() for p in self.points])}], faces=[{','.join(faces_list)}], convexity={self.convexity});"
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ class RadialOffset(Object):
|
|||
# $fa, $fs, and $fn
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"offset(r={self.r}){{\n{self.child.render()}\n}}"
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ class Rotate(Object):
|
|||
self.child = child
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"rotate(a={self.a}, v={self.v.render()}){{\n{self.child.render()}\n}}"
|
||||
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ class RotateExtrude(Object):
|
|||
# $fa, $fs, $fn
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"rotate_extrude(angle={self.angle}, convexity={self.convexity}) {{\n{self.child.render()}\n}}"
|
||||
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ class Scale(Object):
|
|||
self.child = child
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"scale(v={self.v.render()}){{\n{self.child.render()}\n}}"
|
||||
|
||||
|
||||
|
|
|
@ -14,13 +14,12 @@ class Sphere(Object):
|
|||
See https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/The_OpenSCAD_Language#sphere
|
||||
"""
|
||||
|
||||
|
||||
def __init__(self, r):
|
||||
self.r = r
|
||||
# $fa, $fs, $fn
|
||||
|
||||
|
||||
def render(self):
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"sphere(r={self.r});"
|
||||
|
||||
|
||||
|
|
|
@ -15,5 +15,6 @@ class Translate(Object):
|
|||
self.child = child
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"translate(v={self.v.render()}){{\n{self.child.render()}\n}}"
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ class Union(Object):
|
|||
self.child = Collection.c(child)
|
||||
|
||||
def render(self) -> str:
|
||||
"""Render the object into OpenSCAD code"""
|
||||
return f"union(){{ {self.child.render()} }}"
|
||||
|
||||
def union(self, objects: TUnion[list, Object]) -> Object:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue