summaryrefslogtreecommitdiff
path: root/gerbonara/layers.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-04-24 20:08:14 +0200
committerjaseg <git@jaseg.de>2022-04-24 20:08:14 +0200
commita1de37d83f22a883f5e4605e59b82aea69b4a563 (patch)
tree2cad8a7761474163cbdde8ac659601bbd9dc2eae /gerbonara/layers.py
parentb42b0e85fa2220a5083f64383aed43de73788c0c (diff)
downloadgerbonara-a1de37d83f22a883f5e4605e59b82aea69b4a563.tar.gz
gerbonara-a1de37d83f22a883f5e4605e59b82aea69b4a563.tar.bz2
gerbonara-a1de37d83f22a883f5e4605e59b82aea69b4a563.zip
Add SVG export to more things
Diffstat (limited to 'gerbonara/layers.py')
-rw-r--r--gerbonara/layers.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/gerbonara/layers.py b/gerbonara/layers.py
index 4591f93..b79f474 100644
--- a/gerbonara/layers.py
+++ b/gerbonara/layers.py
@@ -29,6 +29,7 @@ from .rs274x import GerberFile
from .ipc356 import Netlist
from .cam import FileSettings
from .layer_rules import MATCH_RULES
+from .utils import sum_bounds, setup_svg, MM, Tag
STANDARD_LAYERS = [
@@ -409,6 +410,51 @@ class LayerStack:
def __repr__(self):
return str(self)
+ def to_svg(self, margin=0, arg_unit=MM, svg_unit=MM, force_bounds=None, tag=Tag):
+ if force_bounds:
+ bounds = svg_unit.convert_bounds_from(arg_unit, force_bounds)
+ else:
+ bounds = self.bounding_box(svg_unit, default=((0, 0), (0, 0)))
+
+ tags = []
+ for (side, use), layer in self.graphic_layers.items():
+ tags.append(tag('g', list(layer.svg_objects(svg_unit=svg_unit, fg='black', bg="white", tag=Tag)),
+ id=f'l-{side}-{use}'))
+
+ for i, layer in enumerate(self.drill_layers):
+ tags.append(tag('g', list(layer.svg_objects(svg_unit=svg_unit, fg='black', bg="white", tag=Tag)),
+ id=f'l-{drill}-{i}'))
+
+ return setup_svg(tags, bounds, margin=margin, arg_unit=arg_unit, svg_unit=svg_unit, pagecolor=bg, tag=tag)
+
+ def to_pretty_svg(self, side='top', margin=0, arg_unit=MM, svg_unit=MM, force_bounds=None, tag=Tag):
+ if force_bounds:
+ bounds = svg_unit.convert_bounds_from(arg_unit, force_bounds)
+ else:
+ bounds = self.bounding_box(svg_unit, default=((0, 0), (0, 0)))
+
+ tags = []
+
+ for use, color in {'copper': 'black', 'mask': 'blue', 'silk': 'red'}:
+ if (side, use) not in self:
+ continue
+
+ layer = self[(side, use)]
+ tags.append(tag('g', list(layer.svg_objects(svg_unit=svg_unit, fg=color, bg="white", tag=Tag)),
+ id=f'l-{side}-{use}'))
+
+ for i, layer in enumerate(self.drill_layers):
+ tags.append(tag('g', list(layer.svg_objects(svg_unit=svg_unit, fg='magenta', bg="white", tag=Tag)),
+ id=f'l-{drill}-{i}'))
+
+ return setup_svg(tags, bounds, margin=margin, arg_unit=arg_unit, svg_unit=svg_unit, pagecolor=bg, tag=tag)
+
+
+
+ def bounding_box(self, unit=MM, default=None):
+ return sum_bounds(( layer.bounding_box(unit, default=default)
+ for layer in (self.graphic_layers + self.drill_layers) ), default=default)
+
def merge_drill_layers(self):
target = ExcellonFile(comments='Drill files merged by gerbonara')