1 \input texinfo @c -*-texinfo-*-
2 @setfilename geda-scheme.info
4 @documentencoding utf-8
5 @dircategory The Algorithmic Language Scheme
7 * gEDA Scheme: (geda-scheme). gEDA extensibility with Guile Scheme.
9 @settitle gEDA Scheme Reference Manual @value{VERSION}
12 This manual is for gEDA/gaf, version @value{VERSION}.
14 Copyright @copyright{} 2011-2013 Peter TB Brett
16 The text of and illustrations in this document are licensed under a
17 Creative Commons Attribution–Share Alike 3.0 Unported license
18 ("CC-BY-SA"). An explanation of CC-BY-SA is available at
19 @uref{http://creativecommons.org/licenses/by-sa/3.0/}. The original
20 authors of this document designate the gEDA Project as the
21 "Attribution Party" for purposes of CC-BY-SA. In accordance with
22 CC-BY-SA, if you distribute this document or an adaptation of it, you
23 must provide the URL for the original version.
27 @title gEDA Scheme Reference Manual
28 @author Peter TB Brett
31 @vskip 0pt plus 1filll
40 @top gEDA Scheme Reference Manual
47 * Schematic Document Model::
48 * Core API Reference::
49 * gschem API Reference::
57 @unnumbered Introduction
61 @dfn{gEDA}, or @emph{GPL Electronic Design Automation}, is a suite of
62 free software tools for designing electronics. The gEDA project has
63 produced and continues working on a full GPL'd suite and toolkit of
64 Electronic Design Automation (EDA) tools. These tools are used for
65 electrical circuit design, schematic capture, simulation, prototyping,
66 and production. Currently, the gEDA project offers a mature suite of
67 free software applications for electronics design, including schematic
68 capture, attribute management, bill of materials (BOM) generation,
69 netlisting into over 20 netlist formats, analog and digital
70 simulation, and printed circuit board (PCB) layout.
72 The gEDA project was started because of the lack of free EDA tools for
73 POSIX systems with the primary purpose of advancing the state of free
74 hardware or open source hardware. The suite is mainly being developed
75 on the GNU/Linux platform with some development effort going into
76 making sure the tools run on other platforms as well.
78 @section About the gEDA Scheme API
80 The @dfn{gEDA Scheme API}, documented in this manual, is a set of
81 Scheme functions which can be used to enhance gEDA applications by
82 adding new functionality or modify existing behaviour.
84 gEDA has always used a Scheme interpreter for interpreting
85 configuration files, managing keybindings in gschem, and implementing
86 netlist exporter backends in gnetlist. However, for a long time the
87 utility of embedding a Scheme interpreter was diminished by the lack
88 of a low-level API for inspecting and modifying schematic documents.
89 The Scheme types and functions documented here were added to gEDA to
92 gEDA uses the @emph{Guile} Scheme implementation (otherwise known as
93 the @emph{GNU Ubiquitous Intelligent Language for Extensions}) as its
94 embedded Scheme. For more information about Guile, please visit
95 @uref{http://www.gnu.org/s/guile/}.
97 @section Getting Additional Help
98 @cindex Reporting bugs
100 If you think you have found a bug, please file a bug report in
101 Launchpad: @uref{http://bugs.launchpad.net/geda}. Please add the tag
102 @samp{scheme-api}. It will help us to fix your bug quickly if you can
103 describe in detail how to reproduce the bug.
105 If you have a question about using gEDA, or about extending gEDA using
106 Scheme, you may wish to send a message to one of the gEDA mailing
107 lists. You may also find additional information in the gEDA
110 Both the mailing lists and wiki can be accessed from the main gEDA
111 website: @uref{http://gpleda.org/}.
113 @section We Need Feedback!
115 If you find a typographical error in this manual, or if you have
116 thought of a way to make this manual better, we would love to hear
117 from you! Please submit a report in Launchpad:
118 @uref{http://bugs.launchpad.net/geda}, with the tag @samp{scheme-api}.
120 @node Schematic Document Model
121 @chapter The Schematic Document Model
123 When using gEDA to design an electronic circuit, users use the
124 schematic editor, gschem, to choose and place @emph{schematic symbols}
125 on a @emph{schematic page}, and connect the @emph{pins} of the symbols
126 together by drawing @emph{nets}. The user may add various
127 @emph{attributes} to symbols, nets or pins to modify how the circuit
128 diagrams should be interpreted. The resulting schematics are then
129 processed with the gnetlist tool to generate a @emph{netlist}.
131 This chapter describes the different data types used by the Scheme API
132 to represent gEDA documents (both schematics and symbols), and how
133 they relate to each other.
138 * Component objects::
140 * Coordinate system::
149 Schematics and symbols are presented as different types of document to
150 the user, with different file extensions, icons and mime-types.
151 However, when they are loaded into a gEDA application such as gschem
152 for editing, they are internally represented in exactly the same way,
153 by the @code{page} type. The @code{page} is the top-level gEDA document
156 Internally, the main difference between a @code{page} for a schematic
157 and a @code{page} for a symbol is the types of schematic element they
158 are permitted to contain (@pxref{Objects}). For example, a symbol is
159 not permitted to contain nets, buses, or instances of other symbols,
160 and a schematic is not permitted to contain pins.
162 @strong{Note}: Although the restrictions on what types of primitive
163 element schematics and symbols may contain are not enforced by the
164 API, designs which violate these restrictions may cause the netlister
165 not to work as expected.
167 Each @code{page} is associated with a filename, although the filename is
168 not required by the API either to be valid or to be associated with a
169 accessible file in the filesystem.
171 Pages are not garbage-collected; once you create a @code{page}, you are
172 responsible for making sure that it is disposed of when it is no
178 @cindex Schematic elements
180 Each @code{page} contains some number of @dfn{schematic elements},
181 represented by the @code{object} type. There are several sub-types of
182 @code{object}, including:
186 graphical lines, circles, arcs, rectangles and paths;
201 and symbol instances, known as 'components'.
204 Each @code{object} can be part of at most a single @code{page} -- they
205 cannot be shared between pages. @code{object}s are automatically
208 Most of different @code{object} sub-types are quite straightforward to
209 understand. The main exceptions are components, and the text
210 @code{object}-based attribute mechanism, which are described in the
213 @node Component objects
214 @section Component objects
216 @cindex Component library
217 @cindex Embedded component
219 When a symbol is instantiated in a schematic (e.g. by the user
220 selecting it from the gschem component library and placing it on the
221 page), a compound @code{object} known as a @dfn{component} is created.
223 Like a @code{page}, a component contains some number of @code{object}
224 elements. When a component is created from a symbol, the contents of
225 the symbol's @code{page} are copied into the component.
227 In order to allow the component to appear in the correct place on the
228 schematic page, at the correct orientation, etc., a transformation is
229 applied to every @code{object} in the component.
231 Normally, when the schematic @code{page} is closed, the parameters of
232 the transformation are stored in the schematic file along with the
233 basename of the original symbol, but the @code{object} contents of the
234 component are discarded. When the schematic is subsequently
235 re-opened, the original symbol is retrieved from the component
236 library, and used to recreate the component.
238 However, a component may optionally be @emph{embedded}. In this case,
239 its contents @emph{are} stored in the schematic file.
241 @strong{Note}: A component cannot contain another component -- only
242 other types of @code{object}.
247 @cindex Attribute format
249 A gEDA user is able to annotate schematic elements with additional
250 data, such as footprints for components or net names for nets. This
251 is carried out using @dfn{attributes}.
253 An attribute is text @code{object} which contains a text string in the
254 form @samp{@var{name}=@var{value}}. Currently, the restrictions on
255 attribute format that are enforced by the API are:
259 Attribute @var{name}s:
263 must contain at least one character;
265 must not contain a @samp{=} character (Unicode @code{U+003D});
267 must not end with a space (@samp{ }, Unicode @code{U+0020}).
271 Attribute @var{value}s:
275 must contain at least one character;
277 must not begin with a space (@samp{ }, Unicode @code{U+0020}).
281 @strong{Note}: Due to assumptions made by some gEDA tools, it is
282 @emph{strongly recommended} that you use attribute @var{name}s which
283 contain only lower-case Latin characters, decimal digits, full stops
284 @samp{.} (@code{U+002E}), and hyphens @samp{-} (@code{U+002D}).
286 There are two types of attribute:
288 @cindex Attached attribute
289 @emph{Attached attributes} are attribute text @code{object}s that are
290 linked to another @code{object}. To attach an attribute to another
291 schematic element, both @code{object}s must be part of the same
292 component or part of the same @code{object}. For example, a
293 @samp{netname=@var{name}} attribute attached to a net @code{object}
294 can be used to give that net a specific name in netlist output, such
295 as @samp{VCC} or @samp{GND}.
297 @cindex Floating attribute
298 @emph{Floating attributes} are attribute text @code{object}s that are
299 not linked to another @code{object}. These attributes affect the
300 schematic or symbol that they're part of as a whole. For example, a
301 floating @samp{documentation=@var{url}} attribute in a symbol tells
302 gschem's @strong{Help → Component Documentation} command how to find
303 the component's data sheet.
305 @node Coordinate system
306 @section Coordinate system
308 gEDA documents use a @dfn{coordinate system} (internally referred to
309 as `world' coordinates) with coordinates increasing upwards and to the
310 right (i.e. a conventional right-handed Cartesian coordinate
313 Although all coordinates may be positive or negative, gschem only
314 displays objects with positive coordinates (i.e. in the upper right
315 quadrant of the coordinate system). It is therefore recommended to
316 use only positive coordinates.
318 In the Scheme API, the coordinate of a point is expressed in the format:
324 and a set of @dfn{bounds} (i.e. a rectangular area in the document
325 plane) is expressed in the format:
328 ((left . top) . (right . bottom))
331 where @code{left} is the smaller x coordinate, @code{right} is the
332 larger x coordinate, and @code{bottom} and @code{top} are respectively
333 the smaller and larger y coordinates.
335 @node Core API Reference
336 @chapter Core API Reference
338 The Scheme modules and functions described in this chapter are
339 primitive operations for working with schematics and symbols, and are
340 available to be used in all gEDA applications.
343 * Core page functions::
344 * Core object functions::
345 * Core attribute functions::
346 * Configuration functions::
347 * System information::
350 @node Core page functions
351 @section Core page functions
353 To use the functions described in this section, you will need to load
354 the @code{(geda page)} module.
359 Returns @samp{#t} if and only if @var{obj} is a @code{page}.
363 Returns a list of all open @code{page}s.
366 @subsection Page creation, disposal and filenames
368 Every @code{page} is associated with a @emph{filename}. The filename
369 does not necessarily have to be a file which exists and/or is
370 accessible in the filesystem.
372 @defun make-page filename
373 Creates and returns a new, empty @code{page}, with the given
374 string @var{filename}.
377 @defun close-page! page
378 Destroys @var{page}. The returned value is undefined.
380 @strong{Warning}: This function closes and destroys @var{page}
381 immediately, regardless of whether the page has been modified since
382 loading or saving, and without asking the user.
385 @defun page-filename page
386 Returns the filename associated with @var{page} as a string.
389 @defun set-page-filename! page filename
390 Sets the filename of @var{page} to @var{filename}. Returns
394 @subsection Page serialisation
396 Pages can be converted to and from strings in the gEDA schematic file
399 @defun string->page filename string
400 Parses @var{string}, which should be in the gEDA file format, to
401 create a new @code{page}. The initial filename for the new
402 @code{page} is @var{filename}.
404 If the string is not in gEDA format, raises an @code{string-format} error.
407 @defun page->string page
408 Returns a string representation of @var{page} in the gEDA file
412 @subsection Page contents
414 A schematic or symbol @code{page} is composed of a set of
415 @code{object}s which determine both its graphical appearance and its
418 @defun page-contents page
419 Returns a list of the @code{object}s which make up @var{page}. The
420 list can be freely modified without changing the contents of
424 @defun page-append! page objects...
425 Appends zero or more @var{objects} to the contents of @var{page} in
426 the order given. Returns @var{page}.
428 If any of the @var{objects} is already part of a @code{page} other
429 than @var{page}, or is part of a component @code{object}, raises an
430 @code{object-state} error. Any of the @var{objects} that are already
431 in the @var{page} are ignored.
434 @defun page-remove! page objects...
435 Removes zero or more @var{objects} from the contents of @var{page}.
438 Any @var{objects} that are not part of a @code{page} or component
439 @code{object} are ignored.
441 An @samp{object-state} error will be thrown if any of the
442 @var{objects} satisfies any of the following conditions:
446 part of a @code{page} other than @var{page};
448 part of component @code{object};
450 has attached attributes (@pxref{Attributes});
452 is attached as an attribute.
456 @defun object-page object
457 Returns the @code{page} which contains @var{object} (either directly
458 or indirectly), or @samp{#f} if @var{object} is not part of a
461 @strong{Note}: If the @var{object} argument to @code{object-page} is
462 part of a component @code{object} which is itself part of a
463 @code{page}, that @code{page} will be returned.
466 @subsection Page dirty flags
468 A @code{page} has a @emph{dirty flag} that is used to indicate to
469 applications that the @code{page} has been modified since it was last
472 @defun page-dirty? page
473 Returns @samp{#t} if the @var{page}'s page has been marked as dirty;
474 otherwise, returns @samp{#f}.
477 @defun set-page-dirty! page [state]
478 Sets the dirty flag for @var{page}. If @var{state} is @samp{#f},
479 clears the dirty flag; otherwise, or if @var{state} is omitted, marks
480 the page as dirty. Returns @var{page}.
483 @node Core object functions
484 @section Core object functions
486 To use the functions described in this section, you will need to load
487 the @code{(geda object)} module.
490 * General object functions::
503 @node General object functions
504 @subsection General object functions
507 Returns @samp{#t} if and only if @var{obj} is an @code{object}.
510 @defun copy-object object
511 Returns a deep copy of @var{object}. The new @code{object} returned
512 has no attached attributes, and is not part of a @code{page} or part
513 of a component @code{object}.
516 @defun object-component object
517 Returns the component @code{object} that contains @var{object}, or
518 @samp{#f} if @var{object} is not part of a component.
521 @defun object-connections object
522 Returns a list of other @code{object}s that are @emph{directly}
523 connected to @var{object}. If @code{object} is not included in a
524 @code{page}, raises an @samp{object-state} error. The connections
525 reported are independent of inclusion in components.
527 For example, consider a page containing a net and a component, and the
528 component contains a single pin. If the connectable end of the pin
529 intersects the net, then @code{(object-connections <net>)} will return
530 a list containing the pin @code{object}, and @emph{not} the component.
535 * Object transformations::
538 * Object fill and stroke::
541 @node Object sub-types
542 @subsubsection Object sub-types
544 Schematic element @code{object}s come in several subtypes.
546 @defun object-type object
547 Returns the sub-type of @var{object} as a symbol. The subtype will be
548 one of the following symbols:
560 @samp{complex} (indicates a component @code{object})
576 @defun object-type? object type
577 Returns @samp{#t} if and only if @var{object} is an @code{object} and
578 that its subtype is @var{type}, which should be a symbol.
581 @node Object transformations
582 @subsubsection Object transformations
584 Objects can be translated, rotated, or mirrored about a point.
586 @defun translate-objects! vector [objects...]
587 Translate @var{objects} by @var{vector}, a world coordinate distance
588 in the form @samp{(x . y)}. Returns a list of the modified
592 @defun rotate-objects! center angle [objects...]
593 Translate @var{objects} anti-clockwise by @var{angle} about
594 @var{center}, a world coordinate position in the form @samp{(x . y)}.
595 @var{angle} must be an integer multiple of 90 degrees. Returns a list
596 of the modified @var{objects}.
599 @defun mirror-objects! x-offset [objects...]
600 Mirror @var{objects} in the line @samp{x = @var{x-offset}}. Returns a
601 list of the modified @var{objects}.
605 @subsubsection Object bounds
607 The bounds of an object is the smallest bounding rectangle of the
608 object, expressed in document coordinates (@pxref{Coordinate system}).
610 @defun object-bounds objects...
611 Returns the world coordinate bounding box containing all of the
612 @var{objects} passed as arguments, or @samp{#f} if none of the
613 @var{objects} have bounds (for example, this can occur if no
614 @var{objects} are specified, or if they are all empty component
617 @strong{Note}: @code{object-bounds} always returns the actual bounds
618 of the @var{objects}, not the visible bounds. This means that the bounds of
619 invisible text is always included.
622 @defun fold-bounds bounds...
623 Calculates the union of several sets of @var{bounds} (as returned by
624 @code{object-bounds}). If any of the @var{bounds} are @samp{#f}, they
625 are skipped; if all of the @var{bounds} are @samp{#f}, @samp{#f} is
630 @subsubsection Object color
632 Object colors in gEDA documents are specified as indices into a color
633 map. This allows users to specify the color map that suits them when
634 viewing schematics and symbols.
636 @defun object-color object
637 Returns the integer color map index of the color used to draw
641 @defun set-object-color! object color
642 Sets the integer color map index for @var{object} to @var{color}.
643 Returns @var{object}.
646 @node Object fill and stroke
647 @subsubsection Object fill and stroke
649 Graphical object subtypes -- lines, boxes, circles, arcs and paths --
650 are drawn with a stroke pattern that can be configured in detail.
652 @defun object-stroke object
653 Returns the stroke settings of the @var{object}, which must be a line,
654 box, circle, arc or path @code{object}. The return value is a list of
659 stroke width, as an integer number of world units
661 cap style, one of the symbols @code{none}, @code{square} or
664 dash style, one of the symbols @code{solid}, @code{dotted},
665 @code{dashed}, @code{center} or @code{phantom}.
667 up to two dash parameters, depending on the dash style:
670 for solid lines, no parameters;
672 for dotted lines, dot spacing;
674 for other styles, dot/dash spacing and dash length.
679 @defun set-object-stroke! object width cap dash [dash-space [dash-length]]
680 Set the stroke settings of the @var{object}, which must be a line,
681 box, circle, arc or path @code{object}. The arguments are the same as
682 the contents of the list returned by @code{object-stroke}. Returns
686 @defun object-stroke-width object
687 Returns the integer stroke width of @var{object}, which must be a
688 line, box, circle, arc or path @code{object}.
691 @defun object-stroke-cap object
692 Returns the stroke cap style of @var{object}, which must be a line,
693 box, circle, arc or path @code{object}. The returned value is one of
694 the symbols @code{none}, @code{square} or @code{round}.
697 @defun object-stroke-dash object
698 Returns the dash style of @var{object}, which must be a line, box,
699 circle, arc or path @code{object}. The return value is a list of
700 between one and three parameters:
704 dash style, one of the symbols @code{solid}, @code{dotted},
705 @code{dashed}, @code{center} or @code{phantom}.
707 for styles other than @code{solid}, dot/dash spacing;
709 for @code{dashed}, @code{center} and @code{phantom}, dash length.
713 Some types of @code{object} -- boxes, circles and paths -- can have
714 their interiors filled with a variety of patterns.
716 @defun object-fill object
717 Returns the fill settings of @var{object}, which must be a box, circle
718 or path @code{object}. The return value is a list of one to six
723 fill style, one of the symbols @code{hollow}, @code{solid},
724 @code{mesh} or @code{hatch};
726 up to five fill parameters, depending on fill style:
729 none for @code{hollow} or @code{solid} fills;
731 line width, line angle (in degrees) and line spacing for @code{hatch} fills;
733 line width, first angle and spacing, and second angle and spacing for
739 @defun set-object-fill! object fill-type . fill-args
740 Sets the fill settings of @var{object}, which must be a box, circle or
741 path @code{object}. The arguments are the same as the contents of the
742 list returned by @code{object-fill}. Returns @var{object}.
747 Line @code{object}s are straight graphical line segments with no
748 electrical meaning. A line's geometrical parameters are a start point
749 and end point, and it supports different colors and stroke styles.
751 Many of the functions for manipulating lines are also used to
752 manipulate line-like objects such as nets, buses or pins.
755 Returns @samp{#t} if and only if @var{object} is a line @code{object}.
758 @defun make-line start end [color]
759 Creates and returns a new line @code{object}. @var{start} is the
760 position of the start of the new line in the form @code{(x . y)} and
761 @var{end} is the position of end of the line. If @var{color} is
762 specified, it should be the integer color map index of the color with
763 which to draw the line. If @var{color} is not specified, the default
767 @defun set-line! line start end [color]
768 Sets the parameters of @var{line} (which may be a line, net, bus or
769 pin @code{object}). The arguments are the same as to
770 @code{make-line}. Returns @var{line}.
773 @defun line-info line
774 Returns the parameters of @var{line} (which may be a line, net, bus or
775 pin @code{object}). The return value is a list in the form:
778 ((start-x . start-y) (end-x . end-y) color)
781 @strong{Note}: For pin @code{object}s, first coordinate is the
782 connectable point on the pin.
785 @defun line-start line
786 Returns the position @samp{(x . y)} of the start of @var{line} (which
787 may be a line, net, bus or pin @code{object}). For pin
788 @code{objects}, this is the position of the connectable point on the
793 Returns the position @samp{(x . y)} of the end of @var{line} (which
794 may be a line, net, bus or pin @code{object}).
798 @subsection Nets and buses
800 Net and bus @code{object}s are straight line segments which represent
801 electrical connectivity. Nets represent single wires, and buses
802 multi-wire connections of arbitrary composition.
804 All of the functions that work on line @code{object}s also work with
805 nets and buses (@pxref{Lines}). Note that @code{line?} will return
806 @code{#f} if called with a net or bus argument.
809 Returns @samp{#t} if and only if @var{object} is a net.
812 @defun make-net start end [color]
813 Creates and returns a new net @code{object}. @var{start} is the
814 position of the start of the new net in the form @code{(x . y)} and
815 @var{end} is the position of end of the net. If @var{color} is
816 specified, it should be the integer color map index of the color with
817 which to draw the net. If @var{color} is not specified, the default
822 Returns @samp{#t} if and only if @var{object} is a bus.
825 @defun make-bus start end [color]
826 Creates and returns a new bus @code{object}. Arguments are as for
833 Pin @code{objects} are straight line segments which represent
834 connectable points in symbols or subcircuits, such as the pins of a
835 semiconductor package. Only one end of a pin can be connected to
836 nets, buses or other pins; the rest of a pin is purely graphical.
838 Pins come in two varieties: @dfn{net pins} and @dfn{bus pins}, which
839 are used for connections to nets and buses respectively (@pxref{Nets
842 All of the functions that work on line @code{object}s also work with
843 pins (@pxref{Lines}). Note that @code{line?} will return @code{#f} if
844 called with a pin argument.
847 Returns @samp{#t} if and only if @var{object} is a pin @code{object}.
850 @defun net-pin? object
851 Returns @samp{#t} if and only if @var{object} is a net pin.
854 @defun make-net-pin start end [color]
855 Creates and returns a new net pin @code{object}. @var{start} is the
856 position of the start of the new pin (the connectable end) in the form
857 @code{(x . y)} and @var{end} is the position of end of the pin. If
858 @var{color} is specified, it should be the integer color map index of
859 the color with which to draw the pin. If @var{color} is not
860 specified, the default pin color is used.
863 @defun bus-pin? object
864 Returns @samp{#t} if and only if @var{object} is a bus pin.
867 @defun make-bus-pin start end [color]
868 Creates and returns a new bus pin @code{object}. Arguments are as for
875 Boxes are rectangles specified by the coordinates of their top left
876 and bottom right corners. They are purely graphical, and have no
877 electrical meaning. They can be drawn in different colors, and with
878 various stroke and fill settings.
881 @xref{Object fill and stroke}.
884 Returns @samp{#t} if and only of @var{object} is a box @code{object}.
887 @defun make-box top-left bottom-right [color]
888 Creates and returns a new box @code{object}. @var{top-left} is the
889 position of the top left of the new box in the form @code{(x . y)},
890 and @var{bottom-right} is the position of the bottom right of the box.
891 If @var{color} is specified, it should be the integer color map index
892 of the color with which to draw the box. If @var{color} is not
893 specified, the default box color is used.
896 @defun set-box! box top-left bottom-right [color]
897 Sets the parameters of @var{box}. The arguments are the same as to
898 @code{make-box}. Returns @var{box}.
902 Returns the parameters of @var{box}. The return value is a list in the form:
905 ((top-left-x . top-left-y) (bottom-right-x . bottom-right-y) color)
909 @defun box-top-left box
910 Returns the position of the top left corner of @var{box} in the form
914 @defun box-bottom-right box
915 Returns the position of the bottom right corner of @var{box} in the
922 Circle @code{objects} are specified by center position and radius, and
923 are purely graphical with no electrical meaning. They can be drawn in
924 different colors, and with various stroke and fill settings.
927 @xref{Object fill and stroke}.
929 @defun circle? object
930 Returns @samp{#t} if and only of @var{object} is a circle @code{object}.
933 @defun make-circle center radius [color]
934 Creates and returns a new circle @code{object}. @var{center} is the
935 position of the center of the new circle in the form @code{(x . y)},
936 and @var{radius} is the integer radius of the circle. If @var{color}
937 is specified, it should be the integer color map index of the color
938 with which to draw the circle. If @var{color} is not specified, the
939 default circle color is used.
942 @defun set-circle! circle center radius [color]
943 Sets the parameters of @var{circle}. The arguments are the same as to
944 @code{make-circle}. Returns @var{circle}.
947 @defun circle-info circle
948 Returns the parameters of @var{circle} as a list of the form:
951 ((center-x . center-y) radius color)
955 @defun circle-center circle
956 Returns the position of the center of @var{circle} as in the form
960 @defun circle-radius circle
961 Returns the radius of @var{circle} as an integer.
966 Arc @code{objects} are specified by center position, radius, and start
967 and end angles. They are purely graphical with no electrical
968 meaning. They can be drawn in different colors, and with various
972 Returns @samp{#t} if and only if @var{object} is an arc @code{object}.
975 @defun make-arc center radius start-angle end-angle [color]
976 Creates and returns a new arc @code{object}. @var{center} is the
977 position of the center of the new arc in the form @code{(x . y)}, and
978 @var{radius} is the integer radius of the arc. @var{start-angle} and
979 @var{end-angle} are the angles at which to start and end the arc, in
980 degrees. If @var{color} is specified, it should be the integer color
981 map index of the color with which to draw the arc. If @var{color}
982 is not specified, the default arc color is used.
985 @defun set-arc! arc center radius start-angle end-angle [color]
986 Sets the parameters of @var{arc}. The arguments are the same as to
987 @code{make-arc}. Returns @var{arc}.
991 Returns the parameters of @var{arc} as a list of the form:
994 ((center-x . center-y) radius start-angle end-angle color)
998 @defun arc-center arc
999 Returns the position of the center of @var{arc} in the form
1003 @defun arc-radius arc
1004 Returns the radius of @var{arc} as an integer.
1007 @defun arc-start-angle arc
1008 Returns the start angle of @var{arc} as an integer number of degrees.
1011 @defun arc-end-angle arc
1012 Returns the end angle of @var{arc} as an integer number of degrees.
1018 Paths are arbitrary shapes comprised of straight lines and BĂ©zier
1019 curves. Each path contains a sequence of @emph{path elements}, each
1020 of which requires zero or more absolute position parameters. The
1021 element types supported by gEDA are:
1025 @samp{moveto} elements represent a step (without drawing) to another
1026 point in the schematic, and begin a new subpath. @samp{moveto}
1027 elements need a single position parameter, which is the position of
1028 the endpoint of the move.
1030 @samp{lineto} elements draw a straight line from the current point to
1031 the point specified by a single position parameter.
1033 @samp{curveto} elements draw a BĂ©zier curve from the current point.
1034 The curve requires three position parameters: the position of the
1035 first control point; the position of the second control point; and the
1036 endpoint of the curve.
1038 @samp{closepath} elements close the current subpath by drawing a
1039 straight line from the current point to the subpath's initial point.
1040 They take no parameters.
1044 Returns @samp{#t} if and only if @var{object} is a path @code{object}.
1047 @defun path-length path
1048 Returns the number of path elements in @var{path}.
1051 @defun path-ref path K
1052 Returns the @var{K}th element in @var{path}. The return value is a
1053 list. The first item in the list is a symbol indicating the type of
1054 element, and any additional items are the position parameters of the
1055 element. For example, a call to @code{path-ref} might return:
1058 (curveto (800 . 525) (700 . 700) (500 . 700))
1061 If @var{K} is not a valid offset into @var{path}, raises an
1062 @samp{out-of-range} error.
1065 @defun path-remove! path K
1066 Removes the @var{K}th element in @var{path}, returning @var{path}. If
1067 @var{K} is not a valid offset, raises an @samp{out-of-range} error.
1070 @defun path-insert! path K type [positions...]
1071 Inserts a new element into @var{path} at index @var{K}. @var{type} is
1072 a symbol indicating the type of element to insert, using the
1073 parameters @var{positions}. If @var{K} is less than zero or greater
1074 than the number of elements @var{path} already contains, the new
1075 element is appended to the path. For example, to append a straight
1076 line section to the current path:
1079 (path-insert! path -1 'lineto '(500. 100))
1084 @subsection Pictures
1086 A picture object displays an image in the schematic, and is a purely
1087 graphical element. Pictures may be in any format supported by the
1088 user's GdkPixbuf installation (but note that images that can't be
1089 loaded for some reason are preserved). The @var{top-left},
1090 @var{bottom-right}, @var{angle} and @var{mirror} properties of a
1091 picture object indicate the transformation that was applied to the
1092 original image. The transformation is applied as follows:
1096 If @var{mirror} is true, the picture is reflected about its vertical
1099 The picture is rotated by @var{angle} anticlockwise about its center
1100 (@var{angle} may only be an integer multiple of 90 degrees).
1102 The picture is scaled and translated to fit within the rectangle
1103 defined by the points @var{top-left} and @var{bottom-right}.
1106 @defun picture? object
1107 Returns @samp{#t} if and only if @var{object} is a picture @code{object}.
1110 @defun make-picture/vector vector filename top-left bottom-right angle mirror
1111 Creates and returns a new picture object for @var{filename}, by
1112 reading image data from @var{vector} (which should be in a standard
1113 image file format). If @var{vector} could not be loaded, an error is
1114 raised. @var{top-left}, @var{bottom-right}, @var{angle} and
1115 @var{mirror} specify the picture transformation.
1117 The points @var{top-left} and @var{bottom-right} should be specified
1118 in the form @samp{(x . y)}.
1121 @defun set-picture! picture top-left bottom-right angle mirror
1122 Sets the picture transformation for @var{picture}.
1125 @defun picture-info picture
1126 Returns the parameters of @var{picture} as a list in the form:
1129 ((top-left-x . top-left-y) (bottom-right-x . bottom-right-y) angle mirror)
1133 @defun picture-filename picture
1134 Returns the filename associated with @var{picture} as a string.
1137 @defun picture-top-left picture
1138 Returns the position of the top left corner of @samp{picture} in the
1139 form @samp{(x . y)}.
1142 @defun picture-bottom-right picture
1143 Returns the position of the bottom right corner of @samp{picture} in
1144 the form @samp{(x . y)}.
1147 @defun picture-angle picture
1148 Returns the angle to rotate @samp{picture} by, as an integer number of
1152 @defun picture-mirror? picture
1153 Returns true if @samp{picture} is mirrored.
1159 Text fulfils two roles, as straightforward labels and notes on
1160 schematics and symbols, and as attached or floating attributes
1161 (@pxref{Attributes}). A text @code{object} can be aligned in
1162 different ways relative to its anchor position, and can be displayed
1163 in different font sizes.
1165 Any text can be set to be visible or invisible on printed output (and
1166 gschem provides ways to preview invisible text). When a text
1167 @code{object} is an attribute (i.e. its string is in a
1168 @samp{@var{name}=@var{value}} format) then the visibility settings are
1169 more fine-grained: the text can be set to display just the attribute
1170 name, just the attribute value, or both.
1175 Returns @samp{#t} if and only if @var{object} is a text @code{object}.
1178 @defun make-text anchor align angle string size visible show [color]
1179 Creates and returns a new text @code{object}. @var{anchor} is the
1180 position of the anchor of the new text in the form @code{(x . y)}, and
1181 @var{align} is a symbol determining how the text should be aligned
1182 relative to the anchor. @var{align} must be one of the following
1195 @samp{middle-center}
1206 For example, if @var{align} is @samp{upper-center}, the anchor will be
1207 located at the top center of the rendered text block.
1209 @var{angle} should be an integer multiple of 90 degrees, determining
1210 the angle which the text should be displayed at. @var{string} is the
1211 string contents for the @code{text} object, and must not contain any
1212 null characters (@samp{#\0} in Scheme, Unicode
1213 @samp{U+0000}. @var{size} is the font size to use. If @var{visible}
1214 is @samp{#f}, the text will be invisible; otherwise, it will be
1217 When the @var{string} is in an attribute format (@pxref{Attributes}),
1218 the @var{show} argument determines which parts of the @var{string}
1219 will be displayed. It must be one of the following symbols:
1230 If @var{color} is specified, it should be the integer color map index
1231 of the color with which to draw the text. If @var{color} is not
1232 specified, the default arc color is used.
1235 @defun set-text! text anchor align angle string size visible show [color]
1236 Sets the parameters of @var{text}. The arguments are the same as to
1237 @code{make-text}. Returns @var{text}.
1240 @defun text-info text
1241 Returns the parameters of @var{text} as a list in the form:
1244 ((anchor-x . anchor-y) align angle string size visible show color)
1247 See @code{make-text} for a description of all of these parameters.
1250 @defun text-center text
1251 Returns the position of the anchor of @var{text} in the form
1255 @defun text-align text
1256 Returns the alignment of @var{text} as one of the following symbols:
1268 @samp{middle-center}
1280 @defun text-angle text
1281 Returns the angle that @var{text} is displayed at as an integer
1282 multiple of 90 degrees.
1285 @defun text-string text
1286 Returns the string content of @var{text}.
1289 @defun set-text-string! text str
1290 Set the string content of @var{text} to @var{str}. @var{str} must not
1291 contain any null characters (@samp{#\0} in Scheme, Unicode
1295 @defun text-size text
1296 Return the font size of @var{text} as an integer.
1299 @defun text-visible? text
1300 Returns @samp{#t} if and only if @var{text} is set to be visible.
1303 @defun set-text-visibility! text visible?
1304 If @var{visible?} is @samp{#f}, sets @var{text} to be invisible;
1305 otherwise, sets it to be visible.
1308 @defun text-attribute-mode text
1309 Returns a symbol indicating which parts of @var{text} will be
1310 displayed when @var{text} is a valid attribute. The returned value
1311 will be one of the following symbols:
1324 @subsection Components
1326 Component @code{object}s represent instances of symbols. They contain
1327 other @code{object}s copied from the original symbol when it is
1328 instantiated into a schematic.
1330 A component's @var{basename} is a string used to identify which symbol
1331 it originated from. When instantiating a symbol on initial placement
1332 in a schematic, or when recreating a component while loading a
1333 schematic, the @var{basename} is used to find the underlying symbol
1334 file in the component library.
1336 @xref{Component objects}.
1338 @strong{Note}: In the gEDA C source code, these are normally called
1339 ``complex'' objects. However, as Guile Scheme supports complex
1340 numbers, and the procedures related to working with complex numbers
1341 use the word @samp{complex} to describe them, this API uses
1342 @samp{component} to avoid ambiguity.
1344 The @var{position}, @var{angle} and @var{mirror} flag of a component
1345 indicates the transformation that was applied to the contents of the
1346 original symbol. The transformation is applied in the following order:
1350 If @var{mirror} is true, the symbol is reflected in the line x = 0.
1352 The symbol is rotated anti-clockwise by @var{angle} degrees about the
1353 point (0,0) (@var{angle} may only be an integer multiple of 90
1356 Finally, the symbol is translated by @var{position}.
1359 The component's contents (as returned by @code{component-contents})
1360 have the transformation already applied to them. Updating the
1361 translation information using e.g. @code{set-component!} will not
1362 alter them -- that must be done separately (e.g. by reloading the
1365 @defun component? object
1366 Returns @samp{#t} if and only if @var{object} is a component @code{object}.
1369 @defun make-component basename position angle mirror locked
1370 Creates and returns a new, empty component @code{object} with the
1371 given @var{basename}. @var{position}, @var{angle} and @var{mirror}
1372 specify the symbol transformation. If @var{locked} is true, the
1373 component will be protected against accidental selection by the user
1374 (this is used in gschem e.g. for titleblocks).
1376 No attempt is made to load a symbol matching @var{basename} from
1377 component libraries, and the returned component is flagged as
1381 @defun make-component/library basename position angle mirror locked
1382 Searches the component libraries for a symbol matching @var{basename},
1383 and if found, instantiates the symbol and returns the resulting
1384 component (which is not flagged as embedded). Arguments are as for
1385 @code{make-component}.
1387 If no match for @var{basename} is found, @samp{#f} is returned.
1390 @defun set-component! component position angle mirror locked
1391 Sets the parameters of @var{component}. Arguments are the same as to
1392 @code{make-component}. Returns @var{component}.
1394 @strong{Note}: Remember that modifying the transformation parameters
1395 of a component does not update the component's contents.
1398 @defun component-info component
1399 Returns the parameters of @var{component} as a list of the form:
1402 (basename (x . y) angle mirror locked)
1406 @defun component-basename component
1407 Returns the basename of @var{component}.
1410 @defun component-position component
1411 Returns the position to which the original symbol was translated when
1412 creating @var{component}.
1415 @defun component-angle component
1416 Returns the angle by which the original symbol was rotated when
1417 creating @var{component}, as an integer number of degrees.
1420 @defun component-mirror? component
1421 Returns true if the original symbol was mirrored when creating
1425 @defun component-locked? component
1426 Returns true if @var{component} is non-selectable.
1429 @defun component-contents component
1430 Returns the contents of @var{components} as a list of objects.
1433 @defun component-append! component objects...
1434 Appends @var{objects} (which must not be component @code{object}s) to
1435 the contents of @var{component}. Any @var{objects} which are already
1436 included in @var{component} are ignored. If any @var{objects} are
1437 already part of a @code{page} or of another component @code{object},
1438 an @samp{object-state} error is raised. Returns @var{component}.
1441 @defun component-remove! component objects...
1442 Removes @var{objects} from the contents of @var{component}. Any
1443 @var{objects} which are not part of a component or of a page are
1444 ignored. Returns @var{component}.
1446 An @samp{object-state} error will be raised if any @var{objects}
1447 satisfy any of the following conditions:
1451 are part of a @code{page};
1453 are part of a component @code{object} other than @var{component};
1455 have attached attributes
1457 are attached as an attribute.
1461 @node Core attribute functions
1462 @section Core attribute functions
1464 To use the functions described in this section, you will need to load
1465 the @code{(geda attrib)} module.
1467 Attributes are text @code{object}s with a particular format of string.
1468 They can be floating, or they can be attached to another
1471 @defun attribute? object
1472 Returns true if and only if @var{object} is an attribute (i.e. a text
1473 @code{object} and in attribute format).
1476 @subsection Attribute names and values
1478 @defun parse-attrib text
1479 Splits the string from @var{text} (a text @code{object}) into name and
1480 value, if it is in attribute format. If it is not in attribute
1481 format, raises an @samp{attribute-format} error. The return value is
1482 in the form @samp{(@var{name} . @var{value})}.
1485 @defun attrib-name attrib
1486 Returns the name part of @var{attrib}, as a string.
1489 @defun attrib-value attrib
1490 Returns the value part of @var{attrib}, as a string.
1493 @defun set-attrib-value! attrib value
1494 Sets the value part of @var{attrib} to @var{value}.
1497 @subsection Attribute attachment
1499 @defun attrib-attachment attrib
1500 If @var{attrib} is attached to another @code{object}, returns that
1501 object. Otherwise, returns @samp{#f}.
1504 @defun object-attribs object
1505 Returns a list of all attributes attached to @var{object}.
1508 @defun attach-attribs! object [attribs...]
1509 Attach @var{attribs} to @var{object}. All the @var{attribs} must be
1510 text @code{object}s. The following conditions must be satisfied, or
1511 an @samp{object-state} error will be raised:
1515 Neither @var{object} nor any of the @var{attribs} may be already
1516 attached as an attribute;
1518 Both @var{object} and all @var{attribs} must be part of the same
1519 @code{page} and/or component @code{object};
1522 Any @var{attribs} that are already attached to @var{object} are
1523 ignored. Returns @var{object}.
1525 @strong{Note}: For historical reasons, @code{attach-attribs!} does not
1526 require that all @var{attribs} satisfy @code{attribute?}.
1527 Nevertheless, avoid attaching non-attribute text objects as attributes.
1530 @defun detach-attribs! object [attribs...]
1531 Detach @var{attribs} from @var{object}. Any @var{attribs} that are
1532 not attached as attributes are ignored. If any @var{attribs} are
1533 attached to @code{object}s other than @var{object}, an
1534 @samp{object-state} error is raised.
1537 @subsection Inherited and promoted attributes
1539 @dfn{Inherited attributes} are unattached attributes inside a
1540 component @code{object}.
1542 @defun inherited-attribs object
1543 Returns the inherited attributes of @var{object}, if @var{object} is a
1544 component. If @var{object} is not a component, returns the empty
1548 @defun attrib-inherited? attrib
1549 Returns @samp{#t} if @var{attrib} is an inherited attribute.
1552 @dfn{promotable attributes} are inherited attributes that are both
1553 visible and have names that are in the list of promotable attributes
1554 set with the @code{always-promote-attributes} rc file parameter.
1556 @defun promotable-attribs component
1557 Returns a list of promotable attributes of @var{component}.
1560 @defun promote-attribs! component
1561 Promote all promotable attributes from @var{component} into the
1562 @code{page} that contains @var{component}. If @var{component} is not
1563 in a page, an @samp{object-state} error is raised.
1565 All promotable attributes are copied, and made invisible. The copies
1566 are added to the @code{page}, and attached as attributes of @var{component}.
1568 The promoted attributes are returned. If @var{component} is not in
1569 fact a component @code{object}, does nothing and returns the empty list.
1572 @node Configuration functions
1573 @section Configuration functions
1574 @cindex Configuration
1576 To use the functions described in this section, you will need to load
1577 the @code{(geda config)} module.
1579 This section describes some functions for accessing, monitoring and
1580 modifying the configuration of gEDA libraries and applications.
1583 * Configuration contexts::
1584 * Configuration parameters::
1585 * Configuration events::
1586 * Configuration errors::
1589 @node Configuration contexts
1590 @subsection Configuration contexts
1591 @cindex Configuration context
1593 A configuration parameter is always evaluated within a
1594 @dfn{configuration context}. Each context is associated with a
1595 configuration file (although the file does not necessarily need to
1598 Each configuration context may have a @dfn{parent context}. If, when
1599 looking up a parameter, it has no value set in the selected context,
1600 the parent context is checked, and so on.
1602 Three special contexts are always automatically defined: the
1603 @dfn{default context}, the @dfn{system context} and the @dfn{user
1604 context}. The user context is the default parent context for all
1605 other configuration contexts, including newly-created ones.
1607 @subsubsection Obtaining a context
1608 @cindex System configuration context
1609 @cindex User configuration context
1610 @cindex Default configuration contex
1612 @defun path-config-context path
1613 Normally, you shouldn't create a configuration context directly; you
1614 should obtain the configuration context associated with a @var{path}.
1616 @code{path-config-context} looks for a configuration file named
1617 @file{geda.conf}. If @var{path} is not a directory, it is truncated,
1618 and then a file named @file{geda.conf} is looked for in that
1619 directory. If none is found, the parent directory is checked, and so
1620 on until a configuration file is found or the filesystem root is
1621 reached. If no configuration file was found, the returned context
1622 will be associated with a @file{geda.conf} in the same directory as
1625 @strong{Warning}: Do not assume that the configuration file associated
1626 with the context returned by @code{path-config-context} is located in
1627 the directory specified by @var{path}.
1630 @defun default_config_context
1631 The default context is not associated with any physical path or
1632 on-disk configuration file, and has no parent context. It contains
1633 the default configuration used when no configuration file can be
1636 @strong{Note}: Normally, the default context should be populated with
1637 built-in default configuration settings on start-up, before loading
1638 any further configuration files. This approach is strongly
1639 recommended, because it means that configuration parameters can then
1640 be safely read without having to use @code{config-has-group?} and
1641 @code{config-has-key?} to check if they are set (@pxref{Configuration
1642 parameters, , Configuration groups and keys}).
1647 @defun system-config-context
1648 The system context is used for system-wide configuration. Its parent
1649 context is the default context. It is located:
1653 By searching @env{XDG_CONFIG_DIRS} for a @file{gEDA/geda-system.conf}
1656 By checking the system configuration directory specified at
1657 compile-time for a @file{gEDA/geda-system.conf} file.
1663 @defun user-config-context
1664 The user context is used for user-specific configuration, and is
1665 loaded from @file{gEDA/geda-user.conf} in @env{XDG_CONFIG_HOME}.
1666 Its parent context is the system context.
1671 @subsubsection Loading and saving configuration files
1672 @cindex Loading configuration
1673 @cindex Saving configuration
1674 Other than the default context, all configuration contexts are
1675 associated with an on-disk configuration file.
1677 @defun config-filename cfg
1678 Return the filename of the configuration file associated with the
1679 context @var{cfg}. For some contexts (including the default context),
1680 this will return @samp{#f}.
1685 @defun config-load! cfg
1686 Attempt to load configuration parameters for the context @var{cfg}
1687 from its associated file.
1690 @defun config-loaded? cfg
1691 Determine whether the context @var{cfg} has been successfully loaded
1697 @defun config-save! cfg
1698 Attempt to save configuration parameters for the context @var{cfg} to
1699 its associated file.
1704 @defun config-changed? cfg
1705 Determine whether the context @var{cfg} has been altered since it was
1706 last synchronised with the on-disk version by loading or saving it.
1711 @subsubsection Context parents
1712 @cindex Context parent
1713 @cindex Parent configuration context
1714 A configuration context may have a @dfn{parent context}, from which it
1715 inherits configuration values. Configuration inheritance loops are
1718 @xref{Configuration parameters, , Configuration inheritance}.
1720 @defun context-parent cfg
1721 Return the parent context of the context @var{cfg}, if it has one.
1726 @defun set-config-parent! cfg parent
1727 Sets @var{parent} as the parent context of @var{cfg}. If @var{parent}
1728 is @samp{#f}, sets @var{cfg} as having no parent context.
1730 @strong{Note}: Normally, application code should avoid using this
1731 function; keeping to the default configuration inheritance structure
1732 is recommended in order to ensure consistent behaviour of all libgeda
1738 @subsubsection Context trust
1739 @cindex Context trust
1740 @cindex Trusted configuration context
1741 @cindex Configuration trust
1743 Some configuration parameters are dangerous; in particular, parameters
1744 that may lead to arbitrary code execution need to be handled
1745 carefully. Such settings might include:
1749 Preferred PDF reader
1751 Preferred web browser
1753 Search path for Scheme plugins
1756 Configuration contexts can be flagged as being @dfn{trusted}. This
1757 allows code that needs to access such dangerous parameters to
1758 determine whether the value has been obtained from a safe source.
1760 By default, the default context, system context and user context are
1761 trusted, and all other contexts untrusted.
1763 @defun config-trusted? cfg
1764 Test whether @var{cfg} is a trusted configuration context.
1769 @defun set-config-trusted! cfg trusted?
1770 Set whether the configuration context @var{cfg} should be trusted as a
1771 source for dangerous configuration parameters.
1773 @strong{Warning}: You should not set a configuration context as
1774 trusted unless you are certain that it originated from a safe source
1775 (e.g. by interacting with the user to verify it).
1780 @defun config-trusted-context cfg
1781 If @var{cfg} is trusted, returns @var{cfg}; otherwise, returns the
1782 first parent context of @var{cfg} that is a trusted context. If no
1783 trusted context can be found, returns @samp{#f}.
1788 @node Configuration parameters
1789 @subsection Configuration parameters
1790 @cindex Configuration parameter
1791 @cindex Configuration key
1792 @cindex Configuration group
1793 @cindex Configuration value
1795 A gEDA @dfn{configuration parameter} consists of three components:
1799 A string which identifies the general category in which the
1800 parameter lies (e.g. which application and/or plugin).
1802 A string which specifically identifies the parameter within the group.
1804 The value of the parameter. This is stored as a string, but can be
1805 converted to a number of possible scalar and list types.
1808 Groups, names and values are all case-sensitive.
1810 @subsubsection Configuration groups and keys
1812 @defun config-groups cfg
1813 Returns a list of all groups available in @var{cfg} and its parent
1819 @defun config-has-group? cfg group
1820 Determines whether @var{cfg} or its parent contexts contain the
1821 specified @var{group}
1826 @defun config-keys cfg group
1827 Returns a list of all keys available in the specified @var{group} in
1828 @var{cfg} and its parent contexts.
1833 @defun config-has-key? cfg group key
1834 Determines whether @var{cfg} or its parent contexts contains @var{key}
1835 in the specified @var{group}.
1840 @subsubsection Configuration inheritance
1842 If a configuration context does not directly specify a value for a
1843 configuration parameter, it inherits the value from its parent
1846 @xref{Configuration contexts, , Context parents}.
1848 @defun config-inherited? cfg group key
1849 Returns @samp{#f} if value of the configuration parameter with the
1850 given @var{group} and @var{key} is specified in the context @var{cfg},
1851 and @samp{#t} if it is inherited from a parent context of @var{cfg}.
1856 @defun config-source cfg group key
1857 Returns the configuration context (either @var{cfg} or one of its
1858 parent contexts) in which the configuration parameter with the given
1859 @var{group} and @var{key} has its value defined.
1864 @subsubsection Configuration values
1865 @cindex Getting configuration parameters
1866 @cindex Setting configuration parameters
1868 Each value is stored as a UTF-8 string in the configuration file.
1869 However, this string can be parsed a several different types. All of
1870 the following types are supported:
1880 Inexact real numbers
1883 In addition, lists of all the above are supported.
1885 @defun config-string cfg group key
1886 Retrieve configuration value as a string.
1891 @defun config-boolean cfg group key
1892 Retrieve configuration value as a boolean.
1897 @defun config-int cfg group key
1898 Retrieve configuration value as an exact integer.
1903 @defun config-real cfg group key
1904 Retrieve configuration value as an inexact real number.
1909 @defun config-string-list cfg group key
1910 Retrieve configuration value as a list of strings.
1915 @defun config-boolean-list cfg group key
1916 Retrieve configuration value as a list of booleans.
1920 @defun config-int-list cfg group key
1921 Retrieve configuration value as a list of exact integers.
1926 @defun config-real-list cfg group key
1927 Retrieve configuration value as a list of inexact real numbers.
1932 @defun config-set! cfg group key value
1933 Set the configuration parameter identified by the given @var{group}
1934 and @var{key} in the configuration context @var{cfg}. The type of
1935 value to set is inferred from @var{value}.
1940 @node Configuration events
1941 @subsection Configuration events
1942 @cindex Configuration events
1943 @cindex Configuration notifications
1945 When the value of a configuration parameter is altered, either
1946 directly or by loading a configuration file, a @dfn{configuration
1947 event} is generated. Handlers can be registered to be notified when a
1948 configuration event occurs. A configuration event is associated with
1949 the group and key that had its value modified.
1951 If a configuration event is emitted by a configuration context, it
1952 propagates to all configuration contexts which inherit that group and
1955 A configuration event handler must be a closure that accepts three
1959 handler cfg group key
1962 @var{cfg} is always the configuration context that received the event,
1963 and the @var{group} and @var{key} identify the configuration parameter
1966 @defun add-config-event! cfg handler
1967 Registers @var{handler} to be called when configuration changes in the
1973 @defun remove-config-event! cfg handler
1974 Stops @var{handler} from being called when configuration changes in
1975 the context @var{cfg}.
1980 @node Configuration errors
1981 @subsection Configuration errors
1982 @cindex Configuration errors
1984 All errors in functions in the @code{(geda config)} are reported using
1989 File errors (e.g. ``Access denied'' or ``File not found'' are
1990 indicated with the @code{system-error} key.
1992 All other errors are indicated using the @code{config-error} key.
1995 When a @code{config-error} is signalled, @code{data} part of the error
1996 arguments is a list containing one of the following symbols:
1999 @item unknown-encoding
2000 The text being parsed was in an unknown encoding.
2002 The configuration data wass ill-formed.
2004 A requested configuration key was not found.
2005 @item group-not-found
2006 A requested configuration group was not found.
2008 A configuration value could not be parsed into the requested format.
2011 @node System information
2012 @section System information
2014 To use the functions described in this section, you will need to load
2015 the @code{(geda os)} module.
2017 This section describes some functions and variables that are useful
2018 for Scheme code that needs to behave differently depending on which
2019 operating system gEDA is running on.
2021 @defvar separator-char
2022 The directory separator character that should be used on the host
2027 A string containing @code{separator-char}.
2030 @defvar path-separator-char
2031 The character used for separating the elements in @samp{PATH}-like
2032 environment variables on the host platform.
2035 @defvar path-separator
2036 A string containing @code{path-separator-char}.
2040 Returns a list of symbols describing the host platform. The returned
2041 symbols may include:
2057 @defun platform? type
2058 Returns @samp{#t} if the platform description list returned by
2059 @code{platform} contains the symbol @var{type}, and @samp{#f}
2063 @defun sys-data-dirs
2064 Returns an ordered list of directories in which to access system-wide
2068 @defun sys-config-dirs
2069 Returns an ordered list of directories in which to access system-wide
2070 gEDA configuration information.
2073 @defun user-data-dir
2074 Returns the directory in which to store user-specific gEDA data.
2077 @defun user-config-dir
2078 Returns the directory in which to store user-specific gEDA
2079 configuration information.
2082 @defun expand-env-variables str
2083 Recursively expands @var{str} until no more environment variables can be
2084 expanded, and return the expanded string. Environment variables are in
2085 the form @samp{$@{VAR@}}.
2088 (expand-env-variables "$@{HOME@}/path/to/dir")
2093 @node gschem API Reference
2094 @chapter gschem API Reference
2096 The Scheme modules and functions described in this chapter are
2097 available in the gschem schematic editor application. They are more
2098 focused on enabling and responding to user editing operations.
2101 * Windows and views::
2106 * Miscellanous gschem functions::
2109 @node Windows and views
2110 @section Windows and views
2112 To use the functions described in this section, you will need to load
2113 the @code{(gschem window)} module.
2116 Returns the @code{page} currently being displayed for editing.
2119 @defun set-active-page! page
2120 Sets the current @code{page} to @var{page}.
2123 @defun pointer-position
2124 Returns the current mouse pointer position in world coordinates in the
2125 form @samp{(x . y)}. If the pointer is outside the display area,
2129 @defun snap-point point
2130 Snaps the given @var{point} to the current snap grid, i.e. returns the
2131 closest grid location to @var{point}. Expects a point in the form
2132 @samp{(x . y)}, and returns a point in the same format.
2136 @section Key mapping
2138 To use the functions described in this section, you will need to load
2139 the @code{(gschem keymap)} module.
2141 @subsection Key combinations
2143 gschem treats key combinations as first-class objects. A key
2144 combination consists of a non-modifier key press with some number of
2145 modifiers applied. For example, the key combination @kbd{Ctrl+Shift+A}
2146 (which calls @strong{Edit→Deselect} by default) is typed by
2147 holding the @key{Ctrl} and @key{Shift} keys down, and then pressing
2151 Returns @samp{#t} if and only if @var{obj} is a key combination.
2154 @defun string->key str
2155 Parses @var{str} to create a new key combination. The expected format
2156 looks like @samp{<Control>a} or @samp{<Shift><Alt>F1}. Key names are
2157 parsed using @code{gdk_keyval_from_name()}, and modifiers may appear in
2158 any order. If @var{str} has invalid syntax or does not represent a
2159 valid key combination, raises a @samp{key-format} error.
2162 @defun key->string key
2163 Converts @var{key} to a string, using a format suitable for passing to
2167 @defun key->display-string key
2168 Converts @var{key} to a string, using a format suitable for
2169 display. This should be used when the key combination needs to be
2170 displayed to the user e.g. in the gschem menus or status area. The
2171 returned string is translated according to the user's current locale.
2174 (key->display-string (string->key ``<Control>bracketright''))
2179 @subsection Key sequences
2181 Most gschem functionality is bound not to single key combinations but to
2182 sequences of them. For example, @strong{File→New} is bound to @kbd{F N}
2183 by default (i.e. press @key{F} followed by @key{N}). Key sequences are
2184 simply vectors of key bindings. For example:
2187 (string->keys ``F N'')
2188 => #(#<gschem-key "F"> #<gschem-key "N">)
2191 In this case, @key{F} is a @dfn{prefix key}, because pressing it does
2192 not cause an action to be carried out directly, but just changes the
2193 effect of pressing subsequent keys.
2196 Returns @samp{#t} if and only if @var{obj} is a valid key sequence.
2199 @defun string->keys str
2200 Parses @var{str} into a key sequence. The expected format is a sequence
2201 of key combination specifications (as could be passed to
2202 @code{string->key}) separated by spaces.
2205 @defun keys->string keys
2206 Converts the key sequence @var{keys} to a string, using a format
2207 suitable for passing to @code{string->keys}.
2210 @defun keys->display-string keys
2211 Converts the key sequence @var{keys} to a string, using a format
2212 suitable for display.
2217 A @dfn{keymap} maps key combinations to values (usually actions) or to
2218 other keymaps. @xref{Actions}.
2221 Returns @samp{#t} if and only if @var{obj} is a keymap.
2225 Creates and returns a new, empty keymap.
2228 @defun keymap-bind-key! keymap key [bindable]
2229 Binds @var{key} to @var{bindable} in @var{keymap}. If @var{bindable} is
2230 @samp{#f} or not specified, removes the binding for @var{key}.
2231 @var{bindable} should be a thunk or a keymap.
2234 @defun keymap-lookup-key keymap key
2235 Looks up the binding for @var{key} in @var{keymap}. If @var{key} is not
2236 bound, returns @samp{#f}.
2239 @defun keymap-lookup-binding keymap bindable
2240 Carries out a reverse lookup in @var{keymap} to find the key bound to
2241 @var{bindable}. If @var{bindable} is not bound in @var{keymap},
2245 @defun keymap-for-each proc keymap
2246 Applies @var{proc} to each binding in @var{keymap}. @var{proc} should
2247 take two arguments: the bound key, and its binding.
2250 Actions are bound to key sequences by binding the first key
2251 combination to a keymap, then in the resulting keymap binding the
2252 second key combination, etc. This results in a directed graph of
2255 For example, to bind the key sequence @kbd{F N}, a keymap is created
2256 containing a binding for @key{N} to the desired action, and then in the
2257 main keymap the prefix key @key{F} is bound to the new keymap.
2259 Three helper functions are provided for working with key sequence
2262 @defun bind-keys! keymap keys [bindable]
2263 Bind @var{keys} to @var{bindable}. Keys may be a key sequence vector, a
2264 single key combination, or a string representing a key sequence or key
2265 combination. If @var{bindable} is @samp{#f} or not specified, removes
2266 the binding for @var{keys}. @var{bindable} should be a thunk or a
2269 If @var{keys} contains invalid prefix keys (e.g. because one of the
2270 prefix keys is already bound to something other than a keymap), raises
2271 an error. Missing prefix keymaps are created as required.
2274 @defun lookup-keys keymap keys
2275 Looks up the binding for @var{keys} in @var{keymap}. @var{keys} is
2276 interpreted the same as for @code{bind-keys!}. If @var{keys} is not
2277 bound, returns @samp{#f}.
2280 @defun lookup-binding keymap bindable
2281 Recursively searches @var{keymap} for the key sequence bound to
2282 @var{bindable}, which should be a thunk or a keymap. If
2283 @var{bindable} is not bound, returns @samp{#f}.
2289 To use the functions described in this section, you will need to load
2290 the @code{(gschem selection)} module.
2292 Each @code{page} in gschem has a @dfn{selection} associated with it,
2293 which is some subset of the @code{page}s contents. Most actions in
2294 gschem operate on the currently selected objects.
2296 @defun page-selection page
2297 Returns the current selection for @var{page}, as a list of
2301 @defun object-selected? object
2302 Returns @samp{#t} if @var{object} is in its containing page's
2303 selection. Otherwise, returns @samp{#f}. If @var{object} is not in a
2304 @code{page}, raises an @samp{object-state} error.
2306 @strong{Note}: @var{object} must be @emph{directly} included in a
2307 @code{page}, not via inclusion in a component @code{object}.
2310 @defun select-object! object
2311 Adds @var{object} to the selection of its containing @code{page}. If
2312 @var{object} is not directly included in a @code{page}, raises an
2313 @samp{object-state} error. If @var{object} is already selected, does
2314 nothing. Returns @var{object}.
2316 @strong{Note}: This function does not call @code{select-objects-hook}.
2319 @defun deselect-object! object
2320 Removes @var{object} from the selection of its containing @code{page}.
2321 If @var{object} is not directly included in a @code{page}, raises an
2322 @samp{object-state} error. If @var{object} is not selected, does
2323 nothing. Returns @var{object}.
2325 @strong{Note}: This function does not call
2326 @code{deselect-objects-hook}.
2332 To use the hooks described in this section, you will need to load the
2333 @code{(gschem hook)} module.
2335 gschem defines a number of hooks that allow functions to be
2336 automatically run whenever a number of built-in actions are invoked by
2339 Most Scheme functions do not call these hooks. If it makes sense for
2340 your code to invoke a standard hook, you should normally do so
2343 @strong{Warning}: Functions added to these standard hooks should not
2344 normally modify their arguments.
2346 For more information on hooks in Guile, @pxref{Hooks, , Hooks, guile,
2347 Guile Reference Manual}.
2349 @defvar add-objects-hook
2350 Called after objects are added to the page, at their initial creation.
2351 The argument is a list of the objects being added.
2354 @defvar remove-objects-hook
2355 Called after objects are removed from the page. Argument is a list of
2356 the objects being removed.
2359 @defvar move-objects-hook
2360 Called after objects are moved. Argument is a list of the objects
2364 @defvar mirror-objects-hook
2365 Called after objects are mirrored. Argument is a list of the objects
2369 @defvar rotate-objects-hook
2370 Called after objects are rotated. Argument is a list of the objects
2374 @defvar paste-objects-hook
2375 Called after objects are pasted to the page, either via @strong{Edit →
2376 Copy Mode} or similar, or via buffers, or via the clipboard. Argument
2377 is a list of the objects that were pasted.
2380 @defvar attach-attribs-hook
2381 Called after attributes are attached to something. The argument is a
2382 list of the attributes that were attached.
2385 @defvar detach-attribs-hook
2386 Called after attributes are detached from something. The argument is
2387 a list of the attributes that were detached.
2390 @defvar select-objects-hook
2391 Called after objects are added to the selection. The argument is a
2392 list of objects that were selected.
2395 @defvar deselect-objects-hook
2396 Called after objects are removed from the selection. The argument is
2397 a list of objects that were deselected.
2400 @defvar new-page-hook
2401 Called when a new page is created. The argument is the new page.
2404 @defvar action-property-hook
2405 Called when an action property is set. The arguments are the action,
2406 the property key and the property value. @xref{Actions}.
2411 @defvar bind-keys-hook
2412 Called when a key binding is set or modified. The arguments are the
2413 keymap, the key sequence and the binding's target.
2415 @strong{Note}: @code{bind-keys-hook} may be run multiple times for a
2416 single key binding event if the target keymap is bound within a
2426 To use the functions described in this section, you will need to load
2427 the @code{(gschem action)} module.
2429 @subsection Action objects
2430 @cindex Action objects
2431 @cindex Action properties
2433 Usually, it is sufficient to use normal Scheme functions when
2434 extending gschem. However, when integrating an extension function
2435 with the gschem GUI (e.g. via keybindings), it is often useful to
2436 couple a Scheme function with metadata such as the label and icon to
2439 You can do this by creating a gschem action. Actions can be called
2440 just like a normal Scheme function, but get executed via the gschem
2441 action dispatcher @code{eval-action!} rather than being invoked
2442 directly. Normally, actions have names begining with an @samp{&}
2445 @defmac define-action (name [keyword value ...]) body
2446 Create a new action, bound to the given @var{name} in the current
2447 module. The @var{body} is a sequence of Scheme expressions which are
2448 evaluated in order when the action is invoked. Any number of initial
2449 properties can be specified for the action by providing pairs of
2450 @var{keyword}s and @var{value}s.
2453 (define-action (&report-bug #:label ``Report Bug'' #:icon ``web-browser'')
2454 (show-uri ``http://bugs.launchpad.net/geda/+reportbug''))
2460 @defun make-action thunk [keyword value ...]
2461 Create and return a new action wrapping @var{thunk}. Optionally,
2462 specify @var{keyword}-@var{value} pairs to set initial properties for the
2469 Returns @samp{#t} iff @var{obj} is a gschem action, and @samp{#f}
2475 Action properties are name-value pairs that are attached to an action.
2477 @defun action-property action key
2478 Return the value of one of @var{action}'s properties. @var{key} is a
2479 symbol naming the property to retrieve.
2484 @defun set-action-property! action key value
2485 Set the value of one of @var{action}'s properties. @var{key} is a
2486 symbol naming the property to set, and @var{value} is the new value.
2491 @subsection Evaluating actions
2492 @cindex Evaluating actions
2493 @cindex Action evaluation
2495 All of gschem's built-in actions are callable just like normal Scheme
2496 functions. However, it's sometimes useful to explicitly evaluate an
2497 action in the same way that the gschem GUI (menus, toolbars or
2498 keybindings) would do so.
2500 @defun eval-action! action
2501 Invoke @var{action}, returning @samp{#t} on success and raising an
2502 error on failure. There are a number of possible types for
2503 @var{action} that @code{eval-action!} will accept:
2511 A symbol naming an action or a thunk in the current module.
2514 The special symbol @samp{repeat-last-command} is interpreted as a
2515 request to repeat the last action evaluated via @code{eval-action!}.
2517 @strong{Note}: If you have an action object @code{&action}, then the
2518 following to calls are equivalent and interchangeable:
2521 (eval-action! &action)
2528 @subsection Action positions
2529 @cindex Action positions
2531 Often in gschem actions it may be useful not to use the actual current
2532 mouse pointer position but to use the mouse pointer position that was
2533 current when the action was invoked.
2535 @defun eval-action-at-point! action [point]
2536 Evaluate @var{action} at a particular point on the schematic plane.
2537 If @var{point} is omitted, the action is evaluated at the current
2538 mouse pointer position.
2543 @defun action-position
2544 Return the current action pointer position, as set when the action was
2545 invoked (via @code{eval-action-at-point!}). This only makes sense to
2546 call from inside an action.
2551 @strong{Note}: The pointer position can only be considered reliable
2552 when the user was actually clicking on or pointing at the schematic
2553 view area to invoke the action, rather than on a menu or toolbar
2554 button. At the moment this means that an action position is only set
2555 when a command is invoked by hotkey.
2557 @node Miscellanous gschem functions
2558 @section Miscellaneous gschem functions
2560 @subsection gschem Attribute Helpers
2562 To use the functions described in this section, you will need to load
2563 the @code{(gschem attrib)} module.
2565 @defun add-attrib! target name value visible show
2566 Create a new attribute, either attached to a @var{target}
2567 @code{object} in the current @code{page}, or floating in the current
2568 @code{page} if @var{target} is @samp{#f}. The @var{name} and
2569 @var{value} for the attribute must be strings, and if visible is
2570 @samp{#f}, the attribute will be invisible. The @var{show} argument
2571 controls which parts of the attribute will be visible, and must be one
2572 of the following symbols:
2583 This function exists to provide a way for actions defined in Scheme to
2584 use the same attribute placement heuristics as gschem's built-in
2585 @strong{Add Attribute} action.
2587 @xref{Text}, @ref{Attributes} and @ref{Windows and views}.
2590 @subsection Miscellaneous utility functions
2592 To use the functions described in this section, you will need to load
2593 the @code{(gschem util)} module.
2596 Open @var{uri} in the registered default application associated for
2597 that type of file or protocol. URI should be fully-qualified URI;
2598 which URIs can be handled by @code{show-uri} will depend on the system
2602 @defun show-file filename
2603 Displays a file in the registered default application for files of
2604 that type. @var{filename} should be the absolute path and filename of
2609 @unnumbered Concept Index
2613 @node Function Index
2614 @unnumbered Function Index
2618 @node Variable Index
2619 @unnumbered Variable Index