Ekstatische Lyriken Pinnwand

Source Code for my PCB Editor

written by Pj on Saturday December 19th, 2015 -- 3:25 p.m.
in reply to New PCBs

edit this message - return to message index
(only moderators may edit messages)
I was going to keep my PCB editor to myself, using the distinctive design as my personal "trademark" for my own PCBs that I might sell, but honestly, when have I ever been so motivated to do anything?

I'm far more concerned that a hard drive failure might cause me to lose the code.  It took me months to get the algorithms that move the tracks around to behave reasonably.  I'd hate to have to do all of that shit over again.

So here's the code: 2015-12-19_PCB_Editor.tgz

If anyone wants to modify it, we'll say it's released under my antiviral license, except for the stb_image.c within the archive whose own license I obviously have no desire to modify.

As for how it works, prepare to be horrified:

PCB data is saved in "save.c" as C source code.  This is #include into the main "pcb.c" such that, when you recompile the executable, you create an executable that just has your PCB in it to begin with when you start the program.  It's presently compiled with the FT240X board above, in case anyone wants to play with it.

The user interface is such that even I can't use it without a cheat-sheet:

The arrow keys scroll the screen around.  Page up and page down change the zoom level.  Number keys 1 through 4 change the current layer.  The - and = keys change the current pad or track size, depending on which mode it is in.  It has four modes of operation, switched by pressing F1 through F4. 

F1 is "Pad Mode," in which left click will create a new pad, and right click will select an existing pad for editing purposes.  When creating a pad, it is created with the current pad radius (press - or = to adjust) and on the current layer (press 1 through 4 to adjust).  You can type some text to label it, but this text is just a label, it won't appear on the final PCB, and it's only visible when the current layer is 1 or 2, it disappears when set to layers 3 or 4 so that it doesn't interfere with viewing the silkscreen layers.  You can rotate the text with the "home" and "end" keys.  You can delete the pad by pressing the "delete" key while it is in editing mode.  Pressing enter removes the pad from editing mode.

F2 is "unanimated track mode", where you can simply draw lines with the mouse.  This is intended for drawing the silkscreen layer.  Holding the left mouse button allows you to draw a track.  Clicking the right mouse button deletes the closest track to the mouse pointer that is in the current layer. 

F3 is "pad move mode".  You start by click-and-drag to form a box around a bunch of pads.  Then use WASD to move those pads around.  Holding shift will move them faster.  Q and E will rotate them as a group.  Pressing G will align them to the current grid.  Another left click, for seemingly no reason, will de-select the pads, causing nothing more to happen when you press WASD until you draw another box.  This is quite confusing, so I'll probably make it so that another left click just lets you draw another box to select new pads, or perhaps to add to the current selection.

F4 is "animated track mode." You start by left-clicking on a pad, then slowly move the mouse towards another pad, and then left-click on it.  The track will slowly move to find the shortest path between those two pads. 

Pressing "." will toggle the visibility of the individual track points, which are constantly moving from source pad to destination pad.  In doing so, each point inevitably ends up taking a shortcut towards the next point, which is what causes the tracks to become shorter.  They are then repulsed by other tracks in the same layer and by pads in the same layer or on all layers.  (the smallest pads are on a specific layer, intended for making surface mount pads) Animated tracks on the silkscreen layers will repulse the board outline (the blue track you can't interact with), whereas unanimated tracks do not.

F5 toggles grid snap mode.  When in F1 mode, when grid snap mode is enabled, the arrow keys will move the screen by one grid unit, making it easy to create a lot of pads with just the keyboard.  Grid size is changed by [ and ] keys. 

F6 saves the current PCB to "save.c".  The entire program must then be recompiled in order to "load" this saved file.  Simply restarting the program will obviously leave you with the last version of the PCB that was compiled into it.

F7 through F12 control the animation of the tracks.  F7 & F8 control how much distance is between each animated point in the tracks.  F9 & F10 control the speed of the points.  F11 & F12 control the strength of the repulsive force that pads and other track points create.  Also, O and P control the clearance between tracks and pads that the program aims for.  I tried to make these controls "safe", but it is entirely possible that changing them will cause the track points to move in such a way that they all (literally all of them, not just a couple of them) tangle up within each other, so you should never play with these controls without saving the PCB first so that you can restore it if that happens. 

Pressing "M" causes the entire PCB to be mirrored.  This is so that you can draw silkscreen text on the back of the board without having to learn to draw text backwards.  Similarly, pressing "R" causes it to rotate 90 degrees so that you can write at other angles.  I suppose that mathematically this may slightly disturb the position of pads, but as all of the math is done with "float" variables, I can't imagine the error ever becomming sufficient that components no longer fit their pads.

Finally, IJKL work like arrow keys to shift the entire design on the screen.  This is because the darker black on the screen (whose size is compiled into the code) is the maximum size of the PCB that DirtyPCBs will create, and so to ensure that the design still fits, it needs to be arranged within that square.  As I would work on designs, I'd find them move out of that square, but still have plenty of space on the other side.  IJKL allwws the whole design to be shifted in the coordinate space easily.

Oh, and the Gerber files are created when you press F6 to save, in a subdirectory named "Gerbers."

Also, I'm pretty sure I just explained all of that for absolutely no one but maybe myself in the future.  If anyone actually ends up using this software, I'd love to hear about it.  Indeed, if I don't, then I probably won't bother to keep it up-to-date if I make future changes.


return to previous message - return to message index

Your Reply

Name: No registration necessary. Simply choose
a name and password and type them in.
You may want to read the rules before you spend a lot of time writing something.
Plain Text - What you type is what you will see.
Some HTML - Use this if you are including HTML tags.
Pure HTML - Copies your post directly into the web page.
first, then