diff --git a/chiplotle/__init__.py b/chiplotle/__init__.py index 34e5919..cf243a9 100644 --- a/chiplotle/__init__.py +++ b/chiplotle/__init__.py @@ -23,7 +23,7 @@ from chiplotle.hpgl.commands import * from chiplotle.hpgl.pen import Pen -from chiplotle.hpgl.decorators import * +#from chiplotle.hpgl.decorators import * #from chiplotle.hpgl.compound import * #from chiplotle.hpgl.compound.decorators import * diff --git a/chiplotle/core/interfaces/decoratable.py b/chiplotle/core/interfaces/decoratable.py deleted file mode 100644 index c99148e..0000000 --- a/chiplotle/core/interfaces/decoratable.py +++ /dev/null @@ -1,40 +0,0 @@ -#from chiplotle.geometry.core.hpglformatvisitor import HPGLFormatVisitor -# -#class Decoratable(object): -# -# def __init__(self): -# self.format_decorators = [ ] -# -# @property -# def _prefix_commands(self): -# result = [ ] -# for deco in self.format_decorators: -# result += deco.preformat_commands -# return result -# -# -# @property -# def _infix_commands(self): -# raise NotImplementedError -# -# @property -# def _suffix_commands(self): -# result = [ ] -# for deco in reversed(self.format_decorators): -# result += deco.postformat_commands -# return result -# -# @property -# def _subcommands(self): -# '''Returns a list of language-specific commands representing self.''' -# result = \ -# self._prefix_commands + \ -# self._infix_commands + \ -# self._suffix_commands -# return result -# -# -# @property -# def format(self): -# '''Returns a language-specific string representation of self.''' -# return ''.join([c.format for c in self._subcommands]) diff --git a/chiplotle/core/interfaces/formatdecorator.py b/chiplotle/core/interfaces/formatdecorator.py index f6e818d..720a1f7 100644 --- a/chiplotle/core/interfaces/formatdecorator.py +++ b/chiplotle/core/interfaces/formatdecorator.py @@ -1,11 +1,8 @@ from chiplotle.geometry.core.shape import _Shape class FormatDecorator(object): - '''FormatDecorators know how to wrap Decoratable objects with additional + '''FormatDecorators know how to wrap Shape objects with additional formatting stuff. - - - `sticky` = False reverts the formatting to a previous state or - some default. ''' @property diff --git a/chiplotle/geometry/shapes/annotation.py b/chiplotle/geometry/shapes/annotation.py index 78c67c6..53ccc99 100644 --- a/chiplotle/geometry/shapes/annotation.py +++ b/chiplotle/geometry/shapes/annotation.py @@ -5,8 +5,6 @@ from chiplotle.geometry.core.group import Group from chiplotle.geometry.core.label import Label from chiplotle.geometry.core.coordinate import Coordinate -from chiplotle.hpgl.pen import Pen -from chiplotle.hpgl.decorators import PenDecorator ## TODO should this be a decorator carried around by the shape? @@ -31,11 +29,10 @@ def annotation(shape): class _Annotation(object): - def __init__(self, shape, charwidth = 0.05, charheight = 0.1, pen = 6): + def __init__(self, shape, charwidth = 0.05, charheight = 0.1): self.shape = shape self.charwidth = charwidth self.charheight = charheight - self.pen = pen def _annotate_structure(self): @@ -54,7 +51,6 @@ def _annotate_properties(self): fields = '\n\r'.join([cr, cd, mn, mx, ws, hs, ]) label = Label(fields, self.charwidth, self.charheight) - PenDecorator(Pen(self.pen))(label) offset(label, self.shape.bottom_left) return label @@ -67,7 +63,6 @@ def _annotate_center(self): c = circle(20) cr = cross(50, 50) mark = Group([c, cr, label]) - PenDecorator(Pen(self.pen))(mark) offset(label, coord) offset(c, coord) @@ -84,7 +79,6 @@ def _annotate_centroid(self): r = rectangle(20, 20) cr = cross(50, 50) mark = Group([r, cr, label]) - PenDecorator(Pen(self.pen))(mark) offset(label, coord) offset(r, coord) @@ -106,6 +100,7 @@ def annotation(self): ## demo if __name__ == '__main__': from chiplotle import * + from chiplotle.hpgl.decorators import Pen from random import randint coords = [(randint(0, 4000), randint(0, 4000)) for i in range(20)] p = bezier_path(coords, 1) @@ -113,8 +108,9 @@ def annotation(self): offset(r, (-2000, 1000)) g1 = Group([r, p]) an = annotation(g1) + Pen(2)(an) g2 = Group([g1, an]) - PenDecorator(Pen(1))(g2) + Pen(1)(g2) io.view(g2) diff --git a/chiplotle/hpgl/decorators/__init__.py b/chiplotle/hpgl/decorators/__init__.py index fe611c2..d8f4625 100644 --- a/chiplotle/hpgl/decorators/__init__.py +++ b/chiplotle/hpgl/decorators/__init__.py @@ -1,3 +1,3 @@ -from .pen import PenDecorator -from .linetype import LineTypeDecorator -from .filltype import FillTypeDecorator +from .pen import Pen +from .linetype import LineType +from .filltype import FillType diff --git a/chiplotle/hpgl/decorators/filltype.py b/chiplotle/hpgl/decorators/filltype.py index 67c2ef5..2512431 100644 --- a/chiplotle/hpgl/decorators/filltype.py +++ b/chiplotle/hpgl/decorators/filltype.py @@ -1,14 +1,18 @@ from chiplotle.hpgl.commands import FT from chiplotle.core.interfaces.formatdecorator import FormatDecorator -class FillTypeDecorator(FormatDecorator): + +class FillType(FormatDecorator): - def __init__(self, filltype): + __doc__ = FT.__doc__ + + def __init__(self, filltype=None, space=None, angle=None): FormatDecorator.__init__(self) - if not isinstance(filltype, FT): - raise TypeError self.filltype = filltype + self.space = space + self.angle = angle + @property def _subcommands(self): - return [self.filltype] + return [FT(self.filltype, self.space, self.angle)] diff --git a/chiplotle/hpgl/decorators/linetype.py b/chiplotle/hpgl/decorators/linetype.py index ab2da49..ccd6216 100644 --- a/chiplotle/hpgl/decorators/linetype.py +++ b/chiplotle/hpgl/decorators/linetype.py @@ -1,17 +1,18 @@ from chiplotle.hpgl.commands import LT from chiplotle.core.interfaces.formatdecorator import FormatDecorator -class LineTypeDecorator(FormatDecorator): +class LineType(FormatDecorator): - def __init__(self, linetype): + __doc__ = LT.__doc__ + + def __init__(self, linetype=None, length=4): FormatDecorator.__init__(self) - if not isinstance(linetype, LT): - raise TypeError - self.linetype = linetype + self.linetype = linetype + self.length = length @property def _subcommands(self): - return [self.linetype] + return [LT(self.linetype, self.length)] @@ -23,10 +24,10 @@ def _subcommands(self): r1 = rectangle(1000, 200) r2 = rectangle(300, 800) - ltd = LineTypeDecorator(LT(2, .5)) + ltd = LineType(2, .5) ltd(r1) g = Group([r1, r2]) - ltd = LineTypeDecorator(LT(3, .1)) + ltd = LineType(3, .1) ltd(g) print g.format io.view(g) diff --git a/chiplotle/hpgl/decorators/pen.py b/chiplotle/hpgl/decorators/pen.py index 9c6aaa9..b732be6 100644 --- a/chiplotle/hpgl/decorators/pen.py +++ b/chiplotle/hpgl/decorators/pen.py @@ -1,24 +1,35 @@ -from chiplotle.hpgl.pen import Pen +from chiplotle.hpgl.pen import Pen as HPGLPen from chiplotle.core.interfaces.formatdecorator import FormatDecorator -class PenDecorator(FormatDecorator): - '''The PenDecorator wraps HPGL Pen properties around a given Shape. +class Pen(FormatDecorator): + '''The Pen wraps HPGL Pen properties around a given Shape. - `pen` is the pen number to use. - `sticky` boolean; set to False to set plotter back to default values at the end of the decorated shape. Set to True to skip reset. ''' - def __init__(self, pen): - if not isinstance(pen, Pen): - raise TypeError + def __init__(self, + number, + velocity = None, + force = None, + acceleration= None, + thickness = None): FormatDecorator.__init__(self) - self.pen = pen + self.number = number + self.velocity = velocity + self.force = force + self.acceleration = acceleration + self.thickness = thickness @property def _subcommands(self): - return self.pen._subcommands - #return [self.pen] + p = HPGLPen(self.number, + self.velocity, + self.force, + self.acceleration, + self.thickness) + return [p] @@ -26,8 +37,7 @@ def _subcommands(self): if __name__ == '__main__': from chiplotle.geometry.shapes.rectangle import rectangle - p = Pen(2, 3, 4, 5, 0.1) - pd = PenDecorator(p) + pd = Pen(2, 3, 4, 5, 0.1) r = rectangle(100, 20) pd(r) print r.format