Now uses the dependencies to locate modules for printed parts and assemblies.

This commit is contained in:
Chris Palmer 2020-03-12 22:47:27 +00:00
parent 2eef050f60
commit 2210396234
6 changed files with 35 additions and 16 deletions

View File

@ -243,3 +243,10 @@ Some parametric designs might have several configurations, for example a 3D prin
The target config file is selected by generating ```target.scad``` that includes ```config_<target_name>.scad```.
The rest of the project includes ```target.scad``` to use the configuration.
Additionally all the generated file directories (assemblies, bom, stls, dxfs, etc.) are placed in a sub-directory called ```<target_name>```.
### Other libraries
The build scripts need to be able to locate the source files where the modules to generate the STL files and assemblies reside. They will search all the scad files
in the project plus any ```printed``` directories outside the project. This covers the printed parts in NopSCADlib but also allows other libraries of printed parts.
Other libraries of vitamins and utilities can be used provided they follow the same convensions of NopSCADlib. The build scripts don't need to search those.

View File

@ -221,7 +221,7 @@ def boms(target = None, assembly = None):
#
# Run openscad
#
openscad.run("-D","$bom=2","-D","$preview=true","-o", "openscad.echo", bom_maker_name)
openscad.run("-D","$bom=2","-D","$preview=true","-o", "openscad.echo", "-d", bom_dir + "/bom.deps", bom_maker_name)
os.remove(bom_maker_name)
print("Generating bom ...", end=" ")

View File

@ -48,3 +48,17 @@ def check_deps(target, dname):
if mtime(dep) > target_mtime:
return dep + ' changed'
return None
def source_dirs(bom_dir):
dirs = set()
lib_dirs = set()
deps = read_deps(bom_dir + '/bom.deps')
cwd = os.getcwd().replace('\\', '/')
for dep in deps:
dir = os.path.dirname(dep)
if dir.startswith(cwd):
dirs.add(dir[len(cwd) + 1:])
else:
if dir.endswith('/printed'):
lib_dirs.add(dir)
return sorted(dirs) + sorted(lib_dirs)

View File

@ -30,14 +30,14 @@ import times
from deps import *
import json
def bom_to_parts(target_dir, part_type, assembly = None):
def bom_to_parts(bom_dir, part_type, assembly = None):
#
# Make a list of all the parts in the BOM
#
part_files = []
bom = assembly + '.txt' if assembly else "bom.txt"
suffix = ".dxf" if part_type == 'svg' else '.' + part_type
with open(target_dir + "/../bom/" + bom, "rt") as f:
with open(bom_dir + '/' + bom, "rt") as f:
for line in f.readlines():
words = line.split()
if words:
@ -63,6 +63,7 @@ def make_parts(target, part_type, parts = None):
top_dir = set_config(target, lambda: usage(part_type))
target_dir = top_dir + part_type + 's'
deps_dir = top_dir + "deps"
bom_dir = top_dir + "bom"
if not os.path.isdir(target_dir):
os.makedirs(target_dir)
if not os.path.isdir(deps_dir):
@ -74,7 +75,7 @@ def make_parts(target, part_type, parts = None):
if parts:
targets = list(parts) #copy the list so we dont modify the list passed in
else:
targets = bom_to_parts(target_dir, part_type)
targets = bom_to_parts(bom_dir, part_type)
for file in os.listdir(target_dir):
if file.endswith('.' + part_type):
if not file in targets:
@ -93,12 +94,11 @@ def make_parts(target, part_type, parts = None):
#
# Find all the scad files
#
lib_dirs = [path + '/' + lib + '/printed' for path in os.environ['OPENSCADPATH'].split(os.pathsep) for lib in sorted(os.listdir(path))]
module_suffix = '_dxf' if part_type == 'svg' else '_' + part_type
for dir in [source_dir, source_dir + '/printed'] + lib_dirs:
if os.path.isdir(dir):
for dir in source_dirs(bom_dir):
if targets and os.path.isdir(dir):
for filename in os.listdir(dir):
if filename[-5:] == ".scad":
if targets and filename[-5:] == ".scad":
#
# find any modules ending in _<part_type>
#
@ -148,9 +148,6 @@ def make_parts(target, part_type, parts = None):
#
if targets:
for part in targets:
if part[-4:] != '.' + part_type:
print(part, "is not a", part_type, "file")
else:
print("Could not find a module called", part[:-4] + module_suffix, "to make", part)
usage(part_type)
times.print_times()

View File

@ -38,13 +38,15 @@ def render(target, type):
#
# Make the target directory
#
target_dir = set_config(target, usage) + type + 's'
top_dir = set_config(target, usage)
target_dir = top_dir + type + 's'
bom_dir = top_dir + 'bom'
if not os.path.isdir(target_dir):
os.makedirs(target_dir)
#
# Find all the parts
#
parts = bom_to_parts(target_dir, type)
parts = bom_to_parts(bom_dir, type)
#
# Remove unused png files
#

View File

@ -137,8 +137,7 @@ def views(target, do_assemblies = None):
# Find all the scad files
#
main_blurb = None
lib_dirs = [path + '/' + lib + '/printed' for path in os.environ['OPENSCADPATH'].split(os.pathsep) for lib in sorted(os.listdir(path))]
for dir in [source_dir, source_dir + '/printed'] + lib_dirs:
for dir in source_dirs(bom_dir):
if os.path.isdir(dir):
for filename in os.listdir(dir):
if filename.endswith('.scad'):