The sad realization that STL import/export is not good enough to cache keyblanks

This commit is contained in:
Eric Van Albert
2017-06-17 21:37:31 -04:00
parent 42aa34d81c
commit af88866d69
6 changed files with 9 additions and 37 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
scad/*.gen.scad

View File

@@ -1,13 +1,12 @@
# Makefile for keygen
# Executables
SCAD = OPENSCADPATH=src:build openscad
SCAD = openscad
POLY = PYTHONPATH=/usr/share/inkscape/extensions bin/paths2openscad.py
SCAD_DIR = src
SCAD_DIR = scad
SVG_DIR = resources
POLY_DIR = build
STL_DIR = build
POLY_DIR = scad
JSON_DIR = build
# Files to include
@@ -17,9 +16,6 @@ SCAD_SRC = $(SCAD_DIR)/schlage.scad
# Generated polygon files
POLY_OBJ = $(patsubst $(SVG_DIR)/%.svg,$(POLY_DIR)/%.gen.scad,$(SVG_SRC))
# Generated STL
STL_OBJ = # populated in .d files
# Generated JSON files
JSON_OBJ = $(patsubst $(SCAD_DIR)/%.scad,$(JSON_DIR)/%.json,$(SCAD_SRC))
@@ -27,19 +23,13 @@ POLYFLAGS =
SCADFLAGS =
# Targets
all: stl $(JSON_DIR)/keys.json
all: $(JSON_DIR)/keys.json poly
poly: $(POLY_OBJ)
$(STL_DIR)/%.d: $(SCAD_DIR)/%.scad
bin/parse.py $< $(STL_DIR)/$*.d $(JSON_DIR)/$*.json
$(JSON_DIR)/%.json: $(SCAD_DIR)/%.scad
bin/parse.py $< $(STL_DIR)/$*.d $(JSON_DIR)/$*.json
bin/parse.py $< $@
$(POLY_DIR)/%.gen.scad: $(SVG_DIR)/%.svg
$(POLY) $(POLYFLAGS) --fname $@ $<
$(JSON_DIR)/keys.json: $(JSON_OBJ)
bin/json_merge.py $^ >$(JSON_DIR)/keys.json
clean:
-rm -f $(POLY_DIR)/*.gen.scad $(STL_DIR)/*.stl $(STL_DIR)/*.d $(JSON_DIR)/*.json
include $(patsubst $(SCAD_DIR)/%.scad,$(STL_DIR)/%.d,$(SCAD_SRC))
stl: $(STL_OBJ)
-rm -f $(POLY_DIR)/*.gen.scad $(JSON_DIR)/*.json

View File

@@ -8,8 +8,7 @@ import string
import itertools
scad_fn = sys.argv[1]
d_fn = sys.argv[2]
json_fn = sys.argv[3]
json_fn = sys.argv[2]
with open(scad_fn) as f:
scad_text = f.read()
@@ -41,27 +40,9 @@ d = d.strip()
os = json.loads(os)
ws = json.loads(ws)
def sanitize(s):
return "".join([c for c in s.lower() if c in string.ascii_lowercase + string.digits])
all_keys = [(n, o, w) for o in os for w in ws]
def stl_filename(n, o, w):
return "$(STL_DIR)/{n_s}_{o_s}_{w_s}.stl".format(n_s=sanitize(n), o_s=sanitize(o), w_s=sanitize(w))
all_keys_makefile = ["{stl_fn}: {scad_fn} {deps}\n\t$(SCAD) $(SCADFLAGS) -D 'outline=\"{o}\"' -D 'warding=\"{w}\"' {scad_fn} -o $@"
.format(n=n, o=o, w=w,
scad_fn=scad_fn, stl_fn=stl_filename(n, o, w), deps=" ".join(["$(POLY_DIR)/{}".format(r) for r in poly_reqs]))
for (n, o, w) in all_keys]
all_stl = [stl_filename(n, o, w) for (n, o, w) in all_keys]
all_keys_makefile.append("STL_OBJ += {}".format(" \\\n ".join(all_stl)))
with open(d_fn, "w") as f:
print("\n".join(all_keys_makefile), file=f
)
json_obj = {
"name": n,
"filename": scad_fn,
"description": d,
"outlines": os,
"wardings": ws