switch to generating the customizer file via a script

This commit is contained in:
Robert Sheldon 2018-06-25 23:14:35 -04:00
parent 410f25c88e
commit 16b7ec4a25
6 changed files with 981 additions and 561 deletions

File diff suppressed because it is too large Load Diff

27
expand.rb Normal file
View File

@ -0,0 +1,27 @@
def expand(filename)
lines = File.readlines(filename)
old_dir = Dir.getwd
Dir.chdir File.dirname(filename)
lines = lines.flat_map do |line|
if line =~ /(include|use)\s*<(.*)>/
# File.readlines("./#{$2}")
expand("./#{$2}")
# in lieu of actually implementing `use`, we can just cull this final line from key.scad
elsif line =~ /example\_key\(\);/
""
else
line
end
end
Dir.chdir old_dir
lines
end
lines = expand(ARGV[1] || 'keys.scad')
f = File.open('customizer.scad', 'w')
f.write lines.join

View File

@ -4,11 +4,11 @@ include <supports/bars.scad>
module supports(type, stem_type, loft, height) { module supports(type, stem_type, loft, height) {
if (type == "flared") { if (type == "flared") {
flared_support(stem_type, loft, height); flared(stem_type, loft, height);
} else if (type == "flat") { } else if (type == "flat") {
flat_support(stem_type, loft, height); flat(stem_type, loft, height);
} else if (type == "bars") { } else if (type == "bars") {
bars_support(stem_type, loft, height); bars(stem_type, loft, height);
} else { } else {
echo("Warning: unsupported $support_type"); echo("Warning: unsupported $support_type");
} }

View File

@ -1,4 +1,4 @@
module bars_support(stem_type, loft, height) { module bars(stem_type, loft, height) {
translate([0,0,loft + height / 2]){ translate([0,0,loft + height / 2]){
cube([2, 100, height], center = true); cube([2, 100, height], center = true);
cube([100, 2, height], center = true); cube([100, 2, height], center = true);

View File

@ -7,7 +7,7 @@ function scale_for_45(height, starting_size) = (height * 2 + starting_size) / st
// complicated since we want the different stems to work well // complicated since we want the different stems to work well
// also kind of messy... oh well // also kind of messy... oh well
module flared_support(stem_type, loft, height) { module flared(stem_type, loft, height) {
translate([0,0,loft]){ translate([0,0,loft]){
if (stem_type == "cherry_rounded") { if (stem_type == "cherry_rounded") {
linear_extrude(height=height, scale = scale_for_45(height, $rounded_cherry_stem_d)){ linear_extrude(height=height, scale = scale_for_45(height, $rounded_cherry_stem_d)){

View File

@ -1,4 +1,4 @@
module flat_support(stem_type, loft, height) { module flat(stem_type, loft, height) {
translate([0,0,loft + 500]){ translate([0,0,loft + 500]){
cube(1000, center=true); cube(1000, center=true);
} }