Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into repack52
Browse files Browse the repository at this point in the history
  • Loading branch information
scottbez1 committed Oct 6, 2024
2 parents 6f95843 + 8db0a90 commit 4143d7e
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 170 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/3d.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
gzip 3d/build/outputs/3d_colored_stl/*.stl
- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: 3d
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/electronics.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
PYTHONUNBUFFERED: 1

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: electronics-classic
Expand Down Expand Up @@ -150,7 +150,7 @@ jobs:
run: cp -r electronics/build/bom electronics/build/outputs

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: electronics-chainlink
Expand Down Expand Up @@ -237,7 +237,7 @@ jobs:
run: cp -r electronics/build/bom electronics/build/outputs

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: electronics-chainlink-tester
Expand Down Expand Up @@ -322,7 +322,7 @@ jobs:
run: cp -r electronics/build/bom electronics/build/outputs

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: electronics-chainlink-base
Expand Down Expand Up @@ -430,7 +430,7 @@ jobs:
run: cp -r electronics/build/bom electronics/build/outputs

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: electronics-chainlink-buddy-t-display
Expand Down Expand Up @@ -538,7 +538,7 @@ jobs:
run: cp -r electronics/build/bom electronics/build/outputs

- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: electronics-chainlink-buddy-breadboard
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/electronics_v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ jobs:
ls -lah electronics/build/outputs
- name: Archive artifacts
uses: actions/upload-artifact@v2
uses: actions/upload-artifact@v4
if: always()
with:
name: electronics-v2
Expand Down
28 changes: 19 additions & 9 deletions 3d/scripts/generate_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,18 +162,28 @@ def getDimensionSvgContents(text, width):
elecrow_zip = os.path.join(laser_parts_directory, 'elecrow.zip')

processor.apply_elecrow_style()
processor.add_dimensions(width_mm, height_mm)
processor.add_dimensions(width_mm, height_mm, args.mirror)
processor.write(elecrow_svg)

logging.info('Resize SVG canvas')
subprocess.check_call([
app_paths.get('inkscape'),
'--verb=FitCanvasToDrawing',
'--verb=FileSave',
'--verb=FileClose',
'--verb=FileQuit',
elecrow_svg,
])
# since version 1.2, inkscape has replaced 'verbs' with 'actions'
# see: https://wiki.inkscape.org/wiki/Using_the_Command_Line
if inkscape._version() < 1.2:
subprocess.check_call([
app_paths.get('inkscape'),
'--verb=FitCanvasToDrawing',
'--verb=FileSave',
'--verb=FileClose',
'--verb=FileQuit',
elecrow_svg,
])
else:
subprocess.check_call([
app_paths.get('inkscape'),
"--actions=select-all;fit-canvas-to-selection;export-type:svg;export-plain-svg;export-do",
elecrow_svg,
"-o", elecrow_svg,
])

logging.info('Output PDF')
subprocess.check_call([
Expand Down
2 changes: 1 addition & 1 deletion 3d/scripts/generate_combined_front_panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
def render(extra_variables, output_directory):
renderer = Renderer(os.path.join(source_parts_dir, 'combined_front_panel.scad'), output_directory, extra_variables)
renderer.clean()
svg_output = renderer.render_svgs(panelize_quantity = 1)
svg_output, _ = renderer.render_svgs(panelize_quantity = 1)
logging.info('\n\n\nDone rendering to SVG: ' + svg_output)

if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion 3d/scripts/generate_fonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
def render(extra_variables, skip_optimize, output_directory):
renderer = Renderer(os.path.join(source_parts_dir, 'font_generator.scad'), output_directory, extra_variables)
renderer.clean()
svg_output = renderer.render_svgs(panelize_quantity = 1)
svg_output, _ = renderer.render_svgs(panelize_quantity = 1)

processor = SvgProcessor(svg_output)

Expand Down
2 changes: 1 addition & 1 deletion 3d/scripts/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
svg.path==4.0.2
svg.path==6.3
58 changes: 38 additions & 20 deletions 3d/scripts/svg_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
from __future__ import print_function
from collections import defaultdict
import os

svg_path_install = f'python3 -m pip install -r {os.path.join(os.path.dirname(__file__), "requirements.txt")}'
try:
from svg.path import (
Path,
Expand All @@ -24,7 +26,11 @@
parse_path,
)
except:
raise RuntimeError(f'Error loading svg.path library. Run "python3 -m pip install -r {os.path.join(os.path.dirname(__file__), "requirements.txt")}" to install it')
raise RuntimeError(f'Error loading svg.path library. Run "{svg_path_install}" to install it')

from importlib.metadata import version
assert int(version('svg.path').split('.')[0]) == 6, f'svg.path library is not new enough (found {version("svg.path")}). Run "{svg_path_install}" to install it'


from xml.dom import minidom

Expand Down Expand Up @@ -159,10 +165,11 @@ def remove_redundant_lines(self):
path_text = path.attributes['d'].value
path_obj = parse_path(path_text)
for line_index, line in enumerate(path_obj):
# Moves don't draw anything by themselves, but they do set the
# target for subsequent closes, so they should not be removed.
slope, intersect = _get_slope_intersect(line.start, line.end)
if not isinstance(line, Move):
if isinstance(line, Close):
# Treat Close as a Line
line = Line(line.start, line.end)
if isinstance(line, Line):
slope, intersect = _get_slope_intersect(line.start, line.end)
# TODO: float inaccuracy and rounding may cause collinear lines to end up in separate buckets in rare
# cases, so this is not quite correct. Would be better to put lines into *2* nearest buckets in each
# dimension to avoid edge cases.
Expand Down Expand Up @@ -203,35 +210,45 @@ def remove_redundant_lines(self):
filtered_path = Path()

for line_index, line in enumerate(path_obj):
if isinstance(line, Close):
# Treat Close as a Line
line = Line(line.start, line.end)
if i in to_remove:
assert isinstance(line, Line)
assert path_index == to_remove[i][0]
assert line_index == to_remove[i][1]
removed += 1
removed_length += line.length()
elif i in to_update:
assert isinstance(line, Line)
assert path_index == to_update[i][0]
assert line_index == to_update[i][1]
replacement_line = to_update[i][2]

filtered_path.append(replacement_line)
kept += 1
kept_length += replacement_line.length()
elif isinstance(line, Close):
# Replace the close with a line, because if we removed all
# or part of the previous line in this path, a close will
# not work as expected.
new_line = Line(line.start, line.end)
filtered_path.append(new_line)
kept += 1
kept_length += new_line.length()
else:
elif isinstance(line, Line):
filtered_path.append(line)
kept += 1
kept_length += line.length()
else:
print(f'Omitting non-line in reconstructed path at index {line_index}: {line!r}')
i += 1

# Update the path data with the filtered path data
path.attributes['d'] = filtered_path.d()
last_line = None
new_path = Path()
for line in filtered_path:
# Newer versions of svg.path keep Moves but don't ensure consistency with line start/ends. We've stripped non-Lines above, so
# we need to add back Moves where Line segments are not connected
if last_line is None or abs(last_line.end.real - line.start.real) > 0.001 or abs(last_line.end.imag - line.start.imag) > 0.001:
new_path.append(Move(line.start))
new_path.append(line)
last_line = line

path.attributes['d'] = new_path.d()
print(f'Optimized line path from\n {path_text!r}\n to\n {path.attributes["d"].value!r}')

print('Removed {} lines ({} length) and kept {} lines ({} length)'.format(
removed,
Expand Down Expand Up @@ -353,30 +370,31 @@ def add_highlight_lines(self, lines, color):

self.svg_node.appendChild(new_path_node)

def add_dimensions(self, width_mm, height_mm):
def add_dimensions(self, width_mm, height_mm, mirror=False):
width_node = self.dom.createElement("path")
width_node.setAttribute('d', f'M 0 10 l 0 5 l {width_mm} 0 l 0 -5')
mirror_dir = -1 if mirror else 1
width_node.setAttribute('d', f'M 0 10 l 0 5 l {mirror_dir * width_mm} 0 l 0 -5')
width_node.setAttribute('fill', 'none')
width_node.setAttribute('stroke', '#ff00ff')
width_node.setAttribute('stroke-width', '1')
self.svg_node.appendChild(width_node)

width_label_node = self.dom.createElement('text')
width_label_node.setAttribute('x', f'{width_mm / 2}')
width_label_node.setAttribute('x', f'{mirror_dir * width_mm / 2}')
width_label_node.setAttribute('y', '25')
width_label_node.setAttribute('style', 'font: 5px sans-serif; fill: #ff00ff; text-anchor: middle;')
width_label_node.appendChild(self.dom.createTextNode(f'{width_mm:.2f} mm'))
self.svg_node.appendChild(width_label_node)

height_node = self.dom.createElement("path")
height_node.setAttribute('d', f'M -10 0 l -5 0 l 0 -{height_mm} l 5 0')
height_node.setAttribute('d', f'M {-width_mm - 10 if mirror else -10} 0 l -5 0 l 0 -{height_mm} l 5 0')
height_node.setAttribute('fill', 'none')
height_node.setAttribute('stroke', '#ff00ff')
height_node.setAttribute('stroke-width', '1')
self.svg_node.appendChild(height_node)

height_label_node = self.dom.createElement('text')
height_label_node.setAttribute('x', '-20')
height_label_node.setAttribute('x', f'{-width_mm - 20 if mirror else -20}')
height_label_node.setAttribute('y', f'{-height_mm / 2}')
height_label_node.setAttribute('style', 'font: 5px sans-serif; fill: #ff00ff; text-anchor: end;')
height_label_node.appendChild(self.dom.createTextNode(f'{height_mm:.2f} mm'))
Expand Down
1 change: 1 addition & 0 deletions 3d/tools/flap_container.scad
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

include <../flap_dimensions.scad>
use <../splitflap.scad>
use <../flap.scad>

num_flaps = 40;
containers_x = 1;
Expand Down
Loading

0 comments on commit 4143d7e

Please sign in to comment.