The method I'm using for my SVG renderer is drawing a path with variable distances. Functionally, the 2u is the same as the 10u with a longer bar, so I initiate a path, move to position, and start tracing a line using relative coords, and then once I hit a variable, I use absolute coords based on Cherry specs.
I run renderSpacebar( -2.625, -2.1, 2.625, 2.1 ); and it'll draw a stabilizer with cutouts at those unit positions for the 6.25u A+B style.
Not as easy to render the options like stab openings, or screw holes, but I'll get to that whenever I get to it.
This is similar to what I am doing, but I am not setting up my layout before hand and then placing the switches after. Instead, I will run over the layout quickly once just to figure out some sums so I can determine the size of the plate based on the number and size of the keys. When working with redefined case layouts (like the poker for example), then I will have to do a little magic to figure out how to get the holes between switches, but we will see...
Basically, I will be cutting one switch at a time based on the current switch size and the previous switch size. I will be looping through each row and placing the switches and 2u stabilizers for keys 2 <= key < 3.
I will have global settings for all of the following details:
these options will be shown after you specify your source layout so I know what size spacebar you will be using and such.
- Switch type (the 4 types I have shown so far)
- 2 unit stab (cherry spec or universal so far)
- spacebar type (cherry spec or universal so far. i will probably draw more options later)
Then when I move through the switches and draw them I will use the global settings to know which switch type to draw. If the key size is (2 <= key < 3) then it will draw a 2 unit stabilizer based on your selection. If the key is (3 <= key), then it will pick draw a spacebar stabilizer based on your previous selection.
Keep in mind that I am still planning this and this is what I have come up with so far.
Currently I have the following function for cutting the switch: cut_switch(p, c, s=None)
It takes the plate to cut the switch on (p) as well as the center of where the switch should be cut (c) and if a stabilizer should be cut (s) which will be a numerical value of the size of the stab to be cut.
When moving from one switch location to the next, the (c) value is calculated as:
c = .5*prev_switch_size*1unit_size + .5*curr_switch_size*1unit_size
So for example, for my testing, the following layout is created with the code below:
![](https://dl.dropboxusercontent.com/u/1392076/swillkb/layout.png)
p = init_plate()
p = p.center((-plate_width/2)+(switch_size/2), (-plate_height/2)+(switch_size/2))
p = cut_switch(p, (plate_x_pad, plate_y_pad))
x_off += u1 - plate_x_pad
p = cut_switch(p, (u1, 0))
p = cut_switch(p, (u1, 0))
p = cut_switch(p, (u1, 0))
p = cut_switch(p, (u1, 0))
p = cut_switch(p, (u1, 0))
p = cut_switch(p, (u1, 0))
p = cut_switch(p, (u1, 0))
p = p.center(-x_off, u1)
x_off = 0
switch_type = 0
p = cut_switch(p, (1.5*u1, 0))
switch_type = 1
p = cut_switch(p, (2*u1, 0))
switch_type = 2
p = cut_switch(p, (2*u1, 0))
switch_type = 3
p = cut_switch(p, (2*u1, 0))
p = p.center(-x_off, u1)
x_off = 0
switch_type = 0
u2_stab_type = 0
p = cut_switch(p, (1.5*u1, 0), 2)
switch_type = 1
p = cut_switch(p, (2*u1, 0), 2)
switch_type = 2
p = cut_switch(p, (2*u1, 0), 2)
switch_type = 3
p = cut_switch(p, (2*u1, 0), 2)
p = p.center(-x_off, u1)
x_off = 0
switch_type = 0
u2_stab_type = 1
p = cut_switch(p, (1.5*u1, 0), 2)
switch_type = 1
p = cut_switch(p, (2*u1, 0), 2)
switch_type = 2
p = cut_switch(p, (2*u1, 0), 2)
switch_type = 3
p = cut_switch(p, (2*u1, 0), 2)
Obviously this is not automated yet, but I am trying to put the pieces in place to be able to easily automate.