summaryrefslogtreecommitdiff
path: root/gerber/cam.py
diff options
context:
space:
mode:
authorHamilton Kibbe <ham@hamiltonkib.be>2014-10-13 12:38:57 -0400
committerHamilton Kibbe <ham@hamiltonkib.be>2014-10-13 12:38:57 -0400
commit6adcdbae5fc06959203761616e778ba4594475cc (patch)
tree1b878d7fe63645899a0d631849596b70bd002b07 /gerber/cam.py
parent152fca07685d6f96f5e5bad723f1f62de99d8b7d (diff)
parent8c5c7ec8bbc8a074884ef04b566f9c0ecd6e78bb (diff)
downloadgerbonara-6adcdbae5fc06959203761616e778ba4594475cc.tar.gz
gerbonara-6adcdbae5fc06959203761616e778ba4594475cc.tar.bz2
gerbonara-6adcdbae5fc06959203761616e778ba4594475cc.zip
Merge branch 'master' of https://github.com/hamiltonkibbe/gerber-tools
Diffstat (limited to 'gerber/cam.py')
-rw-r--r--gerber/cam.py124
1 files changed, 124 insertions, 0 deletions
diff --git a/gerber/cam.py b/gerber/cam.py
new file mode 100644
index 0000000..e7a49d1
--- /dev/null
+++ b/gerber/cam.py
@@ -0,0 +1,124 @@
+#! /usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# copyright 2014 Hamilton Kibbe <ham@hamiltonkib.be>
+#
+# 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
+============
+**AM file classes**
+
+This module provides common base classes for Excellon/Gerber CNC files
+"""
+
+
+class FileSettings(object):
+ """ CAM File Settings
+
+ Provides a common representation of gerber/excellon file settings
+ """
+ def __init__(self, notation='absolute', units='inch',
+ zero_suppression='trailing', format=(2, 5)):
+ if notation not in ['absolute', 'incremental']:
+ raise ValueError('Notation must be either absolute or incremental')
+ self.notation = notation
+
+ if units not in ['inch', 'metric']:
+ raise ValueError('Units must be either inch or metric')
+ self.units = units
+
+ if zero_suppression not in ['leading', 'trailing']:
+ raise ValueError('Zero suppression must be either leading or \
+ trailling')
+ self.zero_suppression = zero_suppression
+
+ if len(format) != 2:
+ raise ValueError('Format must be a tuple(n=2) of integers')
+ self.format = format
+
+ def __getitem__(self, key):
+ if key == 'notation':
+ return self.notation
+ elif key == 'units':
+ return self.units
+ elif key == 'zero_suppression':
+ return self.zero_suppression
+ elif key == 'format':
+ return self.format
+ else:
+ raise KeyError()
+
+
+class CamFile(object):
+ """ Base class for Gerber/Excellon files.
+
+ Provides a common set of settings parameters.
+
+ Parameters
+ ----------
+ settings : FileSettings
+ The current file configuration.
+
+ filename : string
+ Name of the file that this CamFile represents.
+
+ layer_name : string
+ Name of the PCB layer that the file represents
+
+ Attributes
+ ----------
+ settings : FileSettings
+ File settings as a FileSettings object
+
+ notation : string
+ File notation setting. May be either 'absolute' or 'incremental'
+
+ units : string
+ File units setting. May be 'inch' or 'metric'
+
+ zero_suppression : string
+ File zero-suppression setting. May be either 'leading' or 'trailling'
+
+ format : tuple (<int>, <int>)
+ File decimal representation format as a tuple of (integer digits,
+ decimal digits)
+ """
+
+ def __init__(self, statements=None, settings=None, filename=None,
+ layer_name=None):
+ if settings is not None:
+ self.notation = settings['notation']
+ self.units = settings['units']
+ self.zero_suppression = settings['zero_suppression']
+ self.format = settings['format']
+ else:
+ self.notation = 'absolute'
+ self.units = 'inch'
+ self.zero_suppression = 'trailing'
+ self.format = (2, 5)
+ self.statements = statements if statements is not None else []
+ self.filename = filename
+ self.layer_name = layer_name
+
+ @property
+ def settings(self):
+ """ File settings
+
+ Returns
+ -------
+ settings : FileSettings (dict-like)
+ A FileSettings object with the specified configuration.
+ """
+ return FileSettings(self.notation, self.units, self.zero_suppression,
+ self.format)