-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlabels.py
More file actions
216 lines (176 loc) · 7.96 KB
/
labels.py
File metadata and controls
216 lines (176 loc) · 7.96 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
from pysvg.filter import *
from pysvg.gradient import *
from pysvg.linking import *
from pysvg.script import *
from pysvg.shape import *
from pysvg.structure import *
from pysvg.style import *
from pysvg.text import *
from pysvg.builders import *
from pysvg.parser import parse
import math
import helpers
font_family = "Inconsolata"
#for debug purposes only
debug_style = StyleBuilder()
debug_style.setStrokeWidth(1.92/2)
debug_style.setStroke('#ff0000')
debug_style.setFilling('#00ff00')
def function_label_lenght_helper(text, style, added_width, is_italic=True):
em_size = 3
margins = 3
missing_number_offset = 0
if (("fixed_width_chars" in style) and (style["fixed_width_chars"] > len(text))):
missing_number_offset = em_size * abs(style["fixed_width_chars"] - len(text)) # width of digit * number of missing digits
return ((margins * 2) + missing_number_offset + (len(text) * em_size))
def function_label(s, pos_x, pos_y, text, style, added_width, sign=1, is_italic=True, fwco=0):
#TODO: add auto width
height = 7.680 #0.08in
em_size = 3
skew_angle = 10
margins = 3
font_size = "6px" #was 0.5em before. 0.42 for linux ?
kw={}
kw['style'] = 'font-size:' + font_size + '; font-family:' + font_family + '; fill:' + style["textColor"] + '; '
if (is_italic):
kw['style'] += 'font-style:italic; '
rect_args={}
rect_args['style'] ='fill:' + style["fillColor"] + '; stroke-width:0.5; stroke:' + style["strokeColor"] + '; '
skew_error = 0
text_margin = 10
missing_number_offset = 0
if (style["isSkewed"] == True):
rect_args['transform'] = 'skewX(-' + str(skew_angle) + ')'
#get rid of the skew offet by dividing the pos_y to the cot(angle of skew)
cot = 1 / math.tan(skew_angle * math.pi / 180)
skew_error = pos_y / cot
text_margin = 9
if (fwco != 0):
missing_number_offset = em_size * abs(fwco - len(text)) #overwrite
elif (("fixed_width_chars" in style) and (style["fixed_width_chars"] > len(text))):
missing_number_offset = em_size * abs(style["fixed_width_chars"] - len(text)) # width of digit * number of missing digits
if (len(text) > 0):
t = Text(str(text), pos_x + text_margin + margins + (missing_number_offset / 2), pos_y + 7.680 , **kw)
rwidth = (margins * 2) + missing_number_offset + (len(text) * em_size)
r = Rect(pos_x + 10 + skew_error, pos_y + 2, rwidth , height, 2, 2, **rect_args)
if ("special" in style):
if (style["special"] == "hidden"):
return 0
elif (style["special"] == "dummy"):
return rwidth
elif (style["special"] == "onlyText"):
s.addElement(t)
return rwidth
s.addElement(r)
if (len(text) > 0):
s.addElement(t)
return rwidth
def pwm_indicator(x, y):
line_style = StyleBuilder()
line_style.setStrokeWidth(1.92/2) #0.02in
line_style.setStroke('#212121')
line_style.setFilling('none')
origin_x = 0#-16
origin_y = 5
pwm_path = Path('m ' + str(origin_x) + ' ' + str(origin_y) + ' c 2 0 2.5 0 3 0 c 1 0 1 -3 3 -3 c 1.5 0 3 3 3 3 c 0 0 1.5 3 3 3 c 2 0 2 -3 3 -3 c 0 0 1 0 3 0', style=line_style.getStyle())
pwm = G(**helpers.kwargs_helper([("transform", "translate(" + str(x - origin_x) + ", " + str(y - origin_y) + ")")]))
pwm.addElement(pwm_path)
return (pwm)
def pin_maker(pin_data, pin_number_in_group, number_pins_in_group, s, x_origin_offset, y_origin_offset, side, pin_group_data, styles, omit_styles, omit_categories):
height = 7.680
sign = 1 #positive = R
direction = 1 #positive = T ?
line_thickness = 1.92/2 #0.02in
line_label_group = G(**helpers.kwargs_helper([("id", helpers.lineLabelNamer(pin_data))]))
label_group = G()
line_group = G()
if("LR" in side):
pass
elif ("L" in side):
sign = -1
dot_style = StyleBuilder()
dot_style.setStrokeWidth(line_thickness)
if (("lineStyle" in pin_data) and ("stroke" in pin_data["lineStyle"])):
dot_style.setStrokeWidth(pin_data["lineStyle"]["stroke"])
dot_style.setStroke('#212121')
dot_style.setFilling('#212121')
x_offset = 20 #length of the line before the 1st pin indicator
prev_width = 0
pr = 10
for f in pin_data['functions']:
if (("categories" in f) and helpers.intersection(f["categories"], omit_categories)):
pass
elif (("style" in f) and f["style"] in omit_styles):
pass
else:
label_function_group = G(**helpers.kwargs_helper([("class", helpers.labelFunctionNamer(styles['label'][f['style']]))]))
length_label = 0
error_offset = 0
if ("LR" in side):
pass
elif ("L" in side):
length_label = function_label_lenght_helper(f['name'], styles['label'][f['style']], 0)
error_offset = 17.941 #surely due to the skew thinggy
pr = function_label(label_function_group, sign * (x_offset + prev_width + length_label + error_offset) + x_origin_offset, y_origin_offset, f['name'], styles['label'][f['style']], 0, sign)
label_group.addElement(label_function_group)
if (pr != 0): #for the hidden tag
prev_width = prev_width + pr + 3
pwm_offeset = 0
pwm_overlap = 0 #to ensure there is no gap between the line and pwm sign (only when pwmsign is needed)
group_height = 0
bigline_bottom_extention = 0 #extra length of bigline used in the bottom case (for spacing the lines vertically)
added_length = 0 #extra length of pin bigline specified in the json file
if ("length" in pin_group_data):
added_length = helpers.units_to_pixels(pin_group_data["length"]["length"], pin_group_data["length"]["units"])
added_length_dot = added_length
if ("T" in side):
bigline_bottom_extention = (number_pins_in_group - 1 - pin_number_in_group) * helpers.mm_to_pixels(2.54) #TODO: from config file
group_height = helpers.mm_to_pixels(2.54) + (number_pins_in_group - 1 - pin_number_in_group) * helpers.mm_to_pixels(2.54)
if ("B" in side):
bigline_bottom_extention = pin_number_in_group * helpers.mm_to_pixels(2.54) #TODO: from config file
group_height = helpers.mm_to_pixels(2.54) + pin_number_in_group * helpers.mm_to_pixels(2.54)
direction = -1
if (("isPWM" in pin_data) and (pin_data["isPWM"] == True)):
pwmLength = 0
if ("LR" in side):
pass
elif ("L" in side):
pwmLength = 18 #length of the path
line_group.addElement(pwm_indicator(x_origin_offset + sign * (pwmLength + 5), y_origin_offset + 5.92 - 0.08))
pwm_offeset = 18 + 5
pwm_overlap = 0.1
small_line = Line(x_origin_offset - sign * (added_length),
(height/2 + 2) + y_origin_offset,
x_origin_offset + (sign * (5 + pwm_overlap)),
(height/2 + 2) + y_origin_offset)
small_line.set_style(dot_style.getStyle())
line_group.addElement(small_line)
added_length = 0
big_line = Line(x_origin_offset + (sign * (pwm_offeset - pwm_overlap - bigline_bottom_extention - added_length)),
y_origin_offset + (height/2 + 2),
x_origin_offset + (sign * (prev_width + x_offset)),
y_origin_offset + (height/2 + 2))
big_line.set_style(dot_style.getStyle())
line_group.addElement(big_line)
if ("T" in side or "B" in side):
if ("T" in side):
print("Top")
vertical_line = Line(x_origin_offset + (sign * (pwm_offeset - pwm_overlap - bigline_bottom_extention - added_length)),
y_origin_offset + (height/2 + 2) - (line_thickness/2), #slight overlap for nice sharp corners
x_origin_offset + added_length + (sign * (pwm_offeset - pwm_overlap - bigline_bottom_extention)),
y_origin_offset + (height/2 + 2) + group_height)
elif ("B" in side):
vertical_line = Line(x_origin_offset + (sign * (pwm_offeset - pwm_overlap - bigline_bottom_extention - added_length)),
y_origin_offset + (height/2 + 2) + (line_thickness/2), #slight overlap for nice sharp corners
x_origin_offset + added_length + (sign * (pwm_offeset - pwm_overlap - bigline_bottom_extention)),
y_origin_offset + (height/2 + 2) - group_height)
vertical_line.set_style(dot_style.getStyle())
line_group.addElement(vertical_line)
c = Circle(x_origin_offset - sign * (bigline_bottom_extention + added_length_dot),
y_origin_offset + (height/2 + 2) + direction * (group_height),
1.92)
c.set_style(dot_style.getStyle())
line_group.addElement(c)
line_label_group.addElement(line_group)
line_label_group.addElement(label_group)
s.addElement(line_label_group)