pygds/pygds/elements.py

117 lines
2.9 KiB
Python

from enum import Enum
class Transformation(object):
def __init__(self):
self.mirror_x = 0
self.absolute_rotation = 0
self.absolute_magnification = 0
self.zoom = 1
self.rotation = 0
class Element(object):
def __init__(self):
self.elflags = 0
self.plex = 0
class Drawable(object):
def __init__(self):
self.layer = 0
self.datatype = 0
class Boundary(Element, Drawable):
def __init__(self):
self.points = []
class Path(Element, Drawable):
class Styles(Enum):
SQUARE_ENDS = 0
ROUNDED_ENDS = 1
OFFSET_ENDS = 2
CUSTOM_END = 4
def __init__(self):
self.extendEnd = [0,0] # extend past start and end
self.width = 0
self.pathStyle = Path.Styles.SQUARE_ENDS
self.points = []
class Text(Element, Drawable):
class VJust(Enum):
Top = 0
Middle = 1
Bottom = 2
class HJust(Enum):
Left = 0
Center = 1
Right = 2
def __init__(self):
# text info
self.string = ""
self.position = (0,0)
# presentation
self.fontnumber = 0
self.verticalJustification = Text.VJust.Top
self.horizontalJustification = Text.HJust.Left
# optional path info
self.pathStype = Path.Styles.SQUARE_ENDS
self.pathWidth = 0
self.transformation = Transformation()
class Box(Element, Drawable):
def __init__(self):
self.points = []
class SRef(Element):
"""
A Structure Reference defines a single instance of a different structure in
the structure we call parent here
"""
def __init__(self):
self.position = (0,0)
self.structure = ""
self.transformation = Transformation()
self.parent = None
class ARef(SRef):
"""
An Array Reference is similar to the SRef, but it defines the instances in a grid
with size instances spaces evenly between the bound coordinates
with:
v1 = bounds[0] - position
v2 = bounds[1] - position
i = xth instance index
j = yth instance index
this will result in an array like this:
j\i | 0 | 1 | ... | size[0]
----+-----------------+---------------------------+-----+--------------------
0 | (position) | (position + v1) | ... | (bounds[0])
1 | (position + v2) | (position + v1*i + v2*j) | ... | (bounds[0] + v2)
... | ... | ... | ... | ...
size[1] | (bounds[2]) | (bounds[2] + v1) | ... | (bounds[0] + bounds[1])
"""
def __init__(self):
super(ARef, self).__init__()
# positions of last instance in X and Y direction
self.bounds = [(0,0), (0,0)]
# number of instances in X and Y direction
self.size = (0,0)