summaryrefslogtreecommitdiffstats
path: root/case/top.scad
blob: fd8527e60517297b80a0c699e55046ef38974616 (plain)
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
$fn = 72;

include <support.scad>
include <keyboard.scad>
include <logo.scad>

module top_case(with_keyboard=false, as_flat=false) {
    eps = 0.01;

    accent_width    = 1.0000;
    accent_depth    = 0.5;
    accent_y_stride = (keyboard_pcb_length - accent_width) / 5.0;
    accent_y_bottom = keyboard_y_offset;

    vent_width    =  2.0000;
    vent_length   = wall_width;
    vent_height   = 12.0000;
    vent_count    = 33;
    vent_x_first  = keyboard_x_offset + keyboard_pcb_width - vent_count * 2*vent_width;
    vent_y_offset = case_length_bottom - vent_length;

    screw_post_lower_y_offset  = (keyboard_y_offset - 2 * wall_width) / 2 + wall_width;
    screw_post_middle_y_offset = screw_post_lower_y_offset  + 65.00;
    screw_post_upper_y_offset  = screw_post_middle_y_offset + 65.00;
    screw_post_x_offset        = (keyboard_x_offset - 2 * wall_width) / 2 + wall_width;

    screw_posts_top_case = [
        /* Upper row */
        [screw_post_x_offset,   screw_post_upper_y_offset, screw_post_corner_height],
        [case_width_bottom / 2, case_length_bottom - 10.0, screw_post_middle_height],
        [case_width_bottom - screw_post_x_offset, screw_post_upper_y_offset, screw_post_corner_height],

        /* Middle row */
        [screw_post_x_offset, screw_post_middle_y_offset, screw_post_corner_height],
        [case_width_bottom - screw_post_x_offset, screw_post_middle_y_offset, screw_post_corner_height],

        /* Bottom row */
        [screw_post_x_offset, screw_post_lower_y_offset, screw_post_corner_height],
        [case_width_bottom / 2, screw_post_lower_y_offset, screw_post_corner_height],
        [case_width_bottom - screw_post_x_offset, screw_post_lower_y_offset, screw_post_corner_height]
    ];

    module fascia() {
        difference() {
            cube([case_width_bottom, case_length_bottom, wall_width]);

            if (with_keyboard) {
                translate([keyboard_x_offset, keyboard_y_offset, -eps])
                cube([keyboard_pcb_width, keyboard_pcb_length, wall_width + 2*eps]);
            }
        }
    }

    module vents() {
        for (i = [0:vent_count-1]) {
            x = vent_x_first + (i * 2*vent_width);

            translate([x, vent_y_offset-eps, wall_height - vent_height])
            cube([vent_width, vent_length+2*eps, vent_height+eps]);
        }
    }

    module accents() {
        for (y = [accent_y_bottom: accent_y_stride: case_length_bottom]) {
            /* Top */
            translate([-eps, y - eps, wall_height - accent_depth])
            cube([case_width_bottom+2*eps, accent_width + 2*eps, accent_depth+eps]);

            /* Right */
            translate([case_width_bottom - accent_depth, y, -eps])
            cube([accent_depth+eps, accent_width+eps, wall_height+2*eps]);

            /* Left */
            translate([-eps, y, -eps])
            cube([accent_depth+eps, accent_width, wall_height+2*eps]);
        }
    }

    module screw_posts() {
        module screw_post(h) {
            linear_extrude(h)
            difference() {
                circle(d=screw_post_diameter_outer);
                circle(d=screw_post_diameter_inner);
            }
        }

        for (post = screw_posts_top_case) {
            translate([post[0], post[1], wall_height - wall_width - post[2]])
            screw_post(post[2] + eps);
        }
    }

    module supports() {
        support_length_vert  = case_length_bottom - 2 * wall_width;
        support_length_horiz = case_width_bottom  - 2 * wall_width;
        support_height       = 0.7500 * wall_height;
        support_width        = 1.2500;

        support_x_interval = (case_width_bottom  + 2 * wall_width - support_width) / 7;
        support_y_interval = (case_length_bottom + 2 * wall_width - support_width) / 5;

        for (x = [support_x_interval: support_x_interval: case_width_bottom - wall_width]) {
            translate([x, wall_width - eps, wall_height - wall_width])
            support([support_length_vert + 2*eps, support_height], support_width);
        }

        for (y = [support_y_interval: support_y_interval: case_length_bottom - wall_width]) {
            translate([wall_width - eps, y, wall_height - wall_width])
            rotate([0, 0, -90])
            support([support_length_horiz + 2*eps, support_height], support_width);
        }
    }

    module keyboard_supports() {
        support_width  = 1.2500;
        support_height = keyboard_switch_height - wall_width;

        support_x_interval = (keyboard_pcb_width + 2 * wall_width - support_width) / 6;
        support_x_offset   =  keyboard_x_offset - wall_width;

        support_y_interval = (keyboard_pcb_length + 2 * wall_width - support_width) / 4;
        support_y_offset   =  keyboard_y_offset;

        /* Upper vertical supports */
        upper_support_length = case_length_bottom
                             - keyboard_pcb_length
                             - keyboard_y_offset
                             - 2 * wall_width;

        upper_support_y_offset = keyboard_y_offset
                               + keyboard_pcb_length
                               + wall_width;

        /* Lower vertical supports */
        lower_support_length   = keyboard_y_offset - 2 * wall_width;
        lower_support_y_offset = wall_width;

        /* Left horizontal supports */
        left_support_length   = keyboard_x_offset - 2 * wall_width;
        left_support_x_offset = wall_width;

        /* Right horizontal supports */
        right_support_length = case_width_bottom
                             - keyboard_pcb_width
                             - keyboard_x_offset
                             - 2 * wall_width;

        right_support_x_offset = keyboard_x_offset
                               + keyboard_pcb_width
                               + wall_width;

        for (x = [0: support_x_interval: keyboard_pcb_width + 2 * wall_width]) {
            translate([support_x_offset + x,
                       upper_support_y_offset - eps,
                       wall_height - wall_width])
            support([upper_support_length + 2*eps, support_height], support_width);

            translate([support_x_offset + x,
                       lower_support_y_offset - eps,
                       wall_height - wall_width])
            support([lower_support_length + 2*eps, support_height], support_width);
        }

        for (y = [0: support_y_interval: keyboard_pcb_length + 2 * wall_width]) {
            translate([right_support_x_offset - eps,
                       support_y_offset + y - wall_width + support_width,
                       wall_height - wall_width])
            rotate([0, 0, -90])
            support([right_support_length + 2*eps, support_height], support_width);

            translate([left_support_x_offset - eps,
                       support_y_offset + y - wall_width + support_width,
                       wall_height - wall_width])
            rotate([0, 0, -90])
            support([left_support_length + 2*eps, support_height], support_width);
        }
    }

    module badges() {
        translate([keyboard_x_offset,
                   keyboard_y_offset + keyboard_pcb_length + keyboard_switch_length + accent_width,
                   wall_height - accent_depth])
        linear_extrude(accent_depth + eps)
        logotype(size=10);

        sextile_width = 16.0;
        sextile_y      = keyboard_y_offset + (keyboard_switch_width + accent_width) / 2;
        sextile_x      = case_width_bottom - sextile_width;

        translate([sextile_x, sextile_y, wall_height - accent_depth])
        linear_extrude(accent_depth + eps)
        sextile(width=sextile_width);
    }

    module body() {
        translate([0, 0, wall_height - wall_width])
        fascia();

        /* Upper */
        translate([wall_width, case_length_bottom - wall_width_upper, 0])
        cube([case_width_bottom - 2*wall_width, wall_width_upper, wall_lip_upper]);

        translate([0, case_length_bottom - wall_width, wall_lip_upper - eps])
        cube([case_width_bottom, wall_width, wall_height - wall_lip_upper + eps]);

        /* Right */
        translate([case_width_bottom - wall_width, 0, 0])
        cube([wall_width, case_length_bottom, wall_height]);

        /* Lower */
        cube([case_width_bottom, wall_width, wall_height]);

        /* Left */
        cube([wall_width, case_length_bottom, wall_height]);
    }

    module model() {
        difference() {
            body();
            accents();
            vents();
            badges();
        }

        screw_posts();

        if (with_keyboard) {
            z_offset = wall_height - keyboard_switch_height;

            keyboard_supports();

            translate([keyboard_x_offset, keyboard_y_offset, z_offset])
            keyboard_deck(wall_width);
        } else {
            supports();
        }
    }

    module flat() {
        square([wall_width, case_length_bottom], false);
        square([case_width_bottom, wall_width], false);

        translate([case_width_bottom - wall_width, 0, 0])
        square([wall_width, case_length_bottom], false);

        translate([0, case_length_bottom - wall_width, 0])
        square([case_width_bottom, wall_width], false);


        for (screw_post = screw_posts_top_case) {
            x = screw_post[0];
            y = screw_post[1];

            translate([x, y, 0])
            difference() {
                circle(d=screw_post_diameter_outer);
                circle(d=screw_post_diameter_inner);
            }
        }
    }

    if (as_flat) {
        flat();
    } else {
        model();
    }
}

top_case(with_keyboard);