scheme-api: gschem API documentation (windows and views).
[geda-gaf/peter-b.git] / docs / scheme-api / geda-scheme.texi
blobd0b8d13ed08da5a6cdd57c7936a41d02a6ee4208
1 \input texinfo                              @c -*-texinfo-*-
2 @setfilename geda-scheme.info
3 @include version.texi
4 @settitle gEDA Scheme Reference Manual @value{VERSION}
6 @copying
7 This manual is for gEDA/gaf, version @value{VERSION}.
9 Copyright @copyright{} 2011 Peter TB Brett
11 The text of and illustrations in this document are licensed under a
12 Creative Commons Attribution–Share Alike 3.0 Unported license
13 ("CC-BY-SA"). An explanation of CC-BY-SA is available at
14 http://creativecommons.org/licenses/by-sa/3.0/. The original authors
15 of this document designate the gEDA Project as the "Attribution Party"
16 for purposes of CC-BY-SA. In accordance with CC-BY-SA, if you
17 distribute this document or an adaptation of it, you must provide the
18 URL for the original version.
19 @end copying
21 @titlepage
22 @title gEDA Scheme Reference Manual
23 @author Peter TB Brett
25 @page
26 @vskip 0pt plus 1filll
27 @insertcopying
29 @end titlepage
31 @contents
33 @ifnottex
34 @node Top
35 @top gEDA Scheme Reference Manual
36 @insertcopying
37 @end ifnottex
39 @menu
40 * Introduction::
42 * Schematic Document Model::
43 * Core API Reference::
44 * gschem API Reference::
46 * Concept Index::
47 * Function Index::
48 @end menu
50 @node Introduction
51 @unnumbered Introduction
53 @section About gEDA
55 @dfn{gEDA}, or @emph{GPL Electronic Design Automation}, is a suite of
56 free software tools for designing electronics.  The gEDA project has
57 produced and continues working on a full GPL'd suite and toolkit of
58 Electronic Design Automation (EDA) tools. These tools are used for
59 electrical circuit design, schematic capture, simulation, prototyping,
60 and production. Currently, the gEDA project offers a mature suite of
61 free software applications for electronics design, including schematic
62 capture, attribute management, bill of materials (BOM) generation,
63 netlisting into over 20 netlist formats, analog and digital
64 simulation, and printed circuit board (PCB) layout.
66 The gEDA project was started because of the lack of free EDA tools for
67 POSIX systems with the primary purpose of advancing the state of free
68 hardware or open source hardware. The suite is mainly being developed
69 on the GNU/Linux platform with some development effort going into
70 making sure the tools run on other platforms as well.
72 @section About the gEDA Scheme API
74 The @dfn{gEDA Scheme API}, documented in this manual, is a set of
75 Scheme functions which can be used to enhance gEDA applications by
76 adding new functionality or modify existing behaviour.
78 gEDA has always used a Scheme interpreter for interpreting
79 configuration files, managing keybindings in gschem, and implementing
80 netlist exporter backends in gnetlist.  However, for a long time the
81 utility of embedding a Scheme interpreter was diminished by the lack
82 of a low-level API for inspecting and modifying schematic documents.
83 The Scheme types and functions documented here were added to gEDA to
84 address that need.
86 gEDA uses the @emph{Guile} Scheme implementation (otherwise known as
87 the @emph{GNU Ubiquitous Intelligent Language for Extensions}) as its
88 embedded Scheme.  For more information about Guile, please visit
89 @uref{http://www.gnu.org/s/guile/}.
91 @section Getting Additional Help
92 @cindex Reporting bugs
94 If you think you have found a bug, please file a bug report in
95 Launchpad: @uref{http://bugs.launchpad.net/geda}. Please add the tag
96 @samp{scheme-api}.  It will help us to fix your bug quickly if you can
97 describe in detail how to reproduce the bug.
99 If you have a question about using gEDA, or about extending gEDA using
100 Scheme, you may wish to send a message to one of the gEDA mailing
101 lists.  You may also find additional information in the gEDA
102 wiki.
104 Both the mailing lists and wiki can be accessed from the main gEDA
105 website: @uref{http://gpleda.org/}.
107 @section We Need Feedback!
109 If you find a typographical error in this manual, or if you have
110 thought of a way to make this manual better, we would love to hear
111 from you! Please submit a report in Launchpad:
112 @uref{http://bugs.launchpad.net/geda}, with the tag @samp{scheme-api}.
114 @node Schematic Document Model
115 @chapter The Schematic Document Model
117 When using gEDA to design an electronic circuit, users use the
118 schematic editor, gschem, to choose and place @emph{schematic symbols}
119 on a @emph{schematic page}, and connect the @emph{pins} of the symbols
120 together by drawing @emph{nets}.  The user may add various
121 @emph{attributes} to symbols, nets or pins to modify how the circuit
122 diagrams should be interpreted.  The resulting schematics are then
123 processed with the gnetlist tool to generate a @emph{netlist}.
125 This chapter describes the different data types used by the Scheme API
126 to represent gEDA documents (both schematics and symbols), and how
127 they relate to each other.
129 @menu
130 * Pages::
131 * Objects::
132 * Component objects::
133 * Attributes::
134 * Coordinate system::
135 @end menu
137 @node Pages
138 @section Pages
139 @cindex Pages
140 @cindex Schematics
141 @cindex Symbols
143 Schematics and symbols are presented as different types of document to
144 the user, with different file extensions, icons and mime-types.
145 However, when they are loaded into a gEDA application such as gschem
146 for editing, they are internally represented in exactly the same way,
147 by the @code{page} type.  The @code{page} is the top-level gEDA document
148 data type.
150 Internally, the main difference between a @code{page} for a schematic
151 and a @code{page} for a symbol is the types of schematic element they
152 are permitted to contain (@pxref{Objects}).  For example, a symbol is
153 not permitted to contain nets, buses, or instances of other symbols,
154 and a schematic is not permitted to contain pins.
156 @strong{Note}: Although the restrictions on what types of primitive
157 element schematics and symbols may contain are not enforced by the
158 API, designs which violate these restrictions may cause the netlister
159 not to work as expected.
161 Each @code{page} is associated with a filename, although the filename is
162 not required by the API either to be valid or to be associated with a
163 accessible file in the filesystem.
165 Pages are not garbage-collected; once you create a @code{page}, you are
166 responsible for making sure that it is disposed of when it is no
167 longer required.
169 @node Objects
170 @section Objects
171 @cindex Objects
172 @cindex Schematic elements
174 Each @code{page} contains some number of @dfn{schematic elements},
175 represented by the @code{object} type.  There are several sub-types of
176 @code{object}, including:
178 @itemize @bullet
179 @item
180 graphical lines, circles, arcs, rectangles and paths;
182 @item
183 nets and net pins;
185 @item
186 buses and bus pins;
188 @item
189 pictures;
191 @item
192 text;
194 @item
195 and symbol instances, known as 'components'.
196 @end itemize
198 Each @code{object} can be part of at most a single @code{page} -- they
199 cannot be shared between pages.  @code{object}s are automatically
200 garbage collected.
202 Most of different @code{object} sub-types are quite straightforward to
203 understand.  The main exceptions are components, and the text
204 @code{object}-based attribute mechanism, which are described in the
205 following sections.
207 @node Component objects
208 @section Component objects
209 @cindex Component
210 @cindex Component library
211 @cindex Embedded component
213 When a symbol is instantiated in a schematic (e.g. by the user
214 selecting it from the gschem component library and placing it on the
215 page), a compound @code{object} known as a @dfn{component} is created.
217 Like a @code{page}, a component contains some number of @code{object}
218 elements.  When a component is created from a symbol, the contents of
219 the symbol's @code{page} are copied into the component.
221 In order to allow the component to appear in the correct place on the
222 schematic page, at the correct orientation, etc., a transformation is
223 applied to every @code{object} in the component.
225 Normally, when the schematic @code{page} is closed, the parameters of
226 the transformation are stored in the schematic file along with the
227 basename of the original symbol, but the @code{object} contents of the
228 component are discarded.  When the schematic is subsequently
229 re-opened, the original symbol is retrieved from the component
230 library, and used to recreate the component.
232 However, a component may optionally be @emph{embedded}.  In this case,
233 its contents @emph{are} stored in the schematic file.
235 @strong{Note}: A component cannot contain another component -- only
236 other types of @code{object}.
238 @node Attributes
239 @section Attributes
240 @cindex Attribute
241 @cindex Attribute format
243 A gEDA user is able to annotate schematic elements with additional
244 data, such as footprints for components or net names for nets.  This
245 is carried out using @dfn{attributes}.
247 An attribute is text @code{object} which contains a text string in the
248 form @samp{@var{name}=@var{value}}.  Currently, the restrictions on
249 attribute format that are enforced by the API are:
251 @itemize @bullet
252 @item
253 Attribute @var{name}s:
255 @enumerate
256 @item
257 must contain at least one character;
258 @item
259 must not contain a @samp{=} character (Unicode @code{U+003D});
260 @item
261 must not end with a space (@samp{ }, Unicode @code{U+0020}).
262 @end enumerate
264 @item
265 Attribute @var{value}s:
267 @enumerate
268 @item
269 must contain at least one character;
270 @item
271 must not begin with a space (@samp{ }, Unicode @code{U+0020}).
272 @end enumerate
273 @end itemize
275 @strong{Note}: Due to assumptions made by some gEDA tools, it is
276 @emph{strongly recommended} that you use attribute @var{NAME}s which
277 contain only lower-case Latin characters, decimal digits, full stops
278 @samp{.}  (@code{U+002E}), and hyphens @samp{-} (@code{U+002D}).
280 There are two types of attribute:
282 @cindex Attached attribute
283 @emph{Attached attributes} are attribute text @code{object}s that are
284 linked to another @code{object}.  To attach an attribute to another
285 schematic element, both @code{object}s must be part of the same
286 component or part of the same @code{object}.  For example, a
287 @samp{netname=@var{NAME}} attribute attached to a net @code{object}
288 can be used to give that net a specific name in netlist output, such
289 as @samp{VCC} or @samp{GND}.
291 @cindex Floating attribute
292 @emph{Floating attributes} are attribute text @code{object}s that are
293 not linked to another @code{object}.  These attributes affect the
294 schematic or symbol that they're part of as a whole.  For example, a
295 floating @samp{documentation=@var{url}} attribute in a symbol tells
296 gschem's @strong{Help â†’ Component Documentation} command how to find
297 the component's data sheet.
299 @node Coordinate system
300 @section Coordinate system
302 gEDA documents use a @dfn{coordinate system} (internally referred to
303 as `world' coordinates) with coordinates increasing upwards and to the
304 right (i.e. a conventional right-handed Cartesian coordinate
305 system).
307 Although all coordinates may be positive or negative, gschem only
308 displays objects with positive coordinates (i.e. in the upper right
309 quadrant of the coordinate system).  It is therefore recommended to
310 use only positive coordinates.
312 In the Scheme API, the coordinate of a point is expressed in the format:
314 @example
315 (x . y)
316 @end example
318 and a set of @dfn{bounds} (i.e. a rectangular area in the document
319 plane) is expressed in the format:
321 @example
322 ((left . top) . (right . bottom))
323 @end example
325 where @code{left} is the smaller x coordinate, @code{right} is the
326 larger x coordinate, and @code{bottom} and @code{top} are respectively
327 the smaller and larger y coordinates.
329 @node Core API Reference
330 @chapter Core API Reference
332 The Scheme modules and functions described in this chapter are
333 primitive operations for working with schematics and symbols, and are
334 available to be used in all gEDA applications.
336 @menu
337 * Core page functions::
338 * Core object functions::
339 * Core attribute functions::
340 @end menu
342 @node Core page functions
343 @section Core page functions
345 To use the functions described in this section, you will need to load
346 the @code{(geda page)} module.
348 @xref{Pages}.
350 @defun page? obj
351 Returns @samp{#t} if and only if @var{obj} is a @code{page}.
352 @end defun
354 @defun active-pages
355 Returns a list of all open @code{page}s.
356 @end defun
358 @subsection Page creation, disposal and filenames
360 Every @code{page} is associated with a @emph{filename}.  The filename
361 does not necessarily have to be a file which exists and/or is
362 accessible in the filesystem.
364 @defun make-page filename
365 Creates and returns a new, empty @code{page}, with the given
366 string @var{filename}.
367 @end defun
369 @defun close-page! page
370 Destroys @var{page}.  The returned value is undefined.
372 @strong{Warning}: This function closes and destroys @var{page}
373 immediately, regardless of whether the page has been modified since
374 loading or saving, and without asking the user.
375 @end defun
377 @defun page-filename page
378 Returns the filename associated with @var{page} as a string.
379 @end defun
381 @defun set-page-filename! page filename
382 Sets the filename of @var{page} to @var{filename}.  Returns
383 @var{page}.
384 @end defun
386 @subsection Page contents
388 A schematic or symbol @code{page} is composed of a set of
389 @code{object}s which determine both its graphical appearance and its
390 electrical meaning.
392 @defun page-contents page
393 Returns a list of the @code{object}s which make up @var{page}.  The
394 list can be freely modified without changing the contents of
395 @var{page}.
396 @end defun
398 @defun page-append! page objects...
399 Appends zero or more @var{objects} to the contents of @var{page} in
400 the order given.  Returns @var{page}.
402 If any of the @var{objects} is already part of a @code{page} other
403 than @var{page}, or is part of a component @code{object}, raises an
404 @code{object-state} error.  Any of the @var{objects} that are already
405 in the @var{page} are ignored.
406 @end defun
408 @defun page-remove! page objects...
409 Removes zero or more @var{objects} from the contents of @var{page}.
410 Returns @var{page}.
412 Any @var{objects} that are not part of a @code{page} or component
413 @code{object} are ignored.
415 An @samp{object-state} error will be thrown if any of the
416 @var{objects} satisfies any of the following conditions:
418 @itemize
419 @item
420 part of a @code{page} other than @var{page};
421 @item
422 part of component @code{object};
423 @item
424 has attached attributes (@pxref{Attributes});
425 @item
426 is attached as an attribute.
427 @end itemize
428 @end defun
430 @defun object-page object
431 Returns the @code{page} which contains @var{object} (either directly
432 or indirectly), or @samp{#f} if @var{object} is not part of a
433 @code{page}.
435 @strong{Note}: If the @var{object} argument to @code{object-page} is
436 part of a component @code{object} which is itself part of a
437 @code{page}, that @code{page} will be returned.
438 @end defun
440 @subsection Page dirty flags
442 A @code{page} has a @emph{dirty flag} that is used to indicate to
443 applications that the @code{page} has been modified since it was last
444 loaded or saved.
446 @defun page-dirty? page
447 Returns @samp{#t} if the @var{page}'s page has been marked as dirty;
448 otherwise, returns @samp{#f}.
449 @end defun
451 @defun set-page-dirty! page [state]
452 Sets the dirty flag for @var{page}.  If @var{state} is @samp{#f},
453 clears the dirty flag; otherwise, or if @var{state} is omitted, marks
454 the page as dirty.  Returns @var{page}.
455 @end defun
457 @node Core object functions
458 @section Core object functions
460 To use the functions described in this section, you will need to load
461 the @code{(geda object)} module.
463 @menu
464 * General object functions::
465 * Lines::
466 * Nets and buses::
467 * Pins::
468 * Boxes::
469 * Circles::
470 * Arcs::
471 * Paths::
472 * Pictures::
473 * Text::
474 * Components::
475 @end menu
477 @node General object functions
478 @subsection General object functions
480 @defun object? obj
481 Returns @samp{#t} if and only if @var{obj} is an @code{object}.
482 @end defun
484 @defun copy-object object
485 Returns a deep copy of @var{object}.  The new @code{object} returned
486 has no attached attributes, and is not part of a @code{page} or part
487 of a component @code{object}.
488 @end defun
490 @defun object-component object
491 Returns the component @code{object} that contains @var{object}, or
492 @samp{#f} if @var{object} is not part of a component.
493 @end defun
495 @defun object-connections object
496 Returns a list of other @code{object}s that are @emph{directly}
497 connected to @var{object}.  If @code{object} is not included in a
498 @code{page}, raises an @samp{object-state} error.  The connections
499 reported are independent of inclusion in components.
501 For example, consider a page containing a net and a component, and the
502 component contains a single pin.  If the connectable end of the pin
503 intersects the net, then @code{(object-connections <net>)} will return
504 a list containing the pin @code{object}, and @emph{not} the component.
505 @end defun
507 @menu
508 * Object sub-types::
509 * Object bounds::
510 * Object color::
511 * Object fill and stroke::
512 @end menu
514 @node Object sub-types
515 @subsubsection Object sub-types
517 Schematic element @code{object}s come in several subtypes.
519 @defun object-type object
520 Returns the sub-type of @var{object} as a symbol.  The subtype will be
521 one of the following symbols:
523 @itemize
524 @item
525 @samp{arc}
526 @item
527 @samp{box}
528 @item
529 @samp{bus}
530 @item
531 @samp{circle}
532 @item
533 @samp{complex} (indicates a component @code{object})
534 @item
535 @samp{line}
536 @item
537 @samp{net}
538 @item
539 @samp{path}
540 @item
541 @samp{picture}
542 @item
543 @samp{pin}
544 @item
545 @samp{text}
546 @end itemize
547 @end defun
549 @defun object-type? object type
550 Returns @samp{#t} if and only if @var{object} is an @code{object} and
551 that its subtype is @var{type}, which should be a symbol.
552 @end defun
554 @node Object bounds
555 @subsubsection Object bounds
557 The bounds of an object is the smallest bounding rectangle of the
558 object, expressed in document coordinates (@pxref{Coordinate system}).
560 @defun object-bounds objects...
561 Returns the world coordinate bounding box containing all of the
562 @var{objects} passed as arguments, or @samp{#f} if none of the
563 @var{objects} have bounds (for example, this can occur if no
564 @var{objects} are specified, or if they are all empty component
565 @code{object}s).
567 @strong{Note}: @code{object-bounds} always returns the actual bounds
568 of the @var{objects}, not the visible bounds.  This means that the bounds of
569 invisible text is always included.
570 @end defun
572 @defun fold-bounds bounds...
573 Calculates the union of several sets of @var{bounds} (as returned by
574 @code{object-bounds}).  If any of the @var{bounds} are @samp{#f}, they
575 are skipped; if all of the @var{bounds} are @samp{#f}, @samp{#f} is
576 returned.
577 @end defun
579 @node Object color
580 @subsubsection Object color
582 Object colors in gEDA documents are specified as indices into a color
583 map.  This allows users to specify the color map that suits them when
584 viewing schematics and symbols.
586 @defun object-color object
587 Returns the integer color map index of the the color used to draw
588 @var{object}.
589 @end defun
591 @defun set-object-color! object color
592 Sets the integer color map index for @var{object} to @var{color}.
593 Returns @var{object}.
594 @end defun
596 @node Object fill and stroke
597 @subsubsection Object fill and stroke
599 Graphical object subtypes -- lines, boxes, circles, arcs and paths --
600 are drawn with a stroke pattern that can be configured in detail.
602 @defun object-stroke object
603 Returns the stroke settings of the @var{object}, which must be a line,
604 box, circle, arc or path @code{object}.  The return value is a list of
605 parameters:
607 @enumerate
608 @item
609 stroke width, as an integer number of world units
610 @item
611 cap style, one of the symbols @code{none}, @code{square} or
612 @code{round}.
613 @item
614 dash style, one of the symbols @code{solid}, @code{dotted},
615 @code{dashed}, @code{center} or @code{phantom}.
616 @item
617 up to two dash parameters, depending on the dash style:
618 @itemize
619 @item
620 for solid lines, no parameters;
621 @item
622 for dotted lines, dot spacing;
623 @item
624 for other styles, dot/dash spacing and dash length.
625 @end itemize
626 @end enumerate
627 @end defun
629 @defun set-object-stroke! object width cap dash [dash-space [dash-length]]
630 Set the stroke settings of the @var{object}, which must be a line,
631 box, circle, arc or path @code{object}.  The arguments are the same as
632 the contents of the list returned by @code{object-stroke}.  Returns
633 @var{object}.
634 @end defun
636 @defun object-stroke-width object
637 Returns the integer stroke width of @var{object}, which must be a
638 line, box, circle, arc or path @code{object}.
639 @end defun
641 @defun object-stroke-cap object
642 Returns the stroke cap style of @var{object}, which must be a line,
643 box, circle, arc or path @code{object}.  The returned value is one of
644 the symbols @code{none}, @code{square} or @code{round}.
645 @end defun
647 @defun object-stroke-dash object
648 Returns the dash style of @var{object}, which must be a line, box,
649 circle, arc or path @code{object}.  The return value is a list of
650 between one and three parameters:
652 @enumerate
653 @item
654 dash style, one of the symbols @code{solid}, @code{dotted},
655 @code{dashed}, @code{center} or @code{phantom}.
656 @item
657 for styles other than @code{solid}, dot/dash spacing;
658 @item
659 for @code{dashed}, @code{center} and @code{phantom}, dash length.
660 @end enumerate
661 @end defun
663 Some types of @code{object} -- boxes, circles and paths -- can have
664 their interiors filled with a variety of patterns.
666 @defun object-fill object
667 Returns the fill settings of @var{object}, which must be a box, circle
668 or path @code{object}.  The return value is a list of one to six
669 parameters:
671 @enumerate
672 @item
673 fill style, one of the symbols @code{hollow}, @code{solid},
674 @code{mesh} or @code{hatch};
675 @item
676 up to five fill parameters, depending on fill style:
677 @enumerate
678 @item
679 none for @code{hollow} or @code{solid} fills;
680 @item
681 line width, line angle (in degrees) and line spacing for @code{hatch} fills;
682 @item
683 line width, first angle and spacing, and second angle and spacing for
684 @code{mesh} fills.
685 @end enumerate
686 @end enumerate
687 @end defun
689 @defun set-object-fill! object fill-type . fill-args
690 Sets the fill settings of @var{object}, which must be a box, circle or
691 path @code{object}.  The arguments are the same as the contents of the
692 list returned by @code{object-fill}.  Returns @var{object}.
693 @end defun
695 @node Lines
696 @subsection Lines
697 Line @code{object}s are straight graphical line segments with no
698 electrical meaning.  A line's geometrical parameters are a start point
699 and end point, and it supports different colors and stroke styles.
701 Many of the functions for manipulating lines are also used to
702 manipulate line-like objects such as nets, buses or pins.
704 @defun line? object
705 Returns @samp{#t} if and only if @var{object} is a line @code{object}.
706 @end defun
708 @defun make-line start end [color]
709 Creates and returns a new line @code{object}.  @var{start} is the
710 position of the start of the new line in the form @code{(x . y)} and
711 @var{end} is the position of end of the line.  If @var{color} is
712 specified, it should be the integer color map index of the color with
713 which to draw the line.  If @var{color} is not specified, the default
714 line color is used.
715 @end defun
717 @defun set-line! line start end [color]
718 Sets the parameters of @var{line} (which may be a line, net, bus or
719 pin @code{object}).  The arguments are the same as to
720 @code{make-line}.  Returns @var{line}.
721 @end defun
723 @defun line-info line
724 Returns the parameters of @var{line} (which may be a line, net, bus or
725 pin @code{object}).  The return value is a list in the form:
727 @example
728 ((start-x . start-y) (end-x . end-y) color)
729 @end example
731 @strong{Note}: For pin @code{object}s, first coordinate is the
732 connectable point on the pin.
733 @end defun
735 @defun line-start line
736 Returns the position @samp{(x . y)} of the start of @var{line} (which
737 may be a line, net, bus or pin @code{object}).  For pin
738 @code{objects}, this is the position of the connectable point on the
739 pin.
740 @end defun
742 @defun line-end line
743 Returns the position @samp{(x . y)} of the end of @var{line} (which
744 may be a line, net, bus or pin @code{object}).
745 @end defun
747 @node Nets and buses
748 @subsection Nets and buses
750 Net and bus @code{object}s are straight line segments which represent
751 electrical connectivity.  Nets represent single wires, and buses
752 multi-wire connections of arbitrary composition.
754 All of the functions that work on line @code{object}s also work with
755 nets and buses (@pxref{Lines}).  Note that @code{line?} will return
756 @code{#f} if called with a net or bus argument.
758 @defun net? object
759 Returns @samp{#t} if and only if @var{object} is a net.
760 @end defun
762 @defun make-net start end [color]
763 Creates and returns a new net @code{object}.  @var{start} is the
764 position of the start of the new net in the form @code{(x . y)} and
765 @var{end} is the position of end of the net.  If @var{color} is
766 specified, it should be the integer color map index of the color with
767 which to draw the net.  If @var{color} is not specified, the default
768 net color is used.
769 @end defun
771 @defun bus? object
772 Returns @samp{#t} if and only if @var{object} is a bus.
773 @end defun
775 @defun make-bus start end [color]
776 Creates and returns a new bus @code{object}.  Arguments are as for
777 @code{make-net}.
778 @end defun
780 @node Pins
781 @subsection Pins
783 Pin @code{objects} are straight line segments which represent
784 connectable points in symbols or subcircuits, such as the pins of a
785 semiconductor package.  Only one end of a pin can be connected to
786 nets, buses or other pins; the rest of a pin is purely graphical.
788 Pins come in two varieties: @dfn{net pins} and @dfn{bus pins}, which
789 are used for connections to nets and buses respectively (@pxref{Nets
790 and buses}).
792 All of the functions that work on line @code{object}s also work with
793 pins (@pxref{Lines}).  Note that @code{line?} will return @code{#f} if
794 called with a pin argument.
796 @defun pin? object
797 Returns @samp{#t} if and only if @var{object} is a pin @code{object}.
798 @end defun
800 @defun net-pin? object
801 Returns @samp{#t} if and only if @var{object} is a net pin.
802 @end defun
804 @defun make-net-pin start end [color]
805 Creates and returns a new net pin @code{object}.  @var{start} is the
806 position of the start of the new pin (the connectable end) in the form
807 @code{(x . y)} and @var{end} is the position of end of the pin.  If
808 @var{color} is specified, it should be the integer color map index of
809 the color with which to draw the pin.  If @var{color} is not
810 specified, the default pin color is used.
811 @end defun
813 @defun bus-pin? object
814 Returns @samp{#t} if and only if @var{object} is a bus pin.
815 @end defun
817 @defun make-bus-pin start end [color]
818 Creates and returns a new bus pin @code{object}.  Arguments are as for
819 @code{make-net-pin}.
820 @end defun
822 @node Boxes
823 @subsection Boxes
825 Boxes are rectangles specified by the coordinates of their top left
826 and bottom right corners.  They are purely graphical, and have no
827 electrical meaning.  They can be drawn in different colors, and with
828 various stroke and fill settings.
830 @xref{Object color}.
831 @xref{Object fill and stroke}.
833 @defun box? object
834 Returns @samp{#t} if and only of @var{object} is a box @code{object}.
835 @end defun
837 @defun make-box top-left bottom-right [color]
838 Creates and returns a new box @code{object}.  @var{top-left} is the
839 position of the top left of the new box in the form @code{(x . y)},
840 and @var{bottom-right} is the position of the bottom right of the box.
841 If @var{color} is specified, it should be the integer color map index
842 of the color with which to draw the box.  If @var{color} is not
843 specified, the default box color is used.
844 @end defun
846 @defun set-box! box top-left bottom-right [color]
847 Sets the parameters of @var{box}. The arguments are the same as to
848 @code{make-box}.  Returns @var{box}.
849 @end defun
851 @defun box-info box
852 Returns the parameters of @var{box}.  The return value is a list in the form:
854 @example
855 ((top-left-x . top-left-y) (bottom-right-x . bottom-right-y) color)
856 @end example
857 @end defun
859 @defun box-top-left box
860 Returns the position of the top left corner of @var{box} in the form
861 @code{(x . y)}.
862 @end defun
864 @defun box-bottom-right box
865 Returns the position of the bottom right corner of @var{box} in the
866 form @code{(x . y)}.
867 @end defun
869 @node Circles
870 @subsection Circles
872 Circle @code{objects} are specified by center position and radius, and
873 are purely graphical with no electrical meaning.  They can be drawn in
874 different colors, and with various stroke and fill settings.
876 @xref{Object color}.
877 @xref{Object fill and stroke}.
879 @defun circle? object
880 Returns @samp{#t} if and only of @var{object} is a circle @code{object}.
881 @end defun
883 @defun make-circle center radius [color]
884 Creates and returns a new circle @code{object}.  @var{center} is the
885 position of the center of the new circle in the form @code{(x . y)},
886 and @var{radius} is the integer radius of the circle.  If @var{color}
887 is specified, it should be the integer color map index of the color
888 with which to draw the circle.  If @var{color} is not specified, the
889 default circle color is used.
890 @end defun
892 @defun set-circle! circle center radius [color]
893 Sets the parameters of @var{circle}. The arguments are the same as to
894 @code{make-circle}.  Returns @var{circle}.
895 @end defun
897 @defun circle-info circle
898 Returns the parameters of @var{circle} as a list of the form:
900 @example
901 ((center-x . center-y) radius color)
902 @end example
903 @end defun
905 @defun circle-center circle
906 Returns the position of the center of @var{circle} as in the form
907 @code{(x . y)}.
908 @end defun
910 @defun circle-radius circle
911 Returns the radius of @var{circle} as an integer.
912 @end defun
914 @node Arcs
915 @subsection Arcs
916 Arc @code{objects} are specified by center position, radius, and start
917 and end angles.  They are purely graphical with no electrical
918 meaning. They can be drawn in different colors, and with various
919 stroke settings.
921 @defun arc? object
922 Returns @samp{#t} if and only if @var{object} is an arc @code{object}.
923 @end defun
925 @defun make-arc center radius start-angle end-angle [color]
926 Creates and returns a new arc @code{object}.  @var{center} is the
927 position of the center of the new arc in the form @code{(x . y)}, and
928 @var{radius} is the integer radius of the arc.  @var{start-angle} and
929 @var{end-angle} are the angles at which to start and end the arc, in
930 degrees. If @var{color} is specified, it should be the integer color
931 map index of the color with which to draw the arc.  If @var{color}
932 is not specified, the default arc color is used.
933 @end defun
935 @defun set-arc! arc center radius start-angle end-angle [color]
936 Sets the parameters of @var{arc}. The arguments are the same as to
937 @code{make-arc}. Returns @var{arc}.
938 @end defun
940 @defun arc-info arc
941 Returns the parameters of @var{arc} as a list of the form:
943 @example
944 ((center-x . center-y) radius start-angle end-angle color)
945 @end example
946 @end defun
948 @defun arc-center arc
949 Returns the position of the center of @var{arc} in the form
950 @code{(x . y)}.
951 @end defun
953 @defun arc-radius arc
954 Returns the radius of @var{arc} as an integer.
955 @end defun
957 @defun arc-start-angle arc
958 Returns the start angle of @var{arc} as an integer number of degrees.
959 @end defun
961 @defun arc-end-angle arc
962 Returns the end angle of @var{arc} as an integer number of degrees.
963 @end defun
965 @node Paths
966 @subsection Paths
968 @defun path? object
969 Returns @samp{#t} if and only if @var{object} is a path @code{object}.
970 @end defun
972 @node Pictures
973 @subsection Pictures
975 @defun picture? object
976 Returns @samp{#t} if and only if @var{object} is a picture @code{object}.
977 @end defun
979 @node Text
980 @subsection Text
982 Text fulfils two roles, as straightforward labels and notes on
983 schematics and symbols, and as attached or floating attributes
984 (@pxref{Attributes}).  A text @code{object} can be aligned in
985 different ways relative to its anchor position, and can be displayed
986 in different font sizes.
988 Any text can be set to be visible or invisible on printed output (and
989 gschem provides ways to preview invisible text).  When a text
990 @code{object} is an attribute (i.e. its string is in a
991 @samp{@var{name}=@var{value}} format) then the visibility settings are
992 more fine-grained: the text can be set to display just the attribute
993 name, just the attribute value, or both.
995 @xref{Attributes}.
997 @defun text? object
998 Returns @samp{#t} if and only if @var{object} is a text @code{object}.
999 @end defun
1001 @defun make-text anchor align angle string size visible show [color]
1002 Creates and returns a new text @code{object}.  @var{anchor} is the
1003 position of the anchor of the new text in the form @code{(x . y)}, and
1004 @var{align} is a symbol determining how the text should be aligned
1005 relative to the anchor.  @var{align} must be one of the following
1006 symbols:
1008 @itemize
1009 @item
1010 @samp{lower-left}
1011 @item
1012 @samp{middle-left}
1013 @item
1014 @samp{upper-left}
1015 @item
1016 @samp{lower-center}
1017 @item
1018 @samp{middle-center}
1019 @item
1020 @samp{upper-center}
1021 @item
1022 @samp{lower-right}
1023 @item
1024 @samp{middle-right}
1025 @item
1026 @samp{upper-right}
1027 @end itemize
1029 For example, if @var{align} is @samp{upper-center}, the anchor will be
1030 located at the top center of the rendered text block.
1032 @var{angle} should be an integer multiple of 90 degrees, determining
1033 the angle which the text should be displayed at.  @var{string} is the
1034 string contents for the @code{text} object, and must not contain any
1035 null characters (@samp{#\0} in Scheme, Unicode
1036 @samp{U+0000}. @var{size} is the font size to use.  If @var{visible}
1037 is @samp{#f}, the text will be invisible; otherwise, it will be
1038 visible.
1040 When the @var{string} is in an attribute format (@pxref{Attributes}),
1041 the @var{show} argument determines which parts of the @var{string}
1042 will be displayed.  It must be one of the following symbols:
1044 @itemize
1045 @item
1046 @samp{name}
1047 @item
1048 @samp{value}
1049 @item
1050 @samp{both}
1051 @end itemize
1053 If @var{color} is specified, it should be the integer color map index
1054 of the color with which to draw the text.  If @var{color} is not
1055 specified, the default arc color is used.
1056 @end defun
1058 @defun set-text! text anchor align angle string size visible show [color]
1059 Sets the parameters of @var{text}. The arguments are the same as to
1060 @code{make-text}. Returns @var{text}.
1061 @end defun
1063 @defun text-info text
1064 Returns the parameters of @var{text} as a list in the form:
1066 @example
1067 ((anchor-x . anchor-y) align angle string size visible show color)
1068 @end example
1070 See @code{make-text} for a description of all of these parameters.
1071 @end defun
1073 @defun text-center text
1074 Returns the position of the anchor of @var{text} in the form
1075 @code{(x . y)}.
1076 @end defun
1078 @defun text-align text
1079 Returns the alignment of @var{text} as one of the following symbols:
1081 @itemize
1082 @item
1083 @samp{lower-left}
1084 @item
1085 @samp{middle-left}
1086 @item
1087 @samp{upper-left}
1088 @item
1089 @samp{lower-center}
1090 @item
1091 @samp{middle-center}
1092 @item
1093 @samp{upper-center}
1094 @item
1095 @samp{lower-right}
1096 @item
1097 @samp{middle-right}
1098 @item
1099 @samp{upper-right}
1100 @end itemize
1101 @end defun
1103 @defun text-angle text
1104 Returns the angle that @var{text} is displayed at as an integer
1105 multiple of 90 degrees.
1106 @end defun
1108 @defun text-string text
1109 Returns the string content of @var{text}.
1110 @end defun
1112 @defun set-text-string! text str
1113 Set the string content of @var{text} to @var{str}.  @var{str} must not
1114 contain any null characters (@samp{#\0} in Scheme, Unicode
1115 @samp{U+0000}).
1116 @end defun
1118 @defun text-size text
1119 Return the font size of @var{text} as an integer.
1120 @end defun
1122 @defun text-visible? text
1123 Returns @samp{#t} if and only if @var{text} is set to be visible.
1124 @end defun
1126 @defun set-text-visibility! text visible?
1127 If @var{visible?} is @samp{#f}, sets @var{text} to be invisible;
1128 otherwise, sets it to be visible.
1129 @end defun
1131 @defun text-attribute-mode text
1132 Returns a symbol indicating which parts of @var{text} will be
1133 displayed when @var{text} is a valid attribute.  The returned value
1134 will be one of the following symbols:
1136 @itemize
1137 @item
1138 @samp{name}
1139 @item
1140 @samp{value}
1141 @item
1142 @samp{both}
1143 @end itemize
1144 @end defun
1146 @node Components
1147 @subsection Components
1149 Component @code{object}s represent instances of symbols.  They contain
1150 other @code{object}s copied from the original symbol when it is
1151 instantiated into a schematic.
1153 A component's @var{basename} is a string used to identify which symbol
1154 it originated from.  When instantiating a symbol on initial placement
1155 in a schematic, or when recreating a component while loading a
1156 schematic, the @var{basename} is used to find the underlying symbol
1157 file in the component library.
1159 @xref{Component objects}.
1161 @strong{Note}: In the gEDA C source code, these are normally called
1162 ``complex'' objects.  However, as Guile Scheme supports complex
1163 numbers, and the procedures related to working with complex numbers
1164 use the word @samp{complex} to describe them, this API uses
1165 @samp{component} to avoid ambiguity.
1167 The @var{position}, @var{angle} and @var{mirror} flag of a component
1168 indicates the transformation that was applied to the contents of the
1169 original symbol.  The transformation is applied in the following order:
1171 @enumerate
1172 @item
1173 If @var{mirror} is true, the symbol is reflected in the line x = 0.
1174 @item
1175 The symbol is rotated anti-clockwise by @var{angle} degrees about the
1176 point (0,0) (@var{angle} may only be an integer multiple of 90
1177 degrees).
1178 @item
1179 Finally, the symbol is translated by @var{position}.
1180 @end enumerate
1182 The component's contents (as returned by @code{component-contents})
1183 have the transformation already applied to them.  Updating the
1184 translation information using e.g. @code{set-component!} will not
1185 alter them -- that must be done separately (e.g. by reloading the
1186 symbol).
1188 @defun component? object
1189 Returns @samp{#t} if and only if @var{object} is a component @code{object}.
1190 @end defun
1192 @defun make-component basename position angle mirror locked
1193 Creates and returns a new, empty component @code{object} with the
1194 given @var{basename}.  @var{position}, @var{angle} and @var{mirror}
1195 specify the symbol transformation.  If @var{locked} is true, the
1196 component will be protected against accidental selection by the user
1197 (this is used in gschem e.g. for titleblocks).
1199 No attempt is made to load a symbol matching @var{basename} from
1200 component libraries, and the returned component is flagged as
1201 embedded.
1202 @end defun
1204 @defun make-component/library basename position angle mirror locked
1205 Searches the component libraries for a symbol matching @var{basename},
1206 and if found, instantiates the symbol and returns the resulting
1207 component (which is not flagged as embedded).  Arguments are as for
1208 @code{make-component}.
1210 If no match for @var{basename} is found, @samp{#f} is returned.
1211 @end defun
1213 @defun set-component! component position angle mirror locked
1214 Sets the parameters of @var{component}.  Arguments are the same as to
1215 @code{make-component}.  Returns @var{component}.
1217 @strong{Note}: Remember that modifying the transformation parameters
1218 of a component does not update the component's contents.
1219 @end defun
1221 @defun component-info component
1222 Returns the parameters of @var{component} as a list of the form:
1224 @example
1225 (basename (x . y) angle mirror locked)
1226 @end example
1227 @end defun
1229 @defun component-basename component
1230 Returns the basename of @var{component}.
1231 @end defun
1233 @defun component-position component
1234 Returns the position to which the original symbol was translated when
1235 creating @var{component}.
1236 @end defun
1238 @defun component-angle component
1239 Returns the angle by which the original symbol was rotated when
1240 creating @var{component}, as an integer number of degrees.
1241 @end defun
1243 @defun component-mirror? component
1244 Returns true if the original symbol was mirrored when creating
1245 @var{component}.
1246 @end defun
1248 @defun component-locked? component
1249 Returns true if @var{component} is non-selectable.
1250 @end defun
1252 @defun component-contents component
1253 Returns the contents of @var{components} as a list of objects.
1254 @end defun
1256 @defun component-append! component objects...
1257 Appends @var{objects} (which must not be component @code{object}s) to
1258 the contents of @var{component}.  Any @var{objects} which are already
1259 included in @var{component} are ignored.  If any @var{objects} are
1260 already part of a @code{page} or of another component @code{object},
1261 an @samp{object-state} error is raised. Returns @var{component}.
1262 @end defun
1264 @defun component-remove! component objects...
1265 Removes @var{objects} from the contents of @var{component}.  Any
1266 @var{objects} which are not part of a component or of a page are
1267 ignored. Returns @var{component}.
1269 An @samp{object-state} error will be raised if any @var{objects}
1270 satisfy any of the following conditions:
1272 @itemize
1273 @item
1274 are part of a @code{page};
1275 @item
1276 are part of a component @code{object} other than @var{component};
1277 @item
1278 have attached attributes
1279 @item
1280 are attached as an attribute.
1281 @end itemize
1282 @end defun
1284 @node Core attribute functions
1285 @section Core attribute functions
1287 To use the functions described in this section, you will need to load
1288 the @code{(geda attrib)} module.
1290 Attributes are text @code{object}s with a particular format of string.
1291 They can be floating, or they can be attached to another
1292 @code{object}.
1294 @defun attribute? object
1295 Returns true if and only if @var{object} is an attribute (i.e. a text
1296 @code{object} and in attribute format).
1297 @end defun
1299 @subsection Attribute names and values
1301 @defun parse-attrib text
1302 Splits the string from @var{text} (a text @code{object}) into name and
1303 value, if it is in attribute format.  If it is not in attribute
1304 format, raises an @samp{attribute-format} error.  The return value is
1305 in the form @samp{(@var{name} . @var{value})}.
1306 @end defun
1308 @defun attrib-name attrib
1309 Returns the name part of @var{attrib}, as a string.
1310 @end defun
1312 @defun attrib-value attrib
1313 Returns the value part of @var{attrib}, as a string.
1314 @end defun
1316 @defun set-attrib-value! attrib value
1317 Sets the value part of @var{attrib} to @var{value}.
1318 @end defun
1320 @subsection Attribute attachment
1322 @defun attrib-attachment attrib
1323 If @var{attrib} is attached to another @code{object}, returns that
1324 object.  Otherwise, returns @samp{#f}.
1325 @end defun
1327 @defun object-attribs object
1328 Returns a list of all attributes attached to @var{object}.
1329 @end defun
1331 @defun attach-attribs! object [attribs...]
1332 Attach @var{attribs} to @var{object}.  All the @var{attribs} must be
1333 text @code{object}s.  The following conditions must be satisfied, or
1334 an @samp{object-state} error will be raised:
1336 @itemize
1337 @item
1338 Neither @var{object} nor any of the @var{attribs} may be already
1339 attached as an attribute;
1340 @item
1341 Both @var{object} and all @var{attribs} must be part of the same
1342 @code{page} and/or component @code{object};
1343 @end itemize
1345 Any @var{attribs} that are already attached to @var{object} are
1346 ignored.  Returns @var{object}.
1348 @strong{Note}: For historical reasons, @code{attach-attribs!} does not
1349 require that all @var{attribs} satisfy @code{attribute?}.
1350 Nevertheless, avoid attaching non-attribute text objects as attributes.
1351 @end defun
1353 @defun detach-attribs! object [attribs...]
1354 Detach @var{attribs} from @var{object}.  Any @var{attribs} that are
1355 not attached as attributes are ignored.  If any @var{attribs} are
1356 attached to @code{object}s other than @var{object}, an
1357 @samp{object-state} error is raised.
1358 @end defun
1360 @subsection Inherited and promoted attributes
1362 @dfn{Inherited attributes} are unattached attributes inside a
1363 component @code{object}.
1365 @defun inherited-attribs object
1366 Returns the inherited attributes of @var{object}, if @var{object} is a
1367 component.  If @var{object} is not a component, returns the empty
1368 list.
1369 @end defun
1371 @defun attrib-inherited? attrib
1372 Returns @samp{#t} if @var{attrib} is an inherited attribute.
1373 @end defun
1375 @dfn{promotable attributes} are inherited attributes that are both
1376 visible and have names that are in the list of promotable attributes
1377 set with the @code{always-promote-attributes} rc file parameter.
1379 @defun promotable-attribs component
1380 Returns a list of promotable attributes of @var{component}.
1381 @end defun
1383 @defun promote-attribs! component
1384 Promote all promotable attributes from @var{component} into the
1385 @code{page} that contains @var{component}.  If @var{component} is not
1386 in a page, an @samp{object-state} error is raised.
1388 All promotable attributes are copied, and made invisible.  The copies
1389 are added to the @code{page}, and attached as attributes of @var{component}.
1391 The promoted attributes are returned.  If @var{component} is not in
1392 fact a component @code{object}, does nothing and returns the empty list.
1393 @end defun
1395 @node gschem API Reference
1396 @chapter gschem API Reference
1398 The Scheme modules and functions described in this chapter are
1399 available in the gschem schematic editor application.  They are more
1400 focused on enabling and responding to user editing operations.
1402 @menu
1403 * Windows and views::
1404 * Selections::
1405 * Hooks::
1406 * Miscellanous gschem functions::
1407 @end menu
1409 @node Windows and views
1410 @section Windows and views
1412 To use the functions described in this section, you will need to load
1413 the @code{(gschem window)} module.
1415 @defun active-page
1416 Returns the @code{page} currently being displayed for editing.
1417 @end defun
1419 @defun set-active-page! page
1420 Sets the current @code{page} to @var{page}.
1421 @end defun
1423 @defun pointer-position
1424 Returns the current mouse pointer position in world coordinates in the
1425 form @samp{(x . y)}.  If the pointer is outside the display area,
1426 returns @samp{#f}.
1427 @end defun
1429 @node Selections
1430 @section Selections
1432 @node Hooks
1433 @section Hooks
1435 @node Miscellanous gschem functions
1436 @section Miscellaneous gschem functions
1438 @node Concept Index
1439 @unnumbered Concept Index
1441 @printindex cp
1443 @node Function Index
1444 @unnumbered Function Index
1446 @printindex fn
1448 @bye