forked from python50/GLIF
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroup.py
119 lines (90 loc) · 2.48 KB
/
group.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
"""
Licence: GPLv2
Author: Jason White
Definition of Group and Coordiate classes
"""
import copy
#Note that all coordinates are to be stored in nanometers
class vector:
def __init__(self, x, y):
self.x=x
self.y=y
def __str__(self):
return self.__repr__()
def __repr__(self):
#print the name of the class and the X/Y coordinates
#__class__._name__ is used to suppport inheritance
return """<%s, x=%d y=%d>""" % (self.__class__._name__ ,self.x, self.y)
def __add__(self, b):
return vector(self.x+b.x, self.y+b.y)
def __sub__(self, b):
return vector(self.x-b.x, self.y-b.y)
#coordinate inherits from vector
class coordinate(vector):
def __init__(self, x, y):
self.x=x
self.y=y
def __repr__(self):
return """<coordinate, x=%d y=%d>""" % (self.x, self.y)
#angle_pair inherits from vector
class angle_pair(vector):
def __repr__(self):
return """<angle_pair, x=%d y=%d>""" % (self.x, self.y)
#design rules common to all primitives
class design_rule:
def __init__(self, thickness, clearance):
self.thickness=thickness
self.clearance=clearance
class group:
def __init__(self, x, y, layer, members, angle=0, attributes={}):
#patch to fix multiple references to same object
self.members=copy.deepcopy(members)
self.location=coordinate(x, y)
self.layer=layer
self.angle=angle
self.attributes=attributes
"""
Normal member functions
"""
def move(self, x, y):
self.location.x=x
self.location.y=y
def change_layer(self, layer):
self.location.layer=layer
"""
Default functions which make this class behave like a list
"""
def __iter__(self):
for member in self.members:
yield member
def __len__(self):
return len(self.members)
def __getitem__(self, i):
return self.members[i]
def __delitem__(self, i):
del self.members[i]
def __setitem__(self, i, value):
self.members[i] = value
return self.members[i]
def __str__(self):
return self.__repr__()
def __repr__(self):
return """<group %s, x=%d y=%d, layer=%s, members=%s>""" % (id(self),self.location.x, self.location.y, str(self.layer), self.members)
def insert(self, i, value):
self.members.insert(i, value)
def append(self, value):
list_index = len(self.members)
self.insert(list_index, value)
def test_coordinate():
a=coordinate(1, 2)
b=coordinate(3, 4)
print a
print b
print a+b
print a-b
def test_groups():
a=group(1, 2, 0, [1, 2, 3])
b=group(3, 4, 0, [4, 5, 6])
print a
print b
print a[2]