<spanid="camlib"></span><h1>Camlib<aclass="headerlink"href="#module-camlib"title="Permalink to this headline">¶</a></h1>
<dlclass="class">
<dtid="camlib.Geometry">
<emclass="property">class </em><ttclass="descclassname">camlib.</tt><ttclass="descname">Geometry</tt><aclass="headerlink"href="#camlib.Geometry"title="Permalink to this definition">¶</a></dt>
<dd><dlclass="method">
<dtid="camlib.Geometry.bounds">
<ttclass="descname">bounds</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.Geometry.bounds"title="Permalink to this definition">¶</a></dt>
<dd><p>Returns coordinates of rectangular bounds
of geometry: (xmin, ymin, xmax, ymax).</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Geometry.clear_polygon">
<ttclass="descname">clear_polygon</tt><big>(</big><em>polygon</em>, <em>tooldia</em>, <em>overlap=0.15</em><big>)</big><aclass="headerlink"href="#camlib.Geometry.clear_polygon"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates geometry inside a polygon for a tool to cover
the whole area.</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Geometry.convert_units">
<ttclass="descname">convert_units</tt><big>(</big><em>units</em><big>)</big><aclass="headerlink"href="#camlib.Geometry.convert_units"title="Permalink to this definition">¶</a></dt>
<dd><p>Converts the units of the object to <ttclass="docutils literal"><spanclass="pre">units</span></tt> by scaling all
the geometry appropriately. This call <ttclass="docutils literal"><spanclass="pre">scale()</span></tt>. Don’t call
<ttclass="descname">from_dict</tt><big>(</big><em>d</em><big>)</big><aclass="headerlink"href="#camlib.Geometry.from_dict"title="Permalink to this definition">¶</a></dt>
<dd><p>Sets object’s attributes from a dictionary.
Attributes to include are listed in <ttclass="docutils literal"><spanclass="pre">self.ser_attrs</span></tt>.
This method will look only for only and all the
attributes in <ttclass="docutils literal"><spanclass="pre">self.ser_attrs</span></tt>. They must all
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>d</strong> (<em>dict</em>) – Dictionary of attributes to set in the object.</td>
<ttclass="descname">get_empty_area</tt><big>(</big><em>boundary=None</em><big>)</big><aclass="headerlink"href="#camlib.Geometry.get_empty_area"title="Permalink to this definition">¶</a></dt>
<dd><p>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.</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Geometry.isolation_geometry">
<ttclass="descname">isolation_geometry</tt><big>(</big><em>offset</em><big>)</big><aclass="headerlink"href="#camlib.Geometry.isolation_geometry"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates contours around geometry at a given
<trclass="field-odd field"><thclass="field-name">Return type:</th><tdclass="field-body">Shapely.MultiPolygon or Shapely.Polygon</td>
</tr>
</tbody>
</table>
</dd></dl>
<dlclass="method">
<dtid="camlib.Geometry.offset">
<ttclass="descname">offset</tt><big>(</big><em>vect</em><big>)</big><aclass="headerlink"href="#camlib.Geometry.offset"title="Permalink to this definition">¶</a></dt>
<dd><p>Offset the geometry by the given vector. Override this method.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>vect</strong> (<em>tuple</em>) – (x, y) vector by which to offset the object.</td>
<ttclass="descname">scale</tt><big>(</big><em>factor</em><big>)</big><aclass="headerlink"href="#camlib.Geometry.scale"title="Permalink to this definition">¶</a></dt>
<dd><p>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</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Geometry.size">
<ttclass="descname">size</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.Geometry.size"title="Permalink to this definition">¶</a></dt>
<dd><p>Returns (width, height) of rectangular
bounds of geometry.</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Geometry.to_dict">
<ttclass="descname">to_dict</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.Geometry.to_dict"title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a respresentation of the object as a dictionary.
Attributes to include are listed in <ttclass="docutils literal"><spanclass="pre">self.ser_attrs</span></tt>.</p>
<emclass="property">class </em><ttclass="descclassname">camlib.</tt><ttclass="descname">Gerber</tt><big>(</big><em>Geometry</em><big>)</big><aclass="headerlink"href="#camlib.Gerber"title="Permalink to this definition">¶</a></dt>
<dd><p><strong>ATTRIBUTES</strong></p>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">apertures</span></tt> (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:</li>
</ul>
<tableborder="1"class="docutils">
<colgroup>
<colwidth="24%"/>
<colwidth="76%"/>
</colgroup>
<theadvalign="bottom">
<trclass="row-odd"><thclass="head">Key</th>
<thclass="head">Value</th>
</tr>
</thead>
<tbodyvalign="top">
<trclass="row-even"><td>type</td>
<td>(str) “C”, “R”, or “O”</td>
</tr>
<trclass="row-odd"><td>others</td>
<td>Depend on <ttclass="docutils literal"><spanclass="pre">type</span></tt></td>
</tr>
</tbody>
</table>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">paths</span></tt> (list): A path is described by a line an aperture that follows that
line. Each paths[i] is a dictionary:</li>
</ul>
<tableborder="1"class="docutils">
<colgroup>
<colwidth="20%"/>
<colwidth="80%"/>
</colgroup>
<theadvalign="bottom">
<trclass="row-odd"><thclass="head">Key</th>
<thclass="head">Value</th>
</tr>
</thead>
<tbodyvalign="top">
<trclass="row-even"><td>linestring</td>
<td>(Shapely.LineString) The actual path.</td>
</tr>
<trclass="row-odd"><td>aperture</td>
<td>(str) The key for an aperture in apertures.</td>
</tr>
</tbody>
</table>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">flashes</span></tt> (list): Flashes are single-point strokes of an aperture. Each
is a dictionary:</li>
</ul>
<tableborder="1"class="docutils">
<colgroup>
<colwidth="20%"/>
<colwidth="80%"/>
</colgroup>
<theadvalign="bottom">
<trclass="row-odd"><thclass="head">Key</th>
<thclass="head">Value</th>
</tr>
</thead>
<tbodyvalign="top">
<trclass="row-even"><td>loc</td>
<td>(list) [x (float), y (float)] coordinates.</td>
</tr>
<trclass="row-odd"><td>aperture</td>
<td>(str) The key for an aperture in apertures.</td>
</tr>
</tbody>
</table>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">regions</span></tt> (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:</li>
</ul>
<tableborder="1"class="docutils">
<colgroup>
<colwidth="18%"/>
<colwidth="82%"/>
</colgroup>
<theadvalign="bottom">
<trclass="row-odd"><thclass="head">Key</th>
<thclass="head">Value</th>
</tr>
</thead>
<tbodyvalign="top">
<trclass="row-even"><td>polygon</td>
<td>(Shapely.Polygon) The polygon defining the region.</td>
</tr>
<trclass="row-odd"><td>aperture</td>
<td>(str) The key for an aperture in apertures.</td>
</tr>
</tbody>
</table>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">flash_geometry</span></tt> (list): List of (Shapely) geometric object resulting
from <ttclass="docutils literal"><spanclass="pre">flashes</span></tt>. These are generated from <ttclass="docutils literal"><spanclass="pre">flashes</span></tt> in <ttclass="docutils literal"><spanclass="pre">do_flashes()</span></tt>.</li>
<li><ttclass="docutils literal"><spanclass="pre">buffered_paths</span></tt> (list): List of (Shapely) polygons resulting from
<em>buffering</em> (or thickening) the <ttclass="docutils literal"><spanclass="pre">paths</span></tt> with the aperture. These are
generated from <ttclass="docutils literal"><spanclass="pre">paths</span></tt> in <ttclass="docutils literal"><spanclass="pre">buffer_paths()</span></tt>.</li>
<ttclass="descname">aperture_parse</tt><big>(</big><em>gline</em><big>)</big><aclass="headerlink"href="#camlib.Gerber.aperture_parse"title="Permalink to this definition">¶</a></dt>
<dd><p>Parse gerber aperture definition into dictionary of apertures.
The following kinds and their attributes are supported:</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>gline</strong> (<em>str</em>) – Line of Gerber code known to have an aperture definition.</td>
</tr>
<trclass="field-even field"><thclass="field-name">Returns:</th><tdclass="field-body">Identifier of the aperture.</td>
<ttclass="descname">buffer_paths</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.Gerber.buffer_paths"title="Permalink to this definition">¶</a></dt>
<dd><p>This is part of the parsing process. “Thickens” the paths
by their appertures. This will only work for circular appertures.
:return: None</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Gerber.create_geometry">
<ttclass="descname">create_geometry</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.Gerber.create_geometry"title="Permalink to this definition">¶</a></dt>
<dd><p>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.</p>
<p>:rtype : None
:return: None</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Gerber.do_flashes">
<ttclass="descname">do_flashes</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.Gerber.do_flashes"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates geometry for Gerber flashes (aperture on a single point).</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Gerber.fix_regions">
<ttclass="descname">fix_regions</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.Gerber.fix_regions"title="Permalink to this definition">¶</a></dt>
<dd><p>Overwrites the region polygons with fixed
versions if found to be invalid (according to Shapely).</p>
</dd></dl>
<dlclass="attribute">
<dtid="camlib.Gerber.frac_digits">
<ttclass="descname">frac_digits</tt><emclass="property"> = None</em><aclass="headerlink"href="#camlib.Gerber.frac_digits"title="Permalink to this definition">¶</a></dt>
<dd><p>Number of fraction digits in Gerber numbers. Used during parsing.</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Gerber.get_bounding_box">
<ttclass="descname">get_bounding_box</tt><big>(</big><em>margin=0.0</em>, <em>rounded=False</em><big>)</big><aclass="headerlink"href="#camlib.Gerber.get_bounding_box"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates and returns a rectangular polygon bounding at a distance of
margin from the object’s <ttclass="docutils literal"><spanclass="pre">solid_geometry</span></tt>. If margin > 0, the polygon
can optionally have rounded corners of radius equal to margin.</p>
<ttclass="descname">int_digits</tt><emclass="property"> = None</em><aclass="headerlink"href="#camlib.Gerber.int_digits"title="Permalink to this definition">¶</a></dt>
<dd><p>Number of integer digits in Gerber numbers. Used during parsing.</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Gerber.offset">
<ttclass="descname">offset</tt><big>(</big><em>vect</em><big>)</big><aclass="headerlink"href="#camlib.Gerber.offset"title="Permalink to this definition">¶</a></dt>
<dd><p>Offsets the objects’ geometry on the XY plane by a given vector.
<p>Then <ttclass="docutils literal"><spanclass="pre">buffered_paths</span></tt>, <ttclass="docutils literal"><spanclass="pre">flash_geometry</span></tt> and <ttclass="docutils literal"><spanclass="pre">solid_geometry</span></tt>
are re-created with <ttclass="docutils literal"><spanclass="pre">self.create_geometry()</span></tt>.
:param vect: (x, y) offset vector.
:type vect: tuple
:return: None</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Gerber.parse_file">
<ttclass="descname">parse_file</tt><big>(</big><em>filename</em><big>)</big><aclass="headerlink"href="#camlib.Gerber.parse_file"title="Permalink to this definition">¶</a></dt>
<dd><p>Calls Gerber.parse_lines() with array of lines
read from the given file.</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.Gerber.parse_lines">
<ttclass="descname">parse_lines</tt><big>(</big><em>glines</em><big>)</big><aclass="headerlink"href="#camlib.Gerber.parse_lines"title="Permalink to this definition">¶</a></dt>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>glines</strong> (<em>list</em>) – Gerber code as list of strings, each element being
<ttclass="descname">scale</tt><big>(</big><em>factor</em><big>)</big><aclass="headerlink"href="#camlib.Gerber.scale"title="Permalink to this definition">¶</a></dt>
<dd><p>Scales the objects’ geometry on the XY plane by a given factor.
<p>Then <ttclass="docutils literal"><spanclass="pre">buffered_paths</span></tt>, <ttclass="docutils literal"><spanclass="pre">flash_geometry</span></tt> and <ttclass="docutils literal"><spanclass="pre">solid_geometry</span></tt>
are re-created with <ttclass="docutils literal"><spanclass="pre">self.create_geometry()</span></tt>.
:param factor: Number by which to scale.
:type factor: float
:rtype : None</p>
</dd></dl>
</dd></dl>
<dlclass="class">
<dtid="camlib.Excellon">
<emclass="property">class </em><ttclass="descclassname">camlib.</tt><ttclass="descname">Excellon</tt><aclass="headerlink"href="#camlib.Excellon"title="Permalink to this definition">¶</a></dt>
<dd><p><em>ATTRIBUTES</em></p>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">tools</span></tt> (dict): The key is the tool name and the value is
the size (diameter).</li>
<li><ttclass="docutils literal"><spanclass="pre">drills</span></tt> (list): Each is a dictionary:</li>
</ul>
<tableborder="1"class="docutils">
<colgroup>
<colwidth="31%"/>
<colwidth="69%"/>
</colgroup>
<theadvalign="bottom">
<trclass="row-odd"><thclass="head">Key</th>
<thclass="head">Value</th>
</tr>
</thead>
<tbodyvalign="top">
<trclass="row-even"><td>point</td>
<td>(Shapely.Point) Where to drill</td>
</tr>
<trclass="row-odd"><td>tool</td>
<td>(str) A key in <ttclass="docutils literal"><spanclass="pre">tools</span></tt></td>
</tr>
</tbody>
</table>
<dlclass="method">
<dtid="camlib.Excellon.offset">
<ttclass="descname">offset</tt><big>(</big><em>vect</em><big>)</big><aclass="headerlink"href="#camlib.Excellon.offset"title="Permalink to this definition">¶</a></dt>
<dd><p>Offsets geometry on the XY plane in the object by a given vector.</p>
<ttclass="descname">parse_file</tt><big>(</big><em>filename</em><big>)</big><aclass="headerlink"href="#camlib.Excellon.parse_file"title="Permalink to this definition">¶</a></dt>
<dd><p>Reads the specified file as array of lines as
passes it to <ttclass="docutils literal"><spanclass="pre">parse_lines()</span></tt>.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>filename</strong> (<em>str</em>) – The file to be read and parsed.</td>
<ttclass="descname">parse_lines</tt><big>(</big><em>elines</em><big>)</big><aclass="headerlink"href="#camlib.Excellon.parse_lines"title="Permalink to this definition">¶</a></dt>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>elines</strong> (<em>list</em>) – List of strings, each being a line of Excellon code.</td>
<ttclass="descname">scale</tt><big>(</big><em>factor</em><big>)</big><aclass="headerlink"href="#camlib.Excellon.scale"title="Permalink to this definition">¶</a></dt>
<dd><p>Scales geometry on the XY plane in the object by a given factor.
Tool sizes, feedrates an Z-plane dimensions are untouched.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>factor</strong> (<em>float</em>) – Number by which to scale the object.</td>
<emclass="property">class </em><ttclass="descclassname">camlib.</tt><ttclass="descname">CNCjob</tt><big>(</big><em>units='in'</em>, <em>kind='generic'</em>, <em>z_move=0.1</em>, <em>feedrate=3.0</em>, <em>z_cut=-0.002</em>, <em>tooldia=0.0</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob"title="Permalink to this definition">¶</a></dt>
<dd><p>Represents work to be done by a CNC machine.</p>
<p><em>ATTRIBUTES</em></p>
<ulclass="simple">
<li><ttclass="docutils literal"><spanclass="pre">gcode_parsed</span></tt> (list): Each is a dictionary:</li>
<td>(string) “AB”, A is “T” (travel) or
“C” (cut). B is “F” (fast) or “S” (slow).</td>
</tr>
</tbody>
</table>
<dlclass="method">
<dtid="camlib.CNCjob.gcode_parse">
<ttclass="descname">gcode_parse</tt><big>(</big><big>)</big><aclass="headerlink"href="#camlib.CNCjob.gcode_parse"title="Permalink to this definition">¶</a></dt>
<dd><p>G-Code parser (from self.gcode). Generates dictionary with
single-segment LineString’s and “kind” indicating cut or travel,
fast or feedrate speed.</p>
</dd></dl>
<dlclass="method">
<dtid="camlib.CNCjob.generate_from_excellon">
<ttclass="descname">generate_from_excellon</tt><big>(</big><em>exobj</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.generate_from_excellon"title="Permalink to this definition">¶</a></dt>
<dd><p>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.</p>
<ttclass="descname">generate_from_excellon_by_tool</tt><big>(</big><em>exobj</em>, <em>tools='all'</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.generate_from_excellon_by_tool"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates gcode for this object from an Excellon object
<ttclass="descname">generate_from_geometry</tt><big>(</big><em>geometry</em>, <em>append=True</em>, <em>tooldia=None</em>, <em>tolerance=0</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.generate_from_geometry"title="Permalink to this definition">¶</a></dt>
<dd><p>Generates G-Code from a Geometry object. Stores in <ttclass="docutils literal"><spanclass="pre">self.gcode</span></tt>.</p>
<ttclass="descname">linear2gcode</tt><big>(</big><em>linear</em>, <em>tolerance=0</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.linear2gcode"title="Permalink to this definition">¶</a></dt>
<dd><p>Generates G-code to cut along the linear feature.</p>
<ttclass="descname">offset</tt><big>(</big><em>vect</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.offset"title="Permalink to this definition">¶</a></dt>
<dd><p>Offsets all the geometry on the XY plane in the object by the
<ttclass="descname">polygon2gcode</tt><big>(</big><em>polygon</em>, <em>tolerance=0</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.polygon2gcode"title="Permalink to this definition">¶</a></dt>
<dd><p>Creates G-Code for the exterior and all interior paths
<ttclass="descname">pre_parse</tt><big>(</big><em>gtext</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.pre_parse"title="Permalink to this definition">¶</a></dt>
<dd><p>Separates parts of the G-Code text into a list of dictionaries.
Used by <ttclass="docutils literal"><spanclass="pre">self.gcode_parse()</span></tt>.</p>
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>gtext</strong>– A single string with g-code</td>
</tr>
</tbody>
</table>
</dd></dl>
<dlclass="method">
<dtid="camlib.CNCjob.scale">
<ttclass="descname">scale</tt><big>(</big><em>factor</em><big>)</big><aclass="headerlink"href="#camlib.CNCjob.scale"title="Permalink to this definition">¶</a></dt>
<dd><p>Scales all the geometry on the XY plane in the object by the
given factor. Tool sizes, feedrates, or Z-axis dimensions are
<trclass="field-odd field"><thclass="field-name">Parameters:</th><tdclass="field-body"><strong>factor</strong> (<em>float</em>) – Number by which to scale the object.</td>