1
0
mirror of https://github.com/nophead/NopSCADlib.git synced 2025-08-12 18:33:58 +02:00

Restored explode lines to yellow.

Now keeps track of STL bounds and uses them to force a large assembly view when large.
This commit is contained in:
Chris Palmer
2019-06-11 12:38:00 +01:00
parent 00c6914e23
commit 85e1985f1a
17 changed files with 70 additions and 31 deletions

View File

@@ -85,6 +85,8 @@ class STL:
sys.exit(1)
def write(self, fname):
mins = [float('inf'), float('inf'), float('inf')]
maxs = [float('-inf'), float('-inf'), float('-inf')]
with open(fname,"wt") as f:
print('solid OpenSCAD_Model', file=f)
for facet in self.facets:
@@ -92,13 +94,18 @@ class STL:
print(' outer loop', file=f)
for vertex in facet.vertices:
print(' vertex %s %s %s' % (vertex.x, vertex.y, vertex.z), file=f)
for i in range(3):
ordinate = vertex.key[i]
if ordinate > maxs[i]: maxs[i] = ordinate
if ordinate < mins[i]: mins[i] = ordinate
print(' endloop', file=f)
print(' endfacet', file=f)
print('endsolid OpenSCAD_Model', file=f)
return mins, maxs
def canonicalise(fname):
stl = STL(fname)
stl.write(fname)
return stl.write(fname)
if __name__ == '__main__':
if len(sys.argv) == 2:

View File

@@ -28,6 +28,7 @@ from set_config import *
import time
import times
from deps import *
import json
def bom_to_parts(target_dir, part_type, assembly = None):
#
@@ -70,6 +71,16 @@ def make_parts(target, part_type, parts = None):
print("Removing %s" % file)
os.remove(target_dir + '/' + file)
#
# Read existing STL bounds
#
if part_type == 'stl':
bounds_fname = target_dir + '/bounds.json'
try:
with open(bounds_fname) as json_file:
bounds_map = json.load(json_file)
except:
bounds_map = {}
#
# Find all the scad files
#
lib_dir = os.environ['OPENSCADPATH'] + '/NopSCADlib'
@@ -104,13 +115,16 @@ def make_parts(target, part_type, parts = None):
dname = deps_name(deps_dir, filename)
changed = check_deps(mtime(part_file), dname)
changed = times.check_have_time(changed, part)
if part_type == 'stl' and not changed and not part in bounds_map:
changed = "No bounds"
if changed:
print(changed)
t = time.time()
openscad.run("-D$bom=1", "-d", dname, "-o", part_file, part_maker_name)
times.add_time(part, t)
if part_type == 'stl':
c14n_stl.canonicalise(part_file)
bounds = c14n_stl.canonicalise(part_file)
bounds_map[part] = bounds
targets.remove(part)
os.remove(part_maker_name)
#
@@ -120,6 +134,12 @@ def make_parts(target, part_type, parts = None):
if line[:7] == 'ECHO: "' and line[-6:] == '.' + part_type + '"\n':
used.append(line[7:-2])
#
# Write new bounds file
#
if part_type == 'stl':
with open(bounds_fname, 'w') as outfile:
json.dump(bounds_map, outfile, indent = 4)
#
# List the ones we didn't find
#
if targets:

View File

@@ -39,17 +39,26 @@ from colorama import Fore
def is_assembly(s):
return s[-9:] == '_assembly' or s[-11:] == '_assemblies'
def add_assembly(flat_bom, bom):
def add_assembly(flat_bom, bom, bounds_map):
if not bom in flat_bom:
big = False
for ass in bom["assemblies"]:
add_assembly(flat_bom, ass)
if ass["routed"]:
add_assembly(flat_bom, ass, bounds_map)
if ass["big"]:
big = True
if not big:
for stl in bom["printed"]:
bounds = bounds_map[stl]
width = bounds[1][0] - bounds[0][0]
depth = bounds[1][1] - bounds[0][1]
if max(width, depth) > 80:
big = True
break
bom["big"] = big or bom["routed"]
flat_bom.append(bom)
def bom_to_assemblies(bom_dir):
def bom_to_assemblies(bom_dir, bounds_map):
global flat_bom
#
# Make a list of all the parts in the BOM
@@ -59,7 +68,7 @@ def bom_to_assemblies(bom_dir):
with open(bom_file) as json_file:
bom = json.load(json_file)
flat_bom = []
add_assembly(flat_bom, bom)
add_assembly(flat_bom, bom, bounds_map)
ass = flat_bom[-1]
if len(ass["assemblies"]) < 2 and not ass["vitamins"] and not ass["printed"] and not ass["routed"]:
flat_bom = flat_bom[:-1]
@@ -90,11 +99,15 @@ def views(target, do_assemblies = None):
os.makedirs(target_dir)
if not os.path.isdir(deps_dir):
os.makedirs(deps_dir)
times.read_times(target_dir)
bounds_fname = top_dir + 'stls/bounds.json'
with open(bounds_fname) as json_file:
bounds_map = json.load(json_file)
#
# Find all the assemblies
#
assemblies = bom_to_assemblies(bom_dir)
assemblies = bom_to_assemblies(bom_dir, bounds_map)
for file in os.listdir(target_dir):
if file.endswith('.png'):
assembly = file[:-4].replace('_assembled', '_assembly')