From e06bbdbe9b359fb168278b44f039b6d1108e5a2d Mon Sep 17 00:00:00 2001 From: jaseg Date: Mon, 24 May 2021 21:11:21 +0200 Subject: Make templates default to silk layer when opened in inkscape --- gerbolyze/gerbolyze.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gerbolyze') diff --git a/gerbolyze/gerbolyze.py b/gerbolyze/gerbolyze.py index f77e047..d4b4ab5 100755 --- a/gerbolyze/gerbolyze.py +++ b/gerbolyze/gerbolyze.py @@ -504,7 +504,7 @@ DEFAULT_EXTRA_LAYERS = [ layer for layer in LAYER_RENDER_ORDER if layer != "dril def template_layer(name): return f'' -def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS): +def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS, current_layer='silk'): (x1, x2), (y1, y2) = bounds w_mm, h_mm = (x2 - x1), (y2 - y1) @@ -519,6 +519,7 @@ def template_svg_for_png(bounds, png_data, extra_layers=DEFAULT_EXTRA_LAYERS): xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" width="{w_mm}mm" height="{h_mm}mm" viewBox="0 0 {w_mm} {h_mm}" > + @@ -538,7 +539,7 @@ def svg_pt_to_mm(pt_len, dpi=CAIRO_SVG_HARDCODED_DPI): return f'{float(pt_len) / dpi * MM_PER_INCH}mm' -def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS): +def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS, current_layer='silk'): svg = etree.fromstring(svg_data) # add inkscape namespaces @@ -555,6 +556,11 @@ def create_template_from_svg(bounds, svg_data, extra_layers=DEFAULT_EXTRA_LAYERS svg.set('width', svg_pt_to_mm(svg.get('width'))) svg.set('height', svg_pt_to_mm(svg.get('height'))) + # add inkscape elem to set currently selected layer + namedview_elem = etree.SubElement(svg, SODIPODI_NS+'namedview') + namedview_elem.set('id', "namedview23") + namedview_elem.set(INKSCAPE_NS+'current-layer', f'g-{current_layer}') + # make original group an inkscape layer orig_g = svg.find(SVG_NS+'g') orig_g.set('id', 'g-preview') -- cgit