From 9e86bf6b3e92706c190283af83d71999fee03442 Mon Sep 17 00:00:00 2001 From: jaseg Date: Wed, 19 Jan 2022 00:36:05 +0100 Subject: Fix old gerber tests --- gerbonara/gerber/aperture_macros/expression.py | 4 +- gerbonara/gerber/cam.py | 8 +- gerbonara/gerber/gerber_statements.py | 3 +- gerbonara/gerber/layers.py | 1 - gerbonara/gerber/operations.py | 126 ------------------------- gerbonara/gerber/utils.py | 7 ++ 6 files changed, 15 insertions(+), 134 deletions(-) delete mode 100644 gerbonara/gerber/operations.py (limited to 'gerbonara') diff --git a/gerbonara/gerber/aperture_macros/expression.py b/gerbonara/gerber/aperture_macros/expression.py index 2375c56..f25fdd2 100644 --- a/gerbonara/gerber/aperture_macros/expression.py +++ b/gerbonara/gerber/aperture_macros/expression.py @@ -80,10 +80,10 @@ class UnitExpression(Expression): if self.unit is None or unit is None or self.unit == unit: return self._expr - elif unit == MM: + elif MM == unit: return self._expr * MILLIMETERS_PER_INCH - elif unit == Inch: + elif Inch == unit: return self._expr / MILLIMETERS_PER_INCH else: diff --git a/gerbonara/gerber/cam.py b/gerbonara/gerber/cam.py index 6fe5f9b..36e08ac 100644 --- a/gerbonara/gerber/cam.py +++ b/gerbonara/gerber/cam.py @@ -18,6 +18,8 @@ from dataclasses import dataclass from copy import deepcopy +from .utils import LengthUnit, MM, Inch + @dataclass class FileSettings: ''' @@ -31,15 +33,15 @@ class FileSettings: `zeros='trailing'` ''' notation : str = 'absolute' - unit : str = 'inch' + unit : LengthUnit = Inch angle_unit : str = 'degree' zeros : bool = None number_format : tuple = (2, 5) # input validation def __setattr__(self, name, value): - if name == 'unit' and value not in ['inch', 'mm']: - raise ValueError(f'Unit must be either "inch" or "mm", not {value}') + if name == 'unit' and value not in [MM, Inch]: + raise ValueError(f'Unit must be either Inch or MM, not {value}') elif name == 'notation' and value not in ['absolute', 'incremental']: raise ValueError(f'Notation must be either "absolute" or "incremental", not {value}') elif name == 'angle_unit' and value not in ('degree', 'radian'): diff --git a/gerbonara/gerber/gerber_statements.py b/gerbonara/gerber/gerber_statements.py index 55a4bf3..62aab3b 100644 --- a/gerbonara/gerber/gerber_statements.py +++ b/gerbonara/gerber/gerber_statements.py @@ -92,8 +92,7 @@ class ApertureMacroStmt(ParamStmt): self.macro = macro def to_gerber(self, settings): - unit = settings.unit if settings else None - return f'%AM{self.macro.name}*\n{self.macro.to_gerber(unit=unit)}*\n%' + return f'%AM{self.macro.name}*\n{self.macro.to_gerber(unit=settings.unit)}*\n%' def __str__(self): return f'' diff --git a/gerbonara/gerber/layers.py b/gerbonara/gerber/layers.py index c221324..35f2b00 100644 --- a/gerbonara/gerber/layers.py +++ b/gerbonara/gerber/layers.py @@ -295,7 +295,6 @@ class InternalLayer(PCBLayer): return (self.order <= other.order) class PCB: - @classmethod def from_directory(cls, directory, board_name=None, verbose=False): layers = [] diff --git a/gerbonara/gerber/operations.py b/gerbonara/gerber/operations.py deleted file mode 100644 index d06876e..0000000 --- a/gerbonara/gerber/operations.py +++ /dev/null @@ -1,126 +0,0 @@ -#!/usr/bin/env python -# -*- coding: utf-8 -*- - -# copyright 2015 Hamilton Kibbe -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at - -# http://www.apache.org/licenses/LICENSE-2.0 - -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -""" -CAM File Operations -=================== -**Transformations and other operations performed on Gerber and Excellon files** - -""" -import copy - - -def to_inch(cam_file): - """ Convert Gerber or Excellon file units to imperial - - Parameters - ---------- - cam_file : :class:`gerber.cam.CamFile` subclass - Gerber or Excellon file to convert - - Returns - ------- - cam_file : :class:`gerber.cam.CamFile` subclass - A deep copy of the source file with units converted to imperial. - """ - cam_file = copy.deepcopy(cam_file) - cam_file.to_inch() - return cam_file - - -def to_metric(cam_file): - """ Convert Gerber or Excellon file units to metric - - Parameters - ---------- - cam_file : :class:`gerber.cam.CamFile` subclass - Gerber or Excellon file to convert - - Returns - ------- - cam_file : :class:`gerber.cam.CamFile` subclass - A deep copy of the source file with units converted to metric. - """ - cam_file = copy.deepcopy(cam_file) - cam_file.to_metric() - return cam_file - - -def offset(cam_file, x_offset, y_offset): - """ Offset a Cam file by a specified amount in the X and Y directions. - - Parameters - ---------- - cam_file : :class:`gerber.cam.CamFile` subclass - Gerber or Excellon file to offset - - x_offset : float - Amount to offset the file in the X direction - - y_offset : float - Amount to offset the file in the Y direction - - Returns - ------- - cam_file : :class:`gerber.cam.CamFile` subclass - An offset deep copy of the source file. - """ - cam_file = copy.deepcopy(cam_file) - cam_file.offset(x_offset, y_offset) - return cam_file - - -def scale(cam_file, x_scale, y_scale): - """ Scale a Cam file by a specified amount in the X and Y directions. - - Parameters - ---------- - cam_file : :class:`gerber.cam.CamFile` subclass - Gerber or Excellon file to scale - - x_scale : float - X-axis scale factor - - y_scale : float - Y-axis scale factor - - Returns - ------- - cam_file : :class:`gerber.cam.CamFile` subclass - An scaled deep copy of the source file. - """ - # TODO - pass - - -def rotate(cam_file, angle): - """ Rotate a Cam file a specified amount about the origin. - - Parameters - ---------- - cam_file : :class:`gerber.cam.CamFile` subclass - Gerber or Excellon file to rotate - - angle : float - Angle to rotate the file in degrees. - - Returns - ------- - cam_file : :class:`gerber.cam.CamFile` subclass - An rotated deep copy of the source file. - """ - # TODO - pass diff --git a/gerbonara/gerber/utils.py b/gerbonara/gerber/utils.py index 533f0a2..f7df4ed 100644 --- a/gerbonara/gerber/utils.py +++ b/gerbonara/gerber/utils.py @@ -60,6 +60,13 @@ class LengthUnit: else: return id(self) == id(other) + # This class is a singleton, we don't want copies around + def __copy__(self): + return self + + def __deepcopy__(self, memo): + return self + MILLIMETERS_PER_INCH = 25.4 Inch = LengthUnit('inch', 'in', MILLIMETERS_PER_INCH) -- cgit