scheme-api: Add version information to documentation.
[geda-gaf.git] / docs / scheme-api / geda-scheme.texi
blobe51f299eb58c1a91f02afbd5816d2a03518056bd
1 \input texinfo                              @c -*-texinfo-*-
2 @setfilename geda-scheme.info
3 @include version.texi
4 @documentencoding utf-8
5 @dircategory The Algorithmic Language Scheme
6 @direntry
7 * gEDA Scheme: (geda-scheme).  gEDA extensibility with Guile Scheme.
8 @end direntry
9 @settitle gEDA Scheme Reference Manual @value{VERSION}
11 @copying
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.
24 @end copying
26 @titlepage
27 @title gEDA Scheme Reference Manual
28 @author Peter TB Brett
30 @page
31 @vskip 0pt plus 1filll
32 @insertcopying
34 @end titlepage
36 @contents
38 @ifnottex
39 @node Top
40 @top gEDA Scheme Reference Manual
41 @insertcopying
42 @end ifnottex
44 @menu
45 * Introduction::
47 * Schematic Document Model::
48 * Core API Reference::
49 * gschem API Reference::
51 * Concept Index::
52 * Function Index::
53 * Variable Index::
54 @end menu
56 @node Introduction
57 @unnumbered Introduction
59 @section About gEDA
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
90 address that need.
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
108 wiki.
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.
135 @menu
136 * Pages::
137 * Objects::
138 * Component objects::
139 * Attributes::
140 * Coordinate system::
141 @end menu
143 @node Pages
144 @section Pages
145 @cindex Pages
146 @cindex Schematics
147 @cindex Symbols
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
154 data type.
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
173 longer required.
175 @node Objects
176 @section Objects
177 @cindex Objects
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:
184 @itemize @bullet
185 @item
186 graphical lines, circles, arcs, rectangles and paths;
188 @item
189 nets and net pins;
191 @item
192 buses and bus pins;
194 @item
195 pictures;
197 @item
198 text;
200 @item
201 and symbol instances, known as 'components'.
202 @end itemize
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
206 garbage collected.
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
211 following sections.
213 @node Component objects
214 @section Component objects
215 @cindex Component
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}.
244 @node Attributes
245 @section Attributes
246 @cindex Attribute
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:
257 @itemize @bullet
258 @item
259 Attribute @var{name}s:
261 @enumerate
262 @item
263 must contain at least one character;
264 @item
265 must not contain a @samp{=} character (Unicode @code{U+003D});
266 @item
267 must not end with a space (@samp{ }, Unicode @code{U+0020}).
268 @end enumerate
270 @item
271 Attribute @var{value}s:
273 @enumerate
274 @item
275 must contain at least one character;
276 @item
277 must not begin with a space (@samp{ }, Unicode @code{U+0020}).
278 @end enumerate
279 @end itemize
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
311 system).
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:
320 @example
321 (x . y)
322 @end example
324 and a set of @dfn{bounds} (i.e. a rectangular area in the document
325 plane) is expressed in the format:
327 @example
328 ((left . top) . (right . bottom))
329 @end example
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.
342 @menu
343 * Core page functions::
344 * Core object functions::
345 * Core attribute functions::
346 * Configuration functions::
347 * System information::
348 @end menu
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.
356 @xref{Pages}.
358 @defun page? obj
359 Returns @samp{#t} if and only if @var{obj} is a @code{page}.
360 @end defun
362 @defun active-pages
363 Returns a list of all open @code{page}s.
364 @end defun
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}.
375 @end defun
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.
383 @end defun
385 @defun page-filename page
386 Returns the filename associated with @var{page} as a string.
387 @end defun
389 @defun set-page-filename! page filename
390 Sets the filename of @var{page} to @var{filename}.  Returns
391 @var{page}.
392 @end defun
394 @subsection Page serialisation
396 Pages can be converted to and from strings in the gEDA schematic file
397 format.
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.
405 @end defun
407 @defun page->string page
408 Returns a string representation of @var{page} in the gEDA file
409 format.
410 @end defun
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
416 electrical meaning.
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
421 @var{page}.
422 @end defun
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.
432 @end defun
434 @defun page-remove! page objects...
435 Removes zero or more @var{objects} from the contents of @var{page}.
436 Returns @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:
444 @itemize
445 @item
446 part of a @code{page} other than @var{page};
447 @item
448 part of component @code{object};
449 @item
450 has attached attributes (@pxref{Attributes});
451 @item
452 is attached as an attribute.
453 @end itemize
454 @end defun
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
459 @code{page}.
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.
464 @end defun
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
470 loaded or saved.
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}.
475 @end defun
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}.
481 @end defun
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.
489 @menu
490 * General object functions::
491 * Lines::
492 * Nets and buses::
493 * Pins::
494 * Boxes::
495 * Circles::
496 * Arcs::
497 * Paths::
498 * Pictures::
499 * Text::
500 * Components::
501 @end menu
503 @node General object functions
504 @subsection General object functions
506 @defun object? obj
507 Returns @samp{#t} if and only if @var{obj} is an @code{object}.
508 @end defun
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}.
514 @end defun
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.
519 @end defun
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.
531 @end defun
533 @menu
534 * Object sub-types::
535 * Object transformations::
536 * Object bounds::
537 * Object color::
538 * Object fill and stroke::
539 @end menu
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:
550 @itemize
551 @item
552 @samp{arc}
553 @item
554 @samp{box}
555 @item
556 @samp{bus}
557 @item
558 @samp{circle}
559 @item
560 @samp{complex} (indicates a component @code{object})
561 @item
562 @samp{line}
563 @item
564 @samp{net}
565 @item
566 @samp{path}
567 @item
568 @samp{picture}
569 @item
570 @samp{pin}
571 @item
572 @samp{text}
573 @end itemize
574 @end defun
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.
579 @end defun
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
589 @var{objects}.
590 @end defun
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}.
597 @end defun
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}.
602 @end defun
604 @node Object bounds
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
615 @code{object}s).
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.
620 @end defun
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
626 returned.
627 @end defun
629 @node Object color
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
638 @var{object}.
639 @end defun
641 @defun set-object-color! object color
642 Sets the integer color map index for @var{object} to @var{color}.
643 Returns @var{object}.
644 @end defun
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
655 parameters:
657 @enumerate
658 @item
659 stroke width, as an integer number of world units
660 @item
661 cap style, one of the symbols @code{none}, @code{square} or
662 @code{round}.
663 @item
664 dash style, one of the symbols @code{solid}, @code{dotted},
665 @code{dashed}, @code{center} or @code{phantom}.
666 @item
667 up to two dash parameters, depending on the dash style:
668 @itemize
669 @item
670 for solid lines, no parameters;
671 @item
672 for dotted lines, dot spacing;
673 @item
674 for other styles, dot/dash spacing and dash length.
675 @end itemize
676 @end enumerate
677 @end defun
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
683 @var{object}.
684 @end defun
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}.
689 @end defun
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}.
695 @end defun
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:
702 @enumerate
703 @item
704 dash style, one of the symbols @code{solid}, @code{dotted},
705 @code{dashed}, @code{center} or @code{phantom}.
706 @item
707 for styles other than @code{solid}, dot/dash spacing;
708 @item
709 for @code{dashed}, @code{center} and @code{phantom}, dash length.
710 @end enumerate
711 @end defun
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
719 parameters:
721 @enumerate
722 @item
723 fill style, one of the symbols @code{hollow}, @code{solid},
724 @code{mesh} or @code{hatch};
725 @item
726 up to five fill parameters, depending on fill style:
727 @enumerate
728 @item
729 none for @code{hollow} or @code{solid} fills;
730 @item
731 line width, line angle (in degrees) and line spacing for @code{hatch} fills;
732 @item
733 line width, first angle and spacing, and second angle and spacing for
734 @code{mesh} fills.
735 @end enumerate
736 @end enumerate
737 @end defun
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}.
743 @end defun
745 @node Lines
746 @subsection Lines
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.
754 @defun line? object
755 Returns @samp{#t} if and only if @var{object} is a line @code{object}.
756 @end defun
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
764 line color is used.
765 @end defun
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}.
771 @end defun
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:
777 @example
778 ((start-x . start-y) (end-x . end-y) color)
779 @end example
781 @strong{Note}: For pin @code{object}s, first coordinate is the
782 connectable point on the pin.
783 @end defun
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
789 pin.
790 @end defun
792 @defun line-end line
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}).
795 @end defun
797 @node Nets and buses
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.
808 @defun net? object
809 Returns @samp{#t} if and only if @var{object} is a net.
810 @end defun
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
818 net color is used.
819 @end defun
821 @defun bus? object
822 Returns @samp{#t} if and only if @var{object} is a bus.
823 @end defun
825 @defun make-bus start end [color]
826 Creates and returns a new bus @code{object}.  Arguments are as for
827 @code{make-net}.
828 @end defun
830 @node Pins
831 @subsection Pins
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
840 and buses}).
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.
846 @defun pin? object
847 Returns @samp{#t} if and only if @var{object} is a pin @code{object}.
848 @end defun
850 @defun net-pin? object
851 Returns @samp{#t} if and only if @var{object} is a net pin.
852 @end defun
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.
861 @end defun
863 @defun bus-pin? object
864 Returns @samp{#t} if and only if @var{object} is a bus pin.
865 @end defun
867 @defun make-bus-pin start end [color]
868 Creates and returns a new bus pin @code{object}.  Arguments are as for
869 @code{make-net-pin}.
870 @end defun
872 @node Boxes
873 @subsection Boxes
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.
880 @xref{Object color}.
881 @xref{Object fill and stroke}.
883 @defun box? object
884 Returns @samp{#t} if and only of @var{object} is a box @code{object}.
885 @end defun
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.
894 @end defun
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}.
899 @end defun
901 @defun box-info box
902 Returns the parameters of @var{box}.  The return value is a list in the form:
904 @example
905 ((top-left-x . top-left-y) (bottom-right-x . bottom-right-y) color)
906 @end example
907 @end defun
909 @defun box-top-left box
910 Returns the position of the top left corner of @var{box} in the form
911 @code{(x . y)}.
912 @end defun
914 @defun box-bottom-right box
915 Returns the position of the bottom right corner of @var{box} in the
916 form @code{(x . y)}.
917 @end defun
919 @node Circles
920 @subsection Circles
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.
926 @xref{Object color}.
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}.
931 @end defun
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.
940 @end defun
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}.
945 @end defun
947 @defun circle-info circle
948 Returns the parameters of @var{circle} as a list of the form:
950 @example
951 ((center-x . center-y) radius color)
952 @end example
953 @end defun
955 @defun circle-center circle
956 Returns the position of the center of @var{circle} as in the form
957 @code{(x . y)}.
958 @end defun
960 @defun circle-radius circle
961 Returns the radius of @var{circle} as an integer.
962 @end defun
964 @node Arcs
965 @subsection Arcs
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
969 stroke settings.
971 @defun arc? object
972 Returns @samp{#t} if and only if @var{object} is an arc @code{object}.
973 @end defun
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.
983 @end defun
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}.
988 @end defun
990 @defun arc-info arc
991 Returns the parameters of @var{arc} as a list of the form:
993 @example
994 ((center-x . center-y) radius start-angle end-angle color)
995 @end example
996 @end defun
998 @defun arc-center arc
999 Returns the position of the center of @var{arc} in the form
1000 @code{(x . y)}.
1001 @end defun
1003 @defun arc-radius arc
1004 Returns the radius of @var{arc} as an integer.
1005 @end defun
1007 @defun arc-start-angle arc
1008 Returns the start angle of @var{arc} as an integer number of degrees.
1009 @end defun
1011 @defun arc-end-angle arc
1012 Returns the end angle of @var{arc} as an integer number of degrees.
1013 @end defun
1015 @node Paths
1016 @subsection Paths
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:
1023 @itemize
1024 @item
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.
1029 @item
1030 @samp{lineto} elements draw a straight line from the current point to
1031 the point specified by a single position parameter.
1032 @item
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.
1037 @item
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.
1041 @end itemize
1043 @defun path? object
1044 Returns @samp{#t} if and only if @var{object} is a path @code{object}.
1045 @end defun
1047 @defun path-length path
1048 Returns the number of path elements in @var{path}.
1049 @end defun
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:
1057 @example
1058 (curveto (800 . 525) (700 . 700) (500 . 700))
1059 @end example
1061 If @var{K} is not a valid offset into @var{path}, raises an
1062 @samp{out-of-range} error.
1063 @end defun
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.
1068 @end defun
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:
1078 @example
1079 (path-insert! path -1 'lineto '(500. 100))
1080 @end example
1081 @end defun
1083 @node Pictures
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:
1094 @enumerate
1095 @item
1096 If @var{mirror} is true, the picture is reflected about its vertical
1097 centerline.
1098 @item
1099 The picture is rotated by @var{angle} anticlockwise about its center
1100 (@var{angle} may only be an integer multiple of 90 degrees).
1101 @item
1102 The picture is scaled and translated to fit within the rectangle
1103 defined by the points @var{top-left} and @var{bottom-right}.
1104 @end enumerate
1106 @defun picture? object
1107 Returns @samp{#t} if and only if @var{object} is a picture @code{object}.
1108 @end defun
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)}.
1119 @end defun
1121 @defun set-picture! picture top-left bottom-right angle mirror
1122 Sets the picture transformation for @var{picture}.
1123 @end defun
1125 @defun picture-info picture
1126 Returns the parameters of @var{picture} as a list in the form:
1128 @example
1129 ((top-left-x . top-left-y) (bottom-right-x . bottom-right-y) angle mirror)
1130 @end example
1131 @end defun
1133 @defun picture-filename picture
1134 Returns the filename associated with @var{picture} as a string.
1135 @end defun
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)}.
1140 @end defun
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)}.
1145 @end defun
1147 @defun picture-angle picture
1148 Returns the angle to rotate @samp{picture} by, as an integer number of
1149 degrees.
1150 @end defun
1152 @defun picture-mirror? picture
1153 Returns true if @samp{picture} is mirrored.
1154 @end defun
1156 @node Text
1157 @subsection Text
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.
1172 @xref{Attributes}.
1174 @defun text? object
1175 Returns @samp{#t} if and only if @var{object} is a text @code{object}.
1176 @end defun
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
1183 symbols:
1185 @itemize
1186 @item
1187 @samp{lower-left}
1188 @item
1189 @samp{middle-left}
1190 @item
1191 @samp{upper-left}
1192 @item
1193 @samp{lower-center}
1194 @item
1195 @samp{middle-center}
1196 @item
1197 @samp{upper-center}
1198 @item
1199 @samp{lower-right}
1200 @item
1201 @samp{middle-right}
1202 @item
1203 @samp{upper-right}
1204 @end itemize
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
1215 visible.
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:
1221 @itemize
1222 @item
1223 @samp{name}
1224 @item
1225 @samp{value}
1226 @item
1227 @samp{both}
1228 @end itemize
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.
1233 @end defun
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}.
1238 @end defun
1240 @defun text-info text
1241 Returns the parameters of @var{text} as a list in the form:
1243 @example
1244 ((anchor-x . anchor-y) align angle string size visible show color)
1245 @end example
1247 See @code{make-text} for a description of all of these parameters.
1248 @end defun
1250 @defun text-center text
1251 Returns the position of the anchor of @var{text} in the form
1252 @code{(x . y)}.
1253 @end defun
1255 @defun text-align text
1256 Returns the alignment of @var{text} as one of the following symbols:
1258 @itemize
1259 @item
1260 @samp{lower-left}
1261 @item
1262 @samp{middle-left}
1263 @item
1264 @samp{upper-left}
1265 @item
1266 @samp{lower-center}
1267 @item
1268 @samp{middle-center}
1269 @item
1270 @samp{upper-center}
1271 @item
1272 @samp{lower-right}
1273 @item
1274 @samp{middle-right}
1275 @item
1276 @samp{upper-right}
1277 @end itemize
1278 @end defun
1280 @defun text-angle text
1281 Returns the angle that @var{text} is displayed at as an integer
1282 multiple of 90 degrees.
1283 @end defun
1285 @defun text-string text
1286 Returns the string content of @var{text}.
1287 @end defun
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
1292 @samp{U+0000}).
1293 @end defun
1295 @defun text-size text
1296 Return the font size of @var{text} as an integer.
1297 @end defun
1299 @defun text-visible? text
1300 Returns @samp{#t} if and only if @var{text} is set to be visible.
1301 @end defun
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.
1306 @end defun
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:
1313 @itemize
1314 @item
1315 @samp{name}
1316 @item
1317 @samp{value}
1318 @item
1319 @samp{both}
1320 @end itemize
1321 @end defun
1323 @node Components
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:
1348 @enumerate
1349 @item
1350 If @var{mirror} is true, the symbol is reflected in the line x = 0.
1351 @item
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
1354 degrees).
1355 @item
1356 Finally, the symbol is translated by @var{position}.
1357 @end enumerate
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
1363 symbol).
1365 @defun component? object
1366 Returns @samp{#t} if and only if @var{object} is a component @code{object}.
1367 @end defun
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
1378 embedded.
1379 @end defun
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.
1388 @end defun
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.
1396 @end defun
1398 @defun component-info component
1399 Returns the parameters of @var{component} as a list of the form:
1401 @example
1402 (basename (x . y) angle mirror locked)
1403 @end example
1404 @end defun
1406 @defun component-basename component
1407 Returns the basename of @var{component}.
1408 @end defun
1410 @defun component-position component
1411 Returns the position to which the original symbol was translated when
1412 creating @var{component}.
1413 @end defun
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.
1418 @end defun
1420 @defun component-mirror? component
1421 Returns true if the original symbol was mirrored when creating
1422 @var{component}.
1423 @end defun
1425 @defun component-locked? component
1426 Returns true if @var{component} is non-selectable.
1427 @end defun
1429 @defun component-contents component
1430 Returns the contents of @var{components} as a list of objects.
1431 @end defun
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}.
1439 @end defun
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:
1449 @itemize
1450 @item
1451 are part of a @code{page};
1452 @item
1453 are part of a component @code{object} other than @var{component};
1454 @item
1455 have attached attributes
1456 @item
1457 are attached as an attribute.
1458 @end itemize
1459 @end defun
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
1469 @code{object}.
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).
1474 @end defun
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})}.
1483 @end defun
1485 @defun attrib-name attrib
1486 Returns the name part of @var{attrib}, as a string.
1487 @end defun
1489 @defun attrib-value attrib
1490 Returns the value part of @var{attrib}, as a string.
1491 @end defun
1493 @defun set-attrib-value! attrib value
1494 Sets the value part of @var{attrib} to @var{value}.
1495 @end defun
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}.
1502 @end defun
1504 @defun object-attribs object
1505 Returns a list of all attributes attached to @var{object}.
1506 @end defun
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:
1513 @itemize
1514 @item
1515 Neither @var{object} nor any of the @var{attribs} may be already
1516 attached as an attribute;
1517 @item
1518 Both @var{object} and all @var{attribs} must be part of the same
1519 @code{page} and/or component @code{object};
1520 @end itemize
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.
1528 @end defun
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.
1535 @end defun
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
1545 list.
1546 @end defun
1548 @defun attrib-inherited? attrib
1549 Returns @samp{#t} if @var{attrib} is an inherited attribute.
1550 @end defun
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}.
1558 @end defun
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.
1570 @end defun
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.
1582 @menu
1583 * Configuration contexts::
1584 * Configuration parameters::
1585 * Configuration events::
1586 * Configuration errors::
1587 @end menu
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
1596 exist).
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
1623 @var{path}.
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}.
1628 @end defun
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
1634 loaded.
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}).
1644 Since 1.10.
1645 @end defun
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:
1651 @enumerate
1652 @item
1653 By searching @env{XDG_CONFIG_DIRS} for a @file{gEDA/geda-system.conf}
1654 file.
1655 @item
1656 By checking the system configuration directory specified at
1657 compile-time for a @file{gEDA/geda-system.conf} file.
1658 @end enumerate
1660 Since 1.10.
1661 @end defun
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.
1668 Since 1.10.
1669 @end defun
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}.
1682 Since 1.10.
1683 @end defun
1685 @defun config-load! cfg
1686 Attempt to load configuration parameters for the context @var{cfg}
1687 from its associated file.
1688 @end defun
1690 @defun config-loaded? cfg
1691 Determine whether the context @var{cfg} has been successfully loaded
1692 from file.
1694 Since 1.10.
1695 @end defun
1697 @defun config-save! cfg
1698 Attempt to save configuration parameters for the context @var{cfg} to
1699 its associated file.
1701 Since 1.10.
1702 @end defun
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.
1708 Since 1.10.
1709 @end defun
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
1716 not permitted.
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.
1723 Since 1.10.
1724 @end defun
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
1733 applications.
1735 Since 1.10.
1736 @end defun
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:
1747 @itemize
1748 @item
1749 Preferred PDF reader
1750 @item
1751 Preferred web browser
1752 @item
1753 Search path for Scheme plugins
1754 @end itemize
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.
1766 Since 1.10.
1767 @end defun
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).
1777 Since 1.10.
1778 @end defun
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}.
1785 Since 1.10.
1786 @end defun
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:
1797 @table @dfn
1798 @item Group
1799 A string which identifies the general category in which the
1800 parameter lies (e.g. which application and/or plugin).
1801 @item Name
1802 A string which specifically identifies the parameter within the group.
1803 @item Value
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.
1806 @end table
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
1814 contexts.
1816 Since 1.10.
1817 @end defun
1819 @defun config-has-group? cfg group
1820 Determines whether @var{cfg} or its parent contexts contain the
1821 specified @var{group}
1823 Since 1.10.
1824 @end defun
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.
1830 Since 1.10.
1831 @end defun
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}.
1837 Since 1.10.
1838 @end defun
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
1844 context.
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}.
1853 Since 1.10.
1854 @end defun
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.
1861 Since 1.10.
1862 @end defun
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:
1872 @itemize
1873 @item
1874 Strings
1875 @item
1876 Booleans
1877 @item
1878 Exact integers
1879 @item
1880 Inexact real numbers
1881 @end itemize
1883 In addition, lists of all the above are supported.
1885 @defun config-string cfg group key
1886 Retrieve configuration value as a string.
1888 Since 1.10.
1889 @end defun
1891 @defun config-boolean cfg group key
1892 Retrieve configuration value as a boolean.
1894 Since 1.10.
1895 @end defun
1897 @defun config-int cfg group key
1898 Retrieve configuration value as an exact integer.
1900 Since 1.10.
1901 @end defun
1903 @defun config-real cfg group key
1904 Retrieve configuration value as an inexact real number.
1906 Since 1.10.
1907 @end defun
1909 @defun config-string-list cfg group key
1910 Retrieve configuration value as a list of strings.
1912 Since 1.10.
1913 @end defun
1915 @defun config-boolean-list cfg group key
1916 Retrieve configuration value as a list of booleans.
1918 Since 1.10.
1919 @end defun
1920 @defun config-int-list cfg group key
1921 Retrieve configuration value as a list of exact integers.
1923 Since 1.10.
1924 @end defun
1926 @defun config-real-list cfg group key
1927 Retrieve configuration value as a list of inexact real numbers.
1929 Since 1.10.
1930 @end defun
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}.
1937 Since 1.10.
1938 @end defun
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
1953 key from it.
1955 A configuration event handler must be a closure that accepts three
1956 arguments:
1958 @example
1959 handler cfg group key
1960 @end example
1962 @var{cfg} is always the configuration context that received the event,
1963 and the @var{group} and @var{key} identify the configuration parameter
1964 that changed.
1966 @defun add-config-event! cfg handler
1967 Registers @var{handler} to be called when configuration changes in the
1968 context @var{cfg}.
1970 Since 1.10.
1971 @end defun
1973 @defun remove-config-event! cfg handler
1974 Stops @var{handler} from being called when configuration changes in
1975 the context @var{cfg}.
1977 Since 1.10.
1978 @end defun
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
1985 one of two keys:
1987 @enumerate
1988 @item
1989 File errors (e.g. ``Access denied'' or ``File not found'' are
1990 indicated with the @code{system-error} key.
1991 @item
1992 All other errors are indicated using the @code{config-error} key.
1993 @end enumerate
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:
1998 @table @code
1999 @item unknown-encoding
2000 The text being parsed was in an unknown encoding.
2001 @item parse
2002 The configuration data wass ill-formed.
2003 @item key-not-found
2004 A requested configuration key was not found.
2005 @item group-not-found
2006 A requested configuration group was not found.
2007 @item invalid-value
2008 A configuration value could not be parsed into the requested format.
2009 @end table
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
2023 platform.
2024 @end defvar
2026 @defvar separator
2027 A string containing @code{separator-char}.
2028 @end defvar
2030 @defvar path-separator-char
2031 The character used for separating the elements in @samp{PATH}-like
2032 environment variables on the host platform.
2033 @end defvar
2035 @defvar path-separator
2036 A string containing @code{path-separator-char}.
2037 @end defvar
2039 @defun platform
2040 Returns a list of symbols describing the host platform.  The returned
2041 symbols may include:
2043 @itemize
2044 @item
2045 @samp{carbon}
2046 @item
2047 @samp{cygwin}
2048 @item
2049 @samp{linux}
2050 @item
2051 @samp{win32}
2052 @item
2053 @samp{win32-native}
2054 @end itemize
2055 @end defun
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}
2060 otherwise.
2061 @end defun
2063 @defun sys-data-dirs
2064 Returns an ordered list of directories in which to access system-wide
2065 gEDA data.
2066 @end defun
2068 @defun sys-config-dirs
2069 Returns an ordered list of directories in which to access system-wide
2070 gEDA configuration information.
2071 @end defun
2073 @defun user-data-dir
2074 Returns the directory in which to store user-specific gEDA data.
2075 @end defun
2077 @defun user-config-dir
2078 Returns the directory in which to store user-specific gEDA
2079 configuration information.
2080 @end defun
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@}}.
2087 @example
2088 (expand-env-variables "$@{HOME@}/path/to/dir")
2089 @end example
2091 @end defun
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.
2100 @menu
2101 * Windows and views::
2102 * Key mapping::
2103 * Selections::
2104 * Hooks::
2105 * Actions::
2106 * Miscellanous gschem functions::
2107 @end menu
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.
2115 @defun active-page
2116 Returns the @code{page} currently being displayed for editing.
2117 @end defun
2119 @defun set-active-page! page
2120 Sets the current @code{page} to @var{page}.
2121 @end defun
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,
2126 returns @samp{#f}.
2127 @end defun
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.
2133 @end defun
2135 @node Key mapping
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
2148 @key{A}.
2150 @defun key? obj
2151 Returns @samp{#t} if and only if @var{obj} is a key combination.
2152 @end defun
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.
2160 @end defun
2162 @defun key->string key
2163 Converts @var{key} to a string, using a format suitable for passing to
2164 @code{string->key}.
2165 @end defun
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.
2173 @example
2174 (key->display-string (string->key ``<Control>bracketright''))
2175 => ``Ctrl+]''
2176 @end example
2177 @end defun
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:
2186 @example
2187 (string->keys ``F N'')
2188 => #(#<gschem-key "F"> #<gschem-key "N">)
2189 @end example
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.
2195 @defun keys? obj
2196 Returns @samp{#t} if and only if @var{obj} is a valid key sequence.
2197 @end defun
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.
2203 @end defun
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}.
2208 @end defun
2210 @defun keys->display-string keys
2211 Converts the key sequence @var{keys} to a string, using a format
2212 suitable for display.
2213 @end defun
2215 @subsection Keymaps
2217 A @dfn{keymap} maps key combinations to values (usually actions) or to
2218 other keymaps.  @xref{Actions}.
2220 @defun keymap? obj
2221 Returns @samp{#t} if and only if @var{obj} is a keymap.
2222 @end defun
2224 @defun make-keymap
2225 Creates and returns a new, empty keymap.
2226 @end defun
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.
2232 @end defun
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}.
2237 @end defun
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},
2242 returns @samp{#f}.
2243 @end defun
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.
2248 @end defun
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
2253 keymaps.
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
2260 bindings.
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
2267 keymap.
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.
2272 @end defun
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}.
2278 @end defun
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}.
2284 @end defun
2286 @node Selections
2287 @section Selections
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
2298 @code{object}s.
2299 @end defun
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}.
2308 @end defun
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}.
2317 @end defun
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}.
2327 @end defun
2329 @node Hooks
2330 @section Hooks
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
2337 the user.
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
2341 explicitly.
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.
2352 @end defvar
2354 @defvar remove-objects-hook
2355 Called after objects are removed from the page.  Argument is a list of
2356 the objects being removed.
2357 @end defvar
2359 @defvar move-objects-hook
2360 Called after objects are moved.  Argument is a list of the objects
2361 that were mirrored.
2362 @end defvar
2364 @defvar mirror-objects-hook
2365 Called after objects are mirrored.  Argument is a list of the objects
2366 that were mirrored.
2367 @end defvar
2369 @defvar rotate-objects-hook
2370 Called after objects are rotated.  Argument is a list of the objects
2371 that were rotated.
2372 @end defvar
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.
2378 @end defvar
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.
2383 @end defvar
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.
2388 @end defvar
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.
2393 @end defvar
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.
2398 @end defvar
2400 @defvar new-page-hook
2401 Called when a new page is created. The argument is the new page.
2402 @end defvar
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}.
2408 Since 1.10.
2409 @end defvar
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
2417 superior keymap.
2419 Since 1.10.
2420 @end defvar
2422 @node Actions
2423 @section Actions
2424 @cindex Actions
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
2437 show in menus, etc.
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{&}
2443 symbol.
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.
2452 @example
2453 (define-action (&report-bug #:label ``Report Bug'' #:icon ``web-browser'')
2454   (show-uri ``http://bugs.launchpad.net/geda/+reportbug''))
2455 @end example
2457 Since 1.10.
2458 @end defmac
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
2463 action.
2465 Since 1.10.
2466 @end defun
2468 @defun action? obj
2469 Returns @samp{#t} iff @var{obj} is a gschem action, and @samp{#f}
2470 otherwise.
2472 Since 1.10.
2473 @end defun
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.
2481 Since 1.10.
2482 @end defun
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.
2488 Since 1.10.
2489 @end defun
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:
2505 @itemize
2506 @item
2507 A thunk.
2508 @item
2509 A gschem action.
2510 @item
2511 A symbol naming an action or a thunk in the current module.
2512 @end itemize
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:
2520 @example
2521 (eval-action! &action)
2522 (&action)
2523 @end example
2525 Since 1.10.
2526 @end defun
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.
2540 Since 1.10.
2541 @end defun
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.
2548 Since 1.10.
2549 @end defun
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:
2574 @itemize
2575 @item
2576 @samp{name}
2577 @item
2578 @samp{value}
2579 @item
2580 @samp{both}
2581 @end itemize
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}.
2588 @end defun
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.
2595 @defun show-uri uri
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
2599 configuration.
2600 @end defun
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
2605 a local file.
2606 @end defun
2608 @node Concept Index
2609 @unnumbered Concept Index
2611 @printindex cp
2613 @node Function Index
2614 @unnumbered Function Index
2616 @printindex fn
2618 @node Variable Index
2619 @unnumbered Variable Index
2621 @printindex vr
2623 @bye