Skip to content

Commit

Permalink
svg_processor.py: add_dimensions handle when combined.svg is in mirro…
Browse files Browse the repository at this point in the history
…red form
  • Loading branch information
len0rd committed Jun 20, 2024
1 parent 1d3ab50 commit b87e6f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 3d/scripts/generate_2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ 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')
Expand Down
11 changes: 6 additions & 5 deletions 3d/scripts/svg_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,30 +353,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

0 comments on commit b87e6f9

Please sign in to comment.