2016-03-30 14:15:25 +02:00
|
|
|
|
|
|
|
==========================
|
|
|
|
The boxes.Boxes main class
|
|
|
|
==========================
|
|
|
|
|
|
|
|
.. toctree::
|
|
|
|
:maxdepth: 2
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
There is basically one class that takes care of everything. You are
|
|
|
|
supposed to sub class it and implement the ``.__init__()`` and
|
|
|
|
``.render()`` method. This Boxes class keeps a cairo canvas object
|
|
|
|
(self.ctx) that all drawing is made on. In addition it keeps a couple
|
|
|
|
of global settings used for various drawing operations. See the
|
|
|
|
``.__init__()`` method for the details.
|
|
|
|
|
2016-03-30 14:15:25 +02:00
|
|
|
.. autoclass:: boxes.Boxes
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
And easier way to get started is using the
|
|
|
|
``boxes/generators/_template.py`` as a basis for your own generators.
|
2016-03-30 14:15:25 +02:00
|
|
|
|
|
|
|
Basic operation
|
|
|
|
---------------
|
|
|
|
.. automethod:: boxes.Boxes.__init__
|
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.parseArgs
|
|
|
|
.. automethod:: boxes.Boxes.render
|
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.open
|
|
|
|
.. automethod:: boxes.Boxes.close
|
|
|
|
|
|
|
|
|
|
|
|
Generating Parts
|
|
|
|
----------------
|
|
|
|
|
|
|
|
A couple of commands can create whole parts like walls. Typically the
|
|
|
|
sizes given are the inner dimmensions not including additional space
|
|
|
|
needed for burn compensation or joints.
|
|
|
|
|
2018-08-23 23:24:20 +02:00
|
|
|
Currently there are the following parts:
|
2016-03-30 14:15:25 +02:00
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.rectangularWall
|
2018-08-23 23:24:20 +02:00
|
|
|
.. automethod:: boxes.Boxes.flangedWall
|
|
|
|
.. automethod:: boxes.Boxes.rectangularTriangle
|
|
|
|
.. automethod:: boxes.Boxes.regularPolygonWall
|
2016-03-30 14:15:25 +02:00
|
|
|
.. automethod:: boxes.Boxes.roundedPlate
|
|
|
|
.. automethod:: boxes.Boxes.surroundingWall
|
|
|
|
|
2018-08-23 23:24:20 +02:00
|
|
|
Parts Class
|
|
|
|
...........
|
|
|
|
|
|
|
|
More parts are available in a separete class. An instance is available as
|
|
|
|
**Boxes.parts**
|
|
|
|
|
|
|
|
.. automethod:: boxes.parts.Parts.disc
|
|
|
|
.. automethod:: boxes.parts.Parts.waivyKnob
|
|
|
|
.. automethod:: boxes.parts.Parts.concaveKnob
|
|
|
|
.. automethod:: boxes.parts.Parts.ringSegment
|
|
|
|
|
|
|
|
|
|
|
|
There are a few parameter shared by many of those parts:
|
|
|
|
|
2016-03-30 14:15:25 +02:00
|
|
|
The callback parameter
|
|
|
|
......................
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
The callback parameter can take on of the following forms:
|
|
|
|
|
|
|
|
* A function (or bound method) that expects one parameter: the number of the side the callback is currently called for.
|
|
|
|
* A dict with some of the numbers of the sides as keys and functions without parameters as values.
|
|
|
|
* A list of functions without parameters. The list may contain None as place holder and be shorter than the number of sides.
|
|
|
|
|
|
|
|
The callback functions are called with the side of the part at the
|
|
|
|
positive x and y axis. If the edge uses up space this space is below
|
|
|
|
the x axis. You do not have to restore the coordinate settings in the
|
|
|
|
callback.
|
|
|
|
|
|
|
|
Instead of functions it can be handy to use a lambda expression
|
|
|
|
calling the one building block funtion you need (e.g. fingerHolesAt).
|
|
|
|
|
|
|
|
For your own parts you can use this helper function:
|
|
|
|
|
2016-03-30 14:15:25 +02:00
|
|
|
.. automethod:: boxes.Boxes.cc
|
2016-04-04 01:28:02 +02:00
|
|
|
|
|
|
|
For finding the right piece to the *callback* parameter this function is used:
|
|
|
|
|
2016-03-30 14:15:25 +02:00
|
|
|
.. automethod:: boxes.Boxes.getEntry
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
|
2016-03-30 14:15:25 +02:00
|
|
|
The move parameter
|
|
|
|
..................
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
For placing the parts the ``move`` parameter can be used. It is string
|
|
|
|
with space separated words - at most one of each of those options:
|
|
|
|
|
|
|
|
* left / right
|
|
|
|
* up / down
|
|
|
|
* only
|
|
|
|
|
|
|
|
If "only" is given the part is not drawn but only the move is
|
|
|
|
done. This can be useful to go in one direction after having placed
|
|
|
|
multiple parts in the other and have returned with ``.ctx.restore()``.
|
|
|
|
|
|
|
|
For implementing parts the following helper function can be used to
|
|
|
|
implement a ``move`` parameter:
|
|
|
|
|
2016-03-30 14:15:25 +02:00
|
|
|
.. automethod:: boxes.Boxes.move
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
It needs to be called before and after drawing the actual part with
|
|
|
|
the proper ``before`` paramter set.
|
|
|
|
|
2016-03-30 14:15:25 +02:00
|
|
|
The edges parameter
|
|
|
|
...................
|
2016-04-04 01:28:02 +02:00
|
|
|
|
|
|
|
The ``edges`` parameter needs to be an iterable of Edge instances to be
|
|
|
|
used as edges of the part. Instead of instances it is possible to pass
|
|
|
|
a single character that is looked up in the ``.edges`` dict. This
|
|
|
|
allows to pass a string with the desired characters per edge. By
|
|
|
|
default the following character are supported:
|
|
|
|
|
|
|
|
* e : straight edge
|
|
|
|
* E : as above but extended outside by one thickness
|
|
|
|
* f, F : finger joints
|
|
|
|
* h : edge with holes for finger joints
|
|
|
|
* d, D : dove tail joints
|
|
|
|
|
|
|
|
Generators can register their own Edges by putting them into the
|
|
|
|
``.edges`` dictionary.
|
|
|
|
|
|
|
|
Same applies to the parameters of ``.surroundingWall`` although they
|
|
|
|
denominate single edge (types) only.
|
2018-08-23 23:24:20 +02:00
|
|
|
|
|
|
|
PartsMatrix
|
|
|
|
-----------
|
|
|
|
|
|
|
|
To place many of the same part partMatrix can used:
|
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.partsMatrix
|
|
|
|
|
|
|
|
It creates one big block of parts. The move param treat this block like on big
|
|
|
|
part.
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
Navigation
|
|
|
|
----------
|
|
|
|
.. automethod:: boxes.Boxes.moveTo
|
2018-08-23 23:24:20 +02:00
|
|
|
.. automethod:: boxes.Boxes.moveArc
|
2016-04-04 01:28:02 +02:00
|
|
|
|
2018-08-23 23:24:20 +02:00
|
|
|
**Boxes.ctx.save()** allows to save (among other things) the current position.
|
|
|
|
**Boxes.ctx.restore()** restores the previously saved state. Always make sure
|
|
|
|
to have balanced calls to those two functions.
|
2016-04-04 01:28:02 +02:00
|
|
|
|
|
|
|
Turtle Graphics commands
|
|
|
|
------------------------
|
|
|
|
|
|
|
|
These commands all move the coordinate system with them.
|
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.edge
|
|
|
|
.. automethod:: boxes.Boxes.corner
|
|
|
|
.. automethod:: boxes.Boxes.curveTo
|
|
|
|
.. automethod:: boxes.Boxes.polyline
|
|
|
|
|
|
|
|
Special Functions
|
|
|
|
.................
|
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.bedBoltHole
|
|
|
|
|
|
|
|
Latch and Grip
|
|
|
|
..............
|
|
|
|
|
|
|
|
These should probably be Edge classes. But right now they are still functions.
|
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.grip
|
|
|
|
.. automethod:: boxes.Boxes.latch
|
|
|
|
.. automethod:: boxes.Boxes.handle
|
|
|
|
|
|
|
|
Draw Commands
|
|
|
|
-------------
|
|
|
|
|
|
|
|
These commands do not change the coordinate system but get the
|
|
|
|
coordinates passed as parameters. All of them are either som sort of
|
|
|
|
hole or text. These artefacts are placed somewhere independently of
|
|
|
|
some continuous outline of the part their on.
|
|
|
|
|
|
|
|
.. automethod:: boxes.Boxes.hole
|
|
|
|
.. automethod:: boxes.Boxes.rectangularHole
|
2018-08-23 23:24:20 +02:00
|
|
|
.. automethod:: boxes.Boxes.dHole
|
|
|
|
.. automethod:: boxes.Boxes.flatHole
|
2016-04-04 01:28:02 +02:00
|
|
|
.. automethod:: boxes.Boxes.text
|
|
|
|
.. automethod:: boxes.Boxes.NEMA
|
2018-08-23 23:24:20 +02:00
|
|
|
.. automethod:: boxes.Boxes.TX
|
|
|
|
.. automethod:: boxes.Boxes.flex2D
|
|
|
|
.. py:class:: NutHole
|
|
|
|
|
|
|
|
An instance is available as **boxes.Boxes.nutHole()**
|
2016-04-04 01:28:02 +02:00
|
|
|
|
2016-04-09 16:36:13 +02:00
|
|
|
An instance of
|
|
|
|
|
|
|
|
.. autoclass:: boxes.edges.FingerHoles
|
|
|
|
:noindex:
|
|
|
|
|
|
|
|
is accessible as **Boxes.fingerHolesAt**.
|
|
|
|
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
Hexagonal Hole patterns
|
|
|
|
.......................
|
|
|
|
|
2016-04-09 20:54:05 +02:00
|
|
|
Hexagonal hole patterns are one way to have some ventilation for
|
2016-04-04 01:28:02 +02:00
|
|
|
housings maded with Boxes.py. Right now both ``.rectangularWall()``
|
|
|
|
and ``.roundedPlate()`` do supports this pattern directly by passing
|
|
|
|
the parameters to the calls. For other use cases these more low level
|
|
|
|
methods can be used.
|
|
|
|
|
|
|
|
For now this is the only supported pattern for ventilation slots. More
|
|
|
|
may be added in the future.
|
|
|
|
|
2018-08-23 23:24:20 +02:00
|
|
|
There is a global Boxes.hexHolesSettings object that is used if no settings are
|
|
|
|
passed. It currently is just a tuple of (r, dist, style) defualting to
|
|
|
|
(5, 3, 'circle') but might be replace by a Settings instance in the future.
|
|
|
|
|
2016-04-04 01:28:02 +02:00
|
|
|
.. automethod:: boxes.Boxes.hexHolesRectangle
|
|
|
|
.. automethod:: boxes.Boxes.hexHolesCircle
|
|
|
|
.. automethod:: boxes.Boxes.hexHolesPlate
|
|
|
|
.. automethod:: boxes.Boxes.hexHolesHex
|