[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

gEDA-user: Python-based footprint creation library



This may be considered timely or untimely, given the various amusing
discussions of the merits of certain programming languages, both
serious and maliciously jestful ones, but I have just created a tiny
little Python library for creating PCB footprints.  It does
essentially the exact same thing that the m4 libraries do, except it's
in Python and so I can actually stand to look at the code for more
than a few minutes at a time without my head exploding.  (No offense
to anybody who may feel differently about m4.  This is clearly a
deficiency in my own cognitive abilities.)

You can get it, for what it's worth, at:
http://wonderclown.net/pcbelement/

The readme file purports to explain what I did and why, and to save me
needless extra typing, I'll just quote that here in its entirety:

----- readme.txt -----

This is a first quick stab at a Python library for creating
newlib-style elements for the PCB circuit board layout program
(http://pcb.sourceforge.net/).

This stuff isn't even pre-pre-pre-alpha.  It's just an idea put into
code, hastily written because I needed it, right at that moment, to
complete a project with an insane deadline.  It doesn't even have a
revision number, that's how not released it is.

You may or may not be able to find more information, including new
versions, at: http://wonderclown.net/pcbelement/

This "version" is released under the GPL.  I may release future
versions under a different license, because I can.  You can't.  That's
because I'm the copyright holder:

Copyright (C) 2005 Randall C. Nortman

WHY:

Because I really dislike the m4 syntax -- trying to follow the nested
levels of quoting makes my brain hurt.  Embedding mathematical
formulae is ugly.  Control structures are ugly.  Everything is ugly.
Python is pretty, and gives you all the expressive power you need to
do whatever you need to.

Of course, there is already an alternative to m4 -- you can draw the
elements by hand to create newlib-style footprints.  I tried this a
couple of times and found myself always ending up "roughing in" the
footprint graphically and then opening up the result in a text editor
in order to get more precise control over the dimensions and placement
of everything.  In the real world, you need this precise control in
all cases.  But doing all the math by hand takes way longer than
writing a program to do it, especially if you can write one program to
generate a whole class of components.  This is the wisdom of the m4
model.  But see above -- m4 is ugly.  Therefore, I turned to Python.

WHAT:

You won't find this very useful if you don't already know Python.  You
have to know Python at a basic level at least in order to even
understand the following, much less use this code.

The core module is pcbelement.py, a small Python library for creating
PCB elements.  It defines an Element class, plus Pad, Pin, and
ElementLine (i.e., silkscreen lines).  It is far from complete; it has
the features I needed to get my immediate task done and little more.

The other files - smtdil.py, 2pth.py, sot223.py, and rj45.py are
programs (or could be used as modules in another program) for
generating particular types of footprints, using the pcbelement
module.  They are the best source of documentation (by example,
mostly) about how to use this thing.  Some of them can handle an
entire family of similar types of footprints, and some (notably
rj45.py) are designed to produce exactly one particular footprint.

These programs all print the footprint to their standard output.  You
would use them by invoking them with appropriate arguments (those that
take arguments print help if you invoke them without arguments) and
redirecting output to a file in your local PCB elements directory.
The result is a newlib-style footprint which can be accessed by PCB
and also helper programs like gsch2pcb.

The output format is reverse-engineered from the current CVS code,
using what seems to be the most modern of the many formats that the
code will recognize -- the format it writes out itself when it saves.
This format is referred to as "hi_format" in the code.

THE FUTURE:

There's no reason these couldn't be used in the same way the m4
libraries are used -- a program like gsch2pcb could dynamically create
needed footprints by providing the necessary arguments to the Python
functions.  This could be done by invoking Python as an external
program, or by dynamically loading the Python modules within another
Python program (or program embedding a Python interpreter) and
invoking the functions directly.  Given that gsch2pcb is currently
written in Perl, I think invoking Python as an external program
would be more straightforward.

The core library needs to be made more feature-complete before this is
generally useful enough to warrant adapting other utilities to make
use of it.  An interface standard for scripts like gsch2pcb needs to
be set and followed in all of the functions that generate components.

Alternatively, I can just keep using it the way I'm using it, and
anybody else who would like to can do the same.  I would appreciate
hearing from anybody who finds this useful; I won't put my email
address here for all the world's spammers to see, but you can discover
how to contact me by visiting http://wonderclown.net/

----- end readme.txt -----


Make of it what you will,

Randall