gnetlist: spice-sdb "no_end_card" option suppresses ".end"
[geda-gaf/peter-b.git] / docs / scheme-api / geda-scheme.texi
blobc4518872e42ce40f912da459567d2b11e2518b55
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 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 * System information::
347 @end menu
349 @node Core page functions
350 @section Core page functions
352 To use the functions described in this section, you will need to load
353 the @code{(geda page)} module.
355 @xref{Pages}.
357 @defun page? obj
358 Returns @samp{#t} if and only if @var{obj} is a @code{page}.
359 @end defun
361 @defun active-pages
362 Returns a list of all open @code{page}s.
363 @end defun
365 @subsection Page creation, disposal and filenames
367 Every @code{page} is associated with a @emph{filename}.  The filename
368 does not necessarily have to be a file which exists and/or is
369 accessible in the filesystem.
371 @defun make-page filename
372 Creates and returns a new, empty @code{page}, with the given
373 string @var{filename}.
374 @end defun
376 @defun close-page! page
377 Destroys @var{page}.  The returned value is undefined.
379 @strong{Warning}: This function closes and destroys @var{page}
380 immediately, regardless of whether the page has been modified since
381 loading or saving, and without asking the user.
382 @end defun
384 @defun page-filename page
385 Returns the filename associated with @var{page} as a string.
386 @end defun
388 @defun set-page-filename! page filename
389 Sets the filename of @var{page} to @var{filename}.  Returns
390 @var{page}.
391 @end defun
393 @subsection Page serialisation
395 Pages can be converted to and from strings in the gEDA schematic file
396 format.
398 @defun string->page filename string
399 Parses @var{string}, which should be in the gEDA file format, to
400 create a new @code{page}.  The initial filename for the new
401 @code{page} is @var{filename}.
403 @strong{Warning}: Due to missing functionality in the underlying C
404 library, this @code{string->page} cannot currently report invalid
405 syntax or other problems in the @var{string} passed.
406 @end defun
408 @defun page->string page
409 Returns a string representation of @var{page} in the gEDA file
410 format.
411 @end defun
413 @subsection Page contents
415 A schematic or symbol @code{page} is composed of a set of
416 @code{object}s which determine both its graphical appearance and its
417 electrical meaning.
419 @defun page-contents page
420 Returns a list of the @code{object}s which make up @var{page}.  The
421 list can be freely modified without changing the contents of
422 @var{page}.
423 @end defun
425 @defun page-append! page objects...
426 Appends zero or more @var{objects} to the contents of @var{page} in
427 the order given.  Returns @var{page}.
429 If any of the @var{objects} is already part of a @code{page} other
430 than @var{page}, or is part of a component @code{object}, raises an
431 @code{object-state} error.  Any of the @var{objects} that are already
432 in the @var{page} are ignored.
433 @end defun
435 @defun page-remove! page objects...
436 Removes zero or more @var{objects} from the contents of @var{page}.
437 Returns @var{page}.
439 Any @var{objects} that are not part of a @code{page} or component
440 @code{object} are ignored.
442 An @samp{object-state} error will be thrown if any of the
443 @var{objects} satisfies any of the following conditions:
445 @itemize
446 @item
447 part of a @code{page} other than @var{page};
448 @item
449 part of component @code{object};
450 @item
451 has attached attributes (@pxref{Attributes});
452 @item
453 is attached as an attribute.
454 @end itemize
455 @end defun
457 @defun object-page object
458 Returns the @code{page} which contains @var{object} (either directly
459 or indirectly), or @samp{#f} if @var{object} is not part of a
460 @code{page}.
462 @strong{Note}: If the @var{object} argument to @code{object-page} is
463 part of a component @code{object} which is itself part of a
464 @code{page}, that @code{page} will be returned.
465 @end defun
467 @subsection Page dirty flags
469 A @code{page} has a @emph{dirty flag} that is used to indicate to
470 applications that the @code{page} has been modified since it was last
471 loaded or saved.
473 @defun page-dirty? page
474 Returns @samp{#t} if the @var{page}'s page has been marked as dirty;
475 otherwise, returns @samp{#f}.
476 @end defun
478 @defun set-page-dirty! page [state]
479 Sets the dirty flag for @var{page}.  If @var{state} is @samp{#f},
480 clears the dirty flag; otherwise, or if @var{state} is omitted, marks
481 the page as dirty.  Returns @var{page}.
482 @end defun
484 @node Core object functions
485 @section Core object functions
487 To use the functions described in this section, you will need to load
488 the @code{(geda object)} module.
490 @menu
491 * General object functions::
492 * Lines::
493 * Nets and buses::
494 * Pins::
495 * Boxes::
496 * Circles::
497 * Arcs::
498 * Paths::
499 * Pictures::
500 * Text::
501 * Components::
502 @end menu
504 @node General object functions
505 @subsection General object functions
507 @defun object? obj
508 Returns @samp{#t} if and only if @var{obj} is an @code{object}.
509 @end defun
511 @defun copy-object object
512 Returns a deep copy of @var{object}.  The new @code{object} returned
513 has no attached attributes, and is not part of a @code{page} or part
514 of a component @code{object}.
515 @end defun
517 @defun object-component object
518 Returns the component @code{object} that contains @var{object}, or
519 @samp{#f} if @var{object} is not part of a component.
520 @end defun
522 @defun object-connections object
523 Returns a list of other @code{object}s that are @emph{directly}
524 connected to @var{object}.  If @code{object} is not included in a
525 @code{page}, raises an @samp{object-state} error.  The connections
526 reported are independent of inclusion in components.
528 For example, consider a page containing a net and a component, and the
529 component contains a single pin.  If the connectable end of the pin
530 intersects the net, then @code{(object-connections <net>)} will return
531 a list containing the pin @code{object}, and @emph{not} the component.
532 @end defun
534 @menu
535 * Object sub-types::
536 * Object transformations::
537 * Object bounds::
538 * Object color::
539 * Object fill and stroke::
540 @end menu
542 @node Object sub-types
543 @subsubsection Object sub-types
545 Schematic element @code{object}s come in several subtypes.
547 @defun object-type object
548 Returns the sub-type of @var{object} as a symbol.  The subtype will be
549 one of the following symbols:
551 @itemize
552 @item
553 @samp{arc}
554 @item
555 @samp{box}
556 @item
557 @samp{bus}
558 @item
559 @samp{circle}
560 @item
561 @samp{complex} (indicates a component @code{object})
562 @item
563 @samp{line}
564 @item
565 @samp{net}
566 @item
567 @samp{path}
568 @item
569 @samp{picture}
570 @item
571 @samp{pin}
572 @item
573 @samp{text}
574 @end itemize
575 @end defun
577 @defun object-type? object type
578 Returns @samp{#t} if and only if @var{object} is an @code{object} and
579 that its subtype is @var{type}, which should be a symbol.
580 @end defun
582 @node Object transformations
583 @subsubsection Object transformations
585 Objects can be translated, rotated, or mirrored about a point.
587 @defun translate-objects! vector [objects...]
588 Translate @var{objects} by @var{vector}, a world coordinate distance
589 in the form @samp{(x . y)}.  Returns a list of the modified
590 @var{objects}.
591 @end defun
593 @defun rotate-objects! center angle [objects...]
594 Translate @var{objects} anti-clockwise by @var{angle} about
595 @var{center}, a world coordinate position in the form @samp{(x . y)}.
596 @var{angle} must be an integer multiple of 90 degrees.  Returns a list
597 of the modified @var{objects}.
598 @end defun
600 @defun mirror-objects! x-offset [objects...]
601 Mirror @var{objects} in the line @samp{x = @var{x-offset}}.  Returns a
602 list of the modified @var{objects}.
603 @end defun
605 @node Object bounds
606 @subsubsection Object bounds
608 The bounds of an object is the smallest bounding rectangle of the
609 object, expressed in document coordinates (@pxref{Coordinate system}).
611 @defun object-bounds objects...
612 Returns the world coordinate bounding box containing all of the
613 @var{objects} passed as arguments, or @samp{#f} if none of the
614 @var{objects} have bounds (for example, this can occur if no
615 @var{objects} are specified, or if they are all empty component
616 @code{object}s).
618 @strong{Note}: @code{object-bounds} always returns the actual bounds
619 of the @var{objects}, not the visible bounds.  This means that the bounds of
620 invisible text is always included.
621 @end defun
623 @defun fold-bounds bounds...
624 Calculates the union of several sets of @var{bounds} (as returned by
625 @code{object-bounds}).  If any of the @var{bounds} are @samp{#f}, they
626 are skipped; if all of the @var{bounds} are @samp{#f}, @samp{#f} is
627 returned.
628 @end defun
630 @node Object color
631 @subsubsection Object color
633 Object colors in gEDA documents are specified as indices into a color
634 map.  This allows users to specify the color map that suits them when
635 viewing schematics and symbols.
637 @defun object-color object
638 Returns the integer color map index of the the color used to draw
639 @var{object}.
640 @end defun
642 @defun set-object-color! object color
643 Sets the integer color map index for @var{object} to @var{color}.
644 Returns @var{object}.
645 @end defun
647 @node Object fill and stroke
648 @subsubsection Object fill and stroke
650 Graphical object subtypes -- lines, boxes, circles, arcs and paths --
651 are drawn with a stroke pattern that can be configured in detail.
653 @defun object-stroke object
654 Returns the stroke settings of the @var{object}, which must be a line,
655 box, circle, arc or path @code{object}.  The return value is a list of
656 parameters:
658 @enumerate
659 @item
660 stroke width, as an integer number of world units
661 @item
662 cap style, one of the symbols @code{none}, @code{square} or
663 @code{round}.
664 @item
665 dash style, one of the symbols @code{solid}, @code{dotted},
666 @code{dashed}, @code{center} or @code{phantom}.
667 @item
668 up to two dash parameters, depending on the dash style:
669 @itemize
670 @item
671 for solid lines, no parameters;
672 @item
673 for dotted lines, dot spacing;
674 @item
675 for other styles, dot/dash spacing and dash length.
676 @end itemize
677 @end enumerate
678 @end defun
680 @defun set-object-stroke! object width cap dash [dash-space [dash-length]]
681 Set the stroke settings of the @var{object}, which must be a line,
682 box, circle, arc or path @code{object}.  The arguments are the same as
683 the contents of the list returned by @code{object-stroke}.  Returns
684 @var{object}.
685 @end defun
687 @defun object-stroke-width object
688 Returns the integer stroke width of @var{object}, which must be a
689 line, box, circle, arc or path @code{object}.
690 @end defun
692 @defun object-stroke-cap object
693 Returns the stroke cap style of @var{object}, which must be a line,
694 box, circle, arc or path @code{object}.  The returned value is one of
695 the symbols @code{none}, @code{square} or @code{round}.
696 @end defun
698 @defun object-stroke-dash object
699 Returns the dash style of @var{object}, which must be a line, box,
700 circle, arc or path @code{object}.  The return value is a list of
701 between one and three parameters:
703 @enumerate
704 @item
705 dash style, one of the symbols @code{solid}, @code{dotted},
706 @code{dashed}, @code{center} or @code{phantom}.
707 @item
708 for styles other than @code{solid}, dot/dash spacing;
709 @item
710 for @code{dashed}, @code{center} and @code{phantom}, dash length.
711 @end enumerate
712 @end defun
714 Some types of @code{object} -- boxes, circles and paths -- can have
715 their interiors filled with a variety of patterns.
717 @defun object-fill object
718 Returns the fill settings of @var{object}, which must be a box, circle
719 or path @code{object}.  The return value is a list of one to six
720 parameters:
722 @enumerate
723 @item
724 fill style, one of the symbols @code{hollow}, @code{solid},
725 @code{mesh} or @code{hatch};
726 @item
727 up to five fill parameters, depending on fill style:
728 @enumerate
729 @item
730 none for @code{hollow} or @code{solid} fills;
731 @item
732 line width, line angle (in degrees) and line spacing for @code{hatch} fills;
733 @item
734 line width, first angle and spacing, and second angle and spacing for
735 @code{mesh} fills.
736 @end enumerate
737 @end enumerate
738 @end defun
740 @defun set-object-fill! object fill-type . fill-args
741 Sets the fill settings of @var{object}, which must be a box, circle or
742 path @code{object}.  The arguments are the same as the contents of the
743 list returned by @code{object-fill}.  Returns @var{object}.
744 @end defun
746 @node Lines
747 @subsection Lines
748 Line @code{object}s are straight graphical line segments with no
749 electrical meaning.  A line's geometrical parameters are a start point
750 and end point, and it supports different colors and stroke styles.
752 Many of the functions for manipulating lines are also used to
753 manipulate line-like objects such as nets, buses or pins.
755 @defun line? object
756 Returns @samp{#t} if and only if @var{object} is a line @code{object}.
757 @end defun
759 @defun make-line start end [color]
760 Creates and returns a new line @code{object}.  @var{start} is the
761 position of the start of the new line in the form @code{(x . y)} and
762 @var{end} is the position of end of the line.  If @var{color} is
763 specified, it should be the integer color map index of the color with
764 which to draw the line.  If @var{color} is not specified, the default
765 line color is used.
766 @end defun
768 @defun set-line! line start end [color]
769 Sets the parameters of @var{line} (which may be a line, net, bus or
770 pin @code{object}).  The arguments are the same as to
771 @code{make-line}.  Returns @var{line}.
772 @end defun
774 @defun line-info line
775 Returns the parameters of @var{line} (which may be a line, net, bus or
776 pin @code{object}).  The return value is a list in the form:
778 @example
779 ((start-x . start-y) (end-x . end-y) color)
780 @end example
782 @strong{Note}: For pin @code{object}s, first coordinate is the
783 connectable point on the pin.
784 @end defun
786 @defun line-start line
787 Returns the position @samp{(x . y)} of the start of @var{line} (which
788 may be a line, net, bus or pin @code{object}).  For pin
789 @code{objects}, this is the position of the connectable point on the
790 pin.
791 @end defun
793 @defun line-end line
794 Returns the position @samp{(x . y)} of the end of @var{line} (which
795 may be a line, net, bus or pin @code{object}).
796 @end defun
798 @node Nets and buses
799 @subsection Nets and buses
801 Net and bus @code{object}s are straight line segments which represent
802 electrical connectivity.  Nets represent single wires, and buses
803 multi-wire connections of arbitrary composition.
805 All of the functions that work on line @code{object}s also work with
806 nets and buses (@pxref{Lines}).  Note that @code{line?} will return
807 @code{#f} if called with a net or bus argument.
809 @defun net? object
810 Returns @samp{#t} if and only if @var{object} is a net.
811 @end defun
813 @defun make-net start end [color]
814 Creates and returns a new net @code{object}.  @var{start} is the
815 position of the start of the new net in the form @code{(x . y)} and
816 @var{end} is the position of end of the net.  If @var{color} is
817 specified, it should be the integer color map index of the color with
818 which to draw the net.  If @var{color} is not specified, the default
819 net color is used.
820 @end defun
822 @defun bus? object
823 Returns @samp{#t} if and only if @var{object} is a bus.
824 @end defun
826 @defun make-bus start end [color]
827 Creates and returns a new bus @code{object}.  Arguments are as for
828 @code{make-net}.
829 @end defun
831 @node Pins
832 @subsection Pins
834 Pin @code{objects} are straight line segments which represent
835 connectable points in symbols or subcircuits, such as the pins of a
836 semiconductor package.  Only one end of a pin can be connected to
837 nets, buses or other pins; the rest of a pin is purely graphical.
839 Pins come in two varieties: @dfn{net pins} and @dfn{bus pins}, which
840 are used for connections to nets and buses respectively (@pxref{Nets
841 and buses}).
843 All of the functions that work on line @code{object}s also work with
844 pins (@pxref{Lines}).  Note that @code{line?} will return @code{#f} if
845 called with a pin argument.
847 @defun pin? object
848 Returns @samp{#t} if and only if @var{object} is a pin @code{object}.
849 @end defun
851 @defun net-pin? object
852 Returns @samp{#t} if and only if @var{object} is a net pin.
853 @end defun
855 @defun make-net-pin start end [color]
856 Creates and returns a new net pin @code{object}.  @var{start} is the
857 position of the start of the new pin (the connectable end) in the form
858 @code{(x . y)} and @var{end} is the position of end of the pin.  If
859 @var{color} is specified, it should be the integer color map index of
860 the color with which to draw the pin.  If @var{color} is not
861 specified, the default pin color is used.
862 @end defun
864 @defun bus-pin? object
865 Returns @samp{#t} if and only if @var{object} is a bus pin.
866 @end defun
868 @defun make-bus-pin start end [color]
869 Creates and returns a new bus pin @code{object}.  Arguments are as for
870 @code{make-net-pin}.
871 @end defun
873 @node Boxes
874 @subsection Boxes
876 Boxes are rectangles specified by the coordinates of their top left
877 and bottom right corners.  They are purely graphical, and have no
878 electrical meaning.  They can be drawn in different colors, and with
879 various stroke and fill settings.
881 @xref{Object color}.
882 @xref{Object fill and stroke}.
884 @defun box? object
885 Returns @samp{#t} if and only of @var{object} is a box @code{object}.
886 @end defun
888 @defun make-box top-left bottom-right [color]
889 Creates and returns a new box @code{object}.  @var{top-left} is the
890 position of the top left of the new box in the form @code{(x . y)},
891 and @var{bottom-right} is the position of the bottom right of the box.
892 If @var{color} is specified, it should be the integer color map index
893 of the color with which to draw the box.  If @var{color} is not
894 specified, the default box color is used.
895 @end defun
897 @defun set-box! box top-left bottom-right [color]
898 Sets the parameters of @var{box}. The arguments are the same as to
899 @code{make-box}.  Returns @var{box}.
900 @end defun
902 @defun box-info box
903 Returns the parameters of @var{box}.  The return value is a list in the form:
905 @example
906 ((top-left-x . top-left-y) (bottom-right-x . bottom-right-y) color)
907 @end example
908 @end defun
910 @defun box-top-left box
911 Returns the position of the top left corner of @var{box} in the form
912 @code{(x . y)}.
913 @end defun
915 @defun box-bottom-right box
916 Returns the position of the bottom right corner of @var{box} in the
917 form @code{(x . y)}.
918 @end defun
920 @node Circles
921 @subsection Circles
923 Circle @code{objects} are specified by center position and radius, and
924 are purely graphical with no electrical meaning.  They can be drawn in
925 different colors, and with various stroke and fill settings.
927 @xref{Object color}.
928 @xref{Object fill and stroke}.
930 @defun circle? object
931 Returns @samp{#t} if and only of @var{object} is a circle @code{object}.
932 @end defun
934 @defun make-circle center radius [color]
935 Creates and returns a new circle @code{object}.  @var{center} is the
936 position of the center of the new circle in the form @code{(x . y)},
937 and @var{radius} is the integer radius of the circle.  If @var{color}
938 is specified, it should be the integer color map index of the color
939 with which to draw the circle.  If @var{color} is not specified, the
940 default circle color is used.
941 @end defun
943 @defun set-circle! circle center radius [color]
944 Sets the parameters of @var{circle}. The arguments are the same as to
945 @code{make-circle}.  Returns @var{circle}.
946 @end defun
948 @defun circle-info circle
949 Returns the parameters of @var{circle} as a list of the form:
951 @example
952 ((center-x . center-y) radius color)
953 @end example
954 @end defun
956 @defun circle-center circle
957 Returns the position of the center of @var{circle} as in the form
958 @code{(x . y)}.
959 @end defun
961 @defun circle-radius circle
962 Returns the radius of @var{circle} as an integer.
963 @end defun
965 @node Arcs
966 @subsection Arcs
967 Arc @code{objects} are specified by center position, radius, and start
968 and end angles.  They are purely graphical with no electrical
969 meaning. They can be drawn in different colors, and with various
970 stroke settings.
972 @defun arc? object
973 Returns @samp{#t} if and only if @var{object} is an arc @code{object}.
974 @end defun
976 @defun make-arc center radius start-angle end-angle [color]
977 Creates and returns a new arc @code{object}.  @var{center} is the
978 position of the center of the new arc in the form @code{(x . y)}, and
979 @var{radius} is the integer radius of the arc.  @var{start-angle} and
980 @var{end-angle} are the angles at which to start and end the arc, in
981 degrees. If @var{color} is specified, it should be the integer color
982 map index of the color with which to draw the arc.  If @var{color}
983 is not specified, the default arc color is used.
984 @end defun
986 @defun set-arc! arc center radius start-angle end-angle [color]
987 Sets the parameters of @var{arc}. The arguments are the same as to
988 @code{make-arc}. Returns @var{arc}.
989 @end defun
991 @defun arc-info arc
992 Returns the parameters of @var{arc} as a list of the form:
994 @example
995 ((center-x . center-y) radius start-angle end-angle color)
996 @end example
997 @end defun
999 @defun arc-center arc
1000 Returns the position of the center of @var{arc} in the form
1001 @code{(x . y)}.
1002 @end defun
1004 @defun arc-radius arc
1005 Returns the radius of @var{arc} as an integer.
1006 @end defun
1008 @defun arc-start-angle arc
1009 Returns the start angle of @var{arc} as an integer number of degrees.
1010 @end defun
1012 @defun arc-end-angle arc
1013 Returns the end angle of @var{arc} as an integer number of degrees.
1014 @end defun
1016 @node Paths
1017 @subsection Paths
1019 Paths are arbitrary shapes comprised of straight lines and BĂ©zier
1020 curves.  Each path contains a sequence of @emph{path elements}, each
1021 of which requires zero or more absolute position parameters.  The
1022 element types supported by gEDA are:
1024 @itemize
1025 @item
1026 @samp{moveto} elements represent a step (without drawing) to another
1027 point in the schematic, and begin a new subpath.  @samp{moveto}
1028 elements need a single position parameter, which is the position of
1029 the endpoint of the move.
1030 @item
1031 @samp{lineto} elements draw a straight line from the current point to
1032 the point specified by a single position parameter.
1033 @item
1034 @samp{curveto} elements draw a BĂ©zier curve from the current point.
1035 The curve requires three position parameters: the position of the
1036 first control point; the position of the second control point; and the
1037 endpoint of the curve.
1038 @item
1039 @samp{closepath} elements close the current subpath by drawing a
1040 straight line from the current point to the subpath's initial point.
1041 They take no parameters.
1042 @end itemize
1044 @defun path? object
1045 Returns @samp{#t} if and only if @var{object} is a path @code{object}.
1046 @end defun
1048 @defun path-length path
1049 Returns the number of path elements in @var{path}.
1050 @end defun
1052 @defun path-ref path K
1053 Returns the @var{K}th element in @var{path}.  The return value is a
1054 list.  The first item in the list is a symbol indicating the type of
1055 element, and any additional items are the position parameters of the
1056 element.  For example, a call to @code{path-ref} might return:
1058 @example
1059 (curveto (800 . 525) (700 . 700) (500 . 700))
1060 @end example
1062 If @var{K} is not a valid offset into @var{path}, raises an
1063 @samp{out-of-range} error.
1064 @end defun
1066 @defun path-remove! path K
1067 Removes the @var{K}th element in @var{path}, returning @var{path}.  If
1068 @var{K} is not a valid offset, raises an @samp{out-of-range} error.
1069 @end defun
1071 @defun path-insert! path K type [positions...]
1072 Inserts a new element into @var{path} at index @var{K}.  @var{type} is
1073 a symbol indicating the type of element to insert, using the
1074 parameters @var{positions}.  If @var{K} is less than zero or greater
1075 than the number of elements @var{path} already contains, the new
1076 element is appended to the path.  For example, to append a straight
1077 line section to the current path:
1079 @example
1080 (path-insert! path -1 'lineto '(500. 100))
1081 @end example
1082 @end defun
1084 @node Pictures
1085 @subsection Pictures
1087 A picture object displays an image in the schematic, and is a purely
1088 graphical element.  Pictures may be in any format supported by the
1089 user's GdkPixbuf installation (but note that images that can't be
1090 loaded for some reason are preserved).  The @var{top-left},
1091 @var{bottom-right}, @var{angle} and @var{mirror} properties of a
1092 picture object indicate the transformation that was applied to the
1093 original image.  The transformation is applied as follows:
1095 @enumerate
1096 @item
1097 If @var{mirror} is true, the picture is reflected about its vertical
1098 centerline.
1099 @item
1100 The picture is rotated by @var{angle} anticlockwise about its center
1101 (@var{angle} may only be an integer multiple of 90 degrees).
1102 @item
1103 The picture is scaled and translated to fit within the rectangle
1104 defined by the points @var{top-left} and @var{bottom-right}.
1105 @end enumerate
1107 @defun picture? object
1108 Returns @samp{#t} if and only if @var{object} is a picture @code{object}.
1109 @end defun
1111 @defun make-picture/vector vector filename top-left bottom-right angle mirror
1112 Creates and returns a new picture object for @var{filename}, by
1113 reading image data from @var{vector} (which should be in a standard
1114 image file format).  If @var{vector} could not be loaded, an error is
1115 raised.  @var{top-left}, @var{bottom-right}, @var{angle} and
1116 @var{mirror} specify the picture transformation.
1118 The points @var{top-left} and @var{bottom-right} should be specified
1119 in the form @samp{(x . y)}.
1120 @end defun
1122 @defun set-picture! picture top-left bottom-right angle mirror
1123 Sets the picture transformation for @var{picture}.
1124 @end defun
1126 @defun picture-info picture
1127 Returns the parameters of @var{picture} as a list in the form:
1129 @example
1130 ((top-left-x . top-left-y) (bottom-right-x . bottom-right-y) angle mirror)
1131 @end example
1132 @end defun
1134 @defun picture-filename picture
1135 Returns the filename associated with @var{picture} as a string.
1136 @end defun
1138 @defun picture-top-left picture
1139 Returns the position of the top left corner of @samp{picture} in the
1140 form @samp{(x . y)}.
1141 @end defun
1143 @defun picture-bottom-right picture
1144 Returns the position of the bottom right corner of @samp{picture} in
1145 the form @samp{(x . y)}.
1146 @end defun
1148 @defun picture-angle picture
1149 Returns the angle to rotate @samp{picture} by, as an integer number of
1150 degrees.
1151 @end defun
1153 @defun picture-mirror? picture
1154 Returns true if @samp{picture} is mirrored.
1155 @end defun
1157 @node Text
1158 @subsection Text
1160 Text fulfils two roles, as straightforward labels and notes on
1161 schematics and symbols, and as attached or floating attributes
1162 (@pxref{Attributes}).  A text @code{object} can be aligned in
1163 different ways relative to its anchor position, and can be displayed
1164 in different font sizes.
1166 Any text can be set to be visible or invisible on printed output (and
1167 gschem provides ways to preview invisible text).  When a text
1168 @code{object} is an attribute (i.e. its string is in a
1169 @samp{@var{name}=@var{value}} format) then the visibility settings are
1170 more fine-grained: the text can be set to display just the attribute
1171 name, just the attribute value, or both.
1173 @xref{Attributes}.
1175 @defun text? object
1176 Returns @samp{#t} if and only if @var{object} is a text @code{object}.
1177 @end defun
1179 @defun make-text anchor align angle string size visible show [color]
1180 Creates and returns a new text @code{object}.  @var{anchor} is the
1181 position of the anchor of the new text in the form @code{(x . y)}, and
1182 @var{align} is a symbol determining how the text should be aligned
1183 relative to the anchor.  @var{align} must be one of the following
1184 symbols:
1186 @itemize
1187 @item
1188 @samp{lower-left}
1189 @item
1190 @samp{middle-left}
1191 @item
1192 @samp{upper-left}
1193 @item
1194 @samp{lower-center}
1195 @item
1196 @samp{middle-center}
1197 @item
1198 @samp{upper-center}
1199 @item
1200 @samp{lower-right}
1201 @item
1202 @samp{middle-right}
1203 @item
1204 @samp{upper-right}
1205 @end itemize
1207 For example, if @var{align} is @samp{upper-center}, the anchor will be
1208 located at the top center of the rendered text block.
1210 @var{angle} should be an integer multiple of 90 degrees, determining
1211 the angle which the text should be displayed at.  @var{string} is the
1212 string contents for the @code{text} object, and must not contain any
1213 null characters (@samp{#\0} in Scheme, Unicode
1214 @samp{U+0000}. @var{size} is the font size to use.  If @var{visible}
1215 is @samp{#f}, the text will be invisible; otherwise, it will be
1216 visible.
1218 When the @var{string} is in an attribute format (@pxref{Attributes}),
1219 the @var{show} argument determines which parts of the @var{string}
1220 will be displayed.  It must be one of the following symbols:
1222 @itemize
1223 @item
1224 @samp{name}
1225 @item
1226 @samp{value}
1227 @item
1228 @samp{both}
1229 @end itemize
1231 If @var{color} is specified, it should be the integer color map index
1232 of the color with which to draw the text.  If @var{color} is not
1233 specified, the default arc color is used.
1234 @end defun
1236 @defun set-text! text anchor align angle string size visible show [color]
1237 Sets the parameters of @var{text}. The arguments are the same as to
1238 @code{make-text}. Returns @var{text}.
1239 @end defun
1241 @defun text-info text
1242 Returns the parameters of @var{text} as a list in the form:
1244 @example
1245 ((anchor-x . anchor-y) align angle string size visible show color)
1246 @end example
1248 See @code{make-text} for a description of all of these parameters.
1249 @end defun
1251 @defun text-center text
1252 Returns the position of the anchor of @var{text} in the form
1253 @code{(x . y)}.
1254 @end defun
1256 @defun text-align text
1257 Returns the alignment of @var{text} as one of the following symbols:
1259 @itemize
1260 @item
1261 @samp{lower-left}
1262 @item
1263 @samp{middle-left}
1264 @item
1265 @samp{upper-left}
1266 @item
1267 @samp{lower-center}
1268 @item
1269 @samp{middle-center}
1270 @item
1271 @samp{upper-center}
1272 @item
1273 @samp{lower-right}
1274 @item
1275 @samp{middle-right}
1276 @item
1277 @samp{upper-right}
1278 @end itemize
1279 @end defun
1281 @defun text-angle text
1282 Returns the angle that @var{text} is displayed at as an integer
1283 multiple of 90 degrees.
1284 @end defun
1286 @defun text-string text
1287 Returns the string content of @var{text}.
1288 @end defun
1290 @defun set-text-string! text str
1291 Set the string content of @var{text} to @var{str}.  @var{str} must not
1292 contain any null characters (@samp{#\0} in Scheme, Unicode
1293 @samp{U+0000}).
1294 @end defun
1296 @defun text-size text
1297 Return the font size of @var{text} as an integer.
1298 @end defun
1300 @defun text-visible? text
1301 Returns @samp{#t} if and only if @var{text} is set to be visible.
1302 @end defun
1304 @defun set-text-visibility! text visible?
1305 If @var{visible?} is @samp{#f}, sets @var{text} to be invisible;
1306 otherwise, sets it to be visible.
1307 @end defun
1309 @defun text-attribute-mode text
1310 Returns a symbol indicating which parts of @var{text} will be
1311 displayed when @var{text} is a valid attribute.  The returned value
1312 will be one of the following symbols:
1314 @itemize
1315 @item
1316 @samp{name}
1317 @item
1318 @samp{value}
1319 @item
1320 @samp{both}
1321 @end itemize
1322 @end defun
1324 @node Components
1325 @subsection Components
1327 Component @code{object}s represent instances of symbols.  They contain
1328 other @code{object}s copied from the original symbol when it is
1329 instantiated into a schematic.
1331 A component's @var{basename} is a string used to identify which symbol
1332 it originated from.  When instantiating a symbol on initial placement
1333 in a schematic, or when recreating a component while loading a
1334 schematic, the @var{basename} is used to find the underlying symbol
1335 file in the component library.
1337 @xref{Component objects}.
1339 @strong{Note}: In the gEDA C source code, these are normally called
1340 ``complex'' objects.  However, as Guile Scheme supports complex
1341 numbers, and the procedures related to working with complex numbers
1342 use the word @samp{complex} to describe them, this API uses
1343 @samp{component} to avoid ambiguity.
1345 The @var{position}, @var{angle} and @var{mirror} flag of a component
1346 indicates the transformation that was applied to the contents of the
1347 original symbol.  The transformation is applied in the following order:
1349 @enumerate
1350 @item
1351 If @var{mirror} is true, the symbol is reflected in the line x = 0.
1352 @item
1353 The symbol is rotated anti-clockwise by @var{angle} degrees about the
1354 point (0,0) (@var{angle} may only be an integer multiple of 90
1355 degrees).
1356 @item
1357 Finally, the symbol is translated by @var{position}.
1358 @end enumerate
1360 The component's contents (as returned by @code{component-contents})
1361 have the transformation already applied to them.  Updating the
1362 translation information using e.g. @code{set-component!} will not
1363 alter them -- that must be done separately (e.g. by reloading the
1364 symbol).
1366 @defun component? object
1367 Returns @samp{#t} if and only if @var{object} is a component @code{object}.
1368 @end defun
1370 @defun make-component basename position angle mirror locked
1371 Creates and returns a new, empty component @code{object} with the
1372 given @var{basename}.  @var{position}, @var{angle} and @var{mirror}
1373 specify the symbol transformation.  If @var{locked} is true, the
1374 component will be protected against accidental selection by the user
1375 (this is used in gschem e.g. for titleblocks).
1377 No attempt is made to load a symbol matching @var{basename} from
1378 component libraries, and the returned component is flagged as
1379 embedded.
1380 @end defun
1382 @defun make-component/library basename position angle mirror locked
1383 Searches the component libraries for a symbol matching @var{basename},
1384 and if found, instantiates the symbol and returns the resulting
1385 component (which is not flagged as embedded).  Arguments are as for
1386 @code{make-component}.
1388 If no match for @var{basename} is found, @samp{#f} is returned.
1389 @end defun
1391 @defun set-component! component position angle mirror locked
1392 Sets the parameters of @var{component}.  Arguments are the same as to
1393 @code{make-component}.  Returns @var{component}.
1395 @strong{Note}: Remember that modifying the transformation parameters
1396 of a component does not update the component's contents.
1397 @end defun
1399 @defun component-info component
1400 Returns the parameters of @var{component} as a list of the form:
1402 @example
1403 (basename (x . y) angle mirror locked)
1404 @end example
1405 @end defun
1407 @defun component-basename component
1408 Returns the basename of @var{component}.
1409 @end defun
1411 @defun component-position component
1412 Returns the position to which the original symbol was translated when
1413 creating @var{component}.
1414 @end defun
1416 @defun component-angle component
1417 Returns the angle by which the original symbol was rotated when
1418 creating @var{component}, as an integer number of degrees.
1419 @end defun
1421 @defun component-mirror? component
1422 Returns true if the original symbol was mirrored when creating
1423 @var{component}.
1424 @end defun
1426 @defun component-locked? component
1427 Returns true if @var{component} is non-selectable.
1428 @end defun
1430 @defun component-contents component
1431 Returns the contents of @var{components} as a list of objects.
1432 @end defun
1434 @defun component-append! component objects...
1435 Appends @var{objects} (which must not be component @code{object}s) to
1436 the contents of @var{component}.  Any @var{objects} which are already
1437 included in @var{component} are ignored.  If any @var{objects} are
1438 already part of a @code{page} or of another component @code{object},
1439 an @samp{object-state} error is raised. Returns @var{component}.
1440 @end defun
1442 @defun component-remove! component objects...
1443 Removes @var{objects} from the contents of @var{component}.  Any
1444 @var{objects} which are not part of a component or of a page are
1445 ignored. Returns @var{component}.
1447 An @samp{object-state} error will be raised if any @var{objects}
1448 satisfy any of the following conditions:
1450 @itemize
1451 @item
1452 are part of a @code{page};
1453 @item
1454 are part of a component @code{object} other than @var{component};
1455 @item
1456 have attached attributes
1457 @item
1458 are attached as an attribute.
1459 @end itemize
1460 @end defun
1462 @node Core attribute functions
1463 @section Core attribute functions
1465 To use the functions described in this section, you will need to load
1466 the @code{(geda attrib)} module.
1468 Attributes are text @code{object}s with a particular format of string.
1469 They can be floating, or they can be attached to another
1470 @code{object}.
1472 @defun attribute? object
1473 Returns true if and only if @var{object} is an attribute (i.e. a text
1474 @code{object} and in attribute format).
1475 @end defun
1477 @subsection Attribute names and values
1479 @defun parse-attrib text
1480 Splits the string from @var{text} (a text @code{object}) into name and
1481 value, if it is in attribute format.  If it is not in attribute
1482 format, raises an @samp{attribute-format} error.  The return value is
1483 in the form @samp{(@var{name} . @var{value})}.
1484 @end defun
1486 @defun attrib-name attrib
1487 Returns the name part of @var{attrib}, as a string.
1488 @end defun
1490 @defun attrib-value attrib
1491 Returns the value part of @var{attrib}, as a string.
1492 @end defun
1494 @defun set-attrib-value! attrib value
1495 Sets the value part of @var{attrib} to @var{value}.
1496 @end defun
1498 @subsection Attribute attachment
1500 @defun attrib-attachment attrib
1501 If @var{attrib} is attached to another @code{object}, returns that
1502 object.  Otherwise, returns @samp{#f}.
1503 @end defun
1505 @defun object-attribs object
1506 Returns a list of all attributes attached to @var{object}.
1507 @end defun
1509 @defun attach-attribs! object [attribs...]
1510 Attach @var{attribs} to @var{object}.  All the @var{attribs} must be
1511 text @code{object}s.  The following conditions must be satisfied, or
1512 an @samp{object-state} error will be raised:
1514 @itemize
1515 @item
1516 Neither @var{object} nor any of the @var{attribs} may be already
1517 attached as an attribute;
1518 @item
1519 Both @var{object} and all @var{attribs} must be part of the same
1520 @code{page} and/or component @code{object};
1521 @end itemize
1523 Any @var{attribs} that are already attached to @var{object} are
1524 ignored.  Returns @var{object}.
1526 @strong{Note}: For historical reasons, @code{attach-attribs!} does not
1527 require that all @var{attribs} satisfy @code{attribute?}.
1528 Nevertheless, avoid attaching non-attribute text objects as attributes.
1529 @end defun
1531 @defun detach-attribs! object [attribs...]
1532 Detach @var{attribs} from @var{object}.  Any @var{attribs} that are
1533 not attached as attributes are ignored.  If any @var{attribs} are
1534 attached to @code{object}s other than @var{object}, an
1535 @samp{object-state} error is raised.
1536 @end defun
1538 @subsection Inherited and promoted attributes
1540 @dfn{Inherited attributes} are unattached attributes inside a
1541 component @code{object}.
1543 @defun inherited-attribs object
1544 Returns the inherited attributes of @var{object}, if @var{object} is a
1545 component.  If @var{object} is not a component, returns the empty
1546 list.
1547 @end defun
1549 @defun attrib-inherited? attrib
1550 Returns @samp{#t} if @var{attrib} is an inherited attribute.
1551 @end defun
1553 @dfn{promotable attributes} are inherited attributes that are both
1554 visible and have names that are in the list of promotable attributes
1555 set with the @code{always-promote-attributes} rc file parameter.
1557 @defun promotable-attribs component
1558 Returns a list of promotable attributes of @var{component}.
1559 @end defun
1561 @defun promote-attribs! component
1562 Promote all promotable attributes from @var{component} into the
1563 @code{page} that contains @var{component}.  If @var{component} is not
1564 in a page, an @samp{object-state} error is raised.
1566 All promotable attributes are copied, and made invisible.  The copies
1567 are added to the @code{page}, and attached as attributes of @var{component}.
1569 The promoted attributes are returned.  If @var{component} is not in
1570 fact a component @code{object}, does nothing and returns the empty list.
1571 @end defun
1573 @node System information
1574 @section System information
1576 To use the functions described in this section, you will need to load
1577 the @code{(geda os)} module.
1579 This section describes some functions and variables that are useful
1580 for Scheme code that needs to behave differently depending on which
1581 operating system gEDA is running on.
1583 @defvar separator-char
1584 The directory separator character that should be used on the host
1585 platform.
1586 @end defvar
1588 @defvar separator
1589 A string containing @code{separator-char}.
1590 @end defvar
1592 @defvar path-separator-char
1593 The character used for separating the elements in @samp{PATH}-like
1594 environment variables on the host platform.
1595 @end defvar
1597 @defvar path-separator
1598 A string containing @code{path-separator-char}.
1599 @end defvar
1601 @defun platform
1602 Returns a list of symbols describing the host platform.  The returned
1603 symbols may include:
1605 @itemize
1606 @item
1607 @samp{carbon}
1608 @item
1609 @samp{cygwin}
1610 @item
1611 @samp{linux}
1612 @item
1613 @samp{win32}
1614 @item
1615 @samp{win32-native}
1616 @end itemize
1617 @end defun
1619 @defun platform? type
1620 Returns @samp{#t} if the platform description list returned by
1621 @code{platform} contains the symbol @var{type}, and @samp{#f}
1622 otherwise.
1623 @end defun
1625 @defun sys-data-dirs
1626 Returns an ordered list of directories in which to access system-wide
1627 gEDA data.
1628 @end defun
1630 @defun sys-config-dirs
1631 Returns an ordered list of directories in which to access system-wide
1632 gEDA configuration information.
1633 @end defun
1635 @defun user-data-dir
1636 Returns an ordered list of directories in which to store user-specific
1637 gEDA data.
1638 @end defun
1640 @defun user-config-dir
1641 Returns the directory in which to store user-specific gEDA
1642 configuration information.
1643 @end defun
1645 @node gschem API Reference
1646 @chapter gschem API Reference
1648 The Scheme modules and functions described in this chapter are
1649 available in the gschem schematic editor application.  They are more
1650 focused on enabling and responding to user editing operations.
1652 @menu
1653 * Windows and views::
1654 * Key mapping::
1655 * Selections::
1656 * Hooks::
1657 * Miscellanous gschem functions::
1658 @end menu
1660 @node Windows and views
1661 @section Windows and views
1663 To use the functions described in this section, you will need to load
1664 the @code{(gschem window)} module.
1666 @defun active-page
1667 Returns the @code{page} currently being displayed for editing.
1668 @end defun
1670 @defun set-active-page! page
1671 Sets the current @code{page} to @var{page}.
1672 @end defun
1674 @defun pointer-position
1675 Returns the current mouse pointer position in world coordinates in the
1676 form @samp{(x . y)}.  If the pointer is outside the display area,
1677 returns @samp{#f}.
1678 @end defun
1680 @node Key mapping
1681 @section Key mapping
1683 To use the functions described in this section, you will need to load
1684 the @code{(gschem keymap)} module.
1686 @subsection Key combinations
1688 gschem treats key combinations as first-class objects.  A key
1689 combination consists of a non-modifier key press with some number of
1690 modifiers applied.  For example, the key combination @kbd{Ctrl+Shift+A}
1691 (which calls @strong{Edit→Deselect} by default) is typed by
1692 holding the @key{Ctrl} and @key{Shift} keys down, and then pressing
1693 @key{A}.
1695 @defun key? obj
1696 Returns @samp{#t} if and only if @var{obj} is a key combination.
1697 @end defun
1699 @defun string->key str
1700 Parses @var{str} to create a new key combination.  The expected format
1701 looks like @samp{<Control>a} or @samp{<Shift><Alt>F1}.  Key names are
1702 parsed using @code{gdk_keyval_from_name()}, and modifiers may appear in
1703 any order.  If @var{str} has invalid syntax or does not represent a
1704 valid key combination, raises a @samp{key-format} error.
1705 @end defun
1707 @defun key->string key
1708 Converts @var{key} to a string, using a format suitable for passing to
1709 @code{string->key}.
1710 @end defun
1712 @defun key->display-string key
1713 Converts @var{key} to a string, using a format suitable for
1714 display. This should be used when the key combination needs to be
1715 displayed to the user e.g. in the gschem menus or status area.  The
1716 returned string is translated according to the user's current locale.
1718 @example
1719 (key->display-string (string->key ``<Control>bracketright''))
1720 => ``Ctrl+]''
1721 @end example
1722 @end defun
1724 @subsection Key sequences
1726 Most gschem functionality is bound not to single key combinations but to
1727 sequences of them.  For example, @strong{File→New} is bound to @kbd{F N}
1728 by default (i.e. press @key{F} followed by @key{N}).  Key sequences are
1729 simply vectors of key bindings.  For example:
1731 @example
1732 (string->keys ``F N'')
1733 => #(#<gschem-key "F"> #<gschem-key "N">)
1734 @end example
1736 In this case, @key{F} is a @dfn{prefix key}, because pressing it does
1737 not cause an action to be carried out directly, but just changes the
1738 effect of pressing subsequent keys.
1740 @defun keys? obj
1741 Returns @samp{#t} if and only if @var{obj} is a valid key sequence.
1742 @end defun
1744 @defun string->keys str
1745 Parses @var{str} into a key sequence.  The expected format is a sequence
1746 of key combination specifications (as could be passed to
1747 @code{string->key}) separated by spaces.
1748 @end defun
1750 @defun keys->string keys
1751 Converts the key sequence @var{keys} to a string, using a format
1752 suitable for passing to @code{string->keys}.
1753 @end defun
1755 @defun keys->display-string keys
1756 Converts the key sequence @var{keys} to a string, using a format
1757 suitable for display.
1758 @end defun
1760 @subsection Keymaps
1762 A @dfn{keymap} maps key combinations to actions or other keymaps.
1764 @defun keymap? obj
1765 Returns @samp{#t} if and only if @var{obj} is a keymap.
1766 @end defun
1768 @defun make-keymap
1769 Creates and returns a new, empty keymap.
1770 @end defun
1772 @defun keymap-bind-key! keymap key [bindable]
1773 Binds @var{key} to @var{bindable} in @var{keymap}.  If @var{bindable} is
1774 @samp{#f} or not specified, removes the binding for @var{key}.
1775 @var{bindable} should be a thunk or a keymap.
1776 @end defun
1778 @defun keymap-lookup-key keymap key
1779 Looks up the binding for @var{key} in @var{keymap}.  If @var{key} is not
1780 bound, returns @samp{#f}.
1781 @end defun
1783 @defun keymap-lookup-binding keymap bindable
1784 Carries out a reverse lookup in @var{keymap} to find the key bound to
1785 @var{bindable}.  If @var{bindable} is not bound in @var{keymap},
1786 returns @samp{#f}.
1787 @end defun
1789 @defun keymap-for-each proc keymap
1790 Applies @var{proc} to each binding in @var{keymap}.  @var{proc} should
1791 take two arguments: the bound key, and its binding.
1792 @end defun
1794 Actions are bound to key sequences by binding the first key
1795 combination to a keymap, then in the resulting keymap binding the
1796 second key combination, etc.  This results in a directed graph of
1797 keymaps.
1799 For example, to bind the key sequence @kbd{F N}, a keymap is created
1800 containing a binding for @key{N} to the desired action, and then in the
1801 main keymap the prefix key @key{F} is bound to the new keymap.
1803 Three helper functions are provided for working with key sequence
1804 bindings.
1806 @defun bind-keys! keymap keys [bindable]
1807 Bind @var{keys} to @var{bindable}.  Keys may be a key sequence vector, a
1808 single key combination, or a string representing a key sequence or key
1809 combination.  If @var{bindable} is @samp{#f} or not specified, removes
1810 the binding for @var{keys}.  @var{bindable} should be a thunk or a
1811 keymap.
1813 If @var{keys} contains invalid prefix keys (e.g. because one of the
1814 prefix keys is already bound to something other than a keymap), raises
1815 an error.  Missing prefix keymaps are created as required.
1816 @end defun
1818 @defun lookup-keys keymap keys
1819 Looks up the binding for @var{keys} in @var{keymap}.  @var{keys} is
1820 interpreted the same as for @code{bind-keys!}.  If @var{keys} is not
1821 bound, returns @samp{#f}.
1822 @end defun
1824 @defun lookup-binding keymap bindable
1825 Recursively searches @var{keymap} for the key sequence bound to
1826 @var{bindable}, which should be a thunk or a keymap.  If
1827 @var{bindable} is not bound, returns @samp{#f}.
1828 @end defun
1830 @node Selections
1831 @section Selections
1833 To use the functions described in this section, you will need to load
1834 the @code{(gschem selection)} module.
1836 Each @code{page} in gschem has a @dfn{selection} associated with it,
1837 which is some subset of the @code{page}s contents.  Most actions in
1838 gschem operate on the currently selected objects.
1840 @defun page-selection page
1841 Returns the current selection for @var{page}, as a list of
1842 @code{object}s.
1843 @end defun
1845 @defun object-selected? object
1846 Returns @samp{#t} if @var{object} is in its containing page's
1847 selection. Otherwise, returns @samp{#f}.  If @var{object} is not in a
1848 @code{page}, raises an @samp{object-state} error.
1850 @strong{Note}: @var{object} must be @emph{directly} included in a
1851 @code{page}, not via inclusion in a component @code{object}.
1852 @end defun
1854 @defun select-object! object
1855 Adds @var{object} to the selection of its containing @code{page}.  If
1856 @var{object} is not directly included in a @code{page}, raises an
1857 @samp{object-state} error.  If @var{object} is already selected, does
1858 nothing.  Returns @var{object}.
1860 @strong{Note}: This function does not call @code{select-objects-hook}.
1861 @end defun
1863 @defun deselect-object! object
1864 Removes @var{object} from the selection of its containing @code{page}.
1865 If @var{object} is not directly included in a @code{page}, raises an
1866 @samp{object-state} error.  If @var{object} is not selected, does
1867 nothing.  Returns @var{object}.
1869 @strong{Note}: This function does not call
1870 @code{deselect-objects-hook}.
1871 @end defun
1873 @node Hooks
1874 @section Hooks
1876 To use the hooks described in this section, you will need to load the
1877 @code{(gschem hook)} module.
1879 gschem defines a number of hooks that allow functions to be
1880 automatically run whenever a number of built-in actions are invoked by
1881 the user.
1883 Most Scheme functions do not call these hooks.  If it makes sense for
1884 your code to invoke a standard hook, you should normally do so
1885 explicitly.
1887 @strong{Warning}: Functions added to these standard hooks should not
1888 normally modify their arguments.
1890 For more information on hooks in Guile, @pxref{Hooks, , Hooks, guile,
1891 Guile Reference Manual}.
1893 @defvar add-object-hook
1894 Called after objects are added to the page, at their initial creation.
1895 The argument is a list of the objects being added.
1896 @end defvar
1898 @defvar remove-objects-hook
1899 Called after objects are removed from the page.  Argument is a list of
1900 the objects being removed.
1901 @end defvar
1903 @defvar move-objects-hook
1904 Called after objects are moved.  Argument is a list of the objects
1905 that were mirrored.
1906 @end defvar
1908 @defvar mirror-objects-hook
1909 Called after objects are mirrored.  Argument is a list of the objects
1910 that were mirrored.
1911 @end defvar
1913 @defvar rotate-objects-hook
1914 Called after objects are rotated.  Argument is a list of the objects
1915 that were rotated.
1916 @end defvar
1918 @defvar paste-objects-hook
1919 Called after objects are pasted to the page, either via @strong{Edit â†’
1920 Copy Mode} or similar, or via buffers, or via the clipboard.  Argument
1921 is a list of the objects that were pasted.
1922 @end defvar
1924 @defvar attach-attribs-hook
1925 Called after attributes are attached to something.  The argument is a
1926 list of the attributes that were attached.
1927 @end defvar
1929 @defvar detach-attribs-hook
1930 Called after attributes are detached from something.  The argument is
1931 a list of the attributes that were detached.
1932 @end defvar
1934 @defvar select-objects-hook
1935 Called after objects are added to the selection.  The argument is a
1936 list of objects that were selected.
1937 @end defvar
1939 @defvar deselect-objects-hook
1940 Called after objects are removed from the selection.  The argument is
1941 a list of objects that were deselected.
1942 @end defvar
1944 @defvar new-page-hook
1945 Called when a new page is created. The argument is the new page.
1946 @end defvar
1948 @node Miscellanous gschem functions
1949 @section Miscellaneous gschem functions
1951 @subsection gschem Attribute Helpers
1953 To use the functions described in this section, you will need to load
1954 the @code{(gschem attrib)} module.
1956 @defun add-attrib! target name value visible show
1957 Create a new attribute, either attached to a @var{target}
1958 @code{object} in the current @code{page}, or floating in the current
1959 @code{page} if @var{target} is @samp{#f}.  The @var{name} and
1960 @var{value} for the attribute must be strings, and if visible is
1961 @samp{#f}, the attribute will be invisible.  The @var{show} argument
1962 controls which parts of the attribute will be visible, and must be one
1963 of the following symbols:
1965 @itemize
1966 @item
1967 @samp{name}
1968 @item
1969 @samp{value}
1970 @item
1971 @samp{both}
1972 @end itemize
1974 This function exists to provide a way for actions defined in Scheme to
1975 use the same attribute placement heuristics as gschem's built-in
1976 @strong{Add Attribute} action.
1978 @xref{Text}, @ref{Attributes} and @ref{Windows and views}.
1979 @end defun
1981 @subsection Miscellaneous utility functions
1983 To use the functions described in this section, you will need to load
1984 the @code{(gschem util)} module.
1986 @defun show-uri uri
1987 Open @var{uri} in the registered default application associated for
1988 that type of file or protocol.  URI should be fully-qualified URI;
1989 which URIs can be handled by @code{show-uri} will depend on the system
1990 configuration.
1991 @end defun
1993 @defun show-file filename
1994 Displays a file in the registered default application for files of
1995 that type. @var{filename} should be the absolute path and filename of
1996 a local file.
1997 @end defun
1999 @node Concept Index
2000 @unnumbered Concept Index
2002 @printindex cp
2004 @node Function Index
2005 @unnumbered Function Index
2007 @printindex fn
2009 @node Variable Index
2010 @unnumbered Variable Index
2012 @printindex vr
2014 @bye