Assembly module search in views.py now case insensitive

allowing the module name string to specify the capitalisaing used in the
build instructions.
This commit is contained in:
Chris Palmer 2020-03-04 12:15:48 +00:00
parent 53292c9f89
commit f7db793c74
3 changed files with 11 additions and 8 deletions

View File

@ -143,7 +143,7 @@ module psu_shroud(type, cable_d, name, cables = 1) { //! Generate the STL file f
} }
module psu_shroud_assembly(type, cable_d, name, cables = 1) //! The printed parts with inserts fitted module psu_shroud_assembly(type, cable_d, name, cables = 1) //! The printed parts with inserts fitted
assembly(str("psu_shroud_", name)) { assembly(str("PSU_shroud_", name)) {
translate_z(psu_shroud_height(type)) translate_z(psu_shroud_height(type))
vflip() vflip()

View File

@ -107,7 +107,7 @@ module ssr_shroud(type, cable_d, name) { //! Generate the STL file for a spec
} }
module ssr_shroud_assembly(type, cable_d, name) //! The printed parts with inserts fitted module ssr_shroud_assembly(type, cable_d, name) //! The printed parts with inserts fitted
assembly(str("ssr_shroud_", name)) { assembly(str("SSR_shroud_", name)) {
translate_z(ssr_shroud_height(type)) translate_z(ssr_shroud_height(type))
vflip() vflip()

View File

@ -117,9 +117,10 @@ def views(target, do_assemblies = None):
with open(bounds_fname) as json_file: with open(bounds_fname) as json_file:
bounds_map = json.load(json_file) bounds_map = json.load(json_file)
# #
# Find all the assemblies # Find all the assemblies and remove any old views
# #
assemblies = bom_to_assemblies(bom_dir, bounds_map) assemblies = bom_to_assemblies(bom_dir, bounds_map)
lc_assemblies = [ass.lower() for ass in assemblies]
for file in os.listdir(target_dir): for file in os.listdir(target_dir):
if file.endswith('.png'): if file.endswith('.png'):
assembly = file[:-4].replace('_assembled', '_assembly') assembly = file[:-4].replace('_assembled', '_assembly')
@ -148,22 +149,24 @@ def views(target, do_assemblies = None):
if len(words) and words[0] == "module": if len(words) and words[0] == "module":
module = words[1].split('(')[0] module = words[1].split('(')[0]
if is_assembly(module): if is_assembly(module):
if module in assemblies: lc_module = module.lower()
if lc_module in lc_assemblies:
real_name = assemblies[lc_assemblies.index(lc_module)]
# #
# Scrape the assembly instructions # Scrape the assembly instructions
# #
for ass in flat_bom: for ass in flat_bom:
if ass["name"] == module: if ass["name"] == real_name:
if not "blurb" in ass: if not "blurb" in ass:
ass["blurb"] = blurb.scrape_module_blurb(lines[:line_no]) ass["blurb"] = blurb.scrape_module_blurb(lines[:line_no])
break break
if not do_assemblies or module in do_assemblies: if not do_assemblies or real_name in do_assemblies:
# #
# Run openscad on the created file # Run openscad on the created file
# #
dname = deps_name(deps_dir, filename) dname = deps_name(deps_dir, filename)
for explode in [0, 1]: for explode in [0, 1]:
png_name = target_dir + '/' + module + '.png' png_name = target_dir + '/' + real_name + '.png'
if not explode: if not explode:
png_name = png_name.replace('_assembly', '_assembled') png_name = png_name.replace('_assembly', '_assembled')
changed = check_deps(png_name, dname) changed = check_deps(png_name, dname)
@ -189,7 +192,7 @@ def views(target, do_assemblies = None):
if mtime(png_name) > mtime(tn_name): if mtime(png_name) > mtime(tn_name):
do_cmd(("magick "+ png_name + " -trim -resize 280x280 -background " + background + " -gravity Center -extent 280x280 -bordercolor " + background + " -border 10 " + tmp_name).split()) do_cmd(("magick "+ png_name + " -trim -resize 280x280 -background " + background + " -gravity Center -extent 280x280 -bordercolor " + background + " -border 10 " + tmp_name).split())
update_image(tmp_name, tn_name) update_image(tmp_name, tn_name)
done_assemblies.append(module) done_assemblies.append(real_name)
else: else:
if module == 'main_assembly': if module == 'main_assembly':
main_blurb = blurb.scrape_module_blurb(lines[:line_no]) main_blurb = blurb.scrape_module_blurb(lines[:line_no])