From 288ac27084b47166ac662402ea340d0aa25d8f56 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 04:31:23 -0500 Subject: Get unit conversion working for Gerber/Excellon files Started operations module for file operations/transforms --- gerber/operations.py | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 gerber/operations.py (limited to 'gerber/operations.py') diff --git a/gerber/operations.py b/gerber/operations.py new file mode 100644 index 0000000..9624a16 --- /dev/null +++ b/gerber/operations.py @@ -0,0 +1,120 @@ +#!/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 : `gerber.cam.CamFile` subclass + Gerber or Excellon file to convert + + Returns + ------- + gerber_file : `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 : `gerber.cam.CamFile` subclass + Gerber or Excellon file to convert + + Returns + ------- + gerber_file : `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 : `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 + ------- + gerber_file : `gerber.cam.CamFile` subclass + An offset deep copy of the source file. + """ + # TODO + pass + +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 : `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 + ------- + gerber_file : `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 : `gerber.cam.CamFile` subclass + Gerber or Excellon file to rotate + + angle : float + Angle to rotate the file in degrees. + + Returns + ------- + gerber_file : `gerber.cam.CamFile` subclass + An rotated deep copy of the source file. + """ + # TODO + pass -- cgit From 5966d7830bda7f37ed5ddcc1bfccb93e7f780eaa Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 23:13:23 -0500 Subject: Add offset operation --- gerber/operations.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'gerber/operations.py') diff --git a/gerber/operations.py b/gerber/operations.py index 9624a16..50df738 100644 --- a/gerber/operations.py +++ b/gerber/operations.py @@ -75,8 +75,9 @@ def offset(cam_file, x_offset, y_offset): gerber_file : `gerber.cam.CamFile` subclass An offset deep copy of the source file. """ - # TODO - pass + 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. -- cgit From 4db7302485e65937463c2efe3b3c2945549ca588 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Wed, 18 Feb 2015 23:23:53 -0500 Subject: Doc update --- gerber/operations.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'gerber/operations.py') diff --git a/gerber/operations.py b/gerber/operations.py index 50df738..4eb10e5 100644 --- a/gerber/operations.py +++ b/gerber/operations.py @@ -27,12 +27,12 @@ def to_inch(cam_file): Parameters ---------- - cam_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass Gerber or Excellon file to convert Returns ------- - gerber_file : `gerber.cam.CamFile` subclass + 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) @@ -44,12 +44,12 @@ def to_metric(cam_file): Parameters ---------- - cam_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass Gerber or Excellon file to convert Returns ------- - gerber_file : `gerber.cam.CamFile` subclass + 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) @@ -61,7 +61,7 @@ def offset(cam_file, x_offset, y_offset): Parameters ---------- - cam_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass Gerber or Excellon file to offset x_offset : float @@ -72,7 +72,7 @@ def offset(cam_file, x_offset, y_offset): Returns ------- - gerber_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass An offset deep copy of the source file. """ cam_file = copy.deepcopy(cam_file) @@ -84,7 +84,7 @@ def scale(cam_file, x_scale, y_scale): Parameters ---------- - cam_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass Gerber or Excellon file to scale x_scale : float @@ -95,7 +95,7 @@ def scale(cam_file, x_scale, y_scale): Returns ------- - gerber_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass An scaled deep copy of the source file. """ # TODO @@ -106,7 +106,7 @@ def rotate(cam_file, angle): Parameters ---------- - cam_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass Gerber or Excellon file to rotate angle : float @@ -114,7 +114,7 @@ def rotate(cam_file, angle): Returns ------- - gerber_file : `gerber.cam.CamFile` subclass + cam_file : :class:`gerber.cam.CamFile` subclass An rotated deep copy of the source file. """ # TODO -- cgit From 8cd842a41a55ab3d8f558a2e3e198beba7da58a1 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Manually mere rendering changes --- gerber/operations.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'gerber/operations.py') diff --git a/gerber/operations.py b/gerber/operations.py index 4eb10e5..d06876e 100644 --- a/gerber/operations.py +++ b/gerber/operations.py @@ -22,6 +22,7 @@ CAM File Operations """ import copy + def to_inch(cam_file): """ Convert Gerber or Excellon file units to imperial @@ -39,6 +40,7 @@ def to_inch(cam_file): cam_file.to_inch() return cam_file + def to_metric(cam_file): """ Convert Gerber or Excellon file units to metric @@ -56,6 +58,7 @@ def to_metric(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. @@ -79,6 +82,7 @@ def offset(cam_file, x_offset, y_offset): 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. @@ -101,6 +105,7 @@ def scale(cam_file, x_scale, y_scale): # TODO pass + def rotate(cam_file, angle): """ Rotate a Cam file a specified amount about the origin. -- cgit