Root/cvr.py

1#!/usr/bin/python
2
3import shape
4
5
6#
7# gnuplot the outline
8#
9
10def outline_gnuplot(sk, points):
11    while len(points):
12    print points.pop(0), points.pop(0)
13    print
14
15
16def gnuplot_line(x0, y0, x1, y1):
17    print x0, y0
18    print x1, y1
19    print
20
21
22#
23# make a HeeksCAD sketch of the outline
24#
25
26
27def cad_line(sk, x0, y0, x1, y1):
28    cad.line(x0, y0, x1, y1)
29    cad.add(sk, cad.getlastobj())
30
31
32def outline_cad(sk, points):
33    last_x = points.pop(0)
34    last_y = points.pop(0)
35    while len(points):
36    x = points.pop(0)
37    y = points.pop(0)
38    cad_line(sk, last_x, last_y, x, y)
39    last_x = x
40    last_y = y
41
42    cad.reorder(sk)
43    return sk
44
45
46def closed_outline(sk, *args):
47    l = list(args)
48    l.append(args[0])
49    l.append(args[1])
50    do(sk, l)
51
52
53def open_outline(sk, *args):
54    do(sk, list(args))
55
56
57def line(*args):
58    do_line(*args)
59
60 
61#
62# Make the cover sheet 2 mm larger than the counterweight on all sides. We need
63# the following exceptions to avoid mechanical interference:
64#
65# - at the power connector, keep the ymin edge flush with the counterweight
66# - follow the counterweight's J-shaped space for the reset button, with the
67# border reduced from 2 mm to 0.5 mm
68# - next to the long side of the battery, follow the counterweight's edge
69# - also follow the counterweight's bay for the battery cover's tongue and
70# make it even 0.5 mm larger, anticipating imperfect registration
71#
72# Also, as a simplification, we don't follow steps and recesses in these cases:
73#
74# - 1 mm steps on the left and right side. Just use the larger size.
75# - the whole sponge area. Just put the cover on top of the sponge.
76# - all recesses near the batter, except the one for the lid's central tongue
77#
78# The above simplifications are possible, because, being on top of the
79# counterweight, we've already cleared the obstacles these steps and recesses
80# are designed to avoid.
81#
82
83#
84# Note: to visualize the shape defined below, plot the counterweight in 2D with
85# gnuplot and follow the shape it the mouse.
86#
87# To visualize the result, do this:
88#
89# ./cw.py >cw.gnuplot
90# ./cvr.py >cvr.gnuplot
91# gnuplot
92# gnuplot> set style data lines
93# gnuplot> plot "cw.gnuplot", "cvr.gnuplot"
94#
95
96
97def outline(sk):
98    closed_outline(sk,
99      # counterweight corners: (16, 46) and (15, 60)
100      13, 46,
101      # (15, 69.5)
102      13, 71.5,
103      # (82.5, 65), (82.5, 64), (89.5, 64), (89.5, 69)
104      83, 71.5,
105      83, 64.5, 89, 64.5, 89, 71,
106      # (100, 69)
107      102, 71,
108      # (99.5, 46)
109      102, 44,
110      # (88, 46)
111      86, 44,
112      # (88, 55), (82, 50)
113      86, 50,
114      # (59.5, 55), (59.5, 56.5), (52.5, 56.5), (52.5, 55)
115      60, 50,
116      60, 57, 52, 57, 52, 50,
117      # (24, 55)
118      26, 50,
119      # (24, 46)
120      26, 46)
121
122
123def label(sk):
124    u = 2
125    x = 40
126    y = 66
127    # C
128    open_outline(sk,
129      x+u, y+2*u,
130      x, y+2*u,
131      x, y,
132      x+u, y)
133
134    x += u*1.6
135    # W
136    open_outline(sk,
137      x, y+2*u,
138      x, y,
139      x+0.5*u, y+u,
140      x+u, y,
141      x+u, y+2*u)
142
143
144# ----- Counterweight outline -------------------------------------------------
145
146
147lines = []
148
149
150def rect_outline(x0, y0, z0, x1, y1, z1):
151    global lines
152
153    lines.append((x0, y0, x0, y1))
154    lines.append((x1, y0, x1, y1))
155    lines.append((x0, y0, x1, y0))
156    lines.append((x0, y1, x1, y1))
157
158
159# ----- Main ------------------------------------------------------------------
160
161
162def main():
163    global do
164
165    if __name__ == "__main__":
166    do = outline_gnuplot
167    sk = None
168    else:
169    import HeeksPython as cad
170
171    do = outline_cad
172    cad.sketch()
173    sk = cad.getlastobj()
174
175
176    outline(sk)
177    label(sk)
178
179    shape.rect = rect_outline
180    shape.make_base()
181
182    if __name__ == "__main__":
183    for e in lines:
184        gnuplot_line(*e)
185    else:
186    for e in lines:
187        cad_line(sk, *e)
188    cad.translate(sk, -13, -44, 0)
189
190    return sk
191
192
193if __name__ == "__main__":
194    main()
195else:
196    for x in (-100, 0):
197    for y in range(0, 256, 32):
198        sk = main()
199        cad.translate(sk, x, y-150, 0)
200

Archive Download this file

Branches:
master



interactive