-
-

This is the main file for camlib

-

Some text.

+
+

Camlib

+
+
+class camlib.Geometry
+
+
+bounds()
+

Returns coordinates of rectangular bounds +of geometry: (xmin, ymin, xmax, ymax).

+
+ +
+
+clear_polygon(polygon, tooldia, overlap=0.15)
+

Creates geometry inside a polygon for a tool to cover +the whole area.

+
+ +
+
+convert_units(units)
+

Converts the units of the object to units by scaling all +the geometry appropriately. This call scale(). Don’t call +it again in descendents.

+ +++ + + + + + + + +
Parameters:units (str) – “IN” or “MM”
Returns:Scaling factor resulting from unit change.
Return type:float
+
+ +
+
+from_dict(d)
+

Sets object’s attributes from a dictionary. +Attributes to include are listed in self.ser_attrs. +This method will look only for only and all the +attributes in self.ser_attrs. They must all +be present. Use only for deserializing saved +objects.

+ +++ + + + + + +
Parameters:d (dict) – Dictionary of attributes to set in the object.
Returns:None
+
+ +
+
+get_empty_area(boundary=None)
+

Returns the complement of self.solid_geometry within +the given boundary polygon. If not specified, it defaults to +the rectangular bounding box of self.solid_geometry.

+
+ +
+
+isolation_geometry(offset)
+

Creates contours around geometry at a given +offset distance.

+ +++ + + + + + + + +
Parameters:offset (float) – Offset distance.
Returns:The buffered geometry.
Return type:Shapely.MultiPolygon or Shapely.Polygon
+
+ +
+
+offset(vect)
+

Offset the geometry by the given vector. Override this method.

+ +++ + + + + + +
Parameters:vect (tuple) – (x, y) vector by which to offset the object.
Returns:None
+
+ +
+
+scale(factor)
+

Scales all of the object’s geometry by a given factor. Override +this method. +:param factor: Number by which to scale. +:type factor: float +:return: None +:rtype: None

+
+ +
+
+size()
+

Returns (width, height) of rectangular +bounds of geometry.

+
+ +
+
+to_dict()
+

Returns a respresentation of the object as a dictionary. +Attributes to include are listed in self.ser_attrs.

+ +++ + + + + + +
Returns:A dictionary-encoded copy of the object.
Return type:dict
+
+ +
+ +
+
+class camlib.Gerber(Geometry)
+

ATTRIBUTES

+
    +
  • apertures (dict): The keys are names/identifiers of each aperture. +The values are dictionaries key/value pairs which describe the aperture. The +type key is always present and the rest depend on the key:
  • +
+ ++++ + + + + + + + + + + + + + +
KeyValue
type(str) “C”, “R”, or “O”
othersDepend on type
+
    +
  • paths (list): A path is described by a line an aperture that follows that +line. Each paths[i] is a dictionary:
  • +
+ ++++ + + + + + + + + + + + + + +
KeyValue
linestring(Shapely.LineString) The actual path.
aperture(str) The key for an aperture in apertures.
+
    +
  • flashes (list): Flashes are single-point strokes of an aperture. Each +is a dictionary:
  • +
+ ++++ + + + + + + + + + + + + + +
KeyValue
loc(list) [x (float), y (float)] coordinates.
aperture(str) The key for an aperture in apertures.
+
    +
  • regions (list): Are surfaces defined by a polygon (Shapely.Polygon), +which have an exterior and zero or more interiors. An aperture is also +associated with a region. Each is a dictionary:
  • +
+ ++++ + + + + + + + + + + + + + +
KeyValue
polygon(Shapely.Polygon) The polygon defining the region.
aperture(str) The key for an aperture in apertures.
+
    +
  • flash_geometry (list): List of (Shapely) geometric object resulting +from flashes. These are generated from flashes in do_flashes().
  • +
  • buffered_paths (list): List of (Shapely) polygons resulting from +buffering (or thickening) the paths with the aperture. These are +generated from paths in buffer_paths().
  • +
+

USAGE:

+
g = Gerber()
+g.parse_file(filename)
+g.create_geometry()
+do_something(s.solid_geometry)
+
+
+
+
+aperture_parse(gline)
+

Parse gerber aperture definition into dictionary of apertures. +The following kinds and their attributes are supported:

+
    +
  • Circular (C): size (float)
  • +
  • Rectangle (R): width (float), height (float)
  • +
  • Obround (O): width (float), height (float).
  • +
+ +++ + + + + + + + +
Parameters:gline (str) – Line of Gerber code known to have an aperture definition.
Returns:Identifier of the aperture.
Return type:str
+
+ +
+
+buffer_paths()
+

This is part of the parsing process. “Thickens” the paths +by their appertures. This will only work for circular appertures. +:return: None

+
+ +
+
+create_geometry()
+

Geometry from a Gerber file is made up entirely of polygons. +Every stroke (linear or circular) has an aperture which gives +it thickness. Additionally, aperture strokes have non-zero area, +and regions naturally do as well.

+

:rtype : None +:return: None

+
+ +
+
+do_flashes()
+

Creates geometry for Gerber flashes (aperture on a single point).

+
+ +
+
+fix_regions()
+

Overwrites the region polygons with fixed +versions if found to be invalid (according to Shapely).

+
+ +
+
+frac_digits = None
+

Number of fraction digits in Gerber numbers. Used during parsing.

+
+ +
+
+get_bounding_box(margin=0.0, rounded=False)
+

Creates and returns a rectangular polygon bounding at a distance of +margin from the object’s solid_geometry. If margin > 0, the polygon +can optionally have rounded corners of radius equal to margin.

+ +++ + + + + + + + +
Parameters:
    +
  • margin (float) – Distance to enlarge the rectangular bounding +box in both positive and negative, x and y axes.
  • +
  • rounded (bool) – Wether or not to have rounded corners.
  • +
+
Returns:

The bounding box.

+
Return type:

Shapely.Polygon

+
+
+ +
+
+int_digits = None
+

Number of integer digits in Gerber numbers. Used during parsing.

+
+ +
+
+offset(vect)
+

Offsets the objects’ geometry on the XY plane by a given vector. +These are:

+
    +
  • paths
  • +
  • regions
  • +
  • flashes
  • +
+

Then buffered_paths, flash_geometry and solid_geometry +are re-created with self.create_geometry(). +:param vect: (x, y) offset vector. +:type vect: tuple +:return: None

+
+ +
+
+parse_file(filename)
+

Calls Gerber.parse_lines() with array of lines +read from the given file.

+
+ +
+
+parse_lines(glines)
+

Main Gerber parser. Reads Gerber and populates self.paths, self.apertures, +self.flashes, self.regions and self.units.

+ +++ + + + + + + + +
Parameters:glines (list) – Gerber code as list of strings, each element being +one line of the source file.
Returns:None
Return type:None
+
+ +
+
+scale(factor)
+

Scales the objects’ geometry on the XY plane by a given factor. +These are:

+
    +
  • apertures
  • +
  • paths
  • +
  • regions
  • +
  • flashes
  • +
+

Then buffered_paths, flash_geometry and solid_geometry +are re-created with self.create_geometry(). +:param factor: Number by which to scale. +:type factor: float +:rtype : None

+
+ +
+ +
+
+class camlib.Excellon
+

ATTRIBUTES

+
    +
  • tools (dict): The key is the tool name and the value is +the size (diameter).
  • +
  • drills (list): Each is a dictionary:
  • +
+ ++++ + + + + + + + + + + + + + +
KeyValue
point(Shapely.Point) Where to drill
tool(str) A key in tools
+
+
+offset(vect)
+

Offsets geometry on the XY plane in the object by a given vector.

+ +++ + + + + + +
Parameters:vect (tuple) – (x, y) offset vector.
Returns:None
+
+ +
+
+parse_file(filename)
+

Reads the specified file as array of lines as +passes it to parse_lines().

+ +++ + + + + + +
Parameters:filename (str) – The file to be read and parsed.
Returns:None
+
+ +
+
+parse_lines(elines)
+

Main Excellon parser.

+ +++ + + + + + +
Parameters:elines (list) – List of strings, each being a line of Excellon code.
Returns:None
+
+ +
+
+scale(factor)
+

Scales geometry on the XY plane in the object by a given factor. +Tool sizes, feedrates an Z-plane dimensions are untouched.

+ +++ + + + + + + + +
Parameters:factor (float) – Number by which to scale the object.
Returns:None
Return type:NOne
+
+ +
+ +
+
+class camlib.CNCjob(units='in', kind='generic', z_move=0.1, feedrate=3.0, z_cut=-0.002, tooldia=0.0)
+

Represents work to be done by a CNC machine.

+

ATTRIBUTES

+
    +
  • gcode_parsed (list): Each is a dictionary:
  • +
+ ++++ + + + + + + + + + + + + + +
KeyValue
geom(Shapely.LineString) Tool path (XY plane)
kind(string) “AB”, A is “T” (travel) or +“C” (cut). B is “F” (fast) or “S” (slow).
+
+
+gcode_parse()
+

G-Code parser (from self.gcode). Generates dictionary with +single-segment LineString’s and “kind” indicating cut or travel, +fast or feedrate speed.

+
+ +
+
+generate_from_excellon(exobj)
+

Generates G-code for drilling from Excellon object. +self.gcode becomes a list, each element is a +different job for each tool in the excellon code.

+
+ +
+
+generate_from_excellon_by_tool(exobj, tools='all')
+

Creates gcode for this object from an Excellon object +for the specified tools.

+ +++ + + + + + + + + + +
Parameters:
    +
  • exobj (Excellon) – Excellon object to process
  • +
  • tools – Comma separated tool names
  • +
+
Type:

tools: str

+
Returns:

None

+
Return type:

None

+
+
+ +
+
+generate_from_geometry(geometry, append=True, tooldia=None, tolerance=0)
+

Generates G-Code from a Geometry object. Stores in self.gcode.

+ +++ + + + + + + + +
Parameters:
    +
  • geometry (Geometry) – Geometry defining the toolpath
  • +
  • append (bool) – Wether to append to self.gcode or re-write it.
  • +
  • tooldia (bool) – If given, sets the tooldia property but does +not affect the process in any other way.
  • +
  • tolerance – All points in the simplified object will be within the +tolerance distance of the original geometry.
  • +
+
Returns:

None

+
Return type:

None

+
+
+ +
+
+linear2gcode(linear, tolerance=0)
+

Generates G-code to cut along the linear feature.

+ +++ + + + + + + + + + +
Parameters:
    +
  • linear – The path to cut along.
  • +
  • tolerance (float) – All points in the simplified object will be within the +tolerance distance of the original geometry.
  • +
+
Type:

Shapely.LinearRing or Shapely.Linear String

+
Returns:

G-code to cut alon the linear feature.

+
Return type:

str

+
+
+ +
+
+offset(vect)
+

Offsets all the geometry on the XY plane in the object by the +given vector.

+ +++ + + + + + +
Parameters:vect (tuple) – (x, y) offset vector.
Returns:None
+
+ +
+
+plot2(axes, tooldia=None, dpi=75, margin=0.1, color={'C': ['#5E6CFF', '#4650BD'], 'T': ['#F0E24D', '#B5AB3A']}, alpha={'C': 1.0, 'T': 0.3}, tool_tolerance=0.0005)
+

Plots the G-code job onto the given axes.

+ +++ + + + + + +
Parameters:
    +
  • axes – Matplotlib axes on which to plot.
  • +
  • tooldia – Tool diameter.
  • +
  • dpi – Not used!
  • +
  • margin – Not used!
  • +
  • color – Color specification.
  • +
  • alpha – Transparency specification.
  • +
  • tool_tolerance – Tolerance when drawing the toolshape.
  • +
+
Returns:

None

+
+
+ +
+
+polygon2gcode(polygon, tolerance=0)
+

Creates G-Code for the exterior and all interior paths +of a polygon.

+ +++ + + + + + + + +
Parameters:
    +
  • polygon (Shapely.Polygon) – A Shapely.Polygon
  • +
  • tolerance (float) – All points in the simplified object will be within the +tolerance distance of the original geometry.
  • +
+
Returns:

G-code to cut along polygon.

+
Return type:

str

+
+
+ +
+
+pre_parse(gtext)
+

Separates parts of the G-Code text into a list of dictionaries. +Used by self.gcode_parse().

+ +++ + + + +
Parameters:gtext – A single string with g-code
+
+ +
+
+scale(factor)
+

Scales all the geometry on the XY plane in the object by the +given factor. Tool sizes, feedrates, or Z-axis dimensions are +not altered.

+ +++ + + + + + + + +
Parameters:factor (float) – Number by which to scale the object.
Returns:None
Return type:None
+
+ +
+