2 -----------------------------------------------------------------------------
4 An X11 drawing program [especially for circuit schematics]
5 Copyright (c) 2017 Tim Edwards
6 August 1993 -- April 2017
7 -----------------------------------------------------------------------------
9 This README file contains additional notes about the program which may or may
10 not be of interest to anyone.
11 -----------------------------------------------------------------------------
15 Versions beginning with 3.2 can be compiled with the ASG package,
16 or "Automatic Schematic Generation". The package is derived from SPAR,
17 written by Stephen Frezza (currently at Gannon University). SPAR is
18 based on the same "corner-stitched tile" structures used by the EDA
19 tool "magic", modified to encompass the probabilistic nature of auto-
20 routing. The ASG package currently supports (to a limited extent)
21 reading of SPICE files, but will eventually support EDIF netlist output
22 from Verilog (and possibly VHDL) for turning netlists into schematics.
23 Also, the ASG package will handle constrained moving, re-routing networks
24 in response to moving elements around the schematic drawing.
28 Versions beginning with 3.0 are part of a methodology known as
29 "ScriptEDA", a call to put major open-source EDA tools into a similar
30 framework under an interpreter, where most upper-level functions can be
31 written as scripts. My more narrowly-defined version of ScriptEDA is
32 called "toolscript". The rationale behind "toolscript" is to allow a
33 single interpreter to launch multiple EDA tools, such that a
34 single script can control multiple programs, bringing together layout
35 tools, schematic capture, simulation, and so forth, in a highly
36 integrated manner. "Toolscript" requires that each EDA tool should be
37 a shared-object library of routines, that each tool should have its
38 own command namespace, that each tool should launch itself from a
39 "start" command in its namespace, and that the "start" command
40 should return control to the interpreter such that the interpreter is
41 always available from the calling terminal. Applications are encouraged
42 to rely heavily on scripts for functions which do not require fast
43 execution. In particular, scripts should handle most input/output
44 functions, so that users can easily change file formats to suit their
45 needs. The GUI for toolscript applications should be written in Tk,
46 which integrates the graphics event loop with the interpreter, greatly
47 simplifying handling of the interaction between the two. To synchronize
48 the GUI with commands called from the command-line, each program should
49 have a "command tag" function which can associate a script procedure
50 with each command. These callback procedures can then be defined within
51 the GUI script to update the GUI in response to commands. Finally,
52 each application should redefine "printf" output statements to call the
53 corresponding output method for the intperpreter (e.g., "Tcl_Eval" for
54 compatibility with the "tkcon" console). This allows error and standard
55 output to be handled independently. Within "tkcon", stdout and stderr
56 are printed in blue and red, respectively, making the program output
59 The "toolscript" concept is ideally interpreter-independent. However,
60 due mostly to ease of implementation and syntactical issues, TCL has
61 ended up as the only supported interpreter. TCL calls are heavily
62 embedded in the source code, making it somewhat difficult to simply
63 add another interpreter. While XCircuit can be compiled with the Python
64 interpreter, it is embedded, not extended, and so does not follow the
65 principles of "toolscript".
69 This program was written with a number of things in mind. The major
70 point in writing it was that I found all of the drawing programs freely
71 distributed at the usual X11 ftp sources (ftp.uu.net, export.lcs.mit.edu,
72 etc.), which includes xpic and xfig, and even some other programs like
73 idraw and commercial programs like framemaker, were lacking in some manner.
74 Some of them, like xpic, are missing fundamental parts, while others, like
75 xfig and framemaker, have a cumbersome user interface and require
76 inordinately large amounts of time to create simple pictures. The really
77 powerful programs like Adobe Illustrator are, naturally, expensive.
78 There has been a long-standing tradition of making MacDraw lookalikes which
79 I find particularly disturbing, since a number of features of that GUI are
80 fundamentally screwed up, including the dependence on a black-and-white color
81 scheme for things such as grid lines and edit points which can make the screen
82 cluttered and difficult to work with. I have chosen to freely ignore all such
83 standards in cases where they seem to hinder rather than help the user.
84 Disclaimers: The above comments refer to versions of the abovementioned
85 programs available as of 1993 and do not necessarily reflect the programs'
86 current status. Particularly the latest (from 1995 or so) version of xfig
87 is quite good, though it continues to have a "MacDraw" feel to it. XCircuit's
88 schematic capture has always been secondary to its use for drawing, and
89 users may prefer programs such as "gschem" (by Ales Hvezda, part of gEDA)
90 that are more in keeping with "normal" standards for EDA software. Because
91 such programs exist, XCircuit's schematic capture, like its basic drawing
92 functions, often deviate from the norm to explore radical ideas. Among
93 XCircuit's "radical ideas" are automatic port finding, its parameterization
94 method, embedded output formatting directives, and (a recent addition)
95 automatic schematic (re)generation.
97 The principles of XCircuit are as follows:
99 A) Structural backbone
100 1) There are six drawing elements which are considered "primary".
101 These are as follows:
103 a) polygon (multiple lines which may or may not be closed and filled)
104 b) arc (ellipse segment which may be closed and/or filled as above)
106 d) curve (based on the PostScript "curveto" algorithm)
107 e) graphic (graphic image, e.g., from a PPM file)
108 f) object instance (see below)
110 2) There are two drawing elements which are considered "secondary", which
111 is to say, contain instances of primary elements. These are:
113 a) path (a connected series of polygons, arcs, and/or curves)
114 b) object (something containing polygons, arcs, labels,
115 curves, paths, and instances of other objects)
117 Each object is instanced by a primary element called the "object
118 instance", a self-contained unit which allows an object to be scaled,
119 rotated, and translated within another object. Since objects contain
120 object instances and object instances point to objects, there is a
121 two-step recursion which is central to the concept of xcircuit.
123 3) There is one primary object instance called the TopObject, which is
124 the program window, and its associated object, which is whatever
125 appears on the screen. TopObject is a pointer, so that any object
126 in memory may be the top object, allowing a push/pop edit stack.
127 All other objects are organized in an array of pointers called the
128 Library. The Library is filled on startup with the contents of a
129 Library file, and is expanded whenever a new object is created.
131 Actually, there are many different TopObjects, called "pages",
132 which can be switched between at will by typing the number of
133 the page, 1 through 9 and 0 for page 10, or through the "Page"
134 menu command, which allows access to as many pages as are
135 defined. The "load" and "save" commands act only on the
136 present page (unless multiple pages are loaded at a time), as
137 do all the drawing commands.
139 4) All elements allocate memory as they are created and release the
140 memory as they are destroyed, so the only limit on the number of
141 elements in a drawing is the memory of the workstation.
145 1) All input and output is in PostScript, albeit a version of PostScript
146 with extremely restricted syntax: xcircuit is in no sense a PS
147 interpreter! The primary element types are defined as procedures
148 in the PostScript prologue; all secondary elements are defined as
149 "def" structures in PostScript, the only restriction being that no
150 definition can be called before it is defined.
152 2) Output can be encapsulated or non-encapsulated ("full page"), and
153 can have multiple pages. All pages which declare the same
154 "filename" on the "output properties" window will be saved to
157 3) The current state of the program is captured from time to time
158 (default 10 minutes or 20 "significant" changes to the drawing)
159 in a temporary file. If XCircuit crashes, work can be recovered
160 by running "xcircuit" without arguments (i.e., without a specific
161 filename on the command line). This method makes the filename
162 transparent to the user, but the file can be found (on most
163 systems) as /tmp/XC??? where ??? is a randomly-generated number
164 that uniquely identifies the file.
166 4) Text is vector-drawn, in order to best match the flexibility of
167 PostScript, which unlike X11 allows text to be scaled to any size
168 and rotated to any orientation (modern font renderers can do this,
169 but are not good at fast on-the-fly rendering needed for a drawing
170 The quality of the vector-drawn text on the screen is relatively
171 poor; however, the end product of xcircuit is the PostScript file,
172 which does not suffer from those limitations. Text vectors are
173 xcircuit elements read from an xcircuit library file, with
174 encoding information read from a separate file.
176 5) X11 does not have any capability for generalized curves (splines).
177 Therefore, splines are constructed by an N-segment approximation
178 which internally looks like a polygon. The PostScript output is a
179 smooth curve instead of the approximation.
181 6) X11 does not have any capability for generalized ellipses (ellipses
182 under any rotation). Similarly to the splines, arcs are constructed
183 by an N-segment approximation.
185 7) Implementing all arcs and curves as N-segment approximation allows
186 the possibility of general paths, or sequences of polygons, arc
187 sections, and curves which form a path that can be bordered, closed
188 and/or filled like an individual arc, curve, or polygon.
190 8) Other than the qualitative appearance of the text, the screen output
191 of xcircuit is meant to be the closest possible match to the
192 rendering of the PostScript output. A PostScript hack allows
193 stipple pattern fills to be effectively "transparent" (something
194 that PostScript does not do naturally). However, the effect is
195 *extremely* device-dependent because it overrides the printer's
196 halftoning operators. One effect of this is that halftoning
197 will look abnormally large when viewed at screen resolutions,
198 e.g., with GhostScript.
202 1) The mouse button system and the object library are based on the
203 Caltech circuit-simulation program "log" (either "analog" or "diglog").
204 As is usual for most applications, mouse button 1 is used to select
205 things or cycle between selections, button 2 usually terminates a
206 command, and button 3 will abort a command. In addition, button 1
207 has a function called "hold", which occurs after the button has
208 been continually pressed for a short length of time (about 1/5 second).
209 As the name implies, "hold" grabs hold of an element which can then
210 be moved around the screen.
212 Because this program is tailored to circuit drawing, the most common
213 functions are drawing lines and moving object instances. Therefore,
214 these two functions are made directly available from the mouse
215 button 1 (after a "tap" or a "hold", respectively). The next most
216 common function is selection of elements singly or in groups.
217 Button 2 can be used to select an item if tapped, and if pressed
218 and held down, a box will be drawn and everything inside that box
219 selected when the button is released. All other commands are
220 available from the pulldown menus and/or from the keyboard as
221 single-key macros. Keyboard macros are quicker, since they act
222 on the present cursor position, whereas menu commands require an
225 From version 3.4, buttons and keys are handled identically by the
226 interface, with the "hold" function becoming a modifier like "shift"
227 or "control". All XCircuit functions can be arbitrarily bound to
228 any button or key. The button 1 binding corresponds to the drawing
229 mode. If button 1 is bound to function "Wire", then it works as
230 described above. If it is bound to "Arc", then button 1 can be
231 used to draw arcs, while the other functions remain the same.
233 2) The libraries are intended to provide a convenient way to store and
234 retrieve elements of a picture which will be used more than once.
235 For the application of circuit drawing, a built-in library provides
236 basic objects such as transistors, amplifiers, resistors, capacitors,
237 arrows, circles, power and ground symbols, and the like. This file
238 ("builtins.lps") is loaded on startup; the program first looks in
239 the current directory, and then searches in a given global directory
240 (something like ~cad/lib/xcircuit/) if it could not find it initially.
241 Thus each user can add to or modify the file of builtins to reflect
242 personal taste. Since the PostScript output contains all object
243 definitions, these changes to the built-in functions are inherently
244 transferrable. The program checks objects with the same name for
245 equivalence of their contents, and changes names as necessary to
248 An additional library, the user library, contains all of the
249 objects which are created (using the "make object" command)
250 during a session or objects which are loaded from a file but
251 do not belong to the built-in library. The user library can
252 be saved by itself and reloaded later either into the user
253 library or into the built-in library. This is the way to
254 create a personalized built-in library set.
256 3) In the non-TCL-based version of XCircuit, the special file
257 "startup.script" can be edited to include lines such as the
262 The loadlibrary command will automatically include another
263 library file. This method makes it convenient to divide up
264 libraries into separate files according to (for instance)
265 function (digital, analog, clip art, etc.), and use the
266 loadlibrary commands to choose which ones will be loaded
267 on startup. Caveat: If the order of loading is such that
268 an object contains an instance of another object which has
269 not yet been loaded, xcircuit will complain.
271 In the TCL-based version of XCircuit, the equivalent file is
272 "xcstartup.tcl" and the syntax is:
274 library n load filename
276 where "filename" is the name of the library file (e.g.,
277 "digital.lps"), and "n" is the library page number. By
278 specifying the same page as an existing library, a set of
279 objects can be appended to that library. "n" may also refer
280 to a library by name.
282 By default, libraries have the extension ".lps". As they
283 contain only macros, they cannot be displayed with any
284 PostScript interpreter.
286 4) Xcircuit has a strict sense of zooming and snap-to grid. Objects
287 scale absolutely; line widths and text sizes will increase/decrease
288 proportionally with the zoom, as well as dot/dash spacing and all
289 other features. Xcircuit does have a minimum integer grid in
290 coordinate space, which translates to 0.005 inches at an output scale
291 of 1. The maximum zoom scale gives a screen size translating to
292 about 100 by 100 inches at an output scale of 1. The effective
293 scale can be varied by changing the output scale (reached from the
294 "File/Write" menu selection) in order to fit a drawing to a page or
295 to get a grid matched to a specific dimension. A separate scale
296 parameter changes the scale of the reported position relative to
297 the output scale (as it will appear on a printed page).
299 5) The snap-to grid is an all-important feature for circuit drawing,
300 wherein it is critical that wires line up properly with one another.
301 In xcircuit, there is no way to get off the snap-to grid except by
302 turning the snap function off and physically pushing elements off
303 the grid. In any case, objects can always be returned to the snap
304 grid with the "snap" function (key 'S').
308 XCircuit implements a sophisticated schematic capture. Unlike
309 virtually all schematic capture software currently available,
310 xcircuit allows the designer to draw the circuit in a "natural"
311 way, making use both of schematic hierarchies and simple
312 hierarchies created simply by grouping elements together. If
313 the chosen netlist format is hierarchical (like SPICE), both
314 hierarchical forms will be retained in the output. For element
315 grouping, input/output ports connecting into to the group will
316 be determined automatically, from context.
318 Individual networks can be queried (key 'Alt-W') to highlight
319 the entire visible part of the network, with the network name
320 printed in the message window.
322 Any schematic can cover multiple pages. One page is marked as
323 "primary" and the others marked as "secondary". Netlists are
324 generated in the primary page object only, but incorporate
325 information from all the schematic pages. All pages which have
326 the same "page label" are considered to be part of the same
329 -----------------------------------------------------------------------------
332 Local: See the xcircuit manpage ("man xcircuit")
333 Online: http://opencircuitdesign.com/xcircuit/features.html
335 -----------------------------------------------------------------------------
337 Online tutorials: See
338 Standard: http://opencircuitdesign.com/xcircuit/tutorial/tutorial.html
339 Schematic capture: http://opencircuitdesign.com/xcircuit/tutorial/tutorial2.html
341 -----------------------------------------------------------------------------
343 Things to do: See the file "TODO"
345 -----------------------------------------------------------------------------