The Piglet Drawing Editor

What is it?

Piglet is a 2-D engineering drawing editor that supports hierarchical object description. It is inspired by Hewlett-Packard's proprietary HP PIGLET (Personal Interactive Graphic Layout EdiTor), which later became the commercial Graffy editor by DURST CAD. As a past HP employee, I "cut my teeth" doing integrated circuit layouts on the HP Piglet editor, first on a stand-alone graphic system in 1984, moving to HP's Pascal workstation around 1986, and finally winding up on UNIX some years later. The UNIX port eventually became part of the Chipbuster IC layout system and mutated into a behemoth no longer attractive for general drawing application. Since I had become dependent on the expressiveness of the Piglet system for my own personal work, I have searched for an adequate open-source replacement for many years.

HP Piglet had several features that have been notably lacking in all the open source editors of which I am aware. Piglet attempts to combine these features into one clean open-source package in the hopes that the resulting tool will not only be useful, but will inspire adoption of the concepts into other editors. Piglet is a "from-scratch" implementation written under Linux without access to any line of HP or Agilent code. It is generally able to read archive files from both Graffy and HP Piglet with minor modifications. Piglet has been designed by reference to Graffy's published manuals, regression testing to make sure that it can read old archive files, and my memory of many years of chip layout.

Piglet design concepts

Perhaps Piglet's most important feature is unlimited-depth hierarchical definition of objects. If, for instance, a designer creates a drawing of a rivet, then the rivet "cell" can be added by name as an instance into another drawing. The reference remains "live", meaning in that any future change to the rivet cell will propagate through to all drawings which use the cell. Another way to say this is that any drawing made under Piglet is also a library cell. It can be added to any other drawing with arbitary scale, rotation, shearing or mirroring. The nesting level is unlimited meaning that library cells can call other library cells ad-infinitum. This capability is absolutely essential for any editor used for integrated circuit design. It is also very handy for architectural drawing.

Piglet also uses a human readable/writable textual description language for all drawings. Piglet currently uses a subset of the HP-EGS language. Designs can be entered graphically with the mouse, or as text commands into a shell window, or as a combination of mouse/menu picks and typed text. In fact, all mouse commands simply create tokens which get fed to the command parser, so that anything done with the mouse can equally be done with the text interface. This feature makes it easy for computer programs, such as perl or awk, to create devices algorithmically.

Piglet is also very serious about accuracy. If you are designing an IC which will cost $2M USD to fabricate, you have to precise. Piglet allows a fundamental resolution to be specified for the entire drawing. All coordinates then become a multiple of the base resolution. Piglet also snaps all mouse picks to a very flexible grid, making it easy to enforce design-rule constraints. Piglet's grid can be set to any multiple of the base resolution, set to be displayed at any desired multiple of the grid step, and can be centered at any offset. A common design technique is to use a fine grid for designing cells, and a coarser grid for placing cells at the chip level. Usually a very coarse grid is used for power bus routing and pad placement. Every drawing in Piglet saves the grid resolution so that it is automatically used every time a drawing is re-edited.

Why is it so darn simple?

Piglet is written in C with recourse to plain Xlib functions. It is amazing how little X code is required to support the required functionality. This makes Piglet easy to understand and a good vehicle for studying 2-D graphics techniques. Piglet's entire source code fits on a fraction of a floppy disk.

I purposely chose to not use any fancy graphics libraries (except for the couple hundred lines of Xlib code) so that Piglet would be maximally understandable and portable. There are so few editors that have good hierarchy, that I wanted to present the concepts as cleanly and simply as possible. Piglet is written to be a working tool and also an educational object. It is a playground for experimenting with parsers, 2-D graphics algorithms and hierarchical structures. It is my hope that others can use the ideas here and that they spread widely into other, more sophisticated tools.

I brought the idea of hierarchy in drawing editors up with several authors of PD drawing tools. In many cases, I got blank responses: "why would you want that?", "isn't that the same as just cutting and pasting a clip-art?". Very few people were able to grasp the concept or seemed interested in learning more. Hierarchical design is widely used, and arguably a requirement, in serious engineering editors, but is almost unknown in typical Windows-based slide-making drawing tools. Since my verbal explaination wasn't sufficient to entice anyone into reading the available literature on the subject, I felt that a demonstration editor was needed to explain the power of hierarchical description. Here it is - as simple and as modular as I have been capable of making it. Have fun!

Some Examples:

To explain hierarchy, let's actually implement the rivet example above. We'll define a rivet, use it to make a square patch, and then put four patches on a bigger panel. The following code snippets are copies of an actual interactive edit session. Let's first define a drawing of the rivet - a simple circle:

    MAIN> EDIT rivet;
    EDIT> ADD C1 0,0 0,1;
    ADD > SAVE;
    EDIT> EXIT;
    MAIN>

This bit of code creates a new cell definition with the "EDIT" edit command. Commands are terminated with semicolons. To the rivet cell, we ADD a circle on layer 1 (C1) at the origin (0,0), and with a radius of 1 unit. By default the different layers correspond to different colors and line types. We then save the cell and exit back to the main editor prompt. Notice how the prompts change to let you know what the parser is looking for...

We now can define a patch which will recursively include four rivets:

    MAIN> EDI patch;
    EDIT> ADD R2 -10,-10, 10,10;
    ADD>  ADD rivet :x0.5 -5,-5 5,5 -5,5 5,-5;
    ADD>  SAV;
    EDIT> EXI;
    MAIN>

We now have created a 20 x 20 panel with four rivets. Piglet accepts three letter abbreviations of all commands. The rivets are scaled to 0.5 units in diameter with the ":x0.5" scaling option. Next lets make a big bulkhead and put some patches on it:

    MAIN> EDI bulkhead;
    EDIT> ADD R3 -50,-50 50,50;
    ADD>  ADD patch -30,-30 30,30 -30,30 30,-30;
    ADD>  ADD rivet :x2 -45,-45 45,45 -45,45 45,-45;
    ADD>  SAV;
    EDIT> EXI;
    MAIN>
Here's our finished drawing of the bulkhead:

Image created by example code: