From 7bdbe66dc7caf3d27fd13b72a2603b7bca19762d Mon Sep 17 00:00:00 2001 From: jaseg Date: Tue, 21 Jun 2022 14:17:08 +0200 Subject: Fix zip import/export and bounds for empty boards --- gerbonara/cam.py | 2 ++ gerbonara/layers.py | 7 ++++--- gerbonara/utils.py | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/gerbonara/cam.py b/gerbonara/cam.py index fb69e5c..8a5ad68 100644 --- a/gerbonara/cam.py +++ b/gerbonara/cam.py @@ -267,6 +267,8 @@ class CamFile: # setup viewport transform flipping y axis (content_min_x, content_min_y), (content_max_x, content_max_y) = bounds + content_min_x, content_min_y = float(content_min_x), float(content_min_y) + content_max_x, content_max_y = float(content_max_x), float(content_max_y) content_w, content_h = content_max_x - content_min_x, content_max_y - content_min_y xform = f'translate({content_min_x:.6} {content_min_y+content_h:.6}) scale(1 -1) translate({-content_min_x:.6} {-content_min_y:.6})' tags = [tag('g', tags, transform=xform)] diff --git a/gerbonara/layers.py b/gerbonara/layers.py index 41c5bfe..afd6db9 100644 --- a/gerbonara/layers.py +++ b/gerbonara/layers.py @@ -27,6 +27,7 @@ import itertools from collections import namedtuple from pathlib import Path from zipfile import ZipFile, is_zipfile +import tempfile from .excellon import ExcellonFile, parse_allegro_ncparam, parse_allegro_logfile from .rs274x import GerberFile @@ -249,13 +250,13 @@ class LayerStack: @classmethod def open_zip(kls, file, original_path=None, board_name=None, lazy=False): tmpdir = tempfile.TemporaryDirectory() - tmp_indir = Path(tmpdir) / 'input' + tmp_indir = Path(tmpdir.name) / 'input' tmp_indir.mkdir() with ZipFile(file) as f: f.extractall(path=tmp_indir) - inst = kls.from_directory(tmp_indir, board_name=board_name, lazy=lazy) + inst = kls.open_dir(tmp_indir, board_name=board_name, lazy=lazy) inst.tmpdir = tmpdir inst.original_path = Path(original_path or file) inst.was_zipped = True @@ -486,7 +487,7 @@ class LayerStack: if force_bounds: bounds = svg_unit.convert_bounds_from(arg_unit, force_bounds) else: - bounds = selfboard_bounds(unit=svg_unit, default=((0, 0), (0, 0))) + bounds = self.board_bounds(unit=svg_unit, default=((0, 0), (0, 0))) tags = [] inkscape_attrs = lambda label: dict(inkscape__groupmode='layer', inkscape__label=label) if inkscape else {} diff --git a/gerbonara/utils.py b/gerbonara/utils.py index 04d1e54..586232a 100644 --- a/gerbonara/utils.py +++ b/gerbonara/utils.py @@ -269,7 +269,7 @@ def sum_bounds(bounds, *, default=None): :rtype: tuple """ - bounds = iter(bounds) + bounds = iter([ b for b in bounds if b is not None ]) for (min_x, min_y), (max_x, max_y) in bounds: break -- cgit